@tsslint/cli 2.0.3 → 2.0.5

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 (2) hide show
  1. package/index.js +69 -47
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -11,11 +11,11 @@ const os = require("os");
11
11
  const languagePlugins = require("./lib/languagePlugins.js");
12
12
  process.env.TSSLINT_CLI = '1';
13
13
  const _reset = '\x1b[0m';
14
- const darkGray = (s) => '\x1b[90m' + s + _reset;
15
- const lightRed = (s) => '\x1b[91m' + s + _reset;
16
- const lightGreen = (s) => '\x1b[92m' + s + _reset;
17
- const lightYellow = (s) => '\x1b[93m' + s + _reset;
18
- const lightBlue = (s) => '\x1b[94m' + s + _reset;
14
+ const gray = (s) => '\x1b[90m' + s + _reset;
15
+ const red = (s) => '\x1b[91m' + s + _reset;
16
+ const green = (s) => '\x1b[92m' + s + _reset;
17
+ const yellow = (s) => '\x1b[93m' + s + _reset;
18
+ const blue = (s) => '\x1b[94m' + s + _reset;
19
19
  const purple = (s) => '\x1b[95m' + s + _reset;
20
20
  const cyan = (s) => '\x1b[96m' + s + _reset;
21
21
  // https://talyian.github.io/ansicolors/
@@ -30,7 +30,7 @@ if (process.argv.includes('--threads')) {
30
30
  const threadsIndex = process.argv.indexOf('--threads');
31
31
  const threadsArg = process.argv[threadsIndex + 1];
32
32
  if (!threadsArg || threadsArg.startsWith('-')) {
33
- console.error(lightRed(`Missing argument for --threads.`));
33
+ console.error(red(`Missing argument for --threads.`));
34
34
  process.exit(1);
35
35
  }
36
36
  threads = Math.min(os.availableParallelism(), Number(threadsArg));
@@ -39,7 +39,6 @@ class Project {
39
39
  constructor(tsconfig, languages) {
40
40
  this.tsconfig = tsconfig;
41
41
  this.languages = languages;
42
- this.workers = [];
43
42
  this.fileNames = [];
44
43
  this.options = {};
45
44
  this.currentFileIndex = 0;
@@ -47,7 +46,7 @@ class Project {
47
46
  }
48
47
  async init(
49
48
  // @ts-expect-error
50
- clack) {
49
+ clack, filesFilter) {
51
50
  this.configFile = ts.findConfigFile(path.dirname(this.tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
52
51
  const labels = [];
53
52
  if (this.languages.length === 0) {
@@ -70,19 +69,28 @@ class Project {
70
69
  labels.push(astroColor('Astro'));
71
70
  }
72
71
  }
73
- const label = labels.join(darkGray(' | '));
72
+ const label = labels.join(gray(' | '));
74
73
  if (!this.configFile) {
75
- clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No tsslint.config.ts found)')}`);
74
+ clack.log.error(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No tsslint.config.ts found)')}`);
76
75
  return this;
77
76
  }
78
77
  const commonLine = await parseCommonLine(this.tsconfig, this.languages);
79
78
  this.fileNames = commonLine.fileNames;
80
79
  this.options = commonLine.options;
81
80
  if (!this.fileNames.length) {
82
- clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray('(No included files)')}`);
81
+ clack.log.message(`${label} ${gray(path.relative(process.cwd(), this.tsconfig))} ${gray('(0)')}`);
83
82
  return this;
84
83
  }
85
- clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${darkGray(`(${this.fileNames.length})`)}`);
84
+ const originalFileNamesLength = this.fileNames.length;
85
+ if (filesFilter.size) {
86
+ this.fileNames = this.fileNames.filter(f => filesFilter.has(f));
87
+ if (!this.fileNames.length) {
88
+ clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No files left after filter)')}`);
89
+ return this;
90
+ }
91
+ }
92
+ const filteredLengthDiff = originalFileNamesLength - this.fileNames.length;
93
+ clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length}${filteredLengthDiff ? `, skipped ${filteredLengthDiff}` : ''})`)}`);
86
94
  if (!process.argv.includes('--force')) {
87
95
  this.cache = cache.loadCache(this.tsconfig, this.configFile, ts.sys.createHash);
88
96
  }
@@ -112,7 +120,7 @@ class Project {
112
120
  const write = process.stdout.write.bind(process.stdout);
113
121
  process.stdout.write = (...args) => {
114
122
  if (spinnerStopingWarn && typeof args[0] === 'string') {
115
- args[0] = args[0].replace('▲', lightYellow('▲'));
123
+ args[0] = args[0].replace('▲', yellow('▲'));
116
124
  }
117
125
  // @ts-ignore
118
126
  return write(...args);
@@ -177,7 +185,7 @@ class Project {
177
185
  options = options.filter(option => !option.label.endsWith('(0)'));
178
186
  }
179
187
  if (!options.length) {
180
- clack.log.error(lightRed('No projects found.'));
188
+ clack.log.error(red('No projects found.'));
181
189
  process.exit(1);
182
190
  }
183
191
  const selectedTsconfigs = await clack.multiselect({
@@ -196,7 +204,7 @@ class Project {
196
204
  else {
197
205
  command += ` --${language}-project ` + selectedTsconfigs.join(' ');
198
206
  }
199
- clack.log.info(`${darkGray('Command:')} ${purple(command)}`);
207
+ clack.log.info(`${gray('Command:')} ${purple(command)}`);
200
208
  for (let tsconfig of selectedTsconfigs) {
201
209
  tsconfig = resolvePath(tsconfig);
202
210
  tsconfigAndLanguages.set(tsconfig, language ? [language] : []);
@@ -245,7 +253,7 @@ class Project {
245
253
  const searchGlob = process.argv[i];
246
254
  const tsconfigs = glob.sync(searchGlob);
247
255
  if (!tsconfigs.length) {
248
- clack.log.error(lightRed(`No projects found for ${projectFlag} ${searchGlob}.`));
256
+ clack.log.error(red(`No projects found for ${projectFlag} ${searchGlob}.`));
249
257
  process.exit(1);
250
258
  }
251
259
  for (let tsconfig of tsconfigs) {
@@ -259,13 +267,32 @@ class Project {
259
267
  }
260
268
  }
261
269
  if (!foundArg) {
262
- clack.log.error(lightRed(`Missing argument for ${projectFlag}.`));
270
+ clack.log.error(red(`Missing argument for ${projectFlag}.`));
263
271
  process.exit(1);
264
272
  }
265
273
  }
266
274
  }
275
+ // get filter glob option
276
+ let filterSet = new Set();
277
+ const filterArgIndex = process.argv.findIndex(arg => arg === '--filter');
278
+ if (filterArgIndex !== -1) {
279
+ for (let i = filterArgIndex + 1; i < process.argv.length; i++) {
280
+ const filterGlob = process.argv[i];
281
+ if (!filterGlob || filterGlob.startsWith('-')) {
282
+ clack.log.error(red(`Missing argument for --filter.`));
283
+ process.exit(1);
284
+ }
285
+ const fileNames = glob.sync(filterGlob).map(f => path.resolve(f));
286
+ for (const fileName of fileNames)
287
+ filterSet.add(fileName);
288
+ }
289
+ if (!filterSet.size) {
290
+ clack.log.error(red(`No files found after --filter files.`));
291
+ process.exit(1);
292
+ }
293
+ }
267
294
  for (const [tsconfig, languages] of tsconfigAndLanguages) {
268
- projects.push(await new Project(tsconfig, languages).init(clack));
295
+ projects.push(await new Project(tsconfig, languages).init(clack, filterSet));
269
296
  }
270
297
  spinner?.start();
271
298
  projects = projects.filter(project => !!project.configFile);
@@ -278,7 +305,7 @@ class Project {
278
305
  allFilesNum += project.fileNames.length;
279
306
  }
280
307
  if (allFilesNum === 0) {
281
- (spinner?.stop ?? clack.log.message)(lightYellow('No input files.'));
308
+ (spinner?.stop ?? clack.log.message)(yellow('No input files.'));
282
309
  process.exit(1);
283
310
  }
284
311
  if (isTTY || threads >= 2) {
@@ -290,33 +317,33 @@ class Project {
290
317
  await startWorker(worker.createLocal());
291
318
  }
292
319
  (spinner?.stop ?? clack.log.message)(cached
293
- ? darkGray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + darkGray(` to ignore cache.)`)
294
- : darkGray(`Processed ${processed} files.`));
320
+ ? gray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + gray(` to ignore cache.)`)
321
+ : gray(`Processed ${processed} files.`));
295
322
  const projectsFlag = process.argv.find(arg => arg.endsWith('-projects'));
296
323
  if (projectsFlag) {
297
- clack.log.warn(darkGray(`Please use `)
324
+ clack.log.warn(gray(`Please use `)
298
325
  + cyan(`${projectsFlag.slice(0, -1)}`)
299
- + darkGray(` instead of `)
326
+ + gray(` instead of `)
300
327
  + cyan(`${projectsFlag}`)
301
- + darkGray(` starting from version 1.5.0.`));
328
+ + gray(` starting from version 1.5.0.`));
302
329
  }
303
330
  const data = [
304
- [passed, 'passed', lightGreen],
305
- [errors, 'errors', lightRed],
306
- [warnings, 'warnings', lightYellow],
307
- [messages, 'messages', lightBlue],
308
- [suggestions, 'suggestions', darkGray],
309
- [excluded, 'excluded', darkGray],
331
+ [passed, 'passed', green],
332
+ [errors, 'errors', red],
333
+ [warnings, 'warnings', yellow],
334
+ [messages, 'messages', blue],
335
+ [suggestions, 'suggestions', gray],
336
+ [excluded, 'excluded', gray],
310
337
  ];
311
338
  let summary = data
312
339
  .filter(([count]) => count)
313
340
  .map(([count, label, color]) => color(`${count} ${label}`))
314
- .join(darkGray(' | '));
341
+ .join(gray(' | '));
315
342
  if (hasFix) {
316
- summary += darkGray(` (Use `) + cyan(`--fix`) + darkGray(` to apply automatic fixes.)`);
343
+ summary += gray(` (Use `) + cyan(`--fix`) + gray(` to apply automatic fixes.)`);
317
344
  }
318
345
  else if (errors || warnings || messages) {
319
- summary += darkGray(` (No fixes available.)`);
346
+ summary += gray(` (No fixes available.)`);
320
347
  }
321
348
  clack.outro(summary);
322
349
  process.exit((errors || messages) ? 1 : 0);
@@ -325,17 +352,12 @@ class Project {
325
352
  if (!unfinishedProjects.length) {
326
353
  return;
327
354
  }
328
- // Select a project that has not has a worker yet
329
- let project = unfinishedProjects.find(project => !project.workers.length);
355
+ // Select a project that does not have a worker yet
356
+ const project = unfinishedProjects.find(project => !project.worker);
330
357
  if (!project) {
331
- // Choose a project with the most files left per worker
332
- project = unfinishedProjects.sort((a, b) => {
333
- const aFilesPerWorker = (a.fileNames.length - a.currentFileIndex) / a.workers.length;
334
- const bFilesPerWorker = (b.fileNames.length - b.currentFileIndex) / b.workers.length;
335
- return bFilesPerWorker - aFilesPerWorker;
336
- })[0];
358
+ return;
337
359
  }
338
- project.workers.push(linterWorker);
360
+ project.worker = linterWorker;
339
361
  const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options);
340
362
  if (!setupSuccess) {
341
363
  projects = projects.filter(p => p !== project);
@@ -423,7 +445,7 @@ class Project {
423
445
  }
424
446
  async function getBuiltConfig(configFile) {
425
447
  if (!builtConfigs.has(configFile)) {
426
- builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(darkGray(s), code)));
448
+ builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(gray(s), code)));
427
449
  }
428
450
  return await builtConfigs.get(configFile);
429
451
  }
@@ -439,14 +461,14 @@ class Project {
439
461
  let msg;
440
462
  if (processFiles.size === 0) {
441
463
  if (nextFileName) {
442
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
464
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), nextFileName)}`);
443
465
  }
444
466
  }
445
467
  else if (processFiles.size === 1) {
446
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
468
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] ${path.relative(process.cwd(), [...processFiles][0])}`);
447
469
  }
448
470
  else {
449
- msg = darkGray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
471
+ msg = gray(`[${processed + processFiles.size}/${allFilesNum}] Processing ${processFiles.size} files`);
450
472
  }
451
473
  if (!spinner && isTTY) {
452
474
  spinner = clack.spinner();
@@ -488,7 +510,7 @@ class Project {
488
510
  return require.resolve(p, { paths: [process.cwd()] });
489
511
  }
490
512
  catch {
491
- clack.log.error(lightRed(`No such file: ${p}`));
513
+ clack.log.error(red(`No such file: ${p}`));
492
514
  process.exit(1);
493
515
  }
494
516
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/cli",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsslint": "./bin/tsslint.js"
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@clack/prompts": "^0.8.2",
19
- "@tsslint/config": "2.0.3",
20
- "@tsslint/core": "2.0.3",
19
+ "@tsslint/config": "2.0.5",
20
+ "@tsslint/core": "2.0.5",
21
21
  "@volar/language-core": "~2.4.0",
22
22
  "@volar/language-hub": "0.0.1",
23
23
  "@volar/typescript": "~2.4.0",
@@ -31,5 +31,5 @@
31
31
  "@vue-vine/language-service": "latest",
32
32
  "@vue/language-core": "latest"
33
33
  },
34
- "gitHead": "1950a26843ec8ca974ea4f10efa4b6ad36e2ffbf"
34
+ "gitHead": "29342ffe8a6a5cac8059107f9de4cbb45e367a39"
35
35
  }