From b743a7c358c21561ceff4425ea8b7efad66b4296 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 10 Dec 2021 17:52:20 +0900 Subject: [PATCH] fix: ignore resolving (#221) --- src/utils.ts | 28 ++++++++++++++-------------- test/commands/infuse.test.ts | 2 ++ test/commands/squeeze.test.ts | 2 ++ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 720d174..fb08698 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -484,25 +484,25 @@ export function getIgnore (target:string, ignoreFileNames: string): Ignore { const ig = ignore() const files = ignoreFileNames.split(',').filter(Boolean) files.forEach(file => { - const fullPath = resolve(path.join(target, path.normalize(file))) - debug('getIgnore: fullpath', fullPath, fs.existsSync(fullPath)) - if (fs.existsSync(fullPath)) { - const ignoreFiles = readIgnoreFile(fullPath) - returnIgnoreInstance(ig, ignoreFiles) - } + debug('ignore target file', file) + const ignoreFiles = readIgnoreFile(target, file) + returnIgnoreInstance(ig, ignoreFiles) }) return ig } -function readIgnoreFile (ignoreFile: string): string[] { - debug('readIgnoreFile: ignoreFile', ignoreFile) +function readIgnoreFile (target: string, _ignoreFile: string): string[] { + const ignoreFiles = glob.sync(`${target}/**/${_ignoreFile}`) + debug('readIgnoreFile: ignoreFiles', ignoreFiles) const ignoreTargets = [] as string[] - fs.readFileSync(ignoreFile, 'utf8') - .split(/\r?\n/g) - .filter(Boolean) - .forEach(ignoreTarget => { - ignoreTargets.push(formatPath(ignoreFile, ignoreTarget)) - }) + ignoreFiles.forEach(ignoreFile => { + fs.readFileSync(ignoreFile, 'utf8') + .split(/\r?\n/g) + .filter(Boolean) + .forEach(ignoreTarget => { + ignoreTargets.push(formatPath(ignoreFile, ignoreTarget)) + }) + }) debug(`ignoreTargets ${ignoreTargets}`) return ignoreTargets } diff --git a/test/commands/infuse.test.ts b/test/commands/infuse.test.ts index e848733..a4e0b82 100644 --- a/test/commands/infuse.test.ts +++ b/test/commands/infuse.test.ts @@ -299,6 +299,8 @@ test('ignore option', async () => { writeFiles[path as string] = data.toString() }) mockFS.readFileSync.mockImplementationOnce(path => MOCK_IGNORE_FILES) + const mockGlob = glob as jest.Mocked + mockGlob.sync.mockImplementationOnce(p => [`${TARGET_PATH}/src/App.vue`]) const mockPath = path as jest.Mocked mockPath.dirname.mockImplementationOnce(p => TARGET_PATH) diff --git a/test/commands/squeeze.test.ts b/test/commands/squeeze.test.ts index 11f71f9..cb7ac3d 100644 --- a/test/commands/squeeze.test.ts +++ b/test/commands/squeeze.test.ts @@ -176,6 +176,8 @@ test('ignore option', async () => { mockUtils.getExternalLocaleMessages.mockImplementation(() => ({})) const mockFS = fs as jest.Mocked mockFS.readFileSync.mockImplementationOnce(p => MOCK_IGNORE_FILES); + const mockGlob = glob as jest.Mocked + mockGlob.sync.mockImplementationOnce(p => [path.resolve('./test/fixtures/.ignore-i18n')]) const mockPath = path as jest.Mocked mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)