@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.
@@ -0,0 +1,389 @@
1
+ import { g as getVersionMaps, a as getConfigContext, b as findDepPackageJson, l as logger } from './federation-builder.esm.js';
2
+ export { j as buildForFederation, k as bundleExposedAndMappings, p as createBuildResultMap, i as defaultBuildParams, m as describeExposed, n as describeSharedMappings, f as federationBuilder, c as getBuildAdapter, e as getExternals, h as loadFederationConfig, l as logger, q as lookupInResultMap, s as setBuildAdapter, o as setLogLevel, d as writeFederationInfo, w as writeImportMap } from './federation-builder.esm.js';
3
+ import * as path from 'path';
4
+ import path__default from 'path';
5
+ import * as fs from 'fs';
6
+ import fs__default from 'fs';
7
+ import process from 'process';
8
+ import * as JSON5 from 'json5';
9
+ import * as crypto from 'crypto';
10
+ import 'npmlog';
11
+
12
+ const DEFAULT_SKIP_LIST = [
13
+ '@module-federation/native-federation-runtime',
14
+ '@module-federation/native-federation',
15
+ '@module-federation/native-federation-core',
16
+ '@module-federation/native-federation-esbuild',
17
+ '@angular-architects/native-federation',
18
+ '@angular-architects/native-federation-runtime',
19
+ 'es-module-shims',
20
+ 'zone.js',
21
+ 'tslib/',
22
+ '@angular/localize',
23
+ '@angular/localize/init',
24
+ '@angular/localize/tools',
25
+ '@angular/platform-server',
26
+ '@angular/platform-server/init',
27
+ '@angular/ssr',
28
+ 'express',
29
+ /\/schematics(\/|$)/,
30
+ /^@nx\/angular/,
31
+ (pkg)=>pkg.startsWith('@angular/') && !!pkg.match(/\/testing(\/|$)/),
32
+ (pkg)=>pkg.startsWith('@types/')
33
+ ];
34
+ const PREPARED_DEFAULT_SKIP_LIST = prepareSkipList(DEFAULT_SKIP_LIST);
35
+ function prepareSkipList(skipList) {
36
+ return {
37
+ strings: new Set(skipList.filter((e)=>typeof e === 'string')),
38
+ functions: skipList.filter((e)=>typeof e === 'function'),
39
+ regexps: skipList.filter((e)=>typeof e === 'object')
40
+ };
41
+ }
42
+ function isInSkipList(entry, skipList) {
43
+ if (skipList.strings.has(entry)) {
44
+ return true;
45
+ }
46
+ if (skipList.functions.find((f)=>f(entry))) {
47
+ return true;
48
+ }
49
+ if (skipList.regexps.find((r)=>r.test(entry))) {
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+
55
+ let inferVersion = false;
56
+ const DEFAULT_SECONARIES_SKIP_LIST = [
57
+ '@angular/router/upgrade',
58
+ '@angular/common/upgrade'
59
+ ];
60
+ function findRootTsConfigJson() {
61
+ const packageJson = findPackageJson(process.cwd());
62
+ const projectRoot = path__default.dirname(packageJson);
63
+ const tsConfigBaseJson = path__default.join(projectRoot, 'tsconfig.base.json');
64
+ const tsConfigJson = path__default.join(projectRoot, 'tsconfig.json');
65
+ if (fs__default.existsSync(tsConfigBaseJson)) {
66
+ return tsConfigBaseJson;
67
+ } else if (fs__default.existsSync(tsConfigJson)) {
68
+ return tsConfigJson;
69
+ }
70
+ throw new Error('Neither a tsconfig.json nor a tsconfig.base.json was found');
71
+ }
72
+ function findPackageJson(folder) {
73
+ while(!fs__default.existsSync(path__default.join(folder, 'package.json')) && path__default.dirname(folder) !== folder){
74
+ folder = path__default.dirname(folder);
75
+ }
76
+ const filePath = path__default.join(folder, 'package.json');
77
+ if (fs__default.existsSync(filePath)) {
78
+ return filePath;
79
+ }
80
+ throw new Error('no package.json found. Searched the following folder and all parents: ' + folder);
81
+ }
82
+ function lookupVersion(key, workspaceRoot) {
83
+ const versionMaps = getVersionMaps(workspaceRoot, workspaceRoot);
84
+ for (const versionMap of versionMaps){
85
+ const version = lookupVersionInMap(key, versionMap);
86
+ if (version) {
87
+ return version;
88
+ }
89
+ }
90
+ throw new Error(`Shared Dependency ${key} has requiredVersion:'auto'. However, this dependency is not found in your package.json`);
91
+ }
92
+ function lookupVersionInMap(key, versions) {
93
+ const parts = key.split('/');
94
+ if (parts.length >= 2 && parts[0].startsWith('@')) {
95
+ key = parts[0] + '/' + parts[1];
96
+ } else {
97
+ key = parts[0];
98
+ }
99
+ if (key.toLowerCase() === '@angular-architects/module-federation-runtime') {
100
+ key = '@angular-architects/module-federation';
101
+ }
102
+ if (!versions[key]) {
103
+ return null;
104
+ }
105
+ return versions[key];
106
+ }
107
+ function _findSecondaries(libPath, excludes, shareObject, acc) {
108
+ const files = fs__default.readdirSync(libPath);
109
+ const dirs = files.map((f)=>path__default.join(libPath, f)).filter((f)=>fs__default.lstatSync(f).isDirectory() && f !== 'node_modules');
110
+ const secondaries = dirs.filter((d)=>fs__default.existsSync(path__default.join(d, 'package.json')));
111
+ for (const s of secondaries){
112
+ const secondaryLibName = s.replace(/\\/g, '/').replace(/^.*node_modules[/]/, '');
113
+ if (excludes.includes(secondaryLibName)) {
114
+ continue;
115
+ }
116
+ if (isInSkipList(secondaryLibName, PREPARED_DEFAULT_SKIP_LIST)) {
117
+ continue;
118
+ }
119
+ acc[secondaryLibName] = Object.assign({}, shareObject);
120
+ _findSecondaries(s, excludes, shareObject, acc);
121
+ }
122
+ }
123
+ function findSecondaries(libPath, excludes, shareObject) {
124
+ const acc = {};
125
+ _findSecondaries(libPath, excludes, shareObject, acc);
126
+ return acc;
127
+ }
128
+ function getSecondaries(includeSecondaries, libPath, key, shareObject) {
129
+ let exclude = [
130
+ ...DEFAULT_SECONARIES_SKIP_LIST
131
+ ];
132
+ if (typeof includeSecondaries === 'object') {
133
+ if (Array.isArray(includeSecondaries.skip)) {
134
+ exclude = includeSecondaries.skip;
135
+ } else if (typeof includeSecondaries.skip === 'string') {
136
+ exclude = [
137
+ includeSecondaries.skip
138
+ ];
139
+ }
140
+ }
141
+ if (!fs__default.existsSync(libPath)) {
142
+ return {};
143
+ }
144
+ const configured = readConfiguredSecondaries(key, libPath, exclude, shareObject);
145
+ if (configured) {
146
+ return configured;
147
+ }
148
+ // Fallback: Search folders
149
+ const secondaries = findSecondaries(libPath, exclude, shareObject);
150
+ return secondaries;
151
+ }
152
+ function readConfiguredSecondaries(parent, libPath, exclude, shareObject) {
153
+ const libPackageJson = path__default.join(libPath, 'package.json');
154
+ if (!fs__default.existsSync(libPackageJson)) {
155
+ return null;
156
+ }
157
+ const packageJson = JSON.parse(fs__default.readFileSync(libPackageJson, 'utf-8'));
158
+ const exports = packageJson['exports'];
159
+ if (!exports) {
160
+ return null;
161
+ }
162
+ const keys = Object.keys(exports).filter((key)=>key != '.' && key != './package.json' && !key.endsWith('*') && (exports[key]['default'] || typeof exports[key] === 'string'));
163
+ const result = {};
164
+ for (const key of keys){
165
+ // const relPath = exports[key]['default'];
166
+ const secondaryName = path__default.join(parent, key).replace(/\\/g, '/');
167
+ if (exclude.includes(secondaryName)) {
168
+ continue;
169
+ }
170
+ if (isInSkipList(secondaryName, PREPARED_DEFAULT_SKIP_LIST)) {
171
+ continue;
172
+ }
173
+ const entry = getDefaultEntry(exports, key);
174
+ if (typeof entry !== 'string') {
175
+ console.log('No entry point found for ' + secondaryName);
176
+ continue;
177
+ }
178
+ 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'))) {
179
+ continue;
180
+ }
181
+ result[secondaryName] = Object.assign({}, shareObject);
182
+ }
183
+ return result;
184
+ }
185
+ function getDefaultEntry(exports, key) {
186
+ var _a;
187
+ let entry = '';
188
+ if (typeof exports[key] === 'string') {
189
+ entry = exports[key];
190
+ } else {
191
+ entry = (_a = exports[key]) === null || _a === void 0 ? void 0 : _a['default'];
192
+ if (typeof entry === 'object') {
193
+ entry = entry['default'];
194
+ }
195
+ }
196
+ return entry;
197
+ }
198
+ function shareAll(config = {}, skip = DEFAULT_SKIP_LIST, projectPath = '') {
199
+ // let workspacePath: string | undefined = undefined;
200
+ projectPath = inferProjectPath(projectPath);
201
+ // workspacePath = getConfigContext().workspaceRoot ?? '';
202
+ // if (!workspacePath) {
203
+ // workspacePath = projectPath;
204
+ // }
205
+ const versionMaps = getVersionMaps(projectPath, projectPath);
206
+ const share = {};
207
+ for (const versions of versionMaps){
208
+ const preparedSkipList = prepareSkipList(skip);
209
+ for(const key in versions){
210
+ if (isInSkipList(key, preparedSkipList)) {
211
+ continue;
212
+ }
213
+ const inferVersion = !config.requiredVersion || config.requiredVersion === 'auto';
214
+ const requiredVersion = inferVersion ? versions[key] : config.requiredVersion;
215
+ if (!share[key]) {
216
+ share[key] = Object.assign(Object.assign({}, config), {
217
+ requiredVersion
218
+ });
219
+ }
220
+ }
221
+ }
222
+ return module.exports.share(share, projectPath);
223
+ }
224
+ function inferProjectPath(projectPath) {
225
+ if (!projectPath && getConfigContext().packageJson) {
226
+ projectPath = path__default.dirname(getConfigContext().packageJson || '');
227
+ }
228
+ if (!projectPath && getConfigContext().workspaceRoot) {
229
+ projectPath = getConfigContext().workspaceRoot || '';
230
+ }
231
+ if (!projectPath) {
232
+ projectPath = process.cwd();
233
+ }
234
+ return projectPath;
235
+ }
236
+ function setInferVersion(infer) {
237
+ inferVersion = infer;
238
+ }
239
+ function share(shareObjects, projectPath = '') {
240
+ projectPath = inferProjectPath(projectPath);
241
+ const packagePath = findPackageJson(projectPath);
242
+ // const versions = readVersionMap(packagePath);
243
+ const result = {};
244
+ let includeSecondaries;
245
+ for(const key in shareObjects){
246
+ includeSecondaries = false;
247
+ const shareObject = shareObjects[key];
248
+ if (shareObject.requiredVersion === 'auto' || inferVersion && typeof shareObject.requiredVersion === 'undefined') {
249
+ const version = lookupVersion(key, projectPath);
250
+ shareObject.requiredVersion = version;
251
+ shareObject.version = version.replace(/^\D*/, '');
252
+ }
253
+ if (typeof shareObject.includeSecondaries === 'undefined') {
254
+ shareObject.includeSecondaries = true;
255
+ }
256
+ if (shareObject.includeSecondaries) {
257
+ includeSecondaries = shareObject.includeSecondaries;
258
+ delete shareObject.includeSecondaries;
259
+ }
260
+ result[key] = shareObject;
261
+ if (includeSecondaries) {
262
+ const libPackageJson = findDepPackageJson(key, path__default.dirname(packagePath));
263
+ if (!libPackageJson) {
264
+ logger.error('Could not find folder containing dep ' + key);
265
+ continue;
266
+ }
267
+ const libPath = path__default.dirname(libPackageJson);
268
+ const secondaries = getSecondaries(includeSecondaries, libPath, key, shareObject);
269
+ if (secondaries) {
270
+ addSecondaries(secondaries, result);
271
+ }
272
+ }
273
+ }
274
+ return result;
275
+ }
276
+ function addSecondaries(secondaries, result) {
277
+ for(const key in secondaries){
278
+ result[key] = secondaries[key];
279
+ }
280
+ }
281
+
282
+ function getMappedPaths({ rootTsConfigPath, sharedMappings, rootPath }) {
283
+ var _tsConfig_compilerOptions;
284
+ const result = [];
285
+ if (!path.isAbsolute(rootTsConfigPath)) {
286
+ throw new Error('SharedMappings.register: tsConfigPath needs to be an absolute path!');
287
+ }
288
+ if (!rootPath) {
289
+ rootPath = path.normalize(path.dirname(rootTsConfigPath));
290
+ }
291
+ const shareAll = !sharedMappings;
292
+ if (!sharedMappings) {
293
+ sharedMappings = [];
294
+ }
295
+ const tsConfig = JSON5.parse(fs.readFileSync(rootTsConfigPath, {
296
+ encoding: 'utf-8'
297
+ }));
298
+ const mappings = tsConfig == null ? void 0 : (_tsConfig_compilerOptions = tsConfig.compilerOptions) == null ? void 0 : _tsConfig_compilerOptions.paths;
299
+ if (!mappings) {
300
+ return result;
301
+ }
302
+ for(const key in mappings){
303
+ const libPath = path.normalize(path.join(rootPath, mappings[key][0]));
304
+ if (sharedMappings.includes(key) || shareAll) {
305
+ result.push({
306
+ key,
307
+ path: libPath
308
+ });
309
+ }
310
+ }
311
+ return result;
312
+ }
313
+
314
+ function _extends() {
315
+ _extends = Object.assign || function(target) {
316
+ for(var i = 1; i < arguments.length; i++){
317
+ var source = arguments[i];
318
+ for(var key in source){
319
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
320
+ target[key] = source[key];
321
+ }
322
+ }
323
+ }
324
+ return target;
325
+ };
326
+ return _extends.apply(this, arguments);
327
+ }
328
+ function withFederation(config) {
329
+ var _config_skip;
330
+ const skip = prepareSkipList((_config_skip = config.skip) != null ? _config_skip : []);
331
+ var _config_name, _config_filename, _config_exposes, _config_remotes;
332
+ return {
333
+ name: (_config_name = config.name) != null ? _config_name : '',
334
+ filename: (_config_filename = config.filename) != null ? _config_filename : 'remoteEntry',
335
+ exposes: (_config_exposes = config.exposes) != null ? _config_exposes : {},
336
+ remotes: (_config_remotes = config.remotes) != null ? _config_remotes : {},
337
+ shared: normalizeShared(config, skip),
338
+ sharedMappings: normalizeSharedMappings(config, skip)
339
+ };
340
+ }
341
+ function normalizeShared(config, skip) {
342
+ let result = {};
343
+ const shared = config.shared;
344
+ if (!shared) {
345
+ result = shareAll({
346
+ singleton: true,
347
+ strictVersion: true,
348
+ requiredVersion: 'auto'
349
+ });
350
+ } else {
351
+ result = Object.keys(shared).reduce((acc, cur)=>{
352
+ var _shared_cur_requiredVersion, _shared_cur_singleton, _shared_cur_strictVersion;
353
+ return _extends({}, acc, {
354
+ [cur]: {
355
+ requiredVersion: (_shared_cur_requiredVersion = shared[cur].requiredVersion) != null ? _shared_cur_requiredVersion : 'auto',
356
+ singleton: (_shared_cur_singleton = shared[cur].singleton) != null ? _shared_cur_singleton : false,
357
+ strictVersion: (_shared_cur_strictVersion = shared[cur].strictVersion) != null ? _shared_cur_strictVersion : false,
358
+ version: shared[cur].version,
359
+ includeSecondaries: shared[cur].includeSecondaries
360
+ }
361
+ });
362
+ }, {});
363
+ }
364
+ result = Object.keys(result).filter((key)=>!isInSkipList(key, skip)).reduce((acc, cur)=>_extends({}, acc, {
365
+ [cur]: result[cur]
366
+ }), {});
367
+ return result;
368
+ }
369
+ function normalizeSharedMappings(config, skip) {
370
+ const rootTsConfigPath = findRootTsConfigJson();
371
+ const paths = getMappedPaths({
372
+ rootTsConfigPath,
373
+ sharedMappings: config.sharedMappings
374
+ });
375
+ const result = paths.filter((p)=>!isInSkipList(p.key, skip) && !p.key.includes('*'));
376
+ if (paths.find((p)=>p.key.includes('*'))) {
377
+ logger.warn('Sharing mapped paths with wildcards (*) not supported');
378
+ }
379
+ return result;
380
+ }
381
+
382
+ function hashFile(fileName) {
383
+ const fileBuffer = fs.readFileSync(fileName);
384
+ const hashSum = crypto.createHash('md5');
385
+ hashSum.update(fileBuffer);
386
+ return hashSum.digest('hex');
387
+ }
388
+
389
+ export { DEFAULT_SECONARIES_SKIP_LIST, _findSecondaries, addSecondaries, findPackageJson, findRootTsConfigJson, findSecondaries, getDefaultEntry, getSecondaries, hashFile, inferProjectPath, lookupVersion, lookupVersionInMap, readConfiguredSecondaries, setInferVersion, share, shareAll, withFederation };
@@ -0,0 +1,2 @@
1
+ export * from "./src/adapters/esbuild";
2
+ export { default } from "./src/adapters/esbuild";