Skip to content

Commit

Permalink
Merge 405dcf6 into 6295254
Browse files Browse the repository at this point in the history
  • Loading branch information
nana4gonta committed Aug 18, 2019
2 parents 6295254 + 405dcf6 commit ffb0c10
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 @@ -401,7 +401,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 @@ -430,7 +430,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 @@ -441,7 +441,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 ffb0c10

Please sign in to comment.