@php-wasm/cli-util 3.1.21 → 3.1.22

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