@neon-rs/load 0.0.176 → 0.0.178

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,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__UNSTABLE_proxy = exports.proxy = exports.__UNSTABLE_loader = exports.lazy = exports.bin = exports.currentTarget = void 0;
4
- function currentTarget() {
3
+ exports.__UNSTABLE_proxy = exports.proxy = exports.__UNSTABLE_loader = exports.lazy = exports.bin = exports.currentTarget = exports.currentPlatform = void 0;
4
+ function currentPlatform() {
5
5
  let os = null;
6
6
  switch (process.platform) {
7
7
  case 'android':
@@ -57,6 +57,11 @@ function currentTarget() {
57
57
  }
58
58
  throw new Error(`Neon: unsupported system: ${process.platform}`);
59
59
  }
60
+ exports.currentPlatform = currentPlatform;
61
+ // DEPRECATE(0.1)
62
+ function currentTarget() {
63
+ return currentPlatform();
64
+ }
60
65
  exports.currentTarget = currentTarget;
61
66
  function isGlibc() {
62
67
  // Cast to unknown to work around a bug in the type definition:
@@ -89,25 +94,34 @@ function* interleave(a1, a2) {
89
94
  }
90
95
  }
91
96
  function bin(scope, ...rest) {
92
- return [...interleave(scope, rest)].join("") + "/" + currentTarget();
97
+ return [...interleave(scope, rest)].join("") + "/" + currentPlatform();
93
98
  }
94
99
  exports.bin = bin;
100
+ // DEPRECATE(0.1)
95
101
  function lazyV1(loaders, exports) {
96
102
  return lazyV2({
97
103
  targets: loaders,
98
104
  exports
99
105
  });
100
106
  }
107
+ // DEPRECATE(0.1)
101
108
  function lazyV2(options) {
102
- const loaders = options.targets;
109
+ return lazyV3({
110
+ platforms: options.targets,
111
+ exports: options.exports,
112
+ debug: options.debug
113
+ });
114
+ }
115
+ function lazyV3(options) {
116
+ const loaders = options.platforms;
103
117
  let loaded = null;
104
118
  function load() {
105
119
  if (loaded) {
106
120
  return loaded;
107
121
  }
108
- const target = currentTarget();
109
- if (!loaders.hasOwnProperty(target)) {
110
- throw new Error(`no precompiled module found for ${target}`);
122
+ const platform = currentPlatform();
123
+ if (!loaders.hasOwnProperty(platform)) {
124
+ throw new Error(`no precompiled module found for ${platform}`);
111
125
  }
112
126
  if (options.debug) {
113
127
  try {
@@ -118,7 +132,7 @@ function lazyV2(options) {
118
132
  }
119
133
  }
120
134
  if (!loaded) {
121
- loaded = loaders[target]();
135
+ loaded = loaders[platform]();
122
136
  }
123
137
  return loaded;
124
138
  }
@@ -129,17 +143,19 @@ function lazyV2(options) {
129
143
  return module;
130
144
  }
131
145
  function lazy(optionsOrLoaders, exports) {
132
- return exports
133
- ? lazyV1(optionsOrLoaders, exports)
134
- : lazyV2(optionsOrLoaders);
146
+ return (!exports && !('targets' in optionsOrLoaders))
147
+ ? lazyV3(optionsOrLoaders)
148
+ : !exports
149
+ ? lazyV2(optionsOrLoaders)
150
+ : lazyV1(optionsOrLoaders, exports);
135
151
  }
136
152
  exports.lazy = lazy;
137
153
  function __UNSTABLE_loader(loaders) {
138
- const target = currentTarget();
139
- if (!loaders.hasOwnProperty(target)) {
140
- throw new Error(`no precompiled module found for ${target}`);
154
+ const platform = currentPlatform();
155
+ if (!loaders.hasOwnProperty(platform)) {
156
+ throw new Error(`no precompiled module found for ${platform}`);
141
157
  }
142
- const loader = loaders[target];
158
+ const loader = loaders[platform];
143
159
  let loaded = null;
144
160
  return () => {
145
161
  if (loaded) {
@@ -150,19 +166,25 @@ function __UNSTABLE_loader(loaders) {
150
166
  };
151
167
  }
152
168
  exports.__UNSTABLE_loader = __UNSTABLE_loader;
153
- function isTargetTable(options) {
154
- return !('targets' in options);
169
+ // DEPRECATE(0.1)
170
+ function isDeprecatedProxyOptions(options) {
171
+ return 'targets' in options;
172
+ }
173
+ function isProxyOptions(options) {
174
+ return 'platforms' in options;
155
175
  }
156
176
  function proxy(options) {
157
- if (isTargetTable(options)) {
158
- options = { targets: options };
159
- }
160
- const target = currentTarget();
161
- const loaders = options.targets;
162
- if (!loaders.hasOwnProperty(target)) {
163
- throw new Error(`no precompiled module found for ${target}`);
177
+ const opts = isProxyOptions(options)
178
+ ? options
179
+ : !isDeprecatedProxyOptions(options)
180
+ ? { platforms: options }
181
+ : { platforms: options.targets, debug: options.debug };
182
+ const platform = currentPlatform();
183
+ const loaders = opts.platforms;
184
+ if (!loaders.hasOwnProperty(platform)) {
185
+ throw new Error(`no precompiled module found for ${platform}`);
164
186
  }
165
- const loader = loaders[target];
187
+ const loader = loaders[platform];
166
188
  let loaded = null;
167
189
  function load() {
168
190
  if (!loaded) {
@@ -218,6 +240,7 @@ function proxy(options) {
218
240
  return new Proxy({}, handler);
219
241
  }
220
242
  exports.proxy = proxy;
243
+ // DEPRECATE(0.1)
221
244
  function __UNSTABLE_proxy(options) {
222
245
  return proxy(options);
223
246
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/load",
3
- "version": "0.0.176",
3
+ "version": "0.0.178",
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,18 +1,30 @@
1
+ export declare function currentPlatform(): string;
1
2
  export declare function currentTarget(): string;
2
3
  export declare function bin(scope: string[], ...rest: string[]): string;
3
- export type LazyOptions = {
4
+ type __DEPRECATED_LazyOptions = {
4
5
  targets: Record<string, () => any>;
5
6
  exports: string[];
6
7
  debug?: () => any;
7
8
  };
9
+ export type LazyOptions = {
10
+ platforms: Record<string, () => any>;
11
+ exports: string[];
12
+ debug?: () => any;
13
+ };
8
14
  export declare function lazy(loaders: Record<string, () => any>, exports: string[]): any;
15
+ export declare function lazy(options: __DEPRECATED_LazyOptions): any;
9
16
  export declare function lazy(options: LazyOptions): any;
10
17
  export declare function __UNSTABLE_loader(loaders: Record<string, () => Record<string, any>>): () => Record<string, any>;
11
18
  export type ModuleObject = Record<string, any>;
12
- export type TargetTable = Record<string, () => ModuleObject>;
19
+ export type PlatformTable = Record<string, () => ModuleObject>;
20
+ export type __DEPRECATED_ProxyOptions = {
21
+ targets: PlatformTable;
22
+ debug?: () => ModuleObject;
23
+ };
13
24
  export type ProxyOptions = {
14
- targets: TargetTable;
25
+ platforms: PlatformTable;
15
26
  debug?: () => ModuleObject;
16
27
  };
17
- export declare function proxy(options: TargetTable | ProxyOptions): any;
18
- export declare function __UNSTABLE_proxy(options: TargetTable | ProxyOptions): any;
28
+ export declare function proxy(options: PlatformTable | ProxyOptions | __DEPRECATED_ProxyOptions): any;
29
+ export declare function __UNSTABLE_proxy(options: PlatformTable | ProxyOptions | __DEPRECATED_ProxyOptions): any;
30
+ export {};