Skip to content

Commit

Permalink
cleanup(nx-plugin): replace fs-extra with node:fs (#28133)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9dfa4db)
  • Loading branch information
ziebam authored and FrozenPandaz committed Sep 27, 2024
1 parent c247067 commit edbc4b2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
10 changes: 9 additions & 1 deletion packages/plugin/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
1 change: 0 additions & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/utils/testing-utils/nx-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -85,6 +85,6 @@ export function ensureNxProject(
npmPackageName?: string,
pluginDistPath?: string
): void {
ensureDirSync(tmpProjPath());
mkdirSync(tmpProjPath(), { recursive: true });
newNxProject(npmPackageName, pluginDistPath);
}
28 changes: 16 additions & 12 deletions packages/plugin/src/utils/testing-utils/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 }
);
});
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
}

Expand Down Expand Up @@ -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 });
}

/**
Expand Down

0 comments on commit edbc4b2

Please sign in to comment.