@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.
- package/dist/index.js +120 -127
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,44 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
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
|
|
12
|
-
return (
|
|
13
|
-
const
|
|
14
|
-
return
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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", (
|
|
31
|
+
}), t.on("exit", (s, a) => {
|
|
37
32
|
this._dead = !0;
|
|
38
|
-
const
|
|
39
|
-
this.emit("died",
|
|
40
|
-
for (const
|
|
41
|
-
|
|
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
|
|
50
|
-
return new Promise((
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 (
|
|
59
|
-
const
|
|
60
|
-
|
|
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
|
|
63
|
-
if (
|
|
64
|
-
throw new Error("expected ready, got " +
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
} catch (
|
|
68
|
-
|
|
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
|
-
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
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,
|
|
89
|
-
this.nextResolvers.push({ resolve: r, reject:
|
|
79
|
+
return new Promise((r, e) => {
|
|
80
|
+
this.nextResolvers.push({ resolve: r, reject: e });
|
|
90
81
|
});
|
|
91
82
|
}
|
|
92
83
|
dispatch(t) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
106
|
-
this.buffer = this.buffer.slice(r + 1),
|
|
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
|
|
122
|
-
this.inflight = null, r.type === "regen.done" ?
|
|
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
|
-
(
|
|
130
|
-
(
|
|
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
|
|
145
|
-
command:
|
|
146
|
-
buildCommand:
|
|
147
|
-
watch:
|
|
148
|
-
debounceMs:
|
|
149
|
-
startupTimeoutMs:
|
|
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
|
|
153
|
-
const
|
|
154
|
-
let
|
|
155
|
-
const
|
|
156
|
-
clearTimeout(
|
|
157
|
-
if (!
|
|
158
|
-
const n = Array.from(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
`[typefinder] regen ${
|
|
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
|
|
165
|
-
process.stderr.write(`[typefinder] ${
|
|
154
|
+
for (const h of d.warnings)
|
|
155
|
+
process.stderr.write(`[typefinder] ${h}
|
|
166
156
|
`);
|
|
167
|
-
for (const
|
|
168
|
-
process.stderr.write(`[typefinder] ${
|
|
157
|
+
for (const h of d.failed)
|
|
158
|
+
process.stderr.write(`[typefinder] ${h.path}: ${h.message}
|
|
169
159
|
`);
|
|
170
|
-
}).catch((
|
|
171
|
-
process.stderr.write(`[typefinder] regen failed: ${
|
|
160
|
+
}).catch((d) => {
|
|
161
|
+
process.stderr.write(`[typefinder] regen failed: ${d.message}
|
|
172
162
|
`);
|
|
173
163
|
});
|
|
174
|
-
},
|
|
164
|
+
}, e);
|
|
175
165
|
};
|
|
176
166
|
return {
|
|
177
167
|
name: "@pentacore/vite-plugin-laravel-typefinder",
|
|
178
168
|
enforce: "pre",
|
|
179
169
|
configResolved(n) {
|
|
180
|
-
|
|
170
|
+
o = n.root, c = n.command === "build";
|
|
181
171
|
},
|
|
182
172
|
async configureServer(n) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
|
192
|
-
|
|
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: ${
|
|
183
|
+
`[typefinder] watcher exited: ${h} — restart the dev server
|
|
195
184
|
`
|
|
196
185
|
);
|
|
197
186
|
}), n.ws.on("typefinder:full-regen", () => {
|
|
198
|
-
|
|
199
|
-
process.stderr.write(`[typefinder] full regen failed: ${
|
|
187
|
+
i && !i.dead && i.regen([]).catch((h) => {
|
|
188
|
+
process.stderr.write(`[typefinder] full regen failed: ${h.message}
|
|
200
189
|
`);
|
|
201
190
|
});
|
|
202
|
-
}),
|
|
191
|
+
}), n.httpServer?.once("close", () => {
|
|
192
|
+
i?.kill();
|
|
193
|
+
}), process.once("exit", () => {
|
|
194
|
+
i?.kill();
|
|
195
|
+
});
|
|
203
196
|
},
|
|
204
197
|
async buildStart() {
|
|
205
|
-
if (
|
|
206
|
-
if (
|
|
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
|
|
205
|
+
await S(t, { cwd: o });
|
|
213
206
|
} catch (n) {
|
|
214
|
-
const
|
|
215
|
-
throw new Error(`[typefinder] build-time generation failed: ${
|
|
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 (
|
|
220
|
-
const n = await
|
|
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
|
-
|
|
221
|
+
c || !i || i.dead || u(n) && (p.add(n), g());
|
|
229
222
|
},
|
|
230
223
|
async closeBundle() {
|
|
231
|
-
|
|
224
|
+
i && !i.dead && await i.kill();
|
|
232
225
|
}
|
|
233
226
|
};
|
|
234
|
-
},
|
|
235
|
-
const
|
|
236
|
-
for (const
|
|
237
|
-
const
|
|
238
|
-
|
|
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
|
|
233
|
+
return t;
|
|
241
234
|
};
|
|
242
235
|
export {
|
|
243
|
-
|
|
244
|
-
|
|
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": "
|
|
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.
|
|
44
|
+
"eslint": "^10.3.0",
|
|
45
45
|
"typescript": "^6.0.3",
|
|
46
|
-
"typescript-eslint": "^8.
|
|
47
|
-
"vite": "^
|
|
48
|
-
"vite-plugin-dts": "^
|
|
49
|
-
"vitest": "^4.1.
|
|
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"
|