@module-federation/sdk 0.2.2 → 0.2.3
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/dist/index.cjs.js +174 -74
- package/dist/index.esm.js +174 -74
- package/dist/package.json +1 -1
- package/dist/src/normalizeOptions.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -620,7 +620,7 @@ function _define_property$1(obj, key, value) {
|
|
|
620
620
|
}
|
|
621
621
|
return obj;
|
|
622
622
|
}
|
|
623
|
-
function _instanceof(left, right) {
|
|
623
|
+
function _instanceof$1(left, right) {
|
|
624
624
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
625
625
|
return !!right[Symbol.hasInstance](left);
|
|
626
626
|
} else {
|
|
@@ -812,7 +812,7 @@ function createScript(info) {
|
|
|
812
812
|
script.src = info.url;
|
|
813
813
|
if (info.createScriptHook) {
|
|
814
814
|
var createScriptRes = info.createScriptHook(info.url);
|
|
815
|
-
if (_instanceof(createScriptRes, HTMLScriptElement)) {
|
|
815
|
+
if (_instanceof$1(createScriptRes, HTMLScriptElement)) {
|
|
816
816
|
script = createScriptRes;
|
|
817
817
|
} else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
|
|
818
818
|
if (createScriptRes.script) script = createScriptRes.script;
|
|
@@ -888,7 +888,7 @@ function createLink(info) {
|
|
|
888
888
|
link.setAttribute('href', info.url);
|
|
889
889
|
if (info.createLinkHook) {
|
|
890
890
|
var createLinkRes = info.createLinkHook(info.url);
|
|
891
|
-
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
891
|
+
if (_instanceof$1(createLinkRes, HTMLLinkElement)) {
|
|
892
892
|
link = createLinkRes;
|
|
893
893
|
}
|
|
894
894
|
}
|
|
@@ -983,6 +983,13 @@ function _async_to_generator(fn) {
|
|
|
983
983
|
});
|
|
984
984
|
};
|
|
985
985
|
}
|
|
986
|
+
function _instanceof(left, right) {
|
|
987
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
988
|
+
return !!right[Symbol.hasInstance](left);
|
|
989
|
+
} else {
|
|
990
|
+
return left instanceof right;
|
|
991
|
+
}
|
|
992
|
+
}
|
|
986
993
|
function _iterable_to_array_limit(arr, i) {
|
|
987
994
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
988
995
|
if (_i == null) return;
|
|
@@ -1132,6 +1139,85 @@ function importNodeModule(name) {
|
|
|
1132
1139
|
throw error;
|
|
1133
1140
|
});
|
|
1134
1141
|
}
|
|
1142
|
+
var loadNodeFetch = function() {
|
|
1143
|
+
var _ref = _async_to_generator(function() {
|
|
1144
|
+
var fetchModule;
|
|
1145
|
+
return _ts_generator(this, function(_state) {
|
|
1146
|
+
switch(_state.label){
|
|
1147
|
+
case 0:
|
|
1148
|
+
return [
|
|
1149
|
+
4,
|
|
1150
|
+
importNodeModule('node-fetch')
|
|
1151
|
+
];
|
|
1152
|
+
case 1:
|
|
1153
|
+
fetchModule = _state.sent();
|
|
1154
|
+
return [
|
|
1155
|
+
2,
|
|
1156
|
+
fetchModule.default || fetchModule
|
|
1157
|
+
];
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
return function loadNodeFetch1() {
|
|
1162
|
+
return _ref.apply(this, arguments);
|
|
1163
|
+
};
|
|
1164
|
+
}();
|
|
1165
|
+
var lazyLoaderHookFetch = function() {
|
|
1166
|
+
var _ref = _async_to_generator(function(input, init) {
|
|
1167
|
+
var loaderHooks, hook, res, fetchFunction, _tmp;
|
|
1168
|
+
return _ts_generator(this, function(_state) {
|
|
1169
|
+
switch(_state.label){
|
|
1170
|
+
case 0:
|
|
1171
|
+
// @ts-ignore
|
|
1172
|
+
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1173
|
+
hook = function(url, init) {
|
|
1174
|
+
return loaderHooks.lifecycle.fetch.emit(url, init);
|
|
1175
|
+
};
|
|
1176
|
+
return [
|
|
1177
|
+
4,
|
|
1178
|
+
hook(input, init || {})
|
|
1179
|
+
];
|
|
1180
|
+
case 1:
|
|
1181
|
+
res = _state.sent();
|
|
1182
|
+
if (!(!res || !_instanceof(res, Response))) return [
|
|
1183
|
+
3,
|
|
1184
|
+
5
|
|
1185
|
+
];
|
|
1186
|
+
if (!(typeof fetch === 'undefined')) return [
|
|
1187
|
+
3,
|
|
1188
|
+
3
|
|
1189
|
+
];
|
|
1190
|
+
return [
|
|
1191
|
+
4,
|
|
1192
|
+
loadNodeFetch()
|
|
1193
|
+
];
|
|
1194
|
+
case 2:
|
|
1195
|
+
_tmp = _state.sent();
|
|
1196
|
+
return [
|
|
1197
|
+
3,
|
|
1198
|
+
4
|
|
1199
|
+
];
|
|
1200
|
+
case 3:
|
|
1201
|
+
_tmp = fetch;
|
|
1202
|
+
_state.label = 4;
|
|
1203
|
+
case 4:
|
|
1204
|
+
fetchFunction = _tmp;
|
|
1205
|
+
return [
|
|
1206
|
+
2,
|
|
1207
|
+
fetchFunction(input, init || {})
|
|
1208
|
+
];
|
|
1209
|
+
case 5:
|
|
1210
|
+
return [
|
|
1211
|
+
2,
|
|
1212
|
+
res
|
|
1213
|
+
];
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
});
|
|
1217
|
+
return function lazyLoaderHookFetch1(input, init) {
|
|
1218
|
+
return _ref.apply(this, arguments);
|
|
1219
|
+
};
|
|
1220
|
+
}();
|
|
1135
1221
|
function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
1136
1222
|
if (createScriptHook) {
|
|
1137
1223
|
var hookResult = createScriptHook(url);
|
|
@@ -1149,100 +1235,114 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1149
1235
|
}
|
|
1150
1236
|
var getFetch = function() {
|
|
1151
1237
|
var _ref = _async_to_generator(function() {
|
|
1152
|
-
var
|
|
1238
|
+
var loaderHooks;
|
|
1239
|
+
return _ts_generator(this, function(_state) {
|
|
1240
|
+
//@ts-ignore
|
|
1241
|
+
if (typeof __webpack_require__ !== 'undefined') {
|
|
1242
|
+
try {
|
|
1243
|
+
//@ts-ignore
|
|
1244
|
+
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1245
|
+
if (loaderHooks.lifecycle.fetch) {
|
|
1246
|
+
return [
|
|
1247
|
+
2,
|
|
1248
|
+
lazyLoaderHookFetch
|
|
1249
|
+
];
|
|
1250
|
+
}
|
|
1251
|
+
} catch (e) {
|
|
1252
|
+
console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return [
|
|
1256
|
+
2,
|
|
1257
|
+
typeof fetch === 'undefined' ? loadNodeFetch() : fetch
|
|
1258
|
+
];
|
|
1259
|
+
});
|
|
1260
|
+
});
|
|
1261
|
+
return function getFetch() {
|
|
1262
|
+
return _ref.apply(this, arguments);
|
|
1263
|
+
};
|
|
1264
|
+
}();
|
|
1265
|
+
var handleScriptFetch = function() {
|
|
1266
|
+
var _ref = _async_to_generator(function(f, urlObj) {
|
|
1267
|
+
var res, data, _ref, path, vm, scriptContext, urlDirname, filename, script, exportedInterface, container, e;
|
|
1153
1268
|
return _ts_generator(this, function(_state) {
|
|
1154
1269
|
switch(_state.label){
|
|
1155
1270
|
case 0:
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1271
|
+
_state.trys.push([
|
|
1272
|
+
0,
|
|
1273
|
+
4,
|
|
1274
|
+
,
|
|
1275
|
+
5
|
|
1276
|
+
]);
|
|
1160
1277
|
return [
|
|
1161
1278
|
4,
|
|
1162
|
-
|
|
1279
|
+
f(urlObj.href)
|
|
1163
1280
|
];
|
|
1164
1281
|
case 1:
|
|
1165
|
-
|
|
1166
|
-
//@ts-ignore
|
|
1282
|
+
res = _state.sent();
|
|
1167
1283
|
return [
|
|
1168
|
-
|
|
1169
|
-
(
|
|
1284
|
+
4,
|
|
1285
|
+
res.text()
|
|
1170
1286
|
];
|
|
1171
1287
|
case 2:
|
|
1288
|
+
data = _state.sent();
|
|
1172
1289
|
return [
|
|
1173
|
-
|
|
1174
|
-
|
|
1290
|
+
4,
|
|
1291
|
+
Promise.all([
|
|
1292
|
+
importNodeModule('path'),
|
|
1293
|
+
importNodeModule('vm')
|
|
1294
|
+
])
|
|
1175
1295
|
];
|
|
1176
1296
|
case 3:
|
|
1297
|
+
_ref = _sliced_to_array.apply(void 0, [
|
|
1298
|
+
_state.sent(),
|
|
1299
|
+
2
|
|
1300
|
+
]), path = _ref[0], vm = _ref[1];
|
|
1301
|
+
scriptContext = {
|
|
1302
|
+
exports: {},
|
|
1303
|
+
module: {
|
|
1304
|
+
exports: {}
|
|
1305
|
+
}
|
|
1306
|
+
};
|
|
1307
|
+
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1308
|
+
filename = path.basename(urlObj.pathname);
|
|
1309
|
+
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1310
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1311
|
+
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1312
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1313
|
+
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1314
|
+
cb(undefined, container);
|
|
1315
|
+
return [
|
|
1316
|
+
2
|
|
1317
|
+
];
|
|
1318
|
+
}
|
|
1319
|
+
cb(undefined, exportedInterface);
|
|
1320
|
+
return [
|
|
1321
|
+
3,
|
|
1322
|
+
5
|
|
1323
|
+
];
|
|
1324
|
+
case 4:
|
|
1325
|
+
e = _state.sent();
|
|
1326
|
+
cb(new Error("Script execution error: ".concat(e)));
|
|
1327
|
+
return [
|
|
1328
|
+
3,
|
|
1329
|
+
5
|
|
1330
|
+
];
|
|
1331
|
+
case 5:
|
|
1177
1332
|
return [
|
|
1178
1333
|
2
|
|
1179
1334
|
];
|
|
1180
1335
|
}
|
|
1181
1336
|
});
|
|
1182
1337
|
});
|
|
1183
|
-
return function
|
|
1338
|
+
return function handleScriptFetch(f, urlObj) {
|
|
1184
1339
|
return _ref.apply(this, arguments);
|
|
1185
1340
|
};
|
|
1186
1341
|
}();
|
|
1187
|
-
console.log('fetching', urlObj.href);
|
|
1188
1342
|
getFetch().then(function(f) {
|
|
1189
|
-
f
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
var _ref = _async_to_generator(function(data) {
|
|
1193
|
-
var _ref, path, vm, scriptContext, urlDirname, filename, script, exportedInterface, container;
|
|
1194
|
-
return _ts_generator(this, function(_state) {
|
|
1195
|
-
switch(_state.label){
|
|
1196
|
-
case 0:
|
|
1197
|
-
return [
|
|
1198
|
-
4,
|
|
1199
|
-
Promise.all([
|
|
1200
|
-
importNodeModule('path'),
|
|
1201
|
-
importNodeModule('vm')
|
|
1202
|
-
])
|
|
1203
|
-
];
|
|
1204
|
-
case 1:
|
|
1205
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1206
|
-
_state.sent(),
|
|
1207
|
-
2
|
|
1208
|
-
]), path = _ref[0], vm = _ref[1];
|
|
1209
|
-
scriptContext = {
|
|
1210
|
-
exports: {},
|
|
1211
|
-
module: {
|
|
1212
|
-
exports: {}
|
|
1213
|
-
}
|
|
1214
|
-
};
|
|
1215
|
-
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1216
|
-
filename = path.basename(urlObj.pathname);
|
|
1217
|
-
try {
|
|
1218
|
-
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1219
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1220
|
-
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1221
|
-
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1222
|
-
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1223
|
-
cb(undefined, container);
|
|
1224
|
-
return [
|
|
1225
|
-
2
|
|
1226
|
-
];
|
|
1227
|
-
}
|
|
1228
|
-
cb(undefined, exportedInterface);
|
|
1229
|
-
} catch (e) {
|
|
1230
|
-
// console.error('Error running script:', e);
|
|
1231
|
-
cb(new Error("Script execution error: ".concat(e)));
|
|
1232
|
-
}
|
|
1233
|
-
return [
|
|
1234
|
-
2
|
|
1235
|
-
];
|
|
1236
|
-
}
|
|
1237
|
-
});
|
|
1238
|
-
});
|
|
1239
|
-
return function(data) {
|
|
1240
|
-
return _ref.apply(this, arguments);
|
|
1241
|
-
};
|
|
1242
|
-
}()).catch(function(err) {
|
|
1243
|
-
// console.error('Error fetching script:', err);
|
|
1244
|
-
cb(err);
|
|
1245
|
-
});
|
|
1343
|
+
return handleScriptFetch(f, urlObj);
|
|
1344
|
+
}).catch(function(err) {
|
|
1345
|
+
cb(err);
|
|
1246
1346
|
});
|
|
1247
1347
|
}
|
|
1248
1348
|
function loadScriptNode(url, info) {
|
package/dist/index.esm.js
CHANGED
|
@@ -616,7 +616,7 @@ function _define_property$1(obj, key, value) {
|
|
|
616
616
|
}
|
|
617
617
|
return obj;
|
|
618
618
|
}
|
|
619
|
-
function _instanceof(left, right) {
|
|
619
|
+
function _instanceof$1(left, right) {
|
|
620
620
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
621
621
|
return !!right[Symbol.hasInstance](left);
|
|
622
622
|
} else {
|
|
@@ -808,7 +808,7 @@ function createScript(info) {
|
|
|
808
808
|
script.src = info.url;
|
|
809
809
|
if (info.createScriptHook) {
|
|
810
810
|
var createScriptRes = info.createScriptHook(info.url);
|
|
811
|
-
if (_instanceof(createScriptRes, HTMLScriptElement)) {
|
|
811
|
+
if (_instanceof$1(createScriptRes, HTMLScriptElement)) {
|
|
812
812
|
script = createScriptRes;
|
|
813
813
|
} else if ((typeof createScriptRes === "undefined" ? "undefined" : _type_of$2(createScriptRes)) === 'object') {
|
|
814
814
|
if (createScriptRes.script) script = createScriptRes.script;
|
|
@@ -884,7 +884,7 @@ function createLink(info) {
|
|
|
884
884
|
link.setAttribute('href', info.url);
|
|
885
885
|
if (info.createLinkHook) {
|
|
886
886
|
var createLinkRes = info.createLinkHook(info.url);
|
|
887
|
-
if (_instanceof(createLinkRes, HTMLLinkElement)) {
|
|
887
|
+
if (_instanceof$1(createLinkRes, HTMLLinkElement)) {
|
|
888
888
|
link = createLinkRes;
|
|
889
889
|
}
|
|
890
890
|
}
|
|
@@ -979,6 +979,13 @@ function _async_to_generator(fn) {
|
|
|
979
979
|
});
|
|
980
980
|
};
|
|
981
981
|
}
|
|
982
|
+
function _instanceof(left, right) {
|
|
983
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
984
|
+
return !!right[Symbol.hasInstance](left);
|
|
985
|
+
} else {
|
|
986
|
+
return left instanceof right;
|
|
987
|
+
}
|
|
988
|
+
}
|
|
982
989
|
function _iterable_to_array_limit(arr, i) {
|
|
983
990
|
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
984
991
|
if (_i == null) return;
|
|
@@ -1128,6 +1135,85 @@ function importNodeModule(name) {
|
|
|
1128
1135
|
throw error;
|
|
1129
1136
|
});
|
|
1130
1137
|
}
|
|
1138
|
+
var loadNodeFetch = function() {
|
|
1139
|
+
var _ref = _async_to_generator(function() {
|
|
1140
|
+
var fetchModule;
|
|
1141
|
+
return _ts_generator(this, function(_state) {
|
|
1142
|
+
switch(_state.label){
|
|
1143
|
+
case 0:
|
|
1144
|
+
return [
|
|
1145
|
+
4,
|
|
1146
|
+
importNodeModule('node-fetch')
|
|
1147
|
+
];
|
|
1148
|
+
case 1:
|
|
1149
|
+
fetchModule = _state.sent();
|
|
1150
|
+
return [
|
|
1151
|
+
2,
|
|
1152
|
+
fetchModule.default || fetchModule
|
|
1153
|
+
];
|
|
1154
|
+
}
|
|
1155
|
+
});
|
|
1156
|
+
});
|
|
1157
|
+
return function loadNodeFetch1() {
|
|
1158
|
+
return _ref.apply(this, arguments);
|
|
1159
|
+
};
|
|
1160
|
+
}();
|
|
1161
|
+
var lazyLoaderHookFetch = function() {
|
|
1162
|
+
var _ref = _async_to_generator(function(input, init) {
|
|
1163
|
+
var loaderHooks, hook, res, fetchFunction, _tmp;
|
|
1164
|
+
return _ts_generator(this, function(_state) {
|
|
1165
|
+
switch(_state.label){
|
|
1166
|
+
case 0:
|
|
1167
|
+
// @ts-ignore
|
|
1168
|
+
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1169
|
+
hook = function(url, init) {
|
|
1170
|
+
return loaderHooks.lifecycle.fetch.emit(url, init);
|
|
1171
|
+
};
|
|
1172
|
+
return [
|
|
1173
|
+
4,
|
|
1174
|
+
hook(input, init || {})
|
|
1175
|
+
];
|
|
1176
|
+
case 1:
|
|
1177
|
+
res = _state.sent();
|
|
1178
|
+
if (!(!res || !_instanceof(res, Response))) return [
|
|
1179
|
+
3,
|
|
1180
|
+
5
|
|
1181
|
+
];
|
|
1182
|
+
if (!(typeof fetch === 'undefined')) return [
|
|
1183
|
+
3,
|
|
1184
|
+
3
|
|
1185
|
+
];
|
|
1186
|
+
return [
|
|
1187
|
+
4,
|
|
1188
|
+
loadNodeFetch()
|
|
1189
|
+
];
|
|
1190
|
+
case 2:
|
|
1191
|
+
_tmp = _state.sent();
|
|
1192
|
+
return [
|
|
1193
|
+
3,
|
|
1194
|
+
4
|
|
1195
|
+
];
|
|
1196
|
+
case 3:
|
|
1197
|
+
_tmp = fetch;
|
|
1198
|
+
_state.label = 4;
|
|
1199
|
+
case 4:
|
|
1200
|
+
fetchFunction = _tmp;
|
|
1201
|
+
return [
|
|
1202
|
+
2,
|
|
1203
|
+
fetchFunction(input, init || {})
|
|
1204
|
+
];
|
|
1205
|
+
case 5:
|
|
1206
|
+
return [
|
|
1207
|
+
2,
|
|
1208
|
+
res
|
|
1209
|
+
];
|
|
1210
|
+
}
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
return function lazyLoaderHookFetch1(input, init) {
|
|
1214
|
+
return _ref.apply(this, arguments);
|
|
1215
|
+
};
|
|
1216
|
+
}();
|
|
1131
1217
|
function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
1132
1218
|
if (createScriptHook) {
|
|
1133
1219
|
var hookResult = createScriptHook(url);
|
|
@@ -1145,100 +1231,114 @@ function createScriptNode(url, cb, attrs, createScriptHook) {
|
|
|
1145
1231
|
}
|
|
1146
1232
|
var getFetch = function() {
|
|
1147
1233
|
var _ref = _async_to_generator(function() {
|
|
1148
|
-
var
|
|
1234
|
+
var loaderHooks;
|
|
1235
|
+
return _ts_generator(this, function(_state) {
|
|
1236
|
+
//@ts-ignore
|
|
1237
|
+
if (typeof __webpack_require__ !== 'undefined') {
|
|
1238
|
+
try {
|
|
1239
|
+
//@ts-ignore
|
|
1240
|
+
loaderHooks = __webpack_require__.federation.instance.loaderHook;
|
|
1241
|
+
if (loaderHooks.lifecycle.fetch) {
|
|
1242
|
+
return [
|
|
1243
|
+
2,
|
|
1244
|
+
lazyLoaderHookFetch
|
|
1245
|
+
];
|
|
1246
|
+
}
|
|
1247
|
+
} catch (e) {
|
|
1248
|
+
console.warn('federation.instance.loaderHook.lifecycle.fetch failed:', e);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return [
|
|
1252
|
+
2,
|
|
1253
|
+
typeof fetch === 'undefined' ? loadNodeFetch() : fetch
|
|
1254
|
+
];
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
return function getFetch() {
|
|
1258
|
+
return _ref.apply(this, arguments);
|
|
1259
|
+
};
|
|
1260
|
+
}();
|
|
1261
|
+
var handleScriptFetch = function() {
|
|
1262
|
+
var _ref = _async_to_generator(function(f, urlObj) {
|
|
1263
|
+
var res, data, _ref, path, vm, scriptContext, urlDirname, filename, script, exportedInterface, container, e;
|
|
1149
1264
|
return _ts_generator(this, function(_state) {
|
|
1150
1265
|
switch(_state.label){
|
|
1151
1266
|
case 0:
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1267
|
+
_state.trys.push([
|
|
1268
|
+
0,
|
|
1269
|
+
4,
|
|
1270
|
+
,
|
|
1271
|
+
5
|
|
1272
|
+
]);
|
|
1156
1273
|
return [
|
|
1157
1274
|
4,
|
|
1158
|
-
|
|
1275
|
+
f(urlObj.href)
|
|
1159
1276
|
];
|
|
1160
1277
|
case 1:
|
|
1161
|
-
|
|
1162
|
-
//@ts-ignore
|
|
1278
|
+
res = _state.sent();
|
|
1163
1279
|
return [
|
|
1164
|
-
|
|
1165
|
-
(
|
|
1280
|
+
4,
|
|
1281
|
+
res.text()
|
|
1166
1282
|
];
|
|
1167
1283
|
case 2:
|
|
1284
|
+
data = _state.sent();
|
|
1168
1285
|
return [
|
|
1169
|
-
|
|
1170
|
-
|
|
1286
|
+
4,
|
|
1287
|
+
Promise.all([
|
|
1288
|
+
importNodeModule('path'),
|
|
1289
|
+
importNodeModule('vm')
|
|
1290
|
+
])
|
|
1171
1291
|
];
|
|
1172
1292
|
case 3:
|
|
1293
|
+
_ref = _sliced_to_array.apply(void 0, [
|
|
1294
|
+
_state.sent(),
|
|
1295
|
+
2
|
|
1296
|
+
]), path = _ref[0], vm = _ref[1];
|
|
1297
|
+
scriptContext = {
|
|
1298
|
+
exports: {},
|
|
1299
|
+
module: {
|
|
1300
|
+
exports: {}
|
|
1301
|
+
}
|
|
1302
|
+
};
|
|
1303
|
+
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1304
|
+
filename = path.basename(urlObj.pathname);
|
|
1305
|
+
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1306
|
+
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1307
|
+
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1308
|
+
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1309
|
+
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1310
|
+
cb(undefined, container);
|
|
1311
|
+
return [
|
|
1312
|
+
2
|
|
1313
|
+
];
|
|
1314
|
+
}
|
|
1315
|
+
cb(undefined, exportedInterface);
|
|
1316
|
+
return [
|
|
1317
|
+
3,
|
|
1318
|
+
5
|
|
1319
|
+
];
|
|
1320
|
+
case 4:
|
|
1321
|
+
e = _state.sent();
|
|
1322
|
+
cb(new Error("Script execution error: ".concat(e)));
|
|
1323
|
+
return [
|
|
1324
|
+
3,
|
|
1325
|
+
5
|
|
1326
|
+
];
|
|
1327
|
+
case 5:
|
|
1173
1328
|
return [
|
|
1174
1329
|
2
|
|
1175
1330
|
];
|
|
1176
1331
|
}
|
|
1177
1332
|
});
|
|
1178
1333
|
});
|
|
1179
|
-
return function
|
|
1334
|
+
return function handleScriptFetch(f, urlObj) {
|
|
1180
1335
|
return _ref.apply(this, arguments);
|
|
1181
1336
|
};
|
|
1182
1337
|
}();
|
|
1183
|
-
console.log('fetching', urlObj.href);
|
|
1184
1338
|
getFetch().then(function(f) {
|
|
1185
|
-
f
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
var _ref = _async_to_generator(function(data) {
|
|
1189
|
-
var _ref, path, vm, scriptContext, urlDirname, filename, script, exportedInterface, container;
|
|
1190
|
-
return _ts_generator(this, function(_state) {
|
|
1191
|
-
switch(_state.label){
|
|
1192
|
-
case 0:
|
|
1193
|
-
return [
|
|
1194
|
-
4,
|
|
1195
|
-
Promise.all([
|
|
1196
|
-
importNodeModule('path'),
|
|
1197
|
-
importNodeModule('vm')
|
|
1198
|
-
])
|
|
1199
|
-
];
|
|
1200
|
-
case 1:
|
|
1201
|
-
_ref = _sliced_to_array.apply(void 0, [
|
|
1202
|
-
_state.sent(),
|
|
1203
|
-
2
|
|
1204
|
-
]), path = _ref[0], vm = _ref[1];
|
|
1205
|
-
scriptContext = {
|
|
1206
|
-
exports: {},
|
|
1207
|
-
module: {
|
|
1208
|
-
exports: {}
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
urlDirname = urlObj.pathname.split('/').slice(0, -1).join('/');
|
|
1212
|
-
filename = path.basename(urlObj.pathname);
|
|
1213
|
-
try {
|
|
1214
|
-
script = new vm.Script("(function(exports, module, require, __dirname, __filename) {".concat(data, "\n})"), filename);
|
|
1215
|
-
script.runInThisContext()(scriptContext.exports, scriptContext.module, eval('require'), urlDirname, filename);
|
|
1216
|
-
exportedInterface = scriptContext.module.exports || scriptContext.exports;
|
|
1217
|
-
if (attrs && exportedInterface && attrs['globalName']) {
|
|
1218
|
-
container = exportedInterface[attrs['globalName']] || exportedInterface;
|
|
1219
|
-
cb(undefined, container);
|
|
1220
|
-
return [
|
|
1221
|
-
2
|
|
1222
|
-
];
|
|
1223
|
-
}
|
|
1224
|
-
cb(undefined, exportedInterface);
|
|
1225
|
-
} catch (e) {
|
|
1226
|
-
// console.error('Error running script:', e);
|
|
1227
|
-
cb(new Error("Script execution error: ".concat(e)));
|
|
1228
|
-
}
|
|
1229
|
-
return [
|
|
1230
|
-
2
|
|
1231
|
-
];
|
|
1232
|
-
}
|
|
1233
|
-
});
|
|
1234
|
-
});
|
|
1235
|
-
return function(data) {
|
|
1236
|
-
return _ref.apply(this, arguments);
|
|
1237
|
-
};
|
|
1238
|
-
}()).catch(function(err) {
|
|
1239
|
-
// console.error('Error fetching script:', err);
|
|
1240
|
-
cb(err);
|
|
1241
|
-
});
|
|
1339
|
+
return handleScriptFetch(f, urlObj);
|
|
1340
|
+
}).catch(function(err) {
|
|
1341
|
+
cb(err);
|
|
1242
1342
|
});
|
|
1243
1343
|
}
|
|
1244
1344
|
function loadScriptNode(url, info) {
|
package/dist/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function normalizeOptions<T>(enableDefault: boolean, defaultOptions: T, key: string): <U extends boolean |
|
|
1
|
+
export declare function normalizeOptions<T>(enableDefault: boolean, defaultOptions: T, key: string): <U extends boolean | undefined | T>(options: U) => T | false;
|