From 0e7a75824d4dc9fff484d8858cb9bdd95db0769a Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 13 Dec 2024 21:35:44 +0800 Subject: [PATCH 1/2] feat(deps): bump jiti to v2 --- packages/core/package.json | 4 ++-- packages/core/prebundle.config.mjs | 14 +++----------- packages/core/src/config.ts | 9 +++++---- pnpm-lock.yaml | 24 +++++++++++++++--------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 43e1534575..2132cfe809 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -54,7 +54,8 @@ "@rspack/core": "~1.1.6", "@rspack/lite-tapable": "~1.0.1", "@swc/helpers": "^0.5.15", - "core-js": "~3.39.0" + "core-js": "~3.39.0", + "jiti": "2.4.1" }, "devDependencies": { "@rslib/core": "0.1.3", @@ -75,7 +76,6 @@ "dotenv-expand": "11.0.7", "html-rspack-plugin": "6.0.2", "http-proxy-middleware": "^2.0.6", - "jiti": "^1.21.6", "launch-editor-middleware": "^2.9.1", "mrmime": "^2.0.0", "on-finished": "2.4.1", diff --git a/packages/core/prebundle.config.mjs b/packages/core/prebundle.config.mjs index 3e104b4595..7d1734cf6c 100644 --- a/packages/core/prebundle.config.mjs +++ b/packages/core/prebundle.config.mjs @@ -62,12 +62,6 @@ export default { ); }, }, - { - name: 'jiti', - // jiti has been minified, we do not need to prettier it - prettier: false, - ignoreDts: true, - }, { name: 'launch-editor-middleware', ignoreDts: true, @@ -172,7 +166,7 @@ export default { { name: 'postcss-loader', externals: { - jiti: '../jiti', + jiti: 'jiti', semver: './semver', postcss: '../postcss', }, @@ -190,16 +184,14 @@ export default { name: 'postcss-load-config', externals: { yaml: 'yaml', - '../jiti': '../jiti', + jiti: 'jiti', }, ignoreDts: true, // this is a trick to avoid ncc compiling the dynamic import syntax // https://github.com/vercel/ncc/issues/935 beforeBundle(task) { replaceFileContent(join(task.depPath, 'src/req.js'), (content) => - content - .replaceAll('await import', 'await __import') - .replaceAll(`import('jiti')`, `import('../jiti/index.js')`), + content.replaceAll('await import', 'await __import'), ); }, afterBundle(task) { diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index fe33849230..11716570ad 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -472,15 +472,16 @@ export async function loadConfig({ try { if (configExport! === undefined) { - const { default: jiti } = await import('../compiled/jiti/index.js'); - const loadConfig = jiti(__filename, { - esmResolve: true, + const { createJiti } = await import('jiti'); + const jiti = createJiti(__filename, { // disable require cache to support restart CLI and read the new config requireCache: false, interopDefault: true, }); - configExport = loadConfig(configFilePath) as RsbuildConfigExport; + configExport = await jiti.import(configFilePath, { + default: true, + }); } } catch (err) { logger.error(`Failed to load file with jiti: ${color.dim(configFilePath)}`); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3d895ec8b4..3acea9a836 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -591,6 +591,9 @@ importers: core-js: specifier: ~3.39.0 version: 3.39.0 + jiti: + specifier: 2.4.1 + version: 2.4.1 devDependencies: '@rslib/core': specifier: 0.1.3 @@ -646,9 +649,6 @@ importers: http-proxy-middleware: specifier: ^2.0.6 version: 2.0.7 - jiti: - specifier: ^1.21.6 - version: 1.21.6 launch-editor-middleware: specifier: ^2.9.1 version: 2.9.1 @@ -669,7 +669,7 @@ importers: version: 8.4.49 postcss-load-config: specifier: 6.0.1 - version: 6.0.1(jiti@1.21.6)(postcss@8.4.49)(yaml@2.6.0) + version: 6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.6.0) postcss-loader: specifier: 8.1.1 version: 8.1.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(postcss@8.4.49)(typescript@5.7.2)(webpack@5.97.1) @@ -1013,7 +1013,7 @@ importers: version: 3.2.4(svelte@5.9.0) svelte-preprocess: specifier: ^6.0.3 - version: 6.0.3(@babel/core@7.26.0)(less@4.2.1)(postcss-load-config@6.0.1(jiti@1.21.6)(postcss@8.4.49)(yaml@2.6.0))(postcss@8.4.49)(sass@1.82.0)(stylus@0.64.0)(svelte@5.9.0)(typescript@5.7.2) + version: 6.0.3(@babel/core@7.26.0)(less@4.2.1)(postcss-load-config@6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.6.0))(postcss@8.4.49)(sass@1.82.0)(stylus@0.64.0)(svelte@5.9.0)(typescript@5.7.2) devDependencies: '@rsbuild/core': specifier: workspace:* @@ -4534,6 +4534,10 @@ packages: resolution: {integrity: sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==} hasBin: true + jiti@2.4.1: + resolution: {integrity: sha512-yPBThwecp1wS9DmoA4x4KR2h3QoslacnDR8ypuFM962kI4/456Iy1oHx2RAgh4jfZNdn0bctsdadceiBUgpU1g==} + hasBin: true + js-tokens@4.0.0: resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} @@ -10333,6 +10337,8 @@ snapshots: jiti@1.21.6: {} + jiti@2.4.1: {} + js-tokens@4.0.0: {} js-yaml@3.14.1: @@ -11357,11 +11363,11 @@ snapshots: optionalDependencies: postcss: 8.4.49 - postcss-load-config@6.0.1(jiti@1.21.6)(postcss@8.4.49)(yaml@2.6.0): + postcss-load-config@6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.6.0): dependencies: lilconfig: 3.1.2 optionalDependencies: - jiti: 1.21.6 + jiti: 2.4.1 postcss: 8.4.49 yaml: 2.6.0 @@ -12180,14 +12186,14 @@ snapshots: svelte-dev-helper: 1.1.9 svelte-hmr: 0.14.12(svelte@5.9.0) - svelte-preprocess@6.0.3(@babel/core@7.26.0)(less@4.2.1)(postcss-load-config@6.0.1(jiti@1.21.6)(postcss@8.4.49)(yaml@2.6.0))(postcss@8.4.49)(sass@1.82.0)(stylus@0.64.0)(svelte@5.9.0)(typescript@5.7.2): + svelte-preprocess@6.0.3(@babel/core@7.26.0)(less@4.2.1)(postcss-load-config@6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.6.0))(postcss@8.4.49)(sass@1.82.0)(stylus@0.64.0)(svelte@5.9.0)(typescript@5.7.2): dependencies: svelte: 5.9.0 optionalDependencies: '@babel/core': 7.26.0 less: 4.2.1 postcss: 8.4.49 - postcss-load-config: 6.0.1(jiti@1.21.6)(postcss@8.4.49)(yaml@2.6.0) + postcss-load-config: 6.0.1(jiti@2.4.1)(postcss@8.4.49)(yaml@2.6.0) sass: 1.82.0 stylus: 0.64.0 typescript: 5.7.2 From 0dc4e5297b529bdeb37352a82364f88478f3df23 Mon Sep 17 00:00:00 2001 From: neverland Date: Sat, 14 Dec 2024 08:20:18 +0800 Subject: [PATCH 2/2] fix: cache --- packages/core/src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 11716570ad..e904e9f7dd 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -475,7 +475,7 @@ export async function loadConfig({ const { createJiti } = await import('jiti'); const jiti = createJiti(__filename, { // disable require cache to support restart CLI and read the new config - requireCache: false, + moduleCache: false, interopDefault: true, });