@pentacore/vite-plugin-laravel-typefinder 4.2.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +120 -127
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,44 +1,39 @@
1
- var $ = Object.defineProperty;
2
- var v = (l, s, t) => s in l ? $(l, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[s] = t;
3
- var p = (l, s, t) => v(l, typeof s != "symbol" ? s + "" : s, t);
4
- import { spawn as E, exec as S } from "node:child_process";
5
- import { promisify as b } from "node:util";
6
- import T from "picomatch";
7
- import { EventEmitter as R } from "node:events";
8
- const k = (l) => {
9
- if (l.length === 0)
1
+ import { spawn as w, exec as y } from "node:child_process";
2
+ import { promisify as x } from "node:util";
3
+ import $ from "picomatch";
4
+ import { EventEmitter as v } from "node:events";
5
+ const E = (f) => {
6
+ if (f.length === 0)
10
7
  return () => !1;
11
- const s = l.map((r) => `${r.replace(/\\/g, "/").replace(/\/$/, "")}/**/*.php`), t = T(s, { dot: !0 });
12
- return (r) => {
13
- const i = r.replace(/\\/g, "/");
14
- return t(i);
8
+ const t = f.map((e) => `${e.replace(/\\/g, "/").replace(/\/$/, "")}/**/*.php`), r = $(t, { dot: !0 });
9
+ return (e) => {
10
+ const s = e.replace(/\\/g, "/");
11
+ return r(s);
15
12
  };
16
13
  };
17
- class y extends R {
18
- constructor(t, r, i) {
19
- var a, d;
20
- super();
21
- p(this, "handshake");
22
- p(this, "child");
23
- p(this, "killTimeoutMs");
24
- p(this, "buffer", "");
25
- p(this, "inflight", null);
26
- p(this, "nextBatch", null);
27
- p(this, "nextResolvers", []);
28
- p(this, "idCounter", 0);
29
- p(this, "_dead", !1);
30
- this.child = t, this.handshake = r, this.killTimeoutMs = i, (a = t.stdout) == null || a.on("data", (e) => {
31
- this.onStdout(typeof e == "string" ? e : e.toString("utf8"));
32
- }), (d = t.stderr) == null || d.on("data", (e) => {
33
- const c = (typeof e == "string" ? e : e.toString("utf8")).trimEnd();
34
- c !== "" && process.stderr.write(`[typefinder] ${c}
14
+ class m extends v {
15
+ handshake;
16
+ child;
17
+ killTimeoutMs;
18
+ buffer = "";
19
+ inflight = null;
20
+ nextBatch = null;
21
+ nextResolvers = [];
22
+ idCounter = 0;
23
+ _dead = !1;
24
+ constructor(t, r, e) {
25
+ super(), this.child = t, this.handshake = r, this.killTimeoutMs = e, t.stdout?.on("data", (s) => {
26
+ this.onStdout(typeof s == "string" ? s : s.toString("utf8"));
27
+ }), t.stderr?.on("data", (s) => {
28
+ const a = (typeof s == "string" ? s : s.toString("utf8")).trimEnd();
29
+ a !== "" && process.stderr.write(`[typefinder] ${a}
35
30
  `);
36
- }), t.on("exit", (e, c) => {
31
+ }), t.on("exit", (s, a) => {
37
32
  this._dead = !0;
38
- const f = c ? `signal ${c}` : `exit code ${e ?? "null"}`;
39
- this.emit("died", f), this.inflight && (this.inflight.reject(new Error(`watcher died (${f})`)), this.inflight = null);
40
- for (const m of this.nextResolvers)
41
- m.reject(new Error(`watcher died (${f})`));
33
+ const o = a ? `signal ${a}` : `exit code ${s ?? "null"}`;
34
+ this.emit("died", o), this.inflight && (this.inflight.reject(new Error(`watcher died (${o})`)), this.inflight = null);
35
+ for (const i of this.nextResolvers)
36
+ i.reject(new Error(`watcher died (${o})`));
42
37
  this.nextResolvers = [], this.nextBatch = null;
43
38
  });
44
39
  }
@@ -46,35 +41,31 @@ class y extends R {
46
41
  return this._dead;
47
42
  }
48
43
  static async spawn(t) {
49
- const i = (t.spawnFn ?? ((a, d, e) => E(a, d, e)))(t.command, [], { cwd: t.cwd, shell: !0 });
50
- return new Promise((a, d) => {
51
- var w;
52
- let e = "";
53
- const c = (h) => {
54
- var u;
55
- e += typeof h == "string" ? h : h.toString("utf8");
56
- const n = e.indexOf(`
44
+ const e = (t.spawnFn ?? ((s, a, o) => w(s, a, o)))(t.command, [], { cwd: t.cwd, shell: !0 });
45
+ return new Promise((s, a) => {
46
+ let o = "";
47
+ const i = (l) => {
48
+ o += typeof l == "string" ? l : l.toString("utf8");
49
+ const c = o.indexOf(`
57
50
  `);
58
- if (n === -1) return;
59
- const o = e.slice(0, n);
60
- e = e.slice(n + 1), clearTimeout(m), (u = i.stdout) == null || u.off("data", c), i.off("exit", f);
51
+ if (c === -1) return;
52
+ const g = o.slice(0, c);
53
+ o = o.slice(c + 1), clearTimeout(p), e.stdout?.off("data", i), e.off("exit", u);
61
54
  try {
62
- const g = JSON.parse(o);
63
- if (g.type !== "ready")
64
- throw new Error("expected ready, got " + g.type);
65
- const x = new y(i, g, t.killTimeoutMs ?? 2e3);
66
- e.length > 0 && x.onStdout(e), a(x);
67
- } catch (g) {
68
- i.kill("SIGTERM"), d(new Error(`malformed handshake: ${g.message}`));
55
+ const n = JSON.parse(g);
56
+ if (n.type !== "ready")
57
+ throw new Error("expected ready, got " + n.type);
58
+ const d = new m(e, n, t.killTimeoutMs ?? 2e3);
59
+ o.length > 0 && d.onStdout(o), s(d);
60
+ } catch (n) {
61
+ e.kill("SIGTERM"), a(new Error(`malformed handshake: ${n.message}`));
69
62
  }
70
- }, f = (h, n) => {
71
- var o;
72
- clearTimeout(m), (o = i.stdout) == null || o.off("data", c), d(new Error(`watcher exited before handshake (code=${h}, signal=${n})`));
73
- }, m = setTimeout(() => {
74
- var h;
75
- (h = i.stdout) == null || h.off("data", c), i.off("exit", f), i.kill("SIGTERM"), d(new Error(`watcher startup timeout after ${t.startupTimeoutMs}ms`));
63
+ }, u = (l, c) => {
64
+ clearTimeout(p), e.stdout?.off("data", i), a(new Error(`watcher exited before handshake (code=${l}, signal=${c})`));
65
+ }, p = setTimeout(() => {
66
+ e.stdout?.off("data", i), e.off("exit", u), e.kill("SIGTERM"), a(new Error(`watcher startup timeout after ${t.startupTimeoutMs}ms`));
76
67
  }, t.startupTimeoutMs);
77
- (w = i.stdout) == null || w.on("data", c), i.on("exit", f);
68
+ e.stdout?.on("data", i), e.on("exit", u);
78
69
  });
79
70
  }
80
71
  async regen(t) {
@@ -85,16 +76,15 @@ class y extends R {
85
76
  this.nextBatch || (this.nextBatch = /* @__PURE__ */ new Set());
86
77
  for (const r of t)
87
78
  this.nextBatch.add(r);
88
- return new Promise((r, i) => {
89
- this.nextResolvers.push({ resolve: r, reject: i });
79
+ return new Promise((r, e) => {
80
+ this.nextResolvers.push({ resolve: r, reject: e });
90
81
  });
91
82
  }
92
83
  dispatch(t) {
93
- var a;
94
- const r = `r${++this.idCounter}`, i = { type: "regen", id: r, paths: t };
95
- return (a = this.child.stdin) == null || a.write(JSON.stringify(i) + `
96
- `), new Promise((d, e) => {
97
- this.inflight = { id: r, resolve: d, reject: e };
84
+ const r = `r${++this.idCounter}`, e = { type: "regen", id: r, paths: t };
85
+ return this.child.stdin?.write(JSON.stringify(e) + `
86
+ `), new Promise((s, a) => {
87
+ this.inflight = { id: r, resolve: s, reject: a };
98
88
  });
99
89
  }
100
90
  onStdout(t) {
@@ -102,8 +92,8 @@ class y extends R {
102
92
  let r;
103
93
  for (; (r = this.buffer.indexOf(`
104
94
  `)) !== -1; ) {
105
- const i = this.buffer.slice(0, r);
106
- this.buffer = this.buffer.slice(r + 1), i.trim() !== "" && this.handleLine(i);
95
+ const e = this.buffer.slice(0, r);
96
+ this.buffer = this.buffer.slice(r + 1), e.trim() !== "" && this.handleLine(e);
107
97
  }
108
98
  }
109
99
  handleLine(t) {
@@ -118,16 +108,16 @@ class y extends R {
118
108
  if (r.type === "regen.done" || r.type === "regen.error") {
119
109
  if (!this.inflight || "id" in r && this.inflight.id !== r.id)
120
110
  return;
121
- const i = this.inflight;
122
- this.inflight = null, r.type === "regen.done" ? i.resolve(r) : i.reject(new Error(r.message)), this.drainQueued();
111
+ const e = this.inflight;
112
+ this.inflight = null, r.type === "regen.done" ? e.resolve(r) : e.reject(new Error(r.message)), this.drainQueued();
123
113
  }
124
114
  }
125
115
  drainQueued() {
126
116
  if (!this.nextBatch || this.nextResolvers.length === 0) return;
127
117
  const t = Array.from(this.nextBatch), r = [...this.nextResolvers];
128
118
  this.nextBatch = null, this.nextResolvers = [], this.dispatch(t).then(
129
- (i) => r.forEach((a) => a.resolve(i)),
130
- (i) => r.forEach((a) => a.reject(i))
119
+ (e) => r.forEach((s) => s.resolve(e)),
120
+ (e) => r.forEach((s) => s.reject(e))
131
121
  );
132
122
  }
133
123
  async kill() {
@@ -141,83 +131,86 @@ class y extends R {
141
131
  });
142
132
  }
143
133
  }
144
- const M = b(S), G = ({
145
- command: l = "php artisan typefinder:watch",
146
- buildCommand: s = "php artisan typefinder:generate --json",
147
- watch: t,
148
- debounceMs: r = 100,
149
- startupTimeoutMs: i = 1e4,
134
+ const S = x(y), B = ({
135
+ command: f = "php artisan typefinder:watch",
136
+ buildCommand: t = "php artisan typefinder:generate --json",
137
+ watch: r,
138
+ debounceMs: e = 100,
139
+ startupTimeoutMs: s = 1e4,
150
140
  killTimeoutMs: a = 2e3
151
141
  } = {}) => {
152
- let d = process.cwd(), e = null, c = () => !1;
153
- const f = /* @__PURE__ */ new Set();
154
- let m, w = !1;
155
- const h = () => {
156
- clearTimeout(m), m = setTimeout(() => {
157
- if (!e || e.dead) return;
158
- const n = Array.from(f);
159
- f.clear(), n.length !== 0 && e.regen(n).then((o) => {
160
- o.changed.length > 0 && process.stderr.write(
161
- `[typefinder] regen ${o.changed.length} file(s) in ${o.duration_ms}ms
142
+ let o = process.cwd(), i = null, u = () => !1;
143
+ const p = /* @__PURE__ */ new Set();
144
+ let l, c = !1;
145
+ const g = () => {
146
+ clearTimeout(l), l = setTimeout(() => {
147
+ if (!i || i.dead) return;
148
+ const n = Array.from(p);
149
+ p.clear(), n.length !== 0 && i.regen(n).then((d) => {
150
+ d.changed.length > 0 && process.stderr.write(
151
+ `[typefinder] regen ${d.changed.length} file(s) in ${d.duration_ms}ms
162
152
  `
163
153
  );
164
- for (const u of o.warnings)
165
- process.stderr.write(`[typefinder] ${u}
154
+ for (const h of d.warnings)
155
+ process.stderr.write(`[typefinder] ${h}
166
156
  `);
167
- for (const u of o.failed)
168
- process.stderr.write(`[typefinder] ${u.path}: ${u.message}
157
+ for (const h of d.failed)
158
+ process.stderr.write(`[typefinder] ${h.path}: ${h.message}
169
159
  `);
170
- }).catch((o) => {
171
- process.stderr.write(`[typefinder] regen failed: ${o.message}
160
+ }).catch((d) => {
161
+ process.stderr.write(`[typefinder] regen failed: ${d.message}
172
162
  `);
173
163
  });
174
- }, r);
164
+ }, e);
175
165
  };
176
166
  return {
177
167
  name: "@pentacore/vite-plugin-laravel-typefinder",
178
168
  enforce: "pre",
179
169
  configResolved(n) {
180
- d = n.root, w = n.command === "build";
170
+ o = n.root, c = n.command === "build";
181
171
  },
182
172
  async configureServer(n) {
183
- var u;
184
- if (w) return;
185
- e = await y.spawn({
186
- command: l,
187
- cwd: d,
188
- startupTimeoutMs: i,
173
+ if (c) return;
174
+ i = await m.spawn({
175
+ command: f,
176
+ cwd: o,
177
+ startupTimeoutMs: s,
189
178
  killTimeoutMs: a
190
179
  });
191
- const o = t ?? B(e.handshake.categories);
192
- c = k(o), e.on("died", (g) => {
180
+ const d = r ?? b(i.handshake.categories);
181
+ u = E(d), i.on("died", (h) => {
193
182
  process.stderr.write(
194
- `[typefinder] watcher exited: ${g} — restart the dev server
183
+ `[typefinder] watcher exited: ${h} — restart the dev server
195
184
  `
196
185
  );
197
186
  }), n.ws.on("typefinder:full-regen", () => {
198
- e && !e.dead && e.regen([]).catch((g) => {
199
- process.stderr.write(`[typefinder] full regen failed: ${g.message}
187
+ i && !i.dead && i.regen([]).catch((h) => {
188
+ process.stderr.write(`[typefinder] full regen failed: ${h.message}
200
189
  `);
201
190
  });
202
- }), (u = n.httpServer) == null || u.once("close", () => void (e == null ? void 0 : e.kill())), process.once("exit", () => void (e == null ? void 0 : e.kill()));
191
+ }), n.httpServer?.once("close", () => {
192
+ i?.kill();
193
+ }), process.once("exit", () => {
194
+ i?.kill();
195
+ });
203
196
  },
204
197
  async buildStart() {
205
- if (w) {
206
- if (s === !1) {
198
+ if (c) {
199
+ if (t === !1) {
207
200
  process.stderr.write(`[typefinder] build-time generation disabled
208
201
  `);
209
202
  return;
210
203
  }
211
204
  try {
212
- await M(s, { cwd: d });
205
+ await S(t, { cwd: o });
213
206
  } catch (n) {
214
- const o = n instanceof Error ? n.message : String(n);
215
- throw new Error(`[typefinder] build-time generation failed: ${o}`, { cause: n });
207
+ const d = n instanceof Error ? n.message : String(n);
208
+ throw new Error(`[typefinder] build-time generation failed: ${d}`, { cause: n });
216
209
  }
217
210
  return;
218
211
  }
219
- if (e && !e.dead) {
220
- const n = await e.regen([]);
212
+ if (i && !i.dead) {
213
+ const n = await i.regen([]);
221
214
  n.changed.length > 0 && process.stderr.write(
222
215
  `[typefinder] initial regen: ${n.changed.length} file(s) in ${n.duration_ms}ms
223
216
  `
@@ -225,21 +218,21 @@ const M = b(S), G = ({
225
218
  }
226
219
  },
227
220
  handleHotUpdate({ file: n }) {
228
- w || !e || e.dead || c(n) && (f.add(n), h());
221
+ c || !i || i.dead || u(n) && (p.add(n), g());
229
222
  },
230
223
  async closeBundle() {
231
- e && !e.dead && await e.kill();
224
+ i && !i.dead && await i.kill();
232
225
  }
233
226
  };
234
- }, B = (l) => {
235
- const s = [];
236
- for (const t of Object.keys(l)) {
237
- const r = l[t];
238
- r.enabled && s.push(...r.paths);
227
+ }, b = (f) => {
228
+ const t = [];
229
+ for (const r of Object.keys(f)) {
230
+ const e = f[r];
231
+ e.enabled && t.push(...e.paths);
239
232
  }
240
- return s;
233
+ return t;
241
234
  };
242
235
  export {
243
- G as default,
244
- G as typefinder
236
+ B as default,
237
+ B as typefinder
245
238
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pentacore/vite-plugin-laravel-typefinder",
3
- "version": "4.2.2",
3
+ "version": "5.0.0",
4
4
  "description": "Vite plugin for Laravel Typefinder — auto-generate TypeScript types from Models, Enums, Casts, and Requests.",
5
5
  "keywords": [
6
6
  "vite",
@@ -41,12 +41,12 @@
41
41
  "@types/node": "^24.12.2",
42
42
  "@types/picomatch": "^4.0.3",
43
43
  "@vitest/coverage-v8": "^4.1.4",
44
- "eslint": "^10.2.0",
44
+ "eslint": "^10.3.0",
45
45
  "typescript": "^6.0.3",
46
- "typescript-eslint": "^8.58.2",
47
- "vite": "^6.4.2",
48
- "vite-plugin-dts": "^4.5.4",
49
- "vitest": "^4.1.4"
46
+ "typescript-eslint": "^8.63.0",
47
+ "vite": "^7.3.6",
48
+ "vite-plugin-dts": "^5.0.3",
49
+ "vitest": "^4.1.10"
50
50
  },
51
51
  "files": [
52
52
  "dist"