Make the filename option, as exposed to the plugins, consistently relative to the working directory (#7956)

| Q                        | A <!--(Can use an emoji 👍) -->
| ------------------------ | ---
| Fixed Issues?            | 
| Patch: Bug Fix?          | Y
| Major: Breaking Change?  | N
| Minor: New Feature?      |
| Tests Added + Pass?      | Yes
| Documentation PR         | <!-- If so, add `[skip ci]` to your commit message to skip CI -->
| Any Dependency Changes?  |
| License                  | MIT

Currently the `opts.filename` value exposed to plugins is just whatever the user passed. While it _could_ be relative to the working directory, if Babel was passed an absolute URL, it'll be absolute.

This PR explicitly ensures the filename is a relative path based on the working directory. This also exposes an officially endorsed API for reading the working directory path.
This commit is contained in:
Logan Smyth
2018-05-21 17:10:57 -07:00
committed by GitHub
parent 3bee37b14d
commit 69cca412eb
7 changed files with 51 additions and 33 deletions

View File

@@ -1,10 +1,10 @@
var actual = transform(
'var x = <sometag />',
Object.assign({}, opts, { filename: '/fake/path/mock.js' })
Object.assign({}, opts, { filename: 'fake/path/mock.js' })
).code;
var expected = multiline([
'var _jsxFileName = "/fake/path/mock.js";',
'var _jsxFileName = "fake/path/mock.js";',
'var x = <sometag __source={{',
' fileName: _jsxFileName,',
' lineNumber: 1',