@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
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { Rule, Tree } from '@angular-devkit/schematics';
|
|
2
|
-
|
|
3
|
-
import { MfSchematicSchema } from './schema';
|
|
4
|
-
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
|
|
7
|
-
type NormalizedOptions = {
|
|
8
|
-
polyfills: string;
|
|
9
|
-
projectName: string;
|
|
10
|
-
projectRoot: string;
|
|
11
|
-
projectSourceRoot: string;
|
|
12
|
-
manifestPath: string;
|
|
13
|
-
projectConfig: any;
|
|
14
|
-
main: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export default function remove(options: MfSchematicSchema): Rule {
|
|
18
|
-
return async function (tree /*, context*/) {
|
|
19
|
-
const workspaceFileName = getWorkspaceFileName(tree);
|
|
20
|
-
const workspace = JSON.parse(tree.read(workspaceFileName).toString('utf8'));
|
|
21
|
-
|
|
22
|
-
const normalized = normalizeOptions(options, workspace);
|
|
23
|
-
|
|
24
|
-
updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function updateWorkspaceConfig(
|
|
29
|
-
tree: Tree,
|
|
30
|
-
options: NormalizedOptions,
|
|
31
|
-
workspace: any,
|
|
32
|
-
workspaceFileName: string
|
|
33
|
-
) {
|
|
34
|
-
const { projectConfig } = options;
|
|
35
|
-
|
|
36
|
-
if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`The project doen't have a build or serve target in angular.json!`
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (projectConfig.architect.esbuild) {
|
|
43
|
-
projectConfig.architect.esbuild.builder =
|
|
44
|
-
'@angular-devkit/build-angular:application';
|
|
45
|
-
projectConfig.architect.esbuild.options.browser =
|
|
46
|
-
projectConfig.architect.esbuild.options.main;
|
|
47
|
-
delete projectConfig.architect.esbuild.options.main;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (projectConfig.architect['serve-original']) {
|
|
51
|
-
const target = projectConfig.architect['serve-original'];
|
|
52
|
-
if (target.configurations?.production) {
|
|
53
|
-
target.configurations.production.buildTarget =
|
|
54
|
-
target.configurations.production.buildTarget.replace(
|
|
55
|
-
':build:',
|
|
56
|
-
':esbuild:'
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
if (target.configurations?.development) {
|
|
60
|
-
target.configurations.development.buildTarget =
|
|
61
|
-
target.configurations.development.buildTarget.replace(
|
|
62
|
-
':build:',
|
|
63
|
-
':esbuild:'
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (projectConfig.architect.serve) {
|
|
69
|
-
const target = projectConfig.architect.serve;
|
|
70
|
-
target.options.target = target.options.target.replace(
|
|
71
|
-
':esbuild:',
|
|
72
|
-
':serve-original:'
|
|
73
|
-
);
|
|
74
|
-
delete target.options.port;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function normalizeOptions(
|
|
81
|
-
options: MfSchematicSchema,
|
|
82
|
-
workspace: any
|
|
83
|
-
): NormalizedOptions {
|
|
84
|
-
if (!options.project) {
|
|
85
|
-
options.project = workspace.defaultProject;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const projects = Object.keys(workspace.projects);
|
|
89
|
-
|
|
90
|
-
if (!options.project && projects.length === 0) {
|
|
91
|
-
throw new Error(
|
|
92
|
-
`No default project found. Please specifiy a project name!`
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!options.project) {
|
|
97
|
-
console.log(
|
|
98
|
-
'Using first configured project as default project: ' + projects[0]
|
|
99
|
-
);
|
|
100
|
-
options.project = projects[0];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const projectName = options.project;
|
|
104
|
-
const projectConfig = workspace.projects[projectName];
|
|
105
|
-
|
|
106
|
-
if (!projectConfig) {
|
|
107
|
-
throw new Error(`Project ${projectName} not found!`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const projectRoot: string = projectConfig.root?.replace(/\\/g, '/');
|
|
111
|
-
const projectSourceRoot: string = projectConfig.sourceRoot?.replace(
|
|
112
|
-
/\\/g,
|
|
113
|
-
'/'
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
const manifestPath = path
|
|
117
|
-
.join(projectRoot, 'src/assets/federation.manifest.json')
|
|
118
|
-
.replace(/\\/g, '/');
|
|
119
|
-
|
|
120
|
-
const main = projectConfig.architect.build.options.main;
|
|
121
|
-
|
|
122
|
-
if (!projectConfig.architect.build.options.polyfills) {
|
|
123
|
-
projectConfig.architect.build.options.polyfills = [];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const polyfills = projectConfig.architect.build.options.polyfills;
|
|
127
|
-
return {
|
|
128
|
-
polyfills,
|
|
129
|
-
projectName,
|
|
130
|
-
projectRoot,
|
|
131
|
-
projectSourceRoot,
|
|
132
|
-
manifestPath,
|
|
133
|
-
projectConfig,
|
|
134
|
-
main,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function getWorkspaceFileName(tree: Tree): string {
|
|
139
|
-
if (tree.exists('angular.json')) {
|
|
140
|
-
return 'angular.json';
|
|
141
|
-
}
|
|
142
|
-
if (tree.exists('workspace.json')) {
|
|
143
|
-
return 'workspace.json';
|
|
144
|
-
}
|
|
145
|
-
throw new Error(
|
|
146
|
-
"angular.json or workspace.json expected! Did you call this in your project's root?"
|
|
147
|
-
);
|
|
148
|
-
}
|
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
chain,
|
|
3
|
-
Rule,
|
|
4
|
-
Tree,
|
|
5
|
-
url,
|
|
6
|
-
apply,
|
|
7
|
-
mergeWith,
|
|
8
|
-
template,
|
|
9
|
-
move,
|
|
10
|
-
noop,
|
|
11
|
-
} from '@angular-devkit/schematics';
|
|
12
|
-
|
|
13
|
-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
|
|
14
|
-
import { strings } from '@angular-devkit/core';
|
|
15
|
-
import { MfSchematicSchema } from './schema';
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
patchAngularBuildPackageJson,
|
|
19
|
-
privateEntrySrc,
|
|
20
|
-
} from '../../utils/patch-angular-build';
|
|
21
|
-
|
|
22
|
-
import {
|
|
23
|
-
addPackageJsonDependency,
|
|
24
|
-
NodeDependencyType,
|
|
25
|
-
} from '@schematics/angular/utility/dependencies';
|
|
26
|
-
|
|
27
|
-
import * as path from 'path';
|
|
28
|
-
|
|
29
|
-
type NormalizedOptions = {
|
|
30
|
-
polyfills: string;
|
|
31
|
-
projectName: string;
|
|
32
|
-
projectRoot: string;
|
|
33
|
-
projectSourceRoot: string;
|
|
34
|
-
manifestPath: string;
|
|
35
|
-
manifestRelPath: string;
|
|
36
|
-
projectConfig: any;
|
|
37
|
-
main: string;
|
|
38
|
-
port: number;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export function updatePackageJson(tree: Tree): void {
|
|
42
|
-
const packageJson = tree.readJson('package.json');
|
|
43
|
-
|
|
44
|
-
const scriptCall =
|
|
45
|
-
'node node_modules/@angular-architects/native-federation/src/patch-angular-build.js';
|
|
46
|
-
|
|
47
|
-
if (!packageJson['scripts']) {
|
|
48
|
-
packageJson['scripts'] = {};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let postInstall = (packageJson['scripts']?.['postinstall'] || '') as string;
|
|
52
|
-
|
|
53
|
-
if (!postInstall) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (postInstall.includes(scriptCall)) {
|
|
58
|
-
postInstall = postInstall.replace(scriptCall, '');
|
|
59
|
-
}
|
|
60
|
-
if (postInstall.endsWith(' && ')) {
|
|
61
|
-
postInstall = postInstall.substring(0, postInstall.length - 4);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
packageJson['scripts']['postinstall'] = postInstall;
|
|
65
|
-
|
|
66
|
-
tree.overwrite('package.json', JSON.stringify(packageJson, null, 2));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default function config(options: MfSchematicSchema): Rule {
|
|
70
|
-
return async function (tree, context) {
|
|
71
|
-
const workspaceFileName = getWorkspaceFileName(tree);
|
|
72
|
-
const workspace = JSON.parse(tree.read(workspaceFileName).toString('utf8'));
|
|
73
|
-
|
|
74
|
-
const normalized = normalizeOptions(options, workspace, tree);
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
polyfills,
|
|
78
|
-
projectName,
|
|
79
|
-
projectRoot,
|
|
80
|
-
projectSourceRoot,
|
|
81
|
-
manifestPath,
|
|
82
|
-
manifestRelPath,
|
|
83
|
-
main,
|
|
84
|
-
} = normalized;
|
|
85
|
-
|
|
86
|
-
updatePolyfills(tree, polyfills);
|
|
87
|
-
|
|
88
|
-
const remoteMap = await generateRemoteMap(workspace, projectName);
|
|
89
|
-
|
|
90
|
-
if (options.type === 'dynamic-host' && !tree.exists(manifestPath)) {
|
|
91
|
-
tree.create(manifestPath, JSON.stringify(remoteMap, null, '\t'));
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const federationConfigPath = path.join(projectRoot, 'federation.config.js');
|
|
95
|
-
|
|
96
|
-
const exists = tree.exists(federationConfigPath);
|
|
97
|
-
|
|
98
|
-
const generateRule = !exists
|
|
99
|
-
? await generateFederationConfig(
|
|
100
|
-
remoteMap,
|
|
101
|
-
projectRoot,
|
|
102
|
-
projectSourceRoot,
|
|
103
|
-
options
|
|
104
|
-
)
|
|
105
|
-
: noop;
|
|
106
|
-
|
|
107
|
-
updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName);
|
|
108
|
-
|
|
109
|
-
// updatePackageJson(tree);
|
|
110
|
-
// patchAngularBuild(tree);
|
|
111
|
-
|
|
112
|
-
addPackageJsonDependency(tree, {
|
|
113
|
-
name: 'es-module-shims',
|
|
114
|
-
type: NodeDependencyType.Default,
|
|
115
|
-
version: '^1.5.12',
|
|
116
|
-
overwrite: false,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
context.addTask(new NodePackageInstallTask());
|
|
120
|
-
|
|
121
|
-
return chain([
|
|
122
|
-
generateRule,
|
|
123
|
-
makeMainAsync(main, options, remoteMap, manifestRelPath),
|
|
124
|
-
]);
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function patchAngularBuild(tree: Tree) {
|
|
129
|
-
const packagePath = 'node_modules/@angular/build/package.json';
|
|
130
|
-
const privatePath = 'node_modules/@angular/build/private.js';
|
|
131
|
-
|
|
132
|
-
if (!tree.exists(packagePath)) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const packageJson = JSON.parse(tree.read(packagePath).toString('utf8'));
|
|
137
|
-
patchAngularBuildPackageJson(packageJson);
|
|
138
|
-
tree.overwrite(packagePath, JSON.stringify(packageJson, null, 2));
|
|
139
|
-
|
|
140
|
-
if (!tree.exists(privatePath)) {
|
|
141
|
-
tree.create(privatePath, privateEntrySrc);
|
|
142
|
-
} else {
|
|
143
|
-
tree.overwrite(privatePath, privateEntrySrc);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function updateWorkspaceConfig(
|
|
148
|
-
tree: Tree,
|
|
149
|
-
options: NormalizedOptions,
|
|
150
|
-
workspace: any,
|
|
151
|
-
workspaceFileName: string
|
|
152
|
-
) {
|
|
153
|
-
const { projectConfig, projectName, port } = options;
|
|
154
|
-
|
|
155
|
-
if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
`The project doen't have a build or serve target in angular.json!`
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const originalBuild = projectConfig.architect.build;
|
|
162
|
-
|
|
163
|
-
if (originalBuild.builder !== '@angular-devkit/build-angular:application') {
|
|
164
|
-
console.log(
|
|
165
|
-
'Switching project to the application builder using esbuild ...'
|
|
166
|
-
);
|
|
167
|
-
originalBuild.builder = '@angular-devkit/build-angular:application';
|
|
168
|
-
delete originalBuild.configurations?.development?.buildOptimizer;
|
|
169
|
-
delete originalBuild.configurations?.development?.vendorChunk;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (originalBuild.options.main) {
|
|
173
|
-
const main = originalBuild.options.main;
|
|
174
|
-
delete originalBuild.options.main;
|
|
175
|
-
originalBuild.options.browser = main;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
delete originalBuild.options.commonChunk;
|
|
179
|
-
|
|
180
|
-
projectConfig.architect.esbuild = originalBuild;
|
|
181
|
-
|
|
182
|
-
projectConfig.architect.build = {
|
|
183
|
-
builder: '@angular-architects/native-federation:build',
|
|
184
|
-
options: {},
|
|
185
|
-
configurations: {
|
|
186
|
-
production: {
|
|
187
|
-
target: `${projectName}:esbuild:production`,
|
|
188
|
-
},
|
|
189
|
-
development: {
|
|
190
|
-
target: `${projectName}:esbuild:development`,
|
|
191
|
-
dev: true,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
defaultConfiguration: 'production',
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const serve = projectConfig.architect.serve;
|
|
198
|
-
serve.options ??= {};
|
|
199
|
-
serve.options.port = port;
|
|
200
|
-
|
|
201
|
-
delete serve.options.commonChunk;
|
|
202
|
-
|
|
203
|
-
const serveProd = projectConfig.architect.serve.configurations?.production;
|
|
204
|
-
if (serveProd) {
|
|
205
|
-
serveProd.buildTarget = `${projectName}:esbuild:production`;
|
|
206
|
-
delete serveProd.browserTarget;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
const serveDev = projectConfig.architect.serve.configurations?.development;
|
|
210
|
-
if (serveDev) {
|
|
211
|
-
serveDev.buildTarget = `${projectName}:esbuild:development`;
|
|
212
|
-
delete serveDev.browserTarget;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
projectConfig.architect['serve-original'] = projectConfig.architect.serve;
|
|
216
|
-
|
|
217
|
-
projectConfig.architect.serve = {
|
|
218
|
-
builder: '@angular-architects/native-federation:build',
|
|
219
|
-
options: {
|
|
220
|
-
target: `${projectName}:serve-original:development`,
|
|
221
|
-
rebuildDelay: 0,
|
|
222
|
-
dev: true,
|
|
223
|
-
port: 0,
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
const serveSsr = projectConfig.architect['serve-ssr'];
|
|
228
|
-
if (serveSsr && !serveSsr.options) {
|
|
229
|
-
serveSsr.options = {};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (serveSsr) {
|
|
233
|
-
serveSsr.options.port = port;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// projectConfig.architect.serve.builder = serveBuilder;
|
|
237
|
-
// TODO: Register further builders when ready
|
|
238
|
-
tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function normalizeOptions(
|
|
242
|
-
options: MfSchematicSchema,
|
|
243
|
-
workspace: any,
|
|
244
|
-
tree: Tree
|
|
245
|
-
): NormalizedOptions {
|
|
246
|
-
if (!options.project) {
|
|
247
|
-
options.project = workspace.defaultProject;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const projects = Object.keys(workspace.projects);
|
|
251
|
-
|
|
252
|
-
if (!options.project && projects.length === 0) {
|
|
253
|
-
throw new Error(
|
|
254
|
-
`No default project found. Please specifiy a project name!`
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if (!options.project) {
|
|
259
|
-
console.log(
|
|
260
|
-
'Using first configured project as default project: ' + projects[0]
|
|
261
|
-
);
|
|
262
|
-
options.project = projects[0];
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const projectName = options.project;
|
|
266
|
-
const projectConfig = workspace.projects[projectName];
|
|
267
|
-
|
|
268
|
-
if (!projectConfig) {
|
|
269
|
-
throw new Error(`Project ${projectName} not found!`);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const projectRoot: string = projectConfig.root?.replace(/\\/g, '/');
|
|
273
|
-
const projectSourceRoot: string = projectConfig.sourceRoot?.replace(
|
|
274
|
-
/\\/g,
|
|
275
|
-
'/'
|
|
276
|
-
);
|
|
277
|
-
|
|
278
|
-
const publicPath = path.join(projectRoot, 'public').replace(/\\/g, '/');
|
|
279
|
-
|
|
280
|
-
let manifestPath = path
|
|
281
|
-
.join(publicPath, 'federation.manifest.json')
|
|
282
|
-
.replace(/\\/g, '/');
|
|
283
|
-
|
|
284
|
-
let manifestRelPath = 'public/federation.manifest.json';
|
|
285
|
-
|
|
286
|
-
const hasPublicFolder = tree
|
|
287
|
-
.getDir(projectRoot)
|
|
288
|
-
.subdirs.map((p) => String(p))
|
|
289
|
-
.includes('public');
|
|
290
|
-
|
|
291
|
-
if (!hasPublicFolder) {
|
|
292
|
-
manifestPath = path
|
|
293
|
-
.join(projectRoot, 'src/assets/federation.manifest.json')
|
|
294
|
-
.replace(/\\/g, '/');
|
|
295
|
-
|
|
296
|
-
manifestRelPath = 'assets/federation.manifest.json';
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const main =
|
|
300
|
-
projectConfig.architect.build.options.main ||
|
|
301
|
-
projectConfig.architect.build.options.browser;
|
|
302
|
-
|
|
303
|
-
if (!projectConfig.architect.build.options.polyfills) {
|
|
304
|
-
projectConfig.architect.build.options.polyfills = [];
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (typeof projectConfig.architect.build.options.polyfills === 'string') {
|
|
308
|
-
projectConfig.architect.build.options.polyfills = [
|
|
309
|
-
projectConfig.architect.build.options.polyfills,
|
|
310
|
-
];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const polyfills = projectConfig.architect.build.options.polyfills;
|
|
314
|
-
return {
|
|
315
|
-
polyfills,
|
|
316
|
-
projectName,
|
|
317
|
-
projectRoot,
|
|
318
|
-
projectSourceRoot,
|
|
319
|
-
manifestPath,
|
|
320
|
-
manifestRelPath,
|
|
321
|
-
projectConfig,
|
|
322
|
-
main,
|
|
323
|
-
port: +(options.port || 4200),
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function updatePolyfills(tree, polyfills: any) {
|
|
328
|
-
if (typeof polyfills === 'string') {
|
|
329
|
-
updatePolyfillsFile(tree, polyfills);
|
|
330
|
-
} else {
|
|
331
|
-
updatePolyfillsArray(tree, polyfills);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function updatePolyfillsFile(tree, polyfills: any) {
|
|
336
|
-
let polyfillsContent = tree.readText(polyfills);
|
|
337
|
-
if (!polyfillsContent.includes('es-module-shims')) {
|
|
338
|
-
polyfillsContent += `\nimport 'es-module-shims';\n`;
|
|
339
|
-
tree.overwrite(polyfills, polyfillsContent);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function updatePolyfillsArray(tree, polyfills: any) {
|
|
344
|
-
const polyfillsConfig = polyfills as string[];
|
|
345
|
-
|
|
346
|
-
if (!polyfillsConfig.includes('es-module-shims')) {
|
|
347
|
-
polyfillsConfig.push('es-module-shims');
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
function generateRemoteMap(workspace: any, projectName: string) {
|
|
352
|
-
const result = {};
|
|
353
|
-
|
|
354
|
-
for (const p in workspace.projects) {
|
|
355
|
-
const project = workspace.projects[p];
|
|
356
|
-
const projectType = project.projectType ?? 'application';
|
|
357
|
-
|
|
358
|
-
if (
|
|
359
|
-
p !== projectName &&
|
|
360
|
-
projectType === 'application' &&
|
|
361
|
-
project?.architect?.serve &&
|
|
362
|
-
project?.architect?.build
|
|
363
|
-
) {
|
|
364
|
-
const pPort =
|
|
365
|
-
project.architect['serve-original']?.options?.port ??
|
|
366
|
-
project.architect.serve?.options?.port ??
|
|
367
|
-
4200;
|
|
368
|
-
result[
|
|
369
|
-
strings.camelize(p)
|
|
370
|
-
] = `http://localhost:${pPort}/remoteEntry.json`;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
if (Object.keys(result).length === 0) {
|
|
375
|
-
result['mfe1'] = `http://localhost:3000/remoteEntry.json`;
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
return result;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function makeMainAsync(
|
|
382
|
-
main: string,
|
|
383
|
-
options: MfSchematicSchema,
|
|
384
|
-
remoteMap: unknown,
|
|
385
|
-
manifestRelPath: string
|
|
386
|
-
): Rule {
|
|
387
|
-
return async function (tree) {
|
|
388
|
-
const mainPath = path.dirname(main);
|
|
389
|
-
const bootstrapName = path.join(mainPath, 'bootstrap.ts');
|
|
390
|
-
|
|
391
|
-
if (tree.exists(bootstrapName)) {
|
|
392
|
-
console.info(`${bootstrapName} already exists.`);
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
const mainContent = tree.read(main);
|
|
397
|
-
tree.create(bootstrapName, mainContent);
|
|
398
|
-
|
|
399
|
-
let newMainContent = '';
|
|
400
|
-
if (options.type === 'dynamic-host') {
|
|
401
|
-
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
|
|
402
|
-
|
|
403
|
-
initFederation('${manifestRelPath}')
|
|
404
|
-
.catch(err => console.error(err))
|
|
405
|
-
.then(_ => import('./bootstrap'))
|
|
406
|
-
.catch(err => console.error(err));
|
|
407
|
-
`;
|
|
408
|
-
} else if (options.type === 'host') {
|
|
409
|
-
const manifest = JSON.stringify(remoteMap, null, 2).replace(/"/g, "'");
|
|
410
|
-
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
|
|
411
|
-
|
|
412
|
-
initFederation(${manifest})
|
|
413
|
-
.catch(err => console.error(err))
|
|
414
|
-
.then(_ => import('./bootstrap'))
|
|
415
|
-
.catch(err => console.error(err));
|
|
416
|
-
`;
|
|
417
|
-
} else {
|
|
418
|
-
newMainContent = `import { initFederation } from '@angular-architects/native-federation';
|
|
419
|
-
|
|
420
|
-
initFederation()
|
|
421
|
-
.catch(err => console.error(err))
|
|
422
|
-
.then(_ => import('./bootstrap'))
|
|
423
|
-
.catch(err => console.error(err));
|
|
424
|
-
`;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
tree.overwrite(main, newMainContent);
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export function getWorkspaceFileName(tree: Tree): string {
|
|
432
|
-
if (tree.exists('angular.json')) {
|
|
433
|
-
return 'angular.json';
|
|
434
|
-
}
|
|
435
|
-
if (tree.exists('workspace.json')) {
|
|
436
|
-
return 'workspace.json';
|
|
437
|
-
}
|
|
438
|
-
throw new Error(
|
|
439
|
-
"angular.json or workspace.json expected! Did you call this in your project's root?"
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
async function generateFederationConfig(
|
|
444
|
-
remoteMap: Record<string, string>,
|
|
445
|
-
projectRoot: string,
|
|
446
|
-
projectSourceRoot: string,
|
|
447
|
-
options: MfSchematicSchema
|
|
448
|
-
) {
|
|
449
|
-
const tmpl = url('./files');
|
|
450
|
-
|
|
451
|
-
const applied = apply(tmpl, [
|
|
452
|
-
template({
|
|
453
|
-
projectRoot,
|
|
454
|
-
projectSourceRoot,
|
|
455
|
-
remoteMap,
|
|
456
|
-
...options,
|
|
457
|
-
tmpl: '',
|
|
458
|
-
}),
|
|
459
|
-
move(projectRoot),
|
|
460
|
-
]);
|
|
461
|
-
|
|
462
|
-
return mergeWith(applied);
|
|
463
|
-
}
|