@nf-beta/angular 0.0.1 → 0.0.3

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.
Files changed (93) hide show
  1. package/builders.json +10 -0
  2. package/collection.json +27 -0
  3. package/generators.json +12 -0
  4. package/migration-collection.json +13 -0
  5. package/package.json +29 -5
  6. package/src/builders/build/builder.d.ts +6 -0
  7. package/src/builders/build/builder.d.ts.map +1 -0
  8. package/src/builders/build/builder.js +348 -0
  9. package/src/builders/build/federation-build-notifier.d.ts +70 -0
  10. package/src/builders/build/federation-build-notifier.d.ts.map +1 -0
  11. package/src/builders/build/federation-build-notifier.js +186 -0
  12. package/src/builders/build/schema.d.ts +21 -0
  13. package/src/builders/build/schema.json +84 -0
  14. package/src/config.d.ts +3 -0
  15. package/src/config.d.ts.map +1 -0
  16. package/src/config.js +2 -0
  17. package/src/generators/native-federation/files/src/index.ts__template__ +1 -0
  18. package/src/generators/native-federation/generator.d.ts +4 -0
  19. package/src/generators/native-federation/generator.d.ts.map +1 -0
  20. package/src/generators/native-federation/generator.js +43 -0
  21. package/src/generators/native-federation/schema.d.ts +5 -0
  22. package/src/generators/native-federation/schema.json +29 -0
  23. package/src/index.d.ts +2 -0
  24. package/src/index.d.ts.map +1 -0
  25. package/src/index.js +1 -0
  26. package/src/patch-angular-build.d.ts +2 -0
  27. package/src/patch-angular-build.d.ts.map +1 -0
  28. package/src/patch-angular-build.js +5 -0
  29. package/src/plugin/dev-externals-mixin.d.ts +3 -0
  30. package/src/plugin/dev-externals-mixin.d.ts.map +1 -0
  31. package/src/plugin/dev-externals-mixin.js +29 -0
  32. package/src/plugin/externals-skip-list.d.ts +3 -0
  33. package/src/plugin/externals-skip-list.d.ts.map +1 -0
  34. package/src/plugin/externals-skip-list.js +4 -0
  35. package/src/plugin/index.d.ts +4 -0
  36. package/src/plugin/index.d.ts.map +1 -0
  37. package/src/plugin/index.js +75 -0
  38. package/src/schematics/appbuilder/schema.d.ts +3 -0
  39. package/src/schematics/appbuilder/schema.json +17 -0
  40. package/src/schematics/appbuilder/schematic.d.ts +5 -0
  41. package/src/schematics/appbuilder/schematic.d.ts.map +1 -0
  42. package/src/schematics/appbuilder/schematic.js +83 -0
  43. package/src/schematics/init/files/federation.config.js__tmpl__ +33 -0
  44. package/src/schematics/init/schema.d.ts +6 -0
  45. package/src/schematics/init/schema.json +34 -0
  46. package/src/schematics/init/schematic.d.ts +7 -0
  47. package/src/schematics/init/schematic.d.ts.map +1 -0
  48. package/src/schematics/init/schematic.js +422 -0
  49. package/src/schematics/remove/schema.d.ts +3 -0
  50. package/src/schematics/remove/schema.json +17 -0
  51. package/src/schematics/remove/schematic.d.ts +5 -0
  52. package/src/schematics/remove/schematic.d.ts.map +1 -0
  53. package/src/schematics/remove/schematic.js +109 -0
  54. package/src/schematics/update18/schema.json +7 -0
  55. package/src/schematics/update18/schematic.d.ts +3 -0
  56. package/src/schematics/update18/schematic.d.ts.map +1 -0
  57. package/src/schematics/update18/schematic.js +7 -0
  58. package/src/tools/fstart-as-data-url.d.ts +2 -0
  59. package/src/tools/fstart-as-data-url.d.ts.map +1 -0
  60. package/src/tools/fstart-as-data-url.js +1 -0
  61. package/src/utils/angular-esbuild-adapter.d.ts +10 -0
  62. package/src/utils/angular-esbuild-adapter.d.ts.map +1 -0
  63. package/src/utils/angular-esbuild-adapter.js +289 -0
  64. package/src/utils/angular-locales.d.ts +19 -0
  65. package/src/utils/angular-locales.d.ts.map +1 -0
  66. package/src/utils/angular-locales.js +18 -0
  67. package/src/utils/create-awaitable-compiler-plugin.d.ts +6 -0
  68. package/src/utils/create-awaitable-compiler-plugin.d.ts.map +1 -0
  69. package/src/utils/create-awaitable-compiler-plugin.js +29 -0
  70. package/src/utils/create-compiler-options.d.ts +5 -0
  71. package/src/utils/create-compiler-options.d.ts.map +1 -0
  72. package/src/utils/create-compiler-options.js +42 -0
  73. package/src/utils/event-source.d.ts +10 -0
  74. package/src/utils/event-source.d.ts.map +1 -0
  75. package/src/utils/event-source.js +10 -0
  76. package/src/utils/i18n.d.ts +23 -0
  77. package/src/utils/i18n.d.ts.map +1 -0
  78. package/src/utils/i18n.js +61 -0
  79. package/src/utils/mem-resuts.d.ts +29 -0
  80. package/src/utils/mem-resuts.d.ts.map +1 -0
  81. package/src/utils/mem-resuts.js +50 -0
  82. package/src/utils/patch-angular-build.d.ts +4 -0
  83. package/src/utils/patch-angular-build.d.ts.map +1 -0
  84. package/src/utils/patch-angular-build.js +29 -0
  85. package/src/utils/rebuild-events.d.ts +8 -0
  86. package/src/utils/rebuild-events.d.ts.map +1 -0
  87. package/src/utils/rebuild-events.js +4 -0
  88. package/src/utils/shared-mappings-plugin.d.ts +4 -0
  89. package/src/utils/shared-mappings-plugin.d.ts.map +1 -0
  90. package/src/utils/shared-mappings-plugin.js +28 -0
  91. package/src/utils/updateIndexHtml.d.ts +5 -0
  92. package/src/utils/updateIndexHtml.d.ts.map +1 -0
  93. package/src/utils/updateIndexHtml.js +34 -0
@@ -0,0 +1,83 @@
1
+ import * as path from 'path';
2
+ export default function remove(options) {
3
+ return async function (tree /*, context*/) {
4
+ const workspaceFileName = getWorkspaceFileName(tree);
5
+ const workspace = JSON.parse(tree.read(workspaceFileName).toString('utf8'));
6
+ const normalized = normalizeOptions(options, workspace);
7
+ updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName);
8
+ };
9
+ }
10
+ function updateWorkspaceConfig(tree, options, workspace, workspaceFileName) {
11
+ const { projectConfig } = options;
12
+ if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
13
+ throw new Error(`The project doesn't have a build or serve target in angular.json!`);
14
+ }
15
+ if (projectConfig.architect.esbuild) {
16
+ projectConfig.architect.esbuild.builder = '@angular/build:application';
17
+ projectConfig.architect.esbuild.options.browser = projectConfig.architect.esbuild.options.main;
18
+ delete projectConfig.architect.esbuild.options.main;
19
+ }
20
+ if (projectConfig.architect['serve-original']) {
21
+ const target = projectConfig.architect['serve-original'];
22
+ if (target.configurations?.production) {
23
+ target.configurations.production.buildTarget =
24
+ target.configurations.production.buildTarget.replace(':build:', ':esbuild:');
25
+ }
26
+ if (target.configurations?.development) {
27
+ target.configurations.development.buildTarget =
28
+ target.configurations.development.buildTarget.replace(':build:', ':esbuild:');
29
+ }
30
+ }
31
+ if (projectConfig.architect.serve) {
32
+ const target = projectConfig.architect.serve;
33
+ target.options.target = target.options.target.replace(':esbuild:', ':serve-original:');
34
+ delete target.options.port;
35
+ }
36
+ tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
37
+ }
38
+ function normalizeOptions(options, workspace) {
39
+ if (!options.project) {
40
+ options.project = workspace.defaultProject;
41
+ }
42
+ const projects = Object.keys(workspace.projects);
43
+ if (!options.project && projects.length === 0) {
44
+ throw new Error(`No default project found. Please specifiy a project name!`);
45
+ }
46
+ if (!options.project) {
47
+ console.log('Using first configured project as default project: ' + projects[0]);
48
+ options.project = projects[0];
49
+ }
50
+ const projectName = options.project;
51
+ const projectConfig = workspace.projects[projectName];
52
+ if (!projectConfig) {
53
+ throw new Error(`Project ${projectName} not found in angular.json.`);
54
+ }
55
+ const projectRoot = projectConfig.root?.replace(/\\/g, '/');
56
+ const projectSourceRoot = projectConfig.sourceRoot?.replace(/\\/g, '/');
57
+ const manifestPath = path
58
+ .join(projectRoot, 'src/assets/federation.manifest.json')
59
+ .replace(/\\/g, '/');
60
+ const main = projectConfig.architect.build.options.main;
61
+ if (!projectConfig.architect.build.options.polyfills) {
62
+ projectConfig.architect.build.options.polyfills = [];
63
+ }
64
+ const polyfills = projectConfig.architect.build.options.polyfills;
65
+ return {
66
+ polyfills,
67
+ projectName,
68
+ projectRoot,
69
+ projectSourceRoot,
70
+ manifestPath,
71
+ projectConfig,
72
+ main,
73
+ };
74
+ }
75
+ export function getWorkspaceFileName(tree) {
76
+ if (tree.exists('angular.json')) {
77
+ return 'angular.json';
78
+ }
79
+ if (tree.exists('workspace.json')) {
80
+ return 'workspace.json';
81
+ }
82
+ throw new Error("angular.json or workspace.json expected! Did you call this in your project's root?");
83
+ }
@@ -0,0 +1,33 @@
1
+ const { withNativeFederation, shareAll } = require('@angular-architects/native-federation/config');
2
+
3
+ module.exports = withNativeFederation({
4
+ name: '<%=project%>',
5
+
6
+ <% if (type === 'remote') { %>
7
+
8
+ exposes: {
9
+ './Component': './<%=appComponentPath%>',
10
+ },
11
+ <% } %>
12
+ shared: {
13
+ ...shareAll({ singleton: true, strictVersion: true, requiredVersion: 'auto' }),
14
+ },
15
+
16
+ skip: [
17
+ 'rxjs/ajax',
18
+ 'rxjs/fetch',
19
+ 'rxjs/testing',
20
+ 'rxjs/webSocket',
21
+ // Add further packages you don't need at runtime
22
+ ],
23
+
24
+ // Please read our FAQ about sharing libs:
25
+ // https://shorturl.at/jmzH0
26
+
27
+ features: {
28
+ // New feature for more performance and avoiding
29
+ // issues with node libs. Comment this out to
30
+ // get the traditional behavior:
31
+ ignoreUnusedDeps: true
32
+ }
33
+ });
@@ -0,0 +1,6 @@
1
+ export interface NfSchematicSchema {
2
+ project: string;
3
+ port: string;
4
+ nxBuilders: boolean | undefined;
5
+ type: 'host' | 'dynamic-host' | 'remote';
6
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "mf",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "The project to add module federation",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "Project name (press enter for default project)"
15
+ },
16
+ "port": {
17
+ "type": "number",
18
+ "description": "The port to use for the federated module (remote, micro frontend, etc.)",
19
+ "$default": {
20
+ "$source": "argv",
21
+ "index": 1
22
+ }
23
+ },
24
+ "type": {
25
+ "enum": ["host", "dynamic-host", "remote"],
26
+ "type": "string",
27
+ "default": "remote"
28
+ },
29
+ "nxBuilders": {
30
+ "type": "boolean",
31
+ "description": "Use builders provided by Nx instead of ngx-build-plus? Defaults to true for Nx workspaces and false for CLI workspaces."
32
+ }
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ import { type Rule, type Tree } from '@angular-devkit/schematics';
2
+ import type { NfSchematicSchema } from './schema.js';
3
+ export declare function updatePackageJson(tree: Tree): void;
4
+ export default function config(options: NfSchematicSchema): Rule;
5
+ export declare function patchAngularBuild(tree: Tree): void;
6
+ export declare function getWorkspaceFileName(tree: Tree): string;
7
+ //# sourceMappingURL=schematic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schematic.d.ts","sourceRoot":"","sources":["../../../../src/schematics/init/schematic.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,IAAI,EAET,KAAK,IAAI,EAEV,MAAM,4BAA4B,CAAC;AAIpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AA+BrD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CA0BlD;AAED,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAoG/D;AAUD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,QAiB3C;AA0WD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAUvD"}
@@ -0,0 +1,422 @@
1
+ import { apply, chain, mergeWith, move, noop, template, url, } from '@angular-devkit/schematics';
2
+ import { strings } from '@angular-devkit/core';
3
+ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
4
+ import { patchAngularBuildPackageJson, privateEntrySrc } from '../../utils/patch-angular-build.js';
5
+ import { addPackageJsonDependency, getPackageJsonDependency, NodeDependencyType, } from '@schematics/angular/utility/dependencies';
6
+ import * as path from 'path';
7
+ const SSR_VERSION = '^3.3.4';
8
+ export function updatePackageJson(tree) {
9
+ const packageJson = tree.readJson('package.json') ?? {};
10
+ const scriptCall = 'node node_modules/@angular-architects/native-federation/src/patch-angular-build.js';
11
+ if (!packageJson?.['scripts']) {
12
+ packageJson['scripts'] = {};
13
+ }
14
+ let postInstall = (packageJson['scripts']?.['postinstall'] || '');
15
+ if (!postInstall) {
16
+ return;
17
+ }
18
+ if (postInstall.includes(scriptCall)) {
19
+ postInstall = postInstall.replace(scriptCall, '');
20
+ }
21
+ if (postInstall.endsWith(' && ')) {
22
+ postInstall = postInstall.substring(0, postInstall.length - 4);
23
+ }
24
+ packageJson['scripts']['postinstall'] = postInstall;
25
+ tree.overwrite('package.json', JSON.stringify(packageJson, null, 2));
26
+ }
27
+ export default function config(options) {
28
+ return async function (tree, context) {
29
+ const workspaceFileName = getWorkspaceFileName(tree);
30
+ const workspace = JSON.parse(tree.read(workspaceFileName)?.toString('utf8') ?? '{}');
31
+ const normalized = normalizeOptions(options, workspace, tree);
32
+ const { polyfills, projectName, projectRoot, projectSourceRoot, manifestPath, manifestRelPath, main, } = normalized;
33
+ updatePolyfills(tree, polyfills);
34
+ const remoteMap = await generateRemoteMap(workspace, projectName);
35
+ if (options.type === 'dynamic-host' && !tree.exists(manifestPath)) {
36
+ tree.create(manifestPath, JSON.stringify(remoteMap, null, '\t'));
37
+ }
38
+ const federationConfigPath = path.join(projectRoot, 'federation.config.js');
39
+ const exists = tree.exists(federationConfigPath);
40
+ const cand1 = path.join(projectSourceRoot, 'app', 'app.component.ts').replace(/\\/g, '/');
41
+ const cand2 = path.join(projectSourceRoot, 'app', 'app.ts').replace(/\\/g, '/');
42
+ const appComponent = tree.exists(cand1) ? cand1 : tree.exists(cand2) ? cand2 : 'update-this.ts';
43
+ const generateRule = !exists
44
+ ? await generateFederationConfig(remoteMap, projectRoot, projectSourceRoot, appComponent, options)
45
+ : noop;
46
+ const ssr = isSsrProject(normalized);
47
+ const server = ssr ? getSsrFilePath(normalized) : '';
48
+ if (ssr) {
49
+ console.log('SSR detected ...');
50
+ console.log('Activating CORS ...');
51
+ addPackageJsonDependency(tree, {
52
+ name: 'cors',
53
+ type: NodeDependencyType.Default,
54
+ version: '^2.8.5',
55
+ overwrite: false,
56
+ });
57
+ }
58
+ updateWorkspaceConfig(tree, normalized, workspace, workspaceFileName, ssr);
59
+ // updatePackageJson(tree);
60
+ // patchAngularBuild(tree);
61
+ addPackageJsonDependency(tree, {
62
+ name: '@angular/animations',
63
+ type: NodeDependencyType.Default,
64
+ version: getPackageJsonDependency(tree, '@angular/core')?.version || 'latest',
65
+ overwrite: false,
66
+ });
67
+ addPackageJsonDependency(tree, {
68
+ name: '@angular-devkit/build-angular',
69
+ type: NodeDependencyType.Dev,
70
+ version: getPackageJsonDependency(tree, '@angular/build')?.version || 'latest',
71
+ overwrite: false,
72
+ });
73
+ addPackageJsonDependency(tree, {
74
+ name: 'es-module-shims',
75
+ type: NodeDependencyType.Default,
76
+ version: '^1.5.12',
77
+ overwrite: false,
78
+ });
79
+ addPackageJsonDependency(tree, {
80
+ name: '@nf-beta/core-node',
81
+ type: NodeDependencyType.Default,
82
+ version: SSR_VERSION,
83
+ overwrite: true,
84
+ });
85
+ context.addTask(new NodePackageInstallTask());
86
+ return chain([
87
+ generateRule,
88
+ makeMainAsync(main, options, remoteMap, manifestRelPath),
89
+ ssr ? makeServerAsync(server, options, remoteMap) : noop(),
90
+ ]);
91
+ };
92
+ }
93
+ function isSsrProject(normalized) {
94
+ return !!normalized.projectConfig?.architect?.build.options?.ssr;
95
+ }
96
+ function getSsrFilePath(normalized) {
97
+ return normalized.projectConfig.architect.build.options.ssr.entry;
98
+ }
99
+ export function patchAngularBuild(tree) {
100
+ const packagePath = 'node_modules/@angular/build/package.json';
101
+ const privatePath = 'node_modules/@angular/build/private.js';
102
+ if (!tree.exists(packagePath)) {
103
+ return;
104
+ }
105
+ const packageJson = JSON.parse(tree.read(packagePath)?.toString('utf8') ?? '{}');
106
+ patchAngularBuildPackageJson(packageJson);
107
+ tree.overwrite(packagePath, JSON.stringify(packageJson, null, 2));
108
+ if (!tree.exists(privatePath)) {
109
+ tree.create(privatePath, privateEntrySrc);
110
+ }
111
+ else {
112
+ tree.overwrite(privatePath, privateEntrySrc);
113
+ }
114
+ }
115
+ function updateWorkspaceConfig(tree, options, workspace, workspaceFileName, ssr) {
116
+ const { projectConfig, projectName, port } = options;
117
+ if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {
118
+ throw new Error(`The project doesn't have a build or serve target in angular.json!`);
119
+ }
120
+ const originalBuild = projectConfig.architect.build;
121
+ if (originalBuild.builder !== '@angular-devkit/build-angular:application' ||
122
+ originalBuild.builder !== '@angular/build:application') {
123
+ console.log('Switching project to the application builder using esbuild ...');
124
+ originalBuild.builder = '@angular/build:application';
125
+ delete originalBuild.configurations?.development?.buildOptimizer;
126
+ delete originalBuild.configurations?.development?.vendorChunk;
127
+ }
128
+ if (originalBuild.options.main) {
129
+ const main = originalBuild.options.main;
130
+ delete originalBuild.options.main;
131
+ originalBuild.options.browser = main;
132
+ }
133
+ delete originalBuild.options.commonChunk;
134
+ projectConfig.architect.esbuild = originalBuild;
135
+ projectConfig.architect.build = {
136
+ builder: '@angular-architects/native-federation:build',
137
+ options: {},
138
+ configurations: {
139
+ production: {
140
+ target: `${projectName}:esbuild:production`,
141
+ },
142
+ development: {
143
+ target: `${projectName}:esbuild:development`,
144
+ dev: true,
145
+ },
146
+ },
147
+ defaultConfiguration: 'production',
148
+ };
149
+ if (ssr) {
150
+ projectConfig.architect.build.options.ssr = true;
151
+ // projectConfig.architect.esbuild.options.prerender = false;
152
+ }
153
+ const serve = projectConfig.architect.serve;
154
+ serve.options ??= {};
155
+ serve.options.port = port;
156
+ delete serve.options.commonChunk;
157
+ const serveProd = projectConfig.architect.serve.configurations?.production;
158
+ if (serveProd) {
159
+ serveProd.buildTarget = `${projectName}:esbuild:production`;
160
+ delete serveProd.browserTarget;
161
+ }
162
+ const serveDev = projectConfig.architect.serve.configurations?.development;
163
+ if (serveDev) {
164
+ serveDev.buildTarget = `${projectName}:esbuild:development`;
165
+ delete serveDev.browserTarget;
166
+ }
167
+ projectConfig.architect['serve-original'] = projectConfig.architect.serve;
168
+ projectConfig.architect.serve = {
169
+ builder: '@angular-architects/native-federation:build',
170
+ options: {
171
+ target: `${projectName}:serve-original:development`,
172
+ rebuildDelay: 500,
173
+ dev: true,
174
+ cacheExternalArtifacts: false,
175
+ port: 0,
176
+ },
177
+ };
178
+ const serveSsr = projectConfig.architect['serve-ssr'];
179
+ if (serveSsr && !serveSsr.options) {
180
+ serveSsr.options = {};
181
+ }
182
+ if (serveSsr) {
183
+ serveSsr.options.port = port;
184
+ }
185
+ // projectConfig.architect.serve.builder = serveBuilder;
186
+ // TODO: Register further builders when ready
187
+ tree.overwrite(workspaceFileName, JSON.stringify(workspace, null, '\t'));
188
+ }
189
+ function normalizeOptions(options, workspace, tree) {
190
+ if (!options.project) {
191
+ options.project = workspace.defaultProject;
192
+ }
193
+ const projects = Object.keys(workspace.projects);
194
+ if (!options.project && projects.length === 0) {
195
+ throw new Error(`No default project found. Please specifiy a project name!`);
196
+ }
197
+ if (!options.project) {
198
+ console.log('Using first configured project as default project: ' + projects[0]);
199
+ options.project = projects[0];
200
+ }
201
+ const projectName = options.project;
202
+ const projectConfig = workspace.projects[projectName];
203
+ if (!projectConfig) {
204
+ throw new Error(`Project ${projectName} not found in angular.json.`);
205
+ }
206
+ const projectRoot = projectConfig.root?.replace(/\\/g, '/');
207
+ const projectSourceRoot = projectConfig.sourceRoot?.replace(/\\/g, '/');
208
+ const publicPath = path.join(projectRoot, 'public').replace(/\\/g, '/');
209
+ let manifestPath = path.join(publicPath, 'federation.manifest.json').replace(/\\/g, '/');
210
+ let manifestRelPath = 'federation.manifest.json';
211
+ const hasPublicFolder = tree
212
+ .getDir(projectRoot)
213
+ .subdirs.map(p => String(p))
214
+ .includes('public');
215
+ if (!hasPublicFolder) {
216
+ manifestPath = path
217
+ .join(projectRoot, 'src/assets/federation.manifest.json')
218
+ .replace(/\\/g, '/');
219
+ manifestRelPath = 'assets/federation.manifest.json';
220
+ }
221
+ const main = projectConfig.architect.build.options.main || projectConfig.architect.build.options.browser;
222
+ if (!projectConfig.architect.build.options.polyfills) {
223
+ projectConfig.architect.build.options.polyfills = [];
224
+ }
225
+ if (typeof projectConfig.architect.build.options.polyfills === 'string') {
226
+ projectConfig.architect.build.options.polyfills = [
227
+ projectConfig.architect.build.options.polyfills,
228
+ ];
229
+ }
230
+ const polyfills = projectConfig.architect.build.options.polyfills;
231
+ return {
232
+ polyfills,
233
+ projectName,
234
+ projectRoot,
235
+ projectSourceRoot,
236
+ manifestPath,
237
+ manifestRelPath,
238
+ projectConfig,
239
+ main,
240
+ port: +(options.port || 4200),
241
+ };
242
+ }
243
+ function updatePolyfills(tree, polyfills) {
244
+ if (typeof polyfills === 'string') {
245
+ updatePolyfillsFile(tree, polyfills);
246
+ }
247
+ else {
248
+ updatePolyfillsArray(tree, polyfills);
249
+ }
250
+ }
251
+ function updatePolyfillsFile(tree, polyfills) {
252
+ let polyfillsContent = tree.readText(polyfills);
253
+ if (!polyfillsContent.includes('es-module-shims')) {
254
+ polyfillsContent += `\nimport 'es-module-shims';\n`;
255
+ tree.overwrite(polyfills, polyfillsContent);
256
+ }
257
+ }
258
+ function updatePolyfillsArray(_tree, polyfills) {
259
+ const polyfillsConfig = polyfills;
260
+ if (!polyfillsConfig.includes('es-module-shims')) {
261
+ polyfillsConfig.push('es-module-shims');
262
+ }
263
+ }
264
+ function generateRemoteMap(workspace, projectName) {
265
+ const result = {};
266
+ for (const p in workspace.projects) {
267
+ const project = workspace.projects[p];
268
+ const projectType = project.projectType ?? 'application';
269
+ if (p !== projectName &&
270
+ projectType === 'application' &&
271
+ project?.architect?.serve &&
272
+ project?.architect?.build) {
273
+ const pPort = project.architect['serve-original']?.options?.port ??
274
+ project.architect.serve?.options?.port ??
275
+ 4200;
276
+ result[strings.camelize(p)] = `http://localhost:${pPort}/remoteEntry.json`;
277
+ }
278
+ }
279
+ if (Object.keys(result).length === 0) {
280
+ result['mfe1'] = `http://localhost:3000/remoteEntry.json`;
281
+ }
282
+ return result;
283
+ }
284
+ function makeMainAsync(main, options, remoteMap, manifestRelPath) {
285
+ return async function (tree) {
286
+ const mainPath = path.dirname(main);
287
+ const bootstrapName = path.join(mainPath, 'bootstrap.ts');
288
+ if (tree.exists(bootstrapName)) {
289
+ console.info(`${bootstrapName} already exists.`);
290
+ return;
291
+ }
292
+ const mainContent = tree.read(main);
293
+ if (mainContent)
294
+ tree.create(bootstrapName, mainContent);
295
+ let newMainContent = '';
296
+ if (options.type === 'dynamic-host') {
297
+ newMainContent = `import { initFederation } from '@angular-architects/native-federation';
298
+
299
+ initFederation('${manifestRelPath}')
300
+ .catch(err => console.error(err))
301
+ .then(_ => import('./bootstrap'))
302
+ .catch(err => console.error(err));
303
+ `;
304
+ }
305
+ else if (options.type === 'host') {
306
+ const manifest = JSON.stringify(remoteMap, null, 2).replace(/"/g, "'");
307
+ newMainContent = `import { initFederation } from '@angular-architects/native-federation';
308
+
309
+ initFederation(${manifest})
310
+ .catch(err => console.error(err))
311
+ .then(_ => import('./bootstrap'))
312
+ .catch(err => console.error(err));
313
+ `;
314
+ }
315
+ else {
316
+ newMainContent = `import { initFederation } from '@angular-architects/native-federation';
317
+
318
+ initFederation()
319
+ .catch(err => console.error(err))
320
+ .then(_ => import('./bootstrap'))
321
+ .catch(err => console.error(err));
322
+ `;
323
+ }
324
+ tree.overwrite(main, newMainContent);
325
+ };
326
+ }
327
+ function makeServerAsync(server, options, remoteMap) {
328
+ return async function (tree) {
329
+ const mainPath = path.dirname(server);
330
+ const bootstrapName = path.join(mainPath, 'bootstrap-server.ts');
331
+ if (tree.exists(bootstrapName)) {
332
+ console.info(`${bootstrapName} already exists.`);
333
+ return;
334
+ }
335
+ const cors = `import { createRequire } from "module";
336
+ const require = createRequire(import.meta.url);
337
+ const cors = require("cors");
338
+ `;
339
+ const mainContent = tree.read(server)?.toString('utf8');
340
+ const updatedContent = (cors + mainContent)
341
+ .replace(`const port = process.env['PORT'] || 4000`, `const port = process.env['PORT'] || ${options.port || 4000}`)
342
+ .replace(`const app = express();`, `const app = express();\n\tapp.use(cors());\n app.set('view engine', 'html');`)
343
+ .replace(`if (isMainModule(import.meta.url)) {`, ``)
344
+ .replace(/\}(?![\s\S]*\})/, '');
345
+ tree.create(bootstrapName, updatedContent);
346
+ let newMainContent = '';
347
+ if (options.type === 'dynamic-host') {
348
+ newMainContent = `import { initNodeFederation } from '@nf-beta/core-node';
349
+
350
+ console.log('Starting SSR for Shell');
351
+
352
+ (async () => {
353
+
354
+ await initNodeFederation({
355
+ remotesOrManifestUrl: '../browser/federation.manifest.json',
356
+ relBundlePath: '../browser/',
357
+ });
358
+
359
+ await import('./bootstrap-server');
360
+
361
+ })();
362
+ `;
363
+ }
364
+ else if (options.type === 'host') {
365
+ const manifest = JSON.stringify(remoteMap, null, 2).replace(/"/g, "'");
366
+ newMainContent = `import { initNodeFederation } from '@nf-beta/core-node';
367
+
368
+ console.log('Starting SSR for Shell');
369
+
370
+ (async () => {
371
+
372
+ await initNodeFederation({
373
+ remotesOrManifestUrl: ${manifest},
374
+ relBundlePath: '../browser/',
375
+ });
376
+
377
+ await import('./bootstrap-server');
378
+
379
+ })();
380
+ `;
381
+ }
382
+ else {
383
+ newMainContent = `import { initNodeFederation } from '@nf-beta/core-node';
384
+
385
+ (async () => {
386
+
387
+ await initNodeFederation({
388
+ relBundlePath: '../browser/'
389
+ });
390
+
391
+ await import('./bootstrap-server');
392
+
393
+ })();
394
+ `;
395
+ }
396
+ tree.overwrite(server, newMainContent);
397
+ };
398
+ }
399
+ export function getWorkspaceFileName(tree) {
400
+ if (tree.exists('angular.json')) {
401
+ return 'angular.json';
402
+ }
403
+ if (tree.exists('workspace.json')) {
404
+ return 'workspace.json';
405
+ }
406
+ throw new Error("angular.json or workspace.json expected! Did you call this in your project's root?");
407
+ }
408
+ async function generateFederationConfig(remoteMap, projectRoot, projectSourceRoot, appComponentPath, options) {
409
+ const tmpl = url('./files');
410
+ const applied = apply(tmpl, [
411
+ template({
412
+ projectRoot,
413
+ projectSourceRoot,
414
+ appComponentPath,
415
+ remoteMap,
416
+ ...options,
417
+ tmpl: '',
418
+ }),
419
+ move(projectRoot),
420
+ ]);
421
+ return mergeWith(applied);
422
+ }
@@ -0,0 +1,3 @@
1
+ export interface NfSchematicSchema {
2
+ project: string;
3
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "nf",
4
+ "title": "",
5
+ "type": "object",
6
+ "properties": {
7
+ "project": {
8
+ "type": "string",
9
+ "description": "The project to remove native federation from",
10
+ "$default": {
11
+ "$source": "argv",
12
+ "index": 0
13
+ },
14
+ "x-prompt": "Project name (press enter for default project)"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ import type { Rule, Tree } from '@angular-devkit/schematics';
2
+ import type { NfSchematicSchema } from './schema.js';
3
+ export default function remove(options: NfSchematicSchema): Rule;
4
+ export declare function getWorkspaceFileName(tree: Tree): string;
5
+ //# sourceMappingURL=schematic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schematic.d.ts","sourceRoot":"","sources":["../../../../src/schematics/remove/schematic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAcrD,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAgB/D;AAmHD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAUvD"}