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/CHANGELOG.md +49 -29
- package/README.md +302 -195
- package/bin/create-template.mjs +1848 -1764
- package/package.json +9 -3
- package/scripts/add-dependency.mjs +139 -112
- package/scripts/dev.mjs +694 -625
- package/scripts/install-info.mjs +111 -78
- package/scripts/run-app.mjs +52 -40
package/scripts/install-info.mjs
CHANGED
|
@@ -1,78 +1,111 @@
|
|
|
1
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { join, relative } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
7
|
-
const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
8
|
-
const installStatePath = join(root, ".install-state");
|
|
9
|
-
if (process.argv.includes("--complete")) {
|
|
10
|
-
await writeFile(installStatePath, "installed\n");
|
|
11
|
-
process.exit(0);
|
|
12
|
-
}
|
|
13
|
-
const workspaces = await Promise.all(
|
|
14
|
-
project.workspaces.map(async (workspace) => ({
|
|
15
|
-
path: join(root, workspace),
|
|
16
|
-
manifest: JSON.parse(await readFile(join(root, workspace, "package.json"), "utf8")),
|
|
17
|
-
})),
|
|
18
|
-
);
|
|
19
|
-
const declaredDependencies = [
|
|
20
|
-
...Object.keys(project.dependencies ?? {}),
|
|
21
|
-
...Object.keys(project.devDependencies ?? {}),
|
|
22
|
-
...workspaces.flatMap(({ manifest }) => [
|
|
23
|
-
...Object.keys(manifest.dependencies ?? {}),
|
|
24
|
-
...Object.keys(manifest.devDependencies ?? {}),
|
|
25
|
-
]),
|
|
26
|
-
];
|
|
27
|
-
const hasInstalledDependencies = declaredDependencies.some(
|
|
28
|
-
(dependency) =>
|
|
29
|
-
existsSync(join(root, "node_modules", dependency)) ||
|
|
30
|
-
workspaces.some(({ path }) => existsSync(join(path, "node_modules", dependency))),
|
|
31
|
-
);
|
|
32
|
-
let installState;
|
|
33
|
-
try {
|
|
34
|
-
installState = (await readFile(installStatePath, "utf8")).trim();
|
|
35
|
-
} catch (error) {
|
|
36
|
-
if (error.code !== "ENOENT") throw error;
|
|
37
|
-
}
|
|
38
|
-
const freshInstall = installState === undefined && process.env.npm_command === "install";
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
console.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { join, relative } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
7
|
+
const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
8
|
+
const installStatePath = join(root, ".install-state");
|
|
9
|
+
if (process.argv.includes("--complete")) {
|
|
10
|
+
await writeFile(installStatePath, "installed\n");
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
const workspaces = await Promise.all(
|
|
14
|
+
project.workspaces.map(async (workspace) => ({
|
|
15
|
+
path: join(root, workspace),
|
|
16
|
+
manifest: JSON.parse(await readFile(join(root, workspace, "package.json"), "utf8")),
|
|
17
|
+
})),
|
|
18
|
+
);
|
|
19
|
+
const declaredDependencies = [
|
|
20
|
+
...Object.keys(project.dependencies ?? {}),
|
|
21
|
+
...Object.keys(project.devDependencies ?? {}),
|
|
22
|
+
...workspaces.flatMap(({ manifest }) => [
|
|
23
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
24
|
+
...Object.keys(manifest.devDependencies ?? {}),
|
|
25
|
+
]),
|
|
26
|
+
];
|
|
27
|
+
const hasInstalledDependencies = declaredDependencies.some(
|
|
28
|
+
(dependency) =>
|
|
29
|
+
existsSync(join(root, "node_modules", dependency)) ||
|
|
30
|
+
workspaces.some(({ path }) => existsSync(join(path, "node_modules", dependency))),
|
|
31
|
+
);
|
|
32
|
+
let installState;
|
|
33
|
+
try {
|
|
34
|
+
installState = (await readFile(installStatePath, "utf8")).trim();
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code !== "ENOENT") throw error;
|
|
37
|
+
}
|
|
38
|
+
const freshInstall = installState === undefined && process.env.npm_command === "install";
|
|
39
|
+
|
|
40
|
+
const installMode = project.vanillaVite?.installMode ?? "adD";
|
|
41
|
+
|
|
42
|
+
if (installMode === "both") {
|
|
43
|
+
if (
|
|
44
|
+
process.env.VANILLA_VITE_ALLOW_INSTALL !== "1" &&
|
|
45
|
+
process.env.CI === undefined &&
|
|
46
|
+
process.env.npm_command !== "ci" &&
|
|
47
|
+
installState !== undefined
|
|
48
|
+
) {
|
|
49
|
+
const isPnpm = process.env.npm_config_user_agent?.startsWith("pnpm/");
|
|
50
|
+
console.log(
|
|
51
|
+
isPnpm
|
|
52
|
+
? "Tip: `pnpm adD <package>` lets you pick the workspace."
|
|
53
|
+
: "Tip: `npm run adD -- <package>` lets you pick the workspace.",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
} else if (installMode === "adD") {
|
|
57
|
+
if (
|
|
58
|
+
process.env.VANILLA_VITE_ALLOW_INSTALL !== "1" &&
|
|
59
|
+
process.env.CI === undefined &&
|
|
60
|
+
process.env.npm_command !== "ci" &&
|
|
61
|
+
!freshInstall &&
|
|
62
|
+
(installState === "installing" || installState === "installed" || hasInstalledDependencies)
|
|
63
|
+
) {
|
|
64
|
+
const isPnpm = process.env.npm_config_user_agent?.startsWith("pnpm/");
|
|
65
|
+
const syncCmd = isPnpm ? "pnpm adD" : "npm run adD";
|
|
66
|
+
const allowCmd = isPnpm
|
|
67
|
+
? "VANILLA_VITE_ALLOW_INSTALL=1 pnpm install"
|
|
68
|
+
: "VANILLA_VITE_ALLOW_INSTALL=1 npm install";
|
|
69
|
+
const rerunCmd = isPnpm
|
|
70
|
+
? "rm -f .install-state && pnpm install"
|
|
71
|
+
: "rm -f .install-state && npm install";
|
|
72
|
+
console.error(
|
|
73
|
+
"\nDirect installs are disabled to keep dependencies in the intended workspace.\n" +
|
|
74
|
+
"Use `pnpm adD <package>` or `pnpm add-dependency <package>`; with npm, use `npm run adD -- <package>` or `npm run add-dependency -- <package>`.\n" +
|
|
75
|
+
"The adD commands are the supported way to add packages.\n\n" +
|
|
76
|
+
"Recovery instructions:\n" +
|
|
77
|
+
` - To install dependencies across all workspaces, run \`${syncCmd}\` with no arguments to sync dependencies\n` +
|
|
78
|
+
` (or ${allowCmd}).\n` +
|
|
79
|
+
" - If an installation was interrupted, remove .install-state and rerun:\n" +
|
|
80
|
+
` ${rerunCmd}\n`,
|
|
81
|
+
);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (
|
|
87
|
+
process.env.VANILLA_VITE_ALLOW_INSTALL === "1" ||
|
|
88
|
+
process.env.CI !== undefined ||
|
|
89
|
+
process.env.npm_command === "ci" ||
|
|
90
|
+
freshInstall ||
|
|
91
|
+
installMode === "plain" ||
|
|
92
|
+
installMode === "both"
|
|
93
|
+
) {
|
|
94
|
+
await writeFile(installStatePath, "installing\n");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
console.log("Installing workspace dependencies:");
|
|
98
|
+
for (const { path, manifest } of workspaces) {
|
|
99
|
+
const dependencies = {
|
|
100
|
+
...manifest.dependencies,
|
|
101
|
+
...manifest.devDependencies,
|
|
102
|
+
};
|
|
103
|
+
console.log(`\n${manifest.name} (${relative(root, path)}):`);
|
|
104
|
+
if (!Object.keys(dependencies).length) {
|
|
105
|
+
console.log(" No dependencies declared.");
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
for (const [name, version] of Object.entries(dependencies)) {
|
|
109
|
+
console.log(` - ${name}@${version}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
package/scripts/run-app.mjs
CHANGED
|
@@ -1,40 +1,52 @@
|
|
|
1
|
-
import spawn from "cross-spawn";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
const [app, ...args] = process.argv.slice(2);
|
|
7
|
-
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
8
|
-
const { workspaces } = JSON.parse(
|
|
9
|
-
await readFile(join(root, "package.json"), "utf8"),
|
|
10
|
-
);
|
|
11
|
-
const workspace = workspaces.find((name) => name.endsWith(`-${app}`));
|
|
12
|
-
|
|
13
|
-
if (!workspace || !["client", "server"].includes(app)) {
|
|
14
|
-
console.error("Usage:
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
|
|
19
|
-
? "pnpm"
|
|
20
|
-
: "npm";
|
|
21
|
-
let commandArgs;
|
|
22
|
-
if (args.length === 0 || (args.length === 1 && ["dev", "-dev"].includes(args[0]))) {
|
|
23
|
-
const script = args.length === 1 ? "dev" : "start";
|
|
24
|
-
commandArgs =
|
|
25
|
-
packageManager === "pnpm"
|
|
26
|
-
? ["--filter", workspace, "run", script]
|
|
27
|
-
: ["run", script, "--workspace", workspace];
|
|
28
|
-
} else {
|
|
29
|
-
console.error(
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
child.once("
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import spawn from "cross-spawn";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const [app, ...args] = process.argv.slice(2);
|
|
7
|
+
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
8
|
+
const { workspaces } = JSON.parse(
|
|
9
|
+
await readFile(join(root, "package.json"), "utf8"),
|
|
10
|
+
);
|
|
11
|
+
const workspace = workspaces.find((name) => name.endsWith(`-${app}`));
|
|
12
|
+
|
|
13
|
+
if (!workspace || !["client", "server"].includes(app)) {
|
|
14
|
+
console.error("Usage: pnpm client|server [dev|-dev] | npm run client|server [dev|-dev]");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const packageManager = process.env.npm_config_user_agent?.startsWith("pnpm/")
|
|
19
|
+
? "pnpm"
|
|
20
|
+
: "npm";
|
|
21
|
+
let commandArgs;
|
|
22
|
+
if (args.length === 0 || (args.length === 1 && ["dev", "-dev"].includes(args[0]))) {
|
|
23
|
+
const script = args.length === 1 ? "dev" : "start";
|
|
24
|
+
commandArgs =
|
|
25
|
+
packageManager === "pnpm"
|
|
26
|
+
? ["--filter", workspace, "run", script]
|
|
27
|
+
: ["run", script, "--workspace", workspace];
|
|
28
|
+
} else {
|
|
29
|
+
console.error(
|
|
30
|
+
packageManager === "pnpm"
|
|
31
|
+
? `Usage: pnpm ${app} [dev|-dev]`
|
|
32
|
+
: `Usage: npm run ${app} [dev|-dev]`,
|
|
33
|
+
);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const child = spawn(packageManager, commandArgs, { cwd: root, stdio: "inherit" });
|
|
38
|
+
child.once("error", (error) => {
|
|
39
|
+
console.error(`Unable to run ${packageManager}: ${error.message}`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
});
|
|
42
|
+
child.once("exit", (code, signal) => {
|
|
43
|
+
process.exitCode =
|
|
44
|
+
code ??
|
|
45
|
+
(signal === "SIGINT"
|
|
46
|
+
? 130
|
|
47
|
+
: signal === "SIGTERM"
|
|
48
|
+
? 143
|
|
49
|
+
: signal
|
|
50
|
+
? 1
|
|
51
|
+
: 0);
|
|
52
|
+
});
|