diff --git a/.changeset/fix-module-registry-npm-info.md b/.changeset/fix-module-registry-npm-info.md new file mode 100644 index 00000000..3d79f03e --- /dev/null +++ b/.changeset/fix-module-registry-npm-info.md @@ -0,0 +1,6 @@ +--- +"@sfmc-bds/cli": patch +"@sfmc-bds/sfmc": patch +--- + +修正官方模块索引的 npm 来源显示,并按索引的精确版本安装模块。 diff --git a/packages/cli/scripts/module-install/fetch-module.mjs b/packages/cli/scripts/module-install/fetch-module.mjs index d8a6b9cc..f0ee9e03 100644 --- a/packages/cli/scripts/module-install/fetch-module.mjs +++ b/packages/cli/scripts/module-install/fetch-module.mjs @@ -122,8 +122,9 @@ async function defaultSourceFor(id) { const { index } = await resolveRegistryIndex(); const entry = index[id]; if (entry?.npm) { - console.log(`[fetch-module] ${id} found in registry → npm:${entry.npm}`); - return `npm:${entry.npm}`; + const spec = `${entry.npm}${entry.version ? `@${entry.version}` : ""}`; + console.log(`[fetch-module] ${id} found in registry → npm:${spec}`); + return `npm:${spec}`; } if (entry?.repo && entry?.tag) { console.log(`[fetch-module] ${id} found in registry (deprecated github) → github:${entry.repo}@${entry.tag}`); @@ -1003,7 +1004,11 @@ async function main() { console.log(`Registry (${DEFAULT_REGISTRY_REPO}@${DEFAULT_REGISTRY_TAG}) — ${ids.length} modules:`); for (const id of ids) { const e = index[id]; - const src = e.npm ? `npm:${e.npm}` : e.repo ? `github:${e.repo}@${e.tag}` : "?"; + const src = e.npm + ? `npm:${e.npm}${e.version ? `@${e.version}` : ""}` + : e.repo + ? `github:${e.repo}@${e.tag}` + : "?"; console.log(` ${id.padEnd(28)} ${src}`); } return; diff --git a/packages/cli/src/module-commands.ts b/packages/cli/src/module-commands.ts index 83a24f71..454ed5ad 100644 --- a/packages/cli/src/module-commands.ts +++ b/packages/cli/src/module-commands.ts @@ -243,7 +243,9 @@ export async function cmdModuleSearch(args: string[]): Promise { lines.push(c.dim(` ${"id".padEnd(28)}${"source".padEnd(40)}local`)); for (const id of ids) { const e = index[id]!; - const src = `${e.repo}@${e.tag}`; + const src = e.npm + ? `npm:${e.npm}${e.version ? `@${e.version}` : ""}` + : `github:${e.repo}@${e.tag}`; const local = installed.has(id) ? c.green("●") : c.dim("○"); lines.push(` ${local} ${id.padEnd(26)}${src.padEnd(40)}${installed.has(id) ? "installed" : ""}`); } @@ -268,10 +270,17 @@ export async function cmdModuleSearch(args: string[]): Promise { const lines: string[] = [c.bold(`\n${query}`)]; if (staleNote) lines.push(staleNote.trimEnd()); lines.push(` registry : ${DEFAULT_REGISTRY_REPO}@${DEFAULT_REGISTRY_TAG}`); - lines.push(` repo : ${entry.repo}`); - lines.push(` tag : ${entry.tag}`); - lines.push(` source : github:${entry.repo}@${entry.tag}`); - lines.push(` github : https://github.com/${entry.repo}/tree/${entry.tag}`); + if (entry.npm) { + lines.push(` npm : ${entry.npm}`); + if (entry.version) lines.push(` version : ${entry.version}`); + lines.push(` source : npm:${entry.npm}${entry.version ? `@${entry.version}` : ""}`); + if (entry.sdk) lines.push(` sdk : ${entry.sdk}`); + } else { + lines.push(` repo : ${entry.repo}`); + lines.push(` tag : ${entry.tag}`); + lines.push(` source : github:${entry.repo}@${entry.tag}`); + lines.push(` github : https://github.com/${entry.repo}/tree/${entry.tag}`); + } lines.push( ` local : ${isInstalled ? c.green(`installed @ ${installedPath}`) : c.dim("not installed")}` );