@tolki/enum 0.0.2 → 0.0.3

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
@@ -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,31 @@ 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. It will reload the page after you make any update to any of the transformed PHP files.
124
- 4. It will call the publish command on `vite build` before bundling.
125
- 5. It will throw an error if the publish command fails on `vite build`.
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
+
152
+ #### Manifest Updates
153
+
154
+ The collected-files manifest is treated as configuration input for the watcher, not as a publish trigger.
155
+
156
+ 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
157
 
127
158
  ### Plugin Options
128
159
 
@@ -140,9 +171,14 @@ export default defineConfig({
140
171
  /**
141
172
  * The publish command to run when a watched PHP file changes.
142
173
  *
143
- * If you use Sail and run your Vite dev server inside the Sail container,
144
- * you may need to change this command to `sail php artisan ts:publish`
145
- * or `./vendor/bin/sail php artisan ts:publish` depending on your setup.
174
+ * This command runs through Node's `exec()` from the Vite project root.
175
+ * Shell aliases like `sail` are usually not available here.
176
+ *
177
+ * If Vite runs on the host machine and your app uses Sail, prefer
178
+ * `./vendor/bin/sail artisan ts:publish`.
179
+ *
180
+ * If Vite already runs inside the PHP container, use
181
+ * `php artisan ts:publish`.
146
182
  */
147
183
  command: "php artisan ts:publish",
148
184
  /**
@@ -186,4 +222,34 @@ export default defineConfig({
186
222
  });
187
223
  ```
188
224
 
225
+ #### Example for a Host-Machine Vite Dev Server with Sail
226
+
227
+ ```javascript
228
+ import { defineConfig } from "vite";
229
+ import { laravelTsPublish } from "@tolki/enum/vite";
230
+
231
+ export default defineConfig({
232
+ plugins: [
233
+ laravelTsPublish({
234
+ command: "./vendor/bin/sail artisan ts:publish",
235
+ }),
236
+ ],
237
+ });
238
+ ```
239
+
240
+ #### Example for Vite Running Inside the Container
241
+
242
+ ```javascript
243
+ import { defineConfig } from "vite";
244
+ import { laravelTsPublish } from "@tolki/enum/vite";
245
+
246
+ export default defineConfig({
247
+ plugins: [
248
+ laravelTsPublish({
249
+ command: "php artisan ts:publish",
250
+ }),
251
+ ],
252
+ });
253
+ ```
254
+
189
255
  <!-- AUTO-GENERATED-DOCS:END -->
@@ -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;
@@ -63,7 +71,12 @@ export interface LaravelTsPublishOptions {
63
71
  * PHP files to the dev-server file watcher, and re-runs the command when any
64
72
  * of them change via HMR. Optionally runs the command once at startup when
65
73
  * `runOnDevStart` is `true`. Sends a full browser reload after every
66
- * successful run (disable with `reload: false`).
74
+ * successful run (disable with `reload: false`). Manifest updates only
75
+ * refresh the watched-file list and do not trigger the command again.
76
+ * - **Command execution**: the configured command runs through Node's
77
+ * `child_process.exec()` from the Vite project root. Shell aliases are not
78
+ * resolved, so use a real executable path such as `./vendor/bin/sail` when
79
+ * running Vite on the host with Laravel Sail.
67
80
  *
68
81
  * @param options - Configuration options for the plugin.
69
82
  * @returns A Vite plugin object.
@@ -85,7 +98,14 @@ export interface LaravelTsPublishOptions {
85
98
  * ```ts
86
99
  * // With Laravel Sail
87
100
  * laravelTsPublish({
88
- * command: "sail artisan ts:publish",
101
+ * command: "./vendor/bin/sail artisan ts:publish",
102
+ * });
103
+ * ```
104
+ * @example
105
+ * ```ts
106
+ * // When Vite is already running inside the PHP container
107
+ * laravelTsPublish({
108
+ * command: "php artisan ts:publish",
89
109
  * });
90
110
  * ```
91
111
  *
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],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,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CA6LR"}
@@ -16,56 +16,56 @@ function C(h = {}) {
16
16
  } = h;
17
17
  let r, i;
18
18
  const t = /* @__PURE__ */ new Set();
19
- let s = "", l = !1, f = !1;
20
- const a = "[laravel-ts-publish]", m = async () => {
19
+ let n = "", l = !1, f = !1;
20
+ const o = "[laravel-ts-publish]", m = async () => {
21
21
  t.clear();
22
22
  try {
23
- const e = await z(s, "utf-8"), o = JSON.parse(e);
24
- for (const S of o) {
23
+ const e = await z(n, "utf-8"), a = JSON.parse(e);
24
+ for (const S of a) {
25
25
  const F = c(p.resolve(r.root, S));
26
26
  t.add(F);
27
27
  }
28
28
  } catch (e) {
29
29
  if (e instanceof Error && e.code === "ENOENT") {
30
30
  r.logger.warn(
31
- `${a} Manifest not found: ${s}`
31
+ `${o} Manifest not found: ${n}`
32
32
  );
33
33
  return;
34
34
  }
35
35
  r.logger.error(
36
- `${a} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
36
+ `${o} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
37
37
  );
38
38
  }
39
39
  }, g = () => {
40
40
  if (i)
41
41
  for (const e of t)
42
42
  i.watcher.add(e);
43
- }, E = () => d !== void 0 ? d : r.command === "build", n = async () => {
43
+ }, E = () => d !== void 0 ? d : r.command === "build", s = async () => {
44
44
  if (l) {
45
45
  f = !0;
46
46
  return;
47
47
  }
48
48
  l = !0;
49
49
  try {
50
- r.logger.info(`${a} Running: ${u}`, {
50
+ r.logger.info(`${o} Running: ${u}`, {
51
51
  timestamp: !0
52
- }), await T(u, { cwd: r.root }), r.logger.info(`${a} Types published successfully`, {
52
+ }), await T(u, { cwd: r.root }), r.logger.info(`${o} Types published successfully`, {
53
53
  timestamp: !0
54
54
  }), b && i && i.ws.send({ type: "full-reload" });
55
55
  } catch (e) {
56
- const o = `${a} Command failed: ${e instanceof Error ? e.message : String(e)}`;
56
+ const a = `${o} Command failed: ${e instanceof Error ? e.message : String(e)}`;
57
57
  if (E())
58
- throw new Error(o, { cause: e });
59
- r.logger.error(o);
58
+ throw new Error(a, { cause: e });
59
+ r.logger.error(a);
60
60
  } finally {
61
- l = !1, f && (f = !1, await n());
61
+ l = !1, f && (f = !1, await s());
62
62
  }
63
63
  };
64
64
  return {
65
65
  name: "@tolki/vite-plugin-laravel-ts-publish",
66
66
  enforce: "pre",
67
67
  configResolved(e) {
68
- r = e, s = c(
68
+ r = e, n = c(
69
69
  p.resolve(r.root, y, w)
70
70
  );
71
71
  },
@@ -74,23 +74,23 @@ function C(h = {}) {
74
74
  },
75
75
  async buildStart() {
76
76
  if (r.command === "build") {
77
- $ && await n();
77
+ $ && await s();
78
78
  return;
79
79
  }
80
80
  await m(), g(), t.size > 0 && r.logger.info(
81
- `${a} Watching ${t.size} PHP file${t.size === 1 ? "" : "s"} for changes`,
81
+ `${o} Watching ${t.size} PHP file${t.size === 1 ? "" : "s"} for changes`,
82
82
  { timestamp: !0 }
83
- ), v && await n();
83
+ ), v && await s();
84
84
  },
85
85
  async handleHotUpdate({ file: e }) {
86
- const o = c(e);
87
- if (o === s)
86
+ const a = c(e);
87
+ if (a === n)
88
88
  return r.logger.info(
89
- `${a} Manifest changed, reloading watched files`,
89
+ `${o} Manifest changed, reloading watched files`,
90
90
  { timestamp: !0 }
91
- ), await m(), g(), await n(), [];
92
- if (t.has(o))
93
- return await n(), [];
91
+ ), await m(), g(), [];
92
+ if (t.has(a))
93
+ return await s(), [];
94
94
  }
95
95
  };
96
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/enum",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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",