@pentacore/vite-plugin-laravel-typefinder 8.4.2 → 8.6.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/README.md +15 -2
- package/dist/index.js +99 -60
- package/dist/vite-plugin-typefinder.d.ts.map +1 -1
- package/dist/vue.d.ts +8 -0
- package/dist/vue.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,7 +61,8 @@ typefinder({
|
|
|
61
61
|
command: 'php artisan typefinder:watch',
|
|
62
62
|
|
|
63
63
|
// Shell command used in `vite build` (one-shot, no watcher).
|
|
64
|
-
// Set to `false` to skip generation entirely in build mode
|
|
64
|
+
// Set to `false` to skip generation entirely in build mode
|
|
65
|
+
// (the TYPEFINDER_SKIP_BUILD environment variable does the same).
|
|
65
66
|
buildCommand: 'php artisan typefinder:generate --json',
|
|
66
67
|
|
|
67
68
|
// Override the paths the plugin watches. When unset (the default),
|
|
@@ -133,9 +134,21 @@ The watched paths are read from the watcher's startup handshake, which mirrors y
|
|
|
133
134
|
|
|
134
135
|
Creating, editing or deleting a migration triggers a full regeneration. The schema itself changes only when the migration runs, and the watcher notices that on the next regeneration: after `php artisan migrate`, save any watched file (or send the `typefinder:full-regen` event) to pick up the new columns.
|
|
135
136
|
|
|
137
|
+
**Vue:** Vue's SFC compiler caches the types it resolves for `defineProps<PageProps['Users/Show']>()`, and the generated files are not in Vite's module graph, so nothing would tell it they changed: new props would compile to no props until the dev server restarts. When the project has `vue` installed, the plugin clears that cache for every file a regeneration changed, invalidates the `.vue` modules already compiled and reloads the page. Without Vue this does nothing.
|
|
138
|
+
|
|
136
139
|
Warnings and per-file failures of every regeneration, the initial one included, are written to stderr. A regeneration that gets no answer within `regenTimeoutMs` is reported as failed and the next one is sent.
|
|
137
140
|
|
|
138
|
-
**Production (`vite build`):** No watcher. The plugin runs `typefinder:generate --json` once in `buildStart`, prints its warnings, and fails the build on non-zero exit with the generator's error. Set `buildCommand: false` to skip generation entirely
|
|
141
|
+
**Production (`vite build`):** No watcher. The plugin runs `typefinder:generate --json` once in `buildStart`, prints its warnings, and fails the build on non-zero exit with the generator's error. Set `buildCommand: false`, or the `TYPEFINDER_SKIP_BUILD` environment variable, to skip generation entirely.
|
|
142
|
+
|
|
143
|
+
### Builds without a database (Docker, CI)
|
|
144
|
+
|
|
145
|
+
Generating reads the database schema, so a build without a database (a Docker image build, a frontend-only CI job) cannot run it. Commit the generated types and skip build-time generation there: set `TYPEFINDER_SKIP_BUILD` to any value except empty, `0` or `false`, and the plugin uses the committed files as they are.
|
|
146
|
+
|
|
147
|
+
```dockerfile
|
|
148
|
+
RUN npm ci && TYPEFINDER_SKIP_BUILD=1 npm run build
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Keep a check that the committed types are current where the database is available, e.g. `php artisan typefinder:generate --check` in the test job.
|
|
139
152
|
|
|
140
153
|
**Shutdown:** The watcher is killed on `closeBundle` and on process exit. A PHP fatal error or out-of-memory while regenerating ends only the worker of that request: the plugin logs the error and the watcher keeps running. If the watcher itself dies mid-session, the plugin logs the error and stops regenerating — restart the dev server to recover.
|
|
141
154
|
|
package/dist/index.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
import { exec as e, spawn as t } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { EventEmitter as
|
|
6
|
-
//
|
|
7
|
-
var
|
|
2
|
+
import { basename as n, dirname as r, isAbsolute as i, join as a, resolve as o } from "node:path";
|
|
3
|
+
import { promisify as s } from "node:util";
|
|
4
|
+
import { realpathSync as c } from "node:fs";
|
|
5
|
+
import { EventEmitter as l } from "node:events";
|
|
6
|
+
// \0rolldown/runtime.js
|
|
7
|
+
var u = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), d = (e) => {
|
|
8
8
|
let t = e.replace(/\\/g, "/"), n = t.length;
|
|
9
9
|
for (; n > 0 && t[n - 1] === "/";) n--;
|
|
10
10
|
return t.slice(0, n);
|
|
11
|
-
},
|
|
12
|
-
let t = e.map(
|
|
11
|
+
}, f = (e) => {
|
|
12
|
+
let t = e.map(d).filter((e) => e !== "").map((e) => `${e}/`);
|
|
13
13
|
return t.length === 0 ? () => !1 : (e) => {
|
|
14
14
|
let n = e.replace(/\\/g, "/");
|
|
15
15
|
return n.endsWith(".php") ? t.some((e) => n.startsWith(e)) : !1;
|
|
16
16
|
};
|
|
17
|
-
},
|
|
18
|
-
let t = [],
|
|
17
|
+
}, p = (e) => {
|
|
18
|
+
let t = [], i = e;
|
|
19
19
|
for (;;) try {
|
|
20
|
-
let e =
|
|
20
|
+
let e = d(c.native(i));
|
|
21
21
|
return t.length === 0 ? e : `${e}/${t.reverse().join("/")}`;
|
|
22
22
|
} catch {
|
|
23
|
-
let
|
|
24
|
-
if (
|
|
25
|
-
t.push(i
|
|
23
|
+
let a = r(i);
|
|
24
|
+
if (a === i) return d(e);
|
|
25
|
+
t.push(n(i)), i = a;
|
|
26
26
|
}
|
|
27
|
-
},
|
|
27
|
+
}, m = (e, t, n) => e === t ? n : e.startsWith(`${t}/`) ? n + e.slice(t.length) : null, h = class {
|
|
28
28
|
entries;
|
|
29
29
|
constructor(e = {}) {
|
|
30
30
|
this.entries = Object.entries(e).map(([e, t]) => ({
|
|
31
|
-
remote:
|
|
32
|
-
local:
|
|
31
|
+
remote: d(e),
|
|
32
|
+
local: p(t)
|
|
33
33
|
}));
|
|
34
34
|
}
|
|
35
35
|
toHost(e) {
|
|
36
|
-
return this.translate(
|
|
36
|
+
return this.translate(d(e), "remote", "local");
|
|
37
37
|
}
|
|
38
38
|
toWatcher(e) {
|
|
39
|
-
return this.translate(
|
|
39
|
+
return this.translate(d(e), "local", "remote");
|
|
40
40
|
}
|
|
41
41
|
translate(e, t, n) {
|
|
42
42
|
let r = [...this.entries].sort((e, n) => n[t].length - e[t].length);
|
|
43
43
|
for (let i of r) {
|
|
44
|
-
let r =
|
|
44
|
+
let r = m(e, i[t], i[n]);
|
|
45
45
|
if (r !== null) return r;
|
|
46
46
|
}
|
|
47
47
|
return e;
|
|
48
48
|
}
|
|
49
|
-
},
|
|
49
|
+
}, g = class e extends l {
|
|
50
50
|
handshake;
|
|
51
51
|
child;
|
|
52
52
|
killTimeoutMs;
|
|
@@ -173,13 +173,25 @@ var s = (e) => {
|
|
|
173
173
|
}), this.child.kill("SIGTERM");
|
|
174
174
|
});
|
|
175
175
|
}
|
|
176
|
-
},
|
|
176
|
+
}, _ = (/* @__PURE__ */ u(((e, t) => {
|
|
177
|
+
t.exports = {};
|
|
178
|
+
})))(), v = (e) => {
|
|
179
|
+
try {
|
|
180
|
+
let t = (0, _.createRequire)(a(e, "package.json"))("vue/compiler-sfc").invalidateTypeCache;
|
|
181
|
+
return typeof t == "function" ? (e) => void t(e) : null;
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}, y = s(e), b = () => {
|
|
186
|
+
let e = process.env.TYPEFINDER_SKIP_BUILD?.trim().toLowerCase();
|
|
187
|
+
return e !== void 0 && e !== "" && e !== "0" && e !== "false";
|
|
188
|
+
}, x = (e) => {
|
|
177
189
|
process.stderr.write(`[typefinder] ${e}\n`);
|
|
178
|
-
},
|
|
179
|
-
e.changed.length > 0 &&
|
|
180
|
-
for (let t of e.warnings)
|
|
181
|
-
for (let t of e.failed)
|
|
182
|
-
},
|
|
190
|
+
}, S = (e, t) => {
|
|
191
|
+
e.changed.length > 0 && x(`${t} ${e.changed.length} file(s) in ${e.duration_ms}ms`);
|
|
192
|
+
for (let t of e.warnings) x(t);
|
|
193
|
+
for (let t of e.failed) x(`${t.path}: ${t.message}`);
|
|
194
|
+
}, C = (e) => {
|
|
183
195
|
if (typeof e != "string") return null;
|
|
184
196
|
let t = e.split("\n").map((e) => e.trim()).filter((e) => e !== "");
|
|
185
197
|
for (let e = t.length - 1; e >= 0; e--) try {
|
|
@@ -187,64 +199,91 @@ var s = (e) => {
|
|
|
187
199
|
if (typeof n == "object" && n && "success" in n) return n;
|
|
188
200
|
} catch {}
|
|
189
201
|
return null;
|
|
190
|
-
},
|
|
191
|
-
let
|
|
192
|
-
clearTimeout(
|
|
193
|
-
if (!
|
|
194
|
-
let e =
|
|
195
|
-
|
|
196
|
-
|
|
202
|
+
}, w = ({ command: e = "php artisan typefinder:watch", buildCommand: t = "php artisan typefinder:generate --json", watch: n, debounceMs: r = 100, startupTimeoutMs: a = 1e4, killTimeoutMs: s = 2e3, regenTimeoutMs: c = 12e4, pathMap: l, migrations: u } = {}) => {
|
|
203
|
+
let d = process.cwd(), m = null, _ = () => !1, w = () => !1, D = !1, O = new h(), k = /* @__PURE__ */ new Set(), A, j = !1, M = () => {}, N = () => {
|
|
204
|
+
clearTimeout(A), A = setTimeout(() => {
|
|
205
|
+
if (!m || m.dead) return;
|
|
206
|
+
let e = D ? [] : Array.from(k), t = D ? "full regen" : "regen";
|
|
207
|
+
k.clear(), D = !1, m.regen(e).then((e) => {
|
|
208
|
+
S(e, t), M(e);
|
|
209
|
+
}).catch((e) => {
|
|
210
|
+
x(`regen failed: ${e.message}`);
|
|
197
211
|
});
|
|
198
212
|
}, r);
|
|
199
|
-
},
|
|
200
|
-
if (
|
|
201
|
-
let t =
|
|
202
|
-
|
|
213
|
+
}, P = (e) => {
|
|
214
|
+
if (j || !m || m.dead) return;
|
|
215
|
+
let t = p(e);
|
|
216
|
+
w(t) ? (D = !0, N()) : _(t) && (k.add(O.toWatcher(t)), N());
|
|
203
217
|
};
|
|
204
218
|
return {
|
|
205
219
|
name: "@pentacore/vite-plugin-laravel-typefinder",
|
|
206
220
|
enforce: "pre",
|
|
207
221
|
configResolved(e) {
|
|
208
|
-
|
|
222
|
+
d = e.root, j = e.command === "build";
|
|
209
223
|
},
|
|
210
224
|
async configureServer(t) {
|
|
211
|
-
|
|
225
|
+
if (j) return;
|
|
226
|
+
O = new h(l), m = await g.spawn({
|
|
212
227
|
command: e,
|
|
213
|
-
cwd:
|
|
214
|
-
startupTimeoutMs:
|
|
215
|
-
killTimeoutMs:
|
|
216
|
-
regenTimeoutMs:
|
|
217
|
-
}),
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
228
|
+
cwd: d,
|
|
229
|
+
startupTimeoutMs: a,
|
|
230
|
+
killTimeoutMs: s,
|
|
231
|
+
regenTimeoutMs: c
|
|
232
|
+
}), _ = f((n ?? E(m.handshake.categories).map((e) => O.toHost(e))).map(p)), w = f((u === !1 ? [] : u ?? [`${d}/database/migrations`]).map(p));
|
|
233
|
+
let r = O.toHost(m.handshake.output_path);
|
|
234
|
+
M = T(t, v(d), i(r) ? r : o(d, r)), m.on("died", (e) => {
|
|
235
|
+
x(`watcher exited: ${e} — restart the dev server`);
|
|
236
|
+
}), t.watcher.on("add", P), t.watcher.on("change", P), t.watcher.on("unlink", P), t.ws.on("typefinder:full-regen", () => {
|
|
237
|
+
m && !m.dead && m.regen([]).then((e) => {
|
|
238
|
+
S(e, "full regen"), M(e);
|
|
239
|
+
}).catch((e) => {
|
|
240
|
+
x(`full regen failed: ${e.message}`);
|
|
222
241
|
});
|
|
223
|
-
}), t.httpServer?.once("close", () => void
|
|
242
|
+
}), t.httpServer?.once("close", () => void m?.kill()), process.once("exit", () => void m?.kill());
|
|
224
243
|
},
|
|
225
244
|
async buildStart() {
|
|
226
|
-
if (
|
|
245
|
+
if (j) {
|
|
227
246
|
if (t === !1) {
|
|
228
|
-
|
|
247
|
+
x("build-time generation disabled");
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
if (b()) {
|
|
251
|
+
x("build-time generation skipped: TYPEFINDER_SKIP_BUILD is set");
|
|
229
252
|
return;
|
|
230
253
|
}
|
|
231
254
|
let e;
|
|
232
255
|
try {
|
|
233
|
-
({stdout: e} = await
|
|
256
|
+
({stdout: e} = await y(t, { cwd: d }));
|
|
234
257
|
} catch (e) {
|
|
235
|
-
let t =
|
|
236
|
-
for (let e of t?.warnings ?? [])
|
|
258
|
+
let t = C(e.stdout);
|
|
259
|
+
for (let e of t?.warnings ?? []) x(e);
|
|
237
260
|
let n = t?.errors ?? [], r = n.length > 0 ? n.join("\n") : e instanceof Error ? e.message : String(e);
|
|
238
261
|
throw Error(`[typefinder] build-time generation failed: ${r}`, { cause: e });
|
|
239
262
|
}
|
|
240
|
-
for (let t of
|
|
241
|
-
} else
|
|
263
|
+
for (let t of C(e)?.warnings ?? []) x(t);
|
|
264
|
+
} else if (m && !m.dead) {
|
|
265
|
+
let e = await m.regen([]);
|
|
266
|
+
S(e, "initial regen:"), M(e);
|
|
267
|
+
}
|
|
242
268
|
},
|
|
243
269
|
async closeBundle() {
|
|
244
|
-
|
|
270
|
+
m && !m.dead && await m.kill();
|
|
245
271
|
}
|
|
246
272
|
};
|
|
247
|
-
},
|
|
273
|
+
}, T = (e, t, n) => t === null ? () => {} : (r) => {
|
|
274
|
+
if (r.changed.length === 0) return;
|
|
275
|
+
for (let e of r.changed) {
|
|
276
|
+
let r = a(n, e);
|
|
277
|
+
t(r);
|
|
278
|
+
let i = p(r);
|
|
279
|
+
i !== r && t(i);
|
|
280
|
+
}
|
|
281
|
+
let i = [...e.moduleGraph.idToModuleMap.values()].filter((e) => e.file?.endsWith(".vue"));
|
|
282
|
+
if (i.length !== 0) {
|
|
283
|
+
for (let t of i) e.moduleGraph.invalidateModule(t);
|
|
284
|
+
e.ws.send({ type: "full-reload" });
|
|
285
|
+
}
|
|
286
|
+
}, E = (e) => {
|
|
248
287
|
let t = [];
|
|
249
288
|
for (let n of Object.keys(e)) {
|
|
250
289
|
let r = e[n];
|
|
@@ -252,4 +291,4 @@ var s = (e) => {
|
|
|
252
291
|
}
|
|
253
292
|
return t;
|
|
254
293
|
};
|
|
255
|
-
export {
|
|
294
|
+
export { w as default, w as typefinder };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-typefinder.d.ts","sourceRoot":"","sources":["../src/vite-plugin-typefinder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite-plugin-typefinder.d.ts","sourceRoot":"","sources":["../src/vite-plugin-typefinder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAiC,MAAM,MAAM,CAAC;AASlE,MAAM,WAAW,iBAAiB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yFAAyF;IACzF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;CACjC;AAsDD,eAAO,MAAM,UAAU,GAAI,sHAUxB,iBAAsB,KAAG,MA4J3B,CAAC;AAkDF,eAAe,UAAU,CAAC"}
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue's `invalidateTypeCache()` from the project's own `vue/compiler-sfc`,
|
|
3
|
+
* or null when Vue is not installed. Loaded the way `@vitejs/plugin-vue`
|
|
4
|
+
* loads the compiler (a `require` resolved from the Vite root), so it clears
|
|
5
|
+
* the cache that plugin compiles with.
|
|
6
|
+
*/
|
|
7
|
+
export declare const loadVueTypeCacheInvalidator: (root: string) => ((file: string) => void) | null;
|
|
8
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GAAI,MAAM,MAAM,KAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,IAUrF,CAAC"}
|
package/package.json
CHANGED