Skip to content

Commit

Permalink
feat: add enableAutoTranspile setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Feb 21, 2024
1 parent 94912cd commit ae66106
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/config/ts-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
9 changes: 8 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/config/ts-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,23 @@ 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

const result = await configTsNode.tsPath(root, jsCompiled)
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
})
})

0 comments on commit ae66106

Please sign in to comment.