@north-light/crouter 0.3.319 → 0.3.320
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/package.json +2 -1
- package/runtime.lock.json +5 -5
- package/scripts/pack-minify.mjs +108 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/crouter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.320",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"scripts/postinstall.mjs",
|
|
69
69
|
"scripts/patch-pi-tree-root-ordering.mjs",
|
|
70
70
|
"scripts/install-runtime.mjs",
|
|
71
|
+
"scripts/pack-minify.mjs",
|
|
71
72
|
"scripts/runtime-lock.mjs",
|
|
72
73
|
"scripts/self-update.mjs",
|
|
73
74
|
"runtime.lock.json"
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/crouter",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.320",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/crouter",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.320",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"workspaces": [
|
|
@@ -5206,17 +5206,17 @@
|
|
|
5206
5206
|
},
|
|
5207
5207
|
"packages/crouter-api": {
|
|
5208
5208
|
"name": "@north-light/crouter-api",
|
|
5209
|
-
"version": "0.3.
|
|
5209
|
+
"version": "0.3.320",
|
|
5210
5210
|
"license": "UNLICENSED"
|
|
5211
5211
|
},
|
|
5212
5212
|
"packages/crouter-env-docker": {
|
|
5213
5213
|
"name": "@north-light/crouter-env-docker",
|
|
5214
|
-
"version": "0.3.
|
|
5214
|
+
"version": "0.3.320",
|
|
5215
5215
|
"license": "UNLICENSED"
|
|
5216
5216
|
},
|
|
5217
5217
|
"packages/crouter-sdk": {
|
|
5218
5218
|
"name": "@north-light/crouter-sdk",
|
|
5219
|
-
"version": "0.3.
|
|
5219
|
+
"version": "0.3.320",
|
|
5220
5220
|
"license": "UNLICENSED",
|
|
5221
5221
|
"dependencies": {
|
|
5222
5222
|
"@north-light/crouter-api": "^0.3.295"
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Minify the packed dist, and ONLY when CRTR_PACK_MINIFY=1.
|
|
3
|
+
//
|
|
4
|
+
// OFF BY DEFAULT because `npm run install-runtime` builds every local
|
|
5
|
+
// generation by running `npm pack` on this repo (scripts/install-runtime.mjs,
|
|
6
|
+
// `pack()`). An unconditional prepack minify would therefore minify the
|
|
7
|
+
// runtime a developer actually runs, and with no source maps emitted and
|
|
8
|
+
// `src/` not packed, every stack trace in a live daemon log would collapse to
|
|
9
|
+
// `file.js:1:<column>`. The flag keeps local generations readable and moves
|
|
10
|
+
// minification to the published tarball alone.
|
|
11
|
+
//
|
|
12
|
+
// .github/workflows/publish.yml sets the flag in BOTH places that produce a
|
|
13
|
+
// release tarball — the `publish` job and the docker job's `npm pack` step —
|
|
14
|
+
// because docker/README.md's CRTR_PACKAGE_FILE path depends on those two
|
|
15
|
+
// tarballs being identical.
|
|
16
|
+
//
|
|
17
|
+
// This script must stay listed in package.json#files. `prepack` runs it, and
|
|
18
|
+
// scripts/install-runtime.mjs builds a generation by running `npm pack` on the
|
|
19
|
+
// INSTALLED package — so a published tarball without this file makes both the
|
|
20
|
+
// crtrd image build and `crtr sys self-update` fail on a missing module.
|
|
21
|
+
//
|
|
22
|
+
// `keepNames` is not optional. Function and class names survive into stack
|
|
23
|
+
// traces and are what makes a daemon log from a published generation legible
|
|
24
|
+
// at all, since no source maps are emitted and `src/` is not packed.
|
|
25
|
+
import { cp, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
26
|
+
import { globSync } from 'node:fs';
|
|
27
|
+
import { dirname, join, resolve } from 'node:path';
|
|
28
|
+
import { fileURLToPath } from 'node:url';
|
|
29
|
+
import { transform } from 'esbuild';
|
|
30
|
+
|
|
31
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
32
|
+
const DIST = join(ROOT, 'dist');
|
|
33
|
+
const BACKUP = join(ROOT, '.dist-unminified');
|
|
34
|
+
|
|
35
|
+
async function isDirectory(path) {
|
|
36
|
+
try {
|
|
37
|
+
return (await stat(path)).isDirectory();
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Files the tarball ships as executable JavaScript.
|
|
44
|
+
*
|
|
45
|
+
* - `builtin-pi-packages/` is copied source that pi loads on its own terms,
|
|
46
|
+
* not part of the compiled graph.
|
|
47
|
+
* - `clients/attach/viewer.js` is already an esbuild bundle built with
|
|
48
|
+
* `minify: true`; re-minifying 9 MiB buys nothing and risks its banner.
|
|
49
|
+
* - `__tests__/` is excluded from `package.json#files`, so it is not packed. */
|
|
50
|
+
function packedJavaScript() {
|
|
51
|
+
return globSync('**/*.js', { cwd: DIST }).filter(
|
|
52
|
+
(rel) =>
|
|
53
|
+
!rel.startsWith('builtin-pi-packages/') &&
|
|
54
|
+
rel !== 'clients/attach/viewer.js' &&
|
|
55
|
+
!rel.split('/').includes('__tests__'),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function restore() {
|
|
60
|
+
if (!(await isDirectory(BACKUP))) return false;
|
|
61
|
+
await rm(DIST, { recursive: true, force: true });
|
|
62
|
+
await rename(BACKUP, DIST);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const mode = process.argv[2];
|
|
67
|
+
|
|
68
|
+
if (mode === 'prepack') {
|
|
69
|
+
// A pack that crashed before postpack leaves a minified dist beside the
|
|
70
|
+
// backup. Restore first — unconditionally, even when minification is off —
|
|
71
|
+
// so this run minifies readable input rather than minifying already-minified
|
|
72
|
+
// output and losing the readable tree for good.
|
|
73
|
+
await restore();
|
|
74
|
+
if (process.env.CRTR_PACK_MINIFY !== '1') process.exit(0);
|
|
75
|
+
if (!(await isDirectory(DIST))) throw new Error('dist/ is missing — run `npm run build` before packing');
|
|
76
|
+
|
|
77
|
+
await cp(DIST, BACKUP, { recursive: true });
|
|
78
|
+
try {
|
|
79
|
+
const files = packedJavaScript();
|
|
80
|
+
let before = 0;
|
|
81
|
+
let after = 0;
|
|
82
|
+
await Promise.all(
|
|
83
|
+
files.map(async (rel) => {
|
|
84
|
+
const path = join(DIST, rel);
|
|
85
|
+
const source = await readFile(path, 'utf8');
|
|
86
|
+
before += Buffer.byteLength(source);
|
|
87
|
+
const { code } = await transform(source, {
|
|
88
|
+
minify: true,
|
|
89
|
+
keepNames: true,
|
|
90
|
+
format: 'esm',
|
|
91
|
+
target: 'node22',
|
|
92
|
+
loader: 'js',
|
|
93
|
+
});
|
|
94
|
+
after += Buffer.byteLength(code);
|
|
95
|
+
await writeFile(path, code);
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
const mib = (bytes) => (bytes / 1048576).toFixed(1);
|
|
99
|
+
console.log(`pack-minify: ${files.length} files, ${mib(before)} MiB -> ${mib(after)} MiB`);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
await restore();
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
} else if (mode === 'postpack') {
|
|
105
|
+
await restore();
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error('usage: pack-minify.mjs <prepack|postpack>');
|
|
108
|
+
}
|