diff --git a/packages/registry/src/definition.test.ts b/packages/registry/src/definition.test.ts index 9f53de0..3738b5b 100644 --- a/packages/registry/src/definition.test.ts +++ b/packages/registry/src/definition.test.ts @@ -171,6 +171,31 @@ versions: expect(def.versions[0].tag_pattern).toBe("@trpc/server@{version}"); }); + it("accepts a scoped path that uses backslash separators", () => { + // On Windows relative() returns "@apollo\\client", which never matched the + // "@apollo/client" in the file, so listDefinitions() threw for every scoped + // definition. Reproduced here by putting a literal backslash in the filename: + // on Linux that is one filename rather than a separator, but the string + // reaching the comparison is byte-identical to what Windows produces. + const yaml = ` +name: "@apollo/client" +description: "Apollo Client" +source: + type: git + url: https://github.com/apollographql/apollo-client + docs_path: docs +`; + const npmDir = join(tempDir, "npm"); + mkdirSync(npmDir, { recursive: true }); + const filePath = join(npmDir, "@apollo\\client.yaml"); + writeFileSync(filePath, yaml); + + const def = loadDefinition(filePath, npmDir); + + expect(def.name).toBe("@apollo/client"); + expect(def.registry).toBe("npm"); + }); + it("throws when scoped name doesn't match path", () => { const yaml = ` name: "@trpc/client" diff --git a/packages/registry/src/definition.ts b/packages/registry/src/definition.ts index 9381e23..ffd6e8b 100644 --- a/packages/registry/src/definition.ts +++ b/packages/registry/src/definition.ts @@ -167,8 +167,15 @@ export function loadDefinition( // Derive expected name from relative path within managerDir // e.g., npm/@trpc/server.yaml → @trpc/server // e.g., npm/next.yaml → next + // + // relative() returns platform separators, so on Windows a scoped definition + // yields "@apollo\\client" and never matches the "@apollo/client" in the file. + // Normalising unconditionally rather than only when sep is "\\" keeps one code + // path on every platform, so Linux CI exercises the same comparison Windows does. const expectedName = managerDir - ? relative(managerDir, filePath).replace(/\.yaml$/, "") + ? relative(managerDir, filePath) + .replace(/\.yaml$/, "") + .replaceAll("\\", "/") : basename(filePath, ".yaml"); // Allow filesystem-safe encoding: colons in names are replaced with underscores