File tree Expand file tree Collapse file tree 3 files changed +222
-12
lines changed Expand file tree Collapse file tree 3 files changed +222
-12
lines changed Original file line number Diff line number Diff line change 23
23
"scripts" : {
24
24
"test" : " jest" ,
25
25
"lint" : " eslint ." ,
26
- "prepare" : " husky install"
26
+ "prepare" : " husky install" ,
27
+ "bundle-size" : " node scripts/bundle-size"
27
28
},
28
29
"author" :
" Nicolas Charpentier <[email protected] >" ,
29
30
"license" : " MIT" ,
39
40
"jest" : " 29.5.0" ,
40
41
"lint-staged" : " 13.2.3" ,
41
42
"metro-react-native-babel-preset" : " 0.76.7" ,
43
+ "nanoid" : " 3.3.6" ,
42
44
"prettier" : " 2.8.8" ,
43
45
"react" : " 18.2.0" ,
44
46
"react-native" : " 0.72.1" ,
47
+ "react-native-bundle-scale" : " 1.1.0" ,
45
48
"typescript" : " 5.1.6"
46
49
},
47
50
"peerDependencies" : {
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/node
2
+ const util = require ( 'node:util' ) ;
3
+ const exec = util . promisify ( require ( 'node:child_process' ) . exec ) ;
4
+ const { spawn} = require ( 'node:child_process' ) ;
5
+ const fs = require ( 'node:fs' ) ;
6
+ const { nanoid} = require ( 'nanoid' ) ;
7
+
8
+ const { name, version} = require ( '../package.json' ) ;
9
+
10
+ /**
11
+ * We can't simply provide the generated tarball to `react-native-bundle-scale`, because
12
+ * Yarn will cache it based on the name of the tarball, and subsequent runs of this script
13
+ * will always result in the same output even though the content may have changed.
14
+ *
15
+ * That's why we need to rename the tarball with something unique.
16
+ */
17
+ ( async ( ) => {
18
+ await exec ( 'npm pack' ) ;
19
+
20
+ const tarballName = `${ name } -${ nanoid ( ) } ` ;
21
+ await exec ( `mv ${ name } -${ version } .tgz ${ tarballName } .tgz` ) ;
22
+
23
+ const childProcess = spawn (
24
+ 'npx' ,
25
+ [
26
+ 'react-native-bundle-scale' ,
27
+ JSON . stringify ( {
28
+ 'react-native-url-polyfill' : `file:${ __dirname } /../${ tarballName } .tgz` ,
29
+ } ) ,
30
+ '--packages-as-json' ,
31
+ '--debug' ,
32
+ ] ,
33
+ { stdio : 'inherit' } ,
34
+ ) ;
35
+
36
+ childProcess . on ( 'close' , ( ) => {
37
+ fs . unlinkSync ( `${ tarballName } .tgz` ) ;
38
+ } ) ;
39
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments