From 2b11131befef7e622486a4826b920b32a3595845 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 24 Nov 2026 16:48:36 +0000 Subject: [PATCH] fix(cli): registry add looks for a Node package in the folders a file is written to (#8722) --- packages/cli/src/registry/installer.test.ts | 26 +++++++++++++++++++++ packages/cli/src/registry/installer.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/registry/installer.test.ts b/packages/cli/src/registry/installer.test.ts index 6b2e9e40f4..6ed89d2bb5 100644 --- a/packages/cli/src/registry/installer.test.ts +++ b/packages/cli/src/registry/installer.test.ts @@ -217,6 +217,32 @@ describe("installItem", () => { expect(readdirSync(join(dir, "tools", "pkg"))).toEqual([]); }); + it("refuses a browser script below a mixed-case folder that holds a Node package, directly or through a link", async () => { + const options = { force: true, baseUrl: otherRegistry }; + const direct = project(); + mkdirSync(join(direct, "compositions", "Widgets"), { recursive: true }); + writeFileSync( + join(direct, "compositions", "Widgets", "package.json"), + JSON.stringify(nodeManifest), + ); + await expect( + installItem(withTarget("compositions/Widgets/chart.test.js"), { + destDir: direct, + ...options, + }), + ).rejects.toThrow(/Unsafe target.*script Node tooling may run/); + expect(readdirSync(join(direct, "compositions", "Widgets"))).toEqual(["package.json"]); + + const linked = project(); + mkdirSync(join(linked, "tools", "Pkg", "src"), { recursive: true }); + writeFileSync(join(linked, "tools", "Pkg", "package.json"), JSON.stringify(nodeManifest)); + symlinkSync(join(linked, "tools", "Pkg", "src"), join(linked, "lib"), "junction"); + await expect( + installItem(withTarget("lib/shaders.iife.js"), { destDir: linked, ...options }), + ).rejects.toThrow(/Unsafe target.*script Node tooling may run/); + expect(readdirSync(join(linked, "tools", "Pkg", "src"))).toEqual([]); + }); + it("refuses a page whose own file link leads to a Node-only script", async () => { const dir = project(); mkdirSync(join(dir, "tools")); diff --git a/packages/cli/src/registry/installer.ts b/packages/cli/src/registry/installer.ts index b68cc9b24d..9960122e57 100644 --- a/packages/cli/src/registry/installer.ts +++ b/packages/cli/src/registry/installer.ts @@ -302,7 +302,7 @@ function scriptRule(type: RegistryItem["type"], baseUrl: string): ScriptRule { ? (_: string, spelled: string) => nodeOnlyScript(spelled) : (root: string, spelled: string) => nodeMayRun(root, spelled, "file"); return (root, target) => - refused(root, targetSegments(target).join("/")) + refused(root, target.split(/[\\/]/).join("/")) ? "it writes a script Node tooling may run" : null; }