Treat all filenames as absolute paths. (#8044)

This commit is contained in:
Logan Smyth 2018-05-24 20:56:19 -07:00 committed by GitHub
parent 98ff2ce877
commit 53e4d74ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 69 additions and 45 deletions

View File

@ -1 +1 @@
SyntaxError: test.js: Unexpected token, expected ";" (2:10) SyntaxError: <CWD>/test.js: Unexpected token, expected ";" (2:10)

View File

@ -46,7 +46,20 @@ const saveInFiles = function(files) {
}); });
}; };
const assertTest = function(stdout, stderr, opts) { const replacePaths = function(str, cwd) {
let prev;
do {
prev = str;
str = str.replace(cwd, "<CWD>");
} while (str !== prev);
return str;
};
const assertTest = function(stdout, stderr, opts, cwd) {
stdout = replacePaths(stdout, cwd);
stderr = replacePaths(stderr, cwd);
const expectStderr = opts.stderr.trim(); const expectStderr = opts.stderr.trim();
stderr = stderr.trim(); stderr = stderr.trim();
@ -138,7 +151,7 @@ const buildTest = function(binName, testName, opts) {
let err; let err;
try { try {
assertTest(stdout, stderr, opts); assertTest(stdout, stderr, opts, tmpLoc);
} catch (e) { } catch (e) {
err = e; err = e;
} }

View File

@ -60,9 +60,7 @@ export default function loadPrivatePartialConfig(
options.cwd = context.cwd; options.cwd = context.cwd;
options.root = context.root; options.root = context.root;
options.filename = options.filename =
typeof context.filename === "string" typeof context.filename === "string" ? context.filename : undefined;
? path.relative(context.cwd, context.filename)
: undefined;
options.plugins = configChain.plugins.map(descriptor => options.plugins = configChain.plugins.map(descriptor =>
createItemFromDescriptor(descriptor), createItemFromDescriptor(descriptor),

View File

@ -936,7 +936,7 @@ describe("buildConfigChain", function() {
}), }),
).toEqual({ ).toEqual({
...getDefaults(), ...getDefaults(),
filename: path.basename(filename), filename: filename,
cwd: path.dirname(filename), cwd: path.dirname(filename),
root: path.dirname(filename), root: path.dirname(filename),
comments: true, comments: true,
@ -948,7 +948,7 @@ describe("buildConfigChain", function() {
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({ expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
...getDefaults(), ...getDefaults(),
filename: path.basename(filename), filename: filename,
cwd: path.dirname(filename), cwd: path.dirname(filename),
root: path.dirname(filename), root: path.dirname(filename),
comments: true, comments: true,
@ -960,7 +960,7 @@ describe("buildConfigChain", function() {
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({ expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
...getDefaults(), ...getDefaults(),
filename: path.basename(filename), filename: filename,
cwd: path.dirname(filename), cwd: path.dirname(filename),
root: path.dirname(filename), root: path.dirname(filename),
comments: true, comments: true,
@ -1002,7 +1002,7 @@ describe("buildConfigChain", function() {
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({ expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
...getDefaults(), ...getDefaults(),
filename: path.basename(filename), filename: filename,
cwd: path.dirname(filename), cwd: path.dirname(filename),
root: path.dirname(filename), root: path.dirname(filename),
comments: true, comments: true,

View File

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

View File

@ -66,6 +66,9 @@ const buildTest = opts => {
let err; let err;
try { try {
stdout = replacePaths(stdout);
stderr = replacePaths(stderr);
assertTest(stdout, stderr, opts); assertTest(stdout, stderr, opts);
} catch (e) { } catch (e) {
err = e; err = e;
@ -76,6 +79,16 @@ const buildTest = opts => {
}; };
}; };
function replacePaths(str) {
let prev;
do {
prev = str;
str = str.replace(tmpLoc, "<CWD>");
} while (str !== prev);
return str;
}
describe("debug output", () => { describe("debug output", () => {
let cwd; let cwd;

View File

@ -37,7 +37,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within { "android":"4" } es6.array.copy-within { "android":"4" }
es6.array.fill { "android":"4" } es6.array.fill { "android":"4" }
es6.array.find { "android":"4" } es6.array.find { "android":"4" }
@ -147,4 +147,4 @@ Using polyfills with `entry` option:
web.timers { "android":"4" } web.timers { "android":"4" }
web.immediate { "android":"4" } web.immediate { "android":"4" }
web.dom.iterable { "android":"4" } web.dom.iterable { "android":"4" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -20,5 +20,5 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] `import '@babel/polyfill'` was not found. [<CWD>/src/in.js] `import '@babel/polyfill'` was not found.
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -40,7 +40,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.sort { "chrome":"55" } es6.array.sort { "chrome":"55" }
es7.object.define-getter { "chrome":"55" } es7.object.define-getter { "chrome":"55" }
es7.object.define-setter { "chrome":"55" } es7.object.define-setter { "chrome":"55" }
@ -53,4 +53,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"55" } web.timers { "chrome":"55" }
web.immediate { "chrome":"55" } web.immediate { "chrome":"55" }
web.dom.iterable { "chrome":"55" } web.dom.iterable { "chrome":"55" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -39,7 +39,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within { "ie":"10" } es6.array.copy-within { "ie":"10" }
es6.array.fill { "ie":"10" } es6.array.fill { "ie":"10" }
es6.array.find { "ie":"10" } es6.array.find { "ie":"10" }
@ -163,4 +163,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"54", "ie":"10", "node":"6" } web.timers { "chrome":"54", "ie":"10", "node":"6" }
web.immediate { "chrome":"54", "ie":"10", "node":"6" } web.immediate { "chrome":"54", "ie":"10", "node":"6" }
web.dom.iterable { "chrome":"54", "ie":"10", "node":"6" } web.dom.iterable { "chrome":"54", "ie":"10", "node":"6" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -32,7 +32,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.every { "electron":"0.36" } es6.array.every { "electron":"0.36" }
es6.array.filter { "electron":"0.36" } es6.array.filter { "electron":"0.36" }
es6.array.for-each { "electron":"0.36" } es6.array.for-each { "electron":"0.36" }
@ -123,4 +123,4 @@ Using polyfills with `entry` option:
web.timers { "electron":"0.36" } web.timers { "electron":"0.36" }
web.immediate { "electron":"0.36" } web.immediate { "electron":"0.36" }
web.dom.iterable { "electron":"0.36" } web.dom.iterable { "electron":"0.36" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -37,7 +37,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.sort { "chrome":"55" } es6.array.sort { "chrome":"55" }
es7.object.define-getter { "chrome":"55" } es7.object.define-getter { "chrome":"55" }
es7.object.define-setter { "chrome":"55" } es7.object.define-setter { "chrome":"55" }
@ -50,4 +50,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"55" } web.timers { "chrome":"55" }
web.immediate { "chrome":"55" } web.immediate { "chrome":"55" }
web.dom.iterable { "chrome":"55" } web.dom.iterable { "chrome":"55" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -26,4 +26,4 @@ Using plugins:
transform-dotall-regex { "firefox":"52", "node":"7.4" } transform-dotall-regex { "firefox":"52", "node":"7.4" }
Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set. Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -16,7 +16,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.sort { "chrome":"60" } es6.array.sort { "chrome":"60" }
es7.object.define-getter { "chrome":"60" } es7.object.define-getter { "chrome":"60" }
es7.object.define-setter { "chrome":"60" } es7.object.define-setter { "chrome":"60" }
@ -27,4 +27,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"60" } web.timers { "chrome":"60" }
web.immediate { "chrome":"60" } web.immediate { "chrome":"60" }
web.dom.iterable { "chrome":"60" } web.dom.iterable { "chrome":"60" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -36,7 +36,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within {} es6.array.copy-within {}
es6.array.every {} es6.array.every {}
es6.array.fill {} es6.array.fill {}
@ -181,4 +181,4 @@ Using polyfills with `entry` option:
web.timers {} web.timers {}
web.immediate {} web.immediate {}
web.dom.iterable {} web.dom.iterable {}
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -42,7 +42,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within { "ie":"10", "safari":"7" } es6.array.copy-within { "ie":"10", "safari":"7" }
es6.array.fill { "ie":"10", "safari":"7" } es6.array.fill { "ie":"10", "safari":"7" }
es6.array.find { "ie":"10", "safari":"7" } es6.array.find { "ie":"10", "safari":"7" }
@ -167,4 +167,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" } web.timers { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
web.immediate { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" } web.immediate { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
web.dom.iterable { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" } web.dom.iterable { "chrome":"54", "edge":"13", "firefox":"49", "ie":"10", "ios":"9", "safari":"7" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -38,7 +38,7 @@ Using plugins:
Using polyfills with `usage` option: Using polyfills with `usage` option:
[src/in.js] Based on your code and targets, none were added. [<CWD>/src/in.js] Based on your code and targets, none were added.
[src/in2.js] Based on your code and targets, none were added. [<CWD>/src/in2.js] Based on your code and targets, none were added.
🎉 Successfully compiled 2 files with Babel. 🎉 Successfully compiled 2 files with Babel.

View File

@ -15,5 +15,5 @@ Using plugins:
Using polyfills with `usage` option: Using polyfills with `usage` option:
[src/in.js] Based on your code and targets, none were added. [<CWD>/src/in.js] Based on your code and targets, none were added.
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -38,13 +38,13 @@ Using plugins:
Using polyfills with `usage` option: Using polyfills with `usage` option:
[src/in.js] Added following polyfills: [<CWD>/src/in.js] Added following polyfills:
es6.promise { "ie":"11" } es6.promise { "ie":"11" }
es6.map { "firefox":"50", "ie":"11" } es6.map { "firefox":"50", "ie":"11" }
es6.array.iterator { "ie":"11" } es6.array.iterator { "ie":"11" }
web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" } web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" }
[src/in2.js] Added following polyfills: [<CWD>/src/in2.js] Added following polyfills:
regenerator-runtime { "chrome":"52", "firefox":"50", "ie":"11" } regenerator-runtime { "chrome":"52", "firefox":"50", "ie":"11" }
web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" } web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" }
🎉 Successfully compiled 2 files with Babel. 🎉 Successfully compiled 2 files with Babel.

View File

@ -48,7 +48,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within { "ie":"10" } es6.array.copy-within { "ie":"10" }
es6.array.every { "electron":"0.36" } es6.array.every { "electron":"0.36" }
es6.array.fill { "ie":"10" } es6.array.fill { "ie":"10" }
@ -193,4 +193,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" } web.timers { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
web.immediate { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" } web.immediate { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
web.dom.iterable { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" } web.dom.iterable { "chrome":"54", "electron":"0.36", "ie":"10", "node":"6.1" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -39,7 +39,7 @@ Using plugins:
Using polyfills with `entry` option: Using polyfills with `entry` option:
[src/in.js] Replaced `@babel/polyfill` with the following polyfills: [<CWD>/src/in.js] Replaced `@babel/polyfill` with the following polyfills:
es6.array.copy-within { "ie":"10" } es6.array.copy-within { "ie":"10" }
es6.array.fill { "ie":"10" } es6.array.fill { "ie":"10" }
es6.array.find { "ie":"10" } es6.array.find { "ie":"10" }
@ -163,4 +163,4 @@ Using polyfills with `entry` option:
web.timers { "chrome":"54", "ie":"10", "node":"6.10" } web.timers { "chrome":"54", "ie":"10", "node":"6.10" }
web.immediate { "chrome":"54", "ie":"10", "node":"6.10" } web.immediate { "chrome":"54", "ie":"10", "node":"6.10" }
web.dom.iterable { "chrome":"54", "ie":"10", "node":"6.10" } web.dom.iterable { "chrome":"54", "ie":"10", "node":"6.10" }
🎉 Successfully compiled 1 file with Babel. 🎉 Successfully compiled 1 file with Babel.

View File

@ -1,10 +1,10 @@
const actual = transform( const actual = transform(
'<Foo bar="baz" />', '<Foo bar="baz" />',
Object.assign({}, opts, { filename: 'fake/path/mock.js' }) Object.assign({}, opts, { filename: '/fake/path/mock.js' })
).code; ).code;
const expected = multiline([ const expected = multiline([
'var _jsxFileName = "fake/path/mock.js";', 'var _jsxFileName = "/fake/path/mock.js";',
'React.createElement(Foo, {', 'React.createElement(Foo, {',
' bar: "baz",', ' bar: "baz",',
' __source: {', ' __source: {',