@parcel/lsp 2.12.1-dev.3238 → 2.12.1-dev.3260
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/LspServer.js +89 -90
- package/lib/LspServer.js.map +1 -1
- package/package.json +5 -5
package/lib/LspServer.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
var $
|
2
|
-
var $
|
3
|
-
var $
|
4
|
-
var $
|
5
|
-
var $
|
6
|
-
var $
|
7
|
-
var $
|
8
|
-
var $
|
9
|
-
var $
|
10
|
-
var $
|
1
|
+
var $2ASyg$path = require("path");
|
2
|
+
var $2ASyg$fs = require("fs");
|
3
|
+
var $2ASyg$os = require("os");
|
4
|
+
var $2ASyg$vscodelanguageservernode = require("vscode-languageserver/node");
|
5
|
+
var $2ASyg$vscodejsonrpcnode = require("vscode-jsonrpc/node");
|
6
|
+
var $2ASyg$assert = require("assert");
|
7
|
+
var $2ASyg$url = require("url");
|
8
|
+
var $2ASyg$commonpathprefix = require("common-path-prefix");
|
9
|
+
var $2ASyg$parcelwatcher = require("@parcel/watcher");
|
10
|
+
var $2ASyg$parcellspprotocol = require("@parcel/lsp-protocol");
|
11
11
|
|
12
12
|
|
13
13
|
|
@@ -19,31 +19,30 @@ var $ke4eu$parcellspprotocol = require("@parcel/lsp-protocol");
|
|
19
19
|
|
20
20
|
|
21
21
|
|
22
|
-
const $
|
23
|
-
const $
|
24
|
-
const $
|
22
|
+
const $b0ec55fbec0dc8ff$var$connection = (0, $2ASyg$vscodelanguageservernode.createConnection)((0, $2ASyg$vscodelanguageservernode.ProposedFeatures).all);
|
23
|
+
const $b0ec55fbec0dc8ff$var$WORKSPACE_ROOT = process.cwd();
|
24
|
+
const $b0ec55fbec0dc8ff$var$LSP_SENTINEL_FILENAME = 'lsp-server';
|
25
25
|
// Create a simple text document manager.
|
26
26
|
// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
27
|
-
let $
|
28
|
-
let $
|
27
|
+
let $b0ec55fbec0dc8ff$var$hasConfigurationCapability = false;
|
28
|
+
let $b0ec55fbec0dc8ff$var$hasWorkspaceFolderCapability = false;
|
29
29
|
// let hasDiagnosticRelatedInformationCapability = false;
|
30
|
-
let $
|
31
|
-
$
|
32
|
-
var _capabilities_workspace_diagnostics, _capabilities_workspace;
|
30
|
+
let $b0ec55fbec0dc8ff$var$hasDiagnosticsRefreshSupport = false;
|
31
|
+
$b0ec55fbec0dc8ff$var$connection.onInitialize((params)=>{
|
33
32
|
const capabilities = params.capabilities;
|
34
33
|
// Does the client support the `workspace/configuration` request?
|
35
34
|
// If not, we fall back using global settings.
|
36
|
-
$
|
37
|
-
$
|
35
|
+
$b0ec55fbec0dc8ff$var$hasConfigurationCapability = !!(capabilities.workspace && !!capabilities.workspace.configuration);
|
36
|
+
$b0ec55fbec0dc8ff$var$hasWorkspaceFolderCapability = !!(capabilities.workspace && !!capabilities.workspace.workspaceFolders);
|
38
37
|
// hasDiagnosticRelatedInformationCapability = !!(
|
39
38
|
// capabilities.textDocument &&
|
40
39
|
// capabilities.textDocument.publishDiagnostics &&
|
41
40
|
// capabilities.textDocument.publishDiagnostics.relatedInformation
|
42
41
|
// );
|
43
|
-
$
|
42
|
+
$b0ec55fbec0dc8ff$var$hasDiagnosticsRefreshSupport = Boolean(capabilities.workspace?.diagnostics?.refreshSupport);
|
44
43
|
const result = {
|
45
44
|
capabilities: {
|
46
|
-
textDocumentSync: (0, $
|
45
|
+
textDocumentSync: (0, $2ASyg$vscodelanguageservernode.TextDocumentSyncKind).Incremental,
|
47
46
|
// Tell the client that this server supports code completion.
|
48
47
|
diagnosticProvider: {
|
49
48
|
workspaceDiagnostics: false,
|
@@ -51,31 +50,31 @@ $7c07d6b46fb9c242$var$connection.onInitialize((params)=>{
|
|
51
50
|
}
|
52
51
|
}
|
53
52
|
};
|
54
|
-
if ($
|
53
|
+
if ($b0ec55fbec0dc8ff$var$hasWorkspaceFolderCapability) result.capabilities.workspace = {
|
55
54
|
workspaceFolders: {
|
56
55
|
supported: true
|
57
56
|
}
|
58
57
|
};
|
59
58
|
return result;
|
60
59
|
});
|
61
|
-
$
|
62
|
-
if ($
|
63
|
-
$
|
64
|
-
if ($
|
65
|
-
$
|
60
|
+
$b0ec55fbec0dc8ff$var$connection.onInitialized(()=>{
|
61
|
+
if ($b0ec55fbec0dc8ff$var$hasConfigurationCapability) // Register for all configuration changes.
|
62
|
+
$b0ec55fbec0dc8ff$var$connection.client.register((0, $2ASyg$vscodelanguageservernode.DidChangeConfigurationNotification).type, undefined);
|
63
|
+
if ($b0ec55fbec0dc8ff$var$hasWorkspaceFolderCapability) $b0ec55fbec0dc8ff$var$connection.workspace.onDidChangeWorkspaceFolders(()=>{
|
64
|
+
$b0ec55fbec0dc8ff$var$connection.console.log('Workspace folder change event received.');
|
66
65
|
});
|
67
66
|
});
|
68
67
|
// Proxy
|
69
|
-
$
|
70
|
-
let client = $
|
68
|
+
$b0ec55fbec0dc8ff$var$connection.onRequest((0, $2ASyg$parcellspprotocol.RequestImporters), async (params)=>{
|
69
|
+
let client = $b0ec55fbec0dc8ff$var$findClient(params);
|
71
70
|
if (client) {
|
72
|
-
let result = await client.connection.sendRequest((0, $
|
71
|
+
let result = await client.connection.sendRequest((0, $2ASyg$parcellspprotocol.RequestImporters), params);
|
73
72
|
return result;
|
74
73
|
}
|
75
74
|
return null;
|
76
75
|
});
|
77
|
-
$
|
78
|
-
let client = $
|
76
|
+
$b0ec55fbec0dc8ff$var$connection.onRequest((0, $2ASyg$vscodelanguageservernode.DocumentDiagnosticRequest).type, async (params)=>{
|
77
|
+
let client = $b0ec55fbec0dc8ff$var$findClient(params.textDocument.uri);
|
79
78
|
let result;
|
80
79
|
if (client) {
|
81
80
|
// console.log(
|
@@ -84,24 +83,24 @@ $7c07d6b46fb9c242$var$connection.onRequest((0, $ke4eu$vscodelanguageservernode.D
|
|
84
83
|
// params.previousResultId === client.lastBuild,
|
85
84
|
// );
|
86
85
|
if (params.previousResultId === client.lastBuild) return {
|
87
|
-
kind: (0, $
|
86
|
+
kind: (0, $2ASyg$vscodelanguageservernode.DocumentDiagnosticReportKind).Unchanged,
|
88
87
|
resultId: client.lastBuild
|
89
88
|
};
|
90
|
-
result = await client.connection.sendRequest((0, $
|
89
|
+
result = await client.connection.sendRequest((0, $2ASyg$parcellspprotocol.RequestDocumentDiagnostics), params.textDocument.uri);
|
91
90
|
if (result) client.uris.add(params.textDocument.uri);
|
92
91
|
}
|
93
92
|
return {
|
94
|
-
kind: (0, $
|
95
|
-
resultId: client
|
96
|
-
items: result
|
93
|
+
kind: (0, $2ASyg$vscodelanguageservernode.DocumentDiagnosticReportKind).Full,
|
94
|
+
resultId: client?.lastBuild,
|
95
|
+
items: result ?? []
|
97
96
|
};
|
98
97
|
});
|
99
|
-
$
|
100
|
-
class $
|
98
|
+
$b0ec55fbec0dc8ff$var$connection.listen();
|
99
|
+
class $b0ec55fbec0dc8ff$var$ProgressReporter {
|
101
100
|
begin() {
|
102
101
|
this.progressReporterPromise = (async ()=>{
|
103
|
-
let reporter = await $
|
104
|
-
reporter.begin(
|
102
|
+
let reporter = await $b0ec55fbec0dc8ff$var$connection.window.createWorkDoneProgress();
|
103
|
+
reporter.begin('Parcel');
|
105
104
|
return reporter;
|
106
105
|
})();
|
107
106
|
this.progressReporterPromise.then((reporter)=>{
|
@@ -110,7 +109,7 @@ class $7c07d6b46fb9c242$var$ProgressReporter {
|
|
110
109
|
}
|
111
110
|
async done() {
|
112
111
|
if (this.progressReporterPromise == null) this.begin();
|
113
|
-
$
|
112
|
+
$2ASyg$assert(this.progressReporterPromise != null);
|
114
113
|
(await this.progressReporterPromise).done();
|
115
114
|
this.progressReporterPromise = null;
|
116
115
|
}
|
@@ -124,108 +123,108 @@ class $7c07d6b46fb9c242$var$ProgressReporter {
|
|
124
123
|
}
|
125
124
|
}
|
126
125
|
}
|
127
|
-
function $
|
128
|
-
if ($
|
126
|
+
function $b0ec55fbec0dc8ff$var$sendDiagnosticsRefresh() {
|
127
|
+
if ($b0ec55fbec0dc8ff$var$hasDiagnosticsRefreshSupport) $b0ec55fbec0dc8ff$var$connection.sendRequest((0, $2ASyg$vscodelanguageservernode.DiagnosticRefreshRequest).type);
|
129
128
|
}
|
130
|
-
let $
|
131
|
-
let $
|
132
|
-
function $
|
133
|
-
let filepath = $
|
129
|
+
let $b0ec55fbec0dc8ff$var$progressReporter = new $b0ec55fbec0dc8ff$var$ProgressReporter();
|
130
|
+
let $b0ec55fbec0dc8ff$var$clients = new Map();
|
131
|
+
function $b0ec55fbec0dc8ff$var$findClient(document) {
|
132
|
+
let filepath = $2ASyg$url.fileURLToPath(document);
|
134
133
|
let longestPrefix = 0;
|
135
134
|
let bestClient;
|
136
|
-
for (let [, client] of $
|
137
|
-
let prefix = $
|
135
|
+
for (let [, client] of $b0ec55fbec0dc8ff$var$clients){
|
136
|
+
let prefix = $2ASyg$commonpathprefix([
|
138
137
|
client.projectRoot,
|
139
138
|
filepath
|
140
139
|
]).length;
|
141
140
|
if (longestPrefix < prefix) {
|
142
141
|
longestPrefix = prefix;
|
143
142
|
bestClient = client;
|
144
|
-
} else if (longestPrefix === prefix) console.warn(
|
143
|
+
} else if (longestPrefix === prefix) console.warn('Ambiguous client for ' + filepath);
|
145
144
|
}
|
146
145
|
return bestClient;
|
147
146
|
}
|
148
|
-
function $
|
149
|
-
const file = $
|
147
|
+
function $b0ec55fbec0dc8ff$var$loadMetafile(filepath) {
|
148
|
+
const file = $2ASyg$fs.readFileSync(filepath, 'utf-8');
|
150
149
|
return JSON.parse(file);
|
151
150
|
}
|
152
|
-
function $
|
151
|
+
function $b0ec55fbec0dc8ff$var$createClient(metafilepath, metafile) {
|
153
152
|
let socketfilepath = metafilepath.slice(0, -5);
|
154
|
-
let [reader, writer] = (0, $
|
155
|
-
let client = (0, $
|
153
|
+
let [reader, writer] = (0, $2ASyg$vscodejsonrpcnode.createServerPipeTransport)(socketfilepath);
|
154
|
+
let client = (0, $2ASyg$vscodejsonrpcnode.createMessageConnection)(reader, writer);
|
156
155
|
client.listen();
|
157
156
|
let uris = new Set();
|
158
157
|
let result = {
|
159
158
|
connection: client,
|
160
159
|
uris: uris,
|
161
160
|
projectRoot: metafile.projectRoot,
|
162
|
-
lastBuild:
|
161
|
+
lastBuild: '0'
|
163
162
|
};
|
164
|
-
client.onNotification((0, $
|
163
|
+
client.onNotification((0, $2ASyg$parcellspprotocol.NotificationBuildStatus), (state, message)=>{
|
165
164
|
// console.log('got NotificationBuildStatus', state, message);
|
166
|
-
if (state ===
|
167
|
-
$
|
168
|
-
for (let uri of uris)$
|
165
|
+
if (state === 'start') {
|
166
|
+
$b0ec55fbec0dc8ff$var$progressReporter.begin();
|
167
|
+
for (let uri of uris)$b0ec55fbec0dc8ff$var$connection.sendDiagnostics({
|
169
168
|
uri: uri,
|
170
169
|
diagnostics: []
|
171
170
|
});
|
172
|
-
} else if (state ===
|
173
|
-
else if (state ===
|
171
|
+
} else if (state === 'progress' && message != null) $b0ec55fbec0dc8ff$var$progressReporter.report(message);
|
172
|
+
else if (state === 'end') {
|
174
173
|
result.lastBuild = String(Date.now());
|
175
|
-
$
|
176
|
-
$
|
177
|
-
$
|
174
|
+
$b0ec55fbec0dc8ff$var$sendDiagnosticsRefresh();
|
175
|
+
$b0ec55fbec0dc8ff$var$progressReporter.done();
|
176
|
+
$b0ec55fbec0dc8ff$var$connection.sendNotification((0, $2ASyg$parcellspprotocol.NotificationBuild));
|
178
177
|
}
|
179
178
|
});
|
180
|
-
client.onNotification((0, $
|
179
|
+
client.onNotification((0, $2ASyg$parcellspprotocol.NotificationWorkspaceDiagnostics), (diagnostics)=>{
|
181
180
|
// console.log('got NotificationWorkspaceDiagnostics', diagnostics);
|
182
181
|
for (let d of diagnostics){
|
183
182
|
uris.add(d.uri);
|
184
|
-
$
|
183
|
+
$b0ec55fbec0dc8ff$var$connection.sendDiagnostics(d);
|
185
184
|
}
|
186
185
|
});
|
187
186
|
client.onClose(()=>{
|
188
|
-
$
|
189
|
-
$
|
187
|
+
$b0ec55fbec0dc8ff$var$clients.delete(JSON.stringify(metafile));
|
188
|
+
$b0ec55fbec0dc8ff$var$sendDiagnosticsRefresh();
|
190
189
|
return Promise.all([
|
191
190
|
...uris
|
192
|
-
].map((uri)=>$
|
191
|
+
].map((uri)=>$b0ec55fbec0dc8ff$var$connection.sendDiagnostics({
|
193
192
|
uri: uri,
|
194
193
|
diagnostics: []
|
195
194
|
})));
|
196
195
|
});
|
197
|
-
$
|
198
|
-
$
|
196
|
+
$b0ec55fbec0dc8ff$var$sendDiagnosticsRefresh();
|
197
|
+
$b0ec55fbec0dc8ff$var$clients.set(JSON.stringify(metafile), result);
|
199
198
|
}
|
200
199
|
// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)
|
201
|
-
const $
|
202
|
-
$
|
200
|
+
const $b0ec55fbec0dc8ff$var$BASEDIR = $2ASyg$path.join($2ASyg$fs.realpathSync($2ASyg$os.tmpdir()), 'parcel-lsp');
|
201
|
+
$2ASyg$fs.mkdirSync($b0ec55fbec0dc8ff$var$BASEDIR, {
|
203
202
|
recursive: true
|
204
203
|
});
|
205
|
-
$
|
204
|
+
$2ASyg$fs.writeFileSync($2ASyg$path.join($b0ec55fbec0dc8ff$var$BASEDIR, $b0ec55fbec0dc8ff$var$LSP_SENTINEL_FILENAME), '');
|
206
205
|
// Search for currently running Parcel processes in the parcel-lsp dir.
|
207
206
|
// Create an IPC client connection for each running process.
|
208
|
-
for (let filename of $
|
209
|
-
if (!filename.endsWith(
|
210
|
-
let filepath = $
|
211
|
-
const contents = $
|
207
|
+
for (let filename of $2ASyg$fs.readdirSync($b0ec55fbec0dc8ff$var$BASEDIR)){
|
208
|
+
if (!filename.endsWith('.json')) continue;
|
209
|
+
let filepath = $2ASyg$path.join($b0ec55fbec0dc8ff$var$BASEDIR, filename);
|
210
|
+
const contents = $b0ec55fbec0dc8ff$var$loadMetafile(filepath);
|
212
211
|
const { projectRoot: projectRoot } = contents;
|
213
|
-
if ($
|
212
|
+
if ($b0ec55fbec0dc8ff$var$WORKSPACE_ROOT === projectRoot) $b0ec55fbec0dc8ff$var$createClient(filepath, contents);
|
214
213
|
}
|
215
214
|
// Watch for new Parcel processes in the parcel-lsp dir, and disconnect the
|
216
215
|
// client for each corresponding connection when a Parcel process ends
|
217
|
-
$
|
216
|
+
$2ASyg$parcelwatcher.subscribe($b0ec55fbec0dc8ff$var$BASEDIR, async (err, events)=>{
|
218
217
|
if (err) throw err;
|
219
218
|
for (let event of events){
|
220
|
-
if (event.type ===
|
221
|
-
const contents = $
|
219
|
+
if (event.type === 'create' && event.path.endsWith('.json')) {
|
220
|
+
const contents = $b0ec55fbec0dc8ff$var$loadMetafile(event.path);
|
222
221
|
const { projectRoot: projectRoot } = contents;
|
223
|
-
if ($
|
224
|
-
} else if (event.type ===
|
225
|
-
let existing = $
|
226
|
-
console.log(
|
222
|
+
if ($b0ec55fbec0dc8ff$var$WORKSPACE_ROOT === projectRoot) $b0ec55fbec0dc8ff$var$createClient(event.path, contents);
|
223
|
+
} else if (event.type === 'delete' && event.path.endsWith('.json')) {
|
224
|
+
let existing = $b0ec55fbec0dc8ff$var$clients.get(event.path);
|
225
|
+
console.log('existing', event.path, existing);
|
227
226
|
if (existing) {
|
228
|
-
$
|
227
|
+
$b0ec55fbec0dc8ff$var$clients.delete(event.path);
|
229
228
|
existing.connection.end();
|
230
229
|
}
|
231
230
|
}
|
package/lib/LspServer.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,MAAMiC,mCAAa9B,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAAA,EAAiBqB,GAAG;AACxD,MAAMC,uCAAiBJ,QAAQK,GAAG;AAClC,MAAMC,8CAAwB;AAC9B,yCAAA;AACA,kFAAA;AAEA,IAAIC,mDAA6B;AACjC,IAAIC,qDAA+B;AACnC,yDAAA;AACA,IAAIC,qDAA+B;AAEnCP,iCAAWQ,YAAY,CAAC,CAACC;QAiBrBC,qCAAAA;IAhBF,MAAMA,eAAeD,O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AAiBD,iBAAUoI,+BAAS/F,8CAAwB;AAE5D,uEAAA;AACA,4DAAA;AACA,KAAK,IAAIsG,YAAY1I,sBAAemI,+BAAU;IAC5C,IAAI,CAACO,SAASE,QAAQ,CAAC,UAAU;IACjC,IAAIzC,WAAWpG,iBAAUoI,+BAASO;IAClC,MAAMG,WAAWnC,mCAAaP;IAC9B,MAAM,eAACvE,WAAAA,EAAY,GAAGiH;IAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAaZ,UAAU0C;AAE3B;AAEA,2EAAA;AACA,sEAAA;AACAxH,+BAAkB8G,+BAAS,OAAOY,KAAKC;IACrC,IAAID,KACF,MAAMA;IAGR,KAAK,IAAIE,SAASD,OAAQ;QACxB,IAAIC,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAC3D,MAAMC,WAAWnC,mCAAauC,MAAMlJ,IAAI;YACxC,MAAM,eAAC6B,WAAAA,EAAY,GAAGiH;YAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAakC,MAAMlJ,IAAI,EAAE8I;QAE7B,OAAO,IAAII,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAClE,IAAIM,WAAWlD,8BAAQmD,GAAG,CAACF,MAAMlJ,IAAI;YACrC+D,QAAQC,GAAG,CAAC,YAAYkF,MAAMlJ,IAAI,EAAEmJ;YACpC,IAAIA,UAAU;gBACZlD,8BAAQ+B,MAAM,CAACkB,MAAMlJ,IAAI;gBACzBmJ,SAASlH,UAAU,CAACoH,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/utils/parcel-lsp/src/LspServer.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport {\n createConnection,\n DiagnosticRefreshRequest,\n DidChangeConfigurationNotification,\n DocumentDiagnosticParams,\n DocumentDiagnosticReport,\n DocumentDiagnosticReportKind,\n DocumentDiagnosticRequest,\n DocumentUri,\n InitializeParams,\n InitializeResult,\n ProposedFeatures,\n TextDocumentSyncKind,\n WorkDoneProgressServerReporter,\n} from 'vscode-languageserver/node';\n\nimport {\n createServerPipeTransport,\n createMessageConnection,\n MessageConnection,\n} from 'vscode-jsonrpc/node';\nimport * as invariant from 'assert';\nimport * as url from 'url';\nimport commonPathPrefix = require('common-path-prefix');\n\n// import {TextDocument} from 'vscode-languageserver-textdocument';\nimport * as watcher from '@parcel/watcher';\nimport {\n NotificationBuild,\n NotificationBuildStatus,\n NotificationWorkspaceDiagnostics,\n RequestDocumentDiagnostics,\n RequestImporters,\n} from '@parcel/lsp-protocol';\n\ntype Metafile = {\n projectRoot: string;\n pid: typeof process['pid'];\n argv: typeof process['argv'];\n};\n\nconst connection = createConnection(ProposedFeatures.all);\nconst WORKSPACE_ROOT = process.cwd();\nconst LSP_SENTINEL_FILENAME = 'lsp-server';\n// Create a simple text document manager.\n// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\nlet hasWorkspaceFolderCapability = false;\n// let hasDiagnosticRelatedInformationCapability = false;\nlet hasDiagnosticsRefreshSupport = false;\n\nconnection.onInitialize((params: InitializeParams) => {\n const capabilities = params.capabilities;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we fall back using global settings.\n hasConfigurationCapability = !!(\n capabilities.workspace && !!capabilities.workspace.configuration\n );\n hasWorkspaceFolderCapability = !!(\n capabilities.workspace && !!capabilities.workspace.workspaceFolders\n );\n // hasDiagnosticRelatedInformationCapability = !!(\n // capabilities.textDocument &&\n // capabilities.textDocument.publishDiagnostics &&\n // capabilities.textDocument.publishDiagnostics.relatedInformation\n // );\n hasDiagnosticsRefreshSupport = Boolean(\n capabilities.workspace?.diagnostics?.refreshSupport,\n );\n\n const result: InitializeResult = {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n // Tell the client that this server supports code completion.\n diagnosticProvider: {\n workspaceDiagnostics: false,\n interFileDependencies: true,\n },\n },\n };\n\n if (hasWorkspaceFolderCapability) {\n result.capabilities.workspace = {\n workspaceFolders: {\n supported: true,\n },\n };\n }\n return result;\n});\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n if (hasWorkspaceFolderCapability) {\n connection.workspace.onDidChangeWorkspaceFolders(_event => {\n connection.console.log('Workspace folder change event received.');\n });\n }\n});\n\n// Proxy\nconnection.onRequest(RequestImporters, async params => {\n let client = findClient(params);\n if (client) {\n let result = await client.connection.sendRequest(RequestImporters, params);\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n let client = findClient(params.textDocument.uri);\n let result;\n if (client) {\n // console.log(\n // 'DocumentDiagnosticRequest',\n // params.textDocument.uri,\n // params.previousResultId === client.lastBuild,\n // );\n\n if (params.previousResultId === client.lastBuild) {\n return {\n kind: DocumentDiagnosticReportKind.Unchanged,\n resultId: client.lastBuild,\n };\n }\n\n result = await client.connection.sendRequest(\n RequestDocumentDiagnostics,\n params.textDocument.uri,\n );\n\n if (result) {\n client.uris.add(params.textDocument.uri);\n }\n }\n\n return {\n kind: DocumentDiagnosticReportKind.Full,\n resultId: client?.lastBuild,\n items: result ?? [],\n };\n },\n);\n\nconnection.listen();\n\nclass ProgressReporter {\n progressReporterPromise?: Promise<WorkDoneProgressServerReporter> | null;\n lastMessage?: string;\n begin() {\n this.progressReporterPromise = (async () => {\n let reporter = await connection.window.createWorkDoneProgress();\n reporter.begin('Parcel');\n return reporter;\n })();\n this.progressReporterPromise.then(reporter => {\n if (this.lastMessage != null) {\n reporter.report(this.lastMessage);\n }\n });\n }\n async done() {\n if (this.progressReporterPromise == null) {\n this.begin();\n }\n invariant(this.progressReporterPromise != null);\n (await this.progressReporterPromise).done();\n this.progressReporterPromise = null;\n }\n async report(message: string) {\n if (this.progressReporterPromise == null) {\n this.lastMessage = message;\n this.begin();\n } else {\n let r = await this.progressReporterPromise;\n r.report(message);\n }\n }\n}\n\nfunction sendDiagnosticsRefresh() {\n if (hasDiagnosticsRefreshSupport) {\n connection.sendRequest(DiagnosticRefreshRequest.type);\n }\n}\n\ntype Client = {\n connection: MessageConnection;\n projectRoot: string;\n uris: Set<DocumentUri>;\n lastBuild: string;\n};\n\nlet progressReporter = new ProgressReporter();\nlet clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n let filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (let [, client] of clients) {\n let prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\n console.warn('Ambiguous client for ' + filepath);\n }\n }\n return bestClient;\n}\n\nfunction loadMetafile(filepath: string) {\n const file = fs.readFileSync(filepath, 'utf-8');\n return JSON.parse(file);\n}\n\nfunction createClient(metafilepath: string, metafile: Metafile) {\n let socketfilepath = metafilepath.slice(0, -5);\n let [reader, writer] = createServerPipeTransport(socketfilepath);\n let client = createMessageConnection(reader, writer);\n client.listen();\n\n let uris = new Set<DocumentUri>();\n\n let result = {\n connection: client,\n uris,\n projectRoot: metafile.projectRoot,\n lastBuild: '0',\n };\n\n client.onNotification(NotificationBuildStatus, (state, message) => {\n // console.log('got NotificationBuildStatus', state, message);\n if (state === 'start') {\n progressReporter.begin();\n for (let uri of uris) {\n connection.sendDiagnostics({uri, diagnostics: []});\n }\n } else if (state === 'progress' && message != null) {\n progressReporter.report(message);\n } else if (state === 'end') {\n result.lastBuild = String(Date.now());\n sendDiagnosticsRefresh();\n progressReporter.done();\n connection.sendNotification(NotificationBuild);\n }\n });\n\n client.onNotification(NotificationWorkspaceDiagnostics, diagnostics => {\n // console.log('got NotificationWorkspaceDiagnostics', diagnostics);\n for (let d of diagnostics) {\n uris.add(d.uri);\n connection.sendDiagnostics(d);\n }\n });\n\n client.onClose(() => {\n clients.delete(JSON.stringify(metafile));\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map(uri => connection.sendDiagnostics({uri, diagnostics: []})),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(JSON.stringify(metafile), result);\n}\n\n// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)\nconst BASEDIR = path.join(fs.realpathSync(os.tmpdir()), 'parcel-lsp');\nfs.mkdirSync(BASEDIR, {recursive: true});\n\nfs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');\n\n// Search for currently running Parcel processes in the parcel-lsp dir.\n// Create an IPC client connection for each running process.\nfor (let filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n let filepath = path.join(BASEDIR, filename);\n const contents = loadMetafile(filepath);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(filepath, contents);\n }\n}\n\n// Watch for new Parcel processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Parcel process ends\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (let event of events) {\n if (event.type === 'create' && event.path.endsWith('.json')) {\n const contents = loadMetafile(event.path);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(event.path, contents);\n }\n } else if (event.type === 'delete' && event.path.endsWith('.json')) {\n let existing = clients.get(event.path);\n console.log('existing', event.path, existing);\n if (existing) {\n clients.delete(event.path);\n existing.connection.end();\n }\n }\n }\n});\n"],"names":["path","fs","os","createConnection","DiagnosticRefreshRequest","DidChangeConfigurationNotification","DocumentDiagnosticParams","DocumentDiagnosticReport","DocumentDiagnosticReportKind","DocumentDiagnosticRequest","DocumentUri","InitializeParams","InitializeResult","ProposedFeatures","TextDocumentSyncKind","WorkDoneProgressServerReporter","createServerPipeTransport","createMessageConnection","MessageConnection","invariant","url","commonPathPrefix","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","Metafile","projectRoot","pid","process","argv","connection","all","WORKSPACE_ROOT","cwd","LSP_SENTINEL_FILENAME","hasConfigurationCapability","hasWorkspaceFolderCapability","hasDiagnosticsRefreshSupport","onInitialize","params","capabilities","workspace","configuration","workspaceFolders","Boolean","diagnostics","refreshSupport","result","textDocumentSync","Incremental","diagnosticProvider","workspaceDiagnostics","interFileDependencies","supported","onInitialized","client","register","type","undefined","onDidChangeWorkspaceFolders","console","log","onRequest","findClient","sendRequest","Promise","textDocument","uri","previousResultId","lastBuild","kind","Unchanged","resultId","uris","add","Full","items","listen","ProgressReporter","begin","progressReporterPromise","reporter","window","createWorkDoneProgress","then","lastMessage","report","done","message","r","sendDiagnosticsRefresh","Client","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","loadMetafile","file","readFileSync","JSON","parse","createClient","metafilepath","metafile","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","stringify","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","writeFileSync","filename","readdirSync","endsWith","contents","subscribe","err","events","event","existing","get","end"],"version":3,"file":"LspServer.js.map","sourceRoot":"../../../../"}
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;AA4CA,MAAMiC,mCAAa9B,CAAAA,GAAAA,gDAAAA,EAAiBU,CAAAA,GAAAA,gDAAAA,EAAiBqB,GAAG;AACxD,MAAMC,uCAAiBJ,QAAQK,GAAG;AAClC,MAAMC,8CAAwB;AAC9B,yCAAA;AACA,kFAAA;AAEA,IAAIC,mDAA6B;AACjC,IAAIC,qDAA+B;AACnC,yDAAA;AACA,IAAIC,qDAA+B;AAEnCP,iCAAWQ,YAAY,CAAC,CAACC;IACvB,MAAMC,eAAeD,OAAOC,YAAY;IAExC,iEAAA;IACA,8CAAA;IACAL,mDAA6B,CAAC,CAC5BK,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,+BAASO;IAClC,MAAMG,WAAWnC,mCAAaP;IAC9B,MAAM,eAACvE,WAAAA,EAAY,GAAGiH;IAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAaZ,UAAU0C;AAE3B;AAEA,2EAAA;AACA,sEAAA;AACAxH,+BAAkB8G,+BAAS,OAAOY,KAAKC;IACrC,IAAID,KACF,MAAMA;IAGR,KAAK,IAAIE,SAASD,OAAQ;QACxB,IAAIC,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAC3D,MAAMC,WAAWnC,mCAAauC,MAAMlJ,IAAI;YACxC,MAAM,eAAC6B,WAAAA,EAAY,GAAGiH;YAEtB,IAAI3G,yCAAmBN,aACrBmF,mCAAakC,MAAMlJ,IAAI,EAAE8I;QAE7B,OAAO,IAAII,MAAMtF,IAAI,KAAK,YAAYsF,MAAMlJ,IAAI,CAAC6I,QAAQ,CAAC,UAAU;YAClE,IAAIM,WAAWlD,8BAAQmD,GAAG,CAACF,MAAMlJ,IAAI;YACrC+D,QAAQC,GAAG,CAAC,YAAYkF,MAAMlJ,IAAI,EAAEmJ;YACpC,IAAIA,UAAU;gBACZlD,8BAAQ+B,MAAM,CAACkB,MAAMlJ,IAAI;gBACzBmJ,SAASlH,UAAU,CAACoH,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/utils/parcel-lsp/src/LspServer.ts"],"sourcesContent":["import * as path from 'path';\nimport * as fs from 'fs';\nimport * as os from 'os';\nimport {\n createConnection,\n DiagnosticRefreshRequest,\n DidChangeConfigurationNotification,\n DocumentDiagnosticParams,\n DocumentDiagnosticReport,\n DocumentDiagnosticReportKind,\n DocumentDiagnosticRequest,\n DocumentUri,\n InitializeParams,\n InitializeResult,\n ProposedFeatures,\n TextDocumentSyncKind,\n WorkDoneProgressServerReporter,\n} from 'vscode-languageserver/node';\n\nimport {\n createServerPipeTransport,\n createMessageConnection,\n MessageConnection,\n} from 'vscode-jsonrpc/node';\nimport * as invariant from 'assert';\nimport * as url from 'url';\nimport commonPathPrefix = require('common-path-prefix');\n\n// import {TextDocument} from 'vscode-languageserver-textdocument';\nimport * as watcher from '@parcel/watcher';\nimport {\n NotificationBuild,\n NotificationBuildStatus,\n NotificationWorkspaceDiagnostics,\n RequestDocumentDiagnostics,\n RequestImporters,\n} from '@parcel/lsp-protocol';\n\ntype Metafile = {\n projectRoot: string;\n pid: typeof process['pid'];\n argv: typeof process['argv'];\n};\n\nconst connection = createConnection(ProposedFeatures.all);\nconst WORKSPACE_ROOT = process.cwd();\nconst LSP_SENTINEL_FILENAME = 'lsp-server';\n// Create a simple text document manager.\n// const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);\n\nlet hasConfigurationCapability = false;\nlet hasWorkspaceFolderCapability = false;\n// let hasDiagnosticRelatedInformationCapability = false;\nlet hasDiagnosticsRefreshSupport = false;\n\nconnection.onInitialize((params: InitializeParams) => {\n const capabilities = params.capabilities;\n\n // Does the client support the `workspace/configuration` request?\n // If not, we fall back using global settings.\n hasConfigurationCapability = !!(\n capabilities.workspace && !!capabilities.workspace.configuration\n );\n hasWorkspaceFolderCapability = !!(\n capabilities.workspace && !!capabilities.workspace.workspaceFolders\n );\n // hasDiagnosticRelatedInformationCapability = !!(\n // capabilities.textDocument &&\n // capabilities.textDocument.publishDiagnostics &&\n // capabilities.textDocument.publishDiagnostics.relatedInformation\n // );\n hasDiagnosticsRefreshSupport = Boolean(\n capabilities.workspace?.diagnostics?.refreshSupport,\n );\n\n const result: InitializeResult = {\n capabilities: {\n textDocumentSync: TextDocumentSyncKind.Incremental,\n // Tell the client that this server supports code completion.\n diagnosticProvider: {\n workspaceDiagnostics: false,\n interFileDependencies: true,\n },\n },\n };\n\n if (hasWorkspaceFolderCapability) {\n result.capabilities.workspace = {\n workspaceFolders: {\n supported: true,\n },\n };\n }\n return result;\n});\n\nconnection.onInitialized(() => {\n if (hasConfigurationCapability) {\n // Register for all configuration changes.\n connection.client.register(\n DidChangeConfigurationNotification.type,\n undefined,\n );\n }\n if (hasWorkspaceFolderCapability) {\n connection.workspace.onDidChangeWorkspaceFolders(_event => {\n connection.console.log('Workspace folder change event received.');\n });\n }\n});\n\n// Proxy\nconnection.onRequest(RequestImporters, async params => {\n let client = findClient(params);\n if (client) {\n let result = await client.connection.sendRequest(RequestImporters, params);\n return result;\n }\n return null;\n});\n\nconnection.onRequest(\n DocumentDiagnosticRequest.type,\n async (\n params: DocumentDiagnosticParams,\n ): Promise<DocumentDiagnosticReport> => {\n let client = findClient(params.textDocument.uri);\n let result;\n if (client) {\n // console.log(\n // 'DocumentDiagnosticRequest',\n // params.textDocument.uri,\n // params.previousResultId === client.lastBuild,\n // );\n\n if (params.previousResultId === client.lastBuild) {\n return {\n kind: DocumentDiagnosticReportKind.Unchanged,\n resultId: client.lastBuild,\n };\n }\n\n result = await client.connection.sendRequest(\n RequestDocumentDiagnostics,\n params.textDocument.uri,\n );\n\n if (result) {\n client.uris.add(params.textDocument.uri);\n }\n }\n\n return {\n kind: DocumentDiagnosticReportKind.Full,\n resultId: client?.lastBuild,\n items: result ?? [],\n };\n },\n);\n\nconnection.listen();\n\nclass ProgressReporter {\n progressReporterPromise?: Promise<WorkDoneProgressServerReporter> | null;\n lastMessage?: string;\n begin() {\n this.progressReporterPromise = (async () => {\n let reporter = await connection.window.createWorkDoneProgress();\n reporter.begin('Parcel');\n return reporter;\n })();\n this.progressReporterPromise.then(reporter => {\n if (this.lastMessage != null) {\n reporter.report(this.lastMessage);\n }\n });\n }\n async done() {\n if (this.progressReporterPromise == null) {\n this.begin();\n }\n invariant(this.progressReporterPromise != null);\n (await this.progressReporterPromise).done();\n this.progressReporterPromise = null;\n }\n async report(message: string) {\n if (this.progressReporterPromise == null) {\n this.lastMessage = message;\n this.begin();\n } else {\n let r = await this.progressReporterPromise;\n r.report(message);\n }\n }\n}\n\nfunction sendDiagnosticsRefresh() {\n if (hasDiagnosticsRefreshSupport) {\n connection.sendRequest(DiagnosticRefreshRequest.type);\n }\n}\n\ntype Client = {\n connection: MessageConnection;\n projectRoot: string;\n uris: Set<DocumentUri>;\n lastBuild: string;\n};\n\nlet progressReporter = new ProgressReporter();\nlet clients: Map<string, Client> = new Map();\n\nfunction findClient(document: DocumentUri): Client | undefined {\n let filepath = url.fileURLToPath(document);\n\n let longestPrefix = 0;\n let bestClient;\n for (let [, client] of clients) {\n let prefix = commonPathPrefix([client.projectRoot, filepath]).length;\n if (longestPrefix < prefix) {\n longestPrefix = prefix;\n bestClient = client;\n } else if (longestPrefix === prefix) {\n console.warn('Ambiguous client for ' + filepath);\n }\n }\n return bestClient;\n}\n\nfunction loadMetafile(filepath: string) {\n const file = fs.readFileSync(filepath, 'utf-8');\n return JSON.parse(file);\n}\n\nfunction createClient(metafilepath: string, metafile: Metafile) {\n let socketfilepath = metafilepath.slice(0, -5);\n let [reader, writer] = createServerPipeTransport(socketfilepath);\n let client = createMessageConnection(reader, writer);\n client.listen();\n\n let uris = new Set<DocumentUri>();\n\n let result = {\n connection: client,\n uris,\n projectRoot: metafile.projectRoot,\n lastBuild: '0',\n };\n\n client.onNotification(NotificationBuildStatus, (state, message) => {\n // console.log('got NotificationBuildStatus', state, message);\n if (state === 'start') {\n progressReporter.begin();\n for (let uri of uris) {\n connection.sendDiagnostics({uri, diagnostics: []});\n }\n } else if (state === 'progress' && message != null) {\n progressReporter.report(message);\n } else if (state === 'end') {\n result.lastBuild = String(Date.now());\n sendDiagnosticsRefresh();\n progressReporter.done();\n connection.sendNotification(NotificationBuild);\n }\n });\n\n client.onNotification(NotificationWorkspaceDiagnostics, diagnostics => {\n // console.log('got NotificationWorkspaceDiagnostics', diagnostics);\n for (let d of diagnostics) {\n uris.add(d.uri);\n connection.sendDiagnostics(d);\n }\n });\n\n client.onClose(() => {\n clients.delete(JSON.stringify(metafile));\n sendDiagnosticsRefresh();\n return Promise.all(\n [...uris].map(uri => connection.sendDiagnostics({uri, diagnostics: []})),\n );\n });\n\n sendDiagnosticsRefresh();\n clients.set(JSON.stringify(metafile), result);\n}\n\n// Take realpath because to have consistent cache keys on macOS (/var -> /private/var)\nconst BASEDIR = path.join(fs.realpathSync(os.tmpdir()), 'parcel-lsp');\nfs.mkdirSync(BASEDIR, {recursive: true});\n\nfs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');\n\n// Search for currently running Parcel processes in the parcel-lsp dir.\n// Create an IPC client connection for each running process.\nfor (let filename of fs.readdirSync(BASEDIR)) {\n if (!filename.endsWith('.json')) continue;\n let filepath = path.join(BASEDIR, filename);\n const contents = loadMetafile(filepath);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(filepath, contents);\n }\n}\n\n// Watch for new Parcel processes in the parcel-lsp dir, and disconnect the\n// client for each corresponding connection when a Parcel process ends\nwatcher.subscribe(BASEDIR, async (err, events) => {\n if (err) {\n throw err;\n }\n\n for (let event of events) {\n if (event.type === 'create' && event.path.endsWith('.json')) {\n const contents = loadMetafile(event.path);\n const {projectRoot} = contents;\n\n if (WORKSPACE_ROOT === projectRoot) {\n createClient(event.path, contents);\n }\n } else if (event.type === 'delete' && event.path.endsWith('.json')) {\n let existing = clients.get(event.path);\n console.log('existing', event.path, existing);\n if (existing) {\n clients.delete(event.path);\n existing.connection.end();\n }\n }\n }\n});\n"],"names":["path","fs","os","createConnection","DiagnosticRefreshRequest","DidChangeConfigurationNotification","DocumentDiagnosticParams","DocumentDiagnosticReport","DocumentDiagnosticReportKind","DocumentDiagnosticRequest","DocumentUri","InitializeParams","InitializeResult","ProposedFeatures","TextDocumentSyncKind","WorkDoneProgressServerReporter","createServerPipeTransport","createMessageConnection","MessageConnection","invariant","url","commonPathPrefix","watcher","NotificationBuild","NotificationBuildStatus","NotificationWorkspaceDiagnostics","RequestDocumentDiagnostics","RequestImporters","Metafile","projectRoot","pid","process","argv","connection","all","WORKSPACE_ROOT","cwd","LSP_SENTINEL_FILENAME","hasConfigurationCapability","hasWorkspaceFolderCapability","hasDiagnosticsRefreshSupport","onInitialize","params","capabilities","workspace","configuration","workspaceFolders","Boolean","diagnostics","refreshSupport","result","textDocumentSync","Incremental","diagnosticProvider","workspaceDiagnostics","interFileDependencies","supported","onInitialized","client","register","type","undefined","onDidChangeWorkspaceFolders","console","log","onRequest","findClient","sendRequest","Promise","textDocument","uri","previousResultId","lastBuild","kind","Unchanged","resultId","uris","add","Full","items","listen","ProgressReporter","begin","progressReporterPromise","reporter","window","createWorkDoneProgress","then","lastMessage","report","done","message","r","sendDiagnosticsRefresh","Client","Set","progressReporter","clients","Map","document","filepath","fileURLToPath","longestPrefix","bestClient","prefix","length","warn","loadMetafile","file","readFileSync","JSON","parse","createClient","metafilepath","metafile","socketfilepath","slice","reader","writer","onNotification","state","sendDiagnostics","String","Date","now","sendNotification","d","onClose","delete","stringify","map","set","BASEDIR","join","realpathSync","tmpdir","mkdirSync","recursive","writeFileSync","filename","readdirSync","endsWith","contents","subscribe","err","events","event","existing","get","end"],"version":3,"file":"LspServer.js.map","sourceRoot":"../../../../"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@parcel/lsp",
|
3
|
-
"version": "2.12.1-dev.
|
3
|
+
"version": "2.12.1-dev.3260+339350eb3",
|
4
4
|
"license": "MIT",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -21,11 +21,11 @@
|
|
21
21
|
"lint": "eslint src --ext ts"
|
22
22
|
},
|
23
23
|
"engines": {
|
24
|
-
"node": ">=
|
25
|
-
"parcel": "^2.0.0-dev.
|
24
|
+
"node": ">= 16.0.0",
|
25
|
+
"parcel": "^2.0.0-dev.1630+339350eb3"
|
26
26
|
},
|
27
27
|
"dependencies": {
|
28
|
-
"@parcel/lsp-protocol": "2.12.1-dev.
|
28
|
+
"@parcel/lsp-protocol": "2.12.1-dev.3260+339350eb3",
|
29
29
|
"@parcel/watcher": "^2.0.7",
|
30
30
|
"common-path-prefix": "^3.0.0",
|
31
31
|
"nullthrows": "^1.1.1",
|
@@ -44,5 +44,5 @@
|
|
44
44
|
"targets": {
|
45
45
|
"types": false
|
46
46
|
},
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "339350eb31fd33849cb1efe5fd7ad2cb096319f0"
|
48
48
|
}
|