Skip to content

Commit cbf05eb

Browse files
committed
Load custom transformers from tsconfig
1 parent 9526729 commit cbf05eb

File tree

12 files changed

+313
-109
lines changed

12 files changed

+313
-109
lines changed

package-lock.json

Lines changed: 52 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
"node": ">=8.5.0"
4040
},
4141
"dependencies": {
42+
"resolve": "^1.10.1",
4243
"source-map": "^0.7.3",
4344
"typescript": "^3.3.1"
4445
},
4546
"devDependencies": {
4647
"@types/glob": "^5.0.35",
4748
"@types/jest": "^24.0.11",
4849
"@types/node": "^11.13.0",
50+
"@types/resolve": "0.0.8",
4951
"fengari": "^0.1.2",
5052
"glob": "^7.1.2",
5153
"jest": "^24.5.0",
@@ -54,6 +56,6 @@
5456
"rimraf": "^2.6.3",
5557
"ts-jest": "^24.0.0",
5658
"ts-node": "^7.0.0",
57-
"tslint": "^5.10.0"
59+
"tslint": "^5.16.0"
5860
}
5961
}

src/CommandLineParser.ts

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export interface ParsedCommandLine extends ts.ParsedCommandLine {
1010
interface CommandLineOptionBase {
1111
name: string;
1212
aliases?: string[];
13-
describe: string;
13+
description: string;
14+
isTSConfigOnly?: boolean;
1415
}
1516

1617
interface CommandLineOptionOfEnum extends CommandLineOptionBase {
@@ -22,36 +23,52 @@ interface CommandLineOptionOfBoolean extends CommandLineOptionBase {
2223
type: "boolean";
2324
}
2425

25-
type CommandLineOption = CommandLineOptionOfEnum | CommandLineOptionOfBoolean;
26+
interface CommandLineOptionOfListType extends CommandLineOptionBase {
27+
isTSConfigOnly: true;
28+
type: "list";
29+
}
30+
31+
type CommandLineOption =
32+
| CommandLineOptionOfEnum
33+
| CommandLineOptionOfBoolean
34+
| CommandLineOptionOfListType;
35+
2636
const optionDeclarations: CommandLineOption[] = [
2737
{
2838
name: "luaLibImport",
29-
describe: "Specifies how js standard features missing in lua are imported.",
39+
description: "Specifies how js standard features missing in lua are imported.",
3040
type: "enum",
3141
choices: Object.values(LuaLibImportKind),
3242
},
3343
{
3444
name: "luaTarget",
3545
aliases: ["lt"],
36-
describe: "Specify Lua target version.",
46+
description: "Specify Lua target version.",
3747
type: "enum",
3848
choices: Object.values(LuaTarget),
3949
},
4050
{
4151
name: "noHeader",
42-
describe: "Specify if a header will be added to compiled files.",
52+
description: "Specify if a header will be added to compiled files.",
4353
type: "boolean",
4454
},
4555
{
4656
name: "noHoisting",
47-
describe: "Disables hoisting.",
57+
description: "Disables hoisting.",
4858
type: "boolean",
4959
},
5060
{
5161
name: "sourceMapTraceback",
52-
describe: "Applies the source map to show source TS files and lines in error tracebacks.",
62+
description:
63+
"Applies the source map to show source TS files and lines in error tracebacks.",
5364
type: "boolean",
5465
},
66+
{
67+
name: "tsTransformers",
68+
description: "Custom TypeScript transformers.",
69+
isTSConfigOnly: true,
70+
type: "list",
71+
},
5572
];
5673

5774
export const version = `Version ${require("../package.json").version}`;
@@ -72,13 +89,15 @@ export function getHelpString(): string {
7289

7390
result += "Options:\n";
7491
for (const option of optionDeclarations) {
92+
if (option.isTSConfigOnly) continue;
93+
7594
const aliasStrings = (option.aliases || []).map(a => "-" + a);
7695
const optionString = aliasStrings.concat(["--" + option.name]).join("|");
7796

7897
const valuesHint = option.type === "enum" ? option.choices.join("|") : option.type;
7998
const spacing = " ".repeat(Math.max(1, 45 - optionString.length - valuesHint.length));
8099

81-
result += `\n ${optionString} <${valuesHint}>${spacing}${option.describe}\n`;
100+
result += `\n ${optionString} <${valuesHint}>${spacing}${option.description}\n`;
82101
}
83102

84103
return result;
@@ -165,14 +184,24 @@ interface CommandLineArgument extends ReadValueResult {
165184
}
166185

167186
function readCommandLineArgument(option: CommandLineOption, value: any): CommandLineArgument {
187+
if (option.isTSConfigOnly) {
188+
return {
189+
value: undefined,
190+
error: diagnostics.optionCanOnlyBeSpecifiedInTsconfigJsonFile(option.name),
191+
increment: 0,
192+
};
193+
}
194+
168195
if (option.type === "boolean") {
169196
if (value === "true" || value === "false") {
170197
value = value === "true";
171198
} else {
172199
// Set boolean arguments without supplied value to true
173200
return { value: true, increment: 0 };
174201
}
175-
} else if (value === undefined) {
202+
}
203+
204+
if (value === undefined) {
176205
return {
177206
error: diagnostics.compilerOptionExpectsAnArgument(option.name),
178207
value: undefined,
@@ -222,6 +251,17 @@ function readValue(option: CommandLineOption, value: unknown): ReadValueResult {
222251

223252
return { value: normalizedValue };
224253
}
254+
255+
case "list": {
256+
if (!Array.isArray(value)) {
257+
return {
258+
value: undefined,
259+
error: diagnostics.compilerOptionRequiresAValueOfType(option.name, "Array"),
260+
};
261+
}
262+
263+
return { value };
264+
}
225265
}
226266
}
227267

0 commit comments

Comments
 (0)