Skip to content

Commit

Permalink
Prepare v136 Release (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije authored Dec 30, 2024
1 parent 577f317 commit 989cc5b
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 78 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
deploy:
name: Deploy main branch to next.esm.sh
runs-on: ubuntu-latest
environment: next
environment: next.esm.sh

steps:
- name: Checkout
Expand All @@ -28,4 +28,5 @@ jobs:
DEPLOY_HOST_PORT: ${{ secrets.DEPLOY_HOST_PORT }}
DEPLOY_SSH_USER: ${{ secrets.DEPLOY_SSH_USER }}
DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
VERSION: ${{ github.sha }}
SERVER_VERSION: ${{ github.sha }}
RESET_ON_DEPLOY: yes
40 changes: 0 additions & 40 deletions .github/workflows/docker-push.yml

This file was deleted.

89 changes: 89 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Release

on:
push:
tags:
- v*

jobs:
deploy:
name: Deploy server to esm.sh nodes
runs-on: ubuntu-latest
environment: ${{ matrix.environment }}

strategy:
matrix:
environment: [d1.esm.sh]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.23.x

- name: Run Deploy Script
run: ./scripts/deploy-ci.sh
env:
GOOS: ${{ secrets.DEPLOY_HOST_OS }}
GOARCH: ${{ secrets.DEPLOY_HOST_ARCH }}
DEPLOY_HOST_NAME: ${{ secrets.DEPLOY_HOST_NAME }}
DEPLOY_HOST_PORT: ${{ secrets.DEPLOY_HOST_PORT }}
DEPLOY_SSH_USER: ${{ secrets.DEPLOY_SSH_USER }}
DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }}
SERVER_CONFIG: ${{ secrets.SERVER_CONFIG }}
SERVER_VERSION: ${{ github.ref_name }}

push_docker_image:
name: Push docker image to ghcr.io
runs-on: ubuntu-latest
permissions:
packages: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/esm-dev/esm.sh:latest,ghcr.io/esm-dev/esm.sh:${{ github.ref_name }}
build-args: |
SERVER_VERSION=${{ github.ref_name }}
publish:
name: Publish
runs-on: ubuntu-latest
needs: [deploy, push_docker_image]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Extract Release Note
run: echo "console.log(require('fs').readFileSync('CHANGELOG.md','utf8').split('## ')[1].slice('${{ github.ref_name }}'.length).trim())" | node > release-note.txt

- name: Publish Release
uses: softprops/action-gh-release@v2
with:
body_path: release-note.txt
124 changes: 121 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,127 @@
# Changelog

## Unreleased
## v136

* Add two builtin registries:
* [jsr](https://jsr.io) - The open-source package registry for modern JavaScript and TypeScript, created by the Deno team. ([32cd2bd](https://github.com/esm-dev/esm.sh/commit/32cd2bd931f33118cbc96ee89583f20718c58fbf))
```js
// example
import { encodeBase64 } from "https://esm.sh/jsr/@std/[email protected]/base64";
import { Hono } from "https://esm.sh/jsr/@hono/hono@4";
```
* [pkg.pr.new](https://pkg.pr.new) - Continuous (Preview) Releases for your libraries, created by [StackBlitz Labs](https://github.com/stackblitz-labs) ([#904](https://github.com/esm-dev/esm.sh/issues/904), [#913](https://github.com/esm-dev/esm.sh/issues/913))
```js
// Examples
import { Bench } from "https://esm.sh/pr/tinylibs/tinybench/tinybench@a832a55";
import { Bench } from "https://esm.sh/pr/tinybench@a832a55"; // --compact
```

* Respect sematic versioning for dependency resolving ([#875](https://github.com/esm-dev/esm.sh/issues/875))

Prior to v136, dependency resolution used fixed versions, which could lead to duplication issues when a package was updated. Now, we adhere to semantic versioning for dependencies.

```js
// before
"[email protected]" import "/[email protected]/es2022/react.mjs";
// after
"[email protected]" import "/react@^18.3.1?target=es2022";
```

* Add built-in npm package manager ([#948](https://github.com/esm-dev/esm.sh/issues/948))

Implement a built-in npm package manager in Go to replace pnpm. This change reduces the CI test time from 12:15 to 4:30 (**~2.7x faster**) and eliminates the need for `nodejs` and `pnpm` dependencies.

* Splitting modules by analyzing dependency tree when building ([#959](https://github.com/esm-dev/esm.sh/issues/959))

To improve build performance and reduce network requests, esm.sh bundles sub-modules of a package by default. However, this can lead to duplicate code in the build. In v136, the server will split the modules by analyzing the dependency tree during the build process if the package's `exports` field is defined.
* Use [@pi0](https://github.com/pi0)'s [unenv](https://github.com/unjs/unenv) as the node runtime compatibility layer ([#914](https://github.com/esm-dev/esm.sh/issues/914))

unenv provides a collection of Node.js and Web polyfills and mocking utilities with configurable presets for converting JavaScript code and libraries to be platform and runtime agnostic, working in any environment including Browsers, Workers, Node.js, Cloudflare Workers, Deno. unenv is also used by CloudFlare Workers: [blog](https://blog.cloudflare.com/more-npm-packages-on-cloudflare-workers-combining-polyfills-and-native-code/).

You can also access these `unenv` node runtime modules directly via `/node/[node-builtin-module-name].mjs` path, for example:

```js
import * from "https://esm.sh/node/fs.mjs";
```

* Add [npm-replacements](./server/npm_replacements/src/) that follows [e18e](https://e18e.dev)'s [module-replacements](https://github.com/es-tooling/module-replacements). ([#914](https://github.com/esm-dev/esm.sh/issues/914))

The `npm-replacements` package replaces certain polyfill packages on NPM with native modern APIs during the build process. For example, the `object-assign` package is replaced with `Object.assign`:

```js
import assign from "object-assign"; // replaced with "const assign = Object.assign"
```

* Remove the build version prefix of esm.sh in the module path

The build version prefix of esm.sh was introduced to avoid potential breaking changes caused by updates to the esm.sh server. However, it can lead to duplication issues when updating the server. In v136, we have removed the build version prefix from the module path, and the `?pin` query will be ignored. Paths with the build version prefix will continue to work as before, but the new default will be paths without the build version prefix.

```js
// before
"[email protected]" -> "https://esm.sh/v135/[email protected]/es2022/react.mjs";
// after
"[email protected]" -> "https://esm.sh/[email protected]/es2022/react.mjs";
```

* Deprecate the `build` API
```js
import { build } from "https://esm.sh/build";
build() // throws Error: The build API has been deprecated.
```

* Deprecate the Deno CLI script

Deno now includes its own built-in package manager, which can be used to manage `jsr:` nad `npm:` imports in your deno applications. So we decided to deprecate the Deno CLI script.

```bash
# use
deno add npm:pract jsr:@std/encoding
Add npm:[email protected]
Add jsr:@std/[email protected]
# do not use
deno run -A -r https://esm.sh init
error: The deno CLI has been deprecated.
```

* Add `npmScopedRegistries` config

The `npmScopedRegistries` configuration enables you to define the registry, token, user, and password for scoped npm packages. This allows you to import scoped packages using URLs like `https://your-esm-server.com/@scope_name/pkg@version`.

```json
{
"npmScopedRegistries": {
"@scope_name": {
"registry": "https://your-registry.com/",
"token": "xxxxxx",
"user": "",
"password": ""
}
}
}
```

* Experimental Features:
* Build `.vue` and `.svelte` files on the fly ([#906](https://github.com/esm-dev/esm.sh/issues/906))
```js
import "https://esm.sh/gh/phosphor-icons/[email protected]/src/icons/[email protected]"
```
* https://esm.sh/x - ts/jsx/vue/svelte just works™️ in browser. ([#886](https://github.com/esm-dev/esm.sh/issues/886))

* Other Changes:
* Upgrade esbuild to **0.24.2**
* Use native [cjs-module-lexer@v1.0.7](https://github.com/esm-dev/cjs-module-lexer/releases/tag/v1.0.7)
* Use target `es2022` for browsers by default ([#903](https://github.com/esm-dev/esm.sh/issues/903))
* Replace `window` with `globalThis` to make Deno 2 happy ([#964](https://github.com/esm-dev/esm.sh/issues/964))
* Use `.mjs` extenstion for sub-module build (#917)
* dts-transformer: support `.d` extension
* config: Add `corsAllowOrigins` config
* config: Add `customLandingPage` config (#928)
* config: Add `npmQueryCacheTTL` config (#921)
* config: Add npmQueryCacheTTL config (#921)
* config: Support **S3-compatible** storage (#886)

- Use semver versioning for depdency resolving
- Introduce `esm.sh/run` v2

## v135

Expand Down
38 changes: 18 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
# --- build the server from source code
# --- build server from source code
FROM golang:1.23-alpine AS builder

ENV ESM_SH_REPO https://github.com/esm-dev/esm.sh
ENV ESM_SH_VERSION main
ARG SERVER_VERSION="v136"

RUN apk update && apk add --no-cache git
RUN git clone --branch $ESM_SH_VERSION --depth 1 $ESM_SH_REPO /tmp/esm.sh
RUN git clone --branch $SERVER_VERSION --depth 1 https://github.com/esm-dev/esm.sh /tmp/esm.sh

WORKDIR /tmp/esm.sh
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o esmd main.go
RUN go build -ldflags="-s -w -X 'github.com/esm-dev/esm.sh/server.VERSION=${SERVER_VERSION}'" -o esmd main.go
# ---

FROM alpine:latest AS server
FROM alpine:latest

# install tini & git (use to fetch repo tags from Github)
RUN apk update && apk add --no-cache tini git
# install git (use to fetch repo tags from Github)
RUN apk update && apk add --no-cache git

# add user and working directory
RUN addgroup -g 1000 esm && adduser -u 1000 -G esm -D esm && mkdir /esmd && chown -R esm:esm /esmd

# copy esmd & deno build
COPY --from=builder /tmp/esm.sh/esmd /bin/esmd
COPY --from=denoland/deno:bin-2.1.4 --chown=esm:esm /deno /esmd/bin/deno

# deno desn't provider musl build yet, the hack below makes the gnu build working in alpine
# see https://github.com/denoland/deno_docker/blob/main/alpine.dockerfile
Expand All @@ -23,21 +29,13 @@ COPY --from=gcr.io/distroless/cc --chown=root:root --chmod=755 /lib/ld-linux-* /
RUN mkdir /lib64 && ln -s /usr/local/lib/ld-linux-* /lib64/
ENV LD_LIBRARY_PATH="/usr/local/lib"

# don't run as root
RUN addgroup -g 1000 esm && adduser -u 1000 -G esm -D esm
RUN mkdir /esmd && chown -R esm:esm /esmd

COPY --from=builder /tmp/esm.sh/esmd /bin/esmd
COPY --from=denoland/deno:bin-2.1.4 --chown=esm:esm /deno /esmd/bin/deno

# server configuration
ENV ESM_SERVER_PORT="8080"
ENV ESM_SERVER_WORKDIR="/esmd"

# use tini
# see https://github.com/krallin/tini
ENTRYPOINT ["/sbin/tini", "--"]

# switch to non-root user
USER esm
WORKDIR /esmd

EXPOSE 8080
WORKDIR /esmd
CMD ["esmd"]
2 changes: 1 addition & 1 deletion HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,6 @@ You can also create your own Dockerfile based on `ghcr.io/esm-dev/esm.sh`:

```dockerfile
FROM ghcr.io/esm-dev/esm.sh:latest
ADD ./config.json /etc/esmd/config.json
ADD --chown=esm:esm ./config.json /etc/esmd/config.json
CMD ["esmd", "--config", "/etc/esmd/config.json"]
```
Loading

0 comments on commit 989cc5b

Please sign in to comment.