@integr8-media/config 1.0.0 → 1.2.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.
package/README.md CHANGED
@@ -29,9 +29,17 @@ npm install --save-dev typescript @biomejs/biome vitest @vitest/coverage-v8 tsdo
29
29
 
30
30
  ```jsonc
31
31
  // tsconfig.json
32
- { "extends": "@integr8-media/config/tsconfig/react-library.json", "include": ["src"] }
32
+ {
33
+ "extends": "@integr8-media/config/tsconfig/react-library.json",
34
+ "include": ["src"],
35
+ "exclude": ["**/*.config.ts", "playground/dist"]
36
+ }
33
37
  ```
34
38
 
39
+ `include` and `exclude` always go in the repo's own `tsconfig.json`. A preset can't carry them,
40
+ because TypeScript resolves those paths relative to the preset file, which sits inside
41
+ `node_modules`.
42
+
35
43
  | Preset | Use for |
36
44
  | --- | --- |
37
45
  | `@integr8-media/config/tsconfig/library.json` | Node or universal library: NodeNext, declarations, isolatedDeclarations |
@@ -63,10 +71,23 @@ Notes:
63
71
  - Linter: recommended rules, plus as errors: no default exports (allowed in `*.config.ts`),
64
72
  camelCase or PascalCase file names, no explicit `any`, `import type` for type-only imports,
65
73
  no non-null assertions. `console` is a warning.
66
- - Ignores `dist/`, `coverage/`, `playground/dist/` and Markdown files (Biome 2.6 formats
67
- Markdown, which would rewrite docs such as `docs/SPEC.md`). Needs Biome 2.6 or newer.
74
+ - Ignores `dist/`, `coverage/`, `playground/dist/`, `docs/api/` (TypeDoc output),
75
+ `test-results/` and `playwright-report/` (Playwright output), `.vscode/` and Markdown files
76
+ (Biome 2.6 formats Markdown, which would rewrite docs such as `docs/SPEC.md`). Needs Biome
77
+ 2.6 or newer.
78
+ - `vcs` is on (`clientKind: "git"`, `useIgnoreFile: true`), so Biome also skips everything in
79
+ `.gitignore`. Biome fails if there is no `.gitignore` in the folder where it runs, so every
80
+ repo needs one (any git repo has one already).
81
+ - The CSS parser accepts Tailwind v4 directives (`@theme`, `@apply`, `@source`...). Repos
82
+ without Tailwind are not affected.
83
+ - Overrides that turn rules off:
84
+ - `*.config.{ts,mts,js,mjs}`: `style.noDefaultExport`.
85
+ - `.size-limit.{js,mjs,ts}`: `style.noDefaultExport` and `style.useFilenamingConvention`
86
+ (size-limit needs a default export, and the file name starts with a dot).
87
+ - `playground/config.{js,mjs,ts}`: `style.noDefaultExport` (the Ladle config).
88
+ - `scripts/**`: `suspicious.noConsole` (build scripts print progress).
68
89
  - If your `biome.json` sets `files.includes`, Biome adds it to the preset's list, so list only
69
- your extra ignores (for example `"!!.vscode"`) and don't repeat `"**"`.
90
+ your extra ignores (for example `"!!.idea"`) and don't repeat `"**"`.
70
91
 
71
92
  ### Vitest
72
93
 
@@ -74,12 +95,39 @@ Notes:
74
95
  // vitest.config.ts
75
96
  import { integr8Vitest } from '@integr8-media/config/vitest';
76
97
 
77
- export default integr8Vitest({ environment: 'node', coverageThreshold: 80 });
98
+ export default integr8Vitest({
99
+ environment: 'node',
100
+ coverageThreshold: 80,
101
+ setupFiles: './test/setup.ts', // optional: string or list of strings
102
+ });
78
103
  ```
79
104
 
80
105
  v8 coverage on `src/**` (tests, `src/index.ts` and `playground/` excluded). The run fails when
81
- line coverage is below the threshold. `environment: 'jsdom'` needs `jsdom` installed. To add
82
- your own settings, wrap it with `mergeConfig` from `vitest/config`.
106
+ line coverage is below the threshold. `environment: 'jsdom'` needs `jsdom` installed.
107
+
108
+ - `setupFiles` goes to `test.setupFiles` (for example a Testing Library setup file). It takes a
109
+ non-empty string or a non-empty list of non-empty strings; anything else throws
110
+ `ConfigError` with `INVALID_OPTION`.
111
+ - Test collection excludes Vitest's defaults plus `playground/**`, so Playwright specs such as
112
+ `playground/smoke.spec.ts` are not run by `vitest run`.
113
+
114
+ For settings the preset doesn't have, wrap it with `mergeConfig` from `vitest/config`:
115
+
116
+ ```ts
117
+ // vitest.config.ts
118
+ import { integr8Vitest } from '@integr8-media/config/vitest';
119
+ import { defineConfig, mergeConfig } from 'vitest/config';
120
+
121
+ export default mergeConfig(
122
+ integr8Vitest({ environment: 'jsdom', setupFiles: './test/setup.ts' }),
123
+ defineConfig({
124
+ test: {
125
+ // Process CSS files that tests import with ?raw.
126
+ css: { include: [/\.css$/] },
127
+ },
128
+ }),
129
+ );
130
+ ```
83
131
 
84
132
  ### tsdown
85
133
 
@@ -100,15 +148,34 @@ dependencies stay external. Files are always named `.mjs` / `.d.mts`, so point `
100
148
  }
101
149
  ```
102
150
 
103
- ### size-limit
151
+ Option `unbundle?: boolean` (default `false`): with `true`, every source file is built as its own
152
+ output file instead of one bundle. Use it for React libraries whose files start with
153
+ `'use client'`. Each file keeps its own directive, so a Next.js server component can import the
154
+ non-client exports from the same package. Rolldown warns `MODULE_LEVEL_DIRECTIVE` for every such
155
+ file; with `unbundle: true` the preset hides that warning, because the directive is kept. With
156
+ `false` the warning stays, because it is real there. A value that is not a boolean throws
157
+ `ConfigError` with `INVALID_OPTION`.
104
158
 
105
159
  ```ts
106
- // .size-limit.ts
160
+ export default integr8Tsdown({
161
+ entry: ['src/index.ts', 'src/Button.tsx'],
162
+ platform: 'browser',
163
+ unbundle: true,
164
+ });
165
+ ```
166
+
167
+ ### size-limit
168
+
169
+ ```js
170
+ // .size-limit.mjs
107
171
  import { integr8SizeLimit } from '@integr8-media/config/size-limit';
108
172
 
109
173
  export default integr8SizeLimit([{ path: 'dist/index.mjs', limit: '10 kB' }]);
110
174
  ```
111
175
 
176
+ Use `.size-limit.mjs`: it loads without a TypeScript loader, and the Biome preset has an override
177
+ for it (a default export and a dotted file name).
178
+
112
179
  Each entry takes `path`, `limit`, and optionally `name` and `import`. size-limit needs a
113
180
  plugin: `@size-limit/file` measures built files; `@size-limit/esbuild` is needed for `import`.
114
181
 
@@ -121,8 +188,22 @@ extends:
121
188
  ```
122
189
 
123
190
  - pre-commit: `biome check --write` on staged files, fixes re-staged.
124
- - pre-push, in order, stopping at the first failure: `typecheck`, `test:coverage`, `build`, and
125
- `playground:smoke` when that script exists.
191
+ - pre-push, in order, stopping at the first failure: `typecheck`, `test:coverage`, `build`.
192
+
193
+ `playground:smoke` is not in the base: it builds the whole playground and runs Playwright, which
194
+ is too slow for every push. A repo that wants it adds it back in its own `lefthook.yml`; the
195
+ base's `piped: true` then runs it last:
196
+
197
+ ```yaml
198
+ # lefthook.yml
199
+ extends:
200
+ - node_modules/@integr8-media/config/lefthook/base.yml
201
+ pre-push:
202
+ commands:
203
+ playground-smoke:
204
+ priority: 4
205
+ run: npm run playground:smoke
206
+ ```
126
207
 
127
208
  Add `"prepare": "lefthook install"` to your scripts so hooks are installed after `npm install`.
128
209
 
@@ -136,8 +217,9 @@ Add `"prepare": "lefthook install"` to your scripts so hooks are installed after
136
217
  "test": "vitest run",
137
218
  "test:coverage": "vitest run --coverage",
138
219
  "build": "tsdown",
139
- "playground": "ladle serve",
140
- "playground:smoke": "playwright test",
220
+ "playground": "ladle serve --config playground",
221
+ "playground:build": "ladle build --config playground --outDir playground/dist",
222
+ "playground:smoke": "npm run playground:build && playwright test",
141
223
  "size": "size-limit",
142
224
  "check:exports": "publint && attw --pack --profile esm-only"
143
225
  }
@@ -146,9 +228,14 @@ Add `"prepare": "lefthook install"` to your scripts so hooks are installed after
146
228
  `--profile esm-only` tells attw not to report the CommonJS problems that every ESM-only package
147
229
  has.
148
230
 
231
+ A package that exports CSS files must exclude them from attw, which only knows JavaScript and
232
+ types: `attw --pack --profile esm-only --exclude-entrypoints ./styles.css`.
233
+
149
234
  ### GitHub Actions
150
235
 
151
- The workflows live in this GitHub repo, not in the npm package. Because the repo is private, its
236
+ The workflows live in this GitHub repo, not in the npm package. Until a `v1` tag exists, point
237
+ callers at `@main` (`.../pr-checks.yml@main`); once it exists, switch them to `@v1`. The examples
238
+ below show `@v1`. Because the repo is private, its
152
239
  **Settings → Actions → General → Access** must allow access from your other repositories.
153
240
 
154
241
  ```yaml
@@ -168,13 +255,14 @@ jobs:
168
255
  on:
169
256
  push:
170
257
  tags: ["v*.*.*"]
258
+ permissions:
259
+ contents: read
260
+ id-token: write # npm Trusted Publishing
171
261
  jobs:
172
262
  publish:
173
263
  uses: <owner>/integr8-config/.github/workflows/publish.yml@v1
174
264
  with:
175
- provenance: false # true only for public repos (then also grant id-token: write)
176
- secrets:
177
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
265
+ provenance: false # true only for public repos
178
266
  ```
179
267
 
180
268
  - `pr-checks.yml`: install, lint, typecheck, test:coverage, build, size, check:exports.
@@ -182,6 +270,178 @@ jobs:
182
270
  - `publish.yml`: checks the tag is `vX.Y.Z`, is on main and matches `package.json`; then
183
271
  install, build, test and `npm publish --access public`.
184
272
 
273
+ #### Publishing with npm Trusted Publishing
274
+
275
+ No npm token is stored in GitHub. The first version of a package has to be published by hand
276
+ (`npm publish --access public`), because npm only offers Trusted Publishing for existing
277
+ packages. Then, once per package:
278
+
279
+ 1. On npmjs.com open the package → **Settings → Trusted Publisher → GitHub Actions**.
280
+ 2. Enter the GitHub owner, the repo, and the workflow file the tag starts (`release.yml`).
281
+ 3. After one release works, set **Publishing access** to "Require two-factor authentication
282
+ and disallow tokens".
283
+
284
+ To release: bump `version` in `package.json` by hand, merge to `main`, then push the tag:
285
+
286
+ ```sh
287
+ git tag v1.0.1
288
+ git push origin v1.0.1
289
+ ```
290
+
291
+ A package without Trusted Publishing can still pass `secrets: { NPM_TOKEN: ... }` to
292
+ `publish.yml`.
293
+
294
+ ## Registry site
295
+
296
+ Feature packages that ship a shadcn registry also publish a static site on GitHub Pages: a landing
297
+ page, one docs page per item, the registry JSON (`r/`) and a Ladle playground that the pages embed
298
+ for live previews. The generator lives here, so a new package gets the site without copying files.
299
+ It needs `typescript` installed (it reads the TSDoc comments with the TypeScript parser).
300
+
301
+ What a package repo adds:
302
+
303
+ ```js
304
+ // registry/site.config.mjs
305
+ import { defineRegistrySite } from '@integr8-media/config/registry-site';
306
+
307
+ export default defineRegistrySite({
308
+ brand: { name: 'Integr8 Window Manager', slug: 'window-manager' },
309
+ categories: [
310
+ ['shell', 'Shell'],
311
+ ['window', 'Windows'],
312
+ ],
313
+ stories: { window: ['--window-'], taskbar: ['--taskbar-'] },
314
+ ui: { registryUrl: 'https://minalouisleon.github.io/integr8-ui/r' },
315
+ });
316
+ ```
317
+
318
+ ```json
319
+ // package.json
320
+ "scripts": {
321
+ "site:build": "integr8-registry-site build",
322
+ "site": "integr8-registry-site dev"
323
+ }
324
+ ```
325
+
326
+ ```yaml
327
+ # .github/workflows/registry.yml
328
+ name: Registry
329
+ on:
330
+ push:
331
+ branches: [main]
332
+ workflow_dispatch:
333
+ permissions: # the reusable workflow cannot grant itself more than this
334
+ contents: read
335
+ pages: write
336
+ id-token: write
337
+ jobs:
338
+ site:
339
+ uses: <owner>/integr8-config/.github/workflows/registry-site.yml@v1
340
+ ```
341
+
342
+ The repo still owns `scripts/buildRegistry.mjs` (it turns the source into `dist/registry/`). The
343
+ site generator only reads its output.
344
+
345
+ ### Commands
346
+
347
+ | Command | What it does |
348
+ | --- | --- |
349
+ | `integr8-registry-site build` | Runs `commands.assets` (if set), builds the Ladle playground, runs `commands.registry`, writes `site/` |
350
+ | `integr8-registry-site dev` | `build` for `http://localhost:4173/`, then serves `site/` (`PORT=5000` to change) |
351
+ | `integr8-registry-site serve` | Serves an existing `site/` |
352
+ | `integr8-registry-site enabled` | Prints `true` or `false` (the on/off switch) |
353
+ | `integr8-registry-site size [exports…]` | Bundle-size breakdown (needs `bundleSizes` in the config) |
354
+
355
+ Options: `--config <file>`, `--site-base-path <path>`, `--no-playground`.
356
+
357
+ ### Turn the site off
358
+
359
+ One setting, in `package.json`:
360
+
361
+ ```json
362
+ "integr8": { "site": false }
363
+ ```
364
+
365
+ - A missing key means on. Only a JSON boolean is accepted: `"site": "false"` is an error, so a typo
366
+ never silently builds or skips the site.
367
+ - The workflow's `settings` job reads it first. When it is `false`, the `build` and `deploy` jobs
368
+ are skipped and the run still succeeds (green, with a notice).
369
+ - Every `integr8-registry-site` command prints a note and exits with code 0, so `npm run site` and
370
+ `npm run site:build` pass too.
371
+ - `pr-checks.yml` has an input `site-build` (default `false`). When a repo turns it on, it runs
372
+ `npm run site:build`, which obeys the same switch.
373
+ - A package that has no site needs only this line: no config file, no workflow call.
374
+
375
+ There is deliberately no second switch (no `enabled` input, no `SITE_ENABLED` variable): two
376
+ settings can disagree, and one committed line is easy to review. To switch the site off for a
377
+ while, commit the one line.
378
+
379
+ ### Config reference
380
+
381
+ `registry/site.config.mjs` default-exports `defineRegistrySite({...})`. Only `brand.name` is
382
+ required; every other option has a default. Bad input throws `ConfigError` (`INVALID_OPTION`)
383
+ naming the option, such as `registry-site config: "brand.name" is required and must be a non-empty string.`
384
+ Unknown options are errors too (typo guard).
385
+
386
+ | Option | Meaning | Default |
387
+ | --- | --- | --- |
388
+ | `brand.name` | Product name, in titles and labels | required |
389
+ | `brand.slug` | Shown after `integr8/` in the header | name without "Integr8", kebab-case |
390
+ | `brand.mark` | Letters in the header badge | `i8` |
391
+ | `brand.eyebrow` | Text above the hero title (`· v<version>` is added) | `Registry` |
392
+ | `brand.heroTitle`, `brand.heroAccent` | Hero title; the accent is shown in the brand gradient | name, no accent |
393
+ | `brand.lead` | Text under the hero title | `description` of `package.json` |
394
+ | `brand.title`, `brand.description` | Landing page `<title>` and meta description | name, `package.json` description |
395
+ | `brand.footer` | Footer start; `{packageName}` and `{version}` are filled in | `{packageName} · v{version}` |
396
+ | `brand.repositoryUrl` | GitHub link in the header | `$GITHUB_REPOSITORY`, else `repository` in `package.json` |
397
+ | `brand.playgroundLink` | "Playground" link in the header | `false` |
398
+ | `brand.extraStats` | Extra hero numbers, `[{ value, label }]` | none |
399
+ | `brand.heroCommand` | Command in the hero | command of the last setup step |
400
+ | `categories` | Ordered `[id, label]` pairs, matched against each item's first category; the rest go under "Other" | categories found in the registry, in order |
401
+ | `stories` | Item → parts of Ladle story ids (a story matches when its id contains a part), or a function `(item) => parts`. Items not listed have no preview | stories whose id starts with `<item>--` |
402
+ | `defaultStory` | Story shown first in the landing preview: an item name or a story id | first story |
403
+ | `ui` | `{ registryUrl, docsUrl?, packageName? }`: the ui registry the items depend on. Ui items link to the ui site, with the ui theme step. Leave out in the ui package | none |
404
+ | `fonts` | `'copy-from-ui'` (copy `dist/fonts.css` and `dist/fonts/` from the installed ui package), `'build'` (copy the ones this repo built into `dist/`), `false` (system fonts) | `'copy-from-ui'` with `ui`, else `false` |
405
+ | `setup` | "Get started": `steps` (`{ title, text?, command }`), `extras` (`{ title, text?, code, caption? }`), `namespace` (alias in `components.json`), `shortNames`, `title`, `accent`, `lead`. Text, commands and code may use `{registryUrl}`, `{uiRegistryUrl}`, `{version}`, `{packageName}`; other `{...}` stay as written | shadcn init, ui theme (with `ui`), add the first item |
406
+ | `copy` | `previewLead`, `componentsLead`: longer landing texts | generic texts |
407
+ | `previewThemes` | `[id, label]` pairs: adds a theme switcher to the previews (`&integr8Theme=<id>`) | none (no switcher) |
408
+ | `themeNote` | `{ item, skip? }`: "add the theme first" note on item pages; `false` for none | the ui theme with `ui`, else none |
409
+ | `bundleSizes` | `{ entry?, ownCodeLabel?, external? }` for `integr8-registry-site size` (esbuild comes with `@size-limit/esbuild`); `false` for off | off |
410
+ | `commands` | `assets` (for example `node scripts/buildAssets.mjs`, needed with `fonts: 'build'`) and `registry` | registry: `node scripts/buildRegistry.mjs` |
411
+ | `registryUrl` | Where `r/` is served; `{name}` and `{version}` are filled in. `REGISTRY_BASE_URL` wins | GitHub Pages URL from `repository` |
412
+ | `playground` | Build and embed the Ladle playground | `true` |
413
+
414
+ Programmatic use: `buildRegistrySite(options)` writes the site, and `renderSiteFiles(input)` returns
415
+ the pages without touching the file system (pure, for tests).
416
+
417
+ ### Move the site
418
+
419
+ Set two repository variables (Settings → Secrets and variables → Actions → Variables), or pass
420
+ the same values as workflow inputs `registry-base-url` and `site-base-path`:
421
+
422
+ - `REGISTRY_BASE_URL`: full URL of the JSON folder, such as `https://integr8-media.com/ui/r`.
423
+ - `SITE_BASE_PATH`: the path the site is served from, such as `/ui/`.
424
+
425
+ Without them the site is served at `https://<owner>.github.io/<repo>/`.
426
+
427
+ ### One-time Pages setup
428
+
429
+ In the calling repo, Settings → Pages → Source: **GitHub Actions**. Without it `configure-pages`
430
+ fails ("Get Pages site failed"). The calling workflow must also grant `pages: write` and
431
+ `id-token: write`: a reusable workflow cannot raise its own permissions, and a caller that grants
432
+ less fails at startup.
433
+
434
+ ### Local preview and the `--base` pitfall
435
+
436
+ `npm run site` builds the site and serves it on `http://localhost:4173/`.
437
+
438
+ The Ladle playground must be built with `--base <site path>playground/`. Without it, its HTML asks
439
+ for `/assets/...`, which is a 404 under `site/playground/`, so every preview iframe is blank. By
440
+ design, `integr8-registry-site` always passes the right base: `/playground/` locally,
441
+ `${SITE_BASE_PATH}playground/` in CI. If a playground built the wrong way is already in
442
+ `playground/dist`, the site build stops with `PLAYGROUND_BASE_MISMATCH` and the exact command to
443
+ fix it, instead of publishing blank previews. Do not run `ladle build` yourself for the site.
444
+
185
445
  ## API
186
446
 
187
447
  | Import | Exports |
@@ -189,6 +449,9 @@ jobs:
189
449
  | `@integr8-media/config/vitest` | `integr8Vitest(options?)`, `ConfigError` |
190
450
  | `@integr8-media/config/tsdown` | `integr8Tsdown(options)`, `ConfigError` |
191
451
  | `@integr8-media/config/size-limit` | `integr8SizeLimit(entries)`, `ConfigError` |
452
+ | `@integr8-media/config/registry-site` | `defineRegistrySite(config)`, `buildRegistrySite(options)`, `renderSiteFiles(input)`, `readSiteSwitch(pkg)`, `RegistrySiteError`, `ConfigError`, … (see the API reference) |
453
+
454
+ The package also has a command, `integr8-registry-site` (see [Registry site](#registry-site)).
192
455
 
193
456
  Invalid options throw `ConfigError` with `code: 'INVALID_OPTION'`. The API reference is
194
457
  generated from TSDoc with `npm run docs` (output in `docs/api/`).
package/biome/biome.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "files": {
3
- "includes": ["**", "!**/dist", "!**/coverage", "!**/playground/dist", "!**/*.md"]
3
+ "includes": [
4
+ "**",
5
+ "!**/dist",
6
+ "!**/coverage",
7
+ "!**/playground/dist",
8
+ "!**/docs/api",
9
+ "!**/test-results",
10
+ "!**/playwright-report",
11
+ "!**/.vscode",
12
+ "!**/*.md"
13
+ ]
14
+ },
15
+ "vcs": {
16
+ "enabled": true,
17
+ "clientKind": "git",
18
+ "useIgnoreFile": true
19
+ },
20
+ "css": {
21
+ "parser": {
22
+ "tailwindDirectives": true
23
+ }
4
24
  },
5
25
  "formatter": {
6
26
  "enabled": true,
@@ -56,6 +76,37 @@
56
76
  }
57
77
  }
58
78
  }
79
+ },
80
+ {
81
+ "includes": ["**/.size-limit.js", "**/.size-limit.mjs", "**/.size-limit.ts"],
82
+ "linter": {
83
+ "rules": {
84
+ "style": {
85
+ "noDefaultExport": "off",
86
+ "useFilenamingConvention": "off"
87
+ }
88
+ }
89
+ }
90
+ },
91
+ {
92
+ "includes": ["**/playground/config.js", "**/playground/config.mjs", "**/playground/config.ts"],
93
+ "linter": {
94
+ "rules": {
95
+ "style": {
96
+ "noDefaultExport": "off"
97
+ }
98
+ }
99
+ }
100
+ },
101
+ {
102
+ "includes": ["**/scripts/**"],
103
+ "linter": {
104
+ "rules": {
105
+ "suspicious": {
106
+ "noConsole": "off"
107
+ }
108
+ }
109
+ }
59
110
  }
60
111
  ]
61
112
  }