Skip to content

Commit cf5028d

Browse files
authored
feat: support module-sync condition when loading config if enabled (#18650)
1 parent ba821bb commit cf5028d

9 files changed

+28
-15
lines changed

packages/vite/misc/false.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const result: boolean
2+
export default result

packages/vite/misc/false.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default false

packages/vite/misc/true.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const result: boolean
2+
export default result

packages/vite/misc/true.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default true

packages/vite/package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,14 @@
2020
"types": "./dist/node/index.d.ts",
2121
"exports": {
2222
".": {
23-
"import": {
24-
"types": "./dist/node/index.d.ts",
25-
"default": "./dist/node/index.js"
26-
},
27-
"require": {
28-
"types": "./index.d.cts",
29-
"default": "./index.cjs"
30-
}
23+
"module-sync": "./dist/node/index.js",
24+
"import": "./dist/node/index.js",
25+
"require": "./index.cjs"
3126
},
3227
"./client": {
3328
"types": "./client.d.ts"
3429
},
35-
"./module-runner": {
36-
"types": "./dist/node/module-runner.d.ts",
37-
"import": "./dist/node/module-runner.js"
38-
},
30+
"./module-runner": "./dist/node/module-runner.js",
3931
"./dist/client/*": "./dist/client/*",
4032
"./types/*": {
4133
"types": "./types/*"
@@ -50,9 +42,16 @@
5042
]
5143
}
5244
},
45+
"imports": {
46+
"#module-sync-enabled": {
47+
"module-sync": "./misc/true.js",
48+
"default": "./misc/false.js"
49+
}
50+
},
5351
"files": [
5452
"bin",
5553
"dist",
54+
"misc/**/*.js",
5655
"client.d.ts",
5756
"index.cjs",
5857
"index.d.cts",

packages/vite/rollup.config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const nodeConfig = defineConfig({
112112
'fsevents',
113113
'rollup/parseAst',
114114
/^tsx\//,
115+
/^#/,
115116
...Object.keys(pkg.dependencies),
116117
...Object.keys(pkg.peerDependencies),
117118
],

packages/vite/rollup.dts.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const external = [
2424

2525
export default defineConfig({
2626
input: {
27-
index: './temp/node/index.d.ts',
28-
'module-runner': './temp/module-runner/index.d.ts',
27+
index: './temp/src/node/index.d.ts',
28+
'module-runner': './temp/src/module-runner/index.d.ts',
2929
},
3030
output: {
3131
dir: './dist/node',

packages/vite/src/node/config.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,9 @@ async function bundleConfigFile(
17031703
fileName: string,
17041704
isESM: boolean,
17051705
): Promise<{ code: string; dependencies: string[] }> {
1706+
const isModuleSyncConditionEnabled = (await import('#module-sync-enabled'))
1707+
.default
1708+
17061709
const dirnameVarName = '__vite_injected_original_dirname'
17071710
const filenameVarName = '__vite_injected_original_filename'
17081711
const importMetaUrlVarName = '__vite_injected_original_import_meta_url'
@@ -1741,7 +1744,10 @@ async function bundleConfigFile(
17411744
preferRelative: false,
17421745
tryIndex: true,
17431746
mainFields: [],
1744-
conditions: ['node'],
1747+
conditions: [
1748+
'node',
1749+
...(isModuleSyncConditionEnabled ? ['module-sync'] : []),
1750+
],
17451751
externalConditions: [],
17461752
external: [],
17471753
noExternal: [],

packages/vite/tsconfig.base.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"compilerOptions": {
3+
"rootDir": ".",
34
"target": "ES2022",
45
"module": "ESNext",
56
"moduleResolution": "Bundler",

0 commit comments

Comments
 (0)