@module-federation/vite 1.2.0 → 1.2.2
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/lib/index.cjs +26 -4
- package/lib/index.esm.js +26 -4
- package/lib/index.modern.js +26 -4
- package/lib/index.umd.js +26 -4
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -330,12 +330,34 @@ function removePathFromNpmPackage(packageString) {
|
|
|
330
330
|
// 返回匹配到的包名,如果没有匹配到则返回原字符串
|
|
331
331
|
return match ? match[0] : packageString;
|
|
332
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Tries to find the package.json's version of a shared package
|
|
335
|
+
* if `package.json` is not declared in `exports`
|
|
336
|
+
* @param {string} sharedName
|
|
337
|
+
* @returns {string | undefined}
|
|
338
|
+
*/
|
|
339
|
+
function searchPackageVersion(sharedName) {
|
|
340
|
+
try {
|
|
341
|
+
var sharedPath = require.resolve(sharedName);
|
|
342
|
+
var potentialPackageJsonDir = path__namespace.dirname(sharedPath);
|
|
343
|
+
var rootDir = path__namespace.parse(potentialPackageJsonDir).root;
|
|
344
|
+
while (path__namespace.parse(potentialPackageJsonDir).base !== 'node_modules' && potentialPackageJsonDir !== rootDir) {
|
|
345
|
+
var potentialPackageJson = path__namespace.join(potentialPackageJsonDir, 'package.json');
|
|
346
|
+
if (fs__namespace.existsSync(potentialPackageJson)) {
|
|
347
|
+
return require(potentialPackageJson).version;
|
|
348
|
+
}
|
|
349
|
+
potentialPackageJsonDir = path__namespace.dirname(potentialPackageJsonDir);
|
|
350
|
+
}
|
|
351
|
+
} catch (_) {}
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
333
354
|
function normalizeShareItem(key, shareItem) {
|
|
334
355
|
var version;
|
|
335
356
|
try {
|
|
336
357
|
version = require(path__namespace.join(removePathFromNpmPackage(key), 'package.json')).version;
|
|
337
358
|
} catch (e) {
|
|
338
|
-
|
|
359
|
+
version = searchPackageVersion(key);
|
|
360
|
+
if (!version) console.error(e);
|
|
339
361
|
}
|
|
340
362
|
if (typeof shareItem === 'string') {
|
|
341
363
|
return {
|
|
@@ -1214,7 +1236,7 @@ function proxySharedModule(options) {
|
|
|
1214
1236
|
writePreBuildLibPath(source);
|
|
1215
1237
|
addUsedShares(source);
|
|
1216
1238
|
writeLocalSharedImportMap();
|
|
1217
|
-
return this.resolve(loadSharePath);
|
|
1239
|
+
return this.resolve(loadSharePath, importer);
|
|
1218
1240
|
}
|
|
1219
1241
|
};
|
|
1220
1242
|
}));
|
|
@@ -1233,7 +1255,7 @@ function proxySharedModule(options) {
|
|
|
1233
1255
|
try {
|
|
1234
1256
|
var _this = this;
|
|
1235
1257
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1236
|
-
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1258
|
+
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1237
1259
|
return item.id;
|
|
1238
1260
|
})).then(function (result) {
|
|
1239
1261
|
if (!result.includes(_config.cacheDir)) {
|
|
@@ -1243,7 +1265,7 @@ function proxySharedModule(options) {
|
|
|
1243
1265
|
// Fix localSharedImportMap import id
|
|
1244
1266
|
var _resolve = _this.resolve;
|
|
1245
1267
|
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1246
|
-
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1268
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
|
|
1247
1269
|
});
|
|
1248
1270
|
});
|
|
1249
1271
|
} catch (e) {
|
package/lib/index.esm.js
CHANGED
|
@@ -306,12 +306,34 @@ function removePathFromNpmPackage(packageString) {
|
|
|
306
306
|
// 返回匹配到的包名,如果没有匹配到则返回原字符串
|
|
307
307
|
return match ? match[0] : packageString;
|
|
308
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Tries to find the package.json's version of a shared package
|
|
311
|
+
* if `package.json` is not declared in `exports`
|
|
312
|
+
* @param {string} sharedName
|
|
313
|
+
* @returns {string | undefined}
|
|
314
|
+
*/
|
|
315
|
+
function searchPackageVersion(sharedName) {
|
|
316
|
+
try {
|
|
317
|
+
var sharedPath = require.resolve(sharedName);
|
|
318
|
+
var potentialPackageJsonDir = path.dirname(sharedPath);
|
|
319
|
+
var rootDir = path.parse(potentialPackageJsonDir).root;
|
|
320
|
+
while (path.parse(potentialPackageJsonDir).base !== 'node_modules' && potentialPackageJsonDir !== rootDir) {
|
|
321
|
+
var potentialPackageJson = path.join(potentialPackageJsonDir, 'package.json');
|
|
322
|
+
if (fs.existsSync(potentialPackageJson)) {
|
|
323
|
+
return require(potentialPackageJson).version;
|
|
324
|
+
}
|
|
325
|
+
potentialPackageJsonDir = path.dirname(potentialPackageJsonDir);
|
|
326
|
+
}
|
|
327
|
+
} catch (_) {}
|
|
328
|
+
return undefined;
|
|
329
|
+
}
|
|
309
330
|
function normalizeShareItem(key, shareItem) {
|
|
310
331
|
var version;
|
|
311
332
|
try {
|
|
312
333
|
version = require(path.join(removePathFromNpmPackage(key), 'package.json')).version;
|
|
313
334
|
} catch (e) {
|
|
314
|
-
|
|
335
|
+
version = searchPackageVersion(key);
|
|
336
|
+
if (!version) console.error(e);
|
|
315
337
|
}
|
|
316
338
|
if (typeof shareItem === 'string') {
|
|
317
339
|
return {
|
|
@@ -1190,7 +1212,7 @@ function proxySharedModule(options) {
|
|
|
1190
1212
|
writePreBuildLibPath(source);
|
|
1191
1213
|
addUsedShares(source);
|
|
1192
1214
|
writeLocalSharedImportMap();
|
|
1193
|
-
return this.resolve(loadSharePath);
|
|
1215
|
+
return this.resolve(loadSharePath, importer);
|
|
1194
1216
|
}
|
|
1195
1217
|
};
|
|
1196
1218
|
}));
|
|
@@ -1209,7 +1231,7 @@ function proxySharedModule(options) {
|
|
|
1209
1231
|
try {
|
|
1210
1232
|
var _this = this;
|
|
1211
1233
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1212
|
-
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1234
|
+
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1213
1235
|
return item.id;
|
|
1214
1236
|
})).then(function (result) {
|
|
1215
1237
|
if (!result.includes(_config.cacheDir)) {
|
|
@@ -1219,7 +1241,7 @@ function proxySharedModule(options) {
|
|
|
1219
1241
|
// Fix localSharedImportMap import id
|
|
1220
1242
|
var _resolve = _this.resolve;
|
|
1221
1243
|
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1222
|
-
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1244
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
|
|
1223
1245
|
});
|
|
1224
1246
|
});
|
|
1225
1247
|
} catch (e) {
|
package/lib/index.modern.js
CHANGED
|
@@ -279,12 +279,34 @@ function removePathFromNpmPackage(packageString) {
|
|
|
279
279
|
// 返回匹配到的包名,如果没有匹配到则返回原字符串
|
|
280
280
|
return match ? match[0] : packageString;
|
|
281
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Tries to find the package.json's version of a shared package
|
|
284
|
+
* if `package.json` is not declared in `exports`
|
|
285
|
+
* @param {string} sharedName
|
|
286
|
+
* @returns {string | undefined}
|
|
287
|
+
*/
|
|
288
|
+
function searchPackageVersion(sharedName) {
|
|
289
|
+
try {
|
|
290
|
+
const sharedPath = require.resolve(sharedName);
|
|
291
|
+
let potentialPackageJsonDir = path.dirname(sharedPath);
|
|
292
|
+
const rootDir = path.parse(potentialPackageJsonDir).root;
|
|
293
|
+
while (path.parse(potentialPackageJsonDir).base !== 'node_modules' && potentialPackageJsonDir !== rootDir) {
|
|
294
|
+
const potentialPackageJson = path.join(potentialPackageJsonDir, 'package.json');
|
|
295
|
+
if (fs.existsSync(potentialPackageJson)) {
|
|
296
|
+
return require(potentialPackageJson).version;
|
|
297
|
+
}
|
|
298
|
+
potentialPackageJsonDir = path.dirname(potentialPackageJsonDir);
|
|
299
|
+
}
|
|
300
|
+
} catch (_) {}
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
282
303
|
function normalizeShareItem(key, shareItem) {
|
|
283
304
|
let version;
|
|
284
305
|
try {
|
|
285
306
|
version = require(path.join(removePathFromNpmPackage(key), 'package.json')).version;
|
|
286
307
|
} catch (e) {
|
|
287
|
-
|
|
308
|
+
version = searchPackageVersion(key);
|
|
309
|
+
if (!version) console.error(e);
|
|
288
310
|
}
|
|
289
311
|
if (typeof shareItem === 'string') {
|
|
290
312
|
return {
|
|
@@ -1264,7 +1286,7 @@ function proxySharedModule(options) {
|
|
|
1264
1286
|
writePreBuildLibPath(source);
|
|
1265
1287
|
addUsedShares(source);
|
|
1266
1288
|
writeLocalSharedImportMap();
|
|
1267
|
-
return this.resolve(loadSharePath);
|
|
1289
|
+
return this.resolve(loadSharePath, importer);
|
|
1268
1290
|
}
|
|
1269
1291
|
};
|
|
1270
1292
|
}));
|
|
@@ -1281,13 +1303,13 @@ function proxySharedModule(options) {
|
|
|
1281
1303
|
replacement: '$1',
|
|
1282
1304
|
async customResolver(source, importer) {
|
|
1283
1305
|
const pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1284
|
-
const result = await this.resolve(pkgName).then(item => item.id);
|
|
1306
|
+
const result = await this.resolve(pkgName, importer).then(item => item.id);
|
|
1285
1307
|
if (!result.includes(_config.cacheDir)) {
|
|
1286
1308
|
// save pre-bunding module id
|
|
1287
1309
|
savePrebuild.set(pkgName, Promise.resolve(result));
|
|
1288
1310
|
}
|
|
1289
1311
|
// Fix localSharedImportMap import id
|
|
1290
|
-
return await this.resolve(await savePrebuild.get(pkgName));
|
|
1312
|
+
return await this.resolve(await savePrebuild.get(pkgName), importer);
|
|
1291
1313
|
}
|
|
1292
1314
|
};
|
|
1293
1315
|
}));
|
package/lib/index.umd.js
CHANGED
|
@@ -328,12 +328,34 @@
|
|
|
328
328
|
// 返回匹配到的包名,如果没有匹配到则返回原字符串
|
|
329
329
|
return match ? match[0] : packageString;
|
|
330
330
|
}
|
|
331
|
+
/**
|
|
332
|
+
* Tries to find the package.json's version of a shared package
|
|
333
|
+
* if `package.json` is not declared in `exports`
|
|
334
|
+
* @param {string} sharedName
|
|
335
|
+
* @returns {string | undefined}
|
|
336
|
+
*/
|
|
337
|
+
function searchPackageVersion(sharedName) {
|
|
338
|
+
try {
|
|
339
|
+
var sharedPath = require.resolve(sharedName);
|
|
340
|
+
var potentialPackageJsonDir = path__namespace.dirname(sharedPath);
|
|
341
|
+
var rootDir = path__namespace.parse(potentialPackageJsonDir).root;
|
|
342
|
+
while (path__namespace.parse(potentialPackageJsonDir).base !== 'node_modules' && potentialPackageJsonDir !== rootDir) {
|
|
343
|
+
var potentialPackageJson = path__namespace.join(potentialPackageJsonDir, 'package.json');
|
|
344
|
+
if (fs__namespace.existsSync(potentialPackageJson)) {
|
|
345
|
+
return require(potentialPackageJson).version;
|
|
346
|
+
}
|
|
347
|
+
potentialPackageJsonDir = path__namespace.dirname(potentialPackageJsonDir);
|
|
348
|
+
}
|
|
349
|
+
} catch (_) {}
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
331
352
|
function normalizeShareItem(key, shareItem) {
|
|
332
353
|
var version;
|
|
333
354
|
try {
|
|
334
355
|
version = require(path__namespace.join(removePathFromNpmPackage(key), 'package.json')).version;
|
|
335
356
|
} catch (e) {
|
|
336
|
-
|
|
357
|
+
version = searchPackageVersion(key);
|
|
358
|
+
if (!version) console.error(e);
|
|
337
359
|
}
|
|
338
360
|
if (typeof shareItem === 'string') {
|
|
339
361
|
return {
|
|
@@ -1212,7 +1234,7 @@
|
|
|
1212
1234
|
writePreBuildLibPath(source);
|
|
1213
1235
|
addUsedShares(source);
|
|
1214
1236
|
writeLocalSharedImportMap();
|
|
1215
|
-
return this.resolve(loadSharePath);
|
|
1237
|
+
return this.resolve(loadSharePath, importer);
|
|
1216
1238
|
}
|
|
1217
1239
|
};
|
|
1218
1240
|
}));
|
|
@@ -1231,7 +1253,7 @@
|
|
|
1231
1253
|
try {
|
|
1232
1254
|
var _this = this;
|
|
1233
1255
|
var pkgName = VirtualModule.findModule(PREBUILD_TAG, source).name;
|
|
1234
|
-
return Promise.resolve(_this.resolve(pkgName).then(function (item) {
|
|
1256
|
+
return Promise.resolve(_this.resolve(pkgName, importer).then(function (item) {
|
|
1235
1257
|
return item.id;
|
|
1236
1258
|
})).then(function (result) {
|
|
1237
1259
|
if (!result.includes(_config.cacheDir)) {
|
|
@@ -1241,7 +1263,7 @@
|
|
|
1241
1263
|
// Fix localSharedImportMap import id
|
|
1242
1264
|
var _resolve = _this.resolve;
|
|
1243
1265
|
return Promise.resolve(savePrebuild.get(pkgName)).then(function (_savePrebuild$get) {
|
|
1244
|
-
return Promise.resolve(_resolve.call(_this, _savePrebuild$get));
|
|
1266
|
+
return Promise.resolve(_resolve.call(_this, _savePrebuild$get, importer));
|
|
1245
1267
|
});
|
|
1246
1268
|
});
|
|
1247
1269
|
} catch (e) {
|