Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['10', '12', '14', '16', '18', '20', '22', '24']
node: ['20', '22', '24']
os: [ubuntu, macOS]
exclude:
- os: macOS
node: '10'
- os: macOS
node: '12'
- os: macOS
node: '14'

steps:
- uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# master

* Upgrade dependencies, in particular minimatch 10
* Require Node version 20 or newer

# 3.0.0

* [BREAKING] drop node 8
Expand Down
28 changes: 15 additions & 13 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import fsNode = require('fs');
import * as MatcherCollection from 'matcher-collection';
import { Minimatch, type MinimatchOptions } from 'minimatch';
import ensurePosix = require('ensure-posix-path');
import path = require('path');
import { IMinimatch, IOptions as MinimatchOptions, Minimatch } from 'minimatch';

function walkSync(baseDir: string, inputOptions?: walkSync.Options | (string|IMinimatch)[]) {
function walkSync(baseDir: string, inputOptions?: walkSync.Options | (string|Minimatch)[]) {
const options = handleOptions(inputOptions);

let mapFunct: (arg: walkSync.Entry) => string;
Expand All @@ -28,27 +28,27 @@ function getStat(path: string, fs: walkSync.Options['fs'] = fsNode) {
try {
return fs.statSync(path);
} catch(error) {
if (error !== null && typeof error === 'object' && (error.code === 'ENOENT' || error.code === 'ENOTDIR' || error.code === 'EPERM')) {
if (error !== null && typeof error === 'object' && ['ENOENT', 'ENOTDIR', 'EPERM'].includes((error as any).code)) {
return;
}
throw error;
}
}

namespace walkSync {
export function entries(baseDir: string, inputOptions?: Options | (string|IMinimatch)[]) {
export function entries(baseDir: string, inputOptions?: Options | (string|Minimatch)[]) {
const options = handleOptions(inputOptions);

return _walkSync(ensurePosix(baseDir), options, null, []);
};

export interface Options {
includeBasePath?: boolean,
globs?: (string|IMinimatch)[],
ignore?: (string|IMinimatch)[],
directories?: boolean,
fs?: typeof fsNode,
globOptions?: MinimatchOptions,
globs?: (string|Minimatch)[],
ignore?: (string|Minimatch)[],
directories?: boolean,
fs?: typeof fsNode,
globOptions?: MinimatchOptions,
}

export class Entry {
Expand Down Expand Up @@ -80,7 +80,7 @@ function isDefined<T>(val: T | undefined) : val is T {
return typeof val !== 'undefined';
}

function handleOptions(_options?: walkSync.Options | (string|IMinimatch)[]) : walkSync.Options {
function handleOptions(_options?: walkSync.Options | (string|Minimatch)[]) : walkSync.Options {
let options: walkSync.Options = {};

if (Array.isArray(_options)) {
Expand All @@ -92,7 +92,7 @@ function handleOptions(_options?: walkSync.Options | (string|IMinimatch)[]) : wa
return options;
}

function applyGlobOptions(globs: (string|IMinimatch)[] | undefined, options: MinimatchOptions) {
function applyGlobOptions(globs: (string|Minimatch)[] | undefined, options: MinimatchOptions) {
return globs?.map(glob => {
if (typeof glob === 'string') {
return new Minimatch(glob, options);
Expand Down Expand Up @@ -146,11 +146,13 @@ function _walkSync(baseDir: string, options: walkSync.Options, _relativePath: st
let results: walkSync.Entry[] = [];

if (ignorePatterns) {
ignoreMatcher = new MatcherCollection(ignorePatterns);
// matcher-collection's published types expect the legacy IMinimatch from older minimatch
// versions. Cast to any to bridge the mismatch with minimatch@10's types.
ignoreMatcher = new MatcherCollection(ignorePatterns as any[]);
}

if (globs) {
globMatcher = new MatcherCollection(globs);
globMatcher = new MatcherCollection(globs as any[]);
}

if (globMatcher && !globMatcher.mayContain(relativePath)) {
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"types": "dist/index.d.ts",
"license": "MIT",
"engines": {
"node": "10.* || >= 12.*"
"node": ">= 20.*"
},
"repository": {
"type": "git",
Expand All @@ -17,20 +17,20 @@
"dist/"
],
"dependencies": {
"@types/minimatch": "^3.0.4",
"ensure-posix-path": "^1.1.0",
"@types/minimatch": "^5.1.2",
"ensure-posix-path": "^1.1.1",
"matcher-collection": "^2.0.1",
"minimatch": "^3.0.4"
"minimatch": "^10.0.3"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^15.12.2",
"glob": "^7.1.7",
"jest": "^27.0.4",
"memfs": "^3.2.2",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.3",
"typescript": "~4.3.2"
"@types/jest": "^30.0.0",
"@types/node": "^24.3.0",
"glob": "^11.0.3",
"jest": "^30.1.3",
"memfs": "^4.38.2",
"rimraf": "^6.0.1",
"ts-jest": "^29.4.1",
"typescript": "^5.9.2"
},
"scripts": {
"prepare": "yarn run build",
Expand Down
9 changes: 7 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function safeUnlink(path:string) {
try {
fs.unlinkSync(path);
} catch (e) {
if (typeof e === 'object' && e !== null && e.code === 'ENOENT') {
if (typeof e === 'object' && e !== null && 'code' in e && (e as { code?: string }).code === 'ENOENT') {
// handle
} else {
throw e;
Expand All @@ -38,7 +38,12 @@ function safeRmdir(path:string) {
try {
fs.rmdirSync(path);
} catch (e) {
if (typeof e === 'object' && e !== null && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) {
if (
typeof e === 'object' &&
e !== null &&
'code' in e &&
(((e as { code?: string }).code === 'ENOENT') || ((e as { code?: string }).code === 'ENOTDIR'))
) {
// handle
} else {
throw e;
Expand Down
Loading
Loading