@gjsify/cli 0.22.0 → 0.23.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 +24 -1
- package/dist/cli.gjs.mjs +257 -184
- package/lib/bundler-pick.js +12 -4
- package/lib/commands/affected.js +22 -10
- package/lib/commands/check.js +38 -29
- package/lib/commands/flatpak/build.js +19 -18
- package/lib/commands/foreach.js +48 -41
- package/lib/commands/info.js +11 -5
- package/lib/commands/install.d.ts +16 -0
- package/lib/commands/install.js +103 -32
- package/lib/commands/onboard.js +6 -1
- package/lib/commands/pack.js +69 -4
- package/lib/commands/run.js +26 -14
- package/lib/commands/trust.js +4 -62
- package/lib/commands/workspace.js +49 -30
- package/lib/utils/bin-shim.d.ts +66 -0
- package/lib/utils/bin-shim.js +246 -0
- package/lib/utils/build-cache.d.ts +42 -6
- package/lib/utils/build-cache.js +114 -42
- package/lib/utils/detect-native-packages.d.ts +112 -6
- package/lib/utils/detect-native-packages.js +201 -29
- package/lib/utils/install-backend-native.d.ts +24 -0
- package/lib/utils/install-backend-native.js +89 -16
- package/lib/utils/install-global.d.ts +16 -0
- package/lib/utils/install-global.js +58 -8
- package/lib/utils/oxc-resolve.js +18 -55
- package/lib/utils/publish-headers.d.ts +2 -3
- package/lib/utils/publish-headers.js +64 -3
- package/lib/utils/publishable-packages.d.ts +22 -0
- package/lib/utils/publishable-packages.js +93 -0
- package/lib/utils/run-gjs.d.ts +6 -7
- package/lib/utils/run-gjs.js +4 -3
- package/lib/utils/spawn.d.ts +82 -0
- package/lib/utils/spawn.js +139 -0
- package/lib/utils/stdin.d.ts +25 -0
- package/lib/utils/stdin.js +132 -0
- package/package.json +23 -18
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Read ALL of stdin, on Node AND inside the committed GJS bundles.
|
|
3
|
+
//
|
|
4
|
+
// `readFileSync(0, 'utf-8')` is the Node idiom for "slurp stdin", and it is
|
|
5
|
+
// what `gjsify affected --changed-from-stdin` used. It does NOT survive the
|
|
6
|
+
// GJS bundle: `@gjsify/fs` has no numeric-file-descriptor path, so the `0` is
|
|
7
|
+
// coerced to a PATH and the call opens the relative file `./0` — every GJS
|
|
8
|
+
// caller died with
|
|
9
|
+
//
|
|
10
|
+
// Error: ENOENT: … read '0' (readStdinLines → readFileSync)
|
|
11
|
+
//
|
|
12
|
+
// which silently disabled the ONE fixture-driven entry point AGENTS.md
|
|
13
|
+
// documents for testing the CI classifier (`--changed-from-stdin`).
|
|
14
|
+
//
|
|
15
|
+
// Under GJS we therefore read fd 0 through `GioUnix.InputStream`. Two
|
|
16
|
+
// deliberate choices:
|
|
17
|
+
//
|
|
18
|
+
// - `globalThis.imports.gi.GioUnix` rather than a `gi://GioUnix` import.
|
|
19
|
+
// `packages/infra/cli/lib/**` is ALSO the Node entry point of
|
|
20
|
+
// `@gjsify/cli` (`bin: lib/index.js`); a static `gi://` import anywhere
|
|
21
|
+
// reachable from it breaks `gjsify` on Node, and a dynamic one would need
|
|
22
|
+
// an `@girs/giounix-2.0` type dependency the CLI does not otherwise have.
|
|
23
|
+
// The legacy `imports.gi` form is the sanctioned GJS-bootstrap escape
|
|
24
|
+
// hatch (AGENTS.md "Reading globals", exception 4) and adds NO new typelib
|
|
25
|
+
// to the classifier bundle — `gi://GioUnix?version=2.0` is already in its
|
|
26
|
+
// import graph via `@gjsify/fs`.
|
|
27
|
+
// - a synchronous read. The callers are CLI argument-parsing paths that run
|
|
28
|
+
// before any main loop exists, and the async `process.stdin` route carries
|
|
29
|
+
// the documented resume/pause races (see `utils/prompt.ts`).
|
|
30
|
+
import { readFileSync } from 'node:fs';
|
|
31
|
+
const CHUNK = 64 * 1024;
|
|
32
|
+
/** Read fd 0 to EOF under GJS via GioUnix (no `@gjsify/fs` fd support needed). */
|
|
33
|
+
function readStdinTextGioUnix() {
|
|
34
|
+
const gi = giNamespace();
|
|
35
|
+
const GioUnix = gi?.GioUnix;
|
|
36
|
+
if (typeof GioUnix?.InputStream !== 'function') {
|
|
37
|
+
throw new Error('GioUnix.InputStream is unavailable');
|
|
38
|
+
}
|
|
39
|
+
const stream = new GioUnix.InputStream({ fd: 0, close_fd: false });
|
|
40
|
+
const chunks = [];
|
|
41
|
+
let total = 0;
|
|
42
|
+
for (;;) {
|
|
43
|
+
const bytes = stream.read_bytes(CHUNK, null);
|
|
44
|
+
if (bytes.get_size() === 0)
|
|
45
|
+
break;
|
|
46
|
+
const arr = bytes.toArray();
|
|
47
|
+
chunks.push(arr);
|
|
48
|
+
total += arr.length;
|
|
49
|
+
}
|
|
50
|
+
if (total === 0)
|
|
51
|
+
return '';
|
|
52
|
+
const buf = new Uint8Array(total);
|
|
53
|
+
let offset = 0;
|
|
54
|
+
for (const c of chunks) {
|
|
55
|
+
buf.set(c, offset);
|
|
56
|
+
offset += c.length;
|
|
57
|
+
}
|
|
58
|
+
return new TextDecoder().decode(buf);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Read stdin under GJS through Gio ALONE, without GioUnix.
|
|
62
|
+
*
|
|
63
|
+
* `/dev/stdin` is fd 0 by another name, and `Gio` is present in every bundle
|
|
64
|
+
* that can reach this code at all. This exists because the GioUnix route has
|
|
65
|
+
* been observed to be unavailable on a host where it should have worked, and a
|
|
66
|
+
* second independent mechanism is cheaper than another round of guessing.
|
|
67
|
+
*/
|
|
68
|
+
function readStdinTextGioFile() {
|
|
69
|
+
const gi = giNamespace();
|
|
70
|
+
const Gio = gi?.Gio;
|
|
71
|
+
if (!Gio?.File)
|
|
72
|
+
throw new Error('Gio.File is unavailable');
|
|
73
|
+
const [ok, contents] = Gio.File.new_for_path('/dev/stdin').load_contents(null);
|
|
74
|
+
if (!ok)
|
|
75
|
+
throw new Error('Gio.File.load_contents("/dev/stdin") returned false');
|
|
76
|
+
return new TextDecoder().decode(contents);
|
|
77
|
+
}
|
|
78
|
+
/** The GJS `imports.gi` namespace, or `undefined` when not running on GJS. */
|
|
79
|
+
function giNamespace() {
|
|
80
|
+
try {
|
|
81
|
+
return globalThis.imports?.gi;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Read the whole of stdin as UTF-8. Works on Node and under the GJS bundle.
|
|
89
|
+
*
|
|
90
|
+
* Branches on WHICH RUNTIME CAN WORK, not on which capability is present. The
|
|
91
|
+
* distinction matters because the two branches are not interchangeable:
|
|
92
|
+
* `readFileSync(0)` is correct on Node/Bun/Deno and can NEVER work under GJS —
|
|
93
|
+
* `@gjsify/fs` has no numeric-fd path, so the `0` is coerced to a relative
|
|
94
|
+
* PATH and the call opens `./0`. A GJS run that reaches that line is already
|
|
95
|
+
* lost, so using it as GJS's fallback only converts a clear failure into
|
|
96
|
+
* `ENOENT … read '0'`, which is what a capability probe returning a false
|
|
97
|
+
* negative did.
|
|
98
|
+
*
|
|
99
|
+
* So: the presence of `imports.gi` decides. On GJS both GJS readers are tried
|
|
100
|
+
* and a failure THROWS with what was attempted; the Node reader is never
|
|
101
|
+
* reached. Off GJS there is no gi namespace and `readFileSync(0)` is the only
|
|
102
|
+
* and correct answer.
|
|
103
|
+
*/
|
|
104
|
+
export function readStdinText() {
|
|
105
|
+
if (!giNamespace())
|
|
106
|
+
return readFileSync(0, 'utf-8');
|
|
107
|
+
const attempts = [];
|
|
108
|
+
for (const read of [readStdinTextGioUnix, readStdinTextGioFile]) {
|
|
109
|
+
try {
|
|
110
|
+
return read();
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
attempts.push(`${read.name}: ${err.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`gjsify: cannot read stdin under GJS. Tried ${attempts.join('; ')}. ` +
|
|
117
|
+
'Pass the input as an argument instead (e.g. --base <ref> rather than --changed-from-stdin).');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Read stdin and split it into trimmed, non-empty lines. Accepts LF and CRLF
|
|
121
|
+
* so a `git diff --name-only` piped from any host works unchanged.
|
|
122
|
+
*/
|
|
123
|
+
export function readStdinLines() {
|
|
124
|
+
return splitStdinLines(readStdinText());
|
|
125
|
+
}
|
|
126
|
+
/** Pure line-splitter behind {@link readStdinLines} — unit-testable without a pipe. */
|
|
127
|
+
export function splitStdinLines(text) {
|
|
128
|
+
return text
|
|
129
|
+
.split('\n')
|
|
130
|
+
.map((s) => s.trim())
|
|
131
|
+
.filter(Boolean);
|
|
132
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -96,7 +96,12 @@
|
|
|
96
96
|
}
|
|
97
97
|
]
|
|
98
98
|
},
|
|
99
|
-
"tier": 1
|
|
99
|
+
"tier": 1,
|
|
100
|
+
"defineFromPackageJson": {
|
|
101
|
+
"__PACKAGE_VERSION__": {
|
|
102
|
+
"field": "version"
|
|
103
|
+
}
|
|
104
|
+
}
|
|
100
105
|
},
|
|
101
106
|
"files": [
|
|
102
107
|
"lib",
|
|
@@ -125,19 +130,19 @@
|
|
|
125
130
|
"cli"
|
|
126
131
|
],
|
|
127
132
|
"dependencies": {
|
|
128
|
-
"@gjsify/buffer": "^0.
|
|
129
|
-
"@gjsify/create-app": "^0.
|
|
130
|
-
"@gjsify/node-globals": "^0.
|
|
131
|
-
"@gjsify/node-polyfills": "^0.
|
|
132
|
-
"@gjsify/npm-registry": "^0.
|
|
133
|
-
"@gjsify/resolve-npm": "^0.
|
|
134
|
-
"@gjsify/rolldown-plugin-gjsify": "^0.
|
|
135
|
-
"@gjsify/rolldown-plugin-pnp": "^0.
|
|
136
|
-
"@gjsify/semver": "^0.
|
|
137
|
-
"@gjsify/tar": "^0.
|
|
138
|
-
"@gjsify/tsc": "^0.
|
|
139
|
-
"@gjsify/web-polyfills": "^0.
|
|
140
|
-
"@gjsify/workspace": "^0.
|
|
133
|
+
"@gjsify/buffer": "^0.23.0",
|
|
134
|
+
"@gjsify/create-app": "^0.23.0",
|
|
135
|
+
"@gjsify/node-globals": "^0.23.0",
|
|
136
|
+
"@gjsify/node-polyfills": "^0.23.0",
|
|
137
|
+
"@gjsify/npm-registry": "^0.23.0",
|
|
138
|
+
"@gjsify/resolve-npm": "^0.23.0",
|
|
139
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.23.0",
|
|
140
|
+
"@gjsify/rolldown-plugin-pnp": "^0.23.0",
|
|
141
|
+
"@gjsify/semver": "^0.23.0",
|
|
142
|
+
"@gjsify/tar": "^0.23.0",
|
|
143
|
+
"@gjsify/tsc": "^0.23.0",
|
|
144
|
+
"@gjsify/web-polyfills": "^0.23.0",
|
|
145
|
+
"@gjsify/workspace": "^0.23.0",
|
|
141
146
|
"cosmiconfig": "^9.0.2",
|
|
142
147
|
"get-tsconfig": "^4.14.0",
|
|
143
148
|
"pkg-types": "^2.3.1",
|
|
@@ -145,13 +150,13 @@
|
|
|
145
150
|
"yargs": "^18.0.0"
|
|
146
151
|
},
|
|
147
152
|
"devDependencies": {
|
|
148
|
-
"@gjsify/unit": "^0.
|
|
153
|
+
"@gjsify/unit": "^0.23.0",
|
|
149
154
|
"@types/yargs": "^17.0.35",
|
|
150
155
|
"typescript": "^6.0.3"
|
|
151
156
|
},
|
|
152
157
|
"peerDependencies": {
|
|
153
|
-
"@gjsify/oxfmt-native": "^0.
|
|
154
|
-
"@gjsify/rolldown-native": "^0.
|
|
158
|
+
"@gjsify/oxfmt-native": "^0.23.0",
|
|
159
|
+
"@gjsify/rolldown-native": "^0.23.0"
|
|
155
160
|
},
|
|
156
161
|
"peerDependenciesMeta": {
|
|
157
162
|
"@gjsify/oxfmt-native": {
|