create-vanilla-vite 1.1.0 → 1.2.1

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.
@@ -1,33 +1,78 @@
1
- import { readFile } from "node:fs/promises";
2
- import { join } from "node:path";
3
- import { fileURLToPath } from "node:url";
4
-
5
- const root = fileURLToPath(new URL("../", import.meta.url));
6
- const project = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
7
-
8
- if (process.env.VANILLA_VITE_ALLOW_INSTALL !== "1") {
9
- console.error(
10
- "\nDirect installs are disabled to keep dependencies in the intended workspace.\n" +
11
- "Use `pnpm adD <package>` or `pnpm add-dependency <package>`; with npm, use `npm run adD -- <package>` or `npm run add-dependency -- <package>`.",
12
- );
13
- process.exit(1);
14
- }
15
-
16
- console.log("Installing workspace dependencies:");
17
- for (const workspace of project.workspaces) {
18
- const manifest = JSON.parse(
19
- await readFile(join(root, workspace, "package.json"), "utf8"),
20
- );
21
- const dependencies = {
22
- ...manifest.dependencies,
23
- ...manifest.devDependencies,
24
- };
25
- console.log(`\n${manifest.name} (${workspace}):`);
26
- if (!Object.keys(dependencies).length) {
27
- console.log(" No dependencies declared.");
28
- continue;
29
- }
30
- for (const [name, version] of Object.entries(dependencies)) {
31
- console.log(` - ${name}@${version}`);
32
- }
33
- }
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
+ if (
41
+ process.env.VANILLA_VITE_ALLOW_INSTALL !== "1" &&
42
+ process.env.CI === undefined &&
43
+ process.env.npm_command !== "ci" &&
44
+ !freshInstall &&
45
+ (installState === "installing" || installState === "installed" || hasInstalledDependencies)
46
+ ) {
47
+ console.error(
48
+ "\nDirect installs are disabled to keep dependencies in the intended workspace.\n" +
49
+ "Use `pnpm adD <package>` or `pnpm add-dependency <package>`; with npm, use `npm run adD -- <package>` or `npm run add-dependency -- <package>`.\n" +
50
+ "The adD commands are the supported way to add packages.",
51
+ );
52
+ process.exit(1);
53
+ }
54
+
55
+ if (
56
+ process.env.VANILLA_VITE_ALLOW_INSTALL === "1" ||
57
+ process.env.CI !== undefined ||
58
+ process.env.npm_command === "ci" ||
59
+ freshInstall
60
+ ) {
61
+ await writeFile(installStatePath, "installing\n");
62
+ }
63
+
64
+ console.log("Installing workspace dependencies:");
65
+ for (const { path, manifest } of workspaces) {
66
+ const dependencies = {
67
+ ...manifest.dependencies,
68
+ ...manifest.devDependencies,
69
+ };
70
+ console.log(`\n${manifest.name} (${relative(root, path)}):`);
71
+ if (!Object.keys(dependencies).length) {
72
+ console.log(" No dependencies declared.");
73
+ continue;
74
+ }
75
+ for (const [name, version] of Object.entries(dependencies)) {
76
+ console.log(` - ${name}@${version}`);
77
+ }
78
+ }
@@ -1,45 +1,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: npm|pnpm client|server [ -dev | add <package...> ]");
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[0] === "add" && args.length > 1) {
23
- commandArgs =
24
- packageManager === "pnpm"
25
- ? ["--filter", workspace, "add", ...args.slice(1)]
26
- : ["install", ...args.slice(1), "--workspace", workspace];
27
- } else if (args.length === 0 || (args.length === 1 && args[0] === "-dev")) {
28
- const script = args[0] === "-dev" ? "dev" : "start";
29
- commandArgs =
30
- packageManager === "pnpm"
31
- ? ["--filter", workspace, "run", script]
32
- : ["run", script, "--workspace", workspace];
33
- } else {
34
- console.error(`Usage: ${packageManager} ${app} [ -dev | add <package...> ]`);
35
- process.exit(1);
36
- }
37
-
38
- const child = spawn(packageManager, commandArgs, { cwd: root, stdio: "inherit" });
39
- child.once("error", (error) => {
40
- console.error(`Unable to run ${packageManager}: ${error.message}`);
41
- process.exitCode = 1;
42
- });
43
- child.once("exit", (code, signal) => {
44
- process.exitCode = code ?? (signal ? 1 : 0);
45
- });
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: npm|pnpm 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(`Usage: ${packageManager} ${app} [dev|-dev]`);
30
+ process.exit(1);
31
+ }
32
+
33
+ const child = spawn(packageManager, commandArgs, { cwd: root, stdio: "inherit" });
34
+ child.once("error", (error) => {
35
+ console.error(`Unable to run ${packageManager}: ${error.message}`);
36
+ process.exitCode = 1;
37
+ });
38
+ child.once("exit", (code, signal) => {
39
+ process.exitCode = code ?? (signal ? 1 : 0);
40
+ });