Treat all filenames as absolute paths. (#8044)
This commit is contained in:
parent
98ff2ce877
commit
53e4d74ebe
@ -1 +1 @@
|
||||
SyntaxError: test.js: Unexpected token, expected ";" (2:10)
|
||||
SyntaxError: <CWD>/test.js: Unexpected token, expected ";" (2:10)
|
||||
|
||||
@ -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();
|
||||
stderr = stderr.trim();
|
||||
|
||||
@ -138,7 +151,7 @@ const buildTest = function(binName, testName, opts) {
|
||||
let err;
|
||||
|
||||
try {
|
||||
assertTest(stdout, stderr, opts);
|
||||
assertTest(stdout, stderr, opts, tmpLoc);
|
||||
} catch (e) {
|
||||
err = e;
|
||||
}
|
||||
|
||||
@ -60,9 +60,7 @@ export default function loadPrivatePartialConfig(
|
||||
options.cwd = context.cwd;
|
||||
options.root = context.root;
|
||||
options.filename =
|
||||
typeof context.filename === "string"
|
||||
? path.relative(context.cwd, context.filename)
|
||||
: undefined;
|
||||
typeof context.filename === "string" ? context.filename : undefined;
|
||||
|
||||
options.plugins = configChain.plugins.map(descriptor =>
|
||||
createItemFromDescriptor(descriptor),
|
||||
|
||||
@ -936,7 +936,7 @@ describe("buildConfigChain", function() {
|
||||
}),
|
||||
).toEqual({
|
||||
...getDefaults(),
|
||||
filename: path.basename(filename),
|
||||
filename: filename,
|
||||
cwd: path.dirname(filename),
|
||||
root: path.dirname(filename),
|
||||
comments: true,
|
||||
@ -948,7 +948,7 @@ describe("buildConfigChain", function() {
|
||||
|
||||
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
|
||||
...getDefaults(),
|
||||
filename: path.basename(filename),
|
||||
filename: filename,
|
||||
cwd: path.dirname(filename),
|
||||
root: path.dirname(filename),
|
||||
comments: true,
|
||||
@ -960,7 +960,7 @@ describe("buildConfigChain", function() {
|
||||
|
||||
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
|
||||
...getDefaults(),
|
||||
filename: path.basename(filename),
|
||||
filename: filename,
|
||||
cwd: path.dirname(filename),
|
||||
root: path.dirname(filename),
|
||||
comments: true,
|
||||
@ -1002,7 +1002,7 @@ describe("buildConfigChain", function() {
|
||||
|
||||
expect(loadOptions({ filename, cwd: path.dirname(filename) })).toEqual({
|
||||
...getDefaults(),
|
||||
filename: path.basename(filename),
|
||||
filename: filename,
|
||||
cwd: path.dirname(filename),
|
||||
root: path.dirname(filename),
|
||||
comments: true,
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -66,6 +66,9 @@ const buildTest = opts => {
|
||||
let err;
|
||||
|
||||
try {
|
||||
stdout = replacePaths(stdout);
|
||||
stderr = replacePaths(stderr);
|
||||
|
||||
assertTest(stdout, stderr, opts);
|
||||
} catch (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", () => {
|
||||
let cwd;
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ Using plugins:
|
||||
|
||||
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.fill { "android":"4" }
|
||||
es6.array.find { "android":"4" }
|
||||
|
||||
@ -20,5 +20,5 @@ Using plugins:
|
||||
|
||||
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.
|
||||
@ -40,7 +40,7 @@ Using plugins:
|
||||
|
||||
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" }
|
||||
es7.object.define-getter { "chrome":"55" }
|
||||
es7.object.define-setter { "chrome":"55" }
|
||||
|
||||
@ -39,7 +39,7 @@ Using plugins:
|
||||
|
||||
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.fill { "ie":"10" }
|
||||
es6.array.find { "ie":"10" }
|
||||
|
||||
@ -32,7 +32,7 @@ Using plugins:
|
||||
|
||||
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.filter { "electron":"0.36" }
|
||||
es6.array.for-each { "electron":"0.36" }
|
||||
|
||||
@ -37,7 +37,7 @@ Using plugins:
|
||||
|
||||
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" }
|
||||
es7.object.define-getter { "chrome":"55" }
|
||||
es7.object.define-setter { "chrome":"55" }
|
||||
|
||||
@ -16,7 +16,7 @@ Using plugins:
|
||||
|
||||
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" }
|
||||
es7.object.define-getter { "chrome":"60" }
|
||||
es7.object.define-setter { "chrome":"60" }
|
||||
|
||||
@ -36,7 +36,7 @@ Using plugins:
|
||||
|
||||
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.every {}
|
||||
es6.array.fill {}
|
||||
|
||||
@ -42,7 +42,7 @@ Using plugins:
|
||||
|
||||
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.fill { "ie":"10", "safari":"7" }
|
||||
es6.array.find { "ie":"10", "safari":"7" }
|
||||
|
||||
@ -38,7 +38,7 @@ Using plugins:
|
||||
|
||||
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.
|
||||
@ -15,5 +15,5 @@ Using plugins:
|
||||
|
||||
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.
|
||||
@ -38,13 +38,13 @@ Using plugins:
|
||||
|
||||
Using polyfills with `usage` option:
|
||||
|
||||
[src/in.js] Added following polyfills:
|
||||
[<CWD>/src/in.js] Added following polyfills:
|
||||
es6.promise { "ie":"11" }
|
||||
es6.map { "firefox":"50", "ie":"11" }
|
||||
es6.array.iterator { "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" }
|
||||
web.dom.iterable { "chrome":"52", "firefox":"50", "ie":"11" }
|
||||
🎉 Successfully compiled 2 files with Babel.
|
||||
@ -48,7 +48,7 @@ Using plugins:
|
||||
|
||||
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.every { "electron":"0.36" }
|
||||
es6.array.fill { "ie":"10" }
|
||||
|
||||
@ -39,7 +39,7 @@ Using plugins:
|
||||
|
||||
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.fill { "ie":"10" }
|
||||
es6.array.find { "ie":"10" }
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
const actual = transform(
|
||||
'<Foo bar="baz" />',
|
||||
Object.assign({}, opts, { filename: 'fake/path/mock.js' })
|
||||
Object.assign({}, opts, { filename: '/fake/path/mock.js' })
|
||||
).code;
|
||||
|
||||
const expected = multiline([
|
||||
'var _jsxFileName = "fake/path/mock.js";',
|
||||
'var _jsxFileName = "/fake/path/mock.js";',
|
||||
'React.createElement(Foo, {',
|
||||
' bar: "baz",',
|
||||
' __source: {',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user