-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Added npm-packages #33
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ jobs: | |
| "mingw", | ||
| "nginx", | ||
| "node", | ||
| "npm-packages", | ||
| "playwright-deps", | ||
| "python", | ||
| "sonar-scanner-cli", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # NPM Packages (npm-packages) | ||
|
|
||
| Installs NPM packages globally. | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ```json | ||
| "features": { | ||
| "ghcr.io/postfinance/devcontainer-features/npm-packages:0.1.0": { | ||
| "packages": "" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | Type | Default Value | Proposals | | ||
| |-----|-----|-----|-----|-----| | ||
| | packages | Comma-separated list of packages to install | string | <empty> | @devcontainers/cli,which@3.0.1 | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "id": "npm-packages", | ||
| "version": "0.1.0", | ||
| "name": "NPM Packages", | ||
| "description": "Installs NPM packages globally.", | ||
| "options": { | ||
| "packages": { | ||
| "type": "string", | ||
| "proposals": [ | ||
| "@devcontainers/cli,which@3.0.1" | ||
| ], | ||
| "default": "", | ||
| "description": "Comma-separated list of packages to install" | ||
| } | ||
| }, | ||
| "installsAfter": [ | ||
| "ghcr.io/postfinance/devcontainer-features/node", | ||
| "ghcr.io/devcontainers/features/node" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| . ./functions.sh | ||
|
|
||
| "./installer_$(detect_arch)" \ | ||
| -packages="${PACKAGES:-""}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "builder/installer" | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| ) | ||
|
|
||
| ////////// | ||
| // Main | ||
| ////////// | ||
|
|
||
| func main() { | ||
| if err := runMain(); err != nil { | ||
| fmt.Printf("Error: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func runMain() error { | ||
| // Handle the flags | ||
| packages := flag.String("packages", "", "") | ||
| flag.Parse() | ||
|
|
||
| if _, err := exec.LookPath("npm"); err != nil { | ||
| return fmt.Errorf("could not find npm, make sure to install it first.") | ||
| } | ||
|
|
||
| packagesList := strings.Split(*packages, ",") | ||
| var pkgs []string | ||
| for _, p := range packagesList { | ||
| trimmed := strings.TrimSpace(p) | ||
| if trimmed != "" { | ||
| pkgs = append(pkgs, trimmed) | ||
| } | ||
| } | ||
| if len(pkgs) == 0 { | ||
| fmt.Println("No packages specified for installation.") | ||
| return nil | ||
| } | ||
| for _, pkg := range pkgs { | ||
| fmt.Printf("Installing '%s'\n", pkg) | ||
| if err := installer.Tools.Npm.InstallGlobalPackage(pkg); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,8 @@ | ||||||
| #!/bin/bash | ||||||
| set -e | ||||||
|
|
||||||
| [[ -f "$(dirname "$0")/../functions.sh" ]] && source "$(dirname "$0")/../functions.sh" | ||||||
| [[ -f "$(dirname "$0")/functions.sh" ]] && source "$(dirname "$0")/functions.sh" | ||||||
|
|
||||||
| check_version "$(npm list -g @devcontainers/cli 2>&1)" "@devcontainers/cli" | ||||||
| check_version "$(npm list -g which@3.0.1 2>&1)" "which@3.0.1" | ||||||
|
||||||
| check_version "$(npm list -g which@3.0.1 2>&1)" "which@3.0.1" | |
| check_version "$(npm list -g which 2>&1)" "which" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "install": { | ||
| "build": { | ||
| "dockerfile": "Dockerfile", | ||
| "options": [ | ||
| "--add-host=host.docker.internal:host-gateway" | ||
| ] | ||
| }, | ||
| "features": { | ||
| "ghcr.io/postfinance/devcontainer-features/node": { | ||
| "version": "24.4.1" | ||
| }, | ||
| "./npm-packages": { | ||
| "packages": "@devcontainers/cli,which@3.0.1" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [ | ||
| "mcr.microsoft.com/devcontainers/base:debian-11", | ||
| "mcr.microsoft.com/devcontainers/base:debian-12", | ||
| "mcr.microsoft.com/devcontainers/base:ubuntu-24.04" | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example usage shows an empty string for the packages option, which would result in no packages being installed. Consider using a more meaningful example, such as the one from the proposals field: "@devcontainers/cli,which@3.0.1". This would better demonstrate the feature's functionality to users.