Skip to content

Commit 0a095a8

Browse files
build!: switch to esm (#240)
BREAKING CHANGE: This drops support for Node 18, and switches to a pure ESM package. This means that you either have to use `"type": "module"` in your `package.json`, or upgrade to a Node version that supports [require(esm)](https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require), i.e. >= [v20.19.0](https://nodejs.org/en/blog/release/v20.19.0#requireesm-is-now-enabled-by-default), >= [v22.12.0](https://nodejs.org/en/blog/release/v22.12.0#requireesm-is-now-enabled-by-default), or v23 and above.
1 parent d50da47 commit 0a095a8

13 files changed

+25
-29
lines changed

.devcontainer/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
FROM mcr.microsoft.com/devcontainers/javascript-node:20
1+
FROM mcr.microsoft.com/devcontainers/javascript-node:22
22

3+
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
34
RUN corepack enable

.github/workflows/build.yml

-10
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,3 @@ jobs:
4141
node -v
4242
node test.cjs
4343
node test.mjs
44-
45-
- uses: actions/setup-node@v4
46-
with:
47-
node-version: 18
48-
- name: test build package on node@18
49-
working-directory: ./package-test/
50-
run: |
51-
node -v
52-
node test.cjs
53-
node test.mjs

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- run: corepack enable
3737
- uses: actions/setup-node@v4
3838
with:
39-
node-version: 20
39+
node-version: 22
4040
registry-url: "https://registry.npmjs.org"
4141
cache: "yarn"
4242
- run: yarn install --immutable

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
23
"editor.formatOnSave": true,
34
"editor.defaultFormatter": "esbenp.prettier-vscode",
45
"editor.codeActionsOnSave": {

eslint.config.mjs eslint.config.js

File renamed without changes.

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "esbuild-plugin-browserslist",
3+
"type": "module",
34
"description": "Configure esbuild's target based on a browserslist query",
45
"version": "0.16.0",
56
"author": "Nihal Gonsalves <[email protected]>",
@@ -8,10 +9,12 @@
89
"url": "https://github.com/nihalgonsalves/esbuild-plugin-browserslist.git"
910
},
1011
"license": "MIT",
11-
"main": "./dist/index.js",
12-
"types": "./dist/index.d.ts",
12+
"exports": {
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.js"
15+
},
1316
"engines": {
14-
"node": ">=18"
17+
"node": "^20.19.0 || ^22.12.0 || >23.0.0"
1518
},
1619
"files": [
1720
"dist"

release-please-config.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3-
"bump-minor-pre-major": true,
4-
"bump-patch-for-minor-pre-major": true,
53
"bootstrap-sha": "03736f66b1970e7728d40a6b1c53798618f717f3",
64
"packages": {
75
".": {

src/index.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import browserslist from "browserslist";
77
import * as esbuild from "esbuild";
88
import { vi, describe, it } from "vitest";
99

10-
import { esbuildPluginBrowserslist } from ".";
10+
import { esbuildPluginBrowserslist } from "./index.js";
1111

1212
const getFile = async (
1313
input: string,

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Plugin } from "esbuild";
22

3-
import { resolveToEsbuildTarget as resolveToEsbuildTarget_ } from "./resolveToEsbuildTarget";
4-
import { dbg, log, PLUGIN_NAME } from "./util";
3+
import { resolveToEsbuildTarget as resolveToEsbuildTarget_ } from "./resolveToEsbuildTarget.js";
4+
import { dbg, log, PLUGIN_NAME } from "./util.js";
55

66
export type Opts = { printUnknownTargets: boolean };
77

src/resolveToEsbuildTarget.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import browserslist from "browserslist";
22
import { describe, it } from "vitest";
33

4-
import { resolveToEsbuildTarget } from "./resolveToEsbuildTarget";
5-
import { EsbuildEngine } from "./types";
4+
import { resolveToEsbuildTarget } from "./resolveToEsbuildTarget.js";
5+
import { EsbuildEngine } from "./types.js";
66

77
const useLogs = () => {
88
const logs: string[] = [];

src/resolveToEsbuildTarget.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {
44
BrowserslistEsbuildMapping,
55
BrowserslistKind,
66
type EsbuildEngine,
7-
} from "./types";
8-
import { dbg } from "./util";
7+
} from "./types.js";
8+
import { dbg } from "./util.js";
99

1010
const BrowserSchema = z.nativeEnum(BrowserslistKind);
1111
/** 123 or 123.456 or 123.456.789 */

tsconfig.build.json

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"module": "NodeNext",
5-
"moduleResolution": "NodeNext",
64
"declaration": true,
75
"noEmit": false,
86
"incremental": false,

tsconfig.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
{
22
"extends": "@nihalgonsalves/esconfig/tsconfig.shared.json",
33
"compilerOptions": {
4+
// https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
5+
"lib": ["ES2023"],
6+
"target": "ES2023",
7+
"module": "NodeNext",
8+
"moduleResolution": "NodeNext",
49
"noEmit": true,
5-
"verbatimModuleSyntax": false,
6-
"erasableSyntaxOnly": false
10+
"erasableSyntaxOnly": false,
11+
"types": ["node"]
712
},
8-
"include": ["src/", "vitest.config.ts", "eslint.config.mjs"]
13+
"include": ["src/", "vitest.config.ts", "eslint.config.js"]
914
}

0 commit comments

Comments
 (0)