@atlaspack/reporter-lsp 2.14.20 → 2.14.21-typescript-80839fbd5.0

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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2024 Atlassian US., Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -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
  }
package/lib/ipc.js CHANGED
@@ -32,7 +32,9 @@ function createClientPipeTransport(pipeName, onConnected) {
32
32
  close() {
33
33
  return new Promise((res, rej) => {
34
34
  server.close(e => {
35
- if (e) rej(e);else res();
35
+ if (e) rej(e);
36
+ // @ts-expect-error TS2794
37
+ else res();
36
38
  });
37
39
  });
38
40
  }
package/lib/utils.js CHANGED
@@ -14,6 +14,8 @@ function _path() {
14
14
  return data;
15
15
  }
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+ // @ts-expect-error TS2724
18
+
17
19
  function parcelSeverityToLspSeverity(parcelSeverity) {
18
20
  switch (parcelSeverity) {
19
21
  case 'error':
@@ -61,35 +63,31 @@ const DiagnosticTag = exports.DiagnosticTag = {
61
63
  * Clients are allowed to render diagnostics with this tag faded out instead of having
62
64
  * an error squiggle.
63
65
  */
64
- // $FlowFixMe
66
+ // @ts-expect-error TS2304
65
67
  Unnecessary: 1,
66
68
  /**
67
69
  * Deprecated or obsolete code.
68
70
  *
69
71
  * Clients are allowed to rendered diagnostics with this tag strike through.
70
72
  */
71
- // $FlowFixMe
73
+ // @ts-expect-error TS2304
72
74
  Deprecated: 2
73
75
  };
74
76
  const DiagnosticSeverity = exports.DiagnosticSeverity = {
75
77
  /**
76
78
  * Reports an error.
77
79
  */
78
- // $FlowFixMe
79
80
  Error: 1,
80
81
  /**
81
82
  * Reports a warning.
82
83
  */
83
- // $FlowFixMe
84
84
  Warning: 2,
85
85
  /**
86
86
  * Reports an information.
87
87
  */
88
- // $FlowFixMe
89
88
  Information: 3,
90
89
  /**
91
90
  * Reports a hint.
92
91
  */
93
- // $FlowFixMe
94
92
  Hint: 4
95
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/reporter-lsp",
3
- "version": "2.14.20",
3
+ "version": "2.14.21-typescript-80839fbd5.0",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,18 +10,23 @@
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
12
  "main": "lib/LspReporter.js",
13
- "source": "src/LspReporter.js",
13
+ "source": "src/LspReporter.ts",
14
14
  "engines": {
15
15
  "node": ">= 16.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "@atlaspack/lsp-protocol": "2.14.1",
19
- "@atlaspack/plugin": "2.14.20",
20
- "@atlaspack/utils": "2.17.2",
18
+ "@atlaspack/lsp-protocol": "2.14.2-typescript-80839fbd5.0",
19
+ "@atlaspack/plugin": "2.14.21-typescript-80839fbd5.0",
20
+ "@atlaspack/utils": "2.17.3-typescript-80839fbd5.0",
21
21
  "node-ipc": "^9.1.4",
22
22
  "nullthrows": "^1.1.1",
23
23
  "ps-node": "^0.1.6",
24
24
  "vscode-jsonrpc": "^8.0.2"
25
25
  },
26
- "type": "commonjs"
26
+ "type": "commonjs",
27
+ "scripts": {
28
+ "check-ts": "tsc --noEmit"
29
+ },
30
+ "types": "src/LspReporter.ts",
31
+ "gitHead": "80839fbd5c6d6668c2622849856a4b25601354a8"
27
32
  }
@@ -1,7 +1,6 @@
1
- // @flow strict-local
2
-
3
1
  import type {Diagnostic as ParcelDiagnostic} from '@atlaspack/diagnostic';
4
2
  import type {BundleGraph, FilePath, PackagedBundle} from '@atlaspack/types';
3
+ // @ts-expect-error TS7016
5
4
  import type {Program, Query} from 'ps-node';
6
5
  import type {Diagnostic, DocumentUri} from 'vscode-languageserver';
7
6
  import type {MessageConnection} from 'vscode-jsonrpc/node';
@@ -18,12 +17,14 @@ import os from 'os';
18
17
  import url from 'url';
19
18
  import fs from 'fs';
20
19
  import nullthrows from 'nullthrows';
20
+ // @ts-expect-error TS7016
21
21
  import * as ps from 'ps-node';
22
22
  import {promisify} from 'util';
23
23
 
24
24
  import {createServer} from './ipc';
25
25
  import {
26
- type PublishDiagnostic,
26
+ // @ts-expect-error TS2305
27
+ PublishDiagnostic,
27
28
  NotificationBuildStatus,
28
29
  NotificationWorkspaceDiagnostics,
29
30
  RequestDocumentDiagnostics,
@@ -38,12 +39,12 @@ import {
38
39
  } from './utils';
39
40
  import type {FSWatcher} from 'fs';
40
41
 
41
- const lookupPid: (Query) => Program[] = promisify(ps.lookup);
42
+ const lookupPid: (arg1: Query) => Program[] = promisify(ps.lookup);
42
43
 
43
- const ignoreFail = (func) => {
44
+ const ignoreFail = (func: () => void) => {
44
45
  try {
45
46
  func();
46
- } catch (e) {
47
+ } catch (e: any) {
47
48
  /**/
48
49
  }
49
50
  };
@@ -54,22 +55,28 @@ const META_FILE = path.join(BASEDIR, `parcel-${process.pid}.json`);
54
55
 
55
56
  let workspaceDiagnostics: DefaultMap<
56
57
  string,
57
- Array<Diagnostic>,
58
+ Array<Diagnostic>
58
59
  > = new DefaultMap(() => []);
59
60
 
60
61
  const getWorkspaceDiagnostics = (): Array<PublishDiagnostic> =>
61
- [...workspaceDiagnostics].map(([uri, diagnostics]) => ({uri, diagnostics}));
62
+ [...workspaceDiagnostics].map(([uri, diagnostics]: [any, any]) => ({
63
+ uri,
64
+ diagnostics,
65
+ }));
62
66
 
67
+ // @ts-expect-error TS7034
63
68
  let server;
64
69
  let connections: Array<MessageConnection> = [];
65
70
 
66
- let bundleGraphDeferrable =
67
- makeDeferredWithPromise<?BundleGraph<PackagedBundle>>();
68
- let bundleGraph: Promise<?BundleGraph<PackagedBundle>> =
71
+ let bundleGraphDeferrable = makeDeferredWithPromise<
72
+ BundleGraph<PackagedBundle> | null | undefined
73
+ >();
74
+ let bundleGraph: Promise<BundleGraph<PackagedBundle> | null | undefined> =
69
75
  bundleGraphDeferrable.promise;
70
76
 
71
77
  let watchStarted = false;
72
78
  let lspStarted = false;
79
+ // @ts-expect-error TS7034
73
80
  let watchStartPromise;
74
81
 
75
82
  const LSP_SENTINEL_FILENAME = 'lsp-server';
@@ -84,6 +91,7 @@ async function watchLspActive(): Promise<FSWatcher> {
84
91
  //
85
92
  }
86
93
 
94
+ // @ts-expect-error TS2769
87
95
  return fs.watch(BASEDIR, (eventType: string, filename: string) => {
88
96
  switch (eventType) {
89
97
  case 'rename':
@@ -100,7 +108,8 @@ async function watchLspActive(): Promise<FSWatcher> {
100
108
  });
101
109
  }
102
110
 
103
- async function doWatchStart(options) {
111
+ // @ts-expect-error TS2552
112
+ async function doWatchStart(options: PluginOptions) {
104
113
  await fs.promises.mkdir(BASEDIR, {recursive: true});
105
114
 
106
115
  // For each existing file, check if the pid matches a running process.
@@ -126,6 +135,7 @@ async function doWatchStart(options) {
126
135
  let graph = await bundleGraph;
127
136
  if (!graph) return;
128
137
 
138
+ // @ts-expect-error TS2345
129
139
  return getDiagnosticsUnusedExports(graph, uri);
130
140
  });
131
141
 
@@ -133,6 +143,7 @@ async function doWatchStart(options) {
133
143
  let graph = await bundleGraph;
134
144
  if (!graph) return null;
135
145
 
146
+ // @ts-expect-error TS2345
136
147
  return getImporters(graph, params);
137
148
  });
138
149
 
@@ -150,13 +161,14 @@ async function doWatchStart(options) {
150
161
 
151
162
  watchLspActive();
152
163
 
153
- export default (new Reporter({
164
+ export default new Reporter({
154
165
  async report({event, options}) {
155
166
  if (event.type === 'watchStart') {
156
167
  watchStarted = true;
157
168
  }
158
169
 
159
170
  if (watchStarted && lspStarted) {
171
+ // @ts-expect-error TS7005
160
172
  if (!watchStartPromise) {
161
173
  watchStartPromise = doWatchStart(options);
162
174
  }
@@ -189,6 +201,7 @@ export default (new Reporter({
189
201
  }
190
202
  case 'log':
191
203
  if (
204
+ // @ts-expect-error TS2339
192
205
  event.diagnostics != null &&
193
206
  (event.level === 'error' ||
194
207
  event.level === 'warn' ||
@@ -211,16 +224,17 @@ export default (new Reporter({
211
224
  }
212
225
  case 'watchEnd':
213
226
  connections.forEach((c) => c.end());
227
+ // @ts-expect-error TS7005
214
228
  await server.close();
215
229
  ignoreFail(() => fs.unlinkSync(META_FILE));
216
230
  break;
217
231
  }
218
232
  },
219
- }): Reporter);
233
+ }) as Reporter;
220
234
 
221
235
  function updateBuildState(
222
236
  state: 'start' | 'progress' | 'end',
223
- message: string | void,
237
+ message?: string,
224
238
  ) {
225
239
  connections.forEach((c) =>
226
240
  c.sendNotification(NotificationBuildStatus, state, message),
@@ -266,7 +280,8 @@ function updateDiagnostics(
266
280
  continue;
267
281
  }
268
282
 
269
- const relatedInformation = [];
283
+ // @ts-expect-error TS2304
284
+ const relatedInformation: Array<DiagnosticRelatedInformation> = [];
270
285
  for (const codeFrame of codeFrames) {
271
286
  for (const highlight of codeFrame.codeHighlights) {
272
287
  const filePath = codeFrame.filePath;
@@ -323,7 +338,7 @@ function getDiagnosticsUnusedExports(
323
338
  document: string,
324
339
  ): Array<Diagnostic> {
325
340
  let filename = url.fileURLToPath(document);
326
- let diagnostics = [];
341
+ let diagnostics: Array<Diagnostic> = [];
327
342
 
328
343
  let asset = bundleGraph.traverse((node, context, actions) => {
329
344
  if (node.type === 'asset' && node.value.filePath === filename) {
@@ -333,7 +348,8 @@ function getDiagnosticsUnusedExports(
333
348
  });
334
349
 
335
350
  if (asset) {
336
- const generateDiagnostic = (loc, type) => ({
351
+ // @ts-expect-error TS2304
352
+ const generateDiagnostic = (loc: SourceLocation, type: string) => ({
337
353
  range: {
338
354
  start: {
339
355
  line: loc.start.line - 1,
@@ -350,8 +366,10 @@ function getDiagnosticsUnusedExports(
350
366
  tags: [DiagnosticTag.Unnecessary],
351
367
  });
352
368
 
369
+ // @ts-expect-error TS2345
353
370
  let usedSymbols = bundleGraph.getUsedSymbols(asset);
354
371
  if (usedSymbols) {
372
+ // @ts-expect-error TS2339
355
373
  for (let [exported, symbol] of asset.symbols) {
356
374
  if (!usedSymbols.has(exported)) {
357
375
  if (symbol.loc) {
@@ -378,6 +396,7 @@ function getDiagnosticsUnusedExports(
378
396
  // }
379
397
  }
380
398
 
399
+ // @ts-expect-error TS2339
381
400
  for (let dep of asset.getDependencies()) {
382
401
  let usedSymbols = bundleGraph.getUsedSymbols(dep);
383
402
  if (usedSymbols) {
@@ -446,6 +465,7 @@ function getImporters(
446
465
  });
447
466
 
448
467
  if (asset) {
468
+ // @ts-expect-error TS2345
449
469
  let incoming = bundleGraph.getIncomingDependencies(asset);
450
470
  return incoming
451
471
  .filter((dep) => dep.sourcePath != null)
package/src/ipc.ts ADDED
@@ -0,0 +1,77 @@
1
+ import * as net from 'net';
2
+ import type {
3
+ MessageReader,
4
+ MessageWriter,
5
+ MessageConnection,
6
+ } from 'vscode-jsonrpc/node';
7
+ import {
8
+ createMessageConnection,
9
+ SocketMessageReader,
10
+ SocketMessageWriter,
11
+ } from 'vscode-jsonrpc/node';
12
+
13
+ function createClientPipeTransport(
14
+ pipeName: string,
15
+ onConnected: (reader: MessageReader, writer: MessageWriter) => void,
16
+ ): Promise<{
17
+ close: () => Promise<void>;
18
+ }> {
19
+ return new Promise(
20
+ (
21
+ resolve: (
22
+ result:
23
+ | Promise<{
24
+ close(): Promise<void>;
25
+ }>
26
+ | {
27
+ close(): Promise<void>;
28
+ },
29
+ ) => void,
30
+ reject: (error?: any) => void,
31
+ ) => {
32
+ let server: net.Server = net.createServer((socket: net.Socket) => {
33
+ onConnected(
34
+ new SocketMessageReader(socket),
35
+ new SocketMessageWriter(socket),
36
+ );
37
+ });
38
+ server.on('error', reject);
39
+ server.listen(pipeName, () => {
40
+ server.removeListener('error', reject);
41
+ resolve({
42
+ close() {
43
+ return new Promise(
44
+ (
45
+ res: (result: Promise<undefined> | undefined) => void,
46
+ rej: (error?: any) => void,
47
+ ) => {
48
+ server.close((e) => {
49
+ if (e) rej(e);
50
+ // @ts-expect-error TS2794
51
+ else res();
52
+ });
53
+ },
54
+ );
55
+ },
56
+ });
57
+ });
58
+ },
59
+ );
60
+ }
61
+
62
+ export function createServer(
63
+ filename: string,
64
+ setup: (connection: MessageConnection) => void,
65
+ ): Promise<{
66
+ close: () => Promise<void>;
67
+ }> {
68
+ return createClientPipeTransport(
69
+ filename,
70
+ (reader: MessageReader, writer: MessageWriter) => {
71
+ let connection = createMessageConnection(reader, writer);
72
+ connection.listen();
73
+
74
+ setup(connection);
75
+ },
76
+ );
77
+ }
@@ -1,5 +1,5 @@
1
- // @flow
2
1
  import type {DiagnosticLogEvent, FilePath} from '@atlaspack/types';
2
+ // @ts-expect-error TS2724
3
3
  import type {ODiagnosticSeverity} from 'vscode-languageserver';
4
4
 
5
5
  import path from 'path';
@@ -61,35 +61,31 @@ export const DiagnosticTag = {
61
61
  * Clients are allowed to render diagnostics with this tag faded out instead of having
62
62
  * an error squiggle.
63
63
  */
64
- // $FlowFixMe
65
- Unnecessary: (1: ODiagnosticTag),
64
+ // @ts-expect-error TS2304
65
+ Unnecessary: 1 as ODiagnosticTag,
66
66
  /**
67
67
  * Deprecated or obsolete code.
68
68
  *
69
69
  * Clients are allowed to rendered diagnostics with this tag strike through.
70
70
  */
71
- // $FlowFixMe
72
- Deprecated: (2: ODiagnosticTag),
73
- };
71
+ // @ts-expect-error TS2304
72
+ Deprecated: 2 as ODiagnosticTag,
73
+ } as const;
74
74
  export const DiagnosticSeverity = {
75
75
  /**
76
76
  * Reports an error.
77
77
  */
78
- // $FlowFixMe
79
- Error: (1: ODiagnosticSeverity),
78
+ Error: 1 as ODiagnosticSeverity,
80
79
  /**
81
80
  * Reports a warning.
82
81
  */
83
- // $FlowFixMe
84
- Warning: (2: ODiagnosticSeverity),
82
+ Warning: 2 as ODiagnosticSeverity,
85
83
  /**
86
84
  * Reports an information.
87
85
  */
88
- // $FlowFixMe
89
- Information: (3: ODiagnosticSeverity),
86
+ Information: 3 as ODiagnosticSeverity,
90
87
  /**
91
88
  * Reports a hint.
92
89
  */
93
- // $FlowFixMe
94
- Hint: (4: ODiagnosticSeverity),
95
- };
90
+ Hint: 4 as ODiagnosticSeverity,
91
+ } as const;
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }
package/src/ipc.js DELETED
@@ -1,55 +0,0 @@
1
- // @flow
2
- import * as net from 'net';
3
- import type {
4
- MessageReader,
5
- MessageWriter,
6
- MessageConnection,
7
- } from 'vscode-jsonrpc/node';
8
- import {
9
- createMessageConnection,
10
- SocketMessageReader,
11
- SocketMessageWriter,
12
- } from 'vscode-jsonrpc/node';
13
-
14
- function createClientPipeTransport(
15
- pipeName: string,
16
- onConnected: (reader: MessageReader, writer: MessageWriter) => void,
17
- ): Promise<{|close: () => Promise<void>|}> {
18
- return new Promise((resolve, reject) => {
19
- let server: net.Server = net.createServer((socket: net.Socket) => {
20
- onConnected(
21
- new SocketMessageReader(socket),
22
- new SocketMessageWriter(socket),
23
- );
24
- });
25
- server.on('error', reject);
26
- server.listen(pipeName, () => {
27
- server.removeListener('error', reject);
28
- resolve({
29
- close() {
30
- return new Promise((res, rej) => {
31
- server.close((e) => {
32
- if (e) rej(e);
33
- else res();
34
- });
35
- });
36
- },
37
- });
38
- });
39
- });
40
- }
41
-
42
- export function createServer(
43
- filename: string,
44
- setup: (connection: MessageConnection) => void,
45
- ): Promise<{|close: () => Promise<void>|}> {
46
- return createClientPipeTransport(
47
- filename,
48
- (reader: MessageReader, writer: MessageWriter) => {
49
- let connection = createMessageConnection(reader, writer);
50
- connection.listen();
51
-
52
- setup(connection);
53
- },
54
- );
55
- }