From 9f8116878a6b23525b26aae80b8c13b9d2ddceb8 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Sun, 8 Dec 2024 04:15:55 +0800 Subject: [PATCH 01/13] fix(externals): use resolver to resolve request --- package.json | 1 + packages/core/src/config.ts | 51 +++- packages/core/src/css/cssConfig.ts | 8 +- packages/core/src/types/utils.ts | 6 + packages/core/src/utils/helper.ts | 5 + pnpm-lock.yaml | 257 +++++++++++++++++- .../auto-extension/__fixtures__/src/common.ts | 1 - .../auto-extension/__fixtures__/src/foo.ts | 1 + .../auto-extension/__fixtures__/src/index.ts | 5 +- .../__fixtures__/src/utils/index.ts | 1 + .../integration/auto-extension/index.test.ts | 38 ++- .../config-override/package.json | 2 +- .../type-commonjs/default/package.json | 2 +- .../false-bundleless/package.json | 6 + .../false-bundleless/rslib.config.ts | 20 ++ .../type-commonjs/false/package.json | 2 +- .../type-module/config-override/package.json | 2 +- .../type-module/default/package.json | 2 +- .../type-module/false-bundleless/package.json | 6 + .../false-bundleless/rslib.config.ts | 20 ++ .../type-module/false/package.json | 2 +- .../bundle-false/basic/src/index.ts | 4 + .../basic/src/mainFiles1/index.ts | 1 + .../basic/src/mainFiles2/index.ts | 1 + tests/integration/bundle-false/index.test.ts | 55 +++- tests/integration/directive/index.test.ts | 38 ++- tests/integration/entry/index.test.ts | 16 +- tests/scripts/shared.ts | 6 +- 28 files changed, 505 insertions(+), 54 deletions(-) delete mode 100644 tests/integration/auto-extension/__fixtures__/src/common.ts create mode 100644 tests/integration/auto-extension/__fixtures__/src/foo.ts create mode 100644 tests/integration/auto-extension/__fixtures__/src/utils/index.ts create mode 100644 tests/integration/auto-extension/type-commonjs/false-bundleless/package.json create mode 100644 tests/integration/auto-extension/type-commonjs/false-bundleless/rslib.config.ts create mode 100644 tests/integration/auto-extension/type-module/false-bundleless/package.json create mode 100644 tests/integration/auto-extension/type-module/false-bundleless/rslib.config.ts create mode 100644 tests/integration/bundle-false/basic/src/mainFiles1/index.ts create mode 100644 tests/integration/bundle-false/basic/src/mainFiles2/index.ts diff --git a/package.json b/package.json index e13e35edc..ff023d65c 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ }, "pnpm": { "overrides": { + "@rspack/core": "npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520", "zx>@types/node": "-" } } diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 2b99c8866..a2fc849a1 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -5,6 +5,7 @@ import { type RsbuildConfig, type RsbuildPlugin, type RsbuildPlugins, + type Rspack, defineConfig as defineRsbuildConfig, loadConfig as loadRsbuildConfig, mergeRsbuildConfig, @@ -38,6 +39,7 @@ import type { DeepRequired, ExcludesFalse, Format, + GetAsyncFunctionFromUnion, LibConfig, LibOnlyConfig, PkgJson, @@ -63,6 +65,7 @@ import { isIntermediateOutputFormat, isObject, nodeBuiltInModules, + normalizeSlash, omit, pick, readPackageJson, @@ -966,23 +969,37 @@ const composeBundleConfig = ( const isStyleRedirect = redirect.style ?? true; + type Resolver = GetAsyncFunctionFromUnion< + ReturnType> + >; + let resolver: Resolver | undefined; + return { output: { externals: [ - (data: any, callback: any) => { + async (data, callback) => { + const { request, getResolve, context, contextInfo } = data; + if (!request || !getResolve || !context || !contextInfo) { + return callback(); + } + + if (!resolver) { + resolver = (await getResolve()) as Resolver; + } + // Issuer is not empty string when the module is imported by another module. // Prevent from externalizing entry modules here. - if (data.contextInfo.issuer) { + if (contextInfo.issuer) { // Node.js ECMAScript module loader does no extension searching. // Add a file extension according to autoExtension config // when data.request is a relative path and do not have an extension. // If data.request already have an extension, we replace it with new extension // This may result in a change in semantics, // user should use copy to keep origin file or use another separate entry to deal this - let request: string = data.request; + let resolvedRequest: string = request; const cssExternal = cssExternalHandler( - request, + resolvedRequest, callback, jsExtension, cssModulesAuto, @@ -993,27 +1010,39 @@ const composeBundleConfig = ( return cssExternal; } - if (request[0] === '.') { - const ext = extname(request); + if (resolvedRequest[0] === '.') { + const resolved = await resolver(context, resolvedRequest); + resolvedRequest = normalizeSlash( + path.relative(path.dirname(contextInfo.issuer), resolved), + ); + + if (resolvedRequest[0] !== '.') { + resolvedRequest = `./${resolvedRequest}`; + } + + const ext = extname(resolvedRequest); if (ext) { - if (JS_EXTENSIONS_PATTERN.test(request)) { - request = request.replace(/\.[^.]+$/, jsExtension); + if (JS_EXTENSIONS_PATTERN.test(resolvedRequest)) { + resolvedRequest = resolvedRequest.replace( + /\.[^.]+$/, + jsExtension, + ); } else { // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png return callback(); } } else { // TODO: add redirect.extension option - request = `${request}${jsExtension}`; + resolvedRequest = `${resolvedRequest}${jsExtension}`; } } - return callback(null, request); + return callback(undefined, resolvedRequest); } callback(); }, - ], + ] as Rspack.ExternalItem[], }, }; }; diff --git a/packages/core/src/css/cssConfig.ts b/packages/core/src/css/cssConfig.ts index 1a6dca064..b5e6ab94f 100644 --- a/packages/core/src/css/cssConfig.ts +++ b/packages/core/src/css/cssConfig.ts @@ -77,7 +77,7 @@ export function isCssGlobalFile( return !isCssModules; } -type ExternalCallback = (arg0?: null, arg1?: string) => void; +type ExternalCallback = (arg0?: undefined, arg1?: string) => void; export function cssExternalHandler( request: string, @@ -99,12 +99,12 @@ export function cssExternalHandler( if (request[0] === '.' && isCssFile(request)) { // preserve import './CounterButton.module.scss' if (!isStyleRedirect) { - return callback(null, request); + return callback(undefined, request); } if (isCssModulesRequest) { - return callback(null, request.replace(/\.[^.]+$/, jsExtension)); + return callback(undefined, request.replace(/\.[^.]+$/, jsExtension)); } - return callback(null, request.replace(/\.[^.]+$/, '.css')); + return callback(undefined, request.replace(/\.[^.]+$/, '.css')); } return false; diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts index 77e0b962c..ac9b0bb8f 100644 --- a/packages/core/src/types/utils.ts +++ b/packages/core/src/types/utils.ts @@ -12,3 +12,9 @@ export type DeepRequired = Required<{ }>; export type ExcludesFalse = (x: T | false | undefined | null) => x is T; + +export type GetAsyncFunctionFromUnion = T extends ( + ...args: any[] +) => Promise + ? T + : never; diff --git a/packages/core/src/utils/helper.ts b/packages/core/src/utils/helper.ts index 0fefa76a1..302ddbc93 100644 --- a/packages/core/src/utils/helper.ts +++ b/packages/core/src/utils/helper.ts @@ -241,3 +241,8 @@ export const isIntermediateOutputFormat = (format: Format): boolean => { }; export { color }; + +const windowsSlashRegex = /\\/g; +export function normalizeSlash(p: string): string { + return p.replace(windowsSlashRegex, '/'); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 526b09bbe..c8e19e4c3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,7 @@ settings: excludeLinksFromLockfile: false overrides: + '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 zx>@types/node: '-' importers: @@ -87,8 +88,21 @@ importers: version: 19.0.0(react@19.0.0) devDependencies: '@module-federation/rsbuild-plugin': +<<<<<<< HEAD specifier: ^0.8.4 version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= + specifier: ^0.8.1 +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -108,14 +122,42 @@ importers: examples/module-federation/mf-react-component: devDependencies: '@module-federation/enhanced': +<<<<<<< HEAD specifier: ^0.8.4 version: 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= + specifier: ^0.8.1 +<<<<<<< HEAD + version: 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= +<<<<<<< HEAD + version: 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@module-federation/rsbuild-plugin': specifier: ^0.8.4 version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@module-federation/storybook-addon': +<<<<<<< HEAD specifier: ^3.0.15 version: 3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) +======= + specifier: ^3.0.12 +<<<<<<< HEAD + version: 3.0.12(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) +======= + version: 3.0.12(@rsbuild/core@1.1.9)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) +======= + version: 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/rsbuild-plugin': + specifier: ^0.8.1 + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) + '@module-federation/storybook-addon': + specifier: ^3.0.12 + version: 3.0.12(@rsbuild/core@1.1.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@rsbuild/plugin-react': specifier: ^1.1.0 version: 1.1.0(@rsbuild/core@1.1.10) @@ -154,8 +196,21 @@ importers: version: 19.0.0(react@19.0.0) devDependencies: '@module-federation/rsbuild-plugin': +<<<<<<< HEAD specifier: ^0.8.4 version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= + specifier: ^0.8.1 +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -391,8 +446,21 @@ importers: specifier: ^4.0.0 version: 4.0.0(vite@5.3.3(@types/node@22.8.1)(terser@5.31.6))(vitest@2.1.8(@types/node@22.8.1)(terser@5.31.6)) '@module-federation/rsbuild-plugin': +<<<<<<< HEAD specifier: ^0.8.4 version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= + specifier: ^0.8.1 +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) +======= +<<<<<<< HEAD + version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@playwright/test': specifier: 1.49.1 version: 1.49.1 @@ -489,12 +557,16 @@ importers: tests/integration/auto-extension/type-commonjs/false: {} + tests/integration/auto-extension/type-commonjs/false-bundleless: {} + tests/integration/auto-extension/type-module/config-override: {} tests/integration/auto-extension/type-module/default: {} tests/integration/auto-extension/type-module/false: {} + tests/integration/auto-extension/type-module/false-bundleless: {} + tests/integration/auto-external/default: dependencies: ora: @@ -1590,7 +1662,7 @@ packages: '@module-federation/rspack@0.8.4': resolution: {integrity: sha512-fx5u+xTdVQ4EMD6yPZwdt85eORwZtkBPJtr00qvl45LDDxbF9JiII3Ii9afyYtnwAlVSPgeKx4nSICoNuHXP1A==} peerDependencies: - '@rspack/core': '>=0.7' + '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 typescript: ^4.9.0 || ^5.0.0 vue-tsc: '>=1.0.24' peerDependenciesMeta: @@ -1916,6 +1988,7 @@ packages: typescript: optional: true +<<<<<<< HEAD '@rspack/binding-darwin-arm64@1.1.6': resolution: {integrity: sha512-x9dxm2yyiMuL1FBwvWNNMs2/mEUJmRoSRgYb8pblR7HDaTRORrjBFCqhaYlGyAqtQaeUy7o2VAQlE0BavIiFYA==} cpu: [arm64] @@ -1966,6 +2039,58 @@ packages: '@rspack/core@1.1.6': resolution: {integrity: sha512-q0VLphOF5VW2FEG7Vbdq3Ke4I74FbELE/8xmKghSalFtULLZ44SoSz8lyotfMim9GXIRFhDokAaH8WICmPxG+g==} +======= + '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-vwonCXADq2TzpPcgQvZBgMq420VyLvVkYZjlaXm8jofntPHqFwNr0gjAh05S0kUVdePkkAxL64fG4fd91GbSJg==} + + '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-XVy8bM182HJWVEWCwpd5xzhMO3FXFJg9U/gfjjvKlZ1LpZps3Oe5gtdtAp6GC+3gN90o+NfBiEKyGKBDGhh0IQ==} + cpu: [arm64] + os: [darwin] + + '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-xRSLjZX9FvmZSz5QzPs3nZH/S0LkbrO3sXWFK+FauJHzELHQQdilzMP6jpiMaVBbOF6qUNGuPKzDml89HNPfLg==} + cpu: [x64] + os: [darwin] + + '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-JLLdSQ7YSKtzwGTvBc/WPIpCItLe9G38aC3zfLNVrg1CTenwOtRQIP/raL246uH2OI3NMZ1gmW7VE7B/omOBXg==} + cpu: [arm64] + os: [linux] + + '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-sgFq/SdC64S2u1dPbPMpnytgr9TWcDZXutFn9eLSGltH11dbulVhGLDN6IBNP//GANlAkfW077zfxSrgjhZr7A==} + cpu: [arm64] + os: [linux] + + '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-++c+hcxNgyL6x561043XemfSRUKjqRJQ8gLvt0dhdPYVfBdz7tC4S+wrxRyGSWPCoOuPNAz2JYby/G4SK+0FiQ==} + cpu: [x64] + os: [linux] + + '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-tk5O4ANmvhdOD2fWEH/gDlQO6PAMkGwaXiNG7OPfA59ZesPJ2b6IkYzRr0K5UsUGVBR0/ZJGrLd9ugRDLaxzyw==} + cpu: [x64] + os: [linux] + + '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-ubJmhOYkxJmYfZ7nhifMQuKzmTrzjuhyJbLdnw9v9LdTgY9qkPvHoPBv7cI0LU0fj7DNfSlBW4ffLTY43qEhtQ==} + cpu: [arm64] + os: [win32] + + '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-JJPyGdr4CrH6XIbF4fPSYL/hup6Cx+aGlsuCFdKqS3nrnTKmETFLf6A6q5FzZExYwdRCdA+yjpaBhdHzEYQQ4w==} + cpu: [ia32] + os: [win32] + + '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-ik9bHH1T1W5UgKvxqt12nQQg+lllrxMn1HUbGBINz/zsjEIycxwqCvoAIazCj4JLYyDntpxPNLFULwId/yx8UQ==} + cpu: [x64] + os: [win32] + + '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-OwWxxVd9TnWaBnug2SAGmyl7VNR3MVGCwstXXhTAUCh0UTX/lQjmIKERm/tcHQyD04bOCeb+VXoj9qZT3PRbrg==} +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -7265,6 +7390,7 @@ snapshots: - supports-color - utf-8-validate +<<<<<<< HEAD '@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.4 @@ -7275,6 +7401,30 @@ snapshots: '@module-federation/rspack': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 +======= +<<<<<<< HEAD + '@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': +======= +<<<<<<< HEAD + '@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': +======= + '@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) + dependencies: + '@module-federation/bridge-react-webpack-plugin': 0.8.1 + '@module-federation/data-prefetch': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + '@module-federation/dts-plugin': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) + '@module-federation/managers': 0.8.1 + '@module-federation/manifest': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) +<<<<<<< HEAD + '@module-federation/rspack': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) +======= + '@module-federation/rspack': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) + '@module-federation/runtime-tools': 0.8.1 + '@module-federation/sdk': 0.8.1 +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) btoa: 1.2.1 upath: 2.0.1 optionalDependencies: @@ -7313,6 +7463,7 @@ snapshots: - utf-8-validate - vue-tsc +<<<<<<< HEAD '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': dependencies: '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) @@ -7327,7 +7478,42 @@ snapshots: '@module-federation/manifest': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 +======= +<<<<<<< HEAD + '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': + dependencies: + '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= +<<<<<<< HEAD + '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9)': + dependencies: + '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= + '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8)': + dependencies: + '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) + '@module-federation/sdk': 0.8.1 + '@rsbuild/core': 1.1.10 + +<<<<<<< HEAD + '@module-federation/rspack@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': +======= + '@module-federation/rspack@0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) + dependencies: + '@module-federation/bridge-react-webpack-plugin': 0.8.1 + '@module-federation/dts-plugin': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) + '@module-federation/managers': 0.8.1 + '@module-federation/manifest': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) + '@module-federation/runtime-tools': 0.8.1 + '@module-federation/sdk': 0.8.1 +<<<<<<< HEAD +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) '@rspack/core': 1.1.6(@swc/helpers@0.5.15) +======= +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) optionalDependencies: typescript: 5.6.3 vue-tsc: 2.1.10(typescript@5.6.3) @@ -7362,10 +7548,29 @@ snapshots: dependencies: isomorphic-rslog: 0.0.6 +<<<<<<< HEAD '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': dependencies: '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 +======= +<<<<<<< HEAD + '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + dependencies: + '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= +<<<<<<< HEAD + '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.9)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + dependencies: + '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +======= + '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + dependencies: + '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +>>>>>>> 91ab67b (fix(externals): use resolver to resolve request) +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) + '@module-federation/sdk': 0.8.1 +>>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) optionalDependencies: '@rsbuild/core': 1.1.10 webpack: 5.96.1 @@ -7522,7 +7727,11 @@ snapshots: '@rsbuild/core@1.1.10': dependencies: +<<<<<<< HEAD '@rspack/core': 1.1.6(@swc/helpers@0.5.15) +======= + '@rspack/core': '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)' +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) '@rspack/lite-tapable': 1.0.1 '@swc/helpers': 0.5.15 core-js: 3.39.0 @@ -7647,6 +7856,7 @@ snapshots: '@microsoft/api-extractor': 7.48.1(@types/node@22.8.1) typescript: 5.6.3 +<<<<<<< HEAD '@rspack/binding-darwin-arm64@1.1.6': optional: true @@ -7690,6 +7900,51 @@ snapshots: dependencies: '@module-federation/runtime-tools': 0.5.1 '@rspack/binding': 1.1.6 +======= + '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': + optionalDependencies: + '@rspack/binding-darwin-arm64': '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-darwin-x64': '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-linux-arm64-gnu': '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-linux-arm64-musl': '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-linux-x64-gnu': '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-linux-x64-musl': '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-win32-arm64-msvc': '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-win32-ia32-msvc': '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding-win32-x64-msvc': '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' + + '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + optional: true + + '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)': + dependencies: + '@module-federation/runtime-tools': 0.5.1 + '@rspack/binding': '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520' +>>>>>>> a43e933 (fix(externals): use resolver to resolve request) '@rspack/lite-tapable': 1.0.1 caniuse-lite: 1.0.30001680 optionalDependencies: diff --git a/tests/integration/auto-extension/__fixtures__/src/common.ts b/tests/integration/auto-extension/__fixtures__/src/common.ts deleted file mode 100644 index cc798ff50..000000000 --- a/tests/integration/auto-extension/__fixtures__/src/common.ts +++ /dev/null @@ -1 +0,0 @@ -export const a = 1; diff --git a/tests/integration/auto-extension/__fixtures__/src/foo.ts b/tests/integration/auto-extension/__fixtures__/src/foo.ts new file mode 100644 index 000000000..3329a7d97 --- /dev/null +++ b/tests/integration/auto-extension/__fixtures__/src/foo.ts @@ -0,0 +1 @@ +export const foo = 'foo'; diff --git a/tests/integration/auto-extension/__fixtures__/src/index.ts b/tests/integration/auto-extension/__fixtures__/src/index.ts index b5f5ad8ce..d75e8c5fb 100644 --- a/tests/integration/auto-extension/__fixtures__/src/index.ts +++ b/tests/integration/auto-extension/__fixtures__/src/index.ts @@ -1,3 +1,2 @@ -import { a } from './common'; - -console.log(a); +export { foo } from './foo'; +export * from './utils'; diff --git a/tests/integration/auto-extension/__fixtures__/src/utils/index.ts b/tests/integration/auto-extension/__fixtures__/src/utils/index.ts new file mode 100644 index 000000000..9f1738685 --- /dev/null +++ b/tests/integration/auto-extension/__fixtures__/src/utils/index.ts @@ -0,0 +1 @@ +export const bar = 'bar'; diff --git a/tests/integration/auto-extension/index.test.ts b/tests/integration/auto-extension/index.test.ts index fd617a583..e4e772dcb 100644 --- a/tests/integration/auto-extension/index.test.ts +++ b/tests/integration/auto-extension/index.test.ts @@ -1,5 +1,5 @@ import { extname, join } from 'node:path'; -import { buildAndGetResults } from 'test-helper'; +import { buildAndGetResults, queryContent } from 'test-helper'; import { describe, expect, test } from 'vitest'; describe('autoExtension: true', () => { @@ -40,7 +40,7 @@ describe('should respect output.filename.js to override builtin logic', () => { const { entryFiles } = await buildAndGetResults({ fixturePath }); expect(extname(entryFiles.esm!)).toEqual('.mjs'); expect(entryFiles.cjs).toMatchInlineSnapshot( - `"/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.15d386b8.js"`, + `"/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.18bec1db.js"`, ); }); @@ -48,8 +48,40 @@ describe('should respect output.filename.js to override builtin logic', () => { const fixturePath = join(__dirname, 'type-module', 'config-override'); const { entryFiles } = await buildAndGetResults({ fixturePath }); expect(entryFiles.esm).toMatchInlineSnapshot( - `"/tests/integration/auto-extension/type-module/config-override/dist/esm/index.d2068839.js"`, + `"/tests/integration/auto-extension/type-module/config-override/dist/esm/index.996a7edd.js"`, ); expect(extname(entryFiles.cjs!)).toEqual('.cjs'); }); }); + +describe('ESM output should add main files automatically', () => { + test('type is commonjs', async () => { + const fixturePath = join(__dirname, 'type-commonjs', 'false-bundleless'); + const { contents } = await buildAndGetResults({ fixturePath }); + const { path: indexFile } = queryContent(contents.esm, 'index.js', { + basename: true, + }); + + expect(await import(indexFile)).toMatchInlineSnapshot(` + { + "bar": "bar", + "foo": "foo", + } + `); + }); + + test('type is module', async () => { + const fixturePath = join(__dirname, 'type-module', 'false-bundleless'); + const { contents } = await buildAndGetResults({ fixturePath }); + const { path: indexFile } = queryContent(contents.esm, 'index.js', { + basename: true, + }); + + expect(await import(indexFile)).toMatchInlineSnapshot(` + { + "bar": "bar", + "foo": "foo", + } + `); + }); +}); diff --git a/tests/integration/auto-extension/type-commonjs/config-override/package.json b/tests/integration/auto-extension/type-commonjs/config-override/package.json index 0e8db2f59..cc3760a0b 100644 --- a/tests/integration/auto-extension/type-commonjs/config-override/package.json +++ b/tests/integration/auto-extension/type-commonjs/config-override/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-config-override-commonjs-test", + "name": "auto-extension-commonjs-config-override-test", "version": "1.0.0", "private": true } diff --git a/tests/integration/auto-extension/type-commonjs/default/package.json b/tests/integration/auto-extension/type-commonjs/default/package.json index 4560b004e..1d447bb38 100644 --- a/tests/integration/auto-extension/type-commonjs/default/package.json +++ b/tests/integration/auto-extension/type-commonjs/default/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-commonjs-test", + "name": "auto-extension-commonjs-default-test", "version": "1.0.0", "private": true } diff --git a/tests/integration/auto-extension/type-commonjs/false-bundleless/package.json b/tests/integration/auto-extension/type-commonjs/false-bundleless/package.json new file mode 100644 index 000000000..a940c8d46 --- /dev/null +++ b/tests/integration/auto-extension/type-commonjs/false-bundleless/package.json @@ -0,0 +1,6 @@ +{ + "name": "auto-extension-commonjs-false-bundleless-test", + "version": "1.0.0", + "private": true, + "type": "module" +} diff --git a/tests/integration/auto-extension/type-commonjs/false-bundleless/rslib.config.ts b/tests/integration/auto-extension/type-commonjs/false-bundleless/rslib.config.ts new file mode 100644 index 000000000..ffe22d8af --- /dev/null +++ b/tests/integration/auto-extension/type-commonjs/false-bundleless/rslib.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig({ + bundle: false, + autoExtension: false, + }), + generateBundleCjsConfig({ + bundle: false, + autoExtension: false, + }), + ], + source: { + entry: { + index: '../../__fixtures__/src', + }, + }, +}); diff --git a/tests/integration/auto-extension/type-commonjs/false/package.json b/tests/integration/auto-extension/type-commonjs/false/package.json index 7e90e60e9..99a8c4cef 100644 --- a/tests/integration/auto-extension/type-commonjs/false/package.json +++ b/tests/integration/auto-extension/type-commonjs/false/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-false-commonjs-test", + "name": "auto-extension-commonjs-false--test", "version": "1.0.0", "private": true } diff --git a/tests/integration/auto-extension/type-module/config-override/package.json b/tests/integration/auto-extension/type-module/config-override/package.json index 778081e6d..4f1ddd497 100644 --- a/tests/integration/auto-extension/type-module/config-override/package.json +++ b/tests/integration/auto-extension/type-module/config-override/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-config-override-module-test", + "name": "auto-extension-module-config-override-test", "version": "1.0.0", "private": true, "type": "module" diff --git a/tests/integration/auto-extension/type-module/default/package.json b/tests/integration/auto-extension/type-module/default/package.json index 3836bd261..1f060b22c 100644 --- a/tests/integration/auto-extension/type-module/default/package.json +++ b/tests/integration/auto-extension/type-module/default/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-module-test", + "name": "auto-extension-module-default-test", "version": "1.0.0", "private": true, "type": "module" diff --git a/tests/integration/auto-extension/type-module/false-bundleless/package.json b/tests/integration/auto-extension/type-module/false-bundleless/package.json new file mode 100644 index 000000000..df0fea149 --- /dev/null +++ b/tests/integration/auto-extension/type-module/false-bundleless/package.json @@ -0,0 +1,6 @@ +{ + "name": "auto-extension-module-false-bundleless-test", + "version": "1.0.0", + "private": true, + "type": "module" +} diff --git a/tests/integration/auto-extension/type-module/false-bundleless/rslib.config.ts b/tests/integration/auto-extension/type-module/false-bundleless/rslib.config.ts new file mode 100644 index 000000000..ffe22d8af --- /dev/null +++ b/tests/integration/auto-extension/type-module/false-bundleless/rslib.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + generateBundleEsmConfig({ + bundle: false, + autoExtension: false, + }), + generateBundleCjsConfig({ + bundle: false, + autoExtension: false, + }), + ], + source: { + entry: { + index: '../../__fixtures__/src', + }, + }, +}); diff --git a/tests/integration/auto-extension/type-module/false/package.json b/tests/integration/auto-extension/type-module/false/package.json index 5a33607e1..430ef9188 100644 --- a/tests/integration/auto-extension/type-module/false/package.json +++ b/tests/integration/auto-extension/type-module/false/package.json @@ -1,5 +1,5 @@ { - "name": "auto-extension-false-module-test", + "name": "auto-extension-module-false-test", "version": "1.0.0", "private": true, "type": "module" diff --git a/tests/integration/bundle-false/basic/src/index.ts b/tests/integration/bundle-false/basic/src/index.ts index 6eb6b6fb1..e218fd0f6 100644 --- a/tests/integration/bundle-false/basic/src/index.ts +++ b/tests/integration/bundle-false/basic/src/index.ts @@ -1,3 +1,7 @@ +import { mainFiles1 } from './mainFiles1'; +export { mainFiles1 }; + +export * from './mainFiles2'; export * from './utils/numbers'; export * from './utils/strings'; export * from './sum'; diff --git a/tests/integration/bundle-false/basic/src/mainFiles1/index.ts b/tests/integration/bundle-false/basic/src/mainFiles1/index.ts new file mode 100644 index 000000000..a7880c8da --- /dev/null +++ b/tests/integration/bundle-false/basic/src/mainFiles1/index.ts @@ -0,0 +1 @@ +export const mainFiles1 = 'mainFiles1'; diff --git a/tests/integration/bundle-false/basic/src/mainFiles2/index.ts b/tests/integration/bundle-false/basic/src/mainFiles2/index.ts new file mode 100644 index 000000000..8ccac37a3 --- /dev/null +++ b/tests/integration/bundle-false/basic/src/mainFiles2/index.ts @@ -0,0 +1 @@ +export const mainFiles2 = 'mainFiles2'; diff --git a/tests/integration/bundle-false/index.test.ts b/tests/integration/bundle-false/index.test.ts index 26af6c519..c216309ce 100644 --- a/tests/integration/bundle-false/index.test.ts +++ b/tests/integration/bundle-false/index.test.ts @@ -1,27 +1,70 @@ import { join } from 'node:path'; -import { buildAndGetResults } from 'test-helper'; +import { buildAndGetResults, queryContent } from 'test-helper'; import { expect, test } from 'vitest'; test('basic', async () => { const fixturePath = join(__dirname, 'basic'); - const { files } = await buildAndGetResults({ fixturePath }); + const { files, contents } = await buildAndGetResults({ fixturePath }); expect(files.esm).toMatchInlineSnapshot(` [ "/tests/integration/bundle-false/basic/dist/esm/index.js", + "/tests/integration/bundle-false/basic/dist/esm/mainFiles1/index.js", + "/tests/integration/bundle-false/basic/dist/esm/mainFiles2/index.js", "/tests/integration/bundle-false/basic/dist/esm/sum.js", "/tests/integration/bundle-false/basic/dist/esm/utils/numbers.js", "/tests/integration/bundle-false/basic/dist/esm/utils/strings.js", ] `); + + const { path: esmIndexPath } = queryContent(contents.esm, 'index.js', { + basename: true, + }); + + expect(await import(esmIndexPath)).toMatchInlineSnapshot(` + { + "mainFiles1": "mainFiles1", + "mainFiles2": "mainFiles2", + "num1": 1, + "num2": 2, + "num3": 3, + "numSum": 6, + "str1": "str1", + "str2": "str2", + "str3": "str3", + "strSum": "str1str2str3", + } + `); + expect(files.cjs).toMatchInlineSnapshot(` [ "/tests/integration/bundle-false/basic/dist/cjs/index.cjs", + "/tests/integration/bundle-false/basic/dist/cjs/mainFiles1/index.cjs", + "/tests/integration/bundle-false/basic/dist/cjs/mainFiles2/index.cjs", "/tests/integration/bundle-false/basic/dist/cjs/sum.cjs", "/tests/integration/bundle-false/basic/dist/cjs/utils/numbers.cjs", "/tests/integration/bundle-false/basic/dist/cjs/utils/strings.cjs", ] `); + + const { path: cjsIndexPath } = queryContent(contents.cjs, 'index.cjs', { + basename: true, + }); + + expect((await import(cjsIndexPath)).default).toMatchInlineSnapshot(` + { + "mainFiles1": "mainFiles1", + "mainFiles2": "mainFiles2", + "num1": 1, + "num2": 2, + "num3": 3, + "numSum": 6, + "str1": "str1", + "str2": "str2", + "str3": "str3", + "strSum": "str1str2str3", + } + `); }); test('single file', async () => { @@ -47,7 +90,7 @@ test('auto add js extension for relative import', async () => { // basic esm for (const importer of [ 'import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js";', - 'import * as __WEBPACK_EXTERNAL_MODULE__baz_js__ from "./baz.js";', + 'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_js__ from "./baz.js.js";', 'import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js";', 'import * as __WEBPACK_EXTERNAL_MODULE__qux_js__ from "./qux.js";', ]) { @@ -57,7 +100,7 @@ test('auto add js extension for relative import', async () => { // basic cjs for (const requirer of [ 'const external_bar_cjs_namespaceObject = require("./bar.cjs");', - 'const external_baz_cjs_namespaceObject = require("./baz.cjs");', + 'const external_baz_js_cjs_namespaceObject = require("./baz.js.cjs");', 'const external_foo_cjs_namespaceObject = require("./foo.cjs");', 'const external_qux_cjs_namespaceObject = require("./qux.cjs");', ]) { @@ -67,7 +110,7 @@ test('auto add js extension for relative import', async () => { // using `autoExtension: false` along with `output.filename.js` - esm for (const importer of [ 'import * as __WEBPACK_EXTERNAL_MODULE__bar_mjs__ from "./bar.mjs";', - 'import * as __WEBPACK_EXTERNAL_MODULE__baz_mjs__ from "./baz.mjs";', + 'import * as __WEBPACK_EXTERNAL_MODULE__baz_js_mjs__ from "./baz.js.mjs";', 'import * as __WEBPACK_EXTERNAL_MODULE__foo_mjs__ from "./foo.mjs";', 'import * as __WEBPACK_EXTERNAL_MODULE__qux_mjs__ from "./qux.mjs";', ]) { @@ -77,7 +120,7 @@ test('auto add js extension for relative import', async () => { // using `autoExtension: false` along with `output.filename.js` - cjs for (const requirer of [ 'const external_bar_cjs_namespaceObject = require("./bar.cjs");', - 'const external_baz_cjs_namespaceObject = require("./baz.cjs");', + 'const external_baz_js_cjs_namespaceObject = require("./baz.js.cjs");', 'const external_foo_cjs_namespaceObject = require("./foo.cjs");', 'const external_qux_cjs_namespaceObject = require("./qux.cjs");', ]) { diff --git a/tests/integration/directive/index.test.ts b/tests/integration/directive/index.test.ts index d950abe85..510a7b56b 100644 --- a/tests/integration/directive/index.test.ts +++ b/tests/integration/directive/index.test.ts @@ -24,40 +24,46 @@ describe('shebang', async () => { describe('bundle-false', async () => { test('shebang at the beginning', async () => { - const index = queryContent(contents.esm2!, 'index.js', { + const { content: index } = queryContent(contents.esm2!, 'index.js', { basename: true, }); expect(index!.startsWith('#!/usr/bin/env node')).toBe(true); - const bar = queryContent(contents.esm2!, 'bar.js', { basename: true }); + const { content: bar } = queryContent(contents.esm2!, 'bar.js', { + basename: true, + }); expect(bar!.startsWith('#!/usr/bin/env node')).toBe(true); - const foo = queryContent(contents.esm2!, 'foo.js', { basename: true }); + const { content: foo } = queryContent(contents.esm2!, 'foo.js', { + basename: true, + }); expect(foo!.includes('#!')).toBe(false); }); test('shebang at the beginning even if minified', async () => { - const index = queryContent(contents.esm3!, 'index.js', { + const { content: index } = queryContent(contents.esm3!, 'index.js', { basename: true, }); expect(index!.startsWith('#!/usr/bin/env node')).toBe(true); - const bar = queryContent(contents.esm3!, 'bar.js', { + const { content: bar } = queryContent(contents.esm3!, 'bar.js', { basename: true, }); expect(bar!.startsWith('#!/usr/bin/env node')).toBe(true); - const foo = queryContent(contents.esm2!, 'foo.js', { basename: true }); + const { content: foo } = queryContent(contents.esm2!, 'foo.js', { + basename: true, + }); expect(foo!.includes('#!')).toBe(false); }); test.todo('shebang commented by JS parser should be striped', async () => { - const index = queryContent(contents.esm3!, 'index.js', { + const { content: index } = queryContent(contents.esm3!, 'index.js', { basename: true, }); expect(index!.includes('//#!')).toBe(false); - const bar = queryContent(contents.esm3!, 'bar.js', { + const { content: bar } = queryContent(contents.esm3!, 'bar.js', { basename: true, }); expect(bar!.includes('//#!')).toBe(false); @@ -87,18 +93,26 @@ describe('react', async () => { describe('bundle-false', async () => { test('React directive at the beginning', async () => { - const foo = queryContent(contents.esm0!, 'foo.js', { basename: true }); + const { content: foo } = queryContent(contents.esm0!, 'foo.js', { + basename: true, + }); expect(foo!.startsWith(`'use client';`)).toBe(true); - const bar = queryContent(contents.esm0!, 'bar.js', { basename: true }); + const { content: bar } = queryContent(contents.esm0!, 'bar.js', { + basename: true, + }); expect(bar!.startsWith(`'use server';`)).toBe(true); }); test('React directive at the beginning even if minified', async () => { - const foo = queryContent(contents.esm1!, 'foo.js', { basename: true }); + const { content: foo } = queryContent(contents.esm1!, 'foo.js', { + basename: true, + }); expect(foo!.startsWith(`'use client';`)).toBe(true); - const bar = queryContent(contents.esm1!, 'bar.js', { basename: true }); + const { content: bar } = queryContent(contents.esm1!, 'bar.js', { + basename: true, + }); expect(bar!.startsWith(`'use server';`)).toBe(true); }); }); diff --git a/tests/integration/entry/index.test.ts b/tests/integration/entry/index.test.ts index 238746e0a..db2a45288 100644 --- a/tests/integration/entry/index.test.ts +++ b/tests/integration/entry/index.test.ts @@ -39,7 +39,9 @@ test('multiple entry bundle', async () => { } `); - const index = queryContent(contents.esm, 'index.js', { basename: true }); + const { content: index } = queryContent(contents.esm, 'index.js', { + basename: true, + }); expect(index).toMatchInlineSnapshot(` "const shared = 'shared'; const foo = 'foo' + shared; @@ -48,7 +50,9 @@ test('multiple entry bundle', async () => { " `); - const foo = queryContent(contents.esm, 'foo.js', { basename: true }); + const { content: foo } = queryContent(contents.esm, 'foo.js', { + basename: true, + }); expect(foo).toMatchInlineSnapshot(` "const shared = 'shared'; const foo = 'foo' + shared; @@ -56,14 +60,18 @@ test('multiple entry bundle', async () => { " `); - const bar = queryContent(contents.esm, 'bar.js', { basename: true }); + const { content: bar } = queryContent(contents.esm, 'bar.js', { + basename: true, + }); expect(bar).toMatchInlineSnapshot(` "const bar = 'bar'; export { bar }; " `); - const shared = queryContent(contents.esm, 'shared.js', { basename: true }); + const { content: shared } = queryContent(contents.esm, 'shared.js', { + basename: true, + }); expect(shared).toMatchInlineSnapshot(` "const shared = 'shared'; export { shared }; diff --git a/tests/scripts/shared.ts b/tests/scripts/shared.ts index 31a60cfbd..07ca4d101 100644 --- a/tests/scripts/shared.ts +++ b/tests/scripts/shared.ts @@ -327,7 +327,7 @@ export function queryContent( options: { basename?: boolean; } = {}, -): string | null { +): { path: string; content: string } { const useBasename = options?.basename ?? false; const matched = Object.entries(contents).find(([key]) => { const toQueried = useBasename ? basename(key) : key; @@ -337,10 +337,10 @@ export function queryContent( }); if (!matched) { - return null; + throw new Error(`Cannot find content for ${query}`); } - return matched[1]; + return { path: matched[0], content: matched[1] }; } export async function createTempFiles( From 8269288912f00acbb27661bfc5e2230be5f08d04 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Wed, 11 Dec 2024 18:50:25 +0800 Subject: [PATCH 02/13] js redirect --- packages/core/src/config.ts | 162 ++++++++++-------- .../src/types/{config/index.ts => config.ts} | 27 ++- .../tests/__snapshots__/config.test.ts.snap | 12 +- pnpm-lock.yaml | 69 +++++++- scripts/dictionary.txt | 1 + .../redirect/__fixtures__/src/bar/index.ts | 3 + .../redirect/__fixtures__/src/constant.ts | 1 + .../redirect/__fixtures__/src/foo.ts | 1 + .../redirect/__fixtures__/src/index.ts | 10 ++ tests/integration/redirect/js/index.test.ts | 81 +++++++++ tests/integration/redirect/js/package.json | 13 ++ tests/integration/redirect/js/rslib.config.ts | 110 ++++++++++++ .../integration/redirect/js/src/bar/index.ts | 3 + tests/integration/redirect/js/src/constant.ts | 1 + tests/integration/redirect/js/src/foo.ts | 1 + tests/integration/redirect/js/src/index.ts | 8 + .../redirect/js/src/others/bar/index.ts | 3 + .../redirect/js/src/others/constant.ts | 1 + .../integration/redirect/js/src/others/foo.ts | 1 + tests/integration/redirect/js/tsconfig.json | 10 ++ .../style-false}/index.test.ts | 4 +- .../style-false}/package.json | 2 +- .../style-false}/rslib.config.ts | 0 .../style-false}/src/index.less | 0 .../style-false}/src/index.ts | 0 .../style-false}/src/style.module.less | 0 website/docs/en/config/lib/redirect.mdx | 32 ++++ 27 files changed, 478 insertions(+), 78 deletions(-) rename packages/core/src/types/{config/index.ts => config.ts} (88%) create mode 100644 tests/integration/redirect/__fixtures__/src/bar/index.ts create mode 100644 tests/integration/redirect/__fixtures__/src/constant.ts create mode 100644 tests/integration/redirect/__fixtures__/src/foo.ts create mode 100644 tests/integration/redirect/__fixtures__/src/index.ts create mode 100644 tests/integration/redirect/js/index.test.ts create mode 100644 tests/integration/redirect/js/package.json create mode 100644 tests/integration/redirect/js/rslib.config.ts create mode 100644 tests/integration/redirect/js/src/bar/index.ts create mode 100644 tests/integration/redirect/js/src/constant.ts create mode 100644 tests/integration/redirect/js/src/foo.ts create mode 100644 tests/integration/redirect/js/src/index.ts create mode 100644 tests/integration/redirect/js/src/others/bar/index.ts create mode 100644 tests/integration/redirect/js/src/others/constant.ts create mode 100644 tests/integration/redirect/js/src/others/foo.ts create mode 100644 tests/integration/redirect/js/tsconfig.json rename tests/integration/{style/redirect-style-false => redirect/style-false}/index.test.ts (82%) rename tests/integration/{style/redirect-style-false => redirect/style-false}/package.json (53%) rename tests/integration/{style/redirect-style-false => redirect/style-false}/rslib.config.ts (100%) rename tests/integration/{style/redirect-style-false => redirect/style-false}/src/index.less (100%) rename tests/integration/{style/redirect-style-false => redirect/style-false}/src/index.ts (100%) rename tests/integration/{style/redirect-style-false => redirect/style-false}/src/style.module.less (100%) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index a2fc849a1..0a5ecefac 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -40,6 +40,7 @@ import type { ExcludesFalse, Format, GetAsyncFunctionFromUnion, + JsRedirect, LibConfig, LibOnlyConfig, PkgJson, @@ -959,15 +960,20 @@ const composeEntryConfig = async ( }; }; -const composeBundleConfig = ( +const composeBundlelessExternalConfig = ( jsExtension: string, redirect: Redirect, cssModulesAuto: CssLoaderOptionsAuto, bundle: boolean, -): RsbuildConfig => { - if (bundle) return {}; +): { + config: RsbuildConfig; + resolvedJsRedirect?: DeepRequired; +} => { + if (bundle) return { config: {} }; - const isStyleRedirect = redirect.style ?? true; + const doesRedirectStyle = redirect.style ?? true; + const jsRedirectPath = redirect.js?.path ?? true; + const jsRedirectExtension = redirect.js?.extension ?? true; type Resolver = GetAsyncFunctionFromUnion< ReturnType> @@ -975,74 +981,91 @@ const composeBundleConfig = ( let resolver: Resolver | undefined; return { - output: { - externals: [ - async (data, callback) => { - const { request, getResolve, context, contextInfo } = data; - if (!request || !getResolve || !context || !contextInfo) { - return callback(); - } - - if (!resolver) { - resolver = (await getResolve()) as Resolver; - } + resolvedJsRedirect: { + path: jsRedirectPath, + extension: jsRedirectExtension, + }, + config: { + output: { + externals: [ + async (data, callback) => { + const { request, getResolve, context, contextInfo } = data; + if (!request || !getResolve || !context || !contextInfo) { + return callback(); + } - // Issuer is not empty string when the module is imported by another module. - // Prevent from externalizing entry modules here. - if (contextInfo.issuer) { - // Node.js ECMAScript module loader does no extension searching. - // Add a file extension according to autoExtension config - // when data.request is a relative path and do not have an extension. - // If data.request already have an extension, we replace it with new extension - // This may result in a change in semantics, - // user should use copy to keep origin file or use another separate entry to deal this - let resolvedRequest: string = request; - - const cssExternal = cssExternalHandler( - resolvedRequest, - callback, - jsExtension, - cssModulesAuto, - isStyleRedirect, - ); - - if (cssExternal !== false) { - return cssExternal; + if (!resolver) { + resolver = (await getResolve()) as Resolver; } - if (resolvedRequest[0] === '.') { - const resolved = await resolver(context, resolvedRequest); - resolvedRequest = normalizeSlash( - path.relative(path.dirname(contextInfo.issuer), resolved), + // Issuer is not empty string when the module is imported by another module. + // Prevent from externalizing entry modules here. + if (contextInfo.issuer) { + let resolvedRequest: string = request; + + const cssExternal = cssExternalHandler( + resolvedRequest, + callback, + jsExtension, + cssModulesAuto, + doesRedirectStyle, ); - if (resolvedRequest[0] !== '.') { - resolvedRequest = `./${resolvedRequest}`; + if (cssExternal !== false) { + return cssExternal; } - const ext = extname(resolvedRequest); + // Node.js ECMAScript module loader does no extension searching. + // Add a file extension according to autoExtension config + // when data.request is a relative path and do not have an extension. + // If data.request already have an extension, we replace it with new extension + // This may result in a change in semantics, + // user should use copy to keep origin file or use another separate entry to deal this + + if (jsRedirectPath) { + try { + resolvedRequest = await resolver(context, resolvedRequest); + } catch (e) { + // Do nothing, fallthrough to other external matches. + } + + resolvedRequest = normalizeSlash( + path.relative( + path.dirname(contextInfo.issuer), + resolvedRequest, + ), + ); - if (ext) { - if (JS_EXTENSIONS_PATTERN.test(resolvedRequest)) { - resolvedRequest = resolvedRequest.replace( - /\.[^.]+$/, - jsExtension, - ); + if (resolvedRequest[0] !== '.') { + resolvedRequest = `./${resolvedRequest}`; + } + } + + if (jsRedirectExtension) { + const ext = extname(resolvedRequest); + if (ext) { + if (JS_EXTENSIONS_PATTERN.test(resolvedRequest)) { + resolvedRequest = resolvedRequest.replace( + /\.[^.]+$/, + jsExtension, + ); + } else { + // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png + return callback(); + } } else { - // If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png - return callback(); + // TODO: add redirect.extension option + resolvedRequest = `${resolvedRequest}${jsExtension}`; } - } else { - // TODO: add redirect.extension option - resolvedRequest = `${resolvedRequest}${jsExtension}`; } + + return callback(undefined, resolvedRequest); } - return callback(undefined, resolvedRequest); - } - callback(); - }, - ] as Rspack.ExternalItem[], + callback(); + }, + ] as Rspack.ExternalItem[], + }, }, }; }; @@ -1218,7 +1241,7 @@ async function composeLibRsbuildConfig( externalHelpers, pkgJson, ); - const externalsConfig = composeExternalsConfig( + const userExternalConfig = composeExternalsConfig( format!, config.output?.externals, ); @@ -1227,7 +1250,7 @@ async function composeLibRsbuildConfig( jsExtension, dtsExtension, } = composeAutoExtensionConfig(config, autoExtension, pkgJson); - const bundleConfig = composeBundleConfig( + const { config: bundlelessExternalConfig } = composeBundlelessExternalConfig( jsExtension, redirect, cssModulesAuto, @@ -1260,7 +1283,7 @@ async function composeLibRsbuildConfig( const externalsWarnConfig = composeExternalsWarnConfig( format!, autoExternalConfig?.output?.externals, - externalsConfig?.output?.externals, + userExternalConfig?.output?.externals, ); const minifyConfig = composeMinifyConfig(config); const bannerFooterConfig = composeBannerFooterConfig(banner, footer); @@ -1272,15 +1295,20 @@ async function composeLibRsbuildConfig( return mergeRsbuildConfig( formatConfig, shimsConfig, + syntaxConfig, externalHelpersConfig, - // externalsWarnConfig should before other externals config + autoExtensionConfig, + + // `externalsWarnConfig` should before other externals config. externalsWarnConfig, - externalsConfig, autoExternalConfig, - autoExtensionConfig, - syntaxConfig, - bundleConfig, targetConfig, + // The externals config in `bundleConfig` should present after all externals config as + // it relies on other externals config to bail out the externalized modules first then resolve + // the correct path for relative imports. + userExternalConfig, + bundlelessExternalConfig, + entryConfig, cssConfig, assetConfig, diff --git a/packages/core/src/types/config/index.ts b/packages/core/src/types/config.ts similarity index 88% rename from packages/core/src/types/config/index.ts rename to packages/core/src/types/config.ts index 1c0d7839d..dced7e635 100644 --- a/packages/core/src/types/config/index.ts +++ b/packages/core/src/types/config.ts @@ -74,12 +74,33 @@ export type Shims = { }; }; +export type JsRedirect = { + /** + * Whether to automatically redirect the import paths of JavaScript output files, + * compilerOptions.paths in tsconfig.json will be applied by default. + * @defaultValue `true` + */ + path?: boolean; + /** + * Whether to automatically add the file extension based on the JavaScript output files. + * @defaultValue `true` + */ + extension?: boolean; +}; + +// @ts-expect-error TODO: support dts redirect in the future +type DtsRedirect = { + path?: boolean; + extension?: boolean; +}; + export type Redirect = { - // TODO: support other redirects - // alias?: boolean; + /** Controls the redirect of the import paths of JavaScript output files. */ + js?: JsRedirect; style?: boolean; + // TODO: support other redirects // asset?: boolean; - // autoExtension?: boolean; + // dts?: DtsRedirect; }; export interface LibConfig extends RsbuildConfig { diff --git a/packages/core/tests/__snapshots__/config.test.ts.snap b/packages/core/tests/__snapshots__/config.test.ts.snap index 0e4cbf584..4fe3fc0ed 100644 --- a/packages/core/tests/__snapshots__/config.test.ts.snap +++ b/packages/core/tests/__snapshots__/config.test.ts.snap @@ -174,7 +174,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "experiments": { "outputModule": true, }, - "externalsType": "module-import", "module": { "parser": { "javascript": { @@ -211,6 +210,9 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "node", ], }, + { + "externalsType": "module-import", + }, { "plugins": [ EntryChunkPlugin { @@ -414,7 +416,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, }, { - "externalsType": "commonjs-import", "module": { "parser": { "javascript": { @@ -443,6 +444,9 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "node", ], }, + { + "externalsType": "commonjs-import", + }, { "plugins": [ EntryChunkPlugin { @@ -637,7 +641,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 }, }, { - "externalsType": "umd", "module": { "parser": { "javascript": { @@ -661,6 +664,9 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config 1 "node", ], }, + { + "externalsType": "umd", + }, { "plugins": [ EntryChunkPlugin { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8e19e4c3..02622b07f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -93,6 +93,7 @@ importers: version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= specifier: ^0.8.1 +<<<<<<< HEAD <<<<<<< HEAD version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= @@ -102,7 +103,13 @@ importers: version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +<<<<<<< HEAD >>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) +======= +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +>>>>>>> 06ac05a (js redirect) +>>>>>>> 059c9de (js redirect) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -127,6 +134,7 @@ importers: version: 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ======= specifier: ^0.8.1 +<<<<<<< HEAD <<<<<<< HEAD version: 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ======= @@ -157,7 +165,19 @@ importers: version: 3.0.12(@rsbuild/core@1.1.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +<<<<<<< HEAD >>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) +======= +======= + version: 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/rsbuild-plugin': + specifier: ^0.8.1 + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) + '@module-federation/storybook-addon': + specifier: ^3.0.12 + version: 3.0.12(@rsbuild/core@1.1.9)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) +>>>>>>> 06ac05a (js redirect) +>>>>>>> 059c9de (js redirect) '@rsbuild/plugin-react': specifier: ^1.1.0 version: 1.1.0(@rsbuild/core@1.1.10) @@ -201,6 +221,7 @@ importers: version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= specifier: ^0.8.1 +<<<<<<< HEAD <<<<<<< HEAD version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= @@ -210,7 +231,13 @@ importers: version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +<<<<<<< HEAD >>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) +======= +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +>>>>>>> 06ac05a (js redirect) +>>>>>>> 059c9de (js redirect) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -451,6 +478,7 @@ importers: version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= specifier: ^0.8.1 +<<<<<<< HEAD <<<<<<< HEAD version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) ======= @@ -460,7 +488,13 @@ importers: version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +<<<<<<< HEAD >>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) +======= +======= + version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) +>>>>>>> 06ac05a (js redirect) +>>>>>>> 059c9de (js redirect) '@playwright/test': specifier: 1.49.1 version: 1.49.1 @@ -785,6 +819,17 @@ importers: specifier: ^0.11.0 version: 0.11.0(@babel/core@7.26.0) + tests/integration/redirect/js: + devDependencies: + '@types/lodash': + specifier: ^4.17.13 + version: 4.17.13 + lodash: + specifier: ^4.17.21 + version: 4.17.21 + + tests/integration/redirect/style-false: {} + tests/integration/require/import-dynamic: {} tests/integration/require/require-as-expression: {} @@ -849,8 +894,6 @@ importers: specifier: 2.0.0 version: 2.0.0 - tests/integration/style/redirect-style-false: {} - tests/integration/style/sass/bundle: {} tests/integration/style/sass/bundle-false: {} @@ -7390,6 +7433,7 @@ snapshots: - supports-color - utf-8-validate +<<<<<<< HEAD <<<<<<< HEAD '@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': dependencies: @@ -7402,6 +7446,8 @@ snapshots: '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 ======= +======= +>>>>>>> 059c9de (js redirect) <<<<<<< HEAD '@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': ======= @@ -7411,6 +7457,9 @@ snapshots: '@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +======= + '@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': +>>>>>>> 06ac05a (js redirect) dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.1 '@module-federation/data-prefetch': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0) @@ -7463,6 +7512,7 @@ snapshots: - utf-8-validate - vue-tsc +<<<<<<< HEAD <<<<<<< HEAD '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': dependencies: @@ -7479,6 +7529,8 @@ snapshots: '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 ======= +======= +>>>>>>> 059c9de (js redirect) <<<<<<< HEAD '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': dependencies: @@ -7494,6 +7546,11 @@ snapshots: '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +======= + '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9)': + dependencies: + '@module-federation/enhanced': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +>>>>>>> 06ac05a (js redirect) '@module-federation/sdk': 0.8.1 '@rsbuild/core': 1.1.10 @@ -7548,12 +7605,15 @@ snapshots: dependencies: isomorphic-rslog: 0.0.6 +<<<<<<< HEAD <<<<<<< HEAD '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': dependencies: '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 ======= +======= +>>>>>>> 059c9de (js redirect) <<<<<<< HEAD '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': dependencies: @@ -7569,6 +7629,11 @@ snapshots: '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) >>>>>>> 91ab67b (fix(externals): use resolver to resolve request) >>>>>>> a43e933 (fix(externals): use resolver to resolve request) +======= + '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.9)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + dependencies: + '@module-federation/enhanced': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) +>>>>>>> 06ac05a (js redirect) '@module-federation/sdk': 0.8.1 >>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) optionalDependencies: diff --git a/scripts/dictionary.txt b/scripts/dictionary.txt index 800513793..da7eef768 100644 --- a/scripts/dictionary.txt +++ b/scripts/dictionary.txt @@ -51,6 +51,7 @@ jfif jiti jscpuprofile jsesc +jsxs koppers lightningcss liyincode diff --git a/tests/integration/redirect/__fixtures__/src/bar/index.ts b/tests/integration/redirect/__fixtures__/src/bar/index.ts new file mode 100644 index 000000000..0b87c7fd0 --- /dev/null +++ b/tests/integration/redirect/__fixtures__/src/bar/index.ts @@ -0,0 +1,3 @@ +import { value } from '../constant'; + +export const bar = 'bar' + value; diff --git a/tests/integration/redirect/__fixtures__/src/constant.ts b/tests/integration/redirect/__fixtures__/src/constant.ts new file mode 100644 index 000000000..efeee5db1 --- /dev/null +++ b/tests/integration/redirect/__fixtures__/src/constant.ts @@ -0,0 +1 @@ +export const value = 1; diff --git a/tests/integration/redirect/__fixtures__/src/foo.ts b/tests/integration/redirect/__fixtures__/src/foo.ts new file mode 100644 index 000000000..3329a7d97 --- /dev/null +++ b/tests/integration/redirect/__fixtures__/src/foo.ts @@ -0,0 +1 @@ +export const foo = 'foo'; diff --git a/tests/integration/redirect/__fixtures__/src/index.ts b/tests/integration/redirect/__fixtures__/src/index.ts new file mode 100644 index 000000000..e892487c7 --- /dev/null +++ b/tests/integration/redirect/__fixtures__/src/index.ts @@ -0,0 +1,10 @@ +import lodash from 'lodash'; + +import { bar as bar2 } from '@/bar'; +import { foo as foo2 } from '@/foo'; +import { bar } from './bar'; +import { foo } from './foo.ts'; + +export default function (): string { + return lodash.toUpper(foo + bar + foo2 + bar2); +} diff --git a/tests/integration/redirect/js/index.test.ts b/tests/integration/redirect/js/index.test.ts new file mode 100644 index 000000000..888cfa2bf --- /dev/null +++ b/tests/integration/redirect/js/index.test.ts @@ -0,0 +1,81 @@ +import { buildAndGetResults, queryContent } from 'test-helper'; +import { beforeAll, expect, test } from 'vitest'; + +let contents: Awaited>['contents']; + +beforeAll(async () => { + const fixturePath = __dirname; + contents = (await buildAndGetResults({ fixturePath })).contents; +}); + +test('redirect.js default', async () => { + const { content: indexContent, path: indexPath } = queryContent( + contents.esm0!, + /esm\/index\.js/, + ); + expect(indexContent).toMatchInlineSnapshot(` + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; + import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; + import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; + /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar); + export { src_rslib_entry_ as default }; + " + `); + + expect((await import(indexPath)).default).toMatchInlineSnapshot( + `"FOOBAR1FOOBAR1"`, + ); +}); + +test('redirect.js.path false', async () => { + const { content: indexContent } = queryContent( + contents.esm1!, + /esm\/index\.js/, + ); + expect(indexContent).toMatchInlineSnapshot(` + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; + import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js"; + import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "@/foo.js"; + import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js"; + import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; + /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar); + export { src_rslib_entry_ as default }; + " + `); +}); + +test('redirect.js.path with user override externals', async () => { + const { content: indexContent, path: indexPath } = queryContent( + contents.esm2!, + /esm\/index\.js/, + ); + expect(indexContent).toMatchInlineSnapshot(` + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; + import * as __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__ from "./others/bar/index.js"; + import * as __WEBPACK_EXTERNAL_MODULE__others_foo_js__ from "./others/foo.js"; + import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; + import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; + /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__others_foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__.bar); + export { src_rslib_entry_ as default }; + " + `); + + expect((await import(indexPath)).default).toMatchInlineSnapshot( + `"FOOBAR1OTHERFOOOTHERBAR2"`, // cspell:disable-line + ); +}); + +test('redirect.js.extension: false', async () => { + const { content: indexContent } = queryContent( + contents.esm3!, + /esm\/index\.js/, + ); + expect(indexContent).toMatchInlineSnapshot(` + "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; + import * as __WEBPACK_EXTERNAL_MODULE__bar_index_ts__ from "./bar/index.ts"; + import * as __WEBPACK_EXTERNAL_MODULE__foo_ts__ from "./foo.ts"; + /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar); + export { src_rslib_entry_ as default }; + " + `); +}); diff --git a/tests/integration/redirect/js/package.json b/tests/integration/redirect/js/package.json new file mode 100644 index 000000000..0aa0be903 --- /dev/null +++ b/tests/integration/redirect/js/package.json @@ -0,0 +1,13 @@ +{ + "name": "redirect-js-test", + "version": "1.0.0", + "private": true, + "type": "module", + "devDependencies": { + "@types/lodash": "^4.17.13", + "lodash": "^4.17.21" + }, + "peerDependencies": { + "lodash": "^4.17.21" + } +} diff --git a/tests/integration/redirect/js/rslib.config.ts b/tests/integration/redirect/js/rslib.config.ts new file mode 100644 index 000000000..35fbcb09f --- /dev/null +++ b/tests/integration/redirect/js/rslib.config.ts @@ -0,0 +1,110 @@ +import { defineConfig } from '@rslib/core'; +import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper'; + +export default defineConfig({ + lib: [ + // 0 default + generateBundleEsmConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/default/esm', + }, + }, + }), + generateBundleCjsConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/default/cjs', + }, + }, + }), + // 1 js.path: false + generateBundleEsmConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/js-path-false/esm', + }, + }, + redirect: { + js: { + path: false, + }, + }, + }), + generateBundleCjsConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/js-path-false/cjs', + }, + }, + redirect: { + js: { + path: false, + }, + }, + }), + // 2 js.path with user override externals + generateBundleEsmConfig({ + bundle: false, + output: { + externals: { + '@/foo': './others/foo.js', + '@/bar': './others/bar/index.js', + }, + distPath: { + root: 'dist/js-path-externals-override/esm', + }, + }, + }), + generateBundleCjsConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/js-path-externals-override/cjs', + }, + externals: { + '@/foo': './src/others/foo', + '@/bar': './src/others/bar', + }, + }, + }), + // 3 js.extension: false + generateBundleEsmConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/js-extension-false/esm', + }, + }, + redirect: { + js: { + extension: false, + }, + }, + }), + generateBundleCjsConfig({ + bundle: false, + output: { + distPath: { + root: 'dist/js-extension-false/cjs', + }, + }, + redirect: { + js: { + extension: false, + }, + }, + }), + ], + + source: { + entry: { + // index: '../__fixtures__/src', + index: './src/**', + }, + }, +}); diff --git a/tests/integration/redirect/js/src/bar/index.ts b/tests/integration/redirect/js/src/bar/index.ts new file mode 100644 index 000000000..0b87c7fd0 --- /dev/null +++ b/tests/integration/redirect/js/src/bar/index.ts @@ -0,0 +1,3 @@ +import { value } from '../constant'; + +export const bar = 'bar' + value; diff --git a/tests/integration/redirect/js/src/constant.ts b/tests/integration/redirect/js/src/constant.ts new file mode 100644 index 000000000..efeee5db1 --- /dev/null +++ b/tests/integration/redirect/js/src/constant.ts @@ -0,0 +1 @@ +export const value = 1; diff --git a/tests/integration/redirect/js/src/foo.ts b/tests/integration/redirect/js/src/foo.ts new file mode 100644 index 000000000..3329a7d97 --- /dev/null +++ b/tests/integration/redirect/js/src/foo.ts @@ -0,0 +1 @@ +export const foo = 'foo'; diff --git a/tests/integration/redirect/js/src/index.ts b/tests/integration/redirect/js/src/index.ts new file mode 100644 index 000000000..fc6813abc --- /dev/null +++ b/tests/integration/redirect/js/src/index.ts @@ -0,0 +1,8 @@ +import lodash from 'lodash'; + +import { bar as bar2 } from '@/bar'; +import { foo as foo2 } from '@/foo'; +import { bar } from './bar'; +import { foo } from './foo.ts'; + +export default lodash.toUpper(foo + bar + foo2 + bar2); diff --git a/tests/integration/redirect/js/src/others/bar/index.ts b/tests/integration/redirect/js/src/others/bar/index.ts new file mode 100644 index 000000000..96d00c427 --- /dev/null +++ b/tests/integration/redirect/js/src/others/bar/index.ts @@ -0,0 +1,3 @@ +import { value } from '../constant'; + +export const bar = 'otherBar' + value; diff --git a/tests/integration/redirect/js/src/others/constant.ts b/tests/integration/redirect/js/src/others/constant.ts new file mode 100644 index 000000000..44439d586 --- /dev/null +++ b/tests/integration/redirect/js/src/others/constant.ts @@ -0,0 +1 @@ +export const value = 2; diff --git a/tests/integration/redirect/js/src/others/foo.ts b/tests/integration/redirect/js/src/others/foo.ts new file mode 100644 index 000000000..23e046b59 --- /dev/null +++ b/tests/integration/redirect/js/src/others/foo.ts @@ -0,0 +1 @@ +export const foo = 'otherFoo'; diff --git a/tests/integration/redirect/js/tsconfig.json b/tests/integration/redirect/js/tsconfig.json new file mode 100644 index 000000000..2291f72e1 --- /dev/null +++ b/tests/integration/redirect/js/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "@rslib/tsconfig/base", + "compilerOptions": { + "baseUrl": "./", + "paths": { + "@/*": ["./src/*"] + } + }, + "include": ["src"] +} diff --git a/tests/integration/style/redirect-style-false/index.test.ts b/tests/integration/redirect/style-false/index.test.ts similarity index 82% rename from tests/integration/style/redirect-style-false/index.test.ts rename to tests/integration/redirect/style-false/index.test.ts index 3961e1d5b..2380343fc 100644 --- a/tests/integration/style/redirect-style-false/index.test.ts +++ b/tests/integration/redirect/style-false/index.test.ts @@ -8,7 +8,7 @@ test('should extract css successfully when using redirect.style = false', async const esmFiles = Object.keys(contents.esm); expect(esmFiles).toMatchInlineSnapshot(` [ - "/tests/integration/style/redirect-style-false/dist/esm/index.js", + "/tests/integration/redirect/style-false/dist/esm/index.js", ] `); expectFileContainContent(contents.esm, 'index.js', 'import "./index.less";'); @@ -16,7 +16,7 @@ test('should extract css successfully when using redirect.style = false', async const cjsFiles = Object.keys(contents.cjs); expect(cjsFiles).toMatchInlineSnapshot(` [ - "/tests/integration/style/redirect-style-false/dist/cjs/index.cjs", + "/tests/integration/redirect/style-false/dist/cjs/index.cjs", ] `); expectFileContainContent( diff --git a/tests/integration/style/redirect-style-false/package.json b/tests/integration/redirect/style-false/package.json similarity index 53% rename from tests/integration/style/redirect-style-false/package.json rename to tests/integration/redirect/style-false/package.json index 788a8e737..227b360ac 100644 --- a/tests/integration/style/redirect-style-false/package.json +++ b/tests/integration/redirect/style-false/package.json @@ -1,5 +1,5 @@ { - "name": "css-bundle-false-redirect-style-false-test", + "name": "redirect-style-false-test", "version": "1.0.0", "private": true, "type": "module" diff --git a/tests/integration/style/redirect-style-false/rslib.config.ts b/tests/integration/redirect/style-false/rslib.config.ts similarity index 100% rename from tests/integration/style/redirect-style-false/rslib.config.ts rename to tests/integration/redirect/style-false/rslib.config.ts diff --git a/tests/integration/style/redirect-style-false/src/index.less b/tests/integration/redirect/style-false/src/index.less similarity index 100% rename from tests/integration/style/redirect-style-false/src/index.less rename to tests/integration/redirect/style-false/src/index.less diff --git a/tests/integration/style/redirect-style-false/src/index.ts b/tests/integration/redirect/style-false/src/index.ts similarity index 100% rename from tests/integration/style/redirect-style-false/src/index.ts rename to tests/integration/redirect/style-false/src/index.ts diff --git a/tests/integration/style/redirect-style-false/src/style.module.less b/tests/integration/redirect/style-false/src/style.module.less similarity index 100% rename from tests/integration/style/redirect-style-false/src/style.module.less rename to tests/integration/redirect/style-false/src/style.module.less diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index 20c8aa283..42c1e57e0 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -3,7 +3,13 @@ - **Type:** ```ts +type JsRedirect = { + path?: boolean; + extension?: boolean; +}; + type Redirect = { + js?: JsRedirect; style?: boolean; }; ``` @@ -12,6 +18,10 @@ type Redirect = { ```ts const defaultRedirect = { + js: { + path: true, + extension: true, + }, style: true, }; ``` @@ -40,6 +50,28 @@ export default { }; ``` +## redirect.js + +Controls the redirect of the import paths of output JavaScript files. + +### redirect.js.path + +Whether to automatically redirect the import paths of JavaScript output files, compilerOptions.paths in tsconfig.json will be applied by default. + +- **Type:** `boolean` +- **Default:** `true` + +### redirect.js.extension + +Whether to automatically add the file extension based on the JavaScript output files. + +- **Type:** `boolean` +- **Default:** `true` + +:::warning +When [output.externals](/config/rsbuild/output#outputexternals) is configured and a request is matched, neither `redirect.js.path` nor `redirect.js.extension` will take effect, and the final rewritten request path will be entirely controlled by [output.externals](/config/rsbuild/output#outputexternals). +::: + ## redirect.style - **Type:** `boolean` From e7e19e9085359ad825cc39c8f33025d44e125af4 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Fri, 13 Dec 2024 17:40:24 +0800 Subject: [PATCH 03/13] up --- package.json | 1 - pnpm-lock.yaml | 396 ++---------------- .../integration/auto-extension/index.test.ts | 2 +- tests/integration/redirect/js/index.test.ts | 8 +- 4 files changed, 44 insertions(+), 363 deletions(-) diff --git a/package.json b/package.json index ff023d65c..e13e35edc 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ }, "pnpm": { "overrides": { - "@rspack/core": "npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520", "zx>@types/node": "-" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 02622b07f..b94c445dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -88,28 +88,8 @@ importers: version: 19.0.0(react@19.0.0) devDependencies: '@module-federation/rsbuild-plugin': -<<<<<<< HEAD specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= - specifier: ^0.8.1 -<<<<<<< HEAD -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -<<<<<<< HEAD ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) -======= -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) ->>>>>>> 06ac05a (js redirect) ->>>>>>> 059c9de (js redirect) + version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -129,55 +109,14 @@ importers: examples/module-federation/mf-react-component: devDependencies: '@module-federation/enhanced': -<<<<<<< HEAD specifier: ^0.8.4 - version: 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= - specifier: ^0.8.1 -<<<<<<< HEAD -<<<<<<< HEAD - version: 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= -<<<<<<< HEAD - version: 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) + version: 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/rsbuild-plugin': specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) + version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@module-federation/storybook-addon': -<<<<<<< HEAD specifier: ^3.0.15 - version: 3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) -======= - specifier: ^3.0.12 -<<<<<<< HEAD - version: 3.0.12(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) -======= - version: 3.0.12(@rsbuild/core@1.1.9)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) -======= - version: 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) - '@module-federation/rsbuild-plugin': - specifier: ^0.8.1 - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) - '@module-federation/storybook-addon': - specifier: ^3.0.12 - version: 3.0.12(@rsbuild/core@1.1.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -<<<<<<< HEAD ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) -======= -======= - version: 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) - '@module-federation/rsbuild-plugin': - specifier: ^0.8.1 - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) - '@module-federation/storybook-addon': - specifier: ^3.0.12 - version: 3.0.12(@rsbuild/core@1.1.9)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) ->>>>>>> 06ac05a (js redirect) ->>>>>>> 059c9de (js redirect) + version: 3.0.15(@rsbuild/core@1.1.10)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) '@rsbuild/plugin-react': specifier: ^1.1.0 version: 1.1.0(@rsbuild/core@1.1.10) @@ -201,10 +140,10 @@ importers: version: 8.4.7(prettier@3.4.2) storybook-addon-rslib: specifier: ^0.1.6 - version: 0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3) + version: 0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3) storybook-react-rsbuild: specifier: ^0.1.6 - version: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1) + version: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1) examples/module-federation/mf-remote: dependencies: @@ -216,28 +155,8 @@ importers: version: 19.0.0(react@19.0.0) devDependencies: '@module-federation/rsbuild-plugin': -<<<<<<< HEAD specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= - specifier: ^0.8.1 -<<<<<<< HEAD -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -<<<<<<< HEAD ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) -======= -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) ->>>>>>> 06ac05a (js redirect) ->>>>>>> 059c9de (js redirect) + version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -431,7 +350,7 @@ importers: dependencies: magic-string: specifier: ^0.30.15 - version: 0.30.15 + version: 0.30.17 picocolors: specifier: 1.1.1 version: 1.1.1 @@ -473,28 +392,8 @@ importers: specifier: ^4.0.0 version: 4.0.0(vite@5.3.3(@types/node@22.8.1)(terser@5.31.6))(vitest@2.1.8(@types/node@22.8.1)(terser@5.31.6)) '@module-federation/rsbuild-plugin': -<<<<<<< HEAD specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= - specifier: ^0.8.1 -<<<<<<< HEAD -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) -======= -<<<<<<< HEAD - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -<<<<<<< HEAD ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) -======= -======= - version: 0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9) ->>>>>>> 06ac05a (js redirect) ->>>>>>> 059c9de (js redirect) + version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@playwright/test': specifier: 1.49.1 version: 1.49.1 @@ -819,17 +718,6 @@ importers: specifier: ^0.11.0 version: 0.11.0(@babel/core@7.26.0) - tests/integration/redirect/js: - devDependencies: - '@types/lodash': - specifier: ^4.17.13 - version: 4.17.13 - lodash: - specifier: ^4.17.21 - version: 4.17.21 - - tests/integration/redirect/style-false: {} - tests/integration/require/import-dynamic: {} tests/integration/require/require-as-expression: {} @@ -894,6 +782,8 @@ importers: specifier: 2.0.0 version: 2.0.0 + tests/integration/style/redirect-style-false: {} + tests/integration/style/sass/bundle: {} tests/integration/style/sass/bundle-false: {} @@ -2031,58 +1921,6 @@ packages: typescript: optional: true -<<<<<<< HEAD - '@rspack/binding-darwin-arm64@1.1.6': - resolution: {integrity: sha512-x9dxm2yyiMuL1FBwvWNNMs2/mEUJmRoSRgYb8pblR7HDaTRORrjBFCqhaYlGyAqtQaeUy7o2VAQlE0BavIiFYA==} - cpu: [arm64] - os: [darwin] - - '@rspack/binding-darwin-x64@1.1.6': - resolution: {integrity: sha512-o0seilveftGiDjy3VPxug20HmAgYyQbNEuagR3i93/t/PT/eWXHnik+C1jjwqcivZL1Zllqvy4tbZw393aROEQ==} - cpu: [x64] - os: [darwin] - - '@rspack/binding-linux-arm64-gnu@1.1.6': - resolution: {integrity: sha512-4atnoknJx/c3KaQElsMIxHMpPf2jcRRdWsH/SdqJIRSrkWWakMK9Yv4TFwH680I4HDTMf1XLboMVScHzW8e+Mg==} - cpu: [arm64] - os: [linux] - - '@rspack/binding-linux-arm64-musl@1.1.6': - resolution: {integrity: sha512-7QMtwUtgFpt3/Y3/X18fSyN+kk4H8ZnZ8tDzQskVWc/j2AQYShZq56XQYqrhClzwujcCVAHauIQ2eiuJ2ASGag==} - cpu: [arm64] - os: [linux] - - '@rspack/binding-linux-x64-gnu@1.1.6': - resolution: {integrity: sha512-MTjDEfPn4TwHoqs5d5Fck06kmXiTHZctGIcRVfrpg0RK0r1NLEHN+oosavRZ9c9H70f34+NmcHk+/qvV4c8lWg==} - cpu: [x64] - os: [linux] - - '@rspack/binding-linux-x64-musl@1.1.6': - resolution: {integrity: sha512-LqDw7PTVr/4ZuGA0izgDQfamfr72USFHltR1Qhy2YVC3JmDmhG/pQi13LHcOLVaGH1xoeyCmEPNJpVizzDxSjg==} - cpu: [x64] - os: [linux] - - '@rspack/binding-win32-arm64-msvc@1.1.6': - resolution: {integrity: sha512-RHApLM93YN0WdHpS35u2cm7VCqZ8Yg3CrNRL16VJtyT9e6MBqeScoe4XIgIWKPm7edFyedYAjLX0wQOApwfjkg==} - cpu: [arm64] - os: [win32] - - '@rspack/binding-win32-ia32-msvc@1.1.6': - resolution: {integrity: sha512-Y6lx4q0eJawRfMPBo/AclTJAPTZ325DSPFBQJB3TnWh9Z2X7P7pQcYc8PHDmfDuYRIdg5WRsQRvVxihSvF7v8w==} - cpu: [ia32] - os: [win32] - - '@rspack/binding-win32-x64-msvc@1.1.6': - resolution: {integrity: sha512-UuCsfhC/yNuU7xLASOxNXcmsXi2ZvBX14GkxvcdChw6q7IIGNYUKXo1zgR8C1PE/6qDSxmLxbRMS+71d0H3HQg==} - cpu: [x64] - os: [win32] - - '@rspack/binding@1.1.6': - resolution: {integrity: sha512-vfeBEgGOYVwqj5cQjGyvdfrr/BEihAHlyIsobL98FZjTF0uig+bj2yJUH5Ib5F0BpIUKVG3Pw0IjlUBqcVpZsQ==} - - '@rspack/core@1.1.6': - resolution: {integrity: sha512-q0VLphOF5VW2FEG7Vbdq3Ke4I74FbELE/8xmKghSalFtULLZ44SoSz8lyotfMim9GXIRFhDokAaH8WICmPxG+g==} -======= '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': resolution: {integrity: sha512-vwonCXADq2TzpPcgQvZBgMq420VyLvVkYZjlaXm8jofntPHqFwNr0gjAh05S0kUVdePkkAxL64fG4fd91GbSJg==} @@ -2133,7 +1971,6 @@ packages: '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520': resolution: {integrity: sha512-OwWxxVd9TnWaBnug2SAGmyl7VNR3MVGCwstXXhTAUCh0UTX/lQjmIKERm/tcHQyD04bOCeb+VXoj9qZT3PRbrg==} ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -4549,8 +4386,8 @@ packages: resolution: {integrity: sha512-rh+Zjr6DNfUYR3bPwJEnuwDdqMbxZW7LOQfUN4B54+Cl+0o5zaU9RJ6bcidfDtC1cWCZXQ+nvX8bf6bAji37QQ==} engines: {node: '>=12'} - magic-string@0.30.15: - resolution: {integrity: sha512-zXeaYRgZ6ldS1RJJUrMrYgNJ4fdwnyI6tVqoiIhyCyv5IVTK9BU8Ic2l253GGETQHxI4HNUwhJ3fjDhKqEoaAw==} + magic-string@0.30.17: + resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==} make-dir@3.1.0: resolution: {integrity: sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==} @@ -6201,7 +6038,7 @@ packages: resolution: {integrity: sha512-K5BUrytoFju1Olu11T49vlYvDEGOguBF1CBCl4o2ARxDGPoJHHf7fBzLlK0YYkUqI5EFA5cMRUC6332M7hQBHw==} engines: {node: '>=16.0.0'} peerDependencies: - '@rspack/core': ^1.0.0 + '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 typescript: '>=3.8.0' peerDependenciesMeta: '@rspack/core': @@ -7433,47 +7270,16 @@ snapshots: - supports-color - utf-8-validate -<<<<<<< HEAD -<<<<<<< HEAD - '@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': + '@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.4 '@module-federation/data-prefetch': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@module-federation/dts-plugin': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/managers': 0.8.4 '@module-federation/manifest': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) - '@module-federation/rspack': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) + '@module-federation/rspack': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 -======= -======= ->>>>>>> 059c9de (js redirect) -<<<<<<< HEAD - '@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': -======= -<<<<<<< HEAD - '@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': -======= - '@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -======= - '@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': ->>>>>>> 06ac05a (js redirect) - dependencies: - '@module-federation/bridge-react-webpack-plugin': 0.8.1 - '@module-federation/data-prefetch': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - '@module-federation/dts-plugin': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) - '@module-federation/managers': 0.8.1 - '@module-federation/manifest': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) -<<<<<<< HEAD - '@module-federation/rspack': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) -======= - '@module-federation/rspack': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) - '@module-federation/runtime-tools': 0.8.1 - '@module-federation/sdk': 0.8.1 ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) btoa: 1.2.1 upath: 2.0.1 optionalDependencies: @@ -7512,15 +7318,13 @@ snapshots: - utf-8-validate - vue-tsc -<<<<<<< HEAD -<<<<<<< HEAD - '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': + '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': dependencies: - '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/enhanced': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 '@rsbuild/core': 1.1.10 - '@module-federation/rspack@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': + '@module-federation/rspack@0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.4 '@module-federation/dts-plugin': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) @@ -7528,49 +7332,6 @@ snapshots: '@module-federation/manifest': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 -======= -======= ->>>>>>> 059c9de (js redirect) -<<<<<<< HEAD - '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': - dependencies: - '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= -<<<<<<< HEAD - '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9)': - dependencies: - '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= - '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.8)': - dependencies: - '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -======= - '@module-federation/rsbuild-plugin@0.8.1(@module-federation/enhanced@0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.9)': - dependencies: - '@module-federation/enhanced': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ->>>>>>> 06ac05a (js redirect) - '@module-federation/sdk': 0.8.1 - '@rsbuild/core': 1.1.10 - -<<<<<<< HEAD - '@module-federation/rspack@0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': -======= - '@module-federation/rspack@0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) - dependencies: - '@module-federation/bridge-react-webpack-plugin': 0.8.1 - '@module-federation/dts-plugin': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) - '@module-federation/managers': 0.8.1 - '@module-federation/manifest': 0.8.1(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) - '@module-federation/runtime-tools': 0.8.1 - '@module-federation/sdk': 0.8.1 -<<<<<<< HEAD ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) - '@rspack/core': 1.1.6(@swc/helpers@0.5.15) -======= ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) optionalDependencies: typescript: 5.6.3 vue-tsc: 2.1.10(typescript@5.6.3) @@ -7605,37 +7366,10 @@ snapshots: dependencies: isomorphic-rslog: 0.0.6 -<<<<<<< HEAD -<<<<<<< HEAD - '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': dependencies: - '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/enhanced': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 -======= -======= ->>>>>>> 059c9de (js redirect) -<<<<<<< HEAD - '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': - dependencies: - '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= -<<<<<<< HEAD - '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.9)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': - dependencies: - '@module-federation/enhanced': 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) -======= - '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.8)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': - dependencies: - '@module-federation/enhanced': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ->>>>>>> 91ab67b (fix(externals): use resolver to resolve request) ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) -======= - '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.9)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': - dependencies: - '@module-federation/enhanced': 0.8.1(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) ->>>>>>> 06ac05a (js redirect) - '@module-federation/sdk': 0.8.1 ->>>>>>> cf81ff4 (fix(externals): use resolver to resolve request) optionalDependencies: '@rsbuild/core': 1.1.10 webpack: 5.96.1 @@ -7792,11 +7526,7 @@ snapshots: '@rsbuild/core@1.1.10': dependencies: -<<<<<<< HEAD - '@rspack/core': 1.1.6(@swc/helpers@0.5.15) -======= '@rspack/core': '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)' ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) '@rspack/lite-tapable': 1.0.1 '@swc/helpers': 0.5.15 core-js: 3.39.0 @@ -7887,12 +7617,12 @@ snapshots: - supports-color - typescript - '@rsbuild/plugin-type-check@1.1.0(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)': + '@rsbuild/plugin-type-check@1.1.0(@rsbuild/core@1.1.10)(typescript@5.6.3)': dependencies: deepmerge: 4.3.1 json5: 2.2.3 reduce-configs: 1.1.0 - ts-checker-rspack-plugin: 1.0.3(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3) + ts-checker-rspack-plugin: 1.0.3(typescript@5.6.3) optionalDependencies: '@rsbuild/core': 1.1.10 transitivePeerDependencies: @@ -7921,51 +7651,6 @@ snapshots: '@microsoft/api-extractor': 7.48.1(@types/node@22.8.1) typescript: 5.6.3 -<<<<<<< HEAD - '@rspack/binding-darwin-arm64@1.1.6': - optional: true - - '@rspack/binding-darwin-x64@1.1.6': - optional: true - - '@rspack/binding-linux-arm64-gnu@1.1.6': - optional: true - - '@rspack/binding-linux-arm64-musl@1.1.6': - optional: true - - '@rspack/binding-linux-x64-gnu@1.1.6': - optional: true - - '@rspack/binding-linux-x64-musl@1.1.6': - optional: true - - '@rspack/binding-win32-arm64-msvc@1.1.6': - optional: true - - '@rspack/binding-win32-ia32-msvc@1.1.6': - optional: true - - '@rspack/binding-win32-x64-msvc@1.1.6': - optional: true - - '@rspack/binding@1.1.6': - optionalDependencies: - '@rspack/binding-darwin-arm64': 1.1.6 - '@rspack/binding-darwin-x64': 1.1.6 - '@rspack/binding-linux-arm64-gnu': 1.1.6 - '@rspack/binding-linux-arm64-musl': 1.1.6 - '@rspack/binding-linux-x64-gnu': 1.1.6 - '@rspack/binding-linux-x64-musl': 1.1.6 - '@rspack/binding-win32-arm64-msvc': 1.1.6 - '@rspack/binding-win32-ia32-msvc': 1.1.6 - '@rspack/binding-win32-x64-msvc': 1.1.6 - - '@rspack/core@1.1.6(@swc/helpers@0.5.15)': - dependencies: - '@module-federation/runtime-tools': 0.5.1 - '@rspack/binding': 1.1.6 -======= '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': optionalDependencies: '@rspack/binding-darwin-arm64': '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520' @@ -8009,7 +7694,6 @@ snapshots: dependencies: '@module-federation/runtime-tools': 0.5.1 '@rspack/binding': '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520' ->>>>>>> a43e933 (fix(externals): use resolver to resolve request) '@rspack/lite-tapable': 1.0.1 caniuse-lite: 1.0.30001680 optionalDependencies: @@ -8611,7 +8295,7 @@ snapshots: dependencies: '@vitest/spy': 2.1.8 estree-walker: 3.0.3 - magic-string: 0.30.15 + magic-string: 0.30.17 optionalDependencies: vite: 5.3.3(@types/node@22.8.1)(terser@5.31.6) @@ -8627,7 +8311,7 @@ snapshots: '@vitest/snapshot@2.1.8': dependencies: '@vitest/pretty-format': 2.1.8 - magic-string: 0.30.15 + magic-string: 0.30.17 pathe: 1.1.2 '@vitest/spy@2.1.8': @@ -8673,7 +8357,7 @@ snapshots: '@vue/compiler-ssr': 3.5.13 '@vue/shared': 3.5.13 estree-walker: 2.0.2 - magic-string: 0.30.15 + magic-string: 0.30.17 postcss: 8.4.49 source-map-js: 1.2.1 @@ -10728,7 +10412,7 @@ snapshots: luxon@3.5.0: {} - magic-string@0.30.15: + magic-string@0.30.17: dependencies: '@jridgewell/sourcemap-codec': 1.5.0 @@ -12051,7 +11735,7 @@ snapshots: rollup-plugin-dts@6.1.1(rollup@4.18.1)(typescript@5.6.3): dependencies: - magic-string: 0.30.15 + magic-string: 0.30.17 rollup: 4.18.1 typescript: 5.6.3 optionalDependencies: @@ -12082,7 +11766,7 @@ snapshots: rsbuild-plugin-dts@0.1.4(@microsoft/api-extractor@7.48.1(@types/node@22.8.1))(@rsbuild/core@1.1.10)(typescript@5.6.3): dependencies: '@rsbuild/core': 1.1.10 - magic-string: 0.30.15 + magic-string: 0.30.17 picocolors: 1.1.1 tinyglobby: 0.2.10 optionalDependencies: @@ -12423,18 +12107,18 @@ snapshots: stdin-discarder@0.2.2: {} - storybook-addon-rslib@0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3): + storybook-addon-rslib@0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3): dependencies: '@rsbuild/core': 1.1.10 '@rslib/core': link:packages/core - storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) + storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) optionalDependencies: typescript: 5.6.3 - storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3): + storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3): dependencies: '@rsbuild/core': 1.1.10 - '@rsbuild/plugin-type-check': 1.1.0(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3) + '@rsbuild/plugin-type-check': 1.1.0(@rsbuild/core@1.1.10)(typescript@5.6.3) '@storybook/addon-docs': 8.4.2(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(webpack-sources@3.2.3) '@storybook/core-webpack': 8.4.2(storybook@8.4.7(prettier@3.4.2)) browser-assert: 1.2.1 @@ -12443,7 +12127,7 @@ snapshots: constants-browserify: 1.0.0 es-module-lexer: 1.5.4 fs-extra: 11.2.0 - magic-string: 0.30.15 + magic-string: 0.30.17 path-browserify: 1.0.1 process: 0.11.10 rsbuild-plugin-html-minifier-terser: 1.1.1(@rsbuild/core@1.1.10) @@ -12460,7 +12144,7 @@ snapshots: - '@types/react' - webpack-sources - storybook-react-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1): + storybook-react-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1): dependencies: '@rollup/pluginutils': 5.1.3(rollup@4.18.1) '@rsbuild/core': 1.1.10 @@ -12468,13 +12152,13 @@ snapshots: '@storybook/react-docgen-typescript-plugin': 1.0.1(typescript@5.6.3)(webpack@5.96.1) '@types/node': 18.19.64 find-up: 5.0.0 - magic-string: 0.30.15 + magic-string: 0.30.17 react: 19.0.0 react-docgen: 7.1.0 react-dom: 19.0.0(react@19.0.0) resolve: 1.22.8 storybook: 8.4.7(prettier@3.4.2) - storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) + storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) tsconfig-paths: 4.2.0 optionalDependencies: typescript: 5.6.3 @@ -12741,7 +12425,7 @@ snapshots: trough@2.2.0: {} - ts-checker-rspack-plugin@1.0.3(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3): + ts-checker-rspack-plugin@1.0.3(typescript@5.6.3): dependencies: '@babel/code-frame': 7.26.2 '@rspack/lite-tapable': 1.0.1 @@ -12750,8 +12434,6 @@ snapshots: minimatch: 9.0.5 picocolors: 1.1.1 typescript: 5.6.3 - optionalDependencies: - '@rspack/core': 1.1.6(@swc/helpers@0.5.15) ts-dedent@2.2.0: {} @@ -13002,7 +12684,7 @@ snapshots: chai: 5.1.2 debug: 4.3.7 expect-type: 1.1.0 - magic-string: 0.30.15 + magic-string: 0.30.17 pathe: 1.1.2 std-env: 3.8.0 tinybench: 2.9.0 diff --git a/tests/integration/auto-extension/index.test.ts b/tests/integration/auto-extension/index.test.ts index e4e772dcb..e56fbf7fc 100644 --- a/tests/integration/auto-extension/index.test.ts +++ b/tests/integration/auto-extension/index.test.ts @@ -40,7 +40,7 @@ describe('should respect output.filename.js to override builtin logic', () => { const { entryFiles } = await buildAndGetResults({ fixturePath }); expect(extname(entryFiles.esm!)).toEqual('.mjs'); expect(entryFiles.cjs).toMatchInlineSnapshot( - `"/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.18bec1db.js"`, + `"/tests/integration/auto-extension/type-commonjs/config-override/dist/cjs/index.1310c114.js"`, ); }); diff --git a/tests/integration/redirect/js/index.test.ts b/tests/integration/redirect/js/index.test.ts index 888cfa2bf..8d4868ad3 100644 --- a/tests/integration/redirect/js/index.test.ts +++ b/tests/integration/redirect/js/index.test.ts @@ -17,7 +17,7 @@ test('redirect.js default', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar); export { src_rslib_entry_ as default }; " `); @@ -38,7 +38,7 @@ test('redirect.js.path false', async () => { import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "@/foo.js"; import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar); export { src_rslib_entry_ as default }; " `); @@ -55,7 +55,7 @@ test('redirect.js.path with user override externals', async () => { import * as __WEBPACK_EXTERNAL_MODULE__others_foo_js__ from "./others/foo.js"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__others_foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__others_foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__.bar); export { src_rslib_entry_ as default }; " `); @@ -74,7 +74,7 @@ test('redirect.js.extension: false', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_ts__ from "./bar/index.ts"; import * as __WEBPACK_EXTERNAL_MODULE__foo_ts__ from "./foo.ts"; - /* ESM default export */ const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar); export { src_rslib_entry_ as default }; " `); From bbd293d0bdbca1200707c1b5fb594850c9ffa929 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 13:52:00 +0800 Subject: [PATCH 04/13] fix vitest --- .../redirect/__fixtures__/src/bar/index.ts | 3 -- .../redirect/__fixtures__/src/constant.ts | 1 - .../redirect/__fixtures__/src/foo.ts | 1 - .../redirect/__fixtures__/src/index.ts | 10 ------ .../redirect/{js/index.test.ts => js.test.ts} | 34 ++++++++++++++----- tests/integration/redirect/js/rslib.config.ts | 4 +-- tests/integration/redirect/js/src/index.ts | 2 +- 7 files changed, 28 insertions(+), 27 deletions(-) delete mode 100644 tests/integration/redirect/__fixtures__/src/bar/index.ts delete mode 100644 tests/integration/redirect/__fixtures__/src/constant.ts delete mode 100644 tests/integration/redirect/__fixtures__/src/foo.ts delete mode 100644 tests/integration/redirect/__fixtures__/src/index.ts rename tests/integration/redirect/{js/index.test.ts => js.test.ts} (79%) diff --git a/tests/integration/redirect/__fixtures__/src/bar/index.ts b/tests/integration/redirect/__fixtures__/src/bar/index.ts deleted file mode 100644 index 0b87c7fd0..000000000 --- a/tests/integration/redirect/__fixtures__/src/bar/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { value } from '../constant'; - -export const bar = 'bar' + value; diff --git a/tests/integration/redirect/__fixtures__/src/constant.ts b/tests/integration/redirect/__fixtures__/src/constant.ts deleted file mode 100644 index efeee5db1..000000000 --- a/tests/integration/redirect/__fixtures__/src/constant.ts +++ /dev/null @@ -1 +0,0 @@ -export const value = 1; diff --git a/tests/integration/redirect/__fixtures__/src/foo.ts b/tests/integration/redirect/__fixtures__/src/foo.ts deleted file mode 100644 index 3329a7d97..000000000 --- a/tests/integration/redirect/__fixtures__/src/foo.ts +++ /dev/null @@ -1 +0,0 @@ -export const foo = 'foo'; diff --git a/tests/integration/redirect/__fixtures__/src/index.ts b/tests/integration/redirect/__fixtures__/src/index.ts deleted file mode 100644 index e892487c7..000000000 --- a/tests/integration/redirect/__fixtures__/src/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import lodash from 'lodash'; - -import { bar as bar2 } from '@/bar'; -import { foo as foo2 } from '@/foo'; -import { bar } from './bar'; -import { foo } from './foo.ts'; - -export default function (): string { - return lodash.toUpper(foo + bar + foo2 + bar2); -} diff --git a/tests/integration/redirect/js/index.test.ts b/tests/integration/redirect/js.test.ts similarity index 79% rename from tests/integration/redirect/js/index.test.ts rename to tests/integration/redirect/js.test.ts index 8d4868ad3..beadceda3 100644 --- a/tests/integration/redirect/js/index.test.ts +++ b/tests/integration/redirect/js.test.ts @@ -1,18 +1,24 @@ +import path from 'node:path'; import { buildAndGetResults, queryContent } from 'test-helper'; import { beforeAll, expect, test } from 'vitest'; let contents: Awaited>['contents']; beforeAll(async () => { - const fixturePath = __dirname; + const fixturePath = path.resolve(__dirname, './js'); contents = (await buildAndGetResults({ fixturePath })).contents; }); test('redirect.js default', async () => { - const { content: indexContent, path: indexPath } = queryContent( + const { content: indexContent, path: indexEsmPath } = queryContent( contents.esm0!, /esm\/index\.js/, ); + const { path: indexCjsPath } = await queryContent( + contents.cjs0!, + /cjs\/index\.cjs/, + ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; @@ -22,9 +28,11 @@ test('redirect.js default', async () => { " `); - expect((await import(indexPath)).default).toMatchInlineSnapshot( - `"FOOBAR1FOOBAR1"`, - ); + const esmResult = await import(indexEsmPath); + const cjsResult = await import(indexCjsPath); + + expect(esmResult.default).toEqual(cjsResult.default); + expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1FOOBAR1"`); }); test('redirect.js.path false', async () => { @@ -32,6 +40,7 @@ test('redirect.js.path false', async () => { contents.esm1!, /esm\/index\.js/, ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js"; @@ -45,10 +54,15 @@ test('redirect.js.path false', async () => { }); test('redirect.js.path with user override externals', async () => { - const { content: indexContent, path: indexPath } = queryContent( + const { content: indexContent, path: indexEsmPath } = queryContent( contents.esm2!, /esm\/index\.js/, ); + const { path: indexCjsPath } = await queryContent( + contents.cjs2!, + /cjs\/index\.cjs/, + ); + expect(indexContent).toMatchInlineSnapshot(` "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__ from "./others/bar/index.js"; @@ -60,9 +74,11 @@ test('redirect.js.path with user override externals', async () => { " `); - expect((await import(indexPath)).default).toMatchInlineSnapshot( - `"FOOBAR1OTHERFOOOTHERBAR2"`, // cspell:disable-line - ); + const esmResult = await import(indexEsmPath); + const cjsResult = await import(indexCjsPath); + + expect(esmResult.default).toEqual(cjsResult.default); + expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1OTHERFOOOTHERBAR2"`); // cspell:disable-line }); test('redirect.js.extension: false', async () => { diff --git a/tests/integration/redirect/js/rslib.config.ts b/tests/integration/redirect/js/rslib.config.ts index 35fbcb09f..ab17005d1 100644 --- a/tests/integration/redirect/js/rslib.config.ts +++ b/tests/integration/redirect/js/rslib.config.ts @@ -67,8 +67,8 @@ export default defineConfig({ root: 'dist/js-path-externals-override/cjs', }, externals: { - '@/foo': './src/others/foo', - '@/bar': './src/others/bar', + '@/foo': './others/foo.cjs', + '@/bar': './others/bar/index.cjs', }, }, }), diff --git a/tests/integration/redirect/js/src/index.ts b/tests/integration/redirect/js/src/index.ts index fc6813abc..72d073a11 100644 --- a/tests/integration/redirect/js/src/index.ts +++ b/tests/integration/redirect/js/src/index.ts @@ -3,6 +3,6 @@ import lodash from 'lodash'; import { bar as bar2 } from '@/bar'; import { foo as foo2 } from '@/foo'; import { bar } from './bar'; -import { foo } from './foo.ts'; +import { foo } from './foo'; export default lodash.toUpper(foo + bar + foo2 + bar2); From 106521d93353bc64869f5e1c2ea1c047470e4815 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 17:43:22 +0800 Subject: [PATCH 05/13] doc --- pnpm-lock.yaml | 163 +++++++++++++----------- website/docs/en/config/lib/redirect.mdx | 75 +++++++---- website/docs/zh/config/lib/redirect.mdx | 103 +++++++++++---- 3 files changed, 217 insertions(+), 124 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b94c445dc..625757ce1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,6 @@ settings: excludeLinksFromLockfile: false overrides: - '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 zx>@types/node: '-' importers: @@ -89,7 +88,7 @@ importers: devDependencies: '@module-federation/rsbuild-plugin': specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) + version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -110,13 +109,13 @@ importers: devDependencies: '@module-federation/enhanced': specifier: ^0.8.4 - version: 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + version: 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/rsbuild-plugin': specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) + version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@module-federation/storybook-addon': specifier: ^3.0.15 - version: 3.0.15(@rsbuild/core@1.1.10)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) + version: 3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1) '@rsbuild/plugin-react': specifier: ^1.1.0 version: 1.1.0(@rsbuild/core@1.1.10) @@ -140,10 +139,10 @@ importers: version: 8.4.7(prettier@3.4.2) storybook-addon-rslib: specifier: ^0.1.6 - version: 0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3) + version: 0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3) storybook-react-rsbuild: specifier: ^0.1.6 - version: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1) + version: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1) examples/module-federation/mf-remote: dependencies: @@ -156,7 +155,7 @@ importers: devDependencies: '@module-federation/rsbuild-plugin': specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) + version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@rsbuild/core': specifier: ~1.1.10 version: 1.1.10 @@ -393,7 +392,7 @@ importers: version: 4.0.0(vite@5.3.3(@types/node@22.8.1)(terser@5.31.6))(vitest@2.1.8(@types/node@22.8.1)(terser@5.31.6)) '@module-federation/rsbuild-plugin': specifier: ^0.8.4 - version: 0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) + version: 0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10) '@playwright/test': specifier: 1.49.1 version: 1.49.1 @@ -718,6 +717,17 @@ importers: specifier: ^0.11.0 version: 0.11.0(@babel/core@7.26.0) + tests/integration/redirect/js: + devDependencies: + '@types/lodash': + specifier: ^4.17.13 + version: 4.17.13 + lodash: + specifier: ^4.17.21 + version: 4.17.21 + + tests/integration/redirect/style-false: {} + tests/integration/require/import-dynamic: {} tests/integration/require/require-as-expression: {} @@ -782,8 +792,6 @@ importers: specifier: 2.0.0 version: 2.0.0 - tests/integration/style/redirect-style-false: {} - tests/integration/style/sass/bundle: {} tests/integration/style/sass/bundle-false: {} @@ -1595,7 +1603,7 @@ packages: '@module-federation/rspack@0.8.4': resolution: {integrity: sha512-fx5u+xTdVQ4EMD6yPZwdt85eORwZtkBPJtr00qvl45LDDxbF9JiII3Ii9afyYtnwAlVSPgeKx4nSICoNuHXP1A==} peerDependencies: - '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 + '@rspack/core': '>=0.7' typescript: ^4.9.0 || ^5.0.0 vue-tsc: '>=1.0.24' peerDependenciesMeta: @@ -1921,56 +1929,56 @@ packages: typescript: optional: true - '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-vwonCXADq2TzpPcgQvZBgMq420VyLvVkYZjlaXm8jofntPHqFwNr0gjAh05S0kUVdePkkAxL64fG4fd91GbSJg==} - - '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-XVy8bM182HJWVEWCwpd5xzhMO3FXFJg9U/gfjjvKlZ1LpZps3Oe5gtdtAp6GC+3gN90o+NfBiEKyGKBDGhh0IQ==} + '@rspack/binding-darwin-arm64@1.1.6': + resolution: {integrity: sha512-x9dxm2yyiMuL1FBwvWNNMs2/mEUJmRoSRgYb8pblR7HDaTRORrjBFCqhaYlGyAqtQaeUy7o2VAQlE0BavIiFYA==} cpu: [arm64] os: [darwin] - '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-xRSLjZX9FvmZSz5QzPs3nZH/S0LkbrO3sXWFK+FauJHzELHQQdilzMP6jpiMaVBbOF6qUNGuPKzDml89HNPfLg==} + '@rspack/binding-darwin-x64@1.1.6': + resolution: {integrity: sha512-o0seilveftGiDjy3VPxug20HmAgYyQbNEuagR3i93/t/PT/eWXHnik+C1jjwqcivZL1Zllqvy4tbZw393aROEQ==} cpu: [x64] os: [darwin] - '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-JLLdSQ7YSKtzwGTvBc/WPIpCItLe9G38aC3zfLNVrg1CTenwOtRQIP/raL246uH2OI3NMZ1gmW7VE7B/omOBXg==} + '@rspack/binding-linux-arm64-gnu@1.1.6': + resolution: {integrity: sha512-4atnoknJx/c3KaQElsMIxHMpPf2jcRRdWsH/SdqJIRSrkWWakMK9Yv4TFwH680I4HDTMf1XLboMVScHzW8e+Mg==} cpu: [arm64] os: [linux] - '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-sgFq/SdC64S2u1dPbPMpnytgr9TWcDZXutFn9eLSGltH11dbulVhGLDN6IBNP//GANlAkfW077zfxSrgjhZr7A==} + '@rspack/binding-linux-arm64-musl@1.1.6': + resolution: {integrity: sha512-7QMtwUtgFpt3/Y3/X18fSyN+kk4H8ZnZ8tDzQskVWc/j2AQYShZq56XQYqrhClzwujcCVAHauIQ2eiuJ2ASGag==} cpu: [arm64] os: [linux] - '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-++c+hcxNgyL6x561043XemfSRUKjqRJQ8gLvt0dhdPYVfBdz7tC4S+wrxRyGSWPCoOuPNAz2JYby/G4SK+0FiQ==} + '@rspack/binding-linux-x64-gnu@1.1.6': + resolution: {integrity: sha512-MTjDEfPn4TwHoqs5d5Fck06kmXiTHZctGIcRVfrpg0RK0r1NLEHN+oosavRZ9c9H70f34+NmcHk+/qvV4c8lWg==} cpu: [x64] os: [linux] - '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-tk5O4ANmvhdOD2fWEH/gDlQO6PAMkGwaXiNG7OPfA59ZesPJ2b6IkYzRr0K5UsUGVBR0/ZJGrLd9ugRDLaxzyw==} + '@rspack/binding-linux-x64-musl@1.1.6': + resolution: {integrity: sha512-LqDw7PTVr/4ZuGA0izgDQfamfr72USFHltR1Qhy2YVC3JmDmhG/pQi13LHcOLVaGH1xoeyCmEPNJpVizzDxSjg==} cpu: [x64] os: [linux] - '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-ubJmhOYkxJmYfZ7nhifMQuKzmTrzjuhyJbLdnw9v9LdTgY9qkPvHoPBv7cI0LU0fj7DNfSlBW4ffLTY43qEhtQ==} + '@rspack/binding-win32-arm64-msvc@1.1.6': + resolution: {integrity: sha512-RHApLM93YN0WdHpS35u2cm7VCqZ8Yg3CrNRL16VJtyT9e6MBqeScoe4XIgIWKPm7edFyedYAjLX0wQOApwfjkg==} cpu: [arm64] os: [win32] - '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-JJPyGdr4CrH6XIbF4fPSYL/hup6Cx+aGlsuCFdKqS3nrnTKmETFLf6A6q5FzZExYwdRCdA+yjpaBhdHzEYQQ4w==} + '@rspack/binding-win32-ia32-msvc@1.1.6': + resolution: {integrity: sha512-Y6lx4q0eJawRfMPBo/AclTJAPTZ325DSPFBQJB3TnWh9Z2X7P7pQcYc8PHDmfDuYRIdg5WRsQRvVxihSvF7v8w==} cpu: [ia32] os: [win32] - '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-ik9bHH1T1W5UgKvxqt12nQQg+lllrxMn1HUbGBINz/zsjEIycxwqCvoAIazCj4JLYyDntpxPNLFULwId/yx8UQ==} + '@rspack/binding-win32-x64-msvc@1.1.6': + resolution: {integrity: sha512-UuCsfhC/yNuU7xLASOxNXcmsXi2ZvBX14GkxvcdChw6q7IIGNYUKXo1zgR8C1PE/6qDSxmLxbRMS+71d0H3HQg==} cpu: [x64] os: [win32] - '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520': - resolution: {integrity: sha512-OwWxxVd9TnWaBnug2SAGmyl7VNR3MVGCwstXXhTAUCh0UTX/lQjmIKERm/tcHQyD04bOCeb+VXoj9qZT3PRbrg==} + '@rspack/binding@1.1.6': + resolution: {integrity: sha512-vfeBEgGOYVwqj5cQjGyvdfrr/BEihAHlyIsobL98FZjTF0uig+bj2yJUH5Ib5F0BpIUKVG3Pw0IjlUBqcVpZsQ==} + + '@rspack/core@1.1.6': + resolution: {integrity: sha512-q0VLphOF5VW2FEG7Vbdq3Ke4I74FbELE/8xmKghSalFtULLZ44SoSz8lyotfMim9GXIRFhDokAaH8WICmPxG+g==} engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -6038,7 +6046,7 @@ packages: resolution: {integrity: sha512-K5BUrytoFju1Olu11T49vlYvDEGOguBF1CBCl4o2ARxDGPoJHHf7fBzLlK0YYkUqI5EFA5cMRUC6332M7hQBHw==} engines: {node: '>=16.0.0'} peerDependencies: - '@rspack/core': npm:@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520 + '@rspack/core': ^1.0.0 typescript: '>=3.8.0' peerDependenciesMeta: '@rspack/core': @@ -7270,14 +7278,14 @@ snapshots: - supports-color - utf-8-validate - '@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': + '@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1)': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.4 '@module-federation/data-prefetch': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@module-federation/dts-plugin': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/managers': 0.8.4 '@module-federation/manifest': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) - '@module-federation/rspack': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) + '@module-federation/rspack': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 btoa: 1.2.1 @@ -7318,13 +7326,13 @@ snapshots: - utf-8-validate - vue-tsc - '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': + '@module-federation/rsbuild-plugin@0.8.4(@module-federation/enhanced@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1))(@rsbuild/core@1.1.10)': dependencies: - '@module-federation/enhanced': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 '@rsbuild/core': 1.1.10 - '@module-federation/rspack@0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': + '@module-federation/rspack@0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.4 '@module-federation/dts-plugin': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) @@ -7332,6 +7340,7 @@ snapshots: '@module-federation/manifest': 0.8.4(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3)) '@module-federation/runtime-tools': 0.8.4 '@module-federation/sdk': 0.8.4 + '@rspack/core': 1.1.6(@swc/helpers@0.5.15) optionalDependencies: typescript: 5.6.3 vue-tsc: 2.1.10(typescript@5.6.3) @@ -7366,9 +7375,9 @@ snapshots: dependencies: isomorphic-rslog: 0.0.6 - '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': + '@module-federation/storybook-addon@3.0.15(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack-virtual-modules@0.6.2)(webpack@5.96.1)': dependencies: - '@module-federation/enhanced': 0.8.4(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) + '@module-federation/enhanced': 0.8.4(@rspack/core@1.1.6(@swc/helpers@0.5.15))(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(typescript@5.6.3)(vue-tsc@2.1.10(typescript@5.6.3))(webpack@5.96.1) '@module-federation/sdk': 0.8.4 optionalDependencies: '@rsbuild/core': 1.1.10 @@ -7526,7 +7535,7 @@ snapshots: '@rsbuild/core@1.1.10': dependencies: - '@rspack/core': '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)' + '@rspack/core': 1.1.6(@swc/helpers@0.5.15) '@rspack/lite-tapable': 1.0.1 '@swc/helpers': 0.5.15 core-js: 3.39.0 @@ -7617,12 +7626,12 @@ snapshots: - supports-color - typescript - '@rsbuild/plugin-type-check@1.1.0(@rsbuild/core@1.1.10)(typescript@5.6.3)': + '@rsbuild/plugin-type-check@1.1.0(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3)': dependencies: deepmerge: 4.3.1 json5: 2.2.3 reduce-configs: 1.1.0 - ts-checker-rspack-plugin: 1.0.3(typescript@5.6.3) + ts-checker-rspack-plugin: 1.0.3(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3) optionalDependencies: '@rsbuild/core': 1.1.10 transitivePeerDependencies: @@ -7651,49 +7660,49 @@ snapshots: '@microsoft/api-extractor': 7.48.1(@types/node@22.8.1) typescript: 5.6.3 - '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520': - optionalDependencies: - '@rspack/binding-darwin-arm64': '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-darwin-x64': '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-linux-arm64-gnu': '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-linux-arm64-musl': '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-linux-x64-gnu': '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-linux-x64-musl': '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-win32-arm64-msvc': '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-win32-ia32-msvc': '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' - '@rspack/binding-win32-x64-msvc': '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520' - - '@rspack/binding-darwin-arm64-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-darwin-arm64@1.1.6': optional: true - '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-darwin-x64@1.1.6': optional: true - '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-linux-arm64-gnu@1.1.6': optional: true - '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-linux-arm64-musl@1.1.6': optional: true - '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-linux-x64-gnu@1.1.6': optional: true - '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-linux-x64-musl@1.1.6': optional: true - '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-win32-arm64-msvc@1.1.6': optional: true - '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-win32-ia32-msvc@1.1.6': optional: true - '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + '@rspack/binding-win32-x64-msvc@1.1.6': optional: true - '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)': + '@rspack/binding@1.1.6': + optionalDependencies: + '@rspack/binding-darwin-arm64': 1.1.6 + '@rspack/binding-darwin-x64': 1.1.6 + '@rspack/binding-linux-arm64-gnu': 1.1.6 + '@rspack/binding-linux-arm64-musl': 1.1.6 + '@rspack/binding-linux-x64-gnu': 1.1.6 + '@rspack/binding-linux-x64-musl': 1.1.6 + '@rspack/binding-win32-arm64-msvc': 1.1.6 + '@rspack/binding-win32-ia32-msvc': 1.1.6 + '@rspack/binding-win32-x64-msvc': 1.1.6 + + '@rspack/core@1.1.6(@swc/helpers@0.5.15)': dependencies: '@module-federation/runtime-tools': 0.5.1 - '@rspack/binding': '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520' + '@rspack/binding': 1.1.6 '@rspack/lite-tapable': 1.0.1 caniuse-lite: 1.0.30001680 optionalDependencies: @@ -12107,18 +12116,18 @@ snapshots: stdin-discarder@0.2.2: {} - storybook-addon-rslib@0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3): + storybook-addon-rslib@0.1.6(@rsbuild/core@1.1.10)(@rslib/core@packages+core)(storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3))(typescript@5.6.3): dependencies: '@rsbuild/core': 1.1.10 '@rslib/core': link:packages/core - storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) + storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) optionalDependencies: typescript: 5.6.3 - storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3): + storybook-builder-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3): dependencies: '@rsbuild/core': 1.1.10 - '@rsbuild/plugin-type-check': 1.1.0(@rsbuild/core@1.1.10)(typescript@5.6.3) + '@rsbuild/plugin-type-check': 1.1.0(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3) '@storybook/addon-docs': 8.4.2(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(webpack-sources@3.2.3) '@storybook/core-webpack': 8.4.2(storybook@8.4.7(prettier@3.4.2)) browser-assert: 1.2.1 @@ -12144,7 +12153,7 @@ snapshots: - '@types/react' - webpack-sources - storybook-react-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1): + storybook-react-rsbuild@0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(rollup@4.18.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3)(webpack@5.96.1): dependencies: '@rollup/pluginutils': 5.1.3(rollup@4.18.1) '@rsbuild/core': 1.1.10 @@ -12158,7 +12167,7 @@ snapshots: react-dom: 19.0.0(react@19.0.0) resolve: 1.22.8 storybook: 8.4.7(prettier@3.4.2) - storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) + storybook-builder-rsbuild: 0.1.6(@rsbuild/core@1.1.10)(@rspack/core@1.1.6(@swc/helpers@0.5.15))(@types/react@19.0.1)(storybook@8.4.7(prettier@3.4.2))(typescript@5.6.3)(webpack-sources@3.2.3) tsconfig-paths: 4.2.0 optionalDependencies: typescript: 5.6.3 @@ -12425,7 +12434,7 @@ snapshots: trough@2.2.0: {} - ts-checker-rspack-plugin@1.0.3(typescript@5.6.3): + ts-checker-rspack-plugin@1.0.3(@rspack/core@1.1.6(@swc/helpers@0.5.15))(typescript@5.6.3): dependencies: '@babel/code-frame': 7.26.2 '@rspack/lite-tapable': 1.0.1 @@ -12434,6 +12443,8 @@ snapshots: minimatch: 9.0.5 picocolors: 1.1.1 typescript: 5.6.3 + optionalDependencies: + '@rspack/core': 1.1.6(@swc/helpers@0.5.15) ts-dedent@2.2.0: {} diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index 42c1e57e0..c53182640 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -1,5 +1,13 @@ # lib.redirect +:::info + +Redirect is the specific configuration for bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`). It will not take effect in bundle mode because, all output files are packaged into a single file. As a result, import paths do not exist and do not need to be redirected. + +As bundleless mode is still under development, additional redirect configurations will be introduced in the future. + +::: + - **Type:** ```ts @@ -26,57 +34,74 @@ const defaultRedirect = { }; ``` -Configure the redirect of the import paths. +Configure the redirect for import paths in output files. In bundleless mode, there are often needs such as using aliases or automatically appending suffixes for ESM products. The `redirect` configuration is designed to address these issues. -When `bundle: false`, the import path is redirected to ensure that it points to the correct output. +Common scenarios that require redirect: -:::note +- Automatically convert tsconfig.json paths to correct relative path -As bundleless mode is still under development, additional redirect configurations will be introduced in the future. + For example, set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in tsconfig.json, the output file will be redirected to the correct relative path: -::: + ```ts + import { foo } from '@/foo'; // source code of './src/bar.ts' ↓ + import { foo } from './foo.js'; // expected output of './dist/bar.js' -If you don't need these redirects, you can turn it off, and its import path will not be changed. - -```ts title="rslib.config.ts" -export default { - lib: [ - { - redirect: { - style: false, // Turn off the redirect of the style file - }, - }, - ], -}; -``` + import { foo } from '@/foo'; // source code of './src/utils/index.ts' ↓ + import { foo } from '../foo.js'; // expected output './dist/utils/index.js' + ``` + +- Automatically append file suffix + + For ESM products that run in Node.js, you must specify the exact full path for the module import to load correctly. Rslib will automatically add the suffix based on the output file. + + ```ts + import { foo } from './foo'; // source code of './src/bar.ts' ↓ + import { foo } from './foo.mjs'; // expected output of './dist/bar.js' + + import { foo } from './foo.ts'; // source code of './src/utils/index.ts' ↓ + import { foo } from './foo.mjs'; // expected output './dist/utils/index.js' + ``` ## redirect.js Controls the redirect of the import paths of output JavaScript files. +:::warning +When [output.externals](/config/rsbuild/output#outputexternals) is configured and a request is matched, neither `redirect.js.path` nor `redirect.js.extension` will take effect, and the final rewritten request path will be entirely controlled by [output.externals](/config/rsbuild/output#outputexternals). +::: + ### redirect.js.path -Whether to automatically redirect the import paths of JavaScript output files, compilerOptions.paths in tsconfig.json will be applied by default. +Whether to automatically redirect the import paths of JavaScript output files. - **Type:** `boolean` - **Default:** `true` +When set to `true`, [resolve.alias](/config/rsbuild/resolve#resolvealias) and [resolve.aliasStrategy](/config/resolve/alias-strategy) will take effect and applied in the rewritten import path of the output file. For TypeScript projects, you only need to configure [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) in the tsconfig.json file. + +When set to `false`, the import path will not be effected by [resolve.alias](/config/rsbuild/resolve#resolvealias), [resolve.aliasStrategy](/config/resolve/alias-strategy) and tsconfig.json. + ### redirect.js.extension -Whether to automatically add the file extension based on the JavaScript output files. +Whether to automatically add the file extension to import paths based on the JavaScript output files. - **Type:** `boolean` - **Default:** `true` -:::warning -When [output.externals](/config/rsbuild/output#outputexternals) is configured and a request is matched, neither `redirect.js.path` nor `redirect.js.extension` will take effect, and the final rewritten request path will be entirely controlled by [output.externals](/config/rsbuild/output#outputexternals). -::: +When set to `true`, the file extension will automatically be added to the rewritten import path of the output file, regardless of the original extension or whether it is specified in the import path. + +When set to `false`, the file extension will remain unchanged from the original import path in the rewritten import path of the output file (regardless of whether it is specified or specified as any value). ## redirect.style - **Type:** `boolean` - **Default:** `true` -Whether to redirect the import path of the style file. For example: +Whether to redirect the import path of the style file. -- `import './index.less'` will be rewritten to `import './index.css'` +For example, when importing a `.less` file, it will be rewritten to a `.css` file: + +```ts +import './index.less'; // source code ↓ +import './index.css'; // output file +``` diff --git a/website/docs/zh/config/lib/redirect.mdx b/website/docs/zh/config/lib/redirect.mdx index 668f7dacd..60f98d059 100644 --- a/website/docs/zh/config/lib/redirect.mdx +++ b/website/docs/zh/config/lib/redirect.mdx @@ -1,50 +1,107 @@ # lib.redirect -- **类型:** +:::info + +Redirect 是 bundleless 模式(将 [lib.bundle](/config/lib/bundle) 设置为 `false`)的特定配置。在 bundle 模式下不会生效,因为所有输出文件都被打包成一个文件。所以,导入路径不存在因而不需要重定向。 + +由于 bundleless 模式仍在开发中,未来将引入更多的重定向配置。 + +::: + +- **Type:** ```ts +type JsRedirect = { + path?: boolean; + extension?: boolean; +}; + type Redirect = { + js?: JsRedirect; style?: boolean; }; ``` -- **默认值:** +- **Default:** ```ts const defaultRedirect = { + js: { + path: true, + extension: true, + }, style: true, }; ``` -配置导入路径的重定向。 +配置输出文件中导入路径的重定向。在 bundleless 模式下,通常需要使用别名或自动添加 ESM 产物的后缀。`redirect` 配置旨在解决这些问题。 + +常见的需要 redirect 的场景: + +- 自动将 tsconfig.json 路径转换为正确的相对路径 + + 例如,在 tsconfig.json 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }`,输出文件将被重定向到正确的相对路径: + + ```ts + import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓ + import { foo } from './foo.js'; // './dist/bar.js' 预期生成的代码 + + import { foo } from '@/foo'; // './src/utils/index.ts' 的源码 ↓ + import { foo } from '../foo.js'; // './dist/utils/index.js' 预期生成的代码 + ``` + +- 自动添加文件后缀 + + 对于在 Node.js 中运行的 ESM 产物,必须指定模块导入的完整路径才能正确加载。Rslib 将根据输出文件自动添加后缀。 + + ```ts + import { foo } from './foo'; // './src/bar.ts' 的源码 ↓ + import { foo } from './foo.mjs'; // './dist/bar.js' 预期生成的代码 -当 `bundle: false` 时,会对导入路径进行重定向,以确保它指向正确的输出。 + import { foo } from './foo.ts'; // './src/utils/index.ts' 的源码 ↓ + import { foo } from './foo.mjs'; // './dist/utils/index.js' 预期生成的代码 + ``` -:::note +## redirect.js -由于 bundleless 模式仍在开发中,未来会引入更多重定向配置。 +控制输出 JavaScript 文件导入路径的重定向。 +:::warning +当 [output.externals](/config/rsbuild/output#outputexternals) 被配置且请求被匹配时,`redirect.js.path` 和 `redirect.js.extension` 都不会生效,最终重写的请求路径将完全由 [output.externals](/config/rsbuild/output#outputexternals) 控制。 ::: -如果你不需要这些重定向,可以关闭它,这样导入路径将保持不变。 - -```ts title="rslib.config.ts" -export default { - lib: [ - { - redirect: { - style: false, // 关闭样式文件的重定向 - }, - }, - ], -}; -``` +### redirect.js.path + +是否自动重定向 JavaScript 输出文件的导入路径。 + +- **类型:** `boolean` +- **默认值:** `true` + +当设置为 `true` 时,[resolve.alias](/config/rsbuild/resolve#resolvealias) 和 [resolve.aliasStrategy](/config/resolve/alias-strategy) 将生效并应用于输出文件的重写导入路径。对于 TypeScript 项目,您只需在 tsconfig.json 文件中配置 [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths)。 + +当设置为 `false` 时,导入路径将不受 [resolve.alias](/config/rsbuild/resolve#resolvealias)、[resolve.aliasStrategy](/config/resolve/alias-strategy) 和 tsconfig.json 的影响。 + +### redirect.js.extension + +是否根据 JavaScript 输出文件自动添加文件扩展名到导入路径。 + +- **类型:** `boolean` +- **默认值:** `true` + +当设置为 `true` 时,无论原始扩展名或导入路径中是否指定,文件扩展名都将自动添加到输出文件的重写导入路径中。 + +当设置为 `false` 时,文件扩展名将保持原始导入路径中的不变(无论是否指定或指定为任意值)。 ## redirect.style -- **类型:** `boolean` -- **默认值:** `true` +- **类型:** `boolean` +- **默认值:** `true` -是否重定向样式文件的导入路径。例如: +是否重定向样式文件的导入路径。 -- `import './index.less'` 将被重写为 `import './index.css'` +例如,当导入 `.less` 文件时,它将被重写为 `.css` 文件: + +```ts +import './index.less'; // source code ↓ +import './index.css'; // output file +``` From 1981e358c43f5a446e91d31437861a468ef27d62 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 17:52:40 +0800 Subject: [PATCH 06/13] test alias --- tests/integration/redirect/js.test.ts | 18 ++++++++++++------ tests/integration/redirect/js/rslib.config.ts | 7 +++++-- tests/integration/redirect/js/src/baz.ts | 1 + tests/integration/redirect/js/src/index.ts | 3 ++- .../index.test.ts => style.test.ts} | 3 ++- 5 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 tests/integration/redirect/js/src/baz.ts rename tests/integration/redirect/{style-false/index.test.ts => style.test.ts} (90%) diff --git a/tests/integration/redirect/js.test.ts b/tests/integration/redirect/js.test.ts index beadceda3..680ce8179 100644 --- a/tests/integration/redirect/js.test.ts +++ b/tests/integration/redirect/js.test.ts @@ -23,7 +23,8 @@ test('redirect.js default', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar); + import * as __WEBPACK_EXTERNAL_MODULE__baz_js__ from "./baz.js"; + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__baz_js__.baz); export { src_rslib_entry_ as default }; " `); @@ -32,7 +33,7 @@ test('redirect.js default', async () => { const cjsResult = await import(indexCjsPath); expect(esmResult.default).toEqual(cjsResult.default); - expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1FOOBAR1"`); + expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1FOOBAR1BAZ"`); }); test('redirect.js.path false', async () => { @@ -45,9 +46,10 @@ test('redirect.js.path false', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "@/bar.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "@/foo.js"; + import * as __WEBPACK_EXTERNAL_MODULE__baz_js__ from "~/baz.js"; import * as __WEBPACK_EXTERNAL_MODULE__bar_js__ from "./bar.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_js__.bar + __WEBPACK_EXTERNAL_MODULE__baz_js__.baz); export { src_rslib_entry_ as default }; " `); @@ -67,9 +69,10 @@ test('redirect.js.path with user override externals', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__ from "./others/bar/index.js"; import * as __WEBPACK_EXTERNAL_MODULE__others_foo_js__ from "./others/foo.js"; + import * as __WEBPACK_EXTERNAL_MODULE__baz_js__ from "./baz.js"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_js__ from "./bar/index.js"; import * as __WEBPACK_EXTERNAL_MODULE__foo_js__ from "./foo.js"; - const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__others_foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__.bar); + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__others_foo_js__.foo + __WEBPACK_EXTERNAL_MODULE__others_bar_index_js__.bar + __WEBPACK_EXTERNAL_MODULE__baz_js__.baz); export { src_rslib_entry_ as default }; " `); @@ -78,7 +81,9 @@ test('redirect.js.path with user override externals', async () => { const cjsResult = await import(indexCjsPath); expect(esmResult.default).toEqual(cjsResult.default); - expect(esmResult.default).toMatchInlineSnapshot(`"FOOBAR1OTHERFOOOTHERBAR2"`); // cspell:disable-line + expect(esmResult.default).toMatchInlineSnapshot( + `"FOOBAR1OTHERFOOOTHERBAR2BAZ"`, + ); // cspell:disable-line }); test('redirect.js.extension: false', async () => { @@ -90,7 +95,8 @@ test('redirect.js.extension: false', async () => { "import * as __WEBPACK_EXTERNAL_MODULE_lodash__ from "lodash"; import * as __WEBPACK_EXTERNAL_MODULE__bar_index_ts__ from "./bar/index.ts"; import * as __WEBPACK_EXTERNAL_MODULE__foo_ts__ from "./foo.ts"; - const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar); + import * as __WEBPACK_EXTERNAL_MODULE__baz_ts__ from "./baz.ts"; + const src_rslib_entry_ = __WEBPACK_EXTERNAL_MODULE_lodash__["default"].toUpper(__WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__foo_ts__.foo + __WEBPACK_EXTERNAL_MODULE__bar_index_ts__.bar + __WEBPACK_EXTERNAL_MODULE__baz_ts__.baz); export { src_rslib_entry_ as default }; " `); diff --git a/tests/integration/redirect/js/rslib.config.ts b/tests/integration/redirect/js/rslib.config.ts index ab17005d1..57f655801 100644 --- a/tests/integration/redirect/js/rslib.config.ts +++ b/tests/integration/redirect/js/rslib.config.ts @@ -100,10 +100,13 @@ export default defineConfig({ }, }), ], - + resolve: { + alias: { + '~': './src', + }, + }, source: { entry: { - // index: '../__fixtures__/src', index: './src/**', }, }, diff --git a/tests/integration/redirect/js/src/baz.ts b/tests/integration/redirect/js/src/baz.ts new file mode 100644 index 000000000..6061cf077 --- /dev/null +++ b/tests/integration/redirect/js/src/baz.ts @@ -0,0 +1 @@ +export const baz = 'baz'; diff --git a/tests/integration/redirect/js/src/index.ts b/tests/integration/redirect/js/src/index.ts index 72d073a11..8762f61c6 100644 --- a/tests/integration/redirect/js/src/index.ts +++ b/tests/integration/redirect/js/src/index.ts @@ -2,7 +2,8 @@ import lodash from 'lodash'; import { bar as bar2 } from '@/bar'; import { foo as foo2 } from '@/foo'; +import { baz } from '~/baz'; import { bar } from './bar'; import { foo } from './foo'; -export default lodash.toUpper(foo + bar + foo2 + bar2); +export default lodash.toUpper(foo + bar + foo2 + bar2 + baz); diff --git a/tests/integration/redirect/style-false/index.test.ts b/tests/integration/redirect/style.test.ts similarity index 90% rename from tests/integration/redirect/style-false/index.test.ts rename to tests/integration/redirect/style.test.ts index 2380343fc..48bcf496c 100644 --- a/tests/integration/redirect/style-false/index.test.ts +++ b/tests/integration/redirect/style.test.ts @@ -1,9 +1,10 @@ +import path from 'node:path'; import { buildAndGetResults } from 'test-helper'; import { expectFileContainContent } from 'test-helper/vitest'; import { expect, test } from 'vitest'; test('should extract css successfully when using redirect.style = false', async () => { - const fixturePath = __dirname; + const fixturePath = path.resolve(__dirname, './style-false'); const { contents } = await buildAndGetResults({ fixturePath }); const esmFiles = Object.keys(contents.esm); expect(esmFiles).toMatchInlineSnapshot(` From 36afcb4123db9f3c8173efecbdd68aa1a8654dc4 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 17:55:07 +0800 Subject: [PATCH 07/13] fix doc --- website/docs/en/config/lib/redirect.mdx | 4 ++-- website/docs/zh/config/lib/redirect.mdx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index c53182640..ad7ebd068 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -77,9 +77,9 @@ Whether to automatically redirect the import paths of JavaScript output files. - **Type:** `boolean` - **Default:** `true` -When set to `true`, [resolve.alias](/config/rsbuild/resolve#resolvealias) and [resolve.aliasStrategy](/config/resolve/alias-strategy) will take effect and applied in the rewritten import path of the output file. For TypeScript projects, you only need to configure [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) in the tsconfig.json file. +When set to `true`, [resolve.alias](/config/rsbuild/resolve#resolvealias) and [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) will take effect and applied in the rewritten import path of the output file. For TypeScript projects, you only need to configure [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) in the tsconfig.json file. -When set to `false`, the import path will not be effected by [resolve.alias](/config/rsbuild/resolve#resolvealias), [resolve.aliasStrategy](/config/resolve/alias-strategy) and tsconfig.json. +When set to `false`, the import path will not be effected by [resolve.alias](/config/rsbuild/resolve#resolvealias), [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) and tsconfig.json. ### redirect.js.extension diff --git a/website/docs/zh/config/lib/redirect.mdx b/website/docs/zh/config/lib/redirect.mdx index 60f98d059..5e129ef4a 100644 --- a/website/docs/zh/config/lib/redirect.mdx +++ b/website/docs/zh/config/lib/redirect.mdx @@ -77,9 +77,9 @@ const defaultRedirect = { - **类型:** `boolean` - **默认值:** `true` -当设置为 `true` 时,[resolve.alias](/config/rsbuild/resolve#resolvealias) 和 [resolve.aliasStrategy](/config/resolve/alias-strategy) 将生效并应用于输出文件的重写导入路径。对于 TypeScript 项目,您只需在 tsconfig.json 文件中配置 [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths)。 +当设置为 `true` 时,[resolve.alias](/config/rsbuild/resolve#resolvealias) 和 [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) 将生效并应用于输出文件的重写导入路径。对于 TypeScript 项目,您只需在 tsconfig.json 文件中配置 [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths)。 -当设置为 `false` 时,导入路径将不受 [resolve.alias](/config/rsbuild/resolve#resolvealias)、[resolve.aliasStrategy](/config/resolve/alias-strategy) 和 tsconfig.json 的影响。 +当设置为 `false` 时,导入路径将不受 [resolve.alias](/config/rsbuild/resolve#resolvealias)、[resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) 和 tsconfig.json 的影响。 ### redirect.js.extension From 0c21893c02271bae175a146435dc097905e8fdf8 Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 18:32:50 +0800 Subject: [PATCH 08/13] lint --- tests/integration/redirect/js.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/redirect/js.test.ts b/tests/integration/redirect/js.test.ts index 680ce8179..32009b219 100644 --- a/tests/integration/redirect/js.test.ts +++ b/tests/integration/redirect/js.test.ts @@ -82,8 +82,8 @@ test('redirect.js.path with user override externals', async () => { expect(esmResult.default).toEqual(cjsResult.default); expect(esmResult.default).toMatchInlineSnapshot( - `"FOOBAR1OTHERFOOOTHERBAR2BAZ"`, - ); // cspell:disable-line + `"FOOBAR1OTHERFOOOTHERBAR2BAZ"`, // cspell:disable-line + ); }); test('redirect.js.extension: false', async () => { From 87d5b0769ed2b4b92f53cdd02e3c8eca637980ec Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 18:55:48 +0800 Subject: [PATCH 09/13] fix --- packages/core/src/config.ts | 70 +++++++++++++++++-------------- packages/core/src/types/config.ts | 8 ++-- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 0a5ecefac..b92793462 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -1015,18 +1015,14 @@ const composeBundlelessExternalConfig = ( return cssExternal; } - // Node.js ECMAScript module loader does no extension searching. - // Add a file extension according to autoExtension config - // when data.request is a relative path and do not have an extension. - // If data.request already have an extension, we replace it with new extension - // This may result in a change in semantics, - // user should use copy to keep origin file or use another separate entry to deal this - if (jsRedirectPath) { try { resolvedRequest = await resolver(context, resolvedRequest); } catch (e) { // Do nothing, fallthrough to other external matches. + logger.debug( + `Failed to resolve ${resolvedRequest} with resolver`, + ); } resolvedRequest = normalizeSlash( @@ -1041,6 +1037,12 @@ const composeBundlelessExternalConfig = ( } } + // Node.js ECMAScript module loader does no extension searching. + // Add a file extension according to autoExtension config + // when data.request is a relative path and do not have an extension. + // If data.request already have an extension, we replace it with new extension + // This may result in a change in semantics, + // user should use copy to keep origin file or use another separate entry to deal this if (jsRedirectExtension) { const ext = extname(resolvedRequest); if (ext) { @@ -1054,7 +1056,6 @@ const composeBundlelessExternalConfig = ( return callback(); } } else { - // TODO: add redirect.extension option resolvedRequest = `${resolvedRequest}${jsExtension}`; } } @@ -1106,17 +1107,15 @@ const composeDtsConfig = async ( }; const composeTargetConfig = ( - target: RsbuildConfigOutputTarget, + userTarget: RsbuildConfigOutputTarget, format: Format, ): { config: RsbuildConfig; + externalsConfig: RsbuildConfig; target: RsbuildConfigOutputTarget; } => { - let defaultTarget = target; - if (!defaultTarget) { - defaultTarget = format === 'mf' ? 'web' : 'node'; - } - switch (defaultTarget) { + const target = userTarget ?? (format === 'mf' ? 'web' : 'node'); + switch (target) { case 'web': return { config: { @@ -1127,6 +1126,7 @@ const composeTargetConfig = ( }, }, target: 'web', + externalsConfig: {}, }; case 'node': return { @@ -1136,15 +1136,19 @@ const composeTargetConfig = ( target: ['node'], }, }, + output: { + target: 'node', + }, + }, + target: 'node', + externalsConfig: { output: { // When output.target is 'node', Node.js's built-in will be treated as externals of type `node-commonjs`. // Simply override the built-in modules to make them external. // https://github.com/webpack/webpack/blob/dd44b206a9c50f4b4cb4d134e1a0bd0387b159a3/lib/node/NodeTargetPlugin.js#L81 externals: nodeBuiltInModules, - target: 'node', }, }, - target: 'node', }; // TODO: Support `neutral` target, however Rsbuild don't list it as an option in the target field. // case 'neutral': @@ -1156,7 +1160,7 @@ const composeTargetConfig = ( // }, // }; default: - throw new Error(`Unsupported platform: ${defaultTarget}`); + throw new Error(`Unsupported platform: ${target}`); } }; @@ -1241,7 +1245,7 @@ async function composeLibRsbuildConfig( externalHelpers, pkgJson, ); - const userExternalConfig = composeExternalsConfig( + const userExternalsConfig = composeExternalsConfig( format!, config.output?.externals, ); @@ -1256,10 +1260,11 @@ async function composeLibRsbuildConfig( cssModulesAuto, bundle, ); - const { config: targetConfig, target } = composeTargetConfig( - config.output?.target, - format!, - ); + const { + config: targetConfig, + externalsConfig: targetExternalsConfig, + target, + } = composeTargetConfig(config.output?.target, format!); const syntaxConfig = composeSyntaxConfig(target, config?.syntax); const autoExternalConfig = composeAutoExternalConfig({ format: format!, @@ -1283,7 +1288,7 @@ async function composeLibRsbuildConfig( const externalsWarnConfig = composeExternalsWarnConfig( format!, autoExternalConfig?.output?.externals, - userExternalConfig?.output?.externals, + userExternalsConfig?.output?.externals, ); const minifyConfig = composeMinifyConfig(config); const bannerFooterConfig = composeBannerFooterConfig(banner, footer); @@ -1298,17 +1303,20 @@ async function composeLibRsbuildConfig( syntaxConfig, externalHelpersConfig, autoExtensionConfig, - - // `externalsWarnConfig` should before other externals config. + targetConfig, + // #region Externals configs + // The order of the externals config should come in the following order: + // 1. `externalsWarnConfig` should come before other externals config to touch the externalized modules first. + // 2. The externals config in `bundlelessExternalConfig` should present after other externals config as + // it relies on other externals config to bail out the externalized modules first then resolve + // the correct path for relative imports. + // 3. `userExternalsConfig` should present later to override the externals config of the ahead ones. externalsWarnConfig, autoExternalConfig, - targetConfig, - // The externals config in `bundleConfig` should present after all externals config as - // it relies on other externals config to bail out the externalized modules first then resolve - // the correct path for relative imports. - userExternalConfig, + targetExternalsConfig, + userExternalsConfig, bundlelessExternalConfig, - + // #endregion entryConfig, cssConfig, assetConfig, diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index dced7e635..f5d34f5c9 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -76,13 +76,12 @@ export type Shims = { export type JsRedirect = { /** - * Whether to automatically redirect the import paths of JavaScript output files, - * compilerOptions.paths in tsconfig.json will be applied by default. + * Whether to automatically redirect the import paths of JavaScript output files. * @defaultValue `true` */ path?: boolean; /** - * Whether to automatically add the file extension based on the JavaScript output files. + * Whether to automatically add the file extension to import paths based on the JavaScript output files. * @defaultValue `true` */ extension?: boolean; @@ -95,8 +94,9 @@ type DtsRedirect = { }; export type Redirect = { - /** Controls the redirect of the import paths of JavaScript output files. */ + /** Controls the redirect of the import paths of output JavaScript files. */ js?: JsRedirect; + /** Whether to redirect the import path of the style file. */ style?: boolean; // TODO: support other redirects // asset?: boolean; From 1f17f5e883351fc1e125f4f97f609a564598aeff Mon Sep 17 00:00:00 2001 From: Wei Date: Mon, 16 Dec 2024 20:52:02 +0800 Subject: [PATCH 10/13] Update website/docs/en/config/lib/redirect.mdx Co-authored-by: Timeless0911 <50201324+Timeless0911@users.noreply.github.com> --- website/docs/en/config/lib/redirect.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index ad7ebd068..2357f411f 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -2,7 +2,7 @@ :::info -Redirect is the specific configuration for bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`). It will not take effect in bundle mode because, all output files are packaged into a single file. As a result, import paths do not exist and do not need to be redirected. +Redirect is the unique configuration for bundleless mode (set [lib.bundle](/config/lib/bundle) to `false`). It will not take effect in bundle mode where all output files are packaged into a single file, eliminating the need for import path redirection. As bundleless mode is still under development, additional redirect configurations will be introduced in the future. From 1ebdcbbb2174c488d30ad11a7094bcaaf67c31c0 Mon Sep 17 00:00:00 2001 From: Wei Date: Mon, 16 Dec 2024 20:53:58 +0800 Subject: [PATCH 11/13] Update website/docs/en/config/lib/redirect.mdx Co-authored-by: Timeless0911 <50201324+Timeless0911@users.noreply.github.com> --- website/docs/en/config/lib/redirect.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index 2357f411f..1ef358dcd 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -38,7 +38,7 @@ Configure the redirect for import paths in output files. In bundleless mode, the Common scenarios that require redirect: -- Automatically convert tsconfig.json paths to correct relative path +- Automatically convert `paths` in `tsconfig.json` to correct relative path For example, set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in tsconfig.json, the output file will be redirected to the correct relative path: From c1afd8499eecba616e0104b09390f05d99b8200b Mon Sep 17 00:00:00 2001 From: fi3ework Date: Mon, 16 Dec 2024 20:55:15 +0800 Subject: [PATCH 12/13] cr1 --- packages/core/src/config.ts | 13 +++++-------- packages/core/src/types/config.ts | 6 +++++- website/docs/en/config/lib/redirect.mdx | 2 +- website/docs/zh/config/lib/redirect.mdx | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index b92793462..20a88592a 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -39,7 +39,6 @@ import type { DeepRequired, ExcludesFalse, Format, - GetAsyncFunctionFromUnion, JsRedirect, LibConfig, LibOnlyConfig, @@ -53,6 +52,7 @@ import type { RslibConfigAsyncFn, RslibConfigExport, RslibConfigSyncFn, + RspackResolver, Shims, Syntax, } from './types'; @@ -971,14 +971,11 @@ const composeBundlelessExternalConfig = ( } => { if (bundle) return { config: {} }; - const doesRedirectStyle = redirect.style ?? true; + const isStyleRedirected = redirect.style ?? true; const jsRedirectPath = redirect.js?.path ?? true; const jsRedirectExtension = redirect.js?.extension ?? true; - type Resolver = GetAsyncFunctionFromUnion< - ReturnType> - >; - let resolver: Resolver | undefined; + let resolver: RspackResolver | undefined; return { resolvedJsRedirect: { @@ -995,7 +992,7 @@ const composeBundlelessExternalConfig = ( } if (!resolver) { - resolver = (await getResolve()) as Resolver; + resolver = (await getResolve()) as RspackResolver; } // Issuer is not empty string when the module is imported by another module. @@ -1008,7 +1005,7 @@ const composeBundlelessExternalConfig = ( callback, jsExtension, cssModulesAuto, - doesRedirectStyle, + isStyleRedirected, ); if (cssExternal !== false) { diff --git a/packages/core/src/types/config.ts b/packages/core/src/types/config.ts index f5d34f5c9..8a45c09ed 100644 --- a/packages/core/src/types/config.ts +++ b/packages/core/src/types/config.ts @@ -1,5 +1,6 @@ -import type { RsbuildConfig } from '@rsbuild/core'; +import type { RsbuildConfig, Rspack } from '@rsbuild/core'; import type { PluginDtsOptions } from 'rsbuild-plugin-dts'; +import type { GetAsyncFunctionFromUnion } from './utils'; export type Format = 'esm' | 'cjs' | 'umd' | 'mf'; @@ -28,6 +29,9 @@ export type RsbuildConfigEntry = NonNullable< NonNullable['entry'] >; export type RsbuildConfigEntryItem = RsbuildConfigEntry[string]; +export type RspackResolver = GetAsyncFunctionFromUnion< + ReturnType> +>; export type RsbuildConfigOutputTarget = NonNullable< RsbuildConfig['output'] diff --git a/website/docs/en/config/lib/redirect.mdx b/website/docs/en/config/lib/redirect.mdx index 1ef358dcd..b48437afe 100644 --- a/website/docs/en/config/lib/redirect.mdx +++ b/website/docs/en/config/lib/redirect.mdx @@ -38,7 +38,7 @@ Configure the redirect for import paths in output files. In bundleless mode, the Common scenarios that require redirect: -- Automatically convert `paths` in `tsconfig.json` to correct relative path +- Automatically convert `compilerOptions.paths` in tsconfig.json to correct relative path For example, set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in tsconfig.json, the output file will be redirected to the correct relative path: diff --git a/website/docs/zh/config/lib/redirect.mdx b/website/docs/zh/config/lib/redirect.mdx index 5e129ef4a..e2bf63a84 100644 --- a/website/docs/zh/config/lib/redirect.mdx +++ b/website/docs/zh/config/lib/redirect.mdx @@ -38,7 +38,7 @@ const defaultRedirect = { 常见的需要 redirect 的场景: -- 自动将 tsconfig.json 路径转换为正确的相对路径 +- 自动将 tsconfig.json 中 `compilerOptions.paths` 转换为正确的相对路径 例如,在 tsconfig.json 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }`,输出文件将被重定向到正确的相对路径: From 2f03097695b0526f00d018f03c868731331f756e Mon Sep 17 00:00:00 2001 From: fi3ework Date: Wed, 18 Dec 2024 16:01:43 +0800 Subject: [PATCH 13/13] comment --- packages/core/src/config.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 20a88592a..0e6af6556 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -1029,6 +1029,9 @@ const composeBundlelessExternalConfig = ( ), ); + // Requests that fall through here cannot be matched by any other externals config ahead. + // Treat all these requests as relative import of source code. Node.js won't add the + // leading './' to the relative path resolved by `path.relative`. So add manually it here. if (resolvedRequest[0] !== '.') { resolvedRequest = `./${resolvedRequest}`; }