Skip to content

(ISSUELESS) Allow to pass args to tsc #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ inputs:
ts-config-path:
description: "Path of tsconfig file. default is '.'"
default: './tsconfig.json'
ts-extra-args:
description: "Additional tsc options to pass, e.g. '--strict'"
use-check:
description: 'Report status as a CI Check'
check-fail-mode:
description: "Allowed values : added, errors_in_pr, errors_in_code"
required: true
output-behaviour:
description: "Allowed values : comment, annotate, both"
default: "comment"
required: false
default: "both"
debug:
description: "Set true to log ts errors in base branch and pr branch"
default: false
Expand Down
28 changes: 17 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,19 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getAndValidateArgs = void 0;
const core_1 = __nccwpck_require__(2186);
function getAndValidateArgs() {
var _a, _b, _c, _d;
var _a, _b, _c, _d, _e, _f;
const args = {
repoToken: (0, core_1.getInput)('repo-token', { required: true, trimWhitespace: true }),
directory: (0, core_1.getInput)('directory', { trimWhitespace: true }),
tsConfigPath: (0, core_1.getInput)('ts-config-path', { trimWhitespace: true, required: true }),
filesChanged: ((_a = (0, core_1.getInput)('files-changed')) !== null && _a !== void 0 ? _a : "").split(" "),
filesAdded: ((_b = (0, core_1.getInput)('files-added')) !== null && _b !== void 0 ? _b : "").split(" "),
filesDeleted: ((_c = (0, core_1.getInput)('files-deleted')) !== null && _c !== void 0 ? _c : "").split(" "),
lineNumbers: (_d = JSON.parse((0, core_1.getInput)('line-numbers'))) !== null && _d !== void 0 ? _d : [],
tsConfigPath: (_a = (0, core_1.getInput)('ts-config-path', { trimWhitespace: true, required: false })) !== null && _a !== void 0 ? _a : './tsconfig.json',
tsExtraArgs: (0, core_1.getInput)('ts-extra-args', { trimWhitespace: true, required: false }),
filesChanged: ((_b = (0, core_1.getInput)('files-changed')) !== null && _b !== void 0 ? _b : "").split(" "),
filesAdded: ((_c = (0, core_1.getInput)('files-added')) !== null && _c !== void 0 ? _c : "").split(" "),
filesDeleted: ((_d = (0, core_1.getInput)('files-deleted')) !== null && _d !== void 0 ? _d : "").split(" "),
lineNumbers: (_e = JSON.parse((0, core_1.getInput)('line-numbers'))) !== null && _e !== void 0 ? _e : [],
useCheck: (0, core_1.getBooleanInput)('use-check'),
checkFailMode: (0, core_1.getInput)('check-fail-mode'),
outputBehaviour: (0, core_1.getInput)('output-behaviour'),
checkFailMode: (0, core_1.getInput)('check-fail-mode', { required: true }),
outputBehaviour: (_f = (0, core_1.getInput)('output-behaviour')) !== null && _f !== void 0 ? _f : "both" /* OUTPUT_BEHAVIOUR.COMMENT_AND_ANNOTATE */,
debug: (0, core_1.getBooleanInput)('debug')
};
if (![
Expand Down Expand Up @@ -419,7 +420,8 @@ async function run() {
(0, core_1.info)(`[current branch] : tsconfig raw parsing :\n ${JSON.stringify(rawParsingPr)}`);
const { output: tscOutputCurrent } = await (0, runTscCli_1.runTscCli)({
workingDir,
tsconfigPath
tsconfigPath,
extraArgs: args.tsExtraArgs.split(' ')
});
const errorsPr = (0, parseOutputTsc_1.parseOutputTsc)(tscOutputCurrent);
(0, core_1.info)(`[current branch] : ${errorsPr.length} error(s) detected`);
Expand All @@ -443,7 +445,8 @@ async function run() {
(0, core_1.startGroup)(`[base branch] compile ts files`);
const { output: tscOutputBase } = await (0, runTscCli_1.runTscCli)({
workingDir,
tsconfigPath
tsconfigPath,
extraArgs: args.tsExtraArgs.split(' ')
});
const errorsBaseBranch = (0, parseOutputTsc_1.parseOutputTsc)(tscOutputBase);
(0, core_1.info)(`[base branch] : ${errorsBaseBranch.length} error(s) detected`);
Expand Down Expand Up @@ -759,7 +762,7 @@ exemple d'output renvoyé
src/main.ts(39,11): error TS1155: 'const' declarations must be initialized.
src/main.ts(39,11): error TS7005: Variable 'hereIsAUnusedVariableToHaveAnError' implicitly has an 'any' type.
*/
async function runTscCli({ workingDir, tsconfigPath, files }) {
async function runTscCli({ workingDir, tsconfigPath, files, extraArgs }) {
let myOutput = '';
let myError = '';
const options = {};
Expand All @@ -785,6 +788,9 @@ async function runTscCli({ workingDir, tsconfigPath, files }) {
if (tsconfigPath) {
execArgs.push('--project', tsconfigPath);
}
if (extraArgs.length) {
execArgs.push(...extraArgs);
}
// si on passe un tableau de filenames, on les sépare par un espace pour les passer au compiler
if (files) {
execArgs.push(files.reduce((str, file) => {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions src/getAndValidateArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Args = {
repoToken: string
directory: string
tsConfigPath: string
tsExtraArgs: string
filesChanged: string[]
filesAdded: string[]
filesDeleted: string[]
Expand Down Expand Up @@ -54,14 +55,15 @@ export function getAndValidateArgs(): Args {
const args = {
repoToken: getInput('repo-token', { required: true, trimWhitespace: true }),
directory: getInput('directory', { trimWhitespace: true }),
tsConfigPath: getInput('ts-config-path', { trimWhitespace: true, required: true }),
tsConfigPath: getInput('ts-config-path', { trimWhitespace: true, required: false }) ?? './tsconfig.json',
tsExtraArgs: getInput('ts-extra-args', { trimWhitespace: true, required: false }),
filesChanged: (getInput('files-changed') ?? "").split(" "),
filesAdded: (getInput('files-added') ?? "").split(" "),
filesDeleted: (getInput('files-deleted') ?? "").split(" "),
lineNumbers: JSON.parse(getInput('line-numbers')) ?? [],
useCheck: getBooleanInput('use-check'),
checkFailMode: getInput('check-fail-mode') as CHECK_FAIL_MODE,
outputBehaviour: getInput('output-behaviour') as OUTPUT_BEHAVIOUR,
checkFailMode: getInput('check-fail-mode', { required: true }) as CHECK_FAIL_MODE,
outputBehaviour: getInput('output-behaviour') as OUTPUT_BEHAVIOUR ?? OUTPUT_BEHAVIOUR.COMMENT_AND_ANNOTATE,
debug: getBooleanInput('debug')
}

Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ async function run(): Promise<void> {

const { output: tscOutputCurrent } = await runTscCli({
workingDir,
tsconfigPath
tsconfigPath,
extraArgs: args.tsExtraArgs.split(' ')
})

const errorsPr = parseOutputTsc(tscOutputCurrent)
Expand Down Expand Up @@ -118,7 +119,8 @@ async function run(): Promise<void> {

const { output: tscOutputBase } = await runTscCli({
workingDir,
tsconfigPath
tsconfigPath,
extraArgs: args.tsExtraArgs.split(' ')
})

const errorsBaseBranch = parseOutputTsc(tscOutputBase)
Expand Down
7 changes: 6 additions & 1 deletion src/tscHelpers/runTscCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ interface Cfg {
workingDir: string
tsconfigPath?: string
files?: string[]
extraArgs: string[]
}
/*
exemple d'output renvoyé

src/main.ts(39,11): error TS1155: 'const' declarations must be initialized.
src/main.ts(39,11): error TS7005: Variable 'hereIsAUnusedVariableToHaveAnError' implicitly has an 'any' type.
*/
export async function runTscCli({ workingDir, tsconfigPath, files }: Cfg): Promise<{ output: string, error: string }> {
export async function runTscCli({ workingDir, tsconfigPath, files, extraArgs }: Cfg): Promise<{ output: string, error: string }> {

let myOutput = ''
let myError = ''
Expand Down Expand Up @@ -42,6 +43,10 @@ export async function runTscCli({ workingDir, tsconfigPath, files }: Cfg): Promi
if (tsconfigPath) {
execArgs.push('--project', tsconfigPath)
}

if (extraArgs.length) {
execArgs.push(...extraArgs)
}
// si on passe un tableau de filenames, on les sépare par un espace pour les passer au compiler
if (files) {
execArgs.push(files.reduce((str, file) => {
Expand Down