Skip to content

Commit b307ae0

Browse files
authored
fix(rsbuild-plugin): create different temp filepath to prevent invalid manifest.exposes (#4233)
1 parent dd18b3b commit b307ae0

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
---
4+
5+
fix(rsbuild-plugin): create different temp filepath to prevent invalid manifest.exposes

packages/rsbuild-plugin/src/utils/addDataFetchExposes.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,11 @@ export function addDataFetchExposes(
4646
return;
4747
}
4848

49-
const tempDataFetchFilepath = path.resolve(
50-
process.cwd(),
51-
`node_modules/${TEMP_DIR}/data-fetch-fallback.ts`,
52-
);
49+
const tempDataFetch = path.resolve(process.cwd(), `node_modules/${TEMP_DIR}`);
5350
const content = `export const fetchData=()=>{throw new Error('should not be called')};`;
54-
fs.ensureDirSync(path.dirname(tempDataFetchFilepath));
55-
fs.writeFileSync(tempDataFetchFilepath, content);
51+
fs.ensureDirSync(tempDataFetch);
5652

57-
Object.keys(exposes).forEach((key) => {
53+
Object.keys(exposes).forEach((key, index) => {
5854
const expose = exposes[key];
5955
if (typeof expose !== 'string') {
6056
return;
@@ -63,6 +59,8 @@ export function addDataFetchExposes(
6359
const dataFetchPath = `${absPath.replace(path.extname(absPath), '')}.${DATA_FETCH_IDENTIFIER}.ts`;
6460

6561
const dataFetchClientPath = `${absPath.replace(path.extname(absPath), '')}.${DATA_FETCH_IDENTIFIER}.client.ts`;
62+
const tempFile = path.join(tempDataFetch, `data-fetch-fallback${index}.ts`);
63+
fs.writeFileSync(tempFile, content);
6664

6765
const dateFetchClientKey = addDataFetchExpose(
6866
exposes,
@@ -72,14 +70,14 @@ export function addDataFetchExposes(
7270
);
7371
if (!isServer && dateFetchClientKey) {
7472
exposes[dateFetchClientKey.replace(DATA_FETCH_CLIENT_SUFFIX, '')] =
75-
addExcludeDtsSuffix(tempDataFetchFilepath);
73+
addExcludeDtsSuffix(tempFile);
7674
return;
7775
}
7876

7977
const dataFetchKey = addDataFetchExpose(exposes, key, dataFetchPath);
8078
if (dataFetchKey && fs.existsSync(dataFetchClientPath)) {
8179
exposes[`${dataFetchKey}${DATA_FETCH_CLIENT_SUFFIX}`] =
82-
addExcludeDtsSuffix(tempDataFetchFilepath);
80+
addExcludeDtsSuffix(tempFile);
8381
}
8482
});
8583
}

0 commit comments

Comments
 (0)