Skip to content

Commit d516df3

Browse files
committed
fix(nf): #386 and #387
1 parent 544607f commit d516df3

File tree

14 files changed

+99
-36
lines changed

14 files changed

+99
-36
lines changed

libs/mf-tools/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"name": "@angular-architects/module-federation-tools",
33
"version": "17.0.0",
44
"license": "MIT",
5-
"peerDependencies": {
6-
},
5+
"peerDependencies": {},
76
"dependencies": {
87
"tslib": "^2.0.0"
98
}
109
}
11-
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "@softarc/native-federation",
3-
"version": "2.0.4",
3+
"version": "2.0.7",
44
"type": "commonjs",
55
"dependencies": {
66
"json5": "^2.2.0",
77
"npmlog": "^6.0.2",
8-
"@softarc/native-federation-runtime": "2.0.4"
8+
"@softarc/native-federation-runtime": "2.0.7"
99
}
1010
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ function readConfiguredSecondaries(
233233
}
234234

235235
const entry = getDefaultEntry(exports, key);
236+
237+
if (typeof entry !== 'string') {
238+
console.log('No entry point found for ' + secondaryName);
239+
continue;
240+
}
241+
236242
if (
237243
entry?.endsWith('.css') ||
238244
entry?.endsWith('.scss') ||
@@ -259,6 +265,10 @@ function getDefaultEntry(
259265
entry = exports[key] as unknown as string;
260266
} else {
261267
entry = exports[key]?.['default'];
268+
269+
if (typeof entry === 'object') {
270+
entry = entry['default'];
271+
}
262272
}
263273
return entry;
264274
}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,29 @@ export async function bundleShared(
8585
if (e instanceof Error) {
8686
logger.error(e.message);
8787
}
88+
8889
logger.error('For more information, run in verbose mode');
90+
91+
logger.notice('');
92+
logger.notice('');
93+
94+
logger.notice('** Important Information: ***');
95+
logger.notice(
96+
'The error message above shows an issue with bundling a node_module.'
97+
);
8998
logger.notice(
90-
`If you don't need this package, skip it in your federation.config.js!`
99+
'In most cases this is because you (indirectly) shared a Node.js package,'
91100
);
101+
logger.notice('while Native Federation builds for the browser.');
102+
logger.notice(
103+
'You can move such packages into devDependencies or skip them in your federation.config.js.'
104+
);
105+
logger.notice('');
106+
logger.notice('More Details: https://bit.ly/nf-issue');
107+
108+
logger.notice('');
109+
logger.notice('');
110+
92111
logger.verbose(e);
93112
}
94113

libs/native-federation-core/src/lib/utils/package-info.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ export function _getPackageInfo(
199199
if (typeof cand === 'object') {
200200
if (cand.module) {
201201
cand = cand.module;
202+
} else if (cand.import) {
203+
cand = cand.import;
202204
} else if (cand.default) {
203205
cand = cand.default;
204206
} else {
@@ -210,6 +212,8 @@ export function _getPackageInfo(
210212
if (typeof cand === 'object') {
211213
if (cand.module) {
212214
cand = cand.module;
215+
} else if (cand.import) {
216+
cand = cand.import;
213217
} else if (cand.default) {
214218
cand = cand.default;
215219
} else {
@@ -230,6 +234,8 @@ export function _getPackageInfo(
230234
if (typeof cand === 'object') {
231235
if (cand.module) {
232236
cand = cand.module;
237+
} else if (cand.import) {
238+
cand = cand.import;
233239
} else if (cand.default) {
234240
cand = cand.default;
235241
} else {
@@ -251,6 +257,8 @@ export function _getPackageInfo(
251257
if (typeof cand === 'object') {
252258
if (cand.module) {
253259
cand = cand.module;
260+
} else if (cand.import) {
261+
cand = cand.import;
254262
} else if (cand.default) {
255263
cand = cand.default;
256264
} else {

libs/native-federation-esbuild/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-esbuild",
3-
"version": "2.0.4",
3+
"version": "2.0.7",
44
"type": "commonjs",
55
"dependencies": {
66
"@rollup/plugin-commonjs": "^22.0.2",

libs/native-federation-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@softarc/native-federation-runtime",
3-
"version": "2.0.4",
3+
"version": "2.0.7",
44
"peerDependencies": {},
55
"dependencies": {
66
"tslib": "^2.3.0"

libs/native-federation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ We will at least provide a new version of this package per Angular major. If nec
2323
- Use version 16.1.x for Angular 16.1.x
2424
- Use version 16.2.x for Angular 16.2.x
2525
- Use version 17.x for Angular 17.x
26-
26+
2727
## Credits
2828

2929
Big thanks to:

libs/native-federation/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/native-federation",
3-
"version": "17.0.0",
3+
"version": "17.0.6",
44
"main": "src/index.js",
55
"generators": "./collection.json",
66
"builders": "./builders.json",
@@ -16,15 +16,14 @@
1616
},
1717
"dependencies": {
1818
"@babel/core": "^7.19.0",
19-
"@softarc/native-federation": "2.0.4",
20-
"@softarc/native-federation-runtime": "2.0.4",
19+
"@softarc/native-federation": "2.0.7",
20+
"@softarc/native-federation-runtime": "2.0.7",
2121
"@types/browser-sync": "^2.26.3",
2222
"browser-sync": "^2.29.3",
2323
"esbuild": "^0.19.5",
2424
"mrmime": "^1.0.1",
2525
"npmlog": "^6.0.2",
2626
"process": "0.11.10"
2727
},
28-
"peerDependencies": {
29-
}
28+
"peerDependencies": {}
3029
}

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
} from '../../utils/dev-server';
3333
import { RebuildHubs } from '../../utils/rebuild-events';
3434
import { updateIndexHtml } from '../../utils/updateIndexHtml';
35-
import { existsSync, mkdirSync, rmdirSync } from 'fs';
35+
import { existsSync, mkdirSync, rmSync } from 'fs';
3636
import {
3737
EsBuildResult,
3838
MemResults,
@@ -80,7 +80,15 @@ export async function* runBuilder(
8080
const config = await loadFederationConfig(fedOptions);
8181
const externals = getExternals(config);
8282

83-
options.externalDependencies = externals.filter((e) => e !== 'tslib');
83+
// options.externalDependencies = externals.filter((e) => e !== 'tslib');
84+
const plugins = [
85+
{
86+
name: 'externals',
87+
setup(build) {
88+
build.initialOptions.external = externals.filter((e) => e !== 'tslib');
89+
},
90+
},
91+
];
8492

8593
// for await (const r of buildEsbuildBrowser(options, context as any, { write: false })) {
8694
// const output = r.outputFiles ||[];
@@ -103,23 +111,35 @@ export async function* runBuilder(
103111
let lastResult: { success: boolean } | undefined;
104112

105113
if (existsSync(options.outputPath)) {
106-
rmdirSync(options.outputPath, { recursive: true });
114+
rmSync(options.outputPath, { recursive: true });
107115
}
108116

109117
if (!existsSync(options.outputPath)) {
110118
mkdirSync(options.outputPath, { recursive: true });
111119
}
112120

113121
if (!write) {
114-
setMemResultHandler((outFiles) => {
115-
memResults.add(outFiles.map((f) => new EsBuildResult(f)));
122+
setMemResultHandler((outFiles, outDir) => {
123+
const fullOutDir = outDir
124+
? path.join(fedOptions.workspaceRoot, outDir)
125+
: null;
126+
memResults.add(outFiles.map((f) => new EsBuildResult(f, fullOutDir)));
116127
});
117128
}
118129

130+
await buildForFederation(config, fedOptions, externals);
131+
132+
options.deleteOutputPath = false;
133+
119134
// builderRun.output.subscribe(async (output) => {
120-
for await (const output of buildEsbuildBrowser(options, context as any, {
121-
write,
122-
})) {
135+
for await (const output of buildEsbuildBrowser(
136+
options,
137+
context as any,
138+
{
139+
write,
140+
},
141+
plugins
142+
)) {
123143
lastResult = output;
124144

125145
if (!output.success) {
@@ -144,10 +164,6 @@ export async function* runBuilder(
144164
updateIndexHtml(fedOptions);
145165
}
146166

147-
if (first) {
148-
await buildForFederation(config, fedOptions, externals);
149-
}
150-
151167
if (first && runServer) {
152168
startServer(nfOptions, options.outputPath, memResults);
153169
}

libs/native-federation/src/utils/angular-esbuild-adapter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import {
4242

4343
// const fesmFolderRegExp = /[/\\]fesm\d+[/\\]/;
4444

45-
export type MemResultHandler = (outfiles: esbuild.OutputFile[]) => void;
45+
export type MemResultHandler = (
46+
outfiles: esbuild.OutputFile[],
47+
outdir?: string
48+
) => void;
4649

4750
let _memResultHandler: MemResultHandler;
4851

@@ -238,6 +241,8 @@ async function runEsbuild(
238241
undefined
239242
);
240243

244+
pluginOptions.styleOptions.externalDependencies = [];
245+
241246
const config: esbuild.BuildOptions = {
242247
entryPoints: entryPoints.map((ep) => ({
243248
in: ep.fileName,
@@ -259,6 +264,7 @@ async function runEsbuild(
259264
platform: 'browser',
260265
format: 'esm',
261266
target: ['esnext'],
267+
logLimit: kind === 'shared-package' ? 1 : 0,
262268
plugins: plugins || [
263269
createCompilerPlugin(
264270
pluginOptions.pluginOptions,
@@ -326,7 +332,7 @@ function writeResult(
326332
const writtenFiles: string[] = [];
327333

328334
if (memOnly) {
329-
_memResultHandler(result.outputFiles);
335+
_memResultHandler(result.outputFiles, outdir);
330336
}
331337

332338
for (const outFile of result.outputFiles) {

libs/native-federation/src/utils/dev-server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export function startServer(
2626
open: options.open,
2727
middleware: [
2828
function (req, res, next) {
29-
const key = req.url.startsWith('/') ? req.url.substring(1) : req.url;
29+
const temp = req.url.startsWith('/') ? req.url.substring(1) : req.url;
30+
const key =
31+
temp.indexOf('?') > -1 ? temp.substring(0, temp.indexOf('?')) : temp;
32+
3033
const result = memResults.get(key);
3134

3235
if (result) {

libs/native-federation/src/utils/mem-resuts.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OutputFile } from 'esbuild';
2-
import { basename } from 'path';
32
import * as fs from 'fs';
3+
import * as path from 'path';
44

55
export interface BuildResult {
66
fileName: string;
@@ -9,10 +9,14 @@ export interface BuildResult {
99

1010
export class EsBuildResult implements BuildResult {
1111
get fileName() {
12-
return basename(this.outputFile.path);
12+
if (this.fullOutDir) {
13+
return unify(path.relative(this.fullOutDir, this.outputFile.path));
14+
} else {
15+
return unify(this.outputFile.path);
16+
}
1317
}
1418

15-
constructor(private outputFile: OutputFile) {}
19+
constructor(private outputFile: OutputFile, private fullOutDir?: string) {}
1620

1721
get(): Uint8Array {
1822
return this.outputFile.contents;

update-local.bat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
call npm unpublish @softarc/native-federation@2.0.4 --registry http://localhost:4873
2-
call npm unpublish @softarc/native-federation-runtime@2.0.4 --registry http://localhost:4873
3-
call npm unpublish @softarc/native-federation-esbuild@2.0.4 --registry http://localhost:4873
4-
call npm unpublish @angular-architects/native-federation@16.3.4 --registry http://localhost:4873
1+
call npm unpublish @softarc/native-federation@2.0.5 --registry http://localhost:4873
2+
call npm unpublish @softarc/native-federation-runtime@2.0.5 --registry http://localhost:4873
3+
call npm unpublish @softarc/native-federation-esbuild@2.0.5 --registry http://localhost:4873
4+
call npm unpublish @angular-architects/native-federation@17.0.3 --registry http://localhost:4873
55

66
call npx nx build native-federation
77
call npx nx build native-federation-core

0 commit comments

Comments
 (0)