-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow bundleDependencies to be respected during pack
#5966
Conversation
|
Pack-related tests seem to fail. Btw, I'm a bit curious, what are you using |
A deployable tarball. |
@arcanis Tests should now be passing (except for appveyor but they seem to be failing before my change). As @stefanpenner said bundleDependencies are needed for us to create deployable tarball that is completely self contained. |
@thoov mind comparing appveyer before/after and confirming its not worse then before? That should help the yarn maintainers a tad. |
Walk the bundleDependency tree and include the related files.
df2e6cb
to
9479172
Compare
@stefanpenner @arcanis Ok now tests are fully passing |
@arcanis Could you provide a review or do you know who would be best to take a look at this PR? |
Can anyone review and approve this please? |
let bundleDependenciesFiles = []; | ||
if (bundleDependencies) { | ||
for (const dependency of bundleDependencies) { | ||
const dependencyList = depsFor(dependency, config.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.
What is this depsFor
used for? Why can't we just walk the node_modules/${dependency}
tree?
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.
depsFor
simply returns a list of all of the dependencies for a given package so in a sense it is "walking the tree". I agree with your concerns about not adding unnecessary extra packages to the project. Do you know if yarn has a built in util for getting this info? If not I think it is safe to bring this package in.
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.
What I don't understand is: wouldn't something like this work without depsFor
(pseudo code)?
const FOLDERS_IGNORE_NO_NODE_MODULES = new Set(FOLDERS_IGNORE);
FOLDERS_IGNORE_NO_NODE_MODULES.delete('node_modules');
for (const dependency of bundleDependencies) {
const depPath = getPathForDependency(dependency);
const filesForBundledDep = await fs.walk(depPath, null, new Set(FOLDERS_IGNORE_NO_NODE_MODULES));
bundleDependenciesFiles = bundleDependenciesFiles.concat(filesForBundledDep);
}
Since walk
would then traverse the whole node_modules
tree and pack them all.
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.
@arcanis The issue is that this pseudo code doesn't actually walk the dependency graph for a dependency and only walks the directory structure. If we have a dependency a
which has b
and c
as dependencies we get this tree structure:
node_modules/a
node_modules/b
node_modules/c
And const depPath = getPathForDependency(dependency);
would only walk node_modules/a
and miss the other ones. Thats why I use depsFor
as I need more than the "top" level bundled dependencies. Let me know if this make sense or if there is something I am missing.
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 see, that makes sense. I'm not fond of adding a new dep, but I don't see an easy replacement at the moment, so we can start with that.
Hey, sorry for the delay, I'd like to know more about the |
Thanks for the comments @arcanis. I left a response inline to your concern above. |
let bundleDependenciesFiles = []; | ||
if (bundleDependencies) { | ||
for (const dependency of bundleDependencies) { | ||
const dependencyList = depsFor(dependency, config.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.
What I don't understand is: wouldn't something like this work without depsFor
(pseudo code)?
const FOLDERS_IGNORE_NO_NODE_MODULES = new Set(FOLDERS_IGNORE);
FOLDERS_IGNORE_NO_NODE_MODULES.delete('node_modules');
for (const dependency of bundleDependencies) {
const depPath = getPathForDependency(dependency);
const filesForBundledDep = await fs.walk(depPath, null, new Set(FOLDERS_IGNORE_NO_NODE_MODULES));
bundleDependenciesFiles = bundleDependenciesFiles.concat(filesForBundledDep);
}
Since walk
would then traverse the whole node_modules
tree and pack them all.
Merged. Thanks! |
When running `yarn pack` with a bundledDependency yarn was throwing an error: "error An unexpected error occurred: "Cannot find module \".\""." This was due to yarn's cli.js being transpiled to on line 110321: ``` var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()); ``` This line comes from [here](https://github.com/stefanpenner/hash-for-dep/blob/e849d3e2f0350810716a0e504c84603362229570/lib/pkg.js#L20) and is a dynamic require. This commit impements a fix for this based on the guidence from [this issue](webpack/webpack#4175 (comment)) This code was originally added with yarnpkg#5966
When running `yarn pack` with a bundledDependency yarn was throwing an error: "error An unexpected error occurred: "Cannot find module \".\""." This was due to yarn's cli.js being transpiled to on line 110321: ``` var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()); ``` This line comes from https://github.com/stefanpenner/hash-for-dep/blob/e849d3e2f0350810716a0e504c84603362229570/lib/pkg.js#L20 and is a dynamic require. This commit impements a fix for this based on the guidence from webpack/webpack#4175 (comment) This code was originally added with yarnpkg#5966
When running `yarn pack` with a bundledDependency yarn was throwing an error: An unexpected error occurred: "Cannot find module \".\"". This was due to yarn's cli.js being transpiled to on line 110321: ``` var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()); ``` This line comes from https://github.com/stefanpenner/hash-for-dep/blob/e849d3e2f0350810716a0e504c84603362229570/lib/pkg.js#L20 and is a dynamic require. This commit impements a fix for this based on the guidence from webpack/webpack#4175 (comment) This code was originally added with yarnpkg#5966
When running `yarn pack` with a bundledDependency yarn was throwing an error: An unexpected error occurred: "Cannot find module \".\"". This was due to yarn's cli.js being transpiled to on line 110321: ``` var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()); ``` This line comes from https://github.com/stefanpenner/hash-for-dep/blob/e849d3e2f0350810716a0e504c84603362229570/lib/pkg.js#L20 and is a dynamic require. This commit impements a fix for this based on the guidence from webpack/webpack#4175 (comment) This code was originally added with yarnpkg#5966
* Fixing dynamic require missing from webpack When running `yarn pack` with a bundledDependency yarn was throwing an error: An unexpected error occurred: "Cannot find module \".\"". This was due to yarn's cli.js being transpiled to on line 110321: ``` var thePackage = !(function webpackMissingModule() { var e = new Error("Cannot find module \".\""); e.code = 'MODULE_NOT_FOUND'; throw e; }()); ``` This line comes from https://github.com/stefanpenner/hash-for-dep/blob/e849d3e2f0350810716a0e504c84603362229570/lib/pkg.js#L20 and is a dynamic require. This commit impements a fix for this based on the guidence from webpack/webpack#4175 (comment) This code was originally added with #5966 * Update CHANGELOG.md
Summary
Yarn pack does not include bundleDependencies during
yarn pack
. This was due to 3 issues:The normalized property is
bundleDependencies
and notbundledDependencies
. This was causing the destructuring to always be undefined even if bundledDependencies or bundleDependencies were set in package.json.The way the filtering logic is constructed excludes node_modules from the 'search space'. This leads the filtering to attempt to find dependencies but cant because they were excluded.
The logic was only set up to find the dependency but not that dependency's dependency tree. This would lead to an incomplete pack of the needed dependencies.
Fixing problem 1: was a simple property name change which you can see here: 8081ccd
For fixing problems 2 & 3: We take the specified bundleDependencies and construct the list of their dependency graphs. Once we have the list we figure out all of the needed files for each one of those (sub)dependencies. You can see that change here: 54830e4
Related Issue: #2636
Test plan
I ran this in comparison to
npm pack
on a few local projects of various sizes and compared the outputs and performance (right now there is also an issue with bundleDependecies and npm so we will need to use npm 5.3.0 as that is the last working version).The outputs look correct but I do notice a perf hit compared to npm pack. This perf slowness does not seem to be related to these changes directly but on the library that created the tar. On larger projects that I tested it would take npm pack about 15 seconds and for yarn pack it was 45 seconds.