@grove-dev/cli 0.8.0 → 0.10.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 +23 -3
- package/dist/health-cli.d.ts +3 -0
- package/dist/health-cli.d.ts.map +1 -0
- package/dist/health-cli.js +15 -0
- package/dist/health-cli.js.map +1 -0
- package/dist/health.d.ts +7 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +68 -0
- package/dist/health.js.map +1 -0
- package/dist/icons-cli.d.ts.map +1 -1
- package/dist/icons-cli.js +2 -1
- package/dist/icons-cli.js.map +1 -1
- package/dist/index.js +38 -18
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +27 -12
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +180 -53
- package/dist/init.js.map +1 -1
- package/dist/package-manager.d.ts +57 -0
- package/dist/package-manager.d.ts.map +1 -0
- package/dist/package-manager.js +157 -0
- package/dist/package-manager.js.map +1 -0
- package/dist/package.json +3 -2
- package/dist/r/about.json +2 -1
- package/dist/r/browse.json +2 -1
- package/dist/r/collections.json +2 -1
- package/dist/r/contributors.json +2 -1
- package/dist/r/default.json +7 -6
- package/dist/r/home.json +2 -1
- package/dist/r/not-found.json +2 -1
- package/dist/r/project-card.json +2 -1
- package/dist/r/record.json +3 -2
- package/dist/r/registry.json +26 -13
- package/dist/r/shell.json +2 -1
- package/dist/r/submit.json +3 -2
- package/dist/r/taxonomy.json +5 -4
- package/dist/r/ui.json +2 -1
- package/dist/registry.d.ts +6 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/update.d.ts +24 -5
- package/dist/update.d.ts.map +1 -1
- package/dist/update.js +83 -3
- package/dist/update.js.map +1 -1
- package/package.json +5 -4
package/dist/init.js
CHANGED
|
@@ -17,10 +17,17 @@
|
|
|
17
17
|
* `npx shadcn add @grove/<item>` works later) — plus the files
|
|
18
18
|
* the scaffold does not ship because they are project-specific:
|
|
19
19
|
* grove.config.ts, astro.config.mjs, and an empty data/records/.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* Last of these, for pnpm projects only, is pnpm-workspace.yaml,
|
|
21
|
+
* which approves the dependency build scripts pnpm 11 refuses to
|
|
22
|
+
* skip silently.
|
|
23
|
+
* 4. `<pm> dlx shadcn@<pinned> add <bundled default.json> --yes`,
|
|
24
|
+
* where `<pm>` is whichever package manager the user has —
|
|
25
|
+
* detected, not assumed. shadcn writes every scaffold file under
|
|
26
|
+
* src/ and runs the package manager to install the item's deps
|
|
27
|
+
* (astro, tailwindcss, …) with real version ranges. If shadcn
|
|
28
|
+
* fails, the bundled item is written in-process instead — it
|
|
29
|
+
* inlines every file and names its own dependencies, so nothing
|
|
30
|
+
* about the result depends on a third-party CLI staying healthy.
|
|
24
31
|
* 5. Add `@grove-dev/{core,astro,cli}` to package.json,
|
|
25
32
|
* pinned to this CLI's version. After step 4 on purpose: shadcn
|
|
26
33
|
* installs whatever package.json declares, and Grove's own
|
|
@@ -32,15 +39,19 @@
|
|
|
32
39
|
* `grove init` does NOT scaffold `content/`, `public/`, `.github/`, or
|
|
33
40
|
* anything under `data/` besides the empty `records/` directory —
|
|
34
41
|
* those are content/workflow concerns, not UI-registry concerns. The
|
|
35
|
-
* CLI wrapper in index.ts runs
|
|
42
|
+
* CLI wrapper in index.ts runs `<pm> install` and `git init` after
|
|
36
43
|
* this returns, per its own `--no-install`/`--no-git` flags.
|
|
44
|
+
*
|
|
45
|
+
* Steps 2-6 are transactional: if any of them throws, everything
|
|
46
|
+
* written since step 1 is removed again, so the obvious retry is just
|
|
47
|
+
* `grove init` and not `rm -rf` first.
|
|
37
48
|
*/
|
|
38
|
-
import {
|
|
39
|
-
import { mkdir, readdir, readFile, writeFile } from 'node:fs/promises';
|
|
49
|
+
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
40
50
|
import { dirname, resolve } from 'node:path';
|
|
41
51
|
import { fileURLToPath } from 'node:url';
|
|
42
52
|
import { writeLockfile } from './hash.js';
|
|
43
|
-
import {
|
|
53
|
+
import { detectPackageManager, dlxCommand, requirePackageManager, } from './package-manager.js';
|
|
54
|
+
import { buildLockfile, loadItem, REGISTRY_NAMESPACE, REGISTRY_URL_TEMPLATE, resolveBundledItemPath, SHADCN_VERSION, writeItemFiles, } from './registry.js';
|
|
44
55
|
import { run } from './run.js';
|
|
45
56
|
const SKIP_NAMES = new Set(['node_modules', 'dist', '.astro', '.DS_Store', '.grove']);
|
|
46
57
|
// The registry is not in this list on purpose: shadcn installed the UI
|
|
@@ -52,6 +63,17 @@ const PROJECT_SCRIPTS = {
|
|
|
52
63
|
build: 'astro build',
|
|
53
64
|
check: 'astro check',
|
|
54
65
|
};
|
|
66
|
+
/**
|
|
67
|
+
* Dependency install scripts the generated project approves up front.
|
|
68
|
+
*
|
|
69
|
+
* astro pulls in vite, which pulls in esbuild, whose install script
|
|
70
|
+
* links esbuild's platform binary. pnpm 11 fails any install that
|
|
71
|
+
* skipped a build script (`ERR_PNPM_IGNORED_BUILDS`, exit 1) — which
|
|
72
|
+
* killed shadcn's `pnpm add` before it wrote a single scaffold file
|
|
73
|
+
* and left `grove init` with a package.json and no src/. pnpm 10 only
|
|
74
|
+
* warned, which is why CI, pinned to 10.12.1, never saw it.
|
|
75
|
+
*/
|
|
76
|
+
const APPROVED_BUILD_SCRIPTS = ['esbuild'];
|
|
55
77
|
export function readCliVersion() {
|
|
56
78
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
57
79
|
for (const candidate of [resolve(here, 'package.json'), resolve(here, '../package.json')]) {
|
|
@@ -82,18 +104,6 @@ function packageName(value) {
|
|
|
82
104
|
.replace(/[^a-z0-9._-]+/g, '-')
|
|
83
105
|
.replace(/^-+|-+$/g, '') || 'grove-directory');
|
|
84
106
|
}
|
|
85
|
-
/**
|
|
86
|
-
* `grove init` drives pnpm — for the shadcn `dlx` call, for the
|
|
87
|
-
* dependency install, and for the lockfile shadcn's package-manager
|
|
88
|
-
* detector reads. Check for it before writing anything.
|
|
89
|
-
*/
|
|
90
|
-
function requirePnpm() {
|
|
91
|
-
const probe = spawnSync('pnpm', ['--version'], { stdio: 'ignore' });
|
|
92
|
-
if (probe.error || probe.status !== 0) {
|
|
93
|
-
throw new Error('grove init needs pnpm on your PATH (it runs `pnpm dlx shadcn` and `pnpm install`).\n' +
|
|
94
|
-
'Install it with `npm install -g pnpm` or `corepack enable pnpm`, then run grove init again.');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
107
|
async function ensureEmpty(targetDir) {
|
|
98
108
|
await mkdir(targetDir, { recursive: true });
|
|
99
109
|
const entries = (await readdir(targetDir)).filter((entry) => !SKIP_NAMES.has(entry));
|
|
@@ -102,25 +112,105 @@ async function ensureEmpty(targetDir) {
|
|
|
102
112
|
}
|
|
103
113
|
}
|
|
104
114
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* so the user sees the package manager's install output.
|
|
109
|
-
*
|
|
110
|
-
* shadcn picks the package manager for the item's dependencies from
|
|
111
|
-
* the lockfile (or `packageManager` field) it finds in the project —
|
|
112
|
-
* neither exists in a fresh directory, and its `add` path has no
|
|
113
|
-
* user-agent fallback, so it would default to npm and leave a
|
|
114
|
-
* package-lock.json behind in a project the rest of this CLI drives
|
|
115
|
-
* with pnpm. An empty pnpm-lock.yaml is enough for the detector; pnpm
|
|
116
|
-
* itself accepts the empty file and replaces it with a real one.
|
|
115
|
+
* pnpm's two spellings of the same build-script approval. pnpm 11 reads
|
|
116
|
+
* `allowBuilds` and ignores `onlyBuiltDependencies`; pnpm 10 does the
|
|
117
|
+
* reverse. Writing both keeps one generated project working on either.
|
|
117
118
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
119
|
+
function pnpmWorkspaceYaml() {
|
|
120
|
+
return [
|
|
121
|
+
'# Dependency install scripts this project approves.',
|
|
122
|
+
'#',
|
|
123
|
+
'# astro pulls in vite, which pulls in esbuild, whose install script',
|
|
124
|
+
"# links esbuild's platform binary. pnpm 11 refuses to finish an",
|
|
125
|
+
'# install that skipped a build script; pnpm 10 spells the same',
|
|
126
|
+
'# approval differently and ignores the key it does not know.',
|
|
127
|
+
'allowBuilds:',
|
|
128
|
+
...APPROVED_BUILD_SCRIPTS.map((name) => ` ${name}: true`),
|
|
129
|
+
'onlyBuiltDependencies:',
|
|
130
|
+
...APPROVED_BUILD_SCRIPTS.map((name) => ` - ${name}`),
|
|
131
|
+
'',
|
|
132
|
+
].join('\n');
|
|
133
|
+
}
|
|
134
|
+
/** Write a file only if it is not already there — never clobber a consumer's. */
|
|
135
|
+
async function writeIfAbsent(path, content) {
|
|
136
|
+
await writeFile(path, content, { encoding: 'utf8', flag: 'wx' }).catch((err) => {
|
|
120
137
|
if (err.code !== 'EEXIST')
|
|
121
138
|
throw err;
|
|
122
139
|
});
|
|
123
|
-
|
|
140
|
+
}
|
|
141
|
+
/** Read-modify-write a package.json, always through a fresh `dependencies`. */
|
|
142
|
+
async function updatePackageJson(path, mutate) {
|
|
143
|
+
const pkg = JSON.parse(await readFile(path, 'utf8'));
|
|
144
|
+
const next = { ...pkg, dependencies: { ...(pkg.dependencies ?? {}) } };
|
|
145
|
+
mutate(next);
|
|
146
|
+
await writeJson(path, next);
|
|
147
|
+
}
|
|
148
|
+
/** `@astrojs/check@^0.9.9` → `['@astrojs/check', '^0.9.9']`. Splits on the LAST `@`. */
|
|
149
|
+
function parseDependencySpec(spec) {
|
|
150
|
+
const at = spec.lastIndexOf('@');
|
|
151
|
+
if (at <= 0)
|
|
152
|
+
return [spec, 'latest'];
|
|
153
|
+
return [spec.slice(0, at), spec.slice(at + 1)];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* What `shadcn add` would have done, done in-process.
|
|
157
|
+
*
|
|
158
|
+
* shadcn is a third-party CLI fetched at run time: a bad release, an
|
|
159
|
+
* offline machine, or a package manager it cannot drive takes it down —
|
|
160
|
+
* and used to take the whole scaffold with it, because it aborts before
|
|
161
|
+
* writing anything. Nothing it does here is out of reach: the bundled
|
|
162
|
+
* item inlines all of its files and names its own npm dependencies, and
|
|
163
|
+
* `writeItemFiles` is the same writer `grove update` already trusts. So
|
|
164
|
+
* record the dependencies and let the `pnpm install` that follows
|
|
165
|
+
* resolve them.
|
|
166
|
+
*/
|
|
167
|
+
async function installScaffoldDirectly(item, target, packagePath) {
|
|
168
|
+
await writeItemFiles(item, target);
|
|
169
|
+
await updatePackageJson(packagePath, (pkg) => {
|
|
170
|
+
for (const spec of item.dependencies ?? []) {
|
|
171
|
+
const [name, range] = parseDependencySpec(spec);
|
|
172
|
+
pkg.dependencies[name] ??= range;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Undo a failed init. `ensureEmpty()` proved the directory held nothing
|
|
178
|
+
* but SKIP_NAMES entries, so everything that appeared since is ours to
|
|
179
|
+
* remove — and leaving it behind is worse than useless: the obvious
|
|
180
|
+
* retry then trips `ensureEmpty` with "not empty" and the user has to
|
|
181
|
+
* clean up by hand before trying again.
|
|
182
|
+
*/
|
|
183
|
+
async function rollback(target, preexisting) {
|
|
184
|
+
const entries = await readdir(target).catch(() => []);
|
|
185
|
+
for (const entry of entries) {
|
|
186
|
+
if (preexisting.has(entry))
|
|
187
|
+
continue;
|
|
188
|
+
await rm(resolve(target, entry), { recursive: true, force: true });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Default scaffold installer: the official shadcn CLI, pinned, fetched
|
|
193
|
+
* with whichever package manager this project is being scaffolded for.
|
|
194
|
+
* The item path must be absolute — shadcn rejects relative local paths
|
|
195
|
+
* as unsafe. `--yes` skips the confirmation prompts; stdio is inherited
|
|
196
|
+
* so the user sees the install output.
|
|
197
|
+
*
|
|
198
|
+
* shadcn picks the package manager for the item's dependencies from the
|
|
199
|
+
* lockfile or the `packageManager` field it finds in the project, and
|
|
200
|
+
* its `add` path has no user-agent fallback — a fresh directory has
|
|
201
|
+
* neither, so it would silently default to npm. Step 2 writes
|
|
202
|
+
* `packageManager` for exactly that reason; without it a bun project
|
|
203
|
+
* would come back with a package-lock.json in it.
|
|
204
|
+
*/
|
|
205
|
+
export async function installScaffoldWithShadcn({ target, itemPath, packageManager, }) {
|
|
206
|
+
const [command, args] = dlxCommand(packageManager, `shadcn@${SHADCN_VERSION}`, [
|
|
207
|
+
'add',
|
|
208
|
+
itemPath,
|
|
209
|
+
'--yes',
|
|
210
|
+
'--cwd',
|
|
211
|
+
target,
|
|
212
|
+
]);
|
|
213
|
+
await run(command, args, target);
|
|
124
214
|
}
|
|
125
215
|
async function writeJson(path, value) {
|
|
126
216
|
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
@@ -134,13 +224,26 @@ export async function initDirectory(targetDir, options = {}) {
|
|
|
134
224
|
const target = resolve(targetDir);
|
|
135
225
|
// 1. Never install over someone's work.
|
|
136
226
|
await ensureEmpty(target);
|
|
137
|
-
// 1b.
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
//
|
|
142
|
-
|
|
143
|
-
|
|
227
|
+
// 1b. Settle the package manager and confirm it is really there before
|
|
228
|
+
// writing anything, rather than dying partway through.
|
|
229
|
+
const detected = options.packageManager ?? detectPackageManager();
|
|
230
|
+
const packageManager = options.installScaffold === undefined ? requirePackageManager(detected, target) : detected;
|
|
231
|
+
// 1c. Whatever is here now (only SKIP_NAMES entries, per ensureEmpty)
|
|
232
|
+
// is not ours; everything else that appears is, and comes back off
|
|
233
|
+
// again if a later step throws.
|
|
234
|
+
const preexisting = new Set(await readdir(target));
|
|
235
|
+
try {
|
|
236
|
+
return await scaffold(target, options, packageManager);
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
await rollback(target, preexisting);
|
|
240
|
+
console.error(`\nRemoved the partial scaffold in ${target}; ` +
|
|
241
|
+
'run grove init again once the error below is fixed.\n');
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/** Steps 2-6. Only called through `initDirectory`, which owns the rollback. */
|
|
246
|
+
async function scaffold(target, options, packageManager) {
|
|
144
247
|
const version = options.version ?? readCliVersion();
|
|
145
248
|
const fallbackName = target.split(/[\\/]/).at(-1) ?? 'grove-directory';
|
|
146
249
|
const rawName = options.projectName ?? fallbackName;
|
|
@@ -149,10 +252,16 @@ export async function initDirectory(targetDir, options = {}) {
|
|
|
149
252
|
// 2. package.json. Scripts are fixed here — registry items carry
|
|
150
253
|
// files and npm dependency names, not scripts. Dependencies are
|
|
151
254
|
// filled in by shadcn (step 4) and by us (step 5).
|
|
255
|
+
// `packageManager` is the one signal shadcn's package-manager
|
|
256
|
+
// detector can read in an otherwise empty directory, and it is
|
|
257
|
+
// what keeps a bun or yarn scaffold from being installed by npm.
|
|
152
258
|
const packagePath = resolve(target, 'package.json');
|
|
153
259
|
await writeJson(packagePath, {
|
|
154
260
|
name: projectName,
|
|
155
261
|
type: 'module',
|
|
262
|
+
...(packageManager.version
|
|
263
|
+
? { packageManager: `${packageManager.name}@${packageManager.version}` }
|
|
264
|
+
: {}),
|
|
156
265
|
scripts: { ...PROJECT_SCRIPTS },
|
|
157
266
|
dependencies: {},
|
|
158
267
|
});
|
|
@@ -271,19 +380,37 @@ export default defineConfig({
|
|
|
271
380
|
const recordsDir = resolve(target, 'data', 'records');
|
|
272
381
|
await mkdir(recordsDir, { recursive: true });
|
|
273
382
|
await writeFile(resolve(recordsDir, '.gitkeep'), '# Add one YAML file per record here — see /getting-started/first-record/.\n', 'utf8');
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
383
|
+
// 3f. pnpm-workspace.yaml. Every install a pnpm project will ever run
|
|
384
|
+
// — shadcn's in the next step, the one in index.ts, and the
|
|
385
|
+
// consumer's own later on — needs the scaffold's dependency build
|
|
386
|
+
// scripts approved, or pnpm 11 aborts the lot. npm, yarn and bun
|
|
387
|
+
// run install scripts without asking, so this file is pnpm's
|
|
388
|
+
// alone and would only be noise in their projects.
|
|
389
|
+
if (packageManager.name === 'pnpm') {
|
|
390
|
+
await writeIfAbsent(resolve(target, 'pnpm-workspace.yaml'), pnpmWorkspaceYaml());
|
|
391
|
+
}
|
|
392
|
+
// 4. Install the scaffold item. shadcn is the installer of record;
|
|
393
|
+
// when it fails, finish the job in-process rather than hand back a
|
|
394
|
+
// project with no src/ in it.
|
|
395
|
+
const itemPath = options.itemPath ?? resolveBundledItemPath();
|
|
396
|
+
const item = await loadItem(itemPath);
|
|
397
|
+
try {
|
|
398
|
+
await installScaffold({ target, itemPath, packageManager });
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
402
|
+
console.warn(`\nInstalling the scaffold with shadcn failed: ${reason}\n` +
|
|
403
|
+
`Writing the bundled ${REGISTRY_NAMESPACE}/${item.name} item directly instead.\n`);
|
|
404
|
+
await installScaffoldDirectly(item, target, packagePath);
|
|
405
|
+
}
|
|
277
406
|
// 5. Grove's own packages, pinned to this CLI's version. Read-modify-
|
|
278
|
-
// write:
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
await writeJson(packagePath, pkg);
|
|
407
|
+
// write: step 4 rewrote package.json with the item's dependencies.
|
|
408
|
+
await updatePackageJson(packagePath, (pkg) => {
|
|
409
|
+
for (const dep of GROVE_PACKAGES)
|
|
410
|
+
pkg.dependencies[dep] = `^${version}`;
|
|
411
|
+
});
|
|
284
412
|
// 6. Record what was installed for `grove update`.
|
|
285
|
-
const item = await loadItem(itemPath);
|
|
286
413
|
await writeLockfile(target, buildLockfile(item));
|
|
287
|
-
return { targetDir: target, projectName, installedScaffold: item };
|
|
414
|
+
return { targetDir: target, projectName, installedScaffold: item, packageManager };
|
|
288
415
|
}
|
|
289
416
|
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,UAAU,EAEV,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,QAAQ,EACR,kBAAkB,EAClB,qBAAqB,EAErB,sBAAsB,EACtB,cAAc,EACd,cAAc,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtF,uEAAuE;AACvE,0EAA0E;AAC1E,yCAAyC;AACzC,MAAM,cAAc,GAAG,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,gBAAgB,CAAU,CAAC;AAC1F,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,WAAW;IAChB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,aAAa;CACZ,CAAC;AACX;;;;;;;;;GASG;AACH,MAAM,sBAAsB,GAAG,CAAC,SAAS,CAAU,CAAC;AA6CpD,MAAM,UAAU,cAAc;IAC5B,MAAM,IAAI,GAAG,OAAO,C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E,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED,sEAAsE;IACtE,sEAAsE;IACtE,MAAM,iBAAiB,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE;QAC3C,KAAK,MAAM,GAAG,IAAI,cAAc;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,IAAI,OAAO,EAAE,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,mDAAmD;IACnD,MAAM,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export type PackageManagerName = 'pnpm' | 'npm' | 'yarn' | 'bun';
|
|
2
|
+
export interface PackageManager {
|
|
3
|
+
name: PackageManagerName;
|
|
4
|
+
/** Exact version, filled in by `requirePackageManager()`. */
|
|
5
|
+
version?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* `pnpm/10.12.1 npm/? node/v22.22.2 darwin arm64` → pnpm 10.12.1.
|
|
9
|
+
*
|
|
10
|
+
* Every package manager sets `npm_config_user_agent` for the processes
|
|
11
|
+
* it spawns, `npx`/`bunx`/`yarn dlx`/`pnpm dlx` included — so this is
|
|
12
|
+
* how the CLI knows what invoked it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseUserAgent(agent: string | undefined): PackageManager | null;
|
|
15
|
+
/**
|
|
16
|
+
* Which package manager to use in `cwd`, in order of how much the
|
|
17
|
+
* signal actually knows about the user's intent:
|
|
18
|
+
*
|
|
19
|
+
* 1. The project's own `packageManager` field — an explicit choice.
|
|
20
|
+
* 2. Its lockfile — the choice it has been living with.
|
|
21
|
+
* 3. `npm_config_user_agent` — how this very command was launched,
|
|
22
|
+
* which is all `grove init` into a fresh directory has to go on.
|
|
23
|
+
* 4. Whatever is installed, pnpm first, so a machine with no signal
|
|
24
|
+
* behaves the way Grove always did.
|
|
25
|
+
*/
|
|
26
|
+
export declare function detectPackageManager(cwd?: string): PackageManager;
|
|
27
|
+
/**
|
|
28
|
+
* Confirm the package manager is really there before anything is
|
|
29
|
+
* written, and pin down its exact version while we are asking — the
|
|
30
|
+
* generated project records it so shadcn, corepack and the next
|
|
31
|
+
* contributor all agree on which one this project uses.
|
|
32
|
+
*
|
|
33
|
+
* `cwd` is the project being created, not the directory the command was
|
|
34
|
+
* typed in. pnpm and yarn re-exec the version a surrounding project
|
|
35
|
+
* pins, so probing anywhere else reports that neighbour's version and
|
|
36
|
+
* stamps it onto an unrelated new project.
|
|
37
|
+
*/
|
|
38
|
+
export declare function requirePackageManager(pm: PackageManager, cwd: string): PackageManager;
|
|
39
|
+
/** `npm install`, `pnpm install`, `yarn install`, `bun install`. */
|
|
40
|
+
export declare function installCommand(pm: PackageManager): [command: string, args: string[]];
|
|
41
|
+
/** How the user runs a package.json script: always `<pm> run <script>`. */
|
|
42
|
+
export declare function runScriptCommand(pm: PackageManager, script: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Fetch and run a package straight from the registry, npx-style.
|
|
45
|
+
*
|
|
46
|
+
* Yarn is the awkward one: `dlx` arrived in Yarn 2, and on Yarn Classic
|
|
47
|
+
* `yarn dlx` is parsed as `yarn run dlx` and fails. Probe the major
|
|
48
|
+
* rather than guess, and fall back to `npx`, which ships with Node.
|
|
49
|
+
*/
|
|
50
|
+
export declare function dlxCommand(pm: PackageManager, spec: string, args: string[]): [command: string, args: string[]];
|
|
51
|
+
/**
|
|
52
|
+
* A binary installed in the project itself. Grove runs `astro` this
|
|
53
|
+
* way rather than through `<pm> exec`: the file is right there, and
|
|
54
|
+
* asking a package manager to find it only adds a way to fail.
|
|
55
|
+
*/
|
|
56
|
+
export declare function localBin(cwd: string, name: string): string;
|
|
57
|
+
//# sourceMappingURL=package-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAsBA,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;AAEjE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,kBAAkB,CAAC;IACzB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAkBD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,cAAc,GAAG,IAAI,CAM/E;AA+BD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAsB,GAAG,cAAc,CAQhF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,CAWrF;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,EAAE,EAAE,cAAc,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAEpF;AAED,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,EAAE,EAAE,cAAc,EAClB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EAAE,GACb,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAiBnC;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1D"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Which package manager Grove drives, and how.
|
|
4
|
+
*
|
|
5
|
+
* Grove used to hardcode pnpm: `grove init` refused to start without
|
|
6
|
+
* it, and `grove check` shelled out to `pnpm exec astro check` even in
|
|
7
|
+
* a project npm had installed — so a bun or yarn user who followed the
|
|
8
|
+
* docs (which advertise npm/yarn/bun tabs on every page) hit
|
|
9
|
+
* `spawn pnpm ENOENT` from a command that only wanted a local binary.
|
|
10
|
+
*
|
|
11
|
+
* Two rules come out of that and are worth keeping:
|
|
12
|
+
*
|
|
13
|
+
* - Never spawn a package manager to run something already installed
|
|
14
|
+
* in the project. `localBin()` is the whole answer there.
|
|
15
|
+
* - When one genuinely is needed — installing dependencies, fetching
|
|
16
|
+
* shadcn — use the one the user actually has, not the one Grove
|
|
17
|
+
* was written against.
|
|
18
|
+
*/
|
|
19
|
+
import { spawnSync } from 'node:child_process';
|
|
20
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
/** Preference order when a directory carries no signal at all. */
|
|
23
|
+
const FALLBACK_ORDER = ['pnpm', 'npm', 'yarn', 'bun'];
|
|
24
|
+
/** Lockfiles, most specific first — `bun.lock` and `bun.lockb` both mean bun. */
|
|
25
|
+
const LOCKFILES = [
|
|
26
|
+
['pnpm-lock.yaml', 'pnpm'],
|
|
27
|
+
['bun.lock', 'bun'],
|
|
28
|
+
['bun.lockb', 'bun'],
|
|
29
|
+
['yarn.lock', 'yarn'],
|
|
30
|
+
['package-lock.json', 'npm'],
|
|
31
|
+
];
|
|
32
|
+
function isName(value) {
|
|
33
|
+
return value === 'pnpm' || value === 'npm' || value === 'yarn' || value === 'bun';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `pnpm/10.12.1 npm/? node/v22.22.2 darwin arm64` → pnpm 10.12.1.
|
|
37
|
+
*
|
|
38
|
+
* Every package manager sets `npm_config_user_agent` for the processes
|
|
39
|
+
* it spawns, `npx`/`bunx`/`yarn dlx`/`pnpm dlx` included — so this is
|
|
40
|
+
* how the CLI knows what invoked it.
|
|
41
|
+
*/
|
|
42
|
+
export function parseUserAgent(agent) {
|
|
43
|
+
const first = agent?.trim().split(/\s+/)[0];
|
|
44
|
+
if (!first)
|
|
45
|
+
return null;
|
|
46
|
+
const [name, version] = first.split('/');
|
|
47
|
+
if (!name || !isName(name))
|
|
48
|
+
return null;
|
|
49
|
+
return version && version !== '?' ? { name, version } : { name };
|
|
50
|
+
}
|
|
51
|
+
/** The `packageManager` field of a directory's package.json, if any. */
|
|
52
|
+
function fromManifest(cwd) {
|
|
53
|
+
try {
|
|
54
|
+
const manifest = JSON.parse(readFileSync(join(cwd, 'package.json'), 'utf8'));
|
|
55
|
+
const [name, version] = (manifest.packageManager ?? '').split('@');
|
|
56
|
+
if (!name || !isName(name))
|
|
57
|
+
return null;
|
|
58
|
+
// The field may carry a `+sha224.…` integrity suffix; drop it.
|
|
59
|
+
const exact = version?.split('+')[0];
|
|
60
|
+
return exact ? { name, version: exact } : { name };
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// No package.json, or not ours to parse.
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function fromLockfile(cwd) {
|
|
68
|
+
for (const [file, name] of LOCKFILES) {
|
|
69
|
+
if (existsSync(join(cwd, file)))
|
|
70
|
+
return { name };
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function onPath(name) {
|
|
75
|
+
const probe = spawnSync(name, ['--version'], { stdio: 'ignore' });
|
|
76
|
+
return !probe.error && probe.status === 0;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Which package manager to use in `cwd`, in order of how much the
|
|
80
|
+
* signal actually knows about the user's intent:
|
|
81
|
+
*
|
|
82
|
+
* 1. The project's own `packageManager` field — an explicit choice.
|
|
83
|
+
* 2. Its lockfile — the choice it has been living with.
|
|
84
|
+
* 3. `npm_config_user_agent` — how this very command was launched,
|
|
85
|
+
* which is all `grove init` into a fresh directory has to go on.
|
|
86
|
+
* 4. Whatever is installed, pnpm first, so a machine with no signal
|
|
87
|
+
* behaves the way Grove always did.
|
|
88
|
+
*/
|
|
89
|
+
export function detectPackageManager(cwd = process.cwd()) {
|
|
90
|
+
return (fromManifest(cwd) ??
|
|
91
|
+
fromLockfile(cwd) ??
|
|
92
|
+
parseUserAgent(process.env.npm_config_user_agent) ?? {
|
|
93
|
+
name: FALLBACK_ORDER.find(onPath) ?? 'npm',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Confirm the package manager is really there before anything is
|
|
98
|
+
* written, and pin down its exact version while we are asking — the
|
|
99
|
+
* generated project records it so shadcn, corepack and the next
|
|
100
|
+
* contributor all agree on which one this project uses.
|
|
101
|
+
*
|
|
102
|
+
* `cwd` is the project being created, not the directory the command was
|
|
103
|
+
* typed in. pnpm and yarn re-exec the version a surrounding project
|
|
104
|
+
* pins, so probing anywhere else reports that neighbour's version and
|
|
105
|
+
* stamps it onto an unrelated new project.
|
|
106
|
+
*/
|
|
107
|
+
export function requirePackageManager(pm, cwd) {
|
|
108
|
+
const probe = spawnSync(pm.name, ['--version'], { cwd, encoding: 'utf8' });
|
|
109
|
+
if (probe.error || probe.status !== 0) {
|
|
110
|
+
throw new Error(`grove init needs ${pm.name} on your PATH (it installs the scaffold's dependencies with it).\n` +
|
|
111
|
+
`Install ${pm.name}, or run grove init through the package manager you do have — ` +
|
|
112
|
+
'the CLI follows whichever one launches it.');
|
|
113
|
+
}
|
|
114
|
+
const version = probe.stdout.trim();
|
|
115
|
+
return version ? { ...pm, version } : pm;
|
|
116
|
+
}
|
|
117
|
+
/** `npm install`, `pnpm install`, `yarn install`, `bun install`. */
|
|
118
|
+
export function installCommand(pm) {
|
|
119
|
+
return [pm.name, ['install']];
|
|
120
|
+
}
|
|
121
|
+
/** How the user runs a package.json script: always `<pm> run <script>`. */
|
|
122
|
+
export function runScriptCommand(pm, script) {
|
|
123
|
+
return `${pm.name} run ${script}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetch and run a package straight from the registry, npx-style.
|
|
127
|
+
*
|
|
128
|
+
* Yarn is the awkward one: `dlx` arrived in Yarn 2, and on Yarn Classic
|
|
129
|
+
* `yarn dlx` is parsed as `yarn run dlx` and fails. Probe the major
|
|
130
|
+
* rather than guess, and fall back to `npx`, which ships with Node.
|
|
131
|
+
*/
|
|
132
|
+
export function dlxCommand(pm, spec, args) {
|
|
133
|
+
switch (pm.name) {
|
|
134
|
+
case 'pnpm':
|
|
135
|
+
return ['pnpm', ['dlx', spec, ...args]];
|
|
136
|
+
case 'bun':
|
|
137
|
+
return ['bunx', [spec, ...args]];
|
|
138
|
+
case 'yarn': {
|
|
139
|
+
const major = Number.parseInt(pm.version ?? spawnSync('yarn', ['--version'], { encoding: 'utf8' }).stdout?.trim() ?? '', 10);
|
|
140
|
+
if (major >= 2)
|
|
141
|
+
return ['yarn', ['dlx', spec, ...args]];
|
|
142
|
+
return ['npx', ['--yes', spec, ...args]];
|
|
143
|
+
}
|
|
144
|
+
default:
|
|
145
|
+
return ['npm', ['exec', '--yes', '--', spec, ...args]];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A binary installed in the project itself. Grove runs `astro` this
|
|
150
|
+
* way rather than through `<pm> exec`: the file is right there, and
|
|
151
|
+
* asking a package manager to find it only adds a way to fail.
|
|
152
|
+
*/
|
|
153
|
+
export function localBin(cwd, name) {
|
|
154
|
+
const binary = process.platform === 'win32' ? `${name}.cmd` : name;
|
|
155
|
+
return join(cwd, 'node_modules', '.bin', binary);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=package-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,SAAS,EAA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": "module",
|
|
5
5
|
"description": "Grove CLI — scaffolds Grove-powered spaces and orchestrates @grove-dev/core commands.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"dist",
|
|
42
|
-
"README.md"
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
43
44
|
],
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.json && node -e \"require('fs').copyFileSync('package.json','dist/package.json')\" && node -e \"require('fs').cpSync('../registry/dist/r','dist/r',{recursive:true})\"",
|
package/dist/r/about.json
CHANGED
package/dist/r/browse.json
CHANGED
package/dist/r/collections.json
CHANGED