Skip to content

Commit 3cd0263

Browse files
committed
feat(nf): deprecate transient flag
1 parent 73761ca commit 3cd0263

File tree

5 files changed

+80
-29
lines changed

5 files changed

+80
-29
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,18 @@ function findTransientDeps(
379379
const shareConfig = configuredShareObjects[packageName];
380380

381381
if (typeof shareConfig === 'object' && shareConfig.transient) {
382+
logger.warn(
383+
'PLEASE NOTE: The transient flag in your federation.config.js'
384+
);
385+
logger.warn(
386+
'is deprecated. Please remove it. Meanwhile, Native Federation'
387+
);
388+
logger.warn(
389+
'uses the underlying bundler for splitting transient'
390+
);
391+
logger.warn(
392+
'dependencies into separate chunks, _when_ necessary.'
393+
)
382394
const packagePath = path.join(
383395
projectRoot,
384396
'node_modules',

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

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ export async function bundleShared(
9595
platform,
9696
});
9797

98-
const cachedFiles = bundleResult.map(br => path.basename(br.fileName));
98+
const cachedFiles = bundleResult.map((br) => path.basename(br.fileName));
9999
copyCacheToOutput(cachedFiles, cachePath, fullOutputPath);
100-
101100
} catch (e) {
102101
logger.error('Error bundling shared npm package ');
103102
if (e instanceof Error) {
@@ -131,31 +130,33 @@ export async function bundleShared(
131130
}
132131

133132
const resultCacheFile = createCacheFileName(
134-
configState,
135-
sharedBundles,
136-
fedOptions,
137-
cachePath,
133+
configState,
134+
sharedBundles,
135+
fedOptions,
136+
cachePath,
138137
platform
139138
);
140139

141140
if (fs.existsSync(resultCacheFile)) {
142-
const cachedResult: SharedInfo[] = JSON.parse(fs.readFileSync(resultCacheFile, 'utf-8'));
143-
const cachedFiles = cachedResult.map(cr => cr.outFileName);
144-
copyCacheToOutput(cachedFiles, cachePath, fullOutputPath)
145-
return cachedResult;
141+
const cachedResult: SharedInfo[] = JSON.parse(
142+
fs.readFileSync(resultCacheFile, 'utf-8')
143+
);
144+
const cachedFiles = cachedResult.map((cr) => cr.outFileName);
145+
copyCacheToOutput(cachedFiles, cachePath, fullOutputPath);
146+
return cachedResult;
146147
}
147148

148149
const outFileNames = [...exptedResults];
149150

150151
const result = buildResult(
151-
packageInfos,
152-
sharedBundles,
153-
outFileNames,
154-
fedOptions);
152+
packageInfos,
153+
sharedBundles,
154+
outFileNames,
155+
fedOptions
156+
);
155157

156158
const chunks = bundleResult.filter(
157-
(br) => !result.find((r) =>
158-
r.outFileName === path.basename(br.fileName))
159+
(br) => !result.find((r) => r.outFileName === path.basename(br.fileName))
159160
);
160161

161162
addChunksToResult(chunks, result, fedOptions.dev);
@@ -169,7 +170,11 @@ export async function bundleShared(
169170
return result;
170171
}
171172

172-
function copyCacheToOutput(cachedFiles: string[], cachePath: string, fullOutputPath: string) {
173+
function copyCacheToOutput(
174+
cachedFiles: string[],
175+
cachePath: string,
176+
fullOutputPath: string
177+
) {
173178
for (const fileName of cachedFiles) {
174179
const cachedFile = path.join(cachePath, fileName);
175180
const distFileName = path.join(fullOutputPath, fileName);
@@ -178,7 +183,12 @@ function copyCacheToOutput(cachedFiles: string[], cachePath: string, fullOutputP
178183
}
179184
}
180185

181-
function createOutName(pi: PackageInfo, configState: string, fedOptions: FederationOptions, encName: string) {
186+
function createOutName(
187+
pi: PackageInfo,
188+
configState: string,
189+
fedOptions: FederationOptions,
190+
encName: string
191+
) {
182192
const hashBase = pi.version + '_' + pi.entryPoint + '_' + configState;
183193
const hash = calcHash(hashBase);
184194

@@ -188,15 +198,29 @@ function createOutName(pi: PackageInfo, configState: string, fedOptions: Federat
188198
return outName;
189199
}
190200

191-
function createCacheFileName(configState: string, sharedBundles: Record<string, NormalizedSharedConfig>, fedOptions: FederationOptions, cachePath: string, platform: string) {
201+
function createCacheFileName(
202+
configState: string,
203+
sharedBundles: Record<string, NormalizedSharedConfig>,
204+
fedOptions: FederationOptions,
205+
cachePath: string,
206+
platform: string
207+
) {
192208
const resultCacheState = configState + JSON.stringify(sharedBundles);
193209
const resultHash = calcHash(resultCacheState);
194210
const dev = fedOptions.dev ? '-dev' : '';
195-
const resultCacheFile = path.join(cachePath, 'result-' + resultHash + '-' + platform + dev + '.json');
211+
const resultCacheFile = path.join(
212+
cachePath,
213+
'result-' + resultHash + '-' + platform + dev + '.json'
214+
);
196215
return resultCacheFile;
197216
}
198217

199-
function buildResult(packageInfos: PackageInfo[], sharedBundles: Record<string, NormalizedSharedConfig>, outFileNames: string[], fedOptions: FederationOptions) {
218+
function buildResult(
219+
packageInfos: PackageInfo[],
220+
sharedBundles: Record<string, NormalizedSharedConfig>,
221+
outFileNames: string[],
222+
fedOptions: FederationOptions
223+
) {
200224
return packageInfos.map((pi) => {
201225
const shared = sharedBundles[pi.packageName];
202226
return {
@@ -209,13 +233,17 @@ function buildResult(packageInfos: PackageInfo[], sharedBundles: Record<string,
209233
dev: !fedOptions.dev
210234
? undefined
211235
: {
212-
entryPoint: normalize(pi.entryPoint),
213-
},
236+
entryPoint: normalize(pi.entryPoint),
237+
},
214238
} as SharedInfo;
215239
});
216240
}
217241

218-
function addChunksToResult(chunks: BuildResult[], result: SharedInfo[], dev?: boolean) {
242+
function addChunksToResult(
243+
chunks: BuildResult[],
244+
result: SharedInfo[],
245+
dev?: boolean
246+
) {
219247
for (const item of chunks) {
220248
const fileName = path.basename(item.fileName);
221249
result.push({
@@ -228,8 +256,8 @@ function addChunksToResult(chunks: BuildResult[], result: SharedInfo[], dev?: bo
228256
dev: dev
229257
? undefined
230258
: {
231-
entryPoint: normalize(fileName),
232-
},
259+
entryPoint: normalize(fileName),
260+
},
233261
});
234262
}
235263
}
@@ -246,7 +274,6 @@ function calcHash(hashBase: string) {
246274
return hash;
247275
}
248276

249-
250277
function copyFileIfExists(cachedFile: string, fullOutputPath: string) {
251278
fs.mkdirSync(path.dirname(fullOutputPath), { recursive: true });
252279

libs/native-federation-node/LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Copyright 2021 Softarc Consulting GmbH
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8+
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"name": "@softarc/native-federation-node",
3-
"version": "3.0.0"
3+
"version": "3.0.0",
4+
"license": "MIT"
45
}

libs/native-federation/src/builders/build/builder.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,10 @@ export async function* runBuilder(
252252
try {
253253
federationResult = await buildForFederation(config, fedOptions, externals);
254254
} catch (e) {
255-
process.exit(1);
255+
console.error(e);
256+
if (!watch) {
257+
process.exit(1);
258+
}
256259
}
257260

258261
const hasLocales = i18n?.locales && Object.keys(i18n.locales).length > 0;

0 commit comments

Comments
 (0)