@tsslint/cli 2.0.4 → 2.0.6

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 +55 -18
  2. package/package.json +6 -5
package/index.js CHANGED
@@ -8,6 +8,7 @@ const worker = require("./lib/worker.js");
8
8
  const glob = require("glob");
9
9
  const fs = require("fs");
10
10
  const os = require("os");
11
+ const minimatch = require("minimatch");
11
12
  const languagePlugins = require("./lib/languagePlugins.js");
12
13
  process.env.TSSLINT_CLI = '1';
13
14
  const _reset = '\x1b[0m';
@@ -39,7 +40,13 @@ class Project {
39
40
  constructor(tsconfig, languages) {
40
41
  this.tsconfig = tsconfig;
41
42
  this.languages = languages;
42
- this.workers = [];
43
+ /**
44
+ * file names for passing to ts language service host (getScriptFileNames)
45
+ */
46
+ this.rawFileNames = [];
47
+ /**
48
+ * file names after filter, for linting process
49
+ */
43
50
  this.fileNames = [];
44
51
  this.options = {};
45
52
  this.currentFileIndex = 0;
@@ -47,7 +54,7 @@ class Project {
47
54
  }
48
55
  async init(
49
56
  // @ts-expect-error
50
- clack) {
57
+ clack, filesFilter) {
51
58
  this.configFile = ts.findConfigFile(path.dirname(this.tsconfig), ts.sys.fileExists, 'tsslint.config.ts');
52
59
  const labels = [];
53
60
  if (this.languages.length === 0) {
@@ -76,13 +83,24 @@ class Project {
76
83
  return this;
77
84
  }
78
85
  const commonLine = await parseCommonLine(this.tsconfig, this.languages);
79
- this.fileNames = commonLine.fileNames;
86
+ this.rawFileNames = commonLine.fileNames;
80
87
  this.options = commonLine.options;
81
- if (!this.fileNames.length) {
82
- clack.log.warn(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray('(No included files)')}`);
88
+ if (!this.rawFileNames.length) {
89
+ clack.log.message(`${label} ${gray(path.relative(process.cwd(), this.tsconfig))} ${gray('(0)')}`);
83
90
  return this;
84
91
  }
85
- clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length})`)}`);
92
+ if (filesFilter.length) {
93
+ this.fileNames = this.rawFileNames.filter(fileName => filesFilter.some(filter => minimatch.minimatch(fileName, filter, { dot: true })));
94
+ if (!this.fileNames.length) {
95
+ clack.log.message(`${label} ${gray(path.relative(process.cwd(), this.tsconfig))} ${gray('(No files left after filter)')}`);
96
+ return this;
97
+ }
98
+ }
99
+ else {
100
+ this.fileNames = this.rawFileNames;
101
+ }
102
+ const filteredLengthDiff = this.rawFileNames.length - this.fileNames.length;
103
+ clack.log.info(`${label} ${path.relative(process.cwd(), this.tsconfig)} ${gray(`(${this.fileNames.length}${filteredLengthDiff ? `, skipped ${filteredLengthDiff}` : ''})`)}`);
86
104
  if (!process.argv.includes('--force')) {
87
105
  this.cache = cache.loadCache(this.tsconfig, this.configFile, ts.sys.createHash);
88
106
  }
@@ -264,8 +282,32 @@ class Project {
264
282
  }
265
283
  }
266
284
  }
285
+ function normalizeFilterGlobPath(filterGlob, expandDirToGlob = true) {
286
+ let filterPath = path.resolve(process.cwd(), filterGlob);
287
+ if (expandDirToGlob && fs.existsSync(filterPath) && fs.statSync(filterPath).isDirectory()) {
288
+ filterPath = path.join(filterPath, '**/*');
289
+ }
290
+ return ts.server.toNormalizedPath(filterPath);
291
+ }
292
+ const filters = [];
293
+ const filterArgIndex = process.argv.indexOf('--filter');
294
+ if (filterArgIndex !== -1) {
295
+ const filterGlob = process.argv[filterArgIndex + 1];
296
+ if (!filterGlob || filterGlob.startsWith('-')) {
297
+ clack.log.error(red(`Missing argument for --filter.`));
298
+ process.exit(1);
299
+ }
300
+ filters.push(normalizeFilterGlobPath(filterGlob));
301
+ for (let i = filterArgIndex + 2; i < process.argv.length; i++) {
302
+ const filterGlob = process.argv[i];
303
+ if (filterGlob.startsWith('-')) {
304
+ break;
305
+ }
306
+ filters.push(normalizeFilterGlobPath(filterGlob));
307
+ }
308
+ }
267
309
  for (const [tsconfig, languages] of tsconfigAndLanguages) {
268
- projects.push(await new Project(tsconfig, languages).init(clack));
310
+ projects.push(await new Project(tsconfig, languages).init(clack, filters));
269
311
  }
270
312
  spinner?.start();
271
313
  projects = projects.filter(project => !!project.configFile);
@@ -325,18 +367,13 @@ class Project {
325
367
  if (!unfinishedProjects.length) {
326
368
  return;
327
369
  }
328
- // Select a project that has not has a worker yet
329
- let project = unfinishedProjects.find(project => !project.workers.length);
370
+ // Select a project that does not have a worker yet
371
+ const project = unfinishedProjects.find(project => !project.worker);
330
372
  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];
337
- }
338
- project.workers.push(linterWorker);
339
- const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.fileNames, project.options);
373
+ return;
374
+ }
375
+ project.worker = linterWorker;
376
+ const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.builtConfig, project.rawFileNames, project.options);
340
377
  if (!setupSuccess) {
341
378
  projects = projects.filter(p => p !== project);
342
379
  startWorker(linterWorker);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsslint/cli",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "tsslint": "./bin/tsslint.js"
@@ -16,13 +16,14 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@clack/prompts": "^0.8.2",
19
- "@tsslint/config": "2.0.4",
20
- "@tsslint/core": "2.0.4",
19
+ "@tsslint/config": "2.0.6",
20
+ "@tsslint/core": "2.0.6",
21
21
  "@volar/language-core": "~2.4.0",
22
22
  "@volar/language-hub": "0.0.1",
23
23
  "@volar/typescript": "~2.4.0",
24
24
  "glob": "^10.4.1",
25
- "json5": "^2.2.3"
25
+ "json5": "^2.2.3",
26
+ "minimatch": "^10.0.1"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "typescript": "*"
@@ -31,5 +32,5 @@
31
32
  "@vue-vine/language-service": "latest",
32
33
  "@vue/language-core": "latest"
33
34
  },
34
- "gitHead": "6006d07f0f218840a49ae281f074970eed1eddbd"
35
+ "gitHead": "b5914c99cb269150c2518f0f7b097ad2a996296d"
35
36
  }