From 92de181056a2db4123968bf53810de113d371f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B9=B3=E5=B9=B3?= <1847531284@qq.com> Date: Mon, 16 Nov 2026 22:51:06 +0800 Subject: [PATCH] tagged: a page with its own service module is a page (#1226) A page plugin whose page talks to a local service it ships as its main (magpie.page.service) was read as a provider by the tagged list. A package with magpie.page.file and its own module is now a page when its keywords include "magpie-page"; a provider with a settings page says no such keyword and stays a provider. Matches magpie v0.1.4331 (50a38371d). READ is 3, so every tagged repository is read again. By xiaopeng66. Run at 630fbbf (mote, HOME=$(mktemp -d)): bun test scripts/: 40 pass, 0 fail. Broken by hand: the keyword test forced false, "a page stays a page when it also has a module and service" fails. Not tried: the tagged list's real reread (it reaches GitHub). --- scripts/tagged-kind.mjs | 6 ++++-- scripts/tagged-kind.test.mjs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/tagged-kind.mjs b/scripts/tagged-kind.mjs index dcc4046..b7120d9 100644 --- a/scripts/tagged-kind.mjs +++ b/scripts/tagged-kind.mjs @@ -6,7 +6,9 @@ // another way is read again whole, not only the repositories pushed to. // 2: an agent plugin with a module of its own is an agent, and hooks are // read (#1200). -export const READ = 2 +// 3: a page with its own module is a page only when its keywords include +// magpie-page; a page without its own module remains a page as before. +export const READ = 3 export const named = (e) => !!e && (typeof e !== "object" || Object.keys(e).length > 0) @@ -38,7 +40,7 @@ export function kindOf(pj) { // a package that adds an agent is an agent plugin, its module (main) // only what keeps the agent working, not a provider (#737, #1200) if (said(mg.agent)) return "agent" - if (!r && said(mg.page?.file)) return "page" + if (said(mg.page?.file) && (!r || (Array.isArray(pj.keywords) && pj.keywords.some((k) => typeof k === "string" && k.trim().toLowerCase() === "magpie-page")))) return "page" if (!r && said(mg.hooks)) return "hooks" return "" } diff --git a/scripts/tagged-kind.test.mjs b/scripts/tagged-kind.test.mjs index df3e3a5..62f47c3 100644 --- a/scripts/tagged-kind.test.mjs +++ b/scripts/tagged-kind.test.mjs @@ -19,11 +19,14 @@ test("hooks alone are a hooks plugin, and their file is the one to find", () => expect(entryOf(pj, "hooks", true)).toBe("./model-watch.hooks.js") }) -test("a module of its own keeps middleware, a page and hooks a provider, as before", () => { - for (const mg of [{ middleware: "m.js" }, { page: { file: "p.html" } }, { hooks: "h.js" }]) { +test("a page stays a page when it also has a module and service", () => { + for (const mg of [{ middleware: "m.js" }, { hooks: "h.js" }]) { expect(kindOf({ main: "index.mjs", magpie: mg })).toBe("") expect(kindOf({ exports: { ".": "./i.mjs" }, magpie: mg })).toBe("") } + const page = { main: "server/index.mjs", keywords: ["magpie-page"], magpie: { page: { file: "page/index.html", service: { port: 3489 } } } } + expect(kindOf(page)).toBe("page") + expect(entryOf(page, "page", true)).toBe("server/index.mjs") expect(kindOf({ main: "index.mjs" })).toBe("") expect(kindOf({ magpie: { middleware: "m.js" } })).toBe("middleware") expect(kindOf({ magpie: { page: { file: "p.html" } } })).toBe("page") @@ -31,3 +34,8 @@ test("a module of its own keeps middleware, a page and hooks a provider, as befo expect(entryOf({ main: "index.mjs" }, "", false)).toBe("index.js") expect(entryOf({ exports: { ".": { bun: "./b.mjs" } } }, "", true)).toBe("./b.mjs") }) + +test("a page with main needs the magpie-page keyword", () => { + const page = { main: "server/index.mjs", magpie: { page: { file: "page/index.html" } } } + expect(kindOf(page)).toBe("") +})