Skip to content

Commit

Permalink
Handle case where --project is not json
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Feb 27, 2024
1 parent cccc068 commit f84ea8a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10164,6 +10164,9 @@ function checkOverriddenFlags(args) {
break;
}
}
if (configPath && !configPath.endsWith(".json")) {
configPath = path2.posix.join(configPath, "pyrightconfig.json");
}
configPath ??= "pyrightconfig.json";
let parsed;
if (fs.existsSync(configPath)) {
Expand Down
85 changes: 85 additions & 0 deletions src/__snapshots__/main.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,91 @@ exports[`with overridden flags > explicit pyrightconfig.json bad json > process.
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > command.issueCommand 1`] = `[]`;

exports[`with overridden flags > explicit pyrightconfig.json directory > core.error 1`] = `[]`;

exports[`with overridden flags > explicit pyrightconfig.json directory > core.info 1`] = `
[
[
"pyright 1.1.240, node v20.8.1, pyright-action 1.1.0",
],
[
"Working directory: /some/wd/is/deep",
],
[
"Running: /path/to/node --pythonplatform --pythonversion --typeshedpath --venvpath --project /some/path/to",
],
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > core.setFailed 1`] = `[]`;

exports[`with overridden flags > explicit pyrightconfig.json directory > core.warning 1`] = `
[
[
"/some/path/to/pyrightconfig.json contains { pythonPlatform: 'Linux' }; --pythonplatform as passed by pyright-action will have no effect.",
],
[
"/some/path/to/pyrightconfig.json contains { pythonVersion: '3.9' }; --pythonversion as passed by pyright-action will have no effect.",
],
[
"/some/path/to/pyrightconfig.json contains { typeshedPath: '/path/to/typeshed' }; --typeshedpath as passed by pyright-action will have no effect.",
],
[
"/some/path/to/pyrightconfig.json contains { venvPath: '/path/to/venv' }; --venvpath as passed by pyright-action will have no effect.",
],
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > cp.spawnSync 1`] = `
[
[
"/path/to/node",
[
"--pythonplatform",
"--pythonversion",
"--typeshedpath",
"--venvpath",
"--project",
"/some/path/to",
],
{
"stdio": [
"ignore",
"inherit",
"inherit",
],
},
],
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > fs.existsSync 1`] = `
[
[
"/some/path/to/pyrightconfig.json",
],
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > fs.readFileSync 1`] = `
[
[
"/some/path/to/pyrightconfig.json",
"utf8",
],
]
`;

exports[`with overridden flags > explicit pyrightconfig.json directory > process.chdir 1`] = `
[
[
"/some/wd/is/deep",
],
]
`;

exports[`with overridden flags > implicit pyrightconfig.json > command.issueCommand 1`] = `[]`;

exports[`with overridden flags > implicit pyrightconfig.json > core.error 1`] = `[]`;
Expand Down
23 changes: 23 additions & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,29 @@ describe("with overridden flags", () => {
await main();
});

test("explicit pyrightconfig.json directory", async () => {
mockedHelpers.getArgs.mockResolvedValue({
noComments: true,
workingDirectory: wd,
pyrightVersion,
args: [...flags, "--project", "/some/path/to"],
});

mockedFs.readFileSync.mockImplementation(
((p) => {
expect(p).toBe("/some/path/to/pyrightconfig.json");
return configJSON;
}) as typeof fs.readFileSync,
);

mockedFs.existsSync.mockImplementation((p) => {
expect(p).toBe("/some/path/to/pyrightconfig.json");
return true;
});

await main();
});

test("explicit pyrightconfig.json bad json", async () => {
mockedHelpers.getArgs.mockResolvedValue({
noComments: true,
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ function checkOverriddenFlags(args: readonly string[]) {
break;
}
}

if (configPath && !configPath.endsWith(".json")) {
configPath = path.posix.join(configPath, "pyrightconfig.json");
}

configPath ??= "pyrightconfig.json";

let parsed: unknown;
Expand Down

0 comments on commit f84ea8a

Please sign in to comment.