Skip to content

Commit ff5f6eb

Browse files
committed
Switch built-in module imports to getBuiltinModule(…).
1 parent 9521f7c commit ff5f6eb

File tree

14 files changed

+39
-44
lines changed

14 files changed

+39
-44
lines changed

bun.lockb

1.98 KB
Binary file not shown.

package.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"@types/three": "^0.165.0",
6060
"@types/web-bluetooth": "^0.0.20",
6161
"comlink": "^4.4.1",
62+
"getbuiltinmodule-ponyfill": "^1.0.0",
6263
"random-uint-below": "v3.3.0",
6364
"three": "^0.165.0"
6465
},
@@ -68,7 +69,7 @@
6869
"@types/chai": "^4.3.16",
6970
"@types/dom-speech-recognition": "^0.0.4",
7071
"@types/mocha": "^10.0.7",
71-
"@types/node": "^20.14.9",
72+
"@types/node": "^22.5.1",
7273
"@types/yargs": "^17.0.32",
7374
"@web/dev-server-esbuild": "^1.0.2",
7475
"@web/test-runner": "^0.18.2",
@@ -81,7 +82,7 @@
8182
"playwright": "^1.45.0",
8283
"tsup": "^8.1.0",
8384
"typedoc": "^0.26.2",
84-
"typescript": "^5.5.2",
85+
"typescript": "^5.5.4",
8586
"yargs": "^17.7.2"
8687
},
8788
"minimalDevDependencies": [
@@ -92,14 +93,10 @@
9293
"yargs"
9394
],
9495
"engines": {
95-
"node": ">=19",
96+
"node": ">=20.16.0",
9697
"bun": ">=1.0.30"
9798
},
98-
"files": [
99-
"./dist/bin/",
100-
"./dist/lib/",
101-
"*/index.d.ts"
102-
],
99+
"files": ["./dist/bin/", "./dist/lib/", "*/index.d.ts"],
103100
"scripts": {
104101
"default": "make default",
105102
"build": "make build",

script/test/src/import-restrictions/allowedImports.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,14 @@ export const mainAllowedImports: AllowedImports = {
129129
static: ["three", "src/cubing/vendor/mit/three"],
130130
},
131131
"src/cubing/vendor": {
132-
static: ["src/cubing/alg", "random-uint-below"],
132+
static: [
133+
"src/cubing/alg",
134+
"random-uint-below",
135+
"getbuiltinmodule-ponyfill",
136+
],
133137
},
134138
"src/cubing/vendor/apache/comlink-everywhere": {
135-
static: ["comlink"],
139+
static: ["comlink", "getbuiltinmodule-ponyfill"],
136140
},
137141
"src/cubing/vendor/mit/cs0x7f/cstimer/src/js/scramble/444-solver.ts": {
138142
static: ["src/cubing/search/cubing-private"],
@@ -141,6 +145,9 @@ export const mainAllowedImports: AllowedImports = {
141145
"src/sites": {
142146
static: ["src/cubing", "jszip", "three"],
143147
},
148+
"src/sites/experiments.cubing.net/cubing.js/rust/wasm": {
149+
static: ["getbuiltinmodule-ponyfill"],
150+
},
144151
};
145152

146153
// This is a separate definition because the `spec` files are interleaved with source files, and it's easier to run a separate check for them.
@@ -154,6 +161,7 @@ export const specAllowedImports: AllowedImports = {
154161
"comlink",
155162
"three",
156163
"random-uint-below",
164+
"getbuiltinmodule-ponyfill",
157165
],
158166
},
159167
"src/test/chai-workarounds": {

src/cubing/twisty/heavy-code-imports/dynamic-entries/twisty-dynamic-3d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cube3x3x3, type PuzzleLoader } from "../../../puzzles";
2-
import type { HintFaceletStyle } from "../../model/props/puzzle/display/HintFaceletProp";
32
import type { FaceletScale } from "../../model/props/puzzle/display/FaceletScaleProp";
3+
import type { HintFaceletStyle } from "../../model/props/puzzle/display/HintFaceletProp";
44
import { Cube3D, type Cube3DOptions } from "../../views/3D/puzzles/Cube3D";
55
import { PG3D } from "../../views/3D/puzzles/PG3D";
66

src/cubing/vendor/apache/comlink-everywhere/inside/index.ts

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import { expose as comlinkExpose } from "comlink";
2+
import { getBuiltinModule } from "getbuiltinmodule-ponyfill";
23
import nodeEndpoint from "../node-adapter";
34

45
const useNodeWorkarounds =
56
typeof globalThis.Worker === "undefined" &&
67
typeof (globalThis as any).WorkerNavigator === "undefined";
78

8-
// Mangled so that bundlers don't try to inline the source.
9-
const worker_threads_mangled = "node:w-orker-_threa-ds";
10-
const worker_threads_unmangled = () => worker_threads_mangled.replace(/-/g, "");
11-
129
export async function nodeEndpointPort(): Promise<
1310
Worker & {
1411
nodeWorker?: import("node:worker_threads").Worker;
1512
}
1613
> {
17-
const { parentPort } = await import(
18-
/* @vite-ignore */ worker_threads_unmangled()
19-
).catch();
20-
return nodeEndpoint(parentPort);
14+
const { parentPort } = await getBuiltinModule("node:worker_threads");
15+
return nodeEndpoint(
16+
parentPort as unknown as import("node:worker_threads").Worker,
17+
);
2118
}
2219

2320
export function expose(api: any) {

src/cubing/vendor/apache/comlink-everywhere/outside/index.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1+
import { getBuiltinModule } from "getbuiltinmodule-ponyfill";
12
import nodeEndpoint from "../node-adapter";
23

34
export { wrap } from "comlink";
4-
// Mangled so that bundlers don't try to inline the source.
5-
6-
const worker_threads_mangled = "node:w-orker-_threa-ds";
7-
const worker_threads_unmangled = () => worker_threads_mangled.replace(/-/g, "");
8-
95
const useNodeWorkarounds =
106
typeof globalThis.Worker === "undefined" &&
117
typeof (globalThis as any).WorkerNavigator === "undefined";
@@ -14,9 +10,7 @@ async function nodeWorker(
1410
source: string | URL,
1511
options?: { eval?: boolean },
1612
): Promise<Worker> {
17-
const { Worker: NodeWorker } = await import(
18-
/* @vite-ignore */ worker_threads_unmangled()
19-
);
13+
const { Worker: NodeWorker } = await getBuiltinModule("node:worker_threads");
2014
const worker = new NodeWorker(source, options);
2115
worker.unref();
2216
return nodeEndpoint(worker);

src/cubing/vendor/mpl/twsearch/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import "./chunk-FTOVDLBG.js";
55
import { Alg } from "../../../alg";
66

77
// .temp/rust-wasm/twsearch_wasm.js
8-
var node_fs_promises_mangled = "node:-fs/pr-omises";
9-
var node_fs_promises_unmangled = () => node_fs_promises_mangled.replace(/-/g, "");
8+
import { getBuiltinModule } from "getbuiltinmodule-ponyfill";
109
var wasm;
1110
var cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }) : { decode: () => {
1211
throw Error("TextDecoder not available");
@@ -447,7 +446,7 @@ async function __wbg_init(input) {
447446
if (!(e instanceof TypeError)) {
448447
throw e;
449448
}
450-
input = await (await import(node_fs_promises_unmangled())).readFile(input);
449+
input = await (await getBuiltinModule("node:fs/promises")).readFile(input);
451450
}
452451
}
453452
__wbg_init_memory(imports);
@@ -460,7 +459,7 @@ var twsearch_wasm_default = __wbg_init;
460459
var cachedInitWrapper;
461460
async function initWrapper() {
462461
await (cachedInitWrapper ??= (async () => {
463-
const wasmUint8Array = (await import("./twsearch_wasm_bg-V4F3SIUO.js")).default;
462+
const wasmUint8Array = (await import("./twsearch_wasm_bg-AVUYD5YC.js")).default;
464463
await twsearch_wasm_default(wasmUint8Array.buffer);
465464
})());
466465
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:bf3a839ad170d3f700deef548daedb055fd3dab7ec4f42e18b5f819576257d96
3+
size 412751

src/cubing/vendor/mpl/twsearch/twsearch_wasm_bg-V4F3SIUO.js

-3
This file was deleted.

src/sites/experiments.cubing.net/cubing.js/rust/wasm/cubing_rust_wasm.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
1616

1717
export interface InitOutput {
1818
readonly memory: WebAssembly.Memory;
19+
readonly internal_init: () => void;
1920
readonly invert_alg: (a: number, b: number, c: number) => void;
2021
readonly greet: () => void;
21-
readonly internal_init: () => void;
2222
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
2323
readonly __wbindgen_malloc: (a: number) => number;
2424
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;

src/sites/experiments.cubing.net/cubing.js/rust/wasm/cubing_rust_wasm.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Mangled so that bundlers don't try to inline the source.
2-
const node_fs_promises_mangled = "node:-fs/pr-omises";
3-
const node_fs_promises_unmangled = () => node_fs_promises_mangled.replace(/-/g, "");
1+
import { getBuiltinModule } from "getbuiltinmodule-ponyfill";
42

53
let wasm;
64

@@ -258,7 +256,7 @@ async function init(input) {
258256
if (!(e instanceof TypeError)) {
259257
throw e;
260258
}
261-
input = await (await import(node_fs_promises_unmangled())).readFile(input);
259+
input = await getBuiltinModule("node:fs/promises").readFile(input);
262260
}
263261
}
264262

@@ -269,5 +267,5 @@ async function init(input) {
269267
return finalizeInit(instance, module);
270268
}
271269

272-
export { initSync }
270+
export { initSync };
273271
export default init;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:2bcf527d52f4cc0553fc0d705e013aa93a047c69cbde7e4d3f685b06c9605e6e
3-
size 58569
2+
oid sha256:377c485a7cbaf5e3b2cd3315a697ee54c621c71ed089841074f23a3121468ebe
3+
size 53619

src/sites/experiments.cubing.net/cubing.js/rust/wasm/cubing_rust_wasm_bg.wasm.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* tslint:disable */
22
/* eslint-disable */
33
declare const memory: WebAssembly.Memory;
4+
declare function internal_init(): void;
45
declare function invert_alg(a: number, b: number, c: number): void;
56
declare function greet(): void;
6-
declare function internal_init(): void;
77
declare function __wbindgen_add_to_stack_pointer(a: number): number;
88
declare function __wbindgen_malloc(a: number): number;
99
declare function __wbindgen_realloc(a: number, b: number, c: number): number;

src/sites/experiments.cubing.net/cubing.js/rust/wasm/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
<!-- From: https://github.com/lgarron/minimal-html-style (v1.0.0) -->
88
<meta name="viewport" content="width=device-width, initial-scale=0.75">
99
<link rel="stylesheet" href="./index.css">
10+
<script type="importmap">
11+
{ "imports": { "cubing/alg": "https://cdn.cubing.net/js/cubing/alg" } }
12+
</script>
1013
<script src="./index.js" type="module"></script>
1114
</head>
1215

1316
<body>
1417
<textarea class="input" placeholder="Enter an alg" spellcheck="false"></textarea>
1518
<br>
1619
<button id="use-wr">Use the WR</button>
17-
<button id="use-40x40x40x40-solution">Use a huge alg</button>
1820

1921
<fieldset id="rust">
2022
<legend>Rust<span class="duration"></span></legend>

0 commit comments

Comments
 (0)