From 3edb4478f5a7f06aeb9e0b829fc30393fbb2a04d Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sat, 4 Jun 2022 07:38:58 -0600 Subject: [PATCH] Remove remove helper --- package.json | 2 +- src/lib/output/renderer.ts | 7 +++++-- src/lib/utils/fs.ts | 14 -------------- src/lib/utils/index.ts | 1 - src/test/capture-screenshots.ts | 3 +-- 5 files changed, 7 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index dfd94076a..966147949 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "url": "https://github.com/TypeStrong/TypeDoc/issues" }, "engines": { - "node": ">= 14" + "node": ">= 14.14" }, "dependencies": { "lunr": "^2.3.9", diff --git a/src/lib/output/renderer.ts b/src/lib/output/renderer.ts index 9b37f00d9..8db59e343 100644 --- a/src/lib/output/renderer.ts +++ b/src/lib/output/renderer.ts @@ -14,7 +14,7 @@ import type { Theme } from "./theme"; import { RendererEvent, PageEvent } from "./events"; import type { ProjectReflection } from "../models/reflections/project"; import type { UrlMapping } from "./models/UrlMapping"; -import { remove, writeFileSync } from "../utils/fs"; +import { writeFileSync } from "../utils/fs"; import { DefaultTheme } from "./themes/default/DefaultTheme"; import { RendererComponent } from "./components"; import { Component, ChildableComponent } from "../utils/component"; @@ -337,7 +337,10 @@ export class Renderer extends ChildableComponent< private async prepareOutputDirectory(directory: string): Promise { if (this.cleanOutputDir) { try { - await remove(directory); + await fs.promises.rm(directory, { + recursive: true, + force: true, + }); } catch (error) { this.application.logger.warn( "Could not empty the output directory." diff --git a/src/lib/utils/fs.ts b/src/lib/utils/fs.ts index 769779851..8e0ecf658 100644 --- a/src/lib/utils/fs.ts +++ b/src/lib/utils/fs.ts @@ -133,20 +133,6 @@ export function copySync(src: string, dest: string): void { } } -/** - * Equivalent to rm -rf - * @param target - */ -export async function remove(target: string) { - // Since v14.14 - if (fsp.rm) { - await fsp.rm(target, { recursive: true, force: true }); - } else if (fs.existsSync(target)) { - // Ew. We shouldn't need the exists check... Can't wait for Node 14. - await fsp.rmdir(target, { recursive: true }); - } -} - /** * Simpler version of `glob.sync` that only covers our use cases, only ever matching files, and ignoring node_modules. */ diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 43a760e5b..f7a8e508a 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -14,7 +14,6 @@ export { getCommonDirectory, normalizePath, readFile, - remove, writeFile, writeFileSync, } from "./fs"; diff --git a/src/test/capture-screenshots.ts b/src/test/capture-screenshots.ts index 274ee194f..eb303b801 100644 --- a/src/test/capture-screenshots.ts +++ b/src/test/capture-screenshots.ts @@ -2,7 +2,6 @@ import * as fs from "fs"; import { platform } from "os"; import { resolve, join, dirname, relative } from "path"; import { Application, TSConfigReader, EntryPointStrategy } from ".."; -import { remove } from "../lib/utils"; import { glob } from "../lib/utils/fs"; // The @types package plays badly with non-dom packages. @@ -71,7 +70,7 @@ export async function captureRegressionScreenshots() { }); const project = app.convert(); if (!project) throw new Error("Failed to convert."); - await remove(outputDirectory); + await fs.promises.rm(outputDirectory, { recursive: true, force: true }); await app.generateDocs(project, baseDirectory); await captureScreenshots(baseDirectory, outputDirectory);