-
-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
… cjs or esm -- into account when resolving package.json "exports" (#1782) * Add failing test * fix typo in failing test * fix bug * fix test runIf filter * fix * fix * lint
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createExec } from '../exec-helpers'; | ||
import { | ||
ctxTsNode, | ||
nodeSupportsEsmHooks, | ||
TEST_DIR, | ||
tsSupportsStableNodeNextNode16, | ||
CMD_TS_NODE_WITHOUT_PROJECT_FLAG, | ||
nodeSupportsSpawningChildProcess, | ||
} from '../helpers'; | ||
import { context, expect } from '../testlib'; | ||
import { join } from 'path'; | ||
|
||
const exec = createExec({ | ||
cwd: TEST_DIR, | ||
}); | ||
|
||
const test = context(ctxTsNode); | ||
|
||
test.suite( | ||
'Issue #1778: typechecker resolver should take importer\'s module type -- cjs or esm -- into account when resolving package.json "exports"', | ||
(test) => { | ||
test.runIf( | ||
nodeSupportsEsmHooks && | ||
nodeSupportsSpawningChildProcess && | ||
tsSupportsStableNodeNextNode16 | ||
); | ||
test('test', async () => { | ||
const { err, stdout } = await exec( | ||
`${CMD_TS_NODE_WITHOUT_PROJECT_FLAG} ./index.ts`, | ||
{ | ||
cwd: join(TEST_DIR, '1778'), | ||
} | ||
); | ||
expect(err).toBe(null); | ||
expect(stdout).toBe('{ esm: true }\n'); | ||
}); | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import foo from 'foo'; | ||
|
||
// This file is ESM, so if typechecker's resolver is working correctly, will | ||
// resolve to the foo's package.json "exports" mapping for "default", not "require" | ||
const bar: { esm: true } = foo; | ||
console.log(bar); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ts-node": { | ||
"esm": true | ||
}, | ||
"compilerOptions": { | ||
"module": "NodeNext", | ||
"noEmit": true | ||
} | ||
} |