-
Notifications
You must be signed in to change notification settings - Fork 334
Migrate to ESM #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to ESM #484
Changes from 1 commit
f7b7395
2efa207
c1f5bea
c8cb4f7
652c6aa
2a61df5
fc9e38f
8177aee
586fbaa
b76eda7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| name: Setup CI | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: ".node-version" | ||
| cache: yarn | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
| run: yarn install --frozen-lockfile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| v22.9.0 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "type": "node", | ||
| "request": "launch", | ||
| "name": "Debug Current Test File", | ||
| "autoAttachChildProcesses": true, | ||
| "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs", | ||
| "args": ["run", "${relativeFile}"], | ||
| "smartStep": true, | ||
| "console": "integratedTerminal" | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,12 @@ | |
| "name": "@changesets/action", | ||
| "version": "1.5.2", | ||
| "main": "dist/index.js", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
| "@changesets/changelog-github": "^0.4.2", | ||
| "@changesets/cli": "^2.20.0", | ||
| "@changesets/write": "^0.1.6", | ||
| "@changesets/changelog-github": "^0.5.1", | ||
| "@changesets/cli": "^2.29.3", | ||
| "@changesets/write": "^0.4.0", | ||
| "@types/fs-extra": "^8.0.0", | ||
| "@types/node": "^22.15.17", | ||
| "@types/semver": "^7.5.0", | ||
|
|
@@ -18,13 +19,13 @@ | |
| "vitest": "^3.1.3" | ||
| }, | ||
| "scripts": { | ||
| "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --minify --outfile=dist/index.js", | ||
| "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --format=esm --minify --outfile=dist/index.js", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory... this should be quite safe but then... who knows. Perhaps this should only land after testing this e2e in some repo. It feels like a somewhat risky change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used to migrate to esbuild & esm in my actions but reverted back due to some issues I've forgotten, so probably good to look out here too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Damn. That's not great :p I think I'll still try to run with it - but I have to definitely test it e2e first |
||
| "test": "vitest", | ||
| "test:watch": "yarn test --watch", | ||
| "typecheck": "tsc", | ||
| "changeset": "changeset", | ||
| "bump": "node ./scripts/bump.js", | ||
| "release": "node ./scripts/release.js" | ||
| "bump": "node --experimental-strip-types ./scripts/bump.ts", | ||
| "release": "node --experimental-strip-types ./scripts/release.ts" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 20" | ||
|
|
@@ -34,17 +35,17 @@ | |
| "@actions/exec": "^1.1.1", | ||
| "@actions/github": "^6.0.1", | ||
| "@changesets/ghcommit": "1.4.0", | ||
| "@changesets/pre": "^1.0.9", | ||
| "@changesets/read": "^0.5.3", | ||
| "@changesets/pre": "^2.0.2", | ||
| "@changesets/read": "^0.6.5", | ||
| "@manypkg/get-packages": "^1.1.3", | ||
| "@octokit/core": "^5.2.1", | ||
| "@octokit/plugin-throttling": "^8.0.0", | ||
| "@types/mdast": "^3.0.0", | ||
| "fs-extra": "^8.1.0", | ||
| "import-meta-resolve": "^4.1.0", | ||
| "mdast-util-to-string": "^1.0.6", | ||
| "remark-parse": "^7.0.1", | ||
| "remark-stringify": "^7.0.3", | ||
| "resolve-from": "^5.0.0", | ||
| "semver": "^7.5.3", | ||
| "unified": "^8.3.2" | ||
| }, | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { exec } from "@actions/exec"; | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import pkgJson from "../package.json" with { type: "json" }; | ||
|
|
||
| process.chdir(path.join(import.meta.dirname, "..")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only use I'm not sure what is the caveat the docs mention here:
Is that only that it wouldn't be present for modules imported/downloaded using HTTP(s) etc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think that's what it means. On GitHub workflows the code should be ran as files though and shouldn't have this issue, though you need to account for it resolving from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Good point. It's not an issue right now as we don't use it in |
||
|
|
||
| await exec("changeset", ["version"]); | ||
|
|
||
| const releaseLine = `v${pkgJson.version.split(".")[0]}`; | ||
|
|
||
| const readmePath = path.join(import.meta.dirname, "..", "README.md"); | ||
| const content = fs.readFileSync(readmePath, "utf8"); | ||
| const updatedContent = content.replace( | ||
| /changesets\/action@[^\s]+/g, | ||
| `changesets/action@${releaseLine}` | ||
| ); | ||
| fs.writeFileSync(readmePath, updatedContent); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,26 @@ | ||
| import * as core from "@actions/core"; | ||
| import { exec, getExecOutput } from "@actions/exec"; | ||
| import * as github from "@actions/github"; | ||
| import { PreState } from "@changesets/types"; | ||
| import { Package, getPackages } from "@manypkg/get-packages"; | ||
| import type { PreState } from "@changesets/types"; | ||
| import { type Package, getPackages } from "@manypkg/get-packages"; | ||
| import fs from "fs-extra"; | ||
| import { resolve } from "import-meta-resolve"; | ||
| import { createRequire } from "node:module"; | ||
| import { pathToFileURL, fileURLToPath } from "node:url"; | ||
| import path from "path"; | ||
| import resolveFrom from "resolve-from"; | ||
| import semverLt from "semver/functions/lt"; | ||
| import { Git } from "./git"; | ||
| import { Octokit } from "./octokit"; | ||
| import readChangesetState from "./readChangesetState"; | ||
| import semverLt from "semver/functions/lt.js"; | ||
| import { Git } from "./git.ts"; | ||
| import type { Octokit } from "./octokit.ts"; | ||
| import readChangesetState from "./readChangesetState.ts"; | ||
| import { | ||
| getChangedPackages, | ||
| getChangelogEntry, | ||
| getVersionsByDirectory, | ||
| isErrorWithCode, | ||
| sortTheThings, | ||
| } from "./utils"; | ||
| } from "./utils.ts"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| // GitHub Issues/PRs messages have a max size limit on the | ||
| // message body payload. | ||
|
|
@@ -162,7 +166,9 @@ export async function runPublish({ | |
|
|
||
| const requireChangesetsCliPkgJson = (cwd: string) => { | ||
| try { | ||
| return require(resolveFrom(cwd, "@changesets/cli/package.json")); | ||
| return require(require.resolve("@changesets/cli/package.json", { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why we were using |
||
| paths: [cwd], | ||
| })); | ||
| } catch (err) { | ||
| if (isErrorWithCode(err, "MODULE_NOT_FOUND")) { | ||
| throw new Error( | ||
|
|
@@ -286,9 +292,21 @@ export async function runVersion({ | |
| let cmd = semverLt(changesetsCliPkgJson.version, "2.0.0") | ||
| ? "bump" | ||
| : "version"; | ||
| await exec("node", [resolveFrom(cwd, "@changesets/cli/bin.js"), cmd], { | ||
| cwd, | ||
| }); | ||
| await exec( | ||
| "node", | ||
| [ | ||
| fileURLToPath( | ||
| resolve( | ||
| "@changesets/cli/bin.js", | ||
| pathToFileURL(path.join(cwd, "x.cjs")).toString() | ||
| ) | ||
| ), | ||
|
||
| cmd, | ||
| ], | ||
| { | ||
| cwd, | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| let changedPackages = await getChangedPackages(cwd, versionsByDirectory); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,14 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "esnext", | ||
| "allowImportingTsExtensions": true, | ||
| "erasableSyntaxOnly": true, | ||
| "isolatedModules": true, | ||
| "module": "node18", | ||
| "moduleResolution": "node16", | ||
| "noEmit": true, | ||
| "isolatedModules": true, | ||
| "resolveJsonModule": true, | ||
| "strict": true, | ||
| "moduleResolution": "node16", | ||
| "erasableSyntaxOnly": true, | ||
| "skipLibCheck": true | ||
| "target": "esnext", | ||
| "verbatimModuleSyntax": true | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fuzzy on this. This repo only has to support one node version. I had issues using
--experimental-strip-typeson node 20 so I decided to use node 22 here - for dev workflows and on CI. But then only node 20 is currently supported for GitHub Actions (using: 'node22'doesn't work yet).