@php-wasm/cli-util 3.1.16 → 3.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,35 +1,41 @@
1
- import f from "fs";
2
- import P from "path";
3
- import { toPosixPath as D } from "@php-wasm/util";
4
- import { XMLParser as T, XMLBuilder as $ } from "fast-xml-parser";
5
- import * as v from "jsonc-parser";
6
- const O = "PHPWASMCLI";
7
- async function q(c, a, r) {
8
- const p = r === "win32" ? (
1
+ import a from "fs";
2
+ import w from "path";
3
+ import { toPosixPath as $ } from "@php-wasm/util";
4
+ import { XMLParser as F, XMLBuilder as b } from "fast-xml-parser";
5
+ import * as x from "jsonc-parser";
6
+ const N = "PHPWASMCLI", U = [
7
+ "/dev/",
8
+ "/home/",
9
+ "/internal/",
10
+ "/request/",
11
+ "/proc/"
12
+ ];
13
+ async function W(u, f, l) {
14
+ const d = l === "win32" ? (
9
15
  // On Windows, creating a 'dir' symlink can require elevated permissions.
10
16
  // In this case, let's make junction points because they function like
11
17
  // symlinks and do not require elevated permissions.
12
18
  "junction"
13
19
  ) : "dir";
14
- f.symlinkSync(c, a, p);
20
+ a.symlinkSync(u, f, d);
15
21
  }
16
- async function H(c) {
22
+ async function q(u) {
17
23
  try {
18
- f.lstatSync(c).isSymbolicLink() && f.unlinkSync(c);
24
+ a.lstatSync(u).isSymbolicLink() && a.unlinkSync(u);
19
25
  } catch {
20
26
  }
21
27
  }
22
- function A(c, a) {
23
- return a.filter((r) => {
24
- const p = P.resolve(r.hostPath), h = P.join(c, P.sep);
28
+ function D(u, f) {
29
+ return f.filter((l) => {
30
+ const d = w.resolve(l.hostPath), c = w.join(u, w.sep);
25
31
  return (
26
32
  // If auto-mounting from the current directory,
27
33
  // the entire project directory can be mapped.
28
- p === c || p.startsWith(h)
34
+ d === u || d.startsWith(c)
29
35
  );
30
36
  });
31
37
  }
32
- const x = {
38
+ const E = {
33
39
  ignoreAttributes: !1,
34
40
  attributeNamePrefix: "",
35
41
  preserveOrder: !0,
@@ -37,100 +43,104 @@ const x = {
37
43
  commentPropName: "__xmlComment",
38
44
  allowBooleanAttributes: !0,
39
45
  trimValues: !0
40
- }, M = {
41
- ignoreAttributes: x.ignoreAttributes,
42
- attributeNamePrefix: x.attributeNamePrefix,
43
- preserveOrder: x.preserveOrder,
44
- cdataPropName: x.cdataPropName,
45
- commentPropName: x.commentPropName,
46
- suppressBooleanAttributes: !x.allowBooleanAttributes,
46
+ }, I = {
47
+ ignoreAttributes: E.ignoreAttributes,
48
+ attributeNamePrefix: E.attributeNamePrefix,
49
+ preserveOrder: E.preserveOrder,
50
+ cdataPropName: E.cdataPropName,
51
+ commentPropName: E.commentPropName,
52
+ suppressBooleanAttributes: !E.allowBooleanAttributes,
47
53
  format: !0,
48
54
  indentBy: " "
49
- }, j = {
55
+ }, k = {
50
56
  allowEmptyContent: !0,
51
57
  allowTrailingComma: !0
52
58
  };
53
- function _(c, a) {
54
- var E, b, I, F, L, k;
55
- const { name: r, host: p, port: h, mappings: l, ideKey: t } = a, m = new T(x), g = (() => {
59
+ function X(u, f) {
60
+ var S, C, L, T, _, M;
61
+ const { name: l, host: d, port: c, pathMappings: h, ideKey: t } = f, P = new F(E), v = (() => {
56
62
  try {
57
- return m.parse(c, !0);
63
+ return P.parse(u, !0);
58
64
  } catch {
59
65
  throw new Error("PhpStorm configuration file is not valid XML.");
60
66
  }
61
- })(), u = {
67
+ })(), y = {
62
68
  server: [{}],
63
69
  ":@": {
64
- name: r,
70
+ name: l,
65
71
  // NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port)
66
72
  // is provided in `host`. The separate `port` field is ignored or misinterpreted,
67
73
  // so we rely solely on host: "host:port".
68
- host: `${p}:${h}`,
74
+ host: `${d}:${c}`,
69
75
  use_path_mappings: "true"
70
76
  }
71
77
  };
72
- l && l.length && (u.server[0].path_mappings = l.map((e) => ({
73
- mapping: [],
74
- ":@": {
75
- "local-root": `$PROJECT_DIR$/${D(
76
- P.relative(a.projectDir, e.hostPath)
77
- )}`,
78
- "remote-root": e.vfsPath
79
- }
80
- })));
81
- let n = g == null ? void 0 : g.find((e) => !!(e != null && e.project));
82
- if (n) {
83
- const e = (E = n[":@"]) == null ? void 0 : E.version;
84
- if (e === void 0)
78
+ h && h.length && (y.server[0].path_mappings = h.map(
79
+ (n) => ({
80
+ mapping: [],
81
+ ":@": {
82
+ "local-root": `$PROJECT_DIR$/${$(
83
+ w.relative(f.projectDir, n.hostPath)
84
+ )}`,
85
+ "remote-root": n.vfsPath
86
+ }
87
+ })
88
+ ));
89
+ let p = v == null ? void 0 : v.find(
90
+ (n) => !!(n != null && n.project)
91
+ );
92
+ if (p) {
93
+ const n = (S = p[":@"]) == null ? void 0 : S.version;
94
+ if (n === void 0)
85
95
  throw new Error(
86
96
  'PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but the <project> configuration has no version number.'
87
97
  );
88
- if (e !== "4")
98
+ if (n !== "4")
89
99
  throw new Error(
90
- `PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but we found a <project> configuration with version "${e}".`
100
+ `PhpStorm IDE integration only supports <project version="4"> in workspace.xml, but we found a <project> configuration with version "${n}".`
91
101
  );
92
102
  }
93
- n === void 0 && (n = {
103
+ p === void 0 && (p = {
94
104
  project: [],
95
105
  ":@": { version: "4" }
96
- }, g.push(n));
97
- let o = (b = n.project) == null ? void 0 : b.find(
98
- (e) => {
99
- var S;
100
- return !!(e != null && e.component) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === "PhpServers";
106
+ }, v.push(p));
107
+ let o = (C = p.project) == null ? void 0 : C.find(
108
+ (n) => {
109
+ var j;
110
+ return !!(n != null && n.component) && ((j = n == null ? void 0 : n[":@"]) == null ? void 0 : j.name) === "PhpServers";
101
111
  }
102
112
  );
103
113
  o === void 0 && (o = {
104
114
  component: [],
105
115
  ":@": { name: "PhpServers" }
106
- }, n.project === void 0 && (n.project = []), n.project.push(o));
107
- let s = (I = o.component) == null ? void 0 : I.find(
108
- (e) => !!(e != null && e.servers)
116
+ }, p.project === void 0 && (p.project = []), p.project.push(o));
117
+ let i = (L = o.component) == null ? void 0 : L.find(
118
+ (n) => !!(n != null && n.servers)
109
119
  );
110
- s === void 0 && (s = { servers: [] }, o.component === void 0 && (o.component = []), o.component.push(s));
111
- const y = (F = s.servers) == null ? void 0 : F.findIndex(
112
- (e) => {
113
- var S;
114
- return !!(e != null && e.server) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === r;
120
+ i === void 0 && (i = { servers: [] }, o.component === void 0 && (o.component = []), o.component.push(i));
121
+ const r = (T = i.servers) == null ? void 0 : T.findIndex(
122
+ (n) => {
123
+ var j;
124
+ return !!(n != null && n.server) && ((j = n == null ? void 0 : n[":@"]) == null ? void 0 : j.name) === l;
115
125
  }
116
126
  );
117
- (y === void 0 || y < 0) && (s.servers === void 0 && (s.servers = []), s.servers.push(u));
118
- let d = (L = n.project) == null ? void 0 : L.find(
119
- (e) => {
120
- var S;
121
- return !!(e != null && e.component) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === "RunManager";
127
+ (r === void 0 || r < 0) && (i.servers === void 0 && (i.servers = []), i.servers.push(y));
128
+ let e = (_ = p.project) == null ? void 0 : _.find(
129
+ (n) => {
130
+ var j;
131
+ return !!(n != null && n.component) && ((j = n == null ? void 0 : n[":@"]) == null ? void 0 : j.name) === "RunManager";
122
132
  }
123
133
  );
124
- if (d === void 0 && (d = {
134
+ if (e === void 0 && (e = {
125
135
  component: [],
126
136
  ":@": { name: "RunManager" }
127
- }, n.project === void 0 && (n.project = []), n.project.push(d)), (((k = d.component) == null ? void 0 : k.findIndex(
128
- (e) => {
129
- var S;
130
- return !!(e != null && e.configuration) && ((S = e == null ? void 0 : e[":@"]) == null ? void 0 : S.name) === r;
137
+ }, p.project === void 0 && (p.project = []), p.project.push(e)), (((M = e.component) == null ? void 0 : M.findIndex(
138
+ (n) => {
139
+ var j;
140
+ return !!(n != null && n.configuration) && ((j = n == null ? void 0 : n[":@"]) == null ? void 0 : j.name) === l;
131
141
  }
132
142
  )) ?? -1) < 0) {
133
- const e = {
143
+ const n = {
134
144
  configuration: [
135
145
  {
136
146
  method: [],
@@ -138,59 +148,126 @@ function _(c, a) {
138
148
  }
139
149
  ],
140
150
  ":@": {
141
- name: r,
151
+ name: l,
142
152
  type: "PhpRemoteDebugRunConfigurationType",
143
153
  factoryName: "PHP Remote Debug",
144
154
  filter_connections: "FILTER",
145
- server_name: r,
155
+ server_name: l,
146
156
  session_id: t
147
157
  }
148
158
  };
149
- d.component === void 0 && (d.component = []), d.component.push(e);
159
+ e.component === void 0 && (e.component = []), e.component.push(n);
150
160
  }
151
- const C = new $(M).build(g);
161
+ const m = new b(I).build(v);
152
162
  try {
153
- m.parse(C, !0);
163
+ P.parse(m, !0);
154
164
  } catch {
155
165
  throw new Error(
156
166
  "The resulting PhpStorm configuration file is not valid XML."
157
167
  );
158
168
  }
159
- return C;
169
+ return m;
160
170
  }
161
- function B(c, a) {
162
- var u, n;
163
- const { name: r, mappings: p } = a, h = [];
164
- let l = c, t = v.parseTree(l, h, j);
165
- if (t === void 0 || h.length)
171
+ function B(u, f) {
172
+ var p, o, i, r;
173
+ const { pathSkippings: l } = f, d = new F(E), c = (() => {
174
+ try {
175
+ return d.parse(u, !0);
176
+ } catch {
177
+ throw new Error(
178
+ "PhpStorm PHP configuration file is not valid XML."
179
+ );
180
+ }
181
+ })();
182
+ let h = c == null ? void 0 : c.find(
183
+ (e) => !!(e != null && e.project)
184
+ );
185
+ if (h) {
186
+ const e = (p = h[":@"]) == null ? void 0 : p.version;
187
+ if (e === void 0)
188
+ throw new Error(
189
+ 'PhpStorm IDE integration only supports <project version="4"> in php.xml, but the <project> configuration has no version number.'
190
+ );
191
+ if (e !== "4")
192
+ throw new Error(
193
+ `PhpStorm IDE integration only supports <project version="4"> in php.xml, but we found a <project> configuration with version "${e}".`
194
+ );
195
+ }
196
+ h === void 0 && (h = {
197
+ project: [],
198
+ ":@": { version: "4" }
199
+ }, c.push(h));
200
+ let t = (o = h.project) == null ? void 0 : o.find(
201
+ (e) => {
202
+ var s;
203
+ return !!(e != null && e.component) && ((s = e == null ? void 0 : e[":@"]) == null ? void 0 : s.name) === "PhpStepFilterConfiguration";
204
+ }
205
+ );
206
+ t === void 0 && (t = {
207
+ component: [],
208
+ ":@": { name: "PhpStepFilterConfiguration" }
209
+ }, h.project === void 0 && (h.project = []), h.project.push(t));
210
+ let P = (i = t.component) == null ? void 0 : i.find(
211
+ (e) => !!(e != null && e.skipped_files)
212
+ );
213
+ if (P === void 0 && (P = { skipped_files: [] }, t.component === void 0 && (t.component = []), t.component.push(P)), l && l.length)
214
+ for (const e of l) {
215
+ const g = `$PROJECT_DIR$${e.endsWith("/") ? e.slice(0, -1) : e}`;
216
+ ((r = P.skipped_files) == null ? void 0 : r.some(
217
+ (S) => {
218
+ var C;
219
+ return !!(S != null && S.skipped_file) && ((C = S == null ? void 0 : S[":@"]) == null ? void 0 : C.file) === g;
220
+ }
221
+ )) || (P.skipped_files === void 0 && (P.skipped_files = []), P.skipped_files.push({
222
+ skipped_file: [],
223
+ ":@": { file: g }
224
+ }));
225
+ }
226
+ const y = new b(I).build(c);
227
+ try {
228
+ d.parse(y, !0);
229
+ } catch {
230
+ throw new Error(
231
+ "The resulting PhpStorm PHP configuration file is not valid XML."
232
+ );
233
+ }
234
+ return y;
235
+ }
236
+ function O(u, f) {
237
+ var p, o;
238
+ const { name: l, pathMappings: d, pathSkippings: c } = f, h = [];
239
+ let t = u, P = x.parseTree(t, h, k);
240
+ if (P === void 0 || h.length)
166
241
  throw new Error("VS Code configuration file is not valid JSON.");
167
- let m = v.findNodeAtLocation(t, ["configurations"]);
168
- if (m === void 0 || m.children === void 0) {
169
- const o = v.modify(l, ["configurations"], [], {});
170
- l = v.applyEdits(l, o), t = v.parseTree(l, [], j), m = v.findNodeAtLocation(t, [
242
+ let v = x.findNodeAtLocation(P, ["configurations"]);
243
+ if (v === void 0 || v.children === void 0) {
244
+ const i = x.modify(t, ["configurations"], [], {});
245
+ t = x.applyEdits(t, i), P = x.parseTree(t, [], k), v = x.findNodeAtLocation(P, [
171
246
  "configurations"
172
247
  ]);
173
248
  }
174
- const g = (u = m == null ? void 0 : m.children) == null ? void 0 : u.findIndex(
175
- (o) => {
176
- var s;
177
- return ((s = v.findNodeAtLocation(o, ["name"])) == null ? void 0 : s.value) === r;
249
+ const y = (p = v == null ? void 0 : v.children) == null ? void 0 : p.findIndex(
250
+ (i) => {
251
+ var r;
252
+ return ((r = x.findNodeAtLocation(i, ["name"])) == null ? void 0 : r.value) === l;
178
253
  }
179
254
  );
180
- if (g === void 0 || g < 0) {
181
- const o = {
182
- name: r,
255
+ if (y === void 0 || y < 0) {
256
+ const i = {
257
+ name: l,
183
258
  type: "php",
184
259
  request: "launch",
185
260
  port: 9003
186
261
  };
187
- p && p.length && (o.pathMappings = p.reduce((d, i) => (d[i.vfsPath] = `\${workspaceFolder}/${D(
188
- P.relative(a.workspaceDir, i.hostPath)
189
- )}`, d), {}));
190
- const s = ((n = m == null ? void 0 : m.children) == null ? void 0 : n.length) || 0, y = v.modify(
191
- l,
192
- ["configurations", s],
193
- o,
262
+ d && d.length && (i.pathMappings = d.reduce((s, g) => (s[g.vfsPath] = `\${workspaceFolder}/${$(
263
+ w.relative(f.workspaceDir, g.hostPath)
264
+ )}`, s), {})), c && c.length && (i.skipFiles = c.map(
265
+ (s) => s.endsWith("/") ? `${s}**` : s
266
+ ));
267
+ const r = ((o = v == null ? void 0 : v.children) == null ? void 0 : o.length) || 0, e = x.modify(
268
+ t,
269
+ ["configurations", r],
270
+ i,
194
271
  {
195
272
  formattingOptions: {
196
273
  insertSpaces: !0,
@@ -200,141 +277,196 @@ function B(c, a) {
200
277
  }
201
278
  }
202
279
  );
203
- l = N(l, y);
280
+ t = A(t, e);
204
281
  }
205
- return l;
282
+ return t;
206
283
  }
207
- async function U({
208
- name: c,
209
- ides: a,
210
- host: r,
211
- port: p,
212
- cwd: h,
213
- mounts: l,
214
- ideKey: t = O
284
+ async function z({
285
+ name: u,
286
+ ides: f,
287
+ host: l,
288
+ port: d,
289
+ cwd: c,
290
+ mounts: h,
291
+ pathSkippings: t,
292
+ ideKey: P = N
215
293
  }) {
216
- const m = l ? A(h, l) : [], g = {};
217
- if (a.includes("phpstorm")) {
218
- const u = ".idea/workspace.xml", n = P.join(
219
- h,
220
- u
294
+ const v = h ? D(c, h) : [], y = {};
295
+ if (f.includes("phpstorm")) {
296
+ const p = ".idea/workspace.xml", o = w.join(
297
+ c,
298
+ p
221
299
  );
222
- if (!f.existsSync(n)) {
223
- if (f.existsSync(P.dirname(n)))
224
- f.writeFileSync(
225
- n,
300
+ if (!a.existsSync(o)) {
301
+ if (a.existsSync(w.dirname(o)))
302
+ a.writeFileSync(
303
+ o,
226
304
  `<?xml version="1.0" encoding="UTF-8"?>
227
305
  <project version="4">
228
306
  </project>`
229
307
  );
230
- else if (a.length == 1)
308
+ else if (f.length == 1)
231
309
  throw new Error(
232
310
  "PhpStorm IDE integration requested, but no '.idea' directory was found in the current working directory."
233
311
  );
234
312
  }
235
- if (f.existsSync(n)) {
236
- const o = f.readFileSync(n, "utf8"), s = _(o, {
237
- name: c,
238
- host: r,
239
- port: p,
240
- projectDir: h,
241
- mappings: m,
242
- ideKey: t
313
+ if (a.existsSync(o)) {
314
+ const i = a.readFileSync(o, "utf8"), r = X(i, {
315
+ name: u,
316
+ host: l,
317
+ port: d,
318
+ projectDir: c,
319
+ pathMappings: v,
320
+ ideKey: P
243
321
  });
244
- f.writeFileSync(n, s), g.phpstorm = u;
322
+ a.writeFileSync(o, r), y.phpstorm = p;
323
+ }
324
+ if (t && t.length) {
325
+ const i = ".idea/php.xml", r = w.join(
326
+ c,
327
+ i
328
+ );
329
+ if (a.existsSync(r) || a.existsSync(w.dirname(r)) && a.writeFileSync(
330
+ r,
331
+ `<?xml version="1.0" encoding="UTF-8"?>
332
+ <project version="4">
333
+ </project>`
334
+ ), a.existsSync(r)) {
335
+ const e = a.readFileSync(
336
+ r,
337
+ "utf8"
338
+ ), s = B(e, {
339
+ pathSkippings: t
340
+ });
341
+ a.writeFileSync(r, s), y["phpstorm-php"] = i;
342
+ }
245
343
  }
246
344
  }
247
- if (a.includes("vscode")) {
248
- const u = ".vscode/launch.json", n = P.join(
249
- h,
250
- u
345
+ if (f.includes("vscode")) {
346
+ const p = ".vscode/launch.json", o = w.join(
347
+ c,
348
+ p
251
349
  );
252
- if (!f.existsSync(n)) {
253
- if (f.existsSync(P.dirname(n)))
254
- f.writeFileSync(
255
- n,
350
+ if (!a.existsSync(o)) {
351
+ if (a.existsSync(w.dirname(o)))
352
+ a.writeFileSync(
353
+ o,
256
354
  `{
257
355
  "configurations": []
258
356
  }`
259
357
  );
260
- else if (a.length == 1)
358
+ else if (f.length == 1)
261
359
  throw new Error(
262
360
  "VS Code IDE integration requested, but no '.vscode' directory was found in the current working directory."
263
361
  );
264
362
  }
265
- if (f.existsSync(n)) {
266
- const o = f.readFileSync(n, "utf-8"), s = B(o, {
267
- name: c,
268
- workspaceDir: h,
269
- mappings: m
363
+ if (a.existsSync(o)) {
364
+ const i = a.readFileSync(o, "utf-8"), r = O(i, {
365
+ name: u,
366
+ workspaceDir: c,
367
+ pathMappings: v,
368
+ pathSkippings: t
270
369
  });
271
- s !== o && (f.writeFileSync(n, s), g.vscode = u);
370
+ r !== i && (a.writeFileSync(o, r), y.vscode = p);
272
371
  }
273
372
  }
274
- return g;
373
+ return y;
275
374
  }
276
- async function W(c, a) {
277
- var h, l, t, m;
278
- const r = P.join(a, ".idea/workspace.xml");
279
- if (f.existsSync(r)) {
280
- const g = f.readFileSync(r, "utf8"), u = new T(x), n = (() => {
375
+ async function K(u, f) {
376
+ var h, t, P, v, y;
377
+ const l = w.join(f, ".idea/workspace.xml");
378
+ if (a.existsSync(l)) {
379
+ const p = a.readFileSync(l, "utf8"), o = new F(E), i = (() => {
281
380
  try {
282
- return u.parse(g, !0);
381
+ return o.parse(p, !0);
283
382
  } catch {
284
383
  throw new Error(
285
384
  "PhpStorm configuration file is not valid XML."
286
385
  );
287
386
  }
288
- })(), o = n.find(
289
- (i) => !!(i != null && i.project)
290
- ), s = (h = o == null ? void 0 : o.project) == null ? void 0 : h.find(
291
- (i) => {
292
- var w;
293
- return !!(i != null && i.component) && ((w = i == null ? void 0 : i[":@"]) == null ? void 0 : w.name) === "PhpServers";
387
+ })(), r = i.find(
388
+ (m) => !!(m != null && m.project)
389
+ ), e = (h = r == null ? void 0 : r.project) == null ? void 0 : h.find(
390
+ (m) => {
391
+ var S;
392
+ return !!(m != null && m.component) && ((S = m == null ? void 0 : m[":@"]) == null ? void 0 : S.name) === "PhpServers";
294
393
  }
295
- ), y = (l = s == null ? void 0 : s.component) == null ? void 0 : l.find(
296
- (i) => !!(i != null && i.servers)
297
- ), d = (t = y == null ? void 0 : y.servers) == null ? void 0 : t.findIndex(
298
- (i) => {
299
- var w;
300
- return !!(i != null && i.server) && ((w = i == null ? void 0 : i[":@"]) == null ? void 0 : w.name) === c;
394
+ ), s = (t = e == null ? void 0 : e.component) == null ? void 0 : t.find(
395
+ (m) => !!(m != null && m.servers)
396
+ ), g = (P = s == null ? void 0 : s.servers) == null ? void 0 : P.findIndex(
397
+ (m) => {
398
+ var S;
399
+ return !!(m != null && m.server) && ((S = m == null ? void 0 : m[":@"]) == null ? void 0 : S.name) === u;
301
400
  }
302
401
  );
303
- if (d !== void 0 && d >= 0) {
304
- y.servers.splice(d, 1);
305
- const w = new $(M).build(n);
402
+ if (g !== void 0 && g >= 0) {
403
+ s.servers.splice(g, 1);
404
+ const S = new b(I).build(i);
306
405
  try {
307
- u.parse(w, !0);
406
+ o.parse(S, !0);
308
407
  } catch {
309
408
  throw new Error(
310
409
  "The resulting PhpStorm configuration file is not valid XML."
311
410
  );
312
411
  }
313
- w === `<?xml version="1.0" encoding="UTF-8"?>
412
+ S === `<?xml version="1.0" encoding="UTF-8"?>
314
413
  <project version="4">
315
414
  <component name="PhpServers">
316
415
  <servers></servers>
317
416
  </component>
318
- </project>` ? f.unlinkSync(r) : f.writeFileSync(r, w);
417
+ </project>` ? a.unlinkSync(l) : a.writeFileSync(l, S);
319
418
  }
320
419
  }
321
- const p = P.join(a, ".vscode/launch.json");
322
- if (f.existsSync(p)) {
323
- const g = [], u = f.readFileSync(p, "utf-8"), n = v.parseTree(u, g, j);
324
- if (n === void 0 || g.length)
420
+ const d = w.join(f, ".idea/php.xml");
421
+ if (a.existsSync(d)) {
422
+ const p = a.readFileSync(d, "utf8"), o = new F(E), i = (() => {
423
+ try {
424
+ return o.parse(p, !0);
425
+ } catch {
426
+ throw new Error(
427
+ "PhpStorm PHP configuration file is not valid XML."
428
+ );
429
+ }
430
+ })(), r = i.find(
431
+ (s) => !!(s != null && s.project)
432
+ ), e = (v = r == null ? void 0 : r.project) == null ? void 0 : v.findIndex(
433
+ (s) => {
434
+ var g;
435
+ return !!(s != null && s.component) && ((g = s == null ? void 0 : s[":@"]) == null ? void 0 : g.name) === "PhpStepFilterConfiguration";
436
+ }
437
+ );
438
+ if (e !== void 0 && e >= 0) {
439
+ r.project.splice(e, 1);
440
+ const g = new b(I).build(i);
441
+ try {
442
+ o.parse(g, !0);
443
+ } catch {
444
+ throw new Error(
445
+ "The resulting PhpStorm PHP configuration file is not valid XML."
446
+ );
447
+ }
448
+ g === `<?xml version="1.0" encoding="UTF-8"?>
449
+ <project version="4">
450
+ </project>` ? a.unlinkSync(d) : a.writeFileSync(d, g);
451
+ }
452
+ }
453
+ const c = w.join(f, ".vscode/launch.json");
454
+ if (a.existsSync(c)) {
455
+ const p = [], o = a.readFileSync(c, "utf-8"), i = x.parseTree(o, p, k);
456
+ if (i === void 0 || p.length)
325
457
  throw new Error("VS Code configuration file is not valid JSON.");
326
- const o = v.findNodeAtLocation(n, [
458
+ const r = x.findNodeAtLocation(i, [
327
459
  "configurations"
328
- ]), s = (m = o == null ? void 0 : o.children) == null ? void 0 : m.findIndex(
329
- (y) => {
330
- var d;
331
- return ((d = v.findNodeAtLocation(y, ["name"])) == null ? void 0 : d.value) === c;
460
+ ]), e = (y = r == null ? void 0 : r.children) == null ? void 0 : y.findIndex(
461
+ (s) => {
462
+ var g;
463
+ return ((g = x.findNodeAtLocation(s, ["name"])) == null ? void 0 : g.value) === u;
332
464
  }
333
465
  );
334
- if (s !== void 0 && s >= 0) {
335
- const y = v.modify(
336
- u,
337
- ["configurations", s],
466
+ if (e !== void 0 && e >= 0) {
467
+ const s = x.modify(
468
+ o,
469
+ ["configurations", e],
338
470
  void 0,
339
471
  {
340
472
  formattingOptions: {
@@ -344,58 +476,60 @@ async function W(c, a) {
344
476
  `
345
477
  }
346
478
  }
347
- ), d = N(u, y);
348
- d === `{
479
+ ), g = A(o, s);
480
+ g === `{
349
481
  "configurations": []
350
- }` ? f.unlinkSync(p) : f.writeFileSync(p, d);
482
+ }` ? a.unlinkSync(c) : a.writeFileSync(c, g);
351
483
  }
352
484
  }
353
485
  }
354
- function z({
355
- cwd: c,
356
- mounts: a,
357
- pathSkippings: r
486
+ function G({
487
+ cwd: u,
488
+ mounts: f,
489
+ pathSkippings: l
358
490
  }) {
359
- return { pathMappings: c && a ? A(c, a) : void 0, pathSkippings: r };
491
+ return { pathMappings: u && f ? D(u, f) : void 0, pathSkippings: l };
360
492
  }
361
- function N(c, a) {
362
- const r = [], p = v.applyEdits(c, a);
363
- if (r.length = 0, v.parseTree(p, r, j), r.length) {
364
- const h = r.map((t) => ({
365
- message: v.printParseErrorCode(t.error),
493
+ function A(u, f) {
494
+ const l = [], d = x.applyEdits(u, f);
495
+ if (l.length = 0, x.parseTree(d, l, k), l.length) {
496
+ const c = l.map((t) => ({
497
+ message: x.printParseErrorCode(t.error),
366
498
  offset: t.offset,
367
499
  length: t.length,
368
- fragment: p.slice(
500
+ fragment: d.slice(
369
501
  Math.max(0, t.offset - 20),
370
- Math.min(p.length, t.offset + t.length + 10)
502
+ Math.min(d.length, t.offset + t.length + 10)
371
503
  )
372
504
  })).map(
373
505
  (t) => `${t.message} at ${t.offset}:${t.length} (${t.fragment})`
374
- ), l = a.map(
506
+ ), h = f.map(
375
507
  (t) => `At ${t.offset}:${t.length} - (${t.content})`
376
508
  );
377
509
  throw new Error(
378
510
  `VS Code configuration file (.vscode/launch.json) is not valid a JSONC after CLI modifications. This is likely a CLI bug. Please report it at https://github.com/WordPress/wordpress-playground/issues and include the contents of your ".vscode/launch.json" file.
379
511
 
380
- Applied edits: ${l.join(
512
+ Applied edits: ${h.join(
381
513
  `
382
514
  `
383
515
  )}
384
516
 
385
- The errors are: ${h.join(`
517
+ The errors are: ${c.join(`
386
518
  `)}`
387
519
  );
388
520
  }
389
- return p;
521
+ return d;
390
522
  }
391
523
  export {
392
- O as DEFAULT_IDE_KEY,
393
- U as addXdebugIDEConfig,
394
- W as clearXdebugIDEConfig,
395
- q as createTempDirSymlink,
396
- z as makeXdebugConfig,
397
- H as removeTempDirSymlink,
398
- _ as updatePhpStormConfig,
399
- B as updateVSCodeConfig
524
+ N as DEFAULT_IDE_KEY,
525
+ U as DEFAULT_PATH_SKIPPINGS,
526
+ z as addXdebugIDEConfig,
527
+ K as clearXdebugIDEConfig,
528
+ W as createTempDirSymlink,
529
+ G as makeXdebugConfig,
530
+ q as removeTempDirSymlink,
531
+ B as updatePhpStormPHPConfig,
532
+ X as updatePhpStormWorkspaceConfig,
533
+ O as updateVSCodeConfig
400
534
  };
401
535
  //# sourceMappingURL=index.js.map