Skip to content
markpaper

scripts/clean-dist.mjs

v0.3.0 · 713 B

Download file
// A clean build must not ship files emitted for APIs that have since been removed.
import { lstatSync, rmSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const output = path.resolve(packageRoot, 'dist');
if (path.dirname(output) !== packageRoot || path.basename(output) !== 'dist') {
  throw new Error('build output must be the package dist directory');
}
try {
  if (lstatSync(output).isSymbolicLink()) throw new Error('build output must not be a symbolic link');
} catch (error) {
  if (error.code !== 'ENOENT') throw error;
}
rmSync(output, { recursive: true, force: true });
All files