Skip to content

Commit 6e3f50b

Browse files
committed
Adopt path-class throughout.
1 parent 9026573 commit 6e3f50b

File tree

38 files changed

+270
-210
lines changed

38 files changed

+270
-210
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ test-dist-lib-build-size: build-lib-js
229229

230230
.PHONY: test-dist-sites-twizzle
231231
test-dist-sites-twizzle: playwright-install build-sites
232-
${NODE} ./script/test/dist/sites/alpha.twizzle.net/main.js
232+
${BUN_RUN} ./script/test/dist/sites/alpha.twizzle.net/main.ts
233233

234234
.PHONY: test-dist-bin
235235
test-dist-bin: test-dist-bin-shebang test-dist-bin-npm-exec

bun.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"esbuild": "^0.25.0",
3030
"jszip": "^3.10.1",
3131
"mocha": "^10.7.3",
32+
"path-class": "^0.6.0",
3233
"playwright": "^1.47.2",
3334
"printable-shell-command": "^1.1.3",
3435
"tsup": "^8.3.0",
@@ -830,6 +831,8 @@
830831

831832
"parseurl": ["[email protected]", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="],
832833

834+
"path-class": ["[email protected]", "", { "dependencies": { "@types/node": "^24.7.1", "xdg-basedir": "^5.1.0" } }, "sha512-oActRKhpRcGkJ9lrzrhf+eXV3x19qczBr6gjiAkENY9c28StGJJE71+4CAGEIyRi7N30cM7rWZrZMC/iB2gifg=="],
835+
833836
"path-exists": ["[email protected]", "", {}, "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="],
834837

835838
"path-is-absolute": ["[email protected]", "", {}, "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg=="],
@@ -1060,6 +1063,8 @@
10601063

10611064
"ws": ["[email protected]", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="],
10621065

1066+
"xdg-basedir": ["[email protected]", "", {}, "sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ=="],
1067+
10631068
"y18n": ["[email protected]", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="],
10641069

10651070
"yaml": ["[email protected]", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw=="],
@@ -1126,6 +1131,8 @@
11261131

11271132
"log-symbols/chalk": ["[email protected]", "", { "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" } }, "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA=="],
11281133

1134+
"path-class/@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg=="],
1135+
11291136
"path-scurry/lru-cache": ["[email protected]", "", {}, "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ=="],
11301137

11311138
"proxy-agent/lru-cache": ["[email protected]", "", {}, "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA=="],
@@ -1186,6 +1193,8 @@
11861193

11871194
"log-symbols/chalk/supports-color": ["[email protected]", "", { "dependencies": { "has-flag": "^4.0.0" } }, "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw=="],
11881195

1196+
"path-class/@types/node/undici-types": ["[email protected]", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
1197+
11891198
"raw-body/http-errors/statuses": ["[email protected]", "", {}, "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="],
11901199

11911200
"resolve-path/http-errors/depd": ["[email protected]", "", {}, "sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ=="],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"esbuild": "^0.25.0",
8282
"jszip": "^3.10.1",
8383
"mocha": "^10.7.3",
84+
"path-class": "^0.6.0",
8485
"playwright": "^1.47.2",
8586
"printable-shell-command": "^1.1.3",
8687
"tsup": "^8.3.0",

script/bin/screenshot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import type {
2828
TwistyPlayerConfig,
2929
VisualizationFormat,
3030
} from "../../src/cubing/twisty/index.js";
31-
import { startServer } from "../lib/experiments-server/index.js";
31+
import { startServer } from "../lib/experiments-server";
3232

3333
const DEBUG = false;
3434
const PAGE_URL =

script/build/common/paths.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Path } from "path-class";
2+
3+
export const tempPath = new Path("./.temp");

script/build/lib/build-lib-js.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { mkdir, writeFile } from "node:fs/promises";
21
import { type BuildOptions, build } from "esbuild";
32
import { packageEntryPointsWithSearchWorkerEntry } from "../common/package-info";
3+
import { tempPath } from "../common/paths";
44

55
// In theory we could set `packages: "external"` here and rely on `make
66
// test-src-import-restrictions`, but this is safer.
@@ -24,8 +24,4 @@ export const esmOptions: BuildOptions = {
2424

2525
const result = await build(esmOptions);
2626

27-
await mkdir("./.temp", { recursive: true });
28-
await writeFile(
29-
"./.temp/esbuild-metafile.json",
30-
JSON.stringify(result.metafile),
31-
);
27+
await tempPath.join("esbuild-metafile.json").writeJSON(result.metafile);
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { mkdir, writeFile } from "node:fs/promises";
21
import { join } from "node:path";
2+
import { Path } from "path-class";
33
import { PrintableShellCommand } from "printable-shell-command";
44
import { packageNames } from "../common/package-info";
55

@@ -12,24 +12,21 @@ export const SRC_CUBING = "./src/cubing";
1212
export const TYPESCRIPT_INDEX = "index.ts";
1313
export const TYPESCRIPT_DECLARATION_INDEX = "index.d.ts";
1414

15-
const tsupCommand = new PrintableShellCommand("bun", [
15+
await new PrintableShellCommand("bun", [
1616
["x", "tsup"],
1717
...packageNames.map((packageName) =>
1818
join(SRC_CUBING, packageName, TYPESCRIPT_INDEX),
1919
),
2020
"--dts-only",
2121
["--format", "esm"],
2222
["--out-dir", "dist/lib/cubing"],
23-
]);
24-
await tsupCommand.shellOutBun();
23+
]).shellOutBun();
2524

2625
// TODO: remove this once TypeScript resolves types from the `package.json` exports out of the box (by default).
2726
for (const packageName of packageNames) {
28-
await mkdir(packageName, { recursive: true });
29-
const indexFileName = join(packageName, TYPESCRIPT_DECLARATION_INDEX);
30-
await writeFile(
31-
indexFileName,
32-
`export * from ${JSON.stringify(
27+
await new Path(packageName)
28+
.join(TYPESCRIPT_DECLARATION_INDEX)
29+
.write(`export * from ${JSON.stringify(
3330
join(
3431
"..",
3532
"dist",
@@ -39,7 +36,5 @@ for (const packageName of packageNames) {
3936
TYPESCRIPT_DECLARATION_INDEX,
4037
),
4138
)};
42-
`,
43-
"utf-8",
44-
);
39+
`);
4540
}

script/build/lib/clean-types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { existsSync } from "node:fs";
2-
import { rm, rmdir } from "node:fs/promises";
3-
import { join } from "node:path";
2+
import { rmdir } from "node:fs/promises";
3+
import { Path } from "path-class";
44
import { packageNames } from "../common/package-info";
55

66
export const TYPESCRIPT_DECLARATION_INDEX = "index.d.ts";
77

88
for (const packageName of packageNames) {
9-
const indexFileName = join(packageName, TYPESCRIPT_DECLARATION_INDEX);
10-
await rm(indexFileName, { force: true });
9+
const indexFileName = new Path(packageName).join(
10+
TYPESCRIPT_DECLARATION_INDEX,
11+
);
12+
await indexFileName.rm({ force: true });
1113
if (existsSync(packageName)) {
1214
await rmdir(packageName);
1315
}

script/build/sites/barelyServeSite.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import { exec } from "node:child_process";
2-
import { writeFile } from "node:fs/promises";
32
import { join } from "node:path";
4-
import { fileURLToPath } from "node:url";
53
import { barelyServe } from "barely-a-dev-server";
64
import { $ } from "bun";
75
import type { Plugin } from "esbuild";
6+
import { Path } from "path-class";
87
import { needPath } from "../../lib/needPath";
98

109
needPath(
11-
fileURLToPath(
12-
new URL("../../../node_modules/barely-a-dev-server", import.meta.url),
13-
),
10+
Path.resolve("../../../node_modules/barely-a-dev-server", import.meta.url),
1411
"make setup",
1512
);
1613

@@ -54,7 +51,7 @@ export interface VersionJSON {
5451
commitGitHubURL: string;
5552
}
5653

57-
async function writeVersionJSON(siteFolder: string) {
54+
async function writeVersionJSON(siteFolder: Path) {
5855
// https://git-scm.com/docs/git-describe
5956
const gitDescribeVersion = (
6057
await $`git describe --tags || echo v0.0.0`.text()
@@ -64,27 +61,20 @@ async function writeVersionJSON(siteFolder: string) {
6461
const commitHash = (await $`git rev-parse HEAD`.text()).trim();
6562
const commitGitHubURL = `https://github.com/cubing/cubing.js/commit/${commitHash}`;
6663

67-
await writeFile(
68-
join(siteFolder, "version.json"),
69-
JSON.stringify(
70-
{
71-
gitDescribeVersion,
72-
gitBranch,
73-
date,
74-
commitHash,
75-
commitGitHubURL,
76-
} satisfies VersionJSON,
77-
null,
78-
" ",
79-
),
80-
);
64+
await siteFolder.join("version.json").writeJSON({
65+
gitDescribeVersion,
66+
gitBranch,
67+
date,
68+
commitHash,
69+
commitGitHubURL,
70+
} satisfies VersionJSON);
8171
}
8272

8373
export async function barelyServeSite(srcFolder: string, dev: boolean) {
84-
const outDir = dev ? join(".temp/dev", srcFolder) : join("dist", srcFolder);
74+
const outDir = new Path(dev ? ".temp/dev" : "dist").join(srcFolder);
8575
await barelyServe({
8676
entryRoot: join("src", srcFolder),
87-
outDir,
77+
outDir: outDir.path, // TODO: accept `Path` arg in the `barelyServe(…)` signature?
8878
dev,
8979
devDomain: "cubing.localhost",
9080
port: 3333,
@@ -96,6 +86,6 @@ export async function barelyServeSite(srcFolder: string, dev: boolean) {
9686
});
9787
if (!dev) {
9888
// TODO: Include this in the custom build process.
99-
await writeVersionJSON("dist/sites/alpha.twizzle.net");
89+
await writeVersionJSON(new Path("dist/sites/alpha.twizzle.net"));
10090
}
10191
}

script/deploy/twizzle.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as assert from "node:assert";
2-
import { readFile } from "node:fs/promises";
32
import { $ } from "bun";
3+
import { Path } from "path-class";
44
import { PrintableShellCommand } from "printable-shell-command";
55
import type { VersionJSON } from "../build/sites/barelyServeSite";
66
import { rsync } from "./rsync";
@@ -37,9 +37,9 @@ await new PrintableShellCommand("ssh", [
3737
const response = await fetch("https://alpha.twizzle.net/version.json");
3838
const responseJSON = (await response.json()) as VersionJSON;
3939

40-
const distVersionJSON = JSON.parse(
41-
await readFile("./dist/sites/alpha.twizzle.net/version.json", "utf-8"),
42-
);
40+
const distVersionJSON = await new Path(
41+
"./dist/sites/alpha.twizzle.net/version.json",
42+
).readJSON<VersionJSON>();
4343
assert.equal(
4444
distVersionJSON.gitDescribeVersion,
4545
responseJSON.gitDescribeVersion,

0 commit comments

Comments
 (0)