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

[test] Add yarn deduplicate step #2036

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
- run:
name: Check for duplicated packages
command: yarn deduplicate
- save_cache:
name: Save Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"docs:dev": "yarn workspace docs dev",
"e2e:run": "cypress run",
"e2e:open": "cypress open",
"deduplicate": "node scripts/deduplicate.js",
"docgen": "node docs/scripts/docgen.js",
"lint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx,.jsx",
"lint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx,.jsx",
Expand Down Expand Up @@ -53,7 +54,8 @@
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"wait-on": "^5.1.0"
"wait-on": "^5.1.0",
"yarn-deduplicate": "^2.1.1"
},
"husky": {
"hooks": {
Expand Down
40 changes: 40 additions & 0 deletions scripts/deduplicate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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);
});
Loading