-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbundle-size.js
39 lines (34 loc) · 1.11 KB
/
bundle-size.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
32
33
34
35
36
37
38
39
#!/usr/bin/node
const util = require('node:util');
const exec = util.promisify(require('node:child_process').exec);
const {spawn} = require('node:child_process');
const fs = require('node:fs');
const {nanoid} = require('nanoid');
const {name, version} = require('../package.json');
/**
* We can't simply provide the generated tarball to `react-native-bundle-scale`, because
* Yarn will cache it based on the name of the tarball, and subsequent runs of this script
* will always result in the same output even though the content may have changed.
*
* That's why we need to rename the tarball with something unique.
*/
(async () => {
await exec('npm pack');
const tarballName = `${name}-${nanoid()}`;
await exec(`mv ${name}-${version}.tgz ${tarballName}.tgz`);
const childProcess = spawn(
'npx',
[
'react-native-bundle-scale',
JSON.stringify({
'react-native-url-polyfill': `file:${__dirname}/../${tarballName}.tgz`,
}),
'--packages-as-json',
'--debug',
],
{stdio: 'inherit'},
);
childProcess.on('close', () => {
fs.unlinkSync(`${tarballName}.tgz`);
});
})();