@parcel/runtime-js
Advanced tools
Comparing version 2.0.0-canary.1772 to 2.0.0-canary.1775
@@ -90,2 +90,4 @@ "use strict"; | ||
} | ||
let useRuntimeManifest = shouldUseRuntimeManifest(bundle, options); | ||
let useImportMaps = useRuntimeManifest && shouldUseImportMaps(bundleGraph, bundle); | ||
let { | ||
@@ -135,3 +137,5 @@ asyncDependencies, | ||
bundleGroup: resolved.value, | ||
options | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps | ||
}); | ||
@@ -193,7 +197,7 @@ if (loaderRuntime != null) { | ||
if (dependency.specifierType === 'url' || (mainAsset === null || mainAsset === void 0 ? void 0 : mainAsset.meta.jsRuntime) === 'url') { | ||
assets.push(getURLRuntime(dependency, bundle, mainBundle, options)); | ||
assets.push(getURLRuntime(dependency, bundle, mainBundle, options, useRuntimeManifest, useImportMaps)); | ||
continue; | ||
} | ||
if (mainBundle.type === 'node' && mainBundle.env.isNode()) { | ||
let relativePathExpr = getAbsoluteUrlExpr(getRelativePathExpr(bundle, mainBundle, options), mainBundle); | ||
let relativePathExpr = getAbsoluteUrlExpr(bundle, mainBundle, options, useRuntimeManifest, useImportMaps); | ||
assets.push({ | ||
@@ -224,4 +228,3 @@ filePath: __filename, | ||
} | ||
let relativePathExpr = getRelativePathExpr(bundle, referencedBundle, options); | ||
let loaderCode = `require(${JSON.stringify(loader)})( ${getAbsoluteUrlExpr(relativePathExpr, bundle)})`; | ||
let loaderCode = `require(${JSON.stringify(loader)})( ${getAbsoluteUrlExpr(bundle, referencedBundle, options, useRuntimeManifest, useImportMaps)})`; | ||
assets.push({ | ||
@@ -237,3 +240,3 @@ filePath: __filename, | ||
} | ||
if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) { | ||
if (useRuntimeManifest && !useImportMaps && bundle.env.context !== 'react-server' && bundle.env.context !== 'react-client' && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) { | ||
assets.push({ | ||
@@ -284,3 +287,5 @@ filePath: __filename, | ||
bundleGraph, | ||
options | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps | ||
}) { | ||
@@ -317,3 +322,2 @@ let loaders = getLoaders(bundle.env); | ||
let needsDynamicImportPolyfill = !bundle.env.isLibrary && !bundle.env.supports('dynamic-import', true); | ||
let needsEsmLoadPrelude = false; | ||
let loaderModules = []; | ||
@@ -325,11 +329,14 @@ for (let to of externalBundles) { | ||
} | ||
if (to.type === 'js' && to.env.outputFormat === 'esmodule' && !needsDynamicImportPolyfill && shouldUseRuntimeManifest(bundle, options)) { | ||
loaderModules.push(`load(${JSON.stringify(to.publicId)})`); | ||
needsEsmLoadPrelude = true; | ||
if (to.type === 'js' && to.env.outputFormat === 'esmodule' && !needsDynamicImportPolyfill && useRuntimeManifest) { | ||
if (useImportMaps) { | ||
loaderModules.push(`__parcel__import__(${JSON.stringify(to.publicId)})`); | ||
} else { | ||
loaderModules.push(`parcelRequire.load(${JSON.stringify(to.publicId)})`); | ||
} | ||
continue; | ||
} | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
// Use esmodule loader if possible | ||
if (to.type === 'js' && to.env.outputFormat === 'esmodule') { | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
if (!needsDynamicImportPolyfill) { | ||
@@ -341,6 +348,7 @@ loaderModules.push(`__parcel__import__("./" + ${relativePathExpr})`); | ||
} else if (to.type === 'js' && to.env.outputFormat === 'commonjs') { | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
loaderModules.push(`Promise.resolve(__parcel__require__("./" + ${relativePathExpr}))`); | ||
continue; | ||
} | ||
let absoluteUrlExpr = shouldUseRuntimeManifest(bundle, options) ? `require('./helpers/bundle-manifest').resolve(${JSON.stringify(to.publicId)})` : getAbsoluteUrlExpr(relativePathExpr, bundle); | ||
let absoluteUrlExpr = getAbsoluteUrlExpr(bundle, to, options, useRuntimeManifest, useImportMaps); | ||
let code = `require(${JSON.stringify(loader)})(${absoluteUrlExpr})`; | ||
@@ -381,28 +389,5 @@ | ||
} | ||
if (needsEsmLoadPrelude && options.featureFlags.importRetry) { | ||
loaderCode = ` | ||
Object.defineProperty(module, 'exports', { get: () => { | ||
let load = require('./helpers/browser/esm-js-loader-retry'); | ||
return ${loaderCode}.then((v) => { | ||
Object.defineProperty(module, "exports", { value: Promise.resolve(v) }) | ||
return v | ||
}); | ||
}})`; | ||
return { | ||
filePath: __filename, | ||
code: loaderCode, | ||
dependency, | ||
env: { | ||
sourceType: 'module' | ||
} | ||
}; | ||
} | ||
let code = []; | ||
if (needsEsmLoadPrelude) { | ||
code.push(`let load = require('./helpers/browser/esm-js-loader');`); | ||
} | ||
code.push(`module.exports = ${loaderCode};`); | ||
return { | ||
filePath: __filename, | ||
code: code.join('\n'), | ||
code: `module.exports = ${loaderCode};`, | ||
dependency, | ||
@@ -448,5 +433,4 @@ env: { | ||
for (let bundleToPreload of bundlesToPreload) { | ||
let relativePathExpr = getRelativePathExpr(from, bundleToPreload, options); | ||
let priority = TYPE_TO_RESOURCE_PRIORITY[bundleToPreload.type]; | ||
hintLoaders.push(`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`); | ||
hintLoaders.push(`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(from, bundleToPreload, options, false, false)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`); | ||
} | ||
@@ -461,19 +445,13 @@ } | ||
} | ||
function getURLRuntime(dependency, from, to, options) { | ||
let relativePathExpr = getRelativePathExpr(from, to, options, true); | ||
function getURLRuntime(dependency, from, to, options, useRuntimeManifest, useImportMaps) { | ||
let absoluteUrlExpr = getAbsoluteUrlExpr(from, to, options, useRuntimeManifest, useImportMaps); | ||
let code; | ||
if (dependency.meta.webworker === true && !from.env.isLibrary) { | ||
code = `let workerURL = require('./helpers/get-worker-url');\n`; | ||
if (from.env.outputFormat === 'esmodule' && from.env.supports('import-meta-url')) { | ||
code += `let url = new __parcel__URL__(${relativePathExpr});\n`; | ||
code += `module.exports = workerURL(url.toString(), url.origin, ${String(from.env.outputFormat === 'esmodule')});`; | ||
} else { | ||
code += `let bundleURL = require('./helpers/bundle-url');\n`; | ||
code += `let url = bundleURL.getBundleURL('${from.publicId}') + ${relativePathExpr};`; | ||
code += `module.exports = workerURL(url, bundleURL.getOrigin(url), ${String(from.env.outputFormat === 'esmodule')});`; | ||
} | ||
code += `let url = new URL(${absoluteUrlExpr});\n`; | ||
code += `module.exports = workerURL(url.toString(), url.origin, ${String(from.env.outputFormat === 'esmodule')});`; | ||
} else if (from.env.isServer() && to.env.isBrowser()) { | ||
code = `module.exports = ${JSON.stringify((0, _utils().urlJoin)(to.target.publicUrl, to.name))};`; | ||
} else { | ||
code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from)};`; | ||
code = `module.exports = ${absoluteUrlExpr};`; | ||
} | ||
@@ -490,27 +468,4 @@ return { | ||
function getRegisterCode(entryBundle, bundleGraph) { | ||
let mappings = []; | ||
bundleGraph.traverseBundles((bundle, _, actions) => { | ||
if (bundle.bundleBehavior === 'inline') { | ||
return; | ||
} | ||
// To make the manifest as small as possible all bundle key/values are | ||
// serialised into a single array e.g. ['id', 'value', 'id2', 'value2']. | ||
// `./helpers/bundle-manifest` accounts for this by iterating index by 2 | ||
mappings.push(bundle.publicId, (0, _utils().relativeBundlePath)(entryBundle, (0, _nullthrows().default)(bundle), { | ||
leadingDotSlash: false | ||
})); | ||
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) { | ||
for (let referenced of bundleGraph.getReferencedBundles(bundle)) { | ||
mappings.push(referenced.publicId, (0, _utils().relativeBundlePath)(entryBundle, (0, _nullthrows().default)(referenced), { | ||
leadingDotSlash: false | ||
})); | ||
} | ||
// New contexts have their own manifests, so there's no need to continue. | ||
actions.skipChildren(); | ||
} | ||
}, entryBundle); | ||
let baseUrl = entryBundle.env.outputFormat === 'esmodule' && entryBundle.env.supports('import-meta-url') ? 'new __parcel__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it gets replaced currently | ||
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`; | ||
return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`; | ||
let mappings = (0, _utils().getImportMap)(bundleGraph, entryBundle); | ||
return `parcelRequire.extendImportMap(${JSON.stringify(mappings)});`; | ||
} | ||
@@ -527,8 +482,20 @@ function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') { | ||
} | ||
function getAbsoluteUrlExpr(relativePathExpr, bundle) { | ||
if (bundle.env.outputFormat === 'esmodule' && bundle.env.supports('import-meta-url') || bundle.env.outputFormat === 'commonjs' || bundle.env.isNode()) { | ||
function getAbsoluteUrlExpr(bundle, to, options, useRuntimeManifest, useImportMaps) { | ||
// let relativePathExpr; | ||
if (useRuntimeManifest) { | ||
if (useImportMaps) { | ||
return `__parcel__import__.meta.resolve(${JSON.stringify(to.publicId)})`; | ||
} else { | ||
return `parcelRequire.resolve(${JSON.stringify(to.publicId)})`; | ||
} | ||
} else if (bundle.env.isLibrary) { | ||
// This will be compiled to new URL(url, import.meta.url) or new URL(url, 'file:' + __filename). | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
return `new __parcel__URL__(${relativePathExpr}).toString()`; | ||
} else { | ||
return `require('./helpers/bundle-url').getBundleURL('${bundle.publicId}') + ${relativePathExpr}`; | ||
let res = `parcelRequire.resolve(${JSON.stringify(to.name)})`; | ||
if (to.type !== 'js' && options.hmrOptions) { | ||
res += ' + "?" + Date.now()'; | ||
} | ||
return res; | ||
} | ||
@@ -539,2 +506,5 @@ } | ||
return !env.isLibrary && bundle.bundleBehavior !== 'inline' && env.isBrowser() && options.mode === 'production'; | ||
} | ||
function shouldUseImportMaps(bundleGraph, bundle) { | ||
return bundle.env.outputFormat === 'esmodule' && bundle.env.supports('import-meta-resolve') && !bundle.env.isIsolated() && bundleGraph.getEntryBundles().every(entry => entry.type === 'html'); | ||
} |
{ | ||
"name": "@parcel/runtime-js", | ||
"version": "2.0.0-canary.1772+f86f5f27c", | ||
"version": "2.0.0-canary.1775+735a635f7", | ||
"license": "MIT", | ||
@@ -20,11 +20,11 @@ "publishConfig": { | ||
"node": ">= 16.0.0", | ||
"parcel": "^2.0.0-canary.1770+f86f5f27c" | ||
"parcel": "^2.0.0-canary.1773+735a635f7" | ||
}, | ||
"dependencies": { | ||
"@parcel/diagnostic": "2.0.0-canary.1772+f86f5f27c", | ||
"@parcel/plugin": "2.0.0-canary.1772+f86f5f27c", | ||
"@parcel/utils": "2.0.0-canary.1772+f86f5f27c", | ||
"@parcel/diagnostic": "2.0.0-canary.1775+735a635f7", | ||
"@parcel/plugin": "2.0.0-canary.1775+735a635f7", | ||
"@parcel/utils": "2.0.0-canary.1775+735a635f7", | ||
"nullthrows": "^1.1.1" | ||
}, | ||
"gitHead": "f86f5f27c3a6553e70bd35652f19e6ab8d8e4e4a" | ||
"gitHead": "735a635f7eed538c449f37517b26247e0b19c1a4" | ||
} |
@@ -14,3 +14,3 @@ // @flow strict-local | ||
import {Runtime} from '@parcel/plugin'; | ||
import {relativeBundlePath, urlJoin} from '@parcel/utils'; | ||
import {relativeBundlePath, urlJoin, getImportMap} from '@parcel/utils'; | ||
import path from 'path'; | ||
@@ -82,2 +82,6 @@ import nullthrows from 'nullthrows'; | ||
let useRuntimeManifest = shouldUseRuntimeManifest(bundle, options); | ||
let useImportMaps = | ||
useRuntimeManifest && shouldUseImportMaps(bundleGraph, bundle); | ||
let {asyncDependencies, otherDependencies} = getDependencies(bundle); | ||
@@ -134,2 +138,4 @@ | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
}); | ||
@@ -201,3 +207,12 @@ | ||
) { | ||
assets.push(getURLRuntime(dependency, bundle, mainBundle, options)); | ||
assets.push( | ||
getURLRuntime( | ||
dependency, | ||
bundle, | ||
mainBundle, | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
), | ||
); | ||
continue; | ||
@@ -208,4 +223,7 @@ } | ||
let relativePathExpr = getAbsoluteUrlExpr( | ||
getRelativePathExpr(bundle, mainBundle, options), | ||
bundle, | ||
mainBundle, | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
); | ||
@@ -237,10 +255,11 @@ assets.push({ | ||
let relativePathExpr = getRelativePathExpr( | ||
let loaderCode = `require(${JSON.stringify( | ||
loader, | ||
)})( ${getAbsoluteUrlExpr( | ||
bundle, | ||
referencedBundle, | ||
options, | ||
); | ||
let loaderCode = `require(${JSON.stringify( | ||
loader, | ||
)})( ${getAbsoluteUrlExpr(relativePathExpr, bundle)})`; | ||
useRuntimeManifest, | ||
useImportMaps, | ||
)})`; | ||
assets.push({ | ||
@@ -256,3 +275,6 @@ filePath: __filename, | ||
if ( | ||
shouldUseRuntimeManifest(bundle, options) && | ||
useRuntimeManifest && | ||
!useImportMaps && | ||
bundle.env.context !== 'react-server' && | ||
bundle.env.context !== 'react-client' && | ||
bundleGraph | ||
@@ -312,2 +334,4 @@ .getChildBundles(bundle) | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
}: {| | ||
@@ -319,2 +343,4 @@ bundle: NamedBundle, | ||
options: PluginOptions, | ||
useRuntimeManifest: boolean, | ||
useImportMaps: boolean, | ||
|}): ?RuntimeAsset { | ||
@@ -355,3 +381,2 @@ let loaders = getLoaders(bundle.env); | ||
let needsEsmLoadPrelude = false; | ||
let loaderModules = []; | ||
@@ -369,13 +394,19 @@ | ||
!needsDynamicImportPolyfill && | ||
shouldUseRuntimeManifest(bundle, options) | ||
useRuntimeManifest | ||
) { | ||
loaderModules.push(`load(${JSON.stringify(to.publicId)})`); | ||
needsEsmLoadPrelude = true; | ||
if (useImportMaps) { | ||
loaderModules.push( | ||
`__parcel__import__(${JSON.stringify(to.publicId)})`, | ||
); | ||
} else { | ||
loaderModules.push( | ||
`parcelRequire.load(${JSON.stringify(to.publicId)})`, | ||
); | ||
} | ||
continue; | ||
} | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
// Use esmodule loader if possible | ||
if (to.type === 'js' && to.env.outputFormat === 'esmodule') { | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
if (!needsDynamicImportPolyfill) { | ||
@@ -391,2 +422,3 @@ loaderModules.push(`__parcel__import__("./" + ${relativePathExpr})`); | ||
} else if (to.type === 'js' && to.env.outputFormat === 'commonjs') { | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
loaderModules.push( | ||
@@ -398,7 +430,9 @@ `Promise.resolve(__parcel__require__("./" + ${relativePathExpr}))`, | ||
let absoluteUrlExpr = shouldUseRuntimeManifest(bundle, options) | ||
? `require('./helpers/bundle-manifest').resolve(${JSON.stringify( | ||
to.publicId, | ||
)})` | ||
: getAbsoluteUrlExpr(relativePathExpr, bundle); | ||
let absoluteUrlExpr = getAbsoluteUrlExpr( | ||
bundle, | ||
to, | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
); | ||
let code = `require(${JSON.stringify(loader)})(${absoluteUrlExpr})`; | ||
@@ -462,31 +496,5 @@ | ||
if (needsEsmLoadPrelude && options.featureFlags.importRetry) { | ||
loaderCode = ` | ||
Object.defineProperty(module, 'exports', { get: () => { | ||
let load = require('./helpers/browser/esm-js-loader-retry'); | ||
return ${loaderCode}.then((v) => { | ||
Object.defineProperty(module, "exports", { value: Promise.resolve(v) }) | ||
return v | ||
}); | ||
}})`; | ||
return { | ||
filePath: __filename, | ||
code: loaderCode, | ||
dependency, | ||
env: {sourceType: 'module'}, | ||
}; | ||
} | ||
let code = []; | ||
if (needsEsmLoadPrelude) { | ||
code.push(`let load = require('./helpers/browser/esm-js-loader');`); | ||
} | ||
code.push(`module.exports = ${loaderCode};`); | ||
return { | ||
filePath: __filename, | ||
code: code.join('\n'), | ||
code: `module.exports = ${loaderCode};`, | ||
dependency, | ||
@@ -541,12 +549,10 @@ env: {sourceType: 'module'}, | ||
for (let bundleToPreload of bundlesToPreload) { | ||
let relativePathExpr = getRelativePathExpr( | ||
from, | ||
bundleToPreload, | ||
options, | ||
); | ||
let priority = TYPE_TO_RESOURCE_PRIORITY[bundleToPreload.type]; | ||
hintLoaders.push( | ||
`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr( | ||
relativePathExpr, | ||
from, | ||
bundleToPreload, | ||
options, | ||
false, | ||
false, | ||
)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify( | ||
@@ -585,4 +591,12 @@ bundleToPreload.target.env.outputFormat === 'esmodule', | ||
options: PluginOptions, | ||
useRuntimeManifest: boolean, | ||
useImportMaps: boolean, | ||
): RuntimeAsset { | ||
let relativePathExpr = getRelativePathExpr(from, to, options, true); | ||
let absoluteUrlExpr = getAbsoluteUrlExpr( | ||
from, | ||
to, | ||
options, | ||
useRuntimeManifest, | ||
useImportMaps, | ||
); | ||
let code; | ||
@@ -592,17 +606,6 @@ | ||
code = `let workerURL = require('./helpers/get-worker-url');\n`; | ||
if ( | ||
from.env.outputFormat === 'esmodule' && | ||
from.env.supports('import-meta-url') | ||
) { | ||
code += `let url = new __parcel__URL__(${relativePathExpr});\n`; | ||
code += `module.exports = workerURL(url.toString(), url.origin, ${String( | ||
from.env.outputFormat === 'esmodule', | ||
)});`; | ||
} else { | ||
code += `let bundleURL = require('./helpers/bundle-url');\n`; | ||
code += `let url = bundleURL.getBundleURL('${from.publicId}') + ${relativePathExpr};`; | ||
code += `module.exports = workerURL(url, bundleURL.getOrigin(url), ${String( | ||
from.env.outputFormat === 'esmodule', | ||
)});`; | ||
} | ||
code += `let url = new URL(${absoluteUrlExpr});\n`; | ||
code += `module.exports = workerURL(url.toString(), url.origin, ${String( | ||
from.env.outputFormat === 'esmodule', | ||
)});`; | ||
} else if (from.env.isServer() && to.env.isBrowser()) { | ||
@@ -613,3 +616,3 @@ code = `module.exports = ${JSON.stringify( | ||
} else { | ||
code = `module.exports = ${getAbsoluteUrlExpr(relativePathExpr, from)};`; | ||
code = `module.exports = ${absoluteUrlExpr};`; | ||
} | ||
@@ -629,41 +632,4 @@ | ||
): string { | ||
let mappings = []; | ||
bundleGraph.traverseBundles((bundle, _, actions) => { | ||
if (bundle.bundleBehavior === 'inline') { | ||
return; | ||
} | ||
// To make the manifest as small as possible all bundle key/values are | ||
// serialised into a single array e.g. ['id', 'value', 'id2', 'value2']. | ||
// `./helpers/bundle-manifest` accounts for this by iterating index by 2 | ||
mappings.push( | ||
bundle.publicId, | ||
relativeBundlePath(entryBundle, nullthrows(bundle), { | ||
leadingDotSlash: false, | ||
}), | ||
); | ||
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) { | ||
for (let referenced of bundleGraph.getReferencedBundles(bundle)) { | ||
mappings.push( | ||
referenced.publicId, | ||
relativeBundlePath(entryBundle, nullthrows(referenced), { | ||
leadingDotSlash: false, | ||
}), | ||
); | ||
} | ||
// New contexts have their own manifests, so there's no need to continue. | ||
actions.skipChildren(); | ||
} | ||
}, entryBundle); | ||
let baseUrl = | ||
entryBundle.env.outputFormat === 'esmodule' && | ||
entryBundle.env.supports('import-meta-url') | ||
? 'new __parcel__URL__("").toString()' // <-- this isn't ideal. We should use `import.meta.url` directly but it gets replaced currently | ||
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`; | ||
return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify( | ||
JSON.stringify(mappings), | ||
)}));`; | ||
let mappings = getImportMap(bundleGraph, entryBundle); | ||
return `parcelRequire.extendImportMap(${JSON.stringify(mappings)});`; | ||
} | ||
@@ -686,13 +652,26 @@ | ||
function getAbsoluteUrlExpr(relativePathExpr: string, bundle: NamedBundle) { | ||
if ( | ||
(bundle.env.outputFormat === 'esmodule' && | ||
bundle.env.supports('import-meta-url')) || | ||
bundle.env.outputFormat === 'commonjs' || | ||
bundle.env.isNode() | ||
) { | ||
function getAbsoluteUrlExpr( | ||
bundle: NamedBundle, | ||
to: NamedBundle, | ||
options: PluginOptions, | ||
useRuntimeManifest: boolean, | ||
useImportMaps: boolean, | ||
) { | ||
// let relativePathExpr; | ||
if (useRuntimeManifest) { | ||
if (useImportMaps) { | ||
return `__parcel__import__.meta.resolve(${JSON.stringify(to.publicId)})`; | ||
} else { | ||
return `parcelRequire.resolve(${JSON.stringify(to.publicId)})`; | ||
} | ||
} else if (bundle.env.isLibrary) { | ||
// This will be compiled to new URL(url, import.meta.url) or new URL(url, 'file:' + __filename). | ||
let relativePathExpr = getRelativePathExpr(bundle, to, options); | ||
return `new __parcel__URL__(${relativePathExpr}).toString()`; | ||
} else { | ||
return `require('./helpers/bundle-url').getBundleURL('${bundle.publicId}') + ${relativePathExpr}`; | ||
let res = `parcelRequire.resolve(${JSON.stringify(to.name)})`; | ||
if (to.type !== 'js' && options.hmrOptions) { | ||
res += ' + "?" + Date.now()'; | ||
} | ||
return res; | ||
} | ||
@@ -713,1 +692,13 @@ } | ||
} | ||
function shouldUseImportMaps( | ||
bundleGraph: BundleGraph<NamedBundle>, | ||
bundle: NamedBundle, | ||
) { | ||
return ( | ||
bundle.env.outputFormat === 'esmodule' && | ||
bundle.env.supports('import-meta-resolve') && | ||
!bundle.env.isIsolated() && | ||
bundleGraph.getEntryBundles().every(entry => entry.type === 'html') | ||
); | ||
} |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
58667
38
1646