From 81c9e9533a567965f5b2bc569e79c42ff3bb2843 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 13 Nov 2020 16:00:01 +0000 Subject: [PATCH 1/5] fix: run tests on windows There are two things that break this module on windows: 1. Quoting globbed strings to stop unix shells doing path expansion results in the quotes being passed through to globby which breaks 2. Normalising the paths replaces backlashes with forward slashes on Windows. Because the code passes them to globby twice, the second time round nothing is matched because it doesn't understand forward slashes as path separators So in this PR 1. Strip any leading and trailing quotes from strings 2. Do the path.resolve dance to dedupe globby's output but return the original strings instead of the resolved strings --- .github/workflows/tests.yml | 2 +- cli.js | 8 ++++++++ index.js | 4 ++-- package.json | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8f98042..6fd5147 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: node_version: [10, 12, 14, 15] - os: [ubuntu-latest] + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v1 - name: Use Node.js ${{ matrix.node_version }} diff --git a/cli.js b/cli.js index 32b8494..bd9b0b3 100755 --- a/cli.js +++ b/cli.js @@ -52,6 +52,10 @@ if (args.help || args._.length === 0) { process.exit(1) } +// windows leaves leading/trailing quotes on strings needed on unix to +// stop shells from doing path expansion, so strip them if present +args._ = args._.map(stripQuotes) + function extensions (arg) { if (!arg) return undefined const extensions = {} @@ -73,6 +77,10 @@ function extensions (arg) { return extensions } +function stripQuotes (string) { + return string.replace(/(^'|")|('|"$)/g, '') +} + check({ path: args._.shift(), entries: args._, diff --git a/index.js b/index.js index ee0d8bb..2faa4d1 100644 --- a/index.js +++ b/index.js @@ -34,12 +34,12 @@ async function resolveGlobbedPath (entries, cwd) { expandDirectories: false }) - const paths = Object.keys(resolvedEntries.reduce((result, entry) => { + const paths = Object.values(resolvedEntries.reduce((result, entry) => { // Globby yields unix-style paths. const normalized = path.resolve(entry) if (!result[normalized]) { - result[normalized] = true + result[normalized] = entry } return result diff --git a/package.json b/package.json index 4a49f1d..184b9bf 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "lint": "standard", "test-cli:custom-detective": "node cli.js test/ -e js:detective-cjs", "test-cli:glob": "node cli.js 'test/**/*.js' --no-default-entries", + "test-cli:multi-glob": "node cli.js test/foo.js 'test/*.js' \"test/donkey/*.js\" --no-default-entries", "test-cli:main-as-file": "node cli.js test/index.js", "test-cli:simple": "node cli.js test/", "test-cli": "run-p test-cli:*", From 82af2c894864f15bf4a0eee81995fa64f5b1b714 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Tue, 24 Nov 2020 10:32:07 +0000 Subject: [PATCH 2/5] Update cli.js Co-authored-by: Pelle Wessman --- cli.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index bd9b0b3..a4f0c71 100755 --- a/cli.js +++ b/cli.js @@ -78,7 +78,9 @@ function extensions (arg) { } function stripQuotes (string) { - return string.replace(/(^'|")|('|"$)/g, '') + if (string.startsWith("'") || string.startsWith('"')) string = string.slice(1); + if (string.endsWith("'") || string.endsWith('"')) string = string.slice(0, -1); + return string; } check({ From e8606a8aa8f932af6718d6c4d1ba331edadd7bd6 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 24 Nov 2020 10:36:48 +0000 Subject: [PATCH 3/5] linting --- cli.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cli.js b/cli.js index a4f0c71..6743f15 100755 --- a/cli.js +++ b/cli.js @@ -78,9 +78,15 @@ function extensions (arg) { } function stripQuotes (string) { - if (string.startsWith("'") || string.startsWith('"')) string = string.slice(1); - if (string.endsWith("'") || string.endsWith('"')) string = string.slice(0, -1); - return string; + if (string.startsWith("'") || string.startsWith('"')) { + string = string.slice(1) + } + + if (string.endsWith("'") || string.endsWith('"')) { + string = string.slice(0, -1) + } + + return string } check({ From f908462821ade127040cc9178a90461ddfb5b1f6 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 24 Nov 2020 12:05:22 +0000 Subject: [PATCH 4/5] replace backslashes with forward slashes --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2faa4d1..226420f 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,9 @@ const promisedResolveModule = (file, options) => new Promise((resolve, reject) = async function resolveGlobbedPath (entries, cwd) { if (typeof entries === 'string') entries = [entries] + // replace backslashes for forward slashes for windows + entries = entries.map(entry => entry.replace(/\\/g, '/')) + debug('globby resolving', entries) const resolvedEntries = await globby(entries, { @@ -34,12 +37,12 @@ async function resolveGlobbedPath (entries, cwd) { expandDirectories: false }) - const paths = Object.values(resolvedEntries.reduce((result, entry) => { + const paths = Object.keys(resolvedEntries.reduce((result, entry) => { // Globby yields unix-style paths. const normalized = path.resolve(entry) if (!result[normalized]) { - result[normalized] = entry + result[normalized] = true } return result From 96928de49974389c039d777b37040d7d382dde96 Mon Sep 17 00:00:00 2001 From: Pelle Wessman Date: Tue, 24 Nov 2020 13:10:16 +0100 Subject: [PATCH 5/5] Make the tests run on PR:s --- .github/workflows/tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6fd5147..3e552cb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,6 +1,8 @@ name: Node CI -on: [push] +on: + - push + - pull_request jobs: test: