parcel-plugin-externals
Advanced tools
Comparing version 0.3.0-pre.20191112.1 to 0.3.0-pre.20191130.1
@@ -7,2 +7,3 @@ # parcel-plugin-externals Changelog | ||
- Fixed exception on browser property set to false (#6) | ||
- Added support for referencing modules directly (#7) | ||
@@ -9,0 +10,0 @@ ## 0.2.0 |
{ | ||
"name": "parcel-plugin-externals", | ||
"version": "0.3.0-pre.20191112.1", | ||
"version": "0.3.0-pre.20191130.1", | ||
"description": "A plugin for Parcel to omit declared externals from being included in the emitted bundles.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
32
utils.js
@@ -5,7 +5,31 @@ const { readFileSync, existsSync } = require("fs"); | ||
function inspect(name) { | ||
let scope = ""; | ||
let path = ""; | ||
if (name.startsWith("@")) { | ||
scope = name.substr(0, name.indexOf("/")); | ||
name = name.replace(`${scope}/`, ""); | ||
} | ||
if (name.indexOf("/") !== -1) { | ||
path = name.substr(name.indexOf("/") + 1); | ||
name = name.replace(`/${path}`, ""); | ||
} | ||
return { | ||
scope, | ||
name, | ||
path, | ||
fullName: scope ? `${scope}/${name}` : name | ||
}; | ||
} | ||
function resolveModule(rule, targetDir) { | ||
const { name } = splitRule(rule); | ||
const { fullName, path } = inspect(name); | ||
try { | ||
const moduleDefinitionFile = `${name}/package.json`; | ||
const packageName = path ? `${fullName}/${path}` : fullName; | ||
const moduleDefinitionFile = `${fullName}/package.json`; | ||
const moduleDefinition = require(moduleDefinitionFile); | ||
@@ -17,3 +41,3 @@ const replacements = {}; | ||
if (typeof moduleDefinition.browser === "string") { | ||
if (!path && typeof moduleDefinition.browser === "string") { | ||
return [ | ||
@@ -41,3 +65,3 @@ { | ||
if (typeof moduleDefinition.module === "string") { | ||
if (!path && typeof moduleDefinition.module === "string") { | ||
const modulePath = resolve(moduleRoot, moduleDefinition.module); | ||
@@ -54,3 +78,3 @@ return [ | ||
const directPath = require.resolve(name, { | ||
const directPath = require.resolve(packageName, { | ||
paths: [targetDir] | ||
@@ -57,0 +81,0 @@ }); |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
13556
246