bare-module 6.4.0 → 7.0.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/README.md +237 -270
- package/binding.c +623 -333
- package/index.d.ts +156 -63
- package/index.js +87 -1002
- package/lib/errors.js +27 -10
- package/lib/loader.d.ts +56 -0
- package/lib/loader.js +1192 -0
- package/lib/module/addon.js +7 -0
- package/lib/module/binary.js +7 -0
- package/lib/module/builtin.js +19 -0
- package/lib/module/bundle.js +47 -0
- package/lib/module/json.js +19 -0
- package/lib/module/script.js +23 -0
- package/lib/module/source-text.js +13 -0
- package/lib/module/synthetic.js +20 -0
- package/lib/module/text.js +7 -0
- package/lib/module/value.js +27 -0
- package/lib/module.js +392 -0
- package/lib/protocol.d.ts +56 -8
- package/lib/protocol.js +93 -26
- package/lib/source.js +18 -0
- package/lib/url.js +52 -0
- package/package.json +18 -8
- package/prebuilds/android-arm/bare-module.bare +0 -0
- package/prebuilds/android-arm64/bare-module.bare +0 -0
- package/prebuilds/android-ia32/bare-module.bare +0 -0
- package/prebuilds/android-x64/bare-module.bare +0 -0
- package/prebuilds/darwin-arm64/bare-module.bare +0 -0
- package/prebuilds/darwin-x64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64/bare-module.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-module.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-module.bare +0 -0
- package/prebuilds/linux-arm64/bare-module.bare +0 -0
- package/prebuilds/linux-x64/bare-module.bare +0 -0
- package/prebuilds/win32-arm64/bare-module.bare +0 -0
- package/prebuilds/win32-x64/bare-module.bare +0 -0
- package/lib/constants.d.ts +0 -19
- package/lib/constants.js +0 -17
package/lib/errors.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
module.exports = class ModuleError extends Error {
|
|
2
2
|
constructor(msg, fn = ModuleError, code = fn.name) {
|
|
3
3
|
super(`${code}: ${msg}`)
|
|
4
|
+
|
|
4
5
|
this.code = code
|
|
5
6
|
|
|
6
|
-
if (Error.captureStackTrace)
|
|
7
|
-
Error.captureStackTrace(this, fn)
|
|
8
|
-
}
|
|
7
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, fn)
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
get name() {
|
|
@@ -22,8 +21,8 @@ module.exports = class ModuleError extends Error {
|
|
|
22
21
|
return err
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
static
|
|
26
|
-
const err = new ModuleError(msg, ModuleError.
|
|
24
|
+
static ADDON_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
25
|
+
const err = new ModuleError(msg, ModuleError.ADDON_NOT_FOUND)
|
|
27
26
|
|
|
28
27
|
err.specifier = specifier
|
|
29
28
|
err.referrer = referrer
|
|
@@ -32,12 +31,14 @@ module.exports = class ModuleError extends Error {
|
|
|
32
31
|
return err
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
static
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
static ASSET_NOT_FOUND(msg, specifier, referrer = null, candidates = []) {
|
|
35
|
+
const err = new ModuleError(msg, ModuleError.ASSET_NOT_FOUND)
|
|
36
|
+
|
|
37
|
+
err.specifier = specifier
|
|
38
|
+
err.referrer = referrer
|
|
39
|
+
err.candidates = candidates
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
return new ModuleError(msg, ModuleError.INVALID_BUNDLE_EXTENSION)
|
|
41
|
+
return err
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
static INVALID_URL_PATH(msg) {
|
|
@@ -48,7 +49,23 @@ module.exports = class ModuleError extends Error {
|
|
|
48
49
|
return new ModuleError(msg, ModuleError.INVALID_IMPORTS_MAP)
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
static PROTOCOL_INCOMPATIBLE(msg) {
|
|
53
|
+
return new ModuleError(msg, ModuleError.PROTOCOL_INCOMPATIBLE)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static CACHE_INCOMPATIBLE(msg) {
|
|
57
|
+
return new ModuleError(msg, ModuleError.CACHE_INCOMPATIBLE)
|
|
58
|
+
}
|
|
59
|
+
|
|
51
60
|
static TYPE_INCOMPATIBLE(msg) {
|
|
52
61
|
return new ModuleError(msg, ModuleError.TYPE_INCOMPATIBLE)
|
|
53
62
|
}
|
|
63
|
+
|
|
64
|
+
static UNEXPECTED_PROMISE(msg) {
|
|
65
|
+
return new ModuleError(msg, ModuleError.UNEXPECTED_PROMISE)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static UNKNOWN_MODULE_TYPE(msg) {
|
|
69
|
+
return new ModuleError(msg, ModuleError.UNKNOWN_MODULE_TYPE)
|
|
70
|
+
}
|
|
54
71
|
}
|
package/lib/loader.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Buffer from 'bare-buffer'
|
|
2
|
+
import URL from 'bare-url'
|
|
3
|
+
import { Builtins, ImportsMap, ResolutionsMap } from 'bare-module-resolve'
|
|
4
|
+
import { Attributes, Cache, Module } from '..'
|
|
5
|
+
import Protocol from './protocol'
|
|
6
|
+
|
|
7
|
+
interface ModuleLoader {
|
|
8
|
+
/**
|
|
9
|
+
* The cache of loaded modules that the loader was created with, shared with every module of its
|
|
10
|
+
* graph.
|
|
11
|
+
*/
|
|
12
|
+
readonly cache: Cache
|
|
13
|
+
/** The module representing the entry script where the program was launched. */
|
|
14
|
+
readonly main: Module
|
|
15
|
+
/**
|
|
16
|
+
* The `ModuleProtocol` modules are resolved and read through, shared with every module of the
|
|
17
|
+
* loader's graph.
|
|
18
|
+
*/
|
|
19
|
+
readonly protocol: Protocol
|
|
20
|
+
|
|
21
|
+
get(url: URL): Module | null
|
|
22
|
+
|
|
23
|
+
link(entry: URL, source?: Buffer | string | null, opts?: LinkOptions): Promise<Module>
|
|
24
|
+
linkSync(entry: URL, source?: Buffer | string | null, opts?: LinkOptions): Module
|
|
25
|
+
|
|
26
|
+
import(entry: URL, opts?: ImportOptions): Promise<unknown>
|
|
27
|
+
importSync(entry: URL, opts?: ImportOptions): unknown
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare class ModuleLoader {
|
|
31
|
+
constructor(opts?: ModuleLoader.Options)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare namespace ModuleLoader {
|
|
35
|
+
export interface Options {
|
|
36
|
+
builtins?: Builtins
|
|
37
|
+
cache?: Cache
|
|
38
|
+
concurrency?: number
|
|
39
|
+
defaultType?: number
|
|
40
|
+
imports?: ImportsMap
|
|
41
|
+
protocol?: Protocol
|
|
42
|
+
resolutions?: ResolutionsMap
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface LinkOptions {
|
|
46
|
+
/**
|
|
47
|
+
* The import attributes, for example the `{ type: 'json' }` in `import foo from 'foo' with {
|
|
48
|
+
* type: 'json' }`.
|
|
49
|
+
*/
|
|
50
|
+
attributes?: Attributes
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ImportOptions extends LinkOptions {}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export = ModuleLoader
|