@gjsify/cli 0.64.60-next.368 → 0.64.61-next.372
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/dist/cli.gjs.mjs +155 -155
- package/lib/commands/flatpak/check.d.ts +11 -0
- package/lib/commands/flatpak/check.js +46 -15
- package/lib/commands/link.js +19 -5
- package/lib/types/config-data.d.ts +14 -0
- package/lib/utils/app-metadata.d.ts +3 -1
- package/lib/utils/app-metadata.js +18 -0
- package/lib/utils/dev-link.d.ts +34 -0
- package/lib/utils/dev-link.js +121 -7
- package/package.json +21 -21
|
@@ -14,5 +14,16 @@ interface FlatpakCheckOptions {
|
|
|
14
14
|
}
|
|
15
15
|
/** argv for `appstreamcli`; offline unless the caller opts in to URL reachability checks. */
|
|
16
16
|
export declare function appstreamValidateArgs(metainfoAbs: string, network?: boolean): string[];
|
|
17
|
+
/** Flathub ships the linter inside this app; installing it is the documented way to get it. */
|
|
18
|
+
export declare const BUILDER_APP_ID = "org.flatpak.Builder";
|
|
19
|
+
/**
|
|
20
|
+
* How to run `flatpak-builder-lint` when it is not on PATH: through the `org.flatpak.Builder`
|
|
21
|
+
* app, which is how Flathub's own docs install it. Without this fallback every host that followed
|
|
22
|
+
* those docs reported the linter as missing and the whole check as failed.
|
|
23
|
+
*/
|
|
24
|
+
export declare function builderLintViaFlatpak(args: string[]): {
|
|
25
|
+
bin: string;
|
|
26
|
+
args: string[];
|
|
27
|
+
};
|
|
17
28
|
export declare const flatpakCheckCommand: Command<unknown, FlatpakCheckOptions>;
|
|
18
29
|
export {};
|
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
// correctness check (and optionally `repo` for built artefacts)
|
|
9
9
|
//
|
|
10
10
|
// Both ship inside the `org.flatpak.Builder` flatpak. We exec them from
|
|
11
|
-
// the host PATH;
|
|
12
|
-
// `flatpak
|
|
11
|
+
// the host PATH; a missing `flatpak-builder-lint` runs through
|
|
12
|
+
// `flatpak run --command=… org.flatpak.Builder` when that app is installed,
|
|
13
|
+
// else the check prints the install hint.
|
|
13
14
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
14
15
|
import { resolve, join, dirname } from 'node:path';
|
|
15
16
|
import { spawnToCompletion } from '../../utils/spawn.js';
|
|
@@ -20,6 +21,16 @@ import { formatFinding, lintMetainfo, readImageInfo, summarizeFindings, } from '
|
|
|
20
21
|
export function appstreamValidateArgs(metainfoAbs, network = false) {
|
|
21
22
|
return ['validate', '--strict', ...(network ? [] : ['--no-net']), metainfoAbs];
|
|
22
23
|
}
|
|
24
|
+
/** Flathub ships the linter inside this app; installing it is the documented way to get it. */
|
|
25
|
+
export const BUILDER_APP_ID = 'org.flatpak.Builder';
|
|
26
|
+
/**
|
|
27
|
+
* How to run `flatpak-builder-lint` when it is not on PATH: through the `org.flatpak.Builder`
|
|
28
|
+
* app, which is how Flathub's own docs install it. Without this fallback every host that followed
|
|
29
|
+
* those docs reported the linter as missing and the whole check as failed.
|
|
30
|
+
*/
|
|
31
|
+
export function builderLintViaFlatpak(args) {
|
|
32
|
+
return { bin: 'flatpak', args: ['run', '--command=flatpak-builder-lint', BUILDER_APP_ID, ...args] };
|
|
33
|
+
}
|
|
23
34
|
export const flatpakCheckCommand = {
|
|
24
35
|
command: 'check [manifest]',
|
|
25
36
|
description: 'Run Flathub pre-submission linters: appstreamcli validate + flatpak-builder-lint.',
|
|
@@ -114,12 +125,12 @@ export const flatpakCheckCommand = {
|
|
|
114
125
|
console.error(`[gjsify flatpak check] manifest not found: ${manifestPath}`);
|
|
115
126
|
return process.exit(1);
|
|
116
127
|
}
|
|
117
|
-
const ok = await
|
|
128
|
+
const ok = await runBuilderLint(['manifest', manifestPath], args.verbose ?? false);
|
|
118
129
|
if (!ok)
|
|
119
130
|
failures++;
|
|
120
131
|
if (args.repo) {
|
|
121
132
|
const repoPath = resolve(cwd, args.repo);
|
|
122
|
-
const okRepo = await
|
|
133
|
+
const okRepo = await runBuilderLint(['repo', repoPath], args.verbose ?? false);
|
|
123
134
|
if (!okRepo)
|
|
124
135
|
failures++;
|
|
125
136
|
}
|
|
@@ -207,6 +218,32 @@ function resolveManifestPath(explicit, appId, cwd) {
|
|
|
207
218
|
throw new Error('gjsify flatpak check: no manifest path given and could not auto-detect. ' +
|
|
208
219
|
'Pass the manifest as a positional argument.');
|
|
209
220
|
}
|
|
221
|
+
async function runBuilderLint(args, verbose) {
|
|
222
|
+
const direct = await runLinter('flatpak-builder-lint', args, verbose);
|
|
223
|
+
if (direct !== 'missing')
|
|
224
|
+
return direct === 'ok';
|
|
225
|
+
if (await builderAppInstalled()) {
|
|
226
|
+
const via = builderLintViaFlatpak(args);
|
|
227
|
+
return (await runLinter(via.bin, via.args, verbose)) === 'ok';
|
|
228
|
+
}
|
|
229
|
+
console.error(`[gjsify flatpak check] flatpak-builder-lint not found in PATH, and ${BUILDER_APP_ID} is not installed.\n` +
|
|
230
|
+
`Install via:\n` +
|
|
231
|
+
` flatpak install -y flathub ${BUILDER_APP_ID}`);
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
async function builderAppInstalled() {
|
|
235
|
+
try {
|
|
236
|
+
const probe = await spawnToCompletion('flatpak', ['info', BUILDER_APP_ID], {
|
|
237
|
+
completion: 'return',
|
|
238
|
+
stdio: 'capture',
|
|
239
|
+
});
|
|
240
|
+
return probe.code === 0;
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// No `flatpak` binary at all: the app cannot be there either.
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
210
247
|
async function runLinter(bin, args, verbose) {
|
|
211
248
|
// `completion: 'return'` — the handler's SUCCESS path ends with a `console.log`
|
|
212
249
|
// and returns, so under GJS an async spawn leaves `ensureMainLoop`'s loop armed
|
|
@@ -221,16 +258,10 @@ async function runLinter(bin, args, verbose) {
|
|
|
221
258
|
}
|
|
222
259
|
catch (err) {
|
|
223
260
|
const e = err;
|
|
224
|
-
if (e.code === 'ENOENT')
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
` alias ${bin}="flatpak run --command=${bin} org.flatpak.Builder"`);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
console.error(`[gjsify flatpak check] ${bin} failed to spawn: ${e.message}`);
|
|
232
|
-
}
|
|
233
|
-
return false;
|
|
261
|
+
if (e.code === 'ENOENT')
|
|
262
|
+
return 'missing';
|
|
263
|
+
console.error(`[gjsify flatpak check] ${bin} failed to spawn: ${e.message}`);
|
|
264
|
+
return 'fail';
|
|
234
265
|
}
|
|
235
266
|
const ok = result.code === 0;
|
|
236
267
|
console.log(`[gjsify flatpak check] ${ok ? 'OK' : 'FAIL'}: ${bin} ${args.join(' ')}`);
|
|
@@ -240,6 +271,6 @@ async function runLinter(bin, args, verbose) {
|
|
|
240
271
|
if (result.stderr?.trim())
|
|
241
272
|
console.error(result.stderr.trimEnd());
|
|
242
273
|
}
|
|
243
|
-
return ok;
|
|
274
|
+
return ok ? 'ok' : 'fail';
|
|
244
275
|
}
|
|
245
276
|
void join;
|
package/lib/commands/link.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// step is an install anyway.
|
|
13
13
|
import { existsSync } from 'node:fs';
|
|
14
14
|
import { relative, resolve } from 'node:path';
|
|
15
|
-
import { applyDevLinks, consumerKnownNames, consumerNestedPlacements, DEV_LINK_FILE, devLinkPath, ensureLocallyIgnored, formatUnbuiltDevLinks, planDevLinks, prepareDevLinks, readDevLinkOverride, removeDevLinkOverride, removeDevLinks, removeLocalIgnore, resolveCheckoutWorkspaces, retireDevLinks, scanDevLinks, unbuiltDevLinks, writeDevLinkOverride, } from '../utils/dev-link.js';
|
|
15
|
+
import { applyDevLinks, consumerKnownNames, consumerNestedPlacements, DEV_LINK_FILE, devLinkPath, ensureLocallyIgnored, formatUnbuiltDevLinks, planDevLinks, prepareDevLinks, readDevLinkOverride, removeDevLinkClosure, removeDevLinkOverride, removeDevLinks, removeLocalIgnore, resolveCheckoutWorkspaces, retireDevLinks, scanDevLinks, syncDevLinkClosure, unbuiltDevLinks, writeDevLinkOverride, } from '../utils/dev-link.js';
|
|
16
16
|
export const linkCommand = {
|
|
17
17
|
command: 'link <checkout>',
|
|
18
18
|
description: 'Link this project against a local gjsify checkout for development: its workspace packages replace the installed registry copies, recorded in a git-ignored .gjsify-link.json that every later `gjsify install` re-applies. Undo with `gjsify unlink`.',
|
|
@@ -95,7 +95,15 @@ export const linkCommand = {
|
|
|
95
95
|
// because the new override may point somewhere else entirely.
|
|
96
96
|
const retired = retireDevLinks(consumerRoot, sweep, keep);
|
|
97
97
|
const written = applyDevLinks(links);
|
|
98
|
-
|
|
98
|
+
let previousClosure = [];
|
|
99
|
+
try {
|
|
100
|
+
previousClosure = readDevLinkOverride(consumerRoot)?.closure ?? [];
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
// Unreadable old override: nothing recorded to retire.
|
|
104
|
+
}
|
|
105
|
+
const closure = syncDevLinkClosure(links, checkout, previousClosure);
|
|
106
|
+
writeDevLinkOverride(consumerRoot, { version: 1, checkout, packages: patterns, closure });
|
|
99
107
|
const ignored = ensureLocallyIgnored(consumerRoot);
|
|
100
108
|
console.log(`\n ${written.length} link(s) written, ${links.length - written.length} already current.`);
|
|
101
109
|
// Counted against what was PLANNED, not just reported: `removeDevLinks`
|
|
@@ -148,10 +156,12 @@ export const unlinkCommand = {
|
|
|
148
156
|
// part that can fail (a checkout that has since been deleted, an unbuilt
|
|
149
157
|
// one) and the checkout path is what the tree sweep below needs.
|
|
150
158
|
const checkouts = [];
|
|
159
|
+
let closure = [];
|
|
151
160
|
try {
|
|
152
|
-
const
|
|
153
|
-
if (checkout)
|
|
154
|
-
checkouts.push(checkout);
|
|
161
|
+
const override = readDevLinkOverride(consumerRoot);
|
|
162
|
+
if (override?.checkout)
|
|
163
|
+
checkouts.push(override.checkout);
|
|
164
|
+
closure = override?.closure ?? [];
|
|
155
165
|
}
|
|
156
166
|
catch {
|
|
157
167
|
// Unparseable override: the sweep finds nothing, the plan below says
|
|
@@ -173,6 +183,8 @@ export const unlinkCommand = {
|
|
|
173
183
|
names.add(link.name);
|
|
174
184
|
for (const name of [...names].sort())
|
|
175
185
|
console.log(` would remove link ${name}`);
|
|
186
|
+
for (const path of closure)
|
|
187
|
+
console.log(` would remove link ${path}`);
|
|
176
188
|
console.log(` would remove ${overridePath}`);
|
|
177
189
|
console.log(` would remove ${DEV_LINK_FILE} entry from .git/info/exclude (if this module wrote it)`);
|
|
178
190
|
console.log(`\n${label}: nothing changed. Drop --dry-run to apply.`);
|
|
@@ -196,6 +208,8 @@ export const unlinkCommand = {
|
|
|
196
208
|
}
|
|
197
209
|
for (const link of removed)
|
|
198
210
|
console.log(` unlinked ${link.name}`);
|
|
211
|
+
for (const path of removeDevLinkClosure(closure))
|
|
212
|
+
console.log(` unlinked ${path}`);
|
|
199
213
|
// Nothing may point out of `node_modules` any more, or the reinstall below
|
|
200
214
|
// dies on it. If something does, the override STAYS: it is what a later
|
|
201
215
|
// `gjsify unlink` needs, and a half-undone tree with no record of the
|
|
@@ -312,6 +312,8 @@ export interface ConfigDataTest {
|
|
|
312
312
|
/** Default runtimes when `--runtime` not specified. Default: `['gjs', 'node']`. */
|
|
313
313
|
runtimes?: Array<'gjs' | 'node'>;
|
|
314
314
|
}
|
|
315
|
+
/** The closed set of `gjsify::ai-involvement` values (ADR 0153). */
|
|
316
|
+
export type AiInvolvementLevel = 'none' | 'assisted' | 'agent-built';
|
|
315
317
|
/**
|
|
316
318
|
* The app metadata every install format needs — AppStream MetaInfo fields plus
|
|
317
319
|
* what a freedesktop `.desktop` entry is built from. Shared on purpose: a
|
|
@@ -421,6 +423,18 @@ export interface AppMetadata {
|
|
|
421
423
|
accentLight: string;
|
|
422
424
|
accentDark: string;
|
|
423
425
|
};
|
|
426
|
+
/**
|
|
427
|
+
* How much AI built the app (ADR 0153). Rendered as
|
|
428
|
+
* `<custom><value key="gjsify::ai-involvement">` (+ `gjsify::ai-disclosure`), which
|
|
429
|
+
* `gjsify site` and `gjsify webext listing` read. `disclosure` is ONE English sentence naming
|
|
430
|
+
* the parts AI produced and how they are reviewed; it is the gettext msgid, so it is
|
|
431
|
+
* translated through the app's catalogues and `ship` never folds a translated `<value>` into
|
|
432
|
+
* the metainfo (AppStream rejects a repeated custom key).
|
|
433
|
+
*/
|
|
434
|
+
aiInvolvement?: {
|
|
435
|
+
level: AiInvolvementLevel;
|
|
436
|
+
disclosure?: string;
|
|
437
|
+
};
|
|
424
438
|
/**
|
|
425
439
|
* Path to a scalable SVG icon; Flathub requires SVG
|
|
426
440
|
* (`/app/share/icons/hicolor/scalable/apps/<app-id>.svg`). When set, init
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { AppMetadata, DescriptionBlock } from '../types/config-data.js';
|
|
1
|
+
import type { AiInvolvementLevel, AppMetadata, DescriptionBlock } from '../types/config-data.js';
|
|
2
|
+
/** The `gjsify::ai-involvement` values ADR 0153 allows. */
|
|
3
|
+
export declare const AI_INVOLVEMENT_LEVELS: readonly AiInvolvementLevel[];
|
|
2
4
|
/** Everything a renderer needs that is not part of {@link AppMetadata} itself. */
|
|
3
5
|
export interface AppMetadataInputs {
|
|
4
6
|
/** Reverse-DNS application id — the MetaInfo `<id>` and the icon/desktop basename. */
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
// template+placeholder approach to stay legible. The `.desktop` entry stays
|
|
15
15
|
// template-based — it is flat `key=value`.
|
|
16
16
|
import { channelAllowsDonations } from './channel.js';
|
|
17
|
+
/** The `gjsify::ai-involvement` values ADR 0153 allows. */
|
|
18
|
+
export const AI_INVOLVEMENT_LEVELS = ['none', 'assisted', 'agent-built'];
|
|
17
19
|
/**
|
|
18
20
|
* The `.desktop` skeleton, as source rather than as a file to find at runtime.
|
|
19
21
|
*
|
|
@@ -321,6 +323,22 @@ function renderMetainfo(inputs, kind) {
|
|
|
321
323
|
lines.push(` <control>${escapeXml(c)}</control>`);
|
|
322
324
|
lines.push(' </recommends>');
|
|
323
325
|
}
|
|
326
|
+
// <custom> — ADR 0153. ONE value per key, never an `xml:lang` sibling: `appstreamcli validate`
|
|
327
|
+
// rejects a repeated key (`custom-key-duplicated`). The disclosure is translated by the
|
|
328
|
+
// READER through the app's catalogues, so `localizeMetadata` must not touch it either.
|
|
329
|
+
if (m.aiInvolvement !== undefined) {
|
|
330
|
+
const { level, disclosure } = m.aiInvolvement;
|
|
331
|
+
if (!AI_INVOLVEMENT_LEVELS.includes(level)) {
|
|
332
|
+
throw new Error(`${inputs.configKey}.aiInvolvement.level is ${JSON.stringify(level)}; expected one of ` +
|
|
333
|
+
`${AI_INVOLVEMENT_LEVELS.join(', ')} (ADR 0153). An unknown level is never guessed.`);
|
|
334
|
+
}
|
|
335
|
+
lines.push(' <custom>');
|
|
336
|
+
lines.push(` <value key="gjsify::ai-involvement">${escapeXml(level)}</value>`);
|
|
337
|
+
const sentence = disclosure?.trim().replace(/\s+/g, ' ');
|
|
338
|
+
if (sentence)
|
|
339
|
+
lines.push(` <value key="gjsify::ai-disclosure">${escapeXml(sentence)}</value>`);
|
|
340
|
+
lines.push(' </custom>');
|
|
341
|
+
}
|
|
324
342
|
lines.push('</component>');
|
|
325
343
|
return lines.join('\n') + '\n';
|
|
326
344
|
}
|
package/lib/utils/dev-link.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export interface DevLinkOverride {
|
|
|
22
22
|
* `@gjsify/*`, the same dialect `gjsify foreach --include` takes.
|
|
23
23
|
*/
|
|
24
24
|
packages: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Symlinks `gjsify link` created INSIDE the checkout so a linked package resolves its own
|
|
27
|
+
* dependencies from the checkout under `--preserve-symlinks` (see {@link syncDevLinkClosure}).
|
|
28
|
+
* Absolute paths; `unlink` removes exactly these and nothing else.
|
|
29
|
+
*/
|
|
30
|
+
closure?: string[];
|
|
25
31
|
}
|
|
26
32
|
/** One `node_modules/<name>` → checkout package directory link. */
|
|
27
33
|
export interface DevLink {
|
|
@@ -73,6 +79,11 @@ export declare function devLinkRoot(startDir: string): string;
|
|
|
73
79
|
* (`McpServer` is not assignable to `McpServer`). `--preserveSymlinks` keeps
|
|
74
80
|
* resolution in the consumer tree, which is what an unlinked install does.
|
|
75
81
|
* An explicit `--preserveSymlinks` in either spelling wins.
|
|
82
|
+
*
|
|
83
|
+
* Node has the same switch, and the NativeScript CLI turns it ON: `bundler-compiler-service.js`
|
|
84
|
+
* (`shouldUsePreserveSymlinksOption`) starts Vite with `node --preserve-symlinks` unless the
|
|
85
|
+
* package manager is pnpm. Under it a linked package's own dependencies are looked up from the
|
|
86
|
+
* CONSUMER's tree, not the checkout's; {@link syncDevLinkClosure} compensates for that.
|
|
76
87
|
*/
|
|
77
88
|
export declare function tscArgsUnderLink(args: readonly string[], linked: boolean): string[];
|
|
78
89
|
/**
|
|
@@ -153,6 +164,29 @@ export declare function applyDevLinks(links: readonly DevLink[]): DevLink[];
|
|
|
153
164
|
* refusal costs one message.
|
|
154
165
|
*/
|
|
155
166
|
export declare function removeDevLinks(links: readonly DevLink[]): DevLink[];
|
|
167
|
+
/**
|
|
168
|
+
* Make a linked package resolve its dependencies from the CHECKOUT under
|
|
169
|
+
* `node --preserve-symlinks`.
|
|
170
|
+
*
|
|
171
|
+
* Without the switch Node follows `<consumer>/node_modules/@gjsify/X` to its real path and finds
|
|
172
|
+
* X's dependencies in the checkout. With it (the NativeScript CLI sets it, see
|
|
173
|
+
* {@link tscArgsUnderLink}) the lookup walks UP FROM THE LINK: `.../@gjsify/X/node_modules`, then
|
|
174
|
+
* the consumer's own tree — so X gets the consumer's execa 5 instead of the checkout's execa 9,
|
|
175
|
+
* and execa's own dependencies are searched from `.../X/node_modules/execa/..` the same way.
|
|
176
|
+
*
|
|
177
|
+
* The first directory searched is `<checkout>/<X>/node_modules`, and everything below it is
|
|
178
|
+
* looked up from there, so filling that ONE directory covers the whole transitive closure:
|
|
179
|
+
* - absent → it becomes a symlink to the checkout's root `node_modules` (cheapest: one link per
|
|
180
|
+
* package, whatever the dependency count);
|
|
181
|
+
* - present (nested deps) → only the MISSING top-level entries are added as symlinks to the
|
|
182
|
+
* root copy, scope directories included. A real file or directory is never touched.
|
|
183
|
+
*
|
|
184
|
+
* Idempotent: the previous call's links (`previous`) are removed first and the result is the full
|
|
185
|
+
* list now owned, which `gjsify link` records so `unlink` removes exactly those.
|
|
186
|
+
*/
|
|
187
|
+
export declare function syncDevLinkClosure(links: readonly DevLink[], checkout: string, previous: readonly string[]): string[];
|
|
188
|
+
/** Remove the symlinks {@link syncDevLinkClosure} recorded. Only symlinks, nothing else. */
|
|
189
|
+
export declare function removeDevLinkClosure(paths: readonly string[]): string[];
|
|
156
190
|
/**
|
|
157
191
|
* Every `node_modules/<name>` symlink that resolves INSIDE one of `checkouts`.
|
|
158
192
|
*
|
package/lib/utils/dev-link.js
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// committed lockfile the moment a link is active, which is the one thing this
|
|
36
36
|
// feature promises not to do. `linkedNames` therefore applies after the lockfile
|
|
37
37
|
// is written and only to what gets fetched.
|
|
38
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
38
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
|
|
39
39
|
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
40
40
|
import { discoverWorkspaces, filterWorkspaces } from '@gjsify/workspace';
|
|
41
41
|
import { linkDirSync } from './dir-link.js';
|
|
@@ -84,11 +84,15 @@ export function readDevLinkOverride(root) {
|
|
|
84
84
|
packages: Array.isArray(record.packages)
|
|
85
85
|
? record.packages.filter((p) => typeof p === 'string')
|
|
86
86
|
: [],
|
|
87
|
+
...(Array.isArray(record.closure)
|
|
88
|
+
? { closure: record.closure.filter((p) => typeof p === 'string') }
|
|
89
|
+
: {}),
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
92
|
export function writeDevLinkOverride(root, override) {
|
|
90
93
|
const path = devLinkPath(root);
|
|
91
|
-
|
|
94
|
+
const { closure, ...rest } = override;
|
|
95
|
+
writeFileSync(path, JSON.stringify(closure && closure.length > 0 ? { ...rest, closure } : rest, null, 2) + '\n');
|
|
92
96
|
return path;
|
|
93
97
|
}
|
|
94
98
|
/** Remove the override file; returns its path when one was there. */
|
|
@@ -124,6 +128,11 @@ export function devLinkRoot(startDir) {
|
|
|
124
128
|
* (`McpServer` is not assignable to `McpServer`). `--preserveSymlinks` keeps
|
|
125
129
|
* resolution in the consumer tree, which is what an unlinked install does.
|
|
126
130
|
* An explicit `--preserveSymlinks` in either spelling wins.
|
|
131
|
+
*
|
|
132
|
+
* Node has the same switch, and the NativeScript CLI turns it ON: `bundler-compiler-service.js`
|
|
133
|
+
* (`shouldUsePreserveSymlinksOption`) starts Vite with `node --preserve-symlinks` unless the
|
|
134
|
+
* package manager is pnpm. Under it a linked package's own dependencies are looked up from the
|
|
135
|
+
* CONSUMER's tree, not the checkout's; {@link syncDevLinkClosure} compensates for that.
|
|
127
136
|
*/
|
|
128
137
|
export function tscArgsUnderLink(args, linked) {
|
|
129
138
|
if (!linked)
|
|
@@ -368,6 +377,94 @@ export function removeDevLinks(links) {
|
|
|
368
377
|
}
|
|
369
378
|
return removed;
|
|
370
379
|
}
|
|
380
|
+
function missing(path) {
|
|
381
|
+
try {
|
|
382
|
+
lstatSync(path);
|
|
383
|
+
return false;
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Make a linked package resolve its dependencies from the CHECKOUT under
|
|
391
|
+
* `node --preserve-symlinks`.
|
|
392
|
+
*
|
|
393
|
+
* Without the switch Node follows `<consumer>/node_modules/@gjsify/X` to its real path and finds
|
|
394
|
+
* X's dependencies in the checkout. With it (the NativeScript CLI sets it, see
|
|
395
|
+
* {@link tscArgsUnderLink}) the lookup walks UP FROM THE LINK: `.../@gjsify/X/node_modules`, then
|
|
396
|
+
* the consumer's own tree — so X gets the consumer's execa 5 instead of the checkout's execa 9,
|
|
397
|
+
* and execa's own dependencies are searched from `.../X/node_modules/execa/..` the same way.
|
|
398
|
+
*
|
|
399
|
+
* The first directory searched is `<checkout>/<X>/node_modules`, and everything below it is
|
|
400
|
+
* looked up from there, so filling that ONE directory covers the whole transitive closure:
|
|
401
|
+
* - absent → it becomes a symlink to the checkout's root `node_modules` (cheapest: one link per
|
|
402
|
+
* package, whatever the dependency count);
|
|
403
|
+
* - present (nested deps) → only the MISSING top-level entries are added as symlinks to the
|
|
404
|
+
* root copy, scope directories included. A real file or directory is never touched.
|
|
405
|
+
*
|
|
406
|
+
* Idempotent: the previous call's links (`previous`) are removed first and the result is the full
|
|
407
|
+
* list now owned, which `gjsify link` records so `unlink` removes exactly those.
|
|
408
|
+
*/
|
|
409
|
+
export function syncDevLinkClosure(links, checkout, previous) {
|
|
410
|
+
removeDevLinkClosure(previous);
|
|
411
|
+
const root = join(checkout, 'node_modules');
|
|
412
|
+
if (!existsSync(root))
|
|
413
|
+
return [];
|
|
414
|
+
const created = [];
|
|
415
|
+
const add = (path, target) => {
|
|
416
|
+
linkDirSync(path, target);
|
|
417
|
+
created.push(path);
|
|
418
|
+
};
|
|
419
|
+
for (const link of links) {
|
|
420
|
+
const nm = join(link.target, 'node_modules');
|
|
421
|
+
if (nm === root)
|
|
422
|
+
continue;
|
|
423
|
+
if (missing(nm)) {
|
|
424
|
+
add(nm, root);
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (!lstatSync(nm).isDirectory())
|
|
428
|
+
continue;
|
|
429
|
+
for (const entry of readdirSync(root)) {
|
|
430
|
+
if (entry.startsWith('.'))
|
|
431
|
+
continue;
|
|
432
|
+
if (!entry.startsWith('@')) {
|
|
433
|
+
if (missing(join(nm, entry)))
|
|
434
|
+
add(join(nm, entry), join(root, entry));
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
const scopeDir = join(nm, entry);
|
|
438
|
+
if (missing(scopeDir)) {
|
|
439
|
+
add(scopeDir, join(root, entry));
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
if (!lstatSync(scopeDir).isDirectory())
|
|
443
|
+
continue;
|
|
444
|
+
for (const name of readdirSync(join(root, entry))) {
|
|
445
|
+
if (missing(join(scopeDir, name)))
|
|
446
|
+
add(join(scopeDir, name), join(root, entry, name));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return created;
|
|
451
|
+
}
|
|
452
|
+
/** Remove the symlinks {@link syncDevLinkClosure} recorded. Only symlinks, nothing else. */
|
|
453
|
+
export function removeDevLinkClosure(paths) {
|
|
454
|
+
const removed = [];
|
|
455
|
+
for (const path of paths) {
|
|
456
|
+
try {
|
|
457
|
+
if (!lstatSync(path).isSymbolicLink())
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
rmSync(path, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
464
|
+
removed.push(path);
|
|
465
|
+
}
|
|
466
|
+
return removed;
|
|
467
|
+
}
|
|
371
468
|
/**
|
|
372
469
|
* Does `linkPath` already resolve to `target`?
|
|
373
470
|
*
|
|
@@ -405,13 +502,16 @@ function linkAlreadyPointsAt(linkPath, target) {
|
|
|
405
502
|
export function scanDevLinks(consumerRoot, checkouts) {
|
|
406
503
|
const roots = [];
|
|
407
504
|
for (const checkout of checkouts) {
|
|
505
|
+
// A checkout that has since been DELETED still names the links the install
|
|
506
|
+
// left behind, so its spelled path counts as a root too — dangling links
|
|
507
|
+
// into it must be found and removed, not skipped (they include optional
|
|
508
|
+
// native packages of other platforms the host never installs).
|
|
509
|
+
roots.push(resolve(checkout));
|
|
408
510
|
try {
|
|
409
511
|
roots.push(realpathSync(checkout));
|
|
410
512
|
}
|
|
411
513
|
catch {
|
|
412
|
-
// Gone or unreadable:
|
|
413
|
-
// no links. A DANGLING link is not this function's business either —
|
|
414
|
-
// the installer extracts straight over one.
|
|
514
|
+
// Gone or unreadable: the spelled path above is all there is.
|
|
415
515
|
}
|
|
416
516
|
}
|
|
417
517
|
if (roots.length === 0)
|
|
@@ -427,7 +527,13 @@ export function scanDevLinks(consumerRoot, checkouts) {
|
|
|
427
527
|
target = realpathSync(pkg.dir);
|
|
428
528
|
}
|
|
429
529
|
catch {
|
|
430
|
-
|
|
530
|
+
// Dangling: judge it by where the link text points.
|
|
531
|
+
try {
|
|
532
|
+
target = resolve(dirname(pkg.dir), readlinkSync(pkg.dir));
|
|
533
|
+
}
|
|
534
|
+
catch {
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
431
537
|
}
|
|
432
538
|
if (!roots.some((root) => target === root || target.startsWith(root + sep)))
|
|
433
539
|
continue;
|
|
@@ -450,7 +556,15 @@ function packageNameAt(consumerRoot, dir) {
|
|
|
450
556
|
*/
|
|
451
557
|
export function retireDevLinks(consumerRoot, checkouts, keep) {
|
|
452
558
|
const stale = scanDevLinks(consumerRoot, checkouts).filter((link) => !keep.has(link.name));
|
|
453
|
-
|
|
559
|
+
// `scanDevLinks` already established "symlink into the checkout", dangling or
|
|
560
|
+
// not, so remove directly: `removeDevLinks` re-checks through `realpath` and
|
|
561
|
+
// would skip exactly the links whose target is gone.
|
|
562
|
+
const removed = [];
|
|
563
|
+
for (const link of stale) {
|
|
564
|
+
rmSync(link.linkPath, { recursive: true, force: true, maxRetries: 10, retryDelay: 100 });
|
|
565
|
+
removed.push(link);
|
|
566
|
+
}
|
|
567
|
+
return removed;
|
|
454
568
|
}
|
|
455
569
|
/**
|
|
456
570
|
* Which of these links point at something that is not built.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.61-next.372",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -142,22 +142,22 @@
|
|
|
142
142
|
"cli"
|
|
143
143
|
],
|
|
144
144
|
"dependencies": {
|
|
145
|
-
"@gjsify/blueprint": "0.64.
|
|
146
|
-
"@gjsify/buffer": "0.64.
|
|
147
|
-
"@gjsify/create-app": "0.64.
|
|
148
|
-
"@gjsify/node-globals": "0.64.
|
|
149
|
-
"@gjsify/node-polyfills": "0.64.
|
|
150
|
-
"@gjsify/npm-registry": "0.64.
|
|
151
|
-
"@gjsify/resolve-npm": "0.64.
|
|
152
|
-
"@gjsify/rolldown-plugin-gjsify": "0.64.
|
|
153
|
-
"@gjsify/vite-plugin-blueprint": "0.64.
|
|
154
|
-
"@gjsify/rolldown-plugin-pnp": "0.64.
|
|
155
|
-
"@gjsify/semver": "0.64.
|
|
156
|
-
"@gjsify/tar": "0.64.
|
|
157
|
-
"@gjsify/tsc": "0.64.
|
|
158
|
-
"@gjsify/utils": "0.64.
|
|
159
|
-
"@gjsify/web-polyfills": "0.64.
|
|
160
|
-
"@gjsify/workspace": "0.64.
|
|
145
|
+
"@gjsify/blueprint": "0.64.61-next.372",
|
|
146
|
+
"@gjsify/buffer": "0.64.61-next.372",
|
|
147
|
+
"@gjsify/create-app": "0.64.61-next.372",
|
|
148
|
+
"@gjsify/node-globals": "0.64.61-next.372",
|
|
149
|
+
"@gjsify/node-polyfills": "0.64.61-next.372",
|
|
150
|
+
"@gjsify/npm-registry": "0.64.61-next.372",
|
|
151
|
+
"@gjsify/resolve-npm": "0.64.61-next.372",
|
|
152
|
+
"@gjsify/rolldown-plugin-gjsify": "0.64.61-next.372",
|
|
153
|
+
"@gjsify/vite-plugin-blueprint": "0.64.61-next.372",
|
|
154
|
+
"@gjsify/rolldown-plugin-pnp": "0.64.61-next.372",
|
|
155
|
+
"@gjsify/semver": "0.64.61-next.372",
|
|
156
|
+
"@gjsify/tar": "0.64.61-next.372",
|
|
157
|
+
"@gjsify/tsc": "0.64.61-next.372",
|
|
158
|
+
"@gjsify/utils": "0.64.61-next.372",
|
|
159
|
+
"@gjsify/web-polyfills": "0.64.61-next.372",
|
|
160
|
+
"@gjsify/workspace": "0.64.61-next.372",
|
|
161
161
|
"acorn": "^8.17.0",
|
|
162
162
|
"cosmiconfig": "^9.0.2",
|
|
163
163
|
"get-tsconfig": "^4.14.0",
|
|
@@ -166,13 +166,13 @@
|
|
|
166
166
|
"yargs": "^18.0.0"
|
|
167
167
|
},
|
|
168
168
|
"devDependencies": {
|
|
169
|
-
"@gjsify/unit": "0.64.
|
|
169
|
+
"@gjsify/unit": "0.64.61-next.372",
|
|
170
170
|
"@types/yargs": "^17.0.35",
|
|
171
171
|
"typescript": "^6.0.3"
|
|
172
172
|
},
|
|
173
173
|
"peerDependencies": {
|
|
174
|
-
"@gjsify/oxfmt-native": "0.64.
|
|
175
|
-
"@gjsify/rolldown-native": "0.64.
|
|
174
|
+
"@gjsify/oxfmt-native": "0.64.61-next.372",
|
|
175
|
+
"@gjsify/rolldown-native": "0.64.61-next.372"
|
|
176
176
|
},
|
|
177
177
|
"peerDependenciesMeta": {
|
|
178
178
|
"@gjsify/oxfmt-native": {
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
"url": "https://github.com/gjsify/gjsify/issues"
|
|
193
193
|
},
|
|
194
194
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme",
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "8d5f83c60a8c3d2c03428cdbce40c90ab8a06997"
|
|
196
196
|
}
|