@softarc/native-federation 3.5.5 → 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 +33 -5
- package/src/config.d.ts +4 -1
- package/src/config.js +4 -6
- package/src/domain.d.ts +2 -0
- package/src/domain.js +2 -0
- package/src/index.d.ts +10 -1
- package/src/index.js +10 -5
- package/src/internal.d.ts +13 -0
- package/src/internal.js +10 -0
- package/src/lib/config/configuration-context.js +3 -9
- package/src/lib/config/default-skip-list.d.ts +4 -0
- package/src/lib/config/default-skip-list.js +31 -0
- 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 +6 -18
- package/src/lib/config/share-utils.js +49 -128
- package/src/lib/config/with-native-federation.d.ts +1 -1
- package/src/lib/config/with-native-federation.js +48 -75
- package/src/lib/core/build-adapter.d.ts +3 -28
- package/src/lib/core/build-adapter.js +8 -13
- package/src/lib/core/build-for-federation.d.ts +4 -10
- package/src/lib/core/build-for-federation.js +84 -79
- package/src/lib/core/bundle-exposed-and-mappings.d.ts +6 -10
- package/src/lib/core/bundle-exposed-and-mappings.js +78 -60
- package/src/lib/core/bundle-shared.d.ts +11 -6
- package/src/lib/core/bundle-shared.js +88 -72
- package/src/lib/core/default-external-list.js +1 -8
- package/src/lib/core/federation-builder.d.ts +11 -6
- package/src/lib/core/federation-builder.js +27 -21
- 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 +1 -1
- package/src/lib/core/get-externals.js +2 -6
- 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 +2 -2
- package/src/lib/core/write-federation-info.js +3 -8
- package/src/lib/core/write-import-map.d.ts +6 -3
- package/src/lib/core/write-import-map.js +13 -9
- package/src/lib/domain/config/external-config.contract.d.ts +43 -0
- package/src/lib/domain/config/external-config.contract.js +1 -0
- package/src/lib/domain/config/federation-config.contract.d.ts +35 -0
- package/src/lib/domain/config/federation-config.contract.js +1 -0
- package/src/lib/domain/config/index.d.ts +3 -0
- package/src/lib/domain/config/index.js +1 -0
- package/src/lib/{core/default-skip-list.d.ts → domain/config/skip-list.contract.d.ts} +0 -3
- package/src/lib/domain/config/skip-list.contract.js +1 -0
- package/src/lib/domain/config/with-native-federation.contract.d.ts +2 -0
- package/src/lib/domain/config/with-native-federation.contract.js +1 -0
- package/src/lib/domain/core/build-adapter.contract.d.ts +40 -0
- package/src/lib/domain/core/build-adapter.contract.js +1 -0
- package/src/lib/domain/core/build-notification-options.contract.d.ts +9 -0
- package/src/lib/domain/core/build-notification-options.contract.js +6 -0
- 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 +33 -0
- package/src/lib/domain/core/federation-info.contract.js +1 -0
- package/src/lib/domain/core/federation-options.contract.d.ts +21 -0
- package/src/lib/domain/core/federation-options.contract.js +1 -0
- package/src/lib/domain/core/index.d.ts +6 -0
- package/src/lib/domain/core/index.js +2 -0
- package/src/lib/domain/utils/index.d.ts +2 -0
- package/src/lib/domain/utils/index.js +1 -0
- package/src/lib/domain/utils/keyvaluepair.contract.d.ts +4 -0
- package/src/lib/domain/utils/keyvaluepair.contract.js +1 -0
- package/src/lib/domain/utils/mapped-path.contract.d.ts +1 -0
- package/src/lib/domain/utils/mapped-path.contract.js +5 -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 +3 -2
- package/src/lib/utils/build-result-map.js +14 -13
- package/src/lib/utils/{bundle-caching.d.ts → cache-persistence.d.ts} +6 -4
- package/src/lib/utils/cache-persistence.js +66 -0
- package/src/lib/utils/errors.js +1 -6
- package/src/lib/utils/get-external-imports.js +5 -10
- 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.js +3 -8
- package/src/lib/utils/logger.js +10 -16
- package/src/lib/utils/mapped-paths.d.ts +7 -10
- package/src/lib/utils/mapped-paths.js +18 -37
- package/src/lib/utils/normalize.js +2 -7
- package/src/lib/utils/package-info.js +36 -47
- package/src/lib/utils/rebuild-queue.d.ts +14 -1
- package/src/lib/utils/rebuild-queue.js +36 -21
- package/src/lib/utils/resolve-glob.js +7 -12
- package/src/lib/utils/resolve-wildcard-keys.js +9 -15
- package/src/lib/utils/rewrite-chunk-imports.d.ts +0 -2
- package/src/lib/utils/rewrite-chunk-imports.js +13 -29
- package/LICENSE +0 -8
- package/README.md +0 -509
- package/build.d.ts +0 -1
- package/build.js +0 -5
- package/build.js.map +0 -1
- package/src/build.d.ts +0 -19
- package/src/build.js +0 -38
- package/src/build.js.map +0 -1
- package/src/config.js.map +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/config/configuration-context.js.map +0 -1
- package/src/lib/config/federation-config.d.ts +0 -55
- package/src/lib/config/federation-config.js +0 -3
- package/src/lib/config/federation-config.js.map +0 -1
- package/src/lib/config/share-utils.js.map +0 -1
- package/src/lib/config/with-native-federation.js.map +0 -1
- package/src/lib/core/build-adapter.js.map +0 -1
- package/src/lib/core/build-for-federation.js.map +0 -1
- package/src/lib/core/bundle-exposed-and-mappings.js.map +0 -1
- package/src/lib/core/bundle-shared.js.map +0 -1
- package/src/lib/core/default-external-list.js.map +0 -1
- package/src/lib/core/default-server-deps-list.d.ts +0 -2
- package/src/lib/core/default-server-deps-list.js +0 -10
- package/src/lib/core/default-server-deps-list.js.map +0 -1
- package/src/lib/core/default-skip-list.js +0 -49
- package/src/lib/core/default-skip-list.js.map +0 -1
- package/src/lib/core/federation-builder.js.map +0 -1
- package/src/lib/core/federation-options.d.ts +0 -14
- package/src/lib/core/federation-options.js +0 -3
- package/src/lib/core/federation-options.js.map +0 -1
- package/src/lib/core/get-externals.js.map +0 -1
- package/src/lib/core/load-federation-config.d.ts +0 -3
- package/src/lib/core/load-federation-config.js +0 -24
- package/src/lib/core/load-federation-config.js.map +0 -1
- package/src/lib/core/remove-unused-deps.d.ts +0 -2
- package/src/lib/core/remove-unused-deps.js +0 -98
- package/src/lib/core/remove-unused-deps.js.map +0 -1
- package/src/lib/core/write-federation-info.js.map +0 -1
- package/src/lib/core/write-import-map.js.map +0 -1
- package/src/lib/utils/build-result-map.js.map +0 -1
- package/src/lib/utils/build-utils.d.ts +0 -2
- package/src/lib/utils/build-utils.js +0 -9
- package/src/lib/utils/build-utils.js.map +0 -1
- package/src/lib/utils/bundle-caching.js +0 -78
- package/src/lib/utils/bundle-caching.js.map +0 -1
- package/src/lib/utils/config-utils.d.ts +0 -2
- package/src/lib/utils/config-utils.js +0 -13
- package/src/lib/utils/config-utils.js.map +0 -1
- package/src/lib/utils/errors.js.map +0 -1
- package/src/lib/utils/get-external-imports.js.map +0 -1
- package/src/lib/utils/hash-file.js.map +0 -1
- package/src/lib/utils/logger.js.map +0 -1
- package/src/lib/utils/mapped-paths.js.map +0 -1
- package/src/lib/utils/normalize.js.map +0 -1
- package/src/lib/utils/package-info.js.map +0 -1
- package/src/lib/utils/rebuild-queue.js.map +0 -1
- package/src/lib/utils/resolve-glob.js.map +0 -1
- package/src/lib/utils/resolve-wildcard-keys.js.map +0 -1
- package/src/lib/utils/rewrite-chunk-imports.js.map +0 -1
|
@@ -0,0 +1,66 @@
|
|
|
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
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AbortedError = void 0;
|
|
4
|
-
class AbortedError extends Error {
|
|
1
|
+
export class AbortedError extends Error {
|
|
5
2
|
constructor(message) {
|
|
6
3
|
super(message);
|
|
7
4
|
this.name = 'AbortedError';
|
|
8
5
|
Object.setPrototypeOf(this, AbortedError.prototype);
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
exports.AbortedError = AbortedError;
|
|
12
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
const ts = tslib_1.__importStar(require("typescript"));
|
|
8
|
-
function getExternalImports(entryFilePath) {
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as ts from 'typescript';
|
|
4
|
+
export function getExternalImports(entryFilePath) {
|
|
9
5
|
const visited = new Set();
|
|
10
6
|
const externals = new Set();
|
|
11
7
|
function isExternal(specifier) {
|
|
@@ -25,7 +21,7 @@ function getExternalImports(entryFilePath) {
|
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
if (fs.existsSync(abs) && fs.statSync(abs).isDirectory()) {
|
|
28
|
-
for (const file of extensions.map(
|
|
24
|
+
for (const file of extensions.map(e => 'index' + e)) {
|
|
29
25
|
const indexPath = path.join(abs, file);
|
|
30
26
|
if (fs.existsSync(indexPath) && fs.statSync(indexPath).isFile()) {
|
|
31
27
|
return indexPath;
|
|
@@ -82,4 +78,3 @@ function getExternalImports(entryFilePath) {
|
|
|
82
78
|
visit(entryFilePath);
|
|
83
79
|
return Array.from(externals);
|
|
84
80
|
}
|
|
85
|
-
//# sourceMappingURL=get-external-imports.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PathToImport } from '../domain/utils/mapped-path.contract.js';
|
|
2
|
+
import { type UsedDependencies } from '../domain/utils/used-dependencies.contract.js';
|
|
3
|
+
export declare function getUsedDependenciesFactory(workspaceRoot: string, fallbackEntryPoints?: string[]): (config: {
|
|
4
|
+
name?: string;
|
|
5
|
+
exposes?: Record<string, string>;
|
|
6
|
+
sharedMappings: PathToImport;
|
|
7
|
+
}) => UsedDependencies;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { getProjectData } from '@softarc/sheriff-core';
|
|
2
|
+
import { cwd } from 'process';
|
|
3
|
+
import { getPackageInfo } from './package-info.js';
|
|
4
|
+
import { getExternalImports as extractExternalImports } from './get-external-imports.js';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
export function getUsedDependenciesFactory(workspaceRoot, fallbackEntryPoints) {
|
|
7
|
+
return config => {
|
|
8
|
+
let entryPoints = Object.values(config.exposes ?? {});
|
|
9
|
+
if (entryPoints.length < 1)
|
|
10
|
+
entryPoints = fallbackEntryPoints;
|
|
11
|
+
if (!entryPoints || entryPoints.length < 1)
|
|
12
|
+
throw new Error('[removeUnusedDeps] native-federation is missing an entryPoint! You can set it using the Federation options or by setting an exposed module in the Federation config file.');
|
|
13
|
+
const fileInfos = Object.values(entryPoints ?? []).reduce((acc, entryPoint) => ({
|
|
14
|
+
...acc,
|
|
15
|
+
...getProjectData(entryPoint, cwd(), {
|
|
16
|
+
includeExternalLibraries: true,
|
|
17
|
+
}),
|
|
18
|
+
}), {});
|
|
19
|
+
const usedPackageNames = new Set();
|
|
20
|
+
for (const fileInfo of Object.values(fileInfos)) {
|
|
21
|
+
for (const pckg of [
|
|
22
|
+
...(fileInfo?.externalLibraries || []),
|
|
23
|
+
...(fileInfo?.unresolvedImports || []),
|
|
24
|
+
]) {
|
|
25
|
+
usedPackageNames.add(pckg);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
external: addTransientDeps(usedPackageNames, workspaceRoot),
|
|
30
|
+
internal: resolveUsedMappings(fileInfos, workspaceRoot, config.sharedMappings),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function addTransientDeps(packages, workspaceRoot) {
|
|
35
|
+
const packagesAndPeers = new Set([...packages]);
|
|
36
|
+
const discovered = new Set(packagesAndPeers);
|
|
37
|
+
const stack = [...packagesAndPeers];
|
|
38
|
+
while (stack.length > 0) {
|
|
39
|
+
const dep = stack.pop();
|
|
40
|
+
if (!dep) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const pInfo = getPackageInfo(dep, workspaceRoot);
|
|
44
|
+
if (!pInfo) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const peerDeps = extractExternalImports(pInfo.entryPoint);
|
|
48
|
+
for (const peerDep of peerDeps) {
|
|
49
|
+
if (!discovered.has(peerDep)) {
|
|
50
|
+
discovered.add(peerDep);
|
|
51
|
+
stack.push(peerDep);
|
|
52
|
+
packagesAndPeers.add(peerDep);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return packagesAndPeers;
|
|
57
|
+
}
|
|
58
|
+
function resolveUsedMappings(fileInfos, workspaceRoot, sharedMappings) {
|
|
59
|
+
const usedMappings = {};
|
|
60
|
+
for (const fileName of Object.keys(fileInfos)) {
|
|
61
|
+
const fullFileName = path.join(workspaceRoot, fileName);
|
|
62
|
+
if (isSharedMapping(fullFileName, sharedMappings))
|
|
63
|
+
continue;
|
|
64
|
+
const fileInfo = fileInfos[fileName];
|
|
65
|
+
if (!fileInfo)
|
|
66
|
+
continue;
|
|
67
|
+
// Check if any of this file's imports land in a shared mapping
|
|
68
|
+
for (const imp of fileInfo.imports ?? []) {
|
|
69
|
+
const fullImport = path.join(workspaceRoot, imp);
|
|
70
|
+
const match = matchMapping(fullImport, sharedMappings);
|
|
71
|
+
if (match)
|
|
72
|
+
usedMappings[fullImport] = match;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return usedMappings;
|
|
76
|
+
}
|
|
77
|
+
function isSharedMapping(filePath, sharedMappings) {
|
|
78
|
+
for (const sharedPath of Object.keys(sharedMappings)) {
|
|
79
|
+
const asteriskIndex = sharedPath.indexOf('*');
|
|
80
|
+
if (asteriskIndex !== -1) {
|
|
81
|
+
const prefix = sharedPath.substring(0, asteriskIndex);
|
|
82
|
+
if (filePath.startsWith(prefix))
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
else if (filePath.startsWith(sharedPath + path.sep) || filePath === sharedPath) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
function matchMapping(filePath, sharedMappings) {
|
|
92
|
+
for (const [sharedPath, sharedImport] of Object.entries(sharedMappings)) {
|
|
93
|
+
const asteriskIndex = sharedPath.indexOf('*');
|
|
94
|
+
if (asteriskIndex !== -1) {
|
|
95
|
+
const prefix = sharedPath.substring(0, asteriskIndex);
|
|
96
|
+
const suffix = sharedPath.substring(asteriskIndex + 1);
|
|
97
|
+
if (!filePath.startsWith(prefix))
|
|
98
|
+
continue;
|
|
99
|
+
if (suffix && !filePath.includes(suffix))
|
|
100
|
+
continue;
|
|
101
|
+
const captured = suffix
|
|
102
|
+
? filePath.slice(prefix.length, filePath.indexOf(suffix, prefix.length))
|
|
103
|
+
: filePath.slice(prefix.length);
|
|
104
|
+
return sharedImport.replace('*', toImportPath(captured));
|
|
105
|
+
}
|
|
106
|
+
else if (filePath === sharedPath || isIndexOf(filePath, sharedPath)) {
|
|
107
|
+
return sharedImport;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Detect if it's a barrel file which is inferred by typescript
|
|
114
|
+
*/
|
|
115
|
+
const INDEX_PATTERN = /\/index\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/;
|
|
116
|
+
function isIndexOf(filePath, dirPath) {
|
|
117
|
+
return filePath.startsWith(dirPath + path.sep) && INDEX_PATTERN.test(filePath);
|
|
118
|
+
}
|
|
119
|
+
function toImportPath(filePath) {
|
|
120
|
+
const withoutExt = filePath.replace(/\.(ts|tsx|mts|cts|js|jsx|mjs|cjs)$/, '');
|
|
121
|
+
const normalized = withoutExt.replace(/\\/g, '/');
|
|
122
|
+
return normalized.endsWith('/index') ? normalized.slice(0, -6) : normalized;
|
|
123
|
+
}
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const crypto = tslib_1.__importStar(require("crypto"));
|
|
6
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
7
|
-
function hashFile(fileName) {
|
|
1
|
+
import * as crypto from 'crypto';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
export function hashFile(fileName) {
|
|
8
4
|
const fileBuffer = fs.readFileSync(fileName);
|
|
9
5
|
const hashSum = crypto.createHash('md5');
|
|
10
6
|
hashSum.update(fileBuffer);
|
|
11
7
|
return hashSum.digest('hex');
|
|
12
8
|
}
|
|
13
|
-
//# sourceMappingURL=hash-file.js.map
|
package/src/lib/utils/logger.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
|
|
4
|
-
exports.setLogLevel = exports.logger = void 0;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
2
|
+
import chalk from 'chalk';
|
|
7
3
|
let verbose = false;
|
|
8
|
-
|
|
9
|
-
warn: (msg) => console.warn(
|
|
10
|
-
error: (msg) => console.error(
|
|
11
|
-
notice: (msg) => console.log(
|
|
12
|
-
info: (msg) => console.log(
|
|
13
|
-
verbose: (msg) => verbose && console.log(
|
|
14
|
-
debug: (msg) => verbose && console.log(
|
|
4
|
+
export const logger = {
|
|
5
|
+
warn: (msg) => console.warn(chalk.bgYellow.ansi256(15)(' WARN '), msg),
|
|
6
|
+
error: (msg) => console.error(chalk.bgRed.ansi256(15)(' ERRR '), msg),
|
|
7
|
+
notice: (msg) => console.log(chalk.bgYellowBright.black(' NOTE '), msg),
|
|
8
|
+
info: (msg) => console.log(chalk.bgGreen.ansi256(15)(' INFO '), msg),
|
|
9
|
+
verbose: (msg) => verbose && console.log(chalk.bgGreen.ansi256(15)(' DBG! '), msg),
|
|
10
|
+
debug: (msg) => verbose && console.log(chalk.bgGreen.ansi256(15)(' DBG! '), msg),
|
|
15
11
|
measure: (start, milestone) => {
|
|
16
12
|
if (!verbose)
|
|
17
13
|
return;
|
|
@@ -23,11 +19,9 @@ exports.logger = {
|
|
|
23
19
|
const timeStr = `${minutes.toString().padStart(2, '0')}:${seconds
|
|
24
20
|
.toString()
|
|
25
21
|
.padStart(2, '0')}:${msFormatted.padStart(7, '0')}ms`;
|
|
26
|
-
console.log(
|
|
22
|
+
console.log(chalk.bgGreen.ansi256(15)(' DBG! '), `${timeStr} - ${milestone}`);
|
|
27
23
|
},
|
|
28
24
|
};
|
|
29
|
-
const setLogLevel = (level) => {
|
|
25
|
+
export const setLogLevel = (level) => {
|
|
30
26
|
verbose = level === 'verbose';
|
|
31
27
|
};
|
|
32
|
-
exports.setLogLevel = setLogLevel;
|
|
33
|
-
//# sourceMappingURL=logger.js.map
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
rootPath?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function getMappedPaths({ rootTsConfigPath, sharedMappings, rootPath, }: GetMappedPathsOptions): Array<MappedPath>;
|
|
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,52 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const result = [];
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import JSON5 from 'json5';
|
|
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 = {};
|
|
12
11
|
if (!path.isAbsolute(rootTsConfigPath)) {
|
|
13
12
|
throw new Error('SharedMappings.register: tsConfigPath needs to be an absolute path!');
|
|
14
13
|
}
|
|
15
14
|
if (!rootPath) {
|
|
16
15
|
rootPath = path.normalize(path.dirname(rootTsConfigPath));
|
|
17
16
|
}
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
|
|
17
|
+
const shareAll = !configuredSharedMappings;
|
|
18
|
+
if (!configuredSharedMappings) {
|
|
19
|
+
configuredSharedMappings = [];
|
|
21
20
|
}
|
|
22
|
-
const globSharedMappings = sharedMappings
|
|
23
|
-
.filter((m) => m.endsWith('*'))
|
|
24
|
-
.map((m) => m.slice(0, -1));
|
|
25
21
|
const tsConfig = JSON5.parse(fs.readFileSync(rootTsConfigPath, { encoding: 'utf-8' }));
|
|
26
22
|
const mappings = tsConfig?.compilerOptions?.paths;
|
|
27
23
|
if (!mappings) {
|
|
28
|
-
return
|
|
24
|
+
return mappedPaths;
|
|
29
25
|
}
|
|
30
26
|
for (const key in mappings) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'] A mapping path with more than 1 entryPoint is currently not supported, falling back to the first path.');
|
|
27
|
+
const libPath = path.normalize(path.join(rootPath, mappings[key][0]));
|
|
28
|
+
if (configuredSharedMappings.includes(key) || shareAll) {
|
|
29
|
+
mappedPaths[libPath] = key;
|
|
35
30
|
}
|
|
36
|
-
const libPaths = key.includes('*')
|
|
37
|
-
? (0, resolve_wildcard_keys_1.resolveTsConfigWildcard)(key, mappings[key][0], rootPath).map(({ key, value }) => ({
|
|
38
|
-
key,
|
|
39
|
-
path: path.normalize(path.join(rootPath, value)),
|
|
40
|
-
}))
|
|
41
|
-
: [{ key, path: path.normalize(path.join(rootPath, mappings[key][0])) }];
|
|
42
|
-
libPaths
|
|
43
|
-
.filter((mapping) => shareAllMappings ||
|
|
44
|
-
sharedMappings.includes(mapping.key) ||
|
|
45
|
-
globSharedMappings.some((m) => mapping.key.startsWith(m)))
|
|
46
|
-
.forEach((mapping) => {
|
|
47
|
-
result.push(mapping);
|
|
48
|
-
});
|
|
49
31
|
}
|
|
50
|
-
return
|
|
32
|
+
return mappedPaths;
|
|
51
33
|
}
|
|
52
|
-
//# sourceMappingURL=mapped-paths.js.map
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalize = normalize;
|
|
4
|
-
exports.normalizePackageName = normalizePackageName;
|
|
5
|
-
function normalize(path, trailingSlash) {
|
|
1
|
+
export function normalize(path, trailingSlash) {
|
|
6
2
|
let cand = path.replace(/\\/g, '/');
|
|
7
3
|
if (typeof trailingSlash === 'undefined') {
|
|
8
4
|
return cand;
|
|
@@ -15,8 +11,7 @@ function normalize(path, trailingSlash) {
|
|
|
15
11
|
}
|
|
16
12
|
return cand;
|
|
17
13
|
}
|
|
18
|
-
function normalizePackageName(fileName) {
|
|
14
|
+
export function normalizePackageName(fileName) {
|
|
19
15
|
const sanitized = fileName.replace(/[^A-Za-z0-9]/g, '_');
|
|
20
16
|
return sanitized.startsWith('_') ? sanitized.slice(1) : sanitized;
|
|
21
17
|
}
|
|
22
|
-
//# sourceMappingURL=normalize.js.map
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.getPackageInfo = getPackageInfo;
|
|
7
|
-
exports.getVersionMaps = getVersionMaps;
|
|
8
|
-
exports.getPackageJsonFiles = getPackageJsonFiles;
|
|
9
|
-
exports.findDepPackageJson = findDepPackageJson;
|
|
10
|
-
exports._getPackageInfo = _getPackageInfo;
|
|
11
|
-
const tslib_1 = require("tslib");
|
|
12
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
13
|
-
const path = tslib_1.__importStar(require("path"));
|
|
14
|
-
const logger_1 = require("./logger");
|
|
15
|
-
const normalize_1 = require("./normalize");
|
|
16
|
-
const isESMExport = (e) => {
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
import { normalize } from './normalize.js';
|
|
5
|
+
export const isESMExport = (e) => {
|
|
17
6
|
if (e === 'import' || e === 'module-sync')
|
|
18
7
|
return true;
|
|
19
8
|
// Common ESM conventions
|
|
@@ -27,24 +16,23 @@ const isESMExport = (e) => {
|
|
|
27
16
|
// Ambiguous
|
|
28
17
|
return undefined;
|
|
29
18
|
};
|
|
30
|
-
exports.isESMExport = isESMExport;
|
|
31
19
|
const packageCache = {};
|
|
32
|
-
function findPackageJsonFiles(project, workspace) {
|
|
20
|
+
export function findPackageJsonFiles(project, workspace) {
|
|
33
21
|
return expandFolders(project, workspace)
|
|
34
|
-
.map(
|
|
35
|
-
.filter(
|
|
22
|
+
.map(f => path.join(f, 'package.json'))
|
|
23
|
+
.filter(f => fs.existsSync(f));
|
|
36
24
|
}
|
|
37
|
-
function expandFolders(child, parent) {
|
|
25
|
+
export function expandFolders(child, parent) {
|
|
38
26
|
const result = [];
|
|
39
|
-
parent =
|
|
40
|
-
child =
|
|
27
|
+
parent = normalize(parent, true);
|
|
28
|
+
child = normalize(child, true);
|
|
41
29
|
if (!child.startsWith(parent)) {
|
|
42
30
|
throw new Error(`Workspace folder ${path} needs to be a parent of the project folder ${child}`);
|
|
43
31
|
}
|
|
44
32
|
let current = child;
|
|
45
33
|
while (current !== parent) {
|
|
46
34
|
result.push(current);
|
|
47
|
-
const cand =
|
|
35
|
+
const cand = normalize(path.dirname(current), true);
|
|
48
36
|
if (cand === current) {
|
|
49
37
|
break;
|
|
50
38
|
}
|
|
@@ -53,8 +41,8 @@ function expandFolders(child, parent) {
|
|
|
53
41
|
result.push(parent);
|
|
54
42
|
return result;
|
|
55
43
|
}
|
|
56
|
-
function getPackageInfo(packageName, workspaceRoot) {
|
|
57
|
-
workspaceRoot =
|
|
44
|
+
export function getPackageInfo(packageName, workspaceRoot) {
|
|
45
|
+
workspaceRoot = normalize(workspaceRoot, true);
|
|
58
46
|
const packageJsonInfos = getPackageJsonFiles(workspaceRoot, workspaceRoot);
|
|
59
47
|
for (const info of packageJsonInfos) {
|
|
60
48
|
const cand = _getPackageInfo(packageName, info.directory);
|
|
@@ -62,26 +50,26 @@ function getPackageInfo(packageName, workspaceRoot) {
|
|
|
62
50
|
return cand;
|
|
63
51
|
}
|
|
64
52
|
}
|
|
65
|
-
|
|
53
|
+
logger.warn('No meta data found for shared lib ' + packageName);
|
|
66
54
|
return null;
|
|
67
55
|
}
|
|
68
56
|
function getVersionMapCacheKey(project, workspace) {
|
|
69
57
|
return `${project}**${workspace}`;
|
|
70
58
|
}
|
|
71
|
-
function getVersionMaps(project, workspace) {
|
|
72
|
-
return getPackageJsonFiles(project, workspace).map(
|
|
59
|
+
export function getVersionMaps(project, workspace) {
|
|
60
|
+
return getPackageJsonFiles(project, workspace).map(json => ({
|
|
73
61
|
...json.content['dependencies'],
|
|
74
62
|
}));
|
|
75
63
|
}
|
|
76
|
-
function getPackageJsonFiles(project, workspace) {
|
|
64
|
+
export function getPackageJsonFiles(project, workspace) {
|
|
77
65
|
const cacheKey = getVersionMapCacheKey(project, workspace);
|
|
78
66
|
let maps = packageCache[cacheKey];
|
|
79
67
|
if (maps) {
|
|
80
68
|
return maps;
|
|
81
69
|
}
|
|
82
|
-
maps = findPackageJsonFiles(project, workspace).map(
|
|
70
|
+
maps = findPackageJsonFiles(project, workspace).map(f => {
|
|
83
71
|
const content = JSON.parse(fs.readFileSync(f, 'utf-8'));
|
|
84
|
-
const directory =
|
|
72
|
+
const directory = normalize(path.dirname(f), true);
|
|
85
73
|
const result = {
|
|
86
74
|
content,
|
|
87
75
|
directory,
|
|
@@ -91,8 +79,10 @@ function getPackageJsonFiles(project, workspace) {
|
|
|
91
79
|
packageCache[cacheKey] = maps;
|
|
92
80
|
return maps;
|
|
93
81
|
}
|
|
94
|
-
function findDepPackageJson(packageName, projectRoot) {
|
|
82
|
+
export function findDepPackageJson(packageName, projectRoot) {
|
|
95
83
|
const mainPkgName = getPkgFolder(packageName);
|
|
84
|
+
if (!mainPkgName)
|
|
85
|
+
throw new Error(`Package.json "${packageName}" is missing`);
|
|
96
86
|
let mainPkgPath = path.join(projectRoot, 'node_modules', mainPkgName);
|
|
97
87
|
let mainPkgJsonPath = path.join(mainPkgPath, 'package.json');
|
|
98
88
|
let directory = projectRoot;
|
|
@@ -100,14 +90,14 @@ function findDepPackageJson(packageName, projectRoot) {
|
|
|
100
90
|
if (fs.existsSync(mainPkgJsonPath)) {
|
|
101
91
|
break;
|
|
102
92
|
}
|
|
103
|
-
directory =
|
|
93
|
+
directory = normalize(path.dirname(directory), true);
|
|
104
94
|
mainPkgPath = path.join(directory, 'node_modules', mainPkgName);
|
|
105
95
|
mainPkgJsonPath = path.join(mainPkgPath, 'package.json');
|
|
106
96
|
}
|
|
107
97
|
if (!fs.existsSync(mainPkgJsonPath)) {
|
|
108
98
|
// TODO: Add logger
|
|
109
99
|
// context.logger.warn('No package.json found for ' + packageName);
|
|
110
|
-
|
|
100
|
+
logger.verbose('No package.json found for ' + packageName + ' in ' + mainPkgPath);
|
|
111
101
|
return null;
|
|
112
102
|
}
|
|
113
103
|
return mainPkgJsonPath;
|
|
@@ -137,7 +127,7 @@ function findOptimalExport(target, info, isESM = undefined) {
|
|
|
137
127
|
const exportTypes = Object.keys(target);
|
|
138
128
|
// We prefer ESM exports for native support.
|
|
139
129
|
if (typeof isESM === 'undefined') {
|
|
140
|
-
const esmExport = exportTypes.find(
|
|
130
|
+
const esmExport = exportTypes.find(e => isESMExport(e));
|
|
141
131
|
if (esmExport) {
|
|
142
132
|
return findOptimalExport(target[esmExport], info, true);
|
|
143
133
|
}
|
|
@@ -145,12 +135,14 @@ function findOptimalExport(target, info, isESM = undefined) {
|
|
|
145
135
|
// Node.js looks at the exports object and uses the first key that matches the current environment.
|
|
146
136
|
const secondBestEntry = 'default' in target && target['default']
|
|
147
137
|
? 'default'
|
|
148
|
-
: exportTypes.filter(
|
|
138
|
+
: exportTypes.filter(e => e !== 'types')[0];
|
|
149
139
|
const secondBestExport = target[secondBestEntry];
|
|
150
|
-
return findOptimalExport(secondBestExport, info, isESM ??
|
|
140
|
+
return findOptimalExport(secondBestExport, info, isESM ?? isESMExport(secondBestEntry));
|
|
151
141
|
}
|
|
152
|
-
function _getPackageInfo(packageName, directory) {
|
|
142
|
+
export function _getPackageInfo(packageName, directory) {
|
|
153
143
|
const mainPkgName = getPkgFolder(packageName);
|
|
144
|
+
if (!mainPkgName)
|
|
145
|
+
throw new Error(`Could not resolve "${packageName}" in "${directory}`);
|
|
154
146
|
const mainPkgJsonPath = findDepPackageJson(packageName, directory);
|
|
155
147
|
if (!mainPkgJsonPath) {
|
|
156
148
|
return null;
|
|
@@ -160,15 +152,13 @@ function _getPackageInfo(packageName, directory) {
|
|
|
160
152
|
const version = mainPkgJson['version'];
|
|
161
153
|
const esm = mainPkgJson['type'] === 'module';
|
|
162
154
|
if (!version) {
|
|
163
|
-
|
|
155
|
+
logger.warn('No version found for ' + packageName);
|
|
164
156
|
return null;
|
|
165
157
|
}
|
|
166
158
|
const pathToSecondary = path.relative(mainPkgName, packageName);
|
|
167
|
-
const relSecondaryPath = !pathToSecondary
|
|
168
|
-
? '.'
|
|
169
|
-
: './' + pathToSecondary.replace(/\\/g, '/');
|
|
159
|
+
const relSecondaryPath = !pathToSecondary ? '.' : './' + pathToSecondary.replace(/\\/g, '/');
|
|
170
160
|
let secondaryEntryPoint = undefined;
|
|
171
|
-
const packageJsonExportsEntry = Object.keys(mainPkgJson?.exports ?? []).find(
|
|
161
|
+
const packageJsonExportsEntry = Object.keys(mainPkgJson?.exports ?? []).find(e => {
|
|
172
162
|
if (e === relSecondaryPath)
|
|
173
163
|
return true;
|
|
174
164
|
if (e === './*')
|
|
@@ -261,8 +251,8 @@ function _getPackageInfo(packageName, directory) {
|
|
|
261
251
|
esm,
|
|
262
252
|
};
|
|
263
253
|
}
|
|
264
|
-
|
|
265
|
-
|
|
254
|
+
logger.warn('No entry point found for ' + packageName);
|
|
255
|
+
logger.warn("If you don't need this package, skip it in your federation.config.js or consider moving it into depDependencies in your package.json");
|
|
266
256
|
return null;
|
|
267
257
|
}
|
|
268
258
|
function readJson(mainPkgJsonPath) {
|
|
@@ -276,4 +266,3 @@ function getPkgFolder(packageName) {
|
|
|
276
266
|
}
|
|
277
267
|
return folder;
|
|
278
268
|
}
|
|
279
|
-
//# sourceMappingURL=package-info.js.map
|
|
@@ -1,6 +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
|
}
|