|
1 | 1 | import { resolveCompilerOptions } from "../../../../config/config-to-options.js"; |
2 | 2 | import { omitUndefined } from "../../../../utils/misc.js"; |
3 | 3 | import { createDiagnosticCollector } from "../../../diagnostics.js"; |
| 4 | +import { createDiagnostic } from "../../../messages.js"; |
4 | 5 | import { CompilerOptions } from "../../../options.js"; |
5 | 6 | import { resolvePath } from "../../../path-utils.js"; |
6 | | -import { CompilerHost, Diagnostic } from "../../../types.js"; |
| 7 | +import { CompilerHost, Diagnostic, NoTarget } from "../../../types.js"; |
7 | 8 |
|
8 | 9 | export interface CompileCliArgs { |
9 | 10 | path?: string; |
@@ -42,7 +43,7 @@ export async function getCompilerOptions( |
42 | 43 | : resolvePath(cwd, pathArg) |
43 | 44 | : undefined; |
44 | 45 |
|
45 | | - const cliOptions = resolveCliOptions(args); |
| 46 | + const cliOptions = diagnostics.pipe(resolveCliOptions(args)); |
46 | 47 | const resolvedOptions = diagnostics.pipe( |
47 | 48 | await resolveCompilerOptions(host, { |
48 | 49 | entrypoint, |
@@ -89,40 +90,52 @@ function resolveConfigArgs(args: CompileCliArgs): Record<string, string> { |
89 | 90 |
|
90 | 91 | return map; |
91 | 92 | } |
92 | | -function resolveCliOptions(args: CompileCliArgs): { |
93 | | - options: Record<string, Record<string, unknown>>; |
94 | | - miscOptions: Record<string, string> | undefined; |
95 | | -} { |
| 93 | + |
| 94 | +function resolveCliOptions(args: CompileCliArgs): [ |
| 95 | + { |
| 96 | + options: Record<string, Record<string, unknown>>; |
| 97 | + miscOptions: Record<string, string> | undefined; |
| 98 | + }, |
| 99 | + readonly Diagnostic[], |
| 100 | +] { |
| 101 | + const diagnostics: Diagnostic[] = []; |
96 | 102 | let miscOptions: Record<string, string> | undefined; |
97 | | - const options: Record<string, Record<string, string>> = {}; |
| 103 | + const options: Record<string, any> = {}; |
98 | 104 | for (const option of args.options ?? []) { |
99 | 105 | const optionParts = option.split("="); |
100 | 106 | if (optionParts.length !== 2) { |
101 | | - throw new Error( |
102 | | - `The --option parameter value "${option}" must be in the format: <emitterName>.some-options=value`, |
| 107 | + diagnostics.push( |
| 108 | + createDiagnostic({ |
| 109 | + code: "invalid-option-flag", |
| 110 | + target: NoTarget, |
| 111 | + format: { value: option }, |
| 112 | + }), |
103 | 113 | ); |
| 114 | + continue; |
104 | 115 | } |
105 | | - let optionKeyParts = optionParts[0].split("."); |
| 116 | + const optionKeyParts = optionParts[0].split("."); |
106 | 117 | if (optionKeyParts.length === 1) { |
107 | 118 | const key = optionKeyParts[0]; |
108 | 119 | if (miscOptions === undefined) { |
109 | 120 | miscOptions = {}; |
110 | 121 | } |
111 | 122 | miscOptions[key] = optionParts[1]; |
112 | 123 | continue; |
113 | | - } else if (optionKeyParts.length > 2) { |
114 | | - // support emitter/path/file.js.option=xyz |
115 | | - optionKeyParts = [ |
116 | | - optionKeyParts.slice(0, -1).join("."), |
117 | | - optionKeyParts[optionKeyParts.length - 1], |
118 | | - ]; |
119 | 124 | } |
120 | | - const emitterName = optionKeyParts[0]; |
121 | | - const key = optionKeyParts[1]; |
122 | | - if (!(emitterName in options)) { |
123 | | - options[emitterName] = {}; |
| 125 | + |
| 126 | + let current: any = options; |
| 127 | + for (let i = 0; i < optionKeyParts.length; i++) { |
| 128 | + const part = optionKeyParts[i]; |
| 129 | + if (i === optionKeyParts.length - 1) { |
| 130 | + current[part] = optionParts[1]; |
| 131 | + } else { |
| 132 | + if (!current[part]) { |
| 133 | + current[part] = {}; |
| 134 | + } |
| 135 | + current = current[part]; |
| 136 | + } |
124 | 137 | } |
125 | | - options[emitterName][key] = optionParts[1]; |
126 | 138 | } |
127 | | - return { options, miscOptions }; |
| 139 | + |
| 140 | + return [{ options, miscOptions }, diagnostics]; |
128 | 141 | } |
0 commit comments