esm-sync 3.3.7 → 3.4.0-beta.2
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 +1 -2
- package/dist/esm/loader.js +51 -0
- package/dist/esm.d.ts +25 -0
- package/dist/esm.js +2 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +1 -0
- package/dist/native/linux-x64-137.node +0 -0
- package/dist/script/build-sync-await.js +1 -0
- package/native/sync-await.cc +63 -0
- package/package.json +37 -98
- package/esm/loader.js +0 -1
- package/esm.js +0 -223
- package/index.d.ts +0 -27
- package/index.js +0 -4
package/esm.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/* eslint strict: off, node/no-unsupported-features: ["error", { version: 6 }] */
|
|
2
|
-
require("module").Module._extensions[".js"] = function (module, filename) {
|
|
3
|
-
module._compile(require("fs").readFileSync(filename, "utf8"), filename)
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const globalThis = (function () {
|
|
7
|
-
// Reference `this` before `Function()` to prevent CSP errors for unsafe-eval.
|
|
8
|
-
// Fallback to `Function()` when Node is invoked with `--strict`.
|
|
9
|
-
return this ||
|
|
10
|
-
Function("return this")()
|
|
11
|
-
})()
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
apply,
|
|
15
|
-
defineProperty
|
|
16
|
-
} = Reflect
|
|
17
|
-
|
|
18
|
-
const { freeze } = Object
|
|
19
|
-
const { hasOwnProperty } = Object.prototype
|
|
20
|
-
const symbolFor = Symbol.for
|
|
21
|
-
const { type, versions } = process
|
|
22
|
-
|
|
23
|
-
const {
|
|
24
|
-
filename,
|
|
25
|
-
id,
|
|
26
|
-
parent
|
|
27
|
-
} = module
|
|
28
|
-
|
|
29
|
-
const isElectron = has(versions, "electron")
|
|
30
|
-
const isElectronRenderer = isElectron && type === "renderer"
|
|
31
|
-
|
|
32
|
-
let nativeContent = ""
|
|
33
|
-
|
|
34
|
-
if (typeof id === "string" &&
|
|
35
|
-
id.startsWith("internal/")) {
|
|
36
|
-
nativeContent = getNativeSource("internal/esm/loader")
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const Module = require("module")
|
|
40
|
-
const { Script } = require("vm")
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
createCachedData,
|
|
44
|
-
runInNewContext,
|
|
45
|
-
runInThisContext
|
|
46
|
-
} = Script.prototype
|
|
47
|
-
|
|
48
|
-
const { sep } = require("path")
|
|
49
|
-
const { readFileSync } = require("fs")
|
|
50
|
-
|
|
51
|
-
const esmModule = new Module(id)
|
|
52
|
-
|
|
53
|
-
esmModule.filename = filename
|
|
54
|
-
esmModule.parent = parent
|
|
55
|
-
|
|
56
|
-
function getNativeSource(thePath) {
|
|
57
|
-
let result
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
const { internalBinding } = require("internal/bootstrap/loaders")
|
|
61
|
-
const natives = internalBinding("natives")
|
|
62
|
-
|
|
63
|
-
if (has(natives, thePath)) {
|
|
64
|
-
result = natives[thePath]
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {}
|
|
67
|
-
|
|
68
|
-
return typeof result === "string"
|
|
69
|
-
? result
|
|
70
|
-
: ""
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function has(object, name) {
|
|
74
|
-
return object != null &&
|
|
75
|
-
apply(hasOwnProperty, object, [name])
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function loadESM() {
|
|
79
|
-
compiledESM(require, esmModule, shared)
|
|
80
|
-
return esmModule.exports
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function makeRequireFunction(mod, options) {
|
|
84
|
-
return loadESM()(mod, options)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function readFile(filename, options) {
|
|
88
|
-
try {
|
|
89
|
-
return readFileSync(filename, options)
|
|
90
|
-
} catch (e) {}
|
|
91
|
-
|
|
92
|
-
return null
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
let cachedData
|
|
96
|
-
let scriptOptions
|
|
97
|
-
let cachePath = ""
|
|
98
|
-
let content = ""
|
|
99
|
-
|
|
100
|
-
if (nativeContent !== "") {
|
|
101
|
-
content = nativeContent
|
|
102
|
-
|
|
103
|
-
scriptOptions = {
|
|
104
|
-
__proto__: null,
|
|
105
|
-
filename: "esm.js"
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
cachePath = __dirname + sep + "node_modules" + sep + ".cache" + sep + "esm"
|
|
109
|
-
cachedData = readFile(cachePath + sep + ".data.blob")
|
|
110
|
-
content = readFile(__dirname + sep + "esm" + sep + "loader.js", "utf8")
|
|
111
|
-
|
|
112
|
-
if (cachedData === null) {
|
|
113
|
-
cachedData = void 0
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (content === null) {
|
|
117
|
-
content = ""
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
scriptOptions = {
|
|
121
|
-
__proto__: null,
|
|
122
|
-
cachedData,
|
|
123
|
-
filename,
|
|
124
|
-
produceCachedData: typeof createCachedData !== "function"
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const script = new Script(
|
|
129
|
-
"const __global__ = this;" +
|
|
130
|
-
"(function (require, module, __shared__) { " +
|
|
131
|
-
content +
|
|
132
|
-
"\n});",
|
|
133
|
-
scriptOptions
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
let compiledESM
|
|
137
|
-
|
|
138
|
-
if (isElectronRenderer) {
|
|
139
|
-
compiledESM = apply(runInThisContext, script, [{
|
|
140
|
-
__proto__: null,
|
|
141
|
-
filename
|
|
142
|
-
}])
|
|
143
|
-
} else {
|
|
144
|
-
compiledESM = apply(runInNewContext, script, [{
|
|
145
|
-
__proto__: null,
|
|
146
|
-
global: globalThis
|
|
147
|
-
}, {
|
|
148
|
-
__proto__: null,
|
|
149
|
-
filename
|
|
150
|
-
}])
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Declare `shared` before assignment to avoid the TDZ.
|
|
154
|
-
let shared
|
|
155
|
-
|
|
156
|
-
shared = loadESM()
|
|
157
|
-
|
|
158
|
-
if (cachePath !== "") {
|
|
159
|
-
const { dir } = shared.package
|
|
160
|
-
|
|
161
|
-
let cache = dir.get(cachePath)
|
|
162
|
-
|
|
163
|
-
if (cache === void 0) {
|
|
164
|
-
let scriptData = cachedData
|
|
165
|
-
|
|
166
|
-
if (scriptData === void 0) {
|
|
167
|
-
scriptData = null
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
cache = {
|
|
171
|
-
buffer: cachedData,
|
|
172
|
-
compile: new Map([
|
|
173
|
-
["esm", {
|
|
174
|
-
circular: 0,
|
|
175
|
-
code: null,
|
|
176
|
-
codeWithTDZ: null,
|
|
177
|
-
filename: null,
|
|
178
|
-
firstAwaitOutsideFunction: null,
|
|
179
|
-
firstReturnOutsideFunction: null,
|
|
180
|
-
mtime: -1,
|
|
181
|
-
scriptData,
|
|
182
|
-
sourceType: 1,
|
|
183
|
-
transforms: 0,
|
|
184
|
-
yieldIndex: -1
|
|
185
|
-
}]
|
|
186
|
-
]),
|
|
187
|
-
meta: new Map
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
dir.set(cachePath, cache)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const { pendingScripts } = shared
|
|
194
|
-
|
|
195
|
-
let scripts = pendingScripts.get(cachePath)
|
|
196
|
-
|
|
197
|
-
if (scripts === void 0) {
|
|
198
|
-
scripts = new Map
|
|
199
|
-
pendingScripts.set(cachePath, scripts)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
scripts.set("esm", script)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// The legacy symbol used for `esm` export detection.
|
|
206
|
-
defineProperty(makeRequireFunction, shared.symbol.package, {
|
|
207
|
-
__proto__: null,
|
|
208
|
-
value: true
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
defineProperty(makeRequireFunction, shared.customInspectKey, {
|
|
212
|
-
__proto__: null,
|
|
213
|
-
value: () => "esm enabled"
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
defineProperty(makeRequireFunction, symbolFor("esm:package"), {
|
|
217
|
-
__proto__: null,
|
|
218
|
-
value: true
|
|
219
|
-
})
|
|
220
|
-
|
|
221
|
-
freeze(makeRequireFunction)
|
|
222
|
-
|
|
223
|
-
module.exports = makeRequireFunction
|
package/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/// <reference types="node"/>
|
|
2
|
-
|
|
3
|
-
declare namespace Options {
|
|
4
|
-
interface Esm {
|
|
5
|
-
cache: boolean;
|
|
6
|
-
esModule: boolean;
|
|
7
|
-
extensions: boolean;
|
|
8
|
-
mutableNamespace: boolean;
|
|
9
|
-
namedExports: boolean;
|
|
10
|
-
paths: boolean;
|
|
11
|
-
vars: boolean;
|
|
12
|
-
dedefault: boolean;
|
|
13
|
-
topLevelReturn: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface Options {
|
|
17
|
-
cjs: boolean | Partial<Esm>;
|
|
18
|
-
mainFields: string[];
|
|
19
|
-
mode: "auto" | "all" | "strict";
|
|
20
|
-
await: boolean;
|
|
21
|
-
force: boolean;
|
|
22
|
-
wasm: boolean;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare function esm(mod: typeof module, options?: Partial<Options.Options>): typeof require;
|
|
27
|
-
export = esm;
|
package/index.js
DELETED