Skip to content

Commit

Permalink
Improve logic for disabling JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jun 4, 2023
1 parent 24f5e1f commit 13f7f6c
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 11 deletions.
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6952,12 +6952,12 @@ function getNodeInfo() {
execPath: process.execPath
};
}
var flagsWithoutCommentingSupport = /* @__PURE__ */ new Set(["--verifytypes", "--verbose"]);
async function getArgs() {
const pyrightInfo = await getPyrightInfo();
const pyrightPath = await downloadPyright(pyrightInfo);
const args = [path.join(pyrightPath, "package", "index.js")];
const workingDirectory = core.getInput("working-directory");
const noComments = getBooleanInput("no-comments", false);
const pythonPlatform = core.getInput("python-platform");
if (pythonPlatform) {
args.push("--pythonplatform", pythonPlatform);
Expand Down Expand Up @@ -7003,6 +7003,7 @@ async function getArgs() {
args.push(arg);
}
}
const noComments = getBooleanInput("no-comments", false) || args.some((arg) => flagsWithoutCommentingSupport.has(arg));
return {
workingDirectory,
noComments,
Expand Down Expand Up @@ -7058,7 +7059,7 @@ async function main() {
if (workingDirectory) {
process.chdir(workingDirectory);
}
if (noComments || args.includes("--verifytypes")) {
if (noComments) {
printInfo(pyrightVersion, node, args);
const { status: status2 } = cp.spawnSync(node.execPath, args, {
stdio: ["ignore", "inherit", "inherit"]
Expand Down
187 changes: 183 additions & 4 deletions src/__snapshots__/helpers.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ exports[`getArgs valid version extra-args malformed: core.getInput 1`] = `
[
"lib",
],
[
"no-comments",
],
[
"project",
],
Expand Down Expand Up @@ -463,6 +460,188 @@ exports[`getArgs valid version no comments: tc.find 1`] = `
]
`;
exports[`getArgs valid version verbose: core.getInput 1`] = `
[
[
"extra-args",
],
[
"ignore-external",
],
[
"lib",
],
[
"no-comments",
],
[
"project",
],
[
"python-platform",
],
[
"python-version",
],
[
"typeshed-path",
],
[
"venv-path",
],
[
"verify-types",
],
[
"version",
],
[
"warnings",
],
[
"working-directory",
],
]
`;
exports[`getArgs valid version verbose: result 1`] = `
{
"args": [
"<TEMP_DIR>/rootDir/cached/pyright/package/index.js",
"--verbose",
],
"noComments": true,
"pyrightVersion": "1.1.240",
"workingDirectory": "",
}
`;
exports[`getArgs valid version verbose: tc.cacheDir 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright",
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs valid version verbose: tc.downloadTool 1`] = `
[
[
"https://registry.npmjs.org/pyright/-/pyright-1.1.240.tgz",
],
]
`;
exports[`getArgs valid version verbose: tc.extractTar 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright.tar.gz",
],
]
`;
exports[`getArgs valid version verbose: tc.find 1`] = `
[
[
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs valid version verifytypes flag: core.getInput 1`] = `
[
[
"extra-args",
],
[
"ignore-external",
],
[
"lib",
],
[
"no-comments",
],
[
"project",
],
[
"python-platform",
],
[
"python-version",
],
[
"typeshed-path",
],
[
"venv-path",
],
[
"verify-types",
],
[
"version",
],
[
"warnings",
],
[
"working-directory",
],
]
`;
exports[`getArgs valid version verifytypes flag: result 1`] = `
{
"args": [
"<TEMP_DIR>/rootDir/cached/pyright/package/index.js",
"--verifytypes",
],
"noComments": true,
"pyrightVersion": "1.1.240",
"workingDirectory": "",
}
`;
exports[`getArgs valid version verifytypes flag: tc.cacheDir 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright",
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs valid version verifytypes flag: tc.downloadTool 1`] = `
[
[
"https://registry.npmjs.org/pyright/-/pyright-1.1.240.tgz",
],
]
`;
exports[`getArgs valid version verifytypes flag: tc.extractTar 1`] = `
[
[
"<TEMP_DIR>/rootDir/pyright.tar.gz",
],
]
`;
exports[`getArgs valid version verifytypes flag: tc.find 1`] = `
[
[
"pyright",
"1.1.240",
],
]
`;
exports[`getArgs valid version verifytypes: core.getInput 1`] = `
[
[
Expand Down Expand Up @@ -515,7 +694,7 @@ exports[`getArgs valid version verifytypes: result 1`] = `
"some.package",
"--ignoreexternal",
],
"noComments": false,
"noComments": true,
"pyrightVersion": "1.1.240",
"workingDirectory": "",
}
Expand Down
14 changes: 14 additions & 0 deletions src/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ describe("getArgs", () => {
'malformed extra-args: --foo --bar --baz="quoted value" > /dev/null',
);
});

test("verifytypes flag", async () => {
inputs.set("extra-args", "--verifytypes");

const result = await getArgs();
expect(result).toMatchSnapshot("result");
});

test("verbose", async () => {
inputs.set("extra-args", "--verbose");

const result = await getArgs();
expect(result).toMatchSnapshot("result");
});
});
});

Expand Down
7 changes: 5 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export interface Args {
args: readonly string[];
}

const flagsWithoutCommentingSupport = new Set(["--verifytypes", "--verbose"]);

export async function getArgs() {
const pyrightInfo = await getPyrightInfo();
const pyrightPath = await downloadPyright(pyrightInfo);
Expand All @@ -40,8 +42,6 @@ export async function getArgs() {

const workingDirectory = core.getInput("working-directory");

const noComments = getBooleanInput("no-comments", false);

const pythonPlatform = core.getInput("python-platform");
if (pythonPlatform) {
args.push("--pythonplatform", pythonPlatform);
Expand Down Expand Up @@ -98,6 +98,9 @@ export async function getArgs() {
}
}

const noComments = getBooleanInput("no-comments", false)
|| args.some((arg) => flagsWithoutCommentingSupport.has(arg));

return {
workingDirectory,
noComments,
Expand Down
4 changes: 1 addition & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export async function main() {
process.chdir(workingDirectory);
}

// We check for --verifytypes as an arg instead of a flag because it may have
// been passed via extra-args.
if (noComments || args.includes("--verifytypes")) {
if (noComments) {
printInfo(pyrightVersion, node, args);
// If comments are disabled, there's no point in directly processing the output,
// as it's only used for comments.
Expand Down

0 comments on commit 13f7f6c

Please sign in to comment.