cleanup(nx-plugin): replace fs-extra with node:fs (#28133)

This commit is contained in:
pralkarz 2024-09-27 04:27:34 +02:00 committed by GitHub
parent 7da6f85734
commit 9dfa4dbbef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 16 deletions

View File

@ -5,7 +5,15 @@
"overrides": [ "overrides": [
{ {
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], "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"], "files": ["*.ts", "*.tsx"],

View File

@ -27,7 +27,6 @@
"migrations": "./migrations.json" "migrations": "./migrations.json"
}, },
"dependencies": { "dependencies": {
"fs-extra": "^11.1.0",
"tslib": "^2.3.0", "tslib": "^2.3.0",
"@nx/devkit": "file:../devkit", "@nx/devkit": "file:../devkit",
"@nx/jest": "file:../jest", "@nx/jest": "file:../jest",

View File

@ -5,8 +5,8 @@ import {
writeJsonFile, writeJsonFile,
} from '@nx/devkit'; } from '@nx/devkit';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { mkdirSync } from 'node:fs';
import { dirname } from 'path'; import { dirname } from 'path';
import { ensureDirSync } from 'fs-extra';
import { tmpProjPath } from './paths'; import { tmpProjPath } from './paths';
import { cleanup } from './utils'; import { cleanup } from './utils';
@ -85,6 +85,6 @@ export function ensureNxProject(
npmPackageName?: string, npmPackageName?: string,
pluginDistPath?: string pluginDistPath?: string
): void { ): void {
ensureDirSync(tmpProjPath()); mkdirSync(tmpProjPath(), { recursive: true });
newNxProject(npmPackageName, pluginDistPath); newNxProject(npmPackageName, pluginDistPath);
} }

View File

@ -1,13 +1,13 @@
import { import {
copySync, cpSync,
ensureDirSync, mkdirSync,
readdirSync, readdirSync,
readFileSync, readFileSync,
removeSync,
renameSync, renameSync,
rmSync,
statSync, statSync,
writeFileSync, writeFileSync,
} from 'fs-extra'; } from 'node:fs';
import { dirname, isAbsolute } from 'path'; import { dirname, isAbsolute } from 'path';
import { tmpFolder, tmpProjPath } from './paths'; import { tmpFolder, tmpProjPath } from './paths';
import { parseJson } from '@nx/devkit'; import { parseJson } from '@nx/devkit';
@ -22,10 +22,14 @@ export { directoryExists, fileExists };
*/ */
export function copyNodeModules(modules: string[]) { export function copyNodeModules(modules: string[]) {
modules.forEach((module) => { modules.forEach((module) => {
removeSync(`${tmpProjPath()}/node_modules/${module}`); rmSync(`${tmpProjPath()}/node_modules/${module}`, {
copySync( recursive: true,
force: true,
});
cpSync(
`./node_modules/${module}`, `./node_modules/${module}`,
`${tmpProjPath()}/node_modules/${module}` `${tmpProjPath()}/node_modules/${module}`,
{ recursive: true }
); );
}); });
} }
@ -54,7 +58,7 @@ export function updateFile(
file: string, file: string,
content: string | ((originalFileContent: string) => string) content: string | ((originalFileContent: string) => string)
): void { ): void {
ensureDirSync(dirname(tmpProjPath(file))); mkdirSync(dirname(tmpProjPath(file)), { recursive: true });
if (typeof content === 'string') { if (typeof content === 'string') {
writeFileSync(tmpProjPath(file), content); writeFileSync(tmpProjPath(file), content);
} else { } else {
@ -71,7 +75,7 @@ export function updateFile(
* @param newPath New path * @param newPath New path
*/ */
export function renameFile(path: string, newPath: string): void { export function renameFile(path: string, newPath: string): void {
ensureDirSync(dirname(tmpProjPath(newPath))); mkdirSync(dirname(tmpProjPath(newPath)), { recursive: true });
renameSync(tmpProjPath(path), tmpProjPath(newPath)); renameSync(tmpProjPath(path), tmpProjPath(newPath));
} }
@ -125,18 +129,18 @@ export function readFile(path: string): string {
* Deletes the e2e directory * Deletes the e2e directory
*/ */
export function cleanup(): void { export function cleanup(): void {
removeSync(tmpProjPath()); rmSync(tmpProjPath(), { recursive: true, force: true });
} }
/** /**
* Remove the dist folder from the e2e directory * Remove the dist folder from the e2e directory
*/ */
export function rmDist(): void { export function rmDist(): void {
removeSync(`${tmpProjPath()}/dist`); rmSync(`${tmpProjPath()}/dist`, { recursive: true, force: true });
} }
export function removeTmpProject(project: string): void { export function removeTmpProject(project: string): void {
removeSync(`${tmpFolder()}/${project}`); rmSync(`${tmpFolder()}/${project}`, { recursive: true, force: true });
} }
/** /**