@parcel/packager-js
Advanced tools
Comparing version 2.0.0-canary.1772 to 2.0.0-canary.1775
@@ -28,2 +28,3 @@ // modules are defined as an array | ||
var importMap = previousRequire.i || {}; | ||
var cache = previousRequire.cache || {}; | ||
@@ -107,2 +108,3 @@ // Do not use `require` to prevent Webpack from trying to bundle this call | ||
newRequire.publicUrl = publicUrl; | ||
newRequire.i = importMap; | ||
newRequire.register = function (id, exports) { | ||
@@ -109,0 +111,0 @@ modules[id] = [ |
@@ -43,2 +43,3 @@ "use strict"; | ||
var _utils2 = require("./utils"); | ||
var _helpers = require("./helpers"); | ||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } | ||
@@ -163,5 +164,19 @@ const PRELUDE = _fs().default.readFileSync(_path().default.join(__dirname, 'dev-prelude.js'), 'utf8').trim().replace(/;$/, ''); | ||
} | ||
let load = ''; | ||
if (usedHelpers & 4) { | ||
prefix = prefix.replace('// INSERT_LOAD_HERE', 'newRequire.load = function (url) { return import(distDir + "/" + url); }'); | ||
load += _helpers.helpers.$parcel$import(this.bundle.env, this.bundle, new Set()); | ||
load += 'newRequire.load = $parcel$import;\n'; | ||
} | ||
if (usedHelpers & 8) { | ||
load += _helpers.helpers.$parcel$resolve(this.bundle.env, this.bundle, new Set()); | ||
load += 'newRequire.resolve = $parcel$resolve;\n'; | ||
} | ||
if (usedHelpers & 16) { | ||
load += _helpers.helpers.$parcel$extendImportMap(this.bundle.env); | ||
load += `newRequire.extendImportMap = $parcel$extendImportMap;\n`; | ||
} | ||
if (load) { | ||
usedHelpers |= 1 | 2; | ||
prefix = prefix.replace('// INSERT_LOAD_HERE', load); | ||
} | ||
let contents = prefix + '({' + assets + '},' + JSON.stringify(entries.map(asset => this.bundleGraph.getAssetPublicId(asset))) + ', ' + JSON.stringify(mainEntry ? this.bundleGraph.getAssetPublicId(mainEntry) : null) + ', ' + JSON.stringify(this.parcelRequireName); | ||
@@ -171,4 +186,4 @@ if (usedHelpers & 1) { | ||
let distDir = (0, _utils().relativePath)(_path().default.dirname(this.bundle.name), ''); | ||
if (distDir.endsWith('/')) { | ||
distDir = distDir.slice(0, -1); | ||
if (!distDir.endsWith('/')) { | ||
distDir += '/'; | ||
} | ||
@@ -175,0 +190,0 @@ contents += ', ' + JSON.stringify(distDir); |
@@ -141,4 +141,4 @@ "use strict"; | ||
let distDir = (0, _utils().relativePath)(_path().default.dirname(bundle.name), ''); | ||
if (distDir.endsWith('/')) { | ||
distDir = distDir.slice(0, -1); | ||
if (!distDir.endsWith('/')) { | ||
distDir += '/'; | ||
} | ||
@@ -155,5 +155,82 @@ return `var $parcel$distDir = ${JSON.stringify(distDir)};\n`; | ||
}; | ||
const $parcel$import = env => { | ||
return `var $parcel$import = ${fnExpr(env, ['url'], ['return import($parcel$distDir + "/" + url);'])};\n`; | ||
const $parcel$extendImportMap = env => { | ||
let defineImportMap = env.shouldScopeHoist ? 'parcelRequire.i ??= {}' : 'importMap'; | ||
return ` | ||
function $parcel$extendImportMap(map) { | ||
Object.assign(${defineImportMap}, map); | ||
} | ||
`; | ||
}; | ||
const $parcel$import = (env, bundle, usedHelpers) => { | ||
usedHelpers.add('$parcel$distDir'); | ||
let distDir = env.shouldScopeHoist ? '$parcel$distDir' : 'distDir'; | ||
let importMap = env.shouldScopeHoist ? 'parcelRequire.i?.' : 'importMap'; | ||
return ` | ||
function $parcel$import(url) { | ||
url = ${importMap}[url] || url; | ||
return import(${distDir} + url); | ||
} | ||
`; | ||
}; | ||
const $parcel$resolve = (env, bundle, usedHelpers) => { | ||
let distDir = env.shouldScopeHoist ? '$parcel$distDir' : 'distDir'; | ||
let publicUrl = env.shouldScopeHoist ? '$parcel$publicUrl' : 'publicUrl'; | ||
let importMap = env.shouldScopeHoist ? 'parcelRequire.i?.' : 'importMap'; | ||
if (env.context === 'react-server' || env.context === 'react-client') { | ||
usedHelpers.add('$parcel$publicUrl'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return ${publicUrl} + url; | ||
} | ||
`; | ||
} else if (env.outputFormat === 'esmodule' && env.supports('import-meta-resolve')) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return import.meta.resolve(${distDir} + url); | ||
} | ||
`; | ||
} else if (env.outputFormat === 'esmodule' && env.supports('import-meta-url')) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return new URL(${distDir} + url, import.meta.url).toString(); | ||
} | ||
`; | ||
} else if (env.outputFormat === 'commonjs' || env.isNode()) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return new URL(${distDir} + url, 'file:' + __filename).toString(); | ||
} | ||
`; | ||
} else { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
var $parcel$bundleURL; | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
if (!$parcel$bundleURL) { | ||
try { | ||
throw new Error(); | ||
} catch (err) { | ||
var matches = ('' + err.stack).match( | ||
/(https?|file|ftp|(chrome|moz|safari-web)-extension):\\/\\/[^)\\n]+/g, | ||
); | ||
if (matches) { | ||
$parcel$bundleURL = matches[0]; | ||
} else { | ||
return ${distDir} + url; | ||
} | ||
} | ||
} | ||
return new URL(${distDir} + url, $parcel$bundleURL).toString(); | ||
} | ||
`; | ||
} | ||
}; | ||
const helpers = exports.helpers = { | ||
@@ -167,3 +244,5 @@ $parcel$export, | ||
$parcel$publicUrl, | ||
$parcel$import | ||
$parcel$extendImportMap, | ||
$parcel$import, | ||
$parcel$resolve | ||
}; |
@@ -405,4 +405,13 @@ "use strict"; | ||
if (usedHelpers & 4) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$import'); | ||
} | ||
if (usedHelpers & 8) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$resolve'); | ||
} | ||
if (usedHelpers & 16) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$extendImportMap'); | ||
} | ||
} | ||
@@ -1004,3 +1013,3 @@ if (this.bundle.env.isNode() && asset.meta.has_node_replacements) { | ||
if (typeof currentHelper === 'function') { | ||
currentHelper = _helpers.helpers[helper](this.bundle.env, this.bundle); | ||
currentHelper = _helpers.helpers[helper](this.bundle.env, this.bundle, this.usedHelpers); | ||
} | ||
@@ -1007,0 +1016,0 @@ res += currentHelper; |
{ | ||
"name": "@parcel/packager-js", | ||
"version": "2.0.0-canary.1772+f86f5f27c", | ||
"version": "2.0.0-canary.1775+735a635f7", | ||
"license": "MIT", | ||
@@ -20,15 +20,15 @@ "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/rust": "2.13.4-canary.3395+f86f5f27c", | ||
"@parcel/diagnostic": "2.0.0-canary.1775+735a635f7", | ||
"@parcel/plugin": "2.0.0-canary.1775+735a635f7", | ||
"@parcel/rust": "2.13.4-canary.3398+735a635f7", | ||
"@parcel/source-map": "^2.1.1", | ||
"@parcel/types": "2.0.0-canary.1772+f86f5f27c", | ||
"@parcel/utils": "2.0.0-canary.1772+f86f5f27c", | ||
"@parcel/types": "2.0.0-canary.1775+735a635f7", | ||
"@parcel/utils": "2.0.0-canary.1775+735a635f7", | ||
"globals": "^13.2.0", | ||
"nullthrows": "^1.1.1" | ||
}, | ||
"gitHead": "f86f5f27c3a6553e70bd35652f19e6ab8d8e4e4a" | ||
"gitHead": "735a635f7eed538c449f37517b26247e0b19c1a4" | ||
} |
@@ -28,2 +28,3 @@ // modules are defined as an array | ||
var importMap = previousRequire.i || {}; | ||
var cache = previousRequire.cache || {}; | ||
@@ -107,2 +108,3 @@ // Do not use `require` to prevent Webpack from trying to bundle this call | ||
newRequire.publicUrl = publicUrl; | ||
newRequire.i = importMap; | ||
newRequire.register = function (id, exports) { | ||
@@ -109,0 +111,0 @@ modules[id] = [ |
@@ -16,2 +16,3 @@ // @flow strict-local | ||
import {replaceScriptDependencies, getSpecifier} from './utils'; | ||
import {helpers} from './helpers'; | ||
@@ -190,9 +191,23 @@ const PRELUDE = fs | ||
let load = ''; | ||
if (usedHelpers & 4) { | ||
prefix = prefix.replace( | ||
'// INSERT_LOAD_HERE', | ||
'newRequire.load = function (url) { return import(distDir + "/" + url); }', | ||
); | ||
load += helpers.$parcel$import(this.bundle.env, this.bundle, new Set()); | ||
load += 'newRequire.load = $parcel$import;\n'; | ||
} | ||
if (usedHelpers & 8) { | ||
load += helpers.$parcel$resolve(this.bundle.env, this.bundle, new Set()); | ||
load += 'newRequire.resolve = $parcel$resolve;\n'; | ||
} | ||
if (usedHelpers & 16) { | ||
load += helpers.$parcel$extendImportMap(this.bundle.env); | ||
load += `newRequire.extendImportMap = $parcel$extendImportMap;\n`; | ||
} | ||
if (load) { | ||
usedHelpers |= 1 | 2; | ||
prefix = prefix.replace('// INSERT_LOAD_HERE', load); | ||
} | ||
let contents = | ||
@@ -216,4 +231,4 @@ prefix + | ||
let distDir = relativePath(path.dirname(this.bundle.name), ''); | ||
if (distDir.endsWith('/')) { | ||
distDir = distDir.slice(0, -1); | ||
if (!distDir.endsWith('/')) { | ||
distDir += '/'; | ||
} | ||
@@ -220,0 +235,0 @@ contents += ', ' + JSON.stringify(distDir); |
@@ -168,4 +168,4 @@ // @flow strict-local | ||
let distDir = relativePath(path.dirname(bundle.name), ''); | ||
if (distDir.endsWith('/')) { | ||
distDir = distDir.slice(0, -1); | ||
if (!distDir.endsWith('/')) { | ||
distDir += '/'; | ||
} | ||
@@ -184,10 +184,101 @@ return `var $parcel$distDir = ${JSON.stringify(distDir)};\n`; | ||
const $parcel$import = (env: Environment): string => { | ||
return `var $parcel$import = ${fnExpr( | ||
env, | ||
['url'], | ||
['return import($parcel$distDir + "/" + url);'], | ||
)};\n`; | ||
const $parcel$extendImportMap = (env: Environment): string => { | ||
let defineImportMap = env.shouldScopeHoist | ||
? 'parcelRequire.i ??= {}' | ||
: 'importMap'; | ||
return ` | ||
function $parcel$extendImportMap(map) { | ||
Object.assign(${defineImportMap}, map); | ||
} | ||
`; | ||
}; | ||
const $parcel$import = ( | ||
env: Environment, | ||
bundle: NamedBundle, | ||
usedHelpers: Set<string>, | ||
): string => { | ||
usedHelpers.add('$parcel$distDir'); | ||
let distDir = env.shouldScopeHoist ? '$parcel$distDir' : 'distDir'; | ||
let importMap = env.shouldScopeHoist ? 'parcelRequire.i?.' : 'importMap'; | ||
return ` | ||
function $parcel$import(url) { | ||
url = ${importMap}[url] || url; | ||
return import(${distDir} + url); | ||
} | ||
`; | ||
}; | ||
const $parcel$resolve = ( | ||
env: Environment, | ||
bundle: NamedBundle, | ||
usedHelpers: Set<string>, | ||
): string => { | ||
let distDir = env.shouldScopeHoist ? '$parcel$distDir' : 'distDir'; | ||
let publicUrl = env.shouldScopeHoist ? '$parcel$publicUrl' : 'publicUrl'; | ||
let importMap = env.shouldScopeHoist ? 'parcelRequire.i?.' : 'importMap'; | ||
if (env.context === 'react-server' || env.context === 'react-client') { | ||
usedHelpers.add('$parcel$publicUrl'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return ${publicUrl} + url; | ||
} | ||
`; | ||
} else if ( | ||
env.outputFormat === 'esmodule' && | ||
env.supports('import-meta-resolve') | ||
) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return import.meta.resolve(${distDir} + url); | ||
} | ||
`; | ||
} else if ( | ||
env.outputFormat === 'esmodule' && | ||
env.supports('import-meta-url') | ||
) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return new URL(${distDir} + url, import.meta.url).toString(); | ||
} | ||
`; | ||
} else if (env.outputFormat === 'commonjs' || env.isNode()) { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
return new URL(${distDir} + url, 'file:' + __filename).toString(); | ||
} | ||
`; | ||
} else { | ||
usedHelpers.add('$parcel$distDir'); | ||
return ` | ||
var $parcel$bundleURL; | ||
function $parcel$resolve(url) { | ||
url = ${importMap}[url] || url; | ||
if (!$parcel$bundleURL) { | ||
try { | ||
throw new Error(); | ||
} catch (err) { | ||
var matches = ('' + err.stack).match( | ||
/(https?|file|ftp|(chrome|moz|safari-web)-extension):\\/\\/[^)\\n]+/g, | ||
); | ||
if (matches) { | ||
$parcel$bundleURL = matches[0]; | ||
} else { | ||
return ${distDir} + url; | ||
} | ||
} | ||
} | ||
return new URL(${distDir} + url, $parcel$bundleURL).toString(); | ||
} | ||
`; | ||
} | ||
}; | ||
export const helpers = { | ||
@@ -201,3 +292,5 @@ $parcel$export, | ||
$parcel$publicUrl, | ||
$parcel$extendImportMap, | ||
$parcel$import, | ||
$parcel$resolve, | ||
}; |
@@ -528,4 +528,13 @@ // @flow | ||
if (usedHelpers & 4) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$import'); | ||
} | ||
if (usedHelpers & 8) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$resolve'); | ||
} | ||
if (usedHelpers & 16) { | ||
this.needsPrelude = true; | ||
this.usedHelpers.add('$parcel$extendImportMap'); | ||
} | ||
} | ||
@@ -1388,3 +1397,7 @@ | ||
if (typeof currentHelper === 'function') { | ||
currentHelper = helpers[helper](this.bundle.env, this.bundle); | ||
currentHelper = helpers[helper]( | ||
this.bundle.env, | ||
this.bundle, | ||
this.usedHelpers, | ||
); | ||
} | ||
@@ -1391,0 +1404,0 @@ res += currentHelper; |
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
171368
4457