@tolki/enum 0.0.3 → 0.0.4
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 +33 -0
- package/dist/enums.js +3 -3
- package/dist/vite-plugin.d.ts +16 -0
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +64 -57
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -148,6 +148,25 @@ By default, the plugin will work in the following way:
|
|
|
148
148
|
4. It will reload the page after a successful publish triggered by a watched PHP file change.
|
|
149
149
|
5. It will call the publish command on `vite build` before bundling.
|
|
150
150
|
6. It will throw an error if the publish command fails on `vite build`.
|
|
151
|
+
7. When a single PHP file changes during `vite dev`, it will use `--source` to republish only that file instead of running a full publish.
|
|
152
|
+
|
|
153
|
+
#### Single-File Republishing
|
|
154
|
+
|
|
155
|
+
The JSON file list manifest uses the `filepath[]` array format (produced by `laravel-ts-publish`), the plugin will automatically use the `--source` flag to republish only the changed file during development:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Instead of running the full command:
|
|
159
|
+
php artisan ts:publish
|
|
160
|
+
|
|
161
|
+
# The plugin runs a targeted command:
|
|
162
|
+
php artisan ts:publish --source="app/Enums/Status.php"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
This can reduce per-change latency from seconds to near-instant on large projects with hundreds of files.
|
|
166
|
+
|
|
167
|
+
The plugin derives the source command automatically from the `command` option by appending `--source="{file}"`. You can customize this with the `sourceCommand` option or disable it entirely by setting `sourceCommand: false`.
|
|
168
|
+
|
|
169
|
+
Full startup commands (`runOnDevStart`, `runOnBuildStart`) always use the full `command` to ensure all files are generated.
|
|
151
170
|
|
|
152
171
|
#### Manifest Updates
|
|
153
172
|
|
|
@@ -217,6 +236,20 @@ export default defineConfig({
|
|
|
217
236
|
* When specified, it will apply to both `vite dev` and `vite build`.
|
|
218
237
|
*/
|
|
219
238
|
failOnError: undefined,
|
|
239
|
+
/**
|
|
240
|
+
* The command template for single-file republishing during `vite dev`.
|
|
241
|
+
*
|
|
242
|
+
* When a watched PHP file changes, this command is used instead of the
|
|
243
|
+
* full `command`. The `{file}` placeholder is replaced with the relative
|
|
244
|
+
* file path from the manifest for the changed file (exactly as it
|
|
245
|
+
* appears in the manifest array).
|
|
246
|
+
*
|
|
247
|
+
* When not specified, it is auto-derived by appending
|
|
248
|
+
* ` --source="{file}"` to the `command` option.
|
|
249
|
+
*
|
|
250
|
+
* Set to `false` to always run the full command.
|
|
251
|
+
*/
|
|
252
|
+
sourceCommand: 'php artisan ts:publish --source="{file}"',
|
|
220
253
|
}),
|
|
221
254
|
],
|
|
222
255
|
});
|
package/dist/enums.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function a(e, t) {
|
|
2
|
-
const n = new Set(e._cases);
|
|
2
|
+
const n = new Set(e._cases ?? []);
|
|
3
3
|
let r;
|
|
4
4
|
for (const s of n)
|
|
5
5
|
if (e[s] === t) {
|
|
@@ -12,7 +12,7 @@ function a(e, t) {
|
|
|
12
12
|
`Value "${String(t)}" does not match any case in the enum. Values: ${s.join(", ")}, Cases: ${[...n].join(", ")}`
|
|
13
13
|
);
|
|
14
14
|
}
|
|
15
|
-
const c = { value: t }, h = new Set(e._methods), i = e._helpers, f = new Set(
|
|
15
|
+
const c = { value: t }, h = new Set(e._methods ?? []), i = e._helpers, f = new Set(
|
|
16
16
|
Array.isArray(i) ? i : []
|
|
17
17
|
), l = /* @__PURE__ */ new Set([
|
|
18
18
|
"_cases",
|
|
@@ -32,7 +32,7 @@ function y(e, t) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function p(e) {
|
|
35
|
-
return e._cases.map(
|
|
35
|
+
return (e._cases ?? []).map(
|
|
36
36
|
(t) => a(e, e[t])
|
|
37
37
|
);
|
|
38
38
|
}
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -59,6 +59,22 @@ export interface LaravelTsPublishOptions {
|
|
|
59
59
|
* during `vite dev`.
|
|
60
60
|
*/
|
|
61
61
|
failOnError?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The command template for single-file republishing during `vite dev`.
|
|
64
|
+
*
|
|
65
|
+
* When a watched PHP file changes, this command is used instead of the
|
|
66
|
+
* full `command` to republish only the changed file. The `{file}`
|
|
67
|
+
* placeholder is replaced with the relative file path from the manifest.
|
|
68
|
+
*
|
|
69
|
+
* When not specified, it is auto-derived by appending
|
|
70
|
+
* ` --source="{file}"` to the `command` option.
|
|
71
|
+
*
|
|
72
|
+
* Set to `false` to disable single-file republishing and always run
|
|
73
|
+
* the full command.
|
|
74
|
+
*
|
|
75
|
+
* @default Derived from the `command` option: 'php artisan ts:publish --source="{file}"'
|
|
76
|
+
*/
|
|
77
|
+
sourceCommand?: string | false;
|
|
62
78
|
}
|
|
63
79
|
/**
|
|
64
80
|
* Vite plugin that watches PHP source files listed in the Laravel TypeScript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,MAAM,WAAW,uBAAuB;IACpC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;;;;;;;;OAcG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CAiNR"}
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,99 +1,106 @@
|
|
|
1
|
-
import { exec as
|
|
2
|
-
import { readFile as
|
|
3
|
-
import
|
|
4
|
-
import { promisify as
|
|
5
|
-
import { normalizePath as
|
|
6
|
-
const
|
|
7
|
-
function
|
|
1
|
+
import { exec as P } from "node:child_process";
|
|
2
|
+
import { readFile as T } from "node:fs/promises";
|
|
3
|
+
import y from "node:path";
|
|
4
|
+
import { promisify as x } from "node:util";
|
|
5
|
+
import { normalizePath as d } from "vite";
|
|
6
|
+
const F = x(P);
|
|
7
|
+
function k($ = {}) {
|
|
8
8
|
const {
|
|
9
|
-
command:
|
|
10
|
-
filename:
|
|
11
|
-
directory:
|
|
12
|
-
runOnDevStart:
|
|
13
|
-
runOnBuildStart:
|
|
14
|
-
reload:
|
|
15
|
-
failOnError:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
command: m = "php artisan ts:publish",
|
|
10
|
+
filename: b = "laravel-ts-collected-files.json",
|
|
11
|
+
directory: E = "resources/js/types/",
|
|
12
|
+
runOnDevStart: S = !1,
|
|
13
|
+
runOnBuildStart: O = !0,
|
|
14
|
+
reload: C = !0,
|
|
15
|
+
failOnError: g,
|
|
16
|
+
sourceCommand: p
|
|
17
|
+
} = $, h = p === !1 ? !1 : p ?? `${m} --source="{file}"`;
|
|
18
|
+
let r, s;
|
|
19
|
+
const o = /* @__PURE__ */ new Map();
|
|
20
|
+
let i = "", u = !1;
|
|
21
|
+
const l = [], a = "[laravel-ts-publish]", w = async () => {
|
|
22
|
+
o.clear();
|
|
22
23
|
try {
|
|
23
|
-
const e = await
|
|
24
|
-
for (const
|
|
25
|
-
const
|
|
26
|
-
|
|
24
|
+
const e = await T(i, "utf-8"), n = JSON.parse(e);
|
|
25
|
+
for (const t of n) {
|
|
26
|
+
const f = d(y.resolve(r.root, t));
|
|
27
|
+
o.set(f, t);
|
|
27
28
|
}
|
|
28
29
|
} catch (e) {
|
|
29
30
|
if (e instanceof Error && e.code === "ENOENT") {
|
|
30
31
|
r.logger.warn(
|
|
31
|
-
`${
|
|
32
|
+
`${a} Manifest not found: ${i}`
|
|
32
33
|
);
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
35
36
|
r.logger.error(
|
|
36
|
-
`${
|
|
37
|
+
`${a} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
|
|
37
38
|
);
|
|
38
39
|
}
|
|
39
|
-
},
|
|
40
|
-
if (
|
|
41
|
-
for (const e of
|
|
42
|
-
|
|
43
|
-
},
|
|
44
|
-
if (
|
|
45
|
-
|
|
40
|
+
}, v = () => {
|
|
41
|
+
if (s)
|
|
42
|
+
for (const e of o.keys())
|
|
43
|
+
s.watcher.add(e);
|
|
44
|
+
}, z = () => g !== void 0 ? g : r.command === "build", c = async (e = null) => {
|
|
45
|
+
if (u) {
|
|
46
|
+
l.includes(e) || l.push(e);
|
|
46
47
|
return;
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
u = !0;
|
|
50
|
+
const n = e && h ? h.replaceAll("{file}", e) : m;
|
|
49
51
|
try {
|
|
50
|
-
r.logger.info(`${
|
|
52
|
+
r.logger.info(`${a} Running: ${n}`, {
|
|
51
53
|
timestamp: !0
|
|
52
|
-
}), await
|
|
54
|
+
}), await F(n, { cwd: r.root }), r.logger.info(`${a} Types published successfully`, {
|
|
53
55
|
timestamp: !0
|
|
54
|
-
}),
|
|
55
|
-
} catch (
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
throw new Error(
|
|
59
|
-
r.logger.error(
|
|
56
|
+
}), C && s && s.ws.send({ type: "full-reload" });
|
|
57
|
+
} catch (t) {
|
|
58
|
+
const f = `${a} Command failed: ${t instanceof Error ? t.message : String(t)}`;
|
|
59
|
+
if (z())
|
|
60
|
+
throw new Error(f, { cause: t });
|
|
61
|
+
r.logger.error(f);
|
|
60
62
|
} finally {
|
|
61
|
-
|
|
63
|
+
if (u = !1, l.length > 0) {
|
|
64
|
+
const t = l.shift();
|
|
65
|
+
await c(t);
|
|
66
|
+
}
|
|
62
67
|
}
|
|
63
68
|
};
|
|
64
69
|
return {
|
|
65
70
|
name: "@tolki/vite-plugin-laravel-ts-publish",
|
|
66
71
|
enforce: "pre",
|
|
67
72
|
configResolved(e) {
|
|
68
|
-
r = e,
|
|
69
|
-
|
|
73
|
+
r = e, i = d(
|
|
74
|
+
y.resolve(r.root, E, b)
|
|
70
75
|
);
|
|
71
76
|
},
|
|
72
77
|
configureServer(e) {
|
|
73
|
-
|
|
78
|
+
s = e;
|
|
74
79
|
},
|
|
75
80
|
async buildStart() {
|
|
76
81
|
if (r.command === "build") {
|
|
77
|
-
|
|
82
|
+
O && await c();
|
|
78
83
|
return;
|
|
79
84
|
}
|
|
80
|
-
await
|
|
81
|
-
`${
|
|
85
|
+
await w(), v(), o.size > 0 && r.logger.info(
|
|
86
|
+
`${a} Watching ${o.size} PHP file${o.size === 1 ? "" : "s"} for changes`,
|
|
82
87
|
{ timestamp: !0 }
|
|
83
|
-
),
|
|
88
|
+
), S && await c();
|
|
84
89
|
},
|
|
85
90
|
async handleHotUpdate({ file: e }) {
|
|
86
|
-
const
|
|
87
|
-
if (
|
|
91
|
+
const n = d(e);
|
|
92
|
+
if (n === i)
|
|
88
93
|
return r.logger.info(
|
|
89
|
-
`${
|
|
94
|
+
`${a} Manifest changed, reloading watched files`,
|
|
90
95
|
{ timestamp: !0 }
|
|
91
|
-
), await
|
|
92
|
-
if (
|
|
93
|
-
|
|
96
|
+
), await w(), v(), [];
|
|
97
|
+
if (o.has(n)) {
|
|
98
|
+
const t = o.get(n) ?? null;
|
|
99
|
+
return await c(t), [];
|
|
100
|
+
}
|
|
94
101
|
}
|
|
95
102
|
};
|
|
96
103
|
}
|
|
97
104
|
export {
|
|
98
|
-
|
|
105
|
+
k as laravelTsPublish
|
|
99
106
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolki/enum",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "A set of enum utilities for the @tolki packages.",
|
|
5
5
|
"author": "Abraham Arango <https://github.com/abetwothree>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"utilities"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@tolki/types": "^1.1.
|
|
26
|
+
"@tolki/types": "^1.1.2"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"vite": "^7.0.0"
|