forked from yarnpkg/yarn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrim-mirror-test-packages.js
31 lines (27 loc) · 1006 Bytes
/
trim-mirror-test-packages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
/**
* For linking test purposes we may use a mirror of real life packages.
* This script goes through all packages in a mirror folder, strips anything
* that is not package.json because it is irrelevant to tests
*/
require('shelljs/global');
cd('__tests__/fixtures/install');
let files = ls('common-mirror-2');
cd('common-mirror-2');
for (let file of files) {
echo('repacking', file);
exec(`tar -xvzf ${file}`, {silent: true});
let folder = ls('').filter((name) => name.indexOf('.tgz') === -1 && name !== 'trimmed-package')[0];
mkdir('trimmed-package');
cp(`${folder}/package.json`, 'trimmed-package/package.json');
cd('trimmed-package');
let packageJson = JSON.parse(cat('package.json'));
// these sections have references to code and will fail installation
delete packageJson.scripts;
delete packageJson.bin;
JSON.stringify(packageJson, null, 4).to('package.json');
exec('npm pack');
mv(file, '..');
cd('..');
rm('-rf', [folder, 'trimmed-package']);
}