@neon-rs/load 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.load = exports.currentTarget = void 0;
26
+ exports.currentTarget = void 0;
27
27
  const path = __importStar(require("path"));
28
28
  const fs = __importStar(require("fs"));
29
29
  function currentTarget() {
@@ -95,8 +95,23 @@ function isGlibc() {
95
95
  !!header &&
96
96
  ('glibcVersionRuntime' in header);
97
97
  }
98
- function load(dirname) {
98
+ function debug(dirname) {
99
99
  const m = path.join(dirname, "index.node");
100
100
  return fs.existsSync(m) ? require(m) : null;
101
101
  }
102
- exports.load = load;
102
+ function load(options) {
103
+ let debugModule = null;
104
+ if (options.debug && (debugModule = debug(options.debug))) {
105
+ return debugModule;
106
+ }
107
+ if ("dir" in options) {
108
+ return require(path.join(options.dir, "index.node"));
109
+ }
110
+ if ("scope" in options) {
111
+ return require(options.scope + "/" + currentTarget());
112
+ }
113
+ if ("custom" in options) {
114
+ return require(options.custom(currentTarget()));
115
+ }
116
+ }
117
+ exports.default = load;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/load",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Utilities for loading Neon modules.",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
package/types/index.d.ts CHANGED
@@ -1,2 +1,15 @@
1
1
  export declare function currentTarget(): string;
2
- export declare function load(dirname: string): any;
2
+ export type LoadDir = {
3
+ debug?: string;
4
+ dir: string;
5
+ };
6
+ export type LoadScope = {
7
+ debug?: string;
8
+ scope: string;
9
+ };
10
+ export type LoadCustom = {
11
+ debug?: string;
12
+ custom: (target: string) => string;
13
+ };
14
+ export type LoadOptions = LoadDir | LoadScope | LoadCustom;
15
+ export default function load(options: LoadOptions): any;