Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Nov 27, 2024
1 parent b087c0c commit 3892584
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 26 additions & 5 deletions packages/plugin-dts/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,37 @@ export function ensureTempDeclarationDir(cwd: string, name: string): string {
return dirPath;
}

export async function clearTempDeclarationDir(cwd: string): Promise<void> {
const dirPath = path.join(cwd, TEMP_DTS_DIR);
export async function pathExists(path: string): Promise<boolean> {
return fs.promises
.access(path)
.then(() => true)
.catch(() => false);
}

export async function emptyDir(dir: string): Promise<void> {
if (!(await pathExists(dir))) {
return;
}

try {
await fsP.rm(dirPath, { recursive: true, force: true });
} catch (error) {
logger.error(`Error clearing temporary directory ${dirPath}: ${error}`);
for (const file of await fs.promises.readdir(dir)) {
await fs.promises.rm(path.resolve(dir, file), {
recursive: true,
force: true,
});
}
} catch (err) {
logger.debug(`Failed to empty dir: ${dir}`);
logger.debug(err);
}
}

export async function clearTempDeclarationDir(cwd: string): Promise<void> {
const dirPath = path.join(cwd, TEMP_DTS_DIR);

await emptyDir(dirPath);
}

export function getFileLoc(
diagnostic: ts.Diagnostic,
configPath: string,
Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ export async function createTempFiles(
checkFile.push(tempFileCjs, tempFileEsm);

if (bundle) {
const tempDirRslib = join(fixturePath, '.rslib/declarations', 'cjs');
const tempDirRslibEsm = join(fixturePath, '.rslib/declarations', 'esm');
const tempDirRslib = join(fixturePath, '.rslib', 'declarations', 'cjs');
const tempDirRslibEsm = join(fixturePath, '.rslib', 'declarations', 'esm');
const tempFileRslibCjs = join(tempDirRslib, 'tempFile.d.ts');
const tempFileRslibEsm = join(tempDirRslibEsm, 'tempFile.d.ts');

Expand Down

0 comments on commit 3892584

Please sign in to comment.