Skip to content

Commit 6e270d4

Browse files
committed
chore: experiment with wasm-fmt/biome
1 parent 0c558ef commit 6e270d4

10 files changed

+110
-60
lines changed

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@types/jsdom": "20.0.1",
7474
"@typescript-eslint/eslint-plugin": "5.55.0",
7575
"@typescript-eslint/parser": "5.55.0",
76+
"@wasm-fmt/biome_fmt": "^0.1.12",
7677
"async": "3.2.4",
7778
"concurrently": "7.0.0",
7879
"decomment": "0.9.5",
@@ -138,11 +139,7 @@
138139
}
139140
},
140141
"lint-staged": {
141-
"{lib,packages}/**/src/**/*.ts": [
142-
"eslint --fix",
143-
"prettier --write"
144-
],
145-
"**/*.{ts,js,md,json}": "prettier --write"
142+
"**/*.{md,json}": "prettier --write"
146143
},
147144
"packageManager": "[email protected]"
148145
}

scripts/biome-test.mjs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import init, { format } from "@wasm-fmt/biome_fmt";
2+
import { promises } from "node:fs";
3+
import path, { join } from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
import walk from "./utils/walk.js";
7+
8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
9+
await init();
10+
11+
const prettifyCode = async (dir) => {
12+
for await (const file of walk(dir, ["node_modules"])) {
13+
if (file.endsWith(".ts") || file.endsWith(".js")) {
14+
if (file.endsWith("ruleset.ts")) {
15+
continue;
16+
}
17+
promises.readFile(file, "utf-8").then((contents) => {
18+
promises.writeFile(
19+
file,
20+
format(contents, file, {
21+
indent_style: "space",
22+
indent_width: 2,
23+
line_width: 120,
24+
line_ending: "lf",
25+
quote_properties: "as-needed",
26+
arrow_parentheses: "always",
27+
semicolons: "always",
28+
bracket_spacing: true,
29+
bracket_same_line: false,
30+
quote_style: "double",
31+
trailing_comma: "all",
32+
}),
33+
"utf-8"
34+
);
35+
});
36+
}
37+
}
38+
};
39+
40+
prettifyCode(join(__dirname, "..", "clients", "client-s3"));

scripts/generate-clients/code-eslint-fix.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
// @ts-check
2-
const { spawnProcess } = require("../utils/spawn-process");
3-
const path = require("path");
4-
51
const eslintFixCode = async () => {
6-
try {
7-
await spawnProcess(path.join(__dirname, "..", "..", "node_modules", ".bin", "esprint"), [
8-
"check",
9-
"--fix",
10-
"--quiet",
11-
]);
12-
} catch (error) {
13-
// esprint throws error as the clients source code does not follow 'prefer-const' rule.
14-
// And esprint does not have a way to override rules written in .eslintrc
15-
// We will still get linted code though.
16-
}
2+
// superceded by biome.
173
};
184

195
module.exports = {

scripts/generate-clients/code-prettify.js

-18
This file was deleted.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import init from "@wasm-fmt/biome_fmt";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
5+
import { runWasmFmtBiome } from "./run-wasm-fmt-biome.mjs";
6+
7+
export const prettifyCode = async (dir) => {
8+
await init();
9+
10+
for (const subdirectory of fs.readdirSync(dir)) {
11+
const targets = [path.join(subdirectory, "typescript-codegen"), path.join(subdirectory, "typescript-ssdk-codegen")];
12+
13+
for (const target of targets) {
14+
if (fs.existsSync(target) && fs.lstatSync(target).isDirectory()) {
15+
runWasmFmtBiome(target);
16+
}
17+
}
18+
}
19+
};

scripts/generate-clients/generic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const { emptyDirSync } = require("fs-extra");
44
const { generateGenericClient } = require("./code-gen");
55
const { copyToClients } = require("./copy-to-clients");
66
const { CODE_GEN_GENERIC_CLIENT_OUTPUT_DIR } = require("./code-gen-dir");
7-
const { prettifyCode } = require("./code-prettify");
87
const { eslintFixCode } = require("./code-eslint-fix");
98

109
const PRIVATE_CLIENTS_DIR = path.normalize(path.join(__dirname, "..", "..", "private"));
1110

1211
// TODO: remove this script when generate-clients code is refactored.
1312
(async () => {
13+
const { prettifyCode } = await import("./code-prettify.mjs");
1414
try {
1515
await generateGenericClient();
1616

scripts/generate-clients/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const {
1212
DEFAULT_CODE_GEN_INPUT_DIR,
1313
TEMP_CODE_GEN_INPUT_DIR,
1414
} = require("./code-gen-dir");
15-
const { prettifyCode } = require("./code-prettify");
1615
const { eslintFixCode } = require("./code-eslint-fix");
1716
const { buildSmithyTypeScript } = require("./build-smithy-typescript");
1817
const { SMITHY_TS_COMMIT } = require("./config");
@@ -75,6 +74,7 @@ const {
7574
.help().argv;
7675

7776
(async () => {
77+
const { prettifyCode } = await import("./code-prettify.mjs");
7878
try {
7979
if (!noSmithyCheckout) {
8080
await buildSmithyTypeScript(repo, commit);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import init, { format } from "@wasm-fmt/biome_fmt";
2+
import { promises } from "node:fs";
3+
4+
import walk from "../utils/walk.js";
5+
6+
await init();
7+
8+
export const runWasmFmtBiome = async (dir) => {
9+
for await (const file of walk(dir)) {
10+
if (file.endsWith(".ts") || file.endsWith(".js")) {
11+
if (file.endsWith("ruleset.ts")) {
12+
continue;
13+
}
14+
promises.readFile(file, "utf-8").then((contents) => {
15+
promises.writeFile(
16+
file,
17+
format(contents, file, {
18+
indent_style: "space",
19+
indent_width: 2,
20+
line_width: 120,
21+
line_ending: "lf",
22+
quote_properties: "as-needed",
23+
arrow_parentheses: "always",
24+
semicolons: "always",
25+
bracket_spacing: true,
26+
bracket_same_line: false,
27+
quote_style: "double",
28+
trailing_comma: "all",
29+
}),
30+
"utf-8"
31+
);
32+
});
33+
}
34+
}
35+
};

scripts/generate-clients/single-service.js

+6-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { normalize, join } = require("path");
33
const { generateClient } = require("./code-gen");
44
const { codeOrdering } = require("./code-ordering");
55
const { copyToClients } = require("./copy-to-clients");
6-
const { spawnProcess } = require("../utils/spawn-process");
76

87
const SDK_CLIENTS_DIR = normalize(join(__dirname, "..", "..", "clients"));
98

@@ -34,28 +33,15 @@ const { solo } = yargs(process.argv.slice(2))
3433
require("../api-examples/get-examples");
3534
require("../api-examples/merge-examples").merge(void 0, solo);
3635

37-
console.log("================ starting eslint ================", "\n", new Date().toString(), solo);
38-
try {
39-
await spawnProcess("npx", ["eslint", "--quiet", "--fix", `${clientFolder}/src/**/*`]);
40-
} catch (ignored) {}
36+
console.log("================ starting wasm-fmt biome ================", "\n", new Date().toString(), solo);
4137

42-
if (solo === "dynamodb") {
43-
try {
44-
await spawnProcess("npx", ["eslint", "--quiet", "--fix", `${libFolder}/src/**/*`]);
45-
} catch (ignored) {}
46-
}
38+
const target = `${clientFolder}/src`;
39+
const { runWasmFmtBiome } = await import("./run-wasm-fmt-biome.mjs");
40+
runWasmFmtBiome(target);
4741

48-
console.log("================ starting prettier ================", "\n", new Date().toString(), solo);
49-
await spawnProcess("npx", [
50-
"prettier",
51-
"--write",
52-
"--loglevel",
53-
"warn",
54-
`${clientFolder}/src/**/*.{md,js,ts,json}`,
55-
]);
56-
await spawnProcess("npx", ["prettier", "--write", "--loglevel", "warn", `${clientFolder}/README.md`]);
5742
if (solo === "dynamodb") {
58-
await spawnProcess("npx", ["prettier", "--write", "--loglevel", "warn", `${libFolder}/src/**/*.{md,js,ts,json}`]);
43+
const target = `${libFolder}/src`;
44+
runWasmFmtBiome(target);
5945
}
6046

6147
const compress = require("../endpoints-ruleset/compress");

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -4016,6 +4016,11 @@
40164016
loupe "^2.3.6"
40174017
pretty-format "^29.5.0"
40184018

4019+
"@wasm-fmt/biome_fmt@^0.1.12":
4020+
version "0.1.12"
4021+
resolved "https://registry.yarnpkg.com/@wasm-fmt/biome_fmt/-/biome_fmt-0.1.12.tgz#11f239b03b19be9a755006c77183722246c8dfbc"
4022+
integrity sha512-2t7UdDh9sQ4JCXLXHfJeeqmeRcijbbgmLQ69sREWuYU7nMp8R/4F9g4bIEvJVvWmA4sNmPRvPJW/i3s5lDS11A==
4023+
40194024
"@webassemblyjs/[email protected]":
40204025
version "1.11.1"
40214026
resolved "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz"

0 commit comments

Comments
 (0)