869680a5a1
## What this does Resolves the remaining esbuild security alerts on packages we own, and upgrades the repo to **Vite 8** (which drops esbuild entirely in favour of rolldown/oxc). ### 1. esbuild → `^0.28.1` (security) - Raised the declared `esbuild` floor in `twenty-sdk` and the logic-function common-layer (both were `^0.25.0`, which can only resolve to a vulnerable version). These are our packages, so this is just declaring the patched version — clears Dependabot **#1467** and **#1468**. ### 2. Vite 7 → 8 - Bumped `vite` to `^8` in the 5 packages that declare it, and `@vitejs/plugin-react-swc` to `^4.3.1` (the only plugin that needed a bump for Vite 8; everything else already supports it). - `twenty-front` keeps esbuild minification, so esbuild is now an explicit (patched) devDependency there — Vite 8 no longer ships it. ### Two Vite-8 fallout fixes (bundler internals changed) - **Storybook tests:** added React to `optimizeDeps.include` so Vite's dep optimizer doesn't re-bundle React mid-run and break in-flight imports in browser-mode tests. - **`hex-rgb`:** it's ESM-only and broke rolldown's CJS interop (a default import resolved to the wrong thing under jest). Replaced its one use with a tiny inline hex→rgb parse and dropped the dependency. ## Verified Vite resolves to a single `8.0.16` with no esbuild in its tree. Builds pass on Vite 8/rolldown: `twenty-front` production build, the SDKs, and Storybook; the previously-failing front and storybook test jobs now pass; `yarn install --immutable` is clean. ## Note This doesn't close root alert **#1469** — esbuild is still pulled by other third-party tools (storybook, tsx, lingui, zapier, etc.) that haven't shipped a patched release. The vulnerable code path (esbuild's dev server) isn't used here, so that one is best dismissed as not-affected.
181 lines
5.3 KiB
TypeScript
181 lines
5.3 KiB
TypeScript
import react from '@vitejs/plugin-react-swc';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
import { defineConfig } from 'vite';
|
|
import checker from 'vite-plugin-checker';
|
|
import dts, { type PluginOptions } from 'vite-plugin-dts';
|
|
import sassDts from 'vite-plugin-sass-dts';
|
|
import svgr from 'vite-plugin-svgr';
|
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
|
|
type Checkers = Parameters<typeof checker>[0];
|
|
|
|
import packageJson from './package.json';
|
|
|
|
const entries = Object.keys(packageJson.exports)
|
|
.filter((el) => !el.endsWith('.css'))
|
|
.map((module) => `src/${module}/index.ts`);
|
|
|
|
const entryFileNames = (chunk: any, extension: 'cjs' | 'mjs') => {
|
|
if (!chunk.isEntry) {
|
|
throw new Error(
|
|
`Should never occurs, encountered a non entry chunk ${chunk.facadeModuleId}`,
|
|
);
|
|
}
|
|
|
|
const splitFaceModuleId = chunk.facadeModuleId?.split('/');
|
|
if (splitFaceModuleId === undefined) {
|
|
throw new Error(
|
|
`Should never occurs splitFaceModuleId is undefined ${chunk.facadeModuleId}`,
|
|
);
|
|
}
|
|
|
|
const moduleDirectory = splitFaceModuleId[splitFaceModuleId?.length - 2];
|
|
if (moduleDirectory === 'src') {
|
|
return `${chunk.name}.${extension}`;
|
|
}
|
|
return `${moduleDirectory}.${extension}`;
|
|
};
|
|
|
|
export default defineConfig(({ command }) => {
|
|
const isBuildCommand = command === 'build';
|
|
|
|
const tsConfigPath = isBuildCommand
|
|
? path.resolve(__dirname, './tsconfig.lib.json')
|
|
: path.resolve(__dirname, './tsconfig.json');
|
|
|
|
const checkersConfig: Checkers = {
|
|
typescript: {
|
|
tsconfigPath: tsConfigPath,
|
|
},
|
|
};
|
|
|
|
const dtsConfig: PluginOptions = {
|
|
entryRoot: 'src',
|
|
tsconfigPath: tsConfigPath,
|
|
};
|
|
|
|
const BUNDLED_DEPS = ['@tabler/icons-react'];
|
|
|
|
const externalDeps = Object.keys(packageJson.dependencies || {}).filter(
|
|
(dep) => !BUNDLED_DEPS.includes(dep),
|
|
);
|
|
|
|
return {
|
|
resolve: {
|
|
alias: {
|
|
'@ui/': path.resolve(__dirname, 'src') + '/',
|
|
'@assets/': path.resolve(__dirname, 'src/assets') + '/',
|
|
'@styles/': path.resolve(__dirname, 'src/styles') + '/',
|
|
'@tabler/icons-react': '@tabler/icons-react/dist/esm/icons/index.mjs',
|
|
},
|
|
},
|
|
css: {
|
|
modules: {
|
|
localsConvention: 'camelCaseOnly',
|
|
},
|
|
preprocessorOptions: {
|
|
scss: {
|
|
api: 'modern-compiler',
|
|
loadPaths: [path.resolve(__dirname, 'src/styles')],
|
|
additionalData: [
|
|
`@use 'abstracts/functions' as *;`,
|
|
`@use 'abstracts/mixins' as *;`,
|
|
`@use 'abstracts/breakpoints' as *;`,
|
|
'',
|
|
].join('\n'),
|
|
},
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['../../node_modules/.vite', '../../node_modules/.cache'],
|
|
// Pre-bundle React up front so Vite's dep optimizer doesn't re-bundle it
|
|
// mid-run during browser-mode Storybook tests — re-bundling rotates the
|
|
// optimized chunk hash and 404s in-flight dynamic imports (vite 8 / rolldown).
|
|
include: [
|
|
'react',
|
|
'react-dom',
|
|
'react-dom/client',
|
|
'react/jsx-runtime',
|
|
'react/jsx-dev-runtime',
|
|
],
|
|
},
|
|
root: __dirname,
|
|
cacheDir: '../../node_modules/.vite/packages/twenty-ui',
|
|
assetsInclude: ['src/**/*.svg'],
|
|
plugins: [
|
|
react(),
|
|
tsconfigPaths({
|
|
root: __dirname,
|
|
projects: ['tsconfig.json'],
|
|
}),
|
|
svgr(),
|
|
// Generates typed *.module.scss.d.ts siblings (dev mode only — backed by
|
|
// sass-embedded). CI/build relies on the ambient src/scss-modules.d.ts.
|
|
sassDts({ esmExport: true, legacyFileFormat: true }),
|
|
dts(dtsConfig),
|
|
checker(checkersConfig),
|
|
{
|
|
name: 'copy-theme-css',
|
|
closeBundle() {
|
|
const distDir = path.resolve(__dirname, 'dist');
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
const themeCssFiles = ['theme-light.css', 'theme-dark.css'];
|
|
for (const file of themeCssFiles) {
|
|
fs.copyFileSync(
|
|
path.resolve(__dirname, `src/theme-constants/${file}`),
|
|
path.resolve(distDir, file),
|
|
);
|
|
}
|
|
},
|
|
},
|
|
],
|
|
build: {
|
|
cssCodeSplit: false,
|
|
minify: 'esbuild',
|
|
sourcemap: false,
|
|
emptyOutDir: false,
|
|
outDir: './dist',
|
|
reportCompressedSize: true,
|
|
commonjsOptions: {
|
|
transformMixedEsModules: true,
|
|
interopDefault: true,
|
|
defaultIsModuleExports: true,
|
|
requireReturnsDefault: 'auto',
|
|
},
|
|
lib: {
|
|
entry: ['src/index.ts', ...entries],
|
|
name: 'twenty-ui',
|
|
},
|
|
rollupOptions: {
|
|
external: (id: string) =>
|
|
externalDeps.some((dep) => id === dep || id.startsWith(dep + '/')),
|
|
output: [
|
|
{
|
|
assetFileNames: 'style.css',
|
|
globals: {
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
},
|
|
format: 'es',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'mjs'),
|
|
},
|
|
{
|
|
assetFileNames: 'style.css',
|
|
format: 'cjs',
|
|
globals: {
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
},
|
|
interop: 'auto',
|
|
esModule: true,
|
|
exports: 'named',
|
|
entryFileNames: (chunk) => entryFileNames(chunk, 'cjs'),
|
|
},
|
|
],
|
|
},
|
|
},
|
|
logLevel: 'error',
|
|
};
|
|
});
|