Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Toolpad apps compatible with pnpm #3074

Merged
merged 12 commits into from
Jan 12, 2024
87 changes: 25 additions & 62 deletions packages/toolpad-app/src/server/toolpadAppBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import.meta.url ??= url.pathToFileURL(__filename).toString();
const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));

const MAIN_ENTRY = '/main.tsx';
const FALLBACK_MODULES = [
'@mui/material',
'@mui/icons-material',
'@mui/x-data-grid',
'@mui/x-charts',
];

export function getHtmlContent() {
return `
Expand Down Expand Up @@ -41,10 +47,20 @@ function toolpadVitePlugin(): Plugin {
return {
name: 'toolpad',

async resolveId(id) {
async resolveId(id, parent) {
if (id.endsWith('.html')) {
return id;
}
const hasFallback = FALLBACK_MODULES.some(
(moduleName) => moduleName === id || id.startsWith(`${moduleName}/`),
);
if (hasFallback) {
const [userMod, fallbackMod] = await Promise.all([
this.resolve(id, parent),
this.resolve(id, currentDirectory),
]);
return userMod || fallbackMod;
}
return null;
},

Expand Down Expand Up @@ -263,6 +279,7 @@ if (import.meta.hot) {
},
envFile: false,
resolve: {
dedupe: FALLBACK_MODULES,
alias: [
{
// FIXME(https://github.com/mui/material-ui/issues/35233)
Expand All @@ -279,6 +296,10 @@ if (import.meta.hot) {
? 'virtual:toolpad-files:canvas.tsx'
: 'virtual:toolpad-files:main.tsx',
},
{
find: '@mui/toolpad',
replacement: path.resolve(currentDirectory, '../exports'),
},
],
},
server: {
Expand All @@ -287,70 +308,12 @@ if (import.meta.hot) {
},
},
optimizeDeps: {
include: [
'@emotion/cache',
'@emotion/react',
'@mui/icons-material',
'@mui/icons-material/ArrowDropDownRounded',
'@mui/icons-material/Close',
'@mui/icons-material/Delete',
'@mui/icons-material/DarkMode',
'@mui/icons-material/Edit',
'@mui/icons-material/Error',
'@mui/icons-material/HelpOutlined',
'@mui/icons-material/LightMode',
'@mui/icons-material/OpenInNew',
'@mui/icons-material/SettingsBrightnessOutlined',
'@mui/lab',
'@mui/material',
'@mui/material/CircularProgress',
'@mui/material/Button',
'@mui/material/colors',
'@mui/material/styles',
'@mui/material/useMediaQuery',
'@mui/utils',
'@mui/utils/useEventCallback',
'@mui/x-data-grid-pro',
'@mui/x-date-pickers/AdapterDayjs',
'@mui/x-date-pickers/DesktopDatePicker',
'@mui/x-date-pickers/LocalizationProvider',
'@mui/x-license-pro',
'@tanstack/react-query',
'@tanstack/react-query-devtools/build/modern/production.js',
'dayjs',
'dayjs/locale/en',
'dayjs/locale/fr',
'dayjs/locale/nl',
'fractional-indexing',
'invariant',
'lodash-es',
'markdown-to-jsx',
'nanoid/non-secure',
'prop-types',
'react',
'react-dom',
'react-dom/client',
'react-error-boundary',
'react-hook-form',
'react-is',
'react-router-dom',
'react/jsx-dev-runtime',
'react/jsx-runtime',
'recharts',
'superjson',
'title',
'zod',
],
exclude: [
'@mui/toolpad-core',
'@mui/toolpad/browser',
'@mui/toolpad/runtime',
'@mui/toolpad/canvas',
],
entries: [MAIN_ENTRY],
include: FALLBACK_MODULES.map((moduleName) => `@mui/toolpad > ${moduleName}`),
},
appType: 'custom',
logLevel: 'info',
root,
root: currentDirectory,
plugins: [virtualToolpadFiles, react(), toolpadVitePlugin(), ...plugins],
base,
define: {
Expand Down
Loading