Repository: typescript-eslint/tslint-to-eslint-config
Pull request #1162 (2021-07-07 11:50:58)

Revert 1151
Reverts typescript-eslint/tslint-to-eslint-config#1151

See https://github.com/typescript-eslint/tslint-to-eslint-config/issues/1159 / https://github.com/angular-eslint/angular-eslint/issues/571


Patch:
diff --git a/src/api/dependencies.ts b/src/api/dependencies.ts
index 60643b4..854c8c2 100644
--- a/src/api/dependencies.ts
+++ b/src/api/dependencies.ts
@@ -110,16 +110,9 @@ export const findConfigurationDependencies = {
     importer: boundImporter,
 };
 
-export const findPackagesConfigurationDependencies = {
-    fileSystem: fsFileSystem,
-};
-
 export const findOriginalConfigurationsDependencies: FindOriginalConfigurationsDependencies = {
     findESLintConfiguration: bind(findESLintConfiguration, findConfigurationDependencies),
-    findPackagesConfiguration: bind(
-        findPackagesConfiguration,
-        findPackagesConfigurationDependencies,
-    ),
+    findPackagesConfiguration: bind(findPackagesConfiguration, findConfigurationDependencies),
     findTypeScriptConfiguration: bind(findTypeScriptConfiguration, findConfigurationDependencies),
     findTSLintConfiguration: bind(findTSLintConfiguration, findConfigurationDependencies),
     mergeLintConfigurations,
diff --git a/src/input/findPackagesConfiguration.ts b/src/input/findPackagesConfiguration.ts
index 73d9ea8..900acc0 100644
--- a/src/input/findPackagesConfiguration.ts
+++ b/src/input/findPackagesConfiguration.ts
@@ -1,31 +1,31 @@
-import { FileSystem } from "../adapters/fileSystem";
+import {
+    findReportedConfiguration,
+    FindReportedConfigurationDependencies,
+} from "./findReportedConfiguration";
 
 export type PackagesConfiguration = {
     dependencies: Record<string, string | undefined>;
     devDependencies: Record<string, string | undefined>;
 };
 
-export type FindPackagesConfigurationDependencies = {
-    fileSystem: Pick<FileSystem, "readFile">;
-};
-
 export const findPackagesConfiguration = async (
-    dependencies: FindPackagesConfigurationDependencies,
-    config = "./package.json",
+    dependencies: FindReportedConfigurationDependencies,
+    config: string | undefined,
 ): Promise<PackagesConfiguration | Error> => {
-    const rawConfiguration = await dependencies.fileSystem.readFile(config);
-    if (rawConfiguration instanceof Error) {
-        return rawConfiguration;
-    }
-
-    const configuration = JSON.parse(rawConfiguration) as PackagesConfiguration;
+    const rawConfiguration = await findReportedConfiguration<PackagesConfiguration>(
+        dependencies.exec,
+        "cat",
+        config ?? "./package.json",
+    );
 
-    return {
-        dependencies: {
-            ...configuration.dependencies,
-        },
-        devDependencies: {
-            ...configuration.devDependencies,
-        },
-    };
+    return rawConfiguration instanceof Error
+        ? rawConfiguration
+        : {
+            dependencies: {
+                ...rawConfiguration.dependencies,
+            },
+            devDependencies: {
+                ...rawConfiguration.devDependencies,
+            },
+        };
 };


Test patch:
diff --git a/src/input/findPackagesConfiguration.test.ts b/src/input/findPackagesConfiguration.test.ts
index c581856..767227a 100644
--- a/src/input/findPackagesConfiguration.test.ts
+++ b/src/input/findPackagesConfiguration.test.ts
@@ -1,62 +1,33 @@
-import { createStubFileSystem } from "../adapters/fileSystem.stub";
+import { createStubExec } from "../adapters/exec.stubs";
 import { findPackagesConfiguration } from "./findPackagesConfiguration";
 
 describe("findPackagesConfiguration", () => {
     it("defaults the configuration file when one isn't provided", async () => {
         // Arrange
-        const dependencies = {
-            fileSystem: createStubFileSystem({
-                data: "{}",
-            }),
-        };
+        const dependencies = { exec: createStubExec() };
 
         // Act
         await findPackagesConfiguration(dependencies, undefined);
 
         // Assert
-        expect(dependencies.fileSystem.readFile).toHaveBeenLastCalledWith(`./package.json`);
+        expect(dependencies.exec).toHaveBeenLastCalledWith(`cat "./package.json"`);
     });
 
-    it("uses the configuration file from the packages command when one is provided", async () => {
+    it("includes a configuration file in the packages command when one is provided", async () => {
         // Arrange
-        const dependencies = {
-            fileSystem: createStubFileSystem({
-                data: "{}",
-            }),
-        };
+        const dependencies = { exec: createStubExec() };
         const config = "./custom/package.json";
 
         // Act
         await findPackagesConfiguration(dependencies, config);
 
         // Assert
-        expect(dependencies.fileSystem.readFile).toHaveBeenLastCalledWith(`./custom/package.json`);
-    });
-
-    it("returns an error when readFile returns an error", async () => {
-        // Arrange
-        const error = new Error("Oh no!");
-        const dependencies = {
-            fileSystem: createStubFileSystem({
-                data: error,
-            }),
-        };
-        const config = "./custom/package.json";
-
-        // Act
-        const result = await findPackagesConfiguration(dependencies, config);
-
-        // Assert
-        expect(result).toBe(error);
+        expect(dependencies.exec).toHaveBeenLastCalledWith(`cat "./custom/package.json"`);
     });
 
     it("applies packages defaults when none are provided", async () => {
         // Arrange
-        const dependencies = {
-            fileSystem: createStubFileSystem({
-                data: "{}",
-            }),
-        };
+        const dependencies = { exec: createStubExec({ stdout: "{}" }) };
         const config = "./package.json";
 
         // Act
@@ -68,28 +39,4 @@ describe("findPackagesConfiguration", () => {
             devDependencies: {},
         });
     });
-
-    it("uses existing package data when it exists", async () => {
-        // Arrange
-        const data = {
-            dependencies: {
-                eslint: "^11.22.33",
-            },
-            devDependencies: {
-                tslint: "^12.34.56",
-            },
-        };
-        const dependencies = {
-            fileSystem: createStubFileSystem({
-                data: JSON.stringify(data),
-            }),
-        };
-        const config = "./package.json";
-
-        // Act
-        const result = await findPackagesConfiguration(dependencies, config);
-
-        // Assert
-        expect(result).toEqual(data);
-    });
 });