|
| 1 | +import { createRequire } from 'node:module'; |
| 2 | +import { dirname, join } from 'node:path'; |
| 3 | +import { existsSync } from 'node:fs'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | + |
| 6 | +const require = createRequire(import.meta.url); |
| 7 | + |
| 8 | +let solidJsRuntimePath; |
| 9 | +let solidJsHPath; |
| 10 | +const solidWebShimPath = fileURLToPath(new URL('./solid-web-shim.js', import.meta.url)); |
| 11 | +const jsxRuntimeShimPath = fileURLToPath(new URL('./solid-js-jsx-runtime-shim.js', import.meta.url)); |
| 12 | + |
| 13 | +try { |
| 14 | + const solidJsPackagePath = require.resolve('solid-js/package.json'); |
| 15 | + const solidJsRoot = dirname(solidJsPackagePath); |
| 16 | + |
| 17 | + const candidateRuntimePath = join(solidJsRoot, 'h', 'jsx-runtime', 'dist', 'jsx.js'); |
| 18 | + const candidateHPath = join(solidJsRoot, 'h', 'dist', 'h.js'); |
| 19 | + |
| 20 | + if (existsSync(candidateRuntimePath)) { |
| 21 | + solidJsRuntimePath = candidateRuntimePath; |
| 22 | + } |
| 23 | + |
| 24 | + if (existsSync(candidateHPath)) { |
| 25 | + solidJsHPath = candidateHPath; |
| 26 | + } |
| 27 | + |
| 28 | + if (!solidJsRuntimePath || !solidJsHPath) { |
| 29 | + console.warn( |
| 30 | + '[nativescript/tanstack-router] Could not resolve one or more SolidJS runtime alias paths for Vite.', |
| 31 | + { |
| 32 | + runtimeFound: !!solidJsRuntimePath, |
| 33 | + hFound: !!solidJsHPath, |
| 34 | + solidJsRoot, |
| 35 | + }, |
| 36 | + ); |
| 37 | + } |
| 38 | +} catch (error) { |
| 39 | + console.warn( |
| 40 | + '[nativescript/tanstack-router] Failed to resolve SolidJS package location for Vite aliases.', |
| 41 | + error instanceof Error ? error.message : error, |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +export default () => ({ |
| 46 | + resolve: { |
| 47 | + alias: { |
| 48 | + // Keep Vite behavior aligned with nativescript.webpack.js integration. |
| 49 | + 'solid-js/web': solidWebShimPath, |
| 50 | + 'solid-js/jsx-runtime': jsxRuntimeShimPath, |
| 51 | + 'solid-js/jsx-dev-runtime': jsxRuntimeShimPath, |
| 52 | + ...(solidJsHPath |
| 53 | + ? { |
| 54 | + 'solid-js/h': solidJsHPath, |
| 55 | + } |
| 56 | + : {}), |
| 57 | + }, |
| 58 | + }, |
| 59 | +}); |
0 commit comments