Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 97e5fa1

Browse files
Kikobeatsmrbbot
andauthored
avoid await top level (#118)
* avoid await top level * Update packages/jest-environment-miniflare/test/index.spec.ts Co-authored-by: MrBBot <[email protected]> * Update rust.ts * Update index.spec.ts * Update rust.ts Co-authored-by: MrBBot <[email protected]>
1 parent c1a0946 commit 97e5fa1

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

packages/core/src/plugins/rust.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,30 @@ import assert from "assert";
33
import fs from "fs/promises";
44
import path from "path";
55

6-
// 1. Load package.json file generated by wasm-bindgen containing filenames
7-
const pkg: { files: string[] } = JSON.parse(
8-
await fs.readFile(path.join("pkg", "package.json"), "utf8")
9-
);
6+
;(async () => {
7+
// 1. Load package.json file generated by wasm-bindgen containing filenames
8+
const pkg: { files: string[] } = JSON.parse(
9+
await fs.readFile(path.join("pkg", "package.json"), "utf8")
10+
);
1011

11-
// 2. Concatenate wasm-bindgen glue and worker code into worker/generated/script.js
12-
const glueName = pkg.files.find((file) => file.endsWith(".js"));
13-
assert(glueName);
14-
const glueCode = await fs.readFile(path.join("pkg", glueName), "utf8");
15-
const code = await fs.readFile(path.join("worker", "worker.js"), "utf8");
16-
const generatedDir = path.join("worker", "generated");
17-
await fs.mkdir(generatedDir, { recursive: true });
18-
await fs.writeFile(
19-
path.join(generatedDir, "script.js"),
20-
`${glueCode} ${code}`,
21-
"utf8"
22-
);
12+
// 2. Concatenate wasm-bindgen glue and worker code into worker/generated/script.js
13+
const glueName = pkg.files.find((file) => file.endsWith(".js"));
14+
assert(glueName);
15+
const glueCode = await fs.readFile(path.join("pkg", glueName), "utf8");
16+
const code = await fs.readFile(path.join("worker", "worker.js"), "utf8");
17+
const generatedDir = path.join("worker", "generated");
18+
await fs.mkdir(generatedDir, { recursive: true });
19+
await fs.writeFile(
20+
path.join(generatedDir, "script.js"),
21+
`${glueCode} ${code}`,
22+
"utf8"
23+
);
2324

24-
// 3. Copy *_bg.wasm file into worker/generated/script.wasm
25-
const wasmName = pkg.files.find((file) => file.endsWith(".wasm"));
26-
assert(wasmName);
27-
await fs.copyFile(
28-
path.join("pkg", wasmName),
29-
path.join(generatedDir, "script.wasm")
30-
);
25+
// 3. Copy *_bg.wasm file into worker/generated/script.wasm
26+
const wasmName = pkg.files.find((file) => file.endsWith(".wasm"));
27+
assert(wasmName);
28+
await fs.copyFile(
29+
path.join("pkg", wasmName),
30+
path.join(generatedDir, "script.wasm")
31+
);
32+
})();

packages/jest-environment-miniflare/test/index.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ async function findJest() {
2222
return path.resolve(pkgPath, pkg.bin);
2323
}
2424

25-
const jestPath = await findJest();
25+
const jestPathPromise = findJest();
2626

27-
function runJest(
27+
async function runJest(
2828
match: string,
2929
options: MiniflareOptions = {},
3030
cwd = fixturesPath
3131
): Promise<[exitCode: number, output: string]> {
32+
const jestPath = await jestPathPromise;
3233
return new Promise((resolve) => {
3334
const jest = childProcess.spawn(
3435
process.execPath,

0 commit comments

Comments
 (0)