From 5a2363e82185c21c374c7ab56b156733171b03f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Sun, 12 Mar 2023 14:46:40 +0100 Subject: [PATCH] refactor: use builtin `fs/promises` instead of `fs-extra` --- package.json | 2 -- src/bundler.ts | 14 ++++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 17791c51..ebdfdcdf 100644 --- a/package.json +++ b/package.json @@ -63,11 +63,9 @@ "@adonisjs/env": "^4.2.0-0", "@poppinss/chokidar-ts": "^4.1.0-1", "@poppinss/cliui": "^6.1.1-1", - "@types/fs-extra": "^11.0.1", "@types/picomatch": "^2.3.0", "cpy": "^9.0.1", "execa": "^7.0.0", - "fs-extra": "^11.1.0", "get-port": "^6.1.2", "picomatch": "^2.3.1", "slash": "^5.0.0" diff --git a/src/bundler.ts b/src/bundler.ts index e8026b85..23f82065 100644 --- a/src/bundler.ts +++ b/src/bundler.ts @@ -7,10 +7,10 @@ * file that was distributed with this source code. */ -import fs from 'fs-extra' import slash from 'slash' import copyfiles from 'cpy' import type tsStatic from 'typescript' +import fs from 'node:fs/promises' import { fileURLToPath } from 'node:url' import { join, relative } from 'node:path' import { cliui, type Logger } from '@poppinss/cliui' @@ -56,7 +56,7 @@ export class Bundler { * Cleans up the build directory */ async #cleanupBuildDirectory(outDir: string) { - await fs.remove(outDir) + await fs.rm(outDir, { recursive: true, force: true, maxRetries: 5 }) } /** @@ -125,13 +125,19 @@ export class Bundler { * Copies .adonisrc.json file to the destination */ async #copyAdonisRcFile(outDir: string) { - const existingContents = await fs.readJSON(join(this.#cwdPath, '.adonisrc.json')) + const existingContents = JSON.parse( + await fs.readFile(join(this.#cwdPath, '.adonisrc.json'), 'utf-8') + ) const compiledContents = Object.assign({}, existingContents, { typescript: false, lastCompiledAt: new Date().toISOString(), }) - await fs.outputJSON(join(outDir, '.adonisrc.json'), compiledContents, { spaces: 2 }) + await fs.mkdir(outDir, { recursive: true }) + await fs.writeFile( + join(outDir, '.adonisrc.json'), + JSON.stringify(compiledContents, null, 2) + '\n' + ) } /**