Skip to content

Commit 58badc2

Browse files
committed
feat: Added npm-packages
1 parent bd71d50 commit 58badc2

11 files changed

Lines changed: 150 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ jobs:
3333
"mingw",
3434
"nginx",
3535
"node",
36+
"npm-packages",
3637
"playwright-deps",
3738
"python",
3839
"sonar-scanner-cli",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Below is a list with included features, click on the link for more details.
3333
| [mingw](./features/src/mingw/README.md) | Installs MinGW. |
3434
| [nginx](./features/src/nginx/README.md) | Installs Nginx. |
3535
| [node](./features/src/node/README.md) | Installs Node.js. |
36+
| [npm-packages](./features/src/npm-packages/README.md) | Installs NPM packages globally. |
3637
| [playwright-deps](./features/src/playwright-deps/README.md) | Installs all dependencies required to run Playwright. |
3738
| [python](./features/src/python/README.md) | Installs Python. |
3839
| [sonar-scanner-cli](./features/src/sonar-scanner-cli/README.md) | Installs the SonarScanner CLI. |

build/build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ func init() {
170170
gotaskr.Task("Feature:node:Test", func() error { return testFeature("node") })
171171
gotaskr.Task("Feature:node:Publish", func() error { return publishFeature("node") })
172172

173+
////////// npm-packages
174+
gotaskr.Task("Feature:npm-packages:Package", func() error { return packageFeature("npm-packages") })
175+
gotaskr.Task("Feature:npm-packages:Test", func() error { return testFeature("npm-packages") })
176+
gotaskr.Task("Feature:npm-packages:Publish", func() error { return publishFeature("npm-packages") })
177+
173178
////////// playwright-deps
174179
gotaskr.Task("Feature:playwright-deps:Package", func() error { return packageFeature("playwright-deps") })
175180
gotaskr.Task("Feature:playwright-deps:Test", func() error { return testFeature("playwright-deps") })
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# NPM Packages (npm-packages)
2+
3+
Installs NPM packages globally.
4+
5+
## Example Usage
6+
7+
```json
8+
"features": {
9+
"ghcr.io/postfinance/devcontainer-features/npm-packages:0.1.0": {
10+
"packages": ""
11+
}
12+
}
13+
```
14+
15+
## Options
16+
17+
| Option | Description | Type | Default Value | Proposals |
18+
|-----|-----|-----|-----|-----|
19+
| packages | Comma-separated list of packages to install | string | <empty> | @devcontainers/cli,which@3.0.1 |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"id": "npm-packages",
3+
"version": "0.1.0",
4+
"name": "NPM Packages",
5+
"description": "Installs NPM packages globally.",
6+
"options": {
7+
"packages": {
8+
"type": "string",
9+
"proposals": [
10+
"@devcontainers/cli,which@3.0.1"
11+
],
12+
"default": "",
13+
"description": "Comma-separated list of packages to install"
14+
}
15+
},
16+
"installsAfter": [
17+
"ghcr.io/postfinance/devcontainer-features/node",
18+
"ghcr.io/devcontainers/features/node"
19+
]
20+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
. ./functions.sh
2+
3+
"./installer_$(detect_arch)" \
4+
-packages="${PACKAGES:-""}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main
2+
3+
import (
4+
"builder/installer"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"os/exec"
9+
"strings"
10+
)
11+
12+
//////////
13+
// Main
14+
//////////
15+
16+
func main() {
17+
if err := runMain(); err != nil {
18+
fmt.Printf("Error: %v\n", err)
19+
os.Exit(1)
20+
}
21+
}
22+
23+
func runMain() error {
24+
// Handle the flags
25+
packages := flag.String("packages", "", "")
26+
flag.Parse()
27+
28+
if _, err := exec.LookPath("npm"); err != nil {
29+
return fmt.Errorf("could not find npm, make sure to install it first.")
30+
}
31+
32+
packagesList := strings.Split(*packages, ",")
33+
var pkgs []string
34+
for _, p := range packagesList {
35+
trimmed := strings.TrimSpace(p)
36+
if trimmed != "" {
37+
pkgs = append(pkgs, trimmed)
38+
}
39+
}
40+
if len(pkgs) == 0 {
41+
fmt.Println("No packages specified for installation.")
42+
return nil
43+
}
44+
for _, pkg := range pkgs {
45+
fmt.Printf("Installing '%s'\n", pkg)
46+
if err := installer.Tools.Npm.InstallGlobalPackage(pkg); err != nil {
47+
return err
48+
}
49+
}
50+
return nil
51+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
set -e
3+
4+
[[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh"
5+
[[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh"
6+
7+
check_version "$(npm list -g @devcontainers/cli 2>&1)" "@devcontainers/cli"
8+
check_version "$(npm list -g which@3.0.1 2>&1)" "which@3.0.1"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"install": {
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"options": [
6+
"--add-host=host.docker.internal:host-gateway"
7+
]
8+
},
9+
"features": {
10+
"ghcr.io/postfinance/devcontainer-features/node": {
11+
"version": "24.4.1"
12+
},
13+
"./npm-packages": {
14+
"packages": "@devcontainers/cli,which@3.0.1"
15+
}
16+
}
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
"mcr.microsoft.com/devcontainers/base:debian-11",
3+
"mcr.microsoft.com/devcontainers/base:debian-12",
4+
"mcr.microsoft.com/devcontainers/base:ubuntu-24.04"
5+
]

0 commit comments

Comments
 (0)