diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index b0ba2e888..ee0877a19 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -5,9 +5,9 @@ import path from 'path'; import { fileURLToPath } from 'url'; import * as vite from 'vite'; import { BuildInternals, createBuildInternals } from '../../core/build/internal.js'; +import { emptyDir, removeDir } from '../../core/fs/index.js'; import { prependForwardSlash } from '../../core/path.js'; import { isModeServerWithNoAdapter } from '../../core/util.js'; -import { emptyDir, removeDir } from '../../core/fs/index.js'; import { runHookBuildSetup } from '../../integrations/index.js'; import { PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import { info } from '../logger/core.js'; diff --git a/packages/astro/src/core/fs/index.ts b/packages/astro/src/core/fs/index.ts index 472a51580..f865ef4a8 100644 --- a/packages/astro/src/core/fs/index.ts +++ b/packages/astro/src/core/fs/index.ts @@ -1,8 +1,8 @@ import fs from 'fs'; import path from 'path'; -import { fileURLToPath, pathToFileURL } from 'url'; +import { fileURLToPath } from 'url'; -const isWindows = (process.platform === "win32"); +const isWindows = process.platform === 'win32'; /** An fs utility, similar to `rimraf` or `rm -rf` */ export function removeDir(_dir: URL): void { @@ -23,13 +23,13 @@ export function emptyDir(_dir: URL, skip?: Set): void { try { fs.rmSync(p, rmOptions); - } catch(er: any) { - if (er.code === "ENOENT") { - return + } catch (er: any) { + if (er.code === 'ENOENT') { + return; } // Windows can EPERM on stat. Life is suffering. // From https://github.com/isaacs/rimraf/blob/8c10fb8d685d5cc35708e0ffc4dac9ec5dd5b444/rimraf.js#L294 - if (er.code === "EPERM" && isWindows) { + if (er.code === 'EPERM' && isWindows) { fixWinEPERMSync(p, rmOptions, er); } } @@ -38,33 +38,30 @@ export function emptyDir(_dir: URL, skip?: Set): void { // Taken from https://github.com/isaacs/rimraf/blob/8c10fb8d685d5cc35708e0ffc4dac9ec5dd5b444/rimraf.js#L183 const fixWinEPERMSync = (p: string, options: fs.RmDirOptions, er: any) => { - try { - fs.chmodSync(p, 0o666); - } catch (er2: any) { - if (er2.code === "ENOENT") { - return; + try { + fs.chmodSync(p, 0o666); + } catch (er2: any) { + if (er2.code === 'ENOENT') { + return; + } else { + throw er; } - else { - throw er; - } - } - - let stats; - try { - stats = fs.statSync(p); - } catch (er3: any) { - if (er3.code === "ENOENT") { - return; - } - else { - throw er; - } - } - - if (stats.isDirectory()) { - fs.rmdirSync(p, options); } - else { - fs.unlinkSync(p); + + let stats; + try { + stats = fs.statSync(p); + } catch (er3: any) { + if (er3.code === 'ENOENT') { + return; + } else { + throw er; + } } -} + + if (stats.isDirectory()) { + fs.rmdirSync(p, options); + } else { + fs.unlinkSync(p); + } +};