@pentacore/vite-plugin-laravel-typefinder 1.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.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # @pentacore/vite-plugin-laravel-typefinder
2
+
3
+ A Vite plugin that automatically runs `php artisan typefinder:generate` on build start and re-runs it (debounced) whenever watched PHP files change via HMR.
4
+
5
+ ## Requirements
6
+
7
+ - Vite 6+
8
+ - Node 18+
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm i -D @pentacore/vite-plugin-laravel-typefinder
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { defineConfig } from 'vite';
20
+ import laravel from 'laravel-vite-plugin';
21
+ import typefinder from '@pentacore/vite-plugin-laravel-typefinder';
22
+
23
+ export default defineConfig({
24
+ plugins: [
25
+ laravel({ input: ['resources/js/app.js'] }),
26
+ typefinder({
27
+ // All options are optional — defaults shown below
28
+ command: 'php artisan typefinder:generate',
29
+ watch: ['app/Models/**/*.php', 'app/Enums/**/*.php', 'app/Http/Requests/**/*.php'],
30
+ debounceMs: 100,
31
+ }),
32
+ ],
33
+ });
34
+ ```
35
+
36
+ ## Options
37
+
38
+ | Option | Type | Default | Description |
39
+ |---|---|---|---|
40
+ | `command` | `string` | `'php artisan typefinder:generate'` | The shell command to run for type generation |
41
+ | `watch` | `string[]` | `['app/Models/**/*.php', 'app/Enums/**/*.php', 'app/Http/Requests/**/*.php']` | Glob patterns for files that trigger re-generation on HMR change |
42
+ | `debounceMs` | `number` | `100` | Milliseconds to wait after a file change before running the command, to coalesce rapid saves |
43
+
44
+ ## Behavior
45
+
46
+ **On `buildStart`:** The command runs once synchronously before bundling begins, ensuring your TypeScript types are always fresh before the build processes them.
47
+
48
+ **On HMR file changes:** When a file matching one of the `watch` patterns changes, the plugin schedules a debounced run. If the command is already running when the timer fires, the new run is queued — only one run is ever active at a time, but at most one follow-up run will be queued to pick up any changes that arrived mid-run. This prevents stale types while avoiding unbounded queuing.
49
+
50
+ The plugin relies on Typefinder's selective-write behaviour: the PHP command re-extracts the full type graph on every run, but only files whose content has actually changed are rewritten on disk — meaning HMR in your frontend is not needlessly triggered for unchanged types.
51
+
52
+ ## Alternative install (from vendor)
53
+
54
+ If you prefer not to add an npm dependency, the Composer package bundles the built plugin in its `dist/` directory:
55
+
56
+ ```ts
57
+ import typefinder from '../../vendor/typefinder/laravel-typefinder/dist/index.mjs';
58
+ ```
59
+
60
+ Adjust the relative path to match your project structure. This approach means the plugin version is tied to your Composer lock file — which is often desirable.
61
+
62
+ ## License
63
+
64
+ MIT — see [LICENSE](../../LICENSE).