@lumjs/compat 1.3.0 → 1.4.0
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/CHANGELOG.md +16 -1
- package/lib/modulebuilder/index.js +414 -0
- package/lib/modulebuilder/into-core.js +34 -0
- package/lib/v4/index.js +10 -15
- package/lib/v4/loadtracker.js +4 -4
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [1.4.0] - 2023-01-06
|
|
10
|
+
### Changed
|
|
11
|
+
- Made the `v4` set not use any `ModuleBuilder` features anymore.
|
|
12
|
+
- Moved `ModuleBuilder` from core into the `modulebuilder` namespace.
|
|
13
|
+
|
|
14
|
+
## [1.3.1] - 2022-10-18
|
|
15
|
+
### Fixed
|
|
16
|
+
- The `v4/loadtracker` was trying to call a function from the old `Lum` global.
|
|
17
|
+
I replaced it with a new `opts.self` constructor parameter that gets assigned to
|
|
18
|
+
the `this.$self` property.
|
|
19
|
+
### Changed
|
|
20
|
+
- Bumped `@lumjs/core` to `1.7.1`
|
|
21
|
+
- Using some of the new `ModuleBuilder` shortcuts.
|
|
22
|
+
|
|
9
23
|
## [1.3.0] - 2022-10-13
|
|
10
24
|
### Changed
|
|
11
25
|
- Bumped `@lumjs/core` to `1.6.1`.
|
|
@@ -34,7 +48,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
34
48
|
### Added
|
|
35
49
|
- Initial release.
|
|
36
50
|
|
|
37
|
-
[Unreleased]: https://github.com/supernovus/lum.compat.js/compare/v1.3.
|
|
51
|
+
[Unreleased]: https://github.com/supernovus/lum.compat.js/compare/v1.3.1...HEAD
|
|
52
|
+
[1.3.1]: https://github.com/supernovus/lum.compat.js/compare/v1.3.0...v1.3.1
|
|
38
53
|
[1.3.0]: https://github.com/supernovus/lum.compat.js/compare/v1.2.0...v1.3.0
|
|
39
54
|
[1.2.0]: https://github.com/supernovus/lum.compat.js/compare/v1.1.0...v1.2.0
|
|
40
55
|
[1.1.0]: https://github.com/supernovus/lum.compat.js/compare/v1.0.0...v1.1.0
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
|
|
2
|
+
const
|
|
3
|
+
{
|
|
4
|
+
S,F,B,
|
|
5
|
+
isObj,needObj,needType,
|
|
6
|
+
def,lazy
|
|
7
|
+
} = require('@lumjs/core/types');
|
|
8
|
+
|
|
9
|
+
const clone = require('@lumjs/core/obj').duplicateOne;
|
|
10
|
+
|
|
11
|
+
// Methods we want to export in the functional API.
|
|
12
|
+
const BUILD_METHODS = ['has', 'can', 'from', 'set'];
|
|
13
|
+
|
|
14
|
+
// Fallback locale
|
|
15
|
+
const DLOC = 'en-US';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A class to make building modules easier.
|
|
19
|
+
*
|
|
20
|
+
* Basically wraps calls to `require()`, `def()`, `lazy()`,
|
|
21
|
+
* and assignments to `module.exports` into a simple set of methods.
|
|
22
|
+
*
|
|
23
|
+
* @exports module:@lumjs/compat/modulebuilder
|
|
24
|
+
*/
|
|
25
|
+
class ModuleBuilder
|
|
26
|
+
{
|
|
27
|
+
/**
|
|
28
|
+
* Build a new ModuleBuilder instance.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} targetModule - The `module` context variable.
|
|
31
|
+
* @param {object} [opts] - Options to change some default settings.
|
|
32
|
+
* @param {boolean} [opts.configurable=false] Default `configurable` value.
|
|
33
|
+
* @param {boolean} [opts.enumerable=true] Default `enumerable` value.
|
|
34
|
+
* @param {boolean} [opts.writable=false] Default `writable` value.
|
|
35
|
+
*
|
|
36
|
+
* @param {number} [opts.nested=NESTED_ERROR] How to handle nested names.
|
|
37
|
+
*
|
|
38
|
+
* If the `name` parameter in either the `has()` or `can()` method is passed
|
|
39
|
+
* as the path to a nested module with one or more `/` characters,
|
|
40
|
+
* this mode will determine how we derive the property name.
|
|
41
|
+
*
|
|
42
|
+
* For each mode, we'll use an example `name` of `./some/nested/path`.
|
|
43
|
+
*
|
|
44
|
+
* - `ModuleBuilder.NESTED_ERROR` `[0]` (default mode)
|
|
45
|
+
* Throw an `Error` saying paths are unhandled.
|
|
46
|
+
* - `ModuleBuilder.NESTED_FIRST` `[1]`
|
|
47
|
+
* Use the first (non-dot) path element, e.g. `some`
|
|
48
|
+
* - `ModuleBuilder.NESTED_LAST` `[2]`
|
|
49
|
+
* Use the last path element, e.g. `path`
|
|
50
|
+
* - `ModuleBuilder.NESTED_CAMEL` `[3]`
|
|
51
|
+
* Convert the name to camelCase, e.g. `someNestedPath`
|
|
52
|
+
*
|
|
53
|
+
* It's always possible to set the `conf.module` parameter manually as well,
|
|
54
|
+
* which avoids the need to generate a separate parameter name.
|
|
55
|
+
*
|
|
56
|
+
* @param {(string|boolean)} [opts.withLocale=false] Use locales?
|
|
57
|
+
*
|
|
58
|
+
* If this is a `string` it's the name of the locale (e.g. `en-US`).
|
|
59
|
+
*
|
|
60
|
+
* If this is `true` we'll use the default locale as determined by
|
|
61
|
+
* [getLocale()]{@link module:@lumjs/core/strings.getLocale}.
|
|
62
|
+
*
|
|
63
|
+
* If this is `false` we won't use locales (unless the `NESTED_CAMEL`
|
|
64
|
+
* mode is in use, in which case we'll use the default locale.)
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
constructor(targetModule, opts={})
|
|
68
|
+
{
|
|
69
|
+
needObj(opts, 'opts was not an object');
|
|
70
|
+
needObj(targetModule, 'targetModule was not an object');
|
|
71
|
+
needObj(targetModule.exports, 'targetModule.exports was not an object');
|
|
72
|
+
needType(F, targetModule.require, 'targetModule.require was not a function');
|
|
73
|
+
|
|
74
|
+
this.module = targetModule;
|
|
75
|
+
|
|
76
|
+
this.configurable = opts.configurable ?? false;
|
|
77
|
+
this.enumerable = opts.enumerable ?? true;
|
|
78
|
+
this.writable = opts.writable ?? false;
|
|
79
|
+
|
|
80
|
+
this.nested = opts.nested ?? ModuleBuilder.NESTED_ERROR;
|
|
81
|
+
|
|
82
|
+
if (opts.withLocale)
|
|
83
|
+
{ // Initialize the strings here.
|
|
84
|
+
this.withLocale(opts.locale);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Get a descriptor for a module export.
|
|
89
|
+
requireDescriptor(name, conf={})
|
|
90
|
+
{
|
|
91
|
+
if (typeof conf === S)
|
|
92
|
+
{ // A quick shortcut for setting module name.
|
|
93
|
+
conf = {module: conf};
|
|
94
|
+
}
|
|
95
|
+
else if (conf === true)
|
|
96
|
+
{ // Use the lowercase name as the module.
|
|
97
|
+
conf = {module: this.$lc(name)};
|
|
98
|
+
}
|
|
99
|
+
else if (typeof conf.getter === F || typeof conf.setter === F)
|
|
100
|
+
{ // It's an accessor-style descriptor already.
|
|
101
|
+
return conf;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let value = conf.value;
|
|
105
|
+
|
|
106
|
+
if (value === undefined)
|
|
107
|
+
{
|
|
108
|
+
if (typeof conf.module === S)
|
|
109
|
+
name = conf.module;
|
|
110
|
+
if (!name.startsWith('./'))
|
|
111
|
+
name = './'+name;
|
|
112
|
+
|
|
113
|
+
value = this.module.require(name);
|
|
114
|
+
|
|
115
|
+
if (value && conf.prop && value[conf.prop] !== undefined)
|
|
116
|
+
{
|
|
117
|
+
value = value[conf.prop];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const configurable = conf.configurable ?? this.configurable;
|
|
122
|
+
const enumerable = conf.enumerable ?? this.enumerable;
|
|
123
|
+
const writable = conf.writable ?? this.writable;
|
|
124
|
+
|
|
125
|
+
return {configurable, enumerable, writable, value};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
$lc(name)
|
|
129
|
+
{
|
|
130
|
+
return name.toLocaleLowerCase(this.locale ?? DLOC);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Normalize a property name.
|
|
134
|
+
$normalizeProperty(name)
|
|
135
|
+
{
|
|
136
|
+
if (name.startsWith('./'))
|
|
137
|
+
{ // Get rid of the prefix.
|
|
138
|
+
name = name.substring(2);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (name.includes('/'))
|
|
142
|
+
{ // Multiple paths found.
|
|
143
|
+
const names = name.split('/');
|
|
144
|
+
if (this.nested === ModuleBuilder.NESTED_FIRST)
|
|
145
|
+
{
|
|
146
|
+
name = names[0];
|
|
147
|
+
}
|
|
148
|
+
else if (this.nested === ModuleBuilder.NESTED_LAST)
|
|
149
|
+
{
|
|
150
|
+
name = names[names.length-1];
|
|
151
|
+
}
|
|
152
|
+
else if (this.nested === ModuleBuilder.NESTED_CAMEL)
|
|
153
|
+
{
|
|
154
|
+
name = this.$normalizeWithCamelCase(names);
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
{
|
|
158
|
+
throw new Error("No valid nested path handling method was set");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return name;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
withLocale(loc)
|
|
166
|
+
{
|
|
167
|
+
if (this.strings === undefined)
|
|
168
|
+
{ // Load the strings library.
|
|
169
|
+
this.strings = require('@lumjs/core/strings');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (this.locale === undefined)
|
|
173
|
+
{ // Set the locale.
|
|
174
|
+
if (typeof loc === S)
|
|
175
|
+
{ // Use an explicitly passed value.
|
|
176
|
+
this.locale = loc;
|
|
177
|
+
}
|
|
178
|
+
else
|
|
179
|
+
{ // Use the default locale.
|
|
180
|
+
this.locale = this.strings.getLocale();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
$normalizeWithCamelCase(names)
|
|
186
|
+
{
|
|
187
|
+
this.withLocale();
|
|
188
|
+
let name = names.shift().toLocaleLowerCase(this.locale);
|
|
189
|
+
for (const path in names)
|
|
190
|
+
{
|
|
191
|
+
name += this.strings.ucfirst(path, true, this.locale);
|
|
192
|
+
}
|
|
193
|
+
return name;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Export a module directly.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} name - The property name to export.
|
|
200
|
+
*
|
|
201
|
+
* @param {(object|string|true)} [conf] Additional export configuration options.
|
|
202
|
+
*
|
|
203
|
+
* If this is a `string` instead of an `object`, it's assumed to be the
|
|
204
|
+
* `conf.module` value.
|
|
205
|
+
*
|
|
206
|
+
* If this is `true` then the `conf` will be set with `module` being the
|
|
207
|
+
* lowercase version of `name`.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} [conf.module=`./${name}`] The module to `require()`.
|
|
210
|
+
* @param {string} [conf.prop] If set, we want an exported property
|
|
211
|
+
* of this name from the loaded module.
|
|
212
|
+
*
|
|
213
|
+
* If not set, the entire loaded module will be our exported value.
|
|
214
|
+
*
|
|
215
|
+
* @param {boolean} [conf.configurable=this.configurable]
|
|
216
|
+
* Descriptor `configurable` value.
|
|
217
|
+
* @param {boolean} [conf.enumerable=this.enumerable]
|
|
218
|
+
* Descriptor `enumerable` value.
|
|
219
|
+
* @param {boolean} [conf.writable=this.writable]
|
|
220
|
+
* Descriptor `writable` value.
|
|
221
|
+
*
|
|
222
|
+
* @param {*} [conf.value] An explicit value to set.
|
|
223
|
+
*
|
|
224
|
+
* This skips the `require()` call entirely.
|
|
225
|
+
*
|
|
226
|
+
* @returns {object} `this`
|
|
227
|
+
*/
|
|
228
|
+
has(name, conf={})
|
|
229
|
+
{
|
|
230
|
+
const pname = this.$normalizeProperty(name);
|
|
231
|
+
const desc = this.requireDescriptor(name, conf);
|
|
232
|
+
def(this.module.exports, pname, desc);
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Export a lazy-loaded module.
|
|
238
|
+
*
|
|
239
|
+
* @param {string} name - The property name to export.
|
|
240
|
+
*
|
|
241
|
+
* @param {object} [conf] Additional export configuration options.
|
|
242
|
+
*
|
|
243
|
+
* In addition to all the options supported by
|
|
244
|
+
* [has()]{@link module:@lumjs/core/modules#has}
|
|
245
|
+
* this also supports one further option.
|
|
246
|
+
*
|
|
247
|
+
* @param {object} [conf.lazy] Advanced options for the `lazy()` call.
|
|
248
|
+
*
|
|
249
|
+
* If not specified, sane defaults will be used, that ensures the
|
|
250
|
+
* `enumerable` descriptor property for the lazy getter is set the
|
|
251
|
+
* same as the final descriptor property once its loaded.
|
|
252
|
+
*
|
|
253
|
+
* @returns {object} `this`
|
|
254
|
+
*/
|
|
255
|
+
can(name, conf={})
|
|
256
|
+
{
|
|
257
|
+
const pname = this.$normalizeProperty(name);
|
|
258
|
+
const enumerable = conf.enumerable ?? this.enumerable;
|
|
259
|
+
const lazyOpts = isObj(conf.lazy) ? conf.lazy : {enumerable};
|
|
260
|
+
const getter = () => this.requireDescriptor(name, conf);
|
|
261
|
+
lazy(this.module.exports, pname, getter, lazyOpts);
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Re-export some exported properties from a module.
|
|
267
|
+
*
|
|
268
|
+
* By default this uses `has()` to define the exports, but that
|
|
269
|
+
* can be changed using special parameter values.
|
|
270
|
+
*
|
|
271
|
+
* @param {string} modname - The module to export the properties from.
|
|
272
|
+
* @param {...any} libs - What we're exporting.
|
|
273
|
+
*
|
|
274
|
+
* If this is a `string` it is the name of an exported property we want to
|
|
275
|
+
* re-export directly.
|
|
276
|
+
*
|
|
277
|
+
* If this is `true`, all subsequent values will be exported using `can()`.
|
|
278
|
+
*
|
|
279
|
+
* If this is `false`, all subsequent values will be exported using `has()`.
|
|
280
|
+
*
|
|
281
|
+
* If this is an `object`, then it's considered the `conf` parameter for
|
|
282
|
+
* the `has()` or `can()` methods. If the `conf` does not have a `module`
|
|
283
|
+
* property, the `modname` will be assigned as the `module` property.
|
|
284
|
+
* You cannot set the `prop` property, as it's overwritten for every
|
|
285
|
+
* exported property.
|
|
286
|
+
*
|
|
287
|
+
* @returns {object} `this`
|
|
288
|
+
*/
|
|
289
|
+
from(modname, ...libs)
|
|
290
|
+
{
|
|
291
|
+
let func = 'has';
|
|
292
|
+
let curConf = {module: modname};
|
|
293
|
+
for (const lib of libs)
|
|
294
|
+
{
|
|
295
|
+
if (isObj(lib))
|
|
296
|
+
{ // Change the current config.
|
|
297
|
+
curConf = clone(lib);
|
|
298
|
+
if (curConf.module === undefined)
|
|
299
|
+
{ // Make sure the module name is assigned.
|
|
300
|
+
curConf.module = modname;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
else if (typeof lib === B)
|
|
304
|
+
{ // Change the function we're calling.
|
|
305
|
+
func = lib ? 'can' : 'has';
|
|
306
|
+
}
|
|
307
|
+
else if (typeof lib === S)
|
|
308
|
+
{
|
|
309
|
+
const conf = clone(curConf);
|
|
310
|
+
conf.prop = lib;
|
|
311
|
+
this[func](lib, conf);
|
|
312
|
+
}
|
|
313
|
+
else
|
|
314
|
+
{
|
|
315
|
+
throw new TypeError("libs must be strings, booleans, or objects");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return this;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Define an exported property in our module.
|
|
323
|
+
*
|
|
324
|
+
* This is literally just a wrapper around the
|
|
325
|
+
* [def()]{@link module:@lumjs/core/types.def} method,
|
|
326
|
+
* that passes `this.module.exports` as the `obj` parameter.
|
|
327
|
+
*
|
|
328
|
+
* @param {*} name - See `def()` for details.
|
|
329
|
+
* @param {*} value - See `def()` for details.
|
|
330
|
+
* @param {*} opts - See `def()` for details.
|
|
331
|
+
* @returns {(object|function)} What is returned may vary:
|
|
332
|
+
*
|
|
333
|
+
* If the `def()` returns a *bound* copy of itself, we'll return that
|
|
334
|
+
* bound function directly.
|
|
335
|
+
*
|
|
336
|
+
* In any other case, we return `this` ModuleBuilder instance.
|
|
337
|
+
*/
|
|
338
|
+
set(name, value, opts)
|
|
339
|
+
{
|
|
340
|
+
const retval = def(this.module.exports, name, value, opts);
|
|
341
|
+
if (typeof retval === F && isObj(retval.$this) && retval.$this.bound === retval)
|
|
342
|
+
{ // A bound copy was returned, we're going to return it directly.
|
|
343
|
+
return retval;
|
|
344
|
+
}
|
|
345
|
+
return this;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Create a functional API for the ModuleBuilder class.
|
|
350
|
+
*
|
|
351
|
+
* Basically makes a new `ModuleBuilder` instance, then creates standalone
|
|
352
|
+
* closure functions that wrap the main instance methods.
|
|
353
|
+
*
|
|
354
|
+
* These functions can be imported into a namespace directly.
|
|
355
|
+
* They each have a special `builder` property which is a reference
|
|
356
|
+
* to the underlying `ModuleBuilder` instance.
|
|
357
|
+
*
|
|
358
|
+
* There's also a `builder` property in the exported function list,
|
|
359
|
+
* as well as a copy of the `def()` method for quick exporting.
|
|
360
|
+
*
|
|
361
|
+
* Example usage:
|
|
362
|
+
*
|
|
363
|
+
* ```js
|
|
364
|
+
* const {has,can,from,set}
|
|
365
|
+
* = require('@lumjs/compat/modulebuilder').ModuleBuilder.build(module);
|
|
366
|
+
*
|
|
367
|
+
* // exports.foo = require('./foo');
|
|
368
|
+
* has('foo');
|
|
369
|
+
*
|
|
370
|
+
* // exports.someNestedPath = require('./some/nested/path');
|
|
371
|
+
* has('./some/nested/path');
|
|
372
|
+
*
|
|
373
|
+
* ```
|
|
374
|
+
*
|
|
375
|
+
* @param {object} targetModule - The `module` for the Builder instance.
|
|
376
|
+
* @param {object} [opts] - Any options for the Builder instance.
|
|
377
|
+
* @returns {object} An object containing the closure functions.
|
|
378
|
+
*/
|
|
379
|
+
static build(targetModule, opts)
|
|
380
|
+
{
|
|
381
|
+
const builder = new this(targetModule, opts);
|
|
382
|
+
const funcs = {builder, def};
|
|
383
|
+
for (const name of BUILD_METHODS)
|
|
384
|
+
{
|
|
385
|
+
const func = function()
|
|
386
|
+
{
|
|
387
|
+
return builder[name](...arguments);
|
|
388
|
+
}
|
|
389
|
+
def(func, 'builder', builder);
|
|
390
|
+
funcs[name] = func;
|
|
391
|
+
}
|
|
392
|
+
return funcs;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* A static alternative to `new ModuleBuilder()`;
|
|
397
|
+
*
|
|
398
|
+
* @param {object} targetModule
|
|
399
|
+
* @param {object} [opts]
|
|
400
|
+
* @returns {object} The new `ModuleBuilder` instance.
|
|
401
|
+
*/
|
|
402
|
+
static new(targetModule, opts)
|
|
403
|
+
{
|
|
404
|
+
return new this(targetModule, opts);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
def(ModuleBuilder, 'NESTED_ERROR', 0)
|
|
410
|
+
def(ModuleBuilder, 'NESTED_FIRST', 1);
|
|
411
|
+
def(ModuleBuilder, 'NESTED_LAST', 2);
|
|
412
|
+
def(ModuleBuilder, 'NESTED_CAMEL', 3);
|
|
413
|
+
|
|
414
|
+
module.exports = ModuleBuilder;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const core = require('@lumjs/core');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A helper for building modules «Lazy»
|
|
5
|
+
*
|
|
6
|
+
* @name module:@lumjs/core.ModuleBuilder
|
|
7
|
+
* @see module:@lumjs/core/modulebuilder
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
core.lazy(core, 'ModuleBuilder', () => require('./index'), E);
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Return a set of functions for building a module.
|
|
14
|
+
*
|
|
15
|
+
* @alias module:@lumjs/core.buildModule
|
|
16
|
+
* @see module:@lumjs/core/modulebuilder.build
|
|
17
|
+
* @deprecated
|
|
18
|
+
*/
|
|
19
|
+
core.buildModule = function(m,o)
|
|
20
|
+
{
|
|
21
|
+
return core.ModuleBuilder.build(m,o);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a new `ModuleBuilder` instance.
|
|
26
|
+
*
|
|
27
|
+
* @alias module:@lumjs/core.newBuilder
|
|
28
|
+
* @see module:@lumjs/core/modulebuilder.new
|
|
29
|
+
* @deprecated
|
|
30
|
+
*/
|
|
31
|
+
core.newBuilder = function(m, o)
|
|
32
|
+
{
|
|
33
|
+
return core.ModuleBuilder.new(m,o);
|
|
34
|
+
}
|
package/lib/v4/index.js
CHANGED
|
@@ -6,53 +6,48 @@
|
|
|
6
6
|
* @module @lumjs/compat/v4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const {
|
|
9
|
+
const {lazy} = require('@lumjs/core/types');
|
|
10
|
+
|
|
11
|
+
const E = lazy.def.e;
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
* @name module:@lumjs/compat/v4.descriptors
|
|
13
15
|
* @see module:@lumjs/compat/v4/descriptors
|
|
14
16
|
*/
|
|
15
|
-
|
|
16
|
-
//exports.descriptors = require('./descriptors');
|
|
17
|
+
lazy(exports, 'descriptors', () => require('./descriptors'), E);
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @name module:@lumjs/compat/v4.DESC
|
|
20
21
|
* @see module:@lumjs/compat/v4/descriptors.DESC
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
-
//exports.DESC = exports.descriptors.DESC;
|
|
23
|
+
lazy(exports, 'DESC', () => exports.descriptors.DESC, E);
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* @name module:@lumjs/compat/v4.prop
|
|
27
27
|
* @see module:@lumjs/compat/v4/prop
|
|
28
28
|
*/
|
|
29
|
-
|
|
30
|
-
//exports.prop = require('./prop');
|
|
29
|
+
lazy(exports, 'prop', () => require('./prop'), E);
|
|
31
30
|
|
|
32
31
|
/**
|
|
33
32
|
* @name module:@lumjs/compat/v4.deprecated
|
|
34
33
|
* @see module:@lumjs/compat/v4/deprecated
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
|
-
//exports.deprecated = require('./deprecated');
|
|
35
|
+
lazy(exports, 'deprecated', () => require('./deprecated'), E);
|
|
38
36
|
|
|
39
37
|
/**
|
|
40
38
|
* @name module:@lumjs/compat/v4.LoadTracker
|
|
41
39
|
* @see module:@lumjs/compat/v4/loadtracker
|
|
42
40
|
*/
|
|
43
|
-
|
|
44
|
-
//exports.LoadTracker = require('./loadtracker');
|
|
41
|
+
lazy(exports, 'LoadTracker', () => require('./loadtracker'), E);
|
|
45
42
|
|
|
46
43
|
/**
|
|
47
44
|
* @name module:@lumjs/compat/v4.Promise
|
|
48
45
|
* @see module:@lumjs/compat/v4/promise
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
//exports.Promise = require('./promise');
|
|
47
|
+
lazy(exports, 'Promise', () => require('./promise'), E);
|
|
52
48
|
|
|
53
49
|
/**
|
|
54
50
|
* @name module:@lumjs/compat/v4.obj
|
|
55
51
|
* @see module:@lumjs/compat/v4/object-helpers
|
|
56
52
|
*/
|
|
57
|
-
|
|
58
|
-
//exports.obj = require('./object-helpers');
|
|
53
|
+
lazy(exports, 'obj', () => require('./object-helpers'), E);
|
package/lib/v4/loadtracker.js
CHANGED
|
@@ -91,7 +91,7 @@ class LoadTracker
|
|
|
91
91
|
def(this, '$check', opts.check ?? false);
|
|
92
92
|
def(this, '$typeOne', opts.type ?? 'item');
|
|
93
93
|
def(this, '$typeAll', opts.types ?? this.$typeOne + 's');
|
|
94
|
-
|
|
94
|
+
def(this, '$self', opts.self);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -325,7 +325,7 @@ class LoadTracker
|
|
|
325
325
|
*
|
|
326
326
|
* The default method names are:
|
|
327
327
|
*
|
|
328
|
-
* `mark` → Call `lt.mark`, returns `
|
|
328
|
+
* `mark` → Call `lt.mark`, returns `this.$self`.
|
|
329
329
|
* `has` → Proxy `lt.is`.
|
|
330
330
|
* `check` → Proxy `lt.checkOne`.
|
|
331
331
|
* `checkAll` → Proxy `lt.checkAll`.
|
|
@@ -368,7 +368,7 @@ class LoadTracker
|
|
|
368
368
|
addfunc(function()
|
|
369
369
|
{
|
|
370
370
|
thisLoad.mark(...arguments);
|
|
371
|
-
return
|
|
371
|
+
return thisLoad.$self;
|
|
372
372
|
});
|
|
373
373
|
}
|
|
374
374
|
|
|
@@ -448,7 +448,7 @@ class LoadTracker
|
|
|
448
448
|
addfunc(function()
|
|
449
449
|
{
|
|
450
450
|
const missing = getname('missing');
|
|
451
|
-
return ns[missing]({fatal: true, ok:
|
|
451
|
+
return ns[missing]({fatal: true, ok: thisLoad.$self}, ...arguments);
|
|
452
452
|
});
|
|
453
453
|
}
|
|
454
454
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumjs/compat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/index.js",
|
|
7
|
+
"./modulebuilder": "./lib/modulebuilder/index.js",
|
|
8
|
+
"./modulebuilder/into-core": "./lib/modulebuilder/into-core.js",
|
|
7
9
|
"./v4-meta": "./lib/v4/index.js",
|
|
8
10
|
"./v4": "./lib/v4/index.js",
|
|
9
11
|
"./v4/meta": "./lib/v4/index.js",
|
|
@@ -16,7 +18,7 @@
|
|
|
16
18
|
"url": "https://github.com/supernovus/lum.compat.js.git"
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|
|
19
|
-
"@lumjs/core": "^1.
|
|
21
|
+
"@lumjs/core": "^1.8.0",
|
|
20
22
|
"semver": "^7.3.7"
|
|
21
23
|
},
|
|
22
24
|
"scripts":
|