@tsslint/typescript-plugin 0.0.0 → 0.0.2
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/LICENSE +21 -0
- package/index.js +180 -82
- package/lib/builtInPlugins.d.ts +1 -1
- package/lib/builtInPlugins.js +22 -51
- package/lib/watchConfig.d.ts +2 -12
- package/lib/watchConfig.js +72 -40
- package/package.json +7 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Johnson Chu
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
CHANGED
|
@@ -22,51 +22,207 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
const watchConfig_1 = require("./lib/watchConfig");
|
|
26
25
|
const builtInPlugins_1 = require("./lib/builtInPlugins");
|
|
27
26
|
const path = __importStar(require("path"));
|
|
27
|
+
const languageServiceDecorators = new WeakMap();
|
|
28
28
|
const init = (modules) => {
|
|
29
29
|
const { typescript: ts } = modules;
|
|
30
30
|
const pluginModule = {
|
|
31
31
|
create(info) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
if (!languageServiceDecorators.has(info.languageService)) {
|
|
33
|
+
const tsconfig = info.project.projectKind === ts.server.ProjectKind.Configured
|
|
34
|
+
? info.project.getProjectName()
|
|
35
|
+
: undefined;
|
|
36
|
+
if (tsconfig) {
|
|
37
|
+
languageServiceDecorators.set(info.languageService, decorateLanguageService(ts, tsconfig, info));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
languageServiceDecorators.get(info.languageService)?.update(info.config);
|
|
41
|
+
return info.languageService;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
return pluginModule;
|
|
45
|
+
};
|
|
46
|
+
function decorateLanguageService(ts, tsconfig, info) {
|
|
47
|
+
const getCompilerOptionsDiagnostics = info.languageService.getCompilerOptionsDiagnostics;
|
|
48
|
+
const getSyntacticDiagnostics = info.languageService.getSyntacticDiagnostics;
|
|
49
|
+
const getApplicableRefactors = info.languageService.getApplicableRefactors;
|
|
50
|
+
const getEditsForRefactor = info.languageService.getEditsForRefactor;
|
|
51
|
+
let configFile;
|
|
52
|
+
let configFileBuildContext;
|
|
53
|
+
let configFileDiagnostics = [];
|
|
54
|
+
let config;
|
|
55
|
+
let plugins = [];
|
|
56
|
+
info.languageService.getCompilerOptionsDiagnostics = () => {
|
|
57
|
+
return getCompilerOptionsDiagnostics().concat(configFileDiagnostics);
|
|
58
|
+
};
|
|
59
|
+
info.languageService.getSyntacticDiagnostics = fileName => {
|
|
60
|
+
let errors = getSyntacticDiagnostics(fileName);
|
|
61
|
+
errors = errors.concat(configFileDiagnostics);
|
|
62
|
+
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
63
|
+
if (!sourceFile) {
|
|
64
|
+
return errors;
|
|
65
|
+
}
|
|
66
|
+
const token = info.languageServiceHost.getCancellationToken?.();
|
|
67
|
+
for (const plugin of plugins) {
|
|
68
|
+
if (token?.isCancellationRequested()) {
|
|
69
|
+
break;
|
|
37
70
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
71
|
+
if (plugin.lint) {
|
|
72
|
+
let pluginResult = plugin.lint?.(sourceFile, config?.rules ?? {});
|
|
73
|
+
for (const plugin of plugins) {
|
|
74
|
+
if (plugin.resolveResult) {
|
|
75
|
+
pluginResult = plugin.resolveResult(pluginResult);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
errors = errors.concat(pluginResult);
|
|
40
79
|
}
|
|
41
|
-
|
|
80
|
+
}
|
|
81
|
+
if (config?.debug) {
|
|
82
|
+
errors.push({
|
|
83
|
+
category: ts.DiagnosticCategory.Message,
|
|
84
|
+
source: 'tsslint',
|
|
85
|
+
code: 'debug-info',
|
|
86
|
+
messageText: JSON.stringify({
|
|
87
|
+
rules: Object.keys(config?.rules ?? {}),
|
|
88
|
+
plugins: plugins.length,
|
|
89
|
+
configFile,
|
|
90
|
+
tsconfig,
|
|
91
|
+
}, null, 2),
|
|
92
|
+
file: sourceFile,
|
|
93
|
+
start: 0,
|
|
94
|
+
length: 0,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return errors;
|
|
98
|
+
};
|
|
99
|
+
info.languageService.getApplicableRefactors = (fileName, positionOrRange, ...rest) => {
|
|
100
|
+
let refactors = getApplicableRefactors(fileName, positionOrRange, ...rest);
|
|
101
|
+
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
102
|
+
if (!sourceFile) {
|
|
103
|
+
return refactors;
|
|
104
|
+
}
|
|
105
|
+
const token = info.languageServiceHost.getCancellationToken?.();
|
|
106
|
+
for (const plugin of plugins) {
|
|
107
|
+
if (token?.isCancellationRequested()) {
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
refactors = refactors.concat(plugin.getFixes?.(sourceFile, positionOrRange) ?? []);
|
|
111
|
+
}
|
|
112
|
+
return refactors;
|
|
113
|
+
};
|
|
114
|
+
info.languageService.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest) => {
|
|
115
|
+
const sourceFile = info.languageService.getProgram()?.getSourceFile(fileName);
|
|
116
|
+
if (!sourceFile) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (const plugin of plugins) {
|
|
120
|
+
const edits = plugin.fix?.(sourceFile, refactorName, actionName);
|
|
121
|
+
if (edits) {
|
|
122
|
+
return { edits };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return getEditsForRefactor(fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest);
|
|
126
|
+
};
|
|
127
|
+
return { update };
|
|
128
|
+
async function update(pluginConfig) {
|
|
129
|
+
let configOptionSpan = { start: 0, length: 0 };
|
|
130
|
+
let newConfigFile;
|
|
131
|
+
let configImportPath;
|
|
132
|
+
let configResolveError;
|
|
133
|
+
const jsonConfigFile = ts.readJsonConfigFile(tsconfig, ts.sys.readFile);
|
|
134
|
+
try {
|
|
135
|
+
configImportPath = require.resolve('@tsslint/config', { paths: [path.dirname(tsconfig)] });
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
configResolveError = err;
|
|
139
|
+
configFileDiagnostics = [{
|
|
140
|
+
category: ts.DiagnosticCategory.Error,
|
|
141
|
+
code: 0,
|
|
142
|
+
messageText: String(err),
|
|
143
|
+
file: jsonConfigFile,
|
|
144
|
+
start: 0,
|
|
145
|
+
length: 0,
|
|
146
|
+
}];
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const { findConfigFile, watchConfigFile } = require(configImportPath);
|
|
150
|
+
if (pluginConfig?.configFile) {
|
|
151
|
+
configOptionSpan = {
|
|
152
|
+
start: jsonConfigFile.text.indexOf(pluginConfig.configFile) - 1,
|
|
153
|
+
length: pluginConfig.configFile.length + 2,
|
|
154
|
+
};
|
|
42
155
|
try {
|
|
43
|
-
|
|
156
|
+
newConfigFile = require.resolve(pluginConfig.configFile, { paths: [path.dirname(tsconfig)] });
|
|
44
157
|
}
|
|
45
158
|
catch (err) {
|
|
46
|
-
|
|
159
|
+
configResolveError = err;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
newConfigFile = findConfigFile(tsconfig);
|
|
164
|
+
}
|
|
165
|
+
if (newConfigFile !== configFile) {
|
|
166
|
+
configFile = newConfigFile;
|
|
167
|
+
config = undefined;
|
|
168
|
+
plugins = [];
|
|
169
|
+
configFileBuildContext?.dispose();
|
|
170
|
+
configFileDiagnostics = [];
|
|
171
|
+
if (configResolveError) {
|
|
172
|
+
configFileDiagnostics.push({
|
|
173
|
+
category: ts.DiagnosticCategory.Error,
|
|
174
|
+
code: 0,
|
|
175
|
+
messageText: String(configResolveError),
|
|
176
|
+
file: jsonConfigFile,
|
|
177
|
+
start: configOptionSpan.start,
|
|
178
|
+
length: configOptionSpan.length,
|
|
179
|
+
});
|
|
47
180
|
}
|
|
48
181
|
if (!configFile) {
|
|
49
|
-
return
|
|
182
|
+
return;
|
|
50
183
|
}
|
|
51
|
-
let config;
|
|
52
|
-
let plugins = [];
|
|
53
|
-
const languageServiceHost = info.languageServiceHost;
|
|
54
|
-
const languageService = info.languageService;
|
|
55
184
|
const projectContext = {
|
|
56
185
|
configFile,
|
|
57
186
|
tsconfig,
|
|
58
|
-
languageServiceHost,
|
|
59
|
-
languageService,
|
|
187
|
+
languageServiceHost: info.languageServiceHost,
|
|
188
|
+
languageService: info.languageService,
|
|
60
189
|
typescript: ts,
|
|
61
190
|
};
|
|
62
|
-
|
|
63
|
-
(0, watchConfig_1.watchConfig)(configFile, async (_config, result) => {
|
|
191
|
+
configFileBuildContext = await watchConfigFile(configFile, async (_config, { errors, warnings }) => {
|
|
64
192
|
config = _config;
|
|
193
|
+
configFileDiagnostics = [
|
|
194
|
+
...errors.map(error => [error, ts.DiagnosticCategory.Error]),
|
|
195
|
+
...warnings.map(error => [error, ts.DiagnosticCategory.Warning]),
|
|
196
|
+
].map(([error, category]) => {
|
|
197
|
+
const diag = {
|
|
198
|
+
category,
|
|
199
|
+
source: 'tsslint',
|
|
200
|
+
code: 0,
|
|
201
|
+
messageText: 'Failed to build config',
|
|
202
|
+
file: jsonConfigFile,
|
|
203
|
+
start: configOptionSpan.start,
|
|
204
|
+
length: configOptionSpan.length,
|
|
205
|
+
};
|
|
206
|
+
if (error.location) {
|
|
207
|
+
const fileName = path.resolve(error.location.file);
|
|
208
|
+
const fileText = ts.sys.readFile(error.location.file);
|
|
209
|
+
const sourceFile = ts.createSourceFile(fileName, fileText ?? '', ts.ScriptTarget.Latest, true);
|
|
210
|
+
diag.relatedInformation = [{
|
|
211
|
+
category,
|
|
212
|
+
code: error.id,
|
|
213
|
+
messageText: error.text,
|
|
214
|
+
file: sourceFile,
|
|
215
|
+
start: sourceFile.getPositionOfLineAndCharacter(error.location.line - 1, error.location.column),
|
|
216
|
+
length: error.location.lineText.length,
|
|
217
|
+
}];
|
|
218
|
+
}
|
|
219
|
+
return diag;
|
|
220
|
+
});
|
|
65
221
|
if (config) {
|
|
66
222
|
plugins = await Promise.all([
|
|
67
223
|
...builtInPlugins_1.builtInPlugins,
|
|
68
224
|
...config.plugins ?? []
|
|
69
|
-
].map(plugin => plugin(projectContext
|
|
225
|
+
].map(plugin => plugin(projectContext)));
|
|
70
226
|
for (const plugin of plugins) {
|
|
71
227
|
if (plugin.resolveRules) {
|
|
72
228
|
config.rules = plugin.resolveRules(config.rules ?? {});
|
|
@@ -75,66 +231,8 @@ const init = (modules) => {
|
|
|
75
231
|
}
|
|
76
232
|
info.project.refreshDiagnostics();
|
|
77
233
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const getApplicableRefactors = languageService.getApplicableRefactors;
|
|
82
|
-
const getEditsForRefactor = languageService.getEditsForRefactor;
|
|
83
|
-
languageService.getSyntacticDiagnostics = fileName => {
|
|
84
|
-
let errors = getSyntacticDiagnostics(fileName);
|
|
85
|
-
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
|
|
86
|
-
if (!sourceFile) {
|
|
87
|
-
return errors;
|
|
88
|
-
}
|
|
89
|
-
const token = languageServiceHost.getCancellationToken?.();
|
|
90
|
-
for (const plugin of plugins) {
|
|
91
|
-
if (token?.isCancellationRequested()) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
if (plugin.lint) {
|
|
95
|
-
let pluginResult = plugin.lint?.(sourceFile, config?.rules ?? {});
|
|
96
|
-
for (const plugin of plugins) {
|
|
97
|
-
if (plugin.resolveResult) {
|
|
98
|
-
pluginResult = plugin.resolveResult(pluginResult);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
errors = errors.concat(pluginResult);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return errors;
|
|
105
|
-
};
|
|
106
|
-
languageService.getApplicableRefactors = (fileName, positionOrRange, ...rest) => {
|
|
107
|
-
let refactors = getApplicableRefactors(fileName, positionOrRange, ...rest);
|
|
108
|
-
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
|
|
109
|
-
if (!sourceFile) {
|
|
110
|
-
return refactors;
|
|
111
|
-
}
|
|
112
|
-
const token = languageServiceHost.getCancellationToken?.();
|
|
113
|
-
for (const plugin of plugins) {
|
|
114
|
-
if (token?.isCancellationRequested()) {
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
refactors = refactors.concat(plugin.getFixes?.(sourceFile, positionOrRange) ?? []);
|
|
118
|
-
}
|
|
119
|
-
return refactors;
|
|
120
|
-
};
|
|
121
|
-
languageService.getEditsForRefactor = (fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest) => {
|
|
122
|
-
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
|
|
123
|
-
if (!sourceFile) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
for (const plugin of plugins) {
|
|
127
|
-
const edits = plugin.fix?.(sourceFile, refactorName, actionName);
|
|
128
|
-
if (edits) {
|
|
129
|
-
return { edits };
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return getEditsForRefactor(fileName, formatOptions, positionOrRange, refactorName, actionName, ...rest);
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
return pluginModule;
|
|
138
|
-
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
139
237
|
module.exports = init;
|
|
140
238
|
//# sourceMappingURL=index.js.map
|
package/lib/builtInPlugins.d.ts
CHANGED
package/lib/builtInPlugins.js
CHANGED
|
@@ -25,37 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.builtInPlugins = void 0;
|
|
27
27
|
const ErrorStackParser = __importStar(require("error-stack-parser"));
|
|
28
|
+
require('source-map-support').install();
|
|
28
29
|
exports.builtInPlugins = [
|
|
29
|
-
(ctx, { warnings, errors }) => {
|
|
30
|
-
const ts = ctx.typescript;
|
|
31
|
-
return {
|
|
32
|
-
lint(sourceFile) {
|
|
33
|
-
if (sourceFile.fileName !== ctx.configFile) {
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
return [
|
|
37
|
-
...errors.map(error => [error, ts.DiagnosticCategory.Error]),
|
|
38
|
-
...warnings.map(error => [error, ts.DiagnosticCategory.Warning]),
|
|
39
|
-
].map(([error, category]) => {
|
|
40
|
-
const diag = {
|
|
41
|
-
category,
|
|
42
|
-
source: 'tsslint-esbuild',
|
|
43
|
-
code: error.id,
|
|
44
|
-
messageText: JSON.stringify(error, null, 2),
|
|
45
|
-
file: sourceFile,
|
|
46
|
-
start: 0,
|
|
47
|
-
length: 0,
|
|
48
|
-
};
|
|
49
|
-
// TODO: parse error.notes for relatedInformation
|
|
50
|
-
return diag;
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
30
|
ctx => {
|
|
56
31
|
const ts = ctx.typescript;
|
|
57
32
|
const fileFixes = new Map();
|
|
58
33
|
const sourceFiles = new Map();
|
|
34
|
+
const configSourceFile = ts.createSourceFile(ctx.configFile, ts.sys.readFile(ctx.configFile) ?? '', ts.ScriptTarget.Latest, true);
|
|
59
35
|
return {
|
|
60
36
|
lint(sourceFile, rules) {
|
|
61
37
|
const rulesContext = {
|
|
@@ -78,16 +54,16 @@ exports.builtInPlugins = [
|
|
|
78
54
|
rule(rulesContext);
|
|
79
55
|
}
|
|
80
56
|
return result;
|
|
81
|
-
function reportError(message, start, end) {
|
|
82
|
-
return report(ts.DiagnosticCategory.Error, message, start, end);
|
|
57
|
+
function reportError(message, start, end, trace = true) {
|
|
58
|
+
return report(ts.DiagnosticCategory.Error, message, start, end, trace);
|
|
83
59
|
}
|
|
84
|
-
function reportWarning(message, start, end) {
|
|
85
|
-
return report(ts.DiagnosticCategory.Warning, message, start, end);
|
|
60
|
+
function reportWarning(message, start, end, trace = true) {
|
|
61
|
+
return report(ts.DiagnosticCategory.Warning, message, start, end, trace);
|
|
86
62
|
}
|
|
87
|
-
function reportSuggestion(message, start, end) {
|
|
88
|
-
return report(ts.DiagnosticCategory.Suggestion, message, start, end);
|
|
63
|
+
function reportSuggestion(message, start, end, trace = true) {
|
|
64
|
+
return report(ts.DiagnosticCategory.Suggestion, message, start, end, trace);
|
|
89
65
|
}
|
|
90
|
-
function report(category, message, start, end) {
|
|
66
|
+
function report(category, message, start, end, trace) {
|
|
91
67
|
const error = {
|
|
92
68
|
category,
|
|
93
69
|
code: currentRuleId,
|
|
@@ -98,7 +74,7 @@ exports.builtInPlugins = [
|
|
|
98
74
|
source: 'tsslint',
|
|
99
75
|
relatedInformation: [],
|
|
100
76
|
};
|
|
101
|
-
const stacks = ErrorStackParser.parse(new Error());
|
|
77
|
+
const stacks = trace ? ErrorStackParser.parse(new Error()) : [];
|
|
102
78
|
if (stacks.length >= 3) {
|
|
103
79
|
const stack = stacks[2];
|
|
104
80
|
if (stack.fileName && stack.lineNumber !== undefined && stack.columnNumber !== undefined) {
|
|
@@ -107,31 +83,26 @@ exports.builtInPlugins = [
|
|
|
107
83
|
fileName = fileName.substring('file://'.length);
|
|
108
84
|
}
|
|
109
85
|
if (!sourceFiles.has(fileName)) {
|
|
110
|
-
|
|
86
|
+
const text = ctx.languageServiceHost.readFile(fileName) ?? '';
|
|
87
|
+
sourceFiles.set(fileName, ts.createSourceFile(fileName, text, ts.ScriptTarget.Latest, true));
|
|
111
88
|
}
|
|
112
89
|
const stackFile = sourceFiles.get(fileName);
|
|
113
90
|
const pos = stackFile?.getPositionOfLineAndCharacter(stack.lineNumber - 1, stack.columnNumber - 1);
|
|
114
|
-
let reportNode;
|
|
115
|
-
stackFile.forEachChild(function visit(node) {
|
|
116
|
-
if (node.end < pos || reportNode) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
if (node.pos <= pos) {
|
|
120
|
-
if (node.getStart() === pos) {
|
|
121
|
-
reportNode = node;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
node.forEachChild(visit);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
91
|
error.relatedInformation?.push({
|
|
129
92
|
category: ts.DiagnosticCategory.Message,
|
|
130
93
|
code: 0,
|
|
131
94
|
file: stackFile,
|
|
132
95
|
start: pos,
|
|
133
|
-
length:
|
|
134
|
-
messageText: '
|
|
96
|
+
length: 0,
|
|
97
|
+
messageText: 'Related rule file',
|
|
98
|
+
});
|
|
99
|
+
error.relatedInformation?.push({
|
|
100
|
+
category: ts.DiagnosticCategory.Message,
|
|
101
|
+
code: 0,
|
|
102
|
+
file: configSourceFile,
|
|
103
|
+
start: 0,
|
|
104
|
+
length: 0,
|
|
105
|
+
messageText: 'Related config file',
|
|
135
106
|
});
|
|
136
107
|
}
|
|
137
108
|
}
|
package/lib/watchConfig.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
1
|
import type { Config } from '@tsslint/config';
|
|
2
|
-
import
|
|
3
|
-
export declare function watchConfig(tsConfigPath: string, onBuild: (config: Config | undefined, result:
|
|
4
|
-
entryPoints: string[];
|
|
5
|
-
bundle: true;
|
|
6
|
-
outfile: string;
|
|
7
|
-
format: "cjs";
|
|
8
|
-
platform: "node";
|
|
9
|
-
plugins: {
|
|
10
|
-
name: string;
|
|
11
|
-
setup(build: esbuild.PluginBuild): void;
|
|
12
|
-
}[];
|
|
13
|
-
}>>;
|
|
2
|
+
import rollup = require('rollup');
|
|
3
|
+
export declare function watchConfig(tsConfigPath: string, onBuild: (config: Config | undefined, result: Error | undefined) => void): Promise<rollup.RollupBuild>;
|
|
14
4
|
//# sourceMappingURL=watchConfig.d.ts.map
|
package/lib/watchConfig.js
CHANGED
|
@@ -1,56 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.watchConfig = void 0;
|
|
4
|
-
const
|
|
4
|
+
const rollup = require("rollup");
|
|
5
5
|
const path = require("path");
|
|
6
6
|
async function watchConfig(tsConfigPath, onBuild) {
|
|
7
|
-
const outDir = path.resolve(
|
|
8
|
-
const outFileName = path
|
|
9
|
-
.relative(outDir, tsConfigPath)
|
|
10
|
-
.replace(/\.\./g, '__up')
|
|
11
|
-
.replace(/\//g, '__slash')
|
|
12
|
-
+ '.cjs';
|
|
7
|
+
const outDir = path.resolve(__dirname, '..', '..', '.tsslint');
|
|
8
|
+
const outFileName = btoa(path.relative(outDir, tsConfigPath)) + '.cjs';
|
|
13
9
|
const outFile = path.join(outDir, outFileName);
|
|
14
|
-
const ctx = await esbuild.context({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
// const ctx = await esbuild.context({
|
|
11
|
+
// entryPoints: [tsConfigPath],
|
|
12
|
+
// bundle: true,
|
|
13
|
+
// sourcemap: true,
|
|
14
|
+
// outfile: outFile,
|
|
15
|
+
// format: 'cjs',
|
|
16
|
+
// platform: 'node',
|
|
17
|
+
// plugins: [{
|
|
18
|
+
// name: 'tsslint',
|
|
19
|
+
// setup(build) {
|
|
20
|
+
// build.onResolve({ filter: /.*/ }, args => {
|
|
21
|
+
// if (!args.path.endsWith('.ts')) {
|
|
22
|
+
// try {
|
|
23
|
+
// const jsPath = require.resolve(args.path, { paths: [args.resolveDir] });
|
|
24
|
+
// return {
|
|
25
|
+
// path: jsPath,
|
|
26
|
+
// external: true,
|
|
27
|
+
// };
|
|
28
|
+
// } catch { }
|
|
29
|
+
// }
|
|
30
|
+
// return {};
|
|
31
|
+
// });
|
|
32
|
+
// build.onEnd(result => {
|
|
33
|
+
// let config: Config | undefined;
|
|
34
|
+
// if (!result.errors.length) {
|
|
35
|
+
// try {
|
|
36
|
+
// config = require(outFile).default;
|
|
37
|
+
// delete require.cache[outFile!];
|
|
38
|
+
// } catch (e) {
|
|
39
|
+
// result.errors.push({ text: String(e) } as any);
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
// onBuild(config, result);
|
|
43
|
+
// });
|
|
44
|
+
// },
|
|
45
|
+
// }],
|
|
46
|
+
// });
|
|
47
|
+
const bundle = await rollup.rollup({
|
|
48
|
+
input: tsConfigPath,
|
|
49
|
+
output: {
|
|
50
|
+
file: outFile,
|
|
51
|
+
format: 'cjs',
|
|
52
|
+
sourcemap: true,
|
|
53
|
+
},
|
|
54
|
+
watch: {},
|
|
55
|
+
external: ['typescript'],
|
|
20
56
|
plugins: [{
|
|
21
57
|
name: 'tsslint',
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
catch { }
|
|
58
|
+
resolveId(id, importer) {
|
|
59
|
+
if (!id.endsWith('.ts') && importer) {
|
|
60
|
+
try {
|
|
61
|
+
const jsPath = require.resolve(id, { paths: [path.dirname(importer)] });
|
|
62
|
+
return {
|
|
63
|
+
id: jsPath,
|
|
64
|
+
external: true,
|
|
65
|
+
};
|
|
33
66
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
67
|
+
catch { }
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
buildEnd(error) {
|
|
71
|
+
let config;
|
|
72
|
+
if (!error) {
|
|
73
|
+
try {
|
|
74
|
+
config = require(outFile).default;
|
|
75
|
+
delete require.cache[outFile];
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
error = { message: String(e) };
|
|
46
79
|
}
|
|
47
|
-
|
|
48
|
-
|
|
80
|
+
}
|
|
81
|
+
onBuild(config, error);
|
|
49
82
|
},
|
|
50
83
|
}],
|
|
51
84
|
});
|
|
52
|
-
|
|
53
|
-
return ctx;
|
|
85
|
+
return bundle;
|
|
54
86
|
}
|
|
55
87
|
exports.watchConfig = watchConfig;
|
|
56
88
|
//# sourceMappingURL=watchConfig.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsslint/typescript-plugin",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -12,8 +12,11 @@
|
|
|
12
12
|
"directory": "packages/typescript-plugin"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tsslint/config": "0.0.0",
|
|
16
15
|
"error-stack-parser": "^2.1.4",
|
|
17
|
-
"
|
|
18
|
-
}
|
|
16
|
+
"source-map-support": "^0.5.19"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@tsslint/config": "0.0.2"
|
|
20
|
+
},
|
|
21
|
+
"gitHead": "bdca2792d8b64a11c7c1632c80a2bf25b4985c15"
|
|
19
22
|
}
|