-
Notifications
You must be signed in to change notification settings - Fork 146
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
Fix require symlinks for yarn workspaces #15
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
617d697
Fix symlink emission for yarn workspaces
styfle 6165cb4
Simplify logic
styfle f540887
Add reason to emit file
styfle d4b8594
Add unit test fs-emission-symlink
styfle 8db682d
Add missing test result
styfle 0775a83
Fix test output
styfle ee34f86
Add path.join()
styfle 15871ec
Fix test to use require
styfle d2b2fd4
Fix output
styfle f8d3070
Rename test to require-symlink
styfle ba73e33
Remove comment since this is always a symlink
styfle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => console.log('hello'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require('./symlink') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
"require-symlink/another.js", | ||
"require-symlink/input.js", | ||
"require-symlink/symlink" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
another.js |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If you emit the path including the symlink, you probably don't need to also emit the real path (because the real path is not required).
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 understand.
Both the symlink and the real file need to be emitted because the symlink is just a pointer to the real file. Both are necessary.
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.
For example, you could have this path (not real)
/symlink-folder/file
and the real path is/folder/file
.If you add
/symlink-folder/file
to the file list, you're not actually listing anything real (not even a file that contains a pointer).That means that:
@now/node
) would need to follow symlinks when copying filesThere 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 think I see what you mean. My code is immediately emitting the symlink even though there are some cases when the real file will not be emitted (starts with 'node:`, etc).
@guybedford Do you have a solution for this one?
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.
It will always be a symlink on this code path because of the early return for the
node:
URL format.Note that a resolve-dependency is called as part of the emitDependency routine before it itself calls emitFile. Any file emitted by resolve-dependency means that file was necessary for the resolution process, not that that was the resolved file. The emitFile capability was added to resolve-dependency specifically just to emit package.json files (and so this way we don't emit all package.json files, only those that are actually needed by resolution). Emitting package.json + symlinks exactly fits the model.
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'm talking about the case where the symlink is directed at a folder and not a file (which is what yarn workspaces is doing). In that case, with the code above, you emit both a "virtual" file and a real file. Is that the expected behaviour? Could you add a test for that?
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.
The Node.js resolver as written here will only ever resolve a file, not a folder. The statting specifically checks for file existence.
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 confirmed this fixes yarn workspaces with an integration test here: https://github.com/zeit/now-builders/pull/759
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.
Sorry, I explained it wrong. I'm talking about the case where the file itself is not the symlink, but the symlink is located higher in the folder structure. In this case, if we emit the "virtual" file path, we don't need to emit the real file path.
It works but I think we emit some files twice when only one is necessary 🤔
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.
Right, that makes complete sense, but this project is just a "tracer" of the file system. It is up to now node to correctly emit the traced filesystem. And yes, it doesn't due to a lack of symlink support both for files and deeper folders as you describe.