diff --git a/src/prettier/README.md b/src/prettier/README.md index ef31093f9..c9a2183cf 100644 --- a/src/prettier/README.md +++ b/src/prettier/README.md @@ -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 | | diff --git a/src/prettier/devcontainer-feature.json b/src/prettier/devcontainer-feature.json index 321bb266b..24a8fac29 100644 --- a/src/prettier/devcontainer-feature.json +++ b/src/prettier/devcontainer-feature.json @@ -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.", @@ -12,6 +12,11 @@ "latest" ], "type": "string" + }, + "plugins": { + "default": "", + "description": "Comma-separated list of prettier plugins to install.", + "type": "string" } }, "installsAfter": [ diff --git a/src/prettier/install.sh b/src/prettier/install.sh index 1b3b0a434..015b46402 100755 --- a/src/prettier/install.sh +++ b/src/prettier/install.sh @@ -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!' diff --git a/test/prettier/plugin.sh b/test/prettier/plugin.sh new file mode 100755 index 000000000..c274d91d4 --- /dev/null +++ b/test/prettier/plugin.sh @@ -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 diff --git a/test/prettier/scenarios.json b/test/prettier/scenarios.json index 3337bab98..29fec4cc6 100644 --- a/test/prettier/scenarios.json +++ b/test/prettier/scenarios.json @@ -4,5 +4,14 @@ "features": { "prettier": {} } + }, + "plugin": { + "image": "mcr.microsoft.com/devcontainers/base:debian", + "features": { + "prettier": { + "version": "latest", + "plugins": "prettier-plugin-ini" + } + } } } \ No newline at end of file