Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept catalog paths without ending slash #812

Merged
merged 1 commit into from
Nov 2, 2020
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
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