@@ -22,16 +22,20 @@ try {
2222 hdiff = require ( 'node-hdiffpatch' ) . diff ;
2323} catch ( e ) { }
2424
25+
2526async function runReactNativeBundleCommand (
26- bundleName ,
27- development ,
28- entryFile ,
29- outputFolder ,
30- platform ,
31- sourcemapOutput ,
32- config ,
27+ bundleName : string ,
28+ development : string ,
29+ entryFile : string ,
30+ outputFolder : string ,
31+ platform : string ,
32+ sourcemapOutput : string ,
33+ config : string ,
3334) {
34- let gradleConfig = { } ;
35+ let gradleConfig : {
36+ crunchPngs ?: boolean ;
37+ enableHermes ?: boolean ;
38+ } = { } ;
3539 if ( platform === 'android' ) {
3640 gradleConfig = await checkGradleConfig ( ) ;
3741 if ( gradleConfig . crunchPngs !== false ) {
@@ -41,7 +45,7 @@ async function runReactNativeBundleCommand(
4145 }
4246 }
4347
44- const reactNativeBundleArgs = [ ] ;
48+ const reactNativeBundleArgs : string [ ] = [ ] ;
4549
4650 const envArgs = process . env . PUSHY_ENV_ARGS ;
4751
@@ -158,17 +162,17 @@ async function runReactNativeBundleCommand(
158162 ) ,
159163 ) ;
160164 } else {
161- let hermesEnabled = false ;
165+ let hermesEnabled : boolean | undefined = false ;
162166
163167 if ( platform === 'android' ) {
164- const gradlePropeties = await new Promise ( ( resolve ) => {
168+ const gradlePropeties = await new Promise < { hermesEnabled ?: boolean } > ( ( resolve ) => {
165169 properties . parse (
166170 './android/gradle.properties' ,
167171 { path : true } ,
168- ( error , props ) => {
172+ ( error : any , props : { hermesEnabled ?: boolean } ) => {
169173 if ( error ) {
170174 console . error ( error ) ;
171- resolve ( null ) ;
175+ resolve ( { } ) ;
172176 }
173177
174178 resolve ( props ) ;
@@ -201,7 +205,7 @@ async function runReactNativeBundleCommand(
201205 } ) ;
202206}
203207
204- async function copyHarmonyBundle ( outputFolder ) {
208+ async function copyHarmonyBundle ( outputFolder : string ) {
205209 const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile' ;
206210 try {
207211 await fs . ensureDir ( harmonyRawPath ) ;
@@ -215,7 +219,7 @@ async function copyHarmonyBundle(outputFolder) {
215219
216220 await fs . ensureDir ( outputFolder ) ;
217221 await fs . copy ( harmonyRawPath , outputFolder ) ;
218- } catch ( error ) {
222+ } catch ( error : any ) {
219223 console . error ( 'copyHarmonyBundle 错误:' , error ) ;
220224 throw new Error ( `复制文件失败: ${ error . message } ` ) ;
221225 }
@@ -253,10 +257,10 @@ async function checkGradleConfig() {
253257}
254258
255259async function compileHermesByteCode (
256- bundleName ,
257- outputFolder ,
258- sourcemapOutput ,
259- shouldCleanSourcemap ,
260+ bundleName : string ,
261+ outputFolder : string ,
262+ sourcemapOutput : string ,
263+ shouldCleanSourcemap : boolean ,
260264) {
261265 console . log ( 'Hermes enabled, now compiling to hermes bytecode:\n' ) ;
262266 // >= rn 0.69
@@ -318,7 +322,7 @@ async function compileHermesByteCode(
318322 }
319323}
320324
321- async function copyDebugidForSentry ( bundleName , outputFolder , sourcemapOutput ) {
325+ async function copyDebugidForSentry ( bundleName : string , outputFolder : string , sourcemapOutput : string ) {
322326 if ( sourcemapOutput ) {
323327 let copyDebugidPath ;
324328 try {
@@ -355,10 +359,10 @@ async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
355359}
356360
357361async function uploadSourcemapForSentry (
358- bundleName ,
359- outputFolder ,
360- sourcemapOutput ,
361- version ,
362+ bundleName : string ,
363+ outputFolder : string ,
364+ sourcemapOutput : string ,
365+ version : string ,
362366) {
363367 if ( sourcemapOutput ) {
364368 let sentryCliPath ;
@@ -405,19 +409,21 @@ async function uploadSourcemapForSentry(
405409 }
406410}
407411
408- async function pack ( dir , output ) {
412+ const ignorePackingFileNames = [ '.' , '..' , 'index.bundlejs.map' ] ;
413+ const ignorePackingExtensions = [ 'DS_Store' ] ;
414+ async function pack ( dir : string , output : string ) {
409415 console . log ( 'Packing' ) ;
410416 fs . ensureDirSync ( path . dirname ( output ) ) ;
411- await new Promise ( ( resolve , reject ) => {
417+ await new Promise < void > ( ( resolve , reject ) => {
412418 const zipfile = new ZipFile ( ) ;
413419
414- function addDirectory ( root , rel ) {
420+ function addDirectory ( root : string , rel : string ) {
415421 if ( rel ) {
416422 zipfile . addEmptyDirectory ( rel ) ;
417423 }
418424 const childs = fs . readdirSync ( root ) ;
419425 for ( const name of childs ) {
420- if ( name === '.' || name === '..' || name === 'index.bundlejs.map' || name === 'index.bundlejs.txt.map' ) {
426+ if ( ignorePackingFileNames . includes ( name ) || ignorePackingExtensions . some ( ext => name . endsWith ( `. ${ ext } ` ) ) ) {
421427 continue ;
422428 }
423429 const fullPath = path . join ( root , name ) ;
@@ -434,7 +440,7 @@ async function pack(dir, output) {
434440
435441 addDirectory ( dir , '' ) ;
436442
437- zipfile . outputStream . on ( 'error' , ( err ) => reject ( err ) ) ;
443+ zipfile . outputStream . on ( 'error' , ( err : any ) => reject ( err ) ) ;
438444 zipfile . outputStream . pipe ( fs . createWriteStream ( output ) ) . on ( 'close' , ( ) => {
439445 resolve ( ) ;
440446 } ) ;
@@ -443,12 +449,12 @@ async function pack(dir, output) {
443449 console . log ( `ppk热更包已生成并保存到: ${ output } ` ) ;
444450}
445451
446- export function readEntire ( entry , zipFile ) {
447- const buffers = [ ] ;
452+ export function readEntire ( entry : string , zipFile : ZipFile ) {
453+ const buffers : Buffer [ ] = [ ] ;
448454 return new Promise ( ( resolve , reject ) => {
449- zipFile . openReadStream ( entry , ( err , stream ) => {
455+ zipFile . openReadStream ( entry , ( err : any , stream : any ) => {
450456 stream . pipe ( {
451- write ( chunk ) {
457+ write ( chunk : Buffer ) {
452458 buffers . push ( chunk ) ;
453459 } ,
454460 end ( ) {
@@ -463,12 +469,12 @@ export function readEntire(entry, zipFile) {
463469 } ) ;
464470}
465471
466- function basename ( fn ) {
472+ function basename ( fn : string ) {
467473 const m = / ^ ( .+ \/ ) [ ^ \/ ] + \/ ? $ / . exec ( fn ) ;
468474 return m ?. [ 1 ] ;
469475}
470476
471- async function diffFromPPK ( origin , next , output ) {
477+ async function diffFromPPK ( origin : string , next : string , output : string ) {
472478 fs . ensureDirSync ( path . dirname ( output ) ) ;
473479
474480 const originEntries = { } ;
@@ -513,7 +519,7 @@ async function diffFromPPK(origin, next, output) {
513519
514520 const addedEntry = { } ;
515521
516- function addEntry ( fn ) {
522+ function addEntry ( fn : string ) {
517523 //console.log(fn);
518524 if ( ! fn || addedEntry [ fn ] ) {
519525 return ;
@@ -610,11 +616,11 @@ async function diffFromPPK(origin, next, output) {
610616}
611617
612618async function diffFromPackage (
613- origin ,
614- next ,
615- output ,
616- originBundleName ,
617- transformPackagePath = ( v ) => v ,
619+ origin : string ,
620+ next : string ,
621+ output : string ,
622+ originBundleName : string ,
623+ transformPackagePath = ( v : string ) => v ,
618624) {
619625 fs . ensureDirSync ( path . dirname ( output ) ) ;
620626
@@ -623,7 +629,7 @@ async function diffFromPackage(
623629
624630 let originSource ;
625631
626- await enumZipEntries ( origin , ( entry , zipFile ) => {
632+ await enumZipEntries ( origin , ( entry : any , zipFile : any ) => {
627633 if ( ! / \/ $ / . test ( entry . fileName ) ) {
628634 const fn = transformPackagePath ( entry . fileName ) ;
629635 if ( ! fn ) {
@@ -717,9 +723,9 @@ async function diffFromPackage(
717723 await writePromise ;
718724}
719725
720- export async function enumZipEntries ( zipFn , callback , nestedPath = '' ) {
726+ export async function enumZipEntries ( zipFn : string , callback : ( entry : any , zipFile : any ) => void , nestedPath = '' ) {
721727 return new Promise ( ( resolve , reject ) => {
722- openZipFile ( zipFn , { lazyEntries : true } , async ( err , zipfile ) => {
728+ openZipFile ( zipFn , { lazyEntries : true } , async ( err : any , zipfile : ZipFile ) => {
723729 if ( err ) {
724730 return reject ( err ) ;
725731 }
0 commit comments