Allow transform-runtime to insert runtime references with absolute paths.#8435
Merged
loganfsmyth merged 1 commit intobabel:masterfrom Aug 14, 2018
Merged
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8815/ |
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/8770/ |
| function resolveAbsoluteRuntime(moduleName: string, dirname: string) { | ||
| try { | ||
| return path.dirname( | ||
| resolve.sync(`${moduleName}/package.json`, { basedir: dirname }), |
Member
There was a problem hiding this comment.
Why do we need to look for package.json?
Member
Author
There was a problem hiding this comment.
The runtime doesn't have a main or index because it's meant to be a collection of independent files. Since we want to resolve the directory location though, we do need a specific file to resolve, and package.json fits those requirements well.
nicolo-ribaudo
approved these changes
Aug 13, 2018
73c9547 to
5d9c662
Compare
5d9c662 to
67c7ba5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows users to run
transform-runtimebroadly across a whole project. By default,transform-runtimeimports from@babel/runtime/foodirectly, but that only works if@babel/runtimeis in the node modules of the file that is being compiled. This can be problematic for nested node modules, or npm-linked modules, among other cases. To avoid worrying about how the runtime module's location, this allows users to resolve the runtime once up front, and then insert absolute paths to the runtime into the output code.Using absolute paths is not desirable if files are compiled for use at a later time, but in contexts where a file is compiled and then immediately consumed, they can be quite helpful.
This PR exposes two approaches for resolving the runtime:
absoluteRuntime: true- Resolve the runtime:cwdif thetransform-runtimeplugin is passed as a programmatic arg to Babeltransform-runtimeis enabled via a config fileabsoluteRuntime: '/projects/thing/src'__dirnameof some general build process script. e.g. will look at/projects/thing/src/node_modules/@babel/runtime/foo/projects/thing/node_modules/@babel/runtime/foo/projects/node_modules/@babel/runtime/foo/node_modules/@babel/runtime/foocc @insin