@kablamo/rollup-plugin-resolve-externals
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,10 +0,21 @@ | ||
import { escapeRegExp } from "lodash"; | ||
import path from "path"; | ||
export default function resolveExternals({ externals, paths = require.main?.paths, }) { | ||
const external = ((source) => externals.includes(source) || | ||
externals.some((mod) => source.startsWith(`${mod}/`))); | ||
const deepExternalRegex = new RegExp(`^(${externals.map((e) => escapeRegExp(e)).join("|")})/(.+)$`); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var lodash_1 = require("lodash"); | ||
var path_1 = __importDefault(require("path")); | ||
function resolveExternals(_a) { | ||
var _b; | ||
var externals = _a.externals, _c = _a.paths, paths = _c === void 0 ? (_b = require.main) === null || _b === void 0 ? void 0 : _b.paths : _c; | ||
var external = (function (source) { | ||
return externals.includes(source) || | ||
externals.some(function (mod) { | ||
return source.startsWith("".concat(mod, "/")); | ||
}); | ||
}); | ||
var deepExternalRegex = new RegExp("^(".concat(externals.map(function (e) { return (0, lodash_1.escapeRegExp)(e); }).join("|"), ")/(.+)$")); | ||
return { | ||
name: "@kablamo/rollup-plugin-resolve-externals", | ||
resolveId(source) { | ||
resolveId: function (source) { | ||
// Ignore non-externals | ||
@@ -14,7 +25,7 @@ if (!external(source)) | ||
// Match deep imports from a package | ||
const match = deepExternalRegex.exec(source); | ||
var match = deepExternalRegex.exec(source); | ||
if (match) { | ||
const [, mod, importPath] = match; | ||
var mod = match[1], importPath = match[2]; | ||
// eslint-disable-next-line import/no-dynamic-require, global-require, @typescript-eslint/no-var-requires | ||
const pkgJson = require(`${mod}/package.json`); | ||
var pkgJson = require("".concat(mod, "/package.json")); | ||
// If package exports are not defined, we need to resolve the path so that CommonJS files | ||
@@ -24,13 +35,13 @@ // can be resolved properly from `.mjs` files | ||
// Resolve the module to a path on disk | ||
const resolvedPath = require.resolve(`${mod}/${importPath}`, { | ||
paths, | ||
var resolvedPath = require.resolve("".concat(mod, "/").concat(importPath), { | ||
paths: paths, | ||
}); | ||
// Rewrite to a relative path | ||
const rewritten = `${mod}/${path | ||
.relative(path.dirname(require.resolve(`${mod}/package.json`, { | ||
paths, | ||
var rewritten = "".concat(mod, "/").concat(path_1.default | ||
.relative(path_1.default.dirname(require.resolve("".concat(mod, "/package.json"), { | ||
paths: paths, | ||
})), resolvedPath) | ||
// Handle win32 path separators | ||
.split(path.sep) | ||
.join("/")}`; | ||
.split(path_1.default.sep) | ||
.join("/")); | ||
return { | ||
@@ -49,1 +60,2 @@ id: rewritten, | ||
} | ||
exports.default = resolveExternals; |
{ | ||
"name": "@kablamo/rollup-plugin-resolve-externals", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": "https://github.com/KablamoOSS/kerosene/tree/master/packages/rollup-plugin-resolve-externals", | ||
@@ -5,0 +5,0 @@ "bugs": { |
{ | ||
"extends": "../../tsconfig", | ||
"compilerOptions": { | ||
"target": "ES5", | ||
"module": "CommonJS", | ||
"moduleResolution": "Node10", | ||
"resolvePackageJsonExports": false, | ||
"resolvePackageJsonImports": false, | ||
"verbatimModuleSyntax": false, | ||
"isolatedModules": true, | ||
"outDir": "dist", | ||
@@ -5,0 +12,0 @@ "noEmit": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
7191
160