-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Add source maps #21946
Add source maps #21946
Conversation
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
not stale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A rather verbose review + deep dive research into the context of why certain changes were made here, as well as potential solutions for what I believe are the remaining issues that would block this PR from landing. At least in theory, I think all of the potential issues have solutions now. Would love to see this work able to land!
There are a few minor code cleanup 'suggestions' as well, which can all be automatically applied as a single commit as follows:
@@ -364,26 +368,38 @@ function getPlugins( | |||
bundleType === RN_FB_PROFILING; | |||
const shouldStayReadable = isFBWWWBundle || isRNBundle || forcePrettyOutput; | |||
return [ | |||
// Extract error codes from invariant() messages into a file. | |||
// // Extract error codes from invariant() messages into a file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// // Extract error codes from invariant() messages into a file. | |
// Extract error codes from invariant() messages into a file. |
There seem to be a bunch of places where the comment //
has been doubled up in this PR. While it's minor, it will help minimise the diff to better see where the real changes are happening.
// Use Node resolution mechanism. | ||
resolve({ | ||
skip: externals, | ||
}), | ||
// Remove license headers from individual modules | ||
// // Use Node resolution mechanism. | ||
resolve(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was skip: externals
removed from resolve
here out of curiosity?
It looks like the old version of the library removed it in 3.0.0
in favour of using external
:
- https://github.com/rollup/rollup-plugin-node-resolve/blob/master/CHANGELOG.md#300
- [BREAKING] Remove options.skip rollup/rollup-plugin-node-resolve#90
-
People are better off using the
external
option in the main Rollup config
-
- [BREAKING] Remove options.skip rollup/rollup-plugin-node-resolve#90
- https://github.com/rollup/rollup-plugin-node-resolve#resolving-built-ins-like-fs
Looking at the options for the new library, these are the parts that seem potentially relevant:
// // Turn __DEV__ and process.env checks into constants. | ||
replace({ | ||
preventAssignment: true, | ||
values: { | ||
__DEV__: isProduction ? 'false' : 'true', | ||
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false', | ||
__UMD__: isUMDBundle ? 'true' : 'false', | ||
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'", | ||
__EXPERIMENTAL__, | ||
// Enable forked reconciler. | ||
// NOTE: I did not put much thought into how to configure this. | ||
__VARIANT__: bundle.enableNewReconciler === true, | ||
}, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why was this moved earlier in the chain of things? (originally down around line 402-412)
I suspect that this may be incorrect, as now it is being run before useForks
, which could result in different code being imported (and thus more potential locations of use strict
.
Comparing the diff, the main changes seem to be the addition of preventAssignment
, and wrapping the values
(presumably based on a change in the options of the new lib version)
New lib:
- https://github.com/rollup/plugins/tree/master/packages/replace#options
- https://github.com/rollup/plugins/tree/master/packages/replace#preventassignment
-
Prevents replacing strings where they are followed by a single equals sign.
-
Old lib:
- https://github.com/rollup/rollup-plugin-replace#options
-
All other options are treated as
string: replacement
replacers... -
...unless you want to be careful about separating
values
from other options, in which case you can
-
__VARIANT__: bundle.enableNewReconciler === true, | ||
}, | ||
}), | ||
// // Shim any modules that need forking in this environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// // Shim any modules that need forking in this environment. | |
// Shim any modules that need forking in this environment. |
useForks(forks), | ||
// Ensure we don't try to bundle any fbjs modules. | ||
// // Ensure we don't try to bundle any fbjs modules. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// // Ensure we don't try to bundle any fbjs modules. | |
// Ensure we don't try to bundle any fbjs modules. |
babelrc: false, | ||
configFile: false, | ||
sourceMaps: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like @rollup/plugin-babel
generates sourcemaps by default since 2.1.0
:
So we probably don't need to add this (unless it's also going to other plugins that don't set it by default?)
sourceMaps: true, |
"@rollup/plugin-replace": "^2.4.2", | ||
"@rollup/plugin-commonjs": "19.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.1", | ||
"@rollup/plugin-babel": "^5.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest versions:
"rollup": "^2.53.2", | ||
"rollup-plugin-prettier": "^2.1.0", | ||
"rollup-plugin-strip-banner": "^2.0.0", | ||
"rollup-plugin-terser": "^7.0.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Latest versions:
@@ -235,7 +239,7 @@ function getRollupOutputOptions( | |||
freeze: !isProduction, | |||
interop: false, | |||
name: globalName, | |||
sourcemap: false, | |||
sourcemap: !isPretty, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in another comment in this review, I think maybe we should be using shouldStayReadable
here directly, since the only time where we (currently) wouldn't be generating sourcemaps (to my knowledge) is when prettier
is called (though personally, if it doesn't change the build time dramatically, I would be potentially inclined to keep it enabled even then)
sourcemap: !isPretty, | |
sourcemap: !shouldStayReadable, |
skip: externals, | ||
}), | ||
// Remove license headers from individual modules | ||
// // Use Node resolution mechanism. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// // Use Node resolution mechanism. | |
// Use Node resolution mechanism. |
Update Rollup and related plugins to their most recent versions + resolve any breaking changes/deprecations/etc along the way. I made each change piece by piece, so the commit history tells a pretty good story of what was changed where/how/why. fixes #24894 For the full deepdive/context, see: - #24894 The inspiration for this came from @jasonwilliams 's PR for attempting to add sourcemap output support to React's builds: - #20186 - #21946 But I figured that it would be useful to minimise the scope of changes in that PR, and to modernise the build tooling along the way. If any of these updates rely on a node version later than `10.x`, then the following PR may have to land first, otherwise things might break on AppVeyor: - #24891 - #24892 Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu>
Update Rollup and related plugins to their most recent versions + resolve any breaking changes/deprecations/etc along the way. I made each change piece by piece, so the commit history tells a pretty good story of what was changed where/how/why. fixes #24894 For the full deepdive/context, see: - #24894 The inspiration for this came from @jasonwilliams 's PR for attempting to add sourcemap output support to React's builds: - #20186 - #21946 But I figured that it would be useful to minimise the scope of changes in that PR, and to modernise the build tooling along the way. If any of these updates rely on a node version later than `10.x`, then the following PR may have to land first, otherwise things might break on AppVeyor: - #24891 - #24892 Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu> DiffTrain build for [6b6d061](6b6d061) [View git log for this commit](https://github.com/facebook/react/commits/6b6d0617eff48860c5b4e3e79c74cbd3312cf45a)
It looks like the work done in the following PR is likely to supercede and replace this PR: |
Since the above PR (#26446) has been merged, this PR is now obsolete, and can probably be closed out. |
Update Rollup and related plugins to their most recent versions + resolve any breaking changes/deprecations/etc along the way. I made each change piece by piece, so the commit history tells a pretty good story of what was changed where/how/why. fixes facebook/react#24894 For the full deepdive/context, see: - facebook/react#24894 The inspiration for this came from @jasonwilliams 's PR for attempting to add sourcemap output support to React's builds: - facebook/react#20186 - facebook/react#21946 But I figured that it would be useful to minimise the scope of changes in that PR, and to modernise the build tooling along the way. If any of these updates rely on a node version later than `10.x`, then the following PR may have to land first, otherwise things might break on AppVeyor: - facebook/react#24891 - facebook/react#24892 Co-authored-by: Sebastian Markbage <sebastian@calyptus.eu> DiffTrain build for [6b6d0617eff48860c5b4e3e79c74cbd3312cf45a](facebook/react@6b6d061) [View git log for this commit](https://github.com/facebook/react/commits/6b6d0617eff48860c5b4e3e79c74cbd3312cf45a)
Resolved in #26446 Thank you @jasonwilliams for starting this effort 👍🏻 |
Fixes #20186
Summary
Attempts to get sourcemaps working.
Status:
renderChunk
is commented out for now as I had to give up with that oneshouldStayReadable
is true.