@neon-rs/load
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -26,3 +26,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.load = exports.currentTarget = void 0; | ||
exports.currentTarget = void 0; | ||
const path = __importStar(require("path")); | ||
@@ -99,6 +99,21 @@ const fs = __importStar(require("fs")); | ||
} | ||
function load(dirname) { | ||
function debug(dirname) { | ||
const m = path.join(dirname, "index.node"); | ||
return fs.existsSync(m) ? require(m) : null; | ||
} | ||
exports.load = load; | ||
function load(options) { | ||
let debugModule = null; | ||
if (options.debug && (debugModule = debug(options.debug))) { | ||
return debugModule; | ||
} | ||
if ("dir" in options) { | ||
return require(path.join(options.dir, "index.node")); | ||
} | ||
if ("scope" in options) { | ||
return require(options.scope + "/" + currentTarget()); | ||
} | ||
if ("custom" in options) { | ||
return require(options.custom(currentTarget())); | ||
} | ||
} | ||
exports.default = load; |
{ | ||
"name": "@neon-rs/load", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "Utilities for loading Neon modules.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
export declare function currentTarget(): string; | ||
export declare function load(dirname: string): any; | ||
export type LoadDir = { | ||
debug?: string; | ||
dir: string; | ||
}; | ||
export type LoadScope = { | ||
debug?: string; | ||
scope: string; | ||
}; | ||
export type LoadCustom = { | ||
debug?: string; | ||
custom: (target: string) => string; | ||
}; | ||
export type LoadOptions = LoadDir | LoadScope | LoadCustom; | ||
export default function load(options: LoadOptions): any; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
6330
132
5