Skip to content

Conversation

@Andarist
Copy link
Member

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented May 11, 2025

⚠️ No Changeset found

Latest commit: b76eda7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -0,0 +1 @@
v22.9.0
Copy link
Member Author

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-types on 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).

},
"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",
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

The 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

src/run.ts Outdated
Comment on lines 298 to 303
fileURLToPath(
resolve(
"@changesets/cli/bin.js",
pathToFileURL(path.join(cwd, "x.cjs")).toString()
)
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is... quite a dance to make it work. Not the biggest issue but I wish there would be a builtin way to make this easier.

If I'm not mistaken, it also means that a bug was introduced here:
https://github.com/changesets/changesets/blob/268a29fedc948f22c672a3b1e3e51df4427f478d/packages/cli/src/commit/getCommitFunctions.ts#L16

A directory can't be used directly as input to resolve. It should be a filepath. cc @bluwy for double-checking my logic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think you're right. That should probably be a file path otherwise it resolves from one directory higher, which probably coincidentally worked because there's no node_modules in .changeset/ for the linked code.

About this code, could we also use require.resolve instead of import-meta-resolve too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About this code, could we also use require.resolve instead of import-meta-resolve too?

Yep, that was my plan - I just wanted to have a pushed out reference of how to do this using import-meta-resolve ;p I simplified this now.

import path from "node:path";
import pkgJson from "../package.json" with { type: "json" };

process.chdir(path.join(import.meta.dirname, ".."));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only use import.meta.dirname in tests and script so far so it's fine anyway. But I wonder if there are any compatibility gotchas to consider if we'd use this in the code of the action itself.

I'm not sure what is the caveat the docs mention here:

Caveat: only present on file: modules.

Is that only that it wouldn't be present for modules imported/downloaded using HTTP(s) etc?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 dist instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

though you need to account for it resolving from dist instead.

Good point. It's not an issue right now as we don't use it in src (and all files are nested directly in src too). But I'll keep that in mind as something to be more careful about.

const requireChangesetsCliPkgJson = (cwd: string) => {
try {
return require(resolveFrom(cwd, "@changesets/cli/package.json"));
return require(require.resolve("@changesets/cli/package.json", {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we were using resolveFrom. require.resolve supported this for a long time already. It also just seems like using require here is an easier option than dancing around this using import-meta-resolve.

@Andarist Andarist merged commit 5078b4b into main May 16, 2025
1 check passed
@Andarist Andarist deleted the esm branch May 16, 2025 09:39
valpinkman added a commit to LedgerHQ/changeset-action-ledger that referenced this pull request Aug 4, 2025
* upstream/main: (28 commits)
  Version Packages (changesets#480)
  Fixed missed `__dirname` reference (changesets#496)
  Switch to bundling with Rollup (changesets#495)
  Migrate to ESM (changesets#484)
  Fixed situations in which `cwd` was specified as a relative path and used with (default) `commitMode: git-cli` (changesets#486)
  Add LICENSE file (changesets#491)
  Fix PRs sometimes not getting reopened with `commitMode: github-api` (changesets#488)
  Removed `fs-extra` dependency (changesets#481)
  Setup Git user in `release-pr` workflow (changesets#493)
  Use proper ndoe version in `release-pr` workflow (changesets#492)
  Add `release-pr` workflow (changesets#490)
  Migrate to Vitest (changesets#483)
  Switch to `esbuild` for bundling (changesets#479)
  Import only for `semver/functions/lt` (changesets#482)
  Avoid hitting a deprecation warning when encountering errors from `@octokit/request-error` (changesets#461)
  Run typecheck on CI (changesets#478)
  Updated `@actions/*` and `@octokit/*` dependencies (changesets#477)
  Bump @babel/runtime from 7.21.5 to 7.27.1 (changesets#464)
  Version Packages (changesets#476)
  Make git add work consistently with subdirectories (changesets#473)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants