Skip to content

Commit

Permalink
feat: support module-sync condition when loading config if enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Nov 25, 2024
1 parent ba821bb commit cf5028d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/vite/misc/false.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const result: boolean
export default result
1 change: 1 addition & 0 deletions packages/vite/misc/false.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default false
2 changes: 2 additions & 0 deletions packages/vite/misc/true.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const result: boolean
export default result
1 change: 1 addition & 0 deletions packages/vite/misc/true.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default true
23 changes: 11 additions & 12 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@
"types": "./dist/node/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/node/index.d.ts",
"default": "./dist/node/index.js"
},
"require": {
"types": "./index.d.cts",
"default": "./index.cjs"
}
"module-sync": "./dist/node/index.js",
"import": "./dist/node/index.js",
"require": "./index.cjs"
},
"./client": {
"types": "./client.d.ts"
},
"./module-runner": {
"types": "./dist/node/module-runner.d.ts",
"import": "./dist/node/module-runner.js"
},
"./module-runner": "./dist/node/module-runner.js",
"./dist/client/*": "./dist/client/*",
"./types/*": {
"types": "./types/*"
Expand All @@ -50,9 +42,16 @@
]
}
},
"imports": {
"#module-sync-enabled": {
"module-sync": "./misc/true.js",
"default": "./misc/false.js"
}
},
"files": [
"bin",
"dist",
"misc/**/*.js",
"client.d.ts",
"index.cjs",
"index.d.cts",
Expand Down
1 change: 1 addition & 0 deletions packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const nodeConfig = defineConfig({
'fsevents',
'rollup/parseAst',
/^tsx\//,
/^#/,
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/rollup.dts.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const external = [

export default defineConfig({
input: {
index: './temp/node/index.d.ts',
'module-runner': './temp/module-runner/index.d.ts',
index: './temp/src/node/index.d.ts',
'module-runner': './temp/src/module-runner/index.d.ts',
},
output: {
dir: './dist/node',
Expand Down
8 changes: 7 additions & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,9 @@ async function bundleConfigFile(
fileName: string,
isESM: boolean,
): Promise<{ code: string; dependencies: string[] }> {
const isModuleSyncConditionEnabled = (await import('#module-sync-enabled'))
.default

const dirnameVarName = '__vite_injected_original_dirname'
const filenameVarName = '__vite_injected_original_filename'
const importMetaUrlVarName = '__vite_injected_original_import_meta_url'
Expand Down Expand Up @@ -1741,7 +1744,10 @@ async function bundleConfigFile(
preferRelative: false,
tryIndex: true,
mainFields: [],
conditions: ['node'],
conditions: [
'node',
...(isModuleSyncConditionEnabled ? ['module-sync'] : []),
],
externalConditions: [],
external: [],
noExternal: [],
Expand Down
1 change: 1 addition & 0 deletions packages/vite/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"rootDir": ".",
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
Expand Down

0 comments on commit cf5028d

Please sign in to comment.