@bleedingdev/mf-manifest 2.9.1

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/dist/utils.js ADDED
@@ -0,0 +1,299 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ // The require scope
10
+ var __webpack_require__ = {};
11
+
12
+ // webpack/runtime/compat_get_default_export
13
+ (() => {
14
+ // getDefaultExport function for compatibility with non-ESM modules
15
+ __webpack_require__.n = (module) => {
16
+ var getter = module && module.__esModule ?
17
+ () => (module['default']) :
18
+ () => (module);
19
+ __webpack_require__.d(getter, { a: getter });
20
+ return getter;
21
+ };
22
+
23
+ })();
24
+ // webpack/runtime/define_property_getters
25
+ (() => {
26
+ __webpack_require__.d = (exports, getters, values) => {
27
+ var define = (defs, kind) => {
28
+ for(var key in defs) {
29
+ if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
30
+ Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
31
+ }
32
+ }
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
36
+ };
37
+ })();
38
+ // webpack/runtime/has_own_property
39
+ (() => {
40
+ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
41
+ })();
42
+ // webpack/runtime/make_namespace_object
43
+ (() => {
44
+ // define __esModule on exports
45
+ __webpack_require__.r = (exports) => {
46
+ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ }
49
+ Object.defineProperty(exports, '__esModule', { value: true });
50
+ };
51
+ })();
52
+ var __webpack_exports__ = {};
53
+ // ESM COMPAT FLAG
54
+ __webpack_require__.r(__webpack_exports__);
55
+
56
+ // EXPORTS
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ assert: () => (/* binding */ assert),
59
+ error: () => (/* binding */ error),
60
+ findChunk: () => (/* binding */ findChunk),
61
+ getAssetsByChunk: () => (/* binding */ getAssetsByChunk),
62
+ getAssetsByChunkIDs: () => (/* binding */ getAssetsByChunkIDs),
63
+ getFileNameWithOutExt: () => (/* binding */ getFileNameWithOutExt),
64
+ getSharedModules: () => (/* binding */ getSharedModules),
65
+ getTypesMetaInfo: () => (/* binding */ getTypesMetaInfo),
66
+ isDev: () => (/* binding */ isDev)
67
+ });
68
+
69
+ ;// CONCATENATED MODULE: external "path"
70
+ const external_path_namespaceObject = require("path");
71
+ var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
72
+ ;// CONCATENATED MODULE: external "@module-federation/sdk"
73
+ const sdk_namespaceObject = require("@module-federation/sdk");
74
+ ;// CONCATENATED MODULE: external "./constants.js"
75
+ const external_constants_js_namespaceObject = require("./constants.js");
76
+ ;// CONCATENATED MODULE: external "./logger.js"
77
+ const external_logger_js_namespaceObject = require("./logger.js");
78
+ var external_logger_js_default = /*#__PURE__*/__webpack_require__.n(external_logger_js_namespaceObject);
79
+ ;// CONCATENATED MODULE: ./src/utils.ts
80
+
81
+
82
+
83
+
84
+
85
+ function isHotFile(file) {
86
+ return file.includes(external_constants_js_namespaceObject.HOT_UPDATE_SUFFIX);
87
+ }
88
+ const collectAssets = (assets, jsTargetSet, cssTargetSet)=>{
89
+ assets.forEach((file)=>{
90
+ if (file.endsWith('.css')) {
91
+ cssTargetSet.add(file);
92
+ } else {
93
+ if (isDev()) {
94
+ if (!isHotFile(file)) {
95
+ jsTargetSet.add(file);
96
+ }
97
+ } else {
98
+ jsTargetSet.add(file);
99
+ }
100
+ }
101
+ });
102
+ };
103
+ function getSharedModuleName(name) {
104
+ const [_type, _shared, _module, _shareScope, sharedInfo] = name.split(' ');
105
+ return sharedInfo.split('@').slice(0, -1).join('@');
106
+ }
107
+ function getAssetsByChunkIDs(compilation, chunkIDMap) {
108
+ const arrayChunks = Array.from(compilation.chunks);
109
+ const assetMap = {};
110
+ Object.keys(chunkIDMap).forEach((key)=>{
111
+ const chunkIDs = Array.from(chunkIDMap[key]);
112
+ if (!assetMap[key]) {
113
+ assetMap[key] = {
114
+ css: new Set(),
115
+ js: new Set()
116
+ };
117
+ }
118
+ chunkIDs.forEach((chunkID)=>{
119
+ const chunk = arrayChunks.find((item)=>item.id === chunkID);
120
+ if (chunk) {
121
+ collectAssets([
122
+ ...chunk.files
123
+ ], assetMap[key].js, assetMap[key].css);
124
+ }
125
+ });
126
+ });
127
+ const assets = {};
128
+ Object.keys(assetMap).map((key)=>{
129
+ assets[key] = {
130
+ js: Array.from(assetMap[key].js),
131
+ css: Array.from(assetMap[key].css)
132
+ };
133
+ });
134
+ return assets;
135
+ }
136
+ function findChunk(id, chunks) {
137
+ for (const chunk of chunks){
138
+ if (id === chunk.id) {
139
+ return chunk;
140
+ }
141
+ }
142
+ }
143
+ function getSharedModules(stats, sharedModules) {
144
+ // 获取入口文件就是实际内容的 module
145
+ const entryContentModuleNames = [];
146
+ let effectiveSharedModules = stats.modules?.reduce((sum, module)=>{
147
+ for (const sharedModule of sharedModules){
148
+ if (sharedModule.name === module.issuerName) {
149
+ entryContentModuleNames.push(sharedModule.name);
150
+ sum.push([
151
+ getSharedModuleName(module.issuerName),
152
+ module
153
+ ]);
154
+ return sum;
155
+ }
156
+ }
157
+ return sum;
158
+ }, []) || [];
159
+ // 获取入口文件仅作为 Re Export 的 module
160
+ const entryReExportModules = sharedModules.filter((sharedModule)=>!entryContentModuleNames.includes(sharedModule.name));
161
+ if (entryReExportModules.length) {
162
+ effectiveSharedModules = effectiveSharedModules.concat(stats.modules.reduce((sum, module)=>{
163
+ let flag = false;
164
+ for (const entryReExportModule of entryReExportModules){
165
+ if (flag) {
166
+ break;
167
+ }
168
+ if (module.reasons) {
169
+ for (const issueModule of module.reasons){
170
+ if (issueModule.moduleName === entryReExportModule.name) {
171
+ sum.push([
172
+ getSharedModuleName(entryReExportModule.name),
173
+ module
174
+ ]);
175
+ flag = true;
176
+ break;
177
+ }
178
+ }
179
+ }
180
+ }
181
+ return sum;
182
+ }, []));
183
+ }
184
+ return effectiveSharedModules;
185
+ }
186
+ function getAssetsByChunk(chunk, entryPointNames) {
187
+ const assesSet = {
188
+ js: {
189
+ sync: new Set(),
190
+ async: new Set()
191
+ },
192
+ css: {
193
+ sync: new Set(),
194
+ async: new Set()
195
+ }
196
+ };
197
+ const collectChunkFiles = (targetChunk, type)=>{
198
+ [
199
+ ...targetChunk.groupsIterable
200
+ ].forEach((chunkGroup)=>{
201
+ if (chunkGroup.name && !entryPointNames.includes(chunkGroup.name)) {
202
+ collectAssets(chunkGroup.getFiles(), assesSet.js[type], assesSet.css[type]);
203
+ }
204
+ });
205
+ };
206
+ collectChunkFiles(chunk, 'sync');
207
+ [
208
+ ...chunk.getAllAsyncChunks()
209
+ ].forEach((asyncChunk)=>{
210
+ collectAssets([
211
+ ...asyncChunk.files
212
+ ], assesSet.js['async'], assesSet.css['async']);
213
+ collectChunkFiles(asyncChunk, 'async');
214
+ });
215
+ const assets = {
216
+ js: {
217
+ sync: Array.from(assesSet.js.sync),
218
+ async: Array.from(assesSet.js.async)
219
+ },
220
+ css: {
221
+ sync: Array.from(assesSet.css.sync),
222
+ async: Array.from(assesSet.css.async)
223
+ }
224
+ };
225
+ return assets;
226
+ }
227
+ function assert(condition, msg) {
228
+ if (!condition) {
229
+ error(msg);
230
+ }
231
+ }
232
+ function error(msg) {
233
+ throw new Error(`[ ${external_constants_js_namespaceObject.PLUGIN_IDENTIFIER} ]: ${msg}`);
234
+ }
235
+ function isDev() {
236
+ return process.env['NODE_ENV'] === 'development';
237
+ }
238
+ function getFileNameWithOutExt(str) {
239
+ return str.replace(external_path_default().extname(str), '');
240
+ }
241
+ function getTypesMetaInfo(pluginOptions, context) {
242
+ const defaultRemoteOptions = {
243
+ generateAPITypes: true,
244
+ compileInChildProcess: true
245
+ };
246
+ const defaultTypesMetaInfo = {
247
+ path: '',
248
+ name: '',
249
+ zip: '',
250
+ api: ''
251
+ };
252
+ try {
253
+ if (pluginOptions.dts === false) {
254
+ return defaultTypesMetaInfo;
255
+ }
256
+ const { isTSProject, retrieveTypesAssetsInfo } = require("@module-federation/dts-plugin/core");
257
+ const normalizedDtsOptions = (0,sdk_namespaceObject.normalizeOptions)(isTSProject(pluginOptions.dts, context), {
258
+ generateTypes: defaultRemoteOptions,
259
+ consumeTypes: {}
260
+ }, 'mfOptions.dts')(pluginOptions.dts);
261
+ if (normalizedDtsOptions === false) {
262
+ return defaultTypesMetaInfo;
263
+ }
264
+ const normalizedRemote = (0,sdk_namespaceObject.normalizeOptions)(true, defaultRemoteOptions, 'mfOptions.dts.generateTypes')(normalizedDtsOptions.generateTypes);
265
+ if (normalizedRemote === false) {
266
+ return defaultTypesMetaInfo;
267
+ }
268
+ const { apiFileName, zipName } = retrieveTypesAssetsInfo({
269
+ ...normalizedRemote,
270
+ context,
271
+ moduleFederationConfig: pluginOptions
272
+ });
273
+ return {
274
+ path: '',
275
+ name: '',
276
+ zip: zipName,
277
+ api: apiFileName
278
+ };
279
+ } catch (err) {
280
+ external_logger_js_default().warn(`getTypesMetaInfo failed, it will use the default types meta info, and the errors as belows: ${err}`);
281
+ return defaultTypesMetaInfo;
282
+ }
283
+ }
284
+
285
+ exports.assert = __webpack_exports__.assert;
286
+ exports.error = __webpack_exports__.error;
287
+ exports.findChunk = __webpack_exports__.findChunk;
288
+ exports.getAssetsByChunk = __webpack_exports__.getAssetsByChunk;
289
+ exports.getAssetsByChunkIDs = __webpack_exports__.getAssetsByChunkIDs;
290
+ exports.getFileNameWithOutExt = __webpack_exports__.getFileNameWithOutExt;
291
+ exports.getSharedModules = __webpack_exports__.getSharedModules;
292
+ exports.getTypesMetaInfo = __webpack_exports__.getTypesMetaInfo;
293
+ exports.isDev = __webpack_exports__.isDev;
294
+ for(var __rspack_i in __webpack_exports__) {
295
+ if(["assert","error","findChunk","getAssetsByChunk","getAssetsByChunkIDs","getFileNameWithOutExt","getSharedModules","getTypesMetaInfo","isDev"].indexOf(__rspack_i) === -1) {
296
+ exports[__rspack_i] = __webpack_exports__[__rspack_i];
297
+ }
298
+ }
299
+ Object.defineProperty(exports, '__esModule', { value: true });
package/dist/utils.mjs ADDED
@@ -0,0 +1,218 @@
1
+ import path from "path";
2
+ import { normalizeOptions } from "@module-federation/sdk";
3
+ import { createRequire } from "node:module";
4
+ import { HOT_UPDATE_SUFFIX, PLUGIN_IDENTIFIER } from "./constants.mjs";
5
+ import logger from "./logger.mjs";
6
+ const require = createRequire(import.meta.url);
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ function isHotFile(file) {
19
+ return file.includes(HOT_UPDATE_SUFFIX);
20
+ }
21
+ const collectAssets = (assets, jsTargetSet, cssTargetSet)=>{
22
+ assets.forEach((file)=>{
23
+ if (file.endsWith('.css')) {
24
+ cssTargetSet.add(file);
25
+ } else {
26
+ if (isDev()) {
27
+ if (!isHotFile(file)) {
28
+ jsTargetSet.add(file);
29
+ }
30
+ } else {
31
+ jsTargetSet.add(file);
32
+ }
33
+ }
34
+ });
35
+ };
36
+ function getSharedModuleName(name) {
37
+ const [_type, _shared, _module, _shareScope, sharedInfo] = name.split(' ');
38
+ return sharedInfo.split('@').slice(0, -1).join('@');
39
+ }
40
+ function getAssetsByChunkIDs(compilation, chunkIDMap) {
41
+ const arrayChunks = Array.from(compilation.chunks);
42
+ const assetMap = {};
43
+ Object.keys(chunkIDMap).forEach((key)=>{
44
+ const chunkIDs = Array.from(chunkIDMap[key]);
45
+ if (!assetMap[key]) {
46
+ assetMap[key] = {
47
+ css: new Set(),
48
+ js: new Set()
49
+ };
50
+ }
51
+ chunkIDs.forEach((chunkID)=>{
52
+ const chunk = arrayChunks.find((item)=>item.id === chunkID);
53
+ if (chunk) {
54
+ collectAssets([
55
+ ...chunk.files
56
+ ], assetMap[key].js, assetMap[key].css);
57
+ }
58
+ });
59
+ });
60
+ const assets = {};
61
+ Object.keys(assetMap).map((key)=>{
62
+ assets[key] = {
63
+ js: Array.from(assetMap[key].js),
64
+ css: Array.from(assetMap[key].css)
65
+ };
66
+ });
67
+ return assets;
68
+ }
69
+ function findChunk(id, chunks) {
70
+ for (const chunk of chunks){
71
+ if (id === chunk.id) {
72
+ return chunk;
73
+ }
74
+ }
75
+ }
76
+ function getSharedModules(stats, sharedModules) {
77
+ // 获取入口文件就是实际内容的 module
78
+ const entryContentModuleNames = [];
79
+ let effectiveSharedModules = stats.modules?.reduce((sum, module)=>{
80
+ for (const sharedModule of sharedModules){
81
+ if (sharedModule.name === module.issuerName) {
82
+ entryContentModuleNames.push(sharedModule.name);
83
+ sum.push([
84
+ getSharedModuleName(module.issuerName),
85
+ module
86
+ ]);
87
+ return sum;
88
+ }
89
+ }
90
+ return sum;
91
+ }, []) || [];
92
+ // 获取入口文件仅作为 Re Export 的 module
93
+ const entryReExportModules = sharedModules.filter((sharedModule)=>!entryContentModuleNames.includes(sharedModule.name));
94
+ if (entryReExportModules.length) {
95
+ effectiveSharedModules = effectiveSharedModules.concat(stats.modules.reduce((sum, module)=>{
96
+ let flag = false;
97
+ for (const entryReExportModule of entryReExportModules){
98
+ if (flag) {
99
+ break;
100
+ }
101
+ if (module.reasons) {
102
+ for (const issueModule of module.reasons){
103
+ if (issueModule.moduleName === entryReExportModule.name) {
104
+ sum.push([
105
+ getSharedModuleName(entryReExportModule.name),
106
+ module
107
+ ]);
108
+ flag = true;
109
+ break;
110
+ }
111
+ }
112
+ }
113
+ }
114
+ return sum;
115
+ }, []));
116
+ }
117
+ return effectiveSharedModules;
118
+ }
119
+ function getAssetsByChunk(chunk, entryPointNames) {
120
+ const assesSet = {
121
+ js: {
122
+ sync: new Set(),
123
+ async: new Set()
124
+ },
125
+ css: {
126
+ sync: new Set(),
127
+ async: new Set()
128
+ }
129
+ };
130
+ const collectChunkFiles = (targetChunk, type)=>{
131
+ [
132
+ ...targetChunk.groupsIterable
133
+ ].forEach((chunkGroup)=>{
134
+ if (chunkGroup.name && !entryPointNames.includes(chunkGroup.name)) {
135
+ collectAssets(chunkGroup.getFiles(), assesSet.js[type], assesSet.css[type]);
136
+ }
137
+ });
138
+ };
139
+ collectChunkFiles(chunk, 'sync');
140
+ [
141
+ ...chunk.getAllAsyncChunks()
142
+ ].forEach((asyncChunk)=>{
143
+ collectAssets([
144
+ ...asyncChunk.files
145
+ ], assesSet.js['async'], assesSet.css['async']);
146
+ collectChunkFiles(asyncChunk, 'async');
147
+ });
148
+ const assets = {
149
+ js: {
150
+ sync: Array.from(assesSet.js.sync),
151
+ async: Array.from(assesSet.js.async)
152
+ },
153
+ css: {
154
+ sync: Array.from(assesSet.css.sync),
155
+ async: Array.from(assesSet.css.async)
156
+ }
157
+ };
158
+ return assets;
159
+ }
160
+ function assert(condition, msg) {
161
+ if (!condition) {
162
+ error(msg);
163
+ }
164
+ }
165
+ function error(msg) {
166
+ throw new Error(`[ ${PLUGIN_IDENTIFIER} ]: ${msg}`);
167
+ }
168
+ function isDev() {
169
+ return process.env['NODE_ENV'] === 'development';
170
+ }
171
+ function getFileNameWithOutExt(str) {
172
+ return str.replace(path.extname(str), '');
173
+ }
174
+ function getTypesMetaInfo(pluginOptions, context) {
175
+ const defaultRemoteOptions = {
176
+ generateAPITypes: true,
177
+ compileInChildProcess: true
178
+ };
179
+ const defaultTypesMetaInfo = {
180
+ path: '',
181
+ name: '',
182
+ zip: '',
183
+ api: ''
184
+ };
185
+ try {
186
+ if (pluginOptions.dts === false) {
187
+ return defaultTypesMetaInfo;
188
+ }
189
+ const { isTSProject, retrieveTypesAssetsInfo } = require("@module-federation/dts-plugin/core");
190
+ const normalizedDtsOptions = normalizeOptions(isTSProject(pluginOptions.dts, context), {
191
+ generateTypes: defaultRemoteOptions,
192
+ consumeTypes: {}
193
+ }, 'mfOptions.dts')(pluginOptions.dts);
194
+ if (normalizedDtsOptions === false) {
195
+ return defaultTypesMetaInfo;
196
+ }
197
+ const normalizedRemote = normalizeOptions(true, defaultRemoteOptions, 'mfOptions.dts.generateTypes')(normalizedDtsOptions.generateTypes);
198
+ if (normalizedRemote === false) {
199
+ return defaultTypesMetaInfo;
200
+ }
201
+ const { apiFileName, zipName } = retrieveTypesAssetsInfo({
202
+ ...normalizedRemote,
203
+ context,
204
+ moduleFederationConfig: pluginOptions
205
+ });
206
+ return {
207
+ path: '',
208
+ name: '',
209
+ zip: zipName,
210
+ api: apiFileName
211
+ };
212
+ } catch (err) {
213
+ logger.warn(`getTypesMetaInfo failed, it will use the default types meta info, and the errors as belows: ${err}`);
214
+ return defaultTypesMetaInfo;
215
+ }
216
+ }
217
+
218
+ export { assert, error, findChunk, getAssetsByChunk, getAssetsByChunkIDs, getFileNameWithOutExt, getSharedModules, getTypesMetaInfo, isDev };
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@bleedingdev/mf-manifest",
3
+ "version": "2.9.1",
4
+ "license": "MIT",
5
+ "description": "Provide manifest/stats for webpack/rspack MF project .",
6
+ "keywords": [
7
+ "Module Federation",
8
+ "Webpack",
9
+ "Rspack",
10
+ "Manifest"
11
+ ],
12
+ "files": [
13
+ "dist/",
14
+ "README.md"
15
+ ],
16
+ "publishConfig": {
17
+ "registry": "https://registry.npmjs.org/",
18
+ "access": "public"
19
+ },
20
+ "author": "hanric <hanric.zhang@gmail.com>",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/BleedingDev/ultramodern.js.git",
24
+ "directory": "scripts/ultramodern-supply"
25
+ },
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "module": "./dist/index.mjs",
29
+ "types": "./dist/index.d.ts",
30
+ "dependencies": {
31
+ "@module-federation/sdk": "2.9.1",
32
+ "@module-federation/dts-plugin": "npm:@bleedingdev/mf-dts-plugin@2.9.1",
33
+ "@module-federation/managers": "2.9.1"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "import": {
38
+ "types": "./dist/index.d.ts",
39
+ "default": "./dist/index.mjs"
40
+ },
41
+ "require": {
42
+ "types": "./dist/index.d.ts",
43
+ "default": "./dist/index.js"
44
+ }
45
+ }
46
+ },
47
+ "typesVersions": {
48
+ "*": {
49
+ ".": [
50
+ "./dist/index.d.ts"
51
+ ]
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "typescript": "7.0.2",
56
+ "webpack": "^5.0.0"
57
+ },
58
+ "scripts": {
59
+ "build": "rslib build",
60
+ "lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
61
+ "test": "pnpm exec jest --config jest.config.js --passWithNoTests",
62
+ "test:ci": "pnpm exec jest --config jest.config.js --passWithNoTests --ci --coverage",
63
+ "pre-release": "pnpm run test && pnpm run build"
64
+ }
65
+ }