diff --git a/apps/vite/package.json b/apps/vite/package.json index 468020b34..f84fc65d7 100644 --- a/apps/vite/package.json +++ b/apps/vite/package.json @@ -4,7 +4,9 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "build": "tsc && vite build", + "build": "yarn run build:tsc && yarn run build:vite", + "build:tsc": "tsc || exit 0", + "build:vite": "vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview" }, diff --git a/apps/vite/vite.config.ts b/apps/vite/vite.config.ts index bf22b2f89..91ba7a9b1 100644 --- a/apps/vite/vite.config.ts +++ b/apps/vite/vite.config.ts @@ -1,9 +1,11 @@ -import { tamaguiExtractPlugin, tamaguiPlugin } from '@tamagui/vite-plugin'; -import react from '@vitejs/plugin-react-swc'; import { defineConfig } from 'vite'; +import react from '@vitejs/plugin-react-swc'; import { resolve } from 'path'; import esbuildFlowPlugin from 'esbuild-plugin-flow'; import { TanStackRouterVite } from '@tanstack/router-vite-plugin'; +import { tamaguiExtractPlugin, tamaguiPlugin } from '@tamagui/vite-plugin'; +import * as esbuild from 'esbuild'; +import { readFileSync } from 'fs'; const shouldExtract = process.env.EXTRACT === '1'; @@ -14,6 +16,7 @@ const tamaguiConfig = { // https://tamagui.dev/docs/intro/installation const extensions = [ + '.mjs', '.web.tsx', '.tsx', '.web.ts', @@ -30,8 +33,19 @@ const extensions = [ const development = process.env.NODE_ENV === 'development'; +const rollupPlugin = (matchers: RegExp[]) => ({ + name: 'js-in-jsx', + load(id: string) { + if (matchers.some((matcher) => matcher.test(id)) && id.endsWith('.js')) { + const file = readFileSync(id, { encoding: 'utf-8' }); + return esbuild.transformSync(file, { loader: 'jsx', jsx: 'automatic' }); + } + }, +}); + export default defineConfig({ clearScreen: true, + cacheDir: '../../node_modules/.vite/vite-app', plugins: [ react(), TanStackRouterVite(), @@ -69,13 +83,39 @@ export default defineConfig({ // https://github.com/vitejs/vite-plugin-react/issues/192#issuecomment-1627384670 jsx: 'automatic', // need either this or the plugin below - loader: { '.js': 'jsx' }, + loader: { + '.js': 'jsx' + }, plugins: [ - esbuildFlowPlugin(/\.(flow|jsx?)$/, (path) => - /\.jsx$/.test(path) ? 'jsx' : 'jsx', + esbuildFlowPlugin( + /\.(flow|jsx?)$/, + (path) => (/\.jsx$/.test(path) ? 'jsx' : 'jsx'), ), ], }, include: ['@packrat/validations'], + exclude: [], + }, + build: { + commonjsOptions: { transformMixedEsModules: true }, + rollupOptions: { + plugins: [ + rollupPlugin([/react-native-vector-icons/, /@expo\/vector-icons/, /react-native-table-component/]), + ], + }, + }, + server: { + port: 4200, + host: 'localhost', + }, + preview: { + port: 4300, + host: 'localhost', + }, + test: { + globals: true, + cache: { dir: '../../node_modules/.vitest' }, + environment: 'jsdom', + include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], }, }); diff --git a/package.json b/package.json index 0fd9832fe..3c0825191 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,15 @@ "build:expo": "yarn expo:export", "build:ios": "cd apps/expo && yarn build:ios", "build:prod:docker": "docker build -t packrat-app -f Dockerfile.prod .", - "build:prod": "yarn && yarn build:tsc && yarn build:next:static", + "build:prod": "yarn && yarn build:tsc && yarn build:web", "build:prod:cloudflare-next": "cd apps/next && yarn build:cloudflare", "build:tsc:packages": "cd packages/validations && yarn build", "build:tsc:server": "cd server && yarn build", "build:tsc": "yarn build:tsc:packages", "build:validations": "cd packages/validations && yarn build", - "build:web": "cd apps/next && yarn build", + "build:web": "yarn build:vite && yarn build:next:static", "build:next:static": "cd apps/next && yarn build && yarn next export", + "build:vite": "cd apps/vite && yarn build", "build": "yarn workspaces foreach --all run build", "check-deps": "check-dependency-version-consistency .", "check-deps-fix": "yarn check-deps --fix --ignore-dep uuid", diff --git a/packages/cli/src/doctor.js b/packages/cli/src/doctor.js new file mode 100644 index 000000000..178e94cc4 --- /dev/null +++ b/packages/cli/src/doctor.js @@ -0,0 +1,60 @@ +const { prompt } = require('enquirer'); +const fs = require('fs'); +const path = require('path'); + +// Adjust this path if your script is not located in the root of PackRat +const appsPath = path.join(__dirname, '../../../apps'); + +async function checkConfigFiles(appName, configFileNames) { + console.log(`\nChecking ${appName}...`); + const appDir = path.join(appsPath, appName); + + console.log('appDir:', appDir); + + for (const fileName of configFileNames) { + const filePath = path.join(appDir, fileName); + if (fs.existsSync(filePath)) { + console.log(`✅ ${fileName} exists.`); + } else { + console.error(`❌ ${fileName} does not exist.`); + } + } +} + +async function checkPackageJsonDependencies(appName) { + const packageJsonPath = path.join(appsPath, appName, 'package.json'); + if (!fs.existsSync(packageJsonPath)) { + console.error('❌ package.json does not exist.'); + return; + } + + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + console.log(`Dependencies for ${appName}:`); + console.log(packageJson.dependencies); + // Implement additional logic for version checks as needed +} + +async function runDiagnostics() { + const response = await prompt([ + { + type: 'select', + name: 'appName', + message: 'Select an app to diagnose:', + choices: ['bun-server', 'expo', 'next', 'tauri', 'vite'], + } + ]); + + const configFileNames = { + 'expo': ['app.json'], + 'next': ['next.config.js'], + 'vite': ['vite.config.js'], + // Assuming generic checks for Bun and Tauri, adjust based on real config files + 'bun-server': ['package.json'], + 'tauri': ['package.json'], + }; + + await checkConfigFiles(response.appName, configFileNames[response.appName]); + await checkPackageJsonDependencies(response.appName); +} + +runDiagnostics().catch(console.error); diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 8957a225c..4551e237b 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -86,22 +86,26 @@ router.route('/hello', helloRouter); // // Static routes for serving the React Native Web app // if (process.env.NODE_ENV === 'production') { // const __dirname = path.resolve(); +// const serverType = process.env.REACT_APP_SERVER_TYPE || 'vite'; // // Serve the client's index.html file at the root route // router.get('/', (req, res) => { -// // Attach the CSRF token cookie to the response +// // Attach the CSRF token cookie to the response // // res.cookie("XSRF-TOKEN", req.csrfToken()); -// res.sendFile(path.resolve(__dirname, '../apps/next', 'out', 'index.html')); +// const basePath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; +// res.sendFile(path.resolve(__dirname, basePath, 'index.html')); // }); -// // Serve the static assets from the client's dist app -// router.use(express.static(path.join(__dirname, '../apps/next/out'))); +// // Serve the static assets +// const staticPath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; +// router.use(express.static(path.join(__dirname, staticPath))); // // Serve the client's index.html file at all other routes NOT starting with /api // router.get(/^(?!\/?api).*/, (req, res) => { // // res.cookie("XSRF-TOKEN", req.csrfToken()); -// res.sendFile(path.resolve(__dirname, '../apps/next', 'out', 'index.html')); +// const basePath = serverType === 'next' ? '../apps/next/out' : '../apps/vite/dist'; +// res.sendFile(path.resolve(__dirname, basePath, 'index.html')); // }); // }