From 9dfa4dbbef93a3051e1aa8adc3cbc5846c50e0bb Mon Sep 17 00:00:00 2001 From: pralkarz <31964869+ziebam@users.noreply.github.com> Date: Fri, 27 Sep 2024 04:27:34 +0200 Subject: [PATCH] cleanup(nx-plugin): replace `fs-extra` with `node:fs` (#28133) --- packages/plugin/.eslintrc.json | 10 ++++++- packages/plugin/package.json | 1 - .../src/utils/testing-utils/nx-project.ts | 4 +-- .../plugin/src/utils/testing-utils/utils.ts | 28 +++++++++++-------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/packages/plugin/.eslintrc.json b/packages/plugin/.eslintrc.json index b832b47538..d71be5d4b2 100644 --- a/packages/plugin/.eslintrc.json +++ b/packages/plugin/.eslintrc.json @@ -5,7 +5,15 @@ "overrides": [ { "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} + "rules": { + "no-restricted-imports": [ + "error", + { + "name": "fs-extra", + "message": "Please use equivalent utilities from `node:fs` instead." + } + ] + } }, { "files": ["*.ts", "*.tsx"], diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 0ab79ddb1c..40c90ef60e 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -27,7 +27,6 @@ "migrations": "./migrations.json" }, "dependencies": { - "fs-extra": "^11.1.0", "tslib": "^2.3.0", "@nx/devkit": "file:../devkit", "@nx/jest": "file:../jest", diff --git a/packages/plugin/src/utils/testing-utils/nx-project.ts b/packages/plugin/src/utils/testing-utils/nx-project.ts index 6f432da98f..d3bca8f314 100644 --- a/packages/plugin/src/utils/testing-utils/nx-project.ts +++ b/packages/plugin/src/utils/testing-utils/nx-project.ts @@ -5,8 +5,8 @@ import { writeJsonFile, } from '@nx/devkit'; import { execSync } from 'child_process'; +import { mkdirSync } from 'node:fs'; import { dirname } from 'path'; -import { ensureDirSync } from 'fs-extra'; import { tmpProjPath } from './paths'; import { cleanup } from './utils'; @@ -85,6 +85,6 @@ export function ensureNxProject( npmPackageName?: string, pluginDistPath?: string ): void { - ensureDirSync(tmpProjPath()); + mkdirSync(tmpProjPath(), { recursive: true }); newNxProject(npmPackageName, pluginDistPath); } diff --git a/packages/plugin/src/utils/testing-utils/utils.ts b/packages/plugin/src/utils/testing-utils/utils.ts index 33e1c1a341..278f100cf9 100644 --- a/packages/plugin/src/utils/testing-utils/utils.ts +++ b/packages/plugin/src/utils/testing-utils/utils.ts @@ -1,13 +1,13 @@ import { - copySync, - ensureDirSync, + cpSync, + mkdirSync, readdirSync, readFileSync, - removeSync, renameSync, + rmSync, statSync, writeFileSync, -} from 'fs-extra'; +} from 'node:fs'; import { dirname, isAbsolute } from 'path'; import { tmpFolder, tmpProjPath } from './paths'; import { parseJson } from '@nx/devkit'; @@ -22,10 +22,14 @@ export { directoryExists, fileExists }; */ export function copyNodeModules(modules: string[]) { modules.forEach((module) => { - removeSync(`${tmpProjPath()}/node_modules/${module}`); - copySync( + rmSync(`${tmpProjPath()}/node_modules/${module}`, { + recursive: true, + force: true, + }); + cpSync( `./node_modules/${module}`, - `${tmpProjPath()}/node_modules/${module}` + `${tmpProjPath()}/node_modules/${module}`, + { recursive: true } ); }); } @@ -54,7 +58,7 @@ export function updateFile( file: string, content: string | ((originalFileContent: string) => string) ): void { - ensureDirSync(dirname(tmpProjPath(file))); + mkdirSync(dirname(tmpProjPath(file)), { recursive: true }); if (typeof content === 'string') { writeFileSync(tmpProjPath(file), content); } else { @@ -71,7 +75,7 @@ export function updateFile( * @param newPath New path */ export function renameFile(path: string, newPath: string): void { - ensureDirSync(dirname(tmpProjPath(newPath))); + mkdirSync(dirname(tmpProjPath(newPath)), { recursive: true }); renameSync(tmpProjPath(path), tmpProjPath(newPath)); } @@ -125,18 +129,18 @@ export function readFile(path: string): string { * Deletes the e2e directory */ export function cleanup(): void { - removeSync(tmpProjPath()); + rmSync(tmpProjPath(), { recursive: true, force: true }); } /** * Remove the dist folder from the e2e directory */ export function rmDist(): void { - removeSync(`${tmpProjPath()}/dist`); + rmSync(`${tmpProjPath()}/dist`, { recursive: true, force: true }); } export function removeTmpProject(project: string): void { - removeSync(`${tmpFolder()}/${project}`); + rmSync(`${tmpFolder()}/${project}`, { recursive: true, force: true }); } /**