@pentacore/vite-plugin-laravel-typefinder 8.6.0 → 8.7.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.
package/README.md CHANGED
@@ -57,7 +57,8 @@ All options are optional. Defaults work for a standard Laravel project with `php
57
57
  ```ts
58
58
  typefinder({
59
59
  // Shell command for the long-lived watcher process.
60
- // Override for Sail/Herd/Docker.
60
+ // Override for Sail/Herd/Docker. Set to `false` to run no watcher
61
+ // and no regeneration in `vite dev`.
61
62
  command: 'php artisan typefinder:watch',
62
63
 
63
64
  // Shell command used in `vite build` (one-shot, no watcher).
@@ -140,6 +141,8 @@ Warnings and per-file failures of every regeneration, the initial one included,
140
141
 
141
142
  **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
 
144
+ **Vitest:** Vitest starts Vite in serve mode, but the plugin does nothing while `VITEST` is set: it spawns no watcher and regenerates nothing, so a test run never rewrites the generated types and needs neither PHP nor a database. The plugin can stay in a `vite.config.ts` that Vitest shares.
145
+
143
146
  ### Builds without a database (Docker, CI)
144
147
 
145
148
  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.
package/dist/index.js CHANGED
@@ -185,13 +185,16 @@ var u = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e
185
185
  }, y = s(e), b = () => {
186
186
  let e = process.env.TYPEFINDER_SKIP_BUILD?.trim().toLowerCase();
187
187
  return e !== void 0 && e !== "" && e !== "0" && e !== "false";
188
- }, x = (e) => {
188
+ }, x = () => {
189
+ let e = process.env.VITEST?.trim().toLowerCase();
190
+ return e !== void 0 && e !== "" && e !== "0" && e !== "false";
191
+ }, S = (e) => {
189
192
  process.stderr.write(`[typefinder] ${e}\n`);
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) => {
193
+ }, C = (e, t) => {
194
+ e.changed.length > 0 && S(`${t} ${e.changed.length} file(s) in ${e.duration_ms}ms`);
195
+ for (let t of e.warnings) S(t);
196
+ for (let t of e.failed) S(`${t.path}: ${t.message}`);
197
+ }, w = (e) => {
195
198
  if (typeof e != "string") return null;
196
199
  let t = e.split("\n").map((e) => e.trim()).filter((e) => e !== "");
197
200
  for (let e = t.length - 1; e >= 0; e--) try {
@@ -199,78 +202,82 @@ var u = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e
199
202
  if (typeof n == "object" && n && "success" in n) return n;
200
203
  } catch {}
201
204
  return null;
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
+ }, T = ({ 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 } = {}) => {
206
+ let d = process.cwd(), m = null, _ = () => !1, T = () => !1, O = !1, k = new h(), A = /* @__PURE__ */ new Set(), j, M = !1, N = () => {}, P = () => {
207
+ clearTimeout(j), j = setTimeout(() => {
205
208
  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
+ let e = O ? [] : Array.from(A), t = O ? "full regen" : "regen";
210
+ A.clear(), O = !1, m.regen(e).then((e) => {
211
+ C(e, t), N(e);
209
212
  }).catch((e) => {
210
- x(`regen failed: ${e.message}`);
213
+ S(`regen failed: ${e.message}`);
211
214
  });
212
215
  }, r);
213
- }, P = (e) => {
214
- if (j || !m || m.dead) return;
216
+ }, F = (e) => {
217
+ if (M || !m || m.dead) return;
215
218
  let t = p(e);
216
- w(t) ? (D = !0, N()) : _(t) && (k.add(O.toWatcher(t)), N());
219
+ T(t) ? (O = !0, P()) : _(t) && (A.add(k.toWatcher(t)), P());
217
220
  };
218
221
  return {
219
222
  name: "@pentacore/vite-plugin-laravel-typefinder",
220
223
  enforce: "pre",
221
224
  configResolved(e) {
222
- d = e.root, j = e.command === "build";
225
+ d = e.root, M = e.command === "build";
223
226
  },
224
227
  async configureServer(t) {
225
- if (j) return;
226
- O = new h(l), m = await g.spawn({
228
+ if (M || x()) return;
229
+ if (e === !1) {
230
+ S("dev watcher disabled");
231
+ return;
232
+ }
233
+ k = new h(l), m = await g.spawn({
227
234
  command: e,
228
235
  cwd: d,
229
236
  startupTimeoutMs: a,
230
237
  killTimeoutMs: s,
231
238
  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", () => {
239
+ }), _ = f((n ?? D(m.handshake.categories).map((e) => k.toHost(e))).map(p)), T = f((u === !1 ? [] : u ?? [`${d}/database/migrations`]).map(p));
240
+ let r = k.toHost(m.handshake.output_path);
241
+ N = E(t, v(d), i(r) ? r : o(d, r)), m.on("died", (e) => {
242
+ S(`watcher exited: ${e} — restart the dev server`);
243
+ }), t.watcher.on("add", F), t.watcher.on("change", F), t.watcher.on("unlink", F), t.ws.on("typefinder:full-regen", () => {
237
244
  m && !m.dead && m.regen([]).then((e) => {
238
- S(e, "full regen"), M(e);
245
+ C(e, "full regen"), N(e);
239
246
  }).catch((e) => {
240
- x(`full regen failed: ${e.message}`);
247
+ S(`full regen failed: ${e.message}`);
241
248
  });
242
249
  }), t.httpServer?.once("close", () => void m?.kill()), process.once("exit", () => void m?.kill());
243
250
  },
244
251
  async buildStart() {
245
- if (j) {
252
+ if (M) {
246
253
  if (t === !1) {
247
- x("build-time generation disabled");
254
+ S("build-time generation disabled");
248
255
  return;
249
256
  }
250
257
  if (b()) {
251
- x("build-time generation skipped: TYPEFINDER_SKIP_BUILD is set");
258
+ S("build-time generation skipped: TYPEFINDER_SKIP_BUILD is set");
252
259
  return;
253
260
  }
254
261
  let e;
255
262
  try {
256
263
  ({stdout: e} = await y(t, { cwd: d }));
257
264
  } catch (e) {
258
- let t = C(e.stdout);
259
- for (let e of t?.warnings ?? []) x(e);
265
+ let t = w(e.stdout);
266
+ for (let e of t?.warnings ?? []) S(e);
260
267
  let n = t?.errors ?? [], r = n.length > 0 ? n.join("\n") : e instanceof Error ? e.message : String(e);
261
268
  throw Error(`[typefinder] build-time generation failed: ${r}`, { cause: e });
262
269
  }
263
- for (let t of C(e)?.warnings ?? []) x(t);
270
+ for (let t of w(e)?.warnings ?? []) S(t);
264
271
  } else if (m && !m.dead) {
265
272
  let e = await m.regen([]);
266
- S(e, "initial regen:"), M(e);
273
+ C(e, "initial regen:"), N(e);
267
274
  }
268
275
  },
269
276
  async closeBundle() {
270
277
  m && !m.dead && await m.kill();
271
278
  }
272
279
  };
273
- }, T = (e, t, n) => t === null ? () => {} : (r) => {
280
+ }, E = (e, t, n) => t === null ? () => {} : (r) => {
274
281
  if (r.changed.length === 0) return;
275
282
  for (let e of r.changed) {
276
283
  let r = a(n, e);
@@ -283,7 +290,7 @@ var u = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e
283
290
  for (let t of i) e.moduleGraph.invalidateModule(t);
284
291
  e.ws.send({ type: "full-reload" });
285
292
  }
286
- }, E = (e) => {
293
+ }, D = (e) => {
287
294
  let t = [];
288
295
  for (let n of Object.keys(e)) {
289
296
  let r = e[n];
@@ -291,4 +298,4 @@ var u = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e
291
298
  }
292
299
  return t;
293
300
  };
294
- export { w as default, w as typefinder };
301
+ export { T as default, T as typefinder };
@@ -1,6 +1,10 @@
1
1
  import { Plugin } from 'vite';
2
2
  export interface TypefinderOptions {
3
- command?: string;
3
+ /**
4
+ * Shell command for the long-lived watcher process in `vite dev`;
5
+ * `false` disables the watcher and the initial regen there.
6
+ */
7
+ command?: string | false;
4
8
  buildCommand?: string | false;
5
9
  watch?: string[];
6
10
  debounceMs?: number;
@@ -1 +1 @@
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"}
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;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,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;AAgED,eAAO,MAAM,UAAU,GAAI,sHAUxB,iBAAsB,KAAG,MAiK3B,CAAC;AAkDF,eAAe,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pentacore/vite-plugin-laravel-typefinder",
3
- "version": "8.6.0",
3
+ "version": "8.7.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",