@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
|
@@ -1,96 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const build_utils_1 = require("../utils/build-utils");
|
|
11
|
-
const logger_1 = require("../utils/logger");
|
|
12
|
-
const normalize_1 = require("../utils/normalize");
|
|
13
|
-
const errors_1 = require("../utils/errors");
|
|
14
|
-
async function bundleExposedAndMappings(config, fedOptions, externals, signal) {
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { createBuildResultMap, popFromResultMap } from '../utils/build-result-map.js';
|
|
4
|
+
import { logger } from '../utils/logger.js';
|
|
5
|
+
import { normalize } from '../utils/normalize.js';
|
|
6
|
+
import { AbortedError } from '../utils/errors.js';
|
|
7
|
+
import { rewriteChunkImports } from '../utils/rewrite-chunk-imports.js';
|
|
8
|
+
import { getBuildAdapter } from './build-adapter.js';
|
|
9
|
+
export async function bundleExposedAndMappings(config, fedOptions, externals, modifiedFiles, signal) {
|
|
15
10
|
if (signal?.aborted) {
|
|
16
|
-
throw new
|
|
11
|
+
throw new AbortedError('[bundle-exposed-and-mappings] Aborted before bundling');
|
|
17
12
|
}
|
|
18
|
-
const shared = config.sharedMappings.map((
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
const shared = Object.entries(config.sharedMappings).map(([entryPoint, mappedImport]) => {
|
|
14
|
+
return {
|
|
15
|
+
fileName: entryPoint,
|
|
16
|
+
outName: mappedImport.replace(/[^A-Za-z0-9]/g, '_') + '.js',
|
|
17
|
+
key: mappedImport,
|
|
18
|
+
};
|
|
23
19
|
});
|
|
24
|
-
const exposes = Object.
|
|
25
|
-
const entryPoint = config.exposes[key];
|
|
20
|
+
const exposes = Object.entries(config.exposes).map(([key, entry]) => {
|
|
26
21
|
const outFilePath = key + '.js';
|
|
27
|
-
return { fileName:
|
|
22
|
+
return { fileName: entry, outName: outFilePath, key };
|
|
28
23
|
});
|
|
29
24
|
const entryPoints = [...shared, ...exposes];
|
|
30
25
|
const hash = !fedOptions.dev;
|
|
31
|
-
logger_1.logger.info('Building federation artefacts');
|
|
32
26
|
let result;
|
|
33
27
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
if (!modifiedFiles) {
|
|
29
|
+
await getBuildAdapter().setup('mapping-or-exposed', {
|
|
30
|
+
entryPoints,
|
|
31
|
+
outdir: fedOptions.outputPath,
|
|
32
|
+
tsConfigPath: fedOptions.tsConfig,
|
|
33
|
+
external: externals,
|
|
34
|
+
dev: !!fedOptions.dev,
|
|
35
|
+
watch: fedOptions.watch,
|
|
36
|
+
mappedPaths: config.sharedMappings,
|
|
37
|
+
chunks: config.chunks,
|
|
38
|
+
hash,
|
|
39
|
+
optimizedMappings: config.features.ignoreUnusedDeps,
|
|
40
|
+
isMappingOrExposed: true,
|
|
41
|
+
cache: fedOptions.federationCache,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
result = await getBuildAdapter().build('mapping-or-exposed', {
|
|
45
45
|
signal,
|
|
46
|
+
modifiedFiles,
|
|
46
47
|
});
|
|
47
48
|
if (signal?.aborted) {
|
|
48
|
-
throw new
|
|
49
|
+
throw new AbortedError('[bundle-exposed-and-mappings] Aborted after bundle');
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
52
|
-
if (!(error instanceof
|
|
53
|
-
|
|
53
|
+
if (!(error instanceof AbortedError)) {
|
|
54
|
+
logger.error('Error building federation artifacts');
|
|
54
55
|
}
|
|
55
56
|
throw error;
|
|
56
57
|
}
|
|
57
|
-
const resultMap =
|
|
58
|
+
const resultMap = createBuildResultMap(result, hash);
|
|
58
59
|
const sharedResult = [];
|
|
60
|
+
const entryFiles = [];
|
|
61
|
+
// Pick shared-mappings
|
|
59
62
|
for (const item of shared) {
|
|
63
|
+
const distEntryFile = popFromResultMap(resultMap, item.outName);
|
|
60
64
|
sharedResult.push({
|
|
61
65
|
packageName: item.key,
|
|
62
|
-
outFileName:
|
|
66
|
+
outFileName: path.basename(distEntryFile),
|
|
63
67
|
requiredVersion: '',
|
|
64
68
|
singleton: true,
|
|
65
69
|
strictVersion: false,
|
|
66
|
-
version: config.features.mappingVersion
|
|
67
|
-
? getMappingVersion(item.fileName)
|
|
68
|
-
: '',
|
|
70
|
+
version: config.features.mappingVersion ? getMappingVersion(item.fileName) : '',
|
|
69
71
|
dev: !fedOptions.dev
|
|
70
72
|
? undefined
|
|
71
73
|
: {
|
|
72
|
-
entryPoint:
|
|
74
|
+
entryPoint: normalize(path.normalize(item.fileName)),
|
|
73
75
|
},
|
|
74
76
|
});
|
|
77
|
+
entryFiles.push(distEntryFile);
|
|
75
78
|
}
|
|
76
79
|
const exposedResult = [];
|
|
80
|
+
// Pick exposed-modules
|
|
77
81
|
for (const item of exposes) {
|
|
82
|
+
const distEntryFile = popFromResultMap(resultMap, item.outName);
|
|
78
83
|
exposedResult.push({
|
|
79
84
|
key: item.key,
|
|
80
|
-
outFileName:
|
|
85
|
+
outFileName: path.basename(distEntryFile),
|
|
81
86
|
dev: !fedOptions.dev
|
|
82
87
|
? undefined
|
|
83
88
|
: {
|
|
84
|
-
entryPoint:
|
|
89
|
+
entryPoint: normalize(path.join(fedOptions.workspaceRoot, item.fileName)),
|
|
85
90
|
},
|
|
86
91
|
});
|
|
92
|
+
entryFiles.push(distEntryFile);
|
|
93
|
+
}
|
|
94
|
+
// Remove .map files
|
|
95
|
+
Object.keys(resultMap)
|
|
96
|
+
.filter(f => f.endsWith('.map'))
|
|
97
|
+
.forEach(f => popFromResultMap(resultMap, f));
|
|
98
|
+
// Process remaining chunks and lazy loaded internal modules
|
|
99
|
+
let exportedChunks = undefined;
|
|
100
|
+
if (config.chunks && config.features.denseChunking) {
|
|
101
|
+
for (const entryFile of entryFiles)
|
|
102
|
+
rewriteChunkImports(entryFile);
|
|
103
|
+
exportedChunks = {
|
|
104
|
+
['mapping-or-exposed']: Object.values(resultMap).map(chunk => path.basename(chunk)),
|
|
105
|
+
};
|
|
87
106
|
}
|
|
88
|
-
return { mappings: sharedResult, exposes: exposedResult };
|
|
107
|
+
return { mappings: sharedResult, exposes: exposedResult, chunks: exportedChunks };
|
|
89
108
|
}
|
|
90
|
-
function describeExposed(config, options) {
|
|
109
|
+
export function describeExposed(config, options) {
|
|
91
110
|
const result = [];
|
|
92
111
|
for (const key in config.exposes) {
|
|
93
|
-
const localPath =
|
|
112
|
+
const localPath = normalize(path.normalize(path.join(options.workspaceRoot, config.exposes[key])));
|
|
94
113
|
result.push({
|
|
95
114
|
key,
|
|
96
115
|
outFileName: '',
|
|
@@ -103,34 +122,33 @@ function describeExposed(config, options) {
|
|
|
103
122
|
}
|
|
104
123
|
return result;
|
|
105
124
|
}
|
|
106
|
-
function describeSharedMappings(config, fedOptions) {
|
|
125
|
+
export function describeSharedMappings(config, fedOptions) {
|
|
107
126
|
const result = [];
|
|
108
|
-
for (const
|
|
127
|
+
for (const [mappedPath, mappedImport] of Object.entries(config.sharedMappings)) {
|
|
109
128
|
result.push({
|
|
110
|
-
packageName:
|
|
129
|
+
packageName: mappedImport,
|
|
111
130
|
outFileName: '',
|
|
112
131
|
requiredVersion: '',
|
|
113
132
|
singleton: true,
|
|
114
133
|
strictVersion: false,
|
|
115
|
-
version: config.features.mappingVersion ? getMappingVersion(
|
|
134
|
+
version: config.features.mappingVersion ? getMappingVersion(mappedPath) : '',
|
|
116
135
|
dev: !fedOptions.dev
|
|
117
136
|
? undefined
|
|
118
137
|
: {
|
|
119
|
-
entryPoint:
|
|
138
|
+
entryPoint: normalize(path.normalize(mappedPath)),
|
|
120
139
|
},
|
|
121
140
|
});
|
|
122
141
|
}
|
|
123
142
|
return result;
|
|
124
143
|
}
|
|
125
144
|
function getMappingVersion(fileName) {
|
|
126
|
-
const entryFileDir =
|
|
127
|
-
const cand1 =
|
|
128
|
-
const cand2 =
|
|
129
|
-
const packageJsonPath = [cand1, cand2].find(
|
|
145
|
+
const entryFileDir = path.dirname(fileName);
|
|
146
|
+
const cand1 = path.join(entryFileDir, 'package.json');
|
|
147
|
+
const cand2 = path.join(path.dirname(entryFileDir), 'package.json');
|
|
148
|
+
const packageJsonPath = [cand1, cand2].find(cand => fs.existsSync(cand));
|
|
130
149
|
if (packageJsonPath) {
|
|
131
|
-
const json = JSON.parse(
|
|
150
|
+
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
132
151
|
return json.version ?? '';
|
|
133
152
|
}
|
|
134
153
|
return '';
|
|
135
154
|
}
|
|
136
|
-
//# sourceMappingURL=bundle-exposed-and-mappings.js.map
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { NormalizedFederationConfig
|
|
2
|
-
import { SharedInfo } from '
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
2
|
+
import type { SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
3
|
+
import { type NormalizedFederationOptions } from '../domain/core/federation-options.contract.js';
|
|
4
|
+
import type { NormalizedExternalConfig } from '../domain/config/external-config.contract.js';
|
|
5
|
+
export declare function bundleShared(sharedBundles: Record<string, NormalizedExternalConfig>, config: NormalizedFederationConfig, fedOptions: NormalizedFederationOptions, externals: string[], buildOptions: {
|
|
6
|
+
platform: 'browser' | 'node';
|
|
6
7
|
bundleName: string;
|
|
7
|
-
|
|
8
|
+
chunks: boolean;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
externals: SharedInfo[];
|
|
11
|
+
chunks?: Record<string, string[]>;
|
|
12
|
+
}>;
|
|
@@ -1,135 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
async function bundleShared(sharedBundles, config, fedOptions, externals, platform = 'browser', cacheOptions) {
|
|
15
|
-
const checksum = (0, bundle_caching_1.getChecksum)(sharedBundles, fedOptions.dev ? '1' : '0');
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { getPackageInfo } from '../utils/package-info.js';
|
|
4
|
+
import { logger } from '../utils/logger.js';
|
|
5
|
+
import crypto from 'crypto';
|
|
6
|
+
import { DEFAULT_EXTERNAL_LIST } from './default-external-list.js';
|
|
7
|
+
import { isSourceFile, rewriteChunkImports } from '../utils/rewrite-chunk-imports.js';
|
|
8
|
+
import { toChunkImport } from '../domain/core/chunk.js';
|
|
9
|
+
import { cacheEntry, getChecksum, getFilename } from '../utils/cache-persistence.js';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
import { getBuildAdapter } from './build-adapter.js';
|
|
12
|
+
export async function bundleShared(sharedBundles, config, fedOptions, externals, buildOptions) {
|
|
13
|
+
const checksum = getChecksum(sharedBundles, fedOptions.dev ? '1' : '0');
|
|
16
14
|
const folder = fedOptions.packageJson
|
|
17
15
|
? path.dirname(fedOptions.packageJson)
|
|
18
16
|
: fedOptions.workspaceRoot;
|
|
19
|
-
const bundleCache =
|
|
17
|
+
const bundleCache = cacheEntry(fedOptions.federationCache.cachePath, getFilename(buildOptions.bundleName, fedOptions.dev));
|
|
20
18
|
if (fedOptions?.cacheExternalArtifacts) {
|
|
21
19
|
const cacheMetadata = bundleCache.getMetadata(checksum);
|
|
22
20
|
if (cacheMetadata) {
|
|
23
|
-
|
|
21
|
+
logger.debug(`Checksum of ${buildOptions.bundleName} matched, Skipped artifact bundling`);
|
|
24
22
|
bundleCache.copyFiles(path.join(fedOptions.workspaceRoot, fedOptions.outputPath));
|
|
25
|
-
return cacheMetadata.externals;
|
|
23
|
+
return { externals: cacheMetadata.externals, chunks: cacheMetadata.chunks };
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
bundleCache.clear();
|
|
29
27
|
const inferredPackageInfos = Object.keys(sharedBundles)
|
|
30
|
-
.filter(
|
|
31
|
-
.map(
|
|
32
|
-
.filter(
|
|
28
|
+
.filter(packageName => !sharedBundles[packageName]?.packageInfo)
|
|
29
|
+
.map(packageName => getPackageInfo(packageName, folder))
|
|
30
|
+
.filter(pi => !!pi);
|
|
33
31
|
const configuredPackageInfos = Object.keys(sharedBundles)
|
|
34
|
-
.filter(
|
|
35
|
-
.map(
|
|
32
|
+
.filter(packageName => !!sharedBundles[packageName]?.packageInfo)
|
|
33
|
+
.map(packageName => ({
|
|
36
34
|
packageName,
|
|
37
|
-
...sharedBundles[packageName]
|
|
35
|
+
...sharedBundles[packageName]?.packageInfo,
|
|
38
36
|
}));
|
|
39
37
|
const packageInfos = [...inferredPackageInfos, ...configuredPackageInfos];
|
|
38
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
40
39
|
const configState = 'BUNDLER_CHUNKS' + // TODO: Replace this with lib version
|
|
41
|
-
fs.readFileSync(path.join(
|
|
40
|
+
fs.readFileSync(path.join(path.dirname(__filename), '../../../package.json')) +
|
|
42
41
|
JSON.stringify(config);
|
|
43
|
-
const allEntryPoints = packageInfos.map(
|
|
42
|
+
const allEntryPoints = packageInfos.map(pi => {
|
|
44
43
|
const encName = pi.packageName.replace(/[^A-Za-z0-9]/g, '_');
|
|
45
44
|
const outName = createOutName(pi, configState, fedOptions, encName);
|
|
46
45
|
return { fileName: pi.entryPoint, outName };
|
|
47
46
|
});
|
|
48
47
|
const fullOutputPath = path.join(fedOptions.workspaceRoot, fedOptions.outputPath);
|
|
49
|
-
const expectedResults = allEntryPoints.map(
|
|
50
|
-
const entryPoints = allEntryPoints.filter(
|
|
48
|
+
const expectedResults = allEntryPoints.map(ep => path.join(fullOutputPath, ep.outName));
|
|
49
|
+
const entryPoints = allEntryPoints.filter(ep => !fs.existsSync(path.join(fedOptions.federationCache.cachePath, ep.outName)));
|
|
51
50
|
// If we build for the browser and don't remote unused deps from the shared config,
|
|
52
51
|
// we need to exclude typical node libs to avoid compilation issues
|
|
53
|
-
const useDefaultExternalList = platform === 'browser' && !config.features.ignoreUnusedDeps;
|
|
54
|
-
const additionalExternals = useDefaultExternalList
|
|
55
|
-
? default_external_list_1.DEFAULT_EXTERNAL_LIST
|
|
56
|
-
: [];
|
|
52
|
+
const useDefaultExternalList = buildOptions.platform === 'browser' && !config.features.ignoreUnusedDeps;
|
|
53
|
+
const additionalExternals = useDefaultExternalList ? DEFAULT_EXTERNAL_LIST : [];
|
|
57
54
|
let bundleResult = null;
|
|
58
55
|
try {
|
|
59
|
-
|
|
56
|
+
await getBuildAdapter().setup(buildOptions.bundleName, {
|
|
60
57
|
entryPoints,
|
|
61
58
|
tsConfigPath: fedOptions.tsConfig,
|
|
62
59
|
external: [...additionalExternals, ...externals],
|
|
63
|
-
outdir:
|
|
60
|
+
outdir: fedOptions.federationCache.cachePath,
|
|
64
61
|
mappedPaths: config.sharedMappings,
|
|
65
62
|
dev: fedOptions.dev,
|
|
66
|
-
|
|
63
|
+
isMappingOrExposed: false,
|
|
67
64
|
hash: false,
|
|
68
|
-
|
|
65
|
+
chunks: buildOptions.chunks,
|
|
66
|
+
platform: buildOptions.platform,
|
|
69
67
|
optimizedMappings: config.features.ignoreUnusedDeps,
|
|
68
|
+
cache: fedOptions.federationCache,
|
|
70
69
|
});
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
bundleResult = await getBuildAdapter().build(buildOptions.bundleName);
|
|
71
|
+
await getBuildAdapter().dispose(buildOptions.bundleName);
|
|
72
|
+
const cachedFiles = bundleResult.map(br => path.basename(br.fileName));
|
|
73
|
+
rewriteImports(cachedFiles, fedOptions.federationCache.cachePath);
|
|
73
74
|
}
|
|
74
75
|
catch (e) {
|
|
75
|
-
|
|
76
|
+
logger.error('Error bundling shared npm package ');
|
|
76
77
|
if (e instanceof Error) {
|
|
77
|
-
|
|
78
|
+
logger.error(e.message);
|
|
78
79
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
logger.error('For more information, run in verbose mode');
|
|
81
|
+
logger.notice('');
|
|
82
|
+
logger.notice('');
|
|
83
|
+
logger.notice('** Important Information: ***');
|
|
84
|
+
logger.notice('The error message above shows an issue with bundling a node_module.');
|
|
85
|
+
logger.notice('In most cases this is because you (indirectly) shared a Node.js package,');
|
|
86
|
+
logger.notice('while Native Federation builds for the browser.');
|
|
87
|
+
logger.notice('You can move such packages into devDependencies or skip them in your federation.config.js.');
|
|
88
|
+
logger.notice('');
|
|
89
|
+
logger.notice('More Details: https://bit.ly/nf-issue');
|
|
90
|
+
logger.notice('');
|
|
91
|
+
logger.notice('');
|
|
92
|
+
logger.verbose(e);
|
|
92
93
|
throw e;
|
|
93
94
|
}
|
|
94
95
|
const outFileNames = [...expectedResults];
|
|
95
96
|
const result = buildResult(packageInfos, sharedBundles, outFileNames);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
const chunks = bundleResult.filter(br => !br.fileName.endsWith('.map') &&
|
|
98
|
+
!result.find(r => r.outFileName === path.basename(br.fileName)));
|
|
99
|
+
/**
|
|
100
|
+
* Chunking
|
|
101
|
+
*/
|
|
102
|
+
let exportedChunks = undefined;
|
|
103
|
+
if (buildOptions.chunks && config.features.denseChunking) {
|
|
104
|
+
result.forEach(external => {
|
|
105
|
+
external.bundle = buildOptions.bundleName;
|
|
106
|
+
});
|
|
107
|
+
if (chunks.length > 0) {
|
|
108
|
+
exportedChunks = { [buildOptions.bundleName]: getChunkFileNames(chunks) };
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
addChunksToResult(chunks, result);
|
|
113
|
+
}
|
|
100
114
|
bundleCache.persist({
|
|
101
115
|
checksum,
|
|
102
116
|
externals: result,
|
|
103
|
-
files: bundleResult.map(
|
|
117
|
+
files: bundleResult.map(r => r.fileName.split(path.sep).pop() ?? r.fileName),
|
|
118
|
+
chunks: exportedChunks,
|
|
104
119
|
});
|
|
105
120
|
bundleCache.copyFiles(path.join(fedOptions.workspaceRoot, fedOptions.outputPath));
|
|
106
|
-
return result;
|
|
121
|
+
return { externals: result, chunks: exportedChunks };
|
|
107
122
|
}
|
|
108
123
|
function rewriteImports(cachedFiles, cachePath) {
|
|
109
|
-
const newSourceFiles = cachedFiles.filter(
|
|
124
|
+
const newSourceFiles = cachedFiles.filter(cf => isSourceFile(cf));
|
|
110
125
|
for (const sourceFile of newSourceFiles) {
|
|
111
126
|
const sourceFilePath = path.join(cachePath, sourceFile);
|
|
112
|
-
|
|
127
|
+
rewriteChunkImports(sourceFilePath);
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
130
|
function createOutName(pi, configState, fedOptions, encName) {
|
|
116
131
|
const hashBase = pi.version + '_' + pi.entryPoint + '_' + configState;
|
|
117
132
|
const hash = calcHash(hashBase);
|
|
118
|
-
const outName = fedOptions.dev
|
|
119
|
-
? `${encName}.${hash}-dev.js`
|
|
120
|
-
: `${encName}.${hash}.js`;
|
|
133
|
+
const outName = fedOptions.dev ? `${encName}.${hash}-dev.js` : `${encName}.${hash}.js`;
|
|
121
134
|
return outName;
|
|
122
135
|
}
|
|
123
136
|
function buildResult(packageInfos, sharedBundles, outFileNames) {
|
|
124
|
-
return packageInfos.map(
|
|
137
|
+
return packageInfos.map(pi => {
|
|
125
138
|
const shared = sharedBundles[pi.packageName];
|
|
126
139
|
return {
|
|
127
140
|
packageName: pi.packageName,
|
|
128
141
|
outFileName: path.basename(outFileNames.shift() || ''),
|
|
129
|
-
requiredVersion: shared
|
|
130
|
-
singleton: shared
|
|
131
|
-
strictVersion: shared
|
|
142
|
+
requiredVersion: shared?.requiredVersion,
|
|
143
|
+
singleton: shared?.singleton,
|
|
144
|
+
strictVersion: shared?.strictVersion,
|
|
132
145
|
version: pi.version,
|
|
146
|
+
...(shared?.shareScope && { shareScope: shared.shareScope }),
|
|
133
147
|
// TODO: Decide whether/when we need debug infos
|
|
134
148
|
// dev: !fedOptions.dev
|
|
135
149
|
// ? undefined
|
|
@@ -139,7 +153,10 @@ function buildResult(packageInfos, sharedBundles, outFileNames) {
|
|
|
139
153
|
};
|
|
140
154
|
});
|
|
141
155
|
}
|
|
142
|
-
function
|
|
156
|
+
function getChunkFileNames(chunks) {
|
|
157
|
+
return chunks.map(chunk => path.basename(chunk.fileName));
|
|
158
|
+
}
|
|
159
|
+
function addChunksToResult(chunks, result) {
|
|
143
160
|
for (const item of chunks) {
|
|
144
161
|
const fileName = path.basename(item.fileName);
|
|
145
162
|
result.push({
|
|
@@ -155,7 +172,7 @@ function addChunksToResult(chunks, result, dev) {
|
|
|
155
172
|
// take care of singleton and strictVersion.
|
|
156
173
|
version: '0.0.0',
|
|
157
174
|
requiredVersion: '0.0.0',
|
|
158
|
-
packageName: (
|
|
175
|
+
packageName: toChunkImport(fileName),
|
|
159
176
|
outFileName: fileName,
|
|
160
177
|
// dev: dev
|
|
161
178
|
// ? undefined
|
|
@@ -166,7 +183,7 @@ function addChunksToResult(chunks, result, dev) {
|
|
|
166
183
|
}
|
|
167
184
|
}
|
|
168
185
|
function calcHash(hashBase) {
|
|
169
|
-
const hash =
|
|
186
|
+
const hash = crypto
|
|
170
187
|
.createHash('sha256')
|
|
171
188
|
.update(hashBase)
|
|
172
189
|
.digest('base64')
|
|
@@ -176,4 +193,3 @@ function calcHash(hashBase) {
|
|
|
176
193
|
.substring(0, 10);
|
|
177
194
|
return hash;
|
|
178
195
|
}
|
|
179
|
-
//# sourceMappingURL=bundle-shared.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_EXTERNAL_LIST = void 0;
|
|
4
1
|
const NODE_PACKAGES = [
|
|
5
2
|
'assert',
|
|
6
3
|
'buffer',
|
|
@@ -29,8 +26,4 @@ const NODE_PACKAGES = [
|
|
|
29
26
|
'vm',
|
|
30
27
|
'zlib',
|
|
31
28
|
];
|
|
32
|
-
|
|
33
|
-
p,
|
|
34
|
-
'node:' + p,
|
|
35
|
-
]);
|
|
36
|
-
//# sourceMappingURL=default-external-list.js.map
|
|
29
|
+
export const DEFAULT_EXTERNAL_LIST = NODE_PACKAGES.flatMap(p => [p, 'node:' + p]);
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import { FederationInfo } from '
|
|
2
|
-
import { NormalizedFederationConfig } from '../config/federation-config';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { FederationInfo } from '../domain/core/federation-info.contract.js';
|
|
2
|
+
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
3
|
+
import { type FederationOptions } from '../domain/core/federation-options.contract.js';
|
|
4
|
+
import type { NFBuildAdapter } from '../domain/core/build-adapter.contract.js';
|
|
5
5
|
export interface BuildHelperParams {
|
|
6
6
|
options: FederationOptions;
|
|
7
|
-
adapter:
|
|
7
|
+
adapter: NFBuildAdapter;
|
|
8
8
|
}
|
|
9
9
|
declare function init(params: BuildHelperParams): Promise<void>;
|
|
10
|
-
declare function build(
|
|
10
|
+
declare function build(opts?: {
|
|
11
|
+
modifiedFiles?: string[];
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
declare function close(): Promise<void>;
|
|
11
15
|
export declare const federationBuilder: {
|
|
12
16
|
init: typeof init;
|
|
13
17
|
build: typeof build;
|
|
18
|
+
close: typeof close;
|
|
14
19
|
readonly federationInfo: FederationInfo;
|
|
15
20
|
readonly externals: string[];
|
|
16
21
|
readonly config: NormalizedFederationConfig;
|
|
@@ -1,31 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const get_externals_1 = require("./get-externals");
|
|
8
|
-
const load_federation_config_1 = require("./load-federation-config");
|
|
1
|
+
import { getConfigContext, usePackageJson, useWorkspace } from '../config/configuration-context.js';
|
|
2
|
+
import { getBuildAdapter, setBuildAdapter } from './build-adapter.js';
|
|
3
|
+
import { buildForFederation } from './build-for-federation.js';
|
|
4
|
+
import { getExternals } from './get-externals.js';
|
|
5
|
+
import { normalizeFederationOptions } from './normalize-options.js';
|
|
6
|
+
import { rebuildForFederation } from './rebuild-for-federation.js';
|
|
9
7
|
let externals = [];
|
|
10
8
|
let config;
|
|
11
|
-
let
|
|
9
|
+
let options;
|
|
12
10
|
let fedInfo;
|
|
13
11
|
async function init(params) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
externals =
|
|
12
|
+
setBuildAdapter(params.adapter);
|
|
13
|
+
useWorkspace(params.options.workspaceRoot);
|
|
14
|
+
usePackageJson(params.options.packageJson);
|
|
15
|
+
params.options.workspaceRoot = getConfigContext().workspaceRoot ?? params.options.workspaceRoot;
|
|
16
|
+
const normalized = await normalizeFederationOptions(params.options);
|
|
17
|
+
options = normalized.options;
|
|
18
|
+
config = normalized.config;
|
|
19
|
+
externals = getExternals(config);
|
|
22
20
|
}
|
|
23
|
-
async function build(
|
|
24
|
-
|
|
21
|
+
async function build(opts = {}) {
|
|
22
|
+
if (!fedInfo) {
|
|
23
|
+
fedInfo = await buildForFederation(config, options, externals, opts.signal);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
fedInfo = await rebuildForFederation(config, options, externals, opts.modifiedFiles ?? [], opts.signal);
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
async function close() {
|
|
30
|
+
return getBuildAdapter().dispose();
|
|
31
|
+
}
|
|
32
|
+
export const federationBuilder = {
|
|
27
33
|
init,
|
|
28
34
|
build,
|
|
35
|
+
close,
|
|
29
36
|
get federationInfo() {
|
|
30
37
|
return fedInfo;
|
|
31
38
|
},
|
|
@@ -36,4 +43,3 @@ exports.federationBuilder = {
|
|
|
36
43
|
return config;
|
|
37
44
|
},
|
|
38
45
|
};
|
|
39
|
-
//# sourceMappingURL=federation-builder.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FederationCache } from '../domain/core/federation-cache.contract.js';
|
|
2
|
+
import type { ChunkInfo, SharedInfo } from '../domain/core/federation-info.contract.js';
|
|
3
|
+
export declare function createFederationCache(cachePath: string): FederationCache<undefined>;
|
|
4
|
+
export declare function createFederationCache<TBundlerCache>(cachePath: string, bundlerCache: TBundlerCache): FederationCache<TBundlerCache>;
|
|
5
|
+
export declare function addExternalsToCache(cache: FederationCache, { externals, chunks }: {
|
|
6
|
+
externals: SharedInfo[];
|
|
7
|
+
chunks?: ChunkInfo;
|
|
8
|
+
}): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function createFederationCache(cachePath, bundlerCache) {
|
|
2
|
+
return { externals: [], cachePath, bundlerCache };
|
|
3
|
+
}
|
|
4
|
+
export function addExternalsToCache(cache, { externals, chunks }) {
|
|
5
|
+
cache.externals.push(...externals);
|
|
6
|
+
if (chunks) {
|
|
7
|
+
if (!cache.chunks)
|
|
8
|
+
cache.chunks = {};
|
|
9
|
+
cache.chunks = { ...cache.chunks, ...chunks };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { NormalizedFederationConfig } from '../config/federation-config';
|
|
1
|
+
import type { NormalizedFederationConfig } from '../domain/config/federation-config.contract.js';
|
|
2
2
|
export declare function getExternals(config: NormalizedFederationConfig): string[];
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getExternals = getExternals;
|
|
4
|
-
function getExternals(config) {
|
|
1
|
+
export function getExternals(config) {
|
|
5
2
|
const shared = Object.keys(config.shared);
|
|
6
|
-
const sharedMappings = config.sharedMappings
|
|
3
|
+
const sharedMappings = Object.values(config.sharedMappings);
|
|
7
4
|
const externals = [...shared, ...sharedMappings, ...config.externals];
|
|
8
5
|
return externals;
|
|
9
6
|
}
|
|
10
|
-
//# sourceMappingURL=get-externals.js.map
|