Skip to content

Commit 31355f8

Browse files
authored
Merge pull request #109 from creyD/dev
2 parents dc62bca + 6fe86ce commit 31355f8

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ A GitHub action for styling files with [prettier](https://prettier.io).
2626
| commit_description | :x: | - | Custom git extended commit message, will be ignored if used with `same_commit` |
2727
| file_pattern | :x: | `*` | Custom git add file pattern, can't be used with only_changed! |
2828
| prettier_plugins | :x: | - | Install Prettier plugins, i.e. `"@prettier/plugin-php" "@prettier/plugin-other"`. Must be wrapped in quotes since @ is a reserved character in YAML. |
29+
| clean_node_folder | :x: | `true` | Delete the node_modules folder before committing |
2930
| only_changed | :x: | `false` | Only prettify changed files, can't be used with file_pattern! This command works only with the checkout action set to fetch depth '0' (see example 2)|
3031
| github_token | :x: | `${{ github.token }}` | The default [GITHUB_TOKEN](https://docs.github.com/en/actions/reference/authentication-in-a-workflow#about-the-github_token-secret) or a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token)
3132

@@ -160,3 +161,12 @@ More documentation for writing a workflow can be found [here](https://help.githu
160161
## Issues
161162
162163
Please report all bugs and feature request using the [GitHub issues function](https://github.com/creyD/prettier_action/issues/new). Thanks!
164+
165+
### Problem with NPM v9 (19.02.2023)
166+
167+
This issue was discussed in https://github.com/creyD/prettier_action/issues/113. The action until release 4.2 uses the npm bin command, which apparently doesn't work on npm v9. A fix is introduced with v4.3 of this action. If you need an older version of the action working it works until v3.3 and between v3.3 and v4.2 you could use the workaround described in https://github.com/creyD/prettier_action/issues/113 by adding the below to your workflow file:
168+
169+
```
170+
- name: Install npm v8
171+
run: npm i -g npm@8
172+
```

action.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,18 @@ inputs:
5454
description: GitHub Token or PAT token used to authenticate against a repository
5555
required: false
5656
default: ${{ github.token }}
57+
clean_node_folder:
58+
description: Remove the node_modules folder before committing changes
59+
required: false
60+
default: true
5761

5862
runs:
5963
using: "composite"
6064
steps:
6165
- name: Prettify code!
6266
shell: bash
6367
run: >-
64-
PATH=$(cd $GITHUB_ACTION_PATH; npm bin):$PATH
68+
PATH=$GITHUB_ACTION_PATH/node_modules/.bin:$PATH
6569
${{ github.action_path }}/entrypoint.sh
6670
env:
6771
INPUT_COMMIT_MESSAGE: ${{ inputs.commit_message }}
@@ -76,6 +80,7 @@ runs:
7680
INPUT_PRETTIER_PLUGINS: ${{ inputs.prettier_plugins }}
7781
INPUT_WORKING_DIRECTORY: ${{ inputs.working_directory }}
7882
INPUT_GITHUB_TOKEN: ${{ inputs.github_token }}
83+
INPUT_CLEAN_NODE_FOLDER: ${{ inputs.clean_node_folder }}
7984

8085
branding:
8186
icon: "award"

entrypoint.sh

+10-5
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,16 @@ echo "Files:"
7474
prettier $INPUT_PRETTIER_OPTIONS \
7575
|| { PRETTIER_RESULT=$?; echo "Problem running prettier with $INPUT_PRETTIER_OPTIONS"; exit 1; }
7676

77-
# Ignore node modules and other action created files
78-
if [ -d 'node_modules' ]; then
79-
rm -r node_modules/
80-
else
81-
echo "No node_modules/ folder."
77+
echo "Prettier result: $PRETTIER_RESULT"
78+
79+
# Removing the node_modules folder, so it doesn't get committed if it is not added in gitignore
80+
if $INPUT_CLEAN_NODE_FOLDER; then
81+
echo "Deleting node_modules/ folder..."
82+
if [ -d 'node_modules' ]; then
83+
rm -r node_modules/
84+
else
85+
echo "No node_modules/ folder."
86+
fi
8287
fi
8388

8489
if [ -f 'package-lock.json' ]; then

0 commit comments

Comments
 (0)