create-zenbu-app 0.0.19 → 0.0.20
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/index.mjs +47 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -138,6 +138,51 @@ function probeVersion(pm) {
|
|
|
138
138
|
const match = (res.stdout ?? "").trim().match(/\d+\.\d+\.\d+(?:[-+][\w.]+)?/);
|
|
139
139
|
return match ? match[0] : null;
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* `npx`, `npm create`, and `npm exec` all set the same `npm/<version>`
|
|
143
|
+
* user agent, so when `detectPackageManager` reports `npm` the user may
|
|
144
|
+
* actually prefer a different installed pm. Probe all four candidates,
|
|
145
|
+
* present only the ones present on the machine, and let the user pick
|
|
146
|
+
* (or pick automatically when only one is installed / `--yes`).
|
|
147
|
+
*/
|
|
148
|
+
async function resolveNpmAmbiguity(detected, opts) {
|
|
149
|
+
const candidates = [
|
|
150
|
+
"pnpm",
|
|
151
|
+
"npm",
|
|
152
|
+
"yarn",
|
|
153
|
+
"bun"
|
|
154
|
+
];
|
|
155
|
+
const installed = [];
|
|
156
|
+
for (const c of candidates) {
|
|
157
|
+
if (c === "npm") {
|
|
158
|
+
installed.push({
|
|
159
|
+
type: "npm",
|
|
160
|
+
version: detected.version,
|
|
161
|
+
fallback: false
|
|
162
|
+
});
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const v = probeVersion(c);
|
|
166
|
+
if (v) installed.push({
|
|
167
|
+
type: c,
|
|
168
|
+
version: v,
|
|
169
|
+
fallback: false
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
if (installed.length === 1) return installed[0];
|
|
173
|
+
const preferPnpm = installed.find((p) => p.type === "pnpm");
|
|
174
|
+
if (opts.yes) return preferPnpm ?? installed.find((p) => p.type === "npm");
|
|
175
|
+
const pick = await p.select({
|
|
176
|
+
message: "Which package manager should this app use?",
|
|
177
|
+
initialValue: preferPnpm?.type ?? "npm",
|
|
178
|
+
options: installed.map((p) => ({
|
|
179
|
+
value: p.type,
|
|
180
|
+
label: p.type === "pnpm" ? "pnpm (recommended)" : p.type
|
|
181
|
+
}))
|
|
182
|
+
});
|
|
183
|
+
if (p.isCancel(pick)) bail("Scaffolding cancelled.");
|
|
184
|
+
return installed.find((p) => p.type === pick);
|
|
185
|
+
}
|
|
141
186
|
function renderTemplate(value, ctx) {
|
|
142
187
|
return value.replace(/\{\{(\w+)\}\}/g, (full, key) => {
|
|
143
188
|
return Object.prototype.hasOwnProperty.call(ctx, key) ? ctx[key] : full;
|
|
@@ -407,7 +452,8 @@ async function main() {
|
|
|
407
452
|
templateDir = path.join(TEMPLATES_DIR, slug);
|
|
408
453
|
}
|
|
409
454
|
if (!fs.existsSync(templateDir)) bail(`No template found for configuration "${slug}".`);
|
|
410
|
-
|
|
455
|
+
let pm = detectPackageManager();
|
|
456
|
+
if (pm.type === "npm") pm = await resolveNpmAmbiguity(pm, { yes });
|
|
411
457
|
p.log.step(`Scaffolding Zenbu ${pluginMode ? "plugin" : "app"} in "${displayName}" (template: ${slug})`);
|
|
412
458
|
const ctx = pluginMode ? {
|
|
413
459
|
projectName: displayName,
|