diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 641fd9ae..5f4b46da 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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 diff --git a/lib/file_system.js b/lib/file_system.js index 8c4afadd..5cffaf46 100644 --- a/lib/file_system.js +++ b/lib/file_system.js @@ -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 @@ -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))) } /** diff --git a/tests/cli/cli_tests.js b/tests/cli/cli_tests.js index 36a99afe..5bc97919 100644 --- a/tests/cli/cli_tests.js +++ b/tests/cli/cli_tests.js @@ -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) diff --git a/tests/lib/file_system_tests.js b/tests/lib/file_system_tests.js index 88df74d0..3fd25231 100644 --- a/tests/lib/file_system_tests.js +++ b/tests/lib/file_system_tests.js @@ -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) @@ -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') }) }) @@ -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 () => {