@module-federation/metro 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703
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/babel-plugin/patch-initialize-core.js +3 -3
- package/babel-plugin/patch-require.js +3 -3
- package/dist/babel/transformer.js +1 -1
- package/dist/commands/bundle-host/index.js +17 -12
- package/dist/commands/bundle-host/index.mjs +8 -30
- package/dist/commands/bundle-host/options.js +12 -8
- package/dist/commands/bundle-host/options.mjs +2 -3
- package/dist/commands/bundle-host/types.js +2 -2
- package/dist/commands/bundle-host/types.mjs +1 -2
- package/dist/commands/bundle-remote/index.js +34 -19
- package/dist/commands/bundle-remote/index.mjs +28 -38
- package/dist/commands/bundle-remote/options.js +15 -11
- package/dist/commands/bundle-remote/options.mjs +4 -5
- package/dist/commands/bundle-remote/types.js +2 -2
- package/dist/commands/bundle-remote/types.mjs +1 -2
- package/dist/commands/index.js +14 -10
- package/dist/commands/index.mjs +3 -3
- package/dist/commands/types.js +2 -2
- package/dist/commands/types.mjs +1 -2
- package/dist/commands/utils/create-module-path-remapper.js +15 -11
- package/dist/commands/utils/create-module-path-remapper.mjs +1 -2
- package/dist/commands/utils/create-resolver.d.ts +1 -1
- package/dist/commands/utils/create-resolver.js +15 -11
- package/dist/commands/utils/create-resolver.mjs +1 -2
- package/dist/commands/utils/get-community-plugin.d.ts +1 -2
- package/dist/commands/utils/get-community-plugin.js +15 -12
- package/dist/commands/utils/get-community-plugin.mjs +5 -6
- package/dist/commands/utils/load-metro-config.js +15 -14
- package/dist/commands/utils/load-metro-config.mjs +9 -11
- package/dist/commands/utils/path-utils.d.ts +2 -0
- package/dist/commands/utils/path-utils.js +51 -0
- package/dist/commands/utils/path-utils.mjs +11 -0
- package/dist/commands/utils/save-bundle-and-map.d.ts +1 -1
- package/dist/commands/utils/save-bundle-and-map.js +14 -11
- package/dist/commands/utils/save-bundle-and-map.mjs +3 -27
- package/dist/index.js +14 -10
- package/dist/index.mjs +3 -5
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +43 -0
- package/dist/logger.mjs +6 -0
- package/dist/modules/asyncRequire.ts +41 -10
- package/dist/modules/metroCorePlugin.ts +2 -3
- package/dist/plugin/babel-transformer.js +13 -9
- package/dist/plugin/babel-transformer.mjs +3 -3
- package/dist/plugin/constants.d.ts +1 -0
- package/dist/plugin/constants.js +27 -19
- package/dist/plugin/constants.mjs +3 -3
- package/dist/plugin/generators.js +28 -21
- package/dist/plugin/generators.mjs +14 -11
- package/dist/plugin/helpers.d.ts +1 -0
- package/dist/plugin/helpers.js +28 -20
- package/dist/plugin/helpers.mjs +9 -9
- package/dist/plugin/index.d.ts +2 -0
- package/dist/plugin/index.js +64 -13
- package/dist/plugin/index.mjs +54 -7
- package/dist/plugin/manifest-middleware.d.ts +12 -0
- package/dist/plugin/manifest-middleware.js +217 -0
- package/dist/plugin/manifest-middleware.mjs +170 -0
- package/dist/plugin/manifest.d.ts +15 -2
- package/dist/plugin/manifest.js +126 -26
- package/dist/plugin/manifest.mjs +107 -22
- package/dist/plugin/normalize-extra-options.js +16 -12
- package/dist/plugin/normalize-extra-options.mjs +2 -3
- package/dist/plugin/normalize-options.js +70 -20
- package/dist/plugin/normalize-options.mjs +60 -14
- package/dist/plugin/resolver.d.ts +1 -1
- package/dist/plugin/resolver.js +16 -12
- package/dist/plugin/resolver.mjs +10 -11
- package/dist/plugin/rewrite-request.d.ts +5 -1
- package/dist/plugin/rewrite-request.js +23 -10
- package/dist/plugin/rewrite-request.mjs +13 -5
- package/dist/plugin/serializer.d.ts +2 -1
- package/dist/plugin/serializer.js +59 -39
- package/dist/plugin/serializer.mjs +48 -55
- package/dist/plugin/validate-options.js +116 -12
- package/dist/plugin/validate-options.mjs +95 -7
- package/dist/types.d.ts +15 -15
- package/dist/types.js +2 -2
- package/dist/types.mjs +1 -2
- package/dist/utils/errors.js +16 -12
- package/dist/utils/errors.mjs +1 -2
- package/dist/utils/federated-remote-types.d.ts +12 -0
- package/dist/utils/federated-remote-types.js +140 -0
- package/dist/utils/federated-remote-types.mjs +90 -0
- package/dist/utils/index.js +14 -10
- package/dist/utils/index.mjs +3 -5
- package/dist/utils/metro-compat.d.ts +23 -0
- package/dist/utils/metro-compat.js +74 -0
- package/dist/utils/metro-compat.mjs +26 -0
- package/dist/utils/vm-manager.d.ts +1 -1
- package/dist/utils/vm-manager.js +14 -12
- package/dist/utils/vm-manager.mjs +3 -6
- package/package.json +22 -7
- package/dist/babel/transformer.d.ts +0 -2
- package/dist/runtime/host-entry.d.ts +0 -1
- package/dist/runtime/init-host.d.ts +0 -1
- package/dist/runtime/remote-entry.d.ts +0 -1
- package/dist/runtime/remote-hmr.d.ts +0 -1
- package/dist/runtime/remote-module-registry.d.ts +0 -7
- package/dist/runtime/remote-module.d.ts +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { promises } from "node:fs";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { Server } from "../utils/metro-compat.mjs";
|
|
5
|
+
import { MANIFEST_FILENAME } from "./constants.mjs";
|
|
6
|
+
import { getRemoteEntryModule, getRemoteModule } from "./generators.mjs";
|
|
7
|
+
import { removeExtension, replaceExtension, toPosixPath } from "./helpers.mjs";
|
|
8
|
+
import { getSharedVirtualModulePath } from "./manifest.mjs";
|
|
9
|
+
function createManifestMiddleware({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath, vmManager }) {
|
|
10
|
+
const warmups = new Map();
|
|
11
|
+
return (middleware, metroServer)=>{
|
|
12
|
+
const nextMiddleware = middleware;
|
|
13
|
+
return async (req, res, next)=>{
|
|
14
|
+
try {
|
|
15
|
+
const warmupOptions = getManifestWarmupOptions(req.url);
|
|
16
|
+
if (warmupOptions) {
|
|
17
|
+
const warmupKey = JSON.stringify(warmupOptions);
|
|
18
|
+
let warmup = warmups.get(warmupKey);
|
|
19
|
+
if (!warmup) {
|
|
20
|
+
warmup = warmManifestBundles(metroServer, {
|
|
21
|
+
federationConfig,
|
|
22
|
+
host: req.headers.host,
|
|
23
|
+
projectRoot,
|
|
24
|
+
remoteEntryPath,
|
|
25
|
+
tmpDirPath,
|
|
26
|
+
vmManager,
|
|
27
|
+
warmupOptions
|
|
28
|
+
}).finally(()=>{
|
|
29
|
+
warmups.delete(warmupKey);
|
|
30
|
+
});
|
|
31
|
+
warmups.set(warmupKey, warmup);
|
|
32
|
+
}
|
|
33
|
+
await warmup;
|
|
34
|
+
}
|
|
35
|
+
return nextMiddleware(req, res, next);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
next(error instanceof Error ? error : new Error(String(error)));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getManifestWarmupOptions(rawUrl) {
|
|
43
|
+
const parsedUrl = new URL(rawUrl ?? '/', 'http://localhost');
|
|
44
|
+
if (parsedUrl.pathname !== `/${MANIFEST_FILENAME}`) return null;
|
|
45
|
+
const platform = parsedUrl.searchParams.get('platform');
|
|
46
|
+
if (!platform) return null;
|
|
47
|
+
return {
|
|
48
|
+
dev: getBoolean(parsedUrl.searchParams, 'dev', true),
|
|
49
|
+
excludeSource: getBoolean(parsedUrl.searchParams, 'excludeSource', false),
|
|
50
|
+
minify: getBoolean(parsedUrl.searchParams, 'minify', false),
|
|
51
|
+
platform,
|
|
52
|
+
sourcePaths: parsedUrl.searchParams.get('sourcePaths') ?? void 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async function warmManifestBundles(metroServer, { federationConfig, host, projectRoot, remoteEntryPath, tmpDirPath, vmManager, warmupOptions }) {
|
|
56
|
+
for (const request of getBundleWarmupRequests({
|
|
57
|
+
federationConfig,
|
|
58
|
+
projectRoot,
|
|
59
|
+
remoteEntryPath,
|
|
60
|
+
tmpDirPath,
|
|
61
|
+
vmManager
|
|
62
|
+
})){
|
|
63
|
+
if (request.virtualModule) await ensureVirtualModuleReady(request.virtualModule, vmManager);
|
|
64
|
+
await metroServer.build(getBundleOptions(request, host, warmupOptions));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function getBundleWarmupRequests({ federationConfig, projectRoot, remoteEntryPath, tmpDirPath }) {
|
|
68
|
+
const relativeTmpDirPath = toPosixPath(node_path.relative(projectRoot, tmpDirPath));
|
|
69
|
+
const remoteEntryName = removeExtension(node_path.basename(remoteEntryPath));
|
|
70
|
+
const relativeRemoteEntryPath = toPosixPath(node_path.relative(projectRoot, remoteEntryPath));
|
|
71
|
+
const requests = [
|
|
72
|
+
{
|
|
73
|
+
bundlePath: `${relativeTmpDirPath}/${remoteEntryName}.bundle`,
|
|
74
|
+
entryFile: `./${relativeRemoteEntryPath}`,
|
|
75
|
+
isContainer: true,
|
|
76
|
+
virtualModule: {
|
|
77
|
+
filePath: remoteEntryPath,
|
|
78
|
+
getCode: ()=>getRemoteEntryModule(federationConfig, {
|
|
79
|
+
projectDir: projectRoot,
|
|
80
|
+
tmpDir: tmpDirPath
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
for (const exposePath of Object.values(federationConfig.exposes)){
|
|
86
|
+
const bundlePath = getBundlePathForSource(exposePath);
|
|
87
|
+
requests.push({
|
|
88
|
+
bundlePath,
|
|
89
|
+
entryFile: normalizeEntryFile(exposePath),
|
|
90
|
+
isContainer: false
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
for (const [sharedName, sharedConfig] of Object.entries(federationConfig.shared)){
|
|
94
|
+
if (sharedConfig.eager || false === sharedConfig.import) continue;
|
|
95
|
+
const sharedVirtualModulePath = getSharedVirtualModulePath(tmpDirPath, sharedName);
|
|
96
|
+
const relativeSharedVirtualModulePath = toPosixPath(node_path.relative(projectRoot, sharedVirtualModulePath));
|
|
97
|
+
const sharedImportName = getSharedImportName(sharedName, sharedConfig);
|
|
98
|
+
requests.push({
|
|
99
|
+
bundlePath: replaceExtension(relativeSharedVirtualModulePath, '.bundle'),
|
|
100
|
+
entryFile: normalizeEntryFile(relativeSharedVirtualModulePath),
|
|
101
|
+
isContainer: false,
|
|
102
|
+
virtualModule: {
|
|
103
|
+
filePath: sharedVirtualModulePath,
|
|
104
|
+
getCode: ()=>getRemoteModule(sharedImportName)
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return requests;
|
|
109
|
+
}
|
|
110
|
+
async function ensureVirtualModuleReady(virtualModule, vmManager) {
|
|
111
|
+
const code = virtualModule.getCode();
|
|
112
|
+
await promises.mkdir(node_path.dirname(virtualModule.filePath), {
|
|
113
|
+
recursive: true
|
|
114
|
+
});
|
|
115
|
+
await promises.writeFile(virtualModule.filePath, code, 'utf-8');
|
|
116
|
+
vmManager.registerVirtualModule(virtualModule.filePath, ()=>code);
|
|
117
|
+
}
|
|
118
|
+
function getBundleOptions(request, host, warmupOptions) {
|
|
119
|
+
const query = getBundleQuery(warmupOptions, request.isContainer);
|
|
120
|
+
const sourceUrl = getSourceUrl(host, request.bundlePath, query);
|
|
121
|
+
const bundleOptions = {
|
|
122
|
+
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
123
|
+
dev: warmupOptions.dev,
|
|
124
|
+
entryFile: request.entryFile,
|
|
125
|
+
excludeSource: warmupOptions.excludeSource,
|
|
126
|
+
lazy: true,
|
|
127
|
+
minify: warmupOptions.minify,
|
|
128
|
+
modulesOnly: !request.isContainer,
|
|
129
|
+
platform: warmupOptions.platform,
|
|
130
|
+
runModule: request.isContainer,
|
|
131
|
+
sourceMapUrl: sourceUrl.replace(/\.bundle(\?)/, '.map$1'),
|
|
132
|
+
sourceUrl
|
|
133
|
+
};
|
|
134
|
+
if (warmupOptions.sourcePaths) bundleOptions.sourcePaths = warmupOptions.sourcePaths;
|
|
135
|
+
return bundleOptions;
|
|
136
|
+
}
|
|
137
|
+
function getBundleQuery(warmupOptions, isContainer) {
|
|
138
|
+
const query = new URLSearchParams();
|
|
139
|
+
query.set('platform', warmupOptions.platform);
|
|
140
|
+
query.set('dev', String(warmupOptions.dev));
|
|
141
|
+
query.set('lazy', 'true');
|
|
142
|
+
query.set('minify', String(warmupOptions.minify));
|
|
143
|
+
query.set('runModule', String(isContainer));
|
|
144
|
+
query.set('modulesOnly', String(!isContainer));
|
|
145
|
+
if (warmupOptions.excludeSource) query.set('excludeSource', 'true');
|
|
146
|
+
if (warmupOptions.sourcePaths) query.set('sourcePaths', warmupOptions.sourcePaths);
|
|
147
|
+
return query;
|
|
148
|
+
}
|
|
149
|
+
function getSourceUrl(host, bundlePath, query) {
|
|
150
|
+
const normalizedBundlePath = bundlePath.startsWith('/') ? bundlePath : `/${bundlePath}`;
|
|
151
|
+
return `http://${host ?? 'localhost'}${normalizedBundlePath}?${query.toString()}`;
|
|
152
|
+
}
|
|
153
|
+
function getBundlePathForSource(sourcePath) {
|
|
154
|
+
const normalized = toPosixPath(node_path.normalize(sourcePath));
|
|
155
|
+
const withoutPrefix = normalized.startsWith('./') ? normalized.slice(2) : normalized;
|
|
156
|
+
return replaceExtension(withoutPrefix, '.bundle');
|
|
157
|
+
}
|
|
158
|
+
function normalizeEntryFile(sourcePath) {
|
|
159
|
+
const normalized = toPosixPath(node_path.normalize(sourcePath));
|
|
160
|
+
return normalized.startsWith('./') ? normalized : `./${normalized}`;
|
|
161
|
+
}
|
|
162
|
+
function getSharedImportName(sharedName, sharedConfig) {
|
|
163
|
+
return 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
|
|
164
|
+
}
|
|
165
|
+
function getBoolean(params, key, defaultValue) {
|
|
166
|
+
const value = params.get(key);
|
|
167
|
+
if (null == value) return defaultValue;
|
|
168
|
+
return 'true' === value || '1' === value;
|
|
169
|
+
}
|
|
170
|
+
export { createManifestMiddleware };
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import type { ModuleFederationConfigNormalized } from '../types';
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type BundleHashMap = Map<string, string>;
|
|
3
|
+
export type ManifestGenerationOptions = {
|
|
4
|
+
projectRoot?: string;
|
|
5
|
+
target?: 'development' | 'build';
|
|
6
|
+
tmpDirPath?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function createManifest(options: ModuleFederationConfigNormalized, mfMetroPath: string, hashesOrOptions?: BundleHashMap | ManifestGenerationOptions, manifestOptions?: ManifestGenerationOptions): string;
|
|
9
|
+
export declare function updateManifest(manifestPath: string, options: ModuleFederationConfigNormalized, hashesOrOptions?: BundleHashMap | ManifestGenerationOptions, manifestOptions?: ManifestGenerationOptions): string;
|
|
10
|
+
/**
|
|
11
|
+
* Compute SHA-256 of bundle code and store the hash for the matching
|
|
12
|
+
* manifest entry (container, exposed, or shared).
|
|
13
|
+
*/
|
|
14
|
+
export declare function recordBundleHash(hashes: BundleHashMap, code: string, entryPoint: string, projectRoot: string, config: ModuleFederationConfigNormalized): void;
|
|
15
|
+
export declare function getSharedVirtualModuleName(sharedName: string): string;
|
|
16
|
+
export declare function getSharedVirtualModulePath(tmpDirPath: string, sharedName: string): string;
|
package/dist/plugin/manifest.js
CHANGED
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -22,7 +26,7 @@ var __webpack_require__ = {};
|
|
|
22
26
|
})();
|
|
23
27
|
(()=>{
|
|
24
28
|
__webpack_require__.r = (exports1)=>{
|
|
25
|
-
if (
|
|
29
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
30
|
value: 'Module'
|
|
27
31
|
});
|
|
28
32
|
Object.defineProperty(exports1, '__esModule', {
|
|
@@ -34,41 +38,60 @@ var __webpack_exports__ = {};
|
|
|
34
38
|
__webpack_require__.r(__webpack_exports__);
|
|
35
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
40
|
createManifest: ()=>createManifest,
|
|
41
|
+
getSharedVirtualModuleName: ()=>getSharedVirtualModuleName,
|
|
42
|
+
getSharedVirtualModulePath: ()=>getSharedVirtualModulePath,
|
|
43
|
+
recordBundleHash: ()=>recordBundleHash,
|
|
37
44
|
updateManifest: ()=>updateManifest
|
|
38
45
|
});
|
|
46
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
47
|
+
var external_node_crypto_default = /*#__PURE__*/ __webpack_require__.n(external_node_crypto_namespaceObject);
|
|
39
48
|
const external_node_fs_namespaceObject = require("node:fs");
|
|
40
49
|
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
|
|
41
50
|
const external_node_path_namespaceObject = require("node:path");
|
|
42
51
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
43
52
|
const external_constants_js_namespaceObject = require("./constants.js");
|
|
44
|
-
|
|
53
|
+
const external_helpers_js_namespaceObject = require("./helpers.js");
|
|
54
|
+
function createManifest(options, mfMetroPath, hashesOrOptions, manifestOptions) {
|
|
55
|
+
const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
|
|
45
56
|
const manifestPath = external_node_path_default().join(mfMetroPath, external_constants_js_namespaceObject.MANIFEST_FILENAME);
|
|
46
|
-
const manifest = generateManifest(options);
|
|
57
|
+
const manifest = generateManifest(options, hashes, generationOptions);
|
|
47
58
|
external_node_fs_default().writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
|
|
48
59
|
return manifestPath;
|
|
49
60
|
}
|
|
50
|
-
|
|
51
|
-
const
|
|
61
|
+
function updateManifest(manifestPath, options, hashesOrOptions, manifestOptions) {
|
|
62
|
+
const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
|
|
63
|
+
const manifest = generateManifest(options, hashes, generationOptions);
|
|
64
|
+
const existingManifest = readManifest(manifestPath);
|
|
65
|
+
if (existingManifest?.metaData?.types) manifest.metaData.types = {
|
|
66
|
+
...manifest.metaData.types,
|
|
67
|
+
...existingManifest.metaData.types
|
|
68
|
+
};
|
|
52
69
|
external_node_fs_default().writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
|
|
53
70
|
return manifestPath;
|
|
54
|
-
}
|
|
55
|
-
function
|
|
71
|
+
}
|
|
72
|
+
function recordBundleHash(hashes, code, entryPoint, projectRoot, config) {
|
|
73
|
+
const hash = external_node_crypto_default().createHash('sha256').update(code).digest('hex');
|
|
74
|
+
const key = resolveBundleKey(entryPoint, projectRoot, config);
|
|
75
|
+
if (key) hashes.set(key, hash);
|
|
76
|
+
}
|
|
77
|
+
function generateManifest(config, hashes, manifestOptions = {}) {
|
|
56
78
|
return {
|
|
57
79
|
id: config.name,
|
|
58
80
|
name: config.name,
|
|
59
|
-
metaData: generateMetaData(config),
|
|
60
|
-
exposes: generateExposes(config),
|
|
81
|
+
metaData: generateMetaData(config, hashes),
|
|
82
|
+
exposes: generateExposes(config, hashes),
|
|
61
83
|
remotes: generateRemotes(config),
|
|
62
|
-
shared: generateShared(config)
|
|
84
|
+
shared: generateShared(config, hashes, manifestOptions)
|
|
63
85
|
};
|
|
64
86
|
}
|
|
65
|
-
function generateMetaData(config) {
|
|
87
|
+
function generateMetaData(config, hashes) {
|
|
66
88
|
return {
|
|
67
89
|
name: config.name,
|
|
68
90
|
type: 'app',
|
|
69
91
|
buildInfo: {
|
|
70
92
|
buildVersion: '1.0.0',
|
|
71
|
-
buildName: config.name
|
|
93
|
+
buildName: config.name,
|
|
94
|
+
hash: hashes?.get(`container:${config.name}`) ?? ''
|
|
72
95
|
},
|
|
73
96
|
remoteEntry: {
|
|
74
97
|
name: config.filename,
|
|
@@ -86,7 +109,7 @@ function generateMetaData(config) {
|
|
|
86
109
|
publicPath: 'auto'
|
|
87
110
|
};
|
|
88
111
|
}
|
|
89
|
-
function generateExposes(config) {
|
|
112
|
+
function generateExposes(config, hashes) {
|
|
90
113
|
return Object.keys(config.exposes).map((expose)=>{
|
|
91
114
|
const formatKey = expose.replace('./', '');
|
|
92
115
|
const assets = getEmptyAssets();
|
|
@@ -95,7 +118,8 @@ function generateExposes(config) {
|
|
|
95
118
|
id: `${config.name}:${formatKey}`,
|
|
96
119
|
name: formatKey,
|
|
97
120
|
path: expose,
|
|
98
|
-
assets
|
|
121
|
+
assets,
|
|
122
|
+
hash: hashes?.get(`expose:${formatKey}`) ?? ''
|
|
99
123
|
};
|
|
100
124
|
});
|
|
101
125
|
}
|
|
@@ -107,22 +131,92 @@ function generateRemotes(config) {
|
|
|
107
131
|
entry: '*'
|
|
108
132
|
}));
|
|
109
133
|
}
|
|
110
|
-
function generateShared(config) {
|
|
134
|
+
function generateShared(config, hashes, manifestOptions = {}) {
|
|
111
135
|
return Object.keys(config.shared).map((sharedName)=>{
|
|
112
136
|
const assets = getEmptyAssets();
|
|
113
137
|
if (config.shared[sharedName].eager) assets.js.sync.push(config.filename);
|
|
114
|
-
else if (false !== config.shared[sharedName].import) assets.js.sync.push(
|
|
138
|
+
else if (false !== config.shared[sharedName].import) assets.js.sync.push(getSharedAssetPath(sharedName, manifestOptions));
|
|
115
139
|
return {
|
|
116
140
|
id: sharedName,
|
|
117
141
|
name: sharedName,
|
|
118
|
-
version: config.shared[sharedName].version,
|
|
119
|
-
requiredVersion: config.shared[sharedName].requiredVersion,
|
|
142
|
+
version: getManifestVersion(config.shared[sharedName].version),
|
|
143
|
+
requiredVersion: getManifestRequiredVersion(config.shared[sharedName].requiredVersion),
|
|
120
144
|
singleton: config.shared[sharedName].singleton,
|
|
121
|
-
hash: '',
|
|
145
|
+
hash: hashes?.get(`shared:${sharedName}`) ?? '',
|
|
122
146
|
assets
|
|
123
147
|
};
|
|
124
148
|
});
|
|
125
149
|
}
|
|
150
|
+
function resolveBundleKey(entryPoint, projectRoot, config) {
|
|
151
|
+
const relPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, entryPoint));
|
|
152
|
+
const normalizedRel = relPath.startsWith('./') ? relPath.slice(2) : relPath;
|
|
153
|
+
const normalizedRelNoExt = (0, external_helpers_js_namespaceObject.removeExtension)(normalizedRel);
|
|
154
|
+
for (const [exposeKey, exposePath] of Object.entries(config.exposes)){
|
|
155
|
+
const normalizedExpose = (0, external_helpers_js_namespaceObject.toPosixPath)(exposePath.startsWith('./') ? exposePath.slice(2) : exposePath);
|
|
156
|
+
if (normalizedRel === normalizedExpose || normalizedRelNoExt === (0, external_helpers_js_namespaceObject.removeExtension)(normalizedExpose)) return `expose:${exposeKey.replace('./', '')}`;
|
|
157
|
+
}
|
|
158
|
+
if ((0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(entryPoint)) === (0, external_helpers_js_namespaceObject.removeExtension)(external_node_path_default().basename(config.filename))) return `container:${config.name}`;
|
|
159
|
+
const virtualSharedKey = resolveDevVirtualSharedKey(entryPoint, projectRoot, config);
|
|
160
|
+
if (virtualSharedKey) return virtualSharedKey;
|
|
161
|
+
const absPath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().resolve(entryPoint));
|
|
162
|
+
const nmMatch = absPath.match(/.*node_modules\/(.+)/);
|
|
163
|
+
if (nmMatch) {
|
|
164
|
+
const modulePath = (0, external_helpers_js_namespaceObject.removeExtension)(nmMatch[1]);
|
|
165
|
+
const sharedKey = findSharedKeyForModulePath(modulePath, config);
|
|
166
|
+
if (sharedKey) return `shared:${sharedKey}`;
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function normalizeManifestArgs(hashesOrOptions, manifestOptions) {
|
|
171
|
+
if (hashesOrOptions instanceof Map) return {
|
|
172
|
+
hashes: hashesOrOptions,
|
|
173
|
+
options: manifestOptions ?? {}
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
hashes: void 0,
|
|
177
|
+
options: hashesOrOptions ?? {}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function readManifest(manifestPath) {
|
|
181
|
+
if (!external_node_fs_default().existsSync(manifestPath)) return;
|
|
182
|
+
return JSON.parse(external_node_fs_default().readFileSync(manifestPath, 'utf-8'));
|
|
183
|
+
}
|
|
184
|
+
function getSharedVirtualModuleName(sharedName) {
|
|
185
|
+
return sharedName.replaceAll('/', '_');
|
|
186
|
+
}
|
|
187
|
+
function getSharedVirtualModulePath(tmpDirPath, sharedName) {
|
|
188
|
+
return external_node_path_default().join(tmpDirPath, 'shared', `${getSharedVirtualModuleName(sharedName)}.js`);
|
|
189
|
+
}
|
|
190
|
+
function getSharedAssetPath(sharedName, manifestOptions) {
|
|
191
|
+
if ('development' === manifestOptions.target && manifestOptions.projectRoot && manifestOptions.tmpDirPath) return (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(manifestOptions.projectRoot, getSharedVirtualModulePath(manifestOptions.tmpDirPath, sharedName)));
|
|
192
|
+
return `shared/${sharedName}.bundle`;
|
|
193
|
+
}
|
|
194
|
+
function resolveDevVirtualSharedKey(entryPoint, projectRoot, config) {
|
|
195
|
+
const relativePath = (0, external_helpers_js_namespaceObject.toPosixPath)(external_node_path_default().relative(projectRoot, entryPoint));
|
|
196
|
+
const virtualSharedPrefix = `node_modules/${external_constants_js_namespaceObject.TMP_DIR_NAME}/shared/`;
|
|
197
|
+
if (!relativePath.startsWith(virtualSharedPrefix)) return null;
|
|
198
|
+
const virtualModuleName = (0, external_helpers_js_namespaceObject.removeExtension)(relativePath.slice(virtualSharedPrefix.length));
|
|
199
|
+
const sharedKey = Object.keys(config.shared).find((sharedName)=>getSharedVirtualModuleName(sharedName) === virtualModuleName);
|
|
200
|
+
return sharedKey ? `shared:${sharedKey}` : null;
|
|
201
|
+
}
|
|
202
|
+
function findSharedKeyForModulePath(modulePath, config) {
|
|
203
|
+
const sharedEntries = Object.entries(config.shared).map(([sharedName, sharedConfig])=>{
|
|
204
|
+
const importName = 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
|
|
205
|
+
return {
|
|
206
|
+
importName,
|
|
207
|
+
sharedName
|
|
208
|
+
};
|
|
209
|
+
}).sort((a, b)=>b.importName.length - a.importName.length);
|
|
210
|
+
const normalizedModulePath = (0, external_helpers_js_namespaceObject.toPosixPath)(modulePath);
|
|
211
|
+
for (const { importName, sharedName } of sharedEntries)if (normalizedModulePath === importName || normalizedModulePath.startsWith(`${importName}/`)) return sharedName;
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
function getManifestVersion(version) {
|
|
215
|
+
return 'string' == typeof version ? version : '';
|
|
216
|
+
}
|
|
217
|
+
function getManifestRequiredVersion(requiredVersion) {
|
|
218
|
+
return 'string' == typeof requiredVersion ? requiredVersion : '*';
|
|
219
|
+
}
|
|
126
220
|
function getEmptyAssets() {
|
|
127
221
|
return {
|
|
128
222
|
js: {
|
|
@@ -136,11 +230,17 @@ function getEmptyAssets() {
|
|
|
136
230
|
};
|
|
137
231
|
}
|
|
138
232
|
exports.createManifest = __webpack_exports__.createManifest;
|
|
233
|
+
exports.getSharedVirtualModuleName = __webpack_exports__.getSharedVirtualModuleName;
|
|
234
|
+
exports.getSharedVirtualModulePath = __webpack_exports__.getSharedVirtualModulePath;
|
|
235
|
+
exports.recordBundleHash = __webpack_exports__.recordBundleHash;
|
|
139
236
|
exports.updateManifest = __webpack_exports__.updateManifest;
|
|
140
|
-
for(var
|
|
237
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
141
238
|
"createManifest",
|
|
239
|
+
"getSharedVirtualModuleName",
|
|
240
|
+
"getSharedVirtualModulePath",
|
|
241
|
+
"recordBundleHash",
|
|
142
242
|
"updateManifest"
|
|
143
|
-
].indexOf(
|
|
243
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
144
244
|
Object.defineProperty(exports, '__esModule', {
|
|
145
245
|
value: true
|
|
146
246
|
});
|
package/dist/plugin/manifest.mjs
CHANGED
|
@@ -1,36 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_crypto from "node:crypto";
|
|
3
3
|
import node_fs from "node:fs";
|
|
4
4
|
import node_path from "node:path";
|
|
5
|
-
import { MANIFEST_FILENAME } from "./constants.mjs";
|
|
6
|
-
|
|
5
|
+
import { MANIFEST_FILENAME, TMP_DIR_NAME } from "./constants.mjs";
|
|
6
|
+
import { removeExtension, toPosixPath } from "./helpers.mjs";
|
|
7
|
+
function createManifest(options, mfMetroPath, hashesOrOptions, manifestOptions) {
|
|
8
|
+
const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
|
|
7
9
|
const manifestPath = node_path.join(mfMetroPath, MANIFEST_FILENAME);
|
|
8
|
-
const manifest = generateManifest(options);
|
|
10
|
+
const manifest = generateManifest(options, hashes, generationOptions);
|
|
9
11
|
node_fs.writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
|
|
10
12
|
return manifestPath;
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
+
function updateManifest(manifestPath, options, hashesOrOptions, manifestOptions) {
|
|
15
|
+
const { hashes, options: generationOptions } = normalizeManifestArgs(hashesOrOptions, manifestOptions);
|
|
16
|
+
const manifest = generateManifest(options, hashes, generationOptions);
|
|
17
|
+
const existingManifest = readManifest(manifestPath);
|
|
18
|
+
if (existingManifest?.metaData?.types) manifest.metaData.types = {
|
|
19
|
+
...manifest.metaData.types,
|
|
20
|
+
...existingManifest.metaData.types
|
|
21
|
+
};
|
|
14
22
|
node_fs.writeFileSync(manifestPath, JSON.stringify(manifest, void 0, 2));
|
|
15
23
|
return manifestPath;
|
|
16
|
-
}
|
|
17
|
-
function
|
|
24
|
+
}
|
|
25
|
+
function recordBundleHash(hashes, code, entryPoint, projectRoot, config) {
|
|
26
|
+
const hash = node_crypto.createHash('sha256').update(code).digest('hex');
|
|
27
|
+
const key = resolveBundleKey(entryPoint, projectRoot, config);
|
|
28
|
+
if (key) hashes.set(key, hash);
|
|
29
|
+
}
|
|
30
|
+
function generateManifest(config, hashes, manifestOptions = {}) {
|
|
18
31
|
return {
|
|
19
32
|
id: config.name,
|
|
20
33
|
name: config.name,
|
|
21
|
-
metaData: generateMetaData(config),
|
|
22
|
-
exposes: generateExposes(config),
|
|
34
|
+
metaData: generateMetaData(config, hashes),
|
|
35
|
+
exposes: generateExposes(config, hashes),
|
|
23
36
|
remotes: generateRemotes(config),
|
|
24
|
-
shared: generateShared(config)
|
|
37
|
+
shared: generateShared(config, hashes, manifestOptions)
|
|
25
38
|
};
|
|
26
39
|
}
|
|
27
|
-
function generateMetaData(config) {
|
|
40
|
+
function generateMetaData(config, hashes) {
|
|
28
41
|
return {
|
|
29
42
|
name: config.name,
|
|
30
43
|
type: 'app',
|
|
31
44
|
buildInfo: {
|
|
32
45
|
buildVersion: '1.0.0',
|
|
33
|
-
buildName: config.name
|
|
46
|
+
buildName: config.name,
|
|
47
|
+
hash: hashes?.get(`container:${config.name}`) ?? ''
|
|
34
48
|
},
|
|
35
49
|
remoteEntry: {
|
|
36
50
|
name: config.filename,
|
|
@@ -48,7 +62,7 @@ function generateMetaData(config) {
|
|
|
48
62
|
publicPath: 'auto'
|
|
49
63
|
};
|
|
50
64
|
}
|
|
51
|
-
function generateExposes(config) {
|
|
65
|
+
function generateExposes(config, hashes) {
|
|
52
66
|
return Object.keys(config.exposes).map((expose)=>{
|
|
53
67
|
const formatKey = expose.replace('./', '');
|
|
54
68
|
const assets = getEmptyAssets();
|
|
@@ -57,7 +71,8 @@ function generateExposes(config) {
|
|
|
57
71
|
id: `${config.name}:${formatKey}`,
|
|
58
72
|
name: formatKey,
|
|
59
73
|
path: expose,
|
|
60
|
-
assets
|
|
74
|
+
assets,
|
|
75
|
+
hash: hashes?.get(`expose:${formatKey}`) ?? ''
|
|
61
76
|
};
|
|
62
77
|
});
|
|
63
78
|
}
|
|
@@ -69,22 +84,92 @@ function generateRemotes(config) {
|
|
|
69
84
|
entry: '*'
|
|
70
85
|
}));
|
|
71
86
|
}
|
|
72
|
-
function generateShared(config) {
|
|
87
|
+
function generateShared(config, hashes, manifestOptions = {}) {
|
|
73
88
|
return Object.keys(config.shared).map((sharedName)=>{
|
|
74
89
|
const assets = getEmptyAssets();
|
|
75
90
|
if (config.shared[sharedName].eager) assets.js.sync.push(config.filename);
|
|
76
|
-
else if (false !== config.shared[sharedName].import) assets.js.sync.push(
|
|
91
|
+
else if (false !== config.shared[sharedName].import) assets.js.sync.push(getSharedAssetPath(sharedName, manifestOptions));
|
|
77
92
|
return {
|
|
78
93
|
id: sharedName,
|
|
79
94
|
name: sharedName,
|
|
80
|
-
version: config.shared[sharedName].version,
|
|
81
|
-
requiredVersion: config.shared[sharedName].requiredVersion,
|
|
95
|
+
version: getManifestVersion(config.shared[sharedName].version),
|
|
96
|
+
requiredVersion: getManifestRequiredVersion(config.shared[sharedName].requiredVersion),
|
|
82
97
|
singleton: config.shared[sharedName].singleton,
|
|
83
|
-
hash: '',
|
|
98
|
+
hash: hashes?.get(`shared:${sharedName}`) ?? '',
|
|
84
99
|
assets
|
|
85
100
|
};
|
|
86
101
|
});
|
|
87
102
|
}
|
|
103
|
+
function resolveBundleKey(entryPoint, projectRoot, config) {
|
|
104
|
+
const relPath = toPosixPath(node_path.relative(projectRoot, entryPoint));
|
|
105
|
+
const normalizedRel = relPath.startsWith('./') ? relPath.slice(2) : relPath;
|
|
106
|
+
const normalizedRelNoExt = removeExtension(normalizedRel);
|
|
107
|
+
for (const [exposeKey, exposePath] of Object.entries(config.exposes)){
|
|
108
|
+
const normalizedExpose = toPosixPath(exposePath.startsWith('./') ? exposePath.slice(2) : exposePath);
|
|
109
|
+
if (normalizedRel === normalizedExpose || normalizedRelNoExt === removeExtension(normalizedExpose)) return `expose:${exposeKey.replace('./', '')}`;
|
|
110
|
+
}
|
|
111
|
+
if (removeExtension(node_path.basename(entryPoint)) === removeExtension(node_path.basename(config.filename))) return `container:${config.name}`;
|
|
112
|
+
const virtualSharedKey = resolveDevVirtualSharedKey(entryPoint, projectRoot, config);
|
|
113
|
+
if (virtualSharedKey) return virtualSharedKey;
|
|
114
|
+
const absPath = toPosixPath(node_path.resolve(entryPoint));
|
|
115
|
+
const nmMatch = absPath.match(/.*node_modules\/(.+)/);
|
|
116
|
+
if (nmMatch) {
|
|
117
|
+
const modulePath = removeExtension(nmMatch[1]);
|
|
118
|
+
const sharedKey = findSharedKeyForModulePath(modulePath, config);
|
|
119
|
+
if (sharedKey) return `shared:${sharedKey}`;
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
function normalizeManifestArgs(hashesOrOptions, manifestOptions) {
|
|
124
|
+
if (hashesOrOptions instanceof Map) return {
|
|
125
|
+
hashes: hashesOrOptions,
|
|
126
|
+
options: manifestOptions ?? {}
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
hashes: void 0,
|
|
130
|
+
options: hashesOrOptions ?? {}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function readManifest(manifestPath) {
|
|
134
|
+
if (!node_fs.existsSync(manifestPath)) return;
|
|
135
|
+
return JSON.parse(node_fs.readFileSync(manifestPath, 'utf-8'));
|
|
136
|
+
}
|
|
137
|
+
function getSharedVirtualModuleName(sharedName) {
|
|
138
|
+
return sharedName.replaceAll('/', '_');
|
|
139
|
+
}
|
|
140
|
+
function getSharedVirtualModulePath(tmpDirPath, sharedName) {
|
|
141
|
+
return node_path.join(tmpDirPath, 'shared', `${getSharedVirtualModuleName(sharedName)}.js`);
|
|
142
|
+
}
|
|
143
|
+
function getSharedAssetPath(sharedName, manifestOptions) {
|
|
144
|
+
if ('development' === manifestOptions.target && manifestOptions.projectRoot && manifestOptions.tmpDirPath) return toPosixPath(node_path.relative(manifestOptions.projectRoot, getSharedVirtualModulePath(manifestOptions.tmpDirPath, sharedName)));
|
|
145
|
+
return `shared/${sharedName}.bundle`;
|
|
146
|
+
}
|
|
147
|
+
function resolveDevVirtualSharedKey(entryPoint, projectRoot, config) {
|
|
148
|
+
const relativePath = toPosixPath(node_path.relative(projectRoot, entryPoint));
|
|
149
|
+
const virtualSharedPrefix = `node_modules/${TMP_DIR_NAME}/shared/`;
|
|
150
|
+
if (!relativePath.startsWith(virtualSharedPrefix)) return null;
|
|
151
|
+
const virtualModuleName = removeExtension(relativePath.slice(virtualSharedPrefix.length));
|
|
152
|
+
const sharedKey = Object.keys(config.shared).find((sharedName)=>getSharedVirtualModuleName(sharedName) === virtualModuleName);
|
|
153
|
+
return sharedKey ? `shared:${sharedKey}` : null;
|
|
154
|
+
}
|
|
155
|
+
function findSharedKeyForModulePath(modulePath, config) {
|
|
156
|
+
const sharedEntries = Object.entries(config.shared).map(([sharedName, sharedConfig])=>{
|
|
157
|
+
const importName = 'string' == typeof sharedConfig.import ? sharedConfig.import : sharedName;
|
|
158
|
+
return {
|
|
159
|
+
importName,
|
|
160
|
+
sharedName
|
|
161
|
+
};
|
|
162
|
+
}).sort((a, b)=>b.importName.length - a.importName.length);
|
|
163
|
+
const normalizedModulePath = toPosixPath(modulePath);
|
|
164
|
+
for (const { importName, sharedName } of sharedEntries)if (normalizedModulePath === importName || normalizedModulePath.startsWith(`${importName}/`)) return sharedName;
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
function getManifestVersion(version) {
|
|
168
|
+
return 'string' == typeof version ? version : '';
|
|
169
|
+
}
|
|
170
|
+
function getManifestRequiredVersion(requiredVersion) {
|
|
171
|
+
return 'string' == typeof requiredVersion ? requiredVersion : '*';
|
|
172
|
+
}
|
|
88
173
|
function getEmptyAssets() {
|
|
89
174
|
return {
|
|
90
175
|
js: {
|
|
@@ -97,4 +182,4 @@ function getEmptyAssets() {
|
|
|
97
182
|
}
|
|
98
183
|
};
|
|
99
184
|
}
|
|
100
|
-
export { createManifest, updateManifest };
|
|
185
|
+
export { createManifest, getSharedVirtualModuleName, getSharedVirtualModulePath, recordBundleHash, updateManifest };
|