File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed
Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 2424 - name : Build docs-app
2525 run : npm run build:docs
2626 if : github.event.action != 'closed'
27+ env :
28+ GITHUB_PULL_REQUEST_PREVIEW : ' true'
2729 - uses : rossjrw/pr-preview-action@v1
2830 with :
2931 source-dir : ./packages/__docs__/__build__
Original file line number Diff line number Diff line change @@ -30,9 +30,12 @@ import { globbySync } from 'globby'
3030import { merge } from 'webpack-merge'
3131import { processSingleFile } from './lib/build-docs.mjs'
3232import resolve from './resolve.mjs'
33+ import webpack from 'webpack'
34+ import TerserPlugin from 'terser-webpack-plugin'
3335
3436const ENV = process . env . NODE_ENV || 'production'
3537const DEBUG = process . env . DEBUG || ENV === 'development'
38+ const GITHUB_PULL_REQUEST_PREVIEW = process . env . GITHUB_PULL_REQUEST_PREVIEW || 'false'
3639
3740const outputPath = resolvePath ( import . meta. dirname , '__build__' )
3841const resolveAliases = DEBUG ? { resolve } : { }
@@ -79,9 +82,22 @@ const config = merge(baseConfig, {
7982 template : './src/index.html' ,
8083 chunks : [ 'main' ] ,
8184 } ) ,
85+ new webpack . DefinePlugin ( {
86+ 'process.env.GITHUB_PULL_REQUEST_PREVIEW' : JSON . stringify ( GITHUB_PULL_REQUEST_PREVIEW ) ,
87+ } ) ,
8288 ] ,
8389 optimization : {
8490 usedExports : true ,
91+ minimize : true ,
92+ minimizer : [
93+ new TerserPlugin ( {
94+ terserOptions : {
95+ compress : {
96+ drop_console : GITHUB_PULL_REQUEST_PREVIEW !== 'true' ,
97+ } ,
98+ } ,
99+ } ) ,
100+ ] ,
85101 } ,
86102 ...resolveAliases ,
87103 mode : 'production' ,
Original file line number Diff line number Diff line change @@ -55,7 +55,11 @@ function logMessage(
5555 message : string ,
5656 ...args : unknown [ ]
5757) {
58- if ( process . env . NODE_ENV !== 'production' && ! condition ) {
58+ if (
59+ ( process . env . GITHUB_PULL_REQUEST_PREVIEW ||
60+ process . env . NODE_ENV !== 'production' ) &&
61+ ! condition
62+ ) {
5963 if ( typeof console [ level ] === 'function' ) {
6064 const renderStack = withRenderStack ? getRenderStack ( ) : ''
6165 //@ts -expect-error level can be 'constructor' which is not callable
Original file line number Diff line number Diff line change @@ -308,6 +308,21 @@ class Alert extends Component<AlertProps, AlertState> {
308308 }
309309
310310 render ( ) {
311+ // Test 1: Check if the code path exists
312+ // eslint-disable-next-line no-console
313+ console . log ( 'TEST: This line should always appear' )
314+
315+ // Test 2: Check if conditional code exists
316+ if ( process . env . NODE_ENV !== 'production' ) {
317+ // eslint-disable-next-line no-console
318+ console . log ( 'TEST: This should only appear in development' )
319+ }
320+
321+ // Test 3: Force the condition to be runtime-evaluated
322+ if ( process . env . GITHUB_PULL_REQUEST_PREVIEW ) {
323+ // eslint-disable-next-line no-console
324+ console . log ( 'TEST: Runtime evaluation' )
325+ }
311326 const liveRegion = this . getLiveRegion ( )
312327 const screenReaderContent = liveRegion
313328 ? this . createScreenReaderPortal ( liveRegion )
You can’t perform that action at this time.
0 commit comments