diff --git a/features/src/node/NOTES.md b/features/src/node/NOTES.md index 8aa95f8..5467239 100644 --- a/features/src/node/NOTES.md +++ b/features/src/node/NOTES.md @@ -11,3 +11,32 @@ Some binaries could be taken from https://unofficial-builds.nodejs.org but ARM b Needs access to the following URL for downloading and resolving: * https://nodejs.org + +### Corepack + +:warning: Internet access is necessary for corepack to install your preferred package manager. + +If you prefere to use internal sources, additional configuration is required. Add this to your `devcontainer.json`. + +```json + { + "postCreateCommand": "no_proxy=.mycompany.com corepack install", + "containerEnv": { + "COREPACK_NPM_REGISTRY": "https://artifactory.mycompany.com/artifactory/api/npm/npm" + } + } +``` + +Notice the `no_proxy=.mycompany.com`; it is necessary because the package used by corepack does not follow the common rules for the `no_proxy` variable. See [Rob--W/proxy-from-env/issues#29](https://github.com/Rob--W/proxy-from-env/issues/29). + +For **pnpm** to work with Artifactory, you have to additionally add this to the variables of your Dev Container: + +```json + { + "containerEnv": { + "COREPACK_INTEGRITY_KEYS": "0" + } + } +``` + +The reason for this are missing singatures in the Artifactory NPM API. See [nodejs/corepack#725](https://github.com/nodejs/corepack/issues/725) diff --git a/features/src/node/README.md b/features/src/node/README.md index eaec70e..4aa0142 100755 --- a/features/src/node/README.md +++ b/features/src/node/README.md @@ -6,11 +6,12 @@ A package which installs Node.js. ```json "features": { - "ghcr.io/postfinance/devcontainer-features/node:0.2.0": { + "ghcr.io/postfinance/devcontainer-features/node:0.3.0": { "version": "lts", "npmVersion": "included", "yarnVersion": "none", "pnpmVersion": "none", + "corepackVersion": "none", "downloadUrl": "", "versionsUrl": "", "globalNpmRegistry": "" @@ -26,6 +27,7 @@ A package which installs Node.js. | npmVersion | The version of NPM to install. | string | included | included, latest, 10.5.0, 9.9.3 | | yarnVersion | The version of Yarn to install. | string | none | none, latest, 1.22.22, 1.21.1 | | pnpmVersion | The version of Pnpm to install. | string | none | none, latest, 9.14.2, 9 | +| corepackVersion | The version of corepack to install. | string | none | none, latest, 0.34.0, 0.29 | | downloadUrl | The download URL to use for Node.js binaries. | string | <empty> | https://mycompany.com/artifactory/nodejs-generic-remote/dist | | versionsUrl | The URL to fetch the available Node.js versions from. | string | <empty> | | | globalNpmRegistry | The global NPM registry to use. | string | <empty> | https://mycompany.com/artifactory/api/npm/npm/ | @@ -43,3 +45,32 @@ Some binaries could be taken from https://unofficial-builds.nodejs.org but ARM b Needs access to the following URL for downloading and resolving: * https://nodejs.org + +### Corepack + +:warning: Internet access is necessary for corepack to install your preferred package manager. + +If you prefere to use internal sources, additional configuration is required. Add this to your `devcontainer.json`. + +```json + { + "postCreateCommand": "no_proxy=.mycompany.com corepack install", + "containerEnv": { + "COREPACK_NPM_REGISTRY": "https://artifactory.mycompany.com/artifactory/api/npm/npm" + } + } +``` + +Notice the `no_proxy=.mycompany.com`; it is necessary because the package used by corepack does not follow the common rules for the `no_proxy` variable. See [Rob--W/proxy-from-env/issues#29](https://github.com/Rob--W/proxy-from-env/issues/29). + +For **pnpm** to work with Artifactory, you have to additionally add this to the variables of your Dev Container: + +```json + { + "containerEnv": { + "COREPACK_INTEGRITY_KEYS": "0" + } + } +``` + +The reason for this are missing singatures in the Artifactory NPM API. See [nodejs/corepack#725](https://github.com/nodejs/corepack/issues/725) diff --git a/features/src/node/devcontainer-feature.json b/features/src/node/devcontainer-feature.json index f71c798..383706a 100644 --- a/features/src/node/devcontainer-feature.json +++ b/features/src/node/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "node", - "version": "0.2.0", + "version": "0.3.0", "name": "Node.js", "description": "A package which installs Node.js.", "options": { @@ -48,6 +48,17 @@ "default": "none", "description": "The version of Pnpm to install." }, + "corepackVersion": { + "type": "string", + "proposals": [ + "none", + "latest", + "0.34.0", + "0.29" + ], + "default": "none", + "description": "The version of corepack to install." + }, "downloadUrl": { "type": "string", "default": "", diff --git a/features/src/node/install.sh b/features/src/node/install.sh index f6031c0..fe29cd8 100755 --- a/features/src/node/install.sh +++ b/features/src/node/install.sh @@ -5,6 +5,7 @@ -npmVersion="${NPMVERSION:-"included"}" \ -yarnVersion="${YARNVERSION:-"none"}" \ -pnpmVersion="${PNPMVERSION:-"none"}" \ + -corepackVersion="${COREPACKVERSION:-"none"}" \ -downloadUrl="${DOWNLOADURL:-""}" \ -versionsUrl="${VERSIONSURL:-""}" \ -globalNpmRegistry="${GLOBALNPMREGISTRY:-""}" diff --git a/features/src/node/installer.go b/features/src/node/installer.go index 95e020f..b7acea2 100644 --- a/features/src/node/installer.go +++ b/features/src/node/installer.go @@ -37,6 +37,7 @@ func runMain() error { npmVersion := flag.String("npmVersion", "included", "") yarnVersion := flag.String("yarnVersion", "none", "") pnpmVersion := flag.String("pnpmVersion", "none", "") + corepackVersion := flag.String("corepackVersion", "none", "") downloadUrl := flag.String("downloadUrl", "", "") versionsUrl := flag.String("versionsUrl", "", "") globalNpmRegistry := flag.String("globalNpmRegistry", "", "") @@ -70,6 +71,10 @@ func runMain() error { ComponentBase: installer.NewComponentBase("Pnpm", *pnpmVersion), PackageName: "pnpm", }, + &npmComponent{ + ComponentBase: installer.NewComponentBase("corepack", *corepackVersion), + PackageName: "corepack", + }, ) return feature.Process() } diff --git a/features/test/node/corepack.sh b/features/test/node/corepack.sh new file mode 100644 index 0000000..65da26f --- /dev/null +++ b/features/test/node/corepack.sh @@ -0,0 +1,11 @@ +#!/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 "$(node -v)" "v24.4.1" +check_version "$(corepack -v)" "0.34.0" + +corepack prepare yarn@4.9.2 +corepack prepare pnpm@10.14.0 diff --git a/features/test/node/scenarios.json b/features/test/node/scenarios.json index 36e2138..d5e9d0f 100644 --- a/features/test/node/scenarios.json +++ b/features/test/node/scenarios.json @@ -14,5 +14,19 @@ "pnpmVersion": "9.14.2" } } + }, + "corepack": { + "build": { + "dockerfile": "Dockerfile", + "options": [ + "--add-host=host.docker.internal:host-gateway" + ] + }, + "features": { + "./node": { + "version": "24.4.1", + "corepackVersion": "0.34.0" + } + } } } \ No newline at end of file