Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/registry/src/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion packages/registry/src/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down