create-vanilla-vite 1.2.2 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3 - 2026-11-19
4
+
5
+ - Added feature toggle commands (`turn-on`, `trun-on`, `tN` and `turn-off`, `trun-off`, `tO`) to switch features like `adD` / install guard on and off dynamically.
6
+ - Added modular feature manager `scripts/toggle-feature.mjs` with alias resolution (`adD`, `add-dependency`, `install`, `i`, `add`, `guard`, `install-mode`) and status reporting.
7
+ - Fixed CLI update relaunch to target the exact new version instead of `@latest`, preventing pnpm and npm dlx/exec cache reuse of stale versions.
8
+ - Added a pre-publish changelog check in `pnpm vpublish` to verify an entry exists for the target version or prompt for changelog items.
9
+ - Extended `vpublish` to support passing changelog items non-interactively via `--changelog="<entry>"`.
10
+ - Raised pre-publish smoke validation timeout in version manager to 20 minutes with `VPUBLISH_TEST_TIMEOUT_MS` override.
11
+ - Replaced root node_modules symlinking in test suite with isolated fake binaries and minimal stubs.
12
+ - Fixed ReferenceError for file extensions in Express smoke tests.
13
+
3
14
  ## 1.2.2 - 2026-11-19
4
15
 
5
16
  - Added `--install-mode=adD|plain|both` option and interactive prompt to choose dependency installation behavior.
package/README.md CHANGED
@@ -174,6 +174,37 @@ npm run adD
174
174
 
175
175
  In `adD only` mode, do not use `npm install <package>`, `npm add <package>`, or `pnpm add <package>` directly to add packages. They bypass the location prompt and are blocked by the workspace install guard. A failed or aborted install can leave `node_modules` behind; running `pnpm adD` with no arguments safely syncs dependencies.
176
176
 
177
+ ### Toggle features on and off
178
+
179
+ You can dynamically toggle monorepo features on and off at any time.
180
+
181
+ To turn off `adD` / install guard (switches to plain install mode and hides the dev banner):
182
+ ```bash
183
+ pnpm turn-off adD
184
+ # or using shortcuts:
185
+ pnpm tO adD
186
+ pnpm tO
187
+ # with npm:
188
+ npm run tO -- adD
189
+ ```
190
+
191
+ To turn `adD` / install guard back on:
192
+ ```bash
193
+ pnpm turn-on adD
194
+ # or using shortcuts:
195
+ pnpm tN adD
196
+ pnpm tN
197
+ # with npm:
198
+ npm run tN -- adD
199
+ ```
200
+
201
+ Aliases supported for the `adD` feature: `adD`, `add-dependency`, `install`, `i`, `add`, `guard`, `install-mode`. When run without an argument, `tN` and `tO` target `adD` by default.
202
+
203
+ To inspect current features and their status:
204
+ ```bash
205
+ node scripts/toggle-feature.mjs status
206
+ ```
207
+
177
208
  ## Development
178
209
 
179
210
  To test from source:
@@ -287,7 +287,7 @@ async function updateIfOutdated() {
287
287
  }
288
288
  if (!stdin.isTTY) {
289
289
  console.warn(
290
- `\nA newer version of create-vanilla-vite is available (${latestVersion}; current: ${installedVersion}). Run ${packageManager} create vanilla-vite@latest to use it.`,
290
+ `\nA newer version of create-vanilla-vite is available (${latestVersion}; current: ${installedVersion}). Run ${packageManager} create vanilla-vite@${latestVersion} to use it.`,
291
291
  );
292
292
  return;
293
293
  }
@@ -308,11 +308,11 @@ async function updateIfOutdated() {
308
308
  ];
309
309
  const updateArgs =
310
310
  packageManager === "pnpm"
311
- ? ["dlx", "create-vanilla-vite@latest", ...relaunchArgs]
311
+ ? ["dlx", `create-vanilla-vite@${latestVersion}`, ...relaunchArgs]
312
312
  : [
313
313
  "exec",
314
314
  "--yes",
315
- "--package=create-vanilla-vite@latest",
315
+ `--package=create-vanilla-vite@${latestVersion}`,
316
316
  "--",
317
317
  "create-vanilla-vite",
318
318
  ...relaunchArgs,
@@ -1682,6 +1682,7 @@ try {
1682
1682
  "dev.mjs",
1683
1683
  "run-app.mjs",
1684
1684
  "install-info.mjs",
1685
+ "toggle-feature.mjs",
1685
1686
  ...(installMode !== "plain" ? ["add-dependency.mjs"] : []),
1686
1687
  ];
1687
1688
  await Promise.all(scriptsToCopy.map(copyScript));
@@ -1714,6 +1715,12 @@ try {
1714
1715
  }
1715
1716
  : {}),
1716
1717
  ...(includeServer ? { server: "node scripts/run-app.mjs server" } : {}),
1718
+ "turn-on": "node scripts/toggle-feature.mjs on",
1719
+ "trun-on": "node scripts/toggle-feature.mjs on",
1720
+ tN: "node scripts/toggle-feature.mjs on",
1721
+ "turn-off": "node scripts/toggle-feature.mjs off",
1722
+ "trun-off": "node scripts/toggle-feature.mjs off",
1723
+ tO: "node scripts/toggle-feature.mjs off",
1717
1724
  },
1718
1725
  type: "module",
1719
1726
  dependencies: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vanilla-vite",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Scaffold a React or Vite app with an optional Node.js or Express backend",
5
5
  "type": "module",
6
6
  "repository": {
@@ -20,6 +20,7 @@
20
20
  "scripts/run-app.mjs",
21
21
  "scripts/install-info.mjs",
22
22
  "scripts/add-dependency.mjs",
23
+ "scripts/toggle-feature.mjs",
23
24
  "CHANGELOG.md",
24
25
  "README.md"
25
26
  ],
@@ -50,10 +51,21 @@
50
51
  "dependencies": {
51
52
  "cross-spawn": "^7.0.6"
52
53
  },
54
+ "vanillaVite": {
55
+ "installMode": "adD"
56
+ },
53
57
  "scripts": {
54
58
  "test": "node test/fixes.test.mjs && node test/version-manager.test.mjs && node test/smoke.mjs --quick",
55
59
  "test:unit": "node test/fixes.test.mjs && node test/version-manager.test.mjs",
56
60
  "test:smoke": "node test/smoke.mjs",
57
- "vpublish": "node scripts/version-manager.mjs"
61
+ "vpublish": "node scripts/version-manager.mjs",
62
+ "turn-on": "node scripts/toggle-feature.mjs on",
63
+ "trun-on": "node scripts/toggle-feature.mjs on",
64
+ "tN": "node scripts/toggle-feature.mjs on",
65
+ "turn-off": "node scripts/toggle-feature.mjs off",
66
+ "trun-off": "node scripts/toggle-feature.mjs off",
67
+ "tO": "node scripts/toggle-feature.mjs off",
68
+ "adD": "node scripts/add-dependency.mjs",
69
+ "add-dependency": "node scripts/add-dependency.mjs"
58
70
  }
59
71
  }
@@ -0,0 +1,407 @@
1
+ import { readFile, writeFile, mkdir } from "node:fs/promises";
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const root = fileURLToPath(new URL("../", import.meta.url));
7
+
8
+ const ADD_DEPENDENCY_TEMPLATE = `import { readFile } from "node:fs/promises";
9
+ import { join } from "node:path";
10
+ import { fileURLToPath } from "node:url";
11
+ import { emitKeypressEvents } from "node:readline";
12
+ import { stdin, stdout } from "node:process";
13
+ import spawn from "cross-spawn";
14
+
15
+ const root = fileURLToPath(new URL("../", import.meta.url));
16
+ const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
17
+ const packages = process.argv.slice(2);
18
+ const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
19
+ ? "pnpm"
20
+ : "npm";
21
+
22
+ if (packages.length === 0) {
23
+ console.log(\`Syncing workspace dependencies with \${packageManager} install...\`);
24
+ const child = spawn(packageManager, ["install"], {
25
+ cwd: root,
26
+ stdio: "inherit",
27
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
28
+ });
29
+ child.once("error", (error) => {
30
+ console.error(\`Unable to run \${packageManager}: \${error.message}\`);
31
+ process.exitCode = 1;
32
+ });
33
+ child.once("exit", (code, signal) => {
34
+ process.exitCode =
35
+ code ??
36
+ (signal === "SIGINT"
37
+ ? 130
38
+ : signal === "SIGTERM"
39
+ ? 143
40
+ : signal
41
+ ? 1
42
+ : 0);
43
+ });
44
+ await new Promise((resolve) => child.once("close", resolve));
45
+ process.exit(process.exitCode ?? 0);
46
+ }
47
+
48
+ if (!stdin.isTTY) {
49
+ console.error("Choose an install location in an interactive terminal.");
50
+ process.exit(1);
51
+ }
52
+
53
+ const targets = [
54
+ { label: \`Project root (\${project.name})\`, workspace: null },
55
+ ...project.workspaces.map((workspace) => ({
56
+ label: workspace,
57
+ workspace,
58
+ })),
59
+ ];
60
+
61
+ const defaultIndex = Math.max(
62
+ 0,
63
+ targets.findIndex((target) => target.workspace?.endsWith("-client")),
64
+ );
65
+ let selectedIndex = defaultIndex;
66
+ emitKeypressEvents(stdin);
67
+
68
+ const selectedTarget = await new Promise((resolveSelection) => {
69
+ function render() {
70
+ const question = "Where should the package be installed?";
71
+ const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
72
+ ? \`\\x1b[1;36m\${question}\\x1b[0m\`
73
+ : question;
74
+ stdout.write(\`\\r\\x1b[2K\${prompt}\\n\`);
75
+ targets.forEach((target, index) => {
76
+ stdout.write(\` \${index === selectedIndex ? ">" : " "} \${target.label}\\n\`);
77
+ });
78
+ stdout.write(" Use ↑/↓ to select, Enter to confirm, or Esc to keep the default.\\n");
79
+ stdout.write(\`\\x1b[\${targets.length + 2}A\`);
80
+ }
81
+
82
+ function finish(target) {
83
+ stdin.off("keypress", onKeypress);
84
+ stdin.setRawMode(false);
85
+ stdin.pause();
86
+ stdout.write(\`\\x1b[\${targets.length + 2}B\\n\`);
87
+ resolveSelection(target);
88
+ }
89
+
90
+ function onKeypress(_input, key) {
91
+ if (key?.name === "up" || key?.name === "down") {
92
+ selectedIndex =
93
+ (selectedIndex + (key.name === "down" ? 1 : targets.length - 1)) %
94
+ targets.length;
95
+ render();
96
+ } else if (key?.name === "return") finish(targets[selectedIndex]);
97
+ else if (key?.name === "escape") finish(targets[defaultIndex]);
98
+ else if (key?.ctrl && key.name === "c") {
99
+ stdin.off("keypress", onKeypress);
100
+ stdin.setRawMode(false);
101
+ stdin.pause();
102
+ stdout.write("\\n");
103
+ resolveSelection(null);
104
+ }
105
+ }
106
+
107
+ stdin.setRawMode(true);
108
+ stdin.resume();
109
+ stdin.on("keypress", onKeypress);
110
+ render();
111
+ });
112
+
113
+ if (!selectedTarget) {
114
+ process.exit(130);
115
+ }
116
+
117
+ const { workspace } = selectedTarget;
118
+ const commandArgs =
119
+ packageManager === "pnpm"
120
+ ? workspace
121
+ ? ["--filter", workspace, "add", ...packages]
122
+ : ["add", "--workspace-root", ...packages]
123
+ : workspace
124
+ ? ["install", ...packages, "--workspace", workspace]
125
+ : ["install", ...packages];
126
+ const child = spawn(packageManager, commandArgs, {
127
+ cwd: root,
128
+ stdio: "inherit",
129
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
130
+ });
131
+
132
+ child.once("error", (error) => {
133
+ console.error(\`Unable to run \${packageManager}: \${error.message}\`);
134
+ process.exitCode = 1;
135
+ });
136
+ child.once("exit", (code, signal) => {
137
+ process.exitCode =
138
+ code ??
139
+ (signal === "SIGINT"
140
+ ? 130
141
+ : signal === "SIGTERM"
142
+ ? 143
143
+ : signal
144
+ ? 1
145
+ : 0);
146
+ });
147
+ `;
148
+
149
+ export const FEATURES = {
150
+ adD: {
151
+ id: "adD",
152
+ name: "adD",
153
+ description: "Workspace dependency selector and direct install guard",
154
+ aliases: ["add", "add-dependency", "install", "i", "guard", "install-mode"],
155
+ isEnabled(project) {
156
+ return (project.vanillaVite?.installMode ?? "adD") !== "plain";
157
+ },
158
+ getStatus(project) {
159
+ const mode = project.vanillaVite?.installMode ?? "adD";
160
+ const hasScript = Boolean(project.scripts?.adD);
161
+ return {
162
+ enabled: mode !== "plain",
163
+ mode,
164
+ hasScript,
165
+ };
166
+ },
167
+ async turnOn({ rootDir, project, subOption, packageManager }) {
168
+ const targetMode = subOption === "both" || subOption === "--both" ? "both" : "adD";
169
+ project.vanillaVite = project.vanillaVite ?? {};
170
+ project.vanillaVite.installMode = targetMode;
171
+
172
+ project.scripts = project.scripts ?? {};
173
+ project.scripts.adD = "node scripts/add-dependency.mjs";
174
+ project.scripts["add-dependency"] = "node scripts/add-dependency.mjs";
175
+
176
+ const scriptsDir = join(rootDir, "scripts");
177
+ await mkdir(scriptsDir, { recursive: true });
178
+ const scriptPath = join(scriptsDir, "add-dependency.mjs");
179
+ if (!existsSync(scriptPath)) {
180
+ await writeFile(scriptPath, ADD_DEPENDENCY_TEMPLATE, "utf8");
181
+ }
182
+
183
+ await writeFile(
184
+ join(rootDir, "package.json"),
185
+ `${JSON.stringify(project, null, 2)}\n`,
186
+ "utf8",
187
+ );
188
+
189
+ const isPnpm = packageManager === "pnpm";
190
+ const addCmd = isPnpm ? "pnpm adD <package>" : "npm run adD -- <package>";
191
+ const addDepCmd = isPnpm
192
+ ? "pnpm add-dependency <package>"
193
+ : "npm run add-dependency -- <package>";
194
+ const turnOffCmd = isPnpm ? "pnpm tO adD" : "npm run tO -- adD";
195
+
196
+ console.log(`[feature] Feature 'adD' turned ON (mode: ${targetMode}).`);
197
+ console.log(` - Scripts enabled: ${addCmd}, ${addDepCmd}`);
198
+ if (targetMode === "both") {
199
+ console.log(" - Direct installs also permitted alongside adD.");
200
+ } else {
201
+ console.log(" - Direct root installs are guarded to preserve monorepo workspace structure.");
202
+ }
203
+ console.log(" - Development runner banner '>>> ADD DEPENDENCIES LATER <<<' is active.");
204
+ console.log(` To turn off: ${turnOffCmd}\n`);
205
+ },
206
+ async turnOff({ rootDir, project, packageManager }) {
207
+ project.vanillaVite = project.vanillaVite ?? {};
208
+ project.vanillaVite.installMode = "plain";
209
+
210
+ if (project.scripts) {
211
+ delete project.scripts.adD;
212
+ delete project.scripts["add-dependency"];
213
+ }
214
+
215
+ await writeFile(
216
+ join(rootDir, "package.json"),
217
+ `${JSON.stringify(project, null, 2)}\n`,
218
+ "utf8",
219
+ );
220
+
221
+ const isPnpm = packageManager === "pnpm";
222
+ const directInstall = isPnpm ? "pnpm add <package>" : "npm install <package>";
223
+ const turnOnCmd = isPnpm ? "pnpm tN adD" : "npm run tN -- adD";
224
+
225
+ console.log("[feature] Feature 'adD' turned OFF (mode: plain).");
226
+ console.log(` - Direct installs enabled: ${directInstall}`);
227
+ console.log(" - Removed 'adD' and 'add-dependency' scripts.");
228
+ console.log(" - Development runner banner '>>> ADD DEPENDENCIES LATER <<<' is hidden.");
229
+ console.log(` To turn on: ${turnOnCmd}\n`);
230
+ },
231
+ },
232
+ };
233
+
234
+ export function resolveFeature(featureInput) {
235
+ if (!featureInput) return null;
236
+ const normalized = featureInput.trim().toLowerCase();
237
+ for (const feature of Object.values(FEATURES)) {
238
+ if (feature.id.toLowerCase() === normalized) return feature;
239
+ if (feature.aliases.some((alias) => alias.toLowerCase() === normalized)) {
240
+ return feature;
241
+ }
242
+ }
243
+ return null;
244
+ }
245
+
246
+ const ACTION_ON_ALIASES = new Set(["on", "turn-on", "trun-on", "tn", "enable", "1", "true"]);
247
+ const ACTION_OFF_ALIASES = new Set(["off", "turn-off", "trun-off", "to", "disable", "0", "false"]);
248
+ const ACTION_STATUS_ALIASES = new Set(["status", "list", "info", "-s", "--status", "-l", "--list"]);
249
+ const ACTION_TOGGLE_ALIASES = new Set(["toggle", "t"]);
250
+
251
+ export function parseArgs(rawArgs) {
252
+ if (!rawArgs || rawArgs.length === 0) {
253
+ return { action: "status", featureName: null, subOption: null };
254
+ }
255
+
256
+ const normalizeFeature = (input) => {
257
+ if (!input) return "adD";
258
+ const matched = resolveFeature(input);
259
+ return matched ? matched.id : input;
260
+ };
261
+
262
+ const first = rawArgs[0].toLowerCase();
263
+
264
+ if (ACTION_STATUS_ALIASES.has(first)) {
265
+ return {
266
+ action: "status",
267
+ featureName: rawArgs[1] ? normalizeFeature(rawArgs[1]) : null,
268
+ subOption: rawArgs[2] ?? null,
269
+ };
270
+ }
271
+
272
+ if (ACTION_ON_ALIASES.has(first)) {
273
+ return {
274
+ action: "on",
275
+ featureName: normalizeFeature(rawArgs[1]),
276
+ subOption: rawArgs[2] ?? null,
277
+ };
278
+ }
279
+
280
+ if (ACTION_OFF_ALIASES.has(first)) {
281
+ return {
282
+ action: "off",
283
+ featureName: normalizeFeature(rawArgs[1]),
284
+ subOption: rawArgs[2] ?? null,
285
+ };
286
+ }
287
+
288
+ if (ACTION_TOGGLE_ALIASES.has(first)) {
289
+ return {
290
+ action: "toggle",
291
+ featureName: normalizeFeature(rawArgs[1]),
292
+ subOption: rawArgs[2] ?? null,
293
+ };
294
+ }
295
+
296
+ // Check if first argument is a feature identifier or alias
297
+ const matchedFeature = resolveFeature(first);
298
+ if (matchedFeature) {
299
+ const second = rawArgs[1]?.toLowerCase();
300
+ if (!second || ACTION_TOGGLE_ALIASES.has(second)) {
301
+ return { action: "toggle", featureName: matchedFeature.id, subOption: rawArgs[2] ?? null };
302
+ }
303
+ if (ACTION_ON_ALIASES.has(second)) {
304
+ return { action: "on", featureName: matchedFeature.id, subOption: rawArgs[2] ?? null };
305
+ }
306
+ if (ACTION_OFF_ALIASES.has(second)) {
307
+ return { action: "off", featureName: matchedFeature.id, subOption: rawArgs[2] ?? null };
308
+ }
309
+ if (ACTION_STATUS_ALIASES.has(second)) {
310
+ return { action: "status", featureName: matchedFeature.id, subOption: rawArgs[2] ?? null };
311
+ }
312
+ return { action: second, featureName: matchedFeature.id, subOption: rawArgs[2] ?? null };
313
+ }
314
+
315
+ return {
316
+ action: rawArgs[0],
317
+ featureName: rawArgs[1] ? normalizeFeature(rawArgs[1]) : null,
318
+ subOption: rawArgs[2] ?? null,
319
+ };
320
+ }
321
+
322
+ export async function toggleFeature({
323
+ rootDir = root,
324
+ action,
325
+ featureName,
326
+ subOption,
327
+ packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/") ? "pnpm" : "npm",
328
+ }) {
329
+ const packagePath = join(rootDir, "package.json");
330
+ let project;
331
+ try {
332
+ project = JSON.parse(await readFile(packagePath, "utf8"));
333
+ } catch (error) {
334
+ console.error(`Unable to read package.json at ${packagePath}: ${error.message}`);
335
+ process.exitCode = 1;
336
+ return;
337
+ }
338
+
339
+ if (action === "status") {
340
+ printStatus(project, packageManager);
341
+ return;
342
+ }
343
+
344
+ const targetName = featureName ?? "adD";
345
+ const feature = resolveFeature(targetName);
346
+ if (!feature) {
347
+ console.error(`Unknown feature: '${targetName}'.`);
348
+ console.error("Available features:");
349
+ for (const f of Object.values(FEATURES)) {
350
+ console.error(` - ${f.name} (aliases: ${f.aliases.join(", ")})`);
351
+ }
352
+ process.exitCode = 1;
353
+ return;
354
+ }
355
+
356
+ let finalAction = action;
357
+ if (finalAction === "toggle") {
358
+ finalAction = feature.isEnabled(project) ? "off" : "on";
359
+ }
360
+
361
+ if (finalAction === "on") {
362
+ await feature.turnOn({ rootDir, project, subOption, packageManager });
363
+ } else if (finalAction === "off") {
364
+ await feature.turnOff({ rootDir, project, packageManager });
365
+ } else {
366
+ console.error(`Invalid action '${action}'. Use 'on' or 'off'.`);
367
+ process.exitCode = 1;
368
+ }
369
+ }
370
+
371
+ function printStatus(project, packageManager) {
372
+ const isPnpm = packageManager === "pnpm";
373
+ console.log("Vanilla Vite Project Features:");
374
+ for (const feature of Object.values(FEATURES)) {
375
+ const status = feature.getStatus(project);
376
+ const stateStr = status.enabled ? "ENABLED" : "DISABLED";
377
+ console.log(`\n [${feature.name}] - ${stateStr}`);
378
+ console.log(` Description: ${feature.description}`);
379
+ console.log(` Mode: ${status.mode}`);
380
+ console.log(` Aliases: ${feature.aliases.join(", ")}`);
381
+ if (isPnpm) {
382
+ console.log(` Turn on: pnpm tN ${feature.name}`);
383
+ console.log(` Turn off: pnpm tO ${feature.name}`);
384
+ } else {
385
+ console.log(` Turn on: npm run tN -- ${feature.name}`);
386
+ console.log(` Turn off: npm run tO -- ${feature.name}`);
387
+ }
388
+ }
389
+ console.log("");
390
+ }
391
+
392
+ export async function main() {
393
+ const parsed = parseArgs(process.argv.slice(2));
394
+ await toggleFeature({
395
+ rootDir: root,
396
+ action: parsed.action,
397
+ featureName: parsed.featureName,
398
+ subOption: parsed.subOption,
399
+ });
400
+ }
401
+
402
+ if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
403
+ main().catch((error) => {
404
+ console.error(`Feature toggle error: ${error.message}`);
405
+ process.exit(1);
406
+ });
407
+ }