This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch fix-webpack-submodules in repository https://gitbox.apache.org/repos/asf/superset.git
commit 744b36b366089cd3e5ceae90bce471ce699552cc Author: Maxime Beauchemin <[email protected]> AuthorDate: Mon Sep 22 22:44:36 2025 -0700 feat(build): auto-rebuild TypeScript types for packages/plugins in webpack After PR #35159 changes, developers had to manually run `npm run plugins:build` whenever types changed in packages or plugins. This adds automatic type checking and .d.ts generation to the webpack dev process using ForkTsCheckerWebpackPlugin. Key improvements: - Automatic type rebuilding when packages/plugins change - Inline type error reporting in webpack console - Incremental compilation for better performance - skipLibCheck optimization for faster type checking - Can be disabled with DISABLE_TYPE_CHECK=true npm run dev - Fixes PropTypes compatibility for JavaScript files This eliminates the need for manual type rebuilding and makes the development experience smoother while maintaining type safety. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> --- superset-frontend/.gitignore | 2 + .../controls/MetricControl/savedMetricType.ts | 15 +++- superset-frontend/webpack.config.js | 81 +++++++++++++++++++--- 3 files changed, 85 insertions(+), 13 deletions(-) diff --git a/superset-frontend/.gitignore b/superset-frontend/.gitignore index c474d896d7..e85aece081 100644 --- a/superset-frontend/.gitignore +++ b/superset-frontend/.gitignore @@ -3,3 +3,5 @@ cypress/screenshots cypress/videos src/temp .temp_cache/ +.tsbuildinfo +tsconfig.webpack.json diff --git a/superset-frontend/src/explore/components/controls/MetricControl/savedMetricType.ts b/superset-frontend/src/explore/components/controls/MetricControl/savedMetricType.ts index 4ea5b3409a..1d03345e03 100644 --- a/superset-frontend/src/explore/components/controls/MetricControl/savedMetricType.ts +++ b/superset-frontend/src/explore/components/controls/MetricControl/savedMetricType.ts @@ -16,7 +16,16 @@ * specific language governing permissions and limitations * under the License. */ -export { savedMetricType } from './types'; +import PropTypes from 'prop-types'; -// For backward compatibility with PropTypes usage -export { savedMetricType as default } from './types'; +export type { savedMetricType } from './types'; + +// PropTypes definition for JavaScript files +const savedMetricTypePropTypes = PropTypes.shape({ + metric_name: PropTypes.string.isRequired, + verbose_name: PropTypes.string, + expression: PropTypes.string, +}); + +// Export as default for backward compatibility with JavaScript files +export default savedMetricTypePropTypes; diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js index fb806e0cb6..5c7bf310b7 100644 --- a/superset-frontend/webpack.config.js +++ b/superset-frontend/webpack.config.js @@ -184,22 +184,68 @@ if (!isDevMode) { chunkFilename: '[name].[chunkhash].chunk.css', }), ); +} - // Runs type checking on a separate process to speed up the build +// Type checking for both dev and production +// In dev mode, this provides real-time type checking and builds .d.ts files for plugins +// Can be disabled with DISABLE_TYPE_CHECK=true npm run dev +if (isDevMode) { + if (process.env.DISABLE_TYPE_CHECK) { + console.log('⚡ Type checking disabled (DISABLE_TYPE_CHECK=true)'); + } else { + console.log( + '✅ Type checking enabled (disable with DISABLE_TYPE_CHECK=true npm run dev)', + ); + // Optimized configuration for development - much faster type checking + plugins.push( + new ForkTsCheckerWebpackPlugin({ + typescript: { + memoryLimit: 8192, + build: true, // Generate .d.ts files + mode: 'write-references', // Handle project references properly + // Use main tsconfig but with safe performance optimizations + configOverwrite: { + compilerOptions: { + // Only safe optimizations that won't cause errors + skipLibCheck: true, // Skip checking .d.ts files - safe and huge perf boost + incremental: true, // Enable incremental compilation + }, + }, + }, + // Logger configuration + logger: 'webpack-infrastructure', + async: true, // Non-blocking type checking + // Only check files that webpack is actually processing + // This dramatically reduces the scope of type checking + issue: { + scope: 'webpack', // Only check files in webpack's module graph, not entire project + include: [ + { file: 'src/**/*.{ts,tsx}' }, + { file: 'packages/*/src/**/*.{ts,tsx}' }, + { file: 'plugins/*/src/**/*.{ts,tsx}' }, + ], + exclude: [ + { file: '**/node_modules/**' }, + { file: '**/*.test.{ts,tsx}' }, + { file: '**/*.spec.{ts,tsx}' }, + { file: '**/*.stories.tsx' }, + ], + }, + }), + ); + } +} else { + // Production mode - full type checking plugins.push( new ForkTsCheckerWebpackPlugin({ typescript: { memoryLimit: 4096, build: true, - exclude: [ - '**/node_modules/**', - '**/dist/**', - '**/coverage/**', - '**/storybook/**', - '**/*.stories.{ts,tsx,js,jsx}', - '**/*.{test,spec}.{ts,tsx,js,jsx}', - ], + mode: 'write-references', }, + // Logger configuration + logger: 'webpack-infrastructure', + async: false, // Blocking in production to ensure no type errors }), ); } @@ -344,7 +390,12 @@ const config = { }, resolve: { // resolve modules from `/superset_frontend/node_modules` and `/superset_frontend` - modules: ['node_modules', APP_DIR], + modules: [ + 'node_modules', + APP_DIR, + path.resolve(APP_DIR, 'packages'), + path.resolve(APP_DIR, 'plugins'), + ], alias: { react: path.resolve(path.join(APP_DIR, './node_modules/react')), // TODO: remove Handlebars alias once Handlebars NPM package has been updated to @@ -538,6 +589,16 @@ const config = { }, plugins, devtool: isDevMode ? 'eval-cheap-module-source-map' : false, + watchOptions: isDevMode + ? { + // Watch all plugin and package source directories + ignored: ['**/node_modules', '**/.git', '**/lib', '**/esm', '**/dist'], + // Poll less frequently to reduce file handles + poll: 2000, + // Aggregate changes for 500ms before rebuilding + aggregateTimeout: 500, + } + : undefined, }; // find all the symlinked plugins and use their source code for imports
