@tolki/ts 1.0.3 → 1.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.
@@ -1,14 +1,6 @@
1
+ import { escapeShellArg } from '@tolki/utils';
1
2
  import { Plugin } from 'vite';
2
- /**
3
- * Escape a value for safe interpolation into a shell command string.
4
- *
5
- * Uses POSIX single-quote wrapping: the only character that requires
6
- * escaping inside single quotes is the single quote itself.
7
- *
8
- * @param value - The raw string to escape.
9
- * @returns A shell-safe string.
10
- */
11
- export declare function escapeShellArg(value: string): string;
3
+ export { escapeShellArg };
12
4
  export interface LaravelTsPublishOptions {
13
5
  /**
14
6
  * The command to run when a watched PHP file changes.
@@ -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;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAUpD;AAED,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;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CAuPR"}
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAyB,MAAM,cAAc,CAAC;AACrE,OAAO,EAEH,KAAK,MAAM,EAGd,MAAM,MAAM,CAAC;AAId,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B,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;;;;;;;;;;;;;;;OAeG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAC/B;;;;;;;;;;OAUG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,wBAAgB,gBAAgB,CAC5B,OAAO,GAAE,uBAA4B,GACtC,MAAM,CA4PR"}
@@ -1,35 +1,37 @@
1
1
  import { exec as R } from "node:child_process";
2
- import { readFile as W } from "node:fs/promises";
2
+ import { readFile as k } from "node:fs/promises";
3
3
  import q from "node:path";
4
- import { promisify as k } from "node:util";
5
- import { normalizePath as p } from "vite";
6
- const B = k(R);
7
- function H(a) {
8
- return a === "" ? "''" : /^[\w@%+=:,./-]+$/.test(a) ? a : "'" + a.replace(/'/g, "'\\''") + "'";
4
+ import { promisify as B } from "node:util";
5
+ import { escapeWindowsShellArg as H, escapeShellArg as D } from "@tolki/utils";
6
+ import { escapeShellArg as _ } from "@tolki/utils";
7
+ import { normalizePath as w } from "vite";
8
+ const J = B(R);
9
+ function L(c) {
10
+ return process.platform === "win32" ? H(c) : D(c);
9
11
  }
10
- function G(a = {}) {
12
+ function X(c = {}) {
11
13
  const {
12
- command: l = "php artisan ts:publish",
13
- filename: z = "laravel-ts-collected-files.json",
14
- directory: F = "resources/js/types/data/",
14
+ command: a = "php artisan ts:publish",
15
+ filename: x = "laravel-ts-collected-files.json",
16
+ directory: z = "resources/js/types/data/",
15
17
  runOnDevStart: P = !1,
16
18
  runOnBuildStart: T = !0,
17
- reload: x = !0,
18
- failOnError: h,
19
- sourceCommand: w,
19
+ reload: F = !0,
20
+ failOnError: y,
21
+ sourceCommand: $,
20
22
  onBuildOnlyFunctional: M = !0,
21
- quiet: y = !0
22
- } = a, $ = w === !1 ? !1 : w ?? `${l} --source={file}`;
23
- let t, c;
23
+ quiet: v = !0
24
+ } = c, f = $ === !1 ? !1 : $ ?? `${a} --source={file}`;
25
+ let t, l;
24
26
  const r = /* @__PURE__ */ new Map();
25
- let u = "", g = !1;
27
+ let u = "", p = !1;
26
28
  const d = [], n = "[laravel-ts-publish]", b = async () => {
27
29
  r.clear();
28
30
  try {
29
- const e = await W(u, "utf-8"), o = JSON.parse(e);
30
- for (const f of o) {
31
- const s = p(q.resolve(t.root, f));
32
- r.set(s, f);
31
+ const e = await k(u, "utf-8"), o = JSON.parse(e);
32
+ for (const i of o) {
33
+ const g = w(q.resolve(t.root, i));
34
+ r.set(g, i);
33
35
  }
34
36
  } catch (e) {
35
37
  if (e instanceof Error && e.code === "ENOENT") {
@@ -42,40 +44,44 @@ function G(a = {}) {
42
44
  `${n} Failed to read manifest: ${e instanceof Error ? e.message : String(e)}`
43
45
  );
44
46
  }
45
- }, v = () => {
46
- if (c)
47
+ }, S = () => {
48
+ if (l)
47
49
  for (const e of r.keys())
48
- c.watcher.add(e);
49
- }, j = () => h !== void 0 ? h : t.command === "build", m = async (e = null, o) => {
50
- if (g) {
50
+ l.watcher.add(e);
51
+ }, W = () => y !== void 0 ? y : t.command === "build", m = async (e = null, o) => {
52
+ if (p) {
51
53
  d.includes(e) || d.push(e);
52
54
  return;
53
55
  }
54
- g = !0;
55
- let s = e && $ ? $.replaceAll(
56
- "{file}",
57
- H(e)
58
- ) : o ?? l;
59
- y && !s.includes("--quiet") && (s += " --quiet");
56
+ p = !0;
57
+ const i = o ?? a, g = e && f ? f : i;
58
+ let h = e && f ? (
59
+ // A function replacer keeps `$&` and friends in the path literal.
60
+ f.replaceAll(
61
+ "{file}",
62
+ () => L(e)
63
+ )
64
+ ) : i;
65
+ v && !g.includes("--quiet") && (h += " --quiet");
60
66
  try {
61
- t.logger.info(`${n} Running: ${s}`, {
67
+ t.logger.info(`${n} Running: ${h}`, {
62
68
  timestamp: !0
63
- }), await B(s, { cwd: t.root }), t.logger.info(`${n} Types published successfully`, {
69
+ }), await J(h, { cwd: t.root }), t.logger.info(`${n} Types published successfully`, {
64
70
  timestamp: !0
65
- }), x && c && c.ws.send({ type: "full-reload" });
66
- } catch (i) {
67
- const C = i instanceof Error ? i.message : String(i), { stdout: A, stderr: N } = i, O = [N?.trim(), A?.trim()].filter(
68
- (E) => !!E && !C.includes(E)
71
+ }), F && l && l.ws.send({ type: "full-reload" });
72
+ } catch (s) {
73
+ const O = s instanceof Error ? s.message : String(s), { stdout: j, stderr: N } = s, C = [N?.trim(), j?.trim()].filter(
74
+ (A) => !!A && !O.includes(A)
69
75
  ).join(`
70
- `), S = `${n} Command failed: ${C}${O ? `
71
- ${O}` : ""}`;
72
- if (j())
73
- throw new Error(S, { cause: i });
74
- t.logger.error(S);
76
+ `), E = `${n} Command failed: ${O}${C ? `
77
+ ${C}` : ""}`;
78
+ if (W())
79
+ throw new Error(E, { cause: s });
80
+ t.logger.error(E);
75
81
  } finally {
76
- if (g = !1, d.length > 0) {
77
- const i = d.shift();
78
- await m(i);
82
+ if (p = !1, d.length > 0) {
83
+ const s = d.shift();
84
+ await m(s);
79
85
  }
80
86
  }
81
87
  };
@@ -83,41 +89,41 @@ ${O}` : ""}`;
83
89
  name: "@tolki/vite-plugin-laravel-ts-publish",
84
90
  enforce: "pre",
85
91
  configResolved(e) {
86
- t = e, u = p(
87
- q.resolve(t.root, F, z)
92
+ t = e, u = w(
93
+ q.resolve(t.root, z, x)
88
94
  );
89
95
  },
90
96
  configureServer(e) {
91
- c = e;
97
+ l = e;
92
98
  },
93
99
  async buildStart() {
94
100
  if (t.command === "build") {
95
101
  if (T) {
96
- let e = M && !l.includes("--only-functional") ? `${l} --only-functional` : l;
97
- y && !e.includes("--quiet") && (e += " --quiet"), await m(null, e);
102
+ let e = M && !a.includes("--only-functional") ? `${a} --only-functional` : a;
103
+ v && !e.includes("--quiet") && (e += " --quiet"), await m(null, e);
98
104
  }
99
105
  return;
100
106
  }
101
- await b(), v(), r.size > 0 && t.logger.info(
107
+ await b(), S(), r.size > 0 && t.logger.info(
102
108
  `${n} Watching ${r.size} PHP file${r.size === 1 ? "" : "s"} for changes`,
103
109
  { timestamp: !0 }
104
110
  ), P && await m();
105
111
  },
106
112
  async handleHotUpdate({ file: e }) {
107
- const o = p(e);
113
+ const o = w(e);
108
114
  if (o === u)
109
115
  return t.logger.info(
110
116
  `${n} Manifest changed, reloading watched files`,
111
117
  { timestamp: !0 }
112
- ), await b(), v(), [];
118
+ ), await b(), S(), [];
113
119
  if (r.has(o)) {
114
- const f = r.get(o) ?? null;
115
- return await m(f), [];
120
+ const i = r.get(o) ?? null;
121
+ return await m(i), [];
116
122
  }
117
123
  }
118
124
  };
119
125
  }
120
126
  export {
121
- H as escapeShellArg,
122
- G as laravelTsPublish
127
+ _ as escapeShellArg,
128
+ X as laravelTsPublish
123
129
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tolki/ts",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "A set of TypeScript utilities for the Laravel TypeScript Publish PHP package.",
5
5
  "author": "Abraham Arango <https://github.com/abetwothree>",
6
6
  "license": "MIT",
@@ -39,13 +39,18 @@
39
39
  "tolki"
40
40
  ],
41
41
  "dependencies": {
42
- "@tolki/enum": "^1.1.3",
43
- "@tolki/types": "^1.9.0",
44
- "@tolki/utils": "^1.6.0"
42
+ "@tolki/enum": "^1.1.4",
43
+ "@tolki/types": "^1.11.0",
44
+ "@tolki/utils": "^1.6.2"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "vite": "^7.0.0||^8.0.0"
48
48
  },
49
+ "peerDependenciesMeta": {
50
+ "vite": {
51
+ "optional": true
52
+ }
53
+ },
49
54
  "sideEffects": false,
50
55
  "files": [
51
56
  "dist"