From 3a823abcc554cffdda1e14e181dadad9063701de Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Sun, 4 Apr 2021 18:06:02 +0200 Subject: [PATCH] refactor(compiler): remove dependency on fs-extra (#41445) Currently, fs-extra is used to delete a directory recursively, but this is already available in native Node.JS. Hence, making this dependency redundant. See: https://nodejs.org/docs/latest-v12.x/api/fs.html PR Close #41445 --- package.json | 2 -- packages/compiler-cli/BUILD.bazel | 1 - .../compiler-cli/integrationtest/BUILD.bazel | 1 - .../compiler-cli/integrationtest/test_helpers.js | 1 - packages/compiler-cli/package.json | 1 - .../src/ngtsc/file_system/BUILD.bazel | 2 -- .../ngtsc/file_system/src/node_js_file_system.ts | 3 +-- .../src/ngtsc/file_system/test/BUILD.bazel | 1 - .../file_system/test/node_js_file_system_spec.ts | 7 +++---- yarn.lock | 16 ---------------- 10 files changed, 4 insertions(+), 31 deletions(-) diff --git a/package.json b/package.json index 19ce6d6b80..c62b1d95ae 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,6 @@ "@types/convert-source-map": "^1.5.1", "@types/diff": "^3.5.1", "@types/events": "3.0.0", - "@types/fs-extra": "4.0.2", "@types/hammerjs": "2.0.35", "@types/inquirer": "^7.3.0", "@types/jasmine": "3.5.10", @@ -121,7 +120,6 @@ "dependency-graph": "^0.7.2", "diff": "^3.5.0", "domino": "2.1.2", - "fs-extra": "4.0.2", "google-closure-compiler": "20200517.0.0", "hammerjs": "2.0.8", "http-server": "^0.12.3", diff --git a/packages/compiler-cli/BUILD.bazel b/packages/compiler-cli/BUILD.bazel index fe4758ee91..501d2cae2d 100644 --- a/packages/compiler-cli/BUILD.bazel +++ b/packages/compiler-cli/BUILD.bazel @@ -41,7 +41,6 @@ ts_library( "@npm//@bazel/typescript", "@npm//@types/node", "@npm//chokidar", - "@npm//fs-extra", "@npm//minimist", "@npm//reflect-metadata", "@npm//tsickle", diff --git a/packages/compiler-cli/integrationtest/BUILD.bazel b/packages/compiler-cli/integrationtest/BUILD.bazel index 90f5766c14..6738affeb2 100644 --- a/packages/compiler-cli/integrationtest/BUILD.bazel +++ b/packages/compiler-cli/integrationtest/BUILD.bazel @@ -31,7 +31,6 @@ nodejs_test( "@nodejs//:node", "@npm//domino", "@npm//chokidar", - "@npm//fs-extra", "@npm//source-map-support", "@npm//shelljs", "@npm//typescript", diff --git a/packages/compiler-cli/integrationtest/test_helpers.js b/packages/compiler-cli/integrationtest/test_helpers.js index 8a3c0d7630..c3dbb25c0f 100644 --- a/packages/compiler-cli/integrationtest/test_helpers.js +++ b/packages/compiler-cli/integrationtest/test_helpers.js @@ -46,7 +46,6 @@ const requiredNodeModules = { 'tslib': resolveNpmTreeArtifact('npm/node_modules/tslib'), 'domino': resolveNpmTreeArtifact('npm/node_modules/domino'), 'xhr2': resolveNpmTreeArtifact('npm/node_modules/xhr2'), - 'fs-extra': resolveNpmTreeArtifact('npm/node_modules/fs-extra'), // Fine grained dependencies which are used by the integration test Angular modules, and // need to be symlinked so that they can be resolved by NodeJS or NGC. diff --git a/packages/compiler-cli/package.json b/packages/compiler-cli/package.json index a6c2a4c3c3..93d936c6d6 100644 --- a/packages/compiler-cli/package.json +++ b/packages/compiler-cli/package.json @@ -19,7 +19,6 @@ "chokidar": "^3.0.0", "convert-source-map": "^1.5.1", "dependency-graph": "^0.7.2", - "fs-extra": "4.0.2", "magic-string": "^0.25.0", "semver": "^6.3.0", "source-map": "^0.6.1", diff --git a/packages/compiler-cli/src/ngtsc/file_system/BUILD.bazel b/packages/compiler-cli/src/ngtsc/file_system/BUILD.bazel index b40ffa15fb..1dc56c80e7 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/file_system/BUILD.bazel @@ -8,9 +8,7 @@ ts_library( "src/**/*.ts", ]), deps = [ - "@npm//@types/fs-extra", "@npm//@types/node", - "@npm//fs-extra", "@npm//typescript", ], ) diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts index 12c91285c8..b9556b5043 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts @@ -7,7 +7,6 @@ */ /// import * as fs from 'fs'; -import * as fsExtra from 'fs-extra'; import * as p from 'path'; import {AbsoluteFsPath, FileStats, FileSystem, PathManipulation, PathSegment, PathString, ReadonlyFileSystem} from './types'; @@ -121,7 +120,7 @@ export class NodeJSFileSystem extends NodeJSReadonlyFileSystem implements FileSy } } removeDeep(path: AbsoluteFsPath): void { - fsExtra.removeSync(path); + fs.rmdirSync(path, {recursive: true}); } private safeMkdir(path: AbsoluteFsPath): void { diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/BUILD.bazel b/packages/compiler-cli/src/ngtsc/file_system/test/BUILD.bazel index ed75bf3eda..4cdee34cae 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/test/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/file_system/test/BUILD.bazel @@ -11,7 +11,6 @@ ts_library( deps = [ "//packages/compiler-cli/src/ngtsc/file_system", "//packages/compiler-cli/src/ngtsc/file_system/testing", - "@npm//@types/fs-extra", "@npm//typescript", ], ) diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts index 4cd7cfb60c..dc9dbf4362 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ import * as realFs from 'fs'; -import * as fsExtra from 'fs-extra'; import * as os from 'os'; import {NodeJSFileSystem, NodeJSPathManipulation, NodeJSReadonlyFileSystem} from '../src/node_js_file_system'; import {AbsoluteFsPath, PathSegment} from '../src/types'; @@ -269,10 +268,10 @@ describe('NodeJSFileSystem', () => { }); describe('removeDeep()', () => { - it('should delegate to fsExtra.remove()', () => { - const spy = spyOn(fsExtra, 'removeSync'); + it('should delegate to rmdirSync()', () => { + const spy = spyOn(realFs, 'rmdirSync'); fs.removeDeep(abcPath); - expect(spy).toHaveBeenCalledWith(abcPath); + expect(spy).toHaveBeenCalledWith(abcPath, {recursive: true}); }); }); }); diff --git a/yarn.lock b/yarn.lock index 02ea965bfa..b1bcea3925 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2601,13 +2601,6 @@ resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== -"@types/fs-extra@4.0.2": - version "4.0.2" - resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-4.0.2.tgz#7b9b1bbf85962cbe029b5a83c9b530d7c75af3ba" - integrity sha512-Id1hnmfd+7G9K+jWz2syfMcpymx2mj6B1y4C72vAoYQzxOA79UhY/kNvOCyb9yYR1SoSaHyhwcYtWKKqUiLTZA== - dependencies: - "@types/node" "*" - "@types/fs-extra@^8.0.1": version "8.1.0" resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.0.tgz#1114834b53c3914806cd03b3304b37b3bd221a4d" @@ -7528,15 +7521,6 @@ fs-constants@^1.0.0: resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow== -fs-extra@4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.2.tgz#f91704c53d1b461f893452b0c307d9997647ab6b" - integrity sha1-+RcExT0bRh+JNFKwwwfZmXZHq2s= - dependencies: - graceful-fs "^4.1.2" - jsonfile "^4.0.0" - universalify "^0.1.0" - fs-extra@^0.23.1: version "0.23.1" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.23.1.tgz#6611dba6adf2ab8dc9c69fab37cddf8818157e3d"