Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record relative dynamic-require paths #7350

Merged
merged 2 commits into from
May 21, 2018

Conversation

jdelStrother
Copy link
Contributor

@jdelStrother jdelStrother commented May 19, 2018

What kind of change does this PR introduce?

This avoids records like:

"src/dependencies sync ../../../../^/.//.*$": "./src/dependencies sync recursive ^\\.\\/.*$"

when using dynamic requires (eg require("./foo/" + file)), with the number of "../"s varying according to the depth of the folder you're building from.

Fixes #7339

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

Don't believe so.

What needs to be documented once your changes are merged?

Nothing(?)


WDYT to this?

@jsf-clabot
Copy link

jsf-clabot commented May 19, 2018

CLA assistant check
All committers have signed the CLA.

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This need to be documented (issue in webpack/webpack.js.org will be filed when merged)

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

var fs = require("fs");
var path = require("path");
var content = fs.readFileSync(path.join(__dirname, "records.json"), "utf-8");
expect(content).toEqual(`{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a jest snapshot please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do... you're sure about that, though? None of the other configTestCases use snapshots AFAICT - I was trying to mimic, eg, https://github.com/webpack/webpack//blob/master/test/configCases/records/issue-2991/test.js#L2.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also say a snapshot would be appropriate here. The other test was written before we used jest and we did have access to snapshot tests these days. If you want, you can change the other test to a snapshot too.

@@ -12,6 +12,11 @@ const path = require("path");
* @returns {boolean} returns true if path is "Absolute Path"-like
*/
const looksLikeAbsolutePath = maybeAbsolutePath => {
if (maybeAbsolutePath === "/^\\.\\/.*$/") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only possible value?

Copy link
Contributor Author

@jdelStrother jdelStrother May 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, no. We could also get stringified regexps here from something like:

require.context("./dependencies", false, /\.js$/);

Maybe I should just check if it starts and ends with a /, to determine if it's regexp-y. I couldn't find any cases where an absolute filepath would be passed in here with a trailing slash (eg "/src/") - what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threading strings starting and ending with / as RegExp, seems to be safe in my opinion. Every other absolute path is a resolved path and doesn't end with /.

@@ -12,6 +12,11 @@ const path = require("path");
* @returns {boolean} returns true if path is "Absolute Path"-like
*/
const looksLikeAbsolutePath = maybeAbsolutePath => {
if (maybeAbsolutePath === "/^\\.\\/.*$/") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Threading strings starting and ending with / as RegExp, seems to be safe in my opinion. Every other absolute path is a resolved path and doesn't end with /.

var fs = require("fs");
var path = require("path");
var content = fs.readFileSync(path.join(__dirname, "records.json"), "utf-8");
expect(content).toEqual(`{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also say a snapshot would be appropriate here. The other test was written before we used jest and we did have access to snapshot tests these days. If you want, you can change the other test to a snapshot too.

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 webpack#7339
@webpack-bot
Copy link
Contributor

@jdelStrother Thanks for your update.

I labeled the Pull Request so reviewers will review it again.

@sokra Please review the new changes.

@sokra sokra merged commit 6ff5b8f into webpack:master May 21, 2018
@sokra
Copy link
Member

sokra commented May 21, 2018

Thanks

@webpack-bot
Copy link
Contributor

I've created an issue to document this in webpack/webpack.js.org.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants