Skip to content

Commit

Permalink
Fix prefer TS exts via env variables (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
nana4gonta authored and blakeembrey committed Sep 15, 2019
1 parent ebbcf39 commit b01b629
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ describe('ts-node', function () {
})
})

it('should import ts before js when TS_NODE_PREFER_TS_EXTS env is present', function (done) {
exec(`${BIN_EXEC} tests/import-order/compiled`, { env: { ...process.env, TS_NODE_PREFER_TS_EXTS: 'true' } }, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('Hello, TypeScript!\n')

return done()
})
})

it('should ignore .d.ts files', function (done) {
exec(`${BIN_EXEC} tests/import-order/importer`, function (err, stdout) {
expect(err).to.equal(null)
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export function register (opts: Options = {}): Register {
const register: Register = { cwd, compile, getTypeInfo, extensions, ts }

// Register the extensions.
registerExtensions(opts, extensions, ignore, register, originalJsHandler)
registerExtensions(options.preferTsExts, extensions, ignore, register, originalJsHandler)

return register
}
Expand Down Expand Up @@ -446,7 +446,7 @@ function reorderRequireExtension (ext: string) {
* Register the extensions to support when importing files.
*/
function registerExtensions (
opts: Options,
preferTsExts: boolean | null | undefined,
extensions: string[],
ignore: RegExp[],
register: Register,
Expand All @@ -457,7 +457,7 @@ function registerExtensions (
registerExtension(ext, ignore, register, originalJsHandler)
}

if (opts.preferTsExts) {
if (preferTsExts) {
// tslint:disable-next-line
const preferredExtensions = new Set([...extensions, ...Object.keys(require.extensions)])

Expand Down

0 comments on commit b01b629

Please sign in to comment.