@marko/type-check 0.0.18 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -9
  2. package/dist/cli.js +312 -377
  3. package/package.json +5 -5
package/README.md CHANGED
@@ -25,7 +25,6 @@ mtc [options]
25
25
  | ---------------- | ----- | ---------------------------------------------------------------------- | ---------------------------------- |
26
26
  | --project <path> | -p | Path to the tsconfig or jsconfig file | ./tsconfig.json or ./jsconfig.json |
27
27
  | --display <type> | -d | Set the display type for error output. Choices: codeframe or condensed | codeframe |
28
- | --emit | -e | Emit .js, .d.ts, .marko (with types stripped), and .d.marko files | false |
29
28
  | --help | -h | Display the help text | |
30
29
  | --version | -v | Display the CLI version, Marko version, and TypeScript version | |
31
30
 
@@ -43,17 +42,11 @@ marko-type-check
43
42
  mtc -p ./jsconfig.json -d condensed
44
43
  ```
45
44
 
46
- ### Run type check and emit output files:
47
-
48
- ```
49
- marko-type-check -e
50
- ```
51
-
52
45
  ## FAQ
53
46
 
54
- ### What files are emitted with the `--emit` option?
47
+ ### What files are emitted?
55
48
 
56
- The `emit` option outputs files similar to the [`tsc` cli](https://www.typescriptlang.org/docs/handbook/compiler-options.html). Meaning `.js` and `.d.ts` files will be output. Beyond that `.marko` files _with their types stripped_ and an associated `.d.marko` file will be output that serve a similar purpose to the `.js` and `.d.ts` files.
49
+ Outputs files are similar to the [`tsc` cli in build mode](https://www.typescriptlang.org/docs/handbook/project-references.html). Meaning `.js` and `.d.ts` files will be output (depending on your project config). Beyond that `.marko` files _with their types stripped_ and an associated `.d.marko` file will be output that serve a similar purpose to the `.js` and `.d.ts` files.
57
50
 
58
51
  ### What is a `.d.marko` file?
59
52
 
package/dist/cli.js CHANGED
@@ -32,6 +32,7 @@ var import_kleur2 = __toESM(require("kleur"));
32
32
 
33
33
  // src/run.ts
34
34
  var import_path = __toESM(require("path"));
35
+ var import_crypto = __toESM(require("crypto"));
35
36
  var import_tsserverlibrary = __toESM(require("typescript/lib/tsserverlibrary"));
36
37
  var import_kleur = __toESM(require("kleur"));
37
38
  var import_code_frame = require("@babel/code-frame");
@@ -41,424 +42,366 @@ var Display = {
41
42
  condensed: "condensed"
42
43
  };
43
44
  var currentDirectory = import_tsserverlibrary.default.sys.getCurrentDirectory();
45
+ var getCanonicalFileName = import_tsserverlibrary.default.sys.useCaseSensitiveFileNames ? (fileName) => fileName : (fileName) => fileName.toLowerCase();
44
46
  var fsPathReg = /^(?:[./\\]|[A-Z]:)/i;
45
47
  var modulePartsReg = /^((?:@(?:[^/]+)\/)?(?:[^/]+))(.*)$/;
46
48
  var extractCache = /* @__PURE__ */ new WeakMap();
47
49
  var requiredTSCompilerOptions = {
48
50
  allowJs: true,
51
+ composite: true,
52
+ incremental: true,
49
53
  declaration: true,
50
54
  skipLibCheck: true,
51
55
  isolatedModules: true,
52
56
  allowNonTsExtensions: true
53
57
  };
54
- var requiredTSCompilerOptionsEmit = {
55
- ...requiredTSCompilerOptions,
56
- noEmit: false,
57
- declaration: true,
58
- emitDeclarationOnly: false
59
- };
60
- var requiredTSCompilerOptionsNoEmit = {
61
- ...requiredTSCompilerOptions,
62
- noEmit: true,
63
- declaration: false,
64
- emitDeclarationOnly: false
65
- };
66
- var defaultTSConfig = {
67
- include: [],
68
- compilerOptions: {
69
- lib: ["dom", "node", "esnext"]
70
- }
71
- };
72
58
  function run(opts) {
73
- var _a;
74
59
  const {
75
- emit = false,
76
60
  display = Display.codeframe,
77
- project: configFile = findConfigFile("tsconfig.json") || findConfigFile("jsconfig.json")
61
+ project: configFile = findRootConfigFile("tsconfig.json") || findRootConfigFile("jsconfig.json")
78
62
  } = opts;
79
63
  if (!configFile)
80
64
  throw new Error("Could not find tsconfig.json or jsconfig.json");
81
- const { host, parsedCommandLine, getProcessor } = createCompilerHost(
82
- configFile,
83
- emit ? requiredTSCompilerOptionsEmit : requiredTSCompilerOptionsNoEmit
84
- );
85
65
  const formatSettings = import_tsserverlibrary.default.getDefaultFormatCodeSettings(
86
- ((_a = host.getNewLine) == null ? void 0 : _a.call(host)) || import_tsserverlibrary.default.sys.newLine
66
+ import_tsserverlibrary.default.sys.newLine
87
67
  );
88
68
  const report = {
89
69
  out: [],
90
70
  display,
91
- hasErrors: false,
92
71
  formatSettings
93
72
  };
94
- const program = import_tsserverlibrary.default.createProgram({
95
- host,
96
- options: parsedCommandLine.options,
97
- rootNames: parsedCommandLine.fileNames,
98
- projectReferences: parsedCommandLine.projectReferences
99
- });
100
- reportDiagnostics(report, import_tsserverlibrary.default.getPreEmitDiagnostics(program));
101
- if (!report.hasErrors) {
102
- const typeChecker = program.getTypeChecker();
103
- const printer = import_tsserverlibrary.default.createPrinter({
104
- noEmitHelpers: true,
105
- removeComments: true
106
- });
107
- const emitResult = program.emit(
108
- void 0,
109
- emit ? (fileName, _text, writeByteOrderMark, onError, sourceFiles, data) => {
110
- const processor = (sourceFiles == null ? void 0 : sourceFiles.length) === 1 && getProcessor(sourceFiles[0].fileName) || void 0;
111
- if (processor) {
112
- const [sourceFile] = sourceFiles;
113
- const processorExt = (0, import_language_tools.getExt)(sourceFile.fileName);
114
- const inDtsExt = processorExt + import_tsserverlibrary.default.Extension.Dts;
115
- const inJsExt = processorExt + import_tsserverlibrary.default.Extension.Js;
116
- const inExt = fileName.endsWith(inDtsExt) ? inDtsExt : fileName.endsWith(inJsExt) ? inJsExt : void 0;
117
- if (!inExt) {
118
- throw new Error("Unexpected file extension: " + fileName);
119
- }
120
- const isDts = inExt === inDtsExt;
121
- let outFileName = fileName;
122
- if ((0, import_language_tools.isDefinitionFile)(sourceFile.fileName)) {
123
- if (!isDts)
124
- return;
125
- outFileName = fileName.slice(0, -inExt.length) + processorExt;
126
- } else {
127
- if (isDts && program.getSourceFile(
128
- `${sourceFile.fileName.slice(
129
- 0,
130
- -processorExt.length
131
- )}.d${processorExt}`
132
- )) {
133
- return;
134
- }
135
- outFileName = fileName.slice(0, -inExt.length) + (isDts ? ".d" : "") + processorExt;
136
- }
137
- const extracted = extractCache.get(
138
- program.getSourceFile(sourceFile.fileName)
139
- );
140
- const printContext = {
141
- extracted,
142
- printer,
143
- typeChecker,
144
- sourceFile,
145
- formatSettings
146
- };
147
- host.writeFile(
148
- outFileName,
149
- isDts ? processor.printTypes(printContext).code : processor.print(printContext).code,
150
- writeByteOrderMark,
151
- onError,
152
- sourceFiles,
153
- data
154
- );
155
- } else {
156
- host.writeFile(
157
- fileName,
158
- _text,
159
- writeByteOrderMark,
160
- onError,
161
- sourceFiles,
162
- data
163
- );
164
- }
165
- } : void 0,
166
- void 0,
167
- false
168
- );
169
- reportDiagnostics(report, emitResult.diagnostics);
170
- }
171
- const lineSep = report.formatSettings.newLineCharacter + report.formatSettings.newLineCharacter;
172
- console.log(report.out.join(lineSep));
173
- process.exitCode = report.hasErrors ? 1 : 0;
174
- }
175
- function createCompilerHost(configFile, compilerOptions) {
176
- const getProcessor = (fileName) => {
177
- const ext = (0, import_language_tools.getExt)(fileName);
178
- return ext ? processors[ext] : void 0;
179
- };
180
- const resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options, _containingSourceFile, _reusedNames) => {
181
- return moduleLiterals.map((moduleLiteral) => {
182
- return import_tsserverlibrary.default.bundlerModuleNameResolver(
183
- moduleLiteral.text,
184
- containingFile,
185
- options,
186
- host,
187
- resolutionCache,
188
- redirectedReference
189
- );
190
- });
191
- };
192
- const parsedCommandLine = import_tsserverlibrary.default.parseJsonConfigFileContent(
193
- configFile && import_tsserverlibrary.default.readConfigFile(configFile, import_tsserverlibrary.default.sys.readFile).config || defaultTSConfig,
194
- import_tsserverlibrary.default.sys,
195
- currentDirectory,
196
- compilerOptions,
197
- configFile,
73
+ const extraExtensions = import_language_tools.Processors.extensions.map((extension) => ({
74
+ extension,
75
+ isMixedContent: false,
76
+ scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
77
+ }));
78
+ const solutionHost = import_tsserverlibrary.default.createSolutionBuilderHost(
198
79
  void 0,
199
- import_language_tools.Processors.extensions.map((extension) => ({
200
- extension,
201
- isMixedContent: false,
202
- scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
203
- }))
204
- );
205
- const host = {
206
- getDefaultLibFileName: import_tsserverlibrary.default.getDefaultLibFilePath,
207
- writeFile: import_tsserverlibrary.default.sys.writeFile,
208
- getCurrentDirectory: import_tsserverlibrary.default.sys.getCurrentDirectory,
209
- getDirectories: import_tsserverlibrary.default.sys.getDirectories,
210
- getCanonicalFileName: (fileName) => import_tsserverlibrary.default.sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(),
211
- getNewLine: () => import_tsserverlibrary.default.sys.newLine,
212
- useCaseSensitiveFileNames: () => import_tsserverlibrary.default.sys.useCaseSensitiveFileNames,
213
- fileExists: import_tsserverlibrary.default.sys.fileExists,
214
- readFile: import_tsserverlibrary.default.sys.readFile,
215
- readDirectory: (path3, extensions, exclude, include, depth) => import_tsserverlibrary.default.sys.readDirectory(
216
- path3,
217
- extensions == null ? void 0 : extensions.concat(import_language_tools.Processors.extensions),
218
- exclude,
219
- include,
220
- depth
221
- ),
222
- resolveModuleNameLiterals(moduleLiterals, containingFile, redirectedReference, options, containingSourceFile, reusedNames) {
223
- let normalModuleLiterals = moduleLiterals;
224
- let resolvedModules;
225
- for (let i = 0; i < moduleLiterals.length; i++) {
226
- const moduleLiteral = moduleLiterals[i];
227
- const moduleName = moduleLiteral.text;
228
- const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
229
- if (processor) {
230
- let isExternalLibraryImport = false;
231
- let resolvedFileName;
232
- if (fsPathReg.test(moduleName)) {
233
- resolvedFileName = import_path.default.resolve(containingFile, "..", moduleName);
234
- } else {
235
- const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
236
- const { resolvedModule } = import_tsserverlibrary.default.nodeModuleNameResolver(
237
- `${nodeModuleName}/package.json`,
238
- containingFile,
239
- options,
240
- host,
241
- resolutionCache,
242
- redirectedReference
243
- );
244
- if (resolvedModule) {
245
- isExternalLibraryImport = true;
246
- resolvedFileName = import_path.default.join(
247
- resolvedModule.resolvedFileName,
248
- "..",
249
- relativeModulePath
80
+ (rootNames, options, compilerHost, oldProgram, configFileParsingDiagnostics, projectReferences) => {
81
+ if (!compilerHost) {
82
+ throw new Error("Expected compilerHost to be provided.");
83
+ }
84
+ const resolutionCache = import_tsserverlibrary.default.createModuleResolutionCache(
85
+ currentDirectory,
86
+ getCanonicalFileName,
87
+ options
88
+ );
89
+ const { readDirectory = import_tsserverlibrary.default.sys.readDirectory } = compilerHost;
90
+ compilerHost.readDirectory = (path3, extensions, exclude, include, depth) => readDirectory(
91
+ path3,
92
+ extensions == null ? void 0 : extensions.concat(import_language_tools.Processors.extensions),
93
+ exclude,
94
+ include,
95
+ depth
96
+ );
97
+ compilerHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options2, _containingSourceFile, _reusedNames) => {
98
+ let normalModuleLiterals = moduleLiterals;
99
+ let resolvedModules;
100
+ for (let i = 0; i < moduleLiterals.length; i++) {
101
+ const moduleLiteral = moduleLiterals[i];
102
+ const moduleName = moduleLiteral.text;
103
+ const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
104
+ if (processor) {
105
+ let isExternalLibraryImport = false;
106
+ let resolvedFileName;
107
+ if (fsPathReg.test(moduleName)) {
108
+ resolvedFileName = import_path.default.resolve(containingFile, "..", moduleName);
109
+ } else {
110
+ const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
111
+ const { resolvedModule } = import_tsserverlibrary.default.nodeModuleNameResolver(
112
+ `${nodeModuleName}/package.json`,
113
+ containingFile,
114
+ options2,
115
+ compilerHost,
116
+ resolutionCache,
117
+ redirectedReference
250
118
  );
119
+ if (resolvedModule) {
120
+ isExternalLibraryImport = true;
121
+ resolvedFileName = import_path.default.join(
122
+ resolvedModule.resolvedFileName,
123
+ "..",
124
+ relativeModulePath
125
+ );
126
+ }
251
127
  }
252
- }
253
- if (!resolvedModules) {
254
- resolvedModules = [];
255
- normalModuleLiterals = [];
256
- for (let j = 0; j < i; j++) {
257
- resolvedModules.push(void 0);
258
- normalModuleLiterals.push(moduleLiterals[j]);
259
- }
260
- }
261
- if (resolvedFileName) {
262
- if ((0, import_language_tools.isDefinitionFile)(resolvedFileName)) {
263
- if (!host.fileExists(resolvedFileName)) {
264
- resolvedFileName = void 0;
128
+ if (!resolvedModules) {
129
+ resolvedModules = [];
130
+ normalModuleLiterals = [];
131
+ for (let j = 0; j < i; j++) {
132
+ resolvedModules.push(void 0);
133
+ normalModuleLiterals.push(moduleLiterals[j]);
265
134
  }
266
- } else {
267
- const ext = (0, import_language_tools.getExt)(resolvedFileName);
268
- const definitionFile = `${resolvedFileName.slice(
269
- 0,
270
- -ext.length
271
- )}.d${ext}`;
272
- if (host.fileExists(definitionFile)) {
273
- resolvedFileName = definitionFile;
274
- } else if (!host.fileExists(resolvedFileName)) {
275
- resolvedFileName = void 0;
135
+ }
136
+ if (resolvedFileName) {
137
+ if ((0, import_language_tools.isDefinitionFile)(resolvedFileName)) {
138
+ if (!compilerHost.fileExists(resolvedFileName)) {
139
+ resolvedFileName = void 0;
140
+ }
141
+ } else {
142
+ const ext = (0, import_language_tools.getExt)(resolvedFileName);
143
+ const definitionFile = `${resolvedFileName.slice(
144
+ 0,
145
+ -ext.length
146
+ )}.d${ext}`;
147
+ if (compilerHost.fileExists(definitionFile)) {
148
+ resolvedFileName = definitionFile;
149
+ } else if (!compilerHost.fileExists(resolvedFileName)) {
150
+ resolvedFileName = void 0;
151
+ }
276
152
  }
277
153
  }
154
+ resolvedModules.push({
155
+ resolvedModule: resolvedFileName ? {
156
+ resolvedFileName,
157
+ extension: processor.getScriptExtension(resolvedFileName),
158
+ isExternalLibraryImport
159
+ } : void 0
160
+ });
161
+ } else if (resolvedModules) {
162
+ resolvedModules.push(void 0);
163
+ normalModuleLiterals.push(moduleLiteral);
278
164
  }
279
- resolvedModules.push({
280
- resolvedModule: resolvedFileName ? {
281
- resolvedFileName,
282
- extension: processor.getScriptExtension(resolvedFileName),
283
- isExternalLibraryImport
284
- } : void 0
285
- });
286
- } else if (resolvedModules) {
287
- resolvedModules.push(void 0);
288
- normalModuleLiterals.push(moduleLiteral);
289
165
  }
290
- }
291
- const normalResolvedModules = normalModuleLiterals.length ? resolveModuleNameLiterals(
292
- normalModuleLiterals,
293
- containingFile,
294
- redirectedReference,
295
- options,
296
- containingSourceFile,
297
- reusedNames
298
- ) : void 0;
299
- if (resolvedModules) {
300
- if (normalResolvedModules) {
301
- for (let i = 0, j = 0; i < resolvedModules.length; i++) {
302
- if (!resolvedModules[i]) {
303
- resolvedModules[i] = normalResolvedModules[j++];
166
+ const normalResolvedModules = normalModuleLiterals.length ? normalModuleLiterals.map((moduleLiteral) => {
167
+ return import_tsserverlibrary.default.bundlerModuleNameResolver(
168
+ moduleLiteral.text,
169
+ containingFile,
170
+ options2,
171
+ compilerHost,
172
+ resolutionCache,
173
+ redirectedReference
174
+ );
175
+ }) : void 0;
176
+ if (resolvedModules) {
177
+ if (normalResolvedModules) {
178
+ for (let i = 0, j = 0; i < resolvedModules.length; i++) {
179
+ if (!resolvedModules[i]) {
180
+ resolvedModules[i] = normalResolvedModules[j++];
181
+ }
304
182
  }
305
183
  }
184
+ return resolvedModules;
185
+ } else {
186
+ return normalResolvedModules;
306
187
  }
307
- return resolvedModules;
308
- } else {
309
- return normalResolvedModules;
310
- }
311
- },
312
- getSourceFile: (fileName, languageVersion) => {
313
- const processor = getProcessor(fileName);
314
- const code = host.readFile(fileName);
315
- if (code !== void 0) {
316
- if (processor) {
317
- const extracted = processor.extract(fileName, code);
318
- const sourceFile = import_tsserverlibrary.default.createSourceFile(
188
+ };
189
+ const getSourceFile = compilerHost.getSourceFile.bind(compilerHost);
190
+ compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
191
+ const processor = getProcessor(fileName);
192
+ const code = compilerHost.readFile(fileName);
193
+ if (code !== void 0) {
194
+ if (processor) {
195
+ const extracted = processor.extract(fileName, code);
196
+ const extractedCode = extracted.toString();
197
+ const sourceFile = import_tsserverlibrary.default.createSourceFile(
198
+ fileName,
199
+ extractedCode,
200
+ languageVersion,
201
+ true,
202
+ processor.getScriptKind(fileName)
203
+ );
204
+ sourceFile.version = import_crypto.default.createHash("md5").update(extractedCode).digest("hex");
205
+ extractCache.set(sourceFile, extracted);
206
+ return sourceFile;
207
+ }
208
+ return getSourceFile(
319
209
  fileName,
320
- extracted.toString(),
321
210
  languageVersion,
322
- true,
323
- processor.getScriptKind(fileName)
211
+ onError,
212
+ shouldCreateNewSourceFile
324
213
  );
325
- extractCache.set(sourceFile, extracted);
326
- return sourceFile;
327
214
  }
328
- return import_tsserverlibrary.default.createSourceFile(fileName, code, languageVersion, true);
329
- }
330
- }
331
- };
332
- const resolutionCache = import_tsserverlibrary.default.createModuleResolutionCache(
333
- currentDirectory,
334
- host.getCanonicalFileName,
335
- parsedCommandLine.options
215
+ };
216
+ const builderProgram = import_tsserverlibrary.default.createEmitAndSemanticDiagnosticsBuilderProgram(
217
+ rootNames,
218
+ options,
219
+ compilerHost,
220
+ oldProgram,
221
+ configFileParsingDiagnostics,
222
+ projectReferences
223
+ );
224
+ const program = builderProgram.getProgram();
225
+ const builderEmit = builderProgram.emit.bind(builderProgram);
226
+ builderProgram.emit = (targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
227
+ let writeFile = _writeFile;
228
+ if (_writeFile) {
229
+ const typeChecker = program.getTypeChecker();
230
+ const printer = import_tsserverlibrary.default.createPrinter({
231
+ noEmitHelpers: true,
232
+ removeComments: true
233
+ });
234
+ writeFile = (fileName, _text, writeByteOrderMark, onError, sourceFiles, data) => {
235
+ const processor = (sourceFiles == null ? void 0 : sourceFiles.length) === 1 && getProcessor(sourceFiles[0].fileName) || void 0;
236
+ if (processor) {
237
+ const [sourceFile] = sourceFiles;
238
+ const processorExt = (0, import_language_tools.getExt)(sourceFile.fileName);
239
+ const inDtsExt = processorExt + import_tsserverlibrary.default.Extension.Dts;
240
+ const inJsExt = processorExt + import_tsserverlibrary.default.Extension.Js;
241
+ const inExt = fileName.endsWith(inDtsExt) ? inDtsExt : fileName.endsWith(inJsExt) ? inJsExt : void 0;
242
+ if (!inExt) {
243
+ const msg = `Unexpected file extension: ${fileName}`;
244
+ if (onError) {
245
+ onError(msg);
246
+ return;
247
+ }
248
+ throw new Error(msg);
249
+ }
250
+ const isDts = inExt === inDtsExt;
251
+ let outFileName = fileName;
252
+ if ((0, import_language_tools.isDefinitionFile)(sourceFile.fileName)) {
253
+ if (!isDts)
254
+ return;
255
+ outFileName = fileName.slice(0, -inExt.length) + processorExt;
256
+ } else {
257
+ if (isDts && program.getSourceFile(
258
+ `${sourceFile.fileName.slice(
259
+ 0,
260
+ -processorExt.length
261
+ )}.d${processorExt}`
262
+ )) {
263
+ return;
264
+ }
265
+ outFileName = fileName.slice(0, -inExt.length) + (isDts ? ".d" : "") + processorExt;
266
+ }
267
+ const extracted = extractCache.get(
268
+ program.getSourceFile(sourceFile.fileName)
269
+ );
270
+ const printContext = {
271
+ extracted,
272
+ printer,
273
+ typeChecker,
274
+ sourceFile,
275
+ formatSettings: report.formatSettings
276
+ };
277
+ _writeFile(
278
+ outFileName,
279
+ isDts ? processor.printTypes(printContext).code : processor.print(printContext).code,
280
+ writeByteOrderMark,
281
+ onError,
282
+ sourceFiles,
283
+ data
284
+ );
285
+ } else {
286
+ _writeFile(
287
+ fileName,
288
+ _text,
289
+ writeByteOrderMark,
290
+ onError,
291
+ sourceFiles,
292
+ data
293
+ );
294
+ }
295
+ };
296
+ }
297
+ return builderEmit(
298
+ targetSourceFile,
299
+ writeFile,
300
+ cancellationToken,
301
+ emitOnlyDtsFiles,
302
+ customTransformers
303
+ );
304
+ };
305
+ return builderProgram;
306
+ },
307
+ (diag) => reportDiagnostic(report, diag)
336
308
  );
337
309
  const processors = import_language_tools.Processors.create({
338
310
  ts: import_tsserverlibrary.default,
339
- host,
340
- configFile
311
+ configFile,
312
+ host: solutionHost
341
313
  });
342
- parsedCommandLine.fileNames = [
343
- ...new Set(
344
- parsedCommandLine.fileNames.concat(
345
- Object.values(processors).map((processor) => {
346
- var _a;
347
- return (_a = processor.getRootNames) == null ? void 0 : _a.call(processor);
348
- }).flat().filter(Boolean)
349
- )
350
- )
351
- ];
352
- return {
353
- host,
354
- parsedCommandLine,
355
- getProcessor
314
+ const getProcessor = (fileName) => {
315
+ const ext = (0, import_language_tools.getExt)(fileName);
316
+ return ext ? processors[ext] : void 0;
356
317
  };
357
- }
358
- function reportDiagnostics(report, diags) {
359
- for (const diag of diags) {
360
- if (diag.file && diag.start !== void 0) {
361
- const extracted = extractCache.get(diag.file);
362
- let code = diag.file.text;
363
- let loc;
364
- if (extracted) {
365
- loc = extracted.sourceLocationAt(
366
- diag.start,
367
- diag.start + (diag.length || 0)
368
- );
369
- code = extracted.parsed.code;
370
- if (!loc)
371
- continue;
372
- } else {
373
- const start = import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start);
374
- const end = diag.length ? import_tsserverlibrary.default.getLineAndCharacterOfPosition(
375
- diag.file,
376
- diag.start + diag.length
377
- ) : start;
378
- loc = {
379
- start,
380
- end
381
- };
382
- }
383
- if (diag.category === import_tsserverlibrary.default.DiagnosticCategory.Error) {
384
- report.hasErrors = true;
318
+ solutionHost.getParsedCommandLine = (fileName) => {
319
+ var _a, _b;
320
+ const parsedCommandLine = import_tsserverlibrary.default.getParsedCommandLineOfConfigFile(
321
+ fileName,
322
+ requiredTSCompilerOptions,
323
+ {
324
+ ...import_tsserverlibrary.default.sys,
325
+ onUnRecoverableConfigFileDiagnostic(diag) {
326
+ reportDiagnostic(report, diag);
327
+ }
328
+ },
329
+ void 0,
330
+ void 0,
331
+ extraExtensions
332
+ );
333
+ if (!parsedCommandLine)
334
+ return;
335
+ const finalRootNames = new Set(parsedCommandLine.fileNames);
336
+ for (const name in processors) {
337
+ const rootNames = (_b = (_a = processors[name]).getRootNames) == null ? void 0 : _b.call(_a);
338
+ if (rootNames) {
339
+ for (const rootName of rootNames) {
340
+ finalRootNames.add(rootName);
341
+ }
385
342
  }
386
- const diagMessage = flattenDiagnosticMessage(
387
- diag.messageText,
388
- report.display,
389
- report.formatSettings.newLineCharacter
390
- );
391
- report.out.push(
392
- `${import_kleur.default.cyan(
393
- import_path.default.relative(currentDirectory, diag.file.fileName)
394
- )}:${import_kleur.default.yellow(loc.start.line + 1)}:${import_kleur.default.yellow(
395
- loc.start.character + 1
396
- )} - ${coloredDiagnosticCategory(diag.category)} ${import_kleur.default.dim(
397
- `TS${diag.code}`
398
- )}${report.formatSettings.newLineCharacter}${report.display === Display.codeframe ? report.formatSettings.newLineCharacter + formatCodeFrameMessage(code, loc, diagMessage) : diagMessage}`
343
+ }
344
+ parsedCommandLine.fileNames = [...finalRootNames];
345
+ return parsedCommandLine;
346
+ };
347
+ process.exitCode = import_tsserverlibrary.default.createSolutionBuilder(solutionHost, [configFile], {}).build();
348
+ console.log(
349
+ report.out.join(
350
+ report.formatSettings.newLineCharacter + report.formatSettings.newLineCharacter
351
+ )
352
+ );
353
+ }
354
+ function reportDiagnostic(report, diag) {
355
+ if (diag.file && diag.start !== void 0) {
356
+ const extracted = extractCache.get(diag.file);
357
+ let code = diag.file.text;
358
+ let loc;
359
+ if (extracted) {
360
+ loc = extracted.sourceLocationAt(
361
+ diag.start,
362
+ diag.start + (diag.length || 0)
399
363
  );
364
+ code = extracted.parsed.code;
365
+ if (!loc)
366
+ return;
400
367
  } else {
401
- if (diag.category === import_tsserverlibrary.default.DiagnosticCategory.Error) {
402
- report.hasErrors = true;
403
- }
404
- report.out.push(
405
- flattenDiagnosticMessage(
406
- diag.messageText,
407
- report.display,
408
- report.formatSettings.newLineCharacter
409
- )
410
- );
411
- }
412
- if (diag.relatedInformation && report.display === Display.codeframe) {
413
- reportRelatedDiagnostics(report, diag.relatedInformation);
368
+ const start = import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start);
369
+ const end = diag.length ? import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start + diag.length) : start;
370
+ loc = {
371
+ start,
372
+ end
373
+ };
414
374
  }
375
+ const diagMessage = flattenDiagnosticMessage(
376
+ diag.messageText,
377
+ report.display,
378
+ report.formatSettings.newLineCharacter
379
+ );
380
+ report.out.push(
381
+ `${import_kleur.default.cyan(
382
+ import_path.default.relative(currentDirectory, diag.file.fileName)
383
+ )}:${import_kleur.default.yellow(loc.start.line + 1)}:${import_kleur.default.yellow(
384
+ loc.start.character + 1
385
+ )} - ${coloredDiagnosticCategory(diag.category)} ${import_kleur.default.dim(
386
+ `TS${diag.code}`
387
+ )}${report.formatSettings.newLineCharacter}${report.display === Display.codeframe ? report.formatSettings.newLineCharacter + formatCodeFrameMessage(code, loc, diagMessage) : diagMessage}`
388
+ );
389
+ } else {
390
+ report.out.push(
391
+ flattenDiagnosticMessage(
392
+ diag.messageText,
393
+ report.display,
394
+ report.formatSettings.newLineCharacter
395
+ )
396
+ );
397
+ }
398
+ if (diag.relatedInformation && report.display === Display.codeframe) {
399
+ reportRelatedDiagnostics(report, diag.relatedInformation);
415
400
  }
416
401
  }
417
402
  function reportRelatedDiagnostics(report, diags) {
418
403
  for (const diag of diags) {
419
- if (diag.file && diag.start) {
420
- const extracted = extractCache.get(diag.file);
421
- let code = diag.file.text;
422
- let loc;
423
- if (extracted) {
424
- loc = extracted.sourceLocationAt(
425
- diag.start,
426
- diag.start + (diag.length || 0)
427
- );
428
- code = extracted.parsed.code;
429
- } else {
430
- const start = import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start);
431
- const end = diag.length ? import_tsserverlibrary.default.getLineAndCharacterOfPosition(
432
- diag.file,
433
- diag.start + diag.length
434
- ) : start;
435
- loc = {
436
- start,
437
- end
438
- };
439
- }
440
- if (loc) {
441
- report.out.push(
442
- formatCodeFrameMessage(
443
- code,
444
- loc,
445
- `${flattenDiagnosticMessage(
446
- diag.messageText,
447
- report.display,
448
- report.formatSettings.newLineCharacter
449
- )} @ ${import_path.default.relative(currentDirectory, diag.file.fileName)}:${loc.start.line + 1}:${loc.start.character + 1}`
450
- )
451
- );
452
- }
453
- } else {
454
- report.out.push(
455
- flattenDiagnosticMessage(
456
- diag.messageText,
457
- report.display,
458
- report.formatSettings.newLineCharacter
459
- )
460
- );
461
- }
404
+ reportDiagnostic(report, diag);
462
405
  }
463
406
  }
464
407
  function formatCodeFrameMessage(code, loc, message) {
@@ -501,7 +444,7 @@ function coloredDiagnosticCategory(category) {
501
444
  );
502
445
  }
503
446
  }
504
- function findConfigFile(name) {
447
+ function findRootConfigFile(name) {
505
448
  return import_tsserverlibrary.default.findConfigFile(currentDirectory, import_tsserverlibrary.default.sys.fileExists, name);
506
449
  }
507
450
 
@@ -510,12 +453,10 @@ var args = (0, import_arg.default)(
510
453
  {
511
454
  "--project": String,
512
455
  "--display": String,
513
- "--emit": Boolean,
514
456
  "--help": Boolean,
515
457
  "--version": Boolean,
516
458
  "-p": "--project",
517
459
  "-d": "--display",
518
- "-e": "--emit",
519
460
  "-h": "--help",
520
461
  "-v": "--version"
521
462
  },
@@ -541,11 +482,6 @@ ${import_kleur2.default.bold("Options:")}
541
482
  )} Set the display type for error output. Choices: ${import_kleur2.default.green(
542
483
  `"codeframe"`
543
484
  )} or ${import_kleur2.default.green(`"condensed"`)} (default: ${import_kleur2.default.green(`"codeframe"`)})
544
- ${import_kleur2.default.yellow(
545
- "-e, --emit"
546
- )} Emit .js, .d.ts, .marko (with types stripped), and .d.marko files (default: ${import_kleur2.default.magenta(
547
- "false"
548
- )})
549
485
  ${import_kleur2.default.yellow(
550
486
  "-v, --version"
551
487
  )} Display the CLI version, Marko version, and TypeScript version
@@ -577,7 +513,6 @@ For more information, visit ${import_kleur2.default.blue(
577
513
  );
578
514
  } else {
579
515
  const {
580
- "--emit": emit,
581
516
  "--display": display = process.env.CI ? Display.condensed : Display.codeframe
582
517
  } = args;
583
518
  let { "--project": project } = args;
@@ -588,7 +523,7 @@ For more information, visit ${import_kleur2.default.blue(
588
523
  }
589
524
  }
590
525
  checkDisplay(display);
591
- run({ project, display, emit });
526
+ run({ project, display });
592
527
  }
593
528
  function checkDisplay(display) {
594
529
  if (display && Display[display] === void 0) {
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@marko/type-check",
3
3
  "description": "A CLI to type check Marko projects",
4
- "version": "0.0.18",
4
+ "version": "1.0.0",
5
5
  "bugs": "https://github.com/marko-js/language-server/issues/new?template=Bug_report.md",
6
6
  "dependencies": {
7
- "@babel/code-frame": "^7.22.5",
8
- "@marko/language-tools": "^2.1.4",
7
+ "@babel/code-frame": "^7.22.13",
8
+ "@marko/language-tools": "^2.1.5",
9
9
  "arg": "^5.0.2",
10
10
  "kleur": "^4.1.5",
11
11
  "strip-json-comments": "^3.1.1",
12
- "typescript": "^5.1.6"
12
+ "typescript": "^5.2.2"
13
13
  },
14
14
  "devDependencies": {
15
- "@types/babel__code-frame": "^7.0.3"
15
+ "@types/babel__code-frame": "^7.0.4"
16
16
  },
17
17
  "files": [
18
18
  "dist",