Skip to content

Commit

Permalink
Remove postinstall check, remove function wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz committed Jul 17, 2019
1 parent b822fb8 commit e51c925
Showing 1 changed file with 29 additions and 51 deletions.
80 changes: 29 additions & 51 deletions scripts/deduplicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,38 @@ 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 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);
}
const duplicates = deduplicate.listDuplicates(yarnlock);
if (duplicates.length === 0) {
console.log('No duplicated packages found');
process.exit(0);
}

resolve();
});
});
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);
}

async function run() {
if (process.env.NOYARNPOSTINSTALL) {
return;
}
console.log('Deduplicating package(s)');
fs.writeFileSync(lockFile, deduplicate.fixDuplicates(yarnlock));

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

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

0 comments on commit e51c925

Please sign in to comment.