Skip to content

Commit

Permalink
Add plugin support for Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-rojas committed Jul 18, 2023
1 parent 3f9164f commit 655218f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/prettier/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ Prettier is an opinionated code formatter.
| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| version | Select the version to install. | string | latest |
| plugins | Comma-separated list of prettier plugins to install. | string | |


5 changes: 5 additions & 0 deletions src/prettier/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"latest"
],
"type": "string"
},
"plugins": {
"default": "",
"description": "Comma-separated list of prettier plugins to install.",
"type": "string"
}
},
"installsAfter": [
Expand Down
18 changes: 18 additions & 0 deletions src/prettier/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ $nanolayer_location \
--option package='prettier' --option version="$VERSION"


PRETTIER_PLUGINS=${PLUGINS:-""}

# Prettier plugins are expected to be installed locally, not globally
# In particular, VSCode + extensions tend to have issues with this
if [ -n "${PRETTIER_PLUGINS}" ]; then
OIFS=$IFS
IFS=','

for plugin in $PRETTIER_PLUGINS; do
if ! npm list ${plugin} > /dev/null; then
npm install --save-dev prettier ${plugin}
fi
done

IFS=$OIFS
fi



echo 'Done!'

11 changes: 11 additions & 0 deletions test/prettier/plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -i

set -e

source dev-container-features-test-lib

check "prettier --version" prettier --version

check "npm list prettier-plugin-ini" npm list prettier-plugin-ini

reportResults
8 changes: 8 additions & 0 deletions test/prettier/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"features": {
"prettier": {}
}
},
"plugin": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"prettier": {
"plugins": "prettier-plugin-ini"
}
}
}
}

0 comments on commit 655218f

Please sign in to comment.