Skip to content

Commit

Permalink
update prettier, format everything
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 24, 2024
1 parent 10162fb commit 057d5b2
Show file tree
Hide file tree
Showing 41 changed files with 308 additions and 305 deletions.
20 changes: 12 additions & 8 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
/node_modules
/example
/.github
/.tap
/node_modules
/tap-snapshots

/scripts/fixtures
/.tap
/.tshy
/dist
.env
/docs
/example
/node_modules
/tap-snapshots
/.nyc_output
/coverage
/benchmark
/scripts/fixture
/test/fixture
/test/**/fixture
/test/**/fixtures
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ g3.stream().on('data', path => {
'got a path object',
path.fullpath(),
path.isDirectory(),
path.readdirSync().map(e => e.name)
path.readdirSync().map(e => e.name),
)
})

Expand Down Expand Up @@ -606,28 +606,31 @@ share the previously loaded cache.
`false`, and a custom `Ignore` is provided that does not have
an `add()` method, then it will throw an error.

**Caveat** It *only* ignores matches that would be a descendant
**Caveat** It _only_ ignores matches that would be a descendant
of a previous match, and only if that descendant is matched
*after* the ancestor is encountered. Since the file system walk
_after_ the ancestor is encountered. Since the file system walk
happens in indeterminate order, it's possible that a match will
already be added before its ancestor, if multiple or braced
patterns are used.

For example:

```js
const results = await glob([
// likely to match first, since it's just a stat
'a/b/c/d/e/f',

// this pattern is more complicated! It must to various readdir()
// calls and test the results against a regular expression, and that
// is certainly going to take a little bit longer.
//
// So, later on, it encounters a match at 'a/b/c/d/e', but it's too
// late to ignore a/b/c/d/e/f, because it's already been emitted.
'a/[bdf]/?/[a-z]/*',
], { includeChildMatches: false })
const results = await glob(
[
// likely to match first, since it's just a stat
'a/b/c/d/e/f',

// this pattern is more complicated! It must to various readdir()
// calls and test the results against a regular expression, and that
// is certainly going to take a little bit longer.
//
// So, later on, it encounters a match at 'a/b/c/d/e', but it's too
// late to ignore a/b/c/d/e/f, because it's already been emitted.
'a/[bdf]/?/[a-z]/*',
],
{ includeChildMatches: false },
)
```

It's best to only set this to `false` if you can be reasonably
Expand Down
2 changes: 1 addition & 1 deletion examples/g.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ console.log(pattern)

var mg = new Glob(pattern, { mark: true, sync: true }, function (
er,
matches
matches,
) {
console.log('matches', matches)
})
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"presnap": "npm run prepare",
"test": "tap",
"snap": "tap",
"format": "prettier --write . --loglevel warn",
"format": "prettier --write . --log-level warn",
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts",
"prepublish": "npm run benchclean",
"profclean": "rm -f v8.log profile.txt",
Expand All @@ -55,6 +55,7 @@
"benchclean": "node benchclean.cjs"
},
"prettier": {
"experimentalTernaries": true,
"semi": false,
"printWidth": 75,
"tabWidth": 2,
Expand All @@ -76,7 +77,7 @@
"@types/node": "^20.11.30",
"memfs": "^3.4.13",
"mkdirp": "^3.0.1",
"prettier": "^2.8.3",
"prettier": "^3.2.5",
"rimraf": "^5.0.7",
"sync-content": "^1.0.2",
"tap": "^19.0.0",
Expand Down
44 changes: 22 additions & 22 deletions src/bin.mts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { globStream } from './index.js'
const { version } = JSON.parse(
await readFile(
fileURLToPath(new URL('../../package.json', import.meta.url)),
'utf8'
'utf8',
).catch(() =>
readFile(
fileURLToPath(new URL('../../package.json', import.meta.url)),
'utf8'
)
)
'utf8',
),
),
) as { version: string }
/* c8 ignore stop */

Expand All @@ -30,7 +30,7 @@ const j = jack({
Expand the positional glob expression arguments into any matching file
system paths found.
`
`,
)
.opt({
cmd: {
Expand Down Expand Up @@ -202,18 +202,18 @@ const j = jack({
available, or 'linux' if not. Setting --platform=win32
on non-Windows systems may cause strange behavior!`,
validOptions: [
'aix',
'android',
'darwin',
'freebsd',
'haiku',
'linux',
'openbsd',
'sunos',
'win32',
'cygwin',
'netbsd',
]
'aix',
'android',
'darwin',
'freebsd',
'haiku',
'linux',
'openbsd',
'sunos',
'win32',
'cygwin',
'netbsd',
],
},
})
.optList({
Expand Down Expand Up @@ -246,11 +246,11 @@ try {
throw 'No patterns provided'
if (positionals.length === 0 && values.default)
positionals.push(values.default)
const patterns = values.all
? positionals
: positionals.filter(p => !existsSync(p))
const matches = values.all
? []
const patterns =
values.all ? positionals : positionals.filter(p => !existsSync(p))
const matches =
values.all ?
[]
: positionals.filter(p => existsSync(p)).map(p => join(p))
const stream = globStream(patterns, {
absolute: values.absolute,
Expand Down
69 changes: 32 additions & 37 deletions src/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export type GlobParts = Exclude<Minimatch['globParts'], undefined>
// if no process global, just call it linux.
// so we default to case-sensitive, / separators
const defaultPlatform: NodeJS.Platform =
typeof process === 'object' &&
process &&
typeof process.platform === 'string'
? process.platform
: 'linux'
(
typeof process === 'object' &&
process &&
typeof process.platform === 'string'
) ?
process.platform
: 'linux'

/**
* A `GlobOptions` object may be provided to any of the exported methods, and
Expand Down Expand Up @@ -355,21 +357,17 @@ export type GlobOptionsWithFileTypesUnset = GlobOptions & {
withFileTypes?: undefined
}

export type Result<Opts> = Opts extends GlobOptionsWithFileTypesTrue
? Path
: Opts extends GlobOptionsWithFileTypesFalse
? string
: Opts extends GlobOptionsWithFileTypesUnset
? string
export type Result<Opts> =
Opts extends GlobOptionsWithFileTypesTrue ? Path
: Opts extends GlobOptionsWithFileTypesFalse ? string
: Opts extends GlobOptionsWithFileTypesUnset ? string
: string | Path
export type Results<Opts> = Result<Opts>[]

export type FileTypes<Opts> = Opts extends GlobOptionsWithFileTypesTrue
? true
: Opts extends GlobOptionsWithFileTypesFalse
? false
: Opts extends GlobOptionsWithFileTypesUnset
? false
export type FileTypes<Opts> =
Opts extends GlobOptionsWithFileTypesTrue ? true
: Opts extends GlobOptionsWithFileTypesFalse ? false
: Opts extends GlobOptionsWithFileTypesUnset ? false
: boolean

/**
Expand Down Expand Up @@ -494,13 +492,10 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
}
} else {
const Scurry =
opts.platform === 'win32'
? PathScurryWin32
: opts.platform === 'darwin'
? PathScurryDarwin
: opts.platform
? PathScurryPosix
: PathScurry
opts.platform === 'win32' ? PathScurryWin32
: opts.platform === 'darwin' ? PathScurryDarwin
: opts.platform ? PathScurryPosix
: PathScurry
this.scurry = new Scurry(this.cwd, {
nocase: opts.nocase,
fs: opts.fs,
Expand Down Expand Up @@ -539,7 +534,7 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
set[1].push(...m.globParts)
return set
},
[[], []]
[[], []],
)
this.patterns = matchSet.map((set, i) => {
const g = globParts[i]
Expand All @@ -563,9 +558,9 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
...(await new GlobWalker(this.patterns, this.scurry.cwd, {
...this.opts,
maxDepth:
this.maxDepth !== Infinity
? this.maxDepth + this.scurry.cwd.depth()
: Infinity,
this.maxDepth !== Infinity ?
this.maxDepth + this.scurry.cwd.depth()
: Infinity,
platform: this.platform,
nocase: this.nocase,
includeChildMatches: this.includeChildMatches,
Expand All @@ -582,9 +577,9 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
...new GlobWalker(this.patterns, this.scurry.cwd, {
...this.opts,
maxDepth:
this.maxDepth !== Infinity
? this.maxDepth + this.scurry.cwd.depth()
: Infinity,
this.maxDepth !== Infinity ?
this.maxDepth + this.scurry.cwd.depth()
: Infinity,
platform: this.platform,
nocase: this.nocase,
includeChildMatches: this.includeChildMatches,
Expand All @@ -600,9 +595,9 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
return new GlobStream(this.patterns, this.scurry.cwd, {
...this.opts,
maxDepth:
this.maxDepth !== Infinity
? this.maxDepth + this.scurry.cwd.depth()
: Infinity,
this.maxDepth !== Infinity ?
this.maxDepth + this.scurry.cwd.depth()
: Infinity,
platform: this.platform,
nocase: this.nocase,
includeChildMatches: this.includeChildMatches,
Expand All @@ -617,9 +612,9 @@ export class Glob<Opts extends GlobOptions> implements GlobOptions {
return new GlobStream(this.patterns, this.scurry.cwd, {
...this.opts,
maxDepth:
this.maxDepth !== Infinity
? this.maxDepth + this.scurry.cwd.depth()
: Infinity,
this.maxDepth !== Infinity ?
this.maxDepth + this.scurry.cwd.depth()
: Infinity,
platform: this.platform,
nocase: this.nocase,
includeChildMatches: this.includeChildMatches,
Expand Down
2 changes: 1 addition & 1 deletion src/has-magic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { GlobOptions } from './glob.js'
*/
export const hasMagic = (
pattern: string | string[],
options: GlobOptions = {}
options: GlobOptions = {},
): boolean => {
if (!Array.isArray(pattern)) {
pattern = [pattern]
Expand Down
14 changes: 8 additions & 6 deletions src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export interface IgnoreLike {
}

const defaultPlatform: NodeJS.Platform =
typeof process === 'object' &&
process &&
typeof process.platform === 'string'
? process.platform
: 'linux'
(
typeof process === 'object' &&
process &&
typeof process.platform === 'string'
) ?
process.platform
: 'linux'

/**
* Class used to process ignored patterns
Expand All @@ -40,7 +42,7 @@ export class Ignore implements IgnoreLike {
noext,
noglobstar,
platform = defaultPlatform,
}: GlobWalkerOpts
}: GlobWalkerOpts,
) {
this.relative = []
this.absolute = []
Expand Down
Loading

0 comments on commit 057d5b2

Please sign in to comment.