Skip to content

Commit c9293d9

Browse files
authored
Merge pull request #2 from postfinance/feature/node-corepack
feat: add corepack option to node feature
2 parents 6d5881d + 4bb1915 commit c9293d9

File tree

7 files changed

+104
-2
lines changed

7 files changed

+104
-2
lines changed

features/src/node/NOTES.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,32 @@ Some binaries could be taken from https://unofficial-builds.nodejs.org but ARM b
1111

1212
Needs access to the following URL for downloading and resolving:
1313
* https://nodejs.org
14+
15+
### Corepack
16+
17+
:warning: Internet access is necessary for corepack to install your preferred package manager.
18+
19+
If you prefere to use internal sources, additional configuration is required. Add this to your `devcontainer.json`.
20+
21+
```json
22+
{
23+
"postCreateCommand": "no_proxy=.mycompany.com corepack install",
24+
"containerEnv": {
25+
"COREPACK_NPM_REGISTRY": "https://artifactory.mycompany.com/artifactory/api/npm/npm"
26+
}
27+
}
28+
```
29+
30+
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).
31+
32+
For **pnpm** to work with Artifactory, you have to additionally add this to the variables of your Dev Container:
33+
34+
```json
35+
{
36+
"containerEnv": {
37+
"COREPACK_INTEGRITY_KEYS": "0"
38+
}
39+
}
40+
```
41+
42+
The reason for this are missing singatures in the Artifactory NPM API. See [nodejs/corepack#725](https://github.com/nodejs/corepack/issues/725)

features/src/node/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ A package which installs Node.js.
66

77
```json
88
"features": {
9-
"ghcr.io/postfinance/devcontainer-features/node:0.2.0": {
9+
"ghcr.io/postfinance/devcontainer-features/node:0.3.0": {
1010
"version": "lts",
1111
"npmVersion": "included",
1212
"yarnVersion": "none",
1313
"pnpmVersion": "none",
14+
"corepackVersion": "none",
1415
"downloadUrl": "",
1516
"versionsUrl": "",
1617
"globalNpmRegistry": ""
@@ -26,6 +27,7 @@ A package which installs Node.js.
2627
| npmVersion | The version of NPM to install. | string | included | included, latest, 10.5.0, 9.9.3 |
2728
| yarnVersion | The version of Yarn to install. | string | none | none, latest, 1.22.22, 1.21.1 |
2829
| pnpmVersion | The version of Pnpm to install. | string | none | none, latest, 9.14.2, 9 |
30+
| corepackVersion | The version of corepack to install. | string | none | none, latest, 0.34.0, 0.29 |
2931
| downloadUrl | The download URL to use for Node.js binaries. | string | <empty> | https://mycompany.com/artifactory/nodejs-generic-remote/dist |
3032
| versionsUrl | The URL to fetch the available Node.js versions from. | string | <empty> | |
3133
| 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
4345

4446
Needs access to the following URL for downloading and resolving:
4547
* https://nodejs.org
48+
49+
### Corepack
50+
51+
:warning: Internet access is necessary for corepack to install your preferred package manager.
52+
53+
If you prefere to use internal sources, additional configuration is required. Add this to your `devcontainer.json`.
54+
55+
```json
56+
{
57+
"postCreateCommand": "no_proxy=.mycompany.com corepack install",
58+
"containerEnv": {
59+
"COREPACK_NPM_REGISTRY": "https://artifactory.mycompany.com/artifactory/api/npm/npm"
60+
}
61+
}
62+
```
63+
64+
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).
65+
66+
For **pnpm** to work with Artifactory, you have to additionally add this to the variables of your Dev Container:
67+
68+
```json
69+
{
70+
"containerEnv": {
71+
"COREPACK_INTEGRITY_KEYS": "0"
72+
}
73+
}
74+
```
75+
76+
The reason for this are missing singatures in the Artifactory NPM API. See [nodejs/corepack#725](https://github.com/nodejs/corepack/issues/725)

features/src/node/devcontainer-feature.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "node",
3-
"version": "0.2.0",
3+
"version": "0.3.0",
44
"name": "Node.js",
55
"description": "A package which installs Node.js.",
66
"options": {
@@ -48,6 +48,17 @@
4848
"default": "none",
4949
"description": "The version of Pnpm to install."
5050
},
51+
"corepackVersion": {
52+
"type": "string",
53+
"proposals": [
54+
"none",
55+
"latest",
56+
"0.34.0",
57+
"0.29"
58+
],
59+
"default": "none",
60+
"description": "The version of corepack to install."
61+
},
5162
"downloadUrl": {
5263
"type": "string",
5364
"default": "",

features/src/node/install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
-npmVersion="${NPMVERSION:-"included"}" \
66
-yarnVersion="${YARNVERSION:-"none"}" \
77
-pnpmVersion="${PNPMVERSION:-"none"}" \
8+
-corepackVersion="${COREPACKVERSION:-"none"}" \
89
-downloadUrl="${DOWNLOADURL:-""}" \
910
-versionsUrl="${VERSIONSURL:-""}" \
1011
-globalNpmRegistry="${GLOBALNPMREGISTRY:-""}"

features/src/node/installer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func runMain() error {
3737
npmVersion := flag.String("npmVersion", "included", "")
3838
yarnVersion := flag.String("yarnVersion", "none", "")
3939
pnpmVersion := flag.String("pnpmVersion", "none", "")
40+
corepackVersion := flag.String("corepackVersion", "none", "")
4041
downloadUrl := flag.String("downloadUrl", "", "")
4142
versionsUrl := flag.String("versionsUrl", "", "")
4243
globalNpmRegistry := flag.String("globalNpmRegistry", "", "")
@@ -70,6 +71,10 @@ func runMain() error {
7071
ComponentBase: installer.NewComponentBase("Pnpm", *pnpmVersion),
7172
PackageName: "pnpm",
7273
},
74+
&npmComponent{
75+
ComponentBase: installer.NewComponentBase("corepack", *corepackVersion),
76+
PackageName: "corepack",
77+
},
7378
)
7479
return feature.Process()
7580
}

features/test/node/corepack.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "$(node -v)" "v24.4.1"
8+
check_version "$(corepack -v)" "0.34.0"
9+
10+
corepack prepare yarn@4.9.2
11+
corepack prepare pnpm@10.14.0

features/test/node/scenarios.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,19 @@
1414
"pnpmVersion": "9.14.2"
1515
}
1616
}
17+
},
18+
"corepack": {
19+
"build": {
20+
"dockerfile": "Dockerfile",
21+
"options": [
22+
"--add-host=host.docker.internal:host-gateway"
23+
]
24+
},
25+
"features": {
26+
"./node": {
27+
"version": "24.4.1",
28+
"corepackVersion": "0.34.0"
29+
}
30+
}
1731
}
1832
}

0 commit comments

Comments
 (0)