@ryuugg/stanza 0.3.2 → 0.4.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.
Files changed (59) hide show
  1. package/README.md +7 -5
  2. package/package.json +19 -11
  3. package/src/launcher +102 -8
  4. package/src/cli.ts +0 -659
  5. package/src/compile/darwin-arm64.ts +0 -3
  6. package/src/compile/darwin-x64.ts +0 -3
  7. package/src/compile/linux-arm64-musl.ts +0 -3
  8. package/src/compile/linux-arm64.ts +0 -3
  9. package/src/compile/linux-x64-musl.ts +0 -3
  10. package/src/compile/linux-x64.ts +0 -3
  11. package/src/compiled.ts +0 -9
  12. package/src/depth.ts +0 -368
  13. package/src/directories.ts +0 -77
  14. package/src/engine/attach.ts +0 -62
  15. package/src/engine/directives.ts +0 -157
  16. package/src/engine/doc.ts +0 -93
  17. package/src/engine/edits.ts +0 -79
  18. package/src/engine/explain.ts +0 -332
  19. package/src/engine/gaps.ts +0 -357
  20. package/src/engine/hunks.ts +0 -319
  21. package/src/engine/index.ts +0 -273
  22. package/src/engine/model.ts +0 -103
  23. package/src/engine/rules.ts +0 -103
  24. package/src/engine/types.ts +0 -38
  25. package/src/files.ts +0 -975
  26. package/src/format.ts +0 -159
  27. package/src/gitignore.ts +0 -280
  28. package/src/hook.ts +0 -365
  29. package/src/languages/index.ts +0 -34
  30. package/src/languages/javascript/ast.ts +0 -261
  31. package/src/languages/javascript/braces.ts +0 -374
  32. package/src/languages/javascript/config/biome.ts +0 -112
  33. package/src/languages/javascript/config/eslint.ts +0 -128
  34. package/src/languages/javascript/config/evaluate.ts +0 -278
  35. package/src/languages/javascript/config/find.ts +0 -105
  36. package/src/languages/javascript/config/glob.ts +0 -149
  37. package/src/languages/javascript/config/index.ts +0 -48
  38. package/src/languages/javascript/config/layers.ts +0 -468
  39. package/src/languages/javascript/config/module.ts +0 -327
  40. package/src/languages/javascript/config/oxlint.ts +0 -170
  41. package/src/languages/javascript/config/width.ts +0 -723
  42. package/src/languages/javascript/deserializers.ts +0 -17
  43. package/src/languages/javascript/embedded.ts +0 -7
  44. package/src/languages/javascript/entry.ts +0 -42
  45. package/src/languages/javascript/facts.ts +0 -294
  46. package/src/languages/javascript/index.ts +0 -20
  47. package/src/languages/javascript/lists.ts +0 -64
  48. package/src/languages/javascript/oracle.ts +0 -191
  49. package/src/languages/javascript/oxc-raw.d.ts +0 -31
  50. package/src/languages/javascript/parse.ts +0 -131
  51. package/src/languages/javascript/raw.ts +0 -95
  52. package/src/languages/javascript/scan.ts +0 -68
  53. package/src/languages/language.ts +0 -109
  54. package/src/native-file.d.ts +0 -4
  55. package/src/pool.ts +0 -312
  56. package/src/start.ts +0 -49
  57. package/src/step.ts +0 -113
  58. package/src/usage.ts +0 -35
  59. package/src/worker.ts +0 -4
package/README.md CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  ## ✨ What is Stanza?
19
19
 
20
- Stanza formats the spacing inside TypeScript and JavaScript function bodies, the one thing other formatters leave alone, so it runs alongside them without fighting. It edits only blank lines and brace tokens, is deterministic and idempotent, and checks seven hundred files in about half a second.
20
+ Stanza formats the spacing inside TypeScript and JavaScript function bodies, the one thing other formatters leave alone, so it runs alongside them without fighting. It edits only blank lines, brace tokens and the line break under a header whose braces it removed, is deterministic and idempotent, and checks seven hundred files in about half a second.
21
21
 
22
22
  The style is mine, hence opinionated. A function body reads as a sequence of steps, one blank line between steps, none inside a step. A fetch and the `if (!response.ok)` that guards it are one step. A ten line query and the `return` after it are two. If that is not how you read code, this tool will annoy you.
23
23
 
@@ -37,15 +37,17 @@ Before and after `stanza --fix`:
37
37
 
38
38
  ## 🚀 Getting Started
39
39
 
40
- Stanza needs Bun 1.4 or later, even when npm installs it.
40
+ Stanza is a native binary for macOS and Linux, shipped on npm.
41
41
 
42
42
  ```bash
43
- bunx @ryuugg/stanza --check src # run once without installing
44
- bun add -g @ryuugg/stanza # put stanza on your PATH
43
+ npx @ryuugg/stanza --check src # run once without installing
44
+ npm i -g @ryuugg/stanza # put stanza on your PATH
45
45
  ```
46
46
 
47
+ With Bun, `bunx @ryuugg/stanza` and `bun add -g @ryuugg/stanza` do the same.
48
+
47
49
  <details>
48
- <summary>Release binaries, for machines without Bun</summary>
50
+ <summary>Release binaries, for machines without Node.js or Bun</summary>
49
51
 
50
52
  Take the binary for your machine from the [latest release](https://github.com/ryuudotgg/stanza/releases/latest), check it against `SHA256SUMS`, and put it on your `PATH`. There is no Windows binary: run the Linux build inside WSL. [Release Binaries](https://stanza.ryuu.gg/guides/release-binaries) walks through the download, the checksum and musl.
51
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryuugg/stanza",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "An opinionated code formatter for TypeScript.",
5
5
  "keywords": [
6
6
  "formatter",
@@ -31,33 +31,41 @@
31
31
  "stanza": "src/launcher"
32
32
  },
33
33
  "files": [
34
- "src"
34
+ "src/launcher"
35
35
  ],
36
36
  "workspaces": [
37
- "docs"
37
+ "docs",
38
+ "npm/*"
38
39
  ],
39
40
  "scripts": {
40
41
  "bench": "bun scripts/bench.ts",
41
- "build": "bun scripts/build.ts",
42
- "check": "oxlint && oxfmt --check",
43
- "check:fix": "oxlint --fix && oxfmt",
44
- "self-check": "bun run src/cli.ts --check src scripts tests/*.ts",
42
+ "check": "oxlint --disable-nested-config && oxfmt --disable-nested-config --check",
43
+ "check:fix": "oxlint --disable-nested-config --fix && oxfmt --disable-nested-config",
44
+ "self-check": "target/release/stanza --check scripts tests/*.ts docs",
45
45
  "tegami": "bun scripts/tegami.ts",
46
46
  "test": "bun test --parallel",
47
47
  "typecheck": "tsc --noEmit"
48
48
  },
49
- "dependencies": {
50
- "oxc-parser": "^0.151.0"
49
+ "optionalDependencies": {
50
+ "@ryuugg/stanza-darwin-arm64": "0.4.0",
51
+ "@ryuugg/stanza-darwin-x64": "0.4.0",
52
+ "@ryuugg/stanza-linux-arm64": "0.4.0",
53
+ "@ryuugg/stanza-linux-arm64-musl": "0.4.0",
54
+ "@ryuugg/stanza-linux-x64": "0.4.0",
55
+ "@ryuugg/stanza-linux-x64-musl": "0.4.0"
51
56
  },
52
57
  "devDependencies": {
58
+ "@biomejs/biome": "2.6.3",
53
59
  "@types/bun": "latest",
54
- "oxfmt": "^0.70.0",
60
+ "oxc-parser": "0.151.0",
61
+ "oxfmt": "0.70.0",
55
62
  "oxlint": "^1.85.0",
63
+ "prettier": "3.9.10",
56
64
  "tegami": "^1.5.0",
57
65
  "typescript": "^7.0.2"
58
66
  },
59
67
  "engines": {
60
- "bun": ">=1.4.0"
68
+ "node": ">=20.10"
61
69
  },
62
70
  "publishConfig": {
63
71
  "access": "public"
package/src/launcher CHANGED
@@ -1,21 +1,115 @@
1
1
  #!/bin/sh
2
2
  ':' /*
3
- # Runs as sh first and as JS under Bun.
3
+ # Runs as sh first and execs the binary where npm, pnpm and Bun install it, so no JavaScript runtime starts.
4
+ self=$0
5
+ while [ -L "$self" ]; do
6
+ link=$(readlink "$self")
7
+ case $link in
8
+ /*) self=$link ;;
9
+ *) self=${self%/*}/$link ;;
10
+ esac
11
+ done
12
+
13
+ case $self in
14
+ *"/"*) package=${self%/*}/.. ;;
15
+ *) package=.. ;;
16
+ esac
17
+
18
+ musl=
19
+ case $(uname -sm 2>/dev/null) in
20
+ "Darwin arm64") platform=darwin-arm64 ;;
21
+ "Darwin x86_64") platform=darwin-x64 ;;
22
+ "Linux aarch64") platform=linux-arm64 musl=/lib/ld-musl-aarch64.so.1 ;;
23
+ "Linux x86_64") platform=linux-x64 musl=/lib/ld-musl-x86_64.so.1 ;;
24
+ *) platform= ;;
25
+ esac
26
+
27
+ if [ -n "$platform" ]; then
28
+ if [ -n "$musl" ] && [ -e "$musl" ]; then
29
+ order="$platform-musl $platform"
30
+ elif [ -n "$musl" ]; then
31
+ order="$platform $platform-musl"
32
+ else
33
+ order=$platform
34
+ fi
35
+
36
+ for scope in "$package/node_modules/@ryuugg" "$package/.."; do
37
+ for candidate in $order; do
38
+ if [ -x "$scope/stanza-$candidate/stanza" ]; then
39
+ exec "$scope/stanza-$candidate/stanza" "$@"
40
+ fi
41
+ done
42
+ done
43
+ fi
44
+
4
45
  if command -v bun >/dev/null 2>&1; then
5
46
  exec bun "$0" "$@"
6
47
  fi
7
48
 
8
- echo 'stanza: needs Bun 1.4 or later (https://bun.sh) or a release binary (https://github.com/ryuudotgg/stanza/releases/latest)' >&2
49
+ if command -v node >/dev/null 2>&1; then
50
+ exec node "$0" "$@"
51
+ fi
52
+
53
+ echo 'stanza: needs Node.js or Bun to start, or a release binary (https://github.com/ryuudotgg/stanza/releases/latest)' >&2
9
54
  [ "$1" = hook ] && exit 1
10
55
  exit 2
11
56
  */
12
57
 
13
- if (!Bun.semver.satisfies(Bun.version, ">=1.4.0")) {
14
- console.error(
15
- `stanza: found Bun ${Bun.version}, needs Bun 1.4 or later (https://bun.sh) or a release binary (https://github.com/ryuudotgg/stanza/releases/latest)`,
58
+ // Parses as CommonJS and as an ES module, since Node picks the format of an extensionless file by version.
59
+ const args = process.argv.slice(2);
60
+ const failure = args[0] === "hook" ? 1 : 2;
61
+ const releases = "https://github.com/ryuudotgg/stanza/releases/latest";
62
+
63
+ function fail(message) {
64
+ process.stderr.write(`stanza: ${message}\n`);
65
+ process.exit(failure);
66
+ }
67
+
68
+ function candidates(fs) {
69
+ const host = `${process.platform}-${process.arch}`;
70
+ if (process.platform !== "linux") return [host];
71
+
72
+ const loader = `/lib/ld-musl-${process.arch === "x64" ? "x86_64" : "aarch64"}.so.1`;
73
+ const musl = fs.existsSync(loader);
74
+ return musl ? [`${host}-musl`, host] : [host, `${host}-musl`];
75
+ }
76
+
77
+ function locate(fs, path, require) {
78
+ const platforms = candidates(fs);
79
+ for (const platform of platforms)
80
+ try {
81
+ const manifest = require.resolve(`@ryuugg/stanza-${platform}/package.json`);
82
+ return path.join(path.dirname(manifest), "stanza");
83
+ } catch {}
84
+
85
+ fail(
86
+ `no binary package for ${platforms[0]}: install @ryuugg/stanza-${platforms[0]}, or download stanza-${platforms[0]} from ${releases}`,
16
87
  );
17
- process.exit(process.argv[2] === "hook" ? 1 : 2);
18
88
  }
19
89
 
20
- const { start } = await import("./start.ts");
21
- process.exitCode = await start(process.argv.slice(2));
90
+ function run(binary, spawn) {
91
+ let child;
92
+ const forward = (signal) => child.kill(signal);
93
+ const signals = ["SIGINT", "SIGHUP", "SIGTERM"];
94
+ for (const signal of signals) process.on(signal, forward);
95
+
96
+ child = spawn(binary, args, { stdio: "inherit" });
97
+
98
+ child.on("error", (error) => fail(`cannot start ${binary}: ${error.message}`));
99
+ child.on("exit", (code, signal) => {
100
+ if (signal === null) process.exit(code ?? failure);
101
+
102
+ for (const name of signals) process.off(name, forward);
103
+ process.kill(process.pid, signal);
104
+ });
105
+ }
106
+
107
+ Promise.all([
108
+ import("node:fs"),
109
+ import("node:path"),
110
+ import("node:module"),
111
+ import("node:child_process"),
112
+ ]).then(([fs, path, { createRequire }, { spawn }]) => {
113
+ const require = createRequire(fs.realpathSync(process.argv[1]));
114
+ run(locate(fs, path, require), spawn);
115
+ });