@sssb/tools 0.0.0 → 0.3.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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/bin/sssb.js +116 -0
  3. package/package.json +89 -5
  4. package/src/app-port.js +77 -0
  5. package/src/app.js +142 -0
  6. package/src/assembly-checks.d.ts +57 -0
  7. package/src/assembly-checks.js +259 -0
  8. package/src/commands/add-app.js +344 -0
  9. package/src/commands/check-demo-size.js +80 -0
  10. package/src/commands/check-doc-paths.js +48 -0
  11. package/src/commands/check-e2e.js +611 -0
  12. package/src/commands/check-fences.js +51 -0
  13. package/src/commands/check-real-env.js +165 -0
  14. package/src/commands/check-tmpdir-leak.js +78 -0
  15. package/src/commands/ci.js +350 -0
  16. package/src/commands/dev-tick.js +25 -0
  17. package/src/commands/doctor-checks.js +1396 -0
  18. package/src/commands/doctor-settings.js +583 -0
  19. package/src/commands/doctor-vitest.js +262 -0
  20. package/src/commands/doctor.js +1033 -0
  21. package/src/commands/e2e-profile.js +94 -0
  22. package/src/commands/guide.js +108 -0
  23. package/src/commands/launch-json.js +55 -0
  24. package/src/commands/pin.js +411 -0
  25. package/src/commands/port.js +22 -0
  26. package/src/commands/remove-items.js +191 -0
  27. package/src/commands/serve-standalone.js +78 -0
  28. package/src/commands/tick.js +27 -0
  29. package/src/doc-paths.d.ts +106 -0
  30. package/src/doc-paths.js +328 -0
  31. package/src/framework-guard.js +35 -0
  32. package/src/kit.d.ts +49 -0
  33. package/src/kit.js +216 -0
  34. package/src/next.d.ts +16 -0
  35. package/src/next.js +55 -0
  36. package/src/ports.d.ts +72 -0
  37. package/src/ports.js +307 -0
  38. package/src/prune-mantine-css.js +171 -0
  39. package/src/remove-items/code.patch +798 -0
  40. package/src/remove-items/database.patch +218 -0
  41. package/src/remove-items/exact-patch.js +122 -0
  42. package/src/testing/tmp-dir-marker.js +9 -0
  43. package/src/testing/tmp-dir-setup.d.ts +2 -0
  44. package/src/testing/tmp-dir-setup.js +9 -0
  45. package/src/testing/tmp-dir.d.ts +20 -0
  46. package/src/testing/tmp-dir.js +174 -0
  47. package/src/tick/dev-tick.js +128 -0
  48. package/src/tick/tick.js +317 -0
  49. package/src/tick/ticker-marker.d.ts +17 -0
  50. package/src/tick/ticker-marker.js +83 -0
  51. package/src/tick/ticker.d.ts +36 -0
  52. package/src/tick/ticker.js +142 -0
  53. package/src/vite.d.ts +38 -0
  54. package/src/vite.js +64 -0
  55. package/src/vitest.d.ts +38 -0
  56. package/src/vitest.js +82 -0
  57. package/tsconfig.base.json +33 -0
  58. package/README.md +0 -3
@@ -0,0 +1,80 @@
1
+ // @ts-check
2
+ // `sssb check-demo-size <bytes>`: guards the file:// single-file demo artifact against silent bloat (vendored
3
+ // libraries, base64 blobs, a seam import that drags a server graph in).
4
+ //
5
+ // THE BUDGET IS THE APP'S OWN NUMBER, the argument of the `check:demo-size` script in its package.json; this
6
+ // command holds none. One shared number sized for the largest app is not a gate for the others, since a small app
7
+ // could double and still pass. The artifact is the app's (`<app>/dist-demo/index.html`), found from the app's
8
+ // directory: the working directory, or `--app <dir>`.
9
+ //
10
+ // To change an app's number, re-set it in that app's package.json and record what changed and why beside it (SSSB's
11
+ // starter keeps a DEMO-SIZE.md for this), in its own commit: what grew, by how much, and how much headroom you left
12
+ // on purpose.
13
+ //
14
+ // WHEN IT GOES RED: find what grew before raising anything. The static demo build prints, per app, how much
15
+ // stylesheet the Mantine pruning removed; the JS is where features land. Build the previous commit in a throwaway
16
+ // worktree and compare `dist-demo/index.html`, or bundle with a recorder plugin that prints each module's
17
+ // `renderedLength`: a dependency that arrived, a seam registry imported into the bundle (37% in one commit once, see
18
+ // SSSB's ADR-0012), a base64 asset, a catalog namespace. Fix an incidental cause; raise the budget only for a
19
+ // feature.
20
+ //
21
+ // WHEN IT WARNS: under 2% headroom the command passes and says so (on CI as a workflow annotation too). That is the
22
+ // cue to look at what grew while it is cheap, not a failure; it exists because "one dependency bump from red" used
23
+ // to be something a person had to notice by measuring.
24
+ import { statSync } from 'node:fs'
25
+ import path from 'node:path'
26
+ import { takeAppDir, UsageError } from '../app.js'
27
+
28
+ /** Headroom, as a fraction of the budget, under which the gate still passes but says so. */
29
+ const THIN_HEADROOM = 0.02
30
+
31
+ const WHEN_RED =
32
+ 'WHEN IT GOES RED: first find what grew: build the previous commit and compare dist-demo/index.html, or bundle with a recorder ' +
33
+ "plugin that prints each module's renderedLength. Fix an incidental cause (a new dependency, a seam registry " +
34
+ 'imported into the bundle, a base64 asset); raise the budget only for a feature.'
35
+
36
+ /** @param {string[]} args */
37
+ export async function run(args) {
38
+ const appDir = takeAppDir(args)
39
+ if (args.length !== 1) {
40
+ throw new UsageError(
41
+ "usage: sssb check-demo-size <bytes>: pass this app's budget, the argument of the `check:demo-size` " +
42
+ 'script in its package.json',
43
+ )
44
+ }
45
+ const budget = Number(args[0])
46
+ if (!Number.isFinite(budget) || budget <= 0) {
47
+ throw new UsageError(
48
+ `sssb check-demo-size: the budget argument must be a positive number of bytes, got ${args[0]}`,
49
+ )
50
+ }
51
+ const file = path.join(appDir, 'dist-demo', 'index.html')
52
+ let size
53
+ try {
54
+ size = statSync(file).size
55
+ } catch {
56
+ throw new UsageError(`sssb check-demo-size: no ${file}: build the static demo first`)
57
+ }
58
+ if (size > budget) {
59
+ console.error(`${file} is ${size} bytes — ${size - budget} over the ${budget} byte budget.`)
60
+ console.error(
61
+ "That number is this app's own: the argument of `check:demo-size` in its package.json. " +
62
+ `${WHEN_RED} If the growth is intentional, raise the budget in its own commit and say what grew ` +
63
+ 'where the app records its budget.',
64
+ )
65
+ return 1
66
+ }
67
+ const headroom = budget - size
68
+ // Rounded DOWN, so a headroom under THIN_HEADROOM never prints as the threshold itself ("2.0%" beside a warning).
69
+ const percent = (Math.floor((headroom * 1000) / budget) / 10).toFixed(1)
70
+ console.log(`${file}: ${size} / ${budget} bytes — OK (${headroom} bytes, ${percent}% headroom)`)
71
+ if (headroom / budget < THIN_HEADROOM) {
72
+ const message =
73
+ `only ${headroom} bytes (${percent}%) of headroom left under the ${budget} byte budget: the next feature ` +
74
+ "may tip it. Look at what grew while that is cheap; raise this app's budget, in its own commit, only for " +
75
+ 'a feature.'
76
+ console.warn(`check-demo-size: ${message}`)
77
+ if (process.env['GITHUB_ACTIONS']) console.log(`::warning title=demo size headroom::${message}`)
78
+ }
79
+ return 0
80
+ }
@@ -0,0 +1,48 @@
1
+ // @ts-check
2
+ // `sssb check-doc-paths`: fails when a doctrine doc cites a path that does not exist. The doc set and the rules are
3
+ // the workspace's own `sssb.docPaths` (ADR-0014 part 3), so an adopter keeps this gate the day packages/kit leaves
4
+ // the tree.
5
+ import path from 'node:path'
6
+ import process from 'node:process'
7
+ import { citedPaths, docFiles, missingIncludes, readDocPathsConfig, resolves } from '../doc-paths.js'
8
+ import { takeOption, UsageError, workspaceRootOf } from '../app.js'
9
+
10
+ /**
11
+ * @param {string[]} args
12
+ * @returns {Promise<number>} 0 when every citation resolves, 1 otherwise
13
+ */
14
+ export async function run(args) {
15
+ const rest = [...args]
16
+ const other = takeOption(rest, '--root')
17
+ if (rest.length > 0)
18
+ throw new UsageError(
19
+ `sssb check-doc-paths: unknown argument ${rest[0]} (usage: check-doc-paths [--root <dir>])`,
20
+ )
21
+ const root = other === undefined ? workspaceRootOf(process.cwd()) : path.resolve(other)
22
+ const config = readDocPathsConfig(root)
23
+
24
+ const files = docFiles(root, config)
25
+ let checked = 0
26
+ let broken = 0
27
+ // A missing include entry or an empty doc set would make the gate pass by checking nothing.
28
+ for (const rel of missingIncludes(root, config)) {
29
+ broken++
30
+ process.stdout.write(`${rel}: in sssb.docPaths.include, but not in the tree\n`)
31
+ }
32
+ if (files.length === 0) {
33
+ broken++
34
+ process.stdout.write('sssb.docPaths.include names no markdown file: the gate would check nothing\n')
35
+ }
36
+ for (const file of files) {
37
+ for (const { path: cited, line } of citedPaths(file, config, root)) {
38
+ checked++
39
+ if (resolves(cited, root, config)) continue
40
+ broken++
41
+ process.stdout.write(`${file}:${line} cites \`${cited}\`\n`)
42
+ }
43
+ }
44
+ process.stdout.write(
45
+ `check-doc-paths: ${files.length} doc(s), ${checked} citation(s) checked, ${broken} broken` + '\n',
46
+ )
47
+ return broken === 0 ? 0 : 1
48
+ }