diff --git a/.changeset/silver-buttons-wonder.md b/.changeset/silver-buttons-wonder.md new file mode 100644 index 00000000000..3512e854806 --- /dev/null +++ b/.changeset/silver-buttons-wonder.md @@ -0,0 +1,5 @@ +--- +'@module-federation/rsbuild-plugin': patch +--- + +fix(rsbuild-plugin): create different temp filepath to prevent invalid manifest.exposes diff --git a/packages/rsbuild-plugin/src/utils/addDataFetchExposes.ts b/packages/rsbuild-plugin/src/utils/addDataFetchExposes.ts index 1c00a46beed..56554a5f1c1 100644 --- a/packages/rsbuild-plugin/src/utils/addDataFetchExposes.ts +++ b/packages/rsbuild-plugin/src/utils/addDataFetchExposes.ts @@ -46,15 +46,11 @@ export function addDataFetchExposes( return; } - const tempDataFetchFilepath = path.resolve( - process.cwd(), - `node_modules/${TEMP_DIR}/data-fetch-fallback.ts`, - ); + const tempDataFetch = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`); const content = `export const fetchData=()=>{throw new Error('should not be called')};`; - fs.ensureDirSync(path.dirname(tempDataFetchFilepath)); - fs.writeFileSync(tempDataFetchFilepath, content); + fs.ensureDirSync(tempDataFetch); - Object.keys(exposes).forEach((key) => { + Object.keys(exposes).forEach((key, index) => { const expose = exposes[key]; if (typeof expose !== 'string') { return; @@ -63,6 +59,8 @@ export function addDataFetchExposes( const dataFetchPath = `${absPath.replace(path.extname(absPath), '')}.${DATA_FETCH_IDENTIFIER}.ts`; const dataFetchClientPath = `${absPath.replace(path.extname(absPath), '')}.${DATA_FETCH_IDENTIFIER}.client.ts`; + const tempFile = path.join(tempDataFetch, `data-fetch-fallback${index}.ts`); + fs.writeFileSync(tempFile, content); const dateFetchClientKey = addDataFetchExpose( exposes, @@ -72,14 +70,14 @@ export function addDataFetchExposes( ); if (!isServer && dateFetchClientKey) { exposes[dateFetchClientKey.replace(DATA_FETCH_CLIENT_SUFFIX, '')] = - addExcludeDtsSuffix(tempDataFetchFilepath); + addExcludeDtsSuffix(tempFile); return; } const dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath); if (dataFetchKey && fs.existsSync(dataFetchClientPath)) { exposes[`${dataFetchKey}${DATA_FETCH_CLIENT_SUFFIX}`] = - addExcludeDtsSuffix(tempDataFetchFilepath); + addExcludeDtsSuffix(tempFile); } }); }