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: handling glob paths incorrectly on Windows #166

Merged
merged 1 commit into from
May 26, 2022
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
7 changes: 5 additions & 2 deletions src/create-report/language-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import isValidGlob from 'is-valid-glob';
import { SimpleFile, I18NLanguage, I18NItem } from '../types';

export function readLanguageFiles (src: string): SimpleFile[] {
if (!isValidGlob(src)) {
// Replace backslash path segments to make the path work with the glob package.
// https://github.com/Spittal/vue-i18n-extract/issues/159
const normalizedSrc = src.replace(/\\/g, '/');
if (!isValidGlob(normalizedSrc)) {
throw new Error(`languageFiles isn't a valid glob pattern.`);
}

const targetFiles = glob.sync(src);
const targetFiles = glob.sync(normalizedSrc);

if (targetFiles.length === 0) {
throw new Error('languageFiles glob has no files.');
Expand Down
7 changes: 5 additions & 2 deletions src/create-report/vue-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import glob from 'glob';
import fs from 'fs';

export function readVueFiles (src: string): SimpleFile[] {
if (!isValidGlob(src)) {
// Replace backslash path segments to make the path work with the glob package.
// https://github.com/Spittal/vue-i18n-extract/issues/159
const normalizedSrc = src.replace(/\\/g, '/');
if (!isValidGlob(normalizedSrc)) {
throw new Error(`vueFiles isn't a valid glob pattern.`);
}

const targetFiles = glob.sync(src);
const targetFiles = glob.sync(normalizedSrc);

if (targetFiles.length === 0) {
throw new Error('vueFiles glob has no files.');
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/create-report/language-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { readLanguageFiles, writeMissingToLanguageFiles, removeUnusedFromLanguag
import { expectedFromParsedLanguageFiles, expectedI18NReport } from '../../fixtures/expected-values';
import { languageFiles } from '../../fixtures/resolved-sources';

const languageFilesWithBackslashes = languageFiles.replace(/\//g, '\\');

describe('file: create-report/language-files', () => {
describe('function: parselanguageFiles', () => {
it('Parse the file glob into an I18NLanguage object', () => {
it.each([
languageFiles,
languageFilesWithBackslashes
])('Parse the file glob into an I18NLanguage object', (languageFiles) => {
const I18NLanguage = parselanguageFiles(languageFiles);
expect(I18NLanguage).toEqual(expectedFromParsedLanguageFiles);
});
Expand Down Expand Up @@ -48,4 +53,3 @@ describe('file: create-report/language-files', () => {
});
});
})

9 changes: 7 additions & 2 deletions tests/unit/create-report/vue-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import { expectedFromParsedVueFiles } from '../../fixtures/expected-values';
import { vueFiles } from '../../fixtures/resolved-sources';
import path from 'path';

const vueFilesWithBackslashes = vueFiles.replace(/\//g, '\\');

describe('file: create-report/vue-files', () => {
describe('function: parseVueFiles', () => {
it('Parse the file glob into I18n items', () => {
const I18NItems = parseVueFiles(vueFiles);
it.each([
vueFiles,
vueFilesWithBackslashes
])('Parse the file glob into I18n items', (files) => {
const I18NItems = parseVueFiles(files);
expect(I18NItems).toEqual(expectedFromParsedVueFiles);
});

Expand Down