Skip to content
This repository was archived by the owner on Jan 12, 2025. It is now read-only.

Commit c6b0514

Browse files
committed
Add plugin support for Prettier
1 parent 3f9164f commit c6b0514

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/prettier/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ Prettier is an opinionated code formatter.
1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
1818
| version | Select the version to install. | string | latest |
19+
| plugins | Comma-separated list of prettier plugins to install. | string | |
1920

2021

src/prettier/devcontainer-feature.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "prettier",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"name": "Prettier (via npm)",
55
"documentationURL": "http://github.com/devcontainers-contrib/features/tree/main/src/prettier",
66
"description": "Prettier is an opinionated code formatter.",
@@ -12,6 +12,11 @@
1212
"latest"
1313
],
1414
"type": "string"
15+
},
16+
"plugins": {
17+
"default": "",
18+
"description": "Comma-separated list of prettier plugins to install.",
19+
"type": "string"
1520
}
1621
},
1722
"installsAfter": [

src/prettier/install.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ $nanolayer_location \
1919
--option package='prettier' --option version="$VERSION"
2020

2121

22+
PRETTIER_PLUGINS=${PLUGINS:-""}
23+
24+
# Prettier plugins are expected to be installed locally, not globally
25+
# In particular, VSCode + extensions tend to have issues with this
26+
if [ -n "${PRETTIER_PLUGINS}" ]; then
27+
OIFS=$IFS
28+
IFS=','
29+
30+
for plugin in $PRETTIER_PLUGINS; do
31+
if ! npm list ${plugin} > /dev/null; then
32+
npm install --save-dev prettier ${plugin}
33+
fi
34+
done
35+
36+
IFS=$OIFS
37+
fi
38+
39+
2240

2341
echo 'Done!'
2442

test/prettier/plugin.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
check "npm list --parseable --depth 0 | grep prettier-plugin-ini" npm list --parseable --depth 0 | grep "prettier-plugin-ini"
8+
9+
reportResults

test/prettier/scenarios.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@
44
"features": {
55
"prettier": {}
66
}
7+
},
8+
"plugin": {
9+
"image": "mcr.microsoft.com/devcontainers/base:debian",
10+
"features": {
11+
"prettier": {
12+
"version": "latest",
13+
"plugins": "prettier-plugin-ini"
14+
}
15+
}
716
}
817
}

0 commit comments

Comments
 (0)