@tsslint/cli 2.0.7 → 3.0.0-alpha.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.
- package/bin/tsslint.js +1 -1
- package/index.js +24 -45
- package/lib/cache.d.ts +1 -1
- package/lib/cache.js +15 -6
- package/lib/worker.d.ts +3 -3
- package/lib/worker.js +15 -11
- package/package.json +6 -10
package/bin/tsslint.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env -S node --experimental-strip-types --no-warnings
|
|
2
2
|
require('../index');
|
package/index.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const ts = require("typescript");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const core = require("@tsslint/core");
|
|
6
5
|
const cache = require("./lib/cache.js");
|
|
7
6
|
const worker = require("./lib/worker.js");
|
|
8
7
|
const fs = require("fs");
|
|
9
|
-
const os = require("os");
|
|
10
8
|
const minimatch = require("minimatch");
|
|
11
9
|
const languagePlugins = require("./lib/languagePlugins.js");
|
|
12
10
|
process.env.TSSLINT_CLI = '1';
|
|
@@ -26,15 +24,15 @@ const vueVineColor = (s) => '\x1b[38;5;48m' + s + _reset;
|
|
|
26
24
|
const mdxColor = (s) => '\x1b[33m' + s + _reset;
|
|
27
25
|
const astroColor = (s) => '\x1b[38;5;209m' + s + _reset;
|
|
28
26
|
let threads = 1;
|
|
29
|
-
if (process.argv.includes('--threads')) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
27
|
+
// if (process.argv.includes('--threads')) {
|
|
28
|
+
// const threadsIndex = process.argv.indexOf('--threads');
|
|
29
|
+
// const threadsArg = process.argv[threadsIndex + 1];
|
|
30
|
+
// if (!threadsArg || threadsArg.startsWith('-')) {
|
|
31
|
+
// console.error(red(`Missing argument for --threads.`));
|
|
32
|
+
// process.exit(1);
|
|
33
|
+
// }
|
|
34
|
+
// threads = Math.min(os.availableParallelism(), Number(threadsArg));
|
|
35
|
+
// }
|
|
38
36
|
class Project {
|
|
39
37
|
constructor(tsconfig, languages) {
|
|
40
38
|
this.tsconfig = tsconfig;
|
|
@@ -107,7 +105,6 @@ class Project {
|
|
|
107
105
|
}
|
|
108
106
|
}
|
|
109
107
|
(async () => {
|
|
110
|
-
const builtConfigs = new Map();
|
|
111
108
|
const clack = await import('@clack/prompts');
|
|
112
109
|
const processFiles = new Set();
|
|
113
110
|
const tsconfigAndLanguages = new Map();
|
|
@@ -137,17 +134,11 @@ class Project {
|
|
|
137
134
|
}
|
|
138
135
|
if (![
|
|
139
136
|
'--project',
|
|
140
|
-
'--projects',
|
|
141
137
|
'--vue-project',
|
|
142
|
-
'--vue-projects',
|
|
143
138
|
'--vue-vine-project',
|
|
144
|
-
'--vue-vine-projects',
|
|
145
139
|
'--mdx-project',
|
|
146
|
-
'--mdx-projects',
|
|
147
140
|
'--astro-project',
|
|
148
|
-
'--astro-projects',
|
|
149
141
|
'--ts-macro-project',
|
|
150
|
-
'--ts-macro-projects',
|
|
151
142
|
].some(flag => process.argv.includes(flag))) {
|
|
152
143
|
const language = await clack.select({
|
|
153
144
|
message: 'Select framework',
|
|
@@ -222,34 +213,32 @@ class Project {
|
|
|
222
213
|
else {
|
|
223
214
|
const options = [
|
|
224
215
|
{
|
|
225
|
-
|
|
216
|
+
projectFlag: '--project',
|
|
226
217
|
language: undefined,
|
|
227
218
|
},
|
|
228
219
|
{
|
|
229
|
-
|
|
220
|
+
projectFlag: '--vue-project',
|
|
230
221
|
language: 'vue',
|
|
231
222
|
},
|
|
232
223
|
{
|
|
233
|
-
|
|
224
|
+
projectFlag: '--vue-vine-project',
|
|
234
225
|
language: 'vue-vine',
|
|
235
226
|
},
|
|
236
227
|
{
|
|
237
|
-
|
|
238
|
-
projectsFlag: '--mdx-projects',
|
|
228
|
+
projectFlag: '--mdx-project',
|
|
239
229
|
language: 'mdx',
|
|
240
230
|
},
|
|
241
231
|
{
|
|
242
|
-
|
|
232
|
+
projectFlag: '--astro-project',
|
|
243
233
|
language: 'astro',
|
|
244
234
|
},
|
|
245
235
|
{
|
|
246
|
-
|
|
236
|
+
projectFlag: '--ts-macro-project',
|
|
247
237
|
language: 'ts-macro',
|
|
248
238
|
},
|
|
249
239
|
];
|
|
250
|
-
for (const {
|
|
251
|
-
|
|
252
|
-
if (!projectFlag) {
|
|
240
|
+
for (const { projectFlag, language } of options) {
|
|
241
|
+
if (!process.argv.includes(projectFlag)) {
|
|
253
242
|
continue;
|
|
254
243
|
}
|
|
255
244
|
let foundArg = false;
|
|
@@ -311,10 +300,7 @@ class Project {
|
|
|
311
300
|
spinner?.start();
|
|
312
301
|
projects = projects.filter(project => !!project.configFile);
|
|
313
302
|
projects = projects.filter(project => !!project.fileNames.length);
|
|
314
|
-
|
|
315
|
-
project.builtConfig = await getBuiltConfig(project.configFile);
|
|
316
|
-
}
|
|
317
|
-
projects = projects.filter(project => !!project.builtConfig);
|
|
303
|
+
projects = projects.filter(project => !!project.configFile);
|
|
318
304
|
for (const project of projects) {
|
|
319
305
|
allFilesNum += project.fileNames.length;
|
|
320
306
|
}
|
|
@@ -333,13 +319,12 @@ class Project {
|
|
|
333
319
|
(spinner?.stop ?? clack.log.message)(cached
|
|
334
320
|
? gray(`Processed ${processed} files with cache. (Use `) + cyan(`--force`) + gray(` to ignore cache.)`)
|
|
335
321
|
: gray(`Processed ${processed} files.`));
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
clack.log.
|
|
339
|
-
+ cyan(`${
|
|
322
|
+
const deprecatedFlag = process.argv.find(arg => arg.endsWith('-projects'));
|
|
323
|
+
if (deprecatedFlag) {
|
|
324
|
+
clack.log.error(gray(`Use `)
|
|
325
|
+
+ cyan(`${deprecatedFlag.slice(0, -1)}`)
|
|
340
326
|
+ gray(` instead of `)
|
|
341
|
-
+ cyan(`${
|
|
342
|
-
+ gray(` starting from version 1.5.0.`));
|
|
327
|
+
+ cyan(`${deprecatedFlag}.`));
|
|
343
328
|
}
|
|
344
329
|
const data = [
|
|
345
330
|
[passed, 'passed', green],
|
|
@@ -372,7 +357,7 @@ class Project {
|
|
|
372
357
|
return;
|
|
373
358
|
}
|
|
374
359
|
project.worker = linterWorker;
|
|
375
|
-
const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.
|
|
360
|
+
const setupSuccess = await linterWorker.setup(project.tsconfig, project.languages, project.configFile, project.rawFileNames, project.options);
|
|
376
361
|
if (!setupSuccess) {
|
|
377
362
|
projects = projects.filter(p => p !== project);
|
|
378
363
|
startWorker(linterWorker);
|
|
@@ -457,12 +442,6 @@ class Project {
|
|
|
457
442
|
cache.saveCache(project.tsconfig, project.configFile, project.cache, ts.sys.createHash);
|
|
458
443
|
await startWorker(linterWorker);
|
|
459
444
|
}
|
|
460
|
-
async function getBuiltConfig(configFile) {
|
|
461
|
-
if (!builtConfigs.has(configFile)) {
|
|
462
|
-
builtConfigs.set(configFile, core.buildConfig(configFile, ts.sys.createHash, spinner, (s, code) => log(gray(s), code)));
|
|
463
|
-
}
|
|
464
|
-
return await builtConfigs.get(configFile);
|
|
465
|
-
}
|
|
466
445
|
function addProcessFile(fileName) {
|
|
467
446
|
processFiles.add(fileName);
|
|
468
447
|
updateSpinner();
|
package/lib/cache.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import core = require('@tsslint/core');
|
|
2
|
-
export type CacheData = Record<string, core.FileLintCache>;
|
|
2
|
+
export type CacheData = Record<string, /* fileName */ core.FileLintCache>;
|
|
3
3
|
export declare function loadCache(tsconfig: string, configFilePath: string, createHash?: (path: string) => string): CacheData;
|
|
4
4
|
export declare function saveCache(tsconfig: string, configFilePath: string, cache: CacheData, createHash?: (path: string) => string): void;
|
package/lib/cache.js
CHANGED
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadCache = loadCache;
|
|
4
4
|
exports.saveCache = saveCache;
|
|
5
|
-
const core = require("@tsslint/core");
|
|
6
5
|
const path = require("path");
|
|
7
6
|
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const pkg = require('../package.json');
|
|
8
9
|
function loadCache(tsconfig, configFilePath, createHash = btoa) {
|
|
9
|
-
const outDir =
|
|
10
|
-
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '_'
|
|
10
|
+
const outDir = getTsslintCachePath(configFilePath, createHash);
|
|
11
|
+
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '_'
|
|
12
|
+
+ createHash(JSON.stringify(process.argv)) + '_' + createHash(path.relative(outDir, tsconfig)) + '.cache.json';
|
|
11
13
|
const cacheFilePath = path.join(outDir, cacheFileName);
|
|
12
14
|
const cacheFileStat = fs.statSync(cacheFilePath, { throwIfNoEntry: false });
|
|
13
15
|
const configFileStat = fs.statSync(configFilePath, { throwIfNoEntry: false });
|
|
14
16
|
if (cacheFileStat?.isFile() && cacheFileStat.mtimeMs > (configFileStat?.mtimeMs ?? 0)) {
|
|
15
17
|
try {
|
|
16
|
-
return
|
|
18
|
+
return JSON.parse(fs.readFileSync(cacheFilePath, 'utf8'));
|
|
17
19
|
}
|
|
18
20
|
catch {
|
|
19
21
|
return {};
|
|
@@ -22,9 +24,16 @@ function loadCache(tsconfig, configFilePath, createHash = btoa) {
|
|
|
22
24
|
return {};
|
|
23
25
|
}
|
|
24
26
|
function saveCache(tsconfig, configFilePath, cache, createHash = btoa) {
|
|
25
|
-
const outDir =
|
|
26
|
-
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '_'
|
|
27
|
+
const outDir = getTsslintCachePath(configFilePath, createHash);
|
|
28
|
+
const cacheFileName = createHash(path.relative(outDir, configFilePath)) + '_'
|
|
29
|
+
+ createHash(JSON.stringify(process.argv)) + '_' + createHash(path.relative(outDir, tsconfig)) + '.cache.json';
|
|
27
30
|
const cacheFilePath = path.join(outDir, cacheFileName);
|
|
31
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
28
32
|
fs.writeFileSync(cacheFilePath, JSON.stringify(cache));
|
|
29
33
|
}
|
|
34
|
+
function getTsslintCachePath(configFilePath, createHash) {
|
|
35
|
+
const projectRoot = path.resolve(configFilePath, '..');
|
|
36
|
+
const projectHash = createHash(projectRoot);
|
|
37
|
+
return path.join(os.tmpdir(), 'tsslint-cache-' + pkg.version + '-' + projectHash);
|
|
38
|
+
}
|
|
30
39
|
//# sourceMappingURL=cache.js.map
|
package/lib/worker.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import ts = require('typescript');
|
|
2
2
|
import core = require('@tsslint/core');
|
|
3
3
|
export declare function createLocal(): {
|
|
4
|
-
setup(tsconfig: string, languages: string[], configFile: string,
|
|
4
|
+
setup(tsconfig: string, languages: string[], configFile: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
5
5
|
lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): ts.DiagnosticWithLocation[];
|
|
6
6
|
hasCodeFixes(fileName: string): boolean;
|
|
7
7
|
hasRules(fileName: string, minimatchCache: Record<string, boolean>): boolean;
|
|
8
8
|
};
|
|
9
9
|
export declare function create(): {
|
|
10
|
-
setup(tsconfig: string, languages: string[], configFile: string,
|
|
10
|
+
setup(tsconfig: string, languages: string[], configFile: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
11
11
|
lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): Promise<ts.DiagnosticWithLocation[]>;
|
|
12
12
|
hasCodeFixes(fileName: string): Promise<boolean>;
|
|
13
13
|
hasRules(fileName: string, minimatchCache: Record<string, boolean>): Promise<boolean>;
|
|
14
14
|
};
|
|
15
|
-
declare function setup(tsconfig: string, languages: string[], configFile: string,
|
|
15
|
+
declare function setup(tsconfig: string, languages: string[], configFile: string, _fileNames: string[], _options: ts.CompilerOptions): Promise<boolean>;
|
|
16
16
|
declare function lint(fileName: string, fix: boolean, fileCache: core.FileLintCache): readonly [ts.DiagnosticWithLocation[], core.FileLintCache];
|
|
17
17
|
declare function hasCodeFixes(fileName: string): boolean;
|
|
18
18
|
declare function hasRules(fileName: string, minimatchCache: core.FileLintCache[2]): readonly [boolean, Record<string, boolean>];
|
package/lib/worker.js
CHANGED
|
@@ -127,11 +127,11 @@ const handlers = {
|
|
|
127
127
|
hasCodeFixes,
|
|
128
128
|
hasRules,
|
|
129
129
|
};
|
|
130
|
-
async function setup(tsconfig, languages, configFile,
|
|
130
|
+
async function setup(tsconfig, languages, configFile, _fileNames, _options) {
|
|
131
131
|
const clack = await import('@clack/prompts');
|
|
132
132
|
let config;
|
|
133
133
|
try {
|
|
134
|
-
config = (await import(url.pathToFileURL(
|
|
134
|
+
config = (await import(url.pathToFileURL(configFile).toString())).default;
|
|
135
135
|
}
|
|
136
136
|
catch (err) {
|
|
137
137
|
if (err instanceof Error) {
|
|
@@ -188,7 +188,7 @@ async function setup(tsconfig, languages, configFile, builtConfig, _fileNames, _
|
|
|
188
188
|
languageService: linterLanguageService,
|
|
189
189
|
languageServiceHost: linterHost,
|
|
190
190
|
typescript: ts,
|
|
191
|
-
}, path.dirname(configFile), config, () =>
|
|
191
|
+
}, path.dirname(configFile), config, () => [], linterSyntaxOnlyLanguageService);
|
|
192
192
|
return true;
|
|
193
193
|
}
|
|
194
194
|
function lint(fileName, fix, fileCache) {
|
|
@@ -247,10 +247,12 @@ function lint(fileName, fix, fileCache) {
|
|
|
247
247
|
},
|
|
248
248
|
relatedInformation: diagnostic.relatedInformation?.map(info => ({
|
|
249
249
|
...info,
|
|
250
|
-
file: info.file
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
file: info.file
|
|
251
|
+
? {
|
|
252
|
+
fileName: info.file.fileName,
|
|
253
|
+
text: getFileText(info.file.fileName),
|
|
254
|
+
}
|
|
255
|
+
: undefined,
|
|
254
256
|
})),
|
|
255
257
|
}));
|
|
256
258
|
}
|
|
@@ -263,10 +265,12 @@ function lint(fileName, fix, fileCache) {
|
|
|
263
265
|
},
|
|
264
266
|
relatedInformation: diagnostic.relatedInformation?.map(info => ({
|
|
265
267
|
...info,
|
|
266
|
-
file: info.file
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
268
|
+
file: info.file
|
|
269
|
+
? {
|
|
270
|
+
fileName: info.file.fileName,
|
|
271
|
+
text: info.file.text,
|
|
272
|
+
}
|
|
273
|
+
: undefined,
|
|
270
274
|
})),
|
|
271
275
|
}));
|
|
272
276
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=22"
|
|
6
|
+
"node": ">=22.6.0"
|
|
7
7
|
},
|
|
8
8
|
"bin": {
|
|
9
9
|
"tsslint": "./bin/tsslint.js"
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@clack/prompts": "^0.8.2",
|
|
22
|
-
"@tsslint/config": "
|
|
23
|
-
"@tsslint/core": "
|
|
22
|
+
"@tsslint/config": "3.0.0-alpha.1",
|
|
23
|
+
"@tsslint/core": "3.0.0-alpha.1",
|
|
24
24
|
"@volar/language-core": "~2.4.0",
|
|
25
25
|
"@volar/language-hub": "0.0.1",
|
|
26
26
|
"@volar/typescript": "~2.4.0",
|
|
@@ -29,9 +29,5 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"typescript": "*"
|
|
31
31
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
"@vue/language-core": "latest"
|
|
35
|
-
},
|
|
36
|
-
"gitHead": "db83a7c7526c3245d2ffa6fe1c9fb04e77387959"
|
|
37
|
-
}
|
|
32
|
+
"gitHead": "eacd205927cda18d084e78cc21115578792f3955"
|
|
33
|
+
}
|