mirror of https://github.com/webpack/webpack.git
				
				
				
			Don't record absolute paths for regexps used in dynamic requires
This avoids records like: "src/dependencies sync ../../../../^/.//.*$": "./src/dependencies sync recursive ^\\.\\/.*$" with the number of "../"s varying according to the depth of the folder you're building from. Fixes #7339
This commit is contained in:
		
							parent
							
								
									8a6db447a8
								
							
						
					
					
						commit
						6bf9479af2
					
				|  | @ -12,6 +12,11 @@ const path = require("path"); | ||||||
|  * @returns {boolean} returns true if path is "Absolute Path"-like |  * @returns {boolean} returns true if path is "Absolute Path"-like | ||||||
|  */ |  */ | ||||||
| const looksLikeAbsolutePath = maybeAbsolutePath => { | 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); | 	return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -27,3 +27,35 @@ exports[`ConfigTestCases records issue-2991 exported tests should write relative | ||||||
|   } |   } | ||||||
| }" | }" | ||||||
| `; | `; | ||||||
|  | 
 | ||||||
|  | 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 | ||||||
|  |     ] | ||||||
|  |   } | ||||||
|  | }" | ||||||
|  | `; | ||||||
|  |  | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = "Bar" | ||||||
|  | @ -0,0 +1 @@ | ||||||
|  | module.exports = "Foo" | ||||||
|  | @ -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(); | ||||||
|  | }); | ||||||
|  | @ -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 | ||||||
|  | 	} | ||||||
|  | }; | ||||||
		Loading…
	
		Reference in New Issue