Skip to content

Commit d71cc68

Browse files
committed
fix: ignore resolving (#221)
1 parent d809405 commit d71cc68

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/utils.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -477,25 +477,25 @@ export function getIgnore (target:string, ignoreFileNames: string): Ignore {
477477
const ig = ignore()
478478
const files = ignoreFileNames.split(',').filter(Boolean)
479479
files.forEach(file => {
480-
const fullPath = resolve(path.join(target, path.normalize(file)))
481-
debug('getIgnore: fullpath', fullPath, fs.existsSync(fullPath))
482-
if (fs.existsSync(fullPath)) {
483-
const ignoreFiles = readIgnoreFile(fullPath)
484-
returnIgnoreInstance(ig, ignoreFiles)
485-
}
480+
debug('ignore target file', file)
481+
const ignoreFiles = readIgnoreFile(target, file)
482+
returnIgnoreInstance(ig, ignoreFiles)
486483
})
487484
return ig
488485
}
489486

490-
function readIgnoreFile (ignoreFile: string): string[] {
491-
debug('readIgnoreFile: ignoreFile', ignoreFile)
487+
function readIgnoreFile (target: string, _ignoreFile: string): string[] {
488+
const ignoreFiles = glob.sync(`${target}/**/${_ignoreFile}`)
489+
debug('readIgnoreFile: ignoreFiles', ignoreFiles)
492490
const ignoreTargets = [] as string[]
493-
fs.readFileSync(ignoreFile, 'utf8')
494-
.split(/\r?\n/g)
495-
.filter(Boolean)
496-
.forEach(ignoreTarget => {
497-
ignoreTargets.push(formatPath(ignoreFile, ignoreTarget))
498-
})
491+
ignoreFiles.forEach(ignoreFile => {
492+
fs.readFileSync(ignoreFile, 'utf8')
493+
.split(/\r?\n/g)
494+
.filter(Boolean)
495+
.forEach(ignoreTarget => {
496+
ignoreTargets.push(formatPath(ignoreFile, ignoreTarget))
497+
})
498+
})
499499
debug(`ignoreTargets ${ignoreTargets}`)
500500
return ignoreTargets
501501
}

test/commands/infuse.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ test('ignore option', async () => {
306306
writeFiles[path as string] = data.toString()
307307
})
308308
mockFS.readFileSync.mockImplementationOnce(path => MOCK_IGNORE_FILES)
309+
const mockGlob = glob as jest.Mocked<typeof glob>
310+
mockGlob.sync.mockImplementationOnce(p => [`${TARGET_PATH}/src/App.vue`])
309311
const mockPath = path as jest.Mocked<typeof path>
310312
mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)
311313

test/commands/squeeze.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ test('ignore option', async () => {
176176
mockUtils.getExternalLocaleMessages.mockImplementation(() => ({}))
177177
const mockFS = fs as jest.Mocked<typeof fs>
178178
mockFS.readFileSync.mockImplementationOnce(p => MOCK_IGNORE_FILES);
179+
const mockGlob = glob as jest.Mocked<typeof glob>
180+
mockGlob.sync.mockImplementationOnce(p => [path.resolve('./test/fixtures/.ignore-i18n')])
179181
const mockPath = path as jest.Mocked<typeof path>
180182
mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)
181183

0 commit comments

Comments
 (0)