Skip to content

Commit

Permalink
[core] Deduplicate packages (#16608)
Browse files Browse the repository at this point in the history
* [core] Deduplicate packages

* Deduplicate

* Move task to checkout job

* Remove postinstall check, remove function wrapper
  • Loading branch information
merceyz authored and eps1lon committed Jul 19, 2019
1 parent 83521f7 commit b3218e7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
- run:
name: Should not have any git not staged
command: git diff --exit-code
- run:
name: Check for duplicated packages
command: yarn deduplicate
- save_cache:
key: v2-yarn-sha-{{ checksum "yarn.lock" }}
paths:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "4.2.1",
"private": true,
"scripts": {
"deduplicate": "node scripts/deduplicate.js",
"argos": "argos upload test/regressions/screenshots/chrome --token $ARGOS_TOKEN",
"docs:api": "rimraf ./pages/api && cross-env BABEL_ENV=test babel-node ./docs/scripts/buildApi.js ./packages/material-ui/src ./pages/api && cross-env BABEL_ENV=test babel-node ./docs/scripts/buildApi.js ./packages/material-ui-lab/src ./pages/api",
"docs:build": "rimraf .next && cross-env NODE_ENV=production BABEL_ENV=docs-production next build",
Expand Down Expand Up @@ -201,7 +202,8 @@
"webfontloader": "^1.6.28",
"webpack": "^4.28.4",
"webpack-bundle-analyzer": "^3.0.0",
"webpack-cli": "^3.2.3"
"webpack-cli": "^3.2.3",
"yarn-deduplicate": "^1.1.1"
},
"resolutions": {
"**/hoist-non-react-statics": "^3.2.1"
Expand Down
42 changes: 42 additions & 0 deletions scripts/deduplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable no-console */

const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const deduplicate = require('yarn-deduplicate');

const lockFile = path.resolve(__dirname, '../yarn.lock');
const yarnlock = fs.readFileSync(lockFile, 'utf8');

const duplicates = deduplicate.listDuplicates(yarnlock);
if (duplicates.length === 0) {
console.log('No duplicated packages found');
process.exit(0);
}

console.log(
`${duplicates.length} duplicated package(s) found\n${duplicates.map(x => ` ${x}`).join('\n')}`,
);

if (process.env.CI) {
console.error(
[
`Error: There are currently ${duplicates.length} duplicated package(s).`,
`To deduplicate run "yarn deduplicate"`,
].join('\n'),
);
process.exit(1);
}

console.log('Deduplicating package(s)');
fs.writeFileSync(lockFile, deduplicate.fixDuplicates(yarnlock));

const yarn = spawn('yarn', {
shell: true,
stdio: 'inherit',
cwd: path.resolve(__dirname, '..'),
});

yarn.on('close', code => {
process.exit(code);
});
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2652,6 +2652,11 @@
resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d"
integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ==

"@yarnpkg/lockfile@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz#e77a97fbd345b76d83245edcd17d393b1b41fb31"
integrity sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==

"@zeit/next-typescript@^1.1.1":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@zeit/next-typescript/-/next-typescript-1.1.1.tgz#0b0ddfbb13ca04cde52ac2718473f1b9c40ba0ee"
Expand Down Expand Up @@ -4325,7 +4330,7 @@ commander@2.9.0, commander@~2.9.0:
dependencies:
graceful-readlink ">= 1.0.0"

commander@^2.11.0, commander@^2.12.1, commander@^2.18.0, commander@^2.19.0, commander@^2.8.1, commander@^2.9.0, commander@~2.20.0:
commander@^2.10.0, commander@^2.11.0, commander@^2.12.1, commander@^2.18.0, commander@^2.19.0, commander@^2.8.1, commander@^2.9.0, commander@~2.20.0:
version "2.20.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422"
integrity sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==
Expand Down Expand Up @@ -14757,6 +14762,15 @@ yargs@^12.0.0, yargs@^12.0.1, yargs@^12.0.5:
y18n "^3.2.1 || ^4.0.0"
yargs-parser "^11.1.1"

yarn-deduplicate@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/yarn-deduplicate/-/yarn-deduplicate-1.1.1.tgz#19b4a87654b66f55bf3a4bd6b153b4e4ab1b6e6d"
integrity sha512-2FDJ1dFmtvqhRmfja89ohYzpaheCYg7BFBSyaUq+kxK0y61C9oHv1XaQovCWGJtP2WU8PksQOgzMVV7oQOobzw==
dependencies:
"@yarnpkg/lockfile" "^1.1.0"
commander "^2.10.0"
semver "^5.3.0"

yauzl@2.4.1:
version "2.4.1"
resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.4.1.tgz#9528f442dab1b2284e58b4379bb194e22e0c4005"
Expand Down

0 comments on commit b3218e7

Please sign in to comment.