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("") +})