@widgetic/dev-tools 0.3.10 → 0.3.12
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 +6 -0
- package/README.md +38 -2
- package/bin/check-design-system-peers.mjs +0 -0
- package/bin/check-packed-imports.mjs +28 -0
- package/bin/publish-all-to-npm.mjs +0 -0
- package/bin/publish-package.mjs +50 -1
- package/bin/sync-frontend-checkouts.mjs +111 -0
- package/lib/frontend-layout.mjs +27 -2
- package/lib/packed-imports.mjs +390 -0
- package/lib/publish-to-npm.mjs +2 -0
- package/lib/sync-frontend-checkouts.mjs +288 -0
- package/package.json +10 -4
- package/test/frontend-layout.test.mjs +18 -1
- package/test/packed-imports.test.mjs +220 -0
- package/test/publish-to-npm.test.mjs +98 -5
- package/test/sync-frontend-checkouts.test.mjs +149 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ reasons matter more than the categories.
|
|
|
7
7
|
|
|
8
8
|
### Added
|
|
9
9
|
|
|
10
|
+
- **`sync-frontend-checkouts`** (`bin/sync-frontend-checkouts.mjs`, rules in `lib/sync-frontend-checkouts.mjs`): walks every immediate child of `Frontend/` that is a git checkout, commits a dirty working tree (`chore`/`docs` plus the file list; `.env` and similar secrets stay unstaged), then `git pull --ff-only`, then deletes `node_modules/.vite` and `node_modules/.vite-temp` so the next `npm run dev` does not keep serving a prebundle of older `@widgetic/*` source. `--no-commit-dirty` leaves a dirty tree alone. `--dry-run` reports and touches nothing. From this package: `npm run sync-frontend`. From `Frontend/site`: `npm run sync-frontend` (it calls this bin). `npm run test:sync-frontend` drives a throwaway tree with a stub `git`, so a real pull never runs.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
- **The design-system's `inline-completion`, `textarea-overlay` and `prompt-references` are subpaths of the dev alias table.** `SIBLING_PACKAGES['design-system'].subpaths` carries the three (directories, each with an `index.ts`), so an app that aliases the design-system's source in dev (the widget creator, the site, the chat, the workflows assistant) can import `@widgetic/design-system/inline-completion` (ghost text), `@widgetic/design-system/textarea-overlay` (the layer it draws on) and `@widgetic/design-system/prompt-references` (a `#` that names an attached file, with a badge in the text) by name. Without the entries the bare-index alias swallows the import and turns it into `<lib>/index.ts/inline-completion`, which is nothing (`ENOTDIR` in the dev server and in the tests of the app), the same thing that `i18n` and `rtl` have an entry for. The test of the table lists all three, and the disk test (`npm run test:layout:disk`, in a consumer beside the siblings) fails until the design-system checkout that has the three folders is the one beside it. The package ships the ghost-text engine and the file references in the release after the one that is out, so an app takes this release of dev-tools together with that one.
|
|
14
|
+
- **`@widgetic/brand` is a package of the walk.** It is in `PUBLISHABLE_PACKAGES` (right after `dev-tools` and before `widget-creator`, which takes it as a peer for the Agent's mascot), in the publisher's `PACKAGE_PACKAGES` (it is packaged with `npm run package`, like `chat`), and `SIBLING_PACKAGES` carries it as a library package, so an app can alias its source in dev. It has no sibling dependencies, so it is not an adopter of the sibling-source README contract. Its first release is `0.1.1`: the package starts at `0.1.0` and the publisher raises the patch first.
|
|
15
|
+
- **`check-packed-imports`** (`bin/check-packed-imports.mjs`, rules in `lib/packed-imports.mjs`), and the publisher runs it before every `npm publish`. A file that `npm pack` takes can import a file the package does not hold: `../shared/format.js` out of the package, a `./format.js` the build did not write, a `$lib/...` alias the build left in. Such a package installs and then throws when a consumer loads it, and nothing on the laptop that publishes sees it, because every file is there (`@widgetic/editor` 4.1.19 was published that way: `dist/embed/parseCompositionEmbedCode.js` imported `../../../static/embed-schema.json`; 4.1.20 is the fix). The check asks `npm pack --dry-run --json --ignore-scripts` which files would go, reads the `.js`, `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts` files and the `<script>` blocks of the `.svelte` ones, and follows each relative import (`import … from`, `export … from`, `import()`, `require()`, `/// <reference path>`) to a packed file, the way a bundler resolves it (an extension left out, a folder's `index`, a `?url` suffix ignored; a `.d.ts` file's `./x.js` or `./x.ts` is read as `./x.d.ts`, the way TypeScript reads it, and a `.ts` source file's `./x.js` as `./x.ts`, while a file that runs cannot load a declaration file: a `./x.js` that is only `./x.d.ts` in the pack is a break). It reads code, not text: comments, strings, template literals and regular expression literals are taken out first, so an `import x from '../y'` in a comment or in the source a tool writes is never mistaken for an import (a tokenizer, not a parser: an import it cannot see is missed, never invented). It runs after the build and right before `npm publish`, in the one function every package's branch calls; when it finds a problem, or cannot read the pack, it stops with nothing on the registry, lists each import, and puts back the version files the version step changed, so the next publish raises the same version and not the one after it. `npm run test:packed` (`test/packed-imports.test.mjs`) holds the reading and the real `npm pack`; `test/publish-to-npm.test.mjs` runs the real publisher in a throwaway checkout with a stand-in `npm` for the stop, the version put back, the pack that cannot be read, and the order (build, pack, publish) in every package's branch. Run on the published tarballs: `@widgetic/editor` 4.1.19 fails with the one import above and 4.1.20 passes (258 of 298 packed files read); the newest published `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `canvas`, `chat`, `editor`, `file-browser`, `workflows-engine`, `workflows`, `embed-sdk`, `ui-sdk` and `cli` all pass (`widget-creator` could not be read from the registry); on the `cli` and `ui-sdk` checkouts it takes under a second.
|
|
10
16
|
- **`@widgetic/cli` is a package of the walk.** `cli` is in `PUBLISHABLE_PACKAGES` (last: nothing bundles or loads it, and its release gate wants the contracts package the gateway publishes) and the publisher has a branch of its own for it (`packageName === 'cli'`, so it needs no sibling-layout entry: no app aliases its source). Before the version is raised it runs `npm run check` and `npm run check:release`, the gate that the commands the CLI was generated from (`@widgetic/api-contracts`) are the newest the gateway published and that production's MCP server still has the tools they describe (the gate learns that from a public document of the MCP host, with no key; a Widgetic API key made with full access is only the way for a gateway that does not publish the document yet). The gate runs in the publisher and not as `prepublishOnly` because the publish passes `--ignore-scripts`. Then it builds, publishes (public), commits the version files, tags and pushes like the other packages. `test/publish-to-npm.test.mjs` pins the order in the source and runs the real publisher in a throwaway checkout with a stand-in `npm`: a failing check and a failing gate each stop it before the version changes, and no other package runs the gate.
|
|
11
17
|
- **`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.
|
|
12
18
|
- **`publish-all-to-npm`** (`bin/publish-all-to-npm.mjs`): walks the npm packages and runs each package's `publish-to-npm` script.
|
package/README.md
CHANGED
|
@@ -8,8 +8,10 @@ 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
|
+
| `check-packed-imports` | Fails when a file `npm pack` would put in a package imports a file the package does not hold: a path out of the package, a file the build did not write, or a `$lib` alias the build left in. Such a package installs, and throws when it is loaded (`@widgetic/editor` 4.1.19 was published that way). Run it after the build, in the package folder or with the folder as its argument; the publisher runs it before every `npm publish`. Comments, strings, templates and regular expressions are never mistaken for imports. |
|
|
11
12
|
| `comment-console-logs` | Comments out the debugging `console.log`, `console.info`, `console.debug` and `console.trace` statements of a codebase and keeps every one of them in the code. Reads the code with the TypeScript and Svelte parsers of the checkout it edits, comments out only what it can without changing what the program does, and says what it kept and why. Dry run unless told to `--write`. |
|
|
12
13
|
| `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. |
|
|
14
|
+
| `sync-frontend-checkouts` | Fast-forwards every git checkout under `Frontend/` (`git pull --ff-only`) and deletes each `node_modules/.vite` so the next `npm run dev` is not serving yesterday's sibling source. A dirty working tree is committed first (file list in the message; `.env` is not staged), then pulled. From this package: `npm run sync-frontend`. From `Frontend/site`: `npm run sync-frontend`. |
|
|
13
15
|
|
|
14
16
|
It also ships two `lib/` modules with hand-written types and their own `node --test`
|
|
15
17
|
fixtures:
|
|
@@ -28,6 +30,13 @@ fixtures:
|
|
|
28
30
|
- `lib/comment-console-logs.mjs` — the rules behind `comment-console-logs`: what
|
|
29
31
|
is commented out, what is kept, and how a statement is commented out, with the
|
|
30
32
|
parsers handed in rather than depended on (`npm run test:comment-logs`).
|
|
33
|
+
- `lib/packed-imports.mjs` — the reading behind `check-packed-imports`: the files
|
|
34
|
+
`npm pack --dry-run` lists, their relative imports read as code (comments,
|
|
35
|
+
strings, templates and regular expressions taken out first), and where each one
|
|
36
|
+
lands (`npm run test:packed`).
|
|
37
|
+
- `lib/sync-frontend-checkouts.mjs` — the walk behind `sync-frontend-checkouts`:
|
|
38
|
+
which `Frontend/` children are git checkouts, when a pull is skipped, and
|
|
39
|
+
which Vite cache folders are deleted (`npm run test:sync-frontend`).
|
|
31
40
|
|
|
32
41
|
A package that is new to the `Frontend/` checkouts is named in four lists that
|
|
33
42
|
do not know about each other: the publish walk (`lib/publish-to-npm.mjs`), the
|
|
@@ -219,6 +228,33 @@ hook, and site's `lps` exists for the same purpose for its embedded
|
|
|
219
228
|
`file-browser`. Those are per-app choices about which sibling to iterate on;
|
|
220
229
|
they are not part of dev-tools setup, and no step here depends on them.
|
|
221
230
|
|
|
231
|
+
### Keeping every Frontend checkout in step
|
|
232
|
+
|
|
233
|
+
The alias tables only help when the sibling **on disk** is the one a colleague
|
|
234
|
+
already has, and when Vite is not still serving a prebundle of the files it
|
|
235
|
+
saw yesterday. `sync-frontend-checkouts` does both:
|
|
236
|
+
|
|
237
|
+
```sh
|
|
238
|
+
# from Frontend/dev-tools
|
|
239
|
+
npm run sync-frontend
|
|
240
|
+
|
|
241
|
+
# from Frontend/site (same bin)
|
|
242
|
+
npm run sync-frontend
|
|
243
|
+
|
|
244
|
+
# report only
|
|
245
|
+
npx sync-frontend-checkouts --dry-run
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
It lists every immediate child of `Frontend/` that has a `.git` directory
|
|
249
|
+
(`site`, `editor`, `widget-creator`, … — not only the packages in
|
|
250
|
+
`SIBLING_PACKAGES`). A dirty working tree is committed first (`chore` or `docs`
|
|
251
|
+
plus the file list; `.env` is not staged), then `git pull --ff-only`. Then it
|
|
252
|
+
deletes `node_modules/.vite` and `node_modules/.vite-temp`. A branch with no
|
|
253
|
+
upstream, or a history that cannot fast-forward, is named in the report.
|
|
254
|
+
`--no-commit-dirty` leaves local edits uncommitted. Restart `npm run dev` in
|
|
255
|
+
`site` (and `widget-creator`) afterwards so Vite rebuilds the dep cache against
|
|
256
|
+
the files that are actually there.
|
|
257
|
+
|
|
222
258
|
### Linked siblings: consuming built output, not source
|
|
223
259
|
|
|
224
260
|
`embed-sdk` and `ui-sdk` consume a sibling the other way round: they link a
|
|
@@ -399,7 +435,7 @@ laptop.
|
|
|
399
435
|
|
|
400
436
|
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.
|
|
401
437
|
|
|
402
|
-
`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 read from Doppler (the API gateway's production config) every time, so there is no file for them. Before it raises the version it runs `npm run release:settings` in `modules/`, which reads those settings and one object from the bucket and writes nothing, and the publish stops there when that fails: a package that is on npm with no modules to go with it is a half-done release. For embed-sdk it also uploads `dist/umd/embed-sdk-workflows.js` and `dist/umd/embed-sdk.js` to the CDN and purges them, then commits the version and `dist/`, tags, and pushes. The R2 settings for that upload are read from Doppler the same way, every time (there is no `.env.cdn` and no `--env-file`), and before the version is raised it runs `npm run publish:cdn:settings -- --purge` in embed-sdk, which reads the six settings and sends one HEAD for the SDK's object to the bucket, writes nothing, and stops the publish there when it fails, for the same reason. The other packages have no CDN file. dev-tools runs its tests before the version changes. `cli` (`@widgetic/cli`, the `widgetic` command) runs `npm run check` and then `npm run check:release` before the version changes, builds, publishes, and commits, tags and pushes the way the others do. Every command of the CLI is generated from `@widgetic/api-contracts`, the package the API gateway publishes, so `check:release` is the gate that the contracts it was generated from are the newest published and that production's MCP server still has the tools they describe (it reads that from the document production's MCP host publishes for it, public, with no key; only while production runs a gateway older than the release that adds the document does it ask the MCP server itself, with a Widgetic API key made with full access, from `WIDGETIC_API_KEY` or from the one `widgetic auth login` saved: the MCP endpoint refuses a key limited to some scopes, a read-only one included). It runs here, and not as the package's `prepublishOnly`, because the publish passes `--ignore-scripts`.
|
|
438
|
+
`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 read from Doppler (the API gateway's production config) every time, so there is no file for them. Before it raises the version it runs `npm run release:settings` in `modules/`, which reads those settings and one object from the bucket and writes nothing, and the publish stops there when that fails: a package that is on npm with no modules to go with it is a half-done release. For embed-sdk it also uploads `dist/umd/embed-sdk-workflows.js` and `dist/umd/embed-sdk.js` to the CDN and purges them, then commits the version and `dist/`, tags, and pushes. The R2 settings for that upload are read from Doppler the same way, every time (there is no `.env.cdn` and no `--env-file`), and before the version is raised it runs `npm run publish:cdn:settings -- --purge` in embed-sdk, which reads the six settings and sends one HEAD for the SDK's object to the bucket, writes nothing, and stops the publish there when it fails, for the same reason. The other packages have no CDN file. dev-tools runs its tests before the version changes. `cli` (`@widgetic/cli`, the `widgetic` command) runs `npm run check` and then `npm run check:release` before the version changes, builds, publishes, and commits, tags and pushes the way the others do. Every command of the CLI is generated from `@widgetic/api-contracts`, the package the API gateway publishes, so `check:release` is the gate that the contracts it was generated from are the newest published and that production's MCP server still has the tools they describe (it reads that from the document production's MCP host publishes for it, public, with no key; only while production runs a gateway older than the release that adds the document does it ask the MCP server itself, with a Widgetic API key made with full access, from `WIDGETIC_API_KEY` or from the one `widgetic auth login` saved: the MCP endpoint refuses a key limited to some scopes, a read-only one included). It runs here, and not as the package's `prepublishOnly`, because the publish passes `--ignore-scripts`. Right before `npm publish`, every package is read once more: the publisher asks `npm pack --dry-run` which files would go and reads their imports (`check-packed-imports`), and it stops, with nothing on the registry and the version it had raised put back, when a packed file imports a file the package does not hold.
|
|
403
439
|
|
|
404
440
|
From one package, publish only that package:
|
|
405
441
|
|
|
@@ -413,7 +449,7 @@ From `dev-tools`, walk every package:
|
|
|
413
449
|
npm run publish-all-to-npm
|
|
414
450
|
```
|
|
415
451
|
|
|
416
|
-
The walk is `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `canvas`, `chat`, `editor`, `file-browser`, `widget-creator`, `workflows-engine`, `workflows`, `embed-sdk`, `ui-sdk` and `cli`. `site` is not in it. These are the npm packages. The API SDK for Python, Ruby, C#, Java, PHP and Go is published from `api-gateway-service` with `scripts/publish-public-sdks.sh`, not by this walk.
|
|
452
|
+
The walk is `api-sdk`, `cache-layer`, `design-system`, `dev-tools`, `brand`, `canvas`, `chat`, `editor`, `file-browser`, `widget-creator`, `workflows-engine`, `workflows`, `embed-sdk`, `ui-sdk` and `cli`. `site` is not in it. These are the npm packages. The API SDK for Python, Ruby, C#, Java, PHP and Go is published from `api-gateway-service` with `scripts/publish-public-sdks.sh`, not by this walk.
|
|
417
453
|
|
|
418
454
|
## Releasing
|
|
419
455
|
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fails when a file `npm pack` would put in a package imports a file the package does not hold.
|
|
4
|
+
*
|
|
5
|
+
* Usage: check-packed-imports [package-dir] (the current directory when none is given)
|
|
6
|
+
*
|
|
7
|
+
* Run it after the build: it reads what `npm pack --dry-run` lists, so a `dist/` that is not built is a package without it.
|
|
8
|
+
* The publisher (`publish-package.mjs`) runs the same check before every `npm publish`. Exit 0 when every relative import of
|
|
9
|
+
* the packed files lands on a packed file, 1 when one does not, 2 when the pack could not be read.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { checkPackedImports, describePackedImportProblems } from '../lib/packed-imports.mjs';
|
|
14
|
+
|
|
15
|
+
const packageDir = resolve(process.argv[2] ?? process.cwd());
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const { packedCount, scannedCount, problems } = checkPackedImports(packageDir);
|
|
19
|
+
if (problems.length > 0) {
|
|
20
|
+
console.error(`[check-packed-imports] ${problems.length} import(s) of the packed files cannot be loaded from the installed package:`);
|
|
21
|
+
for (const line of describePackedImportProblems(problems)) console.error(` - ${line}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
console.log(`[check-packed-imports] ok: ${scannedCount} of ${packedCount} packed files read, every relative import lands on a packed file (${packageDir})`);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`[check-packed-imports] could not read the pack of ${packageDir}: ${error instanceof Error ? error.message : String(error)}`);
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
File without changes
|
package/bin/publish-package.mjs
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* server still has the tools it was generated from, which it learns from a
|
|
12
12
|
* public document, with no key) before the version changes.
|
|
13
13
|
* Every other package builds, or packages, then publishes.
|
|
14
|
+
* Every package is read once more right before `npm publish`: the files `npm pack` would take must only import files
|
|
15
|
+
* the package holds (lib/packed-imports.mjs). One that does not stops the publish with nothing on the registry.
|
|
14
16
|
*
|
|
15
17
|
* The script fetches origin first. When that branch has commits this checkout
|
|
16
18
|
* does not, it merges them. A conflict stops the publish. It does nothing when
|
|
@@ -23,12 +25,13 @@
|
|
|
23
25
|
import { spawnSync } from 'node:child_process';
|
|
24
26
|
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
25
27
|
import { basename, join } from 'node:path';
|
|
28
|
+
import { checkPackedImports, describePackedImportProblems } from '../lib/packed-imports.mjs';
|
|
26
29
|
|
|
27
30
|
const packageDir = process.cwd();
|
|
28
31
|
const packageName = basename(packageDir);
|
|
29
32
|
|
|
30
33
|
const BUILD_PACKAGES = new Set(['api-sdk', 'cache-layer', 'design-system', 'workflows-engine']);
|
|
31
|
-
const PACKAGE_PACKAGES = new Set(['canvas', 'chat', 'editor', 'file-browser', 'widget-creator', 'workflows']);
|
|
34
|
+
const PACKAGE_PACKAGES = new Set(['brand', 'canvas', 'chat', 'editor', 'file-browser', 'widget-creator', 'workflows']);
|
|
32
35
|
|
|
33
36
|
/**
|
|
34
37
|
* Run a command and stop the publish when it fails.
|
|
@@ -97,7 +100,53 @@ function tagAndPush() {
|
|
|
97
100
|
run('git', ['push', 'origin', 'HEAD', tag]);
|
|
98
101
|
}
|
|
99
102
|
|
|
103
|
+
/**
|
|
104
|
+
* Puts back the files the version step changed (`npm version`, and the SDK_VERSION line of ui-sdk) when a check that comes
|
|
105
|
+
* after it stops the publish: nothing of the version is committed, so the next publish raises the same version and not
|
|
106
|
+
* the one after it.
|
|
107
|
+
*/
|
|
108
|
+
function restoreVersionFiles() {
|
|
109
|
+
const tracked = ['package.json', 'package-lock.json', 'src/sdk/version.ts'].filter(
|
|
110
|
+
(path) =>
|
|
111
|
+
existsSync(join(packageDir, path)) &&
|
|
112
|
+
spawnSync('git', ['ls-files', '--error-unmatch', '--', path], { cwd: packageDir }).status === 0
|
|
113
|
+
);
|
|
114
|
+
if (tracked.length === 0) return;
|
|
115
|
+
spawnSync('git', ['checkout', '--', ...tracked], { cwd: packageDir, stdio: 'inherit' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Stops the publish, with nothing on the registry, when a file that `npm pack` would take imports a file the package does
|
|
120
|
+
* not hold, or an alias that only exists in the source tree. The build has run by now, so the pack is the one that would go.
|
|
121
|
+
*/
|
|
122
|
+
function verifyPackedImports() {
|
|
123
|
+
console.log(`[publish-package] ${packageName}: checking that the packed files only import files of the package`);
|
|
124
|
+
let result;
|
|
125
|
+
try {
|
|
126
|
+
result = checkPackedImports(packageDir);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
restoreVersionFiles();
|
|
129
|
+
console.error(
|
|
130
|
+
`[publish-package] ${packageName}: could not read what npm would pack: ${error instanceof Error ? error.message : String(error)}`
|
|
131
|
+
);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
if (result.problems.length === 0) {
|
|
135
|
+
console.log(
|
|
136
|
+
`[publish-package] ${packageName}: ${result.scannedCount} of ${result.packedCount} packed files read, no import leaves the package`
|
|
137
|
+
);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
restoreVersionFiles();
|
|
141
|
+
console.error(
|
|
142
|
+
`[publish-package] ${packageName}: ${result.problems.length} import(s) of the packed files cannot be loaded from the installed package. Nothing was published.`
|
|
143
|
+
);
|
|
144
|
+
for (const line of describePackedImportProblems(result.problems)) console.error(` - ${line}`);
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
147
|
+
|
|
100
148
|
function publishToNpm() {
|
|
149
|
+
verifyPackedImports();
|
|
101
150
|
// api-sdk is the internal client. Packages with publishConfig.access="restricted" also stay restricted.
|
|
102
151
|
const manifest = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8'));
|
|
103
152
|
const access =
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fast-forward every git checkout under `Frontend/` and drop Vite's dep caches.
|
|
4
|
+
*
|
|
5
|
+
* npx sync-frontend-checkouts
|
|
6
|
+
* npx sync-frontend-checkouts --dry-run
|
|
7
|
+
* npx sync-frontend-checkouts --skip-pull
|
|
8
|
+
* npx sync-frontend-checkouts --skip-clean
|
|
9
|
+
* npx sync-frontend-checkouts --frontend-root /path/to/Frontend
|
|
10
|
+
*
|
|
11
|
+
* From `Frontend/site` the same command is `npm run sync-frontend`.
|
|
12
|
+
*
|
|
13
|
+
* A dirty working tree is committed first (secrets such as `.env` stay unstaged),
|
|
14
|
+
* then pulled. Vite caches are still removed, because they are generated files.
|
|
15
|
+
* `--no-commit-dirty` restores the old skip.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { resolve } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { parseArgs } from 'node:util';
|
|
21
|
+
|
|
22
|
+
import { syncFrontendCheckouts } from '../lib/sync-frontend-checkouts.mjs';
|
|
23
|
+
|
|
24
|
+
const LOG_PREFIX = '[sync-frontend-checkouts]';
|
|
25
|
+
|
|
26
|
+
const USAGE = `Usage: sync-frontend-checkouts [--dry-run] [--skip-pull] [--skip-clean] [--no-commit-dirty] [--frontend-root <dir>]
|
|
27
|
+
|
|
28
|
+
--dry-run Report what would be pulled and deleted. Touch nothing.
|
|
29
|
+
--skip-pull Do not run git pull. Still clean Vite caches unless --skip-clean.
|
|
30
|
+
--skip-clean Do not delete node_modules/.vite. Still pull unless --skip-pull.
|
|
31
|
+
--no-commit-dirty Leave a dirty working tree alone (old behaviour). Default is to commit it, then pull.
|
|
32
|
+
--frontend-root <dir> The Frontend/ directory (default: the parent of this package).
|
|
33
|
+
-h, --help Show this text.
|
|
34
|
+
|
|
35
|
+
Walks every immediate child of Frontend/ that has a .git directory. A dirty tree
|
|
36
|
+
is committed (chore/docs subject plus the file list; .env is not staged), then
|
|
37
|
+
git pull --ff-only. Then deletes node_modules/.vite and node_modules/.vite-temp
|
|
38
|
+
so the next npm run dev does not keep serving a prebundle of older sibling source.
|
|
39
|
+
Restart the site (and widget-creator) after it finishes.`;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @returns {number} Exit code.
|
|
43
|
+
*/
|
|
44
|
+
function main() {
|
|
45
|
+
/** @type {ReturnType<typeof parseArgs>} */
|
|
46
|
+
let parsedArguments;
|
|
47
|
+
try {
|
|
48
|
+
parsedArguments = parseArgs({
|
|
49
|
+
args: process.argv.slice(2),
|
|
50
|
+
allowPositionals: false,
|
|
51
|
+
options: {
|
|
52
|
+
'dry-run': { type: 'boolean', default: false },
|
|
53
|
+
'skip-pull': { type: 'boolean', default: false },
|
|
54
|
+
'skip-clean': { type: 'boolean', default: false },
|
|
55
|
+
'no-commit-dirty': { type: 'boolean', default: false },
|
|
56
|
+
'frontend-root': { type: 'string' },
|
|
57
|
+
help: { type: 'boolean', short: 'h', default: false }
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`${LOG_PREFIX} ${/** @type {Error} */ (error).message}\n\n${USAGE}`);
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { values } = parsedArguments;
|
|
66
|
+
if (values.help) {
|
|
67
|
+
console.log(USAGE);
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const thisPackage = fileURLToPath(new URL('..', import.meta.url));
|
|
72
|
+
const frontendRoot = resolve(
|
|
73
|
+
typeof values['frontend-root'] === 'string' ? values['frontend-root'] : resolve(thisPackage, '..')
|
|
74
|
+
);
|
|
75
|
+
const dryRun = values['dry-run'] === true;
|
|
76
|
+
const pull = values['skip-pull'] !== true;
|
|
77
|
+
const cleanVite = values['skip-clean'] !== true;
|
|
78
|
+
const commitDirty = values['no-commit-dirty'] !== true;
|
|
79
|
+
|
|
80
|
+
console.log(`${LOG_PREFIX} Frontend root: ${frontendRoot}${dryRun ? ' (dry run)' : ''}`);
|
|
81
|
+
const results = syncFrontendCheckouts({ frontendRoot, pull, cleanVite, dryRun, commitDirty });
|
|
82
|
+
if (results.length === 0) {
|
|
83
|
+
console.error(`${LOG_PREFIX} no git checkouts found under ${frontendRoot}`);
|
|
84
|
+
return 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let failed = 0;
|
|
88
|
+
for (const row of results) {
|
|
89
|
+
const cacheCount = dryRun ? row.cachesWouldRemove.length : row.cachesRemoved.length;
|
|
90
|
+
const cacheNote = cleanVite
|
|
91
|
+
? cacheCount > 0
|
|
92
|
+
? `${dryRun ? 'would remove' : 'removed'} ${cacheCount} Vite cache${cacheCount === 1 ? '' : 's'}`
|
|
93
|
+
: 'no Vite cache'
|
|
94
|
+
: 'cache left alone';
|
|
95
|
+
const pullNote = pull ? `${row.pull}${row.pullDetail ? ` (${row.pullDetail})` : ''}` : 'pull skipped';
|
|
96
|
+
const commitNote = row.committed ? `; committed ${row.commitDetail ?? ''}` : '';
|
|
97
|
+
console.log(`${LOG_PREFIX} ${row.name}: ${pullNote}${commitNote}; ${cacheNote}`);
|
|
98
|
+
if (row.pull === 'failed') failed += 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (failed > 0) {
|
|
102
|
+
console.error(`${LOG_PREFIX} ${failed} checkout${failed === 1 ? '' : 's'} could not fast-forward. Fix those by hand, then run again.`);
|
|
103
|
+
return 1;
|
|
104
|
+
}
|
|
105
|
+
if (!dryRun && cleanVite) {
|
|
106
|
+
console.log(`${LOG_PREFIX} done. Restart npm run dev in site (and widget-creator) so Vite rebuilds the dep cache.`);
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
process.exit(main());
|
package/lib/frontend-layout.mjs
CHANGED
|
@@ -46,8 +46,23 @@
|
|
|
46
46
|
*/
|
|
47
47
|
export const SIBLING_PACKAGES = {
|
|
48
48
|
'api-sdk': { dir: 'api-sdk', entry: 'src/index.ts' },
|
|
49
|
+
// The Scribble Mascot and the other brand assets. Consumers take it from npm; the entry lets an app alias its source in dev.
|
|
50
|
+
brand: {
|
|
51
|
+
dir: 'brand',
|
|
52
|
+
lib: 'src/lib',
|
|
53
|
+
subpaths: {
|
|
54
|
+
mascot: 'mascot',
|
|
55
|
+
scribble: 'scribble'
|
|
56
|
+
}
|
|
57
|
+
},
|
|
49
58
|
'cache-layer': { dir: 'cache-layer', entry: 'src/index.ts' },
|
|
50
|
-
canvas: {
|
|
59
|
+
canvas: {
|
|
60
|
+
dir: 'canvas',
|
|
61
|
+
lib: 'src/lib',
|
|
62
|
+
subpaths: {
|
|
63
|
+
tools: 'tools'
|
|
64
|
+
}
|
|
65
|
+
},
|
|
51
66
|
// `dir` was `prompt-chat` when the package was created (see older configs).
|
|
52
67
|
chat: { dir: 'chat', lib: 'src/lib' },
|
|
53
68
|
creator: { dir: 'widget-creator', lib: 'src/lib' },
|
|
@@ -76,7 +91,17 @@ export const SIBLING_PACKAGES = {
|
|
|
76
91
|
i18n: 'i18n',
|
|
77
92
|
// The right to left kit: the source audit (`rtl/audit`) that the tests of every package read their
|
|
78
93
|
// source through. A prefix match as well, and for the same reason as `i18n` above.
|
|
79
|
-
rtl: 'rtl'
|
|
94
|
+
rtl: 'rtl',
|
|
95
|
+
// Ghost text after the caret of a text box (the engine, its `use:` action, the sources that ask the gateway, the
|
|
96
|
+
// outcome counts), and the mirror layer it draws on. Explicit exports of the package that the creator, the site and
|
|
97
|
+
// the hosts of the assistants import by name; without the entries the bare-index alias swallows them, for the same
|
|
98
|
+
// reason as `i18n` above, and turns them into `<lib>/index.ts/inline-completion`.
|
|
99
|
+
'inline-completion': 'inline-completion',
|
|
100
|
+
'textarea-overlay': 'textarea-overlay',
|
|
101
|
+
// References to attached files inside a prompt box (`#` opens the list of files, a badge with the picture stands in the
|
|
102
|
+
// text): the pure model, the `use:` action and the badge's look, an explicit export that the chat, the creator and the
|
|
103
|
+
// workflows assistant import by name. Same reason as `inline-completion` above.
|
|
104
|
+
'prompt-references': 'prompt-references'
|
|
80
105
|
}
|
|
81
106
|
},
|
|
82
107
|
// `dir` was `props-editor` (see older configs — and dangling symlinks).
|