Skip to content

Commit b331033

Browse files
committedOct 17, 2023
Add --directory [dir] argument to run the process from a different dir
1 parent 7f63c75 commit b331033

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ $ npx knip --help
694694
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
695695
--ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
696696
-W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
697+
--directory [dir] Run process from a different directory (default: cwd)
697698
--no-gitignore Don't use .gitignore
698699
--include Report only provided issue type(s), can be comma-separated or repeated (1)
699700
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)

‎src/util/cli-arguments.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Options:
1111
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
1212
--ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
1313
-W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
14+
--directory [dir] Run process from a different directory (default: cwd)
1415
--no-gitignore Don't use .gitignore
1516
--include Report only provided issue type(s), can be comma-separated or repeated (1)
1617
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
@@ -52,6 +53,7 @@ try {
5253
debug: { type: 'boolean', short: 'd' },
5354
'debug-file-filter': { type: 'string' },
5455
dependencies: { type: 'boolean' },
56+
directory: { type: 'string' },
5557
exclude: { type: 'string', multiple: true },
5658
exports: { type: 'boolean' },
5759
help: { type: 'boolean', short: 'h' },

‎src/util/path.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// eslint-disable-next-line n/no-restricted-import
22
import path from 'node:path';
3+
import parsedArgValues from './cli-arguments.js';
4+
5+
const { directory } = parsedArgValues;
36

47
const isAbsolute = path.isAbsolute;
58

@@ -11,7 +14,7 @@ export const join = path.posix.join;
1114

1215
export const toPosix = (value: string) => value.split(path.sep).join(path.posix.sep);
1316

14-
export const cwd = toPosix(process.cwd());
17+
export const cwd = directory ? path.posix.resolve(directory) : toPosix(process.cwd());
1518

1619
export const resolve = (...paths: string[]) =>
1720
paths.length === 1 ? path.posix.join(cwd, paths[0]) : path.posix.resolve(...paths);

0 commit comments

Comments
 (0)
Please sign in to comment.