Skip to content

Commit a2a1965

Browse files
committed
chore(many): make documentation preview builds show console messages
INSTUI-4522
1 parent 101c2a9 commit a2a1965

File tree

9 files changed

+44
-8
lines changed

9 files changed

+44
-8
lines changed

.github/workflows/preview.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ on:
1212
jobs:
1313
deploy-preview:
1414
runs-on: ubuntu-latest
15+
env:
16+
GITHUB_PULL_REQUEST_PREVIEW: 'true'
1517
steps:
1618
- uses: actions/checkout@v4
1719
- name: Install Node 22

packages/__docs__/webpack.config.mjs

Lines changed: 6 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 } : {}
@@ -80,6 +83,9 @@ const config = merge(baseConfig, {
8083
template: './src/index.html',
8184
chunks: ['main'],
8285
}),
86+
new webpack.DefinePlugin({
87+
'process.env.GITHUB_PULL_REQUEST_PREVIEW': JSON.stringify(GITHUB_PULL_REQUEST_PREVIEW),
88+
}),
8389
],
8490
optimization: {
8591
usedExports: true,

packages/console/src/console.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ function logMessage(
5555
message: string,
5656
...args: unknown[]
5757
) {
58-
if (process.env.NODE_ENV !== 'production' && !condition) {
58+
const isGitHubPullRequestPreview =
59+
typeof process !== 'undefined' &&
60+
process?.env?.GITHUB_PULL_REQUEST_PREVIEW === 'true'
61+
if (
62+
(isGitHubPullRequestPreview || process.env.NODE_ENV !== 'production') &&
63+
!condition
64+
) {
5965
if (typeof console[level] === 'function') {
6066
const renderStack = withRenderStack ? getRenderStack() : ''
6167
//@ts-expect-error level can be 'constructor' which is not callable

packages/emotion/src/InstUISettingsProvider/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ function InstUISettingsProvider({
7373
}: InstUIProviderProps) {
7474
const finalDir = dir || useContext(TextDirectionContext)
7575

76-
if (process.env.NODE_ENV !== 'production' && finalDir === 'auto') {
76+
if (
77+
(process.env.NODE_ENV !== 'production' ||
78+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true') &&
79+
finalDir === 'auto'
80+
) {
7781
console.warn(
7882
"'auto' is not an supported value for the 'dir' prop. Please pass 'ltr' or 'rtl'"
7983
)

packages/emotion/src/getTheme.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ const getTheme =
5454
// we need to clone the ancestor theme not to override it
5555
let currentTheme
5656
if (Object.keys(ancestorTheme).length === 0) {
57-
if (process.env.NODE_ENV !== 'production') {
57+
if (
58+
process.env.NODE_ENV !== 'production' ||
59+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true'
60+
) {
5861
console.warn(
5962
'No theme provided for [InstUISettingsProvider], using default `canvas` theme.'
6063
)
@@ -78,7 +81,10 @@ const getTheme =
7881
// If the prop passed is not an Object, it will throw an error.
7982
// We are using this fail-safe here for the non-TS users,
8083
// because the whole page can break without a theme.
81-
if (process.env.NODE_ENV !== 'production') {
84+
if (
85+
process.env.NODE_ENV !== 'production' ||
86+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true'
87+
) {
8288
console.warn(
8389
'The `theme` property provided to InstUISettingsProvider is not a valid InstUI theme object.\ntheme: ',
8490
resolvedThemeOrOverride

packages/emotion/src/useTheme.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ const useTheme = () => {
4040
// This reads the theme from Emotion's ThemeContext
4141
let theme = useEmotionTheme() as BaseThemeOrOverride
4242
if (isEmpty(theme)) {
43-
if (process.env.NODE_ENV !== 'production') {
43+
if (
44+
process.env.NODE_ENV !== 'production' ||
45+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true'
46+
) {
4447
console.warn(
4548
`No theme provided for [InstUISettingsProvider], using default <canvas> theme.`
4649
)

packages/ui-babel-preset/lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ module.exports = function (
108108
)
109109
}
110110

111-
if (opts.removeConsole) {
111+
if (
112+
process.env.GITHUB_PULL_REQUEST_PREVIEW !== 'true' &&
113+
opts.removeConsole
114+
) {
112115
if (typeof opts.removeConsole === 'object') {
113116
plugins.push([
114117
require('babel-plugin-transform-remove-console'),

packages/ui-i18n/src/textDirectionContextConsumer.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ const textDirectionContextConsumer: TextDirectionContextConsumerType =
120120
return (
121121
<TextDirectionContext.Consumer>
122122
{(dir) => {
123-
if (process.env.NODE_ENV !== 'production' && dir === 'auto') {
123+
if (
124+
(process.env.NODE_ENV !== 'production' ||
125+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true') &&
126+
dir === 'auto'
127+
) {
124128
console.warn(
125129
"'auto' is not an supported value for the 'dir' prop. Please pass 'ltr' or 'rtl'"
126130
)

packages/ui-view/src/View/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ class View extends Component<ViewProps> {
9494

9595
let shouldLogError = true
9696
try {
97-
shouldLogError = process.env.NODE_ENV !== 'production'
97+
shouldLogError =
98+
process.env.NODE_ENV !== 'production' ||
99+
process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true'
98100
} catch (e) {
99101
if (e instanceof ReferenceError) {
100102
// if process is not available a ReferenceError is thrown

0 commit comments

Comments
 (0)