diff --git a/src/config/ts-path.ts b/src/config/ts-path.ts index 45d358f1a..029a0af4b 100644 --- a/src/config/ts-path.ts +++ b/src/config/ts-path.ts @@ -239,15 +239,17 @@ export async function tsPath(root: string, orig: string | undefined, plugin?: Pl // NOTE: The order of these checks matter! - if (settings.tsnodeEnabled === false) { - debug(`Skipping typescript path lookup for ${root} because tsNodeEnabled is explicitly set to false`) + const enableAutoTranspile = settings.enableAutoTranspile ?? settings.tsnodeEnabled + + if (enableAutoTranspile === false) { + debug(`Skipping typescript path lookup for ${root} because enableAutoTranspile is explicitly set to false`) return orig } const isProduction = isProd() // Do not skip ts-node registration if the plugin is linked - if (settings.tsnodeEnabled === undefined && isProduction && plugin?.type !== 'link') { + if (enableAutoTranspile === undefined && isProduction && plugin?.type !== 'link') { debug(`Skipping typescript path lookup for ${root} because NODE_ENV is NOT "test" or "development"`) return orig } diff --git a/src/settings.ts b/src/settings.ts index c932553ed..6ee729cd3 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -9,7 +9,7 @@ export type Settings = { /** * Show additional debug output without DEBUG. Mainly shows stackstraces. * - * Useful to set in the ./bin/dev script. + * Useful to set in the ./bin/dev.js script. * oclif.settings.debug = true; */ debug?: boolean @@ -29,8 +29,15 @@ export type Settings = { * Defaults to true in development and test environments (e.g. using bin/dev.js or * NODE_ENV=development or NODE_ENV=test). * + * @deprecated use enableAutoTranspile instead. */ tsnodeEnabled?: boolean + /** + * Enable automatic transpilation of TypeScript files to JavaScript. + * + * Defaults to true in development and test environments (e.g. using bin/dev.js or NODE_ENV=development or NODE_ENV=test). + */ + enableAutoTranspile?: boolean } // Set global.oclif to the new object if it wasn't set before diff --git a/test/config/ts-path.test.ts b/test/config/ts-path.test.ts index 0f6dba137..c7c9e16ad 100644 --- a/test/config/ts-path.test.ts +++ b/test/config/ts-path.test.ts @@ -84,7 +84,7 @@ describe('tsPath', () => { it('should resolve to .ts file if enabled and prod', async () => { sandbox.stub(util, 'readTSConfig').resolves(DEFAULT_TS_CONFIG) - settings.tsnodeEnabled = true + settings.enableAutoTranspile = true const originalNodeEnv = process.env.NODE_ENV delete process.env.NODE_ENV @@ -92,15 +92,15 @@ describe('tsPath', () => { expect(result).to.equal(join(root, tsModule)) process.env.NODE_ENV = originalNodeEnv - delete settings.tsnodeEnabled + delete settings.enableAutoTranspile }) it('should resolve to js if disabled', async () => { sandbox.stub(util, 'readTSConfig').resolves(DEFAULT_TS_CONFIG) - settings.tsnodeEnabled = false + settings.enableAutoTranspile = false const result = await configTsNode.tsPath(root, jsCompiled) expect(result).to.equal(join(root, jsCompiled)) - delete settings.tsnodeEnabled + delete settings.enableAutoTranspile }) })