Skip to content

Commit c92a563

Browse files
committed
build(many): make documentation preview builds show console messages
INSTUI-4522
1 parent 7450ddc commit c92a563

File tree

92 files changed

+291
-92
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+291
-92
lines changed

packages/__docs__/buildScripts/utils/getClientProps.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function getClientProps(docs: ProcessedFile[], library: LibraryOptions) {
113113
}
114114

115115
function warning(message: string, ...args: any[]) {
116-
if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
116+
if ((process.env.NODE_ENV !== 'production' || process.env.GITHUB_PULL_REQUEST_PREVIEW === 'true') && typeof console !== 'undefined') {
117117
console.warn(`Warning: ${message}`, ...args)
118118
}
119119
}

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 } : {}
@@ -79,6 +82,9 @@ 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,

packages/canvas-high-contrast-theme/babel.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = {
2929
{
3030
coverage: Boolean(process.env.COVERAGE),
3131
esModules: Boolean(process.env.ES_MODULES),
32-
removeConsole: process.env.NODE_ENV === 'production',
32+
removeConsole:
33+
process.env.NODE_ENV === 'production' &&
34+
process.env.GITHUB_PULL_REQUEST_PREVIEW !== 'true',
3335
transformImports: false
3436
}
3537
]

packages/canvas-theme/babel.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = {
2929
{
3030
coverage: Boolean(process.env.COVERAGE),
3131
esModules: Boolean(process.env.ES_MODULES),
32-
removeConsole: process.env.NODE_ENV === 'production',
32+
removeConsole:
33+
process.env.NODE_ENV === 'production' &&
34+
process.env.GITHUB_PULL_REQUEST_PREVIEW !== 'true',
3335
transformImports: false
3436
}
3537
]

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/debounce/babel.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = {
2929
{
3030
coverage: Boolean(process.env.COVERAGE),
3131
esModules: Boolean(process.env.ES_MODULES),
32-
removeConsole: process.env.NODE_ENV === 'production',
32+
removeConsole:
33+
process.env.NODE_ENV === 'production' &&
34+
process.env.GITHUB_PULL_REQUEST_PREVIEW !== 'true',
3335
transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
3436
}
3537
]

packages/emotion/babel.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ module.exports = {
2929
{
3030
coverage: Boolean(process.env.COVERAGE),
3131
esModules: Boolean(process.env.ES_MODULES),
32-
removeConsole: process.env.NODE_ENV === 'production',
32+
removeConsole:
33+
process.env.NODE_ENV === 'production' &&
34+
process.env.GITHUB_PULL_REQUEST_PREVIEW !== 'true',
3335
transformImports: Boolean(process.env.TRANSFORM_IMPORTS)
3436
}
3537
]

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
)

0 commit comments

Comments
 (0)