isolated-externals-plugin
Advanced tools
Comparing version 2.4.0-preload-non-esm-fef1d9c.1 to 2.4.0
import { Compiler } from 'webpack'; | ||
import { ExternalInfo } from './util/externalsClasses'; | ||
export type Maybe<T> = T | undefined | null; | ||
interface UnpromisedEntries { | ||
[key: string]: string[]; | ||
} | ||
export interface IsolatedExternalsElement { | ||
@@ -13,5 +15,8 @@ [key: string]: ExternalInfo; | ||
readonly externalsModuleLocation: string; | ||
readonly unpromisedEntryModuleLocation: string; | ||
readonly moduleDir: string; | ||
constructor(config: IsolatedExternals, externalsModuleLocation: string); | ||
readonly unpromisedEntries: UnpromisedEntries; | ||
constructor(config?: IsolatedExternals, externalsModuleLocation?: string, unpromisedEntryModuleLocation?: string); | ||
apply(compiler: Compiler): void; | ||
} | ||
export {}; |
@@ -66,5 +66,6 @@ "use strict"; | ||
class IsolatedExternalsPlugin { | ||
constructor(config = {}, externalsModuleLocation) { | ||
constructor(config = {}, externalsModuleLocation = '', unpromisedEntryModuleLocation = '') { | ||
this.config = config; | ||
this.externalsModuleLocation = externalsModuleLocation; | ||
this.unpromisedEntryModuleLocation = unpromisedEntryModuleLocation; | ||
(0, schema_utils_1.validate)(configSchema, config, { | ||
@@ -77,3 +78,7 @@ name: 'IsolatedExternalsPlugin', | ||
path_1.default.join(__dirname, 'util', 'isolatedExternalsModule.js'); | ||
this.unpromisedEntryModuleLocation = | ||
unpromisedEntryModuleLocation || | ||
path_1.default.join(__dirname, 'util', 'unpromisedEntry.js'); | ||
this.moduleDir = path_1.default.dirname(this.externalsModuleLocation); | ||
this.unpromisedEntries = {}; | ||
} | ||
@@ -117,23 +122,21 @@ apply(compiler) { | ||
}) | ||
.flatMap(([entryName, externals]) => [ | ||
{ | ||
test: /isolatedExternalsModule.js/, | ||
resourceQuery: new RegExp(`${entryName}$`), | ||
use: [ | ||
{ | ||
loader: path_1.default.resolve(path_1.default.join(this.moduleDir, 'isolatedExternalsLoader.js')), | ||
options: externals, | ||
}, | ||
], | ||
}, | ||
{ | ||
resourceQuery: new RegExp(`isolatedExternalsEntry=${entryName}`), | ||
use: [ | ||
{ | ||
loader: path_1.default.resolve(path_1.default.join(this.moduleDir, 'unpromised-entry-loader.js')), | ||
}, | ||
], | ||
}, | ||
]), | ||
.map(([entryName, externals]) => ({ | ||
test: /isolatedExternalsModule.js/, | ||
resourceQuery: new RegExp(`${entryName}$`), | ||
use: [ | ||
{ | ||
loader: path_1.default.resolve(path_1.default.join(this.moduleDir, 'isolatedExternalsLoader.js')), | ||
options: externals, | ||
}, | ||
], | ||
})), | ||
{ | ||
resourceQuery: /unpromised-entry/, | ||
use: [ | ||
{ | ||
loader: path_1.default.resolve(path_1.default.join(this.moduleDir, 'unpromised-entry-loader.js')), | ||
}, | ||
], | ||
}, | ||
{ | ||
resourceQuery: /unpromise-external/, | ||
@@ -165,86 +168,256 @@ use: [ | ||
}); | ||
compiler.hooks.thisCompilation.tap('IsolatedExternalsPlugin', (compilation, compilationParams) => { | ||
const isolateCompilationEntries = (compilation, compilationParams) => { | ||
const logger = compilation.getLogger('IsolatedExternalsPlugin'); | ||
const { normalModuleFactory } = compilationParams; | ||
const unpromisedEntries = {}; | ||
const getTargetEntry = (dep) => { | ||
var _a; | ||
if (!dep) { | ||
const unpromisedEntries = this.unpromisedEntries; | ||
const getParentModule = (result) => compilation.moduleGraph.getParentModule(result.dependencies[0]); | ||
const getEntryParams = (modules) => modules | ||
.map(({ rawRequest }) => { | ||
if (!rawRequest) | ||
return; | ||
const entryName = (0, getRequestParam_1.default)(rawRequest, 'isolatedExternalsEntry') || | ||
(0, getRequestParam_1.default)(rawRequest, 'unpromised-entry'); | ||
if (entryName) { | ||
return entryName; | ||
} | ||
const { rawRequest = '' } = dep || {}; | ||
if (rawRequest) { | ||
const entryName = (0, getRequestParam_1.default)(rawRequest, 'isolatedExternalsEntry'); | ||
if (entryName) { | ||
return dep; | ||
}) | ||
.filter((s) => Boolean(s)); | ||
const getTargetEntries = (dependency, parents) => { | ||
const entries = getEntryParams([dependency, ...parents]); | ||
return [...new Set(entries)]; | ||
}; | ||
function updateRequestWithParam(request, paramName, paramValue) { | ||
const param = `${paramName}=${encodeURIComponent(paramValue)}`; | ||
const parmRegex = new RegExp(`[?&]${paramName}=[^&]+`); | ||
const newRequest = request.replace(parmRegex, ''); | ||
const delimiter = newRequest.includes('?') ? '&' : '?'; | ||
return `${request}${delimiter}${param}`; | ||
} | ||
const getEntryDepsRequest = (entryName, request, replacedRequest, replacedContext) => { | ||
if (!entryName) | ||
return request; | ||
const unpromiseDeps = this.unpromisedEntries[entryName]; | ||
if (!unpromiseDeps) | ||
return request; | ||
const originalRequest = (0, getRequestParam_1.default)(replacedRequest, 'originalRequest') || | ||
replacedRequest; | ||
const originalContext = (0, getRequestParam_1.default)(replacedRequest, 'originalContext') || | ||
replacedContext; | ||
let depRequest = updateRequestWithParam(request, 'originalRequest', originalRequest); | ||
depRequest = updateRequestWithParam(depRequest, 'originalContext', originalContext); | ||
depRequest = updateRequestWithParam(depRequest, 'unpromised-entry', entryName); | ||
depRequest = updateRequestWithParam(depRequest, 'deps', unpromiseDeps.join(',')); | ||
return depRequest; | ||
}; | ||
function getEntryDep(entryName, request) { | ||
if (!entryName) | ||
return; | ||
const entry = compilation.entries.get(entryName); | ||
if (!entry) | ||
return; | ||
const newEntryDep = webpack_1.EntryPlugin.createDependency(request, entry.options || entryName); | ||
return newEntryDep; | ||
} | ||
const setsEqual = (setA, setB) => setA.size === setB.size && [...setA].every((value) => setB.has(value)); | ||
const knownParents = {}; | ||
const addKnownParent = (req, info) => { | ||
var _a; | ||
return (knownParents[req] = Object.assign(Object.assign({}, info), { entries: [ | ||
...new Set([ | ||
...(((_a = knownParents[req]) === null || _a === void 0 ? void 0 : _a.entries) || []), | ||
...(info.entries || []), | ||
]), | ||
] })); | ||
}; | ||
const getKnownParent = (req, parents) => { | ||
const knownParent = knownParents[req]; | ||
return Boolean(knownParents[req]) && | ||
setsEqual(createModuleSet(parents), knownParent.connections) | ||
? knownParent | ||
: undefined; | ||
}; | ||
const moduleHasNonEsmDeps = (module) => module.dependencies.some((dep) => !['unknown', 'esm', 'self'].includes(dep.category) || | ||
dep.constructor.name.includes('CommonJs')); | ||
const parentsHaveNonEsmDep = (parent, parents = []) => { | ||
if (!parents.length) { | ||
logger.debug(`top level parent: \n`, parent.identifier()); | ||
return moduleHasNonEsmDeps(parent); | ||
} | ||
function* hasNonEsmDepGen() { | ||
let parentInd = 0; | ||
let isNonEsm = false; | ||
while (parentInd < parents.length && !isNonEsm) { | ||
let targetParent = parents[parentInd]; | ||
while (!targetParent && parentInd < parents.length) | ||
targetParent = parents[++parentInd]; | ||
if (!targetParent) | ||
return isNonEsm; | ||
isNonEsm = isNonEsmParent(targetParent); | ||
parentInd++; | ||
yield isNonEsm; | ||
} | ||
return isNonEsm; | ||
} | ||
const connections = Array.from(compilation.moduleGraph.getIncomingConnections(dep)); | ||
return getTargetEntry((_a = connections.find((conn) => conn.originModule !== dep && | ||
getTargetEntry(conn.originModule))) === null || _a === void 0 ? void 0 : _a.originModule); | ||
const hasNonEsmDep = hasNonEsmDepGen(); | ||
for (const isNonEsm of hasNonEsmDep) { | ||
if (isNonEsm) | ||
return true; | ||
} | ||
return false; | ||
}; | ||
const getTargetEntryFromDeps = (deps) => { | ||
const targetEntry = deps === null || deps === void 0 ? void 0 : deps.map((dep) => getTargetEntry(compilation.moduleGraph.getParentModule(dep))).find(Boolean); | ||
return targetEntry; | ||
const createModuleSet = (arr) => new Set(arr.filter((m) => Boolean(m)).map((m) => m.identifier())); | ||
const isNonEsmParent = (parent, existingParents) => { | ||
const knownResult = knownParents[parent.identifier()]; | ||
const parents = existingParents; | ||
const parentSet = parents | ||
? createModuleSet(parents) | ||
: new Set(); | ||
try { | ||
if (knownResult && setsEqual(knownResult.connections, parentSet)) { | ||
return knownResult.isNonEsm; | ||
} | ||
const hasNonEsmDeps = moduleHasNonEsmDeps(parent); | ||
const isNonEsm = hasNonEsmDeps || parents | ||
? parentsHaveNonEsmDep(parent, parents) | ||
: false; | ||
addKnownParent(parent.identifier(), { | ||
isNonEsm, | ||
connections: parentSet, | ||
}); | ||
if (hasNonEsmDeps) { | ||
logger.debug('found non-esm parent', { | ||
req: parent.identifier(), | ||
deps: parent.dependencies.map((dep) => { | ||
const { category, constructor: { name: constructorName }, } = dep; | ||
return { | ||
category, | ||
id: dep.request, | ||
name: dep.name, | ||
constructorName, | ||
}; | ||
}), | ||
}); | ||
} | ||
return isNonEsm; | ||
} | ||
catch (err) { | ||
console.warn('Error in isNonEsmParent: ', { | ||
req: parent.identifier(), | ||
parentSet, | ||
}); | ||
console.error(err); | ||
logger.error(err); | ||
throw err; | ||
} | ||
}; | ||
async function rebuildEntryModule(entryName, request, context, unpromiseDeps) { | ||
const rebuilding = new Promise((resolve, reject) => { | ||
const newRequest = request.replace(/(\?|&)unpromised-entry&deps=[^&]+/, ''); | ||
const delimiter = newRequest.includes('?') ? '&' : '?'; | ||
const depRequest = `${newRequest}${delimiter}unpromised-entry&deps=${unpromiseDeps.join(',')}`; | ||
const entry = compilation.entries.get(entryName); | ||
if (!entry) | ||
const isNonEsmResult = (result, parent, parents) => { | ||
const knownParent = getKnownParent(result.request, parents); | ||
if (knownParent) { | ||
logger.debug('known parent: \n', parent.identifier(), '\n', knownParent); | ||
return knownParent.isNonEsm; | ||
} | ||
const isNonEsm = (result.dependencyType !== 'esm' && | ||
(logger.debug(`Found dependency type for ${result.request}:`, result.dependencyType), | ||
true)) || | ||
isNonEsmParent(parent, parents); | ||
return isNonEsm; | ||
}; | ||
const getParentsKey = (parents) => parents.map((p) => p.identifier()).join('!'); | ||
const getUnpromisedRequest = (request, globalName) => { | ||
const req = request.endsWith('/') ? request + 'index' : request; | ||
const newRequest = `${req}?unpromise-external&globalName=${globalName}`; | ||
return newRequest; | ||
}; | ||
const updateResult = (result, isNonEsm, entryNames, parents) => { | ||
const externalsBlocks = entryNames | ||
.map((e) => finalIsolatedExternals[e]) | ||
.filter(Boolean); | ||
const entryNamesStr = entryNames.join('", "'); | ||
const externalName = result.request; | ||
const targetExternals = externalsBlocks | ||
.map((block) => block[externalName]) | ||
.filter(Boolean); | ||
if (!targetExternals.length) | ||
return; | ||
addKnownParent(getParentsKey(parents), { | ||
isNonEsm, | ||
connections: createModuleSet(parents), | ||
entries: entryNames, | ||
}); | ||
if (!isNonEsm) | ||
return; | ||
logger.debug(`unpromising entries "${entryNamesStr}" for external "${result.request}".`); | ||
const newRequest = getUnpromisedRequest(result.request, targetExternals[0].globalName); | ||
result.request = newRequest; | ||
entryNames.forEach((entryName) => { | ||
const externalsBlock = finalIsolatedExternals[entryName]; | ||
if (!externalsBlock) | ||
return; | ||
const entryModule = compilation.moduleGraph.getModule(entry.dependencies[0]); | ||
if (entryModule.rawRequest == depRequest) | ||
return; | ||
const newEntryDep = webpack_1.EntryPlugin.createDependency(depRequest, entry.options || entryName); | ||
compilation.addEntry(context, newEntryDep, entryName, (err, addedModule) => { | ||
addedModule === null || addedModule === void 0 ? void 0 : addedModule.invalidateBuild(); | ||
if (err) { | ||
console.error(`error adding module ${request}`, err); | ||
reject(err); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
const externalsReqs = Object.entries(externalsBlock); | ||
const previousExternals = externalsReqs.slice(0, externalsReqs.findIndex(([key]) => key === externalName)); | ||
const targetExternal = externalsBlock[externalName]; | ||
unpromisedEntries[entryName] = [ | ||
...new Set([ | ||
...(unpromisedEntries[entryName] || []), | ||
...previousExternals.map(([, { globalName }]) => globalName), | ||
targetExternal.globalName, | ||
]), | ||
]; | ||
}); | ||
await rebuilding; | ||
} | ||
function getTargetEntryNameFromResult(result, existingTargetEntry) { | ||
const targetEntry = existingTargetEntry !== null && existingTargetEntry !== void 0 ? existingTargetEntry : getTargetEntryFromDeps(result.dependencies); | ||
if (!targetEntry) | ||
return ''; | ||
const entryName = (0, getRequestParam_1.default)(targetEntry.userRequest, 'isolatedExternalsEntry') || ''; | ||
return entryName; | ||
} | ||
}; | ||
const getAllParents = (module, ids = []) => { | ||
const parents = [ | ||
...compilation.moduleGraph.getIncomingConnections(module), | ||
] | ||
.map((c) => c.originModule) | ||
.filter((m) => Boolean(m)) | ||
.filter((m) => m.identifier() !== module.identifier()); | ||
const newParents = parents.filter((p) => { | ||
if (ids.includes(p.identifier())) | ||
return false; | ||
ids.push(p.identifier()); | ||
return true; | ||
}); | ||
return [ | ||
...newParents, | ||
...newParents.flatMap((p) => getAllParents(p, ids)), | ||
]; | ||
}; | ||
normalModuleFactory.hooks.beforeResolve.tap('IsolatedExternalsPlugin', (result) => { | ||
var _a, _b; | ||
try { | ||
if (result.dependencyType === 'esm') | ||
if (!allIsolatedExternals[result.request]) | ||
return; | ||
const targetEntry = getTargetEntryFromDeps(result.dependencies); | ||
if (!targetEntry) | ||
const parentModule = getParentModule(result); | ||
if (!parentModule) | ||
return; | ||
const entryName = getTargetEntryNameFromResult(result, targetEntry); | ||
const targetExternal = (_a = finalIsolatedExternals[entryName]) === null || _a === void 0 ? void 0 : _a[result.request]; | ||
if (!targetExternal) | ||
const parents = getAllParents(parentModule); | ||
logger.debug('checking', result.request, { | ||
parents: parents.map((p) => p.identifier()), | ||
}); | ||
if (!parents.length) | ||
return; | ||
const req = result.request.endsWith('/') | ||
? result.request + 'index' | ||
: result.request; | ||
result.request = `${req}?unpromise-external&globalName=${targetExternal.globalName}`; | ||
unpromisedEntries[entryName] = { | ||
context: targetEntry.context || '', | ||
request: targetEntry.rawRequest, | ||
deps: [ | ||
...new Set([ | ||
...(((_b = unpromisedEntries[entryName]) === null || _b === void 0 ? void 0 : _b.deps) || []), | ||
targetExternal.globalName, | ||
]), | ||
], | ||
}; | ||
const knownModule = getKnownParent(getParentsKey(parents), parents); | ||
if (knownModule) { | ||
logger.debug(`known module: \n`, result.request, '\n', knownModule); | ||
updateResult(result, knownModule.isNonEsm, | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
knownModule.entries, parents); | ||
return; | ||
} | ||
const entryNames = getTargetEntries(parentModule, parents); | ||
if (entryNames.every((n) => { var _a; return (_a = unpromisedEntries[n]) === null || _a === void 0 ? void 0 : _a.includes(result.request); })) { | ||
logger.debug(`unpromising request "${result.request}" for previously unpromised entries "${entryNames.join(',')}".`); | ||
const newRequest = getUnpromisedRequest(result.request, entryNames.map((n) => finalIsolatedExternals[n][result.request].globalName)[0]); | ||
result.request = newRequest; | ||
return; | ||
} | ||
if (!entryNames.some((entryName) => { var _a; return (_a = finalIsolatedExternals[entryName]) === null || _a === void 0 ? void 0 : _a[result.request]; })) { | ||
return; | ||
} | ||
const nonEsmInChain = isNonEsmResult(result, parentModule, parents); | ||
updateResult(result, nonEsmInChain, entryNames, parents); | ||
} | ||
catch (err) { | ||
console.warn('error setting up unpromise-externals', result.request); | ||
logger.warn('error setting up unpromise-externals', result.request); | ||
logger.error(err); | ||
console.error(err); | ||
@@ -254,41 +427,90 @@ throw err; | ||
}); | ||
normalModuleFactory.hooks.afterResolve.tapPromise('IsolatedExternalsPlugin', async (result) => { | ||
if (!result.request.includes('?unpromise-external')) | ||
return; | ||
const entryName = getTargetEntryNameFromResult(result); | ||
if (!entryName) | ||
return; | ||
const { context, request, deps } = unpromisedEntries[entryName] || {}; | ||
if (!context || !request || !deps) | ||
return; | ||
try { | ||
await rebuildEntryModule(entryName, request, context, deps); | ||
const updateEntries = async () => { | ||
for (const entryName of Object.keys(this.unpromisedEntries)) { | ||
const entry = compilation.entries.get(entryName); | ||
if (!entry) { | ||
logger.debug('no entry', entryName); | ||
break; | ||
} | ||
const entryDep = entry.dependencies.find((dep) => ((0, getRequestParam_1.default)(dep.request, 'isolatedExternalsEntry') || | ||
(0, getRequestParam_1.default)(dep.request, 'unpromised-entry')) === entryName); | ||
if (!entryDep) { | ||
logger.debug('no entry dependency', entryName); | ||
break; | ||
} | ||
const newEntryRequest = getEntryDepsRequest(entryName, this.unpromisedEntryModuleLocation, entryDep.request, /^\./.test(entryDep.request) | ||
? entryDep.getContext() || process.cwd() | ||
: ''); | ||
if (entryDep.request === newEntryRequest) { | ||
logger.debug('no need to rebuild entry module', { | ||
entryName, | ||
request: entryDep.request, | ||
}); | ||
break; | ||
} | ||
logger.debug('Rebuilding entry:', { | ||
entryName, | ||
newEntryRequest, | ||
}); | ||
const newEntryDep = getEntryDep(entryName, newEntryRequest); | ||
if (!newEntryDep) { | ||
break; | ||
} | ||
logger.debug('replacing entry module', { | ||
entryName, | ||
newEntryDep, | ||
}); | ||
entry.dependencies = entry.dependencies.filter((dep) => dep !== entryDep); | ||
const rebuilding = new Promise((resolve, reject) => { | ||
compilation.addEntry('', newEntryDep, entryName, (err) => { | ||
if (err) | ||
return reject(err); | ||
resolve(); | ||
}); | ||
}); | ||
await rebuilding; | ||
} | ||
catch (_a) { | ||
// sometimes we fail. that's ok. | ||
} | ||
}); | ||
}; | ||
compilation.hooks.buildModule.tap('IsolatedExternalsPlugin', () => void updateEntries()); | ||
compilation.hooks.rebuildModule.tap('IsolatedExternalsPlugin', () => void updateEntries()); | ||
const basePathRegex = /^[^&?]+/; | ||
normalModuleFactory.hooks.factorize.tapAsync('IsolatedExternalsPlugin', (data, cb) => { | ||
var _a; | ||
const callOriginalExternalsPlugin = () => originalExternalsPlugin.apply(getPassthroughCompiler(compiler, normalModuleFactory, (originalFactorize) => originalFactorize(data, cb))); | ||
if (!allIsolatedExternals[data.request]) { | ||
const externalPath = ((_a = basePathRegex.exec(data.request)) === null || _a === void 0 ? void 0 : _a[0]) || ''; | ||
const callOriginalExternalsPlugin = () => { | ||
return originalExternalsPlugin.apply(getPassthroughCompiler(compiler, normalModuleFactory, (originalFactorize) => originalFactorize(data, cb))); | ||
}; | ||
if (!allIsolatedExternals[externalPath]) { | ||
callOriginalExternalsPlugin(); | ||
return; | ||
} | ||
const targetEntry = getTargetEntryFromDeps(data.dependencies); | ||
if (!targetEntry) { | ||
if (data.request.includes('unpromise-external')) { | ||
cb(); | ||
return; | ||
} | ||
const parent = getParentModule(data); | ||
const parents = getAllParents(parent); | ||
const entryNames = getTargetEntries(parent, parents); | ||
if (!entryNames.length) { | ||
callOriginalExternalsPlugin(); | ||
return; | ||
} | ||
const entryName = (0, getRequestParam_1.default)(targetEntry.userRequest, 'isolatedExternalsEntry') || ''; | ||
const targetExternal = (_a = finalIsolatedExternals[entryName]) === null || _a === void 0 ? void 0 : _a[data.request]; | ||
if (!targetExternal) { | ||
const targetExternals = entryNames | ||
.map((entryName) => { var _a; return (_a = finalIsolatedExternals[entryName]) === null || _a === void 0 ? void 0 : _a[externalPath]; }) | ||
.filter(Boolean); | ||
if (!targetExternals.length) { | ||
callOriginalExternalsPlugin(); | ||
return cb(); | ||
return; | ||
} | ||
const targetExternal = targetExternals[0]; | ||
return cb(undefined, new webpack_1.ExternalModule(`__webpack_modules__["${externalsClasses_1.EXTERNALS_MODULE_NAME}"]["${targetExternal.globalName}"]`, 'promise', data.request)); | ||
}); | ||
}; | ||
compiler.hooks.thisCompilation.tap('IsolatedExternalsPlugin', isolateCompilationEntries); | ||
compiler.hooks.watchRun.tap('IsolatedExternalsPlugin', (newCompiler) => { | ||
newCompiler.hooks.thisCompilation.tap('IsolatedExternalsPlugin', isolateCompilationEntries); | ||
}); | ||
compiler.hooks.compilation.tap('IsolatedExternalsPlugin', (compilation) => { | ||
compilation.fileDependencies.add(this.externalsModuleLocation); | ||
compilation.fileDependencies.add(this.unpromisedEntryModuleLocation); | ||
}); | ||
@@ -295,0 +517,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getExternal = void 0; | ||
const externalsClasses_1 = require("./externalsClasses"); | ||
var externalsClasses_1 = require("./externalsClasses"); | ||
function getExternal(url) { | ||
const cache = (window.__isolatedExternalsCacheV3 = | ||
var cache = (window.__isolatedExternalsCacheV3 = | ||
window.__isolatedExternalsCacheV3 || {}); | ||
return (cache[url] || | ||
(() => { | ||
const theExternal = new externalsClasses_1.CachedExternal(url); | ||
(function () { | ||
var theExternal = new externalsClasses_1.CachedExternal(url); | ||
cache[url] = theExternal; | ||
@@ -12,0 +12,0 @@ return theExternal; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SYNCED_EXTERNALS_MODULE_NAME = exports.EXTERNALS_MODULE_NAME = exports.CachedExternal = void 0; | ||
const isReady = () => document.readyState === 'interactive' || document.readyState === 'complete'; | ||
class StaticResponse { | ||
constructor(body, responseInit) { | ||
var isReady = function () { | ||
return document.readyState === 'interactive' || document.readyState === 'complete'; | ||
}; | ||
var StaticResponse = /** @class */ (function () { | ||
function StaticResponse(body, responseInit) { | ||
this.__text = body; | ||
this.__status = (responseInit === null || responseInit === void 0 ? void 0 : responseInit.status) || 200; | ||
} | ||
text() { | ||
StaticResponse.prototype.text = function () { | ||
return Promise.resolve(this.__text || ''); | ||
} | ||
clone() { | ||
}; | ||
StaticResponse.prototype.clone = function () { | ||
return this; | ||
} | ||
get status() { | ||
return this.__status; | ||
} | ||
get ok() { | ||
return this.__status < 400; | ||
} | ||
} | ||
class InnerResponse { | ||
constructor(body, responseInit) { | ||
}; | ||
Object.defineProperty(StaticResponse.prototype, "status", { | ||
get: function () { | ||
return this.__status; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(StaticResponse.prototype, "ok", { | ||
get: function () { | ||
return this.__status < 400; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return StaticResponse; | ||
}()); | ||
var InnerResponse = /** @class */ (function () { | ||
function InnerResponse(body, responseInit) { | ||
this.__response = | ||
@@ -30,21 +93,30 @@ 'Response' in window | ||
} | ||
text() { | ||
InnerResponse.prototype.text = function () { | ||
var _a; | ||
return (_a = this.clone()) === null || _a === void 0 ? void 0 : _a.text(); | ||
} | ||
clone() { | ||
}; | ||
InnerResponse.prototype.clone = function () { | ||
return this.__response.clone(); | ||
} | ||
get status() { | ||
return this.__response.status; | ||
} | ||
get ok() { | ||
return this.__response.ok; | ||
} | ||
} | ||
}; | ||
Object.defineProperty(InnerResponse.prototype, "status", { | ||
get: function () { | ||
return this.__response.status; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(InnerResponse.prototype, "ok", { | ||
get: function () { | ||
return this.__response.ok; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
return InnerResponse; | ||
}()); | ||
function XHRLoad(url, onLoaded) { | ||
const request = new XMLHttpRequest(); | ||
const loadedFunction = function () { | ||
const { responseText, status } = this; | ||
onLoaded(new InnerResponse(responseText, { status })); | ||
var request = new XMLHttpRequest(); | ||
var loadedFunction = function () { | ||
var _a = this, responseText = _a.responseText, status = _a.status; | ||
onLoaded(new InnerResponse(responseText, { status: status })); | ||
request.removeEventListener('load', loadedFunction); | ||
@@ -56,41 +128,95 @@ }; | ||
} | ||
async function fetchLoad(url) { | ||
const response = await fetch(url, { | ||
// "follow" is technically the default, | ||
// but making epxlicit for backwards compatibility | ||
redirect: 'follow', | ||
function fetchLoad(url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, fetch(url, { | ||
// "follow" is technically the default, | ||
// but making epxlicit for backwards compatibility | ||
redirect: 'follow', | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
return response; | ||
} | ||
const XHRPromise = (url) => new Promise((resolve) => XHRLoad(url, resolve)); | ||
async function networkLoad(url) { | ||
if ('fetch' in window) { | ||
try { | ||
const loadedExternal = await fetchLoad(url); | ||
return loadedExternal; | ||
var XHRPromise = function (url) { | ||
return new Promise(function (resolve) { return XHRLoad(url, resolve); }); | ||
}; | ||
function networkLoad(url) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loadedExternal, _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!('fetch' in window)) return [3 /*break*/, 5]; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, fetchLoad(url)]; | ||
case 2: | ||
loadedExternal = _b.sent(); | ||
return [2 /*return*/, loadedExternal]; | ||
case 3: | ||
_a = _b.sent(); | ||
return [2 /*return*/, XHRPromise(url)]; | ||
case 4: return [3 /*break*/, 6]; | ||
case 5: return [2 /*return*/, XHRPromise(url)]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
var StaticCache = /** @class */ (function () { | ||
function StaticCache() { | ||
} | ||
StaticCache.prototype.match = function () { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
return [2 /*return*/, Promise.resolve((_a = this.__response) === null || _a === void 0 ? void 0 : _a.clone())]; | ||
}); | ||
}); | ||
}; | ||
StaticCache.prototype.put = function () { | ||
var _a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
_a[_i] = arguments[_i]; | ||
} | ||
catch (_a) { | ||
return XHRPromise(url); | ||
var _b = __read(_a, 2), response = _b[1]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_c) { | ||
this.__response = response; | ||
return [2 /*return*/, Promise.resolve()]; | ||
}); | ||
}); | ||
}; | ||
StaticCache.prototype.add = function () { | ||
var _a = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
_a[_i] = arguments[_i]; | ||
} | ||
} | ||
else { | ||
return XHRPromise(url); | ||
} | ||
} | ||
class StaticCache { | ||
async match() { | ||
var _a; | ||
return Promise.resolve((_a = this.__response) === null || _a === void 0 ? void 0 : _a.clone()); | ||
} | ||
async put(...[, response]) { | ||
this.__response = response; | ||
return Promise.resolve(); | ||
} | ||
async add(...[request]) { | ||
this.__response = await networkLoad(request.url || request); | ||
} | ||
} | ||
const CACHE_NAME = '__isolatedExternalsCache'; | ||
class CachedExternal { | ||
constructor(url) { | ||
var _b = __read(_a, 1), request = _b[0]; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _c; | ||
return __generator(this, function (_d) { | ||
switch (_d.label) { | ||
case 0: | ||
_c = this; | ||
return [4 /*yield*/, networkLoad(request.url || request)]; | ||
case 1: | ||
_c.__response = _d.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return StaticCache; | ||
}()); | ||
var CACHE_NAME = '__isolatedExternalsCache'; | ||
var CachedExternal = /** @class */ (function () { | ||
function CachedExternal(url) { | ||
this.url = url; | ||
@@ -103,45 +229,79 @@ this.failed = false; | ||
} | ||
async getCache() { | ||
if (this.cachePromise) | ||
return await this.cachePromise; | ||
/* | ||
* This covers any browsers without the caches API, | ||
* and works around this Firefox bug: | ||
* https://bugzilla.mozilla.org/show_bug.cgi?id=1724607 | ||
*/ | ||
try { | ||
const staticCachePromise = new Promise((res) => { | ||
setTimeout(() => res(new StaticCache()), 100); | ||
CachedExternal.prototype.getCache = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var staticCachePromise, openCachePromise, _a, staticCache; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!this.cachePromise) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.cachePromise]; | ||
case 1: return [2 /*return*/, _b.sent()]; | ||
case 2: | ||
_b.trys.push([2, 4, , 6]); | ||
staticCachePromise = new Promise(function (res) { | ||
setTimeout(function () { return res(new StaticCache()); }, 100); | ||
}); | ||
openCachePromise = window.caches.open(CACHE_NAME); | ||
this.cachePromise = Promise.race([staticCachePromise, openCachePromise]); | ||
return [4 /*yield*/, this.cachePromise]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
case 4: | ||
_a = _b.sent(); | ||
staticCache = new StaticCache(); | ||
this.cachePromise = Promise.resolve(staticCache); | ||
return [4 /*yield*/, this.cachePromise]; | ||
case 5: return [2 /*return*/, _b.sent()]; | ||
case 6: return [2 /*return*/]; | ||
} | ||
}); | ||
const openCachePromise = window.caches.open(CACHE_NAME); | ||
this.cachePromise = Promise.race([staticCachePromise, openCachePromise]); | ||
return await this.cachePromise; | ||
} | ||
catch (_a) { | ||
const staticCache = new StaticCache(); | ||
this.cachePromise = Promise.resolve(staticCache); | ||
return await this.cachePromise; | ||
} | ||
} | ||
async getContent() { | ||
if (this.failed) | ||
return ''; | ||
const cacheMatch = await (await this.getCache()).match(this.url); | ||
if (cacheMatch) { | ||
return cacheMatch.text(); | ||
} | ||
if (this.loading) | ||
await this.waitForLoad(); | ||
else | ||
await this.load(); | ||
return this.getContent(); | ||
} | ||
async setContent(content) { | ||
await (await this.getCache()).put(this.url, new Response(content)); | ||
} | ||
waitForLoad() { | ||
return new Promise((res) => { | ||
const checkLoad = () => { | ||
if (!this.loading) | ||
return res(this.response); | ||
}); | ||
}; | ||
CachedExternal.prototype.getContent = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cacheMatch; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (this.failed) | ||
return [2 /*return*/, '']; | ||
return [4 /*yield*/, this.getCache()]; | ||
case 1: return [4 /*yield*/, (_a.sent()).match(this.url)]; | ||
case 2: | ||
cacheMatch = _a.sent(); | ||
if (cacheMatch) { | ||
return [2 /*return*/, cacheMatch.text()]; | ||
} | ||
if (!this.loading) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, this.waitForLoad()]; | ||
case 3: | ||
_a.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, this.load()]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [2 /*return*/, this.getContent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CachedExternal.prototype.setContent = function (content) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getCache()]; | ||
case 1: return [4 /*yield*/, (_a.sent()).put(this.url, new Response(content))]; | ||
case 2: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CachedExternal.prototype.waitForLoad = function () { | ||
var _this = this; | ||
return new Promise(function (res) { | ||
var checkLoad = function () { | ||
if (!_this.loading) | ||
return res(_this.response); | ||
window.requestAnimationFrame(checkLoad); | ||
@@ -151,12 +311,13 @@ }; | ||
}); | ||
} | ||
waitForReady() { | ||
return new Promise((res) => { | ||
const readyListener = () => { | ||
}; | ||
CachedExternal.prototype.waitForReady = function () { | ||
var _this = this; | ||
return new Promise(function (res) { | ||
var readyListener = function () { | ||
if (isReady()) | ||
return res(); | ||
const newListener = readyListener.bind(this); | ||
const readyEvent = 'readystatechange'; | ||
document.removeEventListener(readyEvent, this.readyListener || newListener); | ||
this.readyListener = newListener; | ||
var newListener = readyListener.bind(_this); | ||
var readyEvent = 'readystatechange'; | ||
document.removeEventListener(readyEvent, _this.readyListener || newListener); | ||
_this.readyListener = newListener; | ||
document.addEventListener(readyEvent, newListener); | ||
@@ -166,50 +327,85 @@ }; | ||
}); | ||
} | ||
async loadResponse() { | ||
const cache = await this.getCache(); | ||
const cacheMatch = await cache.match(this.url); | ||
if (cacheMatch) | ||
return cacheMatch; | ||
await cache.add(this.url); | ||
const response = await cache.match(this.url); | ||
if (!response) | ||
return; | ||
if (response.redirected) { | ||
await cache.put(response.url, response.clone()); | ||
} | ||
return response; | ||
} | ||
async load() { | ||
if (this.loaded) | ||
return; | ||
this.loading = true; | ||
await this.waitForReady(); | ||
try { | ||
const response = await this.loadResponse(); | ||
this.failed = !(response === null || response === void 0 ? void 0 : response.ok) || (response === null || response === void 0 ? void 0 : response.status) >= 400; | ||
this.loaded = true; | ||
this.response = response; | ||
} | ||
catch (err) { | ||
/* | ||
* Chrome occasionally fails with a network error when attempting to cache | ||
* a url that returns a redirect Response. This retry should get around | ||
* that. | ||
*/ | ||
if (this.retries < CachedExternal.MAX_RETRIES) { | ||
this.retries += 1; | ||
return this.load(); | ||
} | ||
else { | ||
console.error(err); | ||
this.failed = true; | ||
this.error = err; // eslint-disable-line @typescript-eslint/no-unsafe-assignment | ||
} | ||
} | ||
this.loading = false; | ||
} | ||
} | ||
}; | ||
CachedExternal.prototype.loadResponse = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cache, cacheMatch, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getCache()]; | ||
case 1: | ||
cache = _a.sent(); | ||
return [4 /*yield*/, cache.match(this.url)]; | ||
case 2: | ||
cacheMatch = _a.sent(); | ||
if (cacheMatch) | ||
return [2 /*return*/, cacheMatch]; | ||
return [4 /*yield*/, cache.add(this.url)]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, cache.match(this.url)]; | ||
case 4: | ||
response = _a.sent(); | ||
if (!response) | ||
return [2 /*return*/]; | ||
if (!response.redirected) return [3 /*break*/, 6]; | ||
return [4 /*yield*/, cache.put(response.url, response.clone())]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CachedExternal.prototype.load = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (this.loaded) | ||
return [2 /*return*/]; | ||
this.loading = true; | ||
return [4 /*yield*/, this.waitForReady()]; | ||
case 1: | ||
_a.sent(); | ||
_a.label = 2; | ||
case 2: | ||
_a.trys.push([2, 4, , 5]); | ||
return [4 /*yield*/, this.loadResponse()]; | ||
case 3: | ||
response = _a.sent(); | ||
this.failed = !(response === null || response === void 0 ? void 0 : response.ok) || (response === null || response === void 0 ? void 0 : response.status) >= 400; | ||
this.loaded = true; | ||
this.response = response; | ||
return [3 /*break*/, 5]; | ||
case 4: | ||
err_1 = _a.sent(); | ||
/* | ||
* Chrome occasionally fails with a network error when attempting to cache | ||
* a url that returns a redirect Response. This retry should get around | ||
* that. | ||
*/ | ||
if (this.retries < CachedExternal.MAX_RETRIES) { | ||
this.retries += 1; | ||
return [2 /*return*/, this.load()]; | ||
} | ||
else { | ||
console.error(err_1); | ||
this.failed = true; | ||
this.error = err_1; // eslint-disable-line @typescript-eslint/no-unsafe-assignment | ||
} | ||
return [3 /*break*/, 5]; | ||
case 5: | ||
this.loading = false; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
CachedExternal.MAX_RETRIES = 1; | ||
return CachedExternal; | ||
}()); | ||
exports.CachedExternal = CachedExternal; | ||
CachedExternal.MAX_RETRIES = 1; | ||
exports.EXTERNALS_MODULE_NAME = 'externalsModule'; | ||
exports.SYNCED_EXTERNALS_MODULE_NAME = 'syncedExternals'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getRequestParam(request, param) { | ||
const entryUrl = new URL('https://www.example.com/' + request); | ||
const value = entryUrl.searchParams.get(param); | ||
var entryUrl = new URL('https://www.example.com/' + request); | ||
var value = entryUrl.searchParams.get(param); | ||
return value; | ||
} | ||
exports.default = getRequestParam; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getValue(strName, context) { | ||
const names = strName.split('.'); | ||
let value = context; | ||
var names = strName.split('.'); | ||
var value = context; | ||
while (names.length) { | ||
const lookup = names.shift(); | ||
var lookup = names.shift(); | ||
if (!lookup) | ||
@@ -9,0 +9,0 @@ break; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lastClosingCurly = /}([^}]*)$/; | ||
var lastClosingCurly = /}([^}]*)$/; | ||
// copied from webpack | ||
const importDefault = `function(mod) { | ||
return (mod && mod.__esModule) ? mod : { | ||
"default": mod | ||
}; | ||
}`; | ||
const passThroughFunc = `function (x) { return x; }`; | ||
var importDefault = "function(mod) {\n return (mod && mod.__esModule) ? mod : {\n \"default\": mod\n };\n}"; | ||
var passThroughFunc = "function (x) { return x; }"; | ||
function default_1(source) { | ||
const externals = this.getOptions(); | ||
const translatedExternals = Object.keys(externals).reduce((finalExternals, key) => { | ||
const external = externals[key]; | ||
const externalTransformer = external.urlTransformer; | ||
const urlTransformer = externalTransformer | ||
? `(__importDefault || ${importDefault})(require('${externalTransformer}')).default` | ||
var externals = this.getOptions(); | ||
var translatedExternals = Object.keys(externals).reduce(function (finalExternals, key) { | ||
var external = externals[key]; | ||
var externalTransformer = external.urlTransformer; | ||
var urlTransformer = externalTransformer | ||
? "(__importDefault || ".concat(importDefault, ")(require('").concat(externalTransformer, "')).default") | ||
: passThroughFunc; | ||
const transformedExternal = Object.keys(external).reduce((modifiedExternal, key) => key === 'urlTransformer' | ||
? modifiedExternal | ||
: Object.assign(Object.assign({}, modifiedExternal), { [key]: external[key] }), { url: '' }); | ||
const stringExternal = JSON.stringify(transformedExternal, null, 2); | ||
const urlTransformerExternal = stringExternal.replace(lastClosingCurly, `, "urlTransformer": ${urlTransformer}}`); | ||
return finalExternals.replace(lastClosingCurly, `"${key}": ${urlTransformerExternal},}`); | ||
var transformedExternal = Object.keys(external).reduce(function (modifiedExternal, key) { | ||
var _a; | ||
return key === 'urlTransformer' | ||
? modifiedExternal | ||
: __assign(__assign({}, modifiedExternal), (_a = {}, _a[key] = external[key], _a)); | ||
}, { url: '' }); | ||
var stringExternal = JSON.stringify(transformedExternal, null, 2); | ||
var urlTransformerExternal = stringExternal.replace(lastClosingCurly, ", \"urlTransformer\": ".concat(urlTransformer, "}")); | ||
return finalExternals.replace(lastClosingCurly, "\"".concat(key, "\": ").concat(urlTransformerExternal, ",}")); | ||
}, '{}'); | ||
const newSource = source.replace(/ISOLATED_EXTERNALS_OBJECT/, translatedExternals); | ||
var newSource = source.replace(/ISOLATED_EXTERNALS_OBJECT/, translatedExternals); | ||
return newSource; | ||
} | ||
exports.default = default_1; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -7,33 +68,51 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.externals = void 0; | ||
const externalsClasses_1 = require("./externalsClasses"); | ||
const processExternals_1 = require("./processExternals"); | ||
const getValue_1 = __importDefault(require("./getValue")); | ||
const getGlobal_1 = __importDefault(require("./getGlobal")); | ||
const externalsCache_1 = require("./externalsCache"); | ||
async function loadExternal(context, url, previousDeps) { | ||
await Promise.all(previousDeps || []); | ||
const cachedExternal = (0, externalsCache_1.getExternal)(url); | ||
const processingPromise = (0, processExternals_1.processExternal)(context, cachedExternal); | ||
return processingPromise; | ||
var externalsClasses_1 = require("./externalsClasses"); | ||
var processExternals_1 = require("./processExternals"); | ||
var getValue_1 = __importDefault(require("./getValue")); | ||
var getGlobal_1 = __importDefault(require("./getGlobal")); | ||
var externalsCache_1 = require("./externalsCache"); | ||
function loadExternal(context, url, previousDeps) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var cachedExternal, processingPromise; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(previousDeps || [])]; | ||
case 1: | ||
_a.sent(); | ||
cachedExternal = (0, externalsCache_1.getExternal)(url); | ||
processingPromise = (0, processExternals_1.processExternal)(context, cachedExternal); | ||
return [2 /*return*/, processingPromise]; | ||
} | ||
}); | ||
}); | ||
} | ||
function createExternalsObject(externalsInfo) { | ||
let orderedDeps = []; | ||
const externalsContext = {}; | ||
const externalsObject = Object.values(externalsInfo).reduce((extObj, { url, globalName, urlTransformer }) => { | ||
var _this = this; | ||
var orderedDeps = []; | ||
var externalsContext = {}; | ||
var externalsObject = Object.values(externalsInfo).reduce(function (extObj, _a) { | ||
var url = _a.url, globalName = _a.globalName, urlTransformer = _a.urlTransformer; | ||
if (!globalName) | ||
return extObj; | ||
const targetGlobal = (0, getGlobal_1.default)(); | ||
const externalLoad = loadExternal(externalsContext, urlTransformer(url), orderedDeps); | ||
orderedDeps = [...orderedDeps, externalLoad]; | ||
var targetGlobal = (0, getGlobal_1.default)(); | ||
var externalLoad = loadExternal(externalsContext, urlTransformer(url), orderedDeps); | ||
orderedDeps = __spreadArray(__spreadArray([], __read(orderedDeps), false), [externalLoad], false); | ||
Object.defineProperty(extObj, globalName, { | ||
get: async () => { | ||
const foundContext = await externalLoad; | ||
return ((0, getValue_1.default)(globalName, foundContext) || | ||
(0, getValue_1.default)(globalName, targetGlobal)); | ||
}, | ||
get: function () { return __awaiter(_this, void 0, void 0, function () { | ||
var foundContext; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, externalLoad]; | ||
case 1: | ||
foundContext = _a.sent(); | ||
return [2 /*return*/, ((0, getValue_1.default)(globalName, foundContext) || | ||
(0, getValue_1.default)(globalName, targetGlobal))]; | ||
} | ||
}); | ||
}); }, | ||
}); | ||
return extObj; | ||
}, {}); | ||
const externalsGlobalProxy = new Proxy(externalsObject, { | ||
get: (target, prop) => { | ||
var externalsGlobalProxy = new Proxy(externalsObject, { | ||
get: function (target, prop) { | ||
return Reflect.get(target, prop) || Reflect.get((0, getGlobal_1.default)(), prop); | ||
@@ -40,0 +119,0 @@ }, |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,24 +44,33 @@ exports.processExternal = void 0; | ||
// as our context object. | ||
return Function(` | ||
var self=this; | ||
var globalThis = this; | ||
${content}`).call(context); | ||
return Function("\nvar self=this;\nvar globalThis = this;\n".concat(content)).call(context); | ||
} | ||
/* eslint-enable @typescript-eslint/no-implied-eval */ | ||
async function processExternal(context, cachedExternal) { | ||
/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment */ | ||
const { failed, url, error } = cachedExternal; | ||
if (failed) { | ||
console.error(`EXTERNAL LOAD FAILED: failed to load external from '${url}'`, error); | ||
return context; | ||
} | ||
try { | ||
const content = await cachedExternal.getContent(); | ||
applyExternal(content || '', context); | ||
} | ||
catch (e) { | ||
console.error(`EXTERNAL PROCESS FAILED: failed to process external from ${url}`, e); | ||
} | ||
return context; | ||
function processExternal(context, cachedExternal) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var failed, url, error, content, e_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
failed = cachedExternal.failed, url = cachedExternal.url, error = cachedExternal.error; | ||
if (failed) { | ||
console.error("EXTERNAL LOAD FAILED: failed to load external from '".concat(url, "'"), error); | ||
return [2 /*return*/, context]; | ||
} | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, cachedExternal.getContent()]; | ||
case 2: | ||
content = _a.sent(); | ||
applyExternal(content || '', context); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
e_1 = _a.sent(); | ||
console.error("EXTERNAL PROCESS FAILED: failed to process external from ".concat(url), e_1); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/, context]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.processExternal = processExternal; |
"use strict"; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createGetProxy = void 0; | ||
const createGetProxy = (orig, get) => { | ||
var createGetProxy = function (orig, get) { | ||
return new Proxy({}, { | ||
get: (target, key, ...args) => get(target, key) || | ||
Reflect.get(orig, key, ...args), | ||
get: function (target, key) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
return get(target, key) || | ||
Reflect.get.apply(Reflect, __spreadArray([orig, key], __read(args), false)); | ||
}, | ||
}); | ||
}; | ||
exports.createGetProxy = createGetProxy; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,13 +29,18 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const externalsClasses_1 = require("./externalsClasses"); | ||
const getRequestParam_1 = __importDefault(require("./getRequestParam")); | ||
var fs = __importStar(require("fs")); | ||
var path = __importStar(require("path")); | ||
var externalsClasses_1 = require("./externalsClasses"); | ||
var getRequestParam_1 = __importDefault(require("./getRequestParam")); | ||
var syncedExternalText = fs.readFileSync(require.resolve(path.join(__dirname, 'unpromisedExternal.js')), 'utf8'); | ||
function unpromiseLoader(source) { | ||
try { | ||
const globalName = (0, getRequestParam_1.default)(this.resourceQuery, 'globalName'); | ||
var globalName = (0, getRequestParam_1.default)(this.resourceQuery, 'globalName'); | ||
if (!globalName) | ||
return source; | ||
return `exports = __webpack_modules__["${externalsClasses_1.SYNCED_EXTERNALS_MODULE_NAME}"]["${globalName}"];`; | ||
return syncedExternalText | ||
.replace(/SYNCED_EXTERNALS_MODULE_NAME/g, "\"".concat(externalsClasses_1.SYNCED_EXTERNALS_MODULE_NAME, "\"")) | ||
.replace(/THE_GLOBAL/g, "\"".concat(globalName, "\"")); | ||
} | ||
catch (e) { | ||
console.error(`failure to load module for ${this.request}`, e); | ||
console.error("failure to load module for ".concat(this.request), e); | ||
throw e; | ||
@@ -19,0 +47,0 @@ } |
@@ -29,23 +29,37 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const fs = __importStar(require("fs")); | ||
const path = __importStar(require("path")); | ||
const getRequestParam_1 = __importDefault(require("./getRequestParam")); | ||
const externalsClasses_1 = require("./externalsClasses"); | ||
const syncedEntryText = fs.readFileSync(require.resolve(path.join(__dirname, 'unpromisedEntry.js')), 'utf8'); | ||
var fs = __importStar(require("fs")); | ||
var path = __importStar(require("path")); | ||
var getRequestParam_1 = __importDefault(require("./getRequestParam")); | ||
var externalsClasses_1 = require("./externalsClasses"); | ||
var syncedEntryText = fs.readFileSync(require.resolve(path.join(__dirname, 'unpromisedEntry.js')), 'utf8'); | ||
function unpromiseLoader(source) { | ||
try { | ||
const deps = (0, getRequestParam_1.default)(this.resourceQuery, 'deps'); | ||
const normal = (0, getRequestParam_1.default)(this.resourceQuery, 'normal') == true.toString(); | ||
console.warn('unpromise-loader', this.resource); | ||
var deps = (0, getRequestParam_1.default)(this.resourceQuery, 'deps'); | ||
var originalRequest = decodeURIComponent((0, getRequestParam_1.default)(this.resourceQuery, 'originalRequest') || ''); | ||
var originalContext = decodeURIComponent((0, getRequestParam_1.default)(this.resourceQuery, 'originalContext') || ''); | ||
var normal = (0, getRequestParam_1.default)(this.resourceQuery, 'normal') == true.toString(); | ||
var logger = this.getLogger('unpromised-entry-loader'); | ||
logger.debug('unpromised-entry-loader', { | ||
deps: deps, | ||
originalRequest: originalRequest, | ||
normal: normal, | ||
resource: this.resource, | ||
}); | ||
if (!deps || normal) | ||
return source; | ||
const delimiter = this.resource.includes('?') ? '&' : '?'; | ||
return syncedEntryText | ||
var resolvedRequest = originalRequest && originalContext | ||
? path.resolve(path.normalize(originalContext), path.normalize(originalRequest)) | ||
: originalRequest; | ||
var safeRequest = resolvedRequest.replace(/\\/g, '\\\\'); | ||
var delimiter = resolvedRequest.includes('?') ? '&' : '?'; | ||
var result = syncedEntryText | ||
.replace(/DEPS_PLACEHOLDER/g, deps) | ||
.replace(/RELOAD_PLACEHOLDER/g, `${this.resource}${delimiter}normal=true`) | ||
.replace(/SYNCED_EXTERNALS_MODULE_NAME/g, `"${externalsClasses_1.SYNCED_EXTERNALS_MODULE_NAME}"`) | ||
.replace(/EXTERNALS_MODULE_NAME/g, `"${externalsClasses_1.EXTERNALS_MODULE_NAME}"`); | ||
.replace(/RELOAD_PLACEHOLDER/g, "".concat(safeRequest).concat(delimiter, "normal=true")) | ||
.replace(/SYNCED_EXTERNALS_MODULE_NAME/g, "\"".concat(externalsClasses_1.SYNCED_EXTERNALS_MODULE_NAME, "\"")) | ||
.replace(/EXTERNALS_MODULE_NAME/g, "\"".concat(externalsClasses_1.EXTERNALS_MODULE_NAME, "\"")); | ||
return result; | ||
this.callback(undefined, result); | ||
} | ||
catch (e) { | ||
console.error(`failure to load module for ${this.request}`, e); | ||
console.error("failure to load module for ".concat(this.request), e); | ||
throw e; | ||
@@ -52,0 +66,0 @@ } |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const unpromisedDeps = 'DEPS_PLACEHOLDER'.split(','); | ||
const reload = 'RELOAD_PLACEHOLDER'; | ||
async function waitForDep(dep) { | ||
const result = await __webpack_modules__[EXTERNALS_MODULE_NAME][dep]; | ||
(__webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME] || | ||
(() => { | ||
__webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME] = {}; | ||
return __webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME]; | ||
}))[dep] = result; | ||
var unpromisedDeps = 'DEPS_PLACEHOLDER'.split(','); | ||
function waitForDep(dep) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, new Promise(function (resolve) { | ||
var resolveDep = function () { | ||
var _a; | ||
var resolver = (_a = __webpack_modules__[EXTERNALS_MODULE_NAME]) === null || _a === void 0 ? void 0 : _a[dep]; | ||
if (resolver) { | ||
void resolver.then(resolve); | ||
} | ||
else { | ||
requestAnimationFrame(resolveDep); | ||
} | ||
}; | ||
resolveDep(); | ||
})]; | ||
case 1: | ||
result = _a.sent(); | ||
(__webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME] || | ||
(function () { | ||
__webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME] = {}; | ||
return __webpack_modules__[SYNCED_EXTERNALS_MODULE_NAME]; | ||
})())[dep] = result; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
async function awaitDeps() { | ||
await Promise.all(unpromisedDeps.map(waitForDep)); | ||
require(reload); | ||
function awaitDeps() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, Promise.all(unpromisedDeps.map(waitForDep))]; | ||
case 1: | ||
_a.sent(); | ||
require('RELOAD_PLACEHOLDER'); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
void awaitDeps(); |
{ | ||
"name": "isolated-externals-plugin", | ||
"version": "2.4.0-preload-non-esm-fef1d9c.1", | ||
"version": "2.4.0", | ||
"description": "", | ||
@@ -72,3 +72,3 @@ "main": "dist/index.js", | ||
"eslint-plugin-react": "^7.22.0", | ||
"html-webpack-plugin": "^5.5.0", | ||
"html-webpack-plugin": "^5.5.3", | ||
"husky": "^6.0.0", | ||
@@ -75,0 +75,0 @@ "jest": "^29.3.1", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
82103
32
1583
0
4