Skip to content

Commit 5078b4b

Browse files
authored
Migrate to ESM (#484)
* Migrate to ESM * just use `require.resolve` * reuse setup action * checkout PR head for a sec * ls things * try a thing * the dirname had a trailing whitespace, lol
1 parent 7ed1955 commit 5078b4b

File tree

21 files changed

+385
-1232
lines changed

21 files changed

+385
-1232
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Setup CI
2+
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Setup Node.js
7+
uses: actions/setup-node@v4
8+
with:
9+
node-version-file: ".node-version"
10+
cache: yarn
11+
12+
- name: Install dependencies
13+
shell: bash
14+
run: yarn install --frozen-lockfile

.github/workflows/ci.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- name: Checkout Repo
17-
uses: actions/checkout@v4
18-
19-
- name: Use Node.js 20
20-
uses: actions/setup-node@v4
16+
- uses: actions/checkout@v4
2117
with:
22-
node-version: 20.x
18+
ref: ${{ github.event.pull_request.head.sha }}
2319

24-
- name: Install Dependencies
25-
run: yarn --frozen-lockfile
20+
- uses: ./.github/actions/ci-setup
2621

2722
- name: Typecheck
2823
run: yarn typecheck

.github/workflows/release-pr.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
needs: release_check
3838
steps:
3939
- uses: actions/checkout@v4
40+
- uses: ./.github/actions/ci-setup
4041

4142
- name: Checkout pull request
4243
run: gh pr checkout ${{ github.event.issue.number }}
@@ -54,14 +55,6 @@ jobs:
5455
if: steps.check_version_packages.outputs.version_packages == 'true'
5556
run: git reset --hard HEAD~1
5657

57-
- name: Use Node.js 20
58-
uses: actions/setup-node@v4
59-
with:
60-
node-version: 20.x
61-
62-
- name: Install Dependencies
63-
run: yarn --frozen-lockfile
64-
6558
- run: yarn changeset version --snapshot pr${{ github.event.issue.number }}
6659
env:
6760
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/version-or-publish.yml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,8 @@ jobs:
1111
changesets:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- name: Checkout Repo
15-
uses: actions/checkout@v4
16-
17-
- name: Use Node.js 20
18-
uses: actions/setup-node@v4
19-
with:
20-
node-version: 20.x
21-
22-
- name: Install Dependencies
23-
run: yarn --frozen-lockfile
14+
- uses: actions/checkout@v4
15+
- uses: ./.github/actions/ci-setup
2416

2517
- name: Build
2618
run: yarn build

.node-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.9.0

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
3+
"version": "0.2.0",
4+
"configurations": [
5+
{
6+
"type": "node",
7+
"request": "launch",
8+
"name": "Debug Current Test File",
9+
"autoAttachChildProcesses": true,
10+
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
11+
"args": ["run", "${relativeFile}"],
12+
"smartStep": true,
13+
"console": "integratedTerminal"
14+
}
15+
]
16+
}

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"name": "@changesets/action",
33
"version": "1.5.2",
44
"main": "dist/index.js",
5+
"type": "module",
56
"license": "MIT",
67
"devDependencies": {
7-
"@changesets/changelog-github": "^0.4.2",
8-
"@changesets/cli": "^2.20.0",
9-
"@changesets/write": "^0.1.6",
8+
"@changesets/changelog-github": "^0.5.1",
9+
"@changesets/cli": "^2.29.3",
10+
"@changesets/write": "^0.4.0",
1011
"@types/node": "^22.15.17",
1112
"@types/semver": "^7.5.0",
1213
"esbuild": "^0.25.4",
@@ -17,14 +18,14 @@
1718
"vitest": "^3.1.3"
1819
},
1920
"scripts": {
20-
"build": "esbuild src/index.ts --bundle --platform=node --target=node20 --minify --outfile=dist/index.js",
21+
"build": "esbuild src/index.ts --bundle --platform=node --target=node20 --format=esm --minify --outfile=dist/index.js",
2122
"test": "vitest",
2223
"test:watch": "yarn test --watch",
2324
"typecheck": "tsc",
2425
"changeset": "changeset",
25-
"bump": "node ./scripts/bump.js",
26-
"release": "node ./scripts/release.js",
27-
"release:pr": "node ./scripts/release-pr.js"
26+
"bump": "node --experimental-strip-types ./scripts/bump.ts",
27+
"release": "node --experimental-strip-types ./scripts/release.ts",
28+
"release:pr": "node --experimental-strip-types ./scripts/release-pr.ts"
2829
},
2930
"engines": {
3031
"node": ">= 20"
@@ -34,16 +35,15 @@
3435
"@actions/exec": "^1.1.1",
3536
"@actions/github": "^6.0.1",
3637
"@changesets/ghcommit": "^2.0.0",
37-
"@changesets/pre": "^1.0.9",
38-
"@changesets/read": "^0.5.3",
38+
"@changesets/pre": "^2.0.2",
39+
"@changesets/read": "^0.6.5",
3940
"@manypkg/get-packages": "^1.1.3",
4041
"@octokit/core": "^5.2.1",
4142
"@octokit/plugin-throttling": "^8.0.0",
4243
"@types/mdast": "^3.0.0",
4344
"mdast-util-to-string": "^1.0.6",
4445
"remark-parse": "^7.0.1",
4546
"remark-stringify": "^7.0.3",
46-
"resolve-from": "^5.0.0",
4747
"semver": "^7.5.3",
4848
"unified": "^8.3.2"
4949
},

scripts/bump.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

scripts/bump.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { exec } from "@actions/exec";
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
import pkgJson from "../package.json" with { type: "json" };
5+
6+
process.chdir(path.join(import.meta.dirname, ".."));
7+
8+
await exec("changeset", ["version"]);
9+
10+
const releaseLine = `v${pkgJson.version.split(".")[0]}`;
11+
12+
const readmePath = path.join(import.meta.dirname, "..", "README.md");
13+
const content = fs.readFileSync(readmePath, "utf8");
14+
const updatedContent = content.replace(
15+
/changesets\/action@[^\s]+/g,
16+
`changesets/action@${releaseLine}`
17+
);
18+
fs.writeFileSync(readmePath, updatedContent);

scripts/release-pr.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)