@softarc/native-federation 4.1.3 → 4.2.0
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/LICENSE.md +7 -0
- package/README.md +638 -0
- package/dist/config.js +17 -0
- package/dist/domain.js +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +21 -0
- package/{src → dist}/internal.d.ts +6 -7
- package/dist/internal.js +26 -0
- package/dist/lib/config/configuration-context.js +15 -0
- package/dist/lib/config/default-skip-list.js +36 -0
- package/dist/lib/config/get-external-imports.d.ts +2 -0
- package/dist/lib/config/get-external-imports.js +60 -0
- package/dist/lib/config/get-used-dependencies.d.ts +24 -0
- package/dist/lib/config/get-used-dependencies.js +126 -0
- package/{src/lib/utils → dist/lib/config}/mapped-paths.d.ts +2 -2
- package/dist/lib/config/mapped-paths.js +31 -0
- package/dist/lib/config/remove-unused-deps.js +11 -0
- package/dist/lib/config/share-utils.d.ts +20 -0
- package/dist/lib/config/share-utils.js +344 -0
- package/dist/lib/config/with-native-federation.js +80 -0
- package/{src/lib/core → dist/lib/core/build}/build-adapter.d.ts +1 -1
- package/dist/lib/core/build/build-adapter.js +16 -0
- package/dist/lib/core/build/build-for-federation.d.ts +4 -0
- package/dist/lib/core/build/build-for-federation.js +207 -0
- package/{src/lib/utils → dist/lib/core/build}/build-result-map.d.ts +1 -1
- package/dist/lib/core/build/build-result-map.js +39 -0
- package/dist/lib/core/build/bundle-exposed-and-mappings.d.ts +13 -0
- package/dist/lib/core/build/bundle-exposed-and-mappings.js +178 -0
- package/dist/lib/core/build/bundle-shared.d.ts +34 -0
- package/dist/lib/core/build/bundle-shared.js +261 -0
- package/dist/lib/core/build/compute-integrity.d.ts +11 -0
- package/dist/lib/core/build/compute-integrity.js +20 -0
- package/dist/lib/core/build/default-external-list.js +32 -0
- package/dist/lib/core/build/get-externals.d.ts +2 -0
- package/dist/lib/core/build/get-externals.js +9 -0
- package/dist/lib/core/build/rebuild-for-federation.d.ts +4 -0
- package/dist/lib/core/build/rebuild-for-federation.js +52 -0
- package/dist/lib/core/build/rewrite-chunk-imports.d.ts +5 -0
- package/dist/lib/core/build/rewrite-chunk-imports.js +74 -0
- package/dist/lib/core/cache/cache-persistence.d.ts +22 -0
- package/dist/lib/core/cache/cache-persistence.js +63 -0
- package/{src/lib/core → dist/lib/core/cache}/federation-cache.d.ts +2 -2
- package/dist/lib/core/cache/federation-cache.js +22 -0
- package/dist/lib/core/federation-builder.js +53 -0
- package/{src → dist}/lib/core/normalize-options.d.ts +13 -1
- package/dist/lib/core/normalize-options.js +67 -0
- package/dist/lib/core/output/write-federation-info.d.ts +5 -0
- package/dist/lib/core/output/write-federation-info.js +17 -0
- package/dist/lib/core/output/write-import-map.d.ts +11 -0
- package/dist/lib/core/output/write-import-map.js +42 -0
- package/dist/lib/core/rebuild-queue.js +61 -0
- package/{src → dist}/lib/domain/config/external-config.contract.d.ts +2 -2
- package/dist/lib/domain/config/external-config.contract.js +0 -0
- package/dist/lib/domain/config/federation-config.contract.js +0 -0
- package/dist/lib/domain/config/index.js +0 -0
- package/dist/lib/domain/config/skip-list.contract.js +0 -0
- package/dist/lib/domain/core/build-adapter.contract.js +0 -0
- package/dist/lib/domain/core/build-notification-options.contract.js +9 -0
- package/dist/lib/domain/core/chunk.js +12 -0
- package/dist/lib/domain/core/federation-cache.contract.js +0 -0
- package/dist/lib/domain/core/federation-info.contract.js +0 -0
- package/dist/lib/domain/core/federation-options.contract.js +0 -0
- package/dist/lib/domain/core/index.js +9 -0
- package/dist/lib/domain/core/manifest.contract.js +0 -0
- package/dist/lib/domain/utils/file-watcher.contract.js +0 -0
- package/dist/lib/domain/utils/io-port.contract.d.ts +45 -0
- package/dist/lib/domain/utils/io-port.contract.js +0 -0
- package/dist/lib/domain/utils/keyvaluepair.contract.js +0 -0
- package/dist/lib/domain/utils/mapped-path.contract.js +0 -0
- package/dist/lib/domain/utils/package-json.contract.d.ts +27 -0
- package/dist/lib/domain/utils/package-json.contract.js +0 -0
- package/dist/lib/domain/utils/used-dependencies.contract.js +0 -0
- package/dist/lib/utils/errors.js +10 -0
- package/{src → dist}/lib/utils/file-watcher.d.ts +2 -0
- package/dist/lib/utils/file-watcher.js +51 -0
- package/dist/lib/utils/hash-file.d.ts +7 -0
- package/dist/lib/utils/hash-file.js +15 -0
- package/dist/lib/utils/io/node-io-adapter.d.ts +2 -0
- package/dist/lib/utils/io/node-io-adapter.js +68 -0
- package/dist/lib/utils/io/package-json-repository.d.ts +5 -0
- package/dist/lib/utils/io/package-json-repository.js +79 -0
- package/dist/lib/utils/logger.js +29 -0
- package/dist/lib/utils/normalize.js +22 -0
- package/dist/lib/utils/package/entry-point-resolver.d.ts +2 -0
- package/dist/lib/utils/package/entry-point-resolver.js +78 -0
- package/dist/lib/utils/package/esm-detection.d.ts +5 -0
- package/dist/lib/utils/package/esm-detection.js +10 -0
- package/dist/lib/utils/package/exports-resolver.d.ts +13 -0
- package/dist/lib/utils/package/exports-resolver.js +55 -0
- package/dist/lib/utils/package/package-info.d.ts +7 -0
- package/dist/lib/utils/package/package-info.js +31 -0
- package/dist/lib/utils/package/resolve-wildcard-keys.d.ts +3 -0
- package/dist/lib/utils/package/resolve-wildcard-keys.js +22 -0
- package/dist/lib/utils/package/version-maps.d.ts +3 -0
- package/dist/lib/utils/package/version-maps.js +8 -0
- package/dist/lib/utils/path-patterns.d.ts +14 -0
- package/dist/lib/utils/path-patterns.js +28 -0
- package/package.json +45 -22
- package/src/config.js +0 -4
- package/src/domain.js +0 -2
- package/src/index.d.ts +0 -10
- package/src/index.js +0 -10
- package/src/internal.js +0 -11
- package/src/lib/config/configuration-context.js +0 -10
- package/src/lib/config/default-skip-list.js +0 -31
- package/src/lib/config/remove-unused-deps.js +0 -10
- package/src/lib/config/share-utils.d.ts +0 -10
- package/src/lib/config/share-utils.js +0 -302
- package/src/lib/config/with-native-federation.js +0 -79
- package/src/lib/core/build-adapter.js +0 -12
- package/src/lib/core/build-for-federation.d.ts +0 -4
- package/src/lib/core/build-for-federation.js +0 -173
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +0 -7
- package/src/lib/core/bundle-exposed-and-mappings.js +0 -177
- package/src/lib/core/bundle-shared.d.ts +0 -13
- package/src/lib/core/bundle-shared.js +0 -222
- package/src/lib/core/default-external-list.js +0 -29
- package/src/lib/core/federation-builder.js +0 -45
- package/src/lib/core/federation-cache.js +0 -16
- package/src/lib/core/get-externals.d.ts +0 -2
- package/src/lib/core/get-externals.js +0 -6
- package/src/lib/core/normalize-options.js +0 -58
- package/src/lib/core/rebuild-for-federation.d.ts +0 -4
- package/src/lib/core/rebuild-for-federation.js +0 -43
- package/src/lib/core/write-federation-info.d.ts +0 -3
- package/src/lib/core/write-federation-info.js +0 -6
- package/src/lib/core/write-import-map.d.ts +0 -6
- package/src/lib/core/write-import-map.js +0 -33
- package/src/lib/domain/config/external-config.contract.js +0 -1
- package/src/lib/domain/config/federation-config.contract.js +0 -1
- package/src/lib/domain/config/index.js +0 -1
- package/src/lib/domain/config/skip-list.contract.js +0 -1
- package/src/lib/domain/config/with-native-federation.contract.d.ts +0 -2
- package/src/lib/domain/config/with-native-federation.contract.js +0 -1
- package/src/lib/domain/core/build-adapter.contract.js +0 -1
- package/src/lib/domain/core/build-notification-options.contract.js +0 -6
- package/src/lib/domain/core/chunk.js +0 -8
- package/src/lib/domain/core/federation-cache.contract.js +0 -1
- package/src/lib/domain/core/federation-info.contract.js +0 -1
- package/src/lib/domain/core/federation-options.contract.js +0 -1
- package/src/lib/domain/core/index.js +0 -2
- package/src/lib/domain/core/manifest.contract.js +0 -1
- package/src/lib/domain/utils/file-watcher.contract.js +0 -1
- package/src/lib/domain/utils/index.d.ts +0 -2
- package/src/lib/domain/utils/index.js +0 -1
- package/src/lib/domain/utils/keyvaluepair.contract.js +0 -1
- package/src/lib/domain/utils/mapped-path.contract.js +0 -5
- package/src/lib/domain/utils/used-dependencies.contract.js +0 -1
- package/src/lib/utils/build-result-map.js +0 -29
- package/src/lib/utils/cache-persistence.d.ts +0 -19
- package/src/lib/utils/cache-persistence.js +0 -66
- package/src/lib/utils/errors.js +0 -7
- package/src/lib/utils/file-watcher.js +0 -51
- package/src/lib/utils/get-external-imports.d.ts +0 -1
- package/src/lib/utils/get-external-imports.js +0 -80
- package/src/lib/utils/get-used-dependencies.d.ts +0 -8
- package/src/lib/utils/get-used-dependencies.js +0 -123
- package/src/lib/utils/hash-file.d.ts +0 -3
- package/src/lib/utils/hash-file.js +0 -13
- package/src/lib/utils/logger.js +0 -27
- package/src/lib/utils/mapped-paths.js +0 -33
- package/src/lib/utils/normalize.js +0 -17
- package/src/lib/utils/package-info.d.ts +0 -30
- package/src/lib/utils/package-info.js +0 -268
- package/src/lib/utils/rebuild-queue.js +0 -63
- package/src/lib/utils/resolve-glob.d.ts +0 -1
- package/src/lib/utils/resolve-glob.js +0 -29
- package/src/lib/utils/resolve-wildcard-keys.d.ts +0 -29
- package/src/lib/utils/resolve-wildcard-keys.js +0 -126
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -2
- package/src/lib/utils/rewrite-chunk-imports.js +0 -48
- /package/{src → dist}/config.d.ts +0 -0
- /package/{src → dist}/domain.d.ts +0 -0
- /package/{src → dist}/lib/config/configuration-context.d.ts +0 -0
- /package/{src → dist}/lib/config/default-skip-list.d.ts +0 -0
- /package/{src → dist}/lib/config/remove-unused-deps.d.ts +0 -0
- /package/{src → dist}/lib/config/with-native-federation.d.ts +0 -0
- /package/{src/lib/core → dist/lib/core/build}/default-external-list.d.ts +0 -0
- /package/{src → dist}/lib/core/federation-builder.d.ts +0 -0
- /package/{src/lib/utils → dist/lib/core}/rebuild-queue.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/federation-config.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/index.d.ts +0 -0
- /package/{src → dist}/lib/domain/config/skip-list.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/build-adapter.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/build-notification-options.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/chunk.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-cache.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-info.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/federation-options.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/index.d.ts +0 -0
- /package/{src → dist}/lib/domain/core/manifest.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/file-watcher.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/keyvaluepair.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/mapped-path.contract.d.ts +0 -0
- /package/{src → dist}/lib/domain/utils/used-dependencies.contract.d.ts +0 -0
- /package/{src → dist}/lib/utils/errors.d.ts +0 -0
- /package/{src → dist}/lib/utils/logger.d.ts +0 -0
- /package/{src → dist}/lib/utils/normalize.d.ts +0 -0
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function createFederationCache(cachePath, bundlerCache) {
|
|
2
|
-
return { externals: [], cachePath, bundlerCache };
|
|
3
|
-
}
|
|
4
|
-
export function addExternalsToCache(cache, { externals, chunks, integrity, }) {
|
|
5
|
-
cache.externals.push(...externals);
|
|
6
|
-
if (chunks) {
|
|
7
|
-
if (!cache.chunks)
|
|
8
|
-
cache.chunks = {};
|
|
9
|
-
cache.chunks = { ...cache.chunks, ...chunks };
|
|
10
|
-
}
|
|
11
|
-
if (integrity) {
|
|
12
|
-
if (!cache.integrity)
|
|
13
|
-
cache.integrity = {};
|
|
14
|
-
cache.integrity = { ...cache.integrity, ...integrity };
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import { pathToFileURL } from 'url';
|
|
4
|
-
import { removeUnusedDeps } from '../config/remove-unused-deps.js';
|
|
5
|
-
import { createFederationCache } from './federation-cache.js';
|
|
6
|
-
import { getDefaultCachePath } from '../utils/cache-persistence.js';
|
|
7
|
-
import { getUsedDependenciesFactory } from '../utils/get-used-dependencies.js';
|
|
8
|
-
import { logger } from '../utils/logger.js';
|
|
9
|
-
import { normalizePackageName } from '../utils/normalize.js';
|
|
10
|
-
export async function normalizeFederationOptions(options, cache) {
|
|
11
|
-
/**
|
|
12
|
-
* Step 1: normalizing config
|
|
13
|
-
*/
|
|
14
|
-
const fullConfigPath = path.join(options.workspaceRoot, options.federationConfig);
|
|
15
|
-
const getUsedDeps = getUsedDependenciesFactory(options.workspaceRoot, options.entryPoints);
|
|
16
|
-
if (!fs.existsSync(fullConfigPath)) {
|
|
17
|
-
throw new Error('Expected ' + fullConfigPath);
|
|
18
|
-
}
|
|
19
|
-
let config = (await import(pathToFileURL(fullConfigPath).href))
|
|
20
|
-
?.default;
|
|
21
|
-
/**
|
|
22
|
-
* Step 2: normalizing options
|
|
23
|
-
*/
|
|
24
|
-
const federationCache = cache ??
|
|
25
|
-
createFederationCache(getDefaultCachePath(options.workspaceRoot));
|
|
26
|
-
const normalizedOptions = {
|
|
27
|
-
...options,
|
|
28
|
-
entryPoints: options.entryPoints ?? Object.values(config.exposes ?? {}).map(e => e.file),
|
|
29
|
-
projectName: resolveProjectName(options.projectName ?? config.name),
|
|
30
|
-
cacheExternalArtifacts: options.cacheExternalArtifacts ?? true,
|
|
31
|
-
federationCache,
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Step 3: Remove unused deps
|
|
35
|
-
*/
|
|
36
|
-
if (config.features.ignoreUnusedDeps) {
|
|
37
|
-
config = removeUnusedDeps(getUsedDeps(config), config);
|
|
38
|
-
logger.info('Removed unused dependencies.');
|
|
39
|
-
logger.debug('This can be disabled per dependency/external using the "includeSecondaries: {keepAll: true}" property. Or in general by disabling the "ignoreUnusedDeps" feature. ');
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
const withWildcard = Object.keys(config.sharedMappings).some(m => m.includes('*'));
|
|
43
|
-
if (withWildcard) {
|
|
44
|
-
logger.warn('Sharing mapped paths with wildcards (*) is only supported with ignoreUnusedDeps feature.');
|
|
45
|
-
config.sharedMappings = Object.entries(config.sharedMappings)
|
|
46
|
-
.filter(([_path]) => !_path.includes('*'))
|
|
47
|
-
.reduce((acc, [_path, _import]) => ({ ...acc, [_path]: _import }), {});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return { config, options: normalizedOptions };
|
|
51
|
-
}
|
|
52
|
-
export function resolveProjectName(name) {
|
|
53
|
-
if (!name || name.length < 1) {
|
|
54
|
-
logger.warn("Project name in 'federation.config.js' is empty, defaulting to 'shell' cache folder (could collide with other projects in the workspace).");
|
|
55
|
-
return 'shell';
|
|
56
|
-
}
|
|
57
|
-
return normalizePackageName(name);
|
|
58
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { FederationInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
-
import type { NormalizedFederationOptions } from '../domain/core/federation-options.contract.js';
|
|
3
|
-
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
4
|
-
export declare function rebuildForFederation(config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], modifiedFiles: string[], signal?: AbortSignal): Promise<FederationInfo>;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { bundleExposedAndMappings, describeExposed, describeSharedMappings, } from './bundle-exposed-and-mappings.js';
|
|
2
|
-
import { writeFederationInfo } from './write-federation-info.js';
|
|
3
|
-
import { writeImportMap } from './write-import-map.js';
|
|
4
|
-
import { logger } from '../utils/logger.js';
|
|
5
|
-
import { AbortedError } from '../utils/errors.js';
|
|
6
|
-
export async function rebuildForFederation(config, fedOptions, externals, modifiedFiles, signal) {
|
|
7
|
-
const federationCache = fedOptions.federationCache;
|
|
8
|
-
logger.info(`Re-bundling all internal libraries and exposed modules..'`);
|
|
9
|
-
const start = process.hrtime();
|
|
10
|
-
const artifactInfo = await bundleExposedAndMappings(config, fedOptions, externals, modifiedFiles, signal);
|
|
11
|
-
logger.measure(start, 'To re-bundle all internal libraries and exposed modules.');
|
|
12
|
-
if (signal?.aborted)
|
|
13
|
-
throw new AbortedError('[buildForFederation] After exposed-and-mappings bundle');
|
|
14
|
-
const exposedInfo = !artifactInfo ? describeExposed(config, fedOptions) : artifactInfo.exposes;
|
|
15
|
-
const sharedMappingInfo = !artifactInfo
|
|
16
|
-
? describeSharedMappings(config, fedOptions)
|
|
17
|
-
: artifactInfo.mappings;
|
|
18
|
-
const sharedExternals = [...federationCache.externals, ...sharedMappingInfo];
|
|
19
|
-
const buildNotificationsEndpoint = fedOptions.buildNotifications?.enable && fedOptions.dev
|
|
20
|
-
? fedOptions.buildNotifications?.endpoint
|
|
21
|
-
: undefined;
|
|
22
|
-
const federationInfo = {
|
|
23
|
-
name: config.name,
|
|
24
|
-
shared: sharedExternals,
|
|
25
|
-
exposes: exposedInfo,
|
|
26
|
-
buildNotificationsEndpoint,
|
|
27
|
-
};
|
|
28
|
-
if (federationCache.chunks) {
|
|
29
|
-
federationInfo.chunks = federationCache.chunks;
|
|
30
|
-
}
|
|
31
|
-
if (artifactInfo?.chunks) {
|
|
32
|
-
federationInfo.chunks = { ...(federationInfo.chunks ?? {}), ...artifactInfo?.chunks };
|
|
33
|
-
}
|
|
34
|
-
if (config.features.integrityHashes) {
|
|
35
|
-
federationInfo.integrity = {
|
|
36
|
-
...(federationCache.integrity ?? {}),
|
|
37
|
-
...(artifactInfo?.integrity ?? {}),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
writeFederationInfo(federationInfo, fedOptions);
|
|
41
|
-
writeImportMap(federationCache, fedOptions, federationInfo.integrity);
|
|
42
|
-
return federationInfo;
|
|
43
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { FederationInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
-
import type { FederationOptions } from '../domain/core/federation-options.contract.js';
|
|
3
|
-
export declare function writeFederationInfo(federationInfo: FederationInfo, fedOptions: FederationOptions): void;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
import * as path from 'path';
|
|
3
|
-
export function writeFederationInfo(federationInfo, fedOptions) {
|
|
4
|
-
const metaDataPath = path.join(fedOptions.workspaceRoot, fedOptions.outputPath, 'remoteEntry.json');
|
|
5
|
-
fs.writeFileSync(metaDataPath, JSON.stringify(federationInfo, null, 2));
|
|
6
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { ChunkInfo, IntegrityMap, SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
-
import type { FederationOptions } from '../domain/core/federation-options.contract.js';
|
|
3
|
-
export declare function writeImportMap(sharedInfo: {
|
|
4
|
-
externals: SharedInfo[];
|
|
5
|
-
chunks?: ChunkInfo;
|
|
6
|
-
}, fedOption: FederationOptions, fileIntegrity?: IntegrityMap): void;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import { toChunkImport } from '../domain/core/chunk.js';
|
|
4
|
-
export function writeImportMap(sharedInfo, fedOption, fileIntegrity) {
|
|
5
|
-
const imports = sharedInfo.externals.reduce((acc, cur) => {
|
|
6
|
-
return {
|
|
7
|
-
...acc,
|
|
8
|
-
[cur.packageName]: cur.outFileName,
|
|
9
|
-
};
|
|
10
|
-
}, {});
|
|
11
|
-
if (sharedInfo.chunks) {
|
|
12
|
-
Object.values(sharedInfo.chunks).forEach(c => {
|
|
13
|
-
c.forEach(e => {
|
|
14
|
-
const key = toChunkImport(e);
|
|
15
|
-
imports[key] = e;
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
const importMap = { imports };
|
|
20
|
-
if (fileIntegrity) {
|
|
21
|
-
const integrity = {};
|
|
22
|
-
for (const url of Object.values(imports)) {
|
|
23
|
-
const sri = fileIntegrity[url];
|
|
24
|
-
if (sri)
|
|
25
|
-
integrity[url] = sri;
|
|
26
|
-
}
|
|
27
|
-
if (Object.keys(integrity).length > 0) {
|
|
28
|
-
importMap.integrity = integrity;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const importMapPath = path.join(fedOption.workspaceRoot, fedOption.outputPath, 'importmap.json');
|
|
32
|
-
fs.writeFileSync(importMapPath, JSON.stringify(importMap, null, 2));
|
|
33
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var BuildNotificationType;
|
|
2
|
-
(function (BuildNotificationType) {
|
|
3
|
-
BuildNotificationType["COMPLETED"] = "federation-rebuild-complete";
|
|
4
|
-
BuildNotificationType["ERROR"] = "federation-rebuild-error";
|
|
5
|
-
BuildNotificationType["CANCELLED"] = "federation-rebuild-cancelled";
|
|
6
|
-
})(BuildNotificationType || (BuildNotificationType = {}));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
function stripHash(fileName) {
|
|
3
|
-
const start = fileName.lastIndexOf('-');
|
|
4
|
-
const end = fileName.lastIndexOf('.');
|
|
5
|
-
if (start < 0 || end < 0 || start > end)
|
|
6
|
-
return fileName;
|
|
7
|
-
return fileName.substring(0, start) + fileName.substring(end);
|
|
8
|
-
}
|
|
9
|
-
export function createBuildResultMap(buildResult, isHashed, expectedNames = []) {
|
|
10
|
-
const expected = new Set(expectedNames.map(n => path.basename(n)));
|
|
11
|
-
const map = {};
|
|
12
|
-
for (const item of buildResult) {
|
|
13
|
-
const resultName = path.basename(item.fileName);
|
|
14
|
-
const requestName = isHashed && expected.has(stripHash(resultName)) ? stripHash(resultName) : resultName;
|
|
15
|
-
map[requestName] = item.fileName;
|
|
16
|
-
}
|
|
17
|
-
return map;
|
|
18
|
-
}
|
|
19
|
-
export function lookupInResultMap(map, requestName) {
|
|
20
|
-
const key = path.basename(requestName);
|
|
21
|
-
// path.basename is to maintain backwards compatible
|
|
22
|
-
return path.basename(map[key]);
|
|
23
|
-
}
|
|
24
|
-
export function popFromResultMap(map, requestName) {
|
|
25
|
-
const key = path.basename(requestName);
|
|
26
|
-
const out = map[key];
|
|
27
|
-
delete map[key];
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { NormalizedExternalConfig } from '../domain/config/external-config.contract.js';
|
|
2
|
-
import type { ChunkInfo, IntegrityMap, SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
3
|
-
export declare const getDefaultCachePath: (workspaceRoot: string) => string;
|
|
4
|
-
export declare const getFilename: (title: string, dev?: boolean) => string;
|
|
5
|
-
export declare const getChecksum: (shared: Record<string, NormalizedExternalConfig>, dev: "1" | "0") => string;
|
|
6
|
-
type CacheMetadata = {
|
|
7
|
-
checksum: string;
|
|
8
|
-
externals: SharedInfo[];
|
|
9
|
-
chunks?: ChunkInfo;
|
|
10
|
-
integrity?: IntegrityMap;
|
|
11
|
-
files: string[];
|
|
12
|
-
};
|
|
13
|
-
export declare const cacheEntry: (pathToCache: string, fileName: string) => {
|
|
14
|
-
getMetadata: (checksum: string) => CacheMetadata | undefined;
|
|
15
|
-
persist: (payload: CacheMetadata) => void;
|
|
16
|
-
copyFiles: (fullOutputPath: string) => void;
|
|
17
|
-
clear: () => void;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import crypto from 'crypto';
|
|
4
|
-
import { logger } from './logger.js';
|
|
5
|
-
export const getDefaultCachePath = (workspaceRoot) => path.join(workspaceRoot, 'node_modules/.cache/native-federation');
|
|
6
|
-
export const getFilename = (title, dev) => {
|
|
7
|
-
const devSuffix = dev ? '-dev' : '';
|
|
8
|
-
return `${title}${devSuffix}.meta.json`;
|
|
9
|
-
};
|
|
10
|
-
export const getChecksum = (shared, dev) => {
|
|
11
|
-
const denseExternals = Object.keys(shared)
|
|
12
|
-
.sort()
|
|
13
|
-
.reduce((clean, external) => {
|
|
14
|
-
return (clean + ':' + external + (shared[external].version ? `@${shared[external].version}` : ''));
|
|
15
|
-
}, 'deps');
|
|
16
|
-
return crypto
|
|
17
|
-
.createHash('sha256')
|
|
18
|
-
.update(denseExternals + `:dev=${dev}`)
|
|
19
|
-
.digest('hex');
|
|
20
|
-
};
|
|
21
|
-
export const cacheEntry = (pathToCache, fileName) => ({
|
|
22
|
-
getMetadata: (checksum) => {
|
|
23
|
-
const metadataFile = path.join(pathToCache, fileName);
|
|
24
|
-
if (!fs.existsSync(pathToCache) || !fs.existsSync(metadataFile))
|
|
25
|
-
return undefined;
|
|
26
|
-
const cachedResult = JSON.parse(fs.readFileSync(metadataFile, 'utf-8'));
|
|
27
|
-
if (cachedResult.checksum !== checksum)
|
|
28
|
-
return undefined;
|
|
29
|
-
return cachedResult;
|
|
30
|
-
},
|
|
31
|
-
persist: (payload) => {
|
|
32
|
-
fs.writeFileSync(path.join(pathToCache, fileName), JSON.stringify(payload), 'utf-8');
|
|
33
|
-
},
|
|
34
|
-
copyFiles: (fullOutputPath) => {
|
|
35
|
-
const metadataFile = path.join(pathToCache, fileName);
|
|
36
|
-
if (!fs.existsSync(metadataFile))
|
|
37
|
-
throw new Error('Error copying artifacts to dist, metadata file could not be found.');
|
|
38
|
-
const cachedResult = JSON.parse(fs.readFileSync(metadataFile, 'utf-8'));
|
|
39
|
-
fs.mkdirSync(path.dirname(fullOutputPath), { recursive: true });
|
|
40
|
-
cachedResult.files.forEach(file => {
|
|
41
|
-
const cachedFile = path.join(pathToCache, file);
|
|
42
|
-
const distFileName = path.join(fullOutputPath, file);
|
|
43
|
-
if (fs.existsSync(cachedFile)) {
|
|
44
|
-
fs.copyFileSync(cachedFile, distFileName);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
},
|
|
48
|
-
clear: () => {
|
|
49
|
-
const metadataFile = path.join(pathToCache, fileName);
|
|
50
|
-
if (!fs.existsSync(pathToCache)) {
|
|
51
|
-
fs.mkdirSync(pathToCache, { recursive: true });
|
|
52
|
-
logger.debug(`Creating cache folder '${pathToCache}' for '${fileName}'.`);
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (!fs.existsSync(metadataFile))
|
|
56
|
-
return;
|
|
57
|
-
logger.debug(`Purging cached bundle '${metadataFile}'.`);
|
|
58
|
-
const cachedResult = JSON.parse(fs.readFileSync(metadataFile, 'utf-8'));
|
|
59
|
-
cachedResult.files.forEach(file => {
|
|
60
|
-
const cachedFile = path.join(pathToCache, file);
|
|
61
|
-
if (fs.existsSync(cachedFile))
|
|
62
|
-
fs.unlinkSync(cachedFile);
|
|
63
|
-
});
|
|
64
|
-
fs.unlinkSync(metadataFile);
|
|
65
|
-
},
|
|
66
|
-
});
|
package/src/lib/utils/errors.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { logger } from '@softarc/native-federation/internal';
|
|
2
|
-
import { watch, statSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
4
|
-
const toUnix = (p) => p.replace(/\\/g, '/');
|
|
5
|
-
export function createNfWatcher(options = {}) {
|
|
6
|
-
const { onChange } = options;
|
|
7
|
-
const watchers = new Map();
|
|
8
|
-
const dirtyPaths = new Set();
|
|
9
|
-
const notify = (path) => {
|
|
10
|
-
if (onChange)
|
|
11
|
-
onChange(path);
|
|
12
|
-
else
|
|
13
|
-
dirtyPaths.add(path);
|
|
14
|
-
};
|
|
15
|
-
return {
|
|
16
|
-
addPaths(paths) {
|
|
17
|
-
const list = typeof paths === 'string' ? [paths] : [...paths];
|
|
18
|
-
for (const p of list) {
|
|
19
|
-
if (watchers.has(p))
|
|
20
|
-
continue;
|
|
21
|
-
try {
|
|
22
|
-
const isDir = statSync(p).isDirectory();
|
|
23
|
-
const w = isDir
|
|
24
|
-
? watch(p, { recursive: true }, (_, filename) => {
|
|
25
|
-
if (filename)
|
|
26
|
-
notify(toUnix(join(p, filename)));
|
|
27
|
-
})
|
|
28
|
-
: watch(p, () => notify(toUnix(p)));
|
|
29
|
-
watchers.set(p, w);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
logger.debug(`Could not watch path '${p}'.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
get: () => dirtyPaths,
|
|
37
|
-
clear: () => dirtyPaths.clear(),
|
|
38
|
-
mutate: fn => fn(dirtyPaths),
|
|
39
|
-
async close() {
|
|
40
|
-
for (const w of watchers.values()) {
|
|
41
|
-
w.close();
|
|
42
|
-
}
|
|
43
|
-
watchers.clear();
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export function syncNfFileWatcher(watcher, bundlerCache) {
|
|
48
|
-
const files = [...bundlerCache.keys()].filter(k => !k.includes('node_modules'));
|
|
49
|
-
if (files.length)
|
|
50
|
-
watcher.addPaths(files);
|
|
51
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getExternalImports(entryFilePath: string): string[];
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import * as path from 'path';
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as ts from 'typescript';
|
|
4
|
-
export function getExternalImports(entryFilePath) {
|
|
5
|
-
const visited = new Set();
|
|
6
|
-
const externals = new Set();
|
|
7
|
-
function isExternal(specifier) {
|
|
8
|
-
return !specifier.startsWith('.') && !path.isAbsolute(specifier);
|
|
9
|
-
}
|
|
10
|
-
function normalizeExternal(specifier) {
|
|
11
|
-
return specifier;
|
|
12
|
-
}
|
|
13
|
-
function resolveAsFileOrDirectory(p) {
|
|
14
|
-
const abs = path.resolve(p);
|
|
15
|
-
if (fs.existsSync(abs) && fs.statSync(abs).isFile())
|
|
16
|
-
return abs;
|
|
17
|
-
const extensions = ['.ts', '.js', '.mjs', '.cjs'];
|
|
18
|
-
for (const ext of extensions) {
|
|
19
|
-
if (fs.existsSync(abs + ext) && fs.statSync(abs + ext).isFile()) {
|
|
20
|
-
return abs + ext;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) {
|
|
24
|
-
for (const file of extensions.map(e => 'index' + e)) {
|
|
25
|
-
const indexPath = path.join(abs, file);
|
|
26
|
-
if (fs.existsSync(indexPath) && fs.statSync(indexPath).isFile()) {
|
|
27
|
-
return indexPath;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
function visit(filePath) {
|
|
34
|
-
const absPath = path.resolve(filePath);
|
|
35
|
-
if (visited.has(absPath))
|
|
36
|
-
return;
|
|
37
|
-
visited.add(absPath);
|
|
38
|
-
const resolved = resolveAsFileOrDirectory(absPath);
|
|
39
|
-
if (!resolved)
|
|
40
|
-
return;
|
|
41
|
-
const source = fs.readFileSync(resolved, 'utf8');
|
|
42
|
-
const sourceFile = ts.createSourceFile(resolved, source, ts.ScriptTarget.Latest, true);
|
|
43
|
-
function walk(node) {
|
|
44
|
-
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
45
|
-
const moduleSpecifier = node.moduleSpecifier;
|
|
46
|
-
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier)) {
|
|
47
|
-
const spec = moduleSpecifier.text;
|
|
48
|
-
if (isExternal(spec)) {
|
|
49
|
-
externals.add(normalizeExternal(spec));
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const resolvedPath = resolveAsFileOrDirectory(path.resolve(path.dirname(resolved ?? ''), spec));
|
|
53
|
-
if (resolvedPath)
|
|
54
|
-
visit(resolvedPath);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (ts.isCallExpression(node) &&
|
|
59
|
-
ts.isIdentifier(node.expression) &&
|
|
60
|
-
node.expression.kind === ts.SyntaxKind.Identifier &&
|
|
61
|
-
node.expression.escapedText === 'require' &&
|
|
62
|
-
node.arguments.length === 1 &&
|
|
63
|
-
ts.isStringLiteral(node.arguments[0])) {
|
|
64
|
-
const spec = node.arguments[0].text;
|
|
65
|
-
if (isExternal(spec)) {
|
|
66
|
-
externals.add(normalizeExternal(spec));
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
const resolvedPath = resolveAsFileOrDirectory(path.resolve(path.dirname(resolved ?? ''), spec));
|
|
70
|
-
if (resolvedPath)
|
|
71
|
-
visit(resolvedPath);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
ts.forEachChild(node, walk);
|
|
75
|
-
}
|
|
76
|
-
ts.forEachChild(sourceFile, walk);
|
|
77
|
-
}
|
|
78
|
-
visit(entryFilePath);
|
|
79
|
-
return Array.from(externals);
|
|
80
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type PathToImport } from '../domain/utils/mapped-path.contract.js';
|
|
2
|
-
import { type UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
|
|
3
|
-
import { type ExposeEntry } from '../domain/config/federation-config.contract.js';
|
|
4
|
-
export declare function getUsedDependenciesFactory(workspaceRoot: string, fallbackEntryPoints?: string[]): (config: {
|
|
5
|
-
name?: string;
|
|
6
|
-
exposes?: Record<string, ExposeEntry>;
|
|
7
|
-
sharedMappings: PathToImport;
|
|
8
|
-
}) => UsedDependencies;
|