Skip to content

Commit 1a4eb55

Browse files
committed
build(ui-alerts,console): make documentation preview builds show console logs
INSTUI-4522
1 parent f5941b1 commit 1a4eb55

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

.github/workflows/preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
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__

packages/__docs__/webpack.config.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ import { globbySync } from 'globby'
3030
import { merge } from 'webpack-merge'
3131
import { processSingleFile } from './lib/build-docs.mjs'
3232
import resolve from './resolve.mjs'
33+
import webpack from 'webpack'
34+
import TerserPlugin from 'terser-webpack-plugin'
3335

3436
const ENV = process.env.NODE_ENV || 'production'
3537
const DEBUG = process.env.DEBUG || ENV === 'development'
38+
const GITHUB_PULL_REQUEST_PREVIEW = process.env.GITHUB_PULL_REQUEST_PREVIEW || 'false'
3639

3740
const outputPath = resolvePath(import.meta.dirname, '__build__')
3841
const 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',

packages/console/src/console.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

packages/ui-alerts/src/Alert/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)