From a35d79585fb8acd246d21e3ea7016ac0aafe838d Mon Sep 17 00:00:00 2001 From: Keiichiro Amemiya Date: Thu, 26 Dec 2024 21:02:43 +0100 Subject: [PATCH 1/2] chore: remove fs-extra --- package-lock.json | 45 ----------------------------- package.json | 2 -- src/commands/schema-types.ts | 3 +- test/commands/defaultconfig.spec.ts | 22 +++++++------- test/commands/schema-types.spec.ts | 3 +- test/commands/uninstall.spec.ts | 3 +- 6 files changed, 15 insertions(+), 63 deletions(-) diff --git a/package-lock.json b/package-lock.json index 98b955a..1433d70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "chalk": "3.0.0", "commander": "^6.1.0", - "fs-extra": "7.0.1", "inquirer": "^7.3.3", "json-schema-defaults": "0.4.0", "json-schema-to-typescript": "11.0.3", @@ -27,7 +26,6 @@ "devDependencies": { "@eslint/js": "^9.17.0", "@gamesdonequick/prettier-config": "^2.2.1", - "@types/fs-extra": "5.0.4", "@types/hosted-git-info": "2.7.0", "@types/inquirer": "^7.3.1", "@types/node": "18", @@ -1201,15 +1199,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/fs-extra": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-5.0.4.tgz", - "integrity": "sha512-DsknoBvD8s+RFfSGjmERJ7ZOP1HI0UZRA3FSI+Zakhrc/Gy26YQsLI+m5V5DHxroHRJqCDLKJp7Hixn8zyaF7g==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/glob": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.3.tgz", @@ -2860,19 +2849,6 @@ "node": "*" } }, - "node_modules/fs-extra": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", - "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", - "dependencies": { - "graceful-fs": "^4.1.2", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - }, - "engines": { - "node": ">=6 <7 || >=8" - } - }, "node_modules/fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", @@ -2986,11 +2962,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/graceful-fs": { - "version": "4.2.6", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz", - "integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ==" - }, "node_modules/graphemer": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", @@ -3409,14 +3380,6 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", "dev": true }, - "node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/jsprim": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz", @@ -5043,14 +5006,6 @@ "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "license": "MIT" }, - "node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "engines": { - "node": ">= 4.0.0" - } - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index f5e0634..7b289c8 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ "dependencies": { "chalk": "3.0.0", "commander": "^6.1.0", - "fs-extra": "7.0.1", "inquirer": "^7.3.3", "json-schema-defaults": "0.4.0", "json-schema-to-typescript": "11.0.3", @@ -47,7 +46,6 @@ "devDependencies": { "@eslint/js": "^9.17.0", "@gamesdonequick/prettier-config": "^2.2.1", - "@types/fs-extra": "5.0.4", "@types/hosted-git-info": "2.7.0", "@types/inquirer": "^7.3.1", "@types/node": "18", diff --git a/src/commands/schema-types.ts b/src/commands/schema-types.ts index e887cba..5871ed6 100644 --- a/src/commands/schema-types.ts +++ b/src/commands/schema-types.ts @@ -4,7 +4,6 @@ import { promisify } from "node:util"; import chalk from "chalk"; import { Command } from "commander"; -import fse from "fs-extra"; import { compileFromFile } from "json-schema-to-typescript"; const writeFilePromise = promisify(fs.writeFile); @@ -40,7 +39,7 @@ function action(inDir: string, cmd: { outDir: string; configSchema: boolean }) { const outDir = path.resolve(processCwd, cmd.outDir); if (!fs.existsSync(outDir)) { - fse.mkdirpSync(outDir); + fs.mkdirSync(outDir, { recursive: true }); } const configSchemaPath = path.join(processCwd, "configschema.json"); diff --git a/test/commands/defaultconfig.spec.ts b/test/commands/defaultconfig.spec.ts index 0842843..572e4e0 100644 --- a/test/commands/defaultconfig.spec.ts +++ b/test/commands/defaultconfig.spec.ts @@ -2,7 +2,6 @@ import fs from "node:fs"; import path from "node:path"; import { Command } from "commander"; -import fse from "fs-extra"; import { beforeEach, describe, expect, it, vi } from "vitest"; import defaultConfigCommand from "../../src/commands/defaultconfig"; @@ -18,7 +17,7 @@ beforeEach(() => { fs.writeFileSync("package.json", JSON.stringify({ name: "nodecg" })); // Copy fixtures. - fse.copySync(path.resolve(__dirname, "../fixtures/"), "./"); + fs.cpSync(path.resolve(__dirname, "../fixtures/"), "./", { recursive: true }); // Build program. program = createMockProgram(); @@ -29,7 +28,7 @@ describe("when run with a bundle argument", () => { it("should successfully create a bundle config file when bundle has configschema.json", async () => { await program.runWith("defaultconfig config-schema"); const config = JSON.parse( - fs.readFileSync("./cfg/config-schema.json", { encoding: "utf8" }), + fs.readFileSync("./cfg/config-schema.json", { encoding: "utf8" }) ); expect(config.username).toBe("user"); expect(config.value).toBe(5); @@ -38,12 +37,13 @@ describe("when run with a bundle argument", () => { it("should print an error when the target bundle does not have a configschema.json", async () => { const spy = vi.spyOn(console, "error"); - fse.mkdirpSync( + fs.mkdirSync( path.resolve(process.cwd(), "./bundles/missing-schema-bundle"), + { recursive: true } ); await program.runWith("defaultconfig missing-schema-bundle"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s does not have a configschema.json"`, + `"Error: Bundle %s does not have a configschema.json"` ); spy.mockRestore(); }); @@ -52,7 +52,7 @@ describe("when run with a bundle argument", () => { const spy = vi.spyOn(console, "error"); await program.runWith("defaultconfig not-installed"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s does not exist"`, + `"Error: Bundle %s does not exist"` ); spy.mockRestore(); }); @@ -62,11 +62,11 @@ describe("when run with a bundle argument", () => { fs.mkdirSync("./cfg"); fs.writeFileSync( "./cfg/config-schema.json", - JSON.stringify({ fake: "data" }), + JSON.stringify({ fake: "data" }) ); await program.runWith("defaultconfig config-schema"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s already has a config file"`, + `"Error: Bundle %s already has a config file"` ); spy.mockRestore(); }); @@ -80,13 +80,15 @@ describe("when run with no arguments", () => { }); it("should print an error when in a folder with no package.json", async () => { - fse.mkdirpSync(path.resolve(process.cwd(), "./bundles/not-a-bundle")); + fs.mkdirSync(path.resolve(process.cwd(), "./bundles/not-a-bundle"), { + recursive: true, + }); process.chdir("./bundles/not-a-bundle"); const spy = vi.spyOn(console, "error"); await program.runWith("defaultconfig"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: No bundle found in the current directory!"`, + `"Error: No bundle found in the current directory!"` ); spy.mockRestore(); }); diff --git a/test/commands/schema-types.spec.ts b/test/commands/schema-types.spec.ts index b4eec48..f733af2 100644 --- a/test/commands/schema-types.spec.ts +++ b/test/commands/schema-types.spec.ts @@ -2,7 +2,6 @@ import { EventEmitter } from "node:events"; import fs from "node:fs"; import path from "node:path"; -import fse from "fs-extra"; import { beforeEach, expect, it, vi } from "vitest"; import schemaTypesCommand from "../../src/commands/schema-types"; @@ -18,7 +17,7 @@ beforeEach(() => { fs.writeFileSync("package.json", JSON.stringify({ name: "nodecg" })); // Copy fixtures. - fse.copySync(path.resolve(__dirname, "../fixtures/"), "./"); + fs.cpSync(path.resolve(__dirname, "../fixtures/"), "./", { recursive: true }); // Build program. program = createMockProgram(); diff --git a/test/commands/uninstall.spec.ts b/test/commands/uninstall.spec.ts index e51cc27..0c48aed 100644 --- a/test/commands/uninstall.spec.ts +++ b/test/commands/uninstall.spec.ts @@ -2,7 +2,6 @@ import fs from "node:fs"; import path from "node:path"; import { Command } from "commander"; -import fse from "fs-extra"; import inquirer from "inquirer"; import { beforeEach, expect, it, vi } from "vitest"; @@ -19,7 +18,7 @@ beforeEach(() => { fs.writeFileSync("package.json", JSON.stringify({ name: "nodecg" })); // Copy fixtures. - fse.copySync(path.resolve(__dirname, "../fixtures/"), "./"); + fs.cpSync(path.resolve(__dirname, "../fixtures/"), "./", { recursive: true }); // Build program. program = createMockProgram(); From c0bf90230004d9b92581c104bfdc33a793a001b4 Mon Sep 17 00:00:00 2001 From: Keiichiro Amemiya Date: Thu, 26 Dec 2024 21:06:22 +0100 Subject: [PATCH 2/2] prettier --- test/commands/defaultconfig.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/commands/defaultconfig.spec.ts b/test/commands/defaultconfig.spec.ts index 572e4e0..89db214 100644 --- a/test/commands/defaultconfig.spec.ts +++ b/test/commands/defaultconfig.spec.ts @@ -28,7 +28,7 @@ describe("when run with a bundle argument", () => { it("should successfully create a bundle config file when bundle has configschema.json", async () => { await program.runWith("defaultconfig config-schema"); const config = JSON.parse( - fs.readFileSync("./cfg/config-schema.json", { encoding: "utf8" }) + fs.readFileSync("./cfg/config-schema.json", { encoding: "utf8" }), ); expect(config.username).toBe("user"); expect(config.value).toBe(5); @@ -39,11 +39,11 @@ describe("when run with a bundle argument", () => { const spy = vi.spyOn(console, "error"); fs.mkdirSync( path.resolve(process.cwd(), "./bundles/missing-schema-bundle"), - { recursive: true } + { recursive: true }, ); await program.runWith("defaultconfig missing-schema-bundle"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s does not have a configschema.json"` + `"Error: Bundle %s does not have a configschema.json"`, ); spy.mockRestore(); }); @@ -52,7 +52,7 @@ describe("when run with a bundle argument", () => { const spy = vi.spyOn(console, "error"); await program.runWith("defaultconfig not-installed"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s does not exist"` + `"Error: Bundle %s does not exist"`, ); spy.mockRestore(); }); @@ -62,11 +62,11 @@ describe("when run with a bundle argument", () => { fs.mkdirSync("./cfg"); fs.writeFileSync( "./cfg/config-schema.json", - JSON.stringify({ fake: "data" }) + JSON.stringify({ fake: "data" }), ); await program.runWith("defaultconfig config-schema"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: Bundle %s already has a config file"` + `"Error: Bundle %s already has a config file"`, ); spy.mockRestore(); }); @@ -88,7 +88,7 @@ describe("when run with no arguments", () => { const spy = vi.spyOn(console, "error"); await program.runWith("defaultconfig"); expect(spy.mock.calls[0][0]).toMatchInlineSnapshot( - `"Error: No bundle found in the current directory!"` + `"Error: No bundle found in the current directory!"`, ); spy.mockRestore(); });