Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@parcel/runtime-js

Package Overview
Dependencies
Maintainers
1
Versions
889
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@parcel/runtime-js - npm Package Compare versions

Comparing version 2.0.0-nightly.144 to 2.0.0-nightly.146

lib/bundle-manifest.js

80

lib/JSRuntime.js

@@ -16,2 +16,4 @@ "use strict";

var _nullthrows = _interopRequireDefault(require("nullthrows"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -115,24 +117,22 @@

let loaderModules = loaders ? externalBundles.map(b => {
let loader = loaders[b.type];
let loaderModules = loaders ? externalBundles.map(to => {
let loader = loaders[to.type];
if (!loader) {
return;
} // Use esmodule loader if possible
}
let relativePathExpr = getRelativePathExpr(bundle, to); // Use esmodule loader if possible
if (b.type === 'js' && b.env.outputFormat === 'esmodule') {
if (to.type === 'js' && to.env.outputFormat === 'esmodule') {
if (!needsDynamicImportPolyfill) {
return `import('' + '${(0, _utils.relativeBundlePath)(bundle, b)}')`;
return `import("./" + ${relativePathExpr})`;
}
loader = IMPORT_POLYFILL;
} else if (b.type === 'js' && b.env.outputFormat === 'commonjs') {
return `Promise.resolve(require('' + '${(0, _utils.relativeBundlePath)(bundle, b)}'))`;
} else if (to.type === 'js' && to.env.outputFormat === 'commonjs') {
return `Promise.resolve(require("./" + ${relativePathExpr}))`;
}
let relativePath = (0, _utils.relativeBundlePath)(bundle, b, {
leadingDotSlash: false
});
return `require(${JSON.stringify(loader)})(require('./bundle-url').getBundleURL() + ${JSON.stringify(relativePath)})`;
return `require(${JSON.stringify(loader)})(require('./bundle-url').getBundleURL() + ${relativePathExpr})`;
}).filter(Boolean) : [];

@@ -166,2 +166,10 @@

if (shouldUseRuntimeManifest(bundle) && bundleGraph.getChildBundles(bundle).length > 0 && isNewContext(bundle, bundleGraph)) {
assets.push({
filePath: __filename,
code: getRegisterCode(bundle, bundleGraph),
isEntry: true
});
}
return assets;

@@ -174,11 +182,13 @@ }

function getURLRuntime(dependency, bundle, externalBundle) {
let relativePath = (0, _utils.relativeBundlePath)(bundle, externalBundle, {
leadingDotSlash: false
});
function isNewContext(bundle, bundleGraph) {
return bundle.isEntry || bundleGraph.getParentBundles(bundle).some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
}
function getURLRuntime(dependency, from, to) {
let relativePathExpr = getRelativePathExpr(from, to);
if (dependency.meta.webworker === true) {
return {
filePath: __filename,
code: `module.exports = require('./get-worker-url')(${JSON.stringify(relativePath)});`,
code: `module.exports = require('./get-worker-url')(${relativePathExpr});`,
dependency

@@ -190,5 +200,41 @@ };

filePath: __filename,
code: `module.exports = require('./bundle-url').getBundleURL() + ${JSON.stringify(relativePath)}`,
code: `module.exports = require('./bundle-url').getBundleURL() + ${relativePathExpr}`,
dependency
};
}
function getRegisterCode(entryBundle, bundleGraph) {
let idToName = {};
bundleGraph.traverseBundles((bundle, _, actions) => {
if (bundle.isInline) {
return;
}
idToName[getPublicId(bundle.id)] = (0, _nullthrows.default)(bundle.name);
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
// New contexts have their own manifests, so there's no need to continue.
actions.skipChildren();
}
}, entryBundle);
return "require('./bundle-manifest').register(JSON.parse(" + JSON.stringify(JSON.stringify(idToName)) + '));';
}
function getRelativePathExpr(from, to) {
if (shouldUseRuntimeManifest(from)) {
return `require('./relative-path')(${JSON.stringify(getPublicId(from.id))}, ${JSON.stringify(getPublicId(to.id))})`;
}
return JSON.stringify((0, _utils.relativeBundlePath)(from, to, {
leadingDotSlash: false
}));
}
function getPublicId(id) {
return id.slice(-16);
}
function shouldUseRuntimeManifest(bundle) {
let env = bundle.env;
return !env.isLibrary && env.outputFormat === 'global' && env.isBrowser();
}
{
"name": "@parcel/runtime-js",
"version": "2.0.0-nightly.144+dd76c9c8",
"version": "2.0.0-nightly.146+f2a62434",
"license": "MIT",

@@ -19,6 +19,7 @@ "publishConfig": {

"dependencies": {
"@parcel/plugin": "2.0.0-nightly.144+dd76c9c8",
"@parcel/utils": "2.0.0-nightly.144+dd76c9c8"
"@parcel/plugin": "2.0.0-nightly.146+f2a62434",
"@parcel/utils": "2.0.0-nightly.146+f2a62434",
"nullthrows": "^1.1.1"
},
"gitHead": "dd76c9c84ec223365f1a39b6ec8e68dc16a3a31e"
"gitHead": "f2a62434adbba86bdd56774833d70d7852988ed1"
}
// @flow strict-local
import type {Bundle, Dependency, RuntimeAsset} from '@parcel/types';
import type {
Bundle,
BundleGraph,
Dependency,
RuntimeAsset,
} from '@parcel/types';

@@ -9,2 +14,3 @@ import assert from 'assert';

import path from 'path';
import nullthrows from 'nullthrows';

@@ -120,4 +126,4 @@ // List of browsers that support dynamic import natively

? externalBundles
.map(b => {
let loader = loaders[b.type];
.map(to => {
let loader = loaders[to.type];
if (!loader) {

@@ -127,24 +133,21 @@ return;

let relativePathExpr = getRelativePathExpr(bundle, to);
// Use esmodule loader if possible
if (b.type === 'js' && b.env.outputFormat === 'esmodule') {
if (to.type === 'js' && to.env.outputFormat === 'esmodule') {
if (!needsDynamicImportPolyfill) {
return `import('' + '${relativeBundlePath(bundle, b)}')`;
return `import("./" + ${relativePathExpr})`;
}
loader = IMPORT_POLYFILL;
} else if (b.type === 'js' && b.env.outputFormat === 'commonjs') {
return `Promise.resolve(require('' + '${relativeBundlePath(
bundle,
b,
)}'))`;
} else if (
to.type === 'js' &&
to.env.outputFormat === 'commonjs'
) {
return `Promise.resolve(require("./" + ${relativePathExpr}))`;
}
let relativePath = relativeBundlePath(bundle, b, {
leadingDotSlash: false,
});
return `require(${JSON.stringify(
loader,
)})(require('./bundle-url').getBundleURL() + ${JSON.stringify(
relativePath,
)})`;
)})(require('./bundle-url').getBundleURL() + ${relativePathExpr})`;
})

@@ -182,2 +185,14 @@ .filter(Boolean)

if (
shouldUseRuntimeManifest(bundle) &&
bundleGraph.getChildBundles(bundle).length > 0 &&
isNewContext(bundle, bundleGraph)
) {
assets.push({
filePath: __filename,
code: getRegisterCode(bundle, bundleGraph),
isEntry: true,
});
}
return assets;

@@ -187,10 +202,20 @@ },

function isNewContext(bundle: Bundle, bundleGraph: BundleGraph): boolean {
return (
bundle.isEntry ||
bundleGraph
.getParentBundles(bundle)
.some(
parent =>
parent.env.context !== bundle.env.context || parent.type !== 'js',
)
);
}
function getURLRuntime(
dependency: Dependency,
bundle: Bundle,
externalBundle: Bundle,
from: Bundle,
to: Bundle,
): RuntimeAsset {
let relativePath = relativeBundlePath(bundle, externalBundle, {
leadingDotSlash: false,
});
let relativePathExpr = getRelativePathExpr(from, to);

@@ -200,5 +225,3 @@ if (dependency.meta.webworker === true) {

filePath: __filename,
code: `module.exports = require('./get-worker-url')(${JSON.stringify(
relativePath,
)});`,
code: `module.exports = require('./get-worker-url')(${relativePathExpr});`,
dependency,

@@ -210,7 +233,49 @@ };

filePath: __filename,
code: `module.exports = require('./bundle-url').getBundleURL() + ${JSON.stringify(
relativePath,
)}`,
code: `module.exports = require('./bundle-url').getBundleURL() + ${relativePathExpr}`,
dependency,
};
}
function getRegisterCode(
entryBundle: Bundle,
bundleGraph: BundleGraph,
): string {
let idToName = {};
bundleGraph.traverseBundles((bundle, _, actions) => {
if (bundle.isInline) {
return;
}
idToName[getPublicId(bundle.id)] = nullthrows(bundle.name);
if (bundle !== entryBundle && isNewContext(bundle, bundleGraph)) {
// New contexts have their own manifests, so there's no need to continue.
actions.skipChildren();
}
}, entryBundle);
return (
"require('./bundle-manifest').register(JSON.parse(" +
JSON.stringify(JSON.stringify(idToName)) +
'));'
);
}
function getRelativePathExpr(from: Bundle, to: Bundle): string {
if (shouldUseRuntimeManifest(from)) {
return `require('./relative-path')(${JSON.stringify(
getPublicId(from.id),
)}, ${JSON.stringify(getPublicId(to.id))})`;
}
return JSON.stringify(relativeBundlePath(from, to, {leadingDotSlash: false}));
}
function getPublicId(id: string): string {
return id.slice(-16);
}
function shouldUseRuntimeManifest(bundle: Bundle): boolean {
let env = bundle.env;
return !env.isLibrary && env.outputFormat === 'global' && env.isBrowser();
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc