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:
+1
-1
@@ -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
@@ -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,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
@@ -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
@@ -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
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user