isolated-externals-plugin
Advanced tools
Comparing version 2.3.1 to 2.4.0-preload-non-esm-2bc7b8b.1
import { Compiler } from 'webpack'; | ||
import { ExternalInfo } from './util/externalsClasses'; | ||
export type Maybe<T> = T | undefined | null; | ||
export interface IsolatedExternalsElement { | ||
@@ -4,0 +5,0 @@ [key: string]: ExternalInfo; |
@@ -149,3 +149,3 @@ "use strict"; | ||
: [normalizedExistingExternals]; | ||
compiler.options.module.rules = __spreadArray(__spreadArray([], __read(compiler.options.module.rules), false), __read(Object.entries(finalIsolatedExternals) | ||
compiler.options.module.rules = __spreadArray(__spreadArray(__spreadArray([], __read(compiler.options.module.rules), false), __read(Object.entries(finalIsolatedExternals) | ||
// We want the longest names last so the most specific ones are matched first | ||
@@ -171,3 +171,12 @@ // module rules are processed in reverse order | ||
}); | ||
})), false); | ||
})), false), [ | ||
{ | ||
resourceQuery: /unpromise-external/, | ||
use: [ | ||
{ | ||
loader: path_1.default.resolve(path_1.default.join(_this.moduleDir, 'unpromise-loader.js')), | ||
}, | ||
], | ||
}, | ||
], false); | ||
}); | ||
@@ -199,4 +208,53 @@ compiler.hooks.entryOption.tap('IsolatedExternalsPlugin', | ||
var normalModuleFactory = compilationParams.normalModuleFactory; | ||
var getRequestParam = function (request, param) { | ||
var entryUrl = new URL('https://www.example.com/' + request); | ||
var value = entryUrl.searchParams.get(param); | ||
return value; | ||
}; | ||
var getTargetEntry = function (dep) { | ||
var _a; | ||
if (!dep) { | ||
return; | ||
} | ||
var _b = dep.rawRequest, rawRequest = _b === void 0 ? '' : _b; | ||
if (rawRequest) { | ||
var entryName = getRequestParam(rawRequest, 'isolatedExternalsEntry'); | ||
if (entryName) { | ||
return entryName; | ||
} | ||
} | ||
var connections = Array.from(compilation.moduleGraph.getIncomingConnections(dep)); | ||
return getTargetEntry((_a = connections.find(function (conn) { | ||
return conn.originModule !== dep && | ||
getTargetEntry(conn.originModule); | ||
})) === null || _a === void 0 ? void 0 : _a.originModule); | ||
}; | ||
var getTargetEntryFromDeps = function (deps) { | ||
var targetEntry = deps === null || deps === void 0 ? void 0 : deps.map(function (dep) { | ||
return getTargetEntry(compilation.moduleGraph.getParentModule(dep)); | ||
}).find(Boolean); | ||
return targetEntry; | ||
}; | ||
normalModuleFactory.hooks.beforeResolve.tapAsync('IsolatedExternalsPlugin', function (result, cb) { | ||
var _a; | ||
try { | ||
var targetEntry = getTargetEntryFromDeps(result.dependencies); | ||
if (!targetEntry) | ||
return cb(); | ||
if (result.dependencyType === 'esm') | ||
return cb(); | ||
var targetExternal = (_a = finalIsolatedExternals[targetEntry]) === null || _a === void 0 ? void 0 : _a[result.request]; | ||
if (!targetExternal) | ||
return cb(); | ||
result.request = "".concat(result.request, "?unpromise-external&globalName=").concat(targetExternal.globalName); | ||
cb(); | ||
} | ||
catch (err) { | ||
console.warn('error setting up unpromise-externals', result.request); | ||
console.error(err); | ||
throw err; | ||
} | ||
}); | ||
normalModuleFactory.hooks.factorize.tapAsync('IsolatedExternalsPlugin', function (data, cb) { | ||
var _a, _b; | ||
var _a; | ||
var callOriginalExternalsPlugin = function () { | ||
@@ -209,25 +267,3 @@ return originalExternalsPlugin.apply(getPassthroughCompiler(compiler, normalModuleFactory, function (originalFactorize) { return originalFactorize(data, cb); })); | ||
} | ||
var getEntryName = function (request) { | ||
var entryUrl = new URL('https://www.example.com/' + request); | ||
var entry = entryUrl.searchParams.get('isolatedExternalsEntry'); | ||
return entry; | ||
}; | ||
var getTargetEntry = function (dep) { | ||
var _a; | ||
if (!dep) { | ||
return; | ||
} | ||
var _b = dep.rawRequest, rawRequest = _b === void 0 ? '' : _b; | ||
var entryName = getEntryName(rawRequest); | ||
if (entryName) { | ||
return entryName; | ||
} | ||
var connections = Array.from(compilation.moduleGraph.getIncomingConnections(dep)); | ||
return getTargetEntry((_a = connections.find(function (conn) { | ||
return getTargetEntry(conn.originModule); | ||
})) === null || _a === void 0 ? void 0 : _a.originModule); | ||
}; | ||
var targetEntry = (_a = data.dependencies) === null || _a === void 0 ? void 0 : _a.map(function (dep) { | ||
return getTargetEntry(compilation.moduleGraph.getParentModule(dep)); | ||
}).find(Boolean); | ||
var targetEntry = getTargetEntryFromDeps(data.dependencies); | ||
if (!targetEntry) { | ||
@@ -237,3 +273,3 @@ callOriginalExternalsPlugin(); | ||
} | ||
var targetExternal = (_b = finalIsolatedExternals[targetEntry]) === null || _b === void 0 ? void 0 : _b[data.request]; | ||
var targetExternal = (_a = finalIsolatedExternals[targetEntry]) === null || _a === void 0 ? void 0 : _a[data.request]; | ||
if (!targetExternal) { | ||
@@ -240,0 +276,0 @@ callOriginalExternalsPlugin(); |
{ | ||
"name": "isolated-externals-plugin", | ||
"version": "2.3.1", | ||
"version": "2.4.0-preload-non-esm-2bc7b8b.1", | ||
"description": "", | ||
@@ -62,3 +62,4 @@ "main": "dist/index.js", | ||
"@types/randomstring": "^1.1.8", | ||
"@types/webpack": "^5.28.0", | ||
"@types/react-modal": "^3.16.0", | ||
"@types/webpack": "^5.28.1", | ||
"@typescript-eslint/eslint-plugin": "^4.14.2", | ||
@@ -79,5 +80,6 @@ "@typescript-eslint/parser": "^4.14.2", | ||
"react-dom": "^17.0.1", | ||
"semantic-release": "^19.0.5", | ||
"react-modal": "^3.16.1", | ||
"semantic-release": "^21.0.3", | ||
"typescript": "^4.9.3", | ||
"webpack": "^5.75.0", | ||
"webpack": "^5.86.0", | ||
"webpack-cli": "^5.0.0", | ||
@@ -84,0 +86,0 @@ "webpack-dev-server": "^4.11.1" |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
63466
26
1230
34
1
2