@module-federation/esbuild 0.0.95 → 0.0.97

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.
Files changed (61) hide show
  1. package/dist/adapters/lib/collect-exports.js +151 -0
  2. package/dist/adapters/lib/collect-exports.mjs +87 -0
  3. package/dist/adapters/lib/commonjs.js +260 -0
  4. package/dist/adapters/lib/commonjs.mjs +209 -0
  5. package/dist/adapters/lib/containerPlugin.js +232 -0
  6. package/dist/adapters/lib/containerPlugin.mjs +182 -0
  7. package/dist/adapters/lib/containerReference.js +219 -0
  8. package/dist/adapters/lib/containerReference.mjs +154 -0
  9. package/dist/adapters/lib/lexer.js +184 -0
  10. package/dist/adapters/lib/lexer.mjs +138 -0
  11. package/dist/adapters/lib/linkRemotesPlugin.js +115 -0
  12. package/dist/adapters/lib/linkRemotesPlugin.mjs +50 -0
  13. package/dist/adapters/lib/manifest.js +229 -0
  14. package/dist/adapters/lib/manifest.mjs +168 -0
  15. package/dist/adapters/lib/plugin.js +339 -0
  16. package/dist/adapters/lib/plugin.mjs +282 -0
  17. package/dist/adapters/lib/react-replacements.js +81 -0
  18. package/dist/adapters/lib/react-replacements.mjs +35 -0
  19. package/dist/adapters/lib/transform.js +169 -0
  20. package/dist/adapters/lib/transform.mjs +120 -0
  21. package/dist/adapters/lib/utils.js +83 -0
  22. package/dist/adapters/lib/utils.mjs +33 -0
  23. package/dist/build.js +131 -473
  24. package/dist/build.mjs +13 -380
  25. package/dist/index.js +41 -26
  26. package/dist/index.mjs +4 -1
  27. package/dist/lib/config/configuration-context.js +70 -0
  28. package/dist/lib/config/configuration-context.mjs +20 -0
  29. package/dist/lib/config/federation-config.js +31 -0
  30. package/dist/lib/config/federation-config.mjs +4 -0
  31. package/dist/lib/config/share-utils.js +339 -0
  32. package/dist/lib/config/share-utils.mjs +254 -0
  33. package/dist/lib/config/with-native-federation.js +118 -0
  34. package/dist/lib/config/with-native-federation.mjs +71 -0
  35. package/dist/lib/core/build-adapter.js +70 -0
  36. package/dist/lib/core/build-adapter.mjs +18 -0
  37. package/dist/lib/core/createContainerTemplate.js +231 -0
  38. package/dist/lib/core/createContainerTemplate.mjs +185 -0
  39. package/dist/lib/core/default-skip-list.js +99 -0
  40. package/dist/lib/core/default-skip-list.mjs +47 -0
  41. package/dist/lib/core/federation-options.js +31 -0
  42. package/dist/lib/core/federation-options.mjs +4 -0
  43. package/dist/lib/core/get-externals.js +65 -0
  44. package/dist/lib/core/get-externals.mjs +19 -0
  45. package/dist/lib/core/load-federation-config.js +69 -0
  46. package/dist/lib/core/load-federation-config.mjs +20 -0
  47. package/dist/lib/core/write-federation-info.js +65 -0
  48. package/dist/lib/core/write-federation-info.mjs +16 -0
  49. package/dist/lib/utils/logger.js +111 -0
  50. package/dist/lib/utils/logger.mjs +46 -0
  51. package/dist/lib/utils/mapped-paths.js +94 -0
  52. package/dist/lib/utils/mapped-paths.mjs +46 -0
  53. package/dist/lib/utils/normalize.js +63 -0
  54. package/dist/lib/utils/normalize.mjs +17 -0
  55. package/dist/lib/utils/package-info.js +324 -0
  56. package/dist/lib/utils/package-info.mjs +265 -0
  57. package/dist/plugin.d.ts +1 -0
  58. package/dist/plugin.js +79 -1231
  59. package/dist/plugin.mjs +2 -1187
  60. package/dist/resolve/esm-resolver.mjs +15 -22
  61. package/package.json +2 -2
@@ -0,0 +1,265 @@
1
+ import { existsSync, readFileSync } from "fs";
2
+ import { dirname, join, relative } from "path";
3
+ import { logger } from "./logger.mjs";
4
+ import { normalize } from "./normalize.mjs";
5
+
6
+ ;// CONCATENATED MODULE: external "fs"
7
+
8
+ ;// CONCATENATED MODULE: external "path"
9
+
10
+ ;// CONCATENATED MODULE: external "./logger.mjs"
11
+
12
+ ;// CONCATENATED MODULE: external "./normalize.mjs"
13
+
14
+ ;// CONCATENATED MODULE: ./src/lib/utils/package-info.ts
15
+
16
+
17
+
18
+
19
+ const packageCache = {};
20
+ function findPackageJsonFiles(project, workspace) {
21
+ return expandFolders(project, workspace).map((f)=>join(f, 'package.json')).filter((f)=>existsSync(f));
22
+ }
23
+ function expandFolders(child, parent) {
24
+ const result = [];
25
+ parent = normalize(parent, true);
26
+ child = normalize(child, true);
27
+ if (!child.startsWith(parent)) {
28
+ throw new Error(`Workspace folder ${parent} needs to be a parent of the project folder ${child}`);
29
+ }
30
+ let current = child;
31
+ while(current !== parent){
32
+ result.push(current);
33
+ const cand = normalize(dirname(current), true);
34
+ if (cand === current) {
35
+ break;
36
+ }
37
+ current = cand;
38
+ }
39
+ result.push(parent);
40
+ return result;
41
+ }
42
+ function getPackageInfo(packageName, workspaceRoot) {
43
+ workspaceRoot = normalize(workspaceRoot, true);
44
+ const packageJsonInfos = getPackageJsonFiles(workspaceRoot, workspaceRoot);
45
+ for (const info of packageJsonInfos){
46
+ const cand = _getPackageInfo(packageName, info.directory);
47
+ if (cand) {
48
+ return cand;
49
+ }
50
+ }
51
+ logger.warn('No meta data found for shared lib ' + packageName);
52
+ return null;
53
+ }
54
+ function getVersionMapCacheKey(project, workspace) {
55
+ return `${project}**${workspace}`;
56
+ }
57
+ function getVersionMaps(project, workspace) {
58
+ return getPackageJsonFiles(project, workspace).map((json)=>({
59
+ ...json.content['dependencies']
60
+ }));
61
+ }
62
+ function getPackageJsonFiles(project, workspace) {
63
+ const cacheKey = getVersionMapCacheKey(project, workspace);
64
+ let maps = packageCache[cacheKey];
65
+ if (maps) {
66
+ return maps;
67
+ }
68
+ maps = findPackageJsonFiles(project, workspace).map((f)=>{
69
+ const content = JSON.parse(readFileSync(f, 'utf-8'));
70
+ const directory = normalize(dirname(f), true);
71
+ const result = {
72
+ content,
73
+ directory
74
+ };
75
+ return result;
76
+ });
77
+ packageCache[cacheKey] = maps;
78
+ return maps;
79
+ }
80
+ function findDepPackageJson(packageName, projectRoot) {
81
+ const mainPkgName = getPkgFolder(packageName);
82
+ let mainPkgPath = join(projectRoot, 'node_modules', mainPkgName);
83
+ let mainPkgJsonPath = join(mainPkgPath, 'package.json');
84
+ let directory = projectRoot;
85
+ while(dirname(directory) !== directory){
86
+ if (existsSync(mainPkgJsonPath)) {
87
+ break;
88
+ }
89
+ directory = normalize(dirname(directory), true);
90
+ mainPkgPath = join(directory, 'node_modules', mainPkgName);
91
+ mainPkgJsonPath = join(mainPkgPath, 'package.json');
92
+ }
93
+ if (!existsSync(mainPkgJsonPath)) {
94
+ logger.verbose('No package.json found for ' + packageName + ' in ' + mainPkgPath);
95
+ return null;
96
+ }
97
+ return mainPkgJsonPath;
98
+ }
99
+ function _getPackageInfo(packageName, directory) {
100
+ var _mainPkgJson_exports, _mainPkgJson_exports_relSecondaryPath, _mainPkgJson_exports1, _mainPkgJson_exports_relSecondaryPath1, _mainPkgJson_exports2, _mainPkgJson_exports_relSecondaryPath2, _mainPkgJson_exports3;
101
+ const mainPkgName = getPkgFolder(packageName);
102
+ const mainPkgJsonPath = findDepPackageJson(packageName, directory);
103
+ if (!mainPkgJsonPath) {
104
+ return null;
105
+ }
106
+ const mainPkgPath = dirname(mainPkgJsonPath);
107
+ const mainPkgJson = readJson(mainPkgJsonPath);
108
+ const version = mainPkgJson['version'];
109
+ const esm = mainPkgJson['type'] === 'module';
110
+ if (!version) {
111
+ logger.warn('No version found for ' + packageName);
112
+ return null;
113
+ }
114
+ let relSecondaryPath = relative(mainPkgName, packageName);
115
+ if (!relSecondaryPath) {
116
+ relSecondaryPath = '.';
117
+ } else {
118
+ relSecondaryPath = './' + relSecondaryPath.replace(/\\/g, '/');
119
+ }
120
+ let cand = mainPkgJson === null || mainPkgJson === void 0 ? void 0 : (_mainPkgJson_exports = mainPkgJson.exports) === null || _mainPkgJson_exports === void 0 ? void 0 : _mainPkgJson_exports[relSecondaryPath];
121
+ if (typeof cand === 'string') {
122
+ return {
123
+ entryPoint: join(mainPkgPath, cand),
124
+ packageName,
125
+ version,
126
+ esm
127
+ };
128
+ }
129
+ cand = mainPkgJson === null || mainPkgJson === void 0 ? void 0 : (_mainPkgJson_exports1 = mainPkgJson.exports) === null || _mainPkgJson_exports1 === void 0 ? void 0 : (_mainPkgJson_exports_relSecondaryPath = _mainPkgJson_exports1[relSecondaryPath]) === null || _mainPkgJson_exports_relSecondaryPath === void 0 ? void 0 : _mainPkgJson_exports_relSecondaryPath.import;
130
+ if (typeof cand === 'object') {
131
+ if (cand.module) {
132
+ cand = cand.module;
133
+ } else if (cand.import) {
134
+ cand = cand.import;
135
+ } else if (cand.default) {
136
+ cand = cand.default;
137
+ } else {
138
+ cand = null;
139
+ }
140
+ }
141
+ if (cand) {
142
+ if (typeof cand === 'object') {
143
+ if (cand.module) {
144
+ cand = cand.module;
145
+ } else if (cand.import) {
146
+ cand = cand.import;
147
+ } else if (cand.default) {
148
+ cand = cand.default;
149
+ } else {
150
+ cand = null;
151
+ }
152
+ }
153
+ return {
154
+ entryPoint: join(mainPkgPath, cand),
155
+ packageName,
156
+ version,
157
+ esm
158
+ };
159
+ }
160
+ cand = mainPkgJson === null || mainPkgJson === void 0 ? void 0 : (_mainPkgJson_exports2 = mainPkgJson.exports) === null || _mainPkgJson_exports2 === void 0 ? void 0 : (_mainPkgJson_exports_relSecondaryPath1 = _mainPkgJson_exports2[relSecondaryPath]) === null || _mainPkgJson_exports_relSecondaryPath1 === void 0 ? void 0 : _mainPkgJson_exports_relSecondaryPath1.module;
161
+ if (typeof cand === 'object') {
162
+ if (cand.module) {
163
+ cand = cand.module;
164
+ } else if (cand.import) {
165
+ cand = cand.import;
166
+ } else if (cand.default) {
167
+ cand = cand.default;
168
+ } else {
169
+ cand = null;
170
+ }
171
+ }
172
+ if (cand) {
173
+ return {
174
+ entryPoint: join(mainPkgPath, cand),
175
+ packageName,
176
+ version,
177
+ esm
178
+ };
179
+ }
180
+ cand = mainPkgJson === null || mainPkgJson === void 0 ? void 0 : (_mainPkgJson_exports3 = mainPkgJson.exports) === null || _mainPkgJson_exports3 === void 0 ? void 0 : (_mainPkgJson_exports_relSecondaryPath2 = _mainPkgJson_exports3[relSecondaryPath]) === null || _mainPkgJson_exports_relSecondaryPath2 === void 0 ? void 0 : _mainPkgJson_exports_relSecondaryPath2.default;
181
+ if (cand) {
182
+ if (typeof cand === 'object') {
183
+ if (cand.module) {
184
+ cand = cand.module;
185
+ } else if (cand.import) {
186
+ cand = cand.import;
187
+ } else if (cand.default) {
188
+ cand = cand.default;
189
+ } else {
190
+ cand = null;
191
+ }
192
+ }
193
+ return {
194
+ entryPoint: join(mainPkgPath, cand),
195
+ packageName,
196
+ version,
197
+ esm
198
+ };
199
+ }
200
+ cand = mainPkgJson['module'];
201
+ if (cand && relSecondaryPath === '.') {
202
+ return {
203
+ entryPoint: join(mainPkgPath, cand),
204
+ packageName,
205
+ version,
206
+ esm: true
207
+ };
208
+ }
209
+ const secondaryPgkPath = join(mainPkgPath, relSecondaryPath);
210
+ const secondaryPgkJsonPath = join(secondaryPgkPath, 'package.json');
211
+ let secondaryPgkJson = null;
212
+ if (existsSync(secondaryPgkJsonPath)) {
213
+ secondaryPgkJson = readJson(secondaryPgkJsonPath);
214
+ }
215
+ if (secondaryPgkJson && secondaryPgkJson.module) {
216
+ return {
217
+ entryPoint: join(secondaryPgkPath, secondaryPgkJson.module),
218
+ packageName,
219
+ version,
220
+ esm: true
221
+ };
222
+ }
223
+ cand = join(secondaryPgkPath, 'index.mjs');
224
+ if (existsSync(cand)) {
225
+ return {
226
+ entryPoint: cand,
227
+ packageName,
228
+ version,
229
+ esm: true
230
+ };
231
+ }
232
+ if (secondaryPgkJson && secondaryPgkJson.main) {
233
+ return {
234
+ entryPoint: join(secondaryPgkPath, secondaryPgkJson.main),
235
+ packageName,
236
+ version,
237
+ esm
238
+ };
239
+ }
240
+ cand = join(secondaryPgkPath, 'index.js');
241
+ if (existsSync(cand)) {
242
+ return {
243
+ entryPoint: cand,
244
+ packageName,
245
+ version,
246
+ esm
247
+ };
248
+ }
249
+ logger.warn('No entry point found for ' + packageName);
250
+ logger.warn("If you don't need this package, skip it in your federation.config.js or consider moving it into depDependencies in your package.json");
251
+ return null;
252
+ }
253
+ function readJson(mainPkgJsonPath) {
254
+ return JSON.parse(readFileSync(mainPkgJsonPath, 'utf-8'));
255
+ }
256
+ function getPkgFolder(packageName) {
257
+ const parts = packageName.split('/');
258
+ let folder = parts[0];
259
+ if (folder.startsWith('@')) {
260
+ folder += '/' + parts[1];
261
+ }
262
+ return folder;
263
+ }
264
+
265
+ export { _getPackageInfo, expandFolders, findDepPackageJson, findPackageJsonFiles, getPackageInfo, getPackageJsonFiles, getVersionMaps };
@@ -0,0 +1 @@
1
+ export * from './adapters/lib/plugin';