Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable logs for staging and production native apps #30875

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,8 @@ const defaultPlugins = [
];

const webpack = {
env: {
production: {
presets: defaultPresets,
plugins: [...defaultPlugins, 'transform-remove-console'],
},
development: {
presets: defaultPresets,
plugins: defaultPlugins,
},
},
presets: defaultPresets,
plugins: defaultPlugins,
Comment on lines -20 to +21
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The env.production path were never engaged for web builds. The reason being, NODE_ENV isn't defined before initiating the build process.
  • I'm omitting the 'transform-remove-console' plugin. Our intent is to retain console logs for web/desktop in production builds.

In essence, this modification aligns the dev and prod configurations, making them the same, hence the presented code change.

};

const metro = {
Expand Down Expand Up @@ -78,6 +70,11 @@ const metro = {
},
],
],
env: {
production: {
plugins: ['transform-remove-console', {exclude: ['error', 'warn']}],
},
},
Comment on lines +73 to +77
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should preserve, the error and warn logs, because they aren't used frequently to impact the UX

That's why I've opted to keep them (exclude them from removal) here

};

/*
Expand All @@ -102,11 +99,19 @@ if (process.env.CAPTURE_METRICS === 'true') {
]);
}

module.exports = ({caller}) => {
module.exports = (api) => {
console.debug('babel.config.js');
console.debug(' - api.version:', api.version);
console.debug(' - api.env:', api.env());
console.debug(' - process.env.NODE_ENV:', process.env.NODE_ENV);
console.debug(' - process.env.BABEL_ENV:', process.env.BABEL_ENV);
Comment on lines +102 to +107
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've included these logs, because I've found out that when we're building the production web release, the environment output is development, which is why the webpack configuration above never used the env.production path


// For `react-native` (iOS/Android) caller will be "metro"
// For `webpack` (Web) caller will be "@babel-loader"
// For jest, it will be babel-jest
// For `storybook` there won't be any config at all so we must give default argument of an empty object
const runningIn = caller((args = {}) => args.name);
const runningIn = api.caller((args = {}) => args.name);
console.debug(' - running in: ', runningIn);

return ['metro', 'babel-jest'].includes(runningIn) ? metro : webpack;
};
Loading