diff --git a/packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/convert-profiles/cli.imperative-test-cli.config.convert-profiles.integration.subtest.ts b/packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/convert-profiles/cli.imperative-test-cli.config.convert-profiles.integration.subtest.ts index 8025b02006..2d222e1ad5 100644 --- a/packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/convert-profiles/cli.imperative-test-cli.config.convert-profiles.integration.subtest.ts +++ b/packages/imperative/__tests__/__integration__/imperative/__tests__/__integration__/cli/config/convert-profiles/cli.imperative-test-cli.config.convert-profiles.integration.subtest.ts @@ -46,7 +46,7 @@ describe("imperative-test-cli config convert-profiles", () => { if (fs.existsSync(configJsonPath)) { fs.unlinkSync(configJsonPath); } - fsExtra.removeSync(TEST_ENVIRONMENT.workingDir + "/profiles-old"); + fs.rmSync(TEST_ENVIRONMENT.workingDir + "/profiles-old", {recursive: true, force: true}); }); it("should display the help", () => { diff --git a/packages/imperative/__tests__/__src__/environment/SetupTestEnvironment.ts b/packages/imperative/__tests__/__src__/environment/SetupTestEnvironment.ts index 2f65efca32..d28432513f 100644 --- a/packages/imperative/__tests__/__src__/environment/SetupTestEnvironment.ts +++ b/packages/imperative/__tests__/__src__/environment/SetupTestEnvironment.ts @@ -13,7 +13,7 @@ import { ISetupEnvironmentParms } from "./doc/parms/ISetupEnvironmentParms"; import { ImperativeExpect } from "../../../src"; import * as nodePath from "path"; import { TEST_RESULT_DATA_DIR } from "../TestConstants"; -import { mkdirpSync } from "fs-extra"; +import { mkdirSync } from "fs"; import { ITestEnvironment } from "./doc/response/ITestEnvironment"; import { v4 as uuidv4 } from "uuid"; @@ -80,7 +80,7 @@ export class SetupTestEnvironment { public static createUniqueTestDataDir(testName: string): string { const app = uuidv4() + "_" + testName + "/"; const path = nodePath.resolve(TEST_RESULT_DATA_DIR + "/" + app); - mkdirpSync(path); + mkdirSync(path, {recursive: true}); return path; } } diff --git a/packages/imperative/__tests__/src/TestUtil.ts b/packages/imperative/__tests__/src/TestUtil.ts index 1f2693f558..1e74262900 100644 --- a/packages/imperative/__tests__/src/TestUtil.ts +++ b/packages/imperative/__tests__/src/TestUtil.ts @@ -24,7 +24,6 @@ import { ICommandResponse } from "../../src/cmd"; import { ICompareParms } from "./doc/ICompareParms"; import { TestLogger } from "./TestLogger"; import * as nodePath from "path"; -import { mkdirpSync } from "fs-extra"; import * as fs from "fs"; import { randomBytes } from "crypto"; import * as os from "os"; @@ -410,7 +409,7 @@ export function compareJsonObjects(actual: any, expected: any, parms?: ICompareP export function createUniqueTestDataDir(append = ""): string { const app = uuidv4() + "/" + append + "/"; const path = nodePath.resolve(TEST_RESULT_DIR + "/data/" + app); - mkdirpSync(path); + fs.mkdirSync(path, {recursive: true}); return path; } diff --git a/packages/imperative/src/config/__tests__/ConvertV1Profiles.unit.test.ts b/packages/imperative/src/config/__tests__/ConvertV1Profiles.unit.test.ts index a842f4e953..7b672387ae 100644 --- a/packages/imperative/src/config/__tests__/ConvertV1Profiles.unit.test.ts +++ b/packages/imperative/src/config/__tests__/ConvertV1Profiles.unit.test.ts @@ -12,7 +12,6 @@ jest.mock("jsonfile"); import * as fs from "fs"; -import * as fsExtra from "fs-extra"; import * as jsonfile from "jsonfile"; import { CredentialManagerFactory } from "../.."; import { ConvertV1Profiles } from "../"; @@ -834,7 +833,7 @@ describe("ConvertV1Profiles tests", () => { beforeAll(() => { ConvertV1Profiles["oldProfilesDir"] = oldProfileDir; existsSyncSpy = jest.spyOn(fs, "existsSync"); - removeSyncSpy = jest.spyOn(fsExtra, "removeSync"); + removeSyncSpy = jest.spyOn(fs, "rmSync"); }); beforeEach(() => { @@ -907,7 +906,7 @@ describe("ConvertV1Profiles tests", () => { existsSyncSpy.mockReturnValue(true); // pretend that remove crashed - const removeError = "fsExtra.removeSync threw a horrible error"; + const removeError = "fs.rmSync threw a horrible error"; removeSyncSpy.mockImplementation(() => { throw new Error(removeError); }); diff --git a/packages/imperative/src/config/src/ConvertV1Profiles.ts b/packages/imperative/src/config/src/ConvertV1Profiles.ts index 7fcc7e1bd5..deddb1438d 100644 --- a/packages/imperative/src/config/src/ConvertV1Profiles.ts +++ b/packages/imperative/src/config/src/ConvertV1Profiles.ts @@ -12,7 +12,6 @@ import * as fs from "fs"; import * as path from "path"; import { readFileSync } from "jsonfile"; -import { removeSync } from "fs-extra"; import stripAnsi = require("strip-ansi"); import { V1ProfileRead, ProfilesConstants, ProfileUtils } from "../../profiles"; import { Config } from "./Config"; @@ -446,7 +445,7 @@ export class ConvertV1Profiles { // Delete the profiles directory try { if (fs.existsSync(ConvertV1Profiles.oldProfilesDir)) { - removeSync(ConvertV1Profiles.oldProfilesDir); + fs.rmSync(ConvertV1Profiles.oldProfilesDir, {recursive: true}); ConvertV1Profiles.addToConvertMsgs( ConvertMsgFmt.REPORT_LINE | ConvertMsgFmt.PARAGRAPH, `Deleted the old profiles directory ${ConvertV1Profiles.oldProfilesDir}.` diff --git a/packages/imperative/src/imperative/__tests__/plugins/PluginManagementFacility.unit.test.ts b/packages/imperative/src/imperative/__tests__/plugins/PluginManagementFacility.unit.test.ts index 35dd35707e..90db06ae8d 100644 --- a/packages/imperative/src/imperative/__tests__/plugins/PluginManagementFacility.unit.test.ts +++ b/packages/imperative/src/imperative/__tests__/plugins/PluginManagementFacility.unit.test.ts @@ -44,7 +44,7 @@ describe("Plugin Management Facility", () => { existsSync: jest.spyOn(fs, "existsSync"), writeFileSync: jest.spyOn(jsonfile, "writeFileSync"), readFileSync: jest.spyOn(jsonfile, "readFileSync"), - mkdirp: jest.spyOn(IO, "mkdirp") + mkdirp: jest.spyOn(IO, "createDirSync") }; /* Put a base CLI config into ImperativeConfig. It is required by infrastructure diff --git a/packages/imperative/src/io/__tests__/IO.unit.test.ts b/packages/imperative/src/io/__tests__/IO.unit.test.ts index 7651d9042f..d2cf071737 100644 --- a/packages/imperative/src/io/__tests__/IO.unit.test.ts +++ b/packages/imperative/src/io/__tests__/IO.unit.test.ts @@ -119,17 +119,6 @@ describe("IO tests", () => { expect(fnFm).toHaveBeenCalled(); }); - it("should not create a dir if file exists", () => { - existsSyncSpy = jest.spyOn(fs, "existsSync").mockReturnValue(true); - const fnFm = jest.mocked(fs.mkdirSync); - fnFm.mockImplementation(((file: fs.PathLike) => { - return; // do nothing but pretend to write - }) as any); - IO.createDirSync("pretend/already/exists"); - expect(existsSyncSpy).toHaveBeenCalled(); - expect(fnFm).not.toHaveBeenCalled(); - }); - it("should get an error for no input on createDirsSync", () => { let error; try { @@ -155,45 +144,7 @@ describe("IO tests", () => { const dir = willBeADir.join(path.posix.sep); // eslint-disable-next-line deprecation/deprecation IO.createDirsSync(dir); - expect(fnFm).toHaveBeenCalledTimes(willBeADir.length); - }); - - it("should not create several dirs if dirs already exist", () => { - existsSyncSpy = jest.spyOn(fs, "existsSync").mockReturnValue(true); - const fnFm = jest.mocked(fs.mkdirSync); - fnFm.mockImplementation(((file: fs.PathLike) => { - return; // do nothing but pretend to write - }) as any); - const fnPr = jest.mocked(path.resolve); - fnPr.mockImplementation((...pathSegments: any[]) => { - return pathSegments[0]; - }); - const willBeADir = ["pretend", "to", "create"]; - const dir = willBeADir.join(path.posix.sep); - // eslint-disable-next-line deprecation/deprecation - IO.createDirsSync(dir); - expect(fnFm).not.toHaveBeenCalled(); - }); - - it("should only create dirs that do not exist", () => { - // pretend that only one of our directories exist - const willBeADir = ["pretend", "to", "create"]; - existsSyncSpy = jest.spyOn(fs, "existsSync") - .mockReturnValue(false) - .mockReturnValueOnce(true); - - const fnFm = jest.mocked(fs.mkdirSync); - fnFm.mockImplementation(((file: fs.PathLike) => { - return; // do nothing but pretend to write - }) as any); - const fnPr = jest.mocked(path.resolve); - fnPr.mockImplementation((...pathSegments: any[]) => { - return pathSegments[0]; - }); - const dir = willBeADir.join(path.posix.sep); - // eslint-disable-next-line deprecation/deprecation - IO.createDirsSync(dir); - expect(fnFm).toHaveBeenCalledTimes(willBeADir.length - 1); + expect(fnFm).toHaveBeenCalledTimes(1); }); it("should create several dirs if dirs do not exist from input file", () => { @@ -215,55 +166,7 @@ describe("IO tests", () => { const willBeADir = ["pretend", "to", "create", "test.txt"]; const dir = willBeADir.join(path.posix.sep); IO.createDirsSyncFromFilePath(dir); - expect(fnFm).toHaveBeenCalledTimes(willBeADir.length - 1); - }); - - it("should not create several dirs if dirs already exist from input file", () => { - existsSyncSpy = jest.spyOn(fs, "existsSync").mockReturnValue(true); - const fnFm = jest.mocked(fs.mkdirSync); - fnFm.mockImplementation(((file: fs.PathLike) => { - return; // do nothing but pretend to write - }) as any); - const fnPr = jest.mocked(path.resolve); - fnPr.mockImplementation((...pathSegments: any[]) => { - return pathSegments[0]; - }); - const fnPd = jest.mocked(path.dirname); - fnPd.mockImplementation(((...pathSegments: any[]) => { - const toDir: string[] = pathSegments[0].split(path.posix.sep); - toDir.pop(); - return toDir.join(path.posix.sep); - }) as any); - const willBeADir = ["pretend", "to", "create", "test.txt"]; - const dir = willBeADir.join(path.posix.sep); - IO.createDirsSyncFromFilePath(dir); - expect(fnFm).not.toHaveBeenCalled(); - }); - - it("should only create dirs that do not exist from input file", () => { - // pretend that only one of our three directories exist - const willBeADir = ["pretend", "to", "create", "test.txt"]; - existsSyncSpy = jest.spyOn(fs, "existsSync") - .mockReturnValue(false) - .mockReturnValueOnce(true); - - const fnFm = jest.mocked(fs.mkdirSync); - fnFm.mockImplementation(((file: fs.PathLike) => { - return; // do nothing but pretend to write - }) as any); - const fnPr = jest.mocked(path.resolve); - fnPr.mockImplementation((...pathSegments: any[]) => { - return pathSegments[0]; - }); - const fnPd = jest.mocked(path.dirname); - fnPd.mockImplementation(((...pathSegments: any[]) => { - const toDir: string[] = pathSegments[0].split(path.posix.sep); - toDir.pop(); - return toDir.join(path.posix.sep); - }) as any); - const dir = willBeADir.join(path.posix.sep); - IO.createDirsSyncFromFilePath(dir); - expect(fnFm).toHaveBeenCalledTimes(willBeADir.length - 2); + expect(fnFm).toHaveBeenCalledTimes(1); }); it("processNewLines should replace LF line endings with CRLF on Windows", () => { diff --git a/packages/imperative/src/io/src/IO.ts b/packages/imperative/src/io/src/IO.ts index e114fbf891..19ad7b658a 100644 --- a/packages/imperative/src/io/src/IO.ts +++ b/packages/imperative/src/io/src/IO.ts @@ -18,7 +18,6 @@ import { ImperativeExpect } from "../../expect"; // use complete path to ExecUtils to avoid circular dependency that results from utilities/index import { ExecUtils } from "../../utilities/src/ExecUtils"; import { Readable, Writable } from "stream"; -import { mkdirpSync } from "fs-extra"; /** * This class will handle common sequences of node I/O and issue messages / @@ -109,7 +108,7 @@ export class IO { } /** - * Create a directory if it does not yet exist synchronously. + * Create a directory and all subdirectories if they do not yet exist synchronously. * @static * @param {string} dir - directory to create * @return {undefined} @@ -130,17 +129,7 @@ export class IO { * @deprecated Please use IO.createDirSync */ public static createDirsSync(dir: string) { - ImperativeExpect.toBeDefinedAndNonBlank(dir, "dir"); - // we're splitting on a specific separator character, so replace \ with / - // before splitting - const dirs = path.resolve(dir).replace(/\\/g, path.posix.sep).split(path.posix.sep); - - let createDir: string = ""; - for (const crDir of dirs) { - - createDir += crDir + path.posix.sep; - IO.createDirSync(createDir); - } + this.createDirSync(dir); } /** @@ -197,7 +186,7 @@ export class IO { } /** - * Uses the fs-extra package to create a directory (and all subdirectories) + * Create a directory and all subdirectories if they do not yet exist synchronously. * @static * @param {string} dir - the directory (do not include a file name) * @memberof IO @@ -205,7 +194,7 @@ export class IO { */ public static mkdirp(dir: string) { ImperativeExpect.toBeDefinedAndNonBlank(dir, "dir"); - mkdirpSync(dir); + this.createDirSync(dir); } /** diff --git a/packages/imperative/src/operations/src/Operation.ts b/packages/imperative/src/operations/src/Operation.ts index 5f66df8652..45340a6a15 100644 --- a/packages/imperative/src/operations/src/Operation.ts +++ b/packages/imperative/src/operations/src/Operation.ts @@ -13,7 +13,6 @@ import { IOperationResult } from "./doc/IOperationResult"; import { TaskStage } from "./TaskStage"; import * as fs from "fs"; -import { removeSync } from "fs-extra"; import { TextUtils } from "../../utilities"; import { ITaskWithStatus } from "./doc/ITaskWithStatus"; import { TaskProgress } from "./TaskProgress"; @@ -475,11 +474,7 @@ export abstract class Operation implements ITaskWithStatus { for (let x = 0; x < order.length; x++) { this.log.info("Cleaning file: " + this.fileToUndo[x]); try { - if (fs.statSync(order[x]).isDirectory()) { - removeSync(order[x]); - } else { - fs.unlinkSync(order[x]); - } + fs.rmSync(order[x]); } catch (error) { this.log.error("An error occurred deleting: " + order[x]); this.log.error("Message: " + error.message); diff --git a/packages/zosjobs/__tests__/__unit__/DeleteJobs.unit.test.ts b/packages/zosjobs/__tests__/__unit__/DeleteJobs.unit.test.ts index d6bf063145..1e218e910d 100644 --- a/packages/zosjobs/__tests__/__unit__/DeleteJobs.unit.test.ts +++ b/packages/zosjobs/__tests__/__unit__/DeleteJobs.unit.test.ts @@ -51,7 +51,7 @@ describe("Delete Jobs unit tests", () => { describe("Positive tests", () => { it("should allow users to call deleteJob with correct parameters", async () => { - ZosmfRestClient.deleteExpectJSON = jest.fn(returnDeleteJobsDataAsync); + ZosmfRestClient.deleteExpectJSON = jest.fn().mockReturnValue(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); let caughtError; let response; try { @@ -60,11 +60,11 @@ describe("Delete Jobs unit tests", () => { caughtError = error; } expect(caughtError).toBeUndefined(); - expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_ASYNC); + expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); }); it("should allow users to call deleteJobForJob with correct parameters", async () => { - ZosmfRestClient.deleteExpectJSON = jest.fn(returnDeleteJobsDataAsync); + ZosmfRestClient.deleteExpectJSON = jest.fn().mockReturnValue(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); let caughtError; let response; try { @@ -73,7 +73,7 @@ describe("Delete Jobs unit tests", () => { caughtError = error; } expect(caughtError).toBeUndefined(); - expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_ASYNC); + expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); }); it("should allow users to call deleteJobForJob with correct parameters (with modify version 1_0)", async () => { @@ -104,7 +104,7 @@ describe("Delete Jobs unit tests", () => { }); it("should allow users to call deleteJobCommon with correct parameters", async () => { - ZosmfRestClient.deleteExpectJSON = jest.fn(returnDeleteJobsDataAsync); + ZosmfRestClient.deleteExpectJSON = jest.fn().mockReturnValue(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); let caughtError; let response; try { @@ -113,7 +113,7 @@ describe("Delete Jobs unit tests", () => { caughtError = error; } expect(caughtError).toBeUndefined(); - expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_ASYNC); + expect(response).toEqual(CancelJobsData.SAMPLE_JOB_FEEDBACK_GOOD); }); it("should allow users to call deleteJobCommon with correct parameters (with modify version 1_0)", async () => { diff --git a/scripts/bundleCliTgz.js b/scripts/bundleCliTgz.js index ab06e9c232..8abcf43cba 100644 --- a/scripts/bundleCliTgz.js +++ b/scripts/bundleCliTgz.js @@ -10,7 +10,7 @@ */ const childProcess = require("child_process"); -const fs = require("fs-extra"); +const fs = require("fs"); const path = require("path"); // Workaround for https://github.com/npm/cli/issues/3466 @@ -18,7 +18,7 @@ process.chdir(__dirname + "/.."); const cliPkgDir = path.join(process.cwd(), "packages", "cli"); const pkgJsonFile = path.join(cliPkgDir, "package.json"); const execCmd = (cmd) => childProcess.execSync(cmd, { cwd: cliPkgDir, stdio: "inherit" }); -fs.mkdirpSync("dist"); +fs.mkdirSync("dist", {recursive: true}); fs.renameSync(path.join(cliPkgDir, "node_modules"), path.join(cliPkgDir, "node_modules_old")); fs.copyFileSync(pkgJsonFile, pkgJsonFile + ".bak");