@neon-rs/load 0.0.68 → 0.0.70

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bin = exports.currentTarget = void 0;
3
+ exports.lazy = exports.bin = exports.currentTarget = void 0;
4
4
  function currentTarget() {
5
5
  let os = null;
6
6
  switch (process.platform) {
@@ -92,3 +92,23 @@ function bin(scope, ...rest) {
92
92
  return [...interleave(scope, rest)].join("") + "/" + currentTarget();
93
93
  }
94
94
  exports.bin = bin;
95
+ function lazy(loaders, exports) {
96
+ let loaded = null;
97
+ function load() {
98
+ if (loaded) {
99
+ return loaded;
100
+ }
101
+ const target = currentTarget();
102
+ if (!loaders.hasOwnProperty(target)) {
103
+ throw new Error(`no precompiled module found for ${target}`);
104
+ }
105
+ loaded = loaders[target]();
106
+ return loaded;
107
+ }
108
+ let module = {};
109
+ for (const key of exports) {
110
+ Object.defineProperty(module, key, { get() { return load()[key]; } });
111
+ }
112
+ return module;
113
+ }
114
+ exports.lazy = lazy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/load",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
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,3 @@
1
1
  export declare function currentTarget(): string;
2
2
  export declare function bin(scope: string[], ...rest: string[]): string;
3
+ export declare function lazy(loaders: Record<string, () => any>, exports: string[]): any;