Skip to content

Commit 352dce5

Browse files
jfmengelslydell
andauthored
Replace glob by tinyglobby (#647)
Co-authored-by: Simon Lydell <[email protected]>
1 parent 01ed41e commit 352dce5

File tree

6 files changed

+69
-103
lines changed

6 files changed

+69
-103
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ jobs:
5050
env:
5151
NO_ELM_TOOLING_INSTALL: 1
5252

53-
- name: install glob 8
54-
if: steps.cache-node_modules.outputs.cache-hit != 'true' && (matrix.node-version == '12.x' || matrix.node-version == '14.x')
55-
run: npm install glob@8
56-
5753
- name: install mocha 9
5854
if: steps.cache-node_modules.outputs.cache-hit != 'true' && (matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x')
5955
run: npm install mocha@9

lib/FindTests.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const gracefulFs = require('graceful-fs');
44
const fs = require('fs');
5-
const glob = require('glob');
5+
const { globSync } = require('tinyglobby');
66
const path = require('path');
77
const Parser = require('./Parser');
88
const Project = require('./Project');
@@ -59,44 +59,39 @@ function resolveCliArgGlob(
5959
path.resolve(fileGlob)
6060
);
6161

62-
// glob@8 (via minimatch@5) had a breaking change where you _have_ to use
63-
// forwards slash as path separator, regardless of platform, making it
64-
// unambiguous which characters are separators and which are escapes. This
65-
// restores the previous behavior, avoiding a breaking change in elm-test.
62+
// The globs _have_ to use forwards slash as path separator, regardless of
63+
// platform, making it unambiguous which characters are separators and which
64+
// are escapes.
6665
// Note: As far I can tell, escaping glob syntax has _never_ worked on
6766
// Windows. In Elm, needing to escape glob syntax should be very rare, since
6867
// Elm file paths must match the module name (letters only). So it’s probably
6968
// more worth supporting `some\folder\*Test.elm` rather than escaping.
70-
// https://github.com/isaacs/node-glob/issues/468
71-
// https://github.com/isaacs/minimatch/commit/9104d8d175bdd8843338103be1401f80774d2a10#diff-f41746899d033115e03bebe4fbde76acf2de4bf261bfb221744808f4c8a286cf
7269
const pattern =
7370
process.platform === 'win32'
7471
? globRelativeToProjectRoot.replace(/\\/g, '/')
7572
: globRelativeToProjectRoot;
7673

77-
return glob
78-
.sync(pattern, {
79-
cwd: projectRootDir,
80-
nocase: true,
81-
absolute: true,
82-
ignore: ignoredDirsGlobs,
83-
// Match directories as well and mark them with a trailing slash.
84-
nodir: false,
85-
mark: true,
86-
})
87-
.flatMap((filePath) =>
88-
filePath.endsWith('/') ? findAllElmFilesInDir(filePath) : filePath
89-
);
74+
return globSync(pattern, {
75+
cwd: projectRootDir,
76+
caseSensitiveMatch: false,
77+
absolute: true,
78+
ignore: ignoredDirsGlobs,
79+
// Match directories as well
80+
onlyFiles: false,
81+
}).flatMap((filePath) =>
82+
// Directories have their path end with `/`
83+
filePath.endsWith('/') ? findAllElmFilesInDir(filePath) : filePath
84+
);
9085
}
9186

9287
// Recursively search for *.elm files.
9388
function findAllElmFilesInDir(dir /*: string */) /*: Array<string> */ {
94-
return glob.sync('**/*.elm', {
89+
return globSync('**/*.elm', {
9590
cwd: dir,
96-
nocase: true,
91+
caseSensitiveMatch: false,
9792
absolute: true,
9893
ignore: ignoredDirsGlobs,
99-
nodir: true,
94+
onlyFiles: true,
10095
});
10196
}
10297

0 commit comments

Comments
 (0)