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/dist/esm.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Public options accepted by the CommonJS loader factory. */
|
|
2
|
+
interface CommonJsOptions {
|
|
3
|
+
cache: boolean;
|
|
4
|
+
esModule: boolean;
|
|
5
|
+
extensions: boolean;
|
|
6
|
+
mutableNamespace: boolean;
|
|
7
|
+
namedExports: boolean;
|
|
8
|
+
paths: boolean;
|
|
9
|
+
vars: boolean;
|
|
10
|
+
dedefault: boolean;
|
|
11
|
+
topLevelReturn: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface Options {
|
|
14
|
+
cache: boolean | string;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
sourceMap: boolean;
|
|
17
|
+
cjs: boolean | Partial<CommonJsOptions>;
|
|
18
|
+
mainFields: string[];
|
|
19
|
+
mode: "auto" | "all" | "strict";
|
|
20
|
+
await: boolean;
|
|
21
|
+
force: boolean;
|
|
22
|
+
wasm: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare function makeRequireFunction(mod: typeof module, options?: Partial<Options>): NodeJS.Require;
|
|
25
|
+
export = makeRequireFunction;
|
package/dist/esm.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(t){"@babel/helpers - typeof";return e=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},e(t)}function t(t,n){if(e(t)!=`object`||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var i=r.call(t,n||`default`);if(e(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(n===`string`?String:Number)(t)}function n(n){var r=t(n,`string`);return e(r)==`symbol`?r:r+``}function r(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function a(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?i(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}const o=require("module");o.Module._extensions[`.js`]=function(e,t){e._compile(require("fs").readFileSync(t,`utf8`),t)};const s=(function(){return this||Function(`return this`)()})(),{apply:c}=Reflect,l=Reflect.defineProperty,{freeze:u}=Object,{hasOwnProperty:d}=Object.prototype,f=Symbol.for,{type:p,versions:m}=process,{filename:h,id:g,parent:_}=module,v=A(m,`electron`)&&p===`renderer`;let y=``;typeof g==`string`&&g.startsWith(`internal/`)&&(y=k(`internal/esm/loader`));const b=o,{Script:x}=require("vm"),{createCachedData:S,runInNewContext:C,runInThisContext:w}=x.prototype,{resolve:T,sep:E}=require("path"),{readFileSync:D}=require("fs"),O=new b(g);O.filename=h,O.parent=_;function k(e){let t;try{let{internalBinding:n}=require("internal/bootstrap/loaders"),r=n(`natives`);A(r,e)&&(t=r[e])}catch(e){}return typeof t==`string`?t:``}function A(e,t){return e!=null&&c(d,e,[t])}function j(){return V(require,O,H),O.exports}function M(e,t){return j()(e,t)}function N(e,t){try{return t===void 0?D(e):D(e,t)}catch(e){}return null}let P,F,I=``,L=``;if(y!==``)L=y,F={__proto__:null,filename:`esm.js`};else{var R,z;I=T(__dirname,`..`,`node_modules/.cache/esm`),P=(R=N(I+E+`.data.blob`))==null?void 0:R,L=(z=N(__dirname+E+`esm`+E+`loader.js`,`utf8`))==null?``:z,F=a(a({__proto__:null},P===void 0?{}:{cachedData:P}),{},{filename:h,produceCachedData:typeof S!=`function`})}const B=new x(`const __global__ = this;(function (require, module, __shared__) { `+L+`
|
|
2
|
+
});`,F);let V;V=v?c(w,B,[{__proto__:null,filename:h}]):c(C,B,[{__proto__:null,global:s},{__proto__:null,filename:h}]);let H;if(H=j(),I!==``){let{dir:e}=H.package,t=e.get(I);if(t===void 0){var U;let n=(U=P)==null?null:U;t={buffer:P,compile:/* @__PURE__ */ new Map([[`esm`,{circular:0,code:null,codeWithTDZ:null,filename:null,firstAwaitOutsideFunction:null,firstReturnOutsideFunction:null,mtime:-1,scriptData:n,sourceType:1,transforms:0,yieldIndex:-1}]]),meta:/* @__PURE__ */ new Map},e.set(I,t)}let{pendingScripts:n}=H,r=n.get(I);r===void 0&&(r=/* @__PURE__ */ new Map,n.set(I,r)),r.set(`esm`,B)}l(M,H.symbol.package,{__proto__:null,value:!0}),l(M,H.customInspectKey,{__proto__:null,value:()=>`esm enabled`}),l(M,f(`esm:package`),{__proto__:null,value:!0}),u(M),module.exports=M;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Public options accepted by the CommonJS loader factory. */
|
|
2
|
+
interface CommonJsOptions {
|
|
3
|
+
cache: boolean;
|
|
4
|
+
esModule: boolean;
|
|
5
|
+
extensions: boolean;
|
|
6
|
+
mutableNamespace: boolean;
|
|
7
|
+
namedExports: boolean;
|
|
8
|
+
paths: boolean;
|
|
9
|
+
vars: boolean;
|
|
10
|
+
dedefault: boolean;
|
|
11
|
+
topLevelReturn: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface Options {
|
|
14
|
+
cache: boolean | string;
|
|
15
|
+
debug: boolean;
|
|
16
|
+
sourceMap: boolean;
|
|
17
|
+
cjs: boolean | Partial<CommonJsOptions>;
|
|
18
|
+
mainFields: string[];
|
|
19
|
+
mode: "auto" | "all" | "strict";
|
|
20
|
+
await: boolean;
|
|
21
|
+
force: boolean;
|
|
22
|
+
wasm: boolean;
|
|
23
|
+
}
|
|
24
|
+
declare function makeRequireFunction(mod: typeof module, options?: Partial<Options>): NodeJS.Require;
|
|
25
|
+
declare const esm: typeof makeRequireFunction;
|
|
26
|
+
export = esm;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const e=require("./esm.js");module.exports=e;
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("fs");c=s(c);let l=require("path");l=s(l);let u=require("child_process");function d(e={}){if(Number(process.versions.node.split(`.`)[0])<22)return null;let{styleText:t}=require("util"),n=l.default.resolve(__dirname,`../..`),r=`${process.platform}-${process.arch}-${process.versions.modules}.node`,i=l.default.join(n,`dist/native`,r),a=l.default.join(n,`native/sync-await.cc`);c.default.mkdirSync(l.default.dirname(i),{recursive:!0});let o=l.default.dirname(c.default.realpathSync(process.execPath)),s=[process.env.ESM_SYNC_NODE_HEADERS,l.default.resolve(o,`../include/node`),l.default.join(o,`include/node`),`/usr/include/node`,`/usr/local/include/node`].find(e=>{if(!e)return!1;try{return c.default.readFileSync(l.default.join(e,`node_version.h`),`utf8`).includes(`#define NODE_MODULE_VERSION ${process.versions.modules}`)}catch(e){return!1}}),d;if(s){let e=process.platform===`win32`,r=process.env.CXX||(e?`cl.exe`:`c++`),c=e?[`/nologo`,`/LD`,`/EHsc`,`/MD`,`/std:c++20`,`/Zc:__cplusplus`,`/DBUILDING_NODE_EXTENSION`,`/DNODE_GYP_MODULE_NAME=esm_sync_await`,`/I${s}`,`/Fe:${i}`,`/Fo:${l.default.join(n,`dist/native/sync-await.obj`)}`,a,`/link`,`/LIBPATH:${process.env.ESM_SYNC_NODE_LIB||o}`,`node.lib`]:[`-std=c++20`,`-DBUILDING_NODE_EXTENSION`,`-DNODE_GYP_MODULE_NAME=esm_sync_await`,...process.platform===`darwin`?[`-bundle`,`-undefined`,`dynamic_lookup`]:[`-shared`,`-fPIC`],`-I${s}`,`-o`,i,a],f=(0,u.spawnSync)(r,c,{cwd:n,encoding:`utf8`});if(f.status===0)return console.log(`[esm-sync] Native await bridge ${t(`green`,`ready`)}.`),i;d=f.error||Error(f.stderr||f.stdout||`Compiler failed`)}else d=/* @__PURE__ */ Error(`Matching Node headers are missing; set ESM_SYNC_NODE_HEADERS`);if(e.required)throw d;return console.warn(`[esm-sync] Native await bridge ${t(`yellow`,`unavailable`)}; microtask-only loading remains enabled. `+d.message),null}if(require.main===module)try{d({required:process.argv.indexOf(`--required`)!==-1})}catch(e){console.error(e),process.exitCode=1}module.exports=d;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#include <node.h>
|
|
2
|
+
#include <uv.h>
|
|
3
|
+
#include <v8.h>
|
|
4
|
+
|
|
5
|
+
namespace esm_sync {
|
|
6
|
+
|
|
7
|
+
// Each worker has its own loop. Never recursively enter a loop from one of
|
|
8
|
+
// the callbacks dispatched by this bridge (uv_run itself is not reentrant).
|
|
9
|
+
thread_local bool polling = false;
|
|
10
|
+
|
|
11
|
+
void Throw(v8::Isolate* isolate, const char* code, const char* message) {
|
|
12
|
+
auto error = v8::Exception::Error(
|
|
13
|
+
v8::String::NewFromUtf8(isolate, message).ToLocalChecked());
|
|
14
|
+
error.As<v8::Object>()
|
|
15
|
+
->CreateDataProperty(isolate->GetCurrentContext(),
|
|
16
|
+
v8::String::NewFromUtf8Literal(isolate, "code"),
|
|
17
|
+
v8::String::NewFromUtf8(isolate, code).ToLocalChecked())
|
|
18
|
+
.Check();
|
|
19
|
+
isolate->ThrowException(error);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bool CanPoll(v8::Isolate* isolate) {
|
|
23
|
+
return !polling && !v8::MicrotasksScope::IsRunningMicrotasks(isolate) &&
|
|
24
|
+
node::AsyncHooksGetExecutionAsyncId(isolate) == 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
void Check(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
28
|
+
args.GetReturnValue().Set(CanPoll(args.GetIsolate()));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void Alive(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
32
|
+
uv_loop_t* loop = node::GetCurrentEventLoop(args.GetIsolate());
|
|
33
|
+
args.GetReturnValue().Set(loop != nullptr && uv_loop_alive(loop) != 0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void Poll(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
37
|
+
v8::Isolate* isolate = args.GetIsolate();
|
|
38
|
+
uv_loop_t* loop = node::GetCurrentEventLoop(isolate);
|
|
39
|
+
if (!CanPoll(isolate)) {
|
|
40
|
+
Throw(isolate, "ERR_ESM_SYNC_ASYNC_REENTRANT",
|
|
41
|
+
"Cannot poll the event loop from an async callback or microtask");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (loop == nullptr) {
|
|
45
|
+
Throw(isolate, "ERR_ESM_SYNC_ASYNC_PENDING", "No current event loop is available");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
polling = true;
|
|
50
|
+
uv_run(loop, UV_RUN_NOWAIT);
|
|
51
|
+
polling = false;
|
|
52
|
+
// A bounded sleep avoids a busy spin without letting an unrelated handle
|
|
53
|
+
// make UV_RUN_ONCE block beyond the JavaScript evaluator's deadline.
|
|
54
|
+
uv_sleep(1);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
NODE_MODULE_INIT(/* exports, module, context */) {
|
|
58
|
+
NODE_SET_METHOD(exports, "canPoll", Check);
|
|
59
|
+
NODE_SET_METHOD(exports, "alive", Alive);
|
|
60
|
+
NODE_SET_METHOD(exports, "poll", Poll);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
} // namespace esm_sync
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esm-sync",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0-beta.2",
|
|
4
4
|
"description": "Tomorrow's ECMAScript modules today!",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Khiet Tam Nguyen",
|
|
7
|
-
"main": "esm.js",
|
|
8
|
-
"types": "
|
|
9
|
-
"private": false,
|
|
7
|
+
"main": "./dist/esm.js",
|
|
8
|
+
"types": "./dist/esm.d.ts",
|
|
10
9
|
"runkitExample": "require = require(\"esm-sync\")(module)\nrequire(\"lodash-es\")",
|
|
11
|
-
"esm": true,
|
|
12
10
|
"engines": {
|
|
13
11
|
"node": ">=6"
|
|
14
12
|
},
|
|
@@ -26,103 +24,44 @@
|
|
|
26
24
|
"url": "https://github.com/nktnet1/esm-sync"
|
|
27
25
|
},
|
|
28
26
|
"files": [
|
|
29
|
-
"
|
|
30
|
-
"index.d.ts",
|
|
31
|
-
"esm.js",
|
|
32
|
-
"
|
|
27
|
+
"dist/esm.d.ts",
|
|
28
|
+
"dist/index.d.ts",
|
|
29
|
+
"dist/esm.js",
|
|
30
|
+
"dist/index.js",
|
|
31
|
+
"dist/esm/loader.js",
|
|
32
|
+
"dist/native/*.node",
|
|
33
|
+
"dist/script/build-sync-await.js",
|
|
34
|
+
"native/sync-await.cc"
|
|
33
35
|
],
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"punycode": "^2.3.1"
|
|
36
38
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"babel-plugin-transform-remove-console": "^6.9.4",
|
|
61
|
-
"babel-plugin-transform-remove-debugger": "^6.9.4",
|
|
62
|
-
"bluebird": "^3.7.2",
|
|
63
|
-
"chai": "^4.5.0",
|
|
64
|
-
"commander": "^14.0.3",
|
|
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": "^5.1.1",
|
|
72
|
-
"express": "^4.22.1",
|
|
73
|
-
"flow-remove-types": "^2.311.0",
|
|
74
|
-
"fs-extra": "^11.3.4",
|
|
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": "^9.1.7",
|
|
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": "^9.0.1",
|
|
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": "^5.46.2",
|
|
104
|
-
"terser-webpack-plugin": "^5.5.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-cli": "^3.3.12",
|
|
113
|
-
"webpack-bundle-analyzer": "^5.3.0"
|
|
39
|
+
"packageManager": "pnpm@12.15.0",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"types": "./dist/esm.d.ts",
|
|
43
|
+
"default": "./dist/esm.js"
|
|
44
|
+
},
|
|
45
|
+
"./package.json": "./package.json",
|
|
46
|
+
"./esm": {
|
|
47
|
+
"types": "./dist/esm.d.ts",
|
|
48
|
+
"default": "./dist/esm.js"
|
|
49
|
+
},
|
|
50
|
+
"./esm.js": {
|
|
51
|
+
"types": "./dist/esm.d.ts",
|
|
52
|
+
"default": "./dist/esm.js"
|
|
53
|
+
},
|
|
54
|
+
"./index": {
|
|
55
|
+
"types": "./dist/index.d.ts",
|
|
56
|
+
"default": "./dist/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./index.js": {
|
|
59
|
+
"types": "./dist/index.d.ts",
|
|
60
|
+
"default": "./dist/index.js"
|
|
61
|
+
}
|
|
114
62
|
},
|
|
115
63
|
"scripts": {
|
|
116
|
-
"
|
|
117
|
-
"
|
|
118
|
-
"pretest": "pnpm build --test",
|
|
119
|
-
"pretest:prod": "pnpm build:prod --test",
|
|
120
|
-
"build": "node script/build.js",
|
|
121
|
-
"build:prod": "pnpm build --prod",
|
|
122
|
-
"clean": "node script/clean.js",
|
|
123
|
-
"lint": "eslint '**/*.{js,mjs}' --fix --quiet",
|
|
124
|
-
"pub": "node script/publish.js",
|
|
125
|
-
"test": "node script/test.js",
|
|
126
|
-
"test:prod": "node script/test.js --prod"
|
|
64
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
65
|
+
"install": "node -e \"if(require('fs').existsSync('dist/script/build-sync-await.js'))require('./dist/script/build-sync-await.js')()\""
|
|
127
66
|
}
|
|
128
|
-
}
|
|
67
|
+
}
|