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

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