mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
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:
+25
-12
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user