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
This commit is contained in:
Mateusz Burzyński
2025-05-16 11:39:43 +02:00
committed by GitHub
parent 7ed1955546
commit 5078b4b48b
21 changed files with 384 additions and 1231 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ import * as core from "@actions/core";
import { exec, getExecOutput } from "@actions/exec";
import * as github from "@actions/github";
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
import { Octokit } from "./octokit";
import type { Octokit } from "./octokit.ts";
type GitOptions = {
cwd: string;
+5 -5
View File
@@ -1,11 +1,11 @@
import * as core from "@actions/core";
import fs from "node:fs/promises";
import path from "node:path";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
import readChangesetState from "./readChangesetState";
import { runPublish, runVersion } from "./run";
import { fileExists } from "./utils";
import { Git } from "./git.ts";
import { setupOctokit } from "./octokit.ts";
import readChangesetState from "./readChangesetState.ts";
import { runPublish, runVersion } from "./run.ts";
import { fileExists } from "./utils.ts";
const getOptionalInput = (name: string) => core.getInput(name) || undefined;
+1 -1
View File
@@ -1,4 +1,4 @@
import { PreState, NewChangeset } from "@changesets/types";
import type { PreState, NewChangeset } from "@changesets/types";
import { readPreState } from "@changesets/pre";
import readChangesets from "@changesets/read";
+7 -7
View File
@@ -1,12 +1,12 @@
import { Changeset } from "@changesets/types";
import type { Changeset } from "@changesets/types";
import writeChangeset from "@changesets/write";
import fixturez from "fixturez";
import fs from "node:fs/promises";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { Git } from "./git";
import { setupOctokit } from "./octokit";
import { runVersion } from "./run";
import { Git } from "./git.ts";
import { setupOctokit } from "./octokit.ts";
import { runVersion } from "./run.ts";
vi.mock("@actions/github", () => ({
context: {
@@ -21,7 +21,7 @@ vi.mock("@actions/github", () => ({
rest: mockedGithubMethods,
}),
}));
vi.mock("./git");
vi.mock("./git.ts");
vi.mock("@changesets/ghcommit/git");
let mockedGithubMethods = {
@@ -34,11 +34,11 @@ let mockedGithubMethods = {
},
};
let f = fixturez(__dirname);
let f = fixturez(import.meta.dirname);
const linkNodeModules = async (cwd: string) => {
await fs.symlink(
path.join(__dirname, "..", "node_modules"),
path.join(import.meta.dirname, "..", "node_modules"),
path.join(cwd, "node_modules")
);
};
+25 -12
View File
@@ -1,22 +1,24 @@
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 "node:fs/promises";
import { createRequire } from "node:module";
import path from "node: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 +164,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", {
paths: [cwd],
}));
} catch (err) {
if (isErrorWithCode(err, "MODULE_NOT_FOUND")) {
throw new Error(
@@ -286,9 +290,18 @@ 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",
[
require.resolve("@changesets/cli/bin.js", {
paths: [cwd],
}),
cmd,
],
{
cwd,
}
);
}
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
+1 -1
View File
@@ -1,5 +1,5 @@
import { expect, test } from "vitest";
import { BumpLevels, getChangelogEntry, sortTheThings } from "./utils";
import { BumpLevels, getChangelogEntry, sortTheThings } from "./utils.ts";
let changelog = `# @keystone-alpha/email
+1 -1
View File
@@ -5,7 +5,7 @@ import fs from "node:fs/promises";
import type { Root } from "mdast";
// @ts-ignore
import mdastToString from "mdast-util-to-string";
import { getPackages, Package } from "@manypkg/get-packages";
import { getPackages, type Package } from "@manypkg/get-packages";
export const BumpLevels = {
dep: 0,