@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 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
  }
@@ -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;IACj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@ -1,99 +1,106 @@
1
- import { exec as O } from "node:child_process";
2
- import { readFile as z } from "node:fs/promises";
3
- import p from "node:path";
4
- import { promisify as P } from "node:util";
5
- import { normalizePath as c } from "vite";
6
- const T = P(O);
7
- function C(h = {}) {
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: u = "php artisan ts:publish",
10
- filename: w = "laravel-ts-collected-files.json",
11
- directory: y = "resources/js/types/",
12
- runOnDevStart: v = !1,
13
- runOnBuildStart: $ = !0,
14
- reload: b = !0,
15
- failOnError: d
16
- } = h;
17
- let r, i;
18
- const t = /* @__PURE__ */ new Set();
19
- let n = "", l = !1, f = !1;
20
- const o = "[laravel-ts-publish]", m = async () => {
21
- t.clear();
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 z(n, "utf-8"), a = JSON.parse(e);
24
- for (const S of a) {
25
- const F = c(p.resolve(r.root, S));
26
- t.add(F);
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
- `${o} Manifest not found: ${n}`
32
+ `${a} Manifest not found: ${i}`
32
33
  );
33
34
  return;
34
35
  }
35
36
  r.logger.error(
36
- `${o} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
37
+ `${a} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
37
38
  );
38
39
  }
39
- }, g = () => {
40
- if (i)
41
- for (const e of t)
42
- i.watcher.add(e);
43
- }, E = () => d !== void 0 ? d : r.command === "build", s = async () => {
44
- if (l) {
45
- f = !0;
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
- l = !0;
49
+ u = !0;
50
+ const n = e && h ? h.replaceAll("{file}", e) : m;
49
51
  try {
50
- r.logger.info(`${o} Running: ${u}`, {
52
+ r.logger.info(`${a} Running: ${n}`, {
51
53
  timestamp: !0
52
- }), await T(u, { cwd: r.root }), r.logger.info(`${o} Types published successfully`, {
54
+ }), await F(n, { cwd: r.root }), r.logger.info(`${a} Types published successfully`, {
53
55
  timestamp: !0
54
- }), b && i && i.ws.send({ type: "full-reload" });
55
- } catch (e) {
56
- const a = `${o} Command failed: ${e instanceof Error ? e.message : String(e)}`;
57
- if (E())
58
- throw new Error(a, { cause: e });
59
- r.logger.error(a);
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
- l = !1, f && (f = !1, await s());
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, n = c(
69
- p.resolve(r.root, y, w)
73
+ r = e, i = d(
74
+ y.resolve(r.root, E, b)
70
75
  );
71
76
  },
72
77
  configureServer(e) {
73
- i = e;
78
+ s = e;
74
79
  },
75
80
  async buildStart() {
76
81
  if (r.command === "build") {
77
- $ && await s();
82
+ O && await c();
78
83
  return;
79
84
  }
80
- await m(), g(), t.size > 0 && r.logger.info(
81
- `${o} Watching ${t.size} PHP file${t.size === 1 ? "" : "s"} for changes`,
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
- ), v && await s();
88
+ ), S && await c();
84
89
  },
85
90
  async handleHotUpdate({ file: e }) {
86
- const a = c(e);
87
- if (a === n)
91
+ const n = d(e);
92
+ if (n === i)
88
93
  return r.logger.info(
89
- `${o} Manifest changed, reloading watched files`,
94
+ `${a} Manifest changed, reloading watched files`,
90
95
  { timestamp: !0 }
91
- ), await m(), g(), [];
92
- if (t.has(a))
93
- return await s(), [];
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
- C as laravelTsPublish
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",
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.1"
26
+ "@tolki/types": "^1.1.2"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "vite": "^7.0.0"