@module-federation/esbuild 0.0.0-fix-lazy-comile-20250925082726
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 +113 -0
- package/dist/build.cjs.js +532 -0
- package/dist/build.cjs.js.map +1 -0
- package/dist/build.d.ts +1 -0
- package/dist/build.esm.js +494 -0
- package/dist/build.esm.js.map +1 -0
- package/dist/get-externals.cjs.js +22 -0
- package/dist/get-externals.cjs.js.map +1 -0
- package/dist/get-externals.esm.js +20 -0
- package/dist/get-externals.esm.js.map +1 -0
- package/dist/index.cjs.js +6 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +4 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/plugin.cjs.js +1313 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.d.ts +1 -0
- package/dist/plugin.esm.js +1309 -0
- package/dist/plugin.esm.js.map +1 -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 +3 -0
- package/dist/src/adapters/lib/commonjs.d.ts +101 -0
- package/dist/src/adapters/lib/containerPlugin.d.ts +6 -0
- package/dist/src/adapters/lib/containerReference.d.ts +6 -0
- package/dist/src/adapters/lib/lexer.d.ts +9 -0
- package/dist/src/adapters/lib/linkRemotesPlugin.d.ts +6 -0
- package/dist/src/adapters/lib/manifest.d.ts +2 -0
- package/dist/src/adapters/lib/plugin.d.ts +8 -0
- package/dist/src/adapters/lib/react-replacements.d.ts +9 -0
- package/dist/src/adapters/lib/transform.d.ts +8 -0
- package/dist/src/adapters/lib/utils.d.ts +3 -0
- package/dist/src/build.d.ts +5 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/lib/config/configuration-context.d.ts +7 -0
- package/dist/src/lib/config/federation-config.d.ts +30 -0
- package/dist/src/lib/config/share-utils.d.ts +29 -0
- package/dist/src/lib/config/with-native-federation.d.ts +23 -0
- package/dist/src/lib/core/build-adapter.d.ts +4 -0
- package/dist/src/lib/core/createContainerTemplate.d.ts +1 -0
- package/dist/src/lib/core/default-skip-list.d.ts +12 -0
- package/dist/src/lib/core/federation-options.d.ts +10 -0
- package/dist/src/lib/core/get-externals.d.ts +2 -0
- package/dist/src/lib/core/load-federation-config.d.ts +6 -0
- package/dist/src/lib/core/write-federation-info.d.ts +9 -0
- package/dist/src/lib/utils/logger.d.ts +11 -0
- package/dist/src/lib/utils/mapped-paths.d.ts +10 -0
- package/dist/src/lib/utils/normalize.d.ts +1 -0
- package/dist/src/lib/utils/package-info.d.ts +18 -0
- package/package.json +73 -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,113 @@
|
|
|
1
|
+
# @module-federation/esbuild
|
|
2
|
+
|
|
3
|
+
This package provides an esbuild plugin for Module Federation, enabling you to easily share code between independently built and deployed applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @module-federation/esbuild
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
To use the Module Federation plugin with esbuild, add it to your esbuild configuration:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const esbuild = require('esbuild');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { moduleFederationPlugin } = require('@module-federation/esbuild/plugin');
|
|
21
|
+
const federationConfig = require('./federation.config.js');
|
|
22
|
+
|
|
23
|
+
async function buildApp() {
|
|
24
|
+
const tsConfig = 'tsconfig.json';
|
|
25
|
+
const outputPath = path.join('dist', 'host');
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
await esbuild.build({
|
|
29
|
+
entryPoints: [path.join('host', 'main.ts')],
|
|
30
|
+
outdir: outputPath,
|
|
31
|
+
bundle: true,
|
|
32
|
+
platform: 'browser',
|
|
33
|
+
format: 'esm',
|
|
34
|
+
mainFields: ['es2020', 'browser', 'module', 'main'],
|
|
35
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
36
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
37
|
+
tsconfig: tsConfig,
|
|
38
|
+
splitting: true,
|
|
39
|
+
plugins: [moduleFederationPlugin(federationConfig)],
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(err);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
buildApp();
|
|
48
|
+
|
|
49
|
+
// Example of federation.config.js
|
|
50
|
+
|
|
51
|
+
const { withFederation, shareAll } = require('@module-federation/esbuild/build');
|
|
52
|
+
|
|
53
|
+
module.exports = withFederation({
|
|
54
|
+
name: 'host',
|
|
55
|
+
filename: 'remoteEntry.js',
|
|
56
|
+
exposes: {
|
|
57
|
+
'./Component': './src/Component',
|
|
58
|
+
},
|
|
59
|
+
shared: {
|
|
60
|
+
react: {
|
|
61
|
+
singleton: true,
|
|
62
|
+
version: '^18.2.0',
|
|
63
|
+
},
|
|
64
|
+
'react-dom': {
|
|
65
|
+
singleton: true,
|
|
66
|
+
version: '^18.2.0',
|
|
67
|
+
},
|
|
68
|
+
rxjs: {
|
|
69
|
+
singleton: true,
|
|
70
|
+
version: '^7.8.1',
|
|
71
|
+
},
|
|
72
|
+
...shareAll({
|
|
73
|
+
singleton: true,
|
|
74
|
+
strictVersion: true,
|
|
75
|
+
requiredVersion: 'auto',
|
|
76
|
+
includeSecondaries: false,
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `moduleFederationPlugin` accepts a configuration object with the following properties:
|
|
83
|
+
|
|
84
|
+
- `name` (string): The name of the host application.
|
|
85
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
86
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
87
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
88
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
89
|
+
|
|
90
|
+
## Plugin Features
|
|
91
|
+
|
|
92
|
+
The `moduleFederationPlugin` includes the following features:
|
|
93
|
+
|
|
94
|
+
- **Virtual Share Module**: Creates a virtual module for sharing dependencies between the host and remote applications.
|
|
95
|
+
- **Virtual Remote Module**: Creates a virtual module for importing exposed modules from remote applications.
|
|
96
|
+
- **CommonJS to ESM Transformation**: Transforms CommonJS modules to ESM format for compatibility with Module Federation.
|
|
97
|
+
- **Shared Dependencies Linking**: Links shared dependencies between the host and remote applications.
|
|
98
|
+
- **Manifest Generation**: Generates a manifest file containing information about the exposed modules and their exports.
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### `moduleFederationPlugin(config)`
|
|
103
|
+
|
|
104
|
+
Creates an esbuild plugin for Module Federation.
|
|
105
|
+
|
|
106
|
+
- `config` (object): The Module Federation configuration.
|
|
107
|
+
- `name` (string): The name of the host application.
|
|
108
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
109
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
110
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
111
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
112
|
+
|
|
113
|
+
Returns an esbuild plugin instance.
|
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getExternals = require('./get-externals.cjs.js');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var process = require('process');
|
|
7
|
+
var npmlog = require('npmlog');
|
|
8
|
+
require('json5');
|
|
9
|
+
|
|
10
|
+
function _interopNamespaceDefault(e) {
|
|
11
|
+
var n = Object.create(null);
|
|
12
|
+
if (e) {
|
|
13
|
+
Object.keys(e).forEach(function (k) {
|
|
14
|
+
if (k !== 'default') {
|
|
15
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return e[k]; }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
n.default = e;
|
|
24
|
+
return Object.freeze(n);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
28
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
29
|
+
|
|
30
|
+
async function loadFederationConfig(fedOptions) {
|
|
31
|
+
const fullConfigPath = path__namespace.join(fedOptions.workspaceRoot, fedOptions.federationConfig);
|
|
32
|
+
if (!fs__namespace.existsSync(fullConfigPath)) {
|
|
33
|
+
throw new Error('Expected ' + fullConfigPath);
|
|
34
|
+
}
|
|
35
|
+
const config = await import(`${fullConfigPath}`);
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const DEFAULT_SKIP_LIST = [
|
|
40
|
+
'@module-federation/native-federation-runtime',
|
|
41
|
+
'@module-federation/native-federation',
|
|
42
|
+
'@module-federation/native-federation-core',
|
|
43
|
+
'@module-federation/native-federation-esbuild',
|
|
44
|
+
'@angular-architects/native-federation',
|
|
45
|
+
'@angular-architects/native-federation-runtime',
|
|
46
|
+
'es-module-shims',
|
|
47
|
+
'zone.js',
|
|
48
|
+
'tslib/',
|
|
49
|
+
'@angular/localize',
|
|
50
|
+
'@angular/localize/init',
|
|
51
|
+
'@angular/localize/tools',
|
|
52
|
+
'@angular/platform-server',
|
|
53
|
+
'@angular/platform-server/init',
|
|
54
|
+
'@angular/ssr',
|
|
55
|
+
'express',
|
|
56
|
+
/\/schematics(\/|$)/,
|
|
57
|
+
/^@nx\/angular/,
|
|
58
|
+
(pkg)=>pkg.startsWith('@angular/') && !!pkg.match(/\/testing(\/|$)/),
|
|
59
|
+
(pkg)=>pkg.startsWith('@types/'),
|
|
60
|
+
(pkg)=>pkg.startsWith('@module-federation/')
|
|
61
|
+
];
|
|
62
|
+
const PREPARED_DEFAULT_SKIP_LIST = prepareSkipList(DEFAULT_SKIP_LIST);
|
|
63
|
+
function prepareSkipList(skipList) {
|
|
64
|
+
return {
|
|
65
|
+
strings: new Set(skipList.filter((e)=>typeof e === 'string')),
|
|
66
|
+
functions: skipList.filter((e)=>typeof e === 'function'),
|
|
67
|
+
regexps: skipList.filter((e)=>e instanceof RegExp)
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function isInSkipList(entry, skipList) {
|
|
71
|
+
if (skipList.strings.has(entry)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (skipList.functions.some((f)=>f(entry))) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (skipList.regexps.some((r)=>r.test(entry))) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let _context = {};
|
|
84
|
+
function getConfigContext() {
|
|
85
|
+
return _context;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */ //@ts-ignore
|
|
89
|
+
const levels = npmlog.levels;
|
|
90
|
+
npmlog.addLevel('error', levels.error, {
|
|
91
|
+
fg: 'brightWhite',
|
|
92
|
+
bg: 'red'
|
|
93
|
+
}, ' ERR! ');
|
|
94
|
+
npmlog.addLevel('warn', levels.info, {
|
|
95
|
+
fg: 'brightWhite',
|
|
96
|
+
bg: 'yellow'
|
|
97
|
+
}, ' WARN ');
|
|
98
|
+
npmlog.addLevel('info', levels.warn, {
|
|
99
|
+
fg: 'brightWhite',
|
|
100
|
+
bg: 'green'
|
|
101
|
+
}, ' INFO ');
|
|
102
|
+
npmlog.addLevel('notice', levels.notice, {
|
|
103
|
+
fg: 'black',
|
|
104
|
+
bg: 'brightYellow'
|
|
105
|
+
}, ' NOTE ');
|
|
106
|
+
npmlog.addLevel('verbose', levels.verbose, {
|
|
107
|
+
fg: 'brightWhite',
|
|
108
|
+
bg: 'brightBlue'
|
|
109
|
+
}, ' VRB! ');
|
|
110
|
+
npmlog.addLevel('silly', levels.silly, {
|
|
111
|
+
fg: 'black',
|
|
112
|
+
bg: 'white'
|
|
113
|
+
}, ' DBG! ');
|
|
114
|
+
const logger = {
|
|
115
|
+
error: (msg)=>npmlog.error('', msg),
|
|
116
|
+
warn: (msg)=>npmlog.warn('', msg),
|
|
117
|
+
notice: (msg)=>npmlog.notice('', msg),
|
|
118
|
+
info: (msg)=>npmlog.info('', msg),
|
|
119
|
+
verbose: (msg)=>npmlog.verbose('', msg),
|
|
120
|
+
debug: (msg)=>npmlog.silly('', msg)
|
|
121
|
+
};
|
|
122
|
+
const setLogLevel = (level)=>{
|
|
123
|
+
npmlog.level = level === 'debug' ? 'silly' : level;
|
|
124
|
+
};
|
|
125
|
+
setLogLevel('info');
|
|
126
|
+
|
|
127
|
+
function normalize(path, trailingSlash) {
|
|
128
|
+
let cand = path.replace(/\\/g, '/');
|
|
129
|
+
while(cand.endsWith('/')){
|
|
130
|
+
cand = cand.substring(0, cand.length - 1);
|
|
131
|
+
}
|
|
132
|
+
{
|
|
133
|
+
return cand + '/';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function _extends$2() {
|
|
138
|
+
_extends$2 = Object.assign || function(target) {
|
|
139
|
+
for(var i = 1; i < arguments.length; i++){
|
|
140
|
+
var source = arguments[i];
|
|
141
|
+
for(var key in source){
|
|
142
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
143
|
+
target[key] = source[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return target;
|
|
148
|
+
};
|
|
149
|
+
return _extends$2.apply(this, arguments);
|
|
150
|
+
}
|
|
151
|
+
const packageCache = {};
|
|
152
|
+
function findPackageJsonFiles(project, workspace) {
|
|
153
|
+
return expandFolders(project, workspace).map((f)=>path__namespace.join(f, 'package.json')).filter((f)=>fs__namespace.existsSync(f));
|
|
154
|
+
}
|
|
155
|
+
function expandFolders(child, parent) {
|
|
156
|
+
const result = [];
|
|
157
|
+
parent = normalize(parent);
|
|
158
|
+
child = normalize(child);
|
|
159
|
+
if (!child.startsWith(parent)) {
|
|
160
|
+
throw new Error(`Workspace folder ${parent} needs to be a parent of the project folder ${child}`);
|
|
161
|
+
}
|
|
162
|
+
let current = child;
|
|
163
|
+
while(current !== parent){
|
|
164
|
+
result.push(current);
|
|
165
|
+
const cand = normalize(path__namespace.dirname(current));
|
|
166
|
+
if (cand === current) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
current = cand;
|
|
170
|
+
}
|
|
171
|
+
result.push(parent);
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
function getVersionMapCacheKey(project, workspace) {
|
|
175
|
+
return `${project}**${workspace}`;
|
|
176
|
+
}
|
|
177
|
+
function getVersionMaps(project, workspace) {
|
|
178
|
+
return getPackageJsonFiles(project, workspace).map((json)=>_extends$2({}, json.content['dependencies']));
|
|
179
|
+
}
|
|
180
|
+
function getPackageJsonFiles(project, workspace) {
|
|
181
|
+
const cacheKey = getVersionMapCacheKey(project, workspace);
|
|
182
|
+
let maps = packageCache[cacheKey];
|
|
183
|
+
if (maps) {
|
|
184
|
+
return maps;
|
|
185
|
+
}
|
|
186
|
+
maps = findPackageJsonFiles(project, workspace).map((f)=>{
|
|
187
|
+
const content = JSON.parse(fs__namespace.readFileSync(f, 'utf-8'));
|
|
188
|
+
const directory = normalize(path__namespace.dirname(f));
|
|
189
|
+
const result = {
|
|
190
|
+
content,
|
|
191
|
+
directory
|
|
192
|
+
};
|
|
193
|
+
return result;
|
|
194
|
+
});
|
|
195
|
+
packageCache[cacheKey] = maps;
|
|
196
|
+
return maps;
|
|
197
|
+
}
|
|
198
|
+
function findDepPackageJson(packageName, projectRoot) {
|
|
199
|
+
const mainPkgName = getPkgFolder(packageName);
|
|
200
|
+
let mainPkgPath = path__namespace.join(projectRoot, 'node_modules', mainPkgName);
|
|
201
|
+
let mainPkgJsonPath = path__namespace.join(mainPkgPath, 'package.json');
|
|
202
|
+
let directory = projectRoot;
|
|
203
|
+
while(path__namespace.dirname(directory) !== directory){
|
|
204
|
+
if (fs__namespace.existsSync(mainPkgJsonPath)) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
directory = normalize(path__namespace.dirname(directory));
|
|
208
|
+
mainPkgPath = path__namespace.join(directory, 'node_modules', mainPkgName);
|
|
209
|
+
mainPkgJsonPath = path__namespace.join(mainPkgPath, 'package.json');
|
|
210
|
+
}
|
|
211
|
+
if (!fs__namespace.existsSync(mainPkgJsonPath)) {
|
|
212
|
+
logger.verbose('No package.json found for ' + packageName + ' in ' + mainPkgPath);
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return mainPkgJsonPath;
|
|
216
|
+
}
|
|
217
|
+
function getPkgFolder(packageName) {
|
|
218
|
+
const parts = packageName.split('/');
|
|
219
|
+
let folder = parts[0];
|
|
220
|
+
if (folder.startsWith('@')) {
|
|
221
|
+
folder += '/' + parts[1];
|
|
222
|
+
}
|
|
223
|
+
return folder;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function _extends$1() {
|
|
227
|
+
_extends$1 = Object.assign || function(target) {
|
|
228
|
+
for(var i = 1; i < arguments.length; i++){
|
|
229
|
+
var source = arguments[i];
|
|
230
|
+
for(var key in source){
|
|
231
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
232
|
+
target[key] = source[key];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return target;
|
|
237
|
+
};
|
|
238
|
+
return _extends$1.apply(this, arguments);
|
|
239
|
+
}
|
|
240
|
+
let inferVersion = false;
|
|
241
|
+
const DEFAULT_SECONARIES_SKIP_LIST = [
|
|
242
|
+
'@angular/router/upgrade',
|
|
243
|
+
'@angular/common/upgrade'
|
|
244
|
+
];
|
|
245
|
+
function findRootTsConfigJson() {
|
|
246
|
+
const packageJson = findPackageJson(process.cwd());
|
|
247
|
+
const projectRoot = path.dirname(packageJson);
|
|
248
|
+
const tsConfigBaseJson = path.join(projectRoot, 'tsconfig.base.json');
|
|
249
|
+
const tsConfigJson = path.join(projectRoot, 'tsconfig.json');
|
|
250
|
+
if (fs.existsSync(tsConfigBaseJson)) {
|
|
251
|
+
return tsConfigBaseJson;
|
|
252
|
+
} else if (fs.existsSync(tsConfigJson)) {
|
|
253
|
+
return tsConfigJson;
|
|
254
|
+
}
|
|
255
|
+
throw new Error('Neither a tsconfig.json nor a tsconfig.base.json was found');
|
|
256
|
+
}
|
|
257
|
+
function findPackageJson(folder) {
|
|
258
|
+
while(!fs.existsSync(path.join(folder, 'package.json')) && path.dirname(folder) !== folder){
|
|
259
|
+
folder = path.dirname(folder);
|
|
260
|
+
}
|
|
261
|
+
const filePath = path.join(folder, 'package.json');
|
|
262
|
+
if (fs.existsSync(filePath)) {
|
|
263
|
+
return filePath;
|
|
264
|
+
}
|
|
265
|
+
throw new Error(`No package.json found. Searched the following folder and all parents: ${folder}`);
|
|
266
|
+
}
|
|
267
|
+
function lookupVersion(key, workspaceRoot) {
|
|
268
|
+
const versionMaps = getVersionMaps(workspaceRoot, workspaceRoot);
|
|
269
|
+
for (const versionMap of versionMaps){
|
|
270
|
+
const version = lookupVersionInMap(key, versionMap);
|
|
271
|
+
if (version) {
|
|
272
|
+
return version;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
throw new Error(`Shared Dependency ${key} has requiredVersion:'auto'. However, this dependency is not found in your package.json`);
|
|
276
|
+
}
|
|
277
|
+
function lookupVersionInMap(key, versions) {
|
|
278
|
+
const parts = key.split('/');
|
|
279
|
+
if (parts.length >= 2 && parts[0].startsWith('@')) {
|
|
280
|
+
key = `${parts[0]}/${parts[1]}`;
|
|
281
|
+
} else {
|
|
282
|
+
key = parts[0];
|
|
283
|
+
}
|
|
284
|
+
if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
|
|
285
|
+
key = '@angular-architects/module-federation';
|
|
286
|
+
}
|
|
287
|
+
return versions[key] || null;
|
|
288
|
+
}
|
|
289
|
+
function _findSecondaries(libPath, excludes, shareObject, acc) {
|
|
290
|
+
const files = fs.readdirSync(libPath);
|
|
291
|
+
const dirs = files.map((f)=>path.join(libPath, f)).filter((f)=>fs.lstatSync(f).isDirectory() && f !== 'node_modules');
|
|
292
|
+
const secondaries = dirs.filter((d)=>fs.existsSync(path.join(d, 'package.json')));
|
|
293
|
+
for (const s of secondaries){
|
|
294
|
+
const secondaryLibName = s.replace(/\\/g, '/').replace(/^.*node_modules[/]/, '');
|
|
295
|
+
if (excludes.includes(secondaryLibName)) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
acc[secondaryLibName] = _extends$1({}, shareObject);
|
|
302
|
+
_findSecondaries(s, excludes, shareObject, acc);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function findSecondaries(libPath, excludes, shareObject) {
|
|
306
|
+
const acc = {};
|
|
307
|
+
_findSecondaries(libPath, excludes, shareObject, acc);
|
|
308
|
+
return acc;
|
|
309
|
+
}
|
|
310
|
+
function getSecondaries(includeSecondaries, libPath, key, shareObject) {
|
|
311
|
+
let exclude = [
|
|
312
|
+
...DEFAULT_SECONARIES_SKIP_LIST
|
|
313
|
+
];
|
|
314
|
+
if (typeof includeSecondaries === 'object') {
|
|
315
|
+
if (Array.isArray(includeSecondaries.skip)) {
|
|
316
|
+
exclude = includeSecondaries.skip;
|
|
317
|
+
} else if (typeof includeSecondaries.skip === 'string') {
|
|
318
|
+
exclude = [
|
|
319
|
+
includeSecondaries.skip
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (!fs.existsSync(libPath)) {
|
|
324
|
+
return {};
|
|
325
|
+
}
|
|
326
|
+
const configured = readConfiguredSecondaries(key, libPath, exclude, shareObject);
|
|
327
|
+
if (configured) {
|
|
328
|
+
return configured;
|
|
329
|
+
}
|
|
330
|
+
// Fallback: Search folders
|
|
331
|
+
return findSecondaries(libPath, exclude, shareObject);
|
|
332
|
+
}
|
|
333
|
+
function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
|
|
334
|
+
const libPackageJson = path.join(libPath, 'package.json');
|
|
335
|
+
if (!fs.existsSync(libPackageJson)) {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
const packageJson = JSON.parse(fs.readFileSync(libPackageJson, 'utf-8'));
|
|
339
|
+
const exports = packageJson['exports'];
|
|
340
|
+
if (!exports) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
const keys = Object.keys(exports).filter((key)=>key !== '.' && key !== './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
|
|
344
|
+
const result = {};
|
|
345
|
+
for (const key of keys){
|
|
346
|
+
const secondaryName = path.join(parent, key).replace(/\\/g, '/');
|
|
347
|
+
if (exclude.includes(secondaryName)) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (isInSkipList(secondaryName, PREPARED_DEFAULT_SKIP_LIST)) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const entry = getDefaultEntry(exports, key);
|
|
354
|
+
if (typeof entry !== 'string') {
|
|
355
|
+
console.log(`No entry point found for ${secondaryName}`);
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
if ([
|
|
359
|
+
'.css',
|
|
360
|
+
'.scss',
|
|
361
|
+
'.less'
|
|
362
|
+
].some((ext)=>entry.endsWith(ext))) {
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
result[secondaryName] = _extends$1({}, shareObject);
|
|
366
|
+
}
|
|
367
|
+
return result;
|
|
368
|
+
}
|
|
369
|
+
function getDefaultEntry(exports, key) {
|
|
370
|
+
let entry;
|
|
371
|
+
if (typeof exports[key] === 'string') {
|
|
372
|
+
entry = exports[key];
|
|
373
|
+
} else {
|
|
374
|
+
var _exports_key;
|
|
375
|
+
entry = (_exports_key = exports[key]) == null ? void 0 : _exports_key['default'];
|
|
376
|
+
if (typeof entry === 'object') {
|
|
377
|
+
entry = entry['default'];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return entry;
|
|
381
|
+
}
|
|
382
|
+
function shareAll(config, skip = DEFAULT_SKIP_LIST, projectPath = '') {
|
|
383
|
+
projectPath = inferProjectPath(projectPath);
|
|
384
|
+
const versionMaps = getVersionMaps(projectPath, projectPath);
|
|
385
|
+
const shareConfig = {};
|
|
386
|
+
for (const versions of versionMaps){
|
|
387
|
+
const preparedSkipList = prepareSkipList(skip);
|
|
388
|
+
for(const key in versions){
|
|
389
|
+
if (isInSkipList(key, preparedSkipList)) {
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
const inferVersion = !config.requiredVersion || config.requiredVersion === 'auto';
|
|
393
|
+
const requiredVersion = inferVersion ? versions[key] : config.requiredVersion;
|
|
394
|
+
if (!shareConfig[key]) {
|
|
395
|
+
shareConfig[key] = _extends$1({}, config, {
|
|
396
|
+
requiredVersion
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return share(share, projectPath);
|
|
402
|
+
}
|
|
403
|
+
function inferProjectPath(projectPath) {
|
|
404
|
+
if (!projectPath) {
|
|
405
|
+
projectPath = path.dirname(getConfigContext().packageJson || '');
|
|
406
|
+
}
|
|
407
|
+
if (!projectPath && getConfigContext().workspaceRoot) {
|
|
408
|
+
projectPath = getConfigContext().workspaceRoot || '';
|
|
409
|
+
}
|
|
410
|
+
if (!projectPath) {
|
|
411
|
+
projectPath = process.cwd();
|
|
412
|
+
}
|
|
413
|
+
return projectPath;
|
|
414
|
+
}
|
|
415
|
+
function setInferVersion(infer) {
|
|
416
|
+
inferVersion = infer;
|
|
417
|
+
}
|
|
418
|
+
function share(shareObjects, projectPath = '') {
|
|
419
|
+
projectPath = inferProjectPath(projectPath);
|
|
420
|
+
const packagePath = findPackageJson(projectPath);
|
|
421
|
+
const result = {};
|
|
422
|
+
let includeSecondaries;
|
|
423
|
+
for(const key in shareObjects){
|
|
424
|
+
includeSecondaries = false;
|
|
425
|
+
const shareObject = shareObjects[key];
|
|
426
|
+
if (shareObject.requiredVersion === 'auto' || inferVersion && typeof shareObject.requiredVersion === 'undefined') {
|
|
427
|
+
const version = lookupVersion(key, projectPath);
|
|
428
|
+
shareObject.requiredVersion = version;
|
|
429
|
+
shareObject.version = version.replace(/^\D*/, '');
|
|
430
|
+
}
|
|
431
|
+
if (typeof shareObject.includeSecondaries === 'undefined') {
|
|
432
|
+
shareObject.includeSecondaries = true;
|
|
433
|
+
}
|
|
434
|
+
if (shareObject.includeSecondaries) {
|
|
435
|
+
includeSecondaries = shareObject.includeSecondaries;
|
|
436
|
+
delete shareObject.includeSecondaries;
|
|
437
|
+
}
|
|
438
|
+
result[key] = shareObject;
|
|
439
|
+
if (includeSecondaries) {
|
|
440
|
+
const libPackageJson = findDepPackageJson(key, path.dirname(packagePath));
|
|
441
|
+
if (!libPackageJson) {
|
|
442
|
+
logger.error(`Could not find folder containing dep ${key}`);
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const libPath = path.dirname(libPackageJson);
|
|
446
|
+
const secondaries = getSecondaries(includeSecondaries, libPath, key, shareObject);
|
|
447
|
+
if (secondaries) {
|
|
448
|
+
addSecondaries(secondaries, result);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
454
|
+
function addSecondaries(secondaries, result) {
|
|
455
|
+
Object.assign(result, secondaries);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function _extends() {
|
|
459
|
+
_extends = Object.assign || function(target) {
|
|
460
|
+
for(var i = 1; i < arguments.length; i++){
|
|
461
|
+
var source = arguments[i];
|
|
462
|
+
for(var key in source){
|
|
463
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
464
|
+
target[key] = source[key];
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return target;
|
|
469
|
+
};
|
|
470
|
+
return _extends.apply(this, arguments);
|
|
471
|
+
}
|
|
472
|
+
function withFederation(config) {
|
|
473
|
+
var _config_skip;
|
|
474
|
+
const skip = prepareSkipList((_config_skip = config.skip) != null ? _config_skip : []);
|
|
475
|
+
var _config_name, _config_filename, _config_exposes, _config_remotes;
|
|
476
|
+
return {
|
|
477
|
+
name: (_config_name = config.name) != null ? _config_name : '',
|
|
478
|
+
filename: (_config_filename = config.filename) != null ? _config_filename : 'remoteEntry',
|
|
479
|
+
exposes: (_config_exposes = config.exposes) != null ? _config_exposes : {},
|
|
480
|
+
remotes: (_config_remotes = config.remotes) != null ? _config_remotes : {},
|
|
481
|
+
shared: normalizeShared(config, skip)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function normalizeShared(config, skip) {
|
|
485
|
+
let result = {};
|
|
486
|
+
const shared = config.shared;
|
|
487
|
+
if (!shared) {
|
|
488
|
+
result = shareAll({
|
|
489
|
+
singleton: true,
|
|
490
|
+
strictVersion: true,
|
|
491
|
+
requiredVersion: 'auto'
|
|
492
|
+
});
|
|
493
|
+
} else {
|
|
494
|
+
result = Object.keys(shared).reduce((acc, cur)=>{
|
|
495
|
+
var _shared_cur_requiredVersion, _shared_cur_singleton, _shared_cur_strictVersion;
|
|
496
|
+
return _extends({}, acc, {
|
|
497
|
+
[cur]: {
|
|
498
|
+
requiredVersion: (_shared_cur_requiredVersion = shared[cur].requiredVersion) != null ? _shared_cur_requiredVersion : 'auto',
|
|
499
|
+
singleton: (_shared_cur_singleton = shared[cur].singleton) != null ? _shared_cur_singleton : false,
|
|
500
|
+
strictVersion: (_shared_cur_strictVersion = shared[cur].strictVersion) != null ? _shared_cur_strictVersion : false,
|
|
501
|
+
version: shared[cur].version,
|
|
502
|
+
includeSecondaries: shared[cur].includeSecondaries
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
}, {});
|
|
506
|
+
}
|
|
507
|
+
result = Object.keys(result).filter((key)=>!isInSkipList(key, skip)).reduce((acc, cur)=>_extends({}, acc, {
|
|
508
|
+
[cur]: result[cur]
|
|
509
|
+
}), {});
|
|
510
|
+
return result;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
exports.getExternals = getExternals.getExternals;
|
|
514
|
+
exports.DEFAULT_SECONARIES_SKIP_LIST = DEFAULT_SECONARIES_SKIP_LIST;
|
|
515
|
+
exports._findSecondaries = _findSecondaries;
|
|
516
|
+
exports.addSecondaries = addSecondaries;
|
|
517
|
+
exports.findPackageJson = findPackageJson;
|
|
518
|
+
exports.findRootTsConfigJson = findRootTsConfigJson;
|
|
519
|
+
exports.findSecondaries = findSecondaries;
|
|
520
|
+
exports.getDefaultEntry = getDefaultEntry;
|
|
521
|
+
exports.getSecondaries = getSecondaries;
|
|
522
|
+
exports.loadFederationConfig = loadFederationConfig;
|
|
523
|
+
exports.logger = logger;
|
|
524
|
+
exports.lookupVersion = lookupVersion;
|
|
525
|
+
exports.lookupVersionInMap = lookupVersionInMap;
|
|
526
|
+
exports.readConfiguredSecondaries = readConfiguredSecondaries;
|
|
527
|
+
exports.setInferVersion = setInferVersion;
|
|
528
|
+
exports.setLogLevel = setLogLevel;
|
|
529
|
+
exports.share = share;
|
|
530
|
+
exports.shareAll = shareAll;
|
|
531
|
+
exports.withFederation = withFederation;
|
|
532
|
+
//# sourceMappingURL=build.cjs.js.map
|