From a48fb3d5bb405c5a39f1d86ee284392bdf856671 Mon Sep 17 00:00:00 2001 From: tada5hi Date: Thu, 11 Aug 2022 15:02:09 +0200 Subject: [PATCH] allow ignore pattern for file location --- package.json | 3 ++- src/locator/async.ts | 2 ++ src/locator/sync.ts | 2 ++ src/locator/type.ts | 1 + src/locator/utils.ts | 2 ++ 5 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 95d2ff8b..bca128bd 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js", "test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage", "lint": "eslint --ext .js,.vue,.ts ./src", - "lint:fix": "npm run lint -- --fix" + "lint:fix": "npm run lint -- --fix", + "prepublishOnly": "npm run build" }, "keywords": [ "file", diff --git a/src/locator/async.ts b/src/locator/async.ts index 9f668f14..50ebfa05 100644 --- a/src/locator/async.ts +++ b/src/locator/async.ts @@ -31,6 +31,7 @@ export async function locateFiles( absolute: true, cwd: options.path[j], nodir: true, + ignore: options.ignore, }); for (let k = 0; k < files.length; k++) { @@ -64,6 +65,7 @@ export async function locateFile( absolute: true, cwd: options.path[j], nodir: true, + ignore: options.ignore, }); const element = files.shift(); diff --git a/src/locator/sync.ts b/src/locator/sync.ts index 05a6932a..6144a71f 100644 --- a/src/locator/sync.ts +++ b/src/locator/sync.ts @@ -28,6 +28,7 @@ export function locateFilesSync( absolute: true, cwd: options.path[j], nodir: true, + ignore: options.ignore, }); for (let k = 0; k < files.length; k++) { @@ -61,6 +62,7 @@ export function locateFileSync( absolute: true, cwd: options.path[j], nodir: true, + ignore: options.ignore, }); const element = files.shift(); diff --git a/src/locator/type.ts b/src/locator/type.ts index ee67cabe..eecd4eec 100644 --- a/src/locator/type.ts +++ b/src/locator/type.ts @@ -13,4 +13,5 @@ export type LocatorInfo = { export type LocatorOptions = { path: string | string[], + ignore: string | string[] }; diff --git a/src/locator/utils.ts b/src/locator/utils.ts index e9b8a308..ed4f822c 100644 --- a/src/locator/utils.ts +++ b/src/locator/utils.ts @@ -17,6 +17,8 @@ export function buildLocatorOptions(options?: Partial) : Locator options.path.push(process.cwd()); } + options.ignore ??= []; + return options as LocatorOptions; }