@angular-architects/native-federation 18.2.0 → 18.2.2
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/config.js +5 -0
- package/config.js.map +1 -0
- package/package.json +4 -3
- package/src/builders/build/builder.d.ts +5 -0
- package/src/builders/build/builder.js +255 -0
- package/src/builders/build/builder.js.map +1 -0
- package/src/config.d.ts +2 -0
- package/src/config.js +10 -0
- package/src/config.js.map +1 -0
- package/src/executors/build/executor.d.ts +4 -0
- package/src/executors/build/executor.js +13 -0
- package/src/executors/build/executor.js.map +1 -0
- package/src/generators/native-federation/generator.d.ts +3 -0
- package/src/generators/native-federation/generator.js +44 -0
- package/src/generators/native-federation/generator.js.map +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -0
- package/src/patch-angular-build.d.ts +1 -0
- package/src/patch-angular-build.js +7 -0
- package/src/patch-angular-build.js.map +1 -0
- package/src/plugin/dev-externals-mixin.d.ts +1 -0
- package/src/plugin/dev-externals-mixin.js +30 -0
- package/src/plugin/dev-externals-mixin.js.map +1 -0
- package/src/plugin/externals-skip-list.d.ts +2 -0
- package/src/plugin/externals-skip-list.js +9 -0
- package/src/plugin/externals-skip-list.js.map +1 -0
- package/src/plugin/index.d.ts +2 -0
- package/src/plugin/index.js +107 -0
- package/src/plugin/index.js.map +1 -0
- package/src/schematics/appbuilder/schematic.d.ts +4 -0
- package/src/schematics/appbuilder/schematic.js +95 -0
- package/src/schematics/appbuilder/schematic.js.map +1 -0
- package/src/schematics/init/schematic.d.ts +6 -0
- package/src/schematics/init/schematic.js +316 -0
- package/src/schematics/init/schematic.js.map +1 -0
- package/src/schematics/remove/schematic.d.ts +4 -0
- package/src/schematics/remove/schematic.js +119 -0
- package/src/schematics/remove/schematic.js.map +1 -0
- package/src/schematics/update18/schematic.d.ts +2 -0
- package/src/schematics/update18/schematic.js +14 -0
- package/src/schematics/update18/schematic.js.map +1 -0
- package/src/utils/angular-esbuild-adapter.d.ts +9 -0
- package/src/utils/angular-esbuild-adapter.js +274 -0
- package/src/utils/angular-esbuild-adapter.js.map +1 -0
- package/src/utils/create-compiler-options.d.ts +4 -0
- package/src/utils/create-compiler-options.js +45 -0
- package/src/utils/create-compiler-options.js.map +1 -0
- package/src/utils/dev-server.d.ts +7 -0
- package/src/utils/dev-server.js +94 -0
- package/src/utils/dev-server.js.map +1 -0
- package/src/utils/event-sorce.d.ts +9 -0
- package/src/utils/event-sorce.js +20 -0
- package/src/utils/event-sorce.js.map +1 -0
- package/src/utils/mem-resuts.d.ts +29 -0
- package/src/utils/mem-resuts.js +58 -0
- package/src/utils/mem-resuts.js.map +1 -0
- package/src/utils/patch-angular-build.d.ts +3 -0
- package/src/utils/patch-angular-build.js +36 -0
- package/src/utils/patch-angular-build.js.map +1 -0
- package/src/utils/rebuild-events.d.ts +7 -0
- package/src/utils/rebuild-events.js +11 -0
- package/src/utils/rebuild-events.js.map +1 -0
- package/src/utils/shared-mappings-plugin.d.ts +3 -0
- package/src/utils/shared-mappings-plugin.js +31 -0
- package/src/utils/shared-mappings-plugin.js.map +1 -0
- package/src/utils/updateIndexHtml.d.ts +4 -0
- package/src/utils/updateIndexHtml.js +34 -0
- package/src/utils/updateIndexHtml.js.map +1 -0
- package/.eslintrc.json +0 -25
- package/docs/migrate.md +0 -173
- package/docs/share-faq.md +0 -57
- package/docs/update18.md +0 -19
- package/example.png +0 -0
- package/jest.config.ts +0 -11
- package/post-build.js +0 -10
- package/project.json +0 -80
- package/src/builders/build/builder.ts +0 -370
- package/src/config.ts +0 -6
- package/src/executors/build/executor.spec.ts +0 -11
- package/src/executors/build/executor.ts +0 -12
- package/src/generators/native-federation/generator.spec.ts +0 -20
- package/src/generators/native-federation/generator.ts +0 -76
- package/src/patch-angular-build.ts +0 -8
- package/src/plugin/dev-externals-mixin.ts +0 -34
- package/src/plugin/externals-skip-list.ts +0 -5
- package/src/plugin/index.ts +0 -123
- package/src/schematics/appbuilder/schematic.ts +0 -148
- package/src/schematics/init/schematic.ts +0 -463
- package/src/schematics/remove/schematic.ts +0 -179
- package/src/schematics/update18/schematic.ts +0 -10
- package/src/utils/angular-esbuild-adapter.ts +0 -438
- package/src/utils/create-compiler-options.ts +0 -68
- package/src/utils/dev-server.ts +0 -117
- package/src/utils/event-sorce.ts +0 -18
- package/src/utils/mem-resuts.ts +0 -67
- package/src/utils/patch-angular-build.ts +0 -47
- package/src/utils/rebuild-events.ts +0 -9
- package/src/utils/shared-mappings-plugin.ts +0 -35
- package/src/utils/updateIndexHtml.ts +0 -55
- package/tsconfig.json +0 -23
- package/tsconfig.lib.json +0 -11
- package/tsconfig.spec.json +0 -15
- /package/{config.ts → config.d.ts} +0 -0
- /package/src/{index.ts → index.d.ts} +0 -0
package/src/utils/dev-server.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/event-sorce.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|
package/src/utils/mem-resuts.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
}
|
package/tsconfig.lib.json
DELETED
package/tsconfig.spec.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
File without changes
|
|
File without changes
|