@neon-rs/load 0.0.152 → 0.0.154
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 +24 -2
- package/package.json +1 -1
- package/types/index.d.ts +6 -0
package/dist/index.js
CHANGED
|
@@ -92,7 +92,14 @@ function bin(scope, ...rest) {
|
|
|
92
92
|
return [...interleave(scope, rest)].join("") + "/" + currentTarget();
|
|
93
93
|
}
|
|
94
94
|
exports.bin = bin;
|
|
95
|
-
function
|
|
95
|
+
function lazyV1(loaders, exports) {
|
|
96
|
+
return lazyV2({
|
|
97
|
+
targets: loaders,
|
|
98
|
+
exports
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function lazyV2(options) {
|
|
102
|
+
const loaders = options.targets;
|
|
96
103
|
let loaded = null;
|
|
97
104
|
function load() {
|
|
98
105
|
if (loaded) {
|
|
@@ -102,7 +109,17 @@ function lazy(loaders, exports) {
|
|
|
102
109
|
if (!loaders.hasOwnProperty(target)) {
|
|
103
110
|
throw new Error(`no precompiled module found for ${target}`);
|
|
104
111
|
}
|
|
105
|
-
|
|
112
|
+
if (options.debug) {
|
|
113
|
+
try {
|
|
114
|
+
loaded = options.debug();
|
|
115
|
+
}
|
|
116
|
+
catch (_e) {
|
|
117
|
+
loaded = null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (!loaded) {
|
|
121
|
+
loaded = loaders[target]();
|
|
122
|
+
}
|
|
106
123
|
return loaded;
|
|
107
124
|
}
|
|
108
125
|
let module = {};
|
|
@@ -111,4 +128,9 @@ function lazy(loaders, exports) {
|
|
|
111
128
|
}
|
|
112
129
|
return module;
|
|
113
130
|
}
|
|
131
|
+
function lazy(optionsOrLoaders, exports) {
|
|
132
|
+
return exports
|
|
133
|
+
? lazyV1(optionsOrLoaders, exports)
|
|
134
|
+
: lazyV2(optionsOrLoaders);
|
|
135
|
+
}
|
|
114
136
|
exports.lazy = lazy;
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export declare function currentTarget(): string;
|
|
2
2
|
export declare function bin(scope: string[], ...rest: string[]): string;
|
|
3
|
+
export type LazyOptions = {
|
|
4
|
+
targets: Record<string, () => any>;
|
|
5
|
+
exports: string[];
|
|
6
|
+
debug?: () => any;
|
|
7
|
+
};
|
|
3
8
|
export declare function lazy(loaders: Record<string, () => any>, exports: string[]): any;
|
|
9
|
+
export declare function lazy(options: LazyOptions): any;
|