Skip to content

Commit

Permalink
Fix: Keep search in resolveReplacementExtensions (#1165)
Browse files Browse the repository at this point in the history
* Fix: Keep search in resolveReplacementExtensions

* Test: bypass import cache
  • Loading branch information
frandiox authored Nov 27, 2020
1 parent a7aa0af commit c11aa8a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dist-raw/node-esm-resolve-implementation.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('log1')
1 change: 1 addition & 0 deletions tests/esm-import-cache/log2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('log2')
3 changes: 3 additions & 0 deletions tests/esm-import-cache/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
7 changes: 7 additions & 0 deletions tests/esm-import-cache/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "ESNext",
"allowJs": true,
"moduleResolution": "node"
}
}

0 comments on commit c11aa8a

Please sign in to comment.