@gjsify/cli 0.3.21 → 0.4.3
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 +791 -0
- package/lib/actions/build.js +4 -17
- package/lib/bundler-pick.d.ts +79 -0
- package/lib/bundler-pick.js +436 -0
- package/lib/commands/foreach.d.ts +17 -0
- package/lib/commands/foreach.js +341 -0
- package/lib/commands/index.d.ts +2 -0
- package/lib/commands/index.js +2 -0
- package/lib/commands/install.d.ts +1 -0
- package/lib/commands/install.js +401 -27
- package/lib/commands/run.d.ts +1 -1
- package/lib/commands/run.js +113 -20
- package/lib/commands/workspace.d.ts +8 -0
- package/lib/commands/workspace.js +79 -0
- package/lib/config.js +12 -1
- package/lib/index.js +11 -3
- package/lib/types/config-data.d.ts +10 -1
- package/lib/utils/install-backend-native.d.ts +5 -1
- package/lib/utils/install-backend-native.js +329 -70
- package/lib/utils/install-backend.d.ts +11 -1
- package/lib/utils/install-backend.js +4 -2
- package/lib/utils/pkg-json-edit.d.ts +47 -0
- package/lib/utils/pkg-json-edit.js +108 -0
- package/lib/utils/workspace-root.d.ts +1 -0
- package/lib/utils/workspace-root.js +46 -0
- package/package.json +70 -44
- package/src/actions/build.ts +0 -431
- package/src/actions/index.ts +0 -1
- package/src/commands/build.ts +0 -146
- package/src/commands/check.ts +0 -87
- package/src/commands/create.ts +0 -63
- package/src/commands/dlx.ts +0 -195
- package/src/commands/flatpak/build.ts +0 -225
- package/src/commands/flatpak/ci.ts +0 -173
- package/src/commands/flatpak/deps.ts +0 -120
- package/src/commands/flatpak/index.ts +0 -53
- package/src/commands/flatpak/init.ts +0 -191
- package/src/commands/flatpak/utils.ts +0 -76
- package/src/commands/gettext.ts +0 -258
- package/src/commands/gresource.ts +0 -97
- package/src/commands/gsettings.ts +0 -87
- package/src/commands/index.ts +0 -12
- package/src/commands/info.ts +0 -70
- package/src/commands/install.ts +0 -195
- package/src/commands/run.ts +0 -33
- package/src/commands/showcase.ts +0 -149
- package/src/config.ts +0 -304
- package/src/constants.ts +0 -1
- package/src/index.ts +0 -37
- package/src/types/cli-build-options.ts +0 -100
- package/src/types/command.ts +0 -10
- package/src/types/config-data-library.ts +0 -5
- package/src/types/config-data-typescript.ts +0 -6
- package/src/types/config-data.ts +0 -225
- package/src/types/cosmiconfig-result.ts +0 -5
- package/src/types/index.ts +0 -6
- package/src/utils/check-system-deps.ts +0 -480
- package/src/utils/detect-native-packages.ts +0 -153
- package/src/utils/discover-showcases.ts +0 -75
- package/src/utils/dlx-cache.ts +0 -135
- package/src/utils/install-backend-native.ts +0 -363
- package/src/utils/install-backend.ts +0 -88
- package/src/utils/install-global.ts +0 -182
- package/src/utils/normalize-bundler-options.ts +0 -129
- package/src/utils/parse-spec.ts +0 -48
- package/src/utils/resolve-gjs-entry.ts +0 -96
- package/src/utils/resolve-plugin-by-name.ts +0 -106
- package/src/utils/run-gjs.ts +0 -90
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Helpers for editing `package.json` during `gjsify install <pkg>`.
|
|
2
|
+
//
|
|
3
|
+
// Mirrors npm's `--save-{prod,dev,peer,optional}` semantics:
|
|
4
|
+
// - default → dependencies (production)
|
|
5
|
+
// - --save-dev → devDependencies
|
|
6
|
+
// - --save-peer → peerDependencies
|
|
7
|
+
// - --save-optional → optionalDependencies
|
|
8
|
+
//
|
|
9
|
+
// Version specifier resolution mirrors npm's default (`^x.y.z` from the
|
|
10
|
+
// installed version), unless the user passed an explicit range in the spec
|
|
11
|
+
// (`react@^18` → keep `^18`).
|
|
12
|
+
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
13
|
+
export function readPackageJson(pkgPath) {
|
|
14
|
+
if (!existsSync(pkgPath))
|
|
15
|
+
return null;
|
|
16
|
+
const raw = readFileSync(pkgPath, 'utf-8');
|
|
17
|
+
try {
|
|
18
|
+
return JSON.parse(raw);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
throw new Error(`gjsify install: ${pkgPath} is not valid JSON: ${e.message}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function writePackageJson(pkgPath, pkg) {
|
|
25
|
+
const sorted = sortKnownDepFields(pkg);
|
|
26
|
+
writeFileSync(pkgPath, JSON.stringify(sorted, null, 2) + '\n', 'utf-8');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse a user spec into `{ name, range }`:
|
|
30
|
+
* `react` → { name: 'react', range: undefined }
|
|
31
|
+
* `react@^18` → { name: 'react', range: '^18' }
|
|
32
|
+
* `@types/node` → { name: '@types/node', range: undefined }
|
|
33
|
+
* `@types/node@1` → { name: '@types/node', range: '1' }
|
|
34
|
+
*/
|
|
35
|
+
export function parseSpec(spec) {
|
|
36
|
+
if (spec.startsWith('@')) {
|
|
37
|
+
const slash = spec.indexOf('/');
|
|
38
|
+
if (slash === -1)
|
|
39
|
+
return { name: spec };
|
|
40
|
+
const at = spec.indexOf('@', slash + 1);
|
|
41
|
+
if (at === -1)
|
|
42
|
+
return { name: spec };
|
|
43
|
+
return { name: spec.slice(0, at), range: spec.slice(at + 1) };
|
|
44
|
+
}
|
|
45
|
+
const at = spec.indexOf('@');
|
|
46
|
+
if (at === -1)
|
|
47
|
+
return { name: spec };
|
|
48
|
+
return { name: spec.slice(0, at), range: spec.slice(at + 1) };
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Collect existing dependencies + devDependencies + optionalDependencies
|
|
52
|
+
* from a project package.json into installable specs of the form
|
|
53
|
+
* `name@range`. Used by `gjsify install` (no args) to seed the resolver
|
|
54
|
+
* with the project's existing dependency manifest — equivalent to
|
|
55
|
+
* `npm install` reading `package.json`.
|
|
56
|
+
*/
|
|
57
|
+
export function projectSpecsFromPackageJson(pkg) {
|
|
58
|
+
const out = [];
|
|
59
|
+
for (const kind of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
60
|
+
const block = pkg[kind];
|
|
61
|
+
if (!block)
|
|
62
|
+
continue;
|
|
63
|
+
for (const [name, range] of Object.entries(block)) {
|
|
64
|
+
// Skip workspace: / link: / file: / portal: specifiers — those
|
|
65
|
+
// are workspace-local references handled by Phase D.3, not by
|
|
66
|
+
// the project-local install path.
|
|
67
|
+
if (typeof range !== 'string')
|
|
68
|
+
continue;
|
|
69
|
+
if (/^(workspace|link|file|portal|git\+|https?):/.test(range))
|
|
70
|
+
continue;
|
|
71
|
+
out.push(`${name}@${range}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add or update a dependency entry in `pkg`. If the spec didn't include
|
|
78
|
+
* a range, callers fill in the installed version after resolution and
|
|
79
|
+
* call this again with `installedVersion` set.
|
|
80
|
+
*/
|
|
81
|
+
export function addDependencyEntry(pkg, name, range, kind) {
|
|
82
|
+
if (pkg[kind] === undefined) {
|
|
83
|
+
pkg[kind] = {};
|
|
84
|
+
}
|
|
85
|
+
pkg[kind][name] = range;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Default version range when the user didn't pin one: `^x.y.z` from the
|
|
89
|
+
* installed version. Mirrors npm's `save-prefix` default (`^`).
|
|
90
|
+
*/
|
|
91
|
+
export function defaultRangeFromVersion(version) {
|
|
92
|
+
return `^${version}`;
|
|
93
|
+
}
|
|
94
|
+
function sortKnownDepFields(pkg) {
|
|
95
|
+
const out = { ...pkg };
|
|
96
|
+
for (const kind of [
|
|
97
|
+
'dependencies',
|
|
98
|
+
'devDependencies',
|
|
99
|
+
'peerDependencies',
|
|
100
|
+
'optionalDependencies',
|
|
101
|
+
]) {
|
|
102
|
+
const block = out[kind];
|
|
103
|
+
if (!block)
|
|
104
|
+
continue;
|
|
105
|
+
out[kind] = Object.fromEntries(Object.entries(block).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
106
|
+
}
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findWorkspaceRoot(start: string): string | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Walk up from a starting directory to the first ancestor whose
|
|
2
|
+
// `package.json` declares a `workspaces` field — the monorepo root.
|
|
3
|
+
//
|
|
4
|
+
// Used by `gjsify run`, `gjsify workspace`, and `gjsify foreach`: each
|
|
5
|
+
// can be invoked from inside any workspace (chained script calls put the
|
|
6
|
+
// child CLI invocation's cwd at the inner workspace's location), and
|
|
7
|
+
// every one of them needs the monorepo root to discover sibling
|
|
8
|
+
// workspaces, resolve `workspace:^` deps, and walk the dep graph.
|
|
9
|
+
//
|
|
10
|
+
// Sanity-checked via `discoverWorkspaces(candidate)`: the candidate
|
|
11
|
+
// monorepo must actually contain `start` as one of its workspaces.
|
|
12
|
+
// Without this guard, a grand-parent monorepo unrelated to `start`
|
|
13
|
+
// could be picked up.
|
|
14
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
15
|
+
import { join, resolve } from 'node:path';
|
|
16
|
+
import { discoverWorkspaces } from '@gjsify/workspace';
|
|
17
|
+
function readPackageJson(path) {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(readFileSync(path, 'utf-8'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function findWorkspaceRoot(start) {
|
|
26
|
+
let dir = start;
|
|
27
|
+
for (let i = 0; i < 12; i++) {
|
|
28
|
+
const pkgPath = join(dir, 'package.json');
|
|
29
|
+
if (existsSync(pkgPath)) {
|
|
30
|
+
const pkg = readPackageJson(pkgPath);
|
|
31
|
+
if (pkg?.workspaces !== undefined) {
|
|
32
|
+
try {
|
|
33
|
+
const ws = discoverWorkspaces(dir);
|
|
34
|
+
if (dir === start || ws.some((w) => w.location === start))
|
|
35
|
+
return dir;
|
|
36
|
+
}
|
|
37
|
+
catch { /* not a usable workspace root */ }
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const parent = resolve(dir, '..');
|
|
41
|
+
if (parent === dir)
|
|
42
|
+
break;
|
|
43
|
+
dir = parent;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,45 +1,71 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
2
|
+
"name": "@gjsify/cli",
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"description": "CLI for Gjsify",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"module": "lib/index.js",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"gjsify": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"gjsify": {
|
|
13
|
+
"bin": {
|
|
14
|
+
"gjsify": "./dist/cli.gjs.mjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"lib",
|
|
19
|
+
"dist/cli.gjs.mjs",
|
|
20
|
+
"showcases.json"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clear": "rm -rf lib dist tsconfig.tsbuildinfo || exit 0",
|
|
24
|
+
"check": "tsc --noEmit",
|
|
25
|
+
"start": "node lib/index.js",
|
|
26
|
+
"build": "tsc && gjsify run chmod",
|
|
27
|
+
"build:gjs-bundle": "node lib/index.js build src/index.ts --app gjs --outfile dist/cli.gjs.mjs",
|
|
28
|
+
"chmod": "chmod +x ./lib/index.js",
|
|
29
|
+
"build:test:node": "node lib/index.js build src/test.mts --app node --outfile dist/test.node.mjs",
|
|
30
|
+
"test:node": "node dist/test.node.mjs",
|
|
31
|
+
"test": "gjsify run build:test:node && gjsify run test:node"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"gjs",
|
|
35
|
+
"node",
|
|
36
|
+
"gjsify",
|
|
37
|
+
"cli"
|
|
38
|
+
],
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@gjsify/buffer": "workspace:^",
|
|
41
|
+
"@gjsify/create-app": "workspace:^",
|
|
42
|
+
"@gjsify/node-globals": "workspace:^",
|
|
43
|
+
"@gjsify/node-polyfills": "workspace:^",
|
|
44
|
+
"@gjsify/npm-registry": "workspace:^",
|
|
45
|
+
"@gjsify/resolve-npm": "workspace:^",
|
|
46
|
+
"@gjsify/rolldown-plugin-gjsify": "workspace:^",
|
|
47
|
+
"@gjsify/rolldown-plugin-pnp": "workspace:^",
|
|
48
|
+
"@gjsify/semver": "workspace:^",
|
|
49
|
+
"@gjsify/tar": "workspace:^",
|
|
50
|
+
"@gjsify/web-polyfills": "workspace:^",
|
|
51
|
+
"@gjsify/workspace": "workspace:^",
|
|
52
|
+
"cosmiconfig": "^9.0.1",
|
|
53
|
+
"get-tsconfig": "^4.14.0",
|
|
54
|
+
"pkg-types": "^2.3.1",
|
|
55
|
+
"rolldown": "^1.0.0",
|
|
56
|
+
"yargs": "^18.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@gjsify/unit": "workspace:^",
|
|
60
|
+
"@types/yargs": "^17.0.35",
|
|
61
|
+
"typescript": "^6.0.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"@gjsify/rolldown-native": "workspace:^"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"@gjsify/rolldown-native": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|