@cparra/apex-reflection 3.0.0-dev.20260614084225 → 3.1.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/dist/index.mjs +29 -12
- package/dist/node.wasm +0 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { compile } from "./node.mjs";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
// The wasm module is compiled and instantiated once and reused for every
|
|
4
|
+
// reflection. Without this, each call recompiled the ~380 KB module and reran
|
|
5
|
+
// `invokeMain`, which dominated throughput when reflecting many files (e.g. a
|
|
6
|
+
// whole project). Concurrent first-callers share a single instantiation by
|
|
7
|
+
// caching the promise rather than the resolved value; a failed load is not
|
|
8
|
+
// cached so a later call can retry.
|
|
9
|
+
let instancePromise;
|
|
10
|
+
function loadInstance() {
|
|
11
|
+
if (!instancePromise) {
|
|
12
|
+
instancePromise = (async () => {
|
|
13
|
+
const bytes = fs.readFileSync(new URL("./node.wasm", import.meta.url));
|
|
14
|
+
const compiledApp = await compile(bytes);
|
|
15
|
+
const instantiatedApp = await compiledApp.instantiate();
|
|
16
|
+
instantiatedApp.invokeMain();
|
|
17
|
+
return {
|
|
18
|
+
reflect: globalThis.reflect,
|
|
19
|
+
reflectTrigger: globalThis.reflectTrigger,
|
|
20
|
+
};
|
|
21
|
+
})().catch((error) => {
|
|
22
|
+
instancePromise = undefined;
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
15
25
|
}
|
|
26
|
+
return instancePromise;
|
|
27
|
+
}
|
|
28
|
+
async function reflectFor(type, declarationBody) {
|
|
29
|
+
const instance = await loadInstance();
|
|
30
|
+
return type === "reflectType"
|
|
31
|
+
? instance.reflect(declarationBody)
|
|
32
|
+
: instance.reflectTrigger(declarationBody);
|
|
16
33
|
}
|
|
17
34
|
export async function reflect(declarationBody) {
|
|
18
35
|
const result = await reflectFor("reflectType", declarationBody);
|
package/dist/node.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED