esm-sync 3.3.3-beta.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/esm.js ADDED
@@ -0,0 +1,223 @@
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.js ADDED
@@ -0,0 +1,4 @@
1
+ /* eslint strict: off, node/no-unsupported-features: ["error", { version: 6 }] */
2
+ "use strict"
3
+
4
+ module.exports = require("./esm.js")
package/package.json ADDED
@@ -0,0 +1,124 @@
1
+ {
2
+ "name": "esm-sync",
3
+ "version": "3.3.3-beta.0",
4
+ "description": "Tomorrow's ECMAScript modules today!",
5
+ "keywords": [
6
+ "commonjs",
7
+ "ecmascript",
8
+ "export",
9
+ "import",
10
+ "modules",
11
+ "node",
12
+ "require"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/nktnet1/esm-sync"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Khiet Tam Nguyen <tamkhietnguyen1@gmail.com>",
20
+ "main": "esm.js",
21
+ "private": false,
22
+ "runkitExample": "require = require(\"@nktnet1/esm\")(module)\nrequire(\"lodash-es\")",
23
+ "esm": true,
24
+ "engines": {
25
+ "node": ">=6"
26
+ },
27
+ "scripts": {
28
+ "prelint": "npm run pretest",
29
+ "prepare": "npm run build:prod",
30
+ "prepub": "npm run test:prod && npm run build:prod",
31
+ "pretest": "npm run build -- --test",
32
+ "pretest:prod": "npm run build:prod -- --test",
33
+ "build": "node script/build.js",
34
+ "build:prod": "npm run build -- --prod",
35
+ "clean": "node script/clean.js",
36
+ "lint": "eslint '**/*.{js,mjs}' --fix --quiet",
37
+ "pub": "node script/publish.js",
38
+ "test": "node script/test.js",
39
+ "test:prod": "node script/test.js --prod"
40
+ },
41
+ "devDependencies": {
42
+ "@babel/core": "^7.29.0",
43
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
44
+ "@babel/plugin-proposal-optional-catch-binding": "^7.18.6",
45
+ "@babel/plugin-transform-arrow-functions": "^7.27.1",
46
+ "@babel/plugin-transform-block-scoping": "^7.28.6",
47
+ "@babel/plugin-transform-flow-strip-types": "^7.27.1",
48
+ "@babel/plugin-transform-runtime": "^7.29.0",
49
+ "@babel/polyfill": "^7.12.1",
50
+ "@babel/preset-env": "^7.29.2",
51
+ "@babel/register": "^7.28.6",
52
+ "@babel/runtime": "^7.29.2",
53
+ "@hapi/lab": "^24.7.1",
54
+ "@std/esm": "^0.26.0",
55
+ "@types/node": "^14.18.63",
56
+ "acorn": "^8.16.0",
57
+ "ava": "^3.15.0",
58
+ "babel-eslint": "^10.1.0",
59
+ "babel-loader": "^8.4.1",
60
+ "babel-plugin-transform-for-of-as-array": "^1.1.1",
61
+ "babel-plugin-transform-remove-console": "^6.9.4",
62
+ "babel-plugin-transform-remove-debugger": "^6.9.4",
63
+ "bluebird": "^3.7.2",
64
+ "chai": "^4.5.0",
65
+ "core-js": "^2.6.12",
66
+ "download": "^8.0.0",
67
+ "eslint": "^7.32.0",
68
+ "eslint-plugin-babel": "^5.3.1",
69
+ "eslint-plugin-import": "^2.32.0",
70
+ "eslint-plugin-node": "^11.1.0",
71
+ "execa": "^4.1.0",
72
+ "express": "^4.22.1",
73
+ "flow-remove-types": "^2.309.0",
74
+ "fs-extra": "^9.1.0",
75
+ "global-prefix": "^3.0.0",
76
+ "globby": "^11.1.0",
77
+ "golden-fleece": "^1.0.9",
78
+ "hard-rejection": "^2.1.0",
79
+ "html-minifier": "^4.0.0",
80
+ "husky": "^4.3.8",
81
+ "jasmine": "^3.99.0",
82
+ "jest": "^26.6.3",
83
+ "json-6": "^1.1.4",
84
+ "lit-node": "^0.1.1",
85
+ "mocha": "^8.4.0",
86
+ "mock-require": "^3.0.3",
87
+ "mock-stdio": "^1.0.3",
88
+ "module-alias": "^2.3.4",
89
+ "newrelic": "^6.14.0",
90
+ "nop": "^1.0.0",
91
+ "nyc": "^15.1.0",
92
+ "pm2": "^4.5.6",
93
+ "postcss": "^7.0.39",
94
+ "proxyquire": "^2.1.3",
95
+ "require-inject": "^1.4.4",
96
+ "requizzle": "^0.2.4",
97
+ "rewire": "^5.0.0",
98
+ "semver": "^7.7.4",
99
+ "sinon": "^9.2.4",
100
+ "sleep": "^6.3.0",
101
+ "sqreen": "^1.64.2",
102
+ "strip-ansi": "^6.0.1",
103
+ "terser": "^4.8.1",
104
+ "terser-webpack-plugin": "^3.1.0",
105
+ "test262-parser": "^2.2.0",
106
+ "trash": "^6.1.1",
107
+ "ts-node": "^8.10.2",
108
+ "typescript": "^3.9.10",
109
+ "unexpected": "^11.15.1",
110
+ "unused-webpack-plugin": "^2.4.0",
111
+ "webpack": "^4.47.0",
112
+ "webpack-bundle-analyzer": "^3.9.0",
113
+ "webpack-cli": "^3.3.12",
114
+ "yargs": "^15.4.1"
115
+ },
116
+ "files": [
117
+ "index.js",
118
+ "esm.js",
119
+ "esm/loader.js"
120
+ ],
121
+ "dependencies": {
122
+ "punycode": "^2.3.1"
123
+ }
124
+ }