@pentacore/vite-plugin-laravel-typefinder 8.3.1 → 8.4.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 +37 -14
- package/dist/index.js +113 -55
- package/dist/matcher.d.ts +10 -0
- package/dist/matcher.d.ts.map +1 -1
- package/dist/paths.d.ts +22 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/vite-plugin-typefinder.d.ts +15 -1
- package/dist/vite-plugin-typefinder.d.ts.map +1 -1
- package/dist/watcher.d.ts +6 -0
- package/dist/watcher.d.ts.map +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -19,7 +19,6 @@ A Vite plugin that keeps your TypeScript type definitions in sync with your Lara
|
|
|
19
19
|
- [Usage](#usage)
|
|
20
20
|
- [Configuration](#configuration)
|
|
21
21
|
- [Behavior](#behavior)
|
|
22
|
-
- [Alternative install (from vendor)](#alternative-install-from-vendor)
|
|
23
22
|
- [License](#license)
|
|
24
23
|
|
|
25
24
|
## Requirements
|
|
@@ -27,7 +26,7 @@ A Vite plugin that keeps your TypeScript type definitions in sync with your Lara
|
|
|
27
26
|
- The Composer package `pentacore/laravel-typefinder` installed and auto-discovered in your Laravel app.
|
|
28
27
|
- Vite 6+
|
|
29
28
|
- Node 18+
|
|
30
|
-
- ESM-only — the package exposes only `dist/index.
|
|
29
|
+
- ESM-only — the package exposes only `dist/index.js`. Consumers must `import` (not `require`) it. Any modern Vite/Laravel app already meets this.
|
|
31
30
|
|
|
32
31
|
## Installation
|
|
33
32
|
|
|
@@ -78,6 +77,20 @@ typefinder({
|
|
|
78
77
|
|
|
79
78
|
// Grace period between SIGTERM and SIGKILL when shutting down.
|
|
80
79
|
killTimeoutMs: 2_000,
|
|
80
|
+
|
|
81
|
+
// How long to wait for one regeneration before reporting it failed
|
|
82
|
+
// (e.g. a model accessor that blocks on a network call). 0 disables it.
|
|
83
|
+
regenTimeoutMs: 120_000,
|
|
84
|
+
|
|
85
|
+
// Maps a path prefix as the watcher sees it to the same directory on
|
|
86
|
+
// the host Vite runs on. Needed when PHP runs in a container (Sail,
|
|
87
|
+
// Docker): see "Sail and Docker" below.
|
|
88
|
+
pathMap: undefined,
|
|
89
|
+
|
|
90
|
+
// Directories whose files change the database schema. A change there
|
|
91
|
+
// triggers a full regeneration. Defaults to `database/migrations` under
|
|
92
|
+
// the Vite root; `false` turns it off.
|
|
93
|
+
migrations: undefined,
|
|
81
94
|
});
|
|
82
95
|
```
|
|
83
96
|
|
|
@@ -94,15 +107,35 @@ typefinder({ command: 'herd php artisan typefinder:watch' })
|
|
|
94
107
|
typefinder({ command: 'docker compose exec app php artisan typefinder:watch' })
|
|
95
108
|
```
|
|
96
109
|
|
|
110
|
+
### Sail and Docker
|
|
111
|
+
|
|
112
|
+
When PHP runs in a container, the watcher reports its directories as the container sees them (`/var/www/html/app/Models`), while Vite on the host reports changed files under the host path (`/Users/you/project/app/Models/User.php`). Without help the two never match and no regeneration runs. Tell the plugin where the container's project directory lives on the host with `pathMap`:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
typefinder({
|
|
116
|
+
command: './vendor/bin/sail artisan typefinder:watch',
|
|
117
|
+
buildCommand: './vendor/bin/sail artisan typefinder:generate --json',
|
|
118
|
+
pathMap: { '/var/www/html': process.cwd() },
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The mapping is applied both ways: the watcher's directories are translated to host paths to match the files Vite reports, and every changed file is translated back to the container path before it is sent to the watcher. An explicit `watch` array takes host paths. Use the volume mount of your `docker-compose.yml` (`.:/var/www/html` for Sail) as the key and value. With several mounts, add one entry per mount; the longest matching prefix wins.
|
|
123
|
+
|
|
124
|
+
Symlinked project directories need no mapping: the plugin resolves symlinks on both sides, as PHP does.
|
|
125
|
+
|
|
97
126
|
## Behavior
|
|
98
127
|
|
|
99
|
-
**Development (`vite dev`):** The plugin spawns `typefinder:watch` — a persistent Laravel process that boots once and accepts incremental regeneration requests over NDJSON. When a `.php` file matching the watched paths
|
|
128
|
+
**Development (`vite dev`):** The plugin spawns `typefinder:watch` — a persistent Laravel process that boots once and accepts incremental regeneration requests over NDJSON. When a `.php` file matching the watched paths is created, changed, deleted or renamed, the plugin sends the changed file paths to the watcher, which re-extracts only those files and rewrites only the affected `.d.ts` outputs. Multiple rapid edits within the debounce window are coalesced into a single request.
|
|
100
129
|
|
|
101
130
|
A PHP process cannot reload a class it has loaded, so the watcher answers each request in a forked worker that reads the edited classes from the files as they are now. Forking needs PHP's `pcntl` extension. Without it (Windows, some Docker images), or once a class the application loads while booting (a service provider, for example) has been edited, each request starts a new PHP process instead: the same output, but a Laravel boot slower per change. The watcher says so once on stderr; in the second case, restarting the dev server makes it fast again.
|
|
102
131
|
|
|
103
132
|
The watched paths are read from the watcher's startup handshake, which mirrors your `config/typefinder.php`. If you enable Inertia pages or broadcasting in the config, the plugin automatically watches those directories too — no manual `watch` array needed.
|
|
104
133
|
|
|
105
|
-
|
|
134
|
+
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
|
+
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
|
+
|
|
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 (e.g. for pre-built containers without a PHP runtime).
|
|
106
139
|
|
|
107
140
|
**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.
|
|
108
141
|
|
|
@@ -112,16 +145,6 @@ The watched paths are read from the watcher's startup handshake, which mirrors y
|
|
|
112
145
|
- `watch` default changed from a hardcoded path list to `undefined`, meaning "use whatever the watcher reports". Existing explicit `watch: [...]` configurations keep working unchanged.
|
|
113
146
|
- Regenerations now run against a persistent Laravel boot via NDJSON. Typical edit latency drops from ~300-500ms to ~20-60ms.
|
|
114
147
|
|
|
115
|
-
## Alternative install (from vendor)
|
|
116
|
-
|
|
117
|
-
If you prefer not to add an npm dependency, the Composer package bundles the built plugin in its `dist/` directory:
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import typefinder from '../../vendor/pentacore/laravel-typefinder/dist/index.mjs';
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
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.
|
|
124
|
-
|
|
125
148
|
## License
|
|
126
149
|
|
|
127
150
|
MIT — see [LICENSE](../../LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,65 @@
|
|
|
1
1
|
import { exec as e, spawn as t } from "node:child_process";
|
|
2
2
|
import { promisify as n } from "node:util";
|
|
3
|
-
import r from "
|
|
4
|
-
import {
|
|
3
|
+
import { realpathSync as r } from "node:fs";
|
|
4
|
+
import { basename as i, dirname as a } from "node:path";
|
|
5
|
+
import { EventEmitter as o } from "node:events";
|
|
5
6
|
// src/matcher.ts
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return (
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
var s = (e) => {
|
|
8
|
+
let t = e.replace(/\\/g, "/"), n = t.length;
|
|
9
|
+
for (; n > 0 && t[n - 1] === "/";) n--;
|
|
10
|
+
return t.slice(0, n);
|
|
11
|
+
}, c = (e) => {
|
|
12
|
+
let t = e.map(s).filter((e) => e !== "").map((e) => `${e}/`);
|
|
13
|
+
return t.length === 0 ? () => !1 : (e) => {
|
|
14
|
+
let n = e.replace(/\\/g, "/");
|
|
15
|
+
return n.endsWith(".php") ? t.some((e) => n.startsWith(e)) : !1;
|
|
12
16
|
};
|
|
13
|
-
},
|
|
17
|
+
}, l = (e) => {
|
|
18
|
+
let t = [], n = e;
|
|
19
|
+
for (;;) try {
|
|
20
|
+
let e = s(r.native(n));
|
|
21
|
+
return t.length === 0 ? e : `${e}/${t.reverse().join("/")}`;
|
|
22
|
+
} catch {
|
|
23
|
+
let r = a(n);
|
|
24
|
+
if (r === n) return s(e);
|
|
25
|
+
t.push(i(n)), n = r;
|
|
26
|
+
}
|
|
27
|
+
}, u = (e, t, n) => e === t ? n : e.startsWith(`${t}/`) ? n + e.slice(t.length) : null, d = class {
|
|
28
|
+
entries;
|
|
29
|
+
constructor(e = {}) {
|
|
30
|
+
this.entries = Object.entries(e).map(([e, t]) => ({
|
|
31
|
+
remote: s(e),
|
|
32
|
+
local: l(t)
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
toHost(e) {
|
|
36
|
+
return this.translate(s(e), "remote", "local");
|
|
37
|
+
}
|
|
38
|
+
toWatcher(e) {
|
|
39
|
+
return this.translate(s(e), "local", "remote");
|
|
40
|
+
}
|
|
41
|
+
translate(e, t, n) {
|
|
42
|
+
let r = [...this.entries].sort((e, n) => n[t].length - e[t].length);
|
|
43
|
+
for (let i of r) {
|
|
44
|
+
let r = u(e, i[t], i[n]);
|
|
45
|
+
if (r !== null) return r;
|
|
46
|
+
}
|
|
47
|
+
return e;
|
|
48
|
+
}
|
|
49
|
+
}, f = class e extends o {
|
|
14
50
|
handshake;
|
|
15
51
|
child;
|
|
16
52
|
killTimeoutMs;
|
|
53
|
+
regenTimeoutMs;
|
|
17
54
|
buffer = "";
|
|
18
55
|
inflight = null;
|
|
19
56
|
nextBatch = null;
|
|
57
|
+
nextFull = !1;
|
|
20
58
|
nextResolvers = [];
|
|
21
59
|
idCounter = 0;
|
|
22
60
|
_dead = !1;
|
|
23
|
-
constructor(e, t, n) {
|
|
24
|
-
super(), this.child = e, this.handshake = t, this.killTimeoutMs = n, e.stdout?.on("data", (e) => {
|
|
61
|
+
constructor(e, t, n, r) {
|
|
62
|
+
super(), this.child = e, this.handshake = t, this.killTimeoutMs = n, this.regenTimeoutMs = r, e.stdout?.on("data", (e) => {
|
|
25
63
|
this.onStdout(typeof e == "string" ? e : e.toString("utf8"));
|
|
26
64
|
}), e.stderr?.on("data", (e) => {
|
|
27
65
|
let t = (typeof e == "string" ? e : e.toString("utf8")).trimEnd();
|
|
@@ -29,9 +67,9 @@ var a = (e) => {
|
|
|
29
67
|
}), e.on("exit", (e, t) => {
|
|
30
68
|
this._dead = !0;
|
|
31
69
|
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);
|
|
70
|
+
this.emit("died", n), this.inflight &&= (clearTimeout(this.inflight.timer), this.inflight.reject(/* @__PURE__ */ Error(`watcher died (${n})`)), null);
|
|
33
71
|
for (let e of this.nextResolvers) e.reject(/* @__PURE__ */ Error(`watcher died (${n})`));
|
|
34
|
-
this.nextResolvers = [], this.nextBatch = null;
|
|
72
|
+
this.nextResolvers = [], this.nextBatch = null, this.nextFull = !1;
|
|
35
73
|
});
|
|
36
74
|
}
|
|
37
75
|
get dead() {
|
|
@@ -52,7 +90,7 @@ var a = (e) => {
|
|
|
52
90
|
try {
|
|
53
91
|
let i = JSON.parse(d);
|
|
54
92
|
if (i.type !== "ready") throw Error("expected ready, got " + i.type);
|
|
55
|
-
let o = new e(r, i, n.killTimeoutMs ?? 2e3);
|
|
93
|
+
let o = new e(r, i, n.killTimeoutMs ?? 2e3, n.regenTimeoutMs ?? 12e4);
|
|
56
94
|
a.length > 0 && o.onStdout(a), t(o);
|
|
57
95
|
} catch (e) {
|
|
58
96
|
r.kill("SIGTERM"), i(/* @__PURE__ */ Error(`malformed handshake: ${e.message}`));
|
|
@@ -68,7 +106,7 @@ var a = (e) => {
|
|
|
68
106
|
async regen(e) {
|
|
69
107
|
if (this._dead) throw Error("watcher is dead");
|
|
70
108
|
if (!this.inflight) return this.dispatch(e);
|
|
71
|
-
this.nextBatch ||= /* @__PURE__ */ new Set();
|
|
109
|
+
this.nextBatch ||= /* @__PURE__ */ new Set(), e.length === 0 && (this.nextFull = !0);
|
|
72
110
|
for (let t of e) this.nextBatch.add(t);
|
|
73
111
|
return new Promise((e, t) => {
|
|
74
112
|
this.nextResolvers.push({
|
|
@@ -84,13 +122,20 @@ var a = (e) => {
|
|
|
84
122
|
paths: e
|
|
85
123
|
};
|
|
86
124
|
return this.child.stdin?.write(JSON.stringify(n) + "\n"), new Promise((e, n) => {
|
|
125
|
+
let r = this.regenTimeoutMs > 0 ? setTimeout(() => this.onRegenTimeout(t), this.regenTimeoutMs) : void 0;
|
|
87
126
|
this.inflight = {
|
|
88
127
|
id: t,
|
|
89
128
|
resolve: e,
|
|
90
|
-
reject: n
|
|
129
|
+
reject: n,
|
|
130
|
+
timer: r
|
|
91
131
|
};
|
|
92
132
|
});
|
|
93
133
|
}
|
|
134
|
+
onRegenTimeout(e) {
|
|
135
|
+
if (!this.inflight || this.inflight.id !== e) return;
|
|
136
|
+
let t = this.inflight;
|
|
137
|
+
this.inflight = null, t.reject(/* @__PURE__ */ Error(`regen timed out after ${this.regenTimeoutMs}ms — the watcher may be stuck; restart the dev server if regens keep failing`)), this.drainQueued();
|
|
138
|
+
}
|
|
94
139
|
onStdout(e) {
|
|
95
140
|
this.buffer += e;
|
|
96
141
|
let t;
|
|
@@ -110,13 +155,13 @@ var a = (e) => {
|
|
|
110
155
|
if (t.type === "regen.done" || t.type === "regen.error") {
|
|
111
156
|
if (!this.inflight || "id" in t && this.inflight.id !== t.id) return;
|
|
112
157
|
let e = this.inflight;
|
|
113
|
-
this.inflight = null, t.type === "regen.done" ? e.resolve(t) : e.reject(Error(t.message)), this.drainQueued();
|
|
158
|
+
this.inflight = null, clearTimeout(e.timer), t.type === "regen.done" ? e.resolve(t) : e.reject(Error(t.message)), this.drainQueued();
|
|
114
159
|
}
|
|
115
160
|
}
|
|
116
161
|
drainQueued() {
|
|
117
162
|
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)));
|
|
163
|
+
let e = this.nextFull ? [] : Array.from(this.nextBatch), t = [...this.nextResolvers];
|
|
164
|
+
this.nextBatch = null, this.nextFull = !1, this.nextResolvers = [], this.dispatch(e).then((e) => t.forEach((t) => t.resolve(e)), (e) => t.forEach((t) => t.reject(e)));
|
|
120
165
|
}
|
|
121
166
|
async kill() {
|
|
122
167
|
this._dead || await new Promise((e) => {
|
|
@@ -128,65 +173,78 @@ var a = (e) => {
|
|
|
128
173
|
}), this.child.kill("SIGTERM");
|
|
129
174
|
});
|
|
130
175
|
}
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
176
|
+
}, p = n(e), m = (e) => {
|
|
177
|
+
process.stderr.write(`[typefinder] ${e}\n`);
|
|
178
|
+
}, h = (e, t) => {
|
|
179
|
+
e.changed.length > 0 && m(`${t} ${e.changed.length} file(s) in ${e.duration_ms}ms`);
|
|
180
|
+
for (let t of e.warnings) m(t);
|
|
181
|
+
for (let t of e.failed) m(`${t.path}: ${t.message}`);
|
|
182
|
+
}, g = (e) => {
|
|
183
|
+
if (typeof e != "string") return null;
|
|
184
|
+
let t = e.split("\n").map((e) => e.trim()).filter((e) => e !== "");
|
|
185
|
+
for (let e = t.length - 1; e >= 0; e--) try {
|
|
186
|
+
let n = JSON.parse(t[e]);
|
|
187
|
+
if (typeof n == "object" && n && "success" in n) return n;
|
|
188
|
+
} catch {}
|
|
189
|
+
return null;
|
|
190
|
+
}, _ = ({ command: e = "php artisan typefinder:watch", buildCommand: t = "php artisan typefinder:generate --json", watch: n, debounceMs: r = 100, startupTimeoutMs: i = 1e4, killTimeoutMs: a = 2e3, regenTimeoutMs: o = 12e4, pathMap: s, migrations: u } = {}) => {
|
|
191
|
+
let _ = process.cwd(), y = null, b = () => !1, x = () => !1, S = !1, C = new d(), w = /* @__PURE__ */ new Set(), T, E = !1, D = () => {
|
|
192
|
+
clearTimeout(T), T = setTimeout(() => {
|
|
193
|
+
if (!y || y.dead) return;
|
|
194
|
+
let e = S ? [] : Array.from(w), t = S ? "full regen" : "regen";
|
|
195
|
+
w.clear(), S = !1, y.regen(e).then((e) => h(e, t)).catch((e) => {
|
|
196
|
+
m(`regen failed: ${e.message}`);
|
|
142
197
|
});
|
|
143
198
|
}, r);
|
|
199
|
+
}, O = (e) => {
|
|
200
|
+
if (E || !y || y.dead) return;
|
|
201
|
+
let t = l(e);
|
|
202
|
+
x(t) ? (S = !0, D()) : b(t) && (w.add(C.toWatcher(t)), D());
|
|
144
203
|
};
|
|
145
204
|
return {
|
|
146
205
|
name: "@pentacore/vite-plugin-laravel-typefinder",
|
|
147
206
|
enforce: "pre",
|
|
148
207
|
configResolved(e) {
|
|
149
|
-
|
|
208
|
+
_ = e.root, E = e.command === "build";
|
|
150
209
|
},
|
|
151
210
|
async configureServer(t) {
|
|
152
|
-
|
|
211
|
+
E || (C = new d(s), y = await f.spawn({
|
|
153
212
|
command: e,
|
|
154
|
-
cwd:
|
|
213
|
+
cwd: _,
|
|
155
214
|
startupTimeoutMs: i,
|
|
156
|
-
killTimeoutMs:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
215
|
+
killTimeoutMs: a,
|
|
216
|
+
regenTimeoutMs: o
|
|
217
|
+
}), b = c((n ?? v(y.handshake.categories).map((e) => C.toHost(e))).map(l)), x = c((u === !1 ? [] : u ?? [`${_}/database/migrations`]).map(l)), y.on("died", (e) => {
|
|
218
|
+
m(`watcher exited: ${e} — restart the dev server`);
|
|
219
|
+
}), t.watcher.on("add", O), t.watcher.on("change", O), t.watcher.on("unlink", O), t.ws.on("typefinder:full-regen", () => {
|
|
220
|
+
y && !y.dead && y.regen([]).then((e) => h(e, "full regen")).catch((e) => {
|
|
221
|
+
m(`full regen failed: ${e.message}`);
|
|
162
222
|
});
|
|
163
|
-
}), t.httpServer?.once("close", () => void
|
|
223
|
+
}), t.httpServer?.once("close", () => void y?.kill()), process.once("exit", () => void y?.kill()));
|
|
164
224
|
},
|
|
165
225
|
async buildStart() {
|
|
166
|
-
if (
|
|
226
|
+
if (E) {
|
|
167
227
|
if (t === !1) {
|
|
168
|
-
|
|
228
|
+
m("build-time generation disabled");
|
|
169
229
|
return;
|
|
170
230
|
}
|
|
231
|
+
let e;
|
|
171
232
|
try {
|
|
172
|
-
await
|
|
233
|
+
({stdout: e} = await p(t, { cwd: _ }));
|
|
173
234
|
} catch (e) {
|
|
174
|
-
let t = e
|
|
175
|
-
|
|
235
|
+
let t = g(e.stdout);
|
|
236
|
+
for (let e of t?.warnings ?? []) m(e);
|
|
237
|
+
let n = t?.errors ?? [], r = n.length > 0 ? n.join("\n") : e instanceof Error ? e.message : String(e);
|
|
238
|
+
throw Error(`[typefinder] build-time generation failed: ${r}`, { cause: e });
|
|
176
239
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
e.changed.length > 0 && process.stderr.write(`[typefinder] initial regen: ${e.changed.length} file(s) in ${e.duration_ms}ms\n`);
|
|
180
|
-
}
|
|
181
|
-
},
|
|
182
|
-
handleHotUpdate({ file: e }) {
|
|
183
|
-
h || !d || d.dead || f(e) && (p.add(e), g());
|
|
240
|
+
for (let t of g(e)?.warnings ?? []) m(t);
|
|
241
|
+
} else y && !y.dead && h(await y.regen([]), "initial regen:");
|
|
184
242
|
},
|
|
185
243
|
async closeBundle() {
|
|
186
|
-
|
|
244
|
+
y && !y.dead && await y.kill();
|
|
187
245
|
}
|
|
188
246
|
};
|
|
189
|
-
},
|
|
247
|
+
}, v = (e) => {
|
|
190
248
|
let t = [];
|
|
191
249
|
for (let n of Object.keys(e)) {
|
|
192
250
|
let r = e[n];
|
|
@@ -194,4 +252,4 @@ var a = (e) => {
|
|
|
194
252
|
}
|
|
195
253
|
return t;
|
|
196
254
|
};
|
|
197
|
-
export {
|
|
255
|
+
export { _ as default, _ as typefinder };
|
package/dist/matcher.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Forward slashes, without trailing ones. The trailing slashes are trimmed in
|
|
3
|
+
* a loop: the regex `/\/+$/` backtracks polynomially on long runs of `/`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const normalisePath: (path: string) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Matches `.php` files under any of the given directories by plain prefix
|
|
8
|
+
* comparison, so directory names that contain glob characters (`(`, `{`, `+`,
|
|
9
|
+
* `[` …) match like any other.
|
|
10
|
+
*/
|
|
1
11
|
export declare const compileMatcher: (paths: string[]) => ((file: string) => boolean);
|
|
2
12
|
//# sourceMappingURL=matcher.d.ts.map
|
package/dist/matcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../src/matcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../src/matcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAO5C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACvB,OAAO,MAAM,EAAE,KAChB,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAiB5B,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The real path of `path` with symlinks resolved, like PHP's `realpath()` on
|
|
3
|
+
* the watcher side. A path that no longer exists (a deleted file) resolves
|
|
4
|
+
* through its nearest existing ancestor; a path with no existing ancestor is
|
|
5
|
+
* returned as given.
|
|
6
|
+
*/
|
|
7
|
+
export declare const realpathLoose: (path: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Translates paths between the watcher's filesystem (e.g. `/var/www/html`
|
|
10
|
+
* inside a Sail or Docker container) and the host Vite runs on.
|
|
11
|
+
*
|
|
12
|
+
* `pathMap` maps a watcher-side prefix to a host-side prefix. The longest
|
|
13
|
+
* matching prefix wins; a path no entry covers is returned unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export declare class PathMapper {
|
|
16
|
+
private readonly entries;
|
|
17
|
+
constructor(pathMap?: Record<string, string>);
|
|
18
|
+
toHost(path: string): string;
|
|
19
|
+
toWatcher(path: string): string;
|
|
20
|
+
private translate;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MAiB5C,CAAC;AAQF;;;;;;GAMG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2C;gBAEvD,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAOhD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI/B,OAAO,CAAC,SAAS;CAQpB"}
|
|
@@ -6,7 +6,21 @@ export interface TypefinderOptions {
|
|
|
6
6
|
debounceMs?: number;
|
|
7
7
|
startupTimeoutMs?: number;
|
|
8
8
|
killTimeoutMs?: number;
|
|
9
|
+
/** How long to wait for one regen before reporting it failed; 0 disables the timeout. */
|
|
10
|
+
regenTimeoutMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Maps a path prefix as the watcher sees it (inside a Sail / Docker
|
|
13
|
+
* container) to the same directory on the host Vite runs on, e.g.
|
|
14
|
+
* `{ '/var/www/html': process.cwd() }`. Applied both ways.
|
|
15
|
+
*/
|
|
16
|
+
pathMap?: Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Directories whose `.php` files change the database schema. A change
|
|
19
|
+
* there triggers a full regen, since any model may be affected.
|
|
20
|
+
* Defaults to `database/migrations` under the Vite root; `false` disables it.
|
|
21
|
+
*/
|
|
22
|
+
migrations?: string[] | false;
|
|
9
23
|
}
|
|
10
|
-
export declare const typefinder: ({ command, buildCommand, watch, debounceMs, startupTimeoutMs, killTimeoutMs, }?: TypefinderOptions) => Plugin;
|
|
24
|
+
export declare const typefinder: ({ command, buildCommand, watch, debounceMs, startupTimeoutMs, killTimeoutMs, regenTimeoutMs, pathMap, migrations, }?: TypefinderOptions) => Plugin;
|
|
11
25
|
export default typefinder;
|
|
12
26
|
//# sourceMappingURL=vite-plugin-typefinder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin-typefinder.d.ts","sourceRoot":"","sources":["../src/vite-plugin-typefinder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin-typefinder.d.ts","sourceRoot":"","sources":["../src/vite-plugin-typefinder.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAQnD,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;AA4CD,eAAO,MAAM,UAAU,GAAI,sHAUxB,iBAAsB,KAAG,MAwI3B,CAAC;AAaF,eAAe,UAAU,CAAC"}
|
package/dist/watcher.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface WatcherSpawnOptions {
|
|
|
6
6
|
cwd: string;
|
|
7
7
|
startupTimeoutMs: number;
|
|
8
8
|
killTimeoutMs?: number;
|
|
9
|
+
/** How long to wait for a regen answer before failing it; 0 disables the timeout. */
|
|
10
|
+
regenTimeoutMs?: number;
|
|
9
11
|
spawnFn?: (cmd: string, args: string[], opts: {
|
|
10
12
|
cwd: string;
|
|
11
13
|
shell: boolean;
|
|
@@ -15,9 +17,12 @@ export declare class Watcher extends EventEmitter {
|
|
|
15
17
|
readonly handshake: Handshake;
|
|
16
18
|
private readonly child;
|
|
17
19
|
private readonly killTimeoutMs;
|
|
20
|
+
private readonly regenTimeoutMs;
|
|
18
21
|
private buffer;
|
|
19
22
|
private inflight;
|
|
23
|
+
/** Paths of the queued request; an empty set with `nextFull` means a full regen. */
|
|
20
24
|
private nextBatch;
|
|
25
|
+
private nextFull;
|
|
21
26
|
private nextResolvers;
|
|
22
27
|
private idCounter;
|
|
23
28
|
private _dead;
|
|
@@ -26,6 +31,7 @@ export declare class Watcher extends EventEmitter {
|
|
|
26
31
|
static spawn(opts: WatcherSpawnOptions): Promise<Watcher>;
|
|
27
32
|
regen(paths: string[]): Promise<RegenResponse>;
|
|
28
33
|
private dispatch;
|
|
34
|
+
private onRegenTimeout;
|
|
29
35
|
private onStdout;
|
|
30
36
|
private handleLine;
|
|
31
37
|
private drainQueued;
|
package/dist/watcher.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAiC,aAAa,EAAE,MAAM,SAAS,CAAC;AAEvF,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,YAAY,CAAC;CAClG;AAED,qBAAa,OAAQ,SAAQ,YAAY;IACrC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"watcher.d.ts","sourceRoot":"","sources":["../src/watcher.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAiC,aAAa,EAAE,MAAM,SAAS,CAAC;AAEvF,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qFAAqF;IACrF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,YAAY,CAAC;CAClG;AAED,qBAAa,OAAQ,SAAQ,YAAY;IACrC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;IACrC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,QAAQ,CAKA;IAChB,oFAAoF;IACpF,OAAO,CAAC,SAAS,CAA4B;IAC7C,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,aAAa,CAGb;IACR,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,KAAK,CAAS;IAEtB,OAAO;IAyCP,IAAI,IAAI,IAAI,OAAO,CAElB;WAEY,KAAK,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAwDzD,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IA0BpD,OAAO,CAAC,QAAQ;IAahB,OAAO,CAAC,cAAc;IActB,OAAO,CAAC,QAAQ;IAWhB,OAAO,CAAC,UAAU;IA2BlB,OAAO,CAAC,WAAW;IAeb,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAa9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pentacore/vite-plugin-laravel-typefinder",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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",
|
|
@@ -32,17 +32,16 @@
|
|
|
32
32
|
"import": "./dist/index.js"
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
"
|
|
36
|
-
"
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@eslint/js": "^10.0.1",
|
|
40
40
|
"@types/node": "^24.19.1",
|
|
41
|
-
"@types/picomatch": "^4.0.3",
|
|
42
41
|
"@vitest/coverage-v8": "^5.1.0",
|
|
43
|
-
"eslint": "^10.
|
|
42
|
+
"eslint": "^10.15.0",
|
|
44
43
|
"typescript": "^6.0.3",
|
|
45
|
-
"typescript-eslint": "^8.
|
|
44
|
+
"typescript-eslint": "^8.73.0",
|
|
46
45
|
"vite": "^8.3.3",
|
|
47
46
|
"vite-plugin-dts": "^5.1.2",
|
|
48
47
|
"vitest": "^5.0.3"
|