@tolki/enum 0.0.2 → 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 +105 -6
- package/dist/enums.js +3 -3
- package/dist/vite-plugin.d.ts +38 -2
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +62 -55
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -101,6 +101,21 @@ The `@tolki/enum` package provides a Vite plugin to automatically watch for chan
|
|
|
101
101
|
|
|
102
102
|
The Laravel TypeScript Publisher package can publish a JSON file list of transformed PHP files. This Vite plugin uses that JSON file list to watch for changes in those PHP files and automatically call the `php artisan ts:publish` command to transform the changed PHP files into TypeScript files.
|
|
103
103
|
|
|
104
|
+
### Command Execution Notes
|
|
105
|
+
|
|
106
|
+
The plugin runs the configured `command` with Node's `child_process.exec()` from the Vite project root.
|
|
107
|
+
|
|
108
|
+
This has two important consequences:
|
|
109
|
+
|
|
110
|
+
1. The command runs in a non-interactive shell.
|
|
111
|
+
2. Shell aliases such as `sail` are usually not available.
|
|
112
|
+
|
|
113
|
+
If you are using Laravel Sail and Vite is running on your host machine, prefer `./vendor/bin/sail artisan ts:publish` instead of `sail artisan ts:publish`.
|
|
114
|
+
|
|
115
|
+
If Vite is already running inside the PHP container, use `php artisan ts:publish`.
|
|
116
|
+
|
|
117
|
+
When the publish command rewrites the collected-files manifest, the plugin only reloads the watched file list. It does not run the publish command again for that manifest update, which prevents command loops.
|
|
118
|
+
|
|
104
119
|
### Usage
|
|
105
120
|
|
|
106
121
|
To use the Vite plugin, you need to add it to your Vite configuration file. Below is an example of how to add the plugin to your Vite configuration file:
|
|
@@ -114,15 +129,50 @@ export default defineConfig({
|
|
|
114
129
|
});
|
|
115
130
|
```
|
|
116
131
|
|
|
132
|
+
#### Laravel Sail
|
|
133
|
+
|
|
134
|
+
Choose the command based on where `vite dev` is running:
|
|
135
|
+
|
|
136
|
+
- Vite running on the host machine: `./vendor/bin/sail artisan ts:publish`
|
|
137
|
+
- Vite running inside the container: `php artisan ts:publish`
|
|
138
|
+
|
|
139
|
+
Using just `sail artisan ts:publish` often fails because `sail` is commonly defined as a shell alias and aliases are not resolved by `exec()`.
|
|
140
|
+
|
|
117
141
|
### Default Functionality
|
|
118
142
|
|
|
119
143
|
By default, the plugin will work in the following way:
|
|
120
144
|
|
|
121
145
|
1. It will call `php artisan ts:publish` as the republish command when a file changes.
|
|
122
146
|
2. It will look for the list of transformed PHP files here: `resources/js/types/laravel-ts-collected-files.json`.
|
|
123
|
-
3.
|
|
124
|
-
4. It will
|
|
125
|
-
5. It will
|
|
147
|
+
3. If that manifest file changes, it will reload the watched file list without calling the publish command again.
|
|
148
|
+
4. It will reload the page after a successful publish triggered by a watched PHP file change.
|
|
149
|
+
5. It will call the publish command on `vite build` before bundling.
|
|
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.
|
|
170
|
+
|
|
171
|
+
#### Manifest Updates
|
|
172
|
+
|
|
173
|
+
The collected-files manifest is treated as configuration input for the watcher, not as a publish trigger.
|
|
174
|
+
|
|
175
|
+
That means when `ts:publish` updates `resources/js/types/laravel-ts-collected-files.json`, the plugin will refresh its internal watched-file list and continue. It will not immediately run `ts:publish` again from that manifest write.
|
|
126
176
|
|
|
127
177
|
### Plugin Options
|
|
128
178
|
|
|
@@ -140,9 +190,14 @@ export default defineConfig({
|
|
|
140
190
|
/**
|
|
141
191
|
* The publish command to run when a watched PHP file changes.
|
|
142
192
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
193
|
+
* This command runs through Node's `exec()` from the Vite project root.
|
|
194
|
+
* Shell aliases like `sail` are usually not available here.
|
|
195
|
+
*
|
|
196
|
+
* If Vite runs on the host machine and your app uses Sail, prefer
|
|
197
|
+
* `./vendor/bin/sail artisan ts:publish`.
|
|
198
|
+
*
|
|
199
|
+
* If Vite already runs inside the PHP container, use
|
|
200
|
+
* `php artisan ts:publish`.
|
|
146
201
|
*/
|
|
147
202
|
command: "php artisan ts:publish",
|
|
148
203
|
/**
|
|
@@ -181,6 +236,50 @@ export default defineConfig({
|
|
|
181
236
|
* When specified, it will apply to both `vite dev` and `vite build`.
|
|
182
237
|
*/
|
|
183
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}"',
|
|
253
|
+
}),
|
|
254
|
+
],
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
#### Example for a Host-Machine Vite Dev Server with Sail
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
import { defineConfig } from "vite";
|
|
262
|
+
import { laravelTsPublish } from "@tolki/enum/vite";
|
|
263
|
+
|
|
264
|
+
export default defineConfig({
|
|
265
|
+
plugins: [
|
|
266
|
+
laravelTsPublish({
|
|
267
|
+
command: "./vendor/bin/sail artisan ts:publish",
|
|
268
|
+
}),
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
#### Example for Vite Running Inside the Container
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
import { defineConfig } from "vite";
|
|
277
|
+
import { laravelTsPublish } from "@tolki/enum/vite";
|
|
278
|
+
|
|
279
|
+
export default defineConfig({
|
|
280
|
+
plugins: [
|
|
281
|
+
laravelTsPublish({
|
|
282
|
+
command: "php artisan ts:publish",
|
|
184
283
|
}),
|
|
185
284
|
],
|
|
186
285
|
});
|
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
|
@@ -3,6 +3,14 @@ export interface LaravelTsPublishOptions {
|
|
|
3
3
|
/**
|
|
4
4
|
* The command to run when a watched PHP file changes.
|
|
5
5
|
*
|
|
6
|
+
* The command is executed with Node's `exec()` using the Vite project root
|
|
7
|
+
* as the current working directory. Because it runs in a non-interactive
|
|
8
|
+
* shell, shell aliases such as `sail` are usually not available.
|
|
9
|
+
*
|
|
10
|
+
* Common setups:
|
|
11
|
+
* - Run Vite on the host machine with Laravel Sail: `./vendor/bin/sail artisan ts:publish`
|
|
12
|
+
* - Run Vite inside the container: `php artisan ts:publish`
|
|
13
|
+
*
|
|
6
14
|
* @default "php artisan ts:publish"
|
|
7
15
|
*/
|
|
8
16
|
command?: string;
|
|
@@ -51,6 +59,22 @@ export interface LaravelTsPublishOptions {
|
|
|
51
59
|
* during `vite dev`.
|
|
52
60
|
*/
|
|
53
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;
|
|
54
78
|
}
|
|
55
79
|
/**
|
|
56
80
|
* Vite plugin that watches PHP source files listed in the Laravel TypeScript
|
|
@@ -63,7 +87,12 @@ export interface LaravelTsPublishOptions {
|
|
|
63
87
|
* PHP files to the dev-server file watcher, and re-runs the command when any
|
|
64
88
|
* of them change via HMR. Optionally runs the command once at startup when
|
|
65
89
|
* `runOnDevStart` is `true`. Sends a full browser reload after every
|
|
66
|
-
* successful run (disable with `reload: false`).
|
|
90
|
+
* successful run (disable with `reload: false`). Manifest updates only
|
|
91
|
+
* refresh the watched-file list and do not trigger the command again.
|
|
92
|
+
* - **Command execution**: the configured command runs through Node's
|
|
93
|
+
* `child_process.exec()` from the Vite project root. Shell aliases are not
|
|
94
|
+
* resolved, so use a real executable path such as `./vendor/bin/sail` when
|
|
95
|
+
* running Vite on the host with Laravel Sail.
|
|
67
96
|
*
|
|
68
97
|
* @param options - Configuration options for the plugin.
|
|
69
98
|
* @returns A Vite plugin object.
|
|
@@ -85,7 +114,14 @@ export interface LaravelTsPublishOptions {
|
|
|
85
114
|
* ```ts
|
|
86
115
|
* // With Laravel Sail
|
|
87
116
|
* laravelTsPublish({
|
|
88
|
-
* command: "sail artisan ts:publish",
|
|
117
|
+
* command: "./vendor/bin/sail artisan ts:publish",
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* // When Vite is already running inside the PHP container
|
|
123
|
+
* laravelTsPublish({
|
|
124
|
+
* command: "php artisan ts:publish",
|
|
89
125
|
* });
|
|
90
126
|
* ```
|
|
91
127
|
*
|
|
@@ -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
|
|
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,34 +1,35 @@
|
|
|
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
|
-
`${a} Manifest not found: ${
|
|
32
|
+
`${a} Manifest not found: ${i}`
|
|
32
33
|
);
|
|
33
34
|
return;
|
|
34
35
|
}
|
|
@@ -36,64 +37,70 @@ function C(h = {}) {
|
|
|
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(`${a} Running: ${
|
|
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
|
-
`${a} Watching ${
|
|
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"
|