Skip to content

Commit

Permalink
[core] Deduplicate packages
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jul 17, 2019
1 parent 02c62f6 commit 6835008
Show file tree
Hide file tree
Showing 4 changed files with 85 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 @@ -23,6 +23,9 @@ commands:
- run:
name: Install js dependencies
command: yarn
- run:
name: Check for duplicated packages
command: yarn deduplicate
prepare_chrome_headless:
steps:
- run:
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.0",
"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 @@ -200,7 +201,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
64 changes: 64 additions & 0 deletions scripts/deduplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* eslint-disable no-console */

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

function deduplicatePackages() {
return new Promise(resolve => {
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');
resolve();
return;
}

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, '..'),
env: { NOYARNPOSTINSTALL: 1 },
});

yarn.on('close', code => {
if (code !== 0) {
process.exit(code);
}

resolve();
});
});
}

async function run() {
if (process.env.NOYARNPOSTINSTALL) {
return;
}

await deduplicatePackages();
}

run();
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,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 @@ -4323,7 +4328,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 @@ -14737,6 +14742,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 6835008

Please sign in to comment.