@module-federation/esbuild 0.0.81 → 0.0.83
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/build.d.ts +5 -1
- package/dist/build.js +481 -0
- package/dist/build.mjs +380 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +36 -0
- package/dist/index.mjs +2 -0
- package/dist/plugin.js +1247 -0
- package/dist/{plugin.esm.js → plugin.mjs} +198 -317
- package/dist/resolve/esm-resolver.mjs +22 -15
- package/package.json +18 -25
- package/dist/build.cjs.js +0 -532
- package/dist/build.cjs.js.map +0 -1
- package/dist/build.esm.js +0 -494
- package/dist/build.esm.js.map +0 -1
- package/dist/get-externals.cjs.js +0 -22
- package/dist/get-externals.cjs.js.map +0 -1
- package/dist/get-externals.esm.js +0 -20
- package/dist/get-externals.esm.js.map +0 -1
- package/dist/index.cjs.js +0 -6
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -4
- package/dist/index.esm.js.map +0 -1
- package/dist/plugin.cjs.js +0 -1313
- package/dist/plugin.cjs.js.map +0 -1
- package/dist/plugin.d.ts +0 -1
- package/dist/plugin.esm.js.map +0 -1
- package/dist/src/build.d.ts +0 -5
- package/dist/src/index.d.ts +0 -2
- /package/dist/{src/adapters → adapters}/lib/collect-exports.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/commonjs.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/containerPlugin.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/containerReference.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/lexer.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/linkRemotesPlugin.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/manifest.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/plugin.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/react-replacements.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/transform.d.ts +0 -0
- /package/dist/{src/adapters → adapters}/lib/utils.d.ts +0 -0
- /package/dist/{src/lib → lib}/config/configuration-context.d.ts +0 -0
- /package/dist/{src/lib → lib}/config/federation-config.d.ts +0 -0
- /package/dist/{src/lib → lib}/config/share-utils.d.ts +0 -0
- /package/dist/{src/lib → lib}/config/with-native-federation.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/build-adapter.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/createContainerTemplate.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/default-skip-list.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/federation-options.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/get-externals.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/load-federation-config.d.ts +0 -0
- /package/dist/{src/lib → lib}/core/write-federation-info.d.ts +0 -0
- /package/dist/{src/lib → lib}/utils/logger.d.ts +0 -0
- /package/dist/{src/lib → lib}/utils/mapped-paths.d.ts +0 -0
- /package/dist/{src/lib → lib}/utils/normalize.d.ts +0 -0
- /package/dist/{src/lib → lib}/utils/package-info.d.ts +0 -0
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { init as
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_esbuild__ from "esbuild";
|
|
2
|
+
import fs_0, { promises } from "fs";
|
|
3
|
+
import { init as external_es_module_lexer_init, parse as external_es_module_lexer_parse } from "es-module-lexer";
|
|
4
|
+
import { init as external_cjs_module_lexer_init, parse as external_cjs_module_lexer_parse } from "cjs-module-lexer";
|
|
5
|
+
import { promisify } from "util";
|
|
6
|
+
import enhanced_resolve from "enhanced-resolve";
|
|
7
|
+
import path_0 from "path";
|
|
8
|
+
import { version as package_json_version } from "@module-federation/esbuild/package.json";
|
|
9
|
+
var __webpack_modules__ = {
|
|
10
|
+
esbuild: function(module) {
|
|
11
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE_esbuild__;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __webpack_module_cache__ = {};
|
|
15
|
+
function __webpack_require__(moduleId) {
|
|
16
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
17
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
18
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
19
|
+
exports: {}
|
|
20
|
+
};
|
|
21
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
22
|
+
return module.exports;
|
|
23
|
+
}
|
|
24
|
+
const resolve = promisify(enhanced_resolve.create({
|
|
10
25
|
mainFields: [
|
|
11
26
|
'browser',
|
|
12
27
|
'module',
|
|
@@ -14,32 +29,27 @@ const resolve = promisify(enhancedResolve.create({
|
|
|
14
29
|
]
|
|
15
30
|
}));
|
|
16
31
|
async function getExports(modulePath) {
|
|
17
|
-
await
|
|
18
|
-
await
|
|
32
|
+
await external_es_module_lexer_init;
|
|
33
|
+
await external_cjs_module_lexer_init;
|
|
19
34
|
try {
|
|
20
35
|
const exports = [];
|
|
21
36
|
const paths = [];
|
|
22
37
|
const resolvedPath = await resolve(process.cwd(), modulePath);
|
|
23
|
-
if (typeof resolvedPath
|
|
24
|
-
paths.push(resolvedPath);
|
|
25
|
-
}
|
|
38
|
+
if ('string' == typeof resolvedPath) paths.push(resolvedPath);
|
|
26
39
|
while(paths.length > 0){
|
|
27
40
|
const currentPath = paths.pop();
|
|
28
41
|
if (currentPath) {
|
|
29
|
-
const content = await
|
|
42
|
+
const content = await fs_0.promises.readFile(currentPath, 'utf8');
|
|
30
43
|
try {
|
|
31
|
-
const { exports: cjsExports } =
|
|
44
|
+
const { exports: cjsExports } = external_cjs_module_lexer_parse(content);
|
|
32
45
|
exports.push(...cjsExports);
|
|
33
|
-
} catch
|
|
34
|
-
const [, esExports] =
|
|
46
|
+
} catch {
|
|
47
|
+
const [, esExports] = external_es_module_lexer_parse(content);
|
|
35
48
|
exports.push(...esExports.map((exp)=>exp.n));
|
|
36
49
|
}
|
|
37
|
-
// TODO: Handle re-exports
|
|
38
50
|
}
|
|
39
51
|
}
|
|
40
|
-
if (!exports.includes('default'))
|
|
41
|
-
exports.push('default');
|
|
42
|
-
}
|
|
52
|
+
if (!exports.includes('default')) exports.push('default');
|
|
43
53
|
return exports;
|
|
44
54
|
} catch (e) {
|
|
45
55
|
console.log(e);
|
|
@@ -48,29 +58,9 @@ async function getExports(modulePath) {
|
|
|
48
58
|
];
|
|
49
59
|
}
|
|
50
60
|
}
|
|
51
|
-
|
|
52
|
-
var version = "0.0.81";
|
|
53
|
-
|
|
54
|
-
function _extends$1() {
|
|
55
|
-
_extends$1 = Object.assign || function(target) {
|
|
56
|
-
for(var i = 1; i < arguments.length; i++){
|
|
57
|
-
var source = arguments[i];
|
|
58
|
-
for(var key in source){
|
|
59
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
60
|
-
target[key] = source[key];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return target;
|
|
65
|
-
};
|
|
66
|
-
return _extends$1.apply(this, arguments);
|
|
67
|
-
}
|
|
68
61
|
const writeRemoteManifest = async (config, result)=>{
|
|
69
62
|
var _result_metafile, _result_metafile1;
|
|
70
|
-
if (result.errors && result.errors.length > 0)
|
|
71
|
-
console.warn('Build errors detected, skipping writeRemoteManifest.');
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
63
|
+
if (result.errors && result.errors.length > 0) return void console.warn('Build errors detected, skipping writeRemoteManifest.');
|
|
74
64
|
let packageJson;
|
|
75
65
|
try {
|
|
76
66
|
const packageJsonPath = await resolve(process.cwd(), '/package.json') || '';
|
|
@@ -80,29 +70,28 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
80
70
|
name: config.name
|
|
81
71
|
};
|
|
82
72
|
}
|
|
83
|
-
|
|
84
|
-
const envType = process.env['NODE_ENV'] === 'development' ? 'local' : (_process_env_NODE_ENV = process.env['NODE_ENV']) != null ? _process_env_NODE_ENV : '';
|
|
73
|
+
const envType = 'development' === process.env['NODE_ENV'] ? 'local' : process.env['NODE_ENV'] ?? '';
|
|
85
74
|
const publicPath = config.publicPath || 'auto';
|
|
86
75
|
let containerName = '';
|
|
87
|
-
const outputMap = Object.entries(((_result_metafile = result.metafile)
|
|
76
|
+
const outputMap = Object.entries((null == (_result_metafile = result.metafile) ? void 0 : _result_metafile.outputs) || {}).reduce((acc, [chunkKey, chunkValue])=>{
|
|
88
77
|
const { entryPoint } = chunkValue;
|
|
89
78
|
const key = entryPoint || chunkKey;
|
|
90
|
-
if (key.startsWith('container:') && key.endsWith(config.filename))
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
acc[key] = _extends$1({}, chunkValue, {
|
|
79
|
+
if (key.startsWith('container:') && key.endsWith(config.filename)) containerName = key;
|
|
80
|
+
acc[key] = {
|
|
81
|
+
...chunkValue,
|
|
94
82
|
chunk: chunkKey
|
|
95
|
-
}
|
|
83
|
+
};
|
|
96
84
|
return acc;
|
|
97
85
|
}, {});
|
|
98
86
|
if (!outputMap[containerName]) return;
|
|
99
|
-
const outputMapWithoutExt = Object.entries(((_result_metafile1 = result.metafile)
|
|
87
|
+
const outputMapWithoutExt = Object.entries((null == (_result_metafile1 = result.metafile) ? void 0 : _result_metafile1.outputs) || {}).reduce((acc, [chunkKey, chunkValue])=>{
|
|
100
88
|
const { entryPoint } = chunkValue;
|
|
101
89
|
const key = entryPoint || chunkKey;
|
|
102
90
|
const trimKey = key.substring(0, key.lastIndexOf('.')) || key;
|
|
103
|
-
acc[trimKey] =
|
|
91
|
+
acc[trimKey] = {
|
|
92
|
+
...chunkValue,
|
|
104
93
|
chunk: chunkKey
|
|
105
|
-
}
|
|
94
|
+
};
|
|
106
95
|
return acc;
|
|
107
96
|
}, {});
|
|
108
97
|
const getChunks = (meta, outputMap)=>{
|
|
@@ -116,10 +105,10 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
116
105
|
sync: []
|
|
117
106
|
}
|
|
118
107
|
};
|
|
119
|
-
if (
|
|
108
|
+
if (null == meta ? void 0 : meta.imports) {
|
|
120
109
|
meta.imports.forEach((imp)=>{
|
|
121
110
|
const importMeta = outputMap[imp.path];
|
|
122
|
-
if (importMeta &&
|
|
111
|
+
if (importMeta && 'dynamic-import' !== importMeta.kind) {
|
|
123
112
|
const childAssets = getChunks(importMeta, outputMap);
|
|
124
113
|
assets.js.async.push(...childAssets.js.async);
|
|
125
114
|
assets.js.sync.push(...childAssets.js.sync);
|
|
@@ -128,7 +117,7 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
128
117
|
}
|
|
129
118
|
});
|
|
130
119
|
const assetType = meta.chunk.endsWith('.js') ? 'js' : 'css';
|
|
131
|
-
const syncOrAsync =
|
|
120
|
+
const syncOrAsync = 'dynamic-import' === meta.kind ? 'async' : 'sync';
|
|
132
121
|
assets[assetType][syncOrAsync].push(meta.chunk);
|
|
133
122
|
}
|
|
134
123
|
return assets;
|
|
@@ -137,15 +126,11 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
137
126
|
const meta = outputMap['esm-shares:' + pkg];
|
|
138
127
|
const chunks = getChunks(meta, outputMap);
|
|
139
128
|
let { version } = config;
|
|
140
|
-
if (!version) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
} catch (e) {
|
|
147
|
-
console.warn(`Can't resolve ${pkg} version automatically, consider setting "version" manually`);
|
|
148
|
-
}
|
|
129
|
+
if (!version) try {
|
|
130
|
+
const packageJsonPath = await resolve(process.cwd(), `${pkg}/package.json`);
|
|
131
|
+
if (packageJsonPath) version = JSON.parse(fs_0.readFileSync(packageJsonPath, 'utf-8')).version;
|
|
132
|
+
} catch (e) {
|
|
133
|
+
console.warn(`Can't resolve ${pkg} version automatically, consider setting "version" manually`);
|
|
149
134
|
}
|
|
150
135
|
return {
|
|
151
136
|
id: `${config.name}:${pkg}`,
|
|
@@ -184,7 +169,6 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
184
169
|
zip: '@mf-types.zip',
|
|
185
170
|
api: '@mf-types.d.ts'
|
|
186
171
|
};
|
|
187
|
-
var _packageJson_name;
|
|
188
172
|
const manifest = {
|
|
189
173
|
id: config.name,
|
|
190
174
|
name: config.name,
|
|
@@ -193,26 +177,25 @@ const writeRemoteManifest = async (config, result)=>{
|
|
|
193
177
|
type: 'app',
|
|
194
178
|
buildInfo: {
|
|
195
179
|
buildVersion: envType,
|
|
196
|
-
buildName: (
|
|
180
|
+
buildName: (packageJson.name ?? 'default').replace(/[^a-zA-Z0-9]/g, '_')
|
|
197
181
|
},
|
|
198
182
|
remoteEntry: {
|
|
199
183
|
name: config.filename,
|
|
200
|
-
path: outputMap[containerName] ?
|
|
184
|
+
path: outputMap[containerName] ? path_0.dirname(outputMap[containerName].chunk) : '',
|
|
201
185
|
type: 'esm'
|
|
202
186
|
},
|
|
203
187
|
types,
|
|
204
188
|
globalName: config.name,
|
|
205
|
-
pluginVersion:
|
|
189
|
+
pluginVersion: package_json_version,
|
|
206
190
|
publicPath
|
|
207
191
|
},
|
|
208
192
|
shared,
|
|
209
193
|
remotes,
|
|
210
194
|
exposes
|
|
211
195
|
};
|
|
212
|
-
const manifestPath =
|
|
213
|
-
|
|
196
|
+
const manifestPath = path_0.join(path_0.dirname(outputMap[containerName].chunk), 'mf-manifest.json');
|
|
197
|
+
fs_0.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2), 'utf-8');
|
|
214
198
|
};
|
|
215
|
-
|
|
216
199
|
const createContainerCode = `
|
|
217
200
|
import bundler_runtime_base from '@module-federation/webpack-bundler-runtime';
|
|
218
201
|
// import instantiatePatch from "./federation.js";
|
|
@@ -394,7 +377,6 @@ const createContainer = (federationOptions) => {
|
|
|
394
377
|
const __webpack_exports__moduleMap = __webpack_exports__.moduleMap;
|
|
395
378
|
return __webpack_exports__;
|
|
396
379
|
}`;
|
|
397
|
-
|
|
398
380
|
const buildContainerHost = (config)=>{
|
|
399
381
|
const { name, remotes = {}, shared = {}, exposes = {} } = config;
|
|
400
382
|
const remoteConfigs = Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
@@ -405,7 +387,7 @@ const buildContainerHost = (config)=>{
|
|
|
405
387
|
}));
|
|
406
388
|
const sharedConfig = Object.entries(shared).reduce((acc, [pkg, config])=>{
|
|
407
389
|
var _config_requiredVersion;
|
|
408
|
-
const version = ((_config_requiredVersion = config.requiredVersion)
|
|
390
|
+
const version = (null == (_config_requiredVersion = config.requiredVersion) ? void 0 : _config_requiredVersion.replace(/^[^0-9]/, '')) || '';
|
|
409
391
|
acc += `${JSON.stringify(pkg)}: {
|
|
410
392
|
"package": "${pkg}",
|
|
411
393
|
"version": "${version}",
|
|
@@ -492,7 +474,6 @@ const buildContainerHost = (config)=>{
|
|
|
492
474
|
export const get = createdContainer.get;
|
|
493
475
|
export const init = createdContainer.init;
|
|
494
476
|
`;
|
|
495
|
-
//replace with createContainer from bundler runtime - import it in the string as a dep etc
|
|
496
477
|
return [
|
|
497
478
|
createContainerCode,
|
|
498
479
|
injectedContent
|
|
@@ -532,7 +513,7 @@ const createContainerPlugin = (config)=>({
|
|
|
532
513
|
build.onResolve({
|
|
533
514
|
filter: sharedExternals
|
|
534
515
|
}, (args)=>{
|
|
535
|
-
if (
|
|
516
|
+
if ('esm-shares' === args.namespace) return null;
|
|
536
517
|
return {
|
|
537
518
|
path: args.path,
|
|
538
519
|
namespace: 'virtual-share-module',
|
|
@@ -546,17 +527,14 @@ const createContainerPlugin = (config)=>({
|
|
|
546
527
|
filter: /.*/,
|
|
547
528
|
namespace: 'esm-shares'
|
|
548
529
|
}, async (args)=>{
|
|
549
|
-
if (sharedExternals.test(args.path)) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
return undefined;
|
|
530
|
+
if (sharedExternals.test(args.path)) return {
|
|
531
|
+
path: args.path,
|
|
532
|
+
namespace: 'virtual-share-module',
|
|
533
|
+
pluginData: {
|
|
534
|
+
kind: args.kind,
|
|
535
|
+
resolveDir: args.resolveDir
|
|
536
|
+
}
|
|
537
|
+
};
|
|
560
538
|
});
|
|
561
539
|
}
|
|
562
540
|
build.onLoad({
|
|
@@ -569,8 +547,6 @@ const createContainerPlugin = (config)=>({
|
|
|
569
547
|
}));
|
|
570
548
|
}
|
|
571
549
|
});
|
|
572
|
-
|
|
573
|
-
// Builds the federation host code
|
|
574
550
|
const buildFederationHost = (config)=>{
|
|
575
551
|
const { name, remotes, shared } = config;
|
|
576
552
|
const remoteConfigs = remotes ? JSON.stringify(Object.entries(remotes).map(([remoteAlias, remote])=>({
|
|
@@ -579,9 +555,9 @@ const buildFederationHost = (config)=>{
|
|
|
579
555
|
alias: remoteAlias,
|
|
580
556
|
type: 'esm'
|
|
581
557
|
}))) : '[]';
|
|
582
|
-
const sharedConfig = Object.entries(shared
|
|
558
|
+
const sharedConfig = Object.entries(shared ?? {}).reduce((acc, [pkg, config])=>{
|
|
583
559
|
var _config_requiredVersion;
|
|
584
|
-
const version = ((_config_requiredVersion = config.requiredVersion)
|
|
560
|
+
const version = (null == (_config_requiredVersion = config.requiredVersion) ? void 0 : _config_requiredVersion.replace(/^[^0-9]/, '')) || '';
|
|
585
561
|
acc += `${JSON.stringify(pkg)}: {
|
|
586
562
|
"package": "${pkg}",
|
|
587
563
|
"version": "${version}",
|
|
@@ -682,33 +658,25 @@ const initializeHostPlugin = (config)=>({
|
|
|
682
658
|
contents: buildFederationHost(config),
|
|
683
659
|
resolveDir: args.pluginData.resolveDir
|
|
684
660
|
}));
|
|
685
|
-
// Add custom loaders
|
|
686
661
|
const loaders = build.initialOptions.loader || {};
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
};
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
// Fallback loader for files not matched by custom loaders
|
|
662
|
+
for (const [ext, loader] of Object.entries(loaders))build.onLoad({
|
|
663
|
+
filter: new RegExp(`\\${ext}$`),
|
|
664
|
+
namespace: 'file'
|
|
665
|
+
}, async (args)=>{
|
|
666
|
+
const contents = await fs_0.promises.readFile(args.path, 'utf8');
|
|
667
|
+
return {
|
|
668
|
+
contents: buildFederationHost(config) + contents,
|
|
669
|
+
loader
|
|
670
|
+
};
|
|
671
|
+
});
|
|
701
672
|
const fallbackFilter = new RegExp(Object.keys(loaders).map((ext)=>`\\${ext}$`).join('|'));
|
|
702
673
|
build.onLoad({
|
|
703
674
|
filter: /.*\.(ts|js|mjs)$/,
|
|
704
675
|
namespace: 'file'
|
|
705
|
-
},
|
|
706
|
-
async (args)=>{
|
|
676
|
+
}, async (args)=>{
|
|
707
677
|
if (!fallbackFilter.test(args.path)) {
|
|
708
|
-
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e)))
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
const contents = await fs__default.promises.readFile(args.path, 'utf8');
|
|
678
|
+
if (!build.initialOptions.entryPoints.some((e)=>args.path.includes(e))) return;
|
|
679
|
+
const contents = await fs_0.promises.readFile(args.path, 'utf8');
|
|
712
680
|
return {
|
|
713
681
|
contents: 'import "federation-host"; \n ' + contents
|
|
714
682
|
};
|
|
@@ -716,9 +684,7 @@ const initializeHostPlugin = (config)=>({
|
|
|
716
684
|
});
|
|
717
685
|
}
|
|
718
686
|
});
|
|
719
|
-
|
|
720
|
-
// relys on import map since i dont know the named exports of a remote to return.
|
|
721
|
-
const createVirtualRemoteModule$1 = (name, ref)=>`
|
|
687
|
+
const createVirtualRemoteModule = (name, ref)=>`
|
|
722
688
|
export * from ${JSON.stringify('federationRemote/' + ref)}
|
|
723
689
|
`;
|
|
724
690
|
const linkRemotesPlugin = (config)=>({
|
|
@@ -732,42 +698,34 @@ const linkRemotesPlugin = (config)=>({
|
|
|
732
698
|
}, []).join('|'));
|
|
733
699
|
build.onResolve({
|
|
734
700
|
filter: filter
|
|
735
|
-
}, async (args)=>{
|
|
736
|
-
return {
|
|
701
|
+
}, async (args)=>({
|
|
737
702
|
path: args.path,
|
|
738
703
|
namespace: 'remote-module'
|
|
739
|
-
};
|
|
740
|
-
});
|
|
704
|
+
}));
|
|
741
705
|
build.onResolve({
|
|
742
706
|
filter: /^federationRemote/
|
|
743
|
-
}, async (args)=>{
|
|
744
|
-
return {
|
|
707
|
+
}, async (args)=>({
|
|
745
708
|
path: args.path.replace('federationRemote/', ''),
|
|
746
709
|
external: true,
|
|
747
710
|
namespace: 'externals'
|
|
748
|
-
};
|
|
749
|
-
});
|
|
711
|
+
}));
|
|
750
712
|
build.onLoad({
|
|
751
713
|
filter,
|
|
752
714
|
namespace: 'remote-module'
|
|
753
|
-
}, async (args)=>{
|
|
754
|
-
|
|
755
|
-
contents: createVirtualRemoteModule$1(config.name, args.path),
|
|
715
|
+
}, async (args)=>({
|
|
716
|
+
contents: createVirtualRemoteModule(config.name, args.path),
|
|
756
717
|
loader: 'js',
|
|
757
|
-
resolveDir:
|
|
758
|
-
};
|
|
759
|
-
});
|
|
718
|
+
resolveDir: path_0.dirname(args.path)
|
|
719
|
+
}));
|
|
760
720
|
}
|
|
761
721
|
});
|
|
762
|
-
|
|
763
|
-
// simplified from acorn (MIT license)
|
|
764
722
|
function isNewLine(code) {
|
|
765
|
-
return
|
|
723
|
+
return 10 === code || 13 === code || 0x2028 === code || 0x2029 === code;
|
|
766
724
|
}
|
|
767
725
|
function codePointToString(ch) {
|
|
768
726
|
if (ch <= 0xffff) return String.fromCharCode(ch);
|
|
769
727
|
ch -= 0x10000;
|
|
770
|
-
return String.fromCharCode((ch >> 10) + 0xd800, (
|
|
728
|
+
return String.fromCharCode((ch >> 10) + 0xd800, (0x03ff & ch) + 0xdc00);
|
|
771
729
|
}
|
|
772
730
|
class Lexer {
|
|
773
731
|
readString(input, pos) {
|
|
@@ -775,18 +733,17 @@ class Lexer {
|
|
|
775
733
|
this.input = input;
|
|
776
734
|
this.pos = pos;
|
|
777
735
|
const quote = this.input.charCodeAt(pos);
|
|
778
|
-
if (!(
|
|
736
|
+
if (!(34 === quote || 39 === quote)) return null;
|
|
779
737
|
let out = '';
|
|
780
738
|
let chunkStart = ++this.pos;
|
|
781
|
-
//eslint-disable-next-line no-constant-condition
|
|
782
739
|
while(true){
|
|
783
740
|
if (this.pos >= this.input.length) return null;
|
|
784
741
|
const ch = this.input.charCodeAt(this.pos);
|
|
785
742
|
if (ch === quote) break;
|
|
786
|
-
if (
|
|
743
|
+
if (92 === ch) {
|
|
787
744
|
out += this.input.slice(chunkStart, this.pos);
|
|
788
745
|
const escaped = this.readEscapedChar();
|
|
789
|
-
if (
|
|
746
|
+
if (null === escaped) return null;
|
|
790
747
|
out += escaped;
|
|
791
748
|
chunkStart = this.pos;
|
|
792
749
|
} else {
|
|
@@ -808,11 +765,11 @@ class Lexer {
|
|
|
808
765
|
return '\r';
|
|
809
766
|
case 120:
|
|
810
767
|
code = this.readHexChar(2);
|
|
811
|
-
if (
|
|
768
|
+
if (null === code) return null;
|
|
812
769
|
return String.fromCharCode(code);
|
|
813
770
|
case 117:
|
|
814
771
|
code = this.readCodePoint();
|
|
815
|
-
if (
|
|
772
|
+
if (null === code) return null;
|
|
816
773
|
return codePointToString(code);
|
|
817
774
|
case 116:
|
|
818
775
|
return '\t';
|
|
@@ -822,12 +779,8 @@ class Lexer {
|
|
|
822
779
|
return '\u000b';
|
|
823
780
|
case 102:
|
|
824
781
|
return '\f';
|
|
825
|
-
//@ts-ignore
|
|
826
782
|
case 13:
|
|
827
|
-
if (this.input.charCodeAt(this.pos)
|
|
828
|
-
++this.pos;
|
|
829
|
-
}
|
|
830
|
-
// fall through
|
|
783
|
+
if (10 === this.input.charCodeAt(this.pos)) ++this.pos;
|
|
831
784
|
case 10:
|
|
832
785
|
return '';
|
|
833
786
|
case 56:
|
|
@@ -836,7 +789,7 @@ class Lexer {
|
|
|
836
789
|
default:
|
|
837
790
|
if (ch >= 48 && ch <= 55) {
|
|
838
791
|
const match = this.input.slice(this.pos - 1, this.pos + 2).match(/^[0-7]+/);
|
|
839
|
-
if (
|
|
792
|
+
if (null === match) return null;
|
|
840
793
|
let octalStr = match[0];
|
|
841
794
|
let octal = parseInt(octalStr, 8);
|
|
842
795
|
if (octal > 255) {
|
|
@@ -845,7 +798,7 @@ class Lexer {
|
|
|
845
798
|
}
|
|
846
799
|
this.pos += octalStr.length - 1;
|
|
847
800
|
const nextCh = this.input.charCodeAt(this.pos);
|
|
848
|
-
if (
|
|
801
|
+
if ('0' !== octalStr || 56 === nextCh || 57 === nextCh) return null;
|
|
849
802
|
return String.fromCharCode(octal);
|
|
850
803
|
}
|
|
851
804
|
if (isNewLine(ch)) return '';
|
|
@@ -858,19 +811,11 @@ class Lexer {
|
|
|
858
811
|
for(let i = 0; i < len; ++i, ++this.pos){
|
|
859
812
|
const code = this.input.charCodeAt(this.pos);
|
|
860
813
|
let val;
|
|
861
|
-
|
|
862
|
-
val = code - 97 + 10;
|
|
863
|
-
} else if (code >= 65) {
|
|
864
|
-
val = code - 65 + 10;
|
|
865
|
-
} else if (code >= 48 && code <= 57) {
|
|
866
|
-
val = code - 48;
|
|
867
|
-
} else {
|
|
868
|
-
val = Infinity;
|
|
869
|
-
}
|
|
814
|
+
val = code >= 97 ? code - 97 + 10 : code >= 65 ? code - 65 + 10 : code >= 48 && code <= 57 ? code - 48 : 1 / 0;
|
|
870
815
|
if (val >= radix) break;
|
|
871
816
|
total = total * radix + val;
|
|
872
817
|
}
|
|
873
|
-
if (this.pos === start ||
|
|
818
|
+
if (this.pos === start || null != len && this.pos - start !== len) return null;
|
|
874
819
|
return total;
|
|
875
820
|
}
|
|
876
821
|
readHexChar(len) {
|
|
@@ -879,14 +824,12 @@ class Lexer {
|
|
|
879
824
|
readCodePoint() {
|
|
880
825
|
const ch = this.input.charCodeAt(this.pos);
|
|
881
826
|
let code;
|
|
882
|
-
if (
|
|
827
|
+
if (123 === ch) {
|
|
883
828
|
++this.pos;
|
|
884
829
|
code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos);
|
|
885
830
|
++this.pos;
|
|
886
831
|
if (code && code > 0x10ffff) return null;
|
|
887
|
-
} else
|
|
888
|
-
code = this.readHexChar(4);
|
|
889
|
-
}
|
|
832
|
+
} else code = this.readHexChar(4);
|
|
890
833
|
return code;
|
|
891
834
|
}
|
|
892
835
|
constructor(){
|
|
@@ -894,15 +837,12 @@ class Lexer {
|
|
|
894
837
|
this.pos = 0;
|
|
895
838
|
}
|
|
896
839
|
}
|
|
897
|
-
|
|
898
840
|
function orderedUniq(array) {
|
|
899
|
-
// prettier-ignore
|
|
900
841
|
const ret = [], visited = new Set();
|
|
901
842
|
for (const val of array)if (!visited.has(val)) visited.add(val), ret.push(val);
|
|
902
843
|
return ret;
|
|
903
844
|
}
|
|
904
845
|
function cachedReduce(array, reducer, s) {
|
|
905
|
-
// prettier-ignore
|
|
906
846
|
const cache = [
|
|
907
847
|
s
|
|
908
848
|
];
|
|
@@ -912,31 +852,26 @@ function cachedReduce(array, reducer, s) {
|
|
|
912
852
|
return cache[len];
|
|
913
853
|
};
|
|
914
854
|
}
|
|
915
|
-
// from @rollup/pluginutils
|
|
916
855
|
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
|
|
917
856
|
const builtin = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
|
|
918
857
|
const forbiddenIdentifiers = new Set(`${reservedWords} ${builtin}`.split(' '));
|
|
919
858
|
forbiddenIdentifiers.add('');
|
|
920
|
-
const
|
|
859
|
+
const utils_makeLegalIdentifier = function(str) {
|
|
921
860
|
let identifier = str.replace(/-(\w)/g, (_, letter)=>letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
922
|
-
if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) {
|
|
923
|
-
identifier = `_${identifier}`;
|
|
924
|
-
}
|
|
861
|
+
if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) identifier = `_${identifier}`;
|
|
925
862
|
return identifier || '_';
|
|
926
863
|
};
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
const
|
|
930
|
-
const
|
|
931
|
-
const is_ignored = typeof ignore === 'function' ? ignore : Array.isArray(ignore) ? (path)=>ignore.includes(path) : ()=>false;
|
|
864
|
+
function commonjs_commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requireReturnsDefault = true, ignore } = {}) {
|
|
865
|
+
const init_cjs_module_lexer = transform ? import("cjs-module-lexer") : void 0;
|
|
866
|
+
const use_default_export = 'function' == typeof requireReturnsDefault ? requireReturnsDefault : (_path)=>requireReturnsDefault;
|
|
867
|
+
const is_ignored = 'function' == typeof ignore ? ignore : Array.isArray(ignore) ? (path)=>ignore.includes(path) : ()=>false;
|
|
932
868
|
return {
|
|
933
869
|
name: 'commonjs',
|
|
934
870
|
setup ({ onLoad, esbuild, initialOptions }) {
|
|
935
871
|
let esbuild_shim;
|
|
936
|
-
const require_esbuild = ()=>esbuild ||
|
|
872
|
+
const require_esbuild = ()=>esbuild || (esbuild_shim ||= __webpack_require__("esbuild"));
|
|
937
873
|
const read = promises.readFile;
|
|
938
874
|
const lexer = new Lexer();
|
|
939
|
-
//@ts-ignore
|
|
940
875
|
onLoad({
|
|
941
876
|
filter: filter
|
|
942
877
|
}, async (args)=>{
|
|
@@ -948,60 +883,43 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
948
883
|
}
|
|
949
884
|
let contents;
|
|
950
885
|
try {
|
|
951
|
-
//@ts-ignore
|
|
952
886
|
contents = await read(args.path, 'utf8');
|
|
953
|
-
} catch
|
|
887
|
+
} catch {
|
|
954
888
|
return null;
|
|
955
889
|
}
|
|
956
|
-
const willTransform =
|
|
890
|
+
const willTransform = true === transform || 'function' == typeof transform && transform(args.path);
|
|
957
891
|
let cjsExports;
|
|
958
892
|
try {
|
|
959
893
|
if (parseCJS && willTransform) {
|
|
960
|
-
// move sourcemap to the end of the transformed file
|
|
961
894
|
const sourcemapIndex = contents.lastIndexOf('//# sourceMappingURL=');
|
|
962
895
|
let sourcemap;
|
|
963
|
-
if (
|
|
896
|
+
if (-1 !== sourcemapIndex) {
|
|
964
897
|
sourcemap = contents.slice(sourcemapIndex);
|
|
965
898
|
const sourcemapEnd = sourcemap.indexOf('\n');
|
|
966
|
-
if (
|
|
967
|
-
|
|
968
|
-
sourcemap = undefined;
|
|
969
|
-
} else {
|
|
970
|
-
contents = contents.slice(0, sourcemapIndex);
|
|
971
|
-
}
|
|
899
|
+
if (-1 !== sourcemapEnd && sourcemap.slice(sourcemapEnd + 1).trimStart().length > 0) sourcemap = void 0;
|
|
900
|
+
else contents = contents.slice(0, sourcemapIndex);
|
|
972
901
|
}
|
|
973
|
-
// transform commonjs to es modules, easy mode
|
|
974
902
|
cjsExports = parseCJS(contents);
|
|
975
|
-
let { behavior, exports, sideEffects } = typeof willTransform
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
sideEffects != null ? sideEffects : sideEffects = (_transformConfig_sideEffects = transformConfig == null ? void 0 : transformConfig.sideEffects) != null ? _transformConfig_sideEffects : true;
|
|
981
|
-
let exportDefault = behavior === 'node' ? 'export default exports;' : 'export default exports.__esModule ? exports.default : exports;';
|
|
903
|
+
let { behavior, exports, sideEffects } = 'object' == typeof willTransform ? willTransform : {};
|
|
904
|
+
behavior ??= (null == transformConfig ? void 0 : transformConfig.behavior) ?? 'node';
|
|
905
|
+
exports = orderedUniq(cjsExports.exports.concat(exports ?? []));
|
|
906
|
+
sideEffects ??= (null == transformConfig ? void 0 : transformConfig.sideEffects) ?? true;
|
|
907
|
+
let exportDefault = 'node' === behavior ? 'export default exports;' : 'export default exports.__esModule ? exports.default : exports;';
|
|
982
908
|
let exportsMap = exports.map((e)=>[
|
|
983
909
|
e,
|
|
984
|
-
|
|
910
|
+
utils_makeLegalIdentifier(e)
|
|
985
911
|
]);
|
|
986
|
-
if (exportsMap.some(([e])=>e === 'default')
|
|
987
|
-
|
|
988
|
-
exportsMap = exportsMap.filter(([e])=>e !== 'default');
|
|
989
|
-
} else {
|
|
990
|
-
exportDefault = '';
|
|
991
|
-
}
|
|
992
|
-
}
|
|
912
|
+
if (exportsMap.some(([e])=>'default' === e)) if ('node' === behavior) exportsMap = exportsMap.filter(([e])=>'default' !== e);
|
|
913
|
+
else exportDefault = '';
|
|
993
914
|
const reexports = cjsExports.reexports.map((e)=>`export * from ${JSON.stringify(e)};`).join('');
|
|
994
915
|
let transformed;
|
|
995
|
-
if (
|
|
916
|
+
if (false === sideEffects) {
|
|
996
917
|
transformed = [
|
|
997
|
-
// make sure we don't manipulate the first line so that sourcemap is fine
|
|
998
918
|
reexports + 'var mod, exports = /* @__PURE__ */ ((exports, module) => {' + contents,
|
|
999
919
|
'return module.exports})((mod = { exports: {} }).exports, mod); ' + exportDefault
|
|
1000
920
|
];
|
|
1001
921
|
if (exportsMap.length > 0) {
|
|
1002
|
-
for (const [e, name] of exportsMap){
|
|
1003
|
-
transformed.push(`var ${name} = /* @__PURE__ */ (() => exports[${JSON.stringify(e)}])();`);
|
|
1004
|
-
}
|
|
922
|
+
for (const [e, name] of exportsMap)transformed.push(`var ${name} = /* @__PURE__ */ (() => exports[${JSON.stringify(e)}])();`);
|
|
1005
923
|
transformed.push(`export { ${exportsMap.map(([e, name])=>e === name ? e : `${name} as ${JSON.stringify(e)}`).join(', ')} };`);
|
|
1006
924
|
}
|
|
1007
925
|
} else {
|
|
@@ -1009,9 +927,7 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
1009
927
|
reexports + 'var exports = {}, module = { exports }; {' + contents,
|
|
1010
928
|
'}; exports = module.exports; ' + exportDefault
|
|
1011
929
|
];
|
|
1012
|
-
if (exportsMap.length > 0) {
|
|
1013
|
-
transformed.push(`var { ${exportsMap.map(([e, name])=>e === name ? e : `${JSON.stringify(e)}: ${name}`).join(', ')} } = exports;`, `export { ${exportsMap.map(([e, name])=>e === name ? e : `${name} as ${JSON.stringify(e)}`).join(', ')} };`);
|
|
1014
|
-
}
|
|
930
|
+
if (exportsMap.length > 0) transformed.push(`var { ${exportsMap.map(([e, name])=>e === name ? e : `${JSON.stringify(e)}: ${name}`).join(', ')} } = exports;`, `export { ${exportsMap.map(([e, name])=>e === name ? e : `${name} as ${JSON.stringify(e)}`).join(', ')} };`);
|
|
1015
931
|
}
|
|
1016
932
|
contents = transformed.join('\n') + (sourcemap ? '\n' + sourcemap : '');
|
|
1017
933
|
}
|
|
@@ -1019,7 +935,7 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
1019
935
|
return null;
|
|
1020
936
|
}
|
|
1021
937
|
function makeName(path) {
|
|
1022
|
-
let name = `__import_${
|
|
938
|
+
let name = `__import_${utils_makeLegalIdentifier(path)}`;
|
|
1023
939
|
if (contents.includes(name)) {
|
|
1024
940
|
let suffix = 2;
|
|
1025
941
|
while(contents.includes(`${name}${suffix}`))suffix++;
|
|
@@ -1042,19 +958,15 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
1042
958
|
const edits = [];
|
|
1043
959
|
let imports = [];
|
|
1044
960
|
for (const { location } of warnings){
|
|
1045
|
-
if (
|
|
961
|
+
if (null === location) continue;
|
|
1046
962
|
const { line, lineText, column, length } = location;
|
|
1047
963
|
const leftBrace = column + length + 1;
|
|
1048
964
|
const path = lexer.readString(lineText, leftBrace);
|
|
1049
|
-
if (
|
|
965
|
+
if (null === path || is_ignored(path)) continue;
|
|
1050
966
|
const rightBrace = lineText.indexOf(')', leftBrace + 2 + path.length) + 1;
|
|
1051
967
|
const name = makeName(path);
|
|
1052
968
|
let import_statement;
|
|
1053
|
-
|
|
1054
|
-
import_statement = `import ${name} from ${JSON.stringify(path)};`;
|
|
1055
|
-
} else {
|
|
1056
|
-
import_statement = `import * as ${name} from ${JSON.stringify(path)};`;
|
|
1057
|
-
}
|
|
969
|
+
import_statement = use_default_export(path) ? `import ${name} from ${JSON.stringify(path)};` : `import * as ${name} from ${JSON.stringify(path)};`;
|
|
1058
970
|
const offset = getOffset(line - 1);
|
|
1059
971
|
edits.push([
|
|
1060
972
|
offset + column,
|
|
@@ -1063,14 +975,13 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
1063
975
|
]);
|
|
1064
976
|
imports.push(import_statement);
|
|
1065
977
|
}
|
|
1066
|
-
if (imports.length
|
|
978
|
+
if (0 === imports.length) return null;
|
|
1067
979
|
imports = orderedUniq(imports);
|
|
1068
980
|
let offset = 0;
|
|
1069
981
|
for (const [start, end, name] of edits){
|
|
1070
982
|
contents = contents.slice(0, start + offset) + name + contents.slice(end + offset);
|
|
1071
983
|
offset += name.length - (end - start);
|
|
1072
984
|
}
|
|
1073
|
-
// if we have transformed this module (i.e. having `cjsExports`), don't make the file commonjs
|
|
1074
985
|
contents = [
|
|
1075
986
|
...imports,
|
|
1076
987
|
cjsExports ? 'exports;' : '',
|
|
@@ -1084,33 +995,31 @@ function commonjs({ filter = /\.c?js$/, transform = true, transformConfig, requi
|
|
|
1084
995
|
}
|
|
1085
996
|
};
|
|
1086
997
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
return
|
|
998
|
+
function getExternals(config) {
|
|
999
|
+
const shared = Object.keys(config.shared ?? {});
|
|
1000
|
+
const remotes = config.remotes ?? {};
|
|
1001
|
+
const remoteKeys = Object.keys(remotes).reduce((acc, key)=>{
|
|
1002
|
+
if (!key) return acc;
|
|
1003
|
+
acc.push(key);
|
|
1004
|
+
acc.push(key + '/*');
|
|
1005
|
+
return acc;
|
|
1006
|
+
}, []);
|
|
1007
|
+
const externals = [
|
|
1008
|
+
...shared,
|
|
1009
|
+
...remoteKeys
|
|
1010
|
+
];
|
|
1011
|
+
return externals;
|
|
1101
1012
|
}
|
|
1102
|
-
// Creates a virtual module for sharing dependencies
|
|
1103
1013
|
const createVirtualShareModule = (name, ref, exports)=>`
|
|
1104
1014
|
const container = __FEDERATION__.__INSTANCES__.find(container => container.name === ${JSON.stringify(name)}) || __FEDERATION__.__INSTANCES__[0]
|
|
1105
1015
|
|
|
1106
1016
|
const mfLsZJ92 = await container.loadShare(${JSON.stringify(ref)})
|
|
1107
1017
|
|
|
1108
|
-
${exports.map((e)=>
|
|
1018
|
+
${exports.map((e)=>'default' === e ? "export default mfLsZJ92.default" : `export const ${e} = mfLsZJ92[${JSON.stringify(e)}];`).join('\n')}
|
|
1109
1019
|
`;
|
|
1110
|
-
const
|
|
1020
|
+
const plugin_createVirtualRemoteModule = (name, ref)=>`
|
|
1111
1021
|
export * from ${JSON.stringify('federationRemote/' + ref)}
|
|
1112
1022
|
`;
|
|
1113
|
-
// Plugin to transform CommonJS modules to ESM
|
|
1114
1023
|
const cjsToEsmPlugin = {
|
|
1115
1024
|
name: 'cjs-to-esm',
|
|
1116
1025
|
setup (build) {
|
|
@@ -1120,9 +1029,10 @@ const cjsToEsmPlugin = {
|
|
|
1120
1029
|
}, async (args)=>{
|
|
1121
1030
|
var _build_initialOptions_external;
|
|
1122
1031
|
let esbuild_shim;
|
|
1123
|
-
const require_esbuild = ()=>build.esbuild ||
|
|
1124
|
-
const packageBuilder = await require_esbuild().build(
|
|
1125
|
-
|
|
1032
|
+
const require_esbuild = ()=>build.esbuild || (esbuild_shim ||= __webpack_require__("esbuild"));
|
|
1033
|
+
const packageBuilder = await require_esbuild().build({
|
|
1034
|
+
...build.initialOptions,
|
|
1035
|
+
external: null == (_build_initialOptions_external = build.initialOptions.external) ? void 0 : _build_initialOptions_external.filter((e)=>{
|
|
1126
1036
|
if (e.includes('*')) {
|
|
1127
1037
|
const prefix = e.split('*')[0];
|
|
1128
1038
|
return !args.path.startsWith(prefix);
|
|
@@ -1133,12 +1043,12 @@ const cjsToEsmPlugin = {
|
|
|
1133
1043
|
args.path
|
|
1134
1044
|
],
|
|
1135
1045
|
plugins: [
|
|
1136
|
-
|
|
1046
|
+
commonjs_commonjs({
|
|
1137
1047
|
filter: /.*/
|
|
1138
1048
|
})
|
|
1139
1049
|
],
|
|
1140
1050
|
write: false
|
|
1141
|
-
})
|
|
1051
|
+
});
|
|
1142
1052
|
return {
|
|
1143
1053
|
contents: packageBuilder.outputFiles[0].text,
|
|
1144
1054
|
loader: 'js',
|
|
@@ -1147,7 +1057,6 @@ const cjsToEsmPlugin = {
|
|
|
1147
1057
|
});
|
|
1148
1058
|
}
|
|
1149
1059
|
};
|
|
1150
|
-
// Plugin to link shared dependencies
|
|
1151
1060
|
const linkSharedPlugin = (config)=>({
|
|
1152
1061
|
name: 'linkShared',
|
|
1153
1062
|
setup (build) {
|
|
@@ -1155,7 +1064,7 @@ const linkSharedPlugin = (config)=>({
|
|
|
1155
1064
|
build.onResolve({
|
|
1156
1065
|
filter
|
|
1157
1066
|
}, (args)=>{
|
|
1158
|
-
if (
|
|
1067
|
+
if ('esm-shares' === args.namespace) return null;
|
|
1159
1068
|
return {
|
|
1160
1069
|
path: args.path,
|
|
1161
1070
|
namespace: 'virtual-share-module',
|
|
@@ -1169,27 +1078,22 @@ const linkSharedPlugin = (config)=>({
|
|
|
1169
1078
|
filter: /.*/,
|
|
1170
1079
|
namespace: 'esm-shares'
|
|
1171
1080
|
}, (args)=>{
|
|
1172
|
-
if (filter.test(args.path)) {
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
resolveDir: args.resolveDir
|
|
1189
|
-
}
|
|
1190
|
-
};
|
|
1191
|
-
}
|
|
1192
|
-
return undefined;
|
|
1081
|
+
if (filter.test(args.path)) return {
|
|
1082
|
+
path: args.path,
|
|
1083
|
+
namespace: 'virtual-share-module',
|
|
1084
|
+
pluginData: {
|
|
1085
|
+
kind: args.kind,
|
|
1086
|
+
resolveDir: args.resolveDir
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
if (filter.test(args.importer)) return {
|
|
1090
|
+
path: args.path,
|
|
1091
|
+
namespace: 'esm-shares',
|
|
1092
|
+
pluginData: {
|
|
1093
|
+
kind: args.kind,
|
|
1094
|
+
resolveDir: args.resolveDir
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1193
1097
|
});
|
|
1194
1098
|
build.onResolve({
|
|
1195
1099
|
filter: /^federationShare/
|
|
@@ -1209,53 +1113,37 @@ const linkSharedPlugin = (config)=>({
|
|
|
1209
1113
|
return {
|
|
1210
1114
|
contents: createVirtualShareModule(config.name, args.path, exp),
|
|
1211
1115
|
loader: 'js',
|
|
1212
|
-
resolveDir:
|
|
1116
|
+
resolveDir: path_0.dirname(args.path)
|
|
1213
1117
|
};
|
|
1214
1118
|
});
|
|
1215
1119
|
}
|
|
1216
1120
|
});
|
|
1217
|
-
// Main module federation plugin
|
|
1218
1121
|
const moduleFederationPlugin = (config)=>({
|
|
1219
1122
|
name: 'module-federation',
|
|
1220
1123
|
setup (build) {
|
|
1221
1124
|
build.initialOptions.metafile = true;
|
|
1222
1125
|
const externals = getExternals(config);
|
|
1223
|
-
if (build.initialOptions.external)
|
|
1224
|
-
|
|
1225
|
-
...
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
} else {
|
|
1231
|
-
build.initialOptions.external = externals;
|
|
1232
|
-
}
|
|
1126
|
+
if (build.initialOptions.external) build.initialOptions.external = [
|
|
1127
|
+
...new Set([
|
|
1128
|
+
...build.initialOptions.external,
|
|
1129
|
+
...externals
|
|
1130
|
+
])
|
|
1131
|
+
];
|
|
1132
|
+
else build.initialOptions.external = externals;
|
|
1233
1133
|
const pluginStack = [];
|
|
1234
1134
|
const remotes = Object.keys(config.remotes || {}).length;
|
|
1235
1135
|
const shared = Object.keys(config.shared || {}).length;
|
|
1236
1136
|
const exposes = Object.keys(config.exposes || {}).length;
|
|
1237
1137
|
const entryPoints = build.initialOptions.entryPoints;
|
|
1238
1138
|
const filename = config.filename || 'remoteEntry.js';
|
|
1239
|
-
if (remotes)
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
}
|
|
1248
|
-
if (exposes) {
|
|
1249
|
-
if (Array.isArray(entryPoints)) {
|
|
1250
|
-
entryPoints.push(filename);
|
|
1251
|
-
} else if (entryPoints && typeof entryPoints === 'object') {
|
|
1252
|
-
entryPoints[filename] = filename;
|
|
1253
|
-
} else {
|
|
1254
|
-
build.initialOptions.entryPoints = [
|
|
1255
|
-
filename
|
|
1256
|
-
];
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1139
|
+
if (remotes) pluginStack.push(linkRemotesPlugin(config));
|
|
1140
|
+
if (shared) pluginStack.push(linkSharedPlugin(config));
|
|
1141
|
+
if (!entryPoints) build.initialOptions.entryPoints = [];
|
|
1142
|
+
if (exposes) if (Array.isArray(entryPoints)) entryPoints.push(filename);
|
|
1143
|
+
else if (entryPoints && 'object' == typeof entryPoints) entryPoints[filename] = filename;
|
|
1144
|
+
else build.initialOptions.entryPoints = [
|
|
1145
|
+
filename
|
|
1146
|
+
];
|
|
1259
1147
|
[
|
|
1260
1148
|
initializeHostPlugin(config),
|
|
1261
1149
|
createContainerPlugin(config),
|
|
@@ -1269,34 +1157,29 @@ const moduleFederationPlugin = (config)=>({
|
|
|
1269
1157
|
const remoteFile = config.filename;
|
|
1270
1158
|
const exposedEntries = {};
|
|
1271
1159
|
const outputMapWithoutExt = Object.entries(result.metafile.outputs).reduce((acc, [chunkKey, chunkValue])=>{
|
|
1272
|
-
//@ts-ignore
|
|
1273
1160
|
const { entryPoint } = chunkValue;
|
|
1274
1161
|
const key = entryPoint || chunkKey;
|
|
1275
1162
|
const trimKey = key.substring(0, key.lastIndexOf('.')) || key;
|
|
1276
|
-
|
|
1277
|
-
|
|
1163
|
+
acc[trimKey] = {
|
|
1164
|
+
...chunkValue,
|
|
1278
1165
|
chunk: chunkKey
|
|
1279
|
-
}
|
|
1166
|
+
};
|
|
1280
1167
|
return acc;
|
|
1281
1168
|
}, {});
|
|
1282
1169
|
for (const [expose, value] of Object.entries(exposedConfig)){
|
|
1283
|
-
const exposedFound =
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
entryPoint: exposedFound.entryPoint,
|
|
1289
|
-
exports: exposedFound.exports
|
|
1290
|
-
};
|
|
1291
|
-
}
|
|
1170
|
+
const exposedFound = outputMapWithoutExt[value.replace('./', '')] || outputMapWithoutExt[expose.replace('./', '')];
|
|
1171
|
+
if (exposedFound) exposedEntries[expose] = {
|
|
1172
|
+
entryPoint: exposedFound.entryPoint,
|
|
1173
|
+
exports: exposedFound.exports
|
|
1174
|
+
};
|
|
1292
1175
|
}
|
|
1293
1176
|
for (const [outputPath, value] of Object.entries(result.metafile.outputs)){
|
|
1294
1177
|
if (!value.entryPoint) continue;
|
|
1295
1178
|
if (!value.entryPoint.startsWith('container:')) continue;
|
|
1296
1179
|
if (!value.entryPoint.endsWith(remoteFile)) continue;
|
|
1297
|
-
const container =
|
|
1180
|
+
const container = fs_0.readFileSync(outputPath, 'utf-8');
|
|
1298
1181
|
const withExports = container.replace('"__MODULE_MAP__"', `${JSON.stringify(exposedEntries)}`).replace("'__MODULE_MAP__'", `${JSON.stringify(exposedEntries)}`);
|
|
1299
|
-
|
|
1182
|
+
fs_0.writeFileSync(outputPath, withExports, 'utf-8');
|
|
1300
1183
|
}
|
|
1301
1184
|
}
|
|
1302
1185
|
await writeRemoteManifest(config, result);
|
|
@@ -1304,6 +1187,4 @@ const moduleFederationPlugin = (config)=>({
|
|
|
1304
1187
|
});
|
|
1305
1188
|
}
|
|
1306
1189
|
});
|
|
1307
|
-
|
|
1308
|
-
export { createVirtualRemoteModule, createVirtualShareModule, moduleFederationPlugin };
|
|
1309
|
-
//# sourceMappingURL=plugin.esm.js.map
|
|
1190
|
+
export { plugin_createVirtualRemoteModule as createVirtualRemoteModule, createVirtualShareModule, moduleFederationPlugin };
|