@angular-architects/native-federation 18.1.3 → 18.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +25 -0
- package/README.md +1 -0
- package/docs/migrate.md +173 -0
- package/docs/share-faq.md +57 -0
- package/docs/update18.md +19 -0
- package/example.png +0 -0
- package/jest.config.ts +11 -0
- package/package.json +3 -5
- package/post-build.js +10 -0
- package/project.json +80 -0
- package/src/builders/build/builder.ts +370 -0
- package/src/config.ts +6 -0
- package/src/executors/build/executor.spec.ts +11 -0
- package/src/executors/build/executor.ts +12 -0
- package/src/generators/native-federation/generator.spec.ts +20 -0
- package/src/generators/native-federation/generator.ts +76 -0
- package/src/patch-angular-build.ts +8 -0
- package/src/plugin/dev-externals-mixin.ts +34 -0
- package/src/plugin/externals-skip-list.ts +5 -0
- package/src/plugin/index.ts +123 -0
- package/src/schematics/appbuilder/schematic.ts +148 -0
- package/src/schematics/init/schematic.ts +463 -0
- package/src/schematics/remove/schematic.ts +179 -0
- package/src/schematics/update18/schematic.ts +10 -0
- package/src/utils/angular-esbuild-adapter.ts +438 -0
- package/src/utils/create-compiler-options.ts +68 -0
- package/src/utils/dev-server.ts +117 -0
- package/src/utils/event-sorce.ts +18 -0
- package/src/utils/mem-resuts.ts +67 -0
- package/src/utils/patch-angular-build.ts +47 -0
- package/src/utils/rebuild-events.ts +9 -0
- package/src/utils/shared-mappings-plugin.ts +35 -0
- package/src/utils/updateIndexHtml.ts +55 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +11 -0
- package/tsconfig.spec.json +15 -0
- package/config.js +0 -5
- package/config.js.map +0 -1
- package/src/builders/build/builder.d.ts +0 -5
- package/src/builders/build/builder.js +0 -255
- package/src/builders/build/builder.js.map +0 -1
- package/src/config.d.ts +0 -2
- package/src/config.js +0 -10
- package/src/config.js.map +0 -1
- package/src/executors/build/executor.d.ts +0 -4
- package/src/executors/build/executor.js +0 -13
- package/src/executors/build/executor.js.map +0 -1
- package/src/generators/native-federation/generator.d.ts +0 -3
- package/src/generators/native-federation/generator.js +0 -44
- package/src/generators/native-federation/generator.js.map +0 -1
- package/src/index.js +0 -5
- package/src/index.js.map +0 -1
- package/src/patch-angular-build.d.ts +0 -1
- package/src/patch-angular-build.js +0 -7
- package/src/patch-angular-build.js.map +0 -1
- package/src/plugin/dev-externals-mixin.d.ts +0 -1
- package/src/plugin/dev-externals-mixin.js +0 -30
- package/src/plugin/dev-externals-mixin.js.map +0 -1
- package/src/plugin/externals-skip-list.d.ts +0 -2
- package/src/plugin/externals-skip-list.js +0 -9
- package/src/plugin/externals-skip-list.js.map +0 -1
- package/src/plugin/index.d.ts +0 -2
- package/src/plugin/index.js +0 -107
- package/src/plugin/index.js.map +0 -1
- package/src/schematics/appbuilder/schematic.d.ts +0 -4
- package/src/schematics/appbuilder/schematic.js +0 -95
- package/src/schematics/appbuilder/schematic.js.map +0 -1
- package/src/schematics/init/schematic.d.ts +0 -6
- package/src/schematics/init/schematic.js +0 -313
- package/src/schematics/init/schematic.js.map +0 -1
- package/src/schematics/remove/schematic.d.ts +0 -4
- package/src/schematics/remove/schematic.js +0 -119
- package/src/schematics/remove/schematic.js.map +0 -1
- package/src/schematics/update18/schematic.d.ts +0 -2
- package/src/schematics/update18/schematic.js +0 -14
- package/src/schematics/update18/schematic.js.map +0 -1
- package/src/utils/angular-esbuild-adapter.d.ts +0 -9
- package/src/utils/angular-esbuild-adapter.js +0 -270
- package/src/utils/angular-esbuild-adapter.js.map +0 -1
- package/src/utils/create-compiler-options.d.ts +0 -4
- package/src/utils/create-compiler-options.js +0 -45
- package/src/utils/create-compiler-options.js.map +0 -1
- package/src/utils/dev-server.d.ts +0 -7
- package/src/utils/dev-server.js +0 -94
- package/src/utils/dev-server.js.map +0 -1
- package/src/utils/event-sorce.d.ts +0 -9
- package/src/utils/event-sorce.js +0 -20
- package/src/utils/event-sorce.js.map +0 -1
- package/src/utils/mem-resuts.d.ts +0 -29
- package/src/utils/mem-resuts.js +0 -58
- package/src/utils/mem-resuts.js.map +0 -1
- package/src/utils/patch-angular-build.d.ts +0 -3
- package/src/utils/patch-angular-build.js +0 -36
- package/src/utils/patch-angular-build.js.map +0 -1
- package/src/utils/rebuild-events.d.ts +0 -7
- package/src/utils/rebuild-events.js +0 -11
- package/src/utils/rebuild-events.js.map +0 -1
- package/src/utils/shared-mappings-plugin.d.ts +0 -3
- package/src/utils/shared-mappings-plugin.js +0 -31
- package/src/utils/shared-mappings-plugin.js.map +0 -1
- package/src/utils/updateIndexHtml.d.ts +0 -4
- package/src/utils/updateIndexHtml.js +0 -34
- package/src/utils/updateIndexHtml.js.map +0 -1
- /package/{config.d.ts → config.ts} +0 -0
- /package/src/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import * as browserSync from 'browser-sync';
|
|
2
|
+
import { NfBuilderSchema } from '../builders/build/schema';
|
|
3
|
+
import { BuildResult, MemResults } from './mem-resuts';
|
|
4
|
+
import { extname } from 'path';
|
|
5
|
+
import { lookup } from 'mrmime';
|
|
6
|
+
import { updateScriptTags } from './updateIndexHtml';
|
|
7
|
+
|
|
8
|
+
let server: browserSync.BrowserSyncInstance;
|
|
9
|
+
|
|
10
|
+
export function startServer(
|
|
11
|
+
options: NfBuilderSchema,
|
|
12
|
+
path: string,
|
|
13
|
+
memResults: MemResults
|
|
14
|
+
): void {
|
|
15
|
+
const projectName = options.target.split(':')[0];
|
|
16
|
+
|
|
17
|
+
server = browserSync.create(projectName);
|
|
18
|
+
|
|
19
|
+
server.init({
|
|
20
|
+
port: options.port || 4200,
|
|
21
|
+
cors: true,
|
|
22
|
+
server: path,
|
|
23
|
+
notify: false,
|
|
24
|
+
single: true,
|
|
25
|
+
ui: false,
|
|
26
|
+
open: options.open,
|
|
27
|
+
middleware: [
|
|
28
|
+
function (req, res, next) {
|
|
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
|
+
|
|
33
|
+
const result = memResults.get(key);
|
|
34
|
+
|
|
35
|
+
if (result) {
|
|
36
|
+
const mimeType = lookup(extname(key)) || 'text/javascript';
|
|
37
|
+
const body = getBody(result, memResults, options);
|
|
38
|
+
res.writeHead(200, {
|
|
39
|
+
'Content-Type': mimeType,
|
|
40
|
+
});
|
|
41
|
+
res.end(body);
|
|
42
|
+
} else {
|
|
43
|
+
next();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let buildError = '';
|
|
51
|
+
|
|
52
|
+
export function setError(error: string): void {
|
|
53
|
+
buildError = error;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function notifyServer(message: string): void {
|
|
57
|
+
server.notify(message);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function reloadBrowser(): void {
|
|
61
|
+
if (!server) {
|
|
62
|
+
throw new Error('server is not started');
|
|
63
|
+
}
|
|
64
|
+
server.reload();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function reloadShell(shellProjectName: string): void {
|
|
68
|
+
if (!server) {
|
|
69
|
+
throw new Error('server is not started');
|
|
70
|
+
}
|
|
71
|
+
if (!shellProjectName) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (browserSync.has(shellProjectName)) {
|
|
75
|
+
const shellServer = browserSync.get(shellProjectName);
|
|
76
|
+
shellServer.reload();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function modifyIndexHtml(
|
|
81
|
+
content: string,
|
|
82
|
+
fileNames: string[],
|
|
83
|
+
nfOptions: NfBuilderSchema
|
|
84
|
+
): string {
|
|
85
|
+
if (buildError) {
|
|
86
|
+
const errorHtml = `
|
|
87
|
+
<div style="position: absolute; filter: opacity(80%); top:0; bottom:0; left:0; right:0; padding:20px; background-color:black; color:white; ">
|
|
88
|
+
<h2>${buildError}</h2>
|
|
89
|
+
</div>
|
|
90
|
+
`;
|
|
91
|
+
content = errorHtml + content;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const mainName = fileNames.find(
|
|
95
|
+
(f) => f.startsWith('main.') && f.endsWith('.js')
|
|
96
|
+
);
|
|
97
|
+
const polyfillsName = fileNames.find(
|
|
98
|
+
(f) => f.startsWith('polyfills.') && f.endsWith('.js')
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const index = updateScriptTags(content, mainName, polyfillsName, nfOptions);
|
|
102
|
+
return index;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getBody(
|
|
106
|
+
result: BuildResult,
|
|
107
|
+
memResults: MemResults,
|
|
108
|
+
nfOptions: NfBuilderSchema
|
|
109
|
+
): Uint8Array | Buffer | string {
|
|
110
|
+
const body = result.get();
|
|
111
|
+
if (result.fileName === 'index.html') {
|
|
112
|
+
const content = new TextDecoder().decode(body);
|
|
113
|
+
return modifyIndexHtml(content, memResults.getFileNames(), nfOptions);
|
|
114
|
+
} else {
|
|
115
|
+
return body;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type EventHandler = () => Promise<void>;
|
|
2
|
+
|
|
3
|
+
export interface EventSource {
|
|
4
|
+
register(handler: EventHandler): void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class EventHub implements EventSource {
|
|
8
|
+
private handlers: EventHandler[] = [];
|
|
9
|
+
|
|
10
|
+
register(handler: EventHandler): void {
|
|
11
|
+
this.handlers.push(handler);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async emit(): Promise<void> {
|
|
15
|
+
const promises = this.handlers.map((h) => h());
|
|
16
|
+
await Promise.all(promises);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { OutputFile } from 'esbuild';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
|
|
5
|
+
export interface BuildResult {
|
|
6
|
+
fileName: string;
|
|
7
|
+
get(): Uint8Array | Buffer;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class EsBuildResult implements BuildResult {
|
|
11
|
+
get fileName() {
|
|
12
|
+
if (this.fullOutDir) {
|
|
13
|
+
return unify(path.relative(this.fullOutDir, this.outputFile.path));
|
|
14
|
+
} else {
|
|
15
|
+
return unify(this.outputFile.path);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(private outputFile: OutputFile, private fullOutDir?: string) {}
|
|
20
|
+
|
|
21
|
+
get(): Uint8Array {
|
|
22
|
+
return this.outputFile.contents;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NgCliAssetFile {
|
|
27
|
+
source: string;
|
|
28
|
+
destination: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class NgCliAssetResult implements BuildResult {
|
|
32
|
+
public get fileName(): string {
|
|
33
|
+
return unify(this.file.destination);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private file: NgCliAssetFile;
|
|
37
|
+
|
|
38
|
+
constructor(private assetFile: NgCliAssetFile) {
|
|
39
|
+
this.file = assetFile;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get(): Buffer {
|
|
43
|
+
return fs.readFileSync(this.file.source);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export class MemResults {
|
|
48
|
+
private map = new Map<string, BuildResult>();
|
|
49
|
+
|
|
50
|
+
public add(result: BuildResult[]): void {
|
|
51
|
+
for (const file of result) {
|
|
52
|
+
this.map.set(file.fileName, file);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public get(fileName: string): BuildResult | undefined {
|
|
57
|
+
return this.map.get(fileName);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public getFileNames(): string[] {
|
|
61
|
+
return [...this.map.keys()];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function unify(path) {
|
|
66
|
+
return path?.replace(/\\/g, '/');
|
|
67
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
|
|
4
|
+
export const privateEntrySrc = `
|
|
5
|
+
exports = require('./src/private.js');
|
|
6
|
+
`;
|
|
7
|
+
|
|
8
|
+
export function patchAngularBuildPackageJson(packageJson: unknown): void {
|
|
9
|
+
const exportsMap = packageJson['exports'];
|
|
10
|
+
|
|
11
|
+
if (!exportsMap) {
|
|
12
|
+
console.log('No need to patch @angular/build/package.json');
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
packageJson['_exports'] = exportsMap;
|
|
17
|
+
delete packageJson['exports'];
|
|
18
|
+
|
|
19
|
+
packageJson['types'] = './src/index.d.ts';
|
|
20
|
+
packageJson['main'] = './src/index.js';
|
|
21
|
+
packageJson['module'] = './src/index.js';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function patchAngularBuild(workspaceRoot: string): void {
|
|
25
|
+
const packagePath = path.join(
|
|
26
|
+
workspaceRoot,
|
|
27
|
+
'node_modules/@angular/build/package.json'
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const privatePath = path.join(
|
|
31
|
+
workspaceRoot,
|
|
32
|
+
'node_modules/@angular/build/private.js'
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!fs.existsSync(packagePath)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
|
|
40
|
+
|
|
41
|
+
patchAngularBuildPackageJson(packageJson);
|
|
42
|
+
|
|
43
|
+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
|
|
44
|
+
fs.writeFileSync(privatePath, privateEntrySrc);
|
|
45
|
+
|
|
46
|
+
console.log('@angular/build/package.json patched');
|
|
47
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Plugin, PluginBuild } from 'esbuild';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { MappedPath } from '@softarc/native-federation/build';
|
|
4
|
+
|
|
5
|
+
export function createSharedMappingsPlugin(mappedPaths: MappedPath[]): Plugin {
|
|
6
|
+
return {
|
|
7
|
+
name: 'custom',
|
|
8
|
+
setup(build: PluginBuild) {
|
|
9
|
+
build.onResolve({ filter: /^[.]/ }, async (args) => {
|
|
10
|
+
let mappedPath: MappedPath | null = null;
|
|
11
|
+
let isSelf = false;
|
|
12
|
+
|
|
13
|
+
if (args.kind === 'import-statement') {
|
|
14
|
+
const importPath = path.join(args.resolveDir, args.path);
|
|
15
|
+
mappedPath = mappedPaths.find((p) =>
|
|
16
|
+
importPath.startsWith(path.dirname(p.path))
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (mappedPath) {
|
|
21
|
+
isSelf = args.importer.startsWith(path.dirname(mappedPath.path));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (mappedPath && !isSelf) {
|
|
25
|
+
return {
|
|
26
|
+
path: mappedPath.key,
|
|
27
|
+
external: true,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return {};
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { FederationOptions } from '@softarc/native-federation/build';
|
|
4
|
+
import { NfBuilderSchema } from '../builders/build/schema';
|
|
5
|
+
|
|
6
|
+
export function updateIndexHtml(
|
|
7
|
+
fedOptions: FederationOptions,
|
|
8
|
+
nfOptions: NfBuilderSchema
|
|
9
|
+
) {
|
|
10
|
+
const outputPath = path.join(fedOptions.workspaceRoot, fedOptions.outputPath);
|
|
11
|
+
const indexPath = path.join(outputPath, 'index.html');
|
|
12
|
+
const mainName = fs
|
|
13
|
+
.readdirSync(outputPath)
|
|
14
|
+
.find((f) => f.startsWith('main') && f.endsWith('.js'));
|
|
15
|
+
const polyfillsName = fs
|
|
16
|
+
.readdirSync(outputPath)
|
|
17
|
+
.find((f) => f.startsWith('polyfills') && f.endsWith('.js'));
|
|
18
|
+
|
|
19
|
+
let indexContent = fs.readFileSync(indexPath, 'utf-8');
|
|
20
|
+
|
|
21
|
+
indexContent = updateScriptTags(
|
|
22
|
+
indexContent,
|
|
23
|
+
mainName,
|
|
24
|
+
polyfillsName,
|
|
25
|
+
nfOptions
|
|
26
|
+
);
|
|
27
|
+
fs.writeFileSync(indexPath, indexContent, 'utf-8');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function updateScriptTags(
|
|
31
|
+
indexContent: string,
|
|
32
|
+
mainName: string,
|
|
33
|
+
polyfillsName: string,
|
|
34
|
+
nfOptions: NfBuilderSchema
|
|
35
|
+
) {
|
|
36
|
+
const esmsOptions = {
|
|
37
|
+
shimMode: true,
|
|
38
|
+
...nfOptions.esmsInitOptions,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const htmlFragment = `
|
|
42
|
+
<script type="esms-options">${JSON.stringify(esmsOptions)}</script>
|
|
43
|
+
|
|
44
|
+
<script type="module" src="${polyfillsName}"></script>
|
|
45
|
+
<script type="module-shim" src="${mainName}"></script>
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
indexContent = indexContent.replace(
|
|
49
|
+
/<script src="polyfills.*?><\/script>/,
|
|
50
|
+
''
|
|
51
|
+
);
|
|
52
|
+
indexContent = indexContent.replace(/<script src="main.*?><\/script>/, '');
|
|
53
|
+
indexContent = indexContent.replace('</body>', `${htmlFragment}</body>`);
|
|
54
|
+
return indexContent;
|
|
55
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
// "strict": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
10
|
+
// "noImplicitReturns": true,
|
|
11
|
+
"noFallthroughCasesInSwitch": true
|
|
12
|
+
},
|
|
13
|
+
"files": [],
|
|
14
|
+
"include": [],
|
|
15
|
+
"references": [
|
|
16
|
+
{
|
|
17
|
+
"path": "./tsconfig.lib.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "./tsconfig.spec.json"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"composite": true,
|
|
5
|
+
"outDir": "../../dist/out-tsc",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"types": ["jest", "node"]
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"jest.config.ts",
|
|
11
|
+
"src/**/*.test.ts",
|
|
12
|
+
"src/**/*.spec.ts",
|
|
13
|
+
"src/**/*.d.ts"
|
|
14
|
+
]
|
|
15
|
+
}
|
package/config.js
DELETED
package/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../libs/native-federation/config.ts"],"names":[],"mappings":";;;AAAA,uDAA6B"}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { BuilderContext, BuilderOutput } from '@angular-devkit/architect';
|
|
2
|
-
import { NfBuilderSchema } from './schema';
|
|
3
|
-
export declare function runBuilder(nfOptions: NfBuilderSchema, context: BuilderContext): AsyncIterable<BuilderOutput>;
|
|
4
|
-
declare const _default: any;
|
|
5
|
-
export default _default;
|
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runBuilder = runBuilder;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const mrmime = tslib_1.__importStar(require("mrmime"));
|
|
8
|
-
const build_1 = require("@angular/build");
|
|
9
|
-
const private_1 = require("@angular/build/private");
|
|
10
|
-
const architect_1 = require("@angular-devkit/architect");
|
|
11
|
-
const options_1 = require("@angular-devkit/build-angular/src/builders/dev-server/options");
|
|
12
|
-
const build_2 = require("@softarc/native-federation/build");
|
|
13
|
-
const build_3 = require("@softarc/native-federation/build");
|
|
14
|
-
const angular_esbuild_adapter_1 = require("../../utils/angular-esbuild-adapter");
|
|
15
|
-
const build_4 = require("@softarc/native-federation/build");
|
|
16
|
-
const build_5 = require("@softarc/native-federation/build");
|
|
17
|
-
const build_6 = require("@softarc/native-federation/build");
|
|
18
|
-
const architect_2 = require("@angular-devkit/architect");
|
|
19
|
-
const dev_server_1 = require("../../utils/dev-server");
|
|
20
|
-
const rebuild_events_1 = require("../../utils/rebuild-events");
|
|
21
|
-
const updateIndexHtml_1 = require("../../utils/updateIndexHtml");
|
|
22
|
-
const fs_1 = require("fs");
|
|
23
|
-
const mem_resuts_1 = require("../../utils/mem-resuts");
|
|
24
|
-
const shared_mappings_plugin_1 = require("../../utils/shared-mappings-plugin");
|
|
25
|
-
function _buildApplication(options, context, pluginsOrExtensions) {
|
|
26
|
-
let extensions;
|
|
27
|
-
if (pluginsOrExtensions && Array.isArray(pluginsOrExtensions)) {
|
|
28
|
-
extensions = {
|
|
29
|
-
codePlugins: pluginsOrExtensions,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
extensions = pluginsOrExtensions;
|
|
34
|
-
}
|
|
35
|
-
return (0, private_1.buildApplicationInternal)(options, context, { write: false }, extensions);
|
|
36
|
-
}
|
|
37
|
-
function runBuilder(nfOptions, context) {
|
|
38
|
-
return tslib_1.__asyncGenerator(this, arguments, function* runBuilder_1() {
|
|
39
|
-
var _a, e_1, _b, _c;
|
|
40
|
-
let target = (0, architect_2.targetFromTargetString)(nfOptions.target);
|
|
41
|
-
let _options = (yield tslib_1.__await(context.getTargetOptions(target)));
|
|
42
|
-
let builder = yield tslib_1.__await(context.getBuilderNameForTarget(target));
|
|
43
|
-
if (builder === '@angular-devkit/build-angular:browser-esbuild') {
|
|
44
|
-
build_2.logger.info('.: NATIVE FEDERATION - UPDATE NEEDED :.');
|
|
45
|
-
build_2.logger.info('');
|
|
46
|
-
build_2.logger.info("Since version 17.1, Native Federation uses Angular's");
|
|
47
|
-
build_2.logger.info('Application-Builder and its Dev-Server.');
|
|
48
|
-
build_2.logger.info('');
|
|
49
|
-
build_2.logger.info('If you are sill on Angular 17.0.x, please update to');
|
|
50
|
-
build_2.logger.info('Angular 17.1.x or downgrade to Native Federation 17.0.x.');
|
|
51
|
-
build_2.logger.info('');
|
|
52
|
-
build_2.logger.info('For working with Native Federation 17.1.x (recommented), ');
|
|
53
|
-
build_2.logger.info('please update your project config, e.g. in angular.json');
|
|
54
|
-
build_2.logger.info('');
|
|
55
|
-
build_2.logger.info('This command performs the needed update for default configs:');
|
|
56
|
-
build_2.logger.info('');
|
|
57
|
-
build_2.logger.info('\tng g @angular-architects/native-federation:appbuilder');
|
|
58
|
-
build_2.logger.info('');
|
|
59
|
-
build_2.logger.info('You need to run it once per application to migrate');
|
|
60
|
-
build_2.logger.info('Please find more information here: https://shorturl.at/gADJW');
|
|
61
|
-
return yield tslib_1.__await(void 0);
|
|
62
|
-
}
|
|
63
|
-
let options = (yield tslib_1.__await(context.validateOptions(_options, builder)));
|
|
64
|
-
const outerOptions = options;
|
|
65
|
-
const normOuterOptions = nfOptions.dev
|
|
66
|
-
? yield tslib_1.__await((0, options_1.normalizeOptions)(context, context.target.project, outerOptions))
|
|
67
|
-
: null;
|
|
68
|
-
if (nfOptions.dev) {
|
|
69
|
-
target = (0, architect_2.targetFromTargetString)(outerOptions.buildTarget);
|
|
70
|
-
_options = (yield tslib_1.__await(context.getTargetOptions(target)));
|
|
71
|
-
builder = yield tslib_1.__await(context.getBuilderNameForTarget(target));
|
|
72
|
-
options = (yield tslib_1.__await(context.validateOptions(_options, builder)));
|
|
73
|
-
}
|
|
74
|
-
const runServer = !!nfOptions.port;
|
|
75
|
-
const write = !runServer;
|
|
76
|
-
const watch = !!runServer || nfOptions.watch;
|
|
77
|
-
options.watch = watch;
|
|
78
|
-
if (nfOptions.baseHref) {
|
|
79
|
-
options.baseHref = nfOptions.baseHref;
|
|
80
|
-
}
|
|
81
|
-
const rebuildEvents = new rebuild_events_1.RebuildHubs();
|
|
82
|
-
const adapter = (0, angular_esbuild_adapter_1.createAngularBuildAdapter)(options, context, rebuildEvents);
|
|
83
|
-
(0, build_3.setBuildAdapter)(adapter);
|
|
84
|
-
(0, build_2.setLogLevel)(options.verbose ? 'verbose' : 'info');
|
|
85
|
-
const outputPath = options.outputPath;
|
|
86
|
-
const outputOptions = Object.assign(Object.assign({ browser: 'browser', server: 'server', media: 'media' }, (typeof outputPath === 'string' ? undefined : outputPath)), { base: typeof outputPath === 'string' ? outputPath : outputPath.base });
|
|
87
|
-
const browserOutputPath = path.join(outputOptions.base, outputOptions.browser);
|
|
88
|
-
const fedOptions = {
|
|
89
|
-
workspaceRoot: context.workspaceRoot,
|
|
90
|
-
outputPath: browserOutputPath,
|
|
91
|
-
federationConfig: infereConfigPath(options.tsConfig),
|
|
92
|
-
tsConfig: options.tsConfig,
|
|
93
|
-
verbose: options.verbose,
|
|
94
|
-
watch: false, // options.watch,
|
|
95
|
-
dev: !!nfOptions.dev,
|
|
96
|
-
};
|
|
97
|
-
const config = yield tslib_1.__await((0, build_5.loadFederationConfig)(fedOptions));
|
|
98
|
-
const externals = (0, build_4.getExternals)(config);
|
|
99
|
-
const plugins = [
|
|
100
|
-
(0, shared_mappings_plugin_1.createSharedMappingsPlugin)(config.sharedMappings),
|
|
101
|
-
{
|
|
102
|
-
name: 'externals',
|
|
103
|
-
setup(build) {
|
|
104
|
-
if (build.initialOptions.platform !== 'node') {
|
|
105
|
-
build.initialOptions.external = externals.filter((e) => e !== 'tslib');
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
const middleware = [
|
|
111
|
-
(req, res, next) => {
|
|
112
|
-
const url = removeBaseHref(req, options.baseHref);
|
|
113
|
-
const fileName = path.join(fedOptions.workspaceRoot, fedOptions.outputPath, url);
|
|
114
|
-
const exists = fs.existsSync(fileName);
|
|
115
|
-
if (url !== '/' && url !== '' && exists) {
|
|
116
|
-
const lookup = mrmime.lookup;
|
|
117
|
-
const mimeType = lookup(path.extname(fileName)) || 'text/javascript';
|
|
118
|
-
const rawBody = fs.readFileSync(fileName, 'utf-8');
|
|
119
|
-
const body = addDebugInformation(url, rawBody);
|
|
120
|
-
res.writeHead(200, {
|
|
121
|
-
'Content-Type': mimeType,
|
|
122
|
-
'Access-Control-Allow-Origin': '*',
|
|
123
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
|
|
124
|
-
'Access-Control-Allow-Headers': 'Content-Type',
|
|
125
|
-
});
|
|
126
|
-
res.end(body);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
next();
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
];
|
|
133
|
-
const memResults = new mem_resuts_1.MemResults();
|
|
134
|
-
let first = true;
|
|
135
|
-
let lastResult;
|
|
136
|
-
if ((0, fs_1.existsSync)(fedOptions.outputPath)) {
|
|
137
|
-
(0, fs_1.rmSync)(fedOptions.outputPath, { recursive: true });
|
|
138
|
-
}
|
|
139
|
-
if (!(0, fs_1.existsSync)(fedOptions.outputPath)) {
|
|
140
|
-
(0, fs_1.mkdirSync)(fedOptions.outputPath, { recursive: true });
|
|
141
|
-
}
|
|
142
|
-
if (!write) {
|
|
143
|
-
(0, angular_esbuild_adapter_1.setMemResultHandler)((outFiles, outDir) => {
|
|
144
|
-
const fullOutDir = outDir
|
|
145
|
-
? path.join(fedOptions.workspaceRoot, outDir)
|
|
146
|
-
: null;
|
|
147
|
-
memResults.add(outFiles.map((f) => new mem_resuts_1.EsBuildResult(f, fullOutDir)));
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
try {
|
|
151
|
-
yield tslib_1.__await((0, build_6.buildForFederation)(config, fedOptions, externals));
|
|
152
|
-
}
|
|
153
|
-
catch (e) {
|
|
154
|
-
process.exit(1);
|
|
155
|
-
}
|
|
156
|
-
options.deleteOutputPath = false;
|
|
157
|
-
// TODO: Clarify how DevServer needs to be executed. Not sure if its right.
|
|
158
|
-
// TODO: Clarify if buildApplication is needed `executeDevServerBuilder` seems to choose the correct DevServer
|
|
159
|
-
const appBuilderName = '@angular-devkit/build-angular:application';
|
|
160
|
-
const builderRun = nfOptions.dev
|
|
161
|
-
? (0, private_1.serveWithVite)(normOuterOptions, appBuilderName, _buildApplication, context, nfOptions.skipHtmlTransform
|
|
162
|
-
? {}
|
|
163
|
-
: { indexHtml: transformIndexHtml(nfOptions) }, {
|
|
164
|
-
buildPlugins: plugins,
|
|
165
|
-
middleware,
|
|
166
|
-
})
|
|
167
|
-
: (0, build_1.buildApplication)(options, context, plugins);
|
|
168
|
-
try {
|
|
169
|
-
// builderRun.output.subscribe(async (output) => {
|
|
170
|
-
for (var _d = true, builderRun_1 = tslib_1.__asyncValues(builderRun), builderRun_1_1; builderRun_1_1 = yield tslib_1.__await(builderRun_1.next()), _a = builderRun_1_1.done, !_a; _d = true) {
|
|
171
|
-
_c = builderRun_1_1.value;
|
|
172
|
-
_d = false;
|
|
173
|
-
const output = _c;
|
|
174
|
-
lastResult = output;
|
|
175
|
-
if (!output.success) {
|
|
176
|
-
(0, dev_server_1.setError)('Compilation Error');
|
|
177
|
-
(0, dev_server_1.reloadBrowser)();
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
(0, dev_server_1.setError)(null);
|
|
182
|
-
}
|
|
183
|
-
if (!write && output.outputFiles) {
|
|
184
|
-
memResults.add(output.outputFiles.map((file) => new mem_resuts_1.EsBuildResult(file)));
|
|
185
|
-
}
|
|
186
|
-
if (!write && output.assetFiles) {
|
|
187
|
-
memResults.add(output.assetFiles.map((file) => new mem_resuts_1.NgCliAssetResult(file)));
|
|
188
|
-
}
|
|
189
|
-
if (write && !nfOptions.dev && !nfOptions.skipHtmlTransform) {
|
|
190
|
-
(0, updateIndexHtml_1.updateIndexHtml)(fedOptions, nfOptions);
|
|
191
|
-
}
|
|
192
|
-
// if (first && runServer) {
|
|
193
|
-
// startServer(nfOptions, fedOptions.outputPath, memResults);
|
|
194
|
-
// }
|
|
195
|
-
// if (!first && runServer) {
|
|
196
|
-
// reloadBrowser();
|
|
197
|
-
// }
|
|
198
|
-
if (!runServer) {
|
|
199
|
-
yield yield tslib_1.__await(output);
|
|
200
|
-
}
|
|
201
|
-
if (!first && nfOptions.dev) {
|
|
202
|
-
setTimeout(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
203
|
-
// logger.info('Rebuilding federation artefacts ...');
|
|
204
|
-
// await Promise.all([rebuildEvents.rebuild.emit()]);
|
|
205
|
-
yield (0, build_6.buildForFederation)(config, fedOptions, externals);
|
|
206
|
-
build_2.logger.info('Done!');
|
|
207
|
-
if (runServer) {
|
|
208
|
-
setTimeout(() => (0, dev_server_1.reloadShell)(nfOptions.shell), 0);
|
|
209
|
-
}
|
|
210
|
-
}), nfOptions.rebuildDelay);
|
|
211
|
-
}
|
|
212
|
-
first = false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
216
|
-
finally {
|
|
217
|
-
try {
|
|
218
|
-
if (!_d && !_a && (_b = builderRun_1.return)) yield tslib_1.__await(_b.call(builderRun_1));
|
|
219
|
-
}
|
|
220
|
-
finally { if (e_1) throw e_1.error; }
|
|
221
|
-
}
|
|
222
|
-
yield yield tslib_1.__await(lastResult || { success: false });
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
226
|
-
exports.default = (0, architect_1.createBuilder)(runBuilder);
|
|
227
|
-
function removeBaseHref(req, baseHref) {
|
|
228
|
-
let url = req.url;
|
|
229
|
-
if (baseHref && url.startsWith(baseHref)) {
|
|
230
|
-
url = url.substr(baseHref.length);
|
|
231
|
-
}
|
|
232
|
-
return url;
|
|
233
|
-
}
|
|
234
|
-
function infereConfigPath(tsConfig) {
|
|
235
|
-
const relProjectPath = path.dirname(tsConfig);
|
|
236
|
-
const relConfigPath = path.join(relProjectPath, 'federation.config.js');
|
|
237
|
-
return relConfigPath;
|
|
238
|
-
}
|
|
239
|
-
function transformIndexHtml(nfOptions) {
|
|
240
|
-
return (content) => Promise.resolve((0, updateIndexHtml_1.updateScriptTags)(content, 'main.js', 'polyfills.js', nfOptions));
|
|
241
|
-
}
|
|
242
|
-
function addDebugInformation(fileName, rawBody) {
|
|
243
|
-
if (fileName !== '/remoteEntry.json') {
|
|
244
|
-
return rawBody;
|
|
245
|
-
}
|
|
246
|
-
const remoteEntry = JSON.parse(rawBody);
|
|
247
|
-
const shared = remoteEntry.shared;
|
|
248
|
-
if (!shared) {
|
|
249
|
-
return rawBody;
|
|
250
|
-
}
|
|
251
|
-
const sharedForVite = shared.map((s) => (Object.assign(Object.assign({}, s), { packageName: `/@id/${s.packageName}` })));
|
|
252
|
-
remoteEntry.shared = [...shared, ...sharedForVite];
|
|
253
|
-
return JSON.stringify(remoteEntry, null, 2);
|
|
254
|
-
}
|
|
255
|
-
//# sourceMappingURL=builder.js.map
|