@atlaspack/reporter-lsp 2.14.5-canary.36 → 2.14.5-canary.361

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.
@@ -0,0 +1,414 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const utils_1 = require("@atlaspack/utils");
40
+ const plugin_1 = require("@atlaspack/plugin");
41
+ const path_1 = __importDefault(require("path"));
42
+ const os_1 = __importDefault(require("os"));
43
+ const url_1 = __importDefault(require("url"));
44
+ const fs_1 = __importDefault(require("fs"));
45
+ const nullthrows_1 = __importDefault(require("nullthrows"));
46
+ // @ts-expect-error TS7016
47
+ const ps = __importStar(require("ps-node"));
48
+ const util_1 = require("util");
49
+ const ipc_1 = require("./ipc");
50
+ const lsp_protocol_1 = require("@atlaspack/lsp-protocol");
51
+ const utils_2 = require("./utils");
52
+ const lookupPid = (0, util_1.promisify)(ps.lookup);
53
+ const ignoreFail = (func) => {
54
+ try {
55
+ func();
56
+ }
57
+ catch (e) {
58
+ /**/
59
+ }
60
+ };
61
+ const BASEDIR = fs_1.default.realpathSync(path_1.default.join(os_1.default.tmpdir(), 'parcel-lsp'));
62
+ const SOCKET_FILE = path_1.default.join(BASEDIR, `parcel-${process.pid}`);
63
+ const META_FILE = path_1.default.join(BASEDIR, `parcel-${process.pid}.json`);
64
+ let workspaceDiagnostics = new utils_1.DefaultMap(() => []);
65
+ const getWorkspaceDiagnostics = () => [...workspaceDiagnostics].map(([uri, diagnostics]) => ({
66
+ uri,
67
+ diagnostics,
68
+ }));
69
+ // @ts-expect-error TS7034
70
+ let server;
71
+ let connections = [];
72
+ let bundleGraphDeferrable = (0, utils_1.makeDeferredWithPromise)();
73
+ let bundleGraph = bundleGraphDeferrable.promise;
74
+ let watchStarted = false;
75
+ let lspStarted = false;
76
+ // @ts-expect-error TS7034
77
+ let watchStartPromise;
78
+ const LSP_SENTINEL_FILENAME = 'lsp-server';
79
+ const LSP_SENTINEL_FILE = path_1.default.join(BASEDIR, LSP_SENTINEL_FILENAME);
80
+ async function watchLspActive() {
81
+ // Check for lsp-server when reporter is first started
82
+ try {
83
+ await fs_1.default.promises.access(LSP_SENTINEL_FILE, fs_1.default.constants.F_OK);
84
+ lspStarted = true;
85
+ }
86
+ catch {
87
+ //
88
+ }
89
+ // @ts-expect-error TS2769
90
+ return fs_1.default.watch(BASEDIR, (eventType, filename) => {
91
+ switch (eventType) {
92
+ case 'rename':
93
+ if (filename === LSP_SENTINEL_FILENAME) {
94
+ fs_1.default.access(LSP_SENTINEL_FILE, fs_1.default.constants.F_OK, (err) => {
95
+ if (err) {
96
+ lspStarted = false;
97
+ }
98
+ else {
99
+ lspStarted = true;
100
+ }
101
+ });
102
+ }
103
+ }
104
+ });
105
+ }
106
+ // @ts-expect-error TS2552
107
+ async function doWatchStart(options) {
108
+ await fs_1.default.promises.mkdir(BASEDIR, { recursive: true });
109
+ // For each existing file, check if the pid matches a running process.
110
+ // If no process matches, delete the file, assuming it was orphaned
111
+ // by a process that quit unexpectedly.
112
+ for (let filename of fs_1.default.readdirSync(BASEDIR)) {
113
+ if (filename.endsWith('.json'))
114
+ continue;
115
+ let pid = parseInt(filename.slice('parcel-'.length), 10);
116
+ let resultList = await lookupPid({ pid });
117
+ if (resultList.length > 0)
118
+ continue;
119
+ fs_1.default.unlinkSync(path_1.default.join(BASEDIR, filename));
120
+ ignoreFail(() => fs_1.default.unlinkSync(path_1.default.join(BASEDIR, filename + '.json')));
121
+ }
122
+ server = await (0, ipc_1.createServer)(SOCKET_FILE, (connection) => {
123
+ // console.log('got connection');
124
+ connections.push(connection);
125
+ connection.onClose(() => {
126
+ connections = connections.filter((c) => c !== connection);
127
+ });
128
+ connection.onRequest(lsp_protocol_1.RequestDocumentDiagnostics, async (uri) => {
129
+ let graph = await bundleGraph;
130
+ if (!graph)
131
+ return;
132
+ // @ts-expect-error TS2345
133
+ return getDiagnosticsUnusedExports(graph, uri);
134
+ });
135
+ connection.onRequest(lsp_protocol_1.RequestImporters, async (params) => {
136
+ let graph = await bundleGraph;
137
+ if (!graph)
138
+ return null;
139
+ // @ts-expect-error TS2345
140
+ return getImporters(graph, params);
141
+ });
142
+ sendDiagnostics();
143
+ });
144
+ await fs_1.default.promises.writeFile(META_FILE, JSON.stringify({
145
+ projectRoot: options.projectRoot,
146
+ pid: process.pid,
147
+ argv: process.argv,
148
+ }));
149
+ }
150
+ watchLspActive();
151
+ exports.default = new plugin_1.Reporter({
152
+ async report({ event, options }) {
153
+ if (event.type === 'watchStart') {
154
+ watchStarted = true;
155
+ }
156
+ if (watchStarted && lspStarted) {
157
+ // @ts-expect-error TS7005
158
+ if (!watchStartPromise) {
159
+ watchStartPromise = doWatchStart(options);
160
+ }
161
+ await watchStartPromise;
162
+ }
163
+ switch (event.type) {
164
+ case 'watchStart': {
165
+ break;
166
+ }
167
+ case 'buildStart': {
168
+ bundleGraphDeferrable = (0, utils_1.makeDeferredWithPromise)();
169
+ bundleGraph = bundleGraphDeferrable.promise;
170
+ updateBuildState('start');
171
+ clearDiagnostics();
172
+ break;
173
+ }
174
+ case 'buildSuccess':
175
+ bundleGraphDeferrable.deferred.resolve(event.bundleGraph);
176
+ updateBuildState('end');
177
+ sendDiagnostics();
178
+ break;
179
+ case 'buildFailure': {
180
+ bundleGraphDeferrable.deferred.resolve(undefined);
181
+ updateDiagnostics(event.diagnostics, 'error', options.projectRoot);
182
+ updateBuildState('end');
183
+ sendDiagnostics();
184
+ break;
185
+ }
186
+ case 'log':
187
+ if (
188
+ // @ts-expect-error TS2339
189
+ event.diagnostics != null &&
190
+ (event.level === 'error' ||
191
+ event.level === 'warn' ||
192
+ event.level === 'info' ||
193
+ event.level === 'verbose')) {
194
+ updateDiagnostics(event.diagnostics, event.level, options.projectRoot);
195
+ }
196
+ break;
197
+ case 'buildProgress': {
198
+ let message = (0, utils_1.getProgressMessage)(event);
199
+ if (message != null) {
200
+ updateBuildState('progress', message);
201
+ }
202
+ break;
203
+ }
204
+ case 'watchEnd':
205
+ connections.forEach((c) => c.end());
206
+ // @ts-expect-error TS7005
207
+ await server.close();
208
+ ignoreFail(() => fs_1.default.unlinkSync(META_FILE));
209
+ break;
210
+ }
211
+ },
212
+ });
213
+ function updateBuildState(state, message) {
214
+ connections.forEach((c) => c.sendNotification(lsp_protocol_1.NotificationBuildStatus, state, message));
215
+ }
216
+ function clearDiagnostics() {
217
+ workspaceDiagnostics.clear();
218
+ }
219
+ function sendDiagnostics() {
220
+ // console.log('send', getWorkspaceDiagnostics());
221
+ connections.forEach((c) => c.sendNotification(lsp_protocol_1.NotificationWorkspaceDiagnostics, getWorkspaceDiagnostics()));
222
+ }
223
+ function updateDiagnostics(parcelDiagnostics, parcelSeverity, projectRoot) {
224
+ for (let diagnostic of parcelDiagnostics) {
225
+ const codeFrames = diagnostic.codeFrames;
226
+ if (codeFrames == null) {
227
+ continue;
228
+ }
229
+ const firstCodeFrame = codeFrames[0];
230
+ const filePath = firstCodeFrame.filePath;
231
+ if (filePath == null) {
232
+ continue;
233
+ }
234
+ // We use the first highlight of the first codeFrame as the main Diagnostic,
235
+ // and we place everything else in the current Parcel diagnostic
236
+ // in relatedInformation
237
+ // https://code.visualstudio.com/api/references/vscode-api#DiagnosticRelatedInformation
238
+ const firstFrameHighlight = codeFrames[0].codeHighlights[0];
239
+ if (firstFrameHighlight == null) {
240
+ continue;
241
+ }
242
+ // @ts-expect-error TS2304
243
+ const relatedInformation = [];
244
+ for (const codeFrame of codeFrames) {
245
+ for (const highlight of codeFrame.codeHighlights) {
246
+ const filePath = codeFrame.filePath;
247
+ if (highlight === firstFrameHighlight || filePath == null) {
248
+ continue;
249
+ }
250
+ relatedInformation.push({
251
+ location: {
252
+ uri: `file://${(0, utils_2.normalizeFilePath)(filePath, projectRoot)}`,
253
+ range: {
254
+ start: {
255
+ line: highlight.start.line - 1,
256
+ character: highlight.start.column - 1,
257
+ },
258
+ end: {
259
+ line: highlight.end.line - 1,
260
+ character: highlight.end.column,
261
+ },
262
+ },
263
+ },
264
+ message: highlight.message ?? diagnostic.message,
265
+ });
266
+ }
267
+ }
268
+ workspaceDiagnostics
269
+ .get(`file://${(0, utils_2.normalizeFilePath)(filePath, projectRoot)}`)
270
+ .push({
271
+ range: {
272
+ start: {
273
+ line: firstFrameHighlight.start.line - 1,
274
+ character: firstFrameHighlight.start.column - 1,
275
+ },
276
+ end: {
277
+ line: firstFrameHighlight.end.line - 1,
278
+ character: firstFrameHighlight.end.column,
279
+ },
280
+ },
281
+ source: diagnostic.origin,
282
+ severity: (0, utils_2.parcelSeverityToLspSeverity)(parcelSeverity),
283
+ message: diagnostic.message +
284
+ (firstFrameHighlight.message == null
285
+ ? ''
286
+ : ' ' + firstFrameHighlight.message),
287
+ relatedInformation,
288
+ });
289
+ }
290
+ }
291
+ function getDiagnosticsUnusedExports(bundleGraph, document) {
292
+ let filename = url_1.default.fileURLToPath(document);
293
+ let diagnostics = [];
294
+ let asset = bundleGraph.traverse((node, context, actions) => {
295
+ if (node.type === 'asset' && node.value.filePath === filename) {
296
+ actions.stop();
297
+ return node.value;
298
+ }
299
+ });
300
+ if (asset) {
301
+ // @ts-expect-error TS2304
302
+ const generateDiagnostic = (loc, type) => ({
303
+ range: {
304
+ start: {
305
+ line: loc.start.line - 1,
306
+ character: loc.start.column - 1,
307
+ },
308
+ end: {
309
+ line: loc.end.line - 1,
310
+ character: loc.end.column,
311
+ },
312
+ },
313
+ source: '@atlaspack/core',
314
+ severity: utils_2.DiagnosticSeverity.Hint,
315
+ message: `Unused ${type}.`,
316
+ tags: [utils_2.DiagnosticTag.Unnecessary],
317
+ });
318
+ // @ts-expect-error TS2345
319
+ let usedSymbols = bundleGraph.getUsedSymbols(asset);
320
+ if (usedSymbols) {
321
+ // @ts-expect-error TS2339
322
+ for (let [exported, symbol] of asset.symbols) {
323
+ if (!usedSymbols.has(exported)) {
324
+ if (symbol.loc) {
325
+ diagnostics.push(generateDiagnostic(symbol.loc, 'export'));
326
+ }
327
+ }
328
+ }
329
+ // if (usedSymbols.size === 0 && asset.sideEffects !== false) {
330
+ // diagnostics.push({
331
+ // range: {
332
+ // start: {
333
+ // line: 0,
334
+ // character: 0,
335
+ // },
336
+ // end: {
337
+ // line: 0,
338
+ // character: 1,
339
+ // },
340
+ // },
341
+ // source: '@atlaspack/core',
342
+ // severity: DiagnosticSeverity.Warning,
343
+ // message: `Asset has no used exports, but is not marked as sideEffect-free so it cannot be excluded automatically.`,
344
+ // });
345
+ // }
346
+ }
347
+ // @ts-expect-error TS2339
348
+ for (let dep of asset.getDependencies()) {
349
+ let usedSymbols = bundleGraph.getUsedSymbols(dep);
350
+ if (usedSymbols) {
351
+ for (let [exported, symbol] of dep.symbols) {
352
+ if (!usedSymbols.has(exported) && symbol.isWeak && symbol.loc) {
353
+ diagnostics.push(generateDiagnostic(symbol.loc, 'reexport'));
354
+ }
355
+ }
356
+ }
357
+ }
358
+ }
359
+ return diagnostics;
360
+ }
361
+ // function getDefinition(
362
+ // bundleGraph: BundleGraph<PackagedBundle>,
363
+ // document: string,
364
+ // position: Position,
365
+ // ): Array<LocationLink> | void {
366
+ // let filename = url.fileURLToPath(document);
367
+ // let asset = bundleGraph.traverse((node, context, actions) => {
368
+ // if (node.type === 'asset' && node.value.filePath === filename) {
369
+ // actions.stop();
370
+ // return node.value;
371
+ // }
372
+ // });
373
+ // if (asset) {
374
+ // for (let dep of bundleGraph.getDependencies(asset)) {
375
+ // let loc = dep.loc;
376
+ // if (loc && isInRange(loc, position)) {
377
+ // let resolution = bundleGraph.getResolvedAsset(dep);
378
+ // if (resolution) {
379
+ // return [
380
+ // {
381
+ // originSelectionRange: {
382
+ // start: {
383
+ // line: loc.start.line - 1,
384
+ // character: loc.start.column - 1,
385
+ // },
386
+ // end: {line: loc.end.line - 1, character: loc.end.column},
387
+ // },
388
+ // targetUri: `file://${resolution.filePath}`,
389
+ // targetRange: RANGE_DUMMY,
390
+ // targetSelectionRange: RANGE_DUMMY,
391
+ // },
392
+ // ];
393
+ // }
394
+ // }
395
+ // }
396
+ // }
397
+ // }
398
+ function getImporters(bundleGraph, document) {
399
+ let filename = url_1.default.fileURLToPath(document);
400
+ let asset = bundleGraph.traverse((node, context, actions) => {
401
+ if (node.type === 'asset' && node.value.filePath === filename) {
402
+ actions.stop();
403
+ return node.value;
404
+ }
405
+ });
406
+ if (asset) {
407
+ // @ts-expect-error TS2345
408
+ let incoming = bundleGraph.getIncomingDependencies(asset);
409
+ return incoming
410
+ .filter((dep) => dep.sourcePath != null)
411
+ .map((dep) => `file://${(0, nullthrows_1.default)(dep.sourcePath)}`);
412
+ }
413
+ return null;
414
+ }
package/dist/ipc.js ADDED
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.createServer = createServer;
37
+ const net = __importStar(require("net"));
38
+ const node_1 = require("vscode-jsonrpc/node");
39
+ function createClientPipeTransport(pipeName, onConnected) {
40
+ return new Promise((resolve, reject) => {
41
+ let server = net.createServer((socket) => {
42
+ onConnected(new node_1.SocketMessageReader(socket), new node_1.SocketMessageWriter(socket));
43
+ });
44
+ server.on('error', reject);
45
+ server.listen(pipeName, () => {
46
+ server.removeListener('error', reject);
47
+ resolve({
48
+ close() {
49
+ return new Promise((res, rej) => {
50
+ server.close((e) => {
51
+ if (e)
52
+ rej(e);
53
+ // @ts-expect-error TS2794
54
+ else
55
+ res();
56
+ });
57
+ });
58
+ },
59
+ });
60
+ });
61
+ });
62
+ }
63
+ function createServer(filename, setup) {
64
+ return createClientPipeTransport(filename, (reader, writer) => {
65
+ let connection = (0, node_1.createMessageConnection)(reader, writer);
66
+ connection.listen();
67
+ setup(connection);
68
+ });
69
+ }
package/dist/utils.js ADDED
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.DiagnosticSeverity = exports.DiagnosticTag = void 0;
7
+ exports.parcelSeverityToLspSeverity = parcelSeverityToLspSeverity;
8
+ exports.normalizeFilePath = normalizeFilePath;
9
+ const path_1 = __importDefault(require("path"));
10
+ function parcelSeverityToLspSeverity(parcelSeverity) {
11
+ switch (parcelSeverity) {
12
+ case 'error':
13
+ return exports.DiagnosticSeverity.Error;
14
+ case 'warn':
15
+ return exports.DiagnosticSeverity.Warning;
16
+ case 'info':
17
+ return exports.DiagnosticSeverity.Information;
18
+ case 'verbose':
19
+ return exports.DiagnosticSeverity.Hint;
20
+ default:
21
+ throw new Error('Unknown severity');
22
+ }
23
+ }
24
+ function normalizeFilePath(filePath, projectRoot) {
25
+ return path_1.default.isAbsolute(filePath)
26
+ ? filePath
27
+ : path_1.default.join(projectRoot, filePath);
28
+ }
29
+ // export function isInRange(loc: SourceLocation, position: Position): boolean {
30
+ // let pos = {line: position.line + 1, column: position.character + 1};
31
+ // if (pos.line < loc.start.line || loc.end.line < pos.line) {
32
+ // return false;
33
+ // }
34
+ // if (pos.line === loc.start.line) {
35
+ // return loc.start.column <= pos.column;
36
+ // }
37
+ // if (pos.line === loc.end.line - 1) {
38
+ // return pos.column < loc.start.column;
39
+ // }
40
+ // return true;
41
+ // }
42
+ // /** This range is used when refering to a whole file and not a specific range. */
43
+ // export const RANGE_DUMMY: Range = {
44
+ // start: {line: 0, character: 0},
45
+ // end: {line: 0, character: 0},
46
+ // };
47
+ // Copied over from vscode-languageserver to prevent the runtime dependency
48
+ exports.DiagnosticTag = {
49
+ /**
50
+ * Unused or unnecessary code.
51
+ *
52
+ * Clients are allowed to render diagnostics with this tag faded out instead of having
53
+ * an error squiggle.
54
+ */
55
+ // @ts-expect-error TS2304
56
+ Unnecessary: 1,
57
+ /**
58
+ * Deprecated or obsolete code.
59
+ *
60
+ * Clients are allowed to rendered diagnostics with this tag strike through.
61
+ */
62
+ // @ts-expect-error TS2304
63
+ Deprecated: 2,
64
+ };
65
+ exports.DiagnosticSeverity = {
66
+ /**
67
+ * Reports an error.
68
+ */
69
+ Error: 1,
70
+ /**
71
+ * Reports a warning.
72
+ */
73
+ Warning: 2,
74
+ /**
75
+ * Reports an information.
76
+ */
77
+ Information: 3,
78
+ /**
79
+ * Reports a hint.
80
+ */
81
+ Hint: 4,
82
+ };
@@ -79,6 +79,10 @@ var _utils2 = require("./utils");
79
79
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
80
80
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
81
81
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
82
+ // @ts-expect-error TS7016
83
+
84
+ // @ts-expect-error TS7016
85
+
82
86
  const lookupPid = (0, _util().promisify)(ps().lookup);
83
87
  const ignoreFail = func => {
84
88
  try {
@@ -95,12 +99,15 @@ const getWorkspaceDiagnostics = () => [...workspaceDiagnostics].map(([uri, diagn
95
99
  uri,
96
100
  diagnostics
97
101
  }));
102
+
103
+ // @ts-expect-error TS7034
98
104
  let server;
99
105
  let connections = [];
100
106
  let bundleGraphDeferrable = (0, _utils().makeDeferredWithPromise)();
101
107
  let bundleGraph = bundleGraphDeferrable.promise;
102
108
  let watchStarted = false;
103
109
  let lspStarted = false;
110
+ // @ts-expect-error TS7034
104
111
  let watchStartPromise;
105
112
  const LSP_SENTINEL_FILENAME = 'lsp-server';
106
113
  const LSP_SENTINEL_FILE = _path().default.join(BASEDIR, LSP_SENTINEL_FILENAME);
@@ -112,6 +119,8 @@ async function watchLspActive() {
112
119
  } catch {
113
120
  //
114
121
  }
122
+
123
+ // @ts-expect-error TS2769
115
124
  return _fs().default.watch(BASEDIR, (eventType, filename) => {
116
125
  switch (eventType) {
117
126
  case 'rename':
@@ -127,6 +136,8 @@ async function watchLspActive() {
127
136
  }
128
137
  });
129
138
  }
139
+
140
+ // @ts-expect-error TS2552
130
141
  async function doWatchStart(options) {
131
142
  await _fs().default.promises.mkdir(BASEDIR, {
132
143
  recursive: true
@@ -154,11 +165,15 @@ async function doWatchStart(options) {
154
165
  connection.onRequest(_lspProtocol().RequestDocumentDiagnostics, async uri => {
155
166
  let graph = await bundleGraph;
156
167
  if (!graph) return;
168
+
169
+ // @ts-expect-error TS2345
157
170
  return getDiagnosticsUnusedExports(graph, uri);
158
171
  });
159
172
  connection.onRequest(_lspProtocol().RequestImporters, async params => {
160
173
  let graph = await bundleGraph;
161
174
  if (!graph) return null;
175
+
176
+ // @ts-expect-error TS2345
162
177
  return getImporters(graph, params);
163
178
  });
164
179
  sendDiagnostics();
@@ -179,6 +194,7 @@ var _default = exports.default = new (_plugin().Reporter)({
179
194
  watchStarted = true;
180
195
  }
181
196
  if (watchStarted && lspStarted) {
197
+ // @ts-expect-error TS7005
182
198
  if (!watchStartPromise) {
183
199
  watchStartPromise = doWatchStart(options);
184
200
  }
@@ -211,7 +227,9 @@ var _default = exports.default = new (_plugin().Reporter)({
211
227
  break;
212
228
  }
213
229
  case 'log':
214
- if (event.diagnostics != null && (event.level === 'error' || event.level === 'warn' || event.level === 'info' || event.level === 'verbose')) {
230
+ if (
231
+ // @ts-expect-error TS2339
232
+ event.diagnostics != null && (event.level === 'error' || event.level === 'warn' || event.level === 'info' || event.level === 'verbose')) {
215
233
  updateDiagnostics(event.diagnostics, event.level, options.projectRoot);
216
234
  }
217
235
  break;
@@ -225,6 +243,7 @@ var _default = exports.default = new (_plugin().Reporter)({
225
243
  }
226
244
  case 'watchEnd':
227
245
  connections.forEach(c => c.end());
246
+ // @ts-expect-error TS7005
228
247
  await server.close();
229
248
  ignoreFail(() => _fs().default.unlinkSync(META_FILE));
230
249
  break;
@@ -261,6 +280,8 @@ function updateDiagnostics(parcelDiagnostics, parcelSeverity, projectRoot) {
261
280
  if (firstFrameHighlight == null) {
262
281
  continue;
263
282
  }
283
+
284
+ // @ts-expect-error TS2304
264
285
  const relatedInformation = [];
265
286
  for (const codeFrame of codeFrames) {
266
287
  for (const highlight of codeFrame.codeHighlights) {
@@ -314,6 +335,7 @@ function getDiagnosticsUnusedExports(bundleGraph, document) {
314
335
  }
315
336
  });
316
337
  if (asset) {
338
+ // @ts-expect-error TS2304
317
339
  const generateDiagnostic = (loc, type) => ({
318
340
  range: {
319
341
  start: {
@@ -330,8 +352,11 @@ function getDiagnosticsUnusedExports(bundleGraph, document) {
330
352
  message: `Unused ${type}.`,
331
353
  tags: [_utils2.DiagnosticTag.Unnecessary]
332
354
  });
355
+
356
+ // @ts-expect-error TS2345
333
357
  let usedSymbols = bundleGraph.getUsedSymbols(asset);
334
358
  if (usedSymbols) {
359
+ // @ts-expect-error TS2339
335
360
  for (let [exported, symbol] of asset.symbols) {
336
361
  if (!usedSymbols.has(exported)) {
337
362
  if (symbol.loc) {
@@ -358,6 +383,7 @@ function getDiagnosticsUnusedExports(bundleGraph, document) {
358
383
  // }
359
384
  }
360
385
 
386
+ // @ts-expect-error TS2339
361
387
  for (let dep of asset.getDependencies()) {
362
388
  let usedSymbols = bundleGraph.getUsedSymbols(dep);
363
389
  if (usedSymbols) {
@@ -421,6 +447,7 @@ function getImporters(bundleGraph, document) {
421
447
  }
422
448
  });
423
449
  if (asset) {
450
+ // @ts-expect-error TS2345
424
451
  let incoming = bundleGraph.getIncomingDependencies(asset);
425
452
  return incoming.filter(dep => dep.sourcePath != null).map(dep => `file://${(0, _nullthrows().default)(dep.sourcePath)}`);
426
453
  }