Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Keep search in resolveReplacementExtensions #1165

Merged
merged 2 commits into from Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist-raw/node-esm-resolve-implementation.js
Expand Up @@ -307,7 +307,8 @@ function resolveReplacementExtensions(search) {
const pathnameWithoutExtension = search.pathname.slice(0, search.pathname.length - 3);
for (let i = 0; i < replacementExtensions.length; i++) {
const extension = replacementExtensions[i];
const guess = new URL(`${pathnameWithoutExtension}${extension}`, search);
const guess = new URL(search.toString());
guess.pathname = `${pathnameWithoutExtension}${extension}`;
if (fileExists(guess)) return guess;
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/index.spec.ts
Expand Up @@ -932,6 +932,15 @@ describe('ts-node', function () {
})
})

it('should bypass import cache when changing search params', (done) => {
exec(`${cmd} index.ts`, { cwd: join(__dirname, '../tests/esm-import-cache') }, function (err, stdout) {
expect(err).to.equal(null)
expect(stdout).to.equal('log1\nlog2\nlog2\n')

return done()
})
})

it('should support transpile only mode via dedicated loader entrypoint', (done) => {
exec(`${cmd}/transpile-only index.ts`, { cwd: join(__dirname, '../tests/esm-transpile-only') }, function (err, stdout) {
expect(err).to.equal(null)
Expand Down
4 changes: 4 additions & 0 deletions tests/esm-import-cache/index.ts
@@ -0,0 +1,4 @@
import './log1.js'
import './log1.js'
import './log2.js'
import './log2.js?bust'
1 change: 1 addition & 0 deletions tests/esm-import-cache/log1.ts
@@ -0,0 +1 @@
console.log('log1')
1 change: 1 addition & 0 deletions tests/esm-import-cache/log2.ts
@@ -0,0 +1 @@
console.log('log2')
3 changes: 3 additions & 0 deletions tests/esm-import-cache/package.json
@@ -0,0 +1,3 @@
{
"type": "module"
}
7 changes: 7 additions & 0 deletions tests/esm-import-cache/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "ESNext",
"allowJs": true,
"moduleResolution": "node"
}
}