diff --git a/.changeset/public-zebras-hope.md b/.changeset/public-zebras-hope.md new file mode 100644 index 000000000..cf0c886bd --- /dev/null +++ b/.changeset/public-zebras-hope.md @@ -0,0 +1,19 @@ +--- +"@changesets/get-version-range-type": minor +"@changesets/assemble-release-plan": minor +"@changesets/get-dependents-graph": minor +"@changesets/apply-release-plan": minor +"@changesets/changelog-github": minor +"@changesets/get-release-plan": minor +"@changesets/changelog-git": minor +"@changesets/release-utils": minor +"@changesets/parse": minor +"@changesets/write": minor +"@changesets/read": minor +"@changesets/cli": minor +"@changesets/git": minor +--- + +Add a named export that mirrors the current `default` export + +The `default` export is slated for removal in the next major release, so this ensures a smoother transition path. diff --git a/eslint.config.mjs b/eslint.config.mjs index c90f6d773..61daf7eac 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -75,9 +75,20 @@ export default defineConfig( { ignores: ["fs/promises.cp", "import.meta.dirname"] }, ], + "import-lite/no-default-export": "error", "import-lite/no-mutable-exports": "off", // TODO enable and fix errors }, }, + { + files: [ + "**/index.ts", // to be removed in next release (v4) when we are dropping default export + "**/vitest.config.mts", + "**/eslint.config.mjs", + ], + rules: { + "import-lite/no-default-export": "off", + }, + }, { files: ["**/*.{js,mjs}"], ...tseslint.configs.disableTypeChecked, diff --git a/packages/apply-release-plan/src/get-changelog-entry.ts b/packages/apply-release-plan/src/get-changelog-entry.ts index 1a36a3b2a..8c2942962 100644 --- a/packages/apply-release-plan/src/get-changelog-entry.ts +++ b/packages/apply-release-plan/src/get-changelog-entry.ts @@ -24,7 +24,7 @@ async function generateChangesForVersionTypeMarkdown( } // release is the package and version we are releasing -export default async function getChangelogEntry( +export async function getChangelogEntry( cwd: string, release: ModCompWithPackage, releases: ModCompWithPackage[], diff --git a/packages/apply-release-plan/src/index.ts b/packages/apply-release-plan/src/index.ts index 1caf4a06f..646374dc0 100644 --- a/packages/apply-release-plan/src/index.ts +++ b/packages/apply-release-plan/src/index.ts @@ -14,8 +14,8 @@ import fs from "node:fs/promises"; import path from "path"; import prettier from "prettier"; import { resolve } from "import-meta-resolve"; -import getChangelogEntry from "./get-changelog-entry.ts"; -import versionPackage from "./version-package.ts"; +import { getChangelogEntry } from "./get-changelog-entry.ts"; +import { versionPackage } from "./version-package.ts"; import { createRequire } from "node:module"; import { pathToFileURL } from "node:url"; @@ -72,7 +72,7 @@ async function getCommitsThatAddChangesets( return commits; } -export default async function applyReleasePlan( +export async function applyReleasePlan( releasePlan: ReleasePlan, packages: Packages, config: Config = defaultConfig, @@ -378,6 +378,10 @@ async function updatePackageJson( return fs.writeFile(pkgJsonPath, stringified); } +/** @deprecated Use named export `applyReleasePlan` instead */ +const applyReleasePlanDefault = applyReleasePlan; +export default applyReleasePlanDefault; + async function writeFormattedMarkdownFile( filePath: string, content: string, diff --git a/packages/apply-release-plan/src/test-utils/failing-functions.ts b/packages/apply-release-plan/src/test-utils/failing-functions.ts index f208a4be3..cb3e1068a 100644 --- a/packages/apply-release-plan/src/test-utils/failing-functions.ts +++ b/packages/apply-release-plan/src/test-utils/failing-functions.ts @@ -1,3 +1,8 @@ +// plugin, must have a default export +/* eslint-disable import-lite/no-default-export */ + +import type { ChangelogFunctions } from "@changesets/types"; + export default { getReleaseLine: () => { throw new Error("no chance"); @@ -5,4 +10,4 @@ export default { getDependencyReleaseLine: () => { throw new Error("no chance"); }, -}; +} satisfies ChangelogFunctions; diff --git a/packages/apply-release-plan/src/test-utils/get-changelog-entry-with-git-hash.ts b/packages/apply-release-plan/src/test-utils/get-changelog-entry-with-git-hash.ts index 34d2538cd..11911e8a3 100644 --- a/packages/apply-release-plan/src/test-utils/get-changelog-entry-with-git-hash.ts +++ b/packages/apply-release-plan/src/test-utils/get-changelog-entry-with-git-hash.ts @@ -33,6 +33,8 @@ async function getReleaseLines( return `### ${capitalize(type)} Changes\n\n${resolvedLines.join("")}`; } +// plugin, needs default export +// eslint-disable-next-line import-lite/no-default-export export default async function defaultChangelogGetter( release: ComprehensiveRelease, relevantChangesets: RelevantChangesets, diff --git a/packages/apply-release-plan/src/version-package.ts b/packages/apply-release-plan/src/version-package.ts index 1e8e99755..11d6ba860 100644 --- a/packages/apply-release-plan/src/version-package.ts +++ b/packages/apply-release-plan/src/version-package.ts @@ -3,7 +3,7 @@ import type { PackageJSON, VersionType, } from "@changesets/types"; -import getVersionRangeType from "@changesets/get-version-range-type"; +import { getVersionRangeType } from "@changesets/get-version-range-type"; import Range from "semver/classes/range.js"; import semverPrerelease from "semver/functions/prerelease.js"; import validRange from "semver/ranges/valid.js"; @@ -16,7 +16,7 @@ const DEPENDENCY_TYPES = [ "optionalDependencies", ] as const; -export default function versionPackage( +export function versionPackage( release: ComprehensiveRelease & { changelog: string | null; packageJson: PackageJSON; diff --git a/packages/assemble-release-plan/README.md b/packages/assemble-release-plan/README.md index fd5a0258b..7a4127dcf 100644 --- a/packages/assemble-release-plan/README.md +++ b/packages/assemble-release-plan/README.md @@ -9,7 +9,7 @@ Usage ```ts import assembleReleasePlan from "@changesets/assemble-release-plan"; -import readChangesets from "@changesets/read"; +import { readChangesets } from "@changesets/read"; import { read } from "@changesets/config"; import { getPackages } from "@manypkg/get-packages"; import { readPreState } from "@changesets/pre"; diff --git a/packages/assemble-release-plan/src/apply-links.ts b/packages/assemble-release-plan/src/apply-links.ts index d233842a2..1aaefe85e 100644 --- a/packages/assemble-release-plan/src/apply-links.ts +++ b/packages/assemble-release-plan/src/apply-links.ts @@ -14,7 +14,7 @@ import { getCurrentHighestVersion, getHighestReleaseType } from "./utils.ts"; We could solve this by inlining this function, or by returning a deep-cloned then modified array, but we decided both of those are worse than this solution. */ -export default function applyLinks( +export function applyLinks( releases: Map, packagesByName: Map, linked: Linked, diff --git a/packages/assemble-release-plan/src/determine-dependents.ts b/packages/assemble-release-plan/src/determine-dependents.ts index 054531090..bc61a1b12 100644 --- a/packages/assemble-release-plan/src/determine-dependents.ts +++ b/packages/assemble-release-plan/src/determine-dependents.ts @@ -25,7 +25,7 @@ import { mapGetOrThrowInternal } from "./utils.ts"; We could solve this by inlining this function, or by returning a deep-cloned then modified array, but we decided both of those are worse than this solution. */ -export default function determineDependents({ +export function determineDependents({ releases, packagesByName, rootDir, diff --git a/packages/assemble-release-plan/src/flatten-releases.ts b/packages/assemble-release-plan/src/flatten-releases.ts index 14777e026..5010a0a1c 100644 --- a/packages/assemble-release-plan/src/flatten-releases.ts +++ b/packages/assemble-release-plan/src/flatten-releases.ts @@ -6,7 +6,7 @@ import type { Config, NewChangeset, Package } from "@changesets/types"; import type { InternalRelease } from "./types.ts"; import { mapGetOrThrowInternal } from "./utils.ts"; -export default function flattenReleases( +export function flattenReleases( changesets: NewChangeset[], packagesByName: Map, config: Config, diff --git a/packages/assemble-release-plan/src/index.test.ts b/packages/assemble-release-plan/src/index.test.ts index 635b94a79..930ccded0 100644 --- a/packages/assemble-release-plan/src/index.test.ts +++ b/packages/assemble-release-plan/src/index.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it } from "vitest"; import { defaultConfig } from "@changesets/config"; -import assembleReleasePlan from "./index.ts"; -import FakeFullState from "./test-utils.ts"; +import { assembleReleasePlan } from "./index.ts"; +import { FakeFullState } from "./test-utils.ts"; describe("assemble-release-plan", () => { let setup: FakeFullState; diff --git a/packages/assemble-release-plan/src/index.ts b/packages/assemble-release-plan/src/index.ts index 3beafd382..cdd82b56a 100644 --- a/packages/assemble-release-plan/src/index.ts +++ b/packages/assemble-release-plan/src/index.ts @@ -11,11 +11,11 @@ import type { Packages, } from "@changesets/types"; import semverParse from "semver/functions/parse.js"; -import applyLinks from "./apply-links.ts"; -import determineDependents from "./determine-dependents.ts"; -import flattenReleases from "./flatten-releases.ts"; +import { applyLinks } from "./apply-links.ts"; +import { determineDependents } from "./determine-dependents.ts"; +import { flattenReleases } from "./flatten-releases.ts"; import { incrementVersion } from "./increment.ts"; -import matchFixedConstraint from "./match-fixed-constraint.ts"; +import { matchFixedConstraint } from "./match-fixed-constraint.ts"; import type { InternalRelease, PreInfo } from "./types.ts"; import { mapGetOrThrow, mapGetOrThrowInternal } from "./utils.ts"; @@ -120,7 +120,7 @@ function getNewVersion( return incrementVersion(release, preInfo); } -function assembleReleasePlan( +export function assembleReleasePlan( changesets: NewChangeset[], packages: Packages, config: Config, @@ -373,4 +373,6 @@ function getPreInfo( }; } -export default assembleReleasePlan; +/** @deprecated Use named export `assembleReleasePlan` instead */ +const assembleReleasePlanDefault = assembleReleasePlan; +export default assembleReleasePlanDefault; diff --git a/packages/assemble-release-plan/src/match-fixed-constraint.ts b/packages/assemble-release-plan/src/match-fixed-constraint.ts index 38d6008e6..8a0b1d247 100644 --- a/packages/assemble-release-plan/src/match-fixed-constraint.ts +++ b/packages/assemble-release-plan/src/match-fixed-constraint.ts @@ -7,7 +7,7 @@ import { mapGetOrThrowInternal, } from "./utils.ts"; -export default function matchFixedConstraint( +export function matchFixedConstraint( releases: Map, packagesByName: Map, config: Config, diff --git a/packages/assemble-release-plan/src/test-utils.ts b/packages/assemble-release-plan/src/test-utils.ts index 395e0de5e..108574e99 100644 --- a/packages/assemble-release-plan/src/test-utils.ts +++ b/packages/assemble-release-plan/src/test-utils.ts @@ -67,7 +67,7 @@ const getSimpleSetup = () => ({ ] satisfies Array, }); -class FakeFullState { +export class FakeFullState { packages: Packages; changesets: NewChangeset[]; @@ -141,5 +141,3 @@ class FakeFullState { pkg.packageJson.version = version; } } - -export default FakeFullState; diff --git a/packages/changelog-git/src/index.ts b/packages/changelog-git/src/index.ts index 9473af82f..f19ff399f 100644 --- a/packages/changelog-git/src/index.ts +++ b/packages/changelog-git/src/index.ts @@ -50,4 +50,5 @@ const defaultChangelogFunctions = { getDependencyReleaseLine, } satisfies ChangelogFunctions; +// ChangelogFunctions require a default export export default defaultChangelogFunctions; diff --git a/packages/changelog-github/src/index.ts b/packages/changelog-github/src/index.ts index 730a85506..607debb24 100644 --- a/packages/changelog-github/src/index.ts +++ b/packages/changelog-github/src/index.ts @@ -169,4 +169,5 @@ const changelogFunctions: ChangelogFunctions = { }, }; +// ChangelogFunctions require a default export export default changelogFunctions; diff --git a/packages/cli/src/changelog.ts b/packages/cli/src/changelog.ts index 0a80c80ed..bd20ac76e 100644 --- a/packages/cli/src/changelog.ts +++ b/packages/cli/src/changelog.ts @@ -1 +1,2 @@ +// eslint-disable-next-line import-lite/no-default-export export { default } from "@changesets/changelog-git"; diff --git a/packages/cli/src/commands/add/__tests__/add.test.ts b/packages/cli/src/commands/add/__tests__/add.test.ts index 12b05e5e7..903bc68c6 100644 --- a/packages/cli/src/commands/add/__tests__/add.test.ts +++ b/packages/cli/src/commands/add/__tests__/add.test.ts @@ -14,7 +14,7 @@ import getChangesets from "@changesets/read"; import { exec } from "tinyexec"; import * as utils from "../../../utils/cli-utilities.ts"; -import addChangeset from "../index.ts"; +import { add as addChangeset } from "../index.ts"; vi.mock("../../../utils/cli-utilities"); const mockedUtils = vi.mocked(utils); diff --git a/packages/cli/src/commands/add/createChangeset.ts b/packages/cli/src/commands/add/createChangeset.ts index f5aac1a7b..25f201672 100644 --- a/packages/cli/src/commands/add/createChangeset.ts +++ b/packages/cli/src/commands/add/createChangeset.ts @@ -105,7 +105,7 @@ function formatPkgNameAndVersion(pkgName: string, version: string) { return `${bold(pkgName)}@${bold(version)}`; } -export default async function createChangeset( +export async function createChangeset( changedPackages: Array, allPackages: Array, messageFromCli?: string, diff --git a/packages/cli/src/commands/add/index.ts b/packages/cli/src/commands/add/index.ts index 6d678a9f6..c6122daeb 100644 --- a/packages/cli/src/commands/add/index.ts +++ b/packages/cli/src/commands/add/index.ts @@ -6,18 +6,18 @@ import * as git from "@changesets/git"; import { error, info, log, warn } from "@changesets/logger"; import { shouldSkipPackage } from "@changesets/should-skip-package"; import type { Config } from "@changesets/types"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { ExitError } from "@changesets/errors"; import { getPackages } from "@manypkg/get-packages"; import { ExternalEditor } from "@inquirer/external-editor"; import { getCommitFunctions } from "../../commit/getCommitFunctions.ts"; import * as cli from "../../utils/cli-utilities.ts"; import { getVersionableChangedPackages } from "../../utils/versionablePackages.ts"; -import createChangeset from "./createChangeset.ts"; -import printConfirmationMessage from "./messages.ts"; +import { createChangeset } from "./createChangeset.ts"; +import { printConfirmationMessage } from "./messages.ts"; import { fileURLToPath } from "node:url"; -export default async function add( +export async function add( cwd: string, { empty, diff --git a/packages/cli/src/commands/add/messages.ts b/packages/cli/src/commands/add/messages.ts index 38c53b7d0..0c2150857 100644 --- a/packages/cli/src/commands/add/messages.ts +++ b/packages/cli/src/commands/add/messages.ts @@ -2,7 +2,7 @@ import pc from "picocolors"; import { log } from "@changesets/logger"; import type { Release, VersionType } from "@changesets/types"; -export default function printConfirmationMessage( +export function printConfirmationMessage( changeset: { releases: Array; summary: string; diff --git a/packages/cli/src/commands/init/__tests__/command.test.ts b/packages/cli/src/commands/init/__tests__/command.test.ts index 41523e245..5ec0d80ed 100644 --- a/packages/cli/src/commands/init/__tests__/command.test.ts +++ b/packages/cli/src/commands/init/__tests__/command.test.ts @@ -5,7 +5,7 @@ import path from "path"; import { defaultWrittenConfig } from "@changesets/config"; import { silenceLogsInBlock, testdir } from "@changesets/test-utils"; -import initializeCommand from "../index.ts"; +import { init as initializeCommand } from "../index.ts"; const getPaths = (cwd: string) => ({ readmePath: path.join(cwd, ".changeset/README.md"), diff --git a/packages/cli/src/commands/init/index.ts b/packages/cli/src/commands/init/index.ts index 8f214e932..12dce1a5e 100644 --- a/packages/cli/src/commands/init/index.ts +++ b/packages/cli/src/commands/init/index.ts @@ -13,7 +13,7 @@ const pkgPath = path.dirname(require.resolve("@changesets/cli/package.json")); const defaultConfig = `${JSON.stringify(defaultWrittenConfig, null, 2)}\n`; -export default async function init(cwd: string) { +export async function init(cwd: string) { const changesetBase = path.resolve(cwd, ".changeset"); if (existsSync(changesetBase)) { diff --git a/packages/cli/src/commands/pre/index.test.ts b/packages/cli/src/commands/pre/index.test.ts index 4df940340..76004edc6 100644 --- a/packages/cli/src/commands/pre/index.test.ts +++ b/packages/cli/src/commands/pre/index.test.ts @@ -9,7 +9,7 @@ import { testdir, } from "@changesets/test-utils"; -import pre from "./index.ts"; +import { pre } from "./index.ts"; silenceLogsInBlock(); diff --git a/packages/cli/src/commands/pre/index.ts b/packages/cli/src/commands/pre/index.ts index 4d8941e1d..9cc42bd5e 100644 --- a/packages/cli/src/commands/pre/index.ts +++ b/packages/cli/src/commands/pre/index.ts @@ -7,7 +7,7 @@ import { ExitError, } from "@changesets/errors"; -export default async function pre( +export async function pre( rootDir: string, options: | { command: "enter"; tag: string } diff --git a/packages/cli/src/commands/publish/__tests__/index.test.ts b/packages/cli/src/commands/publish/__tests__/index.test.ts index 08bdd16a3..de46f9187 100644 --- a/packages/cli/src/commands/publish/__tests__/index.test.ts +++ b/packages/cli/src/commands/publish/__tests__/index.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import publishCommand from "../index.ts"; +import { publish as publishCommand } from "../index.ts"; import { defaultConfig } from "@changesets/config"; import * as path from "path"; import type { Config } from "@changesets/types"; diff --git a/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts b/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts index 486b35008..eb31c0535 100644 --- a/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts +++ b/packages/cli/src/commands/publish/__tests__/publishPackages.test.ts @@ -1,5 +1,5 @@ import { afterEach, describe, expect, it, vi } from "vitest"; -import publishPackages from "../publishPackages.ts"; +import { publishPackages } from "../publishPackages.ts"; import * as npmUtils from "../npm-utils.ts"; import { getPackages } from "@manypkg/get-packages"; import { silenceLogsInBlock, testdir } from "@changesets/test-utils"; diff --git a/packages/cli/src/commands/publish/__tests__/releaseCommand.test.ts b/packages/cli/src/commands/publish/__tests__/releaseCommand.test.ts index 5439ef37d..60fab0daf 100644 --- a/packages/cli/src/commands/publish/__tests__/releaseCommand.test.ts +++ b/packages/cli/src/commands/publish/__tests__/releaseCommand.test.ts @@ -1,9 +1,9 @@ import { afterEach, describe, expect, it, vi } from "vitest"; -import publishPackages from "../publishPackages.ts"; +import { publishPackages } from "../publishPackages.ts"; import * as git from "@changesets/git"; import { defaultConfig } from "@changesets/config"; import { silenceLogsInBlock, testdir } from "@changesets/test-utils"; -import runRelease from "../index.ts"; +import { publish as runRelease } from "../index.ts"; vi.mock("../../../utils/cli-utilities"); vi.mock("@changesets/git"); diff --git a/packages/cli/src/commands/publish/index.ts b/packages/cli/src/commands/publish/index.ts index 8df66b55e..511a4cafc 100644 --- a/packages/cli/src/commands/publish/index.ts +++ b/packages/cli/src/commands/publish/index.ts @@ -1,4 +1,4 @@ -import publishPackages from "./publishPackages.ts"; +import { publishPackages } from "./publishPackages.ts"; import { ExitError } from "@changesets/errors"; import { error, log, success, warn } from "@changesets/logger"; import * as git from "@changesets/git"; @@ -38,7 +38,7 @@ function showNonLatestTagWarning(tag?: string, preState?: PreState) { warn(importantEnd); } -export default async function publish( +export async function publish( cwd: string, { otp, tag, gitTag = true }: { otp?: string; tag?: string; gitTag?: boolean }, config: Config, diff --git a/packages/cli/src/commands/publish/publishPackages.ts b/packages/cli/src/commands/publish/publishPackages.ts index 183dcfb9a..03adcf2d7 100644 --- a/packages/cli/src/commands/publish/publishPackages.ts +++ b/packages/cli/src/commands/publish/publishPackages.ts @@ -80,7 +80,7 @@ export const requiresDelegatedAuth = (twoFactorState: TwoFactorState) => { ); }; -export default async function publishPackages({ +export async function publishPackages({ packages, access, otp, diff --git a/packages/cli/src/commands/status/__tests__/status.test.ts b/packages/cli/src/commands/status/__tests__/status.test.ts index f325b0c04..ddbda6a99 100644 --- a/packages/cli/src/commands/status/__tests__/status.test.ts +++ b/packages/cli/src/commands/status/__tests__/status.test.ts @@ -3,12 +3,12 @@ import { read } from "@changesets/config"; import * as git from "@changesets/git"; import { gitdir, outputFile, silenceLogsInBlock } from "@changesets/test-utils"; import type { ReleasePlan } from "@changesets/types"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { getPackages } from "@manypkg/get-packages"; import fs from "node:fs/promises"; import path from "path"; import { exec } from "tinyexec"; -import status from "../index.ts"; +import { status } from "../index.ts"; async function readConfig(cwd: string) { const packages = await getPackages(cwd); diff --git a/packages/cli/src/commands/status/index.ts b/packages/cli/src/commands/status/index.ts index 8fe4b9ed1..f4ff7607a 100644 --- a/packages/cli/src/commands/status/index.ts +++ b/packages/cli/src/commands/status/index.ts @@ -1,7 +1,7 @@ import pc from "picocolors"; import fs from "node:fs/promises"; import path from "path"; -import getReleasePlan from "@changesets/get-release-plan"; +import { getReleasePlan } from "@changesets/get-release-plan"; import { error, info, log } from "@changesets/logger"; import type { ComprehensiveRelease, @@ -11,7 +11,7 @@ import type { } from "@changesets/types"; import { getVersionableChangedPackages } from "../../utils/versionablePackages.ts"; -export default async function status( +export async function status( cwd: string, { since, diff --git a/packages/cli/src/commands/tag/__tests__/index.test.ts b/packages/cli/src/commands/tag/__tests__/index.test.ts index 13514fd50..6c44cb5a3 100644 --- a/packages/cli/src/commands/tag/__tests__/index.test.ts +++ b/packages/cli/src/commands/tag/__tests__/index.test.ts @@ -3,7 +3,7 @@ import { read } from "@changesets/config"; import * as git from "@changesets/git"; import { silenceLogsInBlock, testdir } from "@changesets/test-utils"; import { getPackages } from "@manypkg/get-packages"; -import tag from "../index.ts"; +import { tag } from "../index.ts"; vi.mock("@changesets/git"); diff --git a/packages/cli/src/commands/tag/index.ts b/packages/cli/src/commands/tag/index.ts index c8b382e6f..e5e6e9ce3 100644 --- a/packages/cli/src/commands/tag/index.ts +++ b/packages/cli/src/commands/tag/index.ts @@ -5,7 +5,7 @@ import type { Config } from "@changesets/types"; import { getPackages } from "@manypkg/get-packages"; import { getUntaggedPackages } from "../../utils/getUntaggedPackages.ts"; -export default async function tag(cwd: string, config: Config) { +export async function tag(cwd: string, config: Config) { const { packages, tool } = await getPackages(cwd); const allExistingTags = await git.getAllTags(cwd); diff --git a/packages/cli/src/commands/version/index.ts b/packages/cli/src/commands/version/index.ts index 8fffc7aac..80600d757 100644 --- a/packages/cli/src/commands/version/index.ts +++ b/packages/cli/src/commands/version/index.ts @@ -6,8 +6,8 @@ import { getCurrentCommitId } from "@changesets/git"; import { error, log, warn } from "@changesets/logger"; import type { Config } from "@changesets/types"; import applyReleasePlan from "@changesets/apply-release-plan"; -import readChangesets from "@changesets/read"; -import assembleReleasePlan from "@changesets/assemble-release-plan"; +import { readChangesets } from "@changesets/read"; +import { assembleReleasePlan } from "@changesets/assemble-release-plan"; import { getPackages } from "@manypkg/get-packages"; import { readPreState } from "@changesets/pre"; import { ExitError } from "@changesets/errors"; @@ -21,7 +21,7 @@ const importantEnd = pc.red( "----------------------------------------------------------------------", ); -export default async function version( +export async function version( cwd: string, options: { snapshot?: string | boolean; diff --git a/packages/cli/src/commands/version/version.test.ts b/packages/cli/src/commands/version/version.test.ts index 7c756cdb3..63c4e1af2 100644 --- a/packages/cli/src/commands/version/version.test.ts +++ b/packages/cli/src/commands/version/version.test.ts @@ -8,7 +8,7 @@ import { testdir, } from "@changesets/test-utils"; import type { Changeset, Config } from "@changesets/types"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { getPackages } from "@manypkg/get-packages"; import { humanId } from "human-id"; import assert from "node:assert/strict"; @@ -23,8 +23,8 @@ import { type Mock, vi, } from "vitest"; -import pre from "../pre/index.ts"; -import version from "./index.ts"; +import { pre } from "../pre/index.ts"; +import { version } from "./index.ts"; const modifiedDefaultConfig: Config = { ...defaultConfig, diff --git a/packages/cli/src/commit/index.ts b/packages/cli/src/commit/index.ts index 5a56c2afc..c0e7e4c96 100644 --- a/packages/cli/src/commit/index.ts +++ b/packages/cli/src/commit/index.ts @@ -41,4 +41,5 @@ const defaultCommitFunctions = { getVersionMessage, } satisfies Required; +// CommitFunctions require a default export export default defaultCommitFunctions; diff --git a/packages/cli/src/run.test.ts b/packages/cli/src/run.test.ts index d3400d3e6..29aaa2fed 100644 --- a/packages/cli/src/run.test.ts +++ b/packages/cli/src/run.test.ts @@ -5,9 +5,9 @@ import { silenceLogsInBlock, testdir, } from "@changesets/test-utils"; -import add from "./commands/add/index.ts"; +import { add } from "./commands/add/index.ts"; import { run } from "./run.ts"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; vi.mock("./commands/add"); vi.mock("./commands/version"); diff --git a/packages/cli/src/run.ts b/packages/cli/src/run.ts index 56ed6d75e..b1db59bce 100644 --- a/packages/cli/src/run.ts +++ b/packages/cli/src/run.ts @@ -6,14 +6,14 @@ import { shouldSkipPackage } from "@changesets/should-skip-package"; import type { Config } from "@changesets/types"; import { getPackages } from "@manypkg/get-packages"; import fs from "node:fs/promises"; -import path from "path"; -import add from "./commands/add/index.ts"; -import init from "./commands/init/index.ts"; -import pre from "./commands/pre/index.ts"; -import publish from "./commands/publish/index.ts"; -import status from "./commands/status/index.ts"; -import tagCommand from "./commands/tag/index.ts"; -import version from "./commands/version/index.ts"; +import path from "node:path"; +import { add } from "./commands/add/index.ts"; +import { init } from "./commands/init/index.ts"; +import { pre } from "./commands/pre/index.ts"; +import { publish } from "./commands/publish/index.ts"; +import { status } from "./commands/status/index.ts"; +import { tag as tagCommand } from "./commands/tag/index.ts"; +import { version } from "./commands/version/index.ts"; import { COMMAND_HELP } from "./help.ts"; import type { CliOptions } from "./types.ts"; diff --git a/packages/get-dependents-graph/src/get-dependency-graph.test.ts b/packages/get-dependents-graph/src/get-dependency-graph.test.ts index f863cec68..a9e2c0f9c 100644 --- a/packages/get-dependents-graph/src/get-dependency-graph.test.ts +++ b/packages/get-dependents-graph/src/get-dependency-graph.test.ts @@ -1,7 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { stripVTControlCharacters } from "node:util"; import { temporarilySilenceLogs } from "@changesets/test-utils"; -import getDependencyGraph from "./get-dependency-graph.ts"; +import { getDependencyGraph } from "./get-dependency-graph.ts"; import type { Package } from "@changesets/types"; import path from "node:path"; diff --git a/packages/get-dependents-graph/src/get-dependency-graph.ts b/packages/get-dependents-graph/src/get-dependency-graph.ts index e492e954e..a4eac0cee 100644 --- a/packages/get-dependents-graph/src/get-dependency-graph.ts +++ b/packages/get-dependents-graph/src/get-dependency-graph.ts @@ -53,7 +53,7 @@ const getValidRange = (potentialRange: string) => { } }; -export default function getDependencyGraph( +export function getDependencyGraph( packages: Packages, rootPackage: Package, { diff --git a/packages/get-dependents-graph/src/index.ts b/packages/get-dependents-graph/src/index.ts index d3fbc59c2..b17f39b8b 100644 --- a/packages/get-dependents-graph/src/index.ts +++ b/packages/get-dependents-graph/src/index.ts @@ -1,5 +1,5 @@ import type { Package, Packages } from "@changesets/types"; -import getDependencyGraph from "./get-dependency-graph.ts"; +import { getDependencyGraph } from "./get-dependency-graph.ts"; export function getDependentsGraph( packages: Packages, diff --git a/packages/get-release-plan/README.md b/packages/get-release-plan/README.md index 5228a57ac..b8b379ea6 100644 --- a/packages/get-release-plan/README.md +++ b/packages/get-release-plan/README.md @@ -6,7 +6,7 @@ A function that reads information about the current repository ```js -import getReleasePlan from "@changesets/get-release-plan"; +import { getReleasePlan } from "@changesets/get-release-plan"; const releasePlan = await getReleasePlan(cwd, since, passedConfig); ``` diff --git a/packages/get-release-plan/src/index.ts b/packages/get-release-plan/src/index.ts index a812642aa..14244e1a5 100644 --- a/packages/get-release-plan/src/index.ts +++ b/packages/get-release-plan/src/index.ts @@ -1,11 +1,11 @@ -import assembleReleasePlan from "@changesets/assemble-release-plan"; -import readChangesets from "@changesets/read"; +import { assembleReleasePlan } from "@changesets/assemble-release-plan"; +import { readChangesets } from "@changesets/read"; import { read } from "@changesets/config"; import type { Config, ReleasePlan } from "@changesets/types"; import { getPackages } from "@manypkg/get-packages"; import { readPreState } from "@changesets/pre"; -export default async function getReleasePlan( +export async function getReleasePlan( cwd: string, sinceRef?: string, passedConfig?: Config, @@ -18,3 +18,7 @@ export default async function getReleasePlan( return assembleReleasePlan(changesets, packages, config, preState); } + +/** @deprecated Use named export `getReleasePlan` instead */ +const getReleasePlanDefault = getReleasePlan; +export default getReleasePlanDefault; diff --git a/packages/get-version-range-type/src/index.ts b/packages/get-version-range-type/src/index.ts index d43d7e0ca..374664aaa 100644 --- a/packages/get-version-range-type/src/index.ts +++ b/packages/get-version-range-type/src/index.ts @@ -1,4 +1,4 @@ -export default function getVersionRangeType( +export function getVersionRangeType( versionRange: string, ): "^" | "~" | ">=" | "<=" | ">" | "" { if (versionRange.charAt(0) === "^") return "^"; @@ -8,3 +8,7 @@ export default function getVersionRangeType( if (versionRange.charAt(0) === ">") return ">"; return ""; } + +/** @deprecated Use named export `getVersionRangeType` instead */ +const getVersionRangeTypeDefault = getVersionRangeType; +export default getVersionRangeTypeDefault; diff --git a/packages/git/src/index.test.ts b/packages/git/src/index.test.ts index 493629209..870108a65 100644 --- a/packages/git/src/index.test.ts +++ b/packages/git/src/index.test.ts @@ -3,7 +3,7 @@ import { exec } from "tinyexec"; import { pathToFileURL } from "node:url"; import { describe, expect, it } from "vitest"; import { gitdir, outputFile, testdir } from "@changesets/test-utils"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { add, diff --git a/packages/parse/README.md b/packages/parse/README.md index 62a80e39b..b151a6ba7 100644 --- a/packages/parse/README.md +++ b/packages/parse/README.md @@ -6,7 +6,7 @@ Parses a changeset from its written format to a data object. ```js -import parse from "@changesets/parse"; +import { parseChangesetFile } from "@changesets/parse"; const changeset = `--- "@changesets/something": minor @@ -15,7 +15,7 @@ const changeset = `--- A description of a minor change`; -const parsedChangeset = parse(changeset); +const parsedChangeset = parseChangesetFile(changeset); ``` For example, it can convert: diff --git a/packages/parse/src/index.ts b/packages/parse/src/index.ts index 95e9d03fc..522b00058 100644 --- a/packages/parse/src/index.ts +++ b/packages/parse/src/index.ts @@ -48,7 +48,7 @@ function validateReleases(releases: Release[], contents: string): void { } } -export default function parseChangesetFile(contents: string): { +export function parseChangesetFile(contents: string): { summary: string; releases: Release[]; } { @@ -109,3 +109,7 @@ export default function parseChangesetFile(contents: string): { return { releases, summary }; } + +/** @deprecated Use named export `parseChangesetFile` instead */ +const parseChangesetFileDefault = parseChangesetFile; +export default parseChangesetFileDefault; diff --git a/packages/read/README.md b/packages/read/README.md index 603b64d4a..6a6d41915 100644 --- a/packages/read/README.md +++ b/packages/read/README.md @@ -6,7 +6,7 @@ Read in all changesets from a repository. ```js -import readChangesets from "@changesets/read"; +import { readChangesets } from "@changesets/read"; let changesets = await readChangesets(cwd); ``` diff --git a/packages/read/src/index.test.ts b/packages/read/src/index.test.ts index c35e4b687..8934da1d9 100644 --- a/packages/read/src/index.test.ts +++ b/packages/read/src/index.test.ts @@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest"; import read from "./index.ts"; import { gitdir, silenceLogsInBlock, testdir } from "@changesets/test-utils"; import fs from "node:fs/promises"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { add } from "@changesets/git"; silenceLogsInBlock(); diff --git a/packages/read/src/index.ts b/packages/read/src/index.ts index 3ffbf89fe..d79d92482 100644 --- a/packages/read/src/index.ts +++ b/packages/read/src/index.ts @@ -1,6 +1,6 @@ import fs from "node:fs/promises"; -import path from "path"; -import parse from "@changesets/parse"; +import path from "node:path"; +import { parseChangesetFile } from "@changesets/parse"; import type { NewChangeset } from "@changesets/types"; import * as git from "@changesets/git"; @@ -18,7 +18,7 @@ async function filterChangesetsSinceRef( return changesets.filter((dir) => newHashes.includes(dir)); } -export default async function getChangesets( +export async function readChangesets( rootDir: string, sinceRef?: string, ): Promise> { @@ -53,7 +53,11 @@ export default async function getChangesets( const changesetContents = changesets.map(async (file) => { const changeset = await fs.readFile(path.join(changesetBase, file), "utf8"); - return { ...parse(changeset), id: file.replace(".md", "") }; + return { ...parseChangesetFile(changeset), id: file.replace(".md", "") }; }); return await Promise.all(changesetContents); } + +/** @deprecated Use named export `readChangesets` instead */ +const readChangesetsDefault = readChangesets; +export default readChangesetsDefault; diff --git a/packages/release-utils/src/readChangesetState.ts b/packages/release-utils/src/readChangesetState.ts index 289c2f797..05647d6c2 100644 --- a/packages/release-utils/src/readChangesetState.ts +++ b/packages/release-utils/src/readChangesetState.ts @@ -1,6 +1,6 @@ import type { PreState, NewChangeset } from "@changesets/types"; import { readPreState } from "@changesets/pre"; -import readChangesets from "@changesets/read"; +import { readChangesets } from "@changesets/read"; export type ChangesetState = { preState: PreState | undefined; diff --git a/packages/release-utils/src/run.test.ts b/packages/release-utils/src/run.test.ts index fa5dee747..a3a9c7a32 100644 --- a/packages/release-utils/src/run.test.ts +++ b/packages/release-utils/src/run.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, it, test, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { add, commit } from "@changesets/git"; import { linkNodeModules, @@ -6,16 +6,18 @@ import { testdir, } from "@changesets/test-utils"; import type { Changeset } from "@changesets/types"; -import writeChangeset from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; import { pathToFileURL } from "node:url"; import fs from "node:fs/promises"; -import path from "path"; +import path from "node:path"; import { exec } from "tinyexec"; import { getCurrentBranch } from "./gitUtils.ts"; import { runPublish, runVersion } from "./run.ts"; const writeChangesets = (changesets: Changeset[], cwd: string) => { - return Promise.all(changesets.map((commit) => writeChangeset(commit, cwd))); + return Promise.all( + changesets.map((changeset) => writeChangeset(changeset, cwd)), + ); }; vi.setConfig({ testTimeout: 10000 }); @@ -132,29 +134,25 @@ describe("version", () => { path.join(cwd, "packages", "pkg-a", "CHANGELOG.md"), "utf8", ), - ).toEqual( - expect.stringContaining(`# pkg-a + ).toContain(`# pkg-a ## 1.1.0 ### Minor Changes -`), - ); +`); expect( await fs.readFile( path.join(cwd, "packages", "pkg-b", "CHANGELOG.md"), "utf8", ), - ).toEqual( - expect.stringContaining(`# pkg-b + ).toContain(`# pkg-b ## 1.1.0 ### Minor Changes -`), - ); +`); expect(changedPackages).toEqual([ { dir: path.join(clone, "packages", "pkg-a"), @@ -260,15 +258,13 @@ describe("version", () => { path.join(cwd, "packages", "pkg-a", "CHANGELOG.md"), "utf8", ), - ).toEqual( - expect.stringContaining(`# pkg-a + ).toContain(`# pkg-a ## 1.1.0 ### Minor Changes -`), - ); +`); await expect( fs.readFile(path.join(cwd, "packages", "pkg-b", "CHANGELOG.md"), "utf8"), ).rejects.toMatchObject({ code: "ENOENT" }); @@ -337,7 +333,7 @@ describe("version", () => { }); describe("publish", () => { - test("single package repo", async () => { + it("publishes packages in a single package repo", async () => { const cwd = await testdir({ "package.json": JSON.stringify({ private: true, @@ -373,7 +369,7 @@ describe("publish", () => { expect(tagsResult.stdout.trim()).toEqual("v1.0.0"); }); - test("multi package repo", async () => { + it("publishes packages in a multi package repo", async () => { const cwd = await testdir({ "package.json": JSON.stringify({ private: true, diff --git a/packages/write/README.md b/packages/write/README.md index 850357cc7..10366242e 100644 --- a/packages/write/README.md +++ b/packages/write/README.md @@ -3,7 +3,7 @@ Writes a changeset to a file. ```js -import write from "@changesets/write"; +import { writeChangeset } from "@changesets/write"; const changeset = { summary: "A description of a minor change", @@ -13,7 +13,7 @@ const changeset = { ], }; -const uniqueId = await write(changeset, cwd); +const uniqueId = await writeChangeset(changeset, cwd); console.log(uniqueId); // orange-foxes-waggle ``` diff --git a/packages/write/src/index.ts b/packages/write/src/index.ts index 737c6a9a1..2ce41fd1a 100644 --- a/packages/write/src/index.ts +++ b/packages/write/src/index.ts @@ -18,7 +18,7 @@ function getPrettierInstance(cwd: string): typeof prettier { } } -async function writeChangeset( +export async function writeChangeset( { summary, releases }: Changeset, rootDir: string, options?: { prettier?: boolean }, @@ -61,4 +61,6 @@ ${summary} return changesetID; } -export default writeChangeset; +/** @deprecated Use named export `writeChangeset` instead */ +const writeChangesetDefault = writeChangeset; +export default writeChangesetDefault;