Skip to content

Commit a003d4e

Browse files
committed
fix(native-federation): Fix sharing issues
1 parent 1f25059 commit a003d4e

4 files changed

Lines changed: 21 additions & 23 deletions

File tree

libs/native-federation-core/src/lib/config/share-utils.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ function _findSecondaries(
127127
.replace(/\\/g, '/')
128128
.replace(/^.*node_modules[/]/, '');
129129

130-
for (const e in excludes) {
131-
if (e === secondaryLibName) continue;
132-
if (e.endsWith('*') && secondaryLibName.startsWith(e.slice(0, -1)))
133-
continue;
134-
}
130+
let inCustomSkipList = excludes.some(
131+
(e) =>
132+
e === secondaryLibName ||
133+
(e.endsWith('*') && secondaryLibName.startsWith(e.slice(0, -1))),
134+
);
135+
if (inCustomSkipList) continue;
135136

136137
if (isInSkipList(secondaryLibName, preparedSkipList)) {
137138
continue;
@@ -246,10 +247,12 @@ function readConfiguredSecondaries(
246247
for (const key of keys) {
247248
const secondaryName = path.join(parent, key).replace(/\\/g, '/');
248249

249-
for (const e in exclude) {
250-
if (e === secondaryName) continue;
251-
if (e.endsWith('*') && secondaryName.startsWith(e.slice(0, -1))) continue;
252-
}
250+
let inCustomSkipList = exclude.some(
251+
(e) =>
252+
e === secondaryName ||
253+
(e.endsWith('*') && secondaryName.startsWith(e.slice(0, -1))),
254+
);
255+
if (inCustomSkipList) continue;
253256

254257
if (isInSkipList(secondaryName, preparedSkipList)) {
255258
continue;

libs/native-federation-core/src/lib/core/build-for-federation.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ async function bundlePerPackage(
179179
groupedByPackage[packageName][key] = shared;
180180
}
181181

182+
logger.info('Preparing shared npm packages for the platform ' + platform);
183+
logger.notice('This only needs to be done once, as results are cached');
184+
logger.notice(
185+
"Skip packages you don't want to share in your federation config",
186+
);
187+
182188
const bundlePromises = Object.entries(groupedByPackage).map(
183189
async ([packageName, sharedGroup]) => {
184190
return bundleShared(

libs/native-federation-core/src/lib/core/bundle-shared.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,6 @@ export async function bundleShared(
9393
(ep) => !fs.existsSync(path.join(cacheOptions.pathToCache, ep.outName)),
9494
);
9595

96-
if (entryPoints.length > 0) {
97-
logger.info('Preparing shared npm packages for the platform ' + platform);
98-
logger.notice('This only needs to be done once, as results are cached');
99-
logger.notice(
100-
"Skip packages you don't want to share in your federation config",
101-
);
102-
}
103-
10496
// If we build for the browser and don't remote unused deps from the shared config,
10597
// we need to exclude typical node libs to avoid compilation issues
10698
const useDefaultExternalList =

libs/native-federation-core/src/lib/utils/bundle-caching.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,9 @@ export const cacheEntry = (pathToCache: string, fileName: string) => ({
9696
logger.debug(`Creating cache folder '${pathToCache}' for '${fileName}'.`);
9797
return;
9898
}
99-
if (!fs.existsSync(metadataFile)) {
100-
logger.debug(
101-
`Could not purge cached bundle, metadata file '${metadataFile}' does not exist.`,
102-
);
103-
return;
104-
}
99+
if (!fs.existsSync(metadataFile)) return;
100+
101+
logger.debug(`Purging cached bundle '${metadataFile}'.`);
105102

106103
const cachedResult: {
107104
checksum: string;

0 commit comments

Comments
 (0)