Skip to content

Releases: esm-dev/esm.sh

v136

13 Jan 09:15
1ad31b6
Compare
Choose a tag to compare
  • Add two builtin registries:

    • jsr - The open-source package registry for modern JavaScript and TypeScript, created by the Deno team. (32cd2bd)
      // 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 - Continuous (Preview) Releases for your libraries, created by StackBlitz Labs (#904, #913)
      // Examples
      import { Bench } from "https://esm.sh/pr/tinylibs/tinybench/tinybench@a832a55";
      import { Bench } from "https://esm.sh/pr/tinybench@a832a55"; // --compact
  • BREAK CHANGE: Respect semantic versioning for dependency resolving (#875)

    Previously, dependency resolution used fixed versions, which could cause duplication issues when packages were updated. Starting from v136, we now follow semantic versioning for dependencies.

    // before
    "[email protected]" import "/[email protected]/es2022/react.mjs";
    // after
    "[email protected]" import "/react@^19.0.0?target=es2022";
  • BREAK CHANGE: Remove build version prefix from 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.

    // before
    "[email protected]" -> "https://esm.sh/v135/[email protected]/es2022/react.mjs";
    // after
    "[email protected]" -> "https://esm.sh/[email protected]/es2022/react.mjs";
  • Add built-in npm package manager (#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.

  • Split modules by analyzing the dependency tree during the build process (#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's unenv as the node runtime compatibility layer (#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.

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

    import * from "https://esm.sh/node/fs.mjs";
  • Add npm-replacements that follows e18e's module-replacements. (#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:

    import assign from "object-assign"; // replaced with "const assign = Object.assign"
  • Deprecate the build API

    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.

    # use
    deno add npm:preact 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.

    {
      "npmScopedRegistries": {
        "@scope_name": {
          "registry": "https://your-registry.com/",
          "token": "xxxxxx",
          "user": "",
          "password": ""
        }
      }
    }
  • Experimental Features:

  • Other Changes:

    • Upgrade esbuild to 0.24.2
    • Use native [email protected]
    • Use target es2022 for browsers by default (#903)
    • Replace window with globalThis to make Deno 2 happy (#964)
    • Use .mjs extenstion for sub-module build (#917)
    • dts-transformer: support .d and d.cts extension (#987)
    • Support major.minor.patch+build versioning (#985)
    • Support import attributes (#976)
    • config: Support S3-compatible storage (#886)
    • config: Add corsAllowOrigins config
    • config: Add customLandingPage config (#928)
    • config: Add npmQueryCacheTTL config (#921)

v135 / Introducing esm.sh/run

22 Nov 23:16
@ije ije
Compare
Choose a tag to compare

🎉🎉🎉 Introducing esm.sh/run, a 1KB script allows you to write jsx/tsx in HTML without build step!

Installation

<script type="module" src="https://esm.sh/run"></script>

Usage

The script allows you to add <script> elements with jsx/typescript in your HTML, for example:

<script type="text/babel">
  console.log("esm.sh run!" as string)
</script>

Supported types:

  • text/babel (recommended, highlighting is working in vscode)
  • text/jsx
  • text/ts
  • text/tsx

Using Import Maps

esm.sh run supports import maps, it even works in outdated browser that doesn't support the feature.

<script type="importmap">
  {
    "imports": {
      "@jsxImportSource": "https://esm.sh/[email protected]",
      "react-dom/client": "https://esm.sh/[email protected]/client"
    }
  }
</script>

The special @jsxImportSource in the imports is using for JSX transform, you can alternate it to your preferred runtime, for example https://esm.sh/[email protected].

How it Works?

After the page loaded, the run script computes the hash of the source code of non-javascript <script> elements as the cache key, if the cache exists then run it, otherwise sends the source code to esm.sh build API and stores it in the cache system.
The cache system includes two iters of storage, are the localStoarge and Cloudflare Edge cache, to make the compiled JS load fast!

image

Limitations

There are some limitations you need to be aware of:

  • the build task is slower than local babel/swc/esbuild (only happens when the source code has been changed)
  • 60 build tasks pre minute is allowed

Try it Online

👉 Play with TailwindCSS ⏎


Other changes

  • worker: Use raw.esm.sh hostname for ?raw option
  • Add ?no-bundle option
  • Support esm.sh field in package.json
  • Fix sub-module resolving (close #754, #743)
  • Upgrade esbuild to 0.19.7

v134

14 Nov 13:57
@ije ije
Compare
Choose a tag to compare

esm.sh v134 mainly includes some bugfix patches. And now you can add allowList option to serve specific packages on you self-hosting esm.sh server. (Thanks @olekenneth for contributing to this!)

Changelog

  • Add transformOnly option for build api
  • Add allowList in config (#745 by @olekenneth)
  • Improved Deno CLI (#742 by @Kyiro)
  • Worker: fix dist version lookup
  • Fix exported names from a dependency (close #729, #750)
  • Fix: write .npmrc file if NpmRegistry is set (close #737) (#751 by @edeustace)
  • Upgrade esbuild to 0.19.5

v133

08 Oct 06:35
@ije ije
Compare
Choose a tag to compare

In v133, we introduced the ?raw mode that returns the raw JS files and fixed a bunch of bugs.

Escape Hatch: Raw Source Files

In rare cases, you may want to request JS source files from packages, as-is, without transformation into ES modules. To do so, you need to add a ?raw query to the request URL.

For example, you might need to register a package's source script as a service worker in a browser that does not yet support the type: "module" option:

await navigator.serviceWorker.register(
  new URL(
    "https://esm.sh/[email protected]/playground-service-worker.js?raw",
    import.meta.url.href
  ),
  { scope: '/' }
);

You may alternatively specify an &raw extra query after the package version:

<playground-project sandbox-base-url="https://esm.sh/[email protected]&raw/"
></playground-project>

so that transitive references in the raw assets will also be raw requests.

Thanks @johnyanarella for contributing to this.

Changlog:

  • Add ?raw to support requests for raw package source files (#731 by @johnyanarella)
  • Add global setMaxListeners to node:events polyfill (#719)
  • cjs-lexer: resolving error now doesn't break build (close #738)
  • Fix cwd method of node:process polyfill (close #718)
  • Fix applyConditions function use node condition for browser (close #732)
  • Fix *.css.js path (close #728)
  • Fix some invalid require imports (close #724)
  • Fix relative path resolving of browser in package.json
  • Upgrade esbuild to 0.19.4

v132

04 Sep 07:14
@ije ije
Compare
Choose a tag to compare

In v132, no features are added but some bugs have been fixed.

Changelog:

  • Resolve node internal modules when ?external=* set (close #714)
  • Fix builds with bigint and top-level-await for all targets (close #711)
  • Fix node:process ployfill module mssing the hrtime method
  • Fix docker image missing git command
  • esm-worker: add varyUA option for polyfill modules

v131

15 Aug 05:56
@ije ije
Compare
Choose a tag to compare

In v131, we improved the /build API to avoid duplicated builds of same input code, and fixed some bugs:

  • Add a cache layer for the /build API
  • Fix dts transformer resolver ignoring *.mjs url
  • Fix ?external option ignoring sub-modules
  • Use raw order of the exports in package.json (close #705)
  • Redirect old build path (.js) to new build path (.mjs) (close #703)
  • Upgrade esbuild to 0.19.2

v130

28 Jul 13:32
@ije ije
Compare
Choose a tag to compare

esm.sh v130 improves the esm-cjs-lexer to get correct exports of a minified UMD module, this can fix error "missed named exports" of some cjs only packages. The great change was contributed by @lewisl9029, huge thanks ❤️

Changelog:

  • esm-cjs-lexer: support minified UMD exports (#689 @lewisl9029)
  • Fix sub .mjs module (close #691)
  • Fix playground (https://code.esm.sh) editor don't load language workers
  • Fix ?bundle mode ignores node_process.js (close #694)
  • Upgrade @types/react@18 to 18.2.15
  • Upgrade esbuild to 0.18.17

v129

24 Jul 13:31
@ije ije
Compare
Choose a tag to compare

esm.sh v129 mainly inclueds some bug fixs:

  • BREAKING: Remove X-Esm-Deps header (close #683)
  • Sort exports of package.json when looping (close #683)
  • Don't replace typeof window for deno target (close #681)
  • Don't replace node global variable for ?target=node
  • Fix dts transformer (close #670)
  • Fix depreacted message with "
  • esm-worker: Fix cacheKey with X-Real-Origin header

v128

06 Jul 01:19
@ije ije
Compare
Choose a tag to compare

In v128, we added an official Docker image to allow you to self-host esm.sh more easily (This is based on johnpangalos/docker-esm-dot-sh by @johnpangalos, thank you!).

docker pull ghcr.io/esm-dev/esm.sh

More usage check HOSTING.md

For Deno users, we upgraded stableBuild to latest(v128) this may break your deno.lock.

Changelog

  • Add official Docker image: https://ghcr.io/esm-dev/esm.sh
  • Fix missed ?external for deps
  • Fix duplicate Access-Control-Expose-Headers headers
  • Fix dts transform for imports with both default and named imports (#675 by @hayes)
  • Don't bundle dynamic imports
  • BREAKING Upgrade stableBuild to v128

v127

02 Jul 17:10
@ije ije
Compare
Choose a tag to compare

In v127, we improved the network waterfall by adding the dependency imports of current module in the entry module (aka. preload).

For example: https://esm.sh/[email protected]

import "https://esm.sh/stable/[email protected]/es2022/react.mjs";       /* Added in v127 */
import "https://esm.sh/v127/[email protected]/es2022/scheduler.mjs"; /* Added in v127 */
export * from "https://esm.sh/v127/[email protected]/es2022/react-dom.mjs";
export { default } from "https://esm.sh/v127/[email protected]/es2022/react-dom.mjs";

For framework authors, esm.sh provides an extra X-Esm-Deps header that allows you to get those preload import urls.

const res = await fetch("https://esm.sh/[email protected]")
console.log(res.headers.get(`X-Esm-Deps`)?.split(", "))

Changelog:

  • Add preload imports
  • Add modern-normalize to the cssPackages
  • Fix subpath not be resovled with ?alias (close #671)
  • Fix dts transformer for "*.d" path imports (close #660)
  • Fix source map mappings (close #668)
  • CLI: Fix update failure caused by gh module (#661 by @lifegpc)
  • Upgrade esbuild to 0.18.10