diff --git a/packages/cli/src/api/__snapshots__/catalog.test.ts.snap b/packages/cli/src/api/__snapshots__/catalog.test.ts.snap index 638f0f4a3..25d128b95 100644 --- a/packages/cli/src/api/__snapshots__/catalog.test.ts.snap +++ b/packages/cli/src/api/__snapshots__/catalog.test.ts.snap @@ -19,6 +19,23 @@ exports[`Catalog POT Flow Should get translations from template if locale file n } `; +exports[`Catalog collect should extract files with special characters in the include path 1`] = ` +{ + Component D: { + comments: [], + context: undefined, + message: undefined, + origin: [ + [ + collect/[componentD]/index.js, + 1, + ], + ], + placeholders: {}, + }, +} +`; + exports[`Catalog collect should extract files with special characters when passed in options 1`] = ` { Component C: { diff --git a/packages/cli/src/api/catalog.test.ts b/packages/cli/src/api/catalog.test.ts index d295f1e9c..ef79a4ea7 100644 --- a/packages/cli/src/api/catalog.test.ts +++ b/packages/cli/src/api/catalog.test.ts @@ -318,6 +318,21 @@ describe("Catalog", () => { expect(messages).toMatchSnapshot() }) + it("should extract files with special characters in the include path", async () => { + const catalog = new Catalog( + { + name: "messages", + path: "locales/{locale}", + include: [fixture("collect/[componentD]")], + exclude: [], + format, + }, + mockConfig() + ) + const messages = await catalog.collect() + expect(messages).toMatchSnapshot() + }) + it("should throw an error when duplicate identifier with different defaults found", async () => { const catalog = new Catalog( { diff --git a/packages/cli/src/api/catalog.ts b/packages/cli/src/api/catalog.ts index 099b5471d..e0f74f591 100644 --- a/packages/cli/src/api/catalog.ts +++ b/packages/cli/src/api/catalog.ts @@ -264,22 +264,24 @@ export class Catalog { } get sourcePaths() { - const includeGlobs = this.include.map((includePath) => { - const isDir = isDirectory(includePath) - /** - * glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join. - * On windows, this will by default result in /foo/* matching C:\foo\bar.txt. - */ - return isDir - ? normalize( - path.resolve( - process.cwd(), - includePath === "/" ? "" : includePath, - "**/*.*" + const includeGlobs = this.include + .map((includePath) => { + const isDir = isDirectory(includePath) + /** + * glob library results from absolute patterns such as /foo/* are mounted onto the root setting using path.join. + * On windows, this will by default result in /foo/* matching C:\foo\bar.txt. + */ + return isDir + ? normalize( + path.resolve( + process.cwd(), + includePath === "/" ? "" : includePath, + "**/*.*" + ) ) - ) - : includePath - }) + : includePath + }) + .map(makePathRegexSafe) return globSync(includeGlobs, { ignore: this.exclude, mark: true }) }