[Fix] order: fix isExternalModule detect on windows#1651
Conversation
Co-authored-by: Raphael von der Grün <raphinesse@gmail.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
2 similar comments
| if (normSubpath.length === 0) { | ||
| return false | ||
| } | ||
| path = path.replace(/\\/g, '/') |
There was a problem hiding this comment.
perhaps instead of handling both cases, we should use path.sep, so that it handles file paths according to the filesystem you're on?
There was a problem hiding this comment.
I'm not sure that if path.sep works, but I guess no harm we just simply normalize the path?
There was a problem hiding this comment.
in that case, would node's path.normalize work?
There was a problem hiding this comment.
I don't think path.normalize works like expected
require('path').normalize('E:/path\\to/')
'E:\\path\\to\\'
|
(windows tests are broken pending #1648) |
|
Rebased this on top of #1648; still 1 test failing. |
|
Should be good now. |
|
@ljharb I fixed the failed test. But seems still breaking on Node.js@10. But local test passed on my laptop.... This has to be something related to |
|
The error info shows require error If we use that code for node.js 10, will it work? |
|
@raphinesse If that's a bug from |
@fisker I suggested that in #1648 (comment) but that comment got no reply from @ljharb. So I cannot tell you why. |
|
@raphinesse You're right, problem solved. Thanks |
|
I have no interest in disabling coverage anywhere; anything that disables coverage on windows is a nonstarter. |
|
@raphinesse Have you try |
|
@fisker Sorry, I don't have time to do so right now. Plus I fear it might not support enough Node/npm versions. That's just speculation though. |
f73a6c3 to
aa6b2a0
Compare
|
@raphinesse @ljharb Seems windows tests fixed now. |
ca929e3 to
826719e
Compare
ljharb
left a comment
There was a problem hiding this comment.
Thanks! We're almost there :-)
| it('`isExternalModule` works with windows directory separator', function() { | ||
| expect(isExternalModule('foo', {}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true) | ||
| expect(isExternalModule('foo', { | ||
| 'import/external-module-folders': ['E:\\path\\to\\node_modules'], |
There was a problem hiding this comment.
it doesn't seem like we're testing external-module-folders here if it was true before? meaning, maybe we need to add a test that returns false without external-module-folders, and true with it?
There was a problem hiding this comment.
No, without external-module-folders still true, because subpath defualts to node_modules, the test make sure we need replace subpath, remove that line will cause error
There was a problem hiding this comment.
Sorry, to clarify; I'm glad these tests fail without your fix! However, don't we want to also test that a windows path would not be external without the right external-module-folders setting?
| }, 'E:\\path\\to\\node_modules\\foo')).to.equal(true) | ||
| expect(isExternalModule('foo', { | ||
| 'import/external-module-folders': ['E:\\path\\to\\node_modules'], | ||
| }, '.\\foo')).to.equal(false) |
There was a problem hiding this comment.
i'm hoping for "false before, true after", not "same before and after". Can we come up with an example where the external-module-folders setting changes the result?
There was a problem hiding this comment.
I'm not sure I understand this.
Setting import/external-module-folders did not change the result.
expect(isExternalModule('foo', {
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true) expect(isExternalModule('foo', {
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)There are all true, and should be true, but before I add subpath.replace(/\\/g, '/'), this is false on windows, because it's bug. How do I test that, if you want reproduction, you just remove this fix, and
expect(isExternalModule('foo', {
'import/external-module-folders': ['E:\\path\\to\\node_modules'],
}, 'E:\\path\\to\\node_modules\\foo')).to.equal(true)this will fail.
There was a problem hiding this comment.
sure - i appreciate that the bug is that you get true, false instead of true, true.
However, to prevent different regressions later, i'm hoping to also have a test that correctly ensures false, true, even if that test would pass on master now :-)
There was a problem hiding this comment.
I went ahead and added something like that.
|
@fisker i'm sorry to hear this was a bad contribution experience for you; I'd love to understand in what way that was the case. |
|
This supposed to be a simple fix, but I have to wait/help fix the failed/unrelated tests. If I remember correctly, the failed tests is about coverage on old version of Node.js(at least not something I care at all), and I think it's already failed before I send this. I agree coverage is important, but I don't think it something that important to block. If I'm the maintainer, I'd merge first and try to fix later, especially #1648 already working on it at that time. I was patient only because I need this fix get released. It's good to see this plugin still support very old version of ESLint and Node.js, I like write code can run anywhere. Anyway the contribute experience is really bad to make tests pass on old stuff, because the contributors have to deal with things that they don't care at all. I stopped look into this repository because I'm an ESLint rule author of many rules, I can simply give up and make my own one. I remember I wrote first rule for prettier internal also because bug in this plugin, and I didn't try to fix it at all.. Update: link Forgive me to bring this up, no hard feelings, this is just my feeling. |
|
@fisker not at all; i appreciate your willingness to give the feedback even if you've already decided to not contribute in the future. I'll see what I can do in the future to alleviate the "tests for old versions" work for contributors. (the extensions rule should work with |
|
I don't remember the details, but I think I speed time to figure but didn't work, so I have to write one. I didn't try because we don't have one at first, now we have a lot, it's much easier than debug existing rules.. |
|
Reminds me that we don't need import/extensions anymore. 😄 |
isExternalModuleis not right, when use\as separator.This cause external module detected as
internal.Seems we are not running test on windows. I add a test on
isExternalModuleFixes #1655