@angular-architects/native-federation-v4 20.3.7 → 20.3.8

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 (48) hide show
  1. package/collection.json +5 -0
  2. package/migration-collection.json +6 -0
  3. package/package.json +3 -3
  4. package/src/builders/build/builder.d.ts.map +1 -1
  5. package/src/builders/build/builder.js +45 -49
  6. package/src/builders/build/schema.d.ts +3 -5
  7. package/src/builders/build/schema.json +8 -29
  8. package/src/config/angular-skip-list.d.ts +3 -0
  9. package/src/config/angular-skip-list.d.ts.map +1 -0
  10. package/src/config/angular-skip-list.js +13 -0
  11. package/src/config/share-utils.d.ts +9 -0
  12. package/src/config/share-utils.d.ts.map +1 -0
  13. package/src/config/share-utils.js +32 -0
  14. package/src/config.d.ts +2 -2
  15. package/src/config.d.ts.map +1 -1
  16. package/src/config.js +2 -2
  17. package/src/schematics/init/files/federation.config.js__tmpl__ +19 -7
  18. package/src/schematics/init/schema.d.ts +0 -1
  19. package/src/schematics/init/schema.json +2 -6
  20. package/src/schematics/init/schematic.d.ts.map +1 -1
  21. package/src/schematics/init/schematic.js +50 -25
  22. package/src/schematics/update-v4/schema.d.ts +4 -0
  23. package/src/schematics/update-v4/schema.json +23 -0
  24. package/src/schematics/update-v4/schematic.d.ts +4 -0
  25. package/src/schematics/update-v4/schematic.d.ts.map +1 -0
  26. package/src/schematics/update-v4/schematic.js +225 -0
  27. package/src/utils/angular-bundler.d.ts +3 -8
  28. package/src/utils/angular-bundler.d.ts.map +1 -1
  29. package/src/utils/angular-bundler.js +11 -58
  30. package/src/utils/angular-esbuild-adapter.d.ts +5 -4
  31. package/src/utils/angular-esbuild-adapter.d.ts.map +1 -1
  32. package/src/utils/angular-esbuild-adapter.js +14 -17
  33. package/src/utils/angular-locales.d.ts.map +1 -1
  34. package/src/utils/create-federation-tsconfig.d.ts +6 -0
  35. package/src/utils/create-federation-tsconfig.d.ts.map +1 -0
  36. package/src/utils/create-federation-tsconfig.js +49 -0
  37. package/src/utils/get-fallback-platform.d.ts +3 -0
  38. package/src/utils/get-fallback-platform.d.ts.map +1 -0
  39. package/src/utils/get-fallback-platform.js +13 -0
  40. package/src/utils/node-modules-bundler.d.ts +5 -6
  41. package/src/utils/node-modules-bundler.d.ts.map +1 -1
  42. package/src/utils/node-modules-bundler.js +6 -9
  43. package/src/utils/normalize-context-options.d.ts +23 -0
  44. package/src/utils/normalize-context-options.d.ts.map +1 -0
  45. package/src/utils/normalize-context-options.js +18 -0
  46. package/src/utils/shared-mappings-plugin.d.ts +2 -2
  47. package/src/utils/shared-mappings-plugin.d.ts.map +1 -1
  48. package/src/utils/shared-mappings-plugin.js +4 -4
@@ -0,0 +1,49 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import JSON5 from 'json5';
4
+ import { isDeepStrictEqual } from 'util';
5
+ /**
6
+ * Creates a tsconfig.federation.json that includes the federation entry points.
7
+ */
8
+ export function createFederationTsConfig(workspaceRoot, tsConfigPath, entryPoints, optimizedMappings) {
9
+ const fullTsConfigPath = path.join(workspaceRoot, tsConfigPath);
10
+ const tsconfigDir = path.dirname(fullTsConfigPath);
11
+ const tsconfigAsString = fs.readFileSync(fullTsConfigPath, 'utf-8');
12
+ const tsconfig = JSON5.parse(tsconfigAsString);
13
+ tsconfig.files = entryPoints
14
+ .filter(ep => ep.fileName.startsWith('.'))
15
+ .map(ep => path.relative(tsconfigDir, ep.fileName).replace(/\\\\/g, '/'));
16
+ if (optimizedMappings) {
17
+ const filtered = entryPoints
18
+ .filter(ep => !ep.fileName.startsWith('.'))
19
+ .map(ep => path.relative(tsconfigDir, ep.fileName).replace(/\\\\/g, '/'));
20
+ if (!tsconfig.include) {
21
+ tsconfig.include = [];
22
+ }
23
+ for (const ep of filtered) {
24
+ if (!tsconfig.include.includes(ep)) {
25
+ tsconfig.include.push(ep);
26
+ }
27
+ }
28
+ }
29
+ const content = JSON5.stringify(tsconfig, null, 2);
30
+ const tsconfigFedPath = path.join(tsconfigDir, 'tsconfig.federation.json');
31
+ if (!doesFileExistAndJsonEqual(tsconfigFedPath, content)) {
32
+ fs.writeFileSync(tsconfigFedPath, JSON.stringify(tsconfig, null, 2));
33
+ }
34
+ return tsconfigFedPath;
35
+ }
36
+ function doesFileExistAndJsonEqual(filePath, content) {
37
+ if (!fs.existsSync(filePath)) {
38
+ return false;
39
+ }
40
+ try {
41
+ const currentContent = fs.readFileSync(filePath, 'utf-8');
42
+ const currentJson = JSON5.parse(currentContent);
43
+ const newJson = JSON5.parse(content);
44
+ return isDeepStrictEqual(currentJson, newJson);
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ }
@@ -0,0 +1,3 @@
1
+ export declare const DEFAULT_SERVER_DEPS_LIST: string[];
2
+ export declare function getDefaultPlatform(cur: string): 'browser' | 'node';
3
+ //# sourceMappingURL=get-fallback-platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-fallback-platform.d.ts","sourceRoot":"","sources":["../../../src/utils/get-fallback-platform.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAI5C,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAMlE"}
@@ -0,0 +1,13 @@
1
+ export const DEFAULT_SERVER_DEPS_LIST = [
2
+ '@angular/platform-server',
3
+ '@angular/platform-server/init',
4
+ '@angular/ssr',
5
+ ];
6
+ export function getDefaultPlatform(cur) {
7
+ if (DEFAULT_SERVER_DEPS_LIST.find(e => cur.startsWith(e))) {
8
+ return 'node';
9
+ }
10
+ else {
11
+ return 'browser';
12
+ }
13
+ }
@@ -1,12 +1,11 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { type SourceFileCache } from '@angular/build/private';
3
- import type { BuilderContext } from '@angular-devkit/architect';
4
- import type { ApplicationBuilderOptions } from '@angular/build';
5
- import type { EntryPoint, FederationCache } from '@softarc/native-federation';
6
- import type { MappedPath } from '@softarc/native-federation/internal';
2
+ import type { NormalizedContextOptions } from './normalize-context-options.js';
7
3
  export interface NodeModulesBundleResult {
8
4
  ctx: esbuild.BuildContext;
9
5
  pluginDisposed: Promise<void>;
10
6
  }
11
- export declare function createNodeModulesEsbuildContext(builderOptions: ApplicationBuilderOptions, context: BuilderContext, entryPoints: EntryPoint[], external: string[], outdir: string, mappedPaths: MappedPath[], _cache: FederationCache<SourceFileCache>, dev?: boolean, hash?: boolean, chunks?: boolean, platform?: 'browser' | 'node'): Promise<NodeModulesBundleResult>;
7
+ export declare function createNodeModulesEsbuildContext(options: NormalizedContextOptions): Promise<{
8
+ ctx: esbuild.BuildContext;
9
+ pluginDisposed: Promise<void>;
10
+ }>;
12
11
  //# sourceMappingURL=node-modules-bundler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"node-modules-bundler.d.ts","sourceRoot":"","sources":["../../../src/utils/node-modules-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAIL,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAIhE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAwDtE,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAID,wBAAsB,+BAA+B,CACnD,cAAc,EAAE,yBAAyB,EACzC,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,UAAU,EAAE,EACzB,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,UAAU,EAAE,EACzB,MAAM,EAAE,eAAe,CAAC,eAAe,CAAC,EACxC,GAAG,CAAC,EAAE,OAAO,EACb,IAAI,GAAE,OAAe,EACrB,MAAM,CAAC,EAAE,OAAO,EAChB,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CAyElC"}
1
+ {"version":3,"file":"node-modules-bundler.d.ts","sourceRoot":"","sources":["../../../src/utils/node-modules-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAYnC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAsD/E,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAED,wBAAsB,+BAA+B,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAChG,GAAG,EAAE,OAAO,CAAC,YAAY,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B,CAAC,CAwED"}
@@ -3,7 +3,6 @@ import * as path from 'path';
3
3
  import * as fs from 'fs';
4
4
  import { transformSupportedBrowsersToTargets, getSupportedBrowsers, JavaScriptTransformer, } from '@angular/build/private';
5
5
  import { normalizeSourceMaps } from '@angular-devkit/build-angular/src/utils/index.js';
6
- import { createSharedMappingsPlugin } from './shared-mappings-plugin.js';
7
6
  const LINKER_DECLARATION_PREFIX = 'ɵɵngDeclare';
8
7
  /**
9
8
  * Excludes @angular/core and @angular/compiler which define the declarations
@@ -40,7 +39,8 @@ function createAngularLinkerPlugin(jsTransformer, advancedOptimizations) {
40
39
  },
41
40
  };
42
41
  }
43
- export async function createNodeModulesEsbuildContext(builderOptions, context, entryPoints, external, outdir, mappedPaths, _cache, dev, hash = false, chunks, platform) {
42
+ export async function createNodeModulesEsbuildContext(options) {
43
+ const { builderOptions, context, entryPoints, external, outdir, dev, hash, chunks, platform } = options;
44
44
  const workspaceRoot = context.workspaceRoot;
45
45
  const projectMetadata = await context.getProjectMetadata(context.target.project);
46
46
  const projectRoot = path.join(workspaceRoot, projectMetadata['root'] ?? '');
@@ -56,7 +56,8 @@ export async function createNodeModulesEsbuildContext(builderOptions, context, e
56
56
  thirdPartySourcemaps: false,
57
57
  advancedOptimizations,
58
58
  jit: false,
59
- }, 1);
59
+ }, 1 // maxThreads - keep low for node_modules bundling
60
+ );
60
61
  const config = {
61
62
  entryPoints: entryPoints.map(ep => ({
62
63
  in: ep.fileName,
@@ -79,13 +80,9 @@ export async function createNodeModulesEsbuildContext(builderOptions, context, e
79
80
  format: 'esm',
80
81
  target: target,
81
82
  logLimit: 1,
82
- plugins: [
83
- createAngularLinkerPlugin(jsTransformer, advancedOptimizations),
84
- ...(mappedPaths && mappedPaths.length > 0 ? [createSharedMappingsPlugin(mappedPaths)] : []),
85
- commonjsPlugin(),
86
- ],
83
+ plugins: [createAngularLinkerPlugin(jsTransformer, advancedOptimizations), commonjsPlugin()],
87
84
  define: {
88
- ...(!dev ? { ngDevMode: 'false' } : {}),
85
+ ngDevMode: dev ? 'true' : 'false',
89
86
  ngJitMode: 'false',
90
87
  },
91
88
  ...(builderOptions.loader ? { loader: builderOptions.loader } : {}),
@@ -0,0 +1,23 @@
1
+ import type { ApplicationBuilderOptions } from '@angular/build';
2
+ import type { BuilderContext } from '@angular-devkit/architect';
3
+ import type { SourceFileCache } from '@angular/build/private';
4
+ import type { FederationCache, EntryPoint, NFBuildAdapterOptions } from '@softarc/native-federation';
5
+ import type { PathToImport } from '@softarc/native-federation/internal';
6
+ export interface NormalizedContextOptions {
7
+ builderOptions: ApplicationBuilderOptions;
8
+ context: BuilderContext;
9
+ entryPoints: EntryPoint[];
10
+ external: string[];
11
+ outdir: string;
12
+ tsConfigPath?: string;
13
+ mappedPaths: PathToImport;
14
+ cache: FederationCache<SourceFileCache>;
15
+ dev: boolean;
16
+ isMappingOrExposed: boolean;
17
+ hash: boolean;
18
+ chunks?: boolean;
19
+ platform?: 'browser' | 'node';
20
+ optimizedMappings: boolean;
21
+ }
22
+ export declare function normalizeContextOptions(builderOptions: ApplicationBuilderOptions, context: BuilderContext, adapterOptions: NFBuildAdapterOptions<SourceFileCache>): NormalizedContextOptions;
23
+ //# sourceMappingURL=normalize-context-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-context-options.d.ts","sourceRoot":"","sources":["../../../src/utils/normalize-context-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EACV,eAAe,EACf,UAAU,EACV,qBAAqB,EACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,MAAM,WAAW,wBAAwB;IACvC,cAAc,EAAE,yBAAyB,CAAC;IAC1C,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,YAAY,CAAC;IAC1B,KAAK,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC;IACxC,GAAG,EAAE,OAAO,CAAC;IACb,kBAAkB,EAAE,OAAO,CAAC;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,yBAAyB,EACzC,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,qBAAqB,CAAC,eAAe,CAAC,GACrD,wBAAwB,CAiB1B"}
@@ -0,0 +1,18 @@
1
+ export function normalizeContextOptions(builderOptions, context, adapterOptions) {
2
+ return {
3
+ builderOptions,
4
+ context,
5
+ entryPoints: adapterOptions.entryPoints,
6
+ external: adapterOptions.external,
7
+ outdir: adapterOptions.outdir,
8
+ tsConfigPath: adapterOptions.tsConfigPath,
9
+ mappedPaths: adapterOptions.mappedPaths,
10
+ cache: adapterOptions.cache,
11
+ dev: !!adapterOptions.dev,
12
+ isMappingOrExposed: !!adapterOptions.isMappingOrExposed,
13
+ hash: !!adapterOptions.hash,
14
+ chunks: adapterOptions.chunks,
15
+ platform: adapterOptions.platform,
16
+ optimizedMappings: !!adapterOptions.optimizedMappings,
17
+ };
18
+ }
@@ -1,4 +1,4 @@
1
1
  import type { Plugin } from 'esbuild';
2
- import type { MappedPath } from '@softarc/native-federation/internal';
3
- export declare function createSharedMappingsPlugin(mappedPaths: MappedPath[]): Plugin;
2
+ import type { PathToImport } from '@softarc/native-federation/internal';
3
+ export declare function createSharedMappingsPlugin(mappedPaths: PathToImport): Plugin;
4
4
  //# sourceMappingURL=shared-mappings-plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared-mappings-plugin.d.ts","sourceRoot":"","sources":["../../../src/utils/shared-mappings-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,SAAS,CAAC;AAEnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEtE,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,CA8B5E"}
1
+ {"version":3,"file":"shared-mappings-plugin.d.ts","sourceRoot":"","sources":["../../../src/utils/shared-mappings-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAe,MAAM,SAAS,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAExE,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,YAAY,GAAG,MAAM,CA8B5E"}
@@ -4,20 +4,20 @@ export function createSharedMappingsPlugin(mappedPaths) {
4
4
  name: 'custom',
5
5
  setup(build) {
6
6
  build.onResolve({ filter: /^[.]/ }, async (args) => {
7
- let mappedPath = null;
7
+ let mappedPath = undefined;
8
8
  let isSelf = false;
9
9
  if (args.kind === 'import-statement') {
10
10
  const importPath = path.join(args.resolveDir, args.path);
11
11
  if (mappedPaths) {
12
- mappedPath = mappedPaths.find(p => importPath.startsWith(path.dirname(p.path))) ?? null;
12
+ mappedPath = Object.keys(mappedPaths).find(p => importPath.startsWith(path.dirname(p)));
13
13
  }
14
14
  }
15
15
  if (mappedPath) {
16
- isSelf = args.importer.startsWith(path.dirname(mappedPath.path));
16
+ isSelf = args.importer.startsWith(path.dirname(mappedPath));
17
17
  }
18
18
  if (mappedPath && !isSelf) {
19
19
  return {
20
- path: mappedPath.key,
20
+ path: mappedPaths[mappedPath],
21
21
  external: true,
22
22
  };
23
23
  }