Skip to content

Commit b743a7c

Browse files
authored
fix: ignore resolving (#221)
1 parent 009614b commit b743a7c

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/utils.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -484,25 +484,25 @@ export function getIgnore (target:string, ignoreFileNames: string): Ignore {
484484
const ig = ignore()
485485
const files = ignoreFileNames.split(',').filter(Boolean)
486486
files.forEach(file => {
487-
const fullPath = resolve(path.join(target, path.normalize(file)))
488-
debug('getIgnore: fullpath', fullPath, fs.existsSync(fullPath))
489-
if (fs.existsSync(fullPath)) {
490-
const ignoreFiles = readIgnoreFile(fullPath)
491-
returnIgnoreInstance(ig, ignoreFiles)
492-
}
487+
debug('ignore target file', file)
488+
const ignoreFiles = readIgnoreFile(target, file)
489+
returnIgnoreInstance(ig, ignoreFiles)
493490
})
494491
return ig
495492
}
496493

497-
function readIgnoreFile (ignoreFile: string): string[] {
498-
debug('readIgnoreFile: ignoreFile', ignoreFile)
494+
function readIgnoreFile (target: string, _ignoreFile: string): string[] {
495+
const ignoreFiles = glob.sync(`${target}/**/${_ignoreFile}`)
496+
debug('readIgnoreFile: ignoreFiles', ignoreFiles)
499497
const ignoreTargets = [] as string[]
500-
fs.readFileSync(ignoreFile, 'utf8')
501-
.split(/\r?\n/g)
502-
.filter(Boolean)
503-
.forEach(ignoreTarget => {
504-
ignoreTargets.push(formatPath(ignoreFile, ignoreTarget))
505-
})
498+
ignoreFiles.forEach(ignoreFile => {
499+
fs.readFileSync(ignoreFile, 'utf8')
500+
.split(/\r?\n/g)
501+
.filter(Boolean)
502+
.forEach(ignoreTarget => {
503+
ignoreTargets.push(formatPath(ignoreFile, ignoreTarget))
504+
})
505+
})
506506
debug(`ignoreTargets ${ignoreTargets}`)
507507
return ignoreTargets
508508
}

test/commands/infuse.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ test('ignore option', async () => {
299299
writeFiles[path as string] = data.toString()
300300
})
301301
mockFS.readFileSync.mockImplementationOnce(path => MOCK_IGNORE_FILES)
302+
const mockGlob = glob as jest.Mocked<typeof glob>
303+
mockGlob.sync.mockImplementationOnce(p => [`${TARGET_PATH}/src/App.vue`])
302304
const mockPath = path as jest.Mocked<typeof path>
303305
mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)
304306

test/commands/squeeze.test.ts

+2
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)