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 c6b0514
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
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 | |


7 changes: 6 additions & 1 deletion src/prettier/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "prettier",
"version": "1.0.0",
"version": "1.1.0",
"name": "Prettier (via npm)",
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/prettier",
"description": "Prettier is an opinionated code formatter.",
Expand All @@ -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!'

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

set -e

source dev-container-features-test-lib

check "npm list --parseable --depth 0 | grep prettier-plugin-ini" npm list --parseable --depth 0 | grep "prettier-plugin-ini"

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

0 comments on commit c6b0514

Please sign in to comment.