Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scripts): fix create-package path check #5118

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion scripts/create-package/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ export async function readMonorepoFiles(): Promise<MonorepoFileData> {
};
}

/**
* Checks if a package path already exists.
*
* @param packagePath - The package path.
* @returns True if the path exists, false otherwise.
*/
async function packagePathExists(packagePath: string) {
try {
// We use `access`, cause no matter if `packagePath` is a directory or a file, we won't
// be able to write anything there if it already exists.
await fs.access(packagePath);

return true;
} catch {
return false;
}
}

/**
* Finalizes package and repo files, writes them to disk, and performs necessary
* postprocessing (e.g. running `yarn install`).
Expand All @@ -94,7 +112,7 @@ export async function finalizeAndWriteData(
monorepoFileData: MonorepoFileData,
) {
const packagePath = path.join(PACKAGES_PATH, packageData.directoryName);
if ((await fs.stat(packagePath)).isDirectory()) {
if (await packagePathExists(packagePath)) {
throw new Error(`The package directory already exists: ${packagePath}`);
}

Expand Down
Loading