Skip to content

Commit a96f43a

Browse files
committed
Fix lint
1 parent 137ebc2 commit a96f43a

1 file changed

Lines changed: 64 additions & 17 deletions

File tree

.github/scripts/create-changeset-from-pr.mjs

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,29 @@ const affectedPackages = await getAffectedPackages(
5656
);
5757

5858
if (affectedPackages.length === 0) {
59-
console.log('No workspace packages were detected from the PR diff; skipping changeset creation.');
59+
console.log(
60+
'No workspace packages were detected from the PR diff; skipping changeset creation.',
61+
);
6062
process.exit(0);
6163
}
6264

6365
await mkdir(changesetDir, { recursive: true });
6466
const existingFiles = await listChangesetFiles(changesetDir);
6567

66-
execFileSync('pnpm', ['exec', 'changeset', 'add', '--empty', '--message', prTitle], {
67-
cwd: repoRoot,
68-
stdio: 'pipe',
69-
});
68+
execFileSync(
69+
'pnpm',
70+
['exec', 'changeset', 'add', '--empty', '--message', prTitle],
71+
{
72+
cwd: repoRoot,
73+
stdio: 'pipe',
74+
},
75+
);
76+
77+
const createdChangesetFile = await getNewestChangesetFile(
78+
changesetDir,
79+
existingFiles,
80+
);
7081

71-
const createdChangesetFile = await getNewestChangesetFile(changesetDir, existingFiles);
7282
if (!createdChangesetFile) {
7383
console.error('Changesets CLI did not create a changeset file.');
7484
process.exit(1);
@@ -79,6 +89,7 @@ const frontmatter = affectedPackages
7989
.map((pkg) => `"${pkg}": ${releaseType}`)
8090
.join('\n');
8191
const content = `---\n${frontmatter}\n---\n\n${prTitle}\n`;
92+
8293
await writeFile(filePath, content, 'utf8');
8394

8495
console.log(
@@ -94,11 +105,19 @@ async function getWorkspacePackages(repoRootPath) {
94105
entries
95106
.filter((entry) => entry.isDirectory())
96107
.map(async (entry) => {
97-
const packageJsonPath = path.join(packagesDir, entry.name, 'package.json');
108+
const packageJsonPath = path.join(
109+
packagesDir,
110+
entry.name,
111+
'package.json',
112+
);
113+
98114
try {
99115
const packageJsonContent = await readFile(packageJsonPath, 'utf8');
100116
const packageJson = JSON.parse(packageJsonContent);
101-
return packageJson.name ? { name: packageJson.name, dirName: entry.name } : null;
117+
118+
return packageJson.name
119+
? { name: packageJson.name, dirName: entry.name }
120+
: null;
102121
} catch {
103122
return null;
104123
}
@@ -107,14 +126,32 @@ async function getWorkspacePackages(repoRootPath) {
107126
).filter(Boolean);
108127
}
109128

110-
async function getAffectedPackages(repoRootPath, workspacePackagesList, baseShaValue, headShaValue) {
111-
const changedFiles = await getChangedFiles(repoRootPath, baseShaValue, headShaValue);
129+
async function getAffectedPackages(
130+
repoRootPath,
131+
workspacePackagesList,
132+
baseShaValue,
133+
headShaValue,
134+
) {
135+
const changedFiles = await getChangedFiles(
136+
repoRootPath,
137+
baseShaValue,
138+
headShaValue,
139+
);
112140
const affectedPackageNames = new Set();
113-
const ignoredPackages = new Set(['@react-docgen-internal/benchmark', '@react-docgen-internal/website']);
141+
const ignoredPackages = new Set([
142+
'@react-docgen-internal/benchmark',
143+
'@react-docgen-internal/website',
144+
]);
114145

115146
for (const changedFile of changedFiles) {
116147
const normalizedPath = changedFile.replace(/\\/g, '/');
117-
const rootChanges = ['package.json', 'pnpm-workspace.yaml', 'nx.json', 'tsconfig.base.json', 'pnpm-lock.yaml'];
148+
const rootChanges = [
149+
'package.json',
150+
'pnpm-workspace.yaml',
151+
'nx.json',
152+
'tsconfig.base.json',
153+
'pnpm-lock.yaml',
154+
];
118155

119156
if (rootChanges.includes(normalizedPath)) {
120157
for (const workspacePackage of workspacePackagesList) {
@@ -127,9 +164,11 @@ async function getAffectedPackages(repoRootPath, workspacePackagesList, baseShaV
127164

128165
for (const workspacePackage of workspacePackagesList) {
129166
const packagePrefix = `packages/${workspacePackage.dirName}/`;
167+
130168
if (
131169
!ignoredPackages.has(workspacePackage.name) &&
132-
(normalizedPath === `packages/${workspacePackage.dirName}` || normalizedPath.startsWith(packagePrefix))
170+
(normalizedPath === `packages/${workspacePackage.dirName}` ||
171+
normalizedPath.startsWith(packagePrefix))
133172
) {
134173
affectedPackageNames.add(workspacePackage.name);
135174
}
@@ -144,14 +183,19 @@ async function getChangedFiles(repoRootPath, baseShaValue, headShaValue) {
144183
const headRef = headShaValue || 'HEAD';
145184

146185
try {
147-
const diffOutput = execFileSync('git', ['diff', '--name-only', baseRef, headRef], {
148-
cwd: repoRootPath,
149-
encoding: 'utf8',
150-
});
186+
const diffOutput = execFileSync(
187+
'git',
188+
['diff', '--name-only', baseRef, headRef],
189+
{
190+
cwd: repoRootPath,
191+
encoding: 'utf8',
192+
},
193+
);
151194
const files = diffOutput
152195
.split(/\r?\n/)
153196
.map((line) => line.trim())
154197
.filter(Boolean);
198+
155199
if (files.length > 0) {
156200
return files;
157201
}
@@ -164,6 +208,7 @@ async function getChangedFiles(repoRootPath, baseShaValue, headShaValue) {
164208
cwd: repoRootPath,
165209
encoding: 'utf8',
166210
});
211+
167212
return statusOutput
168213
.split(/\r?\n/)
169214
.map((line) => line.trim())
@@ -177,6 +222,7 @@ async function getChangedFiles(repoRootPath, baseShaValue, headShaValue) {
177222

178223
async function listChangesetFiles(changesetDirectory) {
179224
const entries = await readdir(changesetDirectory, { withFileTypes: true });
225+
180226
return entries
181227
.filter((entry) => entry.isFile() && entry.name.endsWith('.md'))
182228
.map((entry) => entry.name)
@@ -199,5 +245,6 @@ async function getNewestChangesetFile(changesetDirectory, existingFiles) {
199245
);
200246

201247
filesWithStats.sort((left, right) => right.mtimeMs - left.mtimeMs);
248+
202249
return filesWithStats[0]?.name ?? null;
203250
}

0 commit comments

Comments
 (0)