Skip to content

Commit f7b0bf2

Browse files
committed
Add pnpm support
1 parent bf2b9bf commit f7b0bf2

File tree

7 files changed

+60
-15
lines changed

7 files changed

+60
-15
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,22 @@ steps:
124124
all-files: ${{ steps.filter.outputs.eslintrc == 'true' }}
125125
```
126126

127+
### Package Manager Support
128+
129+
The action supports different package managers. You can specify which package manager to use with the `package-manager` input:
130+
131+
```yml
132+
steps:
133+
- uses: sibiraj-s/action-eslint@v3
134+
with:
135+
package-manager: 'npm' # or 'pnpm'
136+
```
137+
138+
Supported package managers:
139+
140+
- `npm` - Uses `npx eslint`
141+
- `pnpm` - Uses `pnpm exec eslint`
142+
127143
## Security
128144

129145
For better security it is recommended to pin actions to a full length commit SHA.
@@ -132,7 +148,7 @@ Read more on [using third-party actions](https://docs.github.com/en/actions/lear
132148

133149
## Known Issues
134150

135-
- Yarn 2+ is not supported
151+
- When using `package-manager: 'yarn'`, ensure you're using Yarn 1.x or Yarn 3+ with the modern `yarn exec` command. Yarn 2 (Berry) without proper exec setup may not work as expected.
136152

137153
## Debugging
138154

action.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ inputs:
2525
annotations:
2626
description: Enable or disable annotations
2727
required: false
28-
default: true
28+
default: 'true'
2929
working-directory:
30-
description: Path to project containing npm/yarn installation
30+
description: Path to project containing package manager installation
3131
required: false
3232
ignore-path:
3333
description: Path to ignore file.
@@ -38,8 +38,8 @@ inputs:
3838
all-files:
3939
description: Run eslint on all files.
4040
required: false
41-
default: false
42-
use-npx:
43-
description: Enable or disable using npx instead of node node_modules/.bin/eslint
41+
default: 'false'
42+
package-manager:
43+
description: Package manager to use (npm, pnpm). Defaults to npm if not specified
4444
required: false
45-
default: false
45+
default: npm

dist/main.js

Lines changed: 18 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/eslint.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import { disableAnnotations } from './annotations';
66
import getFiles from './get-files';
77
import getEslintArgs from './get-eslint-args';
88

9+
const getExecutionCommand = (): { command: string; args: string[] } => {
10+
const packageManager = inputs.packageManager.toLowerCase();
11+
12+
switch (packageManager) {
13+
case 'pnpm':
14+
return { command: 'pnpm', args: ['dlx', 'eslint'] };
15+
case 'npm':
16+
return { command: 'npx', args: ['eslint'] };
17+
default:
18+
throw new Error(`Unsupported package manager: ${packageManager}. Supported: npm, pnpm`);
19+
}
20+
};
21+
922
export const runEslint = async (): Promise<void> => {
1023
if (!inputs.annotations) {
1124
disableAnnotations();
@@ -19,13 +32,14 @@ export const runEslint = async (): Promise<void> => {
1932
}
2033

2134
const eslintArgs = getEslintArgs();
35+
const { command, args } = getExecutionCommand();
2236

2337
const execArgs = [
24-
inputs.useNpx ? 'eslint' : 'node_modules/.bin/eslint',
38+
...args,
2539
...files,
2640
...eslintArgs,
2741
].filter(Boolean);
2842
const execOptions = { cwd: inputs.workingDirectory };
2943

30-
await exec(inputs.useNpx ? 'npx' : 'node', execArgs, execOptions);
44+
await exec(command, execArgs, execOptions);
3145
};

src/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const inputs: Inputs = {
1111
ignorePath: getInput('ignore-path'),
1212
ignorePatterns: getMultilineInput('ignore-patterns'),
1313
allFiles: getBooleanInput('all-files'),
14-
useNpx: getBooleanInput('use-npx'),
14+
packageManager: getInput('package-manager'),
1515
};
1616

1717
export default inputs;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface Inputs {
77
ignorePath: string;
88
ignorePatterns: string[];
99
allFiles: boolean;
10-
useNpx: boolean;
10+
packageManager: string;
1111
}
1212

1313
export type FileNamesList = string[];

0 commit comments

Comments
 (0)