@widgetic/dev-tools 0.3.2 → 0.3.4

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  The format roughly follows [Keep a Changelog](https://keepachangelog.com/); the
4
4
  reasons matter more than the categories.
5
5
 
6
+ ## Unreleased
7
+
8
+ ### Added
9
+
10
+ - **`publish-package.mjs`** (`bin/publish-package.mjs`): the laptop publish for every package. Each package's `publish-to-npm` script only calls this file. It does nothing when the latest commit already wrote the current version. Otherwise it raises the patch, publishes, commits the version files, tags the commit `v` plus the version, and pushes both. ui-sdk also releases the modules, and the tag is pushed after that release. embed-sdk also uploads its CDN file. dev-tools runs its tests before the version changes.
11
+ - **`publish-all-to-npm`** (`bin/publish-all-to-npm.mjs`): walks the npm packages and runs each package's `publish-to-npm` script.
12
+ - The README contract no longer checks `recorder` or `__template__`. The linking tier is `embed-sdk` and `ui-sdk`. The adopter tier is the apps that compile sibling source.
13
+
6
14
  ## 0.3.1 — 2026-10-08
7
15
 
8
16
  ### Added
package/README.md CHANGED
@@ -8,6 +8,7 @@ the repositories that consume it cannot drift apart.
8
8
  | `check-runtime-deps` | Fails when a package's `package.json` and its published output disagree: a `dependencies` entry the output never imports (a *phantom*, install weight every consumer pays for), or an import the manifest does not declare (a *missing* dependency, which breaks a consumer's build). |
9
9
  | `check-runtime-deps-fixtures` | Runs the fixture suite that proves the check above fails when it should. |
10
10
  | `check-design-system-peers` | Fails when `canvas` and `file-browser` — the two peers that resolve `@widgetic/design-system` from the registry — disagree: lockfiles resolving different versions, or a lockfile that no longer matches the version the design-system checkout carries. Makes the next publish's consumer refresh land as one coordinated change instead of two drifted ones. |
11
+ | `publish-all-to-npm` | Laptop fallback when GitLab has no compute minutes. Walks the npm packages and runs each package's own `publish-to-npm` script. |
11
12
 
12
13
  It also ships two `lib/` modules with hand-written types and their own `node --test`
13
14
  fixtures:
@@ -174,17 +175,16 @@ tarball, publish, and have every consumer refresh its lockfile in the same
174
175
  commit as its version bump. Run it as `npm run check:readme` here, or
175
176
  `npx check-readme-contracts` anywhere the package is installed.
176
177
 
177
- Three packages consume a sibling the other way round: `embed-sdk`, `recorder`
178
- and `ui-sdk` link a sibling checkout by hand to its built output instead —
179
- `lps`, `lapisdk`, a raw `ln -s`. The sibling-source sentences would be false in
180
- their READMEs, so they carry [their own canonical sentences](lib/readme-contract.mjs)
181
- — the link, what it resolves, and why a sibling edit needs a rebuild to show up
182
- — and [Linked siblings](#linked-siblings-consuming-built-output-not-source)
183
- below is the section they copy. The retired-instruction ban reaches them one
184
- tier narrower: `npm link`, `volta run`, `llinks` and the after-install re-run
185
- are those packages' *live* setup — `recorder`'s `lps` runs `volta run npm link`,
186
- and its `llinks` script reports what `node_modules/@widgetic` resolves to — so
187
- that half of the ban would be banning the truth about them. What stays banned
178
+ Two packages consume a sibling the other way round: `embed-sdk` and `ui-sdk`
179
+ link a sibling checkout by hand to its built output instead — `lapisdk`, or a
180
+ raw `ln -s`. The sibling-source sentences would be false in their READMEs, so
181
+ they carry [their own canonical sentences](lib/readme-contract.mjs) — the link,
182
+ what it resolves, and why a sibling edit needs a rebuild to show up — and
183
+ [Linked siblings](#linked-siblings-consuming-built-output-not-source) below is
184
+ the section they copy. The retired-instruction ban reaches them one tier
185
+ narrower: `npm link`, `volta run`, `llinks` and the after-install re-run are a
186
+ hand-made link's live setup, so that half of the ban would be banning the
187
+ truth about them. What stays banned
188
188
  in either tier is the lore that is dead everywhere: the `ldt` step, which these
189
189
  packages never adopted, and the retired `typescript-sdk` name. All of it is
190
190
  data in `LINKING_PACKAGES` and `STALE_PATTERNS` in
@@ -209,11 +209,11 @@ they are not part of dev-tools setup, and no step here depends on them.
209
209
 
210
210
  ### Linked siblings: consuming built output, not source
211
211
 
212
- `embed-sdk`, `recorder` and `ui-sdk` consume a sibling the other way round:
213
- they link a sibling checkout into `node_modules` by hand — from a script the
214
- package owns — and import what that checkout **builds**, so a sibling edit is
215
- invisible here until that package rebuilds its `dist/`. The mechanism is
216
- theirs and the scripts differ (`lapisdk`, `lps`, a raw `ln -s`), so the
212
+ `embed-sdk` and `ui-sdk` consume a sibling the other way round: they link a
213
+ sibling checkout into `node_modules` by hand — from a script the package owns
214
+ — and import what that checkout **builds**, so a sibling edit is invisible
215
+ here until that package rebuilds its `dist/`. The mechanism is theirs and the
216
+ scripts differ (`lapisdk`, a raw `ln -s`), so the
217
217
  canonical sentences stay command-neutral and each README names its own scripts
218
218
  around them. These are the four sentences, in this order; the same text is
219
219
  data in [`lib/readme-contract.mjs`](lib/readme-contract.mjs), which is what the
@@ -319,6 +319,26 @@ here and a release** — not an edit in the consumer. Every entry needs a reason
319
319
  specific enough that a reviewer can check it; each one is a claim the check can
320
320
  no longer make.
321
321
 
322
+ ## Publishing from a laptop
323
+
324
+ GitLab CI on `main` remains the way a package is published. When the group has no compute minutes left, the same publish can be done from this checkout.
325
+
326
+ `bin/publish-package.mjs` is the publish for every package. Each package's `publish-to-npm` script only calls that file. It does nothing when the latest commit is the one that wrote the current `package.json` version. When a later commit exists, it raises the patch, publishes that version, commits the version files, tags that commit `v` plus the version, and pushes the commit and the tag. The token is the one in `~/.npmrc`. For ui-sdk it also keeps `SDK_VERSION` in step, then raises the modules patch and writes one changelog sentence. It commits before the modules release, because that release refuses a dirty `modules/` directory, and tags and pushes after the release. The R2 settings for the modules are in `modules/.env`, which is not committed. For embed-sdk it also uploads `dist/umd/embed-sdk.js` to the CDN and purges it, then commits the version and `dist/`, tags, and pushes. The R2 settings for that upload are in `.env.cdn`, which is not committed. The other packages have no CDN file. dev-tools runs its tests before the version changes.
327
+
328
+ From one package, publish only that package:
329
+
330
+ ```sh
331
+ npm run publish-to-npm
332
+ ```
333
+
334
+ From `dev-tools`, walk every package:
335
+
336
+ ```sh
337
+ npm run publish-all-to-npm
338
+ ```
339
+
340
+ The walk is `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `canvas`, `chat`, `editor`, `file-browser`, `widget-creator`, `embed-sdk` and `ui-sdk`. `site` is not in it.
341
+
322
342
  ## Releasing
323
343
 
324
344
  Push to `main` with a new `version` in `package.json`. CI runs the check against
@@ -11,8 +11,8 @@
11
11
  * workflow change had no single place to land. Nothing fails when it does —
12
12
  * the section just stops being true.
13
13
  *
14
- * Three more packages consume a sibling through a hand-made link to its built
15
- * output — `embed-sdk`, `recorder`, `ui-sdk` — and were read by nothing at
14
+ * Two more packages consume a sibling through a hand-made link to its built
15
+ * output — `embed-sdk` and `ui-sdk` — and were read by nothing at
16
16
  * all, so drift in one of their READMEs failed nothing. They compile no
17
17
  * sibling source, so the sibling-source sentences would be false in them; they
18
18
  * carry the canonical linked-sibling sentences instead, which state what the
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Run each package's own publish-to-npm script.
4
+ *
5
+ * npm run publish-all-to-npm
6
+ *
7
+ * Each package.json calls bin/publish-package.mjs. That file is the publish.
8
+ * This file only walks the checkouts.
9
+ */
10
+
11
+ import { spawnSync } from 'node:child_process';
12
+ import { existsSync, statSync } from 'node:fs';
13
+ import { resolve } from 'node:path';
14
+ import { fileURLToPath } from 'node:url';
15
+ import { PUBLISHABLE_PACKAGES } from '../lib/publish-to-npm.mjs';
16
+
17
+ const frontendRoot = fileURLToPath(new URL('../..', import.meta.url));
18
+
19
+ let failed = 0;
20
+ for (const pkg of PUBLISHABLE_PACKAGES) {
21
+ const packageDir = resolve(frontendRoot, pkg.dir);
22
+ if (!existsSync(packageDir) || !statSync(packageDir).isDirectory()) {
23
+ console.log(`[publish-all-to-npm] ${pkg.dir}: not checked out, skipping`);
24
+ continue;
25
+ }
26
+ console.log(`[publish-all-to-npm] ${pkg.dir}: npm run ${pkg.script}`);
27
+ const result = spawnSync('npm', ['run', pkg.script], {
28
+ cwd: packageDir,
29
+ stdio: 'inherit'
30
+ });
31
+ if (result.status !== 0) {
32
+ failed += 1;
33
+ console.error(
34
+ `[publish-all-to-npm] ${pkg.dir}: npm run ${pkg.script} exited ${result.status ?? 'without a status'}`
35
+ );
36
+ }
37
+ }
38
+
39
+ if (failed > 0) {
40
+ console.error(`[publish-all-to-npm] ${failed} package(s) failed`);
41
+ process.exit(1);
42
+ }
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Publish the package in the current directory.
4
+ *
5
+ * Each package's publish-to-npm script is only this file. embed-sdk also
6
+ * uploads its CDN file. ui-sdk also releases the modules. dev-tools runs its
7
+ * tests before the version changes. Every other package builds, or packages,
8
+ * then publishes.
9
+ *
10
+ * The script does nothing when the latest commit is the one that wrote the
11
+ * current package.json version. Otherwise it raises the patch, publishes,
12
+ * commits the version files, tags that commit v plus the version, and pushes
13
+ * the commit and the tag.
14
+ */
15
+
16
+ import { spawnSync } from 'node:child_process';
17
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
18
+ import { basename, join } from 'node:path';
19
+
20
+ const packageDir = process.cwd();
21
+ const packageName = basename(packageDir);
22
+
23
+ const BUILD_PACKAGES = new Set(['api-sdk', 'cache-layer', 'design-system']);
24
+ const PACKAGE_PACKAGES = new Set(['canvas', 'chat', 'editor', 'file-browser', 'widget-creator']);
25
+
26
+ /**
27
+ * Run a command and stop the publish when it fails.
28
+ * @param {string} command
29
+ * @param {string[]} args
30
+ * @param {{ cwd?: string, env?: NodeJS.ProcessEnv }} [options]
31
+ */
32
+ function run(command, args, options = {}) {
33
+ const result = spawnSync(command, args, {
34
+ cwd: options.cwd ?? packageDir,
35
+ env: options.env ?? process.env,
36
+ stdio: 'inherit'
37
+ });
38
+ if (result.status !== 0) {
39
+ console.error(`[publish-package] ${packageName}: ${command} ${args.join(' ')} exited ${result.status ?? 'without a status'}`);
40
+ process.exit(result.status ?? 1);
41
+ }
42
+ }
43
+
44
+ /**
45
+ * @param {string[]} args
46
+ * @returns {string}
47
+ */
48
+ function gitOutput(args) {
49
+ return spawnSync('git', args, { cwd: packageDir, encoding: 'utf8' }).stdout.trim();
50
+ }
51
+
52
+ /** @returns {string} */
53
+ function readVersion() {
54
+ return JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8')).version;
55
+ }
56
+
57
+ /**
58
+ * The latest commit is the one that introduced this version string, so there
59
+ * is nothing new to publish.
60
+ * @param {string} version
61
+ * @returns {boolean}
62
+ */
63
+ function versionCommitIsHead(version) {
64
+ const versionCommit = gitOutput(['log', '-1', '--format=%H', '-S', `"version": "${version}"`, '--', 'package.json']);
65
+ const head = gitOutput(['rev-parse', 'HEAD']);
66
+ return versionCommit !== '' && versionCommit === head;
67
+ }
68
+
69
+ /**
70
+ * @param {string[]} paths
71
+ * @param {string} detail
72
+ */
73
+ function commitVersion(paths, detail) {
74
+ const version = readVersion();
75
+ const present = paths.filter((path) => existsSync(join(packageDir, path)));
76
+ run('git', ['add', '--', ...present]);
77
+ run('git', ['commit', '-m', `chore: publish ${version}`, '-m', detail]);
78
+ }
79
+
80
+ function tagAndPush() {
81
+ const version = readVersion();
82
+ const tag = `v${version}`;
83
+ console.log(`[publish-package] ${packageName}: tagging ${tag}`);
84
+ run('git', ['tag', '-a', tag, '-m', tag]);
85
+ run('git', ['push', 'origin', 'HEAD', tag]);
86
+ }
87
+
88
+ function publishToNpm() {
89
+ run('npm', ['publish', '--ignore-scripts', '--access', 'public']);
90
+ }
91
+
92
+ const currentVersion = readVersion();
93
+ if (versionCommitIsHead(currentVersion)) {
94
+ console.log(`[publish-package] ${packageName}: no commits since ${currentVersion}. Nothing to publish.`);
95
+ process.exit(0);
96
+ }
97
+
98
+ console.log(`[publish-package] ${packageName}: publishing the next patch after ${currentVersion}`);
99
+
100
+ if (packageName === 'dev-tools') {
101
+ run('npm', ['test']);
102
+ }
103
+
104
+ run('npm', ['version', 'patch', '--no-git-tag-version']);
105
+
106
+ if (BUILD_PACKAGES.has(packageName)) {
107
+ run('npm', ['run', 'build']);
108
+ publishToNpm();
109
+ commitVersion(
110
+ ['package.json', 'package-lock.json'],
111
+ '- Record the patch that was just published to npm'
112
+ );
113
+ tagAndPush();
114
+ } else if (PACKAGE_PACKAGES.has(packageName)) {
115
+ run('npm', ['run', 'package']);
116
+ publishToNpm();
117
+ commitVersion(
118
+ ['package.json', 'package-lock.json'],
119
+ '- Record the patch that was just published to npm'
120
+ );
121
+ tagAndPush();
122
+ } else if (packageName === 'dev-tools') {
123
+ publishToNpm();
124
+ commitVersion(
125
+ ['package.json', 'package-lock.json'],
126
+ '- Record the patch that was just published to npm'
127
+ );
128
+ tagAndPush();
129
+ } else if (packageName === 'embed-sdk') {
130
+ run('npm', ['run', 'build']);
131
+ run('npm', ['run', 'check:no-secrets']);
132
+ publishToNpm();
133
+ run('npm', ['run', 'publish:cdn', '--', '--yes', '--purge', '--allow-dirty', '--env-file', '.env.cdn']);
134
+ commitVersion(
135
+ ['package.json', 'package-lock.json', 'dist'],
136
+ '- Record the patch that was just published to npm and the CDN file built from it'
137
+ );
138
+ tagAndPush();
139
+ } else if (packageName === 'ui-sdk') {
140
+ const versionFile = join(packageDir, 'src/sdk/version.ts');
141
+ const version = readVersion();
142
+ writeFileSync(
143
+ versionFile,
144
+ readFileSync(versionFile, 'utf8').replace(/SDK_VERSION = '[^']+'/, `SDK_VERSION = '${version}'`)
145
+ );
146
+ run('npm', ['run', 'build:publish']);
147
+ run('node', ['scripts-sdk/check-no-secrets.js']);
148
+ publishToNpm();
149
+ run('node', ['modules/scripts/advance-module-version.mjs']);
150
+ commitVersion(
151
+ [
152
+ 'package.json',
153
+ 'package-lock.json',
154
+ 'src/sdk/version.ts',
155
+ 'modules/package.json',
156
+ 'modules/package-lock.json',
157
+ 'modules/src/composition-editor/CHANGELOG.md',
158
+ 'modules/src/file-browser/CHANGELOG.md',
159
+ 'modules/src/widget-creator/CHANGELOG.md'
160
+ ],
161
+ '- Record the package patch and the modules patch that were just published'
162
+ );
163
+ const modulesDir = join(packageDir, 'modules');
164
+ const modulesVersion = JSON.parse(readFileSync(join(modulesDir, 'package.json'), 'utf8')).version;
165
+ const modulesTag = `modules-v${modulesVersion}`;
166
+ run('npm', ['run', 'release:check', '--', '--tag', modulesTag], { cwd: modulesDir });
167
+ run('npm', ['run', 'build'], {
168
+ cwd: modulesDir,
169
+ env: { ...process.env, NODE_OPTIONS: '--max-old-space-size=8192' }
170
+ });
171
+ run('npm', ['run', 'release:publish', '--', '--tag', modulesTag], { cwd: modulesDir });
172
+ tagAndPush();
173
+ } else {
174
+ console.error(`[publish-package] ${packageName} is not one of the packages this script publishes`);
175
+ process.exit(1);
176
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The Frontend checkouts whose `npm run publish-to-npm` publishes that package.
3
+ *
4
+ * `publish-all-to-npm` walks this list and runs that script. The script calls
5
+ * `bin/publish-package.mjs`, which is the publish for every package. `site`
6
+ * is absent because it is an app, not a package on npm.
7
+ */
8
+
9
+ /** @typedef {{ dir: string, script: string }} PublishablePackage */
10
+
11
+ /** @type {readonly PublishablePackage[]} */
12
+ export const PUBLISHABLE_PACKAGES = [
13
+ { dir: 'api-sdk', script: 'publish-to-npm' },
14
+ { dir: 'cache-layer', script: 'publish-to-npm' },
15
+ { dir: 'design-system', script: 'publish-to-npm' },
16
+ { dir: 'dev-tools', script: 'publish-to-npm' },
17
+ { dir: 'canvas', script: 'publish-to-npm' },
18
+ { dir: 'chat', script: 'publish-to-npm' },
19
+ { dir: 'editor', script: 'publish-to-npm' },
20
+ { dir: 'file-browser', script: 'publish-to-npm' },
21
+ { dir: 'widget-creator', script: 'publish-to-npm' },
22
+ { dir: 'embed-sdk', script: 'publish-to-npm' },
23
+ { dir: 'ui-sdk', script: 'publish-to-npm' }
24
+ ];
@@ -16,10 +16,9 @@
16
16
  * {@link CANONICAL_LINKING_SENTENCES} instead, which state what the link
17
17
  * resolves to and what that costs. The retired-instruction ban reaches them
18
18
  * through its global half only: the link-era mechanics are these packages'
19
- * *live* setup — `recorder`'s `lps` runs `volta run npm link`, its `llinks`
20
- * script reports what `node_modules/@widgetic` resolves to — so banning
21
- * `npm link` in their prose would ban the truth about them. The ban's other
22
- * half is the dev-alias story, and that is an adopter's story.
19
+ * *live* setup, so banning `npm link` in their prose would ban the truth
20
+ * about them. The ban's other half is the dev-alias story, and that is an
21
+ * adopter's story.
23
22
  *
24
23
  * The section earned its guard by drifting three different ways. It taught a
25
24
  * hand-linking practice after the practice was retired (site's `lps` and
@@ -63,8 +62,7 @@ export const ADOPTER_PACKAGES = [
63
62
  'editor',
64
63
  'file-browser',
65
64
  'site',
66
- 'widget-creator',
67
- '__template__'
65
+ 'widget-creator'
68
66
  ];
69
67
 
70
68
  /**
@@ -91,8 +89,8 @@ export const PUBLISH_PACKAGES = ['chat', 'file-browser'];
91
89
  * ordered substrings over whitespace-collapsed prose, with app-specific
92
90
  * sentences allowed between them.
93
91
  *
94
- * What the three share is the shape, not the command: `embed-sdk` links from
95
- * its `lapisdk` script, `recorder` from `lps`, `ui-sdk` from a raw `ln -s`.
92
+ * What the two share is the shape, not the command: `embed-sdk` links from
93
+ * its `lapisdk` script, `ui-sdk` from a raw `ln -s`.
96
94
  * These sentences therefore stay command-neutral — they say what the link
97
95
  * resolves, why that is not the dev-alias workflow, and that the package's own
98
96
  * install script is the setup and the repair path — and each README names its
@@ -107,13 +105,12 @@ export const CANONICAL_LINKING_SENTENCES = [
107
105
 
108
106
  /**
109
107
  * The packages that consume a sibling checkout through a hand-made link to its
110
- * built output rather than the dev-alias workflow — `embed-sdk` and `ui-sdk`
111
- * link `@widgetic/api-sdk` from a script, `recorder` links it and
112
- * `@widgetic/design-system` from `lps`. They are exempt from the canonical
108
+ * built output rather than the dev-alias workflow. `embed-sdk` and `ui-sdk`
109
+ * link `@widgetic/api-sdk` from a script. They are exempt from the canonical
113
110
  * sibling-source sentences (they compile no sibling source) and carry
114
111
  * {@link CANONICAL_LINKING_SENTENCES} instead.
115
112
  */
116
- export const LINKING_PACKAGES = ['embed-sdk', 'recorder', 'ui-sdk'];
113
+ export const LINKING_PACKAGES = ['embed-sdk', 'ui-sdk'];
117
114
 
118
115
  /** Every package the check reads, in tier order. */
119
116
  export const CHECKED_PACKAGES = [...ADOPTER_PACKAGES, ...LINKING_PACKAGES];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/dev-tools",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "description": "Build-time checks and dev tooling shared by the published @widgetic packages, released once so the repositories that consume them cannot drift apart. Currently: check-runtime-deps (with the fixture suite that proves it fails), the Vite sibling-$lib remap, the canonical Frontend sibling layout that builds every consumer's dev-alias tables, and check-links — the link-doctor that fails when a sibling symlink dangles, a promised dist/ file is missing, or a dead checkout name lingers, and check-design-system-peers — which fails when the two design-system peers' lockfiles drift apart.",
6
6
  "repository": {
@@ -22,7 +22,8 @@
22
22
  "check-readme-contracts": "bin/check-readme-contracts.mjs",
23
23
  "check-readme-contracts-fixtures": "bin/check-readme-contracts-fixtures.mjs",
24
24
  "check-layout-fixtures": "bin/check-layout-fixtures.mjs",
25
- "check-design-system-peers": "bin/check-design-system-peers.mjs"
25
+ "check-design-system-peers": "bin/check-design-system-peers.mjs",
26
+ "publish-all-to-npm": "bin/publish-all-to-npm.mjs"
26
27
  },
27
28
  "files": [
28
29
  "bin",
@@ -42,7 +43,10 @@
42
43
  "test:links": "node bin/check-links-fixtures.mjs",
43
44
  "test:readme": "node --test test/readme-contract.test.mjs",
44
45
  "test:peers": "node --test test/lockfile-peers.test.mjs",
45
- "test": "npm run check:deps && npm run test:deps && npm run test:vite && npm run test:layout && npm run test:links && npm run test:readme && npm run test:peers",
46
+ "test:publish": "node --test test/publish-to-npm.test.mjs",
47
+ "test": "npm run check:deps && npm run test:deps && npm run test:vite && npm run test:layout && npm run test:links && npm run test:readme && npm run test:peers && npm run test:publish",
48
+ "publish-to-npm": "node bin/publish-package.mjs",
49
+ "publish-all-to-npm": "node bin/publish-all-to-npm.mjs",
46
50
  "prepublishOnly": "npm test"
47
51
  },
48
52
  "volta": {
@@ -0,0 +1,47 @@
1
+ import { test } from 'node:test';
2
+ import assert from 'node:assert/strict';
3
+ import { readFileSync } from 'node:fs';
4
+ import { resolve } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { PUBLISHABLE_PACKAGES } from '../lib/publish-to-npm.mjs';
7
+
8
+ const FRONTEND = fileURLToPath(new URL('../..', import.meta.url));
9
+
10
+ test('the walk calls publish-to-npm in each npm package', () => {
11
+ assert.deepEqual(
12
+ PUBLISHABLE_PACKAGES.map((pkg) => `${pkg.dir}:${pkg.script}`),
13
+ [
14
+ 'api-sdk:publish-to-npm',
15
+ 'cache-layer:publish-to-npm',
16
+ 'design-system:publish-to-npm',
17
+ 'dev-tools:publish-to-npm',
18
+ 'canvas:publish-to-npm',
19
+ 'chat:publish-to-npm',
20
+ 'editor:publish-to-npm',
21
+ 'file-browser:publish-to-npm',
22
+ 'widget-creator:publish-to-npm',
23
+ 'embed-sdk:publish-to-npm',
24
+ 'ui-sdk:publish-to-npm'
25
+ ]
26
+ );
27
+ assert.equal(PUBLISHABLE_PACKAGES.some((pkg) => pkg.dir === 'site'), false);
28
+ });
29
+
30
+ test('each package script calls the one publisher, and the walk is separate', () => {
31
+ const publisher = readFileSync(resolve(FRONTEND, 'dev-tools/bin/publish-package.mjs'), 'utf8');
32
+ assert.equal(publisher.includes('no commits since'), true);
33
+ assert.equal(publisher.includes("['tag', '-a', tag, '-m', tag]"), true);
34
+ assert.equal(publisher.includes('publish:cdn'), true);
35
+ assert.equal(publisher.includes('advance-module-version.mjs'), true);
36
+ assert.equal(publisher.indexOf('commitVersion(') < publisher.indexOf('release:publish'), true);
37
+ for (const pkg of PUBLISHABLE_PACKAGES) {
38
+ const manifest = JSON.parse(readFileSync(resolve(FRONTEND, pkg.dir, 'package.json'), 'utf8'));
39
+ const command = manifest.scripts?.[pkg.script];
40
+ const expected = pkg.dir === 'dev-tools'
41
+ ? 'node bin/publish-package.mjs'
42
+ : 'node ../dev-tools/bin/publish-package.mjs';
43
+ assert.equal(command, expected, `${pkg.dir} does not call the shared publisher`);
44
+ }
45
+ const devTools = JSON.parse(readFileSync(resolve(FRONTEND, 'dev-tools/package.json'), 'utf8'));
46
+ assert.equal(devTools.scripts['publish-all-to-npm'], 'node bin/publish-all-to-npm.mjs');
47
+ });
@@ -11,7 +11,7 @@
11
11
  * degrades silently: nothing fails, the section just stops being true.
12
12
  *
13
13
  * The second tier is the packages that link a sibling by hand instead of
14
- * compiling its source — `embed-sdk`, `recorder`, `ui-sdk`. Their READMEs
14
+ * compiling its source — `embed-sdk` and `ui-sdk`. Their READMEs
15
15
  * were read by nothing at all: not the adopters' check, not a test. They get
16
16
  * no canonical section (it would be false) but they do get the
17
17
  * retired-instruction ban, and both rules are driven here.
@@ -390,8 +390,8 @@ describe('the checkout collector', () => {
390
390
  });
391
391
 
392
392
  describe('the linking tier', () => {
393
- it('reads the three hand-linking packages by default', () => {
394
- assert.deepEqual(LINKING_PACKAGES, ['embed-sdk', 'recorder', 'ui-sdk']);
393
+ it('reads the hand-linking packages by default', () => {
394
+ assert.deepEqual(LINKING_PACKAGES, ['embed-sdk', 'ui-sdk']);
395
395
  // Every linking package is a subject, and none of them is an adopter:
396
396
  // the canonical sentences would be false in their READMEs.
397
397
  assert.ok(LINKING_PACKAGES.every((p) => CHECKED_PACKAGES.includes(p)));
@@ -425,7 +425,7 @@ describe('the linking tier', () => {
425
425
  'not its source',
426
426
  'rather than its source'
427
427
  );
428
- const f = readmeFindings('recorder', 'recorder/README.md', forked);
428
+ const f = readmeFindings('embed-sdk', 'embed-sdk/README.md', forked);
429
429
  assert.equal(f.length, 1);
430
430
  assert.equal(f[0].kind, 'linked-sibling section drift');
431
431
  // The finding names the first canonical sentence that is missing, so the
@@ -440,7 +440,7 @@ describe('the linking tier', () => {
440
440
  'Here that script is `npm run lps`, which links both siblings at once.\n\n' +
441
441
  `${CANONICAL_LINKING_SENTENCES.slice(1).join(' ')}\n\n` +
442
442
  '```sh\nnpm run i\nnpm run lps\n```\n';
443
- assert.deepEqual(readmeFindings('recorder', 'recorder/README.md', withNotes), []);
443
+ assert.deepEqual(readmeFindings('embed-sdk', 'embed-sdk/README.md', withNotes), []);
444
444
  });
445
445
 
446
446
  it('fails a linking README whose only mention of the sibling is not the section', () => {
@@ -455,15 +455,15 @@ describe('the linking tier', () => {
455
455
  });
456
456
 
457
457
  it('allows the link-era mechanics that are these packages live setup', () => {
458
- // recorder's lps script is `volta run npm link` and its llinks script
459
- // reports what node_modules/@widgetic resolves to — prose describing that
460
- // is the truth about the package, so the ban stops at the tier boundary.
458
+ // A hand-made link is this tier's live setup, so prose that names
459
+ // `volta run`, `npm link` and `llinks` stays allowed. The ban stops
460
+ // at the tier boundary.
461
461
  const raw =
462
462
  `${linkingSection(72)}\n\n` +
463
463
  '`npm run lps` links both siblings through `volta run` with the pinned\n' +
464
464
  'toolchain, and `npm run llinks` reports what `node_modules/@widgetic`\n' +
465
465
  'resolves to.\n';
466
- assert.deepEqual(readmeFindings('recorder', 'recorder/README.md', raw), []);
466
+ assert.deepEqual(readmeFindings('embed-sdk', 'embed-sdk/README.md', raw), []);
467
467
  });
468
468
 
469
469
  it('flags the instructions that are dead for every package, wherever they appear', () => {
@@ -483,12 +483,12 @@ describe('the linking tier', () => {
483
483
  it('requires its own sentences — and only its own — from a linking package', () => {
484
484
  // Same prose, two tiers: the linked-sibling section completes a linking
485
485
  // package, while an adopter carrying that text has drifted from its own.
486
- assert.deepEqual(readmeFindings('recorder', 'recorder/README.md', linkingSection(72)), []);
486
+ assert.deepEqual(readmeFindings('embed-sdk', 'embed-sdk/README.md', linkingSection(72)), []);
487
487
  const adopter = readmeFindings('site', 'site/README.md', linkingSection(72));
488
488
  assert.deepEqual(adopter.map((x) => x.kind), ['ldt section drift']);
489
489
  // The reverse: an adopter's section satisfies a linking package nowhere,
490
490
  // because it never states how the sibling arrives.
491
- const linking = readmeFindings('recorder', 'recorder/README.md', section(72));
491
+ const linking = readmeFindings('embed-sdk', 'embed-sdk/README.md', section(72));
492
492
  assert.deepEqual(linking.map((x) => x.kind), ['linked-sibling section drift']);
493
493
  });
494
494
 
@@ -503,14 +503,14 @@ describe('the linking tier', () => {
503
503
 
504
504
  it('exempts fenced examples, exactly as the adopter tier does', () => {
505
505
  const fenced = `${linkingSection(72)}\n\`\`\`sh\n# historical: npm run ldt after every install\n\`\`\`\n`;
506
- assert.deepEqual(readmeFindings('recorder', 'recorder/README.md', fenced), []);
506
+ assert.deepEqual(readmeFindings('embed-sdk', 'embed-sdk/README.md', fenced), []);
507
507
  });
508
508
 
509
509
  it('flags the same words when prose carries them rather than a fence', () => {
510
510
  // The counterpart of the fence test: outside a fence, the words fail —
511
511
  // with the globally-dead lore, which is what the fence above quotes.
512
512
  const proseForm = `${linkingSection(72)}\nHistorical note: npm run ldt was how it used to work.\n`;
513
- const f = readmeFindings('recorder', 'recorder/README.md', proseForm);
513
+ const f = readmeFindings('embed-sdk', 'embed-sdk/README.md', proseForm);
514
514
  assert.equal(f.length, 1);
515
515
  assert.equal(f[0].kind, 'linked-sibling section drift');
516
516
  });
@@ -532,7 +532,7 @@ describe('the real Frontend checkout', { skip: !DISK_OK }, () => {
532
532
  const { packages } = collectReadmeDrift(FRONTEND);
533
533
  assert.deepEqual(packages, CHECKED_PACKAGES);
534
534
  // A subject whose file vanished would pass a prose scan vacuously, so
535
- // this asserts the three linking READMEs are really there to be read.
535
+ // this asserts the linking READMEs are really there to be read.
536
536
  for (const pkg of LINKING_PACKAGES) {
537
537
  assert.ok(
538
538
  existsSync(join(FRONTEND, pkg, 'README.md')),