Skip to content

Commit 18d061b

Browse files
committed
chore(nf): Made #981 opt-in instead of default
1 parent 11dd80e commit 18d061b

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface FederationConfig {
2727
features?: {
2828
mappingVersion?: boolean;
2929
ignoreUnusedDeps?: boolean;
30+
cacheExternalArtifacts: boolean;
3031
};
3132
}
3233

@@ -55,5 +56,6 @@ export interface NormalizedFederationConfig {
5556
features: {
5657
mappingVersion: boolean;
5758
ignoreUnusedDeps: boolean;
59+
cacheExternalArtifacts: boolean;
5860
};
5961
}

libs/native-federation-core/src/lib/config/with-native-federation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function withNativeFederation(
1818
): NormalizedFederationConfig {
1919
const skip = prepareSkipList(config.skip ?? []);
2020

21-
const normalized = {
21+
const normalized: NormalizedFederationConfig = {
2222
name: config.name ?? '',
2323
exposes: config.exposes ?? {},
2424
shared: normalizeShared(config, skip),
@@ -28,6 +28,7 @@ export function withNativeFederation(
2828
features: {
2929
mappingVersion: config.features?.mappingVersion ?? false,
3030
ignoreUnusedDeps: config.features?.ignoreUnusedDeps ?? false,
31+
cacheExternalArtifacts: config.features?.cacheExternalArtifacts ?? false,
3132
},
3233
};
3334

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,14 @@ export async function buildForFederation(
6464
? describeExposed(config, fedOptions)
6565
: artefactInfo.exposes;
6666

67-
const cacheProjectFolder = normalizePackageName(config.name);
68-
if (cacheProjectFolder.length < 1) {
67+
const normalizedCacheFolder = normalizePackageName(config.name);
68+
if (normalizedCacheFolder.length < 1) {
6969
logger.warn(
70-
"Project name in 'federation.config.js' is empty, defaulting to root cache folder (could collide with other projects in the workspace).",
70+
"Project name in 'federation.config.js' is empty, defaulting to 'shell' cache folder (could collide with other projects in the workspace).",
7171
);
7272
}
73+
const cacheProjectFolder =
74+
normalizedCacheFolder.length < 1 ? 'shell' : normalizedCacheFolder;
7375

7476
const pathToCache = getCachePath(
7577
fedOptions.workspaceRoot,

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@ export async function bundleShared(
3737
getFilename(cacheOptions.bundleName),
3838
);
3939

40-
const cacheMetadata = bundleCache.getMetadata(checksum);
41-
if (cacheMetadata) {
42-
logger.debug(
43-
`Checksum of ${cacheOptions.bundleName} matched, Skipped artifact bundling`,
44-
);
45-
bundleCache.copyFiles(
46-
path.join(fedOptions.workspaceRoot, fedOptions.outputPath),
47-
);
48-
return cacheMetadata.externals;
40+
if (config?.features?.cacheExternalArtifacts) {
41+
const cacheMetadata = bundleCache.getMetadata(checksum);
42+
if (cacheMetadata) {
43+
logger.debug(
44+
`Checksum of ${cacheOptions.bundleName} matched, Skipped artifact bundling`,
45+
);
46+
bundleCache.copyFiles(
47+
path.join(fedOptions.workspaceRoot, fedOptions.outputPath),
48+
);
49+
return cacheMetadata.externals;
50+
}
4951
}
5052

51-
// Delete older packages if checksum didnt match
5253
bundleCache.clear();
5354

5455
const inferredPackageInfos = Object.keys(sharedBundles)

libs/native-federation-core/src/lib/core/federation-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export interface FederationOptions {
44
workspaceRoot: string;
55
outputPath: string;
66
federationConfig: string;
7+
cacheExternals: boolean;
78
tsConfig?: string;
89
verbose?: boolean;
910
dev?: boolean;

libs/native-federation/src/schematics/init/files/federation.config.js__tmpl__

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ module.exports = withNativeFederation({
2828
// New feature for more performance and avoiding
2929
// issues with node libs. Comment this out to
3030
// get the traditional behavior:
31-
ignoreUnusedDeps: true
31+
ignoreUnusedDeps: true,
32+
33+
// Will use a checksum to verify if compiled (external)
34+
// artifacts were unchanged since last build (based on
35+
// name and version). If so it will reuse the compiled ones.
36+
cacheExternalArtifacts: true
3237
}
33-
3438
});

0 commit comments

Comments
 (0)