Skip to content

Commit c5632ae

Browse files
author
Josh Goldberg
authored
Switch from cat to type on Windows (#1247)
1 parent ebc5278 commit c5632ae

5 files changed

+25
-9
lines changed

src/api/dependencies.ts

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ export const boundImporter = bind(importer, nativeImporterDependencies);
108108
export const findConfigurationDependencies = {
109109
exec: childProcessExec,
110110
importer: boundImporter,
111+
platform: process.platform,
111112
};
112113

113114
export const findOriginalConfigurationsDependencies: FindOriginalConfigurationsDependencies = {

src/input/findPackagesConfiguration.test.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { createStubExec } from "../adapters/exec.stubs";
22
import { findPackagesConfiguration } from "./findPackagesConfiguration";
33

44
describe("findPackagesConfiguration", () => {
5-
it("defaults the configuration file when one isn't provided", async () => {
5+
it("defaults the configuration file with cat when one isn't provided on a non-Windows platform", async () => {
66
// Arrange
7-
const dependencies = { exec: createStubExec() };
7+
const dependencies = { exec: createStubExec(), platform: "darwin" };
88

99
// Act
1010
await findPackagesConfiguration(dependencies, undefined);
@@ -13,9 +13,20 @@ describe("findPackagesConfiguration", () => {
1313
expect(dependencies.exec).toHaveBeenLastCalledWith(`cat "./package.json"`);
1414
});
1515

16+
it("defaults the configuration file with type when one isn't provided on a Windows platform", async () => {
17+
// Arrange
18+
const dependencies = { exec: createStubExec(), platform: "win32" };
19+
20+
// Act
21+
await findPackagesConfiguration(dependencies, undefined);
22+
23+
// Assert
24+
expect(dependencies.exec).toHaveBeenLastCalledWith(`type "./package.json"`);
25+
});
26+
1627
it("includes a configuration file in the packages command when one is provided", async () => {
1728
// Arrange
18-
const dependencies = { exec: createStubExec() };
29+
const dependencies = { exec: createStubExec(), platform: "darwin" };
1930
const config = "./custom/package.json";
2031

2132
// Act
@@ -27,7 +38,7 @@ describe("findPackagesConfiguration", () => {
2738

2839
it("applies packages defaults when none are provided", async () => {
2940
// Arrange
30-
const dependencies = { exec: createStubExec({ stdout: "{}" }) };
41+
const dependencies = { exec: createStubExec({ stdout: "{}" }), platform: "darwin" };
3142
const config = "./package.json";
3243

3344
// Act

src/input/findPackagesConfiguration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const findPackagesConfiguration = async (
1414
): Promise<PackagesConfiguration | Error> => {
1515
const rawConfiguration = await findReportedConfiguration<PackagesConfiguration>(
1616
dependencies.exec,
17-
"cat",
17+
dependencies.platform === "win32" ? "type" : "cat",
1818
config ?? "./package.json",
1919
);
2020

src/input/findReportedConfiguration.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type DeepPartial<T> = {
77

88
export type FindReportedConfigurationDependencies = {
99
exec: Exec;
10+
platform: string;
1011
};
1112

1213
export const findReportedConfiguration = async <Configuration>(

src/input/findTypeScriptConfiguration.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ describe("findTypeScriptConfiguration", () => {
55
it("returns an error when one occurs", async () => {
66
// Arrange
77
const message = "error";
8-
const dependencies = { exec: createStubThrowingExec({ stderr: message }) };
8+
const dependencies = {
9+
exec: createStubThrowingExec({ stderr: message }),
10+
platform: "darwin",
11+
};
912

1013
// Act
1114
const result = await findTypeScriptConfiguration(dependencies, undefined);
@@ -20,7 +23,7 @@ describe("findTypeScriptConfiguration", () => {
2023

2124
it("defaults the configuration file when one isn't provided", async () => {
2225
// Arrange
23-
const dependencies = { exec: createStubExec() };
26+
const dependencies = { exec: createStubExec(), platform: "darwin" };
2427

2528
// Act
2629
await findTypeScriptConfiguration(dependencies, undefined);
@@ -31,7 +34,7 @@ describe("findTypeScriptConfiguration", () => {
3134

3235
it("includes a configuration file in the TypeScript command when one is provided", async () => {
3336
// Arrange
34-
const dependencies = { exec: createStubExec() };
37+
const dependencies = { exec: createStubExec(), platform: "darwin" };
3538
const config = "./custom/tsconfig.json";
3639

3740
// Act
@@ -45,7 +48,7 @@ describe("findTypeScriptConfiguration", () => {
4548

4649
it("applies TypeScript defaults when none are provided", async () => {
4750
// Arrange
48-
const dependencies = { exec: createStubExec({ stdout: "{}" }) };
51+
const dependencies = { exec: createStubExec({ stdout: "{}" }), platform: "darwin" };
4952
const config = "./tsconfig.json";
5053

5154
// Act

0 commit comments

Comments
 (0)