Skip to content

Commit

Permalink
Merge 6bf9479 into 3605035
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother committed May 21, 2018
2 parents 3605035 + 6bf9479 commit ee3da4c
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 26 deletions.
5 changes: 5 additions & 0 deletions lib/util/identifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const path = require("path");
* @returns {boolean} returns true if path is "Absolute Path"-like
*/
const looksLikeAbsolutePath = maybeAbsolutePath => {
if (/^\/.*\/$/.test(maybeAbsolutePath)) {
// this 'path' is actually a regexp generated by dynamic requires.
// Don't treat it as an absolute path.
return false;
}
return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
};

Expand Down
61 changes: 61 additions & 0 deletions test/__snapshots__/ConfigTestCases.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ConfigTestCases records issue-2991 exported tests should write relative paths to records 1`] = `
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"external \\\\\\"path\\\\\\"\\": 0,
\\"external \\\\\\"fs\\\\\\"\\": 1,
\\"ignored pkgs/somepackage/foo\\": 2,
\\"test.js\\": 3
},
\\"usedIds\\": {
\\"0\\": 0,
\\"1\\": 1,
\\"2\\": 2,
\\"3\\": 3
}
},
\\"chunks\\": {
\\"byName\\": {
\\"main\\": 0
},
\\"bySource\\": {},
\\"usedIds\\": [
0
]
}
}"
`;

exports[`ConfigTestCases records issue-7339 exported tests should write relative dynamic-require paths to records 1`] = `
"{
\\"modules\\": {
\\"byIdentifier\\": {
\\"dependencies/foo.js\\": 0,
\\"dependencies/bar.js\\": 1,
\\"external \\\\\\"path\\\\\\"\\": 2,
\\"external \\\\\\"fs\\\\\\"\\": 3,
\\"dependencies sync /^\\\\\\\\.\\\\\\\\/.*$/\\": 4,
\\"test.js\\": 5
},
\\"usedIds\\": {
\\"0\\": 0,
\\"1\\": 1,
\\"2\\": 2,
\\"3\\": 3,
\\"4\\": 4,
\\"5\\": 5
}
},
\\"chunks\\": {
\\"byName\\": {
\\"main\\": 0
},
\\"bySource\\": {},
\\"usedIds\\": [
0
]
}
}"
`;
28 changes: 2 additions & 26 deletions test/configCases/records/issue-2991/test.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
try {
require("pkgs/somepackage/foo");
} catch(e){}
} catch (e) {}

it("should write relative paths to records", function() {
var fs = require("fs");
var path = require("path");
var content = fs.readFileSync(path.join(__dirname, "records.json"), "utf-8");
expect(content).toEqual(`{
"modules": {
"byIdentifier": {
"external \\"path\\"": 0,
"external \\"fs\\"": 1,
"ignored pkgs/somepackage/foo": 2,
"test.js": 3
},
"usedIds": {
"0": 0,
"1": 1,
"2": 2,
"3": 3
}
},
"chunks": {
"byName": {
"main": 0
},
"bySource": {},
"usedIds": [
0
]
}
}`);
expect(content).toMatchSnapshot();
});
1 change: 1 addition & 0 deletions test/configCases/records/issue-7339/dependencies/bar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "Bar"
1 change: 1 addition & 0 deletions test/configCases/records/issue-7339/dependencies/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "Foo"
10 changes: 10 additions & 0 deletions test/configCases/records/issue-7339/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function loadDependency(dep) {
require("./dependencies/" + dep);
}

it("should write relative dynamic-require paths to records", function() {
var fs = require("fs");
var path = require("path");
var content = fs.readFileSync(path.join(__dirname, "records.json"), "utf-8");
expect(content).toMatchSnapshot();
});
13 changes: 13 additions & 0 deletions test/configCases/records/issue-7339/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var path = require("path");

module.exports = {
entry: "./test",
recordsOutputPath: path.resolve(
__dirname,
"../../../js/config/records/issue-7339/records.json"
),
target: "node",
node: {
__dirname: false
}
};

0 comments on commit ee3da4c

Please sign in to comment.