From 405b22e4a2f09d485ec0eede25b65a1544f2af9d Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Sat, 24 Feb 2024 18:16:46 +0100 Subject: [PATCH] refactor: use `fs/promises` instead of `rimraf` package refactor to use the `rm()` method instead of the `rimraf` package. Also moved the `deleteOutDirIfEnabled()` method from the WorkspaceUtils class into its own file inside the helper directory because it is the only method of the class. --- actions/build.action.ts | 9 +-- lib/compiler/helpers/delete-out-dir.ts | 19 +++++ lib/compiler/workspace-utils.ts | 21 ----- package-lock.json | 107 ------------------------- package.json | 1 - 5 files changed, 21 insertions(+), 136 deletions(-) create mode 100644 lib/compiler/helpers/delete-out-dir.ts delete mode 100644 lib/compiler/workspace-utils.ts diff --git a/actions/build.action.ts b/actions/build.action.ts index 52cd5150a..100e0fe43 100644 --- a/actions/build.action.ts +++ b/actions/build.action.ts @@ -10,7 +10,7 @@ import { getWebpackConfigPath } from '../lib/compiler/helpers/get-webpack-config import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider'; import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader'; import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader'; -import { WorkspaceUtils } from '../lib/compiler/workspace-utils'; +import { deleteOutDirIfEnabled } from '../lib/compiler/helpers/delete-out-dir'; import { Configuration, ConfigurationLoader, @@ -34,7 +34,6 @@ export class BuildAction extends AbstractAction { this.fileSystemReader, ); protected readonly assetsManager = new AssetsManager(); - protected readonly workspaceUtils = new WorkspaceUtils(); public async handle(commandInputs: Input[], commandOptions: Input[]) { try { @@ -101,11 +100,7 @@ export class BuildAction extends AbstractAction { ? { type: 'webpack' } : getBuilder(configuration, commandOptions, appName); - await this.workspaceUtils.deleteOutDirIfEnabled( - configuration, - appName, - outDir, - ); + await deleteOutDirIfEnabled(configuration, appName, outDir); this.assetsManager.copyAssets( configuration, appName, diff --git a/lib/compiler/helpers/delete-out-dir.ts b/lib/compiler/helpers/delete-out-dir.ts new file mode 100644 index 000000000..de5a64fad --- /dev/null +++ b/lib/compiler/helpers/delete-out-dir.ts @@ -0,0 +1,19 @@ +import { rm } from 'fs/promises'; +import { Configuration } from '../../configuration'; +import { getValueOrDefault } from './get-value-or-default'; + +export async function deleteOutDirIfEnabled( + configuration: Required, + appName: string, + dirPath: string, +) { + const isDeleteEnabled = getValueOrDefault( + configuration, + 'compilerOptions.deleteOutDir', + appName, + ); + if (!isDeleteEnabled) { + return; + } + await rm(dirPath, { recursive: true, force: true }); +} diff --git a/lib/compiler/workspace-utils.ts b/lib/compiler/workspace-utils.ts deleted file mode 100644 index 755ad7653..000000000 --- a/lib/compiler/workspace-utils.ts +++ /dev/null @@ -1,21 +0,0 @@ -import rimraf from 'rimraf'; -import { Configuration } from '../configuration'; -import { getValueOrDefault } from './helpers/get-value-or-default'; - -export class WorkspaceUtils { - public async deleteOutDirIfEnabled( - configuration: Required, - appName: string, - dirPath: string, - ) { - const isDeleteEnabled = getValueOrDefault( - configuration, - 'compilerOptions.deleteOutDir', - appName, - ); - if (!isDeleteEnabled) { - return; - } - await rimraf(dirPath); - } -} diff --git a/package-lock.json b/package-lock.json index d76aa8067..4ec87a835 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,6 @@ "inquirer": "8.2.6", "node-emoji": "1.11.0", "ora": "5.4.1", - "rimraf": "4.4.1", "shelljs": "0.8.5", "source-map-support": "0.5.21", "tree-kill": "1.2.2", @@ -11124,14 +11123,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/minipass": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz", - "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==", - "engines": { - "node": ">=8" - } - }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -13213,62 +13204,6 @@ "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==", "dev": true }, - "node_modules/rimraf": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.1.tgz", - "integrity": "sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og==", - "dependencies": { - "glob": "^9.2.0" - }, - "bin": { - "rimraf": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/rimraf/node_modules/glob": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.2.tgz", - "integrity": "sha512-BTv/JhKXFEHsErMte/AnfiSv8yYOLLiyH2lTg8vn02O21zWFgHPTfxtgn1QRe7NRgggUhC8hacR2Re94svHqeA==", - "dependencies": { - "fs.realpath": "^1.0.0", - "minimatch": "^7.4.1", - "minipass": "^4.2.4", - "path-scurry": "^1.6.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.3.tgz", - "integrity": "sha512-5UB4yYusDtkRPbRiy1cqZ1IpGNcJCGlEMG17RKzPddpyiPKoCdwohbED8g4QXT0ewCt8LTkQXuljsUfQ3FKM4A==", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/run-applescript": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", @@ -23430,11 +23365,6 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==" }, - "minipass": { - "version": "4.2.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz", - "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==" - }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -24887,43 +24817,6 @@ "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==", "dev": true }, - "rimraf": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-4.4.1.tgz", - "integrity": "sha512-Gk8NlF062+T9CqNGn6h4tls3k6T1+/nXdOcSZVikNVtlRdYpA7wRJJMoXmuvOnLW844rPjdQ7JgXCYM6PPC/og==", - "requires": { - "glob": "^9.2.0" - }, - "dependencies": { - "brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "requires": { - "balanced-match": "^1.0.0" - } - }, - "glob": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/glob/-/glob-9.3.2.tgz", - "integrity": "sha512-BTv/JhKXFEHsErMte/AnfiSv8yYOLLiyH2lTg8vn02O21zWFgHPTfxtgn1QRe7NRgggUhC8hacR2Re94svHqeA==", - "requires": { - "fs.realpath": "^1.0.0", - "minimatch": "^7.4.1", - "minipass": "^4.2.4", - "path-scurry": "^1.6.1" - } - }, - "minimatch": { - "version": "7.4.3", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.3.tgz", - "integrity": "sha512-5UB4yYusDtkRPbRiy1cqZ1IpGNcJCGlEMG17RKzPddpyiPKoCdwohbED8g4QXT0ewCt8LTkQXuljsUfQ3FKM4A==", - "requires": { - "brace-expansion": "^2.0.1" - } - } - } - }, "run-applescript": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", diff --git a/package.json b/package.json index 96d330edb..a5df2f15b 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,6 @@ "inquirer": "8.2.6", "node-emoji": "1.11.0", "ora": "5.4.1", - "rimraf": "4.4.1", "shelljs": "0.8.5", "source-map-support": "0.5.21", "tree-kill": "1.2.2",