@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.
- package/package.json +2 -2
- package/src/config.d.ts +0 -1
- package/src/domain.d.ts +0 -1
- package/src/index.d.ts +3 -2
- package/src/index.js +3 -1
- package/src/internal.d.ts +5 -4
- package/src/internal.js +3 -1
- package/src/lib/config/configuration-context.d.ts +0 -1
- package/src/lib/config/default-skip-list.d.ts +0 -1
- package/src/lib/config/default-skip-list.js +3 -15
- package/src/lib/config/remove-unused-deps.d.ts +3 -0
- package/src/lib/config/remove-unused-deps.js +10 -0
- package/src/lib/config/share-utils.d.ts +0 -2
- package/src/lib/config/share-utils.js +7 -13
- package/src/lib/config/with-native-federation.d.ts +0 -1
- package/src/lib/config/with-native-federation.js +41 -59
- package/src/lib/core/build-adapter.d.ts +0 -1
- package/src/lib/core/build-adapter.js +5 -5
- package/src/lib/core/build-for-federation.d.ts +2 -5
- package/src/lib/core/build-for-federation.js +68 -59
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +5 -6
- package/src/lib/core/bundle-exposed-and-mappings.js +56 -28
- package/src/lib/core/bundle-shared.d.ts +8 -5
- package/src/lib/core/bundle-shared.js +41 -18
- package/src/lib/core/default-external-list.d.ts +0 -1
- package/src/lib/core/default-external-list.js +1 -4
- package/src/lib/core/federation-builder.d.ts +6 -2
- package/src/lib/core/federation-builder.js +19 -8
- package/src/lib/core/federation-cache.d.ts +8 -0
- package/src/lib/core/federation-cache.js +11 -0
- package/src/lib/core/get-externals.d.ts +0 -1
- package/src/lib/core/get-externals.js +1 -1
- package/src/lib/core/normalize-options.d.ts +12 -0
- package/src/lib/core/normalize-options.js +57 -0
- package/src/lib/core/rebuild-for-federation.d.ts +4 -0
- package/src/lib/core/rebuild-for-federation.js +37 -0
- package/src/lib/core/write-federation-info.d.ts +0 -1
- package/src/lib/core/write-import-map.d.ts +5 -3
- package/src/lib/core/write-import-map.js +10 -1
- package/src/lib/domain/config/external-config.contract.d.ts +5 -2
- package/src/lib/domain/config/federation-config.contract.d.ts +10 -3
- package/src/lib/domain/config/index.d.ts +0 -1
- package/src/lib/domain/config/skip-list.contract.d.ts +0 -1
- package/src/lib/domain/config/with-native-federation.contract.d.ts +2 -0
- package/src/lib/domain/core/build-adapter.contract.d.ts +23 -11
- package/src/lib/domain/core/build-notification-options.contract.d.ts +0 -1
- package/src/lib/domain/core/chunk.d.ts +2 -0
- package/src/lib/domain/core/chunk.js +8 -0
- package/src/lib/domain/core/federation-cache.contract.d.ts +7 -0
- package/src/lib/domain/core/federation-cache.contract.js +1 -0
- package/src/lib/domain/core/federation-info.contract.d.ts +6 -2
- package/src/lib/domain/core/federation-options.contract.d.ts +8 -2
- package/src/lib/domain/core/index.d.ts +5 -5
- package/src/lib/domain/core/index.js +1 -0
- package/src/lib/domain/utils/index.d.ts +1 -2
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts +0 -1
- package/src/lib/domain/utils/mapped-path.contract.d.ts +1 -5
- package/src/lib/domain/utils/mapped-path.contract.js +4 -0
- package/src/lib/domain/utils/used-dependencies.contract.d.ts +5 -0
- package/src/lib/domain/utils/used-dependencies.contract.js +1 -0
- package/src/lib/utils/build-result-map.d.ts +1 -1
- package/src/lib/utils/build-result-map.js +9 -2
- package/src/lib/utils/{bundle-caching.d.ts → cache-persistence.d.ts} +4 -3
- package/src/lib/utils/{bundle-caching.js → cache-persistence.js} +2 -2
- package/src/lib/utils/errors.d.ts +0 -1
- package/src/lib/utils/get-external-imports.d.ts +0 -1
- package/src/lib/utils/get-used-dependencies.d.ts +7 -0
- package/src/lib/utils/get-used-dependencies.js +123 -0
- package/src/lib/utils/hash-file.d.ts +0 -1
- package/src/lib/utils/logger.d.ts +0 -1
- package/src/lib/utils/mapped-paths.d.ts +7 -8
- package/src/lib/utils/mapped-paths.js +14 -12
- package/src/lib/utils/normalize.d.ts +0 -1
- package/src/lib/utils/package-info.d.ts +0 -1
- package/src/lib/utils/rebuild-queue.d.ts +14 -2
- package/src/lib/utils/rebuild-queue.js +32 -12
- package/src/lib/utils/resolve-glob.d.ts +0 -1
- package/src/lib/utils/resolve-glob.js +4 -4
- package/src/lib/utils/resolve-wildcard-keys.d.ts +29 -3
- package/src/lib/utils/resolve-wildcard-keys.js +105 -38
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -3
- package/src/lib/utils/rewrite-chunk-imports.js +3 -10
- package/src/config.d.ts.map +0 -1
- package/src/domain.d.ts.map +0 -1
- package/src/index.d.ts.map +0 -1
- package/src/internal.d.ts.map +0 -1
- package/src/lib/config/configuration-context.d.ts.map +0 -1
- package/src/lib/config/default-skip-list.d.ts.map +0 -1
- package/src/lib/config/share-utils.d.ts.map +0 -1
- package/src/lib/config/with-native-federation.d.ts.map +0 -1
- package/src/lib/core/build-adapter.d.ts.map +0 -1
- package/src/lib/core/build-for-federation.d.ts.map +0 -1
- package/src/lib/core/bundle-exposed-and-mappings.d.ts.map +0 -1
- package/src/lib/core/bundle-shared.d.ts.map +0 -1
- package/src/lib/core/default-external-list.d.ts.map +0 -1
- package/src/lib/core/default-server-deps-list.d.ts +0 -3
- package/src/lib/core/default-server-deps-list.d.ts.map +0 -1
- package/src/lib/core/default-server-deps-list.js +0 -6
- package/src/lib/core/federation-builder.d.ts.map +0 -1
- package/src/lib/core/get-externals.d.ts.map +0 -1
- package/src/lib/core/load-federation-config.d.ts +0 -4
- package/src/lib/core/load-federation-config.d.ts.map +0 -1
- package/src/lib/core/load-federation-config.js +0 -18
- package/src/lib/core/remove-unused-deps.d.ts +0 -3
- package/src/lib/core/remove-unused-deps.d.ts.map +0 -1
- package/src/lib/core/remove-unused-deps.js +0 -88
- package/src/lib/core/write-federation-info.d.ts.map +0 -1
- package/src/lib/core/write-import-map.d.ts.map +0 -1
- package/src/lib/domain/config/external-config.contract.d.ts.map +0 -1
- package/src/lib/domain/config/federation-config.contract.d.ts.map +0 -1
- package/src/lib/domain/config/index.d.ts.map +0 -1
- package/src/lib/domain/config/skip-list.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-adapter.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-notification-options.contract.d.ts.map +0 -1
- package/src/lib/domain/core/build-params.contract.d.ts +0 -6
- package/src/lib/domain/core/build-params.contract.d.ts.map +0 -1
- package/src/lib/domain/core/federation-info.contract.d.ts.map +0 -1
- package/src/lib/domain/core/federation-options.contract.d.ts.map +0 -1
- package/src/lib/domain/core/index.d.ts.map +0 -1
- package/src/lib/domain/utils/index.d.ts.map +0 -1
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts.map +0 -1
- package/src/lib/domain/utils/mapped-path.contract.d.ts.map +0 -1
- package/src/lib/utils/build-result-map.d.ts.map +0 -1
- package/src/lib/utils/build-utils.d.ts +0 -3
- package/src/lib/utils/build-utils.d.ts.map +0 -1
- package/src/lib/utils/build-utils.js +0 -5
- package/src/lib/utils/bundle-caching.d.ts.map +0 -1
- package/src/lib/utils/errors.d.ts.map +0 -1
- package/src/lib/utils/get-external-imports.d.ts.map +0 -1
- package/src/lib/utils/hash-file.d.ts.map +0 -1
- package/src/lib/utils/logger.d.ts.map +0 -1
- package/src/lib/utils/mapped-paths.d.ts.map +0 -1
- package/src/lib/utils/normalize.d.ts.map +0 -1
- package/src/lib/utils/package-info.d.ts.map +0 -1
- package/src/lib/utils/rebuild-queue.d.ts.map +0 -1
- package/src/lib/utils/resolve-glob.d.ts.map +0 -1
- package/src/lib/utils/resolve-wildcard-keys.d.ts.map +0 -1
- package/src/lib/utils/rewrite-chunk-imports.d.ts.map +0 -1
- /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
|
|
@@ -1,28 +1,40 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export
|
|
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:
|
|
26
|
+
external: string[];
|
|
13
27
|
outdir: string;
|
|
14
|
-
mappedPaths:
|
|
15
|
-
|
|
16
|
-
esm?: boolean;
|
|
28
|
+
mappedPaths: PathToImport;
|
|
29
|
+
isMappingOrExposed: boolean;
|
|
17
30
|
dev?: boolean;
|
|
18
31
|
watch?: boolean;
|
|
19
|
-
|
|
32
|
+
chunks?: boolean;
|
|
20
33
|
hash: boolean;
|
|
21
34
|
platform?: 'browser' | 'node';
|
|
22
35
|
optimizedMappings?: boolean;
|
|
23
|
-
|
|
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
|
|
@@ -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
|
|
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
|
-
|
|
14
|
+
entryPoints?: string[];
|
|
13
15
|
buildNotifications?: BuildNotificationOptions;
|
|
14
16
|
}
|
|
15
|
-
|
|
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,
|
|
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 {
|
|
5
|
-
export
|
|
6
|
-
|
|
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';
|
|
@@ -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
|
-
|
|
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] =
|
|
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
|
-
|
|
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
|
|
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 '
|
|
5
|
-
export const
|
|
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`;
|
|
@@ -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,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
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
|
-
|
|
5
|
-
|
|
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 = !
|
|
13
|
-
if (!
|
|
14
|
-
|
|
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
|
|
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 (
|
|
24
|
-
|
|
25
|
-
key,
|
|
26
|
-
path: libPath,
|
|
27
|
-
});
|
|
28
|
+
if (configuredSharedMappings.includes(key) || shareAll) {
|
|
29
|
+
mappedPaths[libPath] = key;
|
|
28
30
|
}
|
|
29
31
|
}
|
|
30
|
-
return
|
|
32
|
+
return mappedPaths;
|
|
31
33
|
}
|
|
@@ -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
|
-
|
|
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
|
|
5
|
+
async track(rebuildFn, interruptPromise) {
|
|
6
6
|
const buildId = ++this.buildCounter;
|
|
7
|
-
const pendingCancellations = Array.from(this.activeBuilds.values()).map(
|
|
8
|
-
|
|
9
|
-
return
|
|
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
|
|
15
|
+
let resolveCompletion;
|
|
18
16
|
const completionPromise = new Promise(resolve => {
|
|
19
|
-
|
|
17
|
+
resolveCompletion = resolve;
|
|
20
18
|
});
|
|
21
19
|
const control = {
|
|
22
20
|
controller: new AbortController(),
|
|
23
21
|
buildFinished: {
|
|
24
|
-
resolve:
|
|
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
|
-
|
|
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
|
|
39
|
-
|
|
58
|
+
for (const buildControl of this.activeBuilds.values()) {
|
|
59
|
+
buildControl.controller.abort();
|
|
40
60
|
}
|
|
41
61
|
this.activeBuilds.clear();
|
|
42
62
|
}
|
|
@@ -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(
|
|
19
|
-
.forEach(
|
|
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(
|
|
24
|
-
.forEach(
|
|
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);
|