Skip to content

Commit

Permalink
Fixed prettier loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Aug 27, 2022
1 parent 9539fb7 commit b5012c3
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions packages/apply-release-plan/src/index.ts
Expand Up @@ -3,7 +3,7 @@ import {
Config,
ChangelogFunctions,
NewChangeset,
ModCompWithPackage,
ModCompWithPackage
} from "@changesets/types";

import { defaultConfig } from "@changesets/config";
Expand All @@ -19,9 +19,9 @@ import prettier from "prettier";
import versionPackage from "./version-package";
import getChangelogEntry from "./get-changelog-entry";

function getPrettierInstance(): typeof prettier {
function getPrettierInstance(cwd: string): typeof prettier {
try {
return require("prettier");
return require(require.resolve("prettier", { paths: [cwd] }));
} catch (err) {
if (!err || (err as any).code !== "MODULE_NOT_FOUND") {
throw err;
Expand All @@ -37,7 +37,7 @@ async function getCommitsThatAddChangesets(
changesetIds: string[],
cwd: string
) {
const paths = changesetIds.map((id) => `.changeset/${id}.md`);
const paths = changesetIds.map(id => `.changeset/${id}.md`);
const commits = await git.getCommitsThatAddFiles(paths, cwd);

if (commits.every(stringDefined)) {
Expand All @@ -50,7 +50,7 @@ async function getCommitsThatAddChangesets(
.map((id, i) => (commits[i] ? undefined : id))
.filter(stringDefined);

const legacyPaths = missingIds.map((id) => `.changeset/${id}/changes.json`);
const legacyPaths = missingIds.map(id => `.changeset/${id}/changes.json`);
const commitsForLegacyPaths = await git.getCommitsThatAddFiles(
legacyPaths,
cwd
Expand Down Expand Up @@ -78,20 +78,20 @@ export default async function applyReleasePlan(
let touchedFiles = [];

const packagesByName = new Map(
packages.packages.map((x) => [x.packageJson.name, x])
packages.packages.map(x => [x.packageJson.name, x])
);

let { releases, changesets } = releasePlan;

let releasesWithPackage = releases.map((release) => {
let releasesWithPackage = releases.map(release => {
let pkg = packagesByName.get(release.name);
if (!pkg)
throw new Error(
`Could not find matching package for release of: ${release.name}`
);
return {
...release,
...pkg,
...pkg
};
});

Expand All @@ -117,23 +117,23 @@ export default async function applyReleasePlan(
let versionsToUpdate = releases.map(({ name, newVersion, type }) => ({
name,
version: newVersion,
type,
type
}));

// iterate over releases updating packages
let finalisedRelease = releaseWithChangelogs.map((release) => {
let finalisedRelease = releaseWithChangelogs.map(release => {
return versionPackage(release, versionsToUpdate, {
updateInternalDependencies: config.updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange:
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
.onlyUpdatePeerDependentsWhenOutOfRange,
bumpVersionsWithWorkspaceProtocolOnly:
config.bumpVersionsWithWorkspaceProtocolOnly,
snapshot,
snapshot
});
});

let prettierInstance = getPrettierInstance();
let prettierInstance = getPrettierInstance(cwd);
let prettierConfig = await prettierInstance.resolveConfig(cwd);

for (let release of finalisedRelease) {
Expand Down Expand Up @@ -162,7 +162,7 @@ export default async function applyReleasePlan(
) {
let changesetFolder = path.resolve(cwd, ".changeset");
await Promise.all(
changesets.map(async (changeset) => {
changesets.map(async changeset => {
let changesetPath = path.resolve(changesetFolder, `${changeset.id}.md`);
let changesetFolderPath = path.resolve(changesetFolder, changeset.id);
if (await fs.pathExists(changesetPath)) {
Expand All @@ -172,7 +172,7 @@ export default async function applyReleasePlan(
// so we just check if any ignored package exists in this changeset, and only remove it if none exists
// Ignored list is added in v2, so we don't need to do it for v1 changesets
if (
!changeset.releases.find((release) =>
!changeset.releases.find(release =>
config.ignore.includes(release.name)
)
) {
Expand Down Expand Up @@ -200,16 +200,16 @@ async function getNewChangelogEntry(
) {
if (!config.changelog) {
return Promise.resolve(
releasesWithPackage.map((release) => ({
releasesWithPackage.map(release => ({
...release,
changelog: null,
changelog: null
}))
);
}

let getChangelogFuncs: ChangelogFunctions = {
getReleaseLine: () => Promise.resolve(""),
getDependencyReleaseLine: () => Promise.resolve(""),
getDependencyReleaseLine: () => Promise.resolve("")
};

const changelogOpts = config.changelog[1];
Expand All @@ -230,16 +230,16 @@ async function getNewChangelogEntry(
}

let commits = await getCommitsThatAddChangesets(
changesets.map((cs) => cs.id),
changesets.map(cs => cs.id),
cwd
);
let moddedChangesets = changesets.map((cs, i) => ({
...cs,
commit: commits[i],
commit: commits[i]
}));

return Promise.all(
releasesWithPackage.map(async (release) => {
releasesWithPackage.map(async release => {
let changelog = await getChangelogEntry(
release,
releasesWithPackage,
Expand All @@ -250,16 +250,16 @@ async function getNewChangelogEntry(
updateInternalDependencies: config.updateInternalDependencies,
onlyUpdatePeerDependentsWhenOutOfRange:
config.___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH
.onlyUpdatePeerDependentsWhenOutOfRange,
.onlyUpdatePeerDependentsWhenOutOfRange
}
);

return {
...release,
changelog,
changelog
};
})
).catch((e) => {
).catch(e => {
console.error(
"The following error was encountered while generating changelog entries"
);
Expand Down Expand Up @@ -353,7 +353,7 @@ async function writeFormattedMarkdownFile(
prettierInstance.format(content, {
...prettierConfig,
filepath: filePath,
parser: "markdown",
parser: "markdown"
})
);
}

0 comments on commit b5012c3

Please sign in to comment.