Skip to content

Commit 608e3ba

Browse files
mistercrunchclaude
andauthored
feat(build): auto-rebuild/check TypeScript types for packages/plugins in webpack (#35240)
Co-authored-by: Claude <[email protected]>
1 parent b6f6b75 commit 608e3ba

File tree

3 files changed

+85
-14
lines changed

3 files changed

+85
-14
lines changed

superset-frontend/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ cypress/screenshots
33
cypress/videos
44
src/temp
55
.temp_cache/
6+
.tsbuildinfo

superset-frontend/src/explore/components/controls/MetricControl/savedMetricType.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
export { savedMetricType } from './types';
19+
import PropTypes from 'prop-types';
2020

21-
// For backward compatibility with PropTypes usage
22-
export { savedMetricType as default } from './types';
21+
export type { savedMetricType } from './types';
22+
23+
// PropTypes definition for JavaScript files
24+
const savedMetricTypePropTypes = PropTypes.shape({
25+
metric_name: PropTypes.string.isRequired,
26+
verbose_name: PropTypes.string,
27+
expression: PropTypes.string,
28+
});
29+
30+
// Export as default for backward compatibility with JavaScript files
31+
export default savedMetricTypePropTypes;

superset-frontend/webpack.config.js

Lines changed: 72 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ const devserverHost =
6565
const isDevMode = mode !== 'production';
6666
const isDevServer = process.argv[1].includes('webpack-dev-server');
6767

68+
// TypeScript checker memory limit (in MB)
69+
const TYPESCRIPT_MEMORY_LIMIT = 4096;
70+
6871
const output = {
6972
path: BUILD_DIR,
7073
publicPath: '/static/assets/',
@@ -184,21 +187,64 @@ if (!isDevMode) {
184187
chunkFilename: '[name].[chunkhash].chunk.css',
185188
}),
186189
);
190+
}
187191

188-
// Runs type checking on a separate process to speed up the build
192+
// Type checking for both dev and production
193+
// In dev mode, this provides real-time type checking and builds .d.ts files for plugins
194+
// Can be disabled with DISABLE_TYPE_CHECK=true npm run dev
195+
if (isDevMode) {
196+
if (process.env.DISABLE_TYPE_CHECK) {
197+
console.log('⚡ Type checking disabled (DISABLE_TYPE_CHECK=true)');
198+
} else {
199+
console.log(
200+
'✅ Type checking enabled (disable with DISABLE_TYPE_CHECK=true npm run dev)',
201+
);
202+
// Optimized configuration for development - much faster type checking
203+
plugins.push(
204+
new ForkTsCheckerWebpackPlugin({
205+
typescript: {
206+
memoryLimit: TYPESCRIPT_MEMORY_LIMIT,
207+
build: true, // Generate .d.ts files
208+
mode: 'write-references', // Handle project references properly
209+
// Use main tsconfig but with safe performance optimizations
210+
configOverwrite: {
211+
compilerOptions: {
212+
// Only safe optimizations that won't cause errors
213+
skipLibCheck: true, // Skip checking .d.ts files - safe and huge perf boost
214+
incremental: true, // Enable incremental compilation
215+
},
216+
},
217+
},
218+
// Logger configuration
219+
logger: 'webpack-infrastructure',
220+
async: true, // Non-blocking type checking
221+
// Only check files that webpack is actually processing
222+
// This dramatically reduces the scope of type checking
223+
issue: {
224+
scope: 'webpack', // Only check files in webpack's module graph, not entire project
225+
include: [
226+
{ file: 'src/**/*.{ts,tsx}' },
227+
{ file: 'packages/*/src/**/*.{ts,tsx}' },
228+
{ file: 'plugins/*/src/**/*.{ts,tsx}' },
229+
],
230+
exclude: [{ file: '**/node_modules/**' }],
231+
},
232+
}),
233+
);
234+
}
235+
} else {
236+
// Production mode - full type checking
189237
plugins.push(
190238
new ForkTsCheckerWebpackPlugin({
191239
typescript: {
192-
memoryLimit: 4096,
240+
memoryLimit: TYPESCRIPT_MEMORY_LIMIT,
193241
build: true,
194-
exclude: [
195-
'**/node_modules/**',
196-
'**/dist/**',
197-
'**/coverage/**',
198-
'**/storybook/**',
199-
'**/*.stories.{ts,tsx,js,jsx}',
200-
'**/*.{test,spec}.{ts,tsx,js,jsx}',
201-
],
242+
mode: 'write-references',
243+
},
244+
// Logger configuration
245+
logger: 'webpack-infrastructure',
246+
issue: {
247+
exclude: [{ file: '**/node_modules/**' }],
202248
},
203249
}),
204250
);
@@ -344,7 +390,12 @@ const config = {
344390
},
345391
resolve: {
346392
// resolve modules from `/superset_frontend/node_modules` and `/superset_frontend`
347-
modules: ['node_modules', APP_DIR],
393+
modules: [
394+
'node_modules',
395+
APP_DIR,
396+
path.resolve(APP_DIR, 'packages'),
397+
path.resolve(APP_DIR, 'plugins'),
398+
],
348399
alias: {
349400
react: path.resolve(path.join(APP_DIR, './node_modules/react')),
350401
// TODO: remove Handlebars alias once Handlebars NPM package has been updated to
@@ -538,6 +589,16 @@ const config = {
538589
},
539590
plugins,
540591
devtool: isDevMode ? 'eval-cheap-module-source-map' : false,
592+
watchOptions: isDevMode
593+
? {
594+
// Watch all plugin and package source directories
595+
ignored: ['**/node_modules', '**/.git', '**/lib', '**/esm', '**/dist'],
596+
// Poll less frequently to reduce file handles
597+
poll: 2000,
598+
// Aggregate changes for 500ms before rebuilding
599+
aggregateTimeout: 500,
600+
}
601+
: undefined,
541602
};
542603

543604
// find all the symlinked plugins and use their source code for imports

0 commit comments

Comments
 (0)