@@ -73,16 +73,22 @@ export const parseMarker = (body) =>
7373 ( body ?? "" ) . startsWith ( ISSUE_MARKER ) ? true : null ;
7474
7575/**
76- * The manifest a `dependent` from `npm outdated --workspaces` names. npm
77- * reports a workspace by its directory name and the root by the checkout's
78- * directory name, which differs between machines, so anything that is not a
79- * server directory is the root.
76+ * The manifest a `dependent` from `npm outdated --workspaces` names.
77+ *
78+ * npm reports a workspace by its arborist node name, which for this repo's
79+ * workspaces is the directory (`everything`), but a package name
80+ * (`@modelcontextprotocol/server-everything`) is accepted too, so a change in
81+ * how npm spells it cannot fold every workspace into `root` silently. The
82+ * root is reported by the checkout's directory name, which differs between
83+ * machines, so anything that matches no workspace is the root.
8084 *
8185 * @param {string | undefined } dependent
86+ * @param {Record<string, string> } [workspaceNames] package name -> `src/<dir>`
8287 * @returns {string }
8388 */
84- export function installLabel ( dependent ) {
85- return SERVERS . includes ( dependent ?? "" ) ? `src/${ dependent } ` : "root" ;
89+ export function installLabel ( dependent , workspaceNames = { } ) {
90+ if ( SERVERS . includes ( dependent ?? "" ) ) return `src/${ dependent } ` ;
91+ return workspaceNames [ dependent ?? "" ] ?? "root" ;
8692}
8793
8894/**
@@ -91,16 +97,17 @@ export function installLabel(dependent) {
9197 * comes back as an array, one entry per dependent.
9298 *
9399 * @param {string } json raw stdout (may be `""` or `"{}"`)
100+ * @param {Record<string, string> } [workspaceNames] package name -> `src/<dir>`
94101 * @returns {Map<string, Array<{name: string, current: string, wanted: string, latest: string}>> }
95102 * keyed by `installLabel`, each list sorted by name
96103 */
97- export function parseNpmOutdated ( json ) {
104+ export function parseNpmOutdated ( json , workspaceNames = { } ) {
98105 const byInstall = new Map ( ) ;
99106 const trimmed = json . trim ( ) ;
100107 if ( trimmed === "" ) return byInstall ;
101108 for ( const [ name , info ] of Object . entries ( JSON . parse ( trimmed ) ) ) {
102109 for ( const entry of Array . isArray ( info ) ? info : [ info ] ) {
103- const label = installLabel ( entry . dependent ) ;
110+ const label = installLabel ( entry . dependent , workspaceNames ) ;
104111 const rows = byInstall . get ( label ) ?? [ ] ;
105112 // One manifest can reach a package twice (a dependency and a
106113 // devDependency); report it once.
@@ -429,6 +436,23 @@ export function buildClearedBody(isoDate) {
429436 ] . join ( "\n" ) ;
430437}
431438
439+ /**
440+ * Each workspace's package name, mapped to its directory.
441+ *
442+ * @param {string } root
443+ * @returns {Record<string, string> }
444+ */
445+ export function workspacePackageNames ( root ) {
446+ const names = { } ;
447+ for ( const server of SERVERS ) {
448+ const manifest = path . join ( root , "src" , server , "package.json" ) ;
449+ if ( ! existsSync ( manifest ) ) continue ;
450+ const { name } = JSON . parse ( readFileSync ( manifest , "utf8" ) ) ;
451+ if ( name ) names [ name ] = `src/${ server } ` ;
452+ }
453+ return names ;
454+ }
455+
432456function runOutdated ( root , spawn ) {
433457 const result = spawn (
434458 "npm" ,
@@ -546,7 +570,10 @@ export function main({
546570 if ( ! repo ) throw new Error ( "repo not specified (GITHUB_REPOSITORY unset)" ) ;
547571 const writer = issueWriter ( { repo, spawn, dryRun, sweep : SWEEP , log } ) ;
548572
549- const npmByInstall = parseNpmOutdated ( runOutdated ( root , spawn ) ) ;
573+ const npmByInstall = parseNpmOutdated (
574+ runOutdated ( root , spawn ) ,
575+ workspacePackageNames ( root ) ,
576+ ) ;
550577 const npm = [ "root" , ...SERVERS . map ( ( s ) => `src/${ s } ` ) ]
551578 . filter ( ( label ) => npmByInstall . has ( label ) )
552579 . map ( ( label ) => ( { label, packages : npmByInstall . get ( label ) } ) ) ;
0 commit comments