Skip to content

Commit

Permalink
fix: windows compatibility fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
prototypicalpro committed Aug 25, 2020
1 parent 2679c84 commit 8fc0540
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ jobs:

- name: Install Licensee and Linguist
if: ${{ runner.os != 'Windows' }}
run: gem install licensee github-linguist

- name: Add Bundle to Path
if: ${{ runner.os != 'Windows' }}
run: echo "::add-path::$GITHUB_WORKSPACE/vendor/bundle/ruby/2.7.0/bin"
run: gem install --no-ri --no-rdoc licensee github-linguist

- name: Run Test
run: npm test
17 changes: 3 additions & 14 deletions lib/file_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ class FileSystem {
return FileSystem.fileExists(path.resolve(this.targetDir, file))
}

getFilterFiles () {
return this.filterPaths.filter(filter => !filter.endsWith('/'))
}

getFilterDirectories () {
return this.filterPaths.filter(filter => filter.endsWith('/'))
}

/**
* Find the first file or directory matching a list of globs. Globs are
* searched from first to last. Returns the relative path of that file
Expand Down Expand Up @@ -136,13 +128,10 @@ class FileSystem {
}
}

shouldInclude (path) {
shouldInclude (filePath) {
if (this.filterPaths.length === 0) { return true }
return [
this.getFilterFiles().includes(path),
this.getFilterDirectories().some(directory => path.startsWith(directory)),
this.getFilterDirectories().some(directory => path.replace(/\//, '') === directory.replace(/\//, ''))
].some(check => check === true)
const resolvedPath = path.relative(this.targetDir, path.resolve(this.targetDir, filePath))
return this.filterPaths.some(p => resolvedPath.startsWith(path.normalize(p)))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/cli_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function execAsync (
}

describe('cli', function () {
const repolinterPath = path.resolve('bin/repolinter.js')
const repolinterPath = process.platform === 'win32' ? path.resolve('bin/repolinter.bat') : path.resolve('bin/repolinter.js')
const selfPath = path.resolve('tests/cli')
this.timeout(30000)

Expand Down
9 changes: 5 additions & 4 deletions tests/lib/file_system_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('lib', () => {
})

it('should honor filtered files', async () => {
const includedFiles = ['index.js', 'bin/repolinter.bat']
const includedFiles = ['index.js', path.join('bin', 'repolinter.bat')]
const fs = new FileSystem(path.resolve('.'), includedFiles)

const filesRaw = await fs.findAll('**/*', false)
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('lib', () => {
it('should return the contents of a file', async () => {
const raw = await fs.getFileContents('text_file_for_test.txt')
// replace newlines to prevent compatibility issues
const actual = raw.replace('\r', '')
const actual = raw.replace(/\r/g, '')
expect(actual).to.equal('The contents of this file\nwill be monitored for quality assurance purposes\n')
})
})
Expand All @@ -188,8 +188,9 @@ describe('lib', () => {
it('should change the contents of a file', async () => {
const expected = 'somefilecontents\nmorecontents\n'
fs.setFileContents('text_file_for_test.txt', expected)
const fileContents = await realFs.promises.readFile(filePath)
expect(fileContents).to.equal(expected)
const fileContents = await realFs.promises.readFile(filePath, 'utf8')
const realFileContents = fileContents.replace(/\r/g, '')
expect(realFileContents).to.equal(expected)
})

after(async () => {
Expand Down

0 comments on commit 8fc0540

Please sign in to comment.