Skip to content

Commit

Permalink
fix: accept catalog paths without ending slash (#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
semoal authored Nov 2, 2020
1 parent cbe946e commit 5d39586
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/api/__snapshots__/catalog.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Object {
}
`;

exports[`getCatalogs should warn about missing {name} pattern in catalog path 1`] = `Catalog with path "./locales/{locale}" doesn't have a {name} pattern in it, but one of source directories uses it: "{name}/". Either add {name} pattern to "./locales/{locale}" or remove it from all source directories.`;
exports[`getCatalogs should warn about missing {name} pattern in catalog path 1`] = `Catalog with path "./locales/{locale}" doesn't have a {name} pattern in it, but one of source directories uses it: "{name}". Either add {name} pattern to "./locales/{locale}" or remove it from all source directories.`;

exports[`getCatalogs should warn if catalogPath is a directory 1`] = `Remove trailing slash from "./locales/{locale}/". Catalog path isn't a directory, but translation file without extension. For example, catalog path "./locales/{locale}" results in translation file "./locales/en.po".`;

Expand Down
13 changes: 13 additions & 0 deletions packages/cli/src/api/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,19 @@ describe("normalizeRelativePath", function () {
absolute.split("\\").join("/")
)
})

it("directories without ending slash are correctly treaten as dirs", function() {
mockFs({
componentA: {
"index.js": mockFs.file(),
},
"componentB": mockFs.file(),
})
// checked correctly that is a dir, cuz added that ending slash
expect(normalizeRelativePath("./componentA")).toEqual("componentA/")
// ComponentB is a file shouldn't add ending slash
expect(normalizeRelativePath("./componentB")).toEqual("componentB")
})
})

describe("cleanObsolete", function () {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class Catalog {
)
const patterns =
includeGlobs.length > 1 ? `{${includeGlobs.join(",")}}` : includeGlobs[0]
return glob.sync(patterns, { ignore: this.exclude })
return glob.sync(patterns, { ignore: this.exclude, mark: true })
}

get localeDir() {
Expand Down Expand Up @@ -372,6 +372,7 @@ export function getCatalogs(config: LinguiConfig) {
patterns.length > 1 ? `{${patterns.join(",")}` : patterns[0],
{
ignore: exclude,
mark: true
}
)

Expand Down Expand Up @@ -497,7 +498,7 @@ export function normalizeRelativePath(sourcePath: string): string {
return normalize(sourcePath, false)
}

const isDir = normalize(sourcePath, false).endsWith(PATHSEP)
const isDir = fs.existsSync(sourcePath) && fs.lstatSync(sourcePath).isDirectory()
return (
normalize(path.relative(process.cwd(), path.resolve(sourcePath))) +
(isDir ? PATHSEP : "")
Expand Down

1 comment on commit 5d39586

@vercel
Copy link

@vercel vercel bot commented on 5d39586 Nov 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.