Skip to content

Commit

Permalink
fix: ignore resolving (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Dec 10, 2021
1 parent 009614b commit b743a7c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions test/commands/infuse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof glob>
mockGlob.sync.mockImplementationOnce(p => [`${TARGET_PATH}/src/App.vue`])
const mockPath = path as jest.Mocked<typeof path>
mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)

Expand Down
2 changes: 2 additions & 0 deletions test/commands/squeeze.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ test('ignore option', async () => {
mockUtils.getExternalLocaleMessages.mockImplementation(() => ({}))
const mockFS = fs as jest.Mocked<typeof fs>
mockFS.readFileSync.mockImplementationOnce(p => MOCK_IGNORE_FILES);
const mockGlob = glob as jest.Mocked<typeof glob>
mockGlob.sync.mockImplementationOnce(p => [path.resolve('./test/fixtures/.ignore-i18n')])
const mockPath = path as jest.Mocked<typeof path>
mockPath.dirname.mockImplementationOnce(p => TARGET_PATH)

Expand Down

0 comments on commit b743a7c

Please sign in to comment.