@softarc/native-federation 4.1.2 → 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/{src → dist}/lib/domain/config/federation-config.contract.d.ts +6 -2
- 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/{src → dist}/lib/domain/core/federation-info.contract.d.ts +1 -0
- package/dist/lib/domain/core/federation-info.contract.js +0 -0
- package/dist/lib/domain/core/federation-options.contract.js +0 -0
- package/{src → dist}/lib/domain/core/index.d.ts +1 -0
- package/dist/lib/domain/core/index.js +9 -0
- package/dist/lib/domain/core/manifest.contract.d.ts +5 -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 -71
- 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 -174
- 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/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 -7
- 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/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-options.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
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { setBuildAdapter } from "./lib/core/build/build-adapter.js";
|
|
2
|
+
import { buildForFederation } from "./lib/core/build/build-for-federation.js";
|
|
3
|
+
import { rebuildForFederation } from "./lib/core/build/rebuild-for-federation.js";
|
|
4
|
+
import { createFederationCache } from "./lib/core/cache/federation-cache.js";
|
|
5
|
+
import { bundleExposedAndMappings } from "./lib/core/build/bundle-exposed-and-mappings.js";
|
|
6
|
+
import { getExternals } from "./lib/core/build/get-externals.js";
|
|
7
|
+
import { normalizeFederationOptions } from "./lib/core/normalize-options.js";
|
|
8
|
+
import { writeFederationInfo } from "./lib/core/output/write-federation-info.js";
|
|
9
|
+
import { federationBuilder } from "./lib/core/federation-builder.js";
|
|
10
|
+
export * from "./domain.js";
|
|
11
|
+
export {
|
|
12
|
+
buildForFederation,
|
|
13
|
+
bundleExposedAndMappings,
|
|
14
|
+
createFederationCache,
|
|
15
|
+
federationBuilder,
|
|
16
|
+
getExternals,
|
|
17
|
+
normalizeFederationOptions,
|
|
18
|
+
rebuildForFederation,
|
|
19
|
+
setBuildAdapter,
|
|
20
|
+
writeFederationInfo
|
|
21
|
+
};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
export * from './lib/
|
|
1
|
+
export * from './lib/core/build/build-result-map.js';
|
|
2
2
|
export { hashFile } from './lib/utils/hash-file.js';
|
|
3
3
|
export * from './lib/utils/errors.js';
|
|
4
4
|
export { logger, setLogLevel } from './lib/utils/logger.js';
|
|
5
5
|
export type { PathToImport } from './lib/domain/utils/mapped-path.contract.js';
|
|
6
|
-
export { RebuildQueue, type TrackResult } from './lib/
|
|
7
|
-
export {
|
|
8
|
-
export { createBuildResultMap, lookupInResultMap, popFromResultMap, } from './lib/utils/build-result-map.js';
|
|
9
|
-
export { writeImportMap } from './lib/core/write-import-map.js';
|
|
6
|
+
export { RebuildQueue, type TrackResult } from './lib/core/rebuild-queue.js';
|
|
7
|
+
export { writeImportMap } from './lib/core/output/write-import-map.js';
|
|
10
8
|
export type { NormalizedExternalConfig, NormalizedSharedExternalsConfig, } from './lib/domain/config/external-config.contract.js';
|
|
11
9
|
export type { NormalizedFederationConfig } from './lib/domain/config/federation-config.contract.js';
|
|
12
|
-
export { getDefaultCachePath, getChecksum } from './lib/
|
|
10
|
+
export { getDefaultCachePath, getChecksum } from './lib/core/cache/cache-persistence.js';
|
|
11
|
+
export { isESMExport, type ExportCondition, type ExportEntry, } from './lib/utils/package/package-info.js';
|
|
13
12
|
export { isInSkipList, prepareSkipList } from './lib/config/default-skip-list.js';
|
|
14
|
-
export { NfFileWatcher, NfFileWatcherOptions } from './lib/domain/utils/file-watcher.contract.js';
|
|
13
|
+
export type { NfFileWatcher, NfFileWatcherOptions } from './lib/domain/utils/file-watcher.contract.js';
|
|
15
14
|
export { syncNfFileWatcher, createNfWatcher } from './lib/utils/file-watcher.js';
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from "./lib/core/build/build-result-map.js";
|
|
2
|
+
import { hashFile } from "./lib/utils/hash-file.js";
|
|
3
|
+
export * from "./lib/utils/errors.js";
|
|
4
|
+
import { logger, setLogLevel } from "./lib/utils/logger.js";
|
|
5
|
+
import { RebuildQueue } from "./lib/core/rebuild-queue.js";
|
|
6
|
+
import { writeImportMap } from "./lib/core/output/write-import-map.js";
|
|
7
|
+
import { getDefaultCachePath, getChecksum } from "./lib/core/cache/cache-persistence.js";
|
|
8
|
+
import {
|
|
9
|
+
isESMExport
|
|
10
|
+
} from "./lib/utils/package/package-info.js";
|
|
11
|
+
import { isInSkipList, prepareSkipList } from "./lib/config/default-skip-list.js";
|
|
12
|
+
import { syncNfFileWatcher, createNfWatcher } from "./lib/utils/file-watcher.js";
|
|
13
|
+
export {
|
|
14
|
+
RebuildQueue,
|
|
15
|
+
createNfWatcher,
|
|
16
|
+
getChecksum,
|
|
17
|
+
getDefaultCachePath,
|
|
18
|
+
hashFile,
|
|
19
|
+
isESMExport,
|
|
20
|
+
isInSkipList,
|
|
21
|
+
logger,
|
|
22
|
+
prepareSkipList,
|
|
23
|
+
setLogLevel,
|
|
24
|
+
syncNfFileWatcher,
|
|
25
|
+
writeImportMap
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
let _context = {};
|
|
2
|
+
function useWorkspace(workspaceRoot) {
|
|
3
|
+
_context = { ..._context, workspaceRoot };
|
|
4
|
+
}
|
|
5
|
+
function usePackageJson(packageJson) {
|
|
6
|
+
_context = { ..._context, packageJson };
|
|
7
|
+
}
|
|
8
|
+
function getConfigContext() {
|
|
9
|
+
return _context;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getConfigContext,
|
|
13
|
+
usePackageJson,
|
|
14
|
+
useWorkspace
|
|
15
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const DEFAULT_SKIP_LIST = [
|
|
2
|
+
"@softarc/native-federation",
|
|
3
|
+
"@softarc/native-federation-core",
|
|
4
|
+
"@softarc/native-federation-node",
|
|
5
|
+
"@softarc/native-federation-esbuild",
|
|
6
|
+
"@softarc/native-federation-runtime",
|
|
7
|
+
"@softarc/native-federation-orchestrator",
|
|
8
|
+
"vanilla-native-federation",
|
|
9
|
+
"es-module-shims",
|
|
10
|
+
"tslib/",
|
|
11
|
+
(pkg) => pkg.startsWith("@types/")
|
|
12
|
+
];
|
|
13
|
+
function prepareSkipList(skipList) {
|
|
14
|
+
return {
|
|
15
|
+
strings: new Set(skipList.filter((e) => typeof e === "string")),
|
|
16
|
+
functions: skipList.filter((e) => typeof e === "function"),
|
|
17
|
+
regexps: skipList.filter((e) => typeof e === "object")
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isInSkipList(entry, skipList) {
|
|
21
|
+
if (skipList.strings.has(entry)) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (skipList.functions.find((f) => f(entry))) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
if (skipList.regexps.find((r) => r.test(entry))) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
DEFAULT_SKIP_LIST,
|
|
34
|
+
isInSkipList,
|
|
35
|
+
prepareSkipList
|
|
36
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
const RESOLVE_EXTENSIONS = [".ts", ".js", ".mjs", ".cjs"];
|
|
4
|
+
function getExternalImportsCore(io, entryFilePath) {
|
|
5
|
+
const visited = /* @__PURE__ */ new Set();
|
|
6
|
+
const externals = /* @__PURE__ */ new Set();
|
|
7
|
+
function isExternal(specifier) {
|
|
8
|
+
return !specifier.startsWith(".") && !path.isAbsolute(specifier);
|
|
9
|
+
}
|
|
10
|
+
function resolveAsFileOrDirectory(p) {
|
|
11
|
+
const abs = path.resolve(p);
|
|
12
|
+
if (io.isFile(abs)) return abs;
|
|
13
|
+
for (const ext of RESOLVE_EXTENSIONS) {
|
|
14
|
+
if (io.isFile(abs + ext)) return abs + ext;
|
|
15
|
+
}
|
|
16
|
+
if (io.isDirectory(abs)) {
|
|
17
|
+
for (const file of RESOLVE_EXTENSIONS.map((e) => "index" + e)) {
|
|
18
|
+
const indexPath = path.join(abs, file);
|
|
19
|
+
if (io.isFile(indexPath)) return indexPath;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function handleSpecifier(spec, fromFile) {
|
|
25
|
+
if (isExternal(spec)) {
|
|
26
|
+
externals.add(spec);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const resolvedPath = resolveAsFileOrDirectory(path.resolve(path.dirname(fromFile), spec));
|
|
30
|
+
if (resolvedPath) visit(resolvedPath);
|
|
31
|
+
}
|
|
32
|
+
function visit(filePath) {
|
|
33
|
+
const absPath = path.resolve(filePath);
|
|
34
|
+
if (visited.has(absPath)) return;
|
|
35
|
+
visited.add(absPath);
|
|
36
|
+
const resolvedFile = resolveAsFileOrDirectory(absPath);
|
|
37
|
+
if (!resolvedFile) return;
|
|
38
|
+
const fromFile = resolvedFile;
|
|
39
|
+
const source = io.readText(fromFile);
|
|
40
|
+
const sourceFile = ts.createSourceFile(fromFile, source, ts.ScriptTarget.Latest, true);
|
|
41
|
+
function walk(node) {
|
|
42
|
+
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
43
|
+
const moduleSpecifier = node.moduleSpecifier;
|
|
44
|
+
if (moduleSpecifier && ts.isStringLiteral(moduleSpecifier)) {
|
|
45
|
+
handleSpecifier(moduleSpecifier.text, fromFile);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.escapedText === "require" && node.arguments.length === 1 && ts.isStringLiteral(node.arguments[0])) {
|
|
49
|
+
handleSpecifier(node.arguments[0].text, fromFile);
|
|
50
|
+
}
|
|
51
|
+
ts.forEachChild(node, walk);
|
|
52
|
+
}
|
|
53
|
+
ts.forEachChild(sourceFile, walk);
|
|
54
|
+
}
|
|
55
|
+
visit(entryFilePath);
|
|
56
|
+
return Array.from(externals);
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
getExternalImportsCore
|
|
60
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ProjectData } from '@softarc/sheriff-core';
|
|
2
|
+
import { type PackageJsonRepository } from '../domain/utils/package-json.contract.js';
|
|
3
|
+
import { type FileReaderPort } from '../domain/utils/io-port.contract.js';
|
|
4
|
+
import { type PathToImport } from '../domain/utils/mapped-path.contract.js';
|
|
5
|
+
import { type UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
|
|
6
|
+
import { type ExposeEntry } from '../domain/config/federation-config.contract.js';
|
|
7
|
+
type GetProjectData = (entryPoint: string, cwd: string, options: {
|
|
8
|
+
includeExternalLibraries: boolean;
|
|
9
|
+
}) => ProjectData;
|
|
10
|
+
export interface UsedDependenciesDeps {
|
|
11
|
+
io: FileReaderPort;
|
|
12
|
+
repo: PackageJsonRepository;
|
|
13
|
+
getProjectData: GetProjectData;
|
|
14
|
+
}
|
|
15
|
+
type UsedDependenciesConfig = {
|
|
16
|
+
name?: string;
|
|
17
|
+
exposes?: Record<string, ExposeEntry>;
|
|
18
|
+
sharedMappings: PathToImport;
|
|
19
|
+
};
|
|
20
|
+
export declare function getUsedDependenciesFactory(workspaceRoot: string, fallbackEntryPoints?: string[]): (config: UsedDependenciesConfig) => UsedDependencies;
|
|
21
|
+
export declare function getUsedDependenciesFactoryCore(deps: UsedDependenciesDeps, workspaceRoot: string, fallbackEntryPoints?: string[]): (config: UsedDependenciesConfig) => UsedDependencies;
|
|
22
|
+
export declare function isSharedMapping(filePath: string, sharedMappings: PathToImport): boolean;
|
|
23
|
+
export declare function matchMapping(filePath: string, sharedMappings: PathToImport): string | null;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { getProjectData as sheriffGetProjectData } from "@softarc/sheriff-core";
|
|
2
|
+
import { cwd } from "process";
|
|
3
|
+
import { sharedPackageJsonRepository, getPackageInfo } from "../utils/package/package-info.js";
|
|
4
|
+
import { getExternalImportsCore } from "./get-external-imports.js";
|
|
5
|
+
import { nodeIo } from "../utils/io/node-io-adapter.js";
|
|
6
|
+
import { parseWildcard, substituteWildcard, toPosix } from "../utils/path-patterns.js";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
const defaultDeps = {
|
|
9
|
+
io: nodeIo,
|
|
10
|
+
repo: sharedPackageJsonRepository,
|
|
11
|
+
getProjectData: sheriffGetProjectData
|
|
12
|
+
};
|
|
13
|
+
function getUsedDependenciesFactory(workspaceRoot, fallbackEntryPoints) {
|
|
14
|
+
return getUsedDependenciesFactoryCore(defaultDeps, workspaceRoot, fallbackEntryPoints);
|
|
15
|
+
}
|
|
16
|
+
function getUsedDependenciesFactoryCore(deps, workspaceRoot, fallbackEntryPoints) {
|
|
17
|
+
return (config) => {
|
|
18
|
+
let entryPoints = Object.values(config.exposes ?? {}).map((e) => e.file);
|
|
19
|
+
if (entryPoints.length < 1) entryPoints = fallbackEntryPoints;
|
|
20
|
+
if (!entryPoints || entryPoints.length < 1)
|
|
21
|
+
throw new Error(
|
|
22
|
+
"[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."
|
|
23
|
+
);
|
|
24
|
+
const fileInfos = Object.values(entryPoints ?? []).reduce(
|
|
25
|
+
(acc, entryPoint) => ({
|
|
26
|
+
...acc,
|
|
27
|
+
...deps.getProjectData(entryPoint, cwd(), {
|
|
28
|
+
includeExternalLibraries: true
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
{}
|
|
32
|
+
);
|
|
33
|
+
const usedPackageNames = /* @__PURE__ */ new Set();
|
|
34
|
+
for (const fileInfo of Object.values(fileInfos)) {
|
|
35
|
+
for (const pckg of [
|
|
36
|
+
...fileInfo?.externalLibraries || [],
|
|
37
|
+
...fileInfo?.unresolvedImports || []
|
|
38
|
+
]) {
|
|
39
|
+
usedPackageNames.add(pckg);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
external: addTransientDeps(usedPackageNames, workspaceRoot, deps),
|
|
44
|
+
internal: resolveUsedMappings(fileInfos, workspaceRoot, config.sharedMappings)
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function addTransientDeps(packages, workspaceRoot, deps) {
|
|
49
|
+
const packagesAndPeers = /* @__PURE__ */ new Set([...packages]);
|
|
50
|
+
const discovered = new Set(packagesAndPeers);
|
|
51
|
+
const stack = [...packagesAndPeers];
|
|
52
|
+
while (stack.length > 0) {
|
|
53
|
+
const dep = stack.pop();
|
|
54
|
+
if (!dep) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const pInfo = getPackageInfo(dep, workspaceRoot, deps.repo);
|
|
58
|
+
if (!pInfo) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const peerDeps = getExternalImportsCore(deps.io, pInfo.entryPoint);
|
|
62
|
+
for (const peerDep of peerDeps) {
|
|
63
|
+
if (!discovered.has(peerDep)) {
|
|
64
|
+
discovered.add(peerDep);
|
|
65
|
+
stack.push(peerDep);
|
|
66
|
+
packagesAndPeers.add(peerDep);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return packagesAndPeers;
|
|
71
|
+
}
|
|
72
|
+
function resolveUsedMappings(fileInfos, workspaceRoot, sharedMappings) {
|
|
73
|
+
const usedMappings = {};
|
|
74
|
+
for (const fileName of Object.keys(fileInfos)) {
|
|
75
|
+
const fullFileName = path.join(workspaceRoot, fileName);
|
|
76
|
+
if (isSharedMapping(fullFileName, sharedMappings)) continue;
|
|
77
|
+
const fileInfo = fileInfos[fileName];
|
|
78
|
+
if (!fileInfo) continue;
|
|
79
|
+
for (const imp of fileInfo.imports ?? []) {
|
|
80
|
+
const fullImport = path.join(workspaceRoot, imp);
|
|
81
|
+
const match = matchMapping(fullImport, sharedMappings);
|
|
82
|
+
if (match) usedMappings[fullImport] = match;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return usedMappings;
|
|
86
|
+
}
|
|
87
|
+
function isSharedMapping(filePath, sharedMappings) {
|
|
88
|
+
for (const sharedPath of Object.keys(sharedMappings)) {
|
|
89
|
+
const { prefix, hasWildcard } = parseWildcard(sharedPath);
|
|
90
|
+
if (hasWildcard) {
|
|
91
|
+
if (filePath.startsWith(prefix)) return true;
|
|
92
|
+
} else if (filePath.startsWith(sharedPath + path.sep) || filePath === sharedPath) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
function matchMapping(filePath, sharedMappings) {
|
|
99
|
+
for (const [sharedPath, sharedImport] of Object.entries(sharedMappings)) {
|
|
100
|
+
const { prefix, suffix, hasWildcard } = parseWildcard(sharedPath);
|
|
101
|
+
if (hasWildcard) {
|
|
102
|
+
if (!filePath.startsWith(prefix)) continue;
|
|
103
|
+
if (suffix && !filePath.includes(suffix)) continue;
|
|
104
|
+
const captured = suffix ? filePath.slice(prefix.length, filePath.indexOf(suffix, prefix.length)) : filePath.slice(prefix.length);
|
|
105
|
+
return substituteWildcard(sharedImport, toImportPath(captured));
|
|
106
|
+
} else if (filePath === sharedPath || isIndexOf(filePath, sharedPath)) {
|
|
107
|
+
return sharedImport;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
const INDEX_PATTERN = /\/index\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/;
|
|
113
|
+
function isIndexOf(filePath, dirPath) {
|
|
114
|
+
return filePath.startsWith(dirPath + path.sep) && INDEX_PATTERN.test(filePath);
|
|
115
|
+
}
|
|
116
|
+
function toImportPath(filePath) {
|
|
117
|
+
const withoutExt = filePath.replace(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/, "");
|
|
118
|
+
const normalized = toPosix(withoutExt);
|
|
119
|
+
return normalized.endsWith("/index") ? normalized.slice(0, -6) : normalized;
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
getUsedDependenciesFactory,
|
|
123
|
+
getUsedDependenciesFactoryCore,
|
|
124
|
+
isSharedMapping,
|
|
125
|
+
matchMapping
|
|
126
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import type { FileReaderPort } from '../domain/utils/io-port.contract.js';
|
|
1
2
|
import type { PathToImport } from '../domain/utils/mapped-path.contract.js';
|
|
2
3
|
/**
|
|
3
4
|
* Will return user defined and tsconfig defined paths including their imports, might contain wildcards
|
|
4
|
-
* @param param0
|
|
5
|
-
* @returns
|
|
6
5
|
*/
|
|
7
6
|
export declare function getRawMappedPaths(rootTsConfigPath: string, configuredSharedMappings?: string[], rootPath?: string): PathToImport;
|
|
7
|
+
export declare function getRawMappedPathsCore(io: FileReaderPort, rootTsConfigPath: string, configuredSharedMappings?: string[], rootPath?: string): PathToImport;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import JSON5 from "json5";
|
|
3
|
+
import { nodeIo } from "../utils/io/node-io-adapter.js";
|
|
4
|
+
function getRawMappedPaths(rootTsConfigPath, configuredSharedMappings, rootPath) {
|
|
5
|
+
return getRawMappedPathsCore(nodeIo, rootTsConfigPath, configuredSharedMappings, rootPath);
|
|
6
|
+
}
|
|
7
|
+
function getRawMappedPathsCore(io, rootTsConfigPath, configuredSharedMappings, rootPath) {
|
|
8
|
+
const mappedPaths = {};
|
|
9
|
+
if (!path.isAbsolute(rootTsConfigPath)) {
|
|
10
|
+
throw new Error("SharedMappings.register: tsConfigPath needs to be an absolute path!");
|
|
11
|
+
}
|
|
12
|
+
const basePath = rootPath ?? path.normalize(path.dirname(rootTsConfigPath));
|
|
13
|
+
const shareAll = !configuredSharedMappings;
|
|
14
|
+
const sharedMappings = configuredSharedMappings ?? [];
|
|
15
|
+
const tsConfig = JSON5.parse(io.readText(rootTsConfigPath));
|
|
16
|
+
const mappings = tsConfig?.compilerOptions?.paths;
|
|
17
|
+
if (!mappings) {
|
|
18
|
+
return mappedPaths;
|
|
19
|
+
}
|
|
20
|
+
for (const key in mappings) {
|
|
21
|
+
const libPath = path.normalize(path.join(basePath, mappings[key][0]));
|
|
22
|
+
if (shareAll || sharedMappings.includes(key)) {
|
|
23
|
+
mappedPaths[libPath] = key;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return mappedPaths;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
getRawMappedPaths,
|
|
30
|
+
getRawMappedPathsCore
|
|
31
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function removeUnusedDeps(usedDependencies, config) {
|
|
2
|
+
const filteredDependencies = Object.entries(config.shared).filter(([shared, meta]) => !!meta.includeSecondaries || usedDependencies.external.has(shared)).reduce((acc, [shared, meta]) => ({ ...acc, [shared]: meta }), {});
|
|
3
|
+
return {
|
|
4
|
+
...config,
|
|
5
|
+
shared: filteredDependencies,
|
|
6
|
+
sharedMappings: usedDependencies.internal
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
removeUnusedDeps
|
|
11
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type SkipList, type PreparedSkipList } from '../domain/config/skip-list.contract.js';
|
|
2
|
+
import type { PackageJsonRepository } from '../domain/utils/package-json.contract.js';
|
|
3
|
+
import type { FileReaderPort, GlobPort } from '../domain/utils/io-port.contract.js';
|
|
4
|
+
import type { ExternalConfig, IncludeSecondariesOptions, ShareAllExternalsOptions, SharedExternalsConfig, ShareExternalsOptions } from '../domain/config/external-config.contract.js';
|
|
5
|
+
export declare function findRootTsConfigJson(): string;
|
|
6
|
+
export declare function findRootTsConfigJsonCore(io: FileReaderPort): string;
|
|
7
|
+
export declare function getSecondaries(io: FileReaderPort & GlobPort, includeSecondaries: IncludeSecondariesOptions, libPath: string, key: string, shareObject: ExternalConfig, preparedSkipList: PreparedSkipList): SharedExternalsConfig | null;
|
|
8
|
+
export declare function shareAll(config: ShareAllExternalsOptions, opts?: {
|
|
9
|
+
skipList?: SkipList;
|
|
10
|
+
projectPath?: string;
|
|
11
|
+
overrides?: ShareExternalsOptions;
|
|
12
|
+
}): ShareExternalsOptions | null;
|
|
13
|
+
export declare function shareAllCore(io: FileReaderPort & GlobPort, config: ShareAllExternalsOptions, opts?: {
|
|
14
|
+
skipList?: SkipList;
|
|
15
|
+
projectPath?: string;
|
|
16
|
+
overrides?: ShareExternalsOptions;
|
|
17
|
+
}, repo?: PackageJsonRepository): ShareExternalsOptions | null;
|
|
18
|
+
export declare function setInferVersion(infer: boolean): void;
|
|
19
|
+
export declare function share(configuredShareObjects: ShareExternalsOptions, projectPath?: string, skipList?: SkipList): ShareExternalsOptions;
|
|
20
|
+
export declare function shareCore(io: FileReaderPort & GlobPort, configuredShareObjects: ShareExternalsOptions, projectPath?: string, skipList?: SkipList, repo?: PackageJsonRepository): ShareExternalsOptions;
|