Skip to content

Commit 7cba979

Browse files
committed
fix: create-package script
1 parent 3b94a7c commit 7cba979

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

scripts/create-package/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import execa from 'execa';
2-
import { promises as fs } from 'fs';
2+
import { fstatSync, promises as fs } from 'fs';
33
import path from 'path';
44
import { format as prettierFormat } from 'prettier';
55
import type { Options as PrettierOptions } from 'prettier';
@@ -94,8 +94,14 @@ export async function finalizeAndWriteData(
9494
monorepoFileData: MonorepoFileData,
9595
) {
9696
const packagePath = path.join(PACKAGES_PATH, packageData.directoryName);
97-
if ((await fs.stat(packagePath)).isDirectory()) {
98-
throw new Error(`The package directory already exists: ${packagePath}`);
97+
try {
98+
if ((await fs.stat(packagePath)).isDirectory()) {
99+
throw new Error(`The package directory already exists: ${packagePath}`);
100+
}
101+
} catch (error) {
102+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
103+
throw error;
104+
}
99105
}
100106

101107
console.log('Writing package and monorepo files...');
@@ -136,7 +142,7 @@ async function writeJsonFile(
136142
): Promise<void> {
137143
await fs.writeFile(
138144
filePath,
139-
prettierFormat(fileContent, { ...prettierRc, parser: 'json' }),
145+
await prettierFormat(fileContent, { ...prettierRc, parser: 'json' }),
140146
);
141147
}
142148

0 commit comments

Comments
 (0)