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: replace runner-side path normalization with fetchModule-side resolve #18361

Merged
merged 42 commits into from
Dec 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0f1ca5b
fix(runner): normalize absolute path in fetchModule
hi-ogawa Oct 16, 2024
1913865
test: add test
hi-ogawa Oct 16, 2024
de0a2f8
wip: windows
hi-ogawa Oct 16, 2024
5e8e7ec
wip: windows
hi-ogawa Oct 16, 2024
2c3170c
refactor: move normalization to fetchModule
hi-ogawa Oct 16, 2024
3726ec3
chore: remove root
hi-ogawa Oct 16, 2024
f001b7d
chore: cleanup
hi-ogawa Oct 16, 2024
8f8bc80
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 21, 2024
4bf3d0a
test: resolve file url via plugin
hi-ogawa Oct 21, 2024
f35cacb
fix: no support `file://`
hi-ogawa Oct 21, 2024
d9e5dbb
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 21, 2024
b1236bf
debug
hi-ogawa Oct 21, 2024
d4059cd
chore: comment
hi-ogawa Oct 21, 2024
0a50356
test: refactor out fs mock
hi-ogawa Oct 21, 2024
8e510e0
test: revert isolate
hi-ogawa Oct 21, 2024
75ab26e
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 22, 2024
42a5eb4
chore: comment
hi-ogawa Oct 22, 2024
975f597
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 29, 2024
27060f8
cherry-pick https://github.com/vitejs/vite/pull/18421
hi-ogawa Oct 22, 2024
768c935
test: cleanup
hi-ogawa Oct 29, 2024
d5ed954
chore: cleanup
hi-ogawa Oct 29, 2024
08cd7d9
test: tweak
hi-ogawa Oct 29, 2024
ad91d63
chore: remove root
hi-ogawa Oct 29, 2024
0855eb7
ci: debug preview-release
hi-ogawa Oct 29, 2024
5350765
ci: more debug
hi-ogawa Oct 29, 2024
2793b78
ci: tweak
hi-ogawa Oct 29, 2024
2c3c408
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 29, 2024
b3e1e4f
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Oct 30, 2024
446fe6f
fix: deal with isExternalUrl
hi-ogawa Oct 30, 2024
5a44730
test: revive resolveId test
hi-ogawa Oct 30, 2024
cfc4901
chore: cleanup
hi-ogawa Oct 30, 2024
61679ab
chore: remove more
hi-ogawa Oct 30, 2024
a6d6e77
chore: more cleanup
hi-ogawa Oct 30, 2024
0f39deb
Merge branch 'main' into fix-normalize-url-in-fetchModule
hi-ogawa Dec 10, 2024
06d820e
chore: revert some
hi-ogawa Dec 10, 2024
4e04d5c
chore: cleanup
hi-ogawa Dec 10, 2024
92f53eb
docs: update
hi-ogawa Dec 10, 2024
bdfbe10
chore: optional root
hi-ogawa Dec 10, 2024
901170c
docs: remove root
hi-ogawa Dec 10, 2024
feb14b0
chore: remove internal usages of root
hi-ogawa Dec 10, 2024
ff8b33c
chore: remove root in worker examples
hi-ogawa Dec 10, 2024
b1a1722
chore: keep this one though
hi-ogawa Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add test
hi-ogawa committed Oct 16, 2024
commit 1913865aa906e993c27b2fba1930149c622ef903
Original file line number Diff line number Diff line change
@@ -248,3 +248,41 @@ describe('optimize-deps', async () => {
expect(mod.default.hello()).toMatchInlineSnapshot(`"world"`)
})
})

describe('resolveId absolute path entry', async () => {
const it = await createModuleRunnerTester({
plugins: [
{
name: 'test-resolevId',
enforce: 'pre',
resolveId(source) {
if (
source ===
posix.join(this.environment.config.root, 'fixtures/basic.js')
) {
return '\0virtual:basic'
}
},
load(id) {
if (id === '\0virtual:basic') {
return `export const name = "virtual:basic"`
}
},
},
],
})

it('ssrLoadModule', async ({ server }) => {
const mod = await server.ssrLoadModule(
posix.join(server.config.root, 'fixtures/basic.js'),
)
expect(mod.name).toMatchInlineSnapshot(`"virtual:basic"`)
})

it('runner', async ({ server, runner }) => {
const mod = await runner.import(
posix.join(server.config.root, 'fixtures/basic.js'),
)
expect(mod.name).toMatchInlineSnapshot(`"virtual:basic"`)
})
})
1 change: 1 addition & 0 deletions packages/vite/src/node/ssr/runtime/__tests__/utils.ts
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ export async function createModuleRunnerTester(
}
},
},
...(config.plugins ?? []),
],
...config,
})

Unchanged files with check annotations Beta

true,
)
if (!resolved) {
const err: any = new Error(

Check failure on line 75 in packages/vite/src/node/ssr/fetchModule.ts

GitHub Actions / Build&Test: node-20, windows-latest

packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts > module runner initialization > dynamic import doesn't produce duplicates

Error: Cannot find module 'D:/a/vite/vite/packages/vite/src/node/ssr/runtime/__tests__/fixtures/simple.js' imported from 'D:/a/vite/vite/packages/vite/src/node/ssr/runtime/__tests__/fixtures/dynamic-import.js' ❯ Module.fetchModule packages/vite/src/node/ssr/fetchModule.ts:75:24 ❯ RunnableDevEnvironment.fetchModule packages/vite/src/node/server/environment.ts:170:12 ❯ Object.fetchModule packages/vite/src/node/ssr/runtime/serverModuleRunner.ts:96:23 ❯ ModuleRunner.getModuleInformation packages/vite/src/module-runner/runner.ts:258:34 ❯ ModuleRunner.cachedModule packages/vite/src/module-runner/runner.ts:228:21 ❯ request packages/vite/src/module-runner/runner.ts:303:33 ❯ dynamicRequest packages/vite/src/module-runner/runner.ts:316:14 ❯ Module.initialize packages/vite/src/node/ssr/runtime/__tests__/fixtures/dynamic-import.js:17:32 ❯ packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts:165:21 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_MODULE_NOT_FOUND' }
`Cannot find module '${url}' imported from '${importer}'`,
)
err.code = 'ERR_MODULE_NOT_FOUND'