@tsslint/core 1.3.1 → 1.3.3
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/index.d.ts +1 -1
- package/index.js +6 -4
- package/lib/build.d.ts +1 -1
- package/lib/build.js +3 -1
- package/lib/logger.d.ts +1 -0
- package/lib/logger.js +16 -0
- package/lib/watch.d.ts +1 -1
- package/lib/watch.js +32 -17
- package/package.json +9 -3
- package/scripts/cleanCache.js +20 -0
package/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type FileLintCache = [
|
|
|
10
10
|
minimatchResult: Record<string, boolean>
|
|
11
11
|
];
|
|
12
12
|
export type Linter = ReturnType<typeof createLinter>;
|
|
13
|
-
export declare function createLinter(ctx: ProjectContext, config: Config | Config[], mode: 'cli' | 'typescript-plugin'): {
|
|
13
|
+
export declare function createLinter(ctx: ProjectContext, config: Config | Config[], mode: 'cli' | 'typescript-plugin', logger?: typeof import('@clack/prompts')): {
|
|
14
14
|
lint(fileName: string, cache?: FileLintCache): ts.DiagnosticWithLocation[];
|
|
15
15
|
hasCodeFixes(fileName: string): boolean;
|
|
16
16
|
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[], cache?: FileLintCache): ts.CodeFixAction[];
|
package/index.js
CHANGED
|
@@ -22,7 +22,9 @@ __exportStar(require("./lib/watch"), exports);
|
|
|
22
22
|
const ErrorStackParser = require("error-stack-parser");
|
|
23
23
|
const path = require("path");
|
|
24
24
|
const minimatch = require("minimatch");
|
|
25
|
-
function createLinter(ctx, config, mode
|
|
25
|
+
function createLinter(ctx, config, mode,
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
logger) {
|
|
26
28
|
if (mode === 'typescript-plugin') {
|
|
27
29
|
require('source-map-support').install({
|
|
28
30
|
retrieveFile(path) {
|
|
@@ -48,9 +50,6 @@ function createLinter(ctx, config, mode) {
|
|
|
48
50
|
const ts = ctx.typescript;
|
|
49
51
|
const languageService = new Proxy(ctx.languageService, {
|
|
50
52
|
get(target, key, receiver) {
|
|
51
|
-
if (!languageServiceUsage && debug) {
|
|
52
|
-
console.log('Type-aware mode enabled');
|
|
53
|
-
}
|
|
54
53
|
languageServiceUsage++;
|
|
55
54
|
return Reflect.get(target, key, receiver);
|
|
56
55
|
},
|
|
@@ -237,6 +236,9 @@ function createLinter(ctx, config, mode) {
|
|
|
237
236
|
debugInfo.messageText += ` - ${currentRuleId} (❌ ${err && typeof err === 'object' && 'stack' in err ? err.stack : String(err)}})\n`;
|
|
238
237
|
}
|
|
239
238
|
}
|
|
239
|
+
if (debug && !!currentRuleLanguageServiceUsage !== !!languageServiceUsage) {
|
|
240
|
+
logger?.log.message(`Type-aware mode enabled by ${currentRuleId} rule.`);
|
|
241
|
+
}
|
|
240
242
|
if (cache && currentRuleLanguageServiceUsage === languageServiceUsage) {
|
|
241
243
|
cachedRules.set(currentRuleId, currentFixes);
|
|
242
244
|
}
|
package/lib/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Config } from '@tsslint/config';
|
|
2
|
-
export declare function buildConfigFile(configFilePath: string, createHash?: (path: string) => string, logger?:
|
|
2
|
+
export declare function buildConfigFile(configFilePath: string, createHash?: (path: string) => string, logger?: typeof import('@clack/prompts')): Promise<Config | Config[]>;
|
package/lib/build.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildConfigFile = buildConfigFile;
|
|
4
4
|
const watch_1 = require("./watch");
|
|
5
|
-
function buildConfigFile(configFilePath, createHash,
|
|
5
|
+
function buildConfigFile(configFilePath, createHash,
|
|
6
|
+
// @ts-expect-error
|
|
7
|
+
logger) {
|
|
6
8
|
return new Promise((resolve, reject) => {
|
|
7
9
|
(0, watch_1.watchConfigFile)(configFilePath, (config, result) => {
|
|
8
10
|
if (config) {
|
package/lib/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function startLoad(text: string): (endText: string) => void;
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startLoad = startLoad;
|
|
4
|
+
const frames = ['-', '\\', '|', '/'];
|
|
5
|
+
function startLoad(text) {
|
|
6
|
+
const start = Date.now();
|
|
7
|
+
let i = 0;
|
|
8
|
+
const loadingInterval = setInterval(() => {
|
|
9
|
+
process.stdout.write(`\r${frames[i++ % frames.length]} ${text}...`);
|
|
10
|
+
}, 100);
|
|
11
|
+
return (endText) => {
|
|
12
|
+
clearInterval(loadingInterval);
|
|
13
|
+
process.stdout.write(`\r${endText} in ${Date.now() - start}ms\n`);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=logger.js.map
|
package/lib/watch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import esbuild = require('esbuild');
|
|
2
2
|
import type { Config } from '@tsslint/config';
|
|
3
|
-
export declare function watchConfigFile(configFilePath: string, onBuild: (config: Config | Config[] | undefined, result: esbuild.BuildResult) => void, watch?: boolean, createHash?: (path: string) => string, logger?:
|
|
3
|
+
export declare function watchConfigFile(configFilePath: string, onBuild: (config: Config | Config[] | undefined, result: esbuild.BuildResult) => void, watch?: boolean, createHash?: (path: string) => string, logger?: typeof import('@clack/prompts')): Promise<esbuild.BuildContext<{
|
|
4
4
|
entryPoints: string[];
|
|
5
5
|
bundle: true;
|
|
6
6
|
sourcemap: true;
|
package/lib/watch.js
CHANGED
|
@@ -7,14 +7,14 @@ const _path = require("path");
|
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const url = require("url");
|
|
9
9
|
const ErrorStackParser = require("error-stack-parser");
|
|
10
|
-
async function watchConfigFile(configFilePath, onBuild, watch = true, createHash = btoa,
|
|
11
|
-
|
|
10
|
+
async function watchConfigFile(configFilePath, onBuild, watch = true, createHash = btoa,
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
logger) {
|
|
12
13
|
const outDir = getDotTsslintPath(configFilePath);
|
|
13
14
|
const outFileName = createHash(_path.relative(outDir, configFilePath)) + '.mjs';
|
|
14
15
|
const outFile = _path.join(outDir, outFileName);
|
|
16
|
+
const configFileDisplayPath = _path.relative(process.cwd(), configFilePath);
|
|
15
17
|
const resultHandler = async (result) => {
|
|
16
|
-
const t1 = Date.now() - start;
|
|
17
|
-
start = Date.now();
|
|
18
18
|
let config;
|
|
19
19
|
for (const error of [
|
|
20
20
|
...result.errors,
|
|
@@ -27,11 +27,17 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
27
27
|
error.id = 'config-build-error';
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
const buildResultText = 'Built ' + configFileDisplayPath + ' in ' + (Date.now() - buildStart) + 'ms';
|
|
31
|
+
configBuildingSpinner?.message(buildResultText);
|
|
30
32
|
if (!result.errors.length) {
|
|
33
|
+
const loadStart = Date.now();
|
|
34
|
+
configBuildingSpinner?.message(buildResultText + ', importing...');
|
|
31
35
|
try {
|
|
32
36
|
config = (await import(url.pathToFileURL(outFile).toString() + '?time=' + Date.now())).default;
|
|
37
|
+
configBuildingSpinner?.stop(buildResultText + ', imported in ' + (Date.now() - loadStart) + 'ms.');
|
|
33
38
|
}
|
|
34
39
|
catch (e) {
|
|
40
|
+
configBuildingSpinner?.stop(buildResultText + ', failed to import.');
|
|
35
41
|
if (e.stack) {
|
|
36
42
|
const stack = ErrorStackParser.parse(e)[0];
|
|
37
43
|
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
@@ -67,10 +73,11 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
67
73
|
}
|
|
68
74
|
}
|
|
69
75
|
}
|
|
70
|
-
const t2 = Date.now() - start;
|
|
71
|
-
logger.log(`Built ${_path.relative(process.cwd(), configFilePath)} in ${t1}ms, loaded ${config ? 'successfully' : 'with errors'} in ${t2}ms`);
|
|
72
76
|
onBuild(config, result);
|
|
73
77
|
};
|
|
78
|
+
let buildStart;
|
|
79
|
+
const configBuildingSpinner = logger?.spinner();
|
|
80
|
+
configBuildingSpinner?.start('Building ' + configFileDisplayPath);
|
|
74
81
|
const ctx = await esbuild.context({
|
|
75
82
|
entryPoints: [configFilePath],
|
|
76
83
|
bundle: true,
|
|
@@ -82,25 +89,33 @@ async function watchConfigFile(configFilePath, onBuild, watch = true, createHash
|
|
|
82
89
|
name: 'tsslint',
|
|
83
90
|
setup(build) {
|
|
84
91
|
build.onStart(() => {
|
|
85
|
-
|
|
92
|
+
buildStart = Date.now();
|
|
86
93
|
});
|
|
87
|
-
build.onResolve({ filter: /^https?:\/\// }, async ({ path:
|
|
88
|
-
const cachePath = _path.join(outDir,
|
|
94
|
+
build.onResolve({ filter: /^https?:\/\// }, async ({ path: importUrl }) => {
|
|
95
|
+
const cachePath = _path.join(outDir, importUrl.split('://')[0], ...importUrl.split('://')[1].split('/'));
|
|
89
96
|
if (!fs.existsSync(cachePath)) {
|
|
90
|
-
|
|
91
|
-
const response = await fetch(
|
|
97
|
+
configBuildingSpinner?.message('Downloading ' + importUrl);
|
|
98
|
+
const response = await fetch(importUrl);
|
|
99
|
+
configBuildingSpinner?.message('Building ' + configFileDisplayPath);
|
|
92
100
|
if (!response.ok) {
|
|
93
|
-
throw new Error(`Failed to load ${
|
|
101
|
+
throw new Error(`Failed to load ${importUrl}`);
|
|
94
102
|
}
|
|
95
|
-
console.timeEnd('Download ' + url);
|
|
96
103
|
const text = await response.text();
|
|
97
104
|
fs.mkdirSync(_path.dirname(cachePath), { recursive: true });
|
|
98
105
|
fs.writeFileSync(cachePath, text, 'utf8');
|
|
99
106
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
if (isTsFile(cachePath)) {
|
|
108
|
+
return {
|
|
109
|
+
path: cachePath,
|
|
110
|
+
external: false,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
return {
|
|
115
|
+
path: url.pathToFileURL(cachePath).toString(),
|
|
116
|
+
external: true,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
104
119
|
});
|
|
105
120
|
build.onResolve({ filter: /.*/ }, ({ path, resolveDir }) => {
|
|
106
121
|
if (!isTsFile(path)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/core",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,11 +12,17 @@
|
|
|
12
12
|
"directory": "packages/core"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/types": "1.3.
|
|
15
|
+
"@tsslint/types": "1.3.3",
|
|
16
16
|
"error-stack-parser": "^2.1.4",
|
|
17
17
|
"esbuild": ">=0.17.0",
|
|
18
18
|
"minimatch": "^10.0.1",
|
|
19
19
|
"source-map-support": "^0.5.21"
|
|
20
20
|
},
|
|
21
|
-
"
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@clack/prompts": "^0.8.2"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"postinstall": "node scripts/cleanCache.js"
|
|
26
|
+
},
|
|
27
|
+
"gitHead": "0603ce9e9688c96478f96522b56335830390f740"
|
|
22
28
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
let dir = __dirname;
|
|
5
|
+
|
|
6
|
+
while (true) {
|
|
7
|
+
const cachePath = path.join(dir, 'node_modules', '.tsslint');
|
|
8
|
+
if (fs.existsSync(cachePath)) {
|
|
9
|
+
console.log(`Removing ${cachePath}`);
|
|
10
|
+
fs.rmSync(cachePath, { recursive: true });
|
|
11
|
+
break;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const parentDir = path.resolve(dir, '..');
|
|
15
|
+
if (parentDir === dir) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
dir = parentDir;
|
|
20
|
+
}
|