@tishlang/vite-plugin-tish 2.43.8 → 3.1.0

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.
Files changed (2) hide show
  1. package/index.js +42 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -7,13 +7,41 @@
7
7
  //
8
8
  // Platform/surface cascade (RN-style `Button.macos.tish` / `.web.tish` / …) is owned by the `tish`
9
9
  // CLI (`tish resolve-id`); this plugin must not reimplement those rules.
10
+ //
11
+ // Resolution precedence for platform/surface:
12
+ // 1. plugin opts `{ platform, surface }`
13
+ // 2. env `TISH_PLATFORM` / `TISH_SURFACE`
14
+ // 3. package.json `tish.platform` / `tish.surface` (or `tish.desktop.platform` / `.surface`)
10
15
 
11
16
  import { execFileSync } from "node:child_process";
12
- import { existsSync } from "node:fs";
17
+ import { existsSync, readFileSync } from "node:fs";
13
18
  import path from "node:path";
14
19
 
15
20
  const TISH_EXT = ".tish";
16
21
 
22
+ /**
23
+ * @param {string} root
24
+ * @returns {{ platform?: string, surface?: string }}
25
+ */
26
+ export function readPkgTishConfig(root) {
27
+ try {
28
+ const pkgPath = path.join(root, "package.json");
29
+ if (!existsSync(pkgPath)) return {};
30
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
31
+ const t = pkg.tish && typeof pkg.tish === "object" ? pkg.tish : {};
32
+ const desktop =
33
+ t.desktop && typeof t.desktop === "object" ? t.desktop : {};
34
+ const platform = t.platform ?? desktop.platform;
35
+ const surface = t.surface ?? desktop.surface;
36
+ return {
37
+ ...(platform != null && platform !== "" ? { platform: String(platform) } : {}),
38
+ ...(surface != null && surface !== "" ? { surface: String(surface) } : {}),
39
+ };
40
+ } catch {
41
+ return {};
42
+ }
43
+ }
44
+
17
45
  /**
18
46
  * @param {object} [opts]
19
47
  * @param {string} [opts.tishPath] Path to the `tish` binary (default: $TISH_PATH or `tish` on PATH).
@@ -22,13 +50,15 @@ const TISH_EXT = ".tish";
22
50
  * page on any `.tish` change (the documented fallback for `--target bytecode` apps).
23
51
  * @param {string} [opts.platform] Platform token for resolve cascade (`macos`, `ios`, `web`, …).
24
52
  * @param {string} [opts.surface] Surface token (`native`, `webview`, `web`). Defaults from
25
- * `TISH_PLATFORM` / `TISH_SURFACE` when unset.
53
+ * `TISH_PLATFORM` / `TISH_SURFACE`, then package.json `tish.*`, when unset.
26
54
  */
27
55
  export default function tishPlugin(opts = {}) {
28
56
  const tishPath = opts.tishPath ?? process.env.TISH_PATH ?? "tish";
29
57
  const mode = opts.mode ?? "hmr";
30
- const platform = opts.platform ?? process.env.TISH_PLATFORM;
31
- const surface = opts.surface ?? process.env.TISH_SURFACE;
58
+ let platform = opts.platform ?? process.env.TISH_PLATFORM;
59
+ let surface = opts.surface ?? process.env.TISH_SURFACE;
60
+ const optsHadPlatform = opts.platform != null;
61
+ const optsHadSurface = opts.surface != null;
32
62
  let projectRoot = opts.projectRoot;
33
63
  /** @type {boolean|null} */
34
64
  let supportsPlatformFlags = null;
@@ -124,6 +154,14 @@ export default function tishPlugin(opts = {}) {
124
154
 
125
155
  configResolved(config) {
126
156
  if (!projectRoot) projectRoot = config.root;
157
+ const fromPkg = readPkgTishConfig(projectRoot);
158
+ // opts > env (already applied) > package.json
159
+ if (!optsHadPlatform && (platform == null || platform === "") && fromPkg.platform) {
160
+ platform = fromPkg.platform;
161
+ }
162
+ if (!optsHadSurface && (surface == null || surface === "") && fromPkg.surface) {
163
+ surface = fromPkg.surface;
164
+ }
127
165
  },
128
166
 
129
167
  resolveId(source, importer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tishlang/vite-plugin-tish",
3
- "version": "2.43.8",
3
+ "version": "3.1.0",
4
4
  "description": "Vite plugin for Tish: in-graph .tish compilation with HMR and source maps for dev.",
5
5
  "license": "PIF",
6
6
  "type": "module",