From 67087259a848d788e3bb5f4f5eaf26868aada4ad Mon Sep 17 00:00:00 2001 From: Sarthak Singh Date: Thu, 9 Jul 2026 23:52:52 +0530 Subject: [PATCH] fix(init): run frontend npm install with prefix first --- changelog.d/frontend-npm-prefix-install.md | 1 + examples/next/build.zig | 2 +- examples/react/build.zig | 2 +- examples/svelte/build.zig | 2 +- examples/vue/build.zig | 2 +- src/tooling/templates.zig | 6 +++--- 6 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelog.d/frontend-npm-prefix-install.md diff --git a/changelog.d/frontend-npm-prefix-install.md b/changelog.d/frontend-npm-prefix-install.md new file mode 100644 index 00000000..a1cec4d8 --- /dev/null +++ b/changelog.d/frontend-npm-prefix-install.md @@ -0,0 +1 @@ +fix: **Frontend install command compatibility**: generated web-frontend builds now run `npm --prefix frontend install`, matching the existing build/dev command shape and avoiding npm versions that look for a root `package.json` when `--prefix` follows `install`. diff --git a/examples/next/build.zig b/examples/next/build.zig index 13c2d6e3..f4d1f3a8 100644 --- a/examples/next/build.zig +++ b/examples/next/build.zig @@ -96,7 +96,7 @@ pub fn build(b: *std.Build) void { linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install); b.installArtifact(exe); - const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" }); + const frontend_install = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "install" }); const frontend_install_step = b.step("frontend-install", "Install frontend dependencies"); frontend_install_step.dependOn(&frontend_install.step); diff --git a/examples/react/build.zig b/examples/react/build.zig index 7ccc9990..af6caed4 100644 --- a/examples/react/build.zig +++ b/examples/react/build.zig @@ -96,7 +96,7 @@ pub fn build(b: *std.Build) void { linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install); b.installArtifact(exe); - const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" }); + const frontend_install = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "install" }); const frontend_install_step = b.step("frontend-install", "Install frontend dependencies"); frontend_install_step.dependOn(&frontend_install.step); diff --git a/examples/svelte/build.zig b/examples/svelte/build.zig index 5f0fc04d..254d8cbd 100644 --- a/examples/svelte/build.zig +++ b/examples/svelte/build.zig @@ -96,7 +96,7 @@ pub fn build(b: *std.Build) void { linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install); b.installArtifact(exe); - const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" }); + const frontend_install = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "install" }); const frontend_install_step = b.step("frontend-install", "Install frontend dependencies"); frontend_install_step.dependOn(&frontend_install.step); diff --git a/examples/vue/build.zig b/examples/vue/build.zig index 9f4a72da..42dec846 100644 --- a/examples/vue/build.zig +++ b/examples/vue/build.zig @@ -96,7 +96,7 @@ pub fn build(b: *std.Build) void { linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install); b.installArtifact(exe); - const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" }); + const frontend_install = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "install" }); const frontend_install_step = b.step("frontend-install", "Install frontend dependencies"); frontend_install_step.dependOn(&frontend_install.step); diff --git a/src/tooling/templates.zig b/src/tooling/templates.zig index d4b4708a..062e072f 100644 --- a/src/tooling/templates.zig +++ b/src/tooling/templates.zig @@ -932,7 +932,7 @@ fn buildZig(allocator: std.mem.Allocator, names: TemplateNames, framework_path: \\ linkPlatform(b, target, app_mod, exe, selected_platform, web_engine, native_sdk_path, cef_dir, cef_auto_install); \\ b.installArtifact(exe); \\ - \\ const frontend_install = b.addSystemCommand(&.{ "npm", "install", "--prefix", "frontend" }); + \\ const frontend_install = b.addSystemCommand(&.{ "npm", "--prefix", "frontend", "install" }); \\ const frontend_install_step = b.step("frontend-install", "Install frontend dependencies"); \\ frontend_install_step.dependOn(&frontend_install.step); \\ @@ -2704,7 +2704,7 @@ fn readme(allocator: std.mem.Allocator, names: TemplateNames, framework_path: [] \\`zig build dev`, `zig build run`, and `zig build package` install frontend dependencies automatically. To install them explicitly, run: \\ \\```sh - \\npm install --prefix frontend + \\npm --prefix frontend install \\``` \\ \\The generated build defaults to this Native SDK framework path: @@ -2830,7 +2830,7 @@ test "writeDefaultApp emits Vite project files" { try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "npm") != null); try std.testing.expect(std.mem.indexOf(u8, app_zon_text, ".windows") != null); try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-install") != null); - try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"install\", \"--prefix\", \"frontend\"") != null); + try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"npm\", \"--prefix\", \"frontend\", \"install\"") != null); try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend-build") != null); try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "frontend_build.step.dependOn(&frontend_install.step)") != null); try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "\"native\", \"dev\"") != null);