diff --git a/package.json b/package.json index beeacca54..fc8a4c6ed 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 3e3242436..67dbb699f 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -4,6 +4,7 @@ import { type EnvironmentConfig, type RsbuildConfig, type RsbuildPlugin, + type Rspack, defineConfig as defineRsbuildConfig, loadConfig as loadRsbuildConfig, mergeRsbuildConfig, @@ -36,6 +37,7 @@ import type { DeepRequired, ExcludesFalse, Format, + GetAsyncFunctionFromUnion, LibConfig, LibOnlyConfig, PkgJson, @@ -949,23 +951,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, @@ -976,27 +992,40 @@ const composeBundleConfig = ( return cssExternal; } - if (request[0] === '.') { - const ext = extname(request); + if (resolvedRequest[0] === '.') { + const resolved = await resolver(context, resolvedRequest); + resolvedRequest = path.posix.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/pnpm-lock.yaml b/pnpm-lock.yaml index 070780550..e27fdcc70 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: @@ -88,7 +89,7 @@ importers: devDependencies: '@module-federation/rsbuild-plugin': specifier: ^0.8.1 - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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) '@rsbuild/core': specifier: ~1.1.8 version: 1.1.8 @@ -109,13 +110,13 @@ importers: devDependencies: '@module-federation/enhanced': specifier: ^0.8.1 - version: 0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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) '@rsbuild/plugin-react': specifier: ^1.0.7 version: 1.0.7(@rsbuild/core@1.1.8) @@ -155,7 +156,7 @@ importers: devDependencies: '@module-federation/rsbuild-plugin': specifier: ^0.8.1 - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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) '@rsbuild/core': specifier: ~1.1.8 version: 1.1.8 @@ -383,7 +384,7 @@ importers: version: 3.1.1(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.1 - version: 0.8.1(@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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) + 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) '@playwright/test': specifier: 1.49.0 version: 1.49.0 @@ -480,12 +481,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: @@ -1577,7 +1582,7 @@ packages: '@module-federation/rspack@0.8.1': resolution: {integrity: sha512-nTkfEoIfGqYqxvh6E0wFR19xK9yPduE3ZhBYxdw9vCAmxzERjr6rVr7Fu2XVmZg6GTHmugm7oge4xqzLtXa1yA==} 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: @@ -1908,56 +1913,56 @@ packages: typescript: optional: true - '@rspack/binding-darwin-arm64@1.1.5': - resolution: {integrity: sha512-eEynmyPPl+OGYQ9LRFwiQosyRfcca3OQB73akqY4mqDRl39OyiBjq7347DLHJysgbm9z+B1bsiLuh2xc6mdclQ==} + '@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@1.1.5': - resolution: {integrity: sha512-I6HPRgogewU5v1OKe3noEzq2U1FCEYAbW+smy+lPvpTW+3X6PlVMzTT4oelhB0EXDQ+KxjXH9KpOKON1hg/JGg==} + '@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@1.1.5': - resolution: {integrity: sha512-LQnqucNa6Dr6y3By+/M2ARO4jDR3AM+PuCsHgzlYT0RDRLS+Ow3f50WbNBf7eI/DhrEA0aucYL3sz1ljguB3EA==} + '@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@1.1.5': - resolution: {integrity: sha512-b9L/9HJxrWY4cezPWqgj28I9Xe2XxwLHu8x0CMGobwF2XKR0QQVLAst38RW/EusJ8TURdyvNEOuRZlWEIJuYOw==} + '@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@1.1.5': - resolution: {integrity: sha512-0az52ZXTg/ErCGC1v/oFLWByKAiXvng4euv+prwMWF6p1pA7lfLRLzdibDFO4KgC16Zlfcg3hqs7YikLng4x+w==} + '@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@1.1.5': - resolution: {integrity: sha512-EF/LJTtCTkuti2gJnCyvXHC5Q2L5M4+RXm5kj9Bfu/t0Zmmfe6Jd5QUsifgogioeL0ZsH/Pou5QiiVcOFcqFKQ==} + '@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@1.1.5': - resolution: {integrity: sha512-VEqhK6HwIHby6gtOkxIx66SkqYndiaP1ddZ3X39RLE40TY3KlNgfG/SzbN9J5Qb+8jjq3ogV8n50+wLEGkhiWw==} + '@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@1.1.5': - resolution: {integrity: sha512-Yi2BwYehc5/sRVgI7zTGYJKjnV8UszAJt/stWdFHaq82chHiuuF/tQd1WcBUq0Iin9ylBMo16mRJAuFkFmJ74Q==} + '@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@1.1.5': - resolution: {integrity: sha512-4UArXYqJO1Ni7TmCw1T11JnrwfpoThDdiQ9k1P1voBWK3bDahPEBOptk9ZPu2+ZuRX8hFrvumRKkLY3oy7fTMw==} + '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-ik9bHH1T1W5UgKvxqt12nQQg+lllrxMn1HUbGBINz/zsjEIycxwqCvoAIazCj4JLYyDntpxPNLFULwId/yx8UQ==} cpu: [x64] os: [win32] - '@rspack/binding@1.1.5': - resolution: {integrity: sha512-RsSkgi56Q5XUXut0qweLSE1C4Ogcm7g/ueKoOgsbHAYVKrCs9/dTFlPHWSIAaI7QWh0GWEePR/MM2O2HIu+1rw==} - - '@rspack/core@1.1.5': - resolution: {integrity: sha512-/FmxDeMuW8fJkhz8fHuCu7OiJHFKW78xclEu7LkEujWl4PqJgdWjUL/6FWIj50spRwj6PRfuc31hFSL4hbNfCA==} + '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520': + resolution: {integrity: sha512-OwWxxVd9TnWaBnug2SAGmyl7VNR3MVGCwstXXhTAUCh0UTX/lQjmIKERm/tcHQyD04bOCeb+VXoj9qZT3PRbrg==} engines: {node: '>=16.0.0'} peerDependencies: '@swc/helpers': '>=0.5.1' @@ -7206,14 +7211,14 @@ snapshots: - supports-color - utf-8-validate - '@module-federation/enhanced@0.8.1(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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/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)': dependencies: '@module-federation/bridge-react-webpack-plugin': 0.8.1 '@module-federation/data-prefetch': 0.8.1(react-dom@18.3.1(react@18.3.1))(react@18.3.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/rspack': 0.8.1(@rspack/core@1.1.5(@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)) '@module-federation/runtime-tools': 0.8.1 '@module-federation/sdk': 0.8.1 btoa: 1.2.1 @@ -7254,13 +7259,13 @@ snapshots: - utf-8-validate - vue-tsc - '@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@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/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(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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/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) '@module-federation/sdk': 0.8.1 '@rsbuild/core': 1.1.8 - '@module-federation/rspack@0.8.1(@rspack/core@1.1.5(@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))': 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)) @@ -7268,7 +7273,6 @@ snapshots: '@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 - '@rspack/core': 1.1.5(@swc/helpers@0.5.15) optionalDependencies: typescript: 5.6.3 vue-tsc: 2.1.10(typescript@5.6.3) @@ -7303,9 +7307,9 @@ snapshots: dependencies: isomorphic-rslog: 0.0.6 - '@module-federation/storybook-addon@3.0.12(@rsbuild/core@1.1.8)(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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)': + '@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(@rspack/core@1.1.5(@swc/helpers@0.5.15))(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/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) '@module-federation/sdk': 0.8.1 optionalDependencies: '@rsbuild/core': 1.1.8 @@ -7463,7 +7467,7 @@ snapshots: '@rsbuild/core@1.1.8': dependencies: - '@rspack/core': 1.1.5(@swc/helpers@0.5.15) + '@rspack/core': '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)' '@rspack/lite-tapable': 1.0.1 '@swc/helpers': 0.5.15 core-js: 3.39.0 @@ -7598,49 +7602,49 @@ snapshots: '@microsoft/api-extractor': 7.48.0(@types/node@22.8.1) typescript: 5.6.3 - '@rspack/binding-darwin-arm64@1.1.5': + '@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@1.1.5': + '@rspack/binding-darwin-x64-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-linux-arm64-gnu@1.1.5': + '@rspack/binding-linux-arm64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-linux-arm64-musl@1.1.5': + '@rspack/binding-linux-arm64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-linux-x64-gnu@1.1.5': + '@rspack/binding-linux-x64-gnu-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-linux-x64-musl@1.1.5': + '@rspack/binding-linux-x64-musl-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-win32-arm64-msvc@1.1.5': + '@rspack/binding-win32-arm64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-win32-ia32-msvc@1.1.5': + '@rspack/binding-win32-ia32-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding-win32-x64-msvc@1.1.5': + '@rspack/binding-win32-x64-msvc-canary@1.1.6-canary-ec760c2a-20241206100520': optional: true - '@rspack/binding@1.1.5': - optionalDependencies: - '@rspack/binding-darwin-arm64': 1.1.5 - '@rspack/binding-darwin-x64': 1.1.5 - '@rspack/binding-linux-arm64-gnu': 1.1.5 - '@rspack/binding-linux-arm64-musl': 1.1.5 - '@rspack/binding-linux-x64-gnu': 1.1.5 - '@rspack/binding-linux-x64-musl': 1.1.5 - '@rspack/binding-win32-arm64-msvc': 1.1.5 - '@rspack/binding-win32-ia32-msvc': 1.1.5 - '@rspack/binding-win32-x64-msvc': 1.1.5 - - '@rspack/core@1.1.5(@swc/helpers@0.5.15)': + '@rspack/core-canary@1.1.6-canary-ec760c2a-20241206100520(@swc/helpers@0.5.15)': dependencies: '@module-federation/runtime-tools': 0.5.1 - '@rspack/binding': 1.1.5 + '@rspack/binding': '@rspack/binding-canary@1.1.6-canary-ec760c2a-20241206100520' '@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(