@softarc/native-federation 4.0.0-RC1 → 4.0.0-RC10

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 (139) hide show
  1. package/package.json +2 -2
  2. package/src/config.d.ts +0 -1
  3. package/src/domain.d.ts +0 -1
  4. package/src/index.d.ts +3 -2
  5. package/src/index.js +3 -1
  6. package/src/internal.d.ts +5 -4
  7. package/src/internal.js +3 -1
  8. package/src/lib/config/configuration-context.d.ts +0 -1
  9. package/src/lib/config/default-skip-list.d.ts +0 -1
  10. package/src/lib/config/default-skip-list.js +3 -15
  11. package/src/lib/config/remove-unused-deps.d.ts +3 -0
  12. package/src/lib/config/remove-unused-deps.js +10 -0
  13. package/src/lib/config/share-utils.d.ts +0 -2
  14. package/src/lib/config/share-utils.js +7 -13
  15. package/src/lib/config/with-native-federation.d.ts +0 -1
  16. package/src/lib/config/with-native-federation.js +41 -59
  17. package/src/lib/core/build-adapter.d.ts +0 -1
  18. package/src/lib/core/build-adapter.js +5 -5
  19. package/src/lib/core/build-for-federation.d.ts +2 -5
  20. package/src/lib/core/build-for-federation.js +68 -59
  21. package/src/lib/core/bundle-exposed-and-mappings.d.ts +5 -6
  22. package/src/lib/core/bundle-exposed-and-mappings.js +56 -28
  23. package/src/lib/core/bundle-shared.d.ts +8 -5
  24. package/src/lib/core/bundle-shared.js +41 -18
  25. package/src/lib/core/default-external-list.d.ts +0 -1
  26. package/src/lib/core/default-external-list.js +1 -4
  27. package/src/lib/core/federation-builder.d.ts +6 -2
  28. package/src/lib/core/federation-builder.js +19 -8
  29. package/src/lib/core/federation-cache.d.ts +8 -0
  30. package/src/lib/core/federation-cache.js +11 -0
  31. package/src/lib/core/get-externals.d.ts +0 -1
  32. package/src/lib/core/get-externals.js +1 -1
  33. package/src/lib/core/normalize-options.d.ts +12 -0
  34. package/src/lib/core/normalize-options.js +57 -0
  35. package/src/lib/core/rebuild-for-federation.d.ts +4 -0
  36. package/src/lib/core/rebuild-for-federation.js +37 -0
  37. package/src/lib/core/write-federation-info.d.ts +0 -1
  38. package/src/lib/core/write-import-map.d.ts +5 -3
  39. package/src/lib/core/write-import-map.js +10 -1
  40. package/src/lib/domain/config/external-config.contract.d.ts +5 -2
  41. package/src/lib/domain/config/federation-config.contract.d.ts +10 -3
  42. package/src/lib/domain/config/index.d.ts +0 -1
  43. package/src/lib/domain/config/skip-list.contract.d.ts +0 -1
  44. package/src/lib/domain/config/with-native-federation.contract.d.ts +2 -0
  45. package/src/lib/domain/core/build-adapter.contract.d.ts +23 -11
  46. package/src/lib/domain/core/build-notification-options.contract.d.ts +0 -1
  47. package/src/lib/domain/core/chunk.d.ts +2 -0
  48. package/src/lib/domain/core/chunk.js +8 -0
  49. package/src/lib/domain/core/federation-cache.contract.d.ts +7 -0
  50. package/src/lib/domain/core/federation-cache.contract.js +1 -0
  51. package/src/lib/domain/core/federation-info.contract.d.ts +6 -2
  52. package/src/lib/domain/core/federation-options.contract.d.ts +8 -2
  53. package/src/lib/domain/core/index.d.ts +5 -5
  54. package/src/lib/domain/core/index.js +1 -0
  55. package/src/lib/domain/utils/index.d.ts +1 -2
  56. package/src/lib/domain/utils/keyvaluepair.contract.d.ts +0 -1
  57. package/src/lib/domain/utils/mapped-path.contract.d.ts +1 -5
  58. package/src/lib/domain/utils/mapped-path.contract.js +4 -0
  59. package/src/lib/domain/utils/used-dependencies.contract.d.ts +5 -0
  60. package/src/lib/domain/utils/used-dependencies.contract.js +1 -0
  61. package/src/lib/utils/build-result-map.d.ts +1 -1
  62. package/src/lib/utils/build-result-map.js +9 -2
  63. package/src/lib/utils/{bundle-caching.d.ts → cache-persistence.d.ts} +4 -3
  64. package/src/lib/utils/{bundle-caching.js → cache-persistence.js} +2 -2
  65. package/src/lib/utils/errors.d.ts +0 -1
  66. package/src/lib/utils/get-external-imports.d.ts +0 -1
  67. package/src/lib/utils/get-used-dependencies.d.ts +7 -0
  68. package/src/lib/utils/get-used-dependencies.js +123 -0
  69. package/src/lib/utils/hash-file.d.ts +0 -1
  70. package/src/lib/utils/logger.d.ts +0 -1
  71. package/src/lib/utils/mapped-paths.d.ts +7 -8
  72. package/src/lib/utils/mapped-paths.js +14 -12
  73. package/src/lib/utils/normalize.d.ts +0 -1
  74. package/src/lib/utils/package-info.d.ts +0 -1
  75. package/src/lib/utils/rebuild-queue.d.ts +14 -2
  76. package/src/lib/utils/rebuild-queue.js +32 -12
  77. package/src/lib/utils/resolve-glob.d.ts +0 -1
  78. package/src/lib/utils/resolve-glob.js +4 -4
  79. package/src/lib/utils/resolve-wildcard-keys.d.ts +29 -3
  80. package/src/lib/utils/resolve-wildcard-keys.js +105 -38
  81. package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -3
  82. package/src/lib/utils/rewrite-chunk-imports.js +3 -10
  83. package/src/config.d.ts.map +0 -1
  84. package/src/domain.d.ts.map +0 -1
  85. package/src/index.d.ts.map +0 -1
  86. package/src/internal.d.ts.map +0 -1
  87. package/src/lib/config/configuration-context.d.ts.map +0 -1
  88. package/src/lib/config/default-skip-list.d.ts.map +0 -1
  89. package/src/lib/config/share-utils.d.ts.map +0 -1
  90. package/src/lib/config/with-native-federation.d.ts.map +0 -1
  91. package/src/lib/core/build-adapter.d.ts.map +0 -1
  92. package/src/lib/core/build-for-federation.d.ts.map +0 -1
  93. package/src/lib/core/bundle-exposed-and-mappings.d.ts.map +0 -1
  94. package/src/lib/core/bundle-shared.d.ts.map +0 -1
  95. package/src/lib/core/default-external-list.d.ts.map +0 -1
  96. package/src/lib/core/default-server-deps-list.d.ts +0 -3
  97. package/src/lib/core/default-server-deps-list.d.ts.map +0 -1
  98. package/src/lib/core/default-server-deps-list.js +0 -6
  99. package/src/lib/core/federation-builder.d.ts.map +0 -1
  100. package/src/lib/core/get-externals.d.ts.map +0 -1
  101. package/src/lib/core/load-federation-config.d.ts +0 -4
  102. package/src/lib/core/load-federation-config.d.ts.map +0 -1
  103. package/src/lib/core/load-federation-config.js +0 -18
  104. package/src/lib/core/remove-unused-deps.d.ts +0 -3
  105. package/src/lib/core/remove-unused-deps.d.ts.map +0 -1
  106. package/src/lib/core/remove-unused-deps.js +0 -88
  107. package/src/lib/core/write-federation-info.d.ts.map +0 -1
  108. package/src/lib/core/write-import-map.d.ts.map +0 -1
  109. package/src/lib/domain/config/external-config.contract.d.ts.map +0 -1
  110. package/src/lib/domain/config/federation-config.contract.d.ts.map +0 -1
  111. package/src/lib/domain/config/index.d.ts.map +0 -1
  112. package/src/lib/domain/config/skip-list.contract.d.ts.map +0 -1
  113. package/src/lib/domain/core/build-adapter.contract.d.ts.map +0 -1
  114. package/src/lib/domain/core/build-notification-options.contract.d.ts.map +0 -1
  115. package/src/lib/domain/core/build-params.contract.d.ts +0 -6
  116. package/src/lib/domain/core/build-params.contract.d.ts.map +0 -1
  117. package/src/lib/domain/core/federation-info.contract.d.ts.map +0 -1
  118. package/src/lib/domain/core/federation-options.contract.d.ts.map +0 -1
  119. package/src/lib/domain/core/index.d.ts.map +0 -1
  120. package/src/lib/domain/utils/index.d.ts.map +0 -1
  121. package/src/lib/domain/utils/keyvaluepair.contract.d.ts.map +0 -1
  122. package/src/lib/domain/utils/mapped-path.contract.d.ts.map +0 -1
  123. package/src/lib/utils/build-result-map.d.ts.map +0 -1
  124. package/src/lib/utils/build-utils.d.ts +0 -3
  125. package/src/lib/utils/build-utils.d.ts.map +0 -1
  126. package/src/lib/utils/build-utils.js +0 -5
  127. package/src/lib/utils/bundle-caching.d.ts.map +0 -1
  128. package/src/lib/utils/errors.d.ts.map +0 -1
  129. package/src/lib/utils/get-external-imports.d.ts.map +0 -1
  130. package/src/lib/utils/hash-file.d.ts.map +0 -1
  131. package/src/lib/utils/logger.d.ts.map +0 -1
  132. package/src/lib/utils/mapped-paths.d.ts.map +0 -1
  133. package/src/lib/utils/normalize.d.ts.map +0 -1
  134. package/src/lib/utils/package-info.d.ts.map +0 -1
  135. package/src/lib/utils/rebuild-queue.d.ts.map +0 -1
  136. package/src/lib/utils/resolve-glob.d.ts.map +0 -1
  137. package/src/lib/utils/resolve-wildcard-keys.d.ts.map +0 -1
  138. package/src/lib/utils/rewrite-chunk-imports.d.ts.map +0 -1
  139. /package/src/lib/domain/{core/build-params.contract.js → config/with-native-federation.contract.js} +0 -0
@@ -1,4 +1,3 @@
1
1
  export type { ExternalConfig, IncludeSecondariesOptions, SharedExternalsConfig, ShareAllExternalsOptions, ShareExternalsOptions, } from './external-config.contract.js';
2
2
  export type { FederationConfig } from './federation-config.contract.js';
3
3
  export type { PreparedSkipList, SkipFn, SkipList, SkipListEntry } from './skip-list.contract.js';
4
- //# sourceMappingURL=index.d.ts.map
@@ -6,4 +6,3 @@ export type PreparedSkipList = {
6
6
  functions: SkipFn[];
7
7
  regexps: RegExp[];
8
8
  };
9
- //# sourceMappingURL=skip-list.contract.d.ts.map
@@ -0,0 +1,2 @@
1
+ import type { NormalizedFederationConfig } from './federation-config.contract.js';
2
+ export type WithNativeFederation = NormalizedFederationConfig;
@@ -1,28 +1,40 @@
1
- import type { MappedPath } from '../utils/mapped-path.contract.js';
2
- export type NFBuildAdapter = (options: NFBuildAdapterOptions) => Promise<NFBuildAdapterResult[]>;
3
- export type BuildKind = 'shared-package' | 'shared-mapping' | 'exposed' | 'mapping-or-exposed';
1
+ import type { PathToImport } from '../utils/mapped-path.contract.js';
2
+ import type { FederationCache } from './federation-cache.contract.js';
3
+ export interface NFBuildAdapterContext<TBundlerContext = unknown> {
4
+ ctx: TBundlerContext;
5
+ outdir: string;
6
+ dev: boolean;
7
+ name: string;
8
+ isMappingOrExposed: boolean;
9
+ }
10
+ export interface NFBuildAdapter {
11
+ setup(name: string, options: NFBuildAdapterOptions): Promise<void>;
12
+ build(name: string, opts?: {
13
+ modifiedFiles?: string[];
14
+ signal?: AbortSignal;
15
+ }): Promise<NFBuildAdapterResult[]>;
16
+ dispose(name?: string): Promise<void>;
17
+ }
4
18
  export interface EntryPoint {
5
19
  fileName: string;
6
20
  outName: string;
7
21
  key?: string;
8
22
  }
9
- export interface NFBuildAdapterOptions {
23
+ export interface NFBuildAdapterOptions<TBundlerCache = unknown> {
10
24
  entryPoints: EntryPoint[];
11
25
  tsConfigPath?: string;
12
- external: Array<string>;
26
+ external: string[];
13
27
  outdir: string;
14
- mappedPaths: MappedPath[];
15
- packageName?: string;
16
- esm?: boolean;
28
+ mappedPaths: PathToImport;
29
+ isMappingOrExposed: boolean;
17
30
  dev?: boolean;
18
31
  watch?: boolean;
19
- kind: BuildKind;
32
+ chunks?: boolean;
20
33
  hash: boolean;
21
34
  platform?: 'browser' | 'node';
22
35
  optimizedMappings?: boolean;
23
- signal?: AbortSignal;
36
+ cache: FederationCache<TBundlerCache>;
24
37
  }
25
38
  export interface NFBuildAdapterResult {
26
39
  fileName: string;
27
40
  }
28
- //# sourceMappingURL=build-adapter.contract.d.ts.map
@@ -7,4 +7,3 @@ export declare enum BuildNotificationType {
7
7
  ERROR = "federation-rebuild-error",
8
8
  CANCELLED = "federation-rebuild-cancelled"
9
9
  }
10
- //# sourceMappingURL=build-notification-options.contract.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const CHUNK_PREFIX = "@nf-internal";
2
+ export declare function toChunkImport(fileName: string): string;
@@ -0,0 +1,8 @@
1
+ export const CHUNK_PREFIX = '@nf-internal';
2
+ export function toChunkImport(fileName) {
3
+ if (fileName.startsWith('./')) {
4
+ fileName = fileName.slice(2);
5
+ }
6
+ const packageName = fileName.replace(/.(m|c)?js$/, '');
7
+ return CHUNK_PREFIX + '/' + packageName;
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { ChunkInfo, SharedInfo } from './federation-info.contract.js';
2
+ export type FederationCache<TBundlerCache = unknown> = {
3
+ externals: SharedInfo[];
4
+ chunks?: ChunkInfo;
5
+ bundlerCache: TBundlerCache;
6
+ cachePath: string;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -2,6 +2,7 @@ export interface FederationInfo {
2
2
  name: string;
3
3
  exposes: ExposesInfo[];
4
4
  shared: SharedInfo[];
5
+ chunks?: Record<string, string[]>;
5
6
  buildNotificationsEndpoint?: string;
6
7
  }
7
8
  export type SharedInfo = {
@@ -10,11 +11,14 @@ export type SharedInfo = {
10
11
  requiredVersion: string;
11
12
  version?: string;
12
13
  packageName: string;
14
+ shareScope?: string;
15
+ bundle?: string;
13
16
  outFileName: string;
14
17
  dev?: {
15
18
  entryPoint: string;
16
19
  };
17
20
  };
21
+ export type ChunkInfo = Record<string, string[]>;
18
22
  export interface ExposesInfo {
19
23
  key: string;
20
24
  outFileName: string;
@@ -22,8 +26,8 @@ export interface ExposesInfo {
22
26
  entryPoint: string;
23
27
  };
24
28
  }
25
- export interface ArtefactInfo {
29
+ export interface ArtifactInfo {
26
30
  mappings: SharedInfo[];
27
31
  exposes: ExposesInfo[];
32
+ chunks?: ChunkInfo;
28
33
  }
29
- //# sourceMappingURL=federation-info.contract.d.ts.map
@@ -1,15 +1,21 @@
1
1
  import type { BuildNotificationOptions } from './build-notification-options.contract.js';
2
+ import type { FederationCache } from './federation-cache.contract.js';
2
3
  export interface FederationOptions {
3
4
  workspaceRoot: string;
4
5
  outputPath: string;
5
6
  federationConfig: string;
7
+ projectName?: string;
6
8
  cacheExternalArtifacts?: boolean;
7
9
  tsConfig?: string;
8
10
  verbose?: boolean;
9
11
  dev?: boolean;
10
12
  watch?: boolean;
11
13
  packageJson?: string;
12
- entryPoint?: string;
14
+ entryPoints?: string[];
13
15
  buildNotifications?: BuildNotificationOptions;
14
16
  }
15
- //# sourceMappingURL=federation-options.contract.d.ts.map
17
+ export interface NormalizedFederationOptions<TBundlerCache = unknown> extends FederationOptions {
18
+ federationCache: FederationCache<TBundlerCache>;
19
+ entryPoints: string[];
20
+ projectName: string;
21
+ }
@@ -1,6 +1,6 @@
1
- export type { SharedInfo, FederationInfo, ExposesInfo, ArtefactInfo, } from './federation-info.contract.js';
1
+ export type { SharedInfo, FederationInfo, ExposesInfo, ArtifactInfo, ChunkInfo, } from './federation-info.contract.js';
2
2
  export { type BuildNotificationOptions, BuildNotificationType, } from './build-notification-options.contract.js';
3
- export type { FederationOptions } from './federation-options.contract.js';
4
- export type { BuildKind, EntryPoint, NFBuildAdapterOptions, NFBuildAdapter, NFBuildAdapterResult, } from './build-adapter.contract.js';
5
- export type { BuildParams } from './build-params.contract.js';
6
- //# sourceMappingURL=index.d.ts.map
3
+ export type { FederationOptions, NormalizedFederationOptions, } from './federation-options.contract.js';
4
+ export type { EntryPoint, NFBuildAdapterOptions, NFBuildAdapter, NFBuildAdapterResult, NFBuildAdapterContext, } from './build-adapter.contract.js';
5
+ export { CHUNK_PREFIX, toChunkImport } from './chunk.js';
6
+ export type { FederationCache } from './federation-cache.contract.js';
@@ -1 +1,2 @@
1
1
  export { BuildNotificationType, } from './build-notification-options.contract.js';
2
+ export { CHUNK_PREFIX, toChunkImport } from './chunk.js';
@@ -1,3 +1,2 @@
1
1
  export type { KeyValuePair } from './keyvaluepair.contract.js';
2
- export type { MappedPath } from './mapped-path.contract.js';
3
- //# sourceMappingURL=index.d.ts.map
2
+ export type { PathToImport } from './mapped-path.contract.js';
@@ -2,4 +2,3 @@ export type KeyValuePair = {
2
2
  key: string;
3
3
  value: string;
4
4
  };
5
- //# sourceMappingURL=keyvaluepair.contract.d.ts.map
@@ -1,5 +1 @@
1
- export interface MappedPath {
2
- key: string;
3
- path: string;
4
- }
5
- //# sourceMappingURL=mapped-path.contract.d.ts.map
1
+ export type PathToImport = Record<string, string>;
@@ -1 +1,5 @@
1
+ // export interface MappedPath {
2
+ // key: string;
3
+ // path: string;
4
+ // }
1
5
  export {};
@@ -0,0 +1,5 @@
1
+ import type { PathToImport } from './mapped-path.contract.js';
2
+ export type UsedDependencies = {
3
+ external: Set<string>;
4
+ internal: PathToImport;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
1
  import type { NFBuildAdapterResult } from '../domain/core/build-adapter.contract.js';
2
2
  export declare function createBuildResultMap(buildResult: NFBuildAdapterResult[], isHashed: boolean): Record<string, string>;
3
3
  export declare function lookupInResultMap(map: Record<string, string>, requestName: string): string;
4
- //# sourceMappingURL=build-result-map.d.ts.map
4
+ export declare function popFromResultMap(map: Record<string, string>, requestName: string): string;
@@ -11,11 +11,18 @@ export function createBuildResultMap(buildResult, isHashed) {
11
11
  const part2 = resultName.substring(end);
12
12
  requestName = part1 + part2;
13
13
  }
14
- map[requestName] = resultName;
14
+ map[requestName] = item.fileName;
15
15
  }
16
16
  return map;
17
17
  }
18
18
  export function lookupInResultMap(map, requestName) {
19
19
  const key = path.basename(requestName);
20
- return map[key];
20
+ // path.basename is to maintain backwards compatible
21
+ return path.basename(map[key]);
22
+ }
23
+ export function popFromResultMap(map, requestName) {
24
+ const key = path.basename(requestName);
25
+ const out = map[key];
26
+ delete map[key];
27
+ return out;
21
28
  }
@@ -1,20 +1,21 @@
1
1
  import type { NormalizedExternalConfig } from '../domain/config/external-config.contract.js';
2
- import type { SharedInfo } from '../domain/core/federation-info.contract.js';
3
- export declare const getCachePath: (workspaceRoot: string, project: string) => string;
2
+ import type { ChunkInfo, SharedInfo } from '../domain/core/federation-info.contract.js';
3
+ export declare const getDefaultCachePath: (workspaceRoot: string) => string;
4
4
  export declare const getFilename: (title: string, dev?: boolean) => string;
5
5
  export declare const getChecksum: (shared: Record<string, NormalizedExternalConfig>, dev: "1" | "0") => string;
6
6
  export declare const cacheEntry: (pathToCache: string, fileName: string) => {
7
7
  getMetadata: (checksum: string) => {
8
8
  checksum: string;
9
9
  externals: SharedInfo[];
10
+ chunks?: ChunkInfo;
10
11
  files: string[];
11
12
  } | undefined;
12
13
  persist: (payload: {
13
14
  checksum: string;
14
15
  externals: SharedInfo[];
16
+ chunks?: ChunkInfo;
15
17
  files: string[];
16
18
  }) => void;
17
19
  copyFiles: (fullOutputPath: string) => void;
18
20
  clear: () => void;
19
21
  };
20
- //# sourceMappingURL=bundle-caching.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
3
  import crypto from 'crypto';
4
- import { logger } from '../utils/logger.js';
5
- export const getCachePath = (workspaceRoot, project) => path.join(workspaceRoot, 'node_modules/.cache/native-federation', project);
4
+ import { logger } from './logger.js';
5
+ export const getDefaultCachePath = (workspaceRoot) => path.join(workspaceRoot, 'node_modules/.cache/native-federation');
6
6
  export const getFilename = (title, dev) => {
7
7
  const devSuffix = dev ? '-dev' : '';
8
8
  return `${title}${devSuffix}.meta.json`;
@@ -1,4 +1,3 @@
1
1
  export declare class AbortedError extends Error {
2
2
  constructor(message: string);
3
3
  }
4
- //# sourceMappingURL=errors.d.ts.map
@@ -1,2 +1 @@
1
1
  export declare function getExternalImports(entryFilePath: string): string[];
2
- //# sourceMappingURL=get-external-imports.d.ts.map
@@ -0,0 +1,7 @@
1
+ import { type PathToImport } from '../domain/utils/mapped-path.contract.js';
2
+ import { type UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
3
+ export declare function getUsedDependenciesFactory(workspaceRoot: string, fallbackEntryPoints?: string[]): (config: {
4
+ name?: string;
5
+ exposes?: Record<string, string>;
6
+ sharedMappings: PathToImport;
7
+ }) => UsedDependencies;
@@ -0,0 +1,123 @@
1
+ import { getProjectData } from '@softarc/sheriff-core';
2
+ import { cwd } from 'process';
3
+ import { getPackageInfo } from './package-info.js';
4
+ import { getExternalImports as extractExternalImports } from './get-external-imports.js';
5
+ import * as path from 'path';
6
+ export function getUsedDependenciesFactory(workspaceRoot, fallbackEntryPoints) {
7
+ return config => {
8
+ let entryPoints = Object.values(config.exposes ?? {});
9
+ if (entryPoints.length < 1)
10
+ entryPoints = fallbackEntryPoints;
11
+ if (!entryPoints || entryPoints.length < 1)
12
+ throw new Error('[removeUnusedDeps] native-federation is missing an entryPoint! You can set it using the Federation options or by setting an exposed module in the Federation config file.');
13
+ const fileInfos = Object.values(entryPoints ?? []).reduce((acc, entryPoint) => ({
14
+ ...acc,
15
+ ...getProjectData(entryPoint, cwd(), {
16
+ includeExternalLibraries: true,
17
+ }),
18
+ }), {});
19
+ const usedPackageNames = new Set();
20
+ for (const fileInfo of Object.values(fileInfos)) {
21
+ for (const pckg of [
22
+ ...(fileInfo?.externalLibraries || []),
23
+ ...(fileInfo?.unresolvedImports || []),
24
+ ]) {
25
+ usedPackageNames.add(pckg);
26
+ }
27
+ }
28
+ return {
29
+ external: addTransientDeps(usedPackageNames, workspaceRoot),
30
+ internal: resolveUsedMappings(fileInfos, workspaceRoot, config.sharedMappings),
31
+ };
32
+ };
33
+ }
34
+ function addTransientDeps(packages, workspaceRoot) {
35
+ const packagesAndPeers = new Set([...packages]);
36
+ const discovered = new Set(packagesAndPeers);
37
+ const stack = [...packagesAndPeers];
38
+ while (stack.length > 0) {
39
+ const dep = stack.pop();
40
+ if (!dep) {
41
+ continue;
42
+ }
43
+ const pInfo = getPackageInfo(dep, workspaceRoot);
44
+ if (!pInfo) {
45
+ continue;
46
+ }
47
+ const peerDeps = extractExternalImports(pInfo.entryPoint);
48
+ for (const peerDep of peerDeps) {
49
+ if (!discovered.has(peerDep)) {
50
+ discovered.add(peerDep);
51
+ stack.push(peerDep);
52
+ packagesAndPeers.add(peerDep);
53
+ }
54
+ }
55
+ }
56
+ return packagesAndPeers;
57
+ }
58
+ function resolveUsedMappings(fileInfos, workspaceRoot, sharedMappings) {
59
+ const usedMappings = {};
60
+ for (const fileName of Object.keys(fileInfos)) {
61
+ const fullFileName = path.join(workspaceRoot, fileName);
62
+ if (isSharedMapping(fullFileName, sharedMappings))
63
+ continue;
64
+ const fileInfo = fileInfos[fileName];
65
+ if (!fileInfo)
66
+ continue;
67
+ // Check if any of this file's imports land in a shared mapping
68
+ for (const imp of fileInfo.imports ?? []) {
69
+ const fullImport = path.join(workspaceRoot, imp);
70
+ const match = matchMapping(fullImport, sharedMappings);
71
+ if (match)
72
+ usedMappings[fullImport] = match;
73
+ }
74
+ }
75
+ return usedMappings;
76
+ }
77
+ function isSharedMapping(filePath, sharedMappings) {
78
+ for (const sharedPath of Object.keys(sharedMappings)) {
79
+ const asteriskIndex = sharedPath.indexOf('*');
80
+ if (asteriskIndex !== -1) {
81
+ const prefix = sharedPath.substring(0, asteriskIndex);
82
+ if (filePath.startsWith(prefix))
83
+ return true;
84
+ }
85
+ else if (filePath.startsWith(sharedPath + path.sep) || filePath === sharedPath) {
86
+ return true;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ function matchMapping(filePath, sharedMappings) {
92
+ for (const [sharedPath, sharedImport] of Object.entries(sharedMappings)) {
93
+ const asteriskIndex = sharedPath.indexOf('*');
94
+ if (asteriskIndex !== -1) {
95
+ const prefix = sharedPath.substring(0, asteriskIndex);
96
+ const suffix = sharedPath.substring(asteriskIndex + 1);
97
+ if (!filePath.startsWith(prefix))
98
+ continue;
99
+ if (suffix && !filePath.includes(suffix))
100
+ continue;
101
+ const captured = suffix
102
+ ? filePath.slice(prefix.length, filePath.indexOf(suffix, prefix.length))
103
+ : filePath.slice(prefix.length);
104
+ return sharedImport.replace('*', toImportPath(captured));
105
+ }
106
+ else if (filePath === sharedPath || isIndexOf(filePath, sharedPath)) {
107
+ return sharedImport;
108
+ }
109
+ }
110
+ return null;
111
+ }
112
+ /**
113
+ * Detect if it's a barrel file which is inferred by typescript
114
+ */
115
+ const INDEX_PATTERN = /\/index\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/;
116
+ function isIndexOf(filePath, dirPath) {
117
+ return filePath.startsWith(dirPath + path.sep) && INDEX_PATTERN.test(filePath);
118
+ }
119
+ function toImportPath(filePath) {
120
+ const withoutExt = filePath.replace(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/, '');
121
+ const normalized = withoutExt.replace(/\\/g, '/');
122
+ return normalized.endsWith('/index') ? normalized.slice(0, -6) : normalized;
123
+ }
@@ -1,2 +1 @@
1
1
  export declare function hashFile(fileName: string): string;
2
- //# sourceMappingURL=hash-file.d.ts.map
@@ -8,4 +8,3 @@ export declare const logger: {
8
8
  measure: (start: [number, number], milestone: string) => void;
9
9
  };
10
10
  export declare const setLogLevel: (level: string) => void;
11
- //# sourceMappingURL=logger.d.ts.map
@@ -1,8 +1,7 @@
1
- import type { MappedPath } from '../domain/utils/mapped-path.contract.js';
2
- export interface GetMappedPathsOptions {
3
- rootTsConfigPath: string;
4
- sharedMappings?: string[];
5
- rootPath?: string;
6
- }
7
- export declare function getMappedPaths({ rootTsConfigPath, sharedMappings, rootPath, }: GetMappedPathsOptions): Array<MappedPath>;
8
- //# sourceMappingURL=mapped-paths.d.ts.map
1
+ import type { PathToImport } from '../domain/utils/mapped-path.contract.js';
2
+ /**
3
+ * Will return user defined and tsconfig defined paths including their imports, might contain wildcards
4
+ * @param param0
5
+ * @returns
6
+ */
7
+ export declare function getRawMappedPaths(rootTsConfigPath: string, configuredSharedMappings?: string[], rootPath?: string): PathToImport;
@@ -1,31 +1,33 @@
1
1
  import * as path from 'path';
2
2
  import * as fs from 'fs';
3
3
  import JSON5 from 'json5';
4
- export function getMappedPaths({ rootTsConfigPath, sharedMappings, rootPath, }) {
5
- const result = [];
4
+ /**
5
+ * Will return user defined and tsconfig defined paths including their imports, might contain wildcards
6
+ * @param param0
7
+ * @returns
8
+ */
9
+ export function getRawMappedPaths(rootTsConfigPath, configuredSharedMappings, rootPath) {
10
+ const mappedPaths = {};
6
11
  if (!path.isAbsolute(rootTsConfigPath)) {
7
12
  throw new Error('SharedMappings.register: tsConfigPath needs to be an absolute path!');
8
13
  }
9
14
  if (!rootPath) {
10
15
  rootPath = path.normalize(path.dirname(rootTsConfigPath));
11
16
  }
12
- const shareAll = !sharedMappings;
13
- if (!sharedMappings) {
14
- sharedMappings = [];
17
+ const shareAll = !configuredSharedMappings;
18
+ if (!configuredSharedMappings) {
19
+ configuredSharedMappings = [];
15
20
  }
16
21
  const tsConfig = JSON5.parse(fs.readFileSync(rootTsConfigPath, { encoding: 'utf-8' }));
17
22
  const mappings = tsConfig?.compilerOptions?.paths;
18
23
  if (!mappings) {
19
- return result;
24
+ return mappedPaths;
20
25
  }
21
26
  for (const key in mappings) {
22
27
  const libPath = path.normalize(path.join(rootPath, mappings[key][0]));
23
- if (sharedMappings.includes(key) || shareAll) {
24
- result.push({
25
- key,
26
- path: libPath,
27
- });
28
+ if (configuredSharedMappings.includes(key) || shareAll) {
29
+ mappedPaths[libPath] = key;
28
30
  }
29
31
  }
30
- return result;
32
+ return mappedPaths;
31
33
  }
@@ -1,3 +1,2 @@
1
1
  export declare function normalize(path: string, trailingSlash?: boolean): string;
2
2
  export declare function normalizePackageName(fileName: string): string;
3
- //# sourceMappingURL=normalize.d.ts.map
@@ -28,4 +28,3 @@ export declare function getVersionMaps(project: string, workspace: string): Vers
28
28
  export declare function getPackageJsonFiles(project: string, workspace: string): PackageJsonInfo[];
29
29
  export declare function findDepPackageJson(packageName: string, projectRoot: string): string | null;
30
30
  export declare function _getPackageInfo(packageName: string, directory: string): PackageInfo | null;
31
- //# sourceMappingURL=package-info.d.ts.map
@@ -1,7 +1,19 @@
1
+ export type TrackResult<T = never> = {
2
+ type: 'completed';
3
+ result: {
4
+ success: boolean;
5
+ cancelled?: boolean;
6
+ };
7
+ } | {
8
+ type: 'interrupted';
9
+ value: T;
10
+ };
1
11
  export declare class RebuildQueue {
2
12
  private activeBuilds;
3
13
  private buildCounter;
4
- enqueue(rebuildFn: (signal: AbortSignal) => Promise<void>): Promise<void>;
14
+ track<T = never>(rebuildFn: (signal: AbortSignal) => Promise<{
15
+ success: boolean;
16
+ cancelled?: boolean;
17
+ }>, interruptPromise?: Promise<T>): Promise<TrackResult<T>>;
5
18
  dispose(): void;
6
19
  }
7
- //# sourceMappingURL=rebuild-queue.d.ts.map
@@ -2,41 +2,61 @@ import { logger } from './logger.js';
2
2
  export class RebuildQueue {
3
3
  activeBuilds = new Map();
4
4
  buildCounter = 0;
5
- async enqueue(rebuildFn) {
5
+ async track(rebuildFn, interruptPromise) {
6
6
  const buildId = ++this.buildCounter;
7
- const pendingCancellations = Array.from(this.activeBuilds.values()).map(buildInfo => {
8
- buildInfo.controller.abort();
9
- return buildInfo.buildFinished.promise;
7
+ const pendingCancellations = Array.from(this.activeBuilds.values()).map(buildControl => {
8
+ buildControl.controller.abort();
9
+ return buildControl.buildFinished.promise;
10
10
  });
11
11
  if (pendingCancellations.length > 0) {
12
12
  logger.info(`Aborting ${pendingCancellations.length} bundling task(s)..`);
13
- }
14
- if (pendingCancellations.length > 0) {
15
13
  await Promise.all(pendingCancellations);
16
14
  }
17
- let buildFinished;
15
+ let resolveCompletion;
18
16
  const completionPromise = new Promise(resolve => {
19
- buildFinished = resolve;
17
+ resolveCompletion = resolve;
20
18
  });
21
19
  const control = {
22
20
  controller: new AbortController(),
23
21
  buildFinished: {
24
- resolve: buildFinished,
22
+ resolve: resolveCompletion,
25
23
  promise: completionPromise,
26
24
  },
27
25
  };
28
26
  this.activeBuilds.set(buildId, control);
27
+ const buildPromise = rebuildFn(control.controller.signal)
28
+ .then(result => ({ type: 'completed', result }))
29
+ .catch(error => ({ type: 'completed', result: { success: false, error } }));
30
+ let trackResult;
29
31
  try {
30
- await rebuildFn(control.controller.signal);
32
+ if (interruptPromise) {
33
+ const interruptResult = interruptPromise.then(value => ({
34
+ type: 'interrupted',
35
+ value,
36
+ }));
37
+ const raceResult = await Promise.race([buildPromise, interruptResult]);
38
+ if (raceResult.type === 'interrupted') {
39
+ control.controller.abort();
40
+ await buildPromise;
41
+ trackResult = raceResult;
42
+ }
43
+ else {
44
+ trackResult = raceResult;
45
+ }
46
+ }
47
+ else {
48
+ trackResult = await buildPromise;
49
+ }
31
50
  }
32
51
  finally {
33
52
  control.buildFinished.resolve();
34
53
  this.activeBuilds.delete(buildId);
35
54
  }
55
+ return trackResult;
36
56
  }
37
57
  dispose() {
38
- for (const [_, buildInfo] of this.activeBuilds) {
39
- buildInfo.controller.abort();
58
+ for (const buildControl of this.activeBuilds.values()) {
59
+ buildControl.controller.abort();
40
60
  }
41
61
  this.activeBuilds.clear();
42
62
  }
@@ -1,2 +1 @@
1
1
  export declare function resolveGlobSync(pattern: string, baseDir?: string): string[];
2
- //# sourceMappingURL=resolve-glob.d.ts.map
@@ -15,13 +15,13 @@ export function resolveGlobSync(pattern, baseDir = process.cwd()) {
15
15
  const entries = fs.readdirSync(dir, { withFileTypes: true });
16
16
  if (segment === '*') {
17
17
  entries
18
- .filter((entry) => entry.isDirectory())
19
- .forEach((entry) => search(path.join(dir, entry.name), segmentIndex + 1));
18
+ .filter(entry => entry.isDirectory())
19
+ .forEach(entry => search(path.join(dir, entry.name), segmentIndex + 1));
20
20
  }
21
21
  else {
22
22
  entries
23
- .filter((entry) => entry.name === segment)
24
- .forEach((entry) => search(path.join(dir, entry.name), segmentIndex + 1));
23
+ .filter(entry => entry.name === segment)
24
+ .forEach(entry => search(path.join(dir, entry.name), segmentIndex + 1));
25
25
  }
26
26
  }
27
27
  search(baseDir, 0);