@timbal-ai/timbal-react 0.6.0 → 0.6.1
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/package.json +1 -1
- package/vite/local-dev.mjs +46 -2
package/package.json
CHANGED
package/vite/local-dev.mjs
CHANGED
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
*
|
|
4
4
|
* - Skips pre-bundling so `dist/` updates are not stuck in `node_modules/.vite/deps`
|
|
5
5
|
* - Watches the linked package `dist/` and triggers a full reload when it changes
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: this is a no-op for normal npm installs. Excluding the package from
|
|
8
|
+
* `optimizeDeps` only makes sense when it is `file:`-linked (a symlink in
|
|
9
|
+
* `node_modules`). For published installs Vite must pre-bundle the package so its
|
|
10
|
+
* CJS-only transitive deps (e.g. `use-sync-external-store/shim` reached via
|
|
11
|
+
* `radix-ui` -> `@radix-ui/react-use-is-hydrated`) are converted to ESM instead of
|
|
12
|
+
* leaking to the browser.
|
|
6
13
|
*/
|
|
7
14
|
import { createRequire } from "node:module";
|
|
15
|
+
import fs from "node:fs";
|
|
8
16
|
import path from "node:path";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
17
|
|
|
11
18
|
const TIMBAL_REACT_EXPORTS = [
|
|
12
19
|
"@timbal-ai/timbal-react",
|
|
@@ -16,6 +23,18 @@ const TIMBAL_REACT_EXPORTS = [
|
|
|
16
23
|
"@timbal-ai/timbal-react/app",
|
|
17
24
|
];
|
|
18
25
|
|
|
26
|
+
/**
|
|
27
|
+
* CJS-only transitive deps that must be pre-bundled even when the package itself
|
|
28
|
+
* is excluded, so their `useSyncExternalStore` named imports resolve as ESM.
|
|
29
|
+
*/
|
|
30
|
+
const CJS_INTEROP_DEPS = [
|
|
31
|
+
"radix-ui",
|
|
32
|
+
"@radix-ui/react-use-is-hydrated",
|
|
33
|
+
"use-sync-external-store/shim",
|
|
34
|
+
"use-sync-external-store/shim/with-selector",
|
|
35
|
+
"zustand",
|
|
36
|
+
];
|
|
37
|
+
|
|
19
38
|
function resolveLinkedPackageRoot() {
|
|
20
39
|
try {
|
|
21
40
|
const require = createRequire(import.meta.url);
|
|
@@ -26,6 +45,28 @@ function resolveLinkedPackageRoot() {
|
|
|
26
45
|
}
|
|
27
46
|
}
|
|
28
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Only treat the install as "linked" when the `node_modules` entry is a symlink,
|
|
50
|
+
* i.e. installed via `file:../timbal-react` (or a workspace link). Normal npm
|
|
51
|
+
* installs are real directories and must be left to Vite's pre-bundler.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} [root] consuming project root
|
|
54
|
+
*/
|
|
55
|
+
function isLinkedInstall(root) {
|
|
56
|
+
const base = root || process.cwd();
|
|
57
|
+
const entry = path.join(
|
|
58
|
+
base,
|
|
59
|
+
"node_modules",
|
|
60
|
+
"@timbal-ai",
|
|
61
|
+
"timbal-react",
|
|
62
|
+
);
|
|
63
|
+
try {
|
|
64
|
+
return fs.lstatSync(entry).isSymbolicLink();
|
|
65
|
+
} catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
29
70
|
/** @returns {import('vite').Plugin} */
|
|
30
71
|
export function timbalReactLocalDev() {
|
|
31
72
|
/** @type {string | null} */
|
|
@@ -34,7 +75,9 @@ export function timbalReactLocalDev() {
|
|
|
34
75
|
return {
|
|
35
76
|
name: "timbal-react-local-dev",
|
|
36
77
|
enforce: "pre",
|
|
37
|
-
config() {
|
|
78
|
+
config(config) {
|
|
79
|
+
if (!isLinkedInstall(config.root)) return {};
|
|
80
|
+
|
|
38
81
|
const pkgRoot = resolveLinkedPackageRoot();
|
|
39
82
|
if (!pkgRoot) return {};
|
|
40
83
|
|
|
@@ -44,6 +87,7 @@ export function timbalReactLocalDev() {
|
|
|
44
87
|
return {
|
|
45
88
|
optimizeDeps: {
|
|
46
89
|
exclude: TIMBAL_REACT_EXPORTS,
|
|
90
|
+
include: CJS_INTEROP_DEPS,
|
|
47
91
|
},
|
|
48
92
|
server: {
|
|
49
93
|
watch: {
|