@module-federation/esbuild 0.0.0-next-20240523224941
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/LICENSE +21 -0
- package/README.md +117 -0
- package/dist/build.cjs.d.ts +1 -0
- package/dist/build.cjs.js +450 -0
- package/dist/build.esm.js +389 -0
- package/dist/esbuild.cjs.d.ts +2 -0
- package/dist/esbuild.cjs.js +1117 -0
- package/dist/esbuild.esm.js +1086 -0
- package/dist/federation-builder.cjs.js +741 -0
- package/dist/federation-builder.esm.js +697 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +14 -0
- package/dist/index.esm.js +1 -0
- package/dist/package.json +68 -0
- package/dist/resolve/esm-resolver.mjs +19 -0
- package/dist/resolve/package.json +3 -0
- package/dist/src/adapters/lib/collect-exports.d.ts +11 -0
- package/dist/src/adapters/lib/containerPlugin.d.ts +5 -0
- package/dist/src/adapters/lib/containerReference.d.ts +5 -0
- package/dist/src/adapters/lib/linkRemotesPlugin.d.ts +5 -0
- package/dist/src/adapters/lib/manifest.d.ts +17 -0
- package/dist/src/adapters/lib/plugin.d.ts +7 -0
- package/dist/src/lib/core/createContainerTemplate.d.ts +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present zhouxiao(zhoushaw)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Here's an updated README.md that incorporates the plugin options and ensures they are met:
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# @module-federation/esbuild
|
|
5
|
+
|
|
6
|
+
This package provides an esbuild plugin for Module Federation, enabling you to easily share code between independently built and deployed applications.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Install the package using npm:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @module-federation/esbuild
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
To use the Module Federation plugin with esbuild, add it to your esbuild configuration:
|
|
19
|
+
|
|
20
|
+
```js
|
|
21
|
+
const esbuild = require('esbuild');
|
|
22
|
+
const path = require('path');
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const { moduleFederationPlugin } = require('@module-federation/esbuild/esbuild-adapter');
|
|
25
|
+
const { federationBuilder } = require('@module-federation/esbuild/build');
|
|
26
|
+
|
|
27
|
+
async function build() {
|
|
28
|
+
const tsConfig = 'tsconfig.json';
|
|
29
|
+
const outputPath = path.join('dist', 'host');
|
|
30
|
+
|
|
31
|
+
await federationBuilder.init({
|
|
32
|
+
options: {
|
|
33
|
+
workspaceRoot: path.join(__dirname, '..'),
|
|
34
|
+
outputPath,
|
|
35
|
+
tsConfig,
|
|
36
|
+
federationConfig: path.join('host', 'federation.config.js'),
|
|
37
|
+
verbose: false,
|
|
38
|
+
watch: false,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
await esbuild.build({
|
|
43
|
+
entryPoints: [path.join('host', 'main.ts')],
|
|
44
|
+
external: federationBuilder.externals,
|
|
45
|
+
outdir: outputPath,
|
|
46
|
+
bundle: true,
|
|
47
|
+
platform: 'browser',
|
|
48
|
+
format: 'esm',
|
|
49
|
+
mainFields: ['es2020', 'browser', 'module', 'main'],
|
|
50
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
51
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
52
|
+
tsconfig: tsConfig,
|
|
53
|
+
splitting: true,
|
|
54
|
+
plugins: [moduleFederationPlugin(federationBuilder)],
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
build().catch((err) => {
|
|
59
|
+
console.error(err);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Example of federation.config.js
|
|
64
|
+
|
|
65
|
+
const { withFederation, shareAll } = require('@module-federation/esbuild/build');
|
|
66
|
+
|
|
67
|
+
module.exports = withFederation({
|
|
68
|
+
name: 'host',
|
|
69
|
+
filename: 'remoteEntry.js',
|
|
70
|
+
exposes: {
|
|
71
|
+
'./Component': './src/Component',
|
|
72
|
+
},
|
|
73
|
+
shared: {
|
|
74
|
+
...shareAll({
|
|
75
|
+
singleton: true,
|
|
76
|
+
strictVersion: true,
|
|
77
|
+
requiredVersion: 'auto',
|
|
78
|
+
includeSecondaries: false,
|
|
79
|
+
}),
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The `moduleFederationPlugin` accepts a configuration object with the following properties:
|
|
86
|
+
|
|
87
|
+
- `name` (string): The name of the host application.
|
|
88
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
89
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
90
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
91
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
92
|
+
|
|
93
|
+
## Plugin Features
|
|
94
|
+
|
|
95
|
+
The `moduleFederationPlugin` includes the following features:
|
|
96
|
+
|
|
97
|
+
- **Virtual Share Module**: Creates a virtual module for sharing dependencies between the host and remote applications.
|
|
98
|
+
- **Virtual Remote Module**: Creates a virtual module for importing exposed modules from remote applications.
|
|
99
|
+
- **CommonJS to ESM Transformation**: Transforms CommonJS modules to ESM format for compatibility with Module Federation.
|
|
100
|
+
- **Shared Dependencies Linking**: Links shared dependencies between the host and remote applications.
|
|
101
|
+
- **Manifest Generation**: Generates a manifest file containing information about the exposed modules and their exports.
|
|
102
|
+
|
|
103
|
+
## API
|
|
104
|
+
|
|
105
|
+
### `moduleFederationPlugin(config)`
|
|
106
|
+
|
|
107
|
+
Creates an esbuild plugin for Module Federation.
|
|
108
|
+
|
|
109
|
+
- `config` (object): The Module Federation configuration.
|
|
110
|
+
- `name` (string): The name of the host application.
|
|
111
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
112
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
113
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
114
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
115
|
+
|
|
116
|
+
Returns an esbuild plugin instance.
|
|
117
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/build";
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var federationBuilder = require('./federation-builder.cjs.js');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
var fs = require('fs');
|
|
8
|
+
var process = require('process');
|
|
9
|
+
var JSON5 = require('json5');
|
|
10
|
+
var crypto = require('crypto');
|
|
11
|
+
require('npmlog');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n["default"] = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
34
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
35
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
36
|
+
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
37
|
+
var process__default = /*#__PURE__*/_interopDefaultLegacy(process);
|
|
38
|
+
var JSON5__namespace = /*#__PURE__*/_interopNamespace(JSON5);
|
|
39
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespace(crypto);
|
|
40
|
+
|
|
41
|
+
const DEFAULT_SKIP_LIST = [
|
|
42
|
+
'@module-federation/native-federation-runtime',
|
|
43
|
+
'@module-federation/native-federation',
|
|
44
|
+
'@module-federation/native-federation-core',
|
|
45
|
+
'@module-federation/native-federation-esbuild',
|
|
46
|
+
'@angular-architects/native-federation',
|
|
47
|
+
'@angular-architects/native-federation-runtime',
|
|
48
|
+
'es-module-shims',
|
|
49
|
+
'zone.js',
|
|
50
|
+
'tslib/',
|
|
51
|
+
'@angular/localize',
|
|
52
|
+
'@angular/localize/init',
|
|
53
|
+
'@angular/localize/tools',
|
|
54
|
+
'@angular/platform-server',
|
|
55
|
+
'@angular/platform-server/init',
|
|
56
|
+
'@angular/ssr',
|
|
57
|
+
'express',
|
|
58
|
+
/\/schematics(\/|$)/,
|
|
59
|
+
/^@nx\/angular/,
|
|
60
|
+
(pkg)=>pkg.startsWith('@angular/') && !!pkg.match(/\/testing(\/|$)/),
|
|
61
|
+
(pkg)=>pkg.startsWith('@types/')
|
|
62
|
+
];
|
|
63
|
+
const PREPARED_DEFAULT_SKIP_LIST = prepareSkipList(DEFAULT_SKIP_LIST);
|
|
64
|
+
function prepareSkipList(skipList) {
|
|
65
|
+
return {
|
|
66
|
+
strings: new Set(skipList.filter((e)=>typeof e === 'string')),
|
|
67
|
+
functions: skipList.filter((e)=>typeof e === 'function'),
|
|
68
|
+
regexps: skipList.filter((e)=>typeof e === 'object')
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function isInSkipList(entry, skipList) {
|
|
72
|
+
if (skipList.strings.has(entry)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (skipList.functions.find((f)=>f(entry))) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
if (skipList.regexps.find((r)=>r.test(entry))) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let inferVersion = false;
|
|
85
|
+
const DEFAULT_SECONARIES_SKIP_LIST = [
|
|
86
|
+
'@angular/router/upgrade',
|
|
87
|
+
'@angular/common/upgrade'
|
|
88
|
+
];
|
|
89
|
+
function findRootTsConfigJson() {
|
|
90
|
+
const packageJson = findPackageJson(process__default["default"].cwd());
|
|
91
|
+
const projectRoot = path__default["default"].dirname(packageJson);
|
|
92
|
+
const tsConfigBaseJson = path__default["default"].join(projectRoot, 'tsconfig.base.json');
|
|
93
|
+
const tsConfigJson = path__default["default"].join(projectRoot, 'tsconfig.json');
|
|
94
|
+
if (fs__default["default"].existsSync(tsConfigBaseJson)) {
|
|
95
|
+
return tsConfigBaseJson;
|
|
96
|
+
} else if (fs__default["default"].existsSync(tsConfigJson)) {
|
|
97
|
+
return tsConfigJson;
|
|
98
|
+
}
|
|
99
|
+
throw new Error('Neither a tsconfig.json nor a tsconfig.base.json was found');
|
|
100
|
+
}
|
|
101
|
+
function findPackageJson(folder) {
|
|
102
|
+
while(!fs__default["default"].existsSync(path__default["default"].join(folder, 'package.json')) && path__default["default"].dirname(folder) !== folder){
|
|
103
|
+
folder = path__default["default"].dirname(folder);
|
|
104
|
+
}
|
|
105
|
+
const filePath = path__default["default"].join(folder, 'package.json');
|
|
106
|
+
if (fs__default["default"].existsSync(filePath)) {
|
|
107
|
+
return filePath;
|
|
108
|
+
}
|
|
109
|
+
throw new Error('no package.json found. Searched the following folder and all parents: ' + folder);
|
|
110
|
+
}
|
|
111
|
+
function lookupVersion(key, workspaceRoot) {
|
|
112
|
+
const versionMaps = federationBuilder.getVersionMaps(workspaceRoot, workspaceRoot);
|
|
113
|
+
for (const versionMap of versionMaps){
|
|
114
|
+
const version = lookupVersionInMap(key, versionMap);
|
|
115
|
+
if (version) {
|
|
116
|
+
return version;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
throw new Error(`Shared Dependency ${key} has requiredVersion:'auto'. However, this dependency is not found in your package.json`);
|
|
120
|
+
}
|
|
121
|
+
function lookupVersionInMap(key, versions) {
|
|
122
|
+
const parts = key.split('/');
|
|
123
|
+
if (parts.length >= 2 && parts[0].startsWith('@')) {
|
|
124
|
+
key = parts[0] + '/' + parts[1];
|
|
125
|
+
} else {
|
|
126
|
+
key = parts[0];
|
|
127
|
+
}
|
|
128
|
+
if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
|
|
129
|
+
key = '@angular-architects/module-federation';
|
|
130
|
+
}
|
|
131
|
+
if (!versions[key]) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return versions[key];
|
|
135
|
+
}
|
|
136
|
+
function _findSecondaries(libPath, excludes, shareObject, acc) {
|
|
137
|
+
const files = fs__default["default"].readdirSync(libPath);
|
|
138
|
+
const dirs = files.map((f)=>path__default["default"].join(libPath, f)).filter((f)=>fs__default["default"].lstatSync(f).isDirectory() && f !== 'node_modules');
|
|
139
|
+
const secondaries = dirs.filter((d)=>fs__default["default"].existsSync(path__default["default"].join(d, 'package.json')));
|
|
140
|
+
for (const s of secondaries){
|
|
141
|
+
const secondaryLibName = s.replace(/\\/g, '/').replace(/^.*node_modules[/]/, '');
|
|
142
|
+
if (excludes.includes(secondaryLibName)) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
acc[secondaryLibName] = Object.assign({}, shareObject);
|
|
149
|
+
_findSecondaries(s, excludes, shareObject, acc);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function findSecondaries(libPath, excludes, shareObject) {
|
|
153
|
+
const acc = {};
|
|
154
|
+
_findSecondaries(libPath, excludes, shareObject, acc);
|
|
155
|
+
return acc;
|
|
156
|
+
}
|
|
157
|
+
function getSecondaries(includeSecondaries, libPath, key, shareObject) {
|
|
158
|
+
let exclude = [
|
|
159
|
+
...DEFAULT_SECONARIES_SKIP_LIST
|
|
160
|
+
];
|
|
161
|
+
if (typeof includeSecondaries === 'object') {
|
|
162
|
+
if (Array.isArray(includeSecondaries.skip)) {
|
|
163
|
+
exclude = includeSecondaries.skip;
|
|
164
|
+
} else if (typeof includeSecondaries.skip === 'string') {
|
|
165
|
+
exclude = [
|
|
166
|
+
includeSecondaries.skip
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (!fs__default["default"].existsSync(libPath)) {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
const configured = readConfiguredSecondaries(key, libPath, exclude, shareObject);
|
|
174
|
+
if (configured) {
|
|
175
|
+
return configured;
|
|
176
|
+
}
|
|
177
|
+
// Fallback: Search folders
|
|
178
|
+
const secondaries = findSecondaries(libPath, exclude, shareObject);
|
|
179
|
+
return secondaries;
|
|
180
|
+
}
|
|
181
|
+
function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
|
|
182
|
+
const libPackageJson = path__default["default"].join(libPath, 'package.json');
|
|
183
|
+
if (!fs__default["default"].existsSync(libPackageJson)) {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
const packageJson = JSON.parse(fs__default["default"].readFileSync(libPackageJson, 'utf-8'));
|
|
187
|
+
const exports = packageJson['exports'];
|
|
188
|
+
if (!exports) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
const keys = Object.keys(exports).filter((key)=>key != '.' && key != './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
|
|
192
|
+
const result = {};
|
|
193
|
+
for (const key of keys){
|
|
194
|
+
// const relPath = exports[key]['default'];
|
|
195
|
+
const secondaryName = path__default["default"].join(parent, key).replace(/\\/g, '/');
|
|
196
|
+
if (exclude.includes(secondaryName)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if (isInSkipList(secondaryName, PREPARED_DEFAULT_SKIP_LIST)) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const entry = getDefaultEntry(exports, key);
|
|
203
|
+
if (typeof entry !== 'string') {
|
|
204
|
+
console.log('No entry point found for ' + secondaryName);
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if ((entry === null || entry === void 0 ? void 0 : entry.endsWith('.css')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.scss')) || (entry === null || entry === void 0 ? void 0 : entry.endsWith('.less'))) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
result[secondaryName] = Object.assign({}, shareObject);
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
function getDefaultEntry(exports, key) {
|
|
215
|
+
var _a;
|
|
216
|
+
let entry = '';
|
|
217
|
+
if (typeof exports[key] === 'string') {
|
|
218
|
+
entry = exports[key];
|
|
219
|
+
} else {
|
|
220
|
+
entry = (_a = exports[key]) === null || _a === void 0 ? void 0 : _a['default'];
|
|
221
|
+
if (typeof entry === 'object') {
|
|
222
|
+
entry = entry['default'];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return entry;
|
|
226
|
+
}
|
|
227
|
+
function shareAll(config = {}, skip = DEFAULT_SKIP_LIST, projectPath = '') {
|
|
228
|
+
// let workspacePath: string | undefined = undefined;
|
|
229
|
+
projectPath = inferProjectPath(projectPath);
|
|
230
|
+
// workspacePath = getConfigContext().workspaceRoot ?? '';
|
|
231
|
+
// if (!workspacePath) {
|
|
232
|
+
// workspacePath = projectPath;
|
|
233
|
+
// }
|
|
234
|
+
const versionMaps = federationBuilder.getVersionMaps(projectPath, projectPath);
|
|
235
|
+
const share = {};
|
|
236
|
+
for (const versions of versionMaps){
|
|
237
|
+
const preparedSkipList = prepareSkipList(skip);
|
|
238
|
+
for(const key in versions){
|
|
239
|
+
if (isInSkipList(key, preparedSkipList)) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const inferVersion = !config.requiredVersion || config.requiredVersion === 'auto';
|
|
243
|
+
const requiredVersion = inferVersion ? versions[key] : config.requiredVersion;
|
|
244
|
+
if (!share[key]) {
|
|
245
|
+
share[key] = Object.assign(Object.assign({}, config), {
|
|
246
|
+
requiredVersion
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
return module.exports.share(share, projectPath);
|
|
252
|
+
}
|
|
253
|
+
function inferProjectPath(projectPath) {
|
|
254
|
+
if (!projectPath && federationBuilder.getConfigContext().packageJson) {
|
|
255
|
+
projectPath = path__default["default"].dirname(federationBuilder.getConfigContext().packageJson || '');
|
|
256
|
+
}
|
|
257
|
+
if (!projectPath && federationBuilder.getConfigContext().workspaceRoot) {
|
|
258
|
+
projectPath = federationBuilder.getConfigContext().workspaceRoot || '';
|
|
259
|
+
}
|
|
260
|
+
if (!projectPath) {
|
|
261
|
+
projectPath = process__default["default"].cwd();
|
|
262
|
+
}
|
|
263
|
+
return projectPath;
|
|
264
|
+
}
|
|
265
|
+
function setInferVersion(infer) {
|
|
266
|
+
inferVersion = infer;
|
|
267
|
+
}
|
|
268
|
+
function share(shareObjects, projectPath = '') {
|
|
269
|
+
projectPath = inferProjectPath(projectPath);
|
|
270
|
+
const packagePath = findPackageJson(projectPath);
|
|
271
|
+
// const versions = readVersionMap(packagePath);
|
|
272
|
+
const result = {};
|
|
273
|
+
let includeSecondaries;
|
|
274
|
+
for(const key in shareObjects){
|
|
275
|
+
includeSecondaries = false;
|
|
276
|
+
const shareObject = shareObjects[key];
|
|
277
|
+
if (shareObject.requiredVersion === 'auto' || inferVersion && typeof shareObject.requiredVersion === 'undefined') {
|
|
278
|
+
const version = lookupVersion(key, projectPath);
|
|
279
|
+
shareObject.requiredVersion = version;
|
|
280
|
+
shareObject.version = version.replace(/^\D*/, '');
|
|
281
|
+
}
|
|
282
|
+
if (typeof shareObject.includeSecondaries === 'undefined') {
|
|
283
|
+
shareObject.includeSecondaries = true;
|
|
284
|
+
}
|
|
285
|
+
if (shareObject.includeSecondaries) {
|
|
286
|
+
includeSecondaries = shareObject.includeSecondaries;
|
|
287
|
+
delete shareObject.includeSecondaries;
|
|
288
|
+
}
|
|
289
|
+
result[key] = shareObject;
|
|
290
|
+
if (includeSecondaries) {
|
|
291
|
+
const libPackageJson = federationBuilder.findDepPackageJson(key, path__default["default"].dirname(packagePath));
|
|
292
|
+
if (!libPackageJson) {
|
|
293
|
+
federationBuilder.logger.error('Could not find folder containing dep ' + key);
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const libPath = path__default["default"].dirname(libPackageJson);
|
|
297
|
+
const secondaries = getSecondaries(includeSecondaries, libPath, key, shareObject);
|
|
298
|
+
if (secondaries) {
|
|
299
|
+
addSecondaries(secondaries, result);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
function addSecondaries(secondaries, result) {
|
|
306
|
+
for(const key in secondaries){
|
|
307
|
+
result[key] = secondaries[key];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function getMappedPaths({ rootTsConfigPath, sharedMappings, rootPath }) {
|
|
312
|
+
var _tsConfig_compilerOptions;
|
|
313
|
+
const result = [];
|
|
314
|
+
if (!path__namespace.isAbsolute(rootTsConfigPath)) {
|
|
315
|
+
throw new Error('SharedMappings.register: tsConfigPath needs to be an absolute path!');
|
|
316
|
+
}
|
|
317
|
+
if (!rootPath) {
|
|
318
|
+
rootPath = path__namespace.normalize(path__namespace.dirname(rootTsConfigPath));
|
|
319
|
+
}
|
|
320
|
+
const shareAll = !sharedMappings;
|
|
321
|
+
if (!sharedMappings) {
|
|
322
|
+
sharedMappings = [];
|
|
323
|
+
}
|
|
324
|
+
const tsConfig = JSON5__namespace.parse(fs__namespace.readFileSync(rootTsConfigPath, {
|
|
325
|
+
encoding: 'utf-8'
|
|
326
|
+
}));
|
|
327
|
+
const mappings = tsConfig == null ? void 0 : (_tsConfig_compilerOptions = tsConfig.compilerOptions) == null ? void 0 : _tsConfig_compilerOptions.paths;
|
|
328
|
+
if (!mappings) {
|
|
329
|
+
return result;
|
|
330
|
+
}
|
|
331
|
+
for(const key in mappings){
|
|
332
|
+
const libPath = path__namespace.normalize(path__namespace.join(rootPath, mappings[key][0]));
|
|
333
|
+
if (sharedMappings.includes(key) || shareAll) {
|
|
334
|
+
result.push({
|
|
335
|
+
key,
|
|
336
|
+
path: libPath
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function _extends() {
|
|
344
|
+
_extends = Object.assign || function(target) {
|
|
345
|
+
for(var i = 1; i < arguments.length; i++){
|
|
346
|
+
var source = arguments[i];
|
|
347
|
+
for(var key in source){
|
|
348
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
349
|
+
target[key] = source[key];
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return target;
|
|
354
|
+
};
|
|
355
|
+
return _extends.apply(this, arguments);
|
|
356
|
+
}
|
|
357
|
+
function withFederation(config) {
|
|
358
|
+
var _config_skip;
|
|
359
|
+
const skip = prepareSkipList((_config_skip = config.skip) != null ? _config_skip : []);
|
|
360
|
+
var _config_name, _config_filename, _config_exposes, _config_remotes;
|
|
361
|
+
return {
|
|
362
|
+
name: (_config_name = config.name) != null ? _config_name : '',
|
|
363
|
+
filename: (_config_filename = config.filename) != null ? _config_filename : 'remoteEntry',
|
|
364
|
+
exposes: (_config_exposes = config.exposes) != null ? _config_exposes : {},
|
|
365
|
+
remotes: (_config_remotes = config.remotes) != null ? _config_remotes : {},
|
|
366
|
+
shared: normalizeShared(config, skip),
|
|
367
|
+
sharedMappings: normalizeSharedMappings(config, skip)
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function normalizeShared(config, skip) {
|
|
371
|
+
let result = {};
|
|
372
|
+
const shared = config.shared;
|
|
373
|
+
if (!shared) {
|
|
374
|
+
result = shareAll({
|
|
375
|
+
singleton: true,
|
|
376
|
+
strictVersion: true,
|
|
377
|
+
requiredVersion: 'auto'
|
|
378
|
+
});
|
|
379
|
+
} else {
|
|
380
|
+
result = Object.keys(shared).reduce((acc, cur)=>{
|
|
381
|
+
var _shared_cur_requiredVersion, _shared_cur_singleton, _shared_cur_strictVersion;
|
|
382
|
+
return _extends({}, acc, {
|
|
383
|
+
[cur]: {
|
|
384
|
+
requiredVersion: (_shared_cur_requiredVersion = shared[cur].requiredVersion) != null ? _shared_cur_requiredVersion : 'auto',
|
|
385
|
+
singleton: (_shared_cur_singleton = shared[cur].singleton) != null ? _shared_cur_singleton : false,
|
|
386
|
+
strictVersion: (_shared_cur_strictVersion = shared[cur].strictVersion) != null ? _shared_cur_strictVersion : false,
|
|
387
|
+
version: shared[cur].version,
|
|
388
|
+
includeSecondaries: shared[cur].includeSecondaries
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}, {});
|
|
392
|
+
}
|
|
393
|
+
result = Object.keys(result).filter((key)=>!isInSkipList(key, skip)).reduce((acc, cur)=>_extends({}, acc, {
|
|
394
|
+
[cur]: result[cur]
|
|
395
|
+
}), {});
|
|
396
|
+
return result;
|
|
397
|
+
}
|
|
398
|
+
function normalizeSharedMappings(config, skip) {
|
|
399
|
+
const rootTsConfigPath = findRootTsConfigJson();
|
|
400
|
+
const paths = getMappedPaths({
|
|
401
|
+
rootTsConfigPath,
|
|
402
|
+
sharedMappings: config.sharedMappings
|
|
403
|
+
});
|
|
404
|
+
const result = paths.filter((p)=>!isInSkipList(p.key, skip) && !p.key.includes('*'));
|
|
405
|
+
if (paths.find((p)=>p.key.includes('*'))) {
|
|
406
|
+
federationBuilder.logger.warn('Sharing mapped paths with wildcards (*) not supported');
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function hashFile(fileName) {
|
|
412
|
+
const fileBuffer = fs__namespace.readFileSync(fileName);
|
|
413
|
+
const hashSum = crypto__namespace.createHash('md5');
|
|
414
|
+
hashSum.update(fileBuffer);
|
|
415
|
+
return hashSum.digest('hex');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
exports.buildForFederation = federationBuilder.buildForFederation;
|
|
419
|
+
exports.bundleExposedAndMappings = federationBuilder.bundleExposedAndMappings;
|
|
420
|
+
exports.createBuildResultMap = federationBuilder.createBuildResultMap;
|
|
421
|
+
exports.defaultBuildParams = federationBuilder.defaultBuildParams;
|
|
422
|
+
exports.describeExposed = federationBuilder.describeExposed;
|
|
423
|
+
exports.describeSharedMappings = federationBuilder.describeSharedMappings;
|
|
424
|
+
exports.federationBuilder = federationBuilder.federationBuilder;
|
|
425
|
+
exports.getBuildAdapter = federationBuilder.getBuildAdapter;
|
|
426
|
+
exports.getExternals = federationBuilder.getExternals;
|
|
427
|
+
exports.loadFederationConfig = federationBuilder.loadFederationConfig;
|
|
428
|
+
exports.logger = federationBuilder.logger;
|
|
429
|
+
exports.lookupInResultMap = federationBuilder.lookupInResultMap;
|
|
430
|
+
exports.setBuildAdapter = federationBuilder.setBuildAdapter;
|
|
431
|
+
exports.setLogLevel = federationBuilder.setLogLevel;
|
|
432
|
+
exports.writeFederationInfo = federationBuilder.writeFederationInfo;
|
|
433
|
+
exports.writeImportMap = federationBuilder.writeImportMap;
|
|
434
|
+
exports.DEFAULT_SECONARIES_SKIP_LIST = DEFAULT_SECONARIES_SKIP_LIST;
|
|
435
|
+
exports._findSecondaries = _findSecondaries;
|
|
436
|
+
exports.addSecondaries = addSecondaries;
|
|
437
|
+
exports.findPackageJson = findPackageJson;
|
|
438
|
+
exports.findRootTsConfigJson = findRootTsConfigJson;
|
|
439
|
+
exports.findSecondaries = findSecondaries;
|
|
440
|
+
exports.getDefaultEntry = getDefaultEntry;
|
|
441
|
+
exports.getSecondaries = getSecondaries;
|
|
442
|
+
exports.hashFile = hashFile;
|
|
443
|
+
exports.inferProjectPath = inferProjectPath;
|
|
444
|
+
exports.lookupVersion = lookupVersion;
|
|
445
|
+
exports.lookupVersionInMap = lookupVersionInMap;
|
|
446
|
+
exports.readConfiguredSecondaries = readConfiguredSecondaries;
|
|
447
|
+
exports.setInferVersion = setInferVersion;
|
|
448
|
+
exports.share = share;
|
|
449
|
+
exports.shareAll = shareAll;
|
|
450
|
+
exports.withFederation = withFederation;
|