11import path from 'node:path' ;
22import { translateOptions } from './utils' ;
33import * as fs from 'fs-extra' ;
4- import { ZipFile } from 'yazl' ;
5- import { open as openZipFile } from 'yauzl' ;
4+ import { ZipFile as YazlZipFile } from 'yazl' ;
5+ import {
6+ type Entry ,
7+ open as openZipFile ,
8+ type ZipFile as YauzlZipFile ,
9+ } from 'yauzl' ;
610import { question , checkPlugins } from './utils' ;
711import { checkPlatform } from './app' ;
812import { spawn , spawnSync } from 'node:child_process' ;
@@ -16,9 +20,11 @@ import { tempDir } from './utils/constants';
1620import { checkLockFiles } from './utils/check-lockfile' ;
1721import { addGitIgnore } from './utils/add-gitignore' ;
1822
19- let bsdiff ;
20- let hdiff ;
21- let diff ;
23+ type Diff = ( oldSource ?: Buffer , newSource ?: Buffer ) => Buffer ;
24+
25+ let bsdiff : Diff ;
26+ let hdiff : Diff ;
27+ let diff : Diff ;
2228try {
2329 bsdiff = require ( 'node-bsdiff' ) . diff ;
2430} catch ( e ) { }
@@ -59,9 +65,7 @@ async function runReactNativeBundleCommand({
5965 if ( platform === 'android' ) {
6066 gradleConfig = await checkGradleConfig ( ) ;
6167 if ( gradleConfig . crunchPngs !== false ) {
62- console . warn (
63- 'android 的 crunchPngs 选项似乎尚未禁用(如已禁用则请忽略此提示),这可能导致热更包体积异常增大,具体请参考 https://pushy.reactnative.cn/docs/getting-started.html#%E7%A6%81%E7%94%A8-android-%E7%9A%84-crunch-%E4%BC%98%E5%8C%96 \n' ,
64- ) ;
68+ console . warn ( t ( 'androidCrunchPngsWarning' ) ) ;
6569 }
6670 }
6771
@@ -321,7 +325,7 @@ async function compileHermesByteCode(
321325 sourcemapOutput : string ,
322326 shouldCleanSourcemap : boolean ,
323327) {
324- console . log ( 'Hermes enabled, now compiling to hermes bytecode:\n' ) ;
328+ console . log ( t ( 'hermesEnabledCompiling' ) ) ;
325329 // >= rn 0.69
326330 const rnDir = path . dirname (
327331 require . resolve ( 'react-native' , {
@@ -351,7 +355,9 @@ async function compileHermesByteCode(
351355 ) ;
352356 args . push ( '-output-source-map' ) ;
353357 }
354- console . log ( t ( 'runningHermesc' , { command : hermesCommand , args : args . join ( ' ' ) } ) ) ;
358+ console . log (
359+ t ( 'runningHermesc' , { command : hermesCommand , args : args . join ( ' ' ) } ) ,
360+ ) ;
355361 spawnSync ( hermesCommand , args , {
356362 stdio : 'ignore' ,
357363 } ) ;
@@ -387,7 +393,7 @@ async function copyDebugidForSentry(
387393 sourcemapOutput : string ,
388394) {
389395 if ( sourcemapOutput ) {
390- let copyDebugidPath ;
396+ let copyDebugidPath : string | undefined ;
391397 try {
392398 copyDebugidPath = require . resolve (
393399 '@sentry/react-native/scripts/copy-debugid.js' ,
@@ -426,13 +432,13 @@ async function uploadSourcemapForSentry(
426432 version : string ,
427433) {
428434 if ( sourcemapOutput ) {
429- let sentryCliPath ;
435+ let sentryCliPath : string | undefined ;
430436 try {
431437 sentryCliPath = require . resolve ( '@sentry/cli/bin/sentry-cli' , {
432438 paths : [ process . cwd ( ) ] ,
433439 } ) ;
434440 } catch ( error ) {
435- console . error ( '无法找到 Sentry CLI 工具,请确保已正确安装 @sentry/cli' ) ;
441+ console . error ( t ( 'sentryCliNotFound' ) ) ;
436442 return ;
437443 }
438444
@@ -471,12 +477,12 @@ async function uploadSourcemapForSentry(
471477}
472478
473479const ignorePackingFileNames = [ '.' , '..' , 'index.bundlejs.map' ] ;
474- const ignorePackingExtensions = [ 'DS_Store' , 'txt.map' ] ;
480+ const ignorePackingExtensions = [ 'DS_Store' , 'txt.map' ] ;
475481async function pack ( dir : string , output : string ) {
476482 console . log ( t ( 'packing' ) ) ;
477483 fs . ensureDirSync ( path . dirname ( output ) ) ;
478484 await new Promise < void > ( ( resolve , reject ) => {
479- const zipfile = new ZipFile ( ) ;
485+ const zipfile = new YazlZipFile ( ) ;
480486
481487 function addDirectory ( root : string , rel : string ) {
482488 if ( rel ) {
@@ -513,10 +519,13 @@ async function pack(dir: string, output: string) {
513519 console . log ( t ( 'fileGenerated' , { file : output } ) ) ;
514520}
515521
516- export function readEntire ( entry : string , zipFile : ZipFile ) {
522+ export function readEntry (
523+ entry : Entry ,
524+ zipFile : YauzlZipFile ,
525+ ) : Promise < Buffer > {
517526 const buffers : Buffer [ ] = [ ] ;
518527 return new Promise ( ( resolve , reject ) => {
519- zipFile . openReadStream ( entry , ( err : any , stream : any ) => {
528+ zipFile . openReadStream ( entry , ( err , stream ) => {
520529 stream . pipe ( {
521530 write ( chunk : Buffer ) {
522531 buffers . push ( chunk ) ;
@@ -544,7 +553,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
544553 const originEntries = { } ;
545554 const originMap = { } ;
546555
547- let originSource ;
556+ let originSource : Buffer | undefined ;
548557
549558 await enumZipEntries ( origin , ( entry , zipFile ) => {
550559 originEntries [ entry . fileName ] = entry ;
@@ -557,7 +566,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
557566 entry . fileName === 'bundle.harmony.js'
558567 ) {
559568 // This is source.
560- return readEntire ( entry , zipFile ) . then ( ( v ) => ( originSource = v ) ) ;
569+ return readEntry ( entry , zipFile ) . then ( ( v ) => ( originSource = v ) ) ;
561570 }
562571 }
563572 } ) ;
@@ -570,7 +579,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
570579
571580 const copies = { } ;
572581
573- const zipfile = new ZipFile ( ) ;
582+ const zipfile = new YazlZipFile ( ) ;
574583
575584 const writePromise = new Promise ( ( resolve , reject ) => {
576585 zipfile . outputStream . on ( 'error' , ( err ) => {
@@ -607,7 +616,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
607616 }
608617 } else if ( entry . fileName === 'index.bundlejs' ) {
609618 //console.log('Found bundle');
610- return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
619+ return readEntry ( entry , nextZipfile ) . then ( ( newSource ) => {
611620 //console.log('Begin diff');
612621 zipfile . addBuffer (
613622 diff ( originSource , newSource ) ,
@@ -617,7 +626,7 @@ async function diffFromPPK(origin: string, next: string, output: string) {
617626 } ) ;
618627 } else if ( entry . fileName === 'bundle.harmony.js' ) {
619628 //console.log('Found bundle');
620- return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
629+ return readEntry ( entry , nextZipfile ) . then ( ( newSource ) => {
621630 //console.log('Begin diff');
622631 zipfile . addBuffer (
623632 diff ( originSource , newSource ) ,
@@ -691,9 +700,9 @@ async function diffFromPackage(
691700 const originEntries = { } ;
692701 const originMap = { } ;
693702
694- let originSource ;
703+ let originSource : Buffer | undefined ;
695704
696- await enumZipEntries ( origin , ( entry : any , zipFile : any ) => {
705+ await enumZipEntries ( origin , ( entry , zipFile ) => {
697706 if ( ! / \/ $ / . test ( entry . fileName ) ) {
698707 const fn = transformPackagePath ( entry . fileName ) ;
699708 if ( ! fn ) {
@@ -707,7 +716,7 @@ async function diffFromPackage(
707716
708717 if ( fn === originBundleName ) {
709718 // This is source.
710- return readEntire ( entry , zipFile ) . then ( ( v ) => ( originSource = v ) ) ;
719+ return readEntry ( entry , zipFile ) . then ( ( v ) => ( originSource = v ) ) ;
711720 }
712721 }
713722 } ) ;
@@ -720,7 +729,7 @@ async function diffFromPackage(
720729
721730 const copies = { } ;
722731
723- const zipfile = new ZipFile ( ) ;
732+ const zipfile = new YazlZipFile ( ) ;
724733
725734 const writePromise = new Promise ( ( resolve , reject ) => {
726735 zipfile . outputStream . on ( 'error' , ( err ) => {
@@ -737,7 +746,7 @@ async function diffFromPackage(
737746 zipfile . addEmptyDirectory ( entry . fileName ) ;
738747 } else if ( entry . fileName === 'index.bundlejs' ) {
739748 //console.log('Found bundle');
740- return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
749+ return readEntry ( entry , nextZipfile ) . then ( ( newSource ) => {
741750 //console.log('Begin diff');
742751 zipfile . addBuffer (
743752 diff ( originSource , newSource ) ,
@@ -747,7 +756,7 @@ async function diffFromPackage(
747756 } ) ;
748757 } else if ( entry . fileName === 'bundle.harmony.js' ) {
749758 //console.log('Found bundle');
750- return readEntire ( entry , nextZipfile ) . then ( ( newSource ) => {
759+ return readEntry ( entry , nextZipfile ) . then ( ( newSource ) => {
751760 //console.log('Begin diff');
752761 zipfile . addBuffer (
753762 diff ( originSource , newSource ) ,
@@ -789,14 +798,18 @@ async function diffFromPackage(
789798
790799export async function enumZipEntries (
791800 zipFn : string ,
792- callback : ( entry : any , zipFile : any ) => void ,
801+ callback : (
802+ entry : Entry ,
803+ zipFile : YauzlZipFile ,
804+ nestedPath ?: string ,
805+ ) => Promise < any > ,
793806 nestedPath = '' ,
794807) {
795808 return new Promise ( ( resolve , reject ) => {
796809 openZipFile (
797810 zipFn ,
798811 { lazyEntries : true } ,
799- async ( err : any , zipfile : ZipFile ) => {
812+ async ( err : any , zipfile : YauzlZipFile ) => {
800813 if ( err ) {
801814 return reject ( err ) ;
802815 }
@@ -850,7 +863,7 @@ export async function enumZipEntries(
850863 } ) ;
851864}
852865
853- function diffArgsCheck ( args , options , diffFn ) {
866+ function diffArgsCheck ( args : string [ ] , options : any , diffFn : string ) {
854867 const [ origin , next ] = args ;
855868
856869 if ( ! origin || ! next ) {
@@ -889,7 +902,7 @@ function diffArgsCheck(args, options, diffFn) {
889902export const commands = {
890903 bundle : async function ( { options } ) {
891904 const platform = checkPlatform (
892- options . platform || ( await question ( '平台(ios/android/harmony):' ) ) ,
905+ options . platform || ( await question ( t ( 'platformPrompt' ) ) ) ,
893906 ) ;
894907
895908 const {
@@ -943,7 +956,7 @@ export const commands = {
943956
944957 await pack ( path . resolve ( intermediaDir ) , realOutput ) ;
945958
946- const v = await question ( '是否现在上传此热更包?(Y/N)' ) ;
959+ const v = await question ( t ( 'uploadBundlePrompt' ) ) ;
947960 if ( v . toLowerCase ( ) === 'y' ) {
948961 const versionName = await this . publish ( {
949962 args : [ realOutput ] ,
0 commit comments