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

unique file entries in integrity file #6704

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hulkish
Copy link
Contributor

@hulkish hulkish commented Nov 19, 2018

Summary

Fixes #6703

Test plan
After installing dependencies with this modified yarn, run:

cat node_modules/.yarn-integrity | jq -r .files[] | uniq -c

You should only see a 1 next to each entry.

@arcanis
Copy link
Member

arcanis commented Nov 20, 2018

It seems good, but for posterity can you detail why duplicate entries can even occur? The old code was iterating over readdir, so I'm not sure I understand how it can happen

@buildsize
Copy link

buildsize bot commented Nov 21, 2018

File name Previous Size New Size Change
yarn-[version].noarch.rpm 1.1 MB 1.1 MB -504 bytes (0%)
yarn-[version].js 4.47 MB 4.46 MB -6.52 KB (0%)
yarn-legacy-[version].js 4.66 MB 4.65 MB -6.42 KB (0%)
yarn-v[version].tar.gz 1.12 MB 1.11 MB -3.14 KB (0%)
yarn_[version]all.deb 814.52 KB 813.57 KB -974 bytes (0%)

@hulkish
Copy link
Contributor Author

hulkish commented Nov 21, 2018

It seems good, but for posterity can you detail why duplicate entries can even occur? The old code was iterating over readdir, so I'm not sure I understand how it can happen

@arcanis @rally25rs So, I've reached the root cause of this issue. Which, lead me to a better solution for this. Basically, modulesFolders was incorrectly being populated with 2 entries of the workspace root dir. I think after you see my new changes it will become more clear.

.filter(Boolean)
// $FlowFixMe
.map(({loc}) => path.join(loc, constants.NODE_MODULES_FOLDER)),
);
Copy link
Member

Choose a reason for hiding this comment

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

I think I'd prefer to keep using the for...of style that the previous code was using. This particular chaining of the array methods makes the code more confusing imo and doesn't help Flow.

Copy link
Contributor Author

@hulkish hulkish Nov 21, 2018

Choose a reason for hiding this comment

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

@arcanis So, im happy to restore the sequential awaits. I just thought this would be preferred in terms of perf. Flow barfs on comparing custom types with Object.values() entries.

Copy link
Member

Choose a reason for hiding this comment

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

There is no await here, right?

if (workspaceLayout) {
for (const workspaceName of Object.keys(workspaceLayout.workspaces)) {
const loc = workspaceLayout.workspaces[workspaceName].loc;
const folders = await Promise.all(locations.map(async loc => (await fs.exists(loc)) && loc));
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this lambda return loc && (await fs.exists(loc)) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arcanis you would be correct, if it were using filter instead of map

const locations = [];

if (this.config.modulesFolder) {
locations.push(this.config.modulesFolder);
Copy link
Member

Choose a reason for hiding this comment

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

You've removed this part of the code without replacement - won't that break the modulesFolder settings?

Copy link
Contributor Author

@hulkish hulkish Nov 21, 2018

Choose a reason for hiding this comment

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

@arcanis this was actually causing the issue, since these dirs are included already.

For ex, i added the following log:

    console.log(
      this.config.modulesFolder,
      path.join(this.config.lockfileFolder, constants.NODE_MODULES_FOLDER),
      Object.values(workspaceLayout.workspaces)
          .filter(Boolean).map(({loc}) => loc)
    );

which yields:

undefined '/Users/myuser/dev/repos/my-repo/node_modules' [ '/Users/myuser/dev/repos/my-repo/components',
  '/Users/myuser/dev/repos/my-repo/contexts',
  '/Users/myuser/dev/repos/my-repo/modules',
  '/Users/myuser/dev/repos/my-repo/pages',
  '/Users/myuser/dev/repos/my-repo/packages/browser-dev-tools',
  '/Users/myuser/dev/repos/my-repo/packages/dal',
  '/Users/myuser/dev/repos/my-repo/packages/dev-certs',
  '/Users/myuser/dev/repos/my-repo/packages/env',
  '/Users/myuser/dev/repos/my-repo/packages/koa-auth-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-error-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-transform-multistats-assets',
  '/Users/myuser/dev/repos/my-repo/packages/koa-wc-headers-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-wc-health-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-wc-logging-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-wc-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/koa-webpack-dev-middleware',
  '/Users/myuser/dev/repos/my-repo/packages/logger',
  '/Users/myuser/dev/repos/my-repo/packages/module-interface',
  '/Users/myuser/dev/repos/my-repo/packages/react-render-to-stream',
  '/Users/myuser/dev/repos/my-repo/packages/redux-create-store',
  '/Users/myuser/dev/repos/my-repo/packages/server',
  '/Users/myuser/dev/repos/my-repo/services/akamai-headers',
  '/Users/myuser/dev/repos/my-repo/services/hello-world',
  '/Users/myuser/dev/repos/my-repo/services/redux-dal',
  '/Users/myuser/dev/repos/my-repo/services/storybook',
  '/Users/myuser/dev/repos/my-repo/tools/cli',
  '/Users/myuser/dev/repos/my-repo/tools/lib-src-resolver',
  '/Users/myuser/dev/repos/my-repo/tools/platform-cache',
  '/Users/myuser/dev/repos/my-repo/tools/platform-config',
  '/Users/myuser/dev/repos/my-repo/tools/platform-core',
  '/Users/myuser/dev/repos/my-repo/tools/progress-webpack-plugin',
  '/Users/myuser/dev/repos/my-repo/tools/storybook-helpers',
  '/Users/myuser/dev/repos/my-repo/tools/webpack-chunk-assets-plugin',
  '/Users/myuser/dev/repos/my-repo' ]

@hulkish hulkish force-pushed the patch-2 branch 2 times, most recently from d3163ac to 2ca9cce Compare November 21, 2018 21:39
@jeanregisser
Copy link

@hulkish are you still interested in getting this PR merged?

I came across this problem too as detailed in celo-org/celo-monorepo#2798

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

Successfully merging this pull request may close these issues.

Duplicate file entries in .yarn-integrity file
3 participants