@marko/type-check 0.0.18 → 1.0.1

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 +318 -378
  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,371 @@ 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
- formatSettings
71
+ formatSettings,
72
+ hasErrors: false
93
73
  };
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,
74
+ const extraExtensions = import_language_tools.Processors.extensions.map((extension) => ({
75
+ extension,
76
+ isMixedContent: false,
77
+ scriptKind: import_tsserverlibrary.default.ScriptKind.Deferred
78
+ }));
79
+ const solutionHost = import_tsserverlibrary.default.createSolutionBuilderHost(
198
80
  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
81
+ (rootNames, options, compilerHost, oldProgram, configFileParsingDiagnostics, projectReferences) => {
82
+ if (!compilerHost) {
83
+ throw new Error("Expected compilerHost to be provided.");
84
+ }
85
+ const resolutionCache = import_tsserverlibrary.default.createModuleResolutionCache(
86
+ currentDirectory,
87
+ getCanonicalFileName,
88
+ options
89
+ );
90
+ const { readDirectory = import_tsserverlibrary.default.sys.readDirectory } = compilerHost;
91
+ compilerHost.readDirectory = (path3, extensions, exclude, include, depth) => readDirectory(
92
+ path3,
93
+ extensions == null ? void 0 : extensions.concat(import_language_tools.Processors.extensions),
94
+ exclude,
95
+ include,
96
+ depth
97
+ );
98
+ compilerHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options2, _containingSourceFile, _reusedNames) => {
99
+ let normalModuleLiterals = moduleLiterals;
100
+ let resolvedModules;
101
+ for (let i = 0; i < moduleLiterals.length; i++) {
102
+ const moduleLiteral = moduleLiterals[i];
103
+ const moduleName = moduleLiteral.text;
104
+ const processor = moduleName[0] !== "*" ? getProcessor(moduleName) : void 0;
105
+ if (processor) {
106
+ let isExternalLibraryImport = false;
107
+ let resolvedFileName;
108
+ if (fsPathReg.test(moduleName)) {
109
+ resolvedFileName = import_path.default.resolve(containingFile, "..", moduleName);
110
+ } else {
111
+ const [, nodeModuleName, relativeModulePath] = modulePartsReg.exec(moduleName);
112
+ const { resolvedModule } = import_tsserverlibrary.default.nodeModuleNameResolver(
113
+ `${nodeModuleName}/package.json`,
114
+ containingFile,
115
+ options2,
116
+ compilerHost,
117
+ resolutionCache,
118
+ redirectedReference
250
119
  );
120
+ if (resolvedModule) {
121
+ isExternalLibraryImport = true;
122
+ resolvedFileName = import_path.default.join(
123
+ resolvedModule.resolvedFileName,
124
+ "..",
125
+ relativeModulePath
126
+ );
127
+ }
251
128
  }
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;
129
+ if (!resolvedModules) {
130
+ resolvedModules = [];
131
+ normalModuleLiterals = [];
132
+ for (let j = 0; j < i; j++) {
133
+ resolvedModules.push(void 0);
134
+ normalModuleLiterals.push(moduleLiterals[j]);
265
135
  }
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;
136
+ }
137
+ if (resolvedFileName) {
138
+ if ((0, import_language_tools.isDefinitionFile)(resolvedFileName)) {
139
+ if (!compilerHost.fileExists(resolvedFileName)) {
140
+ resolvedFileName = void 0;
141
+ }
142
+ } else {
143
+ const ext = (0, import_language_tools.getExt)(resolvedFileName);
144
+ const definitionFile = `${resolvedFileName.slice(
145
+ 0,
146
+ -ext.length
147
+ )}.d${ext}`;
148
+ if (compilerHost.fileExists(definitionFile)) {
149
+ resolvedFileName = definitionFile;
150
+ } else if (!compilerHost.fileExists(resolvedFileName)) {
151
+ resolvedFileName = void 0;
152
+ }
276
153
  }
277
154
  }
155
+ resolvedModules.push({
156
+ resolvedModule: resolvedFileName ? {
157
+ resolvedFileName,
158
+ extension: processor.getScriptExtension(resolvedFileName),
159
+ isExternalLibraryImport
160
+ } : void 0
161
+ });
162
+ } else if (resolvedModules) {
163
+ resolvedModules.push(void 0);
164
+ normalModuleLiterals.push(moduleLiteral);
278
165
  }
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
166
  }
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++];
167
+ const normalResolvedModules = normalModuleLiterals.length ? normalModuleLiterals.map((moduleLiteral) => {
168
+ return import_tsserverlibrary.default.bundlerModuleNameResolver(
169
+ moduleLiteral.text,
170
+ containingFile,
171
+ options2,
172
+ compilerHost,
173
+ resolutionCache,
174
+ redirectedReference
175
+ );
176
+ }) : void 0;
177
+ if (resolvedModules) {
178
+ if (normalResolvedModules) {
179
+ for (let i = 0, j = 0; i < resolvedModules.length; i++) {
180
+ if (!resolvedModules[i]) {
181
+ resolvedModules[i] = normalResolvedModules[j++];
182
+ }
304
183
  }
305
184
  }
185
+ return resolvedModules;
186
+ } else {
187
+ return normalResolvedModules;
306
188
  }
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(
189
+ };
190
+ const getSourceFile = compilerHost.getSourceFile.bind(compilerHost);
191
+ compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
192
+ const processor = getProcessor(fileName);
193
+ const code = compilerHost.readFile(fileName);
194
+ if (code !== void 0) {
195
+ if (processor) {
196
+ const extracted = processor.extract(fileName, code);
197
+ const extractedCode = extracted.toString();
198
+ const sourceFile = import_tsserverlibrary.default.createSourceFile(
199
+ fileName,
200
+ extractedCode,
201
+ languageVersion,
202
+ true,
203
+ processor.getScriptKind(fileName)
204
+ );
205
+ sourceFile.version = import_crypto.default.createHash("md5").update(extractedCode).digest("hex");
206
+ extractCache.set(sourceFile, extracted);
207
+ return sourceFile;
208
+ }
209
+ return getSourceFile(
319
210
  fileName,
320
- extracted.toString(),
321
211
  languageVersion,
322
- true,
323
- processor.getScriptKind(fileName)
212
+ onError,
213
+ shouldCreateNewSourceFile
324
214
  );
325
- extractCache.set(sourceFile, extracted);
326
- return sourceFile;
327
215
  }
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
216
+ };
217
+ const builderProgram = import_tsserverlibrary.default.createEmitAndSemanticDiagnosticsBuilderProgram(
218
+ rootNames,
219
+ options,
220
+ compilerHost,
221
+ oldProgram,
222
+ configFileParsingDiagnostics,
223
+ projectReferences
224
+ );
225
+ const program = builderProgram.getProgram();
226
+ const builderEmit = builderProgram.emit.bind(builderProgram);
227
+ builderProgram.emit = (targetSourceFile, _writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers) => {
228
+ let writeFile = _writeFile;
229
+ if (_writeFile) {
230
+ const typeChecker = program.getTypeChecker();
231
+ const printer = import_tsserverlibrary.default.createPrinter({
232
+ noEmitHelpers: true,
233
+ removeComments: true
234
+ });
235
+ writeFile = (fileName, _text, writeByteOrderMark, onError, sourceFiles, data) => {
236
+ const processor = (sourceFiles == null ? void 0 : sourceFiles.length) === 1 && getProcessor(sourceFiles[0].fileName) || void 0;
237
+ if (processor) {
238
+ const [sourceFile] = sourceFiles;
239
+ const processorExt = (0, import_language_tools.getExt)(sourceFile.fileName);
240
+ const inDtsExt = processorExt + import_tsserverlibrary.default.Extension.Dts;
241
+ const inJsExt = processorExt + import_tsserverlibrary.default.Extension.Js;
242
+ const inExt = fileName.endsWith(inDtsExt) ? inDtsExt : fileName.endsWith(inJsExt) ? inJsExt : void 0;
243
+ if (!inExt) {
244
+ const msg = `Unexpected file extension: ${fileName}`;
245
+ if (onError) {
246
+ onError(msg);
247
+ return;
248
+ }
249
+ throw new Error(msg);
250
+ }
251
+ const isDts = inExt === inDtsExt;
252
+ let outFileName = fileName;
253
+ if ((0, import_language_tools.isDefinitionFile)(sourceFile.fileName)) {
254
+ if (!isDts)
255
+ return;
256
+ outFileName = fileName.slice(0, -inExt.length) + processorExt;
257
+ } else {
258
+ if (isDts && program.getSourceFile(
259
+ `${sourceFile.fileName.slice(
260
+ 0,
261
+ -processorExt.length
262
+ )}.d${processorExt}`
263
+ )) {
264
+ return;
265
+ }
266
+ outFileName = fileName.slice(0, -inExt.length) + (isDts ? ".d" : "") + processorExt;
267
+ }
268
+ const extracted = extractCache.get(
269
+ program.getSourceFile(sourceFile.fileName)
270
+ );
271
+ const printContext = {
272
+ extracted,
273
+ printer,
274
+ typeChecker,
275
+ sourceFile,
276
+ formatSettings: report.formatSettings
277
+ };
278
+ _writeFile(
279
+ outFileName,
280
+ isDts ? processor.printTypes(printContext).code : processor.print(printContext).code,
281
+ writeByteOrderMark,
282
+ onError,
283
+ sourceFiles,
284
+ data
285
+ );
286
+ } else {
287
+ _writeFile(
288
+ fileName,
289
+ _text,
290
+ writeByteOrderMark,
291
+ onError,
292
+ sourceFiles,
293
+ data
294
+ );
295
+ }
296
+ };
297
+ }
298
+ return builderEmit(
299
+ targetSourceFile,
300
+ writeFile,
301
+ cancellationToken,
302
+ emitOnlyDtsFiles,
303
+ customTransformers
304
+ );
305
+ };
306
+ return builderProgram;
307
+ },
308
+ (diag) => reportDiagnostic(report, diag)
336
309
  );
337
310
  const processors = import_language_tools.Processors.create({
338
311
  ts: import_tsserverlibrary.default,
339
- host,
340
- configFile
312
+ configFile,
313
+ host: solutionHost
341
314
  });
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
315
+ const getProcessor = (fileName) => {
316
+ const ext = (0, import_language_tools.getExt)(fileName);
317
+ return ext ? processors[ext] : void 0;
356
318
  };
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;
319
+ solutionHost.getParsedCommandLine = (fileName) => {
320
+ var _a, _b;
321
+ const parsedCommandLine = import_tsserverlibrary.default.getParsedCommandLineOfConfigFile(
322
+ fileName,
323
+ requiredTSCompilerOptions,
324
+ {
325
+ ...import_tsserverlibrary.default.sys,
326
+ onUnRecoverableConfigFileDiagnostic(diag) {
327
+ reportDiagnostic(report, diag);
328
+ }
329
+ },
330
+ void 0,
331
+ void 0,
332
+ extraExtensions
333
+ );
334
+ if (!parsedCommandLine)
335
+ return;
336
+ const finalRootNames = new Set(parsedCommandLine.fileNames);
337
+ for (const name in processors) {
338
+ const rootNames = (_b = (_a = processors[name]).getRootNames) == null ? void 0 : _b.call(_a);
339
+ if (rootNames) {
340
+ for (const rootName of rootNames) {
341
+ finalRootNames.add(rootName);
342
+ }
385
343
  }
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}`
344
+ }
345
+ parsedCommandLine.fileNames = [...finalRootNames];
346
+ return parsedCommandLine;
347
+ };
348
+ import_tsserverlibrary.default.createSolutionBuilder(solutionHost, [configFile], {}).build();
349
+ process.exitCode = report.hasErrors ? 1 : 0;
350
+ console.log(
351
+ report.out.join(
352
+ report.formatSettings.newLineCharacter + report.formatSettings.newLineCharacter
353
+ )
354
+ );
355
+ }
356
+ function reportDiagnostic(report, diag) {
357
+ if (diag.file && diag.start !== void 0) {
358
+ const extracted = extractCache.get(diag.file);
359
+ let code = diag.file.text;
360
+ let loc;
361
+ if (extracted) {
362
+ loc = extracted.sourceLocationAt(
363
+ diag.start,
364
+ diag.start + (diag.length || 0)
399
365
  );
366
+ code = extracted.parsed.code;
367
+ if (!loc)
368
+ return;
400
369
  } 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);
370
+ const start = import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start);
371
+ const end = diag.length ? import_tsserverlibrary.default.getLineAndCharacterOfPosition(diag.file, diag.start + diag.length) : start;
372
+ loc = {
373
+ start,
374
+ end
375
+ };
414
376
  }
377
+ const diagMessage = flattenDiagnosticMessage(
378
+ diag.messageText,
379
+ report.display,
380
+ report.formatSettings.newLineCharacter
381
+ );
382
+ report.out.push(
383
+ `${import_kleur.default.cyan(
384
+ import_path.default.relative(currentDirectory, diag.file.fileName)
385
+ )}:${import_kleur.default.yellow(loc.start.line + 1)}:${import_kleur.default.yellow(
386
+ loc.start.character + 1
387
+ )} - ${coloredDiagnosticCategory(diag.category)} ${import_kleur.default.dim(
388
+ `TS${diag.code}`
389
+ )}${report.formatSettings.newLineCharacter}${report.display === Display.codeframe ? report.formatSettings.newLineCharacter + formatCodeFrameMessage(code, loc, diagMessage) : diagMessage}`
390
+ );
391
+ } else {
392
+ report.out.push(
393
+ flattenDiagnosticMessage(
394
+ diag.messageText,
395
+ report.display,
396
+ report.formatSettings.newLineCharacter
397
+ )
398
+ );
399
+ }
400
+ if (!report.hasErrors && diag.category === import_tsserverlibrary.default.DiagnosticCategory.Error) {
401
+ report.hasErrors = true;
402
+ }
403
+ if (diag.relatedInformation && report.display === Display.codeframe) {
404
+ reportRelatedDiagnostics(report, diag.relatedInformation);
415
405
  }
416
406
  }
417
407
  function reportRelatedDiagnostics(report, diags) {
418
408
  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
- }
409
+ reportDiagnostic(report, diag);
462
410
  }
463
411
  }
464
412
  function formatCodeFrameMessage(code, loc, message) {
@@ -501,7 +449,7 @@ function coloredDiagnosticCategory(category) {
501
449
  );
502
450
  }
503
451
  }
504
- function findConfigFile(name) {
452
+ function findRootConfigFile(name) {
505
453
  return import_tsserverlibrary.default.findConfigFile(currentDirectory, import_tsserverlibrary.default.sys.fileExists, name);
506
454
  }
507
455
 
@@ -510,12 +458,10 @@ var args = (0, import_arg.default)(
510
458
  {
511
459
  "--project": String,
512
460
  "--display": String,
513
- "--emit": Boolean,
514
461
  "--help": Boolean,
515
462
  "--version": Boolean,
516
463
  "-p": "--project",
517
464
  "-d": "--display",
518
- "-e": "--emit",
519
465
  "-h": "--help",
520
466
  "-v": "--version"
521
467
  },
@@ -541,11 +487,6 @@ ${import_kleur2.default.bold("Options:")}
541
487
  )} Set the display type for error output. Choices: ${import_kleur2.default.green(
542
488
  `"codeframe"`
543
489
  )} 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
490
  ${import_kleur2.default.yellow(
550
491
  "-v, --version"
551
492
  )} Display the CLI version, Marko version, and TypeScript version
@@ -577,7 +518,6 @@ For more information, visit ${import_kleur2.default.blue(
577
518
  );
578
519
  } else {
579
520
  const {
580
- "--emit": emit,
581
521
  "--display": display = process.env.CI ? Display.condensed : Display.codeframe
582
522
  } = args;
583
523
  let { "--project": project } = args;
@@ -588,7 +528,7 @@ For more information, visit ${import_kleur2.default.blue(
588
528
  }
589
529
  }
590
530
  checkDisplay(display);
591
- run({ project, display, emit });
531
+ run({ project, display });
592
532
  }
593
533
  function checkDisplay(display) {
594
534
  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.1",
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",