Skip to content

Commit 0a4b859

Browse files
committed
Use nodejs 22
1 parent d5e8998 commit 0a4b859

File tree

6 files changed

+60
-17
lines changed

6 files changed

+60
-17
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ jobs:
1818
- name: Setup Node.js
1919
uses: actions/setup-node@v3
2020
with:
21-
node-version: 20
21+
node-version: 22
2222

2323
- name: Install pnpm
2424
uses: pnpm/action-setup@v3
2525
with:
26-
version: 8
26+
version: 9
2727
run_install: false
2828

2929
- name: Get pnpm store directory

.github/workflows/docker-push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
context: .
3838
platforms: linux/amd64,linux/arm64
3939
push: true
40-
tags: ghcr.io/esm-dev/esm.sh:latest,ghcr.io/esm-dev/esm.sh:v135_1
40+
tags: ghcr.io/esm-dev/esm.sh:latest,ghcr.io/esm-dev/esm.sh:v136

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Build Stage
22
FROM golang:1.22-alpine AS build-stage
33

4-
ENV ESM_SH_VERSION v135_1
4+
ENV ESM_SH_VERSION v136
55
ENV ESM_SH_GIT_URL https://github.com/esm-dev/esm.sh
66

77
RUN apk update && apk add --no-cache git
@@ -11,7 +11,7 @@ WORKDIR /tmp/esm.sh
1111
RUN CGO_ENABLED=0 GOOS=linux go build -o esmd main.go
1212

1313
# Release Stage
14-
FROM node:20-alpine AS release-stage
14+
FROM node:22-alpine AS release-stage
1515

1616
RUN apk update && apk add --no-cache git libcap-utils
1717
RUN npm i -g pnpm

server/consts.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ var nativeNodePackages = []string{
7979
"zlib-sync",
8080
}
8181

82+
// unsupported node modules for `denonext` target
83+
var denoNextUnspportedNodeModules = map[string]bool{
84+
"inspector": true,
85+
}
86+
8287
// force to use `npm:` specifier for `denonext` target to fix `createRequire` issue
8388
var forceNpmSpecifiers = map[string]bool{
8489
"css-tree": true,

server/nodejs.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import (
1616
)
1717

1818
const (
19-
nodejsMinVersion = 20
20-
nodejsLatestLTS = "20.11.1"
21-
nodeTypesVersion = "20.11.20"
19+
nodejsMinVersion = 22
20+
nodeTypesVersion = "20.12.8"
2221
denoStdVersion = "0.177.1"
2322
)
2423

@@ -76,27 +75,28 @@ var nodejsInternalModules = map[string]bool{
7675
"zlib": true,
7776
}
7877

79-
var denoNextUnspportedNodeModules = map[string]bool{
80-
"inspector": true,
81-
}
82-
8378
func checkNodejs(installDir string) (nodeVersion string, pnpmVersion string, err error) {
8479
nodeVersion, major, err := getNodejsVersion()
85-
usingSystemNodejs := err == nil && major >= nodejsMinVersion
80+
useSystemNodejs := err == nil && major >= nodejsMinVersion
8681

87-
if !usingSystemNodejs {
82+
if !useSystemNodejs {
8883
PATH := os.Getenv("PATH")
8984
nodeBinDir := path.Join(installDir, "bin")
9085
if !strings.Contains(PATH, nodeBinDir) {
9186
os.Setenv("PATH", fmt.Sprintf("%s%c%s", nodeBinDir, os.PathListSeparator, PATH))
9287
}
9388
nodeVersion, major, err = getNodejsVersion()
9489
if err != nil || major < nodejsMinVersion {
95-
err = installNodejs(installDir, nodejsLatestLTS)
90+
var latestVersion string
91+
latestVersion, err = getNodejsLatestVersion()
92+
if err != nil {
93+
return
94+
}
95+
err = installNodejs(installDir, latestVersion)
9696
if err != nil {
9797
return
9898
}
99-
log.Infof("nodejs %s installed", nodejsLatestLTS)
99+
log.Infof("nodejs %s installed", latestVersion)
100100
}
101101
nodeVersion, major, err = getNodejsVersion()
102102
}
@@ -134,6 +134,27 @@ func getNodejsVersion() (version string, major int, err error) {
134134
return
135135
}
136136

137+
func getNodejsLatestVersion() (verison string, err error) {
138+
var res *http.Response
139+
res, err = http.Get(fmt.Sprintf("https://nodejs.org/download/release/latest-v%d.x/", nodejsMinVersion))
140+
if err != nil {
141+
return
142+
}
143+
defer res.Body.Close()
144+
var body []byte
145+
body, err = io.ReadAll(res.Body)
146+
if err != nil {
147+
return
148+
}
149+
i := strings.Index(string(body), fmt.Sprintf("node-v%d.", nodejsMinVersion))
150+
if i < 0 {
151+
err = fmt.Errorf("no nodejs version found")
152+
return
153+
}
154+
verison, _ = utils.SplitByFirstByte(string(body[i+5:]), '-')
155+
return
156+
}
157+
137158
func installNodejs(installDir string, version string) (err error) {
138159
arch := runtime.GOARCH
139160
switch arch {
@@ -142,7 +163,7 @@ func installNodejs(installDir string, version string) (err error) {
142163
case "386":
143164
arch = "x86"
144165
}
145-
dlURL := fmt.Sprintf("https://nodejs.org/dist/v%s/node-v%s-%s-%s.tar.xz", version, version, runtime.GOOS, arch)
166+
dlURL := fmt.Sprintf("https://nodejs.org/dist/%s/node-%s-%s-%s.tar.xz", version, version, runtime.GOOS, arch)
146167
resp, err := http.Get(dlURL)
147168
if err != nil {
148169
err = fmt.Errorf("download nodejs: %v", err)

server/nodejs_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package server
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"testing"
7+
)
8+
9+
func TestGetNodejsLatestVersion(t *testing.T) {
10+
version, err := getNodejsLatestVersion()
11+
if err != nil {
12+
t.Fatal(err)
13+
}
14+
if !strings.HasPrefix(version, fmt.Sprintf("v%d.", nodejsMinVersion)) {
15+
t.Fatalf("bad version %s", version)
16+
}
17+
}

0 commit comments

Comments
 (0)