Skip to content

Commit 4fcf424

Browse files
committed
refactor(toolkit): dispatch toolkit-js compact variants on full patch version
toolkit-js now selects its compact-js variant on the full <major>.<minor>.<patch> compactc version instead of truncating to <major>.<minor>, since a compactc patch can ship a contract format expecting a different compact-js patch. Renames the variant workspaces (compact-0.29 -> compact-0.29.0, etc.), strips any tree-hash suffix from COMPACTC_VERSION when matching, and errors on unsupported patches. Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Oscar Bailey <79094698+ozgb@users.noreply.github.com>
1 parent 1b516c0 commit 4fcf424

15 files changed

Lines changed: 224 additions & 264 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#toolkit #compactc
2+
# Dispatch toolkit-js compact variants on the full patch version
3+
4+
toolkit-js now selects its `@midnight-ntwrk/compact-js*` variant on the full
5+
`<major>.<minor>.<patch>` compactc version instead of truncating to
6+
`<major>.<minor>`. A compactc patch can ship a contract format that expects a
7+
different `compact-js` patch, so the previous "compact-js is patch-stable within a
8+
minor line" assumption no longer holds.
9+
10+
The variant workspaces are renamed accordingly:
11+
- `compact-0.29/``compact-0.29.0/` (compact-js 2.4.3)
12+
- `compact-0.30/``compact-0.30.0/` (compact-js 2.5.0)
13+
- `compact-0.31/``compact-0.31.0/` (compact-js 2.5.1)
14+
15+
`resolveCompactcVersion` now keeps the leading `<major>.<minor>.<patch>` and drops
16+
any trailing build/tree-hash suffix (e.g. `0.31.0-6587676a9bb2`, the form the dev
17+
shell exports from the root `COMPACTC_VERSION` file). An unsupported patch such as
18+
`0.31.1` now errors loudly rather than silently mapping to the minor line.
19+
20+
`SUPPORTED_COMPACTC_VERSIONS`, the root `package.json` dependencies, each variant's
21+
package name, the regenerated `package-lock.json`, the `test-all-compactc.sh`
22+
comments, and the README maintenance docs all use the full-patch naming. The
23+
`compact-*` workspace glob and `node-toolkit-compact-*` build filter pick the
24+
renamed workspaces up automatically.
25+
26+
PR:
27+
Issue:

util/toolkit-js/README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -226,26 +226,28 @@ transitively, a matching `@midnight-ntwrk/compact-runtime`). To let one toolkit
226226
different `compactc` versions, each supported version has its own sibling workspace that pins that line:
227227

228228
```
229-
compact-0.29/ → @midnight-ntwrk/compact-js* 2.4.3
230-
compact-0.30/ → @midnight-ntwrk/compact-js* 2.5.0
231-
compact-0.31/ → @midnight-ntwrk/compact-js* 2.5.1
229+
compact-0.29.0/ → @midnight-ntwrk/compact-js* 2.4.3
230+
compact-0.30.0/ → @midnight-ntwrk/compact-js* 2.5.0
231+
compact-0.31.0/ → @midnight-ntwrk/compact-js* 2.5.1
232232
```
233233

234-
The root package depends on every variant (`@midnight-ntwrk/node-toolkit-compact-<major>.<minor>`). At runtime,
235-
`src/compactc-resolver.ts` reads `COMPACTC_VERSION`, picks the matching variant, and installs a module-resolution
236-
hook that redirects **every** `@midnight-ntwrk/compact-js*` / `@midnight-ntwrk/compact-runtime` import — including
237-
the transitive ones reached while a `contract.config.ts` is loaded — to that variant's pinned copy. `src/bin.ts`
238-
(the CLI) and `test/setup-compactc-resolver.ts` (the tests) both use this single resolver, so tests exercise the
239-
same dispatch as production.
234+
The root package depends on every variant (`@midnight-ntwrk/node-toolkit-compact-<major>.<minor>.<patch>`). At
235+
runtime, `src/compactc-resolver.ts` reads `COMPACTC_VERSION`, picks the matching variant, and installs a
236+
module-resolution hook that redirects **every** `@midnight-ntwrk/compact-js*` / `@midnight-ntwrk/compact-runtime`
237+
import — including the transitive ones reached while a `contract.config.ts` is loaded — to that variant's pinned
238+
copy. `src/bin.ts` (the CLI) and `test/setup-compactc-resolver.ts` (the tests) both use this single resolver, so
239+
tests exercise the same dispatch as production.
240240

241-
`COMPACTC_VERSION` accepts either `<major>.<minor>` or the full `<major>.<minor>.<patch>` form; dispatch is on
242-
`<major>.<minor>` only, since `compact-js` is patch-stable within a minor line.
241+
Dispatch is on the full `<major>.<minor>.<patch>` version, since a `compactc` patch can ship a contract format
242+
that expects a different `@midnight-ntwrk/compact-js` patch. `COMPACTC_VERSION` may also carry a trailing
243+
build/tree-hash suffix (e.g. `0.31.0-6587676a9bb2`, the form stored in the root `COMPACTC_VERSION` file); only the
244+
leading `<major>.<minor>.<patch>` is matched.
243245

244246
### Adding support for a new `compactc` version
245247

246-
1. **Create the variant workspace.** Copy an existing one, e.g. `cp -r compact-0.31 compact-<major>.<minor>`.
248+
1. **Create the variant workspace.** Copy an existing one, e.g. `cp -r compact-0.31.0 compact-<major>.<minor>.<patch>`.
247249
In its `package.json`:
248-
- set `"name"` to `@midnight-ntwrk/node-toolkit-compact-<major>.<minor>`;
250+
- set `"name"` to `@midnight-ntwrk/node-toolkit-compact-<major>.<minor>.<patch>`;
249251
- pin `@midnight-ntwrk/compact-js`, `@midnight-ntwrk/compact-js-command`, and `@midnight-ntwrk/compact-js-node`
250252
to the line that targets the new `compactc`;
251253
- align the `@effect/*` versions (`@effect/cli`, `@effect/platform-node`) with what that `compact-js` line
@@ -259,8 +261,8 @@ same dispatch as production.
259261
default baked into the resolver.
260262

261263
3. **Depend on the variant** from the root `package.json` `dependencies`
262-
(`"@midnight-ntwrk/node-toolkit-compact-<major>.<minor>": "^0.1.0"`). The `compact-*` workspaces glob picks it
263-
up automatically.
264+
(`"@midnight-ntwrk/node-toolkit-compact-<major>.<minor>.<patch>": "^0.1.0"`). The `compact-*` workspaces glob
265+
picks it up automatically.
264266

265267
4. **Add the concrete patch version** to `DEFAULT_VERSIONS` in `scripts/test-all-compactc.sh`.
266268

@@ -272,7 +274,7 @@ same dispatch as production.
272274
```
273275

274276
To drop an old version, reverse these steps: remove it from `SUPPORTED_COMPACTC_VERSIONS`, the root dependency,
275-
and the test script, then delete the `compact-<major>.<minor>/` workspace.
277+
and the test script, then delete the `compact-<major>.<minor>.<patch>/` workspace.
276278

277279
> [!IMPORTANT]
278280
> The CLI option surface can change between `compactc`/`compact-js-command` versions. For example, the global

util/toolkit-js/compact-0.29/package.json renamed to util/toolkit-js/compact-0.29.0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@midnight-ntwrk/node-toolkit-compact-0.29",
2+
"name": "@midnight-ntwrk/node-toolkit-compact-0.29.0",
33
"version": "0.1.0",
44
"license": "Apache-2.0",
55
"description": "Interface gateway between Rust `midnight-node-toolkit` and TS `@midnight-ntwrk` packages",
File renamed without changes.
File renamed without changes.

util/toolkit-js/compact-0.30/package.json renamed to util/toolkit-js/compact-0.30.0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@midnight-ntwrk/node-toolkit-compact-0.30",
2+
"name": "@midnight-ntwrk/node-toolkit-compact-0.30.0",
33
"version": "0.1.0",
44
"license": "Apache-2.0",
55
"description": "Interface gateway between Rust `midnight-node-toolkit` and TS `@midnight-ntwrk` packages",
File renamed without changes.
File renamed without changes.

util/toolkit-js/compact-0.31/package.json renamed to util/toolkit-js/compact-0.31.0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@midnight-ntwrk/node-toolkit-compact-0.31",
2+
"name": "@midnight-ntwrk/node-toolkit-compact-0.31.0",
33
"version": "0.1.0",
44
"license": "Apache-2.0",
55
"description": "Interface gateway between Rust `midnight-node-toolkit` and TS `@midnight-ntwrk` packages",
File renamed without changes.

0 commit comments

Comments
 (0)