Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugin support for Prettier #493

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 30 additions & 0 deletions src/prettier/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,36 @@ $nanolayer_location \
--option package='prettier' --option version="$VERSION"


PRETTIER_PLUGINS=${PLUGINS:-""}

setup_npm() {
export NVM_DIR=/usr/local/share/nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
}

install_prettier_plugin() {
echo "Installing prettier plugin - $1"
if ! npm list $1 >/dev/null; then
npm install --save-dev prettier $1
fi
}

# 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
if ! type npm >/dev/null 2>&1; then
setup_npm
fi

OIFS=$IFS
IFS=','
for plugin in $PRETTIER_PLUGINS; do
install_prettier_plugin $plugin
done
IFS=$OIFS
fi



echo 'Done!'

File renamed without changes.
20 changes: 19 additions & 1 deletion test/prettier/scenarios.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
{
"test": {
"latest": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"prettier": {}
}
},
"v3-plugin": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"prettier": {
"version": "3.0.0",
"plugins": "prettier-plugin-ini"
}
}
},
"v2-plugins": {
"image": "mcr.microsoft.com/devcontainers/base:debian",
"features": {
"prettier": {
"version": "2.8.8",
"plugins": "@prettier/[email protected],@prettier/[email protected],@prettier/[email protected]"
}
}
}
}
14 changes: 14 additions & 0 deletions test/prettier/v2-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

source dev-container-features-test-lib

check "prettier --version = 2.8.8" [ "$(prettier --version)" = "2.8.8" ]

for p in php ruby xml; do
plugin="@prettier/plugin-${p}"
check "npm list --parseable --depth 0 | grep ${plugin}" npm list --parseable --depth 0 | grep "${plugin}"
done

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

set -e

source dev-container-features-test-lib

check "prettier --version = 3.0.0" [ "$(prettier --version)" = "3.0.0" ]

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

reportResults