diff --git a/src/commands/push.ts b/src/commands/push.ts index 6d0e3fdd..8ebfaf27 100644 --- a/src/commands/push.ts +++ b/src/commands/push.ts @@ -3,7 +3,6 @@ import type { BaseOptions } from '../options.js'; import { extname, join } from 'path'; import { readdir, readFile, stat } from 'fs/promises'; import { Command, Option } from 'commander'; -import { glob } from 'glob'; import { loading, @@ -17,6 +16,7 @@ import { askString } from '../utils/ask.js'; import { mapImportFormat } from '../utils/mapImportFormat.js'; import { TolgeeClient, handleLoadableError } from '../client/TolgeeClient.js'; import { BodyOf } from '../client/internal/schema.utils.js'; +import { windowsCompatibleGlob } from '../utils/windowsCompatibleGlob.js'; type ImportRequest = BodyOf< '/v2/projects/{projectId}/single-step-import', @@ -46,7 +46,7 @@ type PushOptions = BaseOptions & { async function allInPattern(pattern: string) { const files: File[] = []; - const items = await glob(pattern); + const items = await windowsCompatibleGlob(pattern); for (const item of items) { if ((await stat(item)).isDirectory()) { files.push(...(await readDirectory(item))); diff --git a/src/config/tolgeerc.ts b/src/config/tolgeerc.ts index 3bc4effb..3ca468f4 100644 --- a/src/config/tolgeerc.ts +++ b/src/config/tolgeerc.ts @@ -60,6 +60,7 @@ function parseConfig(input: Schema, configDir: string): Schema { })); } + // convert relative paths in config to absolute if (rc.pull?.path !== undefined) { rc.pull.path = resolve(configDir, rc.pull.path); } diff --git a/src/extractor/runner.ts b/src/extractor/runner.ts index 7bc1f9d9..a0b209c5 100644 --- a/src/extractor/runner.ts +++ b/src/extractor/runner.ts @@ -4,11 +4,11 @@ import type { ParserType, VerboseOption, } from './index.js'; -import { glob } from 'glob'; import { extname } from 'path'; import { callWorker } from './worker.js'; import { exitWithError } from '../utils/logger.js'; +import { windowsCompatibleGlob } from '../utils/windowsCompatibleGlob.js'; export const NullNamespace = Symbol('namespace.null'); @@ -94,9 +94,8 @@ export async function extractKeysOfFiles(opts: Opts) { exitWithError("Missing '--patterns' or 'config.patterns' option"); } - const files = await glob(opts.patterns, { + const files = await windowsCompatibleGlob(opts.patterns, { nodir: true, - windowsPathsNoEscape: process.platform === 'win32', }); if (files.length === 0) { diff --git a/src/utils/windowsCompatibleGlob.ts b/src/utils/windowsCompatibleGlob.ts new file mode 100644 index 00000000..ffed258e --- /dev/null +++ b/src/utils/windowsCompatibleGlob.ts @@ -0,0 +1,11 @@ +import { glob, GlobOptionsWithFileTypesUnset } from 'glob'; + +export const windowsCompatibleGlob = ( + pattern: string | string[], + options?: GlobOptionsWithFileTypesUnset | undefined +) => { + return glob(pattern, { + ...options, + windowsPathsNoEscape: process.platform === 'win32', + }); +}; diff --git a/test/__fixtures__/validTolgeeRc/i18n/en.json b/test/__fixtures__/validTolgeeRc/i18n/en.json new file mode 100644 index 00000000..7fb631fc --- /dev/null +++ b/test/__fixtures__/validTolgeeRc/i18n/en.json @@ -0,0 +1,3 @@ +{ + "test": "Test" +} diff --git a/test/__fixtures__/validTolgeeRc/src/App.tsx b/test/__fixtures__/validTolgeeRc/src/App.tsx new file mode 100644 index 00000000..bf974672 --- /dev/null +++ b/test/__fixtures__/validTolgeeRc/src/App.tsx @@ -0,0 +1,3 @@ +export function App() { + return null; +} diff --git a/test/unit/config.test.ts b/test/unit/config.test.ts index 1f3e9b22..38a1aeac 100644 --- a/test/unit/config.test.ts +++ b/test/unit/config.test.ts @@ -2,6 +2,7 @@ import { fileURLToPath } from 'url'; import { MockInstance, vi } from 'vitest'; import loadTolgeeRc from '#cli/config/tolgeerc.js'; +import { windowsCompatibleGlob } from '#cli/utils/windowsCompatibleGlob.js'; const FIXTURES_PATH = new URL('../__fixtures__/', import.meta.url); @@ -73,13 +74,14 @@ describe('.tolgeerc', () => { const cfg = (await loadTolgeeRc(path))!; // make sure all paths in the config file are expanded relatively to the config location - [ + for (const path of [ cfg.extractor, ...cfg.patterns!, ...cfg.push!.files!.map((f) => f.path), - ].forEach((path) => { - expect(path).toMatch(/[/\\]validTolgeeRc[/\\]/); - }); + ]) { + expect(path).toMatch(/[^/\\][/\\]validTolgeeRc[/\\][^/\\]/); + expect(await windowsCompatibleGlob(path!)).length.above(0); + } }); it('converts projectId to number', async () => {