Skip to content

Commit

Permalink
add nx command shorthand support
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjjonathan committed Dec 29, 2024
1 parent 9590b92 commit a1ee0ed
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/knip/fixtures/plugins/nx/libs/b/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
},
"tsc": {
"executor": "./tools/executors/tsc:tsc"
},
"lint": {
"command": "biome lint ."
}
}
}
9 changes: 7 additions & 2 deletions packages/knip/src/plugins/nx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ const resolveConfig: ResolveConfig<NxProjectConfiguration | NxConfigRoot> = asyn
.map(executor => executor?.split(':')[0]);

const scripts = targets
.filter(target => target.executor === 'nx:run-commands')
.flatMap(target => target.options?.commands ?? (target.options?.command ? [target.options.command] : []));
.filter(target => target.executor === 'nx:run-commands' || target.command)
.flatMap(target => {
if (target.command) return [target.command];
if (target.options?.command) return [target.options.command];
if (target.options?.commands) return target.options.commands;
return [];
});

const inputs = options.getInputsFromScripts(scripts);

Expand Down
1 change: 1 addition & 0 deletions packages/knip/src/plugins/nx/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface NxProjectConfiguration {
targets?: {
[targetName: string]: {
command?: string;
executor?: string;
options?: {
command?: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/knip/test/plugins/nx.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ test('Find dependencies with the Nx plugin', async () => {
assert(issues.binaries['package.json']['nx']);
assert(issues.binaries['libs/b/project.json']['webpack']);
assert(issues.binaries['libs/b/project.json']['compodoc']);
assert(issues.binaries['libs/b/project.json']['biome']);

assert.deepEqual(counters, {
...baseCounters,
binaries: 4,
binaries: 5,
devDependencies: 6,
unlisted: 3,
processed: 0,
Expand Down

0 comments on commit a1ee0ed

Please sign in to comment.