@shadow-js/vite 0.1.0 → 0.3.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.
package/README.md CHANGED
@@ -26,7 +26,7 @@ npm install @shadow-js/vite
26
26
  Install together with ShadowJS:
27
27
 
28
28
  ```bash
29
- npm install shadow-js @shadow-js/vite
29
+ npm install @shadow-js/core @shadow-js/vite
30
30
  ```
31
31
 
32
32
  ## 🚀 Quick Start
@@ -47,7 +47,7 @@ export default defineConfig({
47
47
  **src/App.tsx**
48
48
 
49
49
  ```jsx
50
- import { useStore, Show } from "shadow-js";
50
+ import { useStore, Show } from "@shadow-js/core";
51
51
 
52
52
  function App() {
53
53
  const [count, setCount] = useStore(0);
@@ -69,7 +69,7 @@ export default App;
69
69
  **src/main.ts**
70
70
 
71
71
  ```typescript
72
- import { render } from "shadow-js";
72
+ import { render } from "@shadow-js/core";
73
73
  import App from "./App";
74
74
 
75
75
  render(App, document.getElementById("app")!);
@@ -290,8 +290,8 @@ MIT License - see [LICENSE](../../LICENSE) for details.
290
290
 
291
291
  - **Documentation**: [Vite Plugin Guide](../../packages/vite/README.md)
292
292
  - **Examples**: [Integration Examples](../../documentation/examples.md)
293
- - **Issues**: [GitHub Issues](https://github.com/shadow-js/shadow/issues)
294
- - **Discussions**: [GitHub Discussions](https://github.com/shadow-js/shadow/discussions)
293
+ - **Issues**: [GitHub Issues](https://github.com/shadowjs-dev/shadow/issues)
294
+ - **Discussions**: [GitHub Discussions](https://github.com/shadowjs-dev/shadow/discussions)
295
295
 
296
296
  ---
297
297
 
package/dist/index.cjs CHANGED
@@ -34,7 +34,7 @@ function shadow() {
34
34
  transform: {
35
35
  react: {
36
36
  runtime: "automatic",
37
- importSource: "shadow-js"
37
+ importSource: "@shadow-js/core"
38
38
  }
39
39
  },
40
40
  target: "es2022"
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["transformSource","swcTransform"],"mappings":";;;;;;AA8De,SAAR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AAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"shadow-js\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"shadow-js\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["transformSource","swcTransform"],"mappings":";;;;;;AA8De,SAAR,MAAA,GAAwC;AAC7C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA;AAAA,IAGT,MAAA,GAAS;AACP,MAAA,OAAO;AAAA,QACL,OAAA,EAAS;AAAA,UACP,GAAA,EAAK;AAAA;AACP,OACF;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,SAA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AAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.cjs","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"@shadow-js/core\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"@shadow-js/core\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -40,7 +40,7 @@ import { PluginOption } from 'vite';
40
40
  * @example
41
41
  * ```typescript
42
42
  * // Your component file (App.tsx)
43
- * import { useStore, Show } from "shadow-js";
43
+ * import { useStore, Show } from "@shadow-js/core";
44
44
  *
45
45
  * function App() {
46
46
  * const [count, setCount] = useStore(0)
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@ import { PluginOption } from 'vite';
40
40
  * @example
41
41
  * ```typescript
42
42
  * // Your component file (App.tsx)
43
- * import { useStore, Show } from "shadow-js";
43
+ * import { useStore, Show } from "@shadow-js/core";
44
44
  *
45
45
  * function App() {
46
46
  * const [count, setCount] = useStore(0)
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ function shadow() {
32
32
  transform: {
33
33
  react: {
34
34
  runtime: "automatic",
35
- importSource: "shadow-js"
35
+ importSource: "@shadow-js/core"
36
36
  }
37
37
  },
38
38
  target: "es2022"
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["swcTransform"],"mappings":";;;;AA8De,SAAR,MAAA,GAAwC;AAC7C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA;AAAA,IAGT,MAAA,GAAS;AACP,MAAA,OAAO;AAAA,QACL,OAAA,EAAS;AAAA,UACP,GAAA,EAAK;AAAA;AACP,OACF;AAAA,IACF,CAAA;AAAA,IAEA,MAAM,SAAA,CAAU,IAAA,EAAM,EAAA,EAAI;AAExB,MAAA,IAAI,CAAC,cAAA,CAAe,IAAA,CAAK,EAAE,GAAG,OAAO,IAAA;AACrC,MAAA,IAAI,EAAA,CAAG,QAAA,CAAS,cAAc,CAAA,EAAG,OAAO,IAAA;AAGxC,MAAA,IAAI,eAAA;AACJ,MAAA,IAAI;AACF,QAAA,eAAA,GAAkB,gBAAgB,IAAI,CAAA;AAAA,MACxC,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,qCAAA,EAAwC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACtE;AAGA,MAAA,IAAI;AACF,QAAA,MAAM,MAAA,GAAS,MAAMA,SAAA,CAAa,eAAA,EAAiB;AAAA,UACjD,QAAA,EAAU,EAAA;AAAA,UACV,GAAA,EAAK;AAAA,YACH,MAAA,EAAQ,EAAE,MAAA,EAAQ,YAAA,EAAc,KAAK,IAAA,EAAK;AAAA,YAC1C,SAAA,EAAW;AAAA,cACT,KAAA,EAAO;AAAA,gBACL,OAAA,EAAS,WAAA;AAAA,gBACT,YAAA,EAAc;AAAA;AAChB,aACF;AAAA,YACA,MAAA,EAAQ;AAAA,WACV;AAAA,UACA,MAAA,EAAQ,EAAE,IAAA,EAAM,KAAA,EAAM;AAAA,UACtB,UAAA,EAAY;AAAA,SACb,CAAA;AAED,QAAA,OAAO;AAAA,UACL,MAAM,MAAA,CAAO,IAAA;AAAA,UACb,GAAA,EAAK,OAAO,GAAA,IAAO;AAAA,SACrB;AAAA,MACF,SAAS,CAAA,EAAG;AACV,QAAA,MAAM,MAAM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"shadow-js\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"shadow-js\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]}
1
+ {"version":3,"sources":["../src/index.ts"],"names":["swcTransform"],"mappings":";;;;AA8De,SAAR,MAAA,GAAwC;AAC7C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,iBAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA;AAAA,IAGT,MAAA,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AM,CAAA,YAAa,KAAA,GAAQ,CAAA,CAAE,OAAA,GAAU,OAAO,CAAC,CAAA;AACrD,QAAA,MAAM,IAAI,KAAA,CAAM,CAAA,gCAAA,EAAmC,EAAE,CAAA,EAAA,EAAK,GAAG,CAAA,CAAE,CAAA;AAAA,MACjE;AAAA,IACF;AAAA,GACF;AACF","file":"index.js","sourcesContent":["import type { PluginOption } from \"vite\";\nimport { transformSource } from \"@shadow-js/compiler\";\nimport { transform as swcTransform } from \"@swc/core\";\n\n/**\n * Shadow Vite Plugin\n *\n * This plugin integrates Shadow with Vite to provide seamless development experience.\n * It handles the complete transformation pipeline from TSX/JSX source code to\n * Shadow-compatible JavaScript with reactive expressions.\n *\n * Plugin Pipeline:\n * 1. **Shadow Compiler**: Applies JSX transformations to inject reactive functions\n * 2. **SWC Transformation**: Converts TypeScript/JSX to JavaScript with proper imports\n * 3. **JSX Runtime Injection**: Automatically imports Shadow's JSX runtime functions\n * 4. **Source Map Generation**: Preserves debugging capabilities\n *\n * Features:\n * - **Selective Processing**: Only transforms user code (excludes node_modules)\n * - **TypeScript Support**: Full TypeScript and TSX compilation\n * - **Hot Module Replacement**: Compatible with Vite's HMR system\n * - **Error Handling**: Provides clear error messages for compilation failures\n * - **Performance**: Uses fast SWC compiler for optimal build speeds\n *\n * The plugin automatically configures Vite to preserve JSX for SWC processing\n * instead of using esbuild's JSX transform, ensuring compatibility with Shadow's\n * reactive programming model.\n *\n * @returns Vite PluginOption instance for Shadow integration\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from \"vite\";\n * import shadow from \"@shadow-js/vite\";\n *\n * export default defineConfig({\n * plugins: [shadow()]\n * })\n * ```\n *\n * @example\n * ```typescript\n * // Your component file (App.tsx)\n * import { useStore, Show } from \"@shadow-js/core\";\n *\n * function App() {\n * const [count, setCount] = useStore(0)\n *\n * return (\n * <div>\n * <button onClick={() => setCount((c) => c + 1)}>\n * Increment\n * </button>\n * <Show when={count() > 0}>\n * <div>Count: {count()}</div>\n * </Show>\n * </div>\n * )\n * }\n * ```\n */\nexport default function shadow(): PluginOption {\n return {\n name: \"@shadow-js/vite\",\n enforce: \"pre\",\n\n // Prevent esbuild from also transforming JSX to avoid double transforms.\n config() {\n return {\n esbuild: {\n jsx: \"preserve\",\n },\n };\n },\n\n async transform(code, id) {\n // Only TSX/JSX user files\n if (!/\\.(tsx|jsx)$/.test(id)) return null;\n if (id.includes(\"node_modules\")) return null;\n\n // 1) Apply Shadow compiler transforms on source text\n let transformedCode: string;\n try {\n transformedCode = transformSource(code);\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): compiler failed for ${id}: ${msg}`);\n }\n\n // 2) Use SWC to handle TS/JSX -> JS and inject jsx runtime imports\n try {\n const result = await swcTransform(transformedCode, {\n filename: id,\n jsc: {\n parser: { syntax: \"typescript\", tsx: true },\n transform: {\n react: {\n runtime: \"automatic\",\n importSource: \"@shadow-js/core\",\n },\n },\n target: \"es2022\",\n },\n module: { type: \"es6\" },\n sourceMaps: true,\n });\n\n return {\n code: result.code,\n map: result.map ?? null,\n };\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n throw new Error(`ShadowJS (vite): SWC failed for ${id}: ${msg}`);\n }\n },\n } satisfies PluginOption;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shadow-js/vite",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Vite plugin for ShadowJS (JSX + transforms via SWC)",
5
5
  "author": "Jehaad AL-Johani",
6
6
  "homepage": "https://github.com/shadowjs-dev/shadow#readme",
@@ -46,12 +46,12 @@
46
46
  "typecheck": "tsc -p tsconfig.json --noEmit"
47
47
  },
48
48
  "dependencies": {
49
- "@shadow-js/compiler": "^0.1.0"
49
+ "@shadow-js/compiler": "^0.2.0"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@swc/core": "^1.3.96",
53
- "shadow-js": "^0.1.0",
54
- "vite": "^7.1.3"
53
+ "@shadow-js/core": "^0.1.0",
54
+ "vite": "^5.1.4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@swc/core": "^1.13.3",