-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
env.NODE_PATH support in Storyshots #2873
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2873 +/- ##
==========================================
+ Coverage 35.91% 35.92% +<.01%
==========================================
Files 428 428
Lines 9483 9486 +3
Branches 973 993 +20
==========================================
+ Hits 3406 3408 +2
+ Misses 5417 5382 -35
- Partials 660 696 +36
Continue to review full report at Codecov.
|
@igor-dv would it not make more sense to not call While we are modifying this file, I would suggest we also fix the glaring bug that it calls |
Probably you are right... Will try to test it with a repo from the issue.
Why is it a bug? it's a mock of what webpack does, so you can decide how to take care of it =) |
Because the require happens at a different time -- in this code (direct from the docs): // In storyshots, the require happens here:
const req = require.context('../src/components', true, /\.stories\.js$/)
function loadStories() {
// in webpack it happens here:
req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module); This has caused bugs in the past, for instance if you add a decorator between the two.. |
[We don't have to fix this issue in this PR] |
Is there any open bug on it? |
Only in my head for some reason I think.. |
@tmeasday, just checked with an absolute path, and |
@igor-dv I created an issue here: #2894. Note that the original issue (#2838) will also have this problem ;)
Yes, but not so much with "components", it treats this equivalently to "./components". i.e.: > path.resolve('/a', '/b') # 1.
'/b'
> path.resolve('/a', 'b') # 2.
'/a/b'
> path.resolve('/a', './b') # 3.
'/a/b' The idea of using |
Aha ! Now I understand what you are talking about 😈 I'll do it |
@@ -40,6 +41,14 @@ function isRelativeRequest(request) { | |||
); | |||
} | |||
|
|||
function getFullPath(dirname, request) { | |||
if (isRelativeRequest(request) || !process.env.NODE_PATH) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it needs to be this complex; process.env.NODE_PATH
will automatically apply if you require something non-relative, won't it?
So it can just be:
return isRelativeRequest(request) ? path.resolve(dirname, request) : dirname;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked it now, and it's not applied. It's just resolved according to the cwd. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh, because we need to a fs.readdirSync
in the directory. Sorry I am bit slow 😊
Do we not need to worry about other require rules in this case? For instance if I do require.context('foo')
and I have node_modules/foo
or ../node_modules/foo
or .. etc
I guess this is better than nothing though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... I would say let's fix on request =)
Also, why would anyone require.context('foo')
, when foo is a node module 🤔 what should we expect to happen
that’s fair..
…On Fri, 2 Feb 2018 at 9:46 pm, Igor ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In addons/storyshots/src/require_context.js
<#2873 (comment)>:
> @@ -40,6 +41,14 @@ function isRelativeRequest(request) {
);
}
+function getFullPath(dirname, request) {
+ if (isRelativeRequest(request) || !process.env.NODE_PATH) {
Yeah... I would say let's fix on request =)
Also, why would anyone require.context('foo'), when foo is a node module
🤔 what should we expect to happen
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2873 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIFytc7Wk99UGYMCrSvXQISlmqukZ8Aks5tQueXgaJpZM4RydSt>
.
|
Issue: #2838
What I did
I've added NODE_PATH support in the mocked "require.context"
How to test
I have no idea how to add a working example into the monorepo... I've tested it with the repo from the issue.