@nf-beta/angular 0.0.1 → 0.0.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.
Files changed (95) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +458 -0
  3. package/builders.json +10 -0
  4. package/collection.json +27 -0
  5. package/generators.json +12 -0
  6. package/migration-collection.json +13 -0
  7. package/package.json +18 -8
  8. package/src/builders/build/builder.d.ts +6 -0
  9. package/src/builders/build/builder.d.ts.map +1 -0
  10. package/src/builders/build/builder.js +348 -0
  11. package/src/builders/build/federation-build-notifier.d.ts +70 -0
  12. package/src/builders/build/federation-build-notifier.d.ts.map +1 -0
  13. package/src/builders/build/federation-build-notifier.js +186 -0
  14. package/src/builders/build/schema.d.ts +21 -0
  15. package/src/builders/build/schema.json +84 -0
  16. package/src/config.d.ts +3 -0
  17. package/src/config.d.ts.map +1 -0
  18. package/src/config.js +2 -0
  19. package/src/generators/native-federation/files/src/index.ts__template__ +1 -0
  20. package/src/generators/native-federation/generator.d.ts +4 -0
  21. package/src/generators/native-federation/generator.d.ts.map +1 -0
  22. package/src/generators/native-federation/generator.js +43 -0
  23. package/src/generators/native-federation/schema.d.ts +5 -0
  24. package/src/generators/native-federation/schema.json +29 -0
  25. package/src/index.d.ts +2 -0
  26. package/src/index.d.ts.map +1 -0
  27. package/src/index.js +1 -0
  28. package/src/patch-angular-build.d.ts +2 -0
  29. package/src/patch-angular-build.d.ts.map +1 -0
  30. package/src/patch-angular-build.js +5 -0
  31. package/src/plugin/dev-externals-mixin.d.ts +3 -0
  32. package/src/plugin/dev-externals-mixin.d.ts.map +1 -0
  33. package/src/plugin/dev-externals-mixin.js +29 -0
  34. package/src/plugin/externals-skip-list.d.ts +3 -0
  35. package/src/plugin/externals-skip-list.d.ts.map +1 -0
  36. package/src/plugin/externals-skip-list.js +4 -0
  37. package/src/plugin/index.d.ts +4 -0
  38. package/src/plugin/index.d.ts.map +1 -0
  39. package/src/plugin/index.js +75 -0
  40. package/src/schematics/appbuilder/schema.d.ts +3 -0
  41. package/src/schematics/appbuilder/schema.json +17 -0
  42. package/src/schematics/appbuilder/schematic.d.ts +5 -0
  43. package/src/schematics/appbuilder/schematic.d.ts.map +1 -0
  44. package/src/schematics/appbuilder/schematic.js +83 -0
  45. package/src/schematics/init/files/federation.config.js__tmpl__ +33 -0
  46. package/src/schematics/init/schema.d.ts +6 -0
  47. package/src/schematics/init/schema.json +34 -0
  48. package/src/schematics/init/schematic.d.ts +7 -0
  49. package/src/schematics/init/schematic.d.ts.map +1 -0
  50. package/src/schematics/init/schematic.js +422 -0
  51. package/src/schematics/remove/schema.d.ts +3 -0
  52. package/src/schematics/remove/schema.json +17 -0
  53. package/src/schematics/remove/schematic.d.ts +5 -0
  54. package/src/schematics/remove/schematic.d.ts.map +1 -0
  55. package/src/schematics/remove/schematic.js +109 -0
  56. package/src/schematics/update18/schema.json +7 -0
  57. package/src/schematics/update18/schematic.d.ts +3 -0
  58. package/src/schematics/update18/schematic.d.ts.map +1 -0
  59. package/src/schematics/update18/schematic.js +7 -0
  60. package/src/tools/fstart-as-data-url.d.ts +2 -0
  61. package/src/tools/fstart-as-data-url.d.ts.map +1 -0
  62. package/src/tools/fstart-as-data-url.js +1 -0
  63. package/src/utils/angular-esbuild-adapter.d.ts +10 -0
  64. package/src/utils/angular-esbuild-adapter.d.ts.map +1 -0
  65. package/src/utils/angular-esbuild-adapter.js +289 -0
  66. package/src/utils/angular-locales.d.ts +19 -0
  67. package/src/utils/angular-locales.d.ts.map +1 -0
  68. package/src/utils/angular-locales.js +18 -0
  69. package/src/utils/create-awaitable-compiler-plugin.d.ts +6 -0
  70. package/src/utils/create-awaitable-compiler-plugin.d.ts.map +1 -0
  71. package/src/utils/create-awaitable-compiler-plugin.js +29 -0
  72. package/src/utils/create-compiler-options.d.ts +5 -0
  73. package/src/utils/create-compiler-options.d.ts.map +1 -0
  74. package/src/utils/create-compiler-options.js +42 -0
  75. package/src/utils/event-source.d.ts +10 -0
  76. package/src/utils/event-source.d.ts.map +1 -0
  77. package/src/utils/event-source.js +10 -0
  78. package/src/utils/i18n.d.ts +23 -0
  79. package/src/utils/i18n.d.ts.map +1 -0
  80. package/src/utils/i18n.js +61 -0
  81. package/src/utils/mem-resuts.d.ts +29 -0
  82. package/src/utils/mem-resuts.d.ts.map +1 -0
  83. package/src/utils/mem-resuts.js +50 -0
  84. package/src/utils/patch-angular-build.d.ts +4 -0
  85. package/src/utils/patch-angular-build.d.ts.map +1 -0
  86. package/src/utils/patch-angular-build.js +29 -0
  87. package/src/utils/rebuild-events.d.ts +8 -0
  88. package/src/utils/rebuild-events.d.ts.map +1 -0
  89. package/src/utils/rebuild-events.js +4 -0
  90. package/src/utils/shared-mappings-plugin.d.ts +4 -0
  91. package/src/utils/shared-mappings-plugin.d.ts.map +1 -0
  92. package/src/utils/shared-mappings-plugin.js +28 -0
  93. package/src/utils/updateIndexHtml.d.ts +5 -0
  94. package/src/utils/updateIndexHtml.d.ts.map +1 -0
  95. package/src/utils/updateIndexHtml.js +34 -0
@@ -0,0 +1,84 @@
1
+ {
2
+ "version": 2,
3
+ "outputCapture": "direct-nodejs",
4
+ "$schema": "http://json-schema.org/draft-07/schema",
5
+ "title": "native federation browser builder",
6
+ "description": "builder for native federation browser apps",
7
+ "type": "object",
8
+ "properties": {
9
+ "target": {
10
+ "type": "string",
11
+ "description": "target configured for the esbuild builder"
12
+ },
13
+ "dev": {
14
+ "type": "boolean",
15
+ "description": "Set this to true to start the builder in dev mode",
16
+ "default": false
17
+ },
18
+ "watch": {
19
+ "type": "boolean",
20
+ "default": false
21
+ },
22
+ "port": {
23
+ "type": "number",
24
+ "default": 0
25
+ },
26
+ "open": {
27
+ "type": "boolean",
28
+ "default": true,
29
+ "description": "Open browser?",
30
+ "alias": "o"
31
+ },
32
+ "rebuildDelay": {
33
+ "type": "number",
34
+ "default": 2000,
35
+ "description": "The delay for rebuilding federation artefacts. This allows to have more resources for refreshing your micro frontend in the browser."
36
+ },
37
+ "shell": {
38
+ "type": "string",
39
+ "description": "Experimental",
40
+ "default": ""
41
+ },
42
+ "skipHtmlTransform": {
43
+ "type": "boolean",
44
+ "default": false
45
+ },
46
+ "baseHref": {
47
+ "type": "string"
48
+ },
49
+ "outputPath": {
50
+ "type": "string"
51
+ },
52
+ "esmsInitOptions": {
53
+ "type": "object",
54
+ "description": "Options for esms-module-shims https://github.com/guybedford/es-module-shims?tab=readme-ov-file#init-options",
55
+ "default": {
56
+ "shimMode": true
57
+ }
58
+ },
59
+ "ssr": {
60
+ "type": "boolean",
61
+ "description": "uses federation for ssr in ApplicationBuilder too",
62
+ "default": false
63
+ },
64
+ "devServer": {
65
+ "type": "boolean",
66
+ "description": "can be used to disable the dev server when dev=true"
67
+ },
68
+ "buildNotifications": {
69
+ "type": "object",
70
+ "properties": {
71
+ "enable": {
72
+ "type": "boolean",
73
+ "default": true,
74
+ "description": "Enable build completion notifications for local development. It will send events to notify when the federation build is complete."
75
+ },
76
+ "endpoint": {
77
+ "type": "string",
78
+ "default": "/@angular-architects/native-federation:build-notifications",
79
+ "description": "You can override the default endpoint to send build completion events to."
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,3 @@
1
+ export { findRootTsConfigJson, withNativeFederation, share, shareAll, DEFAULT_SKIP_LIST, } from '@nf-beta/core/build';
2
+ export { shareAngularLocales } from './utils/angular-locales.js';
3
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,EACL,QAAQ,EACR,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
package/src/config.js ADDED
@@ -0,0 +1,2 @@
1
+ export { findRootTsConfigJson, withNativeFederation, share, shareAll, DEFAULT_SKIP_LIST, } from '@nf-beta/core/build';
2
+ export { shareAngularLocales } from './utils/angular-locales.js';
@@ -0,0 +1 @@
1
+ const variable = "<%= projectName %>";
@@ -0,0 +1,4 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import type { NativeFederationGeneratorSchema } from './schema.js';
3
+ export default function (tree: Tree, options: NativeFederationGeneratorSchema): Promise<void>;
4
+ //# sourceMappingURL=generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../../src/generators/native-federation/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAqCnE,yBAA+B,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,+BAA+B,iBAelF"}
@@ -0,0 +1,43 @@
1
+ import { addProjectConfiguration, formatFiles, generateFiles, getWorkspaceLayout, names, offsetFromRoot, } from '@nx/devkit';
2
+ import * as path from 'path';
3
+ function normalizeOptions(tree, options) {
4
+ const name = names(options.name).fileName;
5
+ const projectDirectory = options.directory
6
+ ? `${names(options.directory).fileName}/${name}`
7
+ : name;
8
+ const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');
9
+ const projectRoot = `${getWorkspaceLayout(tree).libsDir}/${projectDirectory}`;
10
+ const parsedTags = options.tags ? options.tags.split(',').map(s => s.trim()) : [];
11
+ return {
12
+ ...options,
13
+ projectName,
14
+ projectRoot,
15
+ projectDirectory,
16
+ parsedTags,
17
+ };
18
+ }
19
+ function addFiles(tree, options) {
20
+ const templateOptions = {
21
+ ...options,
22
+ ...names(options.name),
23
+ offsetFromRoot: offsetFromRoot(options.projectRoot),
24
+ template: '',
25
+ };
26
+ generateFiles(tree, path.join(__dirname, 'files'), options.projectRoot, templateOptions);
27
+ }
28
+ export default async function (tree, options) {
29
+ const normalizedOptions = normalizeOptions(tree, options);
30
+ addProjectConfiguration(tree, normalizedOptions.projectName, {
31
+ root: normalizedOptions.projectRoot,
32
+ projectType: 'library',
33
+ sourceRoot: `${normalizedOptions.projectRoot}/src`,
34
+ targets: {
35
+ build: {
36
+ executor: '@angular-architects/native-federation:build',
37
+ },
38
+ },
39
+ tags: normalizedOptions.parsedTags,
40
+ });
41
+ addFiles(tree, normalizedOptions);
42
+ await formatFiles(tree);
43
+ }
@@ -0,0 +1,5 @@
1
+ export interface NativeFederationGeneratorSchema {
2
+ name: string;
3
+ tags?: string;
4
+ directory?: string;
5
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "cli": "nx",
4
+ "$id": "NativeFederation",
5
+ "title": "",
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "type": "string",
10
+ "description": "",
11
+ "$default": {
12
+ "$source": "argv",
13
+ "index": 0
14
+ },
15
+ "x-prompt": "What name would you like to use?"
16
+ },
17
+ "tags": {
18
+ "type": "string",
19
+ "description": "Add tags to the project (used for linting)",
20
+ "alias": "t"
21
+ },
22
+ "directory": {
23
+ "type": "string",
24
+ "description": "A directory where the project is placed",
25
+ "alias": "d"
26
+ }
27
+ },
28
+ "required": ["name"]
29
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from '@nf-beta/runtime';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
package/src/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '@nf-beta/runtime';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=patch-angular-build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patch-angular-build.d.ts","sourceRoot":"","sources":["../../src/patch-angular-build.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ // import { patchAngularBuild } from './utils/patch-angular-build';
2
+ // const workspaceRoot = process.cwd();
3
+ // patchAngularBuild(workspaceRoot);
4
+ console.log('Please remove the postbuild task calling patch-angular-build. This is not needed since Native Federation 18.1 anymore!');
5
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vite';
2
+ export declare const devExternalsMixin: Partial<Plugin>;
3
+ //# sourceMappingURL=dev-externals-mixin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-externals-mixin.d.ts","sourceRoot":"","sources":["../../../src/plugin/dev-externals-mixin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA8B,MAAM,MAAM,CAAC;AAM/D,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,MAAM,CA0B7C,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { federationBuilder } from '@nf-beta/core/build';
2
+ import { filterExternals } from './externals-skip-list.js';
3
+ // see: https://github.com/vitejs/vite/issues/6393#issuecomment-1006819717
4
+ export const devExternalsMixin = {
5
+ enforce: 'pre',
6
+ config(config) {
7
+ config.optimizeDeps = {
8
+ ...(config.optimizeDeps ?? {}),
9
+ exclude: [
10
+ ...(config.optimizeDeps?.exclude ?? []),
11
+ ...filterExternals(federationBuilder.externals),
12
+ ],
13
+ };
14
+ },
15
+ configResolved(resolvedConfig) {
16
+ const VALID_ID_PREFIX = `/@id/`;
17
+ const reg = new RegExp(`${VALID_ID_PREFIX}(${federationBuilder.externals.join('|')})`, 'g');
18
+ resolvedConfig.plugins.push({
19
+ name: 'vite-plugin-ignore-static-import-replace-idprefix',
20
+ transform: (code) => reg.test(code) ? code.replace(reg, (_m, s1) => s1) : code,
21
+ });
22
+ },
23
+ resolveId(id) {
24
+ if (filterExternals(federationBuilder.externals).includes(id)) {
25
+ return { id, external: true };
26
+ }
27
+ return null;
28
+ },
29
+ };
@@ -0,0 +1,3 @@
1
+ export declare const externalsSkipList: Set<string>;
2
+ export declare function filterExternals(deps: string[]): string[];
3
+ //# sourceMappingURL=externals-skip-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"externals-skip-list.d.ts","sourceRoot":"","sources":["../../../src/plugin/externals-skip-list.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,aAAqB,CAAC;AAEpD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAExD"}
@@ -0,0 +1,4 @@
1
+ export const externalsSkipList = new Set(['tslib']);
2
+ export function filterExternals(deps) {
3
+ return deps.filter((d) => !externalsSkipList.has(d));
4
+ }
@@ -0,0 +1,4 @@
1
+ import type { Plugin } from 'vite';
2
+ import { type BuildHelperParams } from '@nf-beta/core/build';
3
+ export declare const federation: (params: BuildHelperParams) => Plugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAoD,MAAM,MAAM,CAAC;AAIrF,OAAO,EAAE,KAAK,iBAAiB,EAAqB,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,UAAU,GAAI,QAAQ,iBAAiB,KAAG,MAoCtD,CAAC"}
@@ -0,0 +1,75 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { lookup } from 'mrmime';
4
+ import { devExternalsMixin } from './dev-externals-mixin.js';
5
+ import { filterExternals } from './externals-skip-list.js';
6
+ import { federationBuilder } from '@nf-beta/core/build';
7
+ export const federation = (params) => {
8
+ return {
9
+ ...devExternalsMixin,
10
+ name: '@module-federation/vite', // required, will show up in warnings and errors
11
+ async config(config, env) {
12
+ await federationBuilder.init(params);
13
+ if (typeof devExternalsMixin.config === 'function') {
14
+ devExternalsMixin.config.call(this, config, env);
15
+ }
16
+ },
17
+ options(o) {
18
+ o['external'] = filterExternals(federationBuilder.externals);
19
+ },
20
+ async closeBundle() {
21
+ await federationBuilder.build();
22
+ },
23
+ async configureServer(server) {
24
+ const fedInfoRef = {
25
+ federationInfo: federationBuilder.federationInfo,
26
+ };
27
+ await configureDevServer(server, params, fedInfoRef);
28
+ },
29
+ transformIndexHtml(html) {
30
+ const fragment = '<script src="polyfills.js" type="module-shim">';
31
+ const updated = `
32
+ <script type="esms-options">
33
+ {
34
+ "shimMode": true
35
+ }
36
+ </script>
37
+ <script src="polyfills.js" type="module">
38
+ `;
39
+ html = html.replace(/type="module"/g, 'type="module-shim"');
40
+ return html.replace(fragment, updated);
41
+ },
42
+ };
43
+ };
44
+ const configureDevServer = async (server, params, fedInfo) => {
45
+ await federationBuilder.build();
46
+ const op = params.options;
47
+ const dist = path.join(op.workspaceRoot, op.outputPath);
48
+ server.middlewares.use(serveFromDist(dist, fedInfo));
49
+ };
50
+ const serveFromDist = (dist, fedInfoRef) => {
51
+ const fedFiles = new Set([
52
+ ...fedInfoRef.federationInfo.shared.map(s => path.join('/', s.outFileName)),
53
+ ...fedInfoRef.federationInfo.exposes.map(e => path.join('/', e.outFileName)),
54
+ '/remoteEntry.json',
55
+ ]);
56
+ return (req, res, next) => {
57
+ if (!req.url || req.url.endsWith('/index.html') || !fedFiles.has(req.url)) {
58
+ next();
59
+ return;
60
+ }
61
+ const file = path.join(dist, req.url);
62
+ if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
63
+ res.setHeader('Access-Control-Allow-Origin', '*');
64
+ const type = lookup(req.url) || '';
65
+ res.setHeader('Content-Type', type);
66
+ const content = fs.readFileSync(file, 'utf-8');
67
+ // const modified = enhanceFile(file, content);
68
+ const modified = content;
69
+ res.write(modified);
70
+ res.end();
71
+ return;
72
+ }
73
+ next();
74
+ };
75
+ };
@@ -0,0 +1,3 @@
1
+ export interface MfSchematicSchema {
2
+ project: string;
3
+ }
@@ -0,0 +1,17 @@
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
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ import type { Rule, Tree } from '@angular-devkit/schematics';
2
+ import type { MfSchematicSchema } from './schema.js';
3
+ export default function remove(options: MfSchematicSchema): 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/appbuilder/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,CAS/D;AA0FD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAUvD"}
@@ -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"}