create-vanilla-vite 1.2.0 → 1.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vanilla-vite",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Scaffold a React or Vite app with an optional Node.js or Express backend",
5
5
  "type": "module",
6
6
  "repository": {
@@ -16,7 +16,10 @@
16
16
  },
17
17
  "files": [
18
18
  "bin/",
19
- "scripts/",
19
+ "scripts/dev.mjs",
20
+ "scripts/run-app.mjs",
21
+ "scripts/install-info.mjs",
22
+ "scripts/add-dependency.mjs",
20
23
  "CHANGELOG.md",
21
24
  "README.md"
22
25
  ],
@@ -48,6 +51,9 @@
48
51
  "cross-spawn": "^7.0.6"
49
52
  },
50
53
  "scripts": {
51
- "test:smoke": "node test/smoke.mjs"
54
+ "test": "node test/fixes.test.mjs && node test/version-manager.test.mjs && node test/smoke.mjs --quick",
55
+ "test:unit": "node test/fixes.test.mjs && node test/version-manager.test.mjs",
56
+ "test:smoke": "node test/smoke.mjs",
57
+ "vpublish": "node scripts/version-manager.mjs"
52
58
  }
53
59
  }
@@ -1,112 +1,139 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
- import { emitKeypressEvents } from "node:readline";
5
- import { stdin, stdout } from "node:process";
6
- import spawn from "cross-spawn";
7
-
8
- const root = fileURLToPath(new URL("../", import.meta.url));
9
- const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
10
- const packages = process.argv.slice(2);
11
-
12
- if (packages.length === 0) {
13
- console.error(
14
- "Usage: pnpm adD|add-dependency <package...> | npm run adD|add-dependency -- <package...>",
15
- );
16
- process.exit(1);
17
- }
18
-
19
- if (!stdin.isTTY) {
20
- console.error("Choose an install location in an interactive terminal.");
21
- process.exit(1);
22
- }
23
-
24
- const targets = [
25
- { label: `Project root (${project.name})`, workspace: null },
26
- ...project.workspaces.map((workspace) => ({
27
- label: workspace,
28
- workspace,
29
- })),
30
- ];
31
-
32
- const defaultIndex = Math.max(
33
- 0,
34
- targets.findIndex((target) => target.workspace?.endsWith("-client")),
35
- );
36
- let selectedIndex = defaultIndex;
37
- emitKeypressEvents(stdin);
38
-
39
- const selectedTarget = await new Promise((resolveSelection) => {
40
- function render() {
41
- const question = "Where should the package be installed?";
42
- const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
43
- ? `\x1b[1;36m${question}\x1b[0m`
44
- : question;
45
- stdout.write(`\r\x1b[2K${prompt}\n`);
46
- targets.forEach((target, index) => {
47
- stdout.write(` ${index === selectedIndex ? "❯" : " "} ${target.label}\n`);
48
- });
49
- stdout.write(" Use ↑/↓ to select, Enter to confirm, or Esc to keep the default.\n");
50
- stdout.write(`\x1b[${targets.length + 2}A`);
51
- }
52
-
53
- function finish(target) {
54
- stdin.off("keypress", onKeypress);
55
- stdin.setRawMode(false);
56
- stdin.pause();
57
- stdout.write(`\x1b[${targets.length + 2}B\n`);
58
- resolveSelection(target);
59
- }
60
-
61
- function onKeypress(_input, key) {
62
- if (key?.name === "up" || key?.name === "down") {
63
- selectedIndex =
64
- (selectedIndex + (key.name === "down" ? 1 : targets.length - 1)) %
65
- targets.length;
66
- render();
67
- } else if (key?.name === "return") finish(targets[selectedIndex]);
68
- else if (key?.name === "escape") finish(targets[defaultIndex]);
69
- else if (key?.ctrl && key.name === "c") {
70
- stdin.off("keypress", onKeypress);
71
- stdin.setRawMode(false);
72
- stdin.pause();
73
- stdout.write("\n");
74
- resolveSelection(null);
75
- }
76
- }
77
-
78
- stdin.setRawMode(true);
79
- stdin.resume();
80
- stdin.on("keypress", onKeypress);
81
- render();
82
- });
83
-
84
- if (!selectedTarget) {
85
- process.exit(130);
86
- }
87
-
88
- const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
89
- ? "pnpm"
90
- : "npm";
91
- const { workspace } = selectedTarget;
92
- const commandArgs =
93
- packageManager === "pnpm"
94
- ? workspace
95
- ? ["--filter", workspace, "add", ...packages]
96
- : ["add", "--workspace-root", ...packages]
97
- : workspace
98
- ? ["install", ...packages, "--workspace", workspace]
99
- : ["install", ...packages];
100
- const child = spawn(packageManager, commandArgs, {
101
- cwd: root,
102
- stdio: "inherit",
103
- env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
104
- });
105
-
106
- child.once("error", (error) => {
107
- console.error(`Unable to run ${packageManager}: ${error.message}`);
108
- process.exitCode = 1;
109
- });
110
- child.once("exit", (code, signal) => {
111
- process.exitCode = code ?? (signal ? 1 : 0);
112
- });
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { emitKeypressEvents } from "node:readline";
5
+ import { stdin, stdout } from "node:process";
6
+ import spawn from "cross-spawn";
7
+
8
+ const root = fileURLToPath(new URL("../", import.meta.url));
9
+ const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
10
+ const packages = process.argv.slice(2);
11
+ const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
12
+ ? "pnpm"
13
+ : "npm";
14
+
15
+ if (packages.length === 0) {
16
+ console.log(`Syncing workspace dependencies with ${packageManager} install...`);
17
+ const child = spawn(packageManager, ["install"], {
18
+ cwd: root,
19
+ stdio: "inherit",
20
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
21
+ });
22
+ child.once("error", (error) => {
23
+ console.error(`Unable to run ${packageManager}: ${error.message}`);
24
+ process.exitCode = 1;
25
+ });
26
+ child.once("exit", (code, signal) => {
27
+ process.exitCode =
28
+ code ??
29
+ (signal === "SIGINT"
30
+ ? 130
31
+ : signal === "SIGTERM"
32
+ ? 143
33
+ : signal
34
+ ? 1
35
+ : 0);
36
+ });
37
+ await new Promise((resolve) => child.once("close", resolve));
38
+ process.exit(process.exitCode ?? 0);
39
+ }
40
+
41
+ if (!stdin.isTTY) {
42
+ console.error("Choose an install location in an interactive terminal.");
43
+ process.exit(1);
44
+ }
45
+
46
+ const targets = [
47
+ { label: `Project root (${project.name})`, workspace: null },
48
+ ...project.workspaces.map((workspace) => ({
49
+ label: workspace,
50
+ workspace,
51
+ })),
52
+ ];
53
+
54
+ const defaultIndex = Math.max(
55
+ 0,
56
+ targets.findIndex((target) => target.workspace?.endsWith("-client")),
57
+ );
58
+ let selectedIndex = defaultIndex;
59
+ emitKeypressEvents(stdin);
60
+
61
+ const selectedTarget = await new Promise((resolveSelection) => {
62
+ function render() {
63
+ const question = "Where should the package be installed?";
64
+ const prompt = stdout.isTTY && process.env.NO_COLOR === undefined
65
+ ? `\x1b[1;36m${question}\x1b[0m`
66
+ : question;
67
+ stdout.write(`\r\x1b[2K${prompt}\n`);
68
+ targets.forEach((target, index) => {
69
+ stdout.write(` ${index === selectedIndex ? "❯" : " "} ${target.label}\n`);
70
+ });
71
+ stdout.write(" Use ↑/↓ to select, Enter to confirm, or Esc to keep the default.\n");
72
+ stdout.write(`\x1b[${targets.length + 2}A`);
73
+ }
74
+
75
+ function finish(target) {
76
+ stdin.off("keypress", onKeypress);
77
+ stdin.setRawMode(false);
78
+ stdin.pause();
79
+ stdout.write(`\x1b[${targets.length + 2}B\n`);
80
+ resolveSelection(target);
81
+ }
82
+
83
+ function onKeypress(_input, key) {
84
+ if (key?.name === "up" || key?.name === "down") {
85
+ selectedIndex =
86
+ (selectedIndex + (key.name === "down" ? 1 : targets.length - 1)) %
87
+ targets.length;
88
+ render();
89
+ } else if (key?.name === "return") finish(targets[selectedIndex]);
90
+ else if (key?.name === "escape") finish(targets[defaultIndex]);
91
+ else if (key?.ctrl && key.name === "c") {
92
+ stdin.off("keypress", onKeypress);
93
+ stdin.setRawMode(false);
94
+ stdin.pause();
95
+ stdout.write("\n");
96
+ resolveSelection(null);
97
+ }
98
+ }
99
+
100
+ stdin.setRawMode(true);
101
+ stdin.resume();
102
+ stdin.on("keypress", onKeypress);
103
+ render();
104
+ });
105
+
106
+ if (!selectedTarget) {
107
+ process.exit(130);
108
+ }
109
+
110
+ const { workspace } = selectedTarget;
111
+ const commandArgs =
112
+ packageManager === "pnpm"
113
+ ? workspace
114
+ ? ["--filter", workspace, "add", ...packages]
115
+ : ["add", "--workspace-root", ...packages]
116
+ : workspace
117
+ ? ["install", ...packages, "--workspace", workspace]
118
+ : ["install", ...packages];
119
+ const child = spawn(packageManager, commandArgs, {
120
+ cwd: root,
121
+ stdio: "inherit",
122
+ env: { ...process.env, VANILLA_VITE_ALLOW_INSTALL: "1" },
123
+ });
124
+
125
+ child.once("error", (error) => {
126
+ console.error(`Unable to run ${packageManager}: ${error.message}`);
127
+ process.exitCode = 1;
128
+ });
129
+ child.once("exit", (code, signal) => {
130
+ process.exitCode =
131
+ code ??
132
+ (signal === "SIGINT"
133
+ ? 130
134
+ : signal === "SIGTERM"
135
+ ? 143
136
+ : signal
137
+ ? 1
138
+ : 0);
139
+ });