react-native-update-cli 2.7.3 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundle.js +6 -384
- package/lib/diff.js +387 -0
- package/lib/index.js +3 -0
- package/lib/utils/app-info-parser/utils.js +0 -1
- package/lib/utils/app-info-parser/zip.js +12 -14
- package/lib/utils/latest-version/index.js +5 -4
- package/lib/utils/zip-entries.js +129 -0
- package/package.json +26 -7
- package/src/bundle.ts +1 -483
- package/src/diff.ts +405 -0
- package/src/index.ts +3 -0
- package/src/utils/app-info-parser/utils.ts +0 -4
- package/src/utils/app-info-parser/zip.ts +9 -19
- package/src/utils/latest-version/index.ts +2 -1
- package/src/utils/zip-entries.ts +96 -0
package/lib/bundle.js
CHANGED
|
@@ -2,33 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
bundleCommands: function() {
|
|
5
|
+
Object.defineProperty(exports, "bundleCommands", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
13
8
|
return bundleCommands;
|
|
14
|
-
},
|
|
15
|
-
enumZipEntries: function() {
|
|
16
|
-
return enumZipEntries;
|
|
17
|
-
},
|
|
18
|
-
readEntry: function() {
|
|
19
|
-
return readEntry;
|
|
20
9
|
}
|
|
21
10
|
});
|
|
22
11
|
const _child_process = require("child_process");
|
|
23
12
|
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
24
13
|
const _compareversions = require("compare-versions");
|
|
25
14
|
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
26
|
-
const _yauzl = require("yauzl");
|
|
27
15
|
const _yazl = require("yazl");
|
|
28
16
|
const _app = require("./app");
|
|
29
17
|
const _utils = require("./utils");
|
|
30
|
-
const _os = /*#__PURE__*/ _interop_require_default(require("os"));
|
|
31
|
-
const _globaldirs = require("global-dirs");
|
|
32
18
|
const _addgitignore = require("./utils/add-gitignore");
|
|
33
19
|
const _checklockfile = require("./utils/check-lockfile");
|
|
34
20
|
const _constants = require("./utils/constants");
|
|
@@ -83,28 +69,6 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
83
69
|
}
|
|
84
70
|
const g2js = require('gradle-to-js/lib/parser');
|
|
85
71
|
const properties = require('properties');
|
|
86
|
-
const loadDiffModule = (pkgName)=>{
|
|
87
|
-
const resolvePaths = [
|
|
88
|
-
process.cwd(),
|
|
89
|
-
_globaldirs.npm.packages,
|
|
90
|
-
_globaldirs.yarn.packages
|
|
91
|
-
];
|
|
92
|
-
try {
|
|
93
|
-
const resolved = require.resolve(pkgName, {
|
|
94
|
-
paths: resolvePaths
|
|
95
|
-
});
|
|
96
|
-
const mod = require(resolved);
|
|
97
|
-
if (mod == null ? void 0 : mod.diff) {
|
|
98
|
-
return mod.diff;
|
|
99
|
-
}
|
|
100
|
-
} catch (e) {}
|
|
101
|
-
return undefined;
|
|
102
|
-
};
|
|
103
|
-
let bsdiff;
|
|
104
|
-
let hdiff;
|
|
105
|
-
let diff;
|
|
106
|
-
bsdiff = loadDiffModule('node-bsdiff');
|
|
107
|
-
hdiff = loadDiffModule('node-hdiffpatch');
|
|
108
72
|
async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputFolder, platform, sourcemapOutput, config, forceHermes, cli }) {
|
|
109
73
|
let gradleConfig = {};
|
|
110
74
|
if (platform === 'android') {
|
|
@@ -289,9 +253,9 @@ async function runReactNativeBundleCommand({ bundleName, dev, entryFile, outputF
|
|
|
289
253
|
});
|
|
290
254
|
}
|
|
291
255
|
function getHermesOSBin() {
|
|
292
|
-
if (
|
|
293
|
-
if (
|
|
294
|
-
if (
|
|
256
|
+
if (os.platform() === 'win32') return 'win64-bin';
|
|
257
|
+
if (os.platform() === 'darwin') return 'osx-bin';
|
|
258
|
+
if (os.platform() === 'linux') return 'linux64-bin';
|
|
295
259
|
}
|
|
296
260
|
async function checkGradleConfig() {
|
|
297
261
|
let enableHermes = false;
|
|
@@ -483,286 +447,6 @@ async function pack(dir, output) {
|
|
|
483
447
|
file: output
|
|
484
448
|
}));
|
|
485
449
|
}
|
|
486
|
-
function readEntry(entry, zipFile) {
|
|
487
|
-
const buffers = [];
|
|
488
|
-
return new Promise((resolve, reject)=>{
|
|
489
|
-
zipFile.openReadStream(entry, (err, stream)=>{
|
|
490
|
-
stream.on('data', (chunk)=>{
|
|
491
|
-
buffers.push(chunk);
|
|
492
|
-
});
|
|
493
|
-
stream.on('end', ()=>{
|
|
494
|
-
resolve(Buffer.concat(buffers));
|
|
495
|
-
});
|
|
496
|
-
stream.on('error', (err)=>{
|
|
497
|
-
reject(err);
|
|
498
|
-
});
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
}
|
|
502
|
-
function basename(fn) {
|
|
503
|
-
const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
|
|
504
|
-
return m == null ? void 0 : m[1];
|
|
505
|
-
}
|
|
506
|
-
async function diffFromPPK(origin, next, output) {
|
|
507
|
-
_fsextra.ensureDirSync(_path.default.dirname(output));
|
|
508
|
-
const originEntries = {};
|
|
509
|
-
const originMap = {};
|
|
510
|
-
let originSource;
|
|
511
|
-
await enumZipEntries(origin, (entry, zipFile)=>{
|
|
512
|
-
originEntries[entry.fileName] = entry;
|
|
513
|
-
if (!/\/$/.test(entry.fileName)) {
|
|
514
|
-
// isFile
|
|
515
|
-
originMap[entry.crc32] = entry.fileName;
|
|
516
|
-
if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
|
|
517
|
-
// This is source.
|
|
518
|
-
return readEntry(entry, zipFile).then((v)=>originSource = v);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
if (!originSource) {
|
|
523
|
-
throw new Error((0, _i18n.t)('bundleFileNotFound'));
|
|
524
|
-
}
|
|
525
|
-
const copies = {};
|
|
526
|
-
const zipfile = new _yazl.ZipFile();
|
|
527
|
-
const writePromise = new Promise((resolve, reject)=>{
|
|
528
|
-
zipfile.outputStream.on('error', (err)=>{
|
|
529
|
-
throw err;
|
|
530
|
-
});
|
|
531
|
-
zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
|
|
532
|
-
resolve(void 0);
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
const addedEntry = {};
|
|
536
|
-
function addEntry(fn) {
|
|
537
|
-
//console.log(fn);
|
|
538
|
-
if (!fn || addedEntry[fn]) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const base = basename(fn);
|
|
542
|
-
if (base) {
|
|
543
|
-
addEntry(base);
|
|
544
|
-
}
|
|
545
|
-
zipfile.addEmptyDirectory(fn);
|
|
546
|
-
}
|
|
547
|
-
const newEntries = {};
|
|
548
|
-
await enumZipEntries(next, (entry, nextZipfile)=>{
|
|
549
|
-
newEntries[entry.fileName] = entry;
|
|
550
|
-
if (/\/$/.test(entry.fileName)) {
|
|
551
|
-
// Directory
|
|
552
|
-
if (!originEntries[entry.fileName]) {
|
|
553
|
-
addEntry(entry.fileName);
|
|
554
|
-
}
|
|
555
|
-
} else if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
|
|
556
|
-
//console.log('Found bundle');
|
|
557
|
-
return readEntry(entry, nextZipfile).then((newSource)=>{
|
|
558
|
-
//console.log('Begin diff');
|
|
559
|
-
zipfile.addBuffer(diff(originSource, newSource), `${entry.fileName}.patch`);
|
|
560
|
-
//console.log('End diff');
|
|
561
|
-
});
|
|
562
|
-
} else {
|
|
563
|
-
// If same file.
|
|
564
|
-
const originEntry = originEntries[entry.fileName];
|
|
565
|
-
if (originEntry && originEntry.crc32 === entry.crc32) {
|
|
566
|
-
// ignore
|
|
567
|
-
return;
|
|
568
|
-
}
|
|
569
|
-
// If moved from other place
|
|
570
|
-
if (originMap[entry.crc32]) {
|
|
571
|
-
const base = basename(entry.fileName);
|
|
572
|
-
if (!originEntries[base]) {
|
|
573
|
-
addEntry(base);
|
|
574
|
-
}
|
|
575
|
-
copies[entry.fileName] = originMap[entry.crc32];
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
// New file.
|
|
579
|
-
addEntry(basename(entry.fileName));
|
|
580
|
-
return new Promise((resolve, reject)=>{
|
|
581
|
-
nextZipfile.openReadStream(entry, (err, readStream)=>{
|
|
582
|
-
if (err) {
|
|
583
|
-
return reject(err);
|
|
584
|
-
}
|
|
585
|
-
zipfile.addReadStream(readStream, entry.fileName);
|
|
586
|
-
readStream.on('end', ()=>{
|
|
587
|
-
//console.log('add finished');
|
|
588
|
-
resolve(void 0);
|
|
589
|
-
});
|
|
590
|
-
});
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
|
-
const deletes = {};
|
|
595
|
-
for(const k in originEntries){
|
|
596
|
-
if (!newEntries[k]) {
|
|
597
|
-
console.log((0, _i18n.t)('deleteFile', {
|
|
598
|
-
file: k
|
|
599
|
-
}));
|
|
600
|
-
deletes[k] = 1;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
//console.log({copies, deletes});
|
|
604
|
-
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
605
|
-
copies,
|
|
606
|
-
deletes
|
|
607
|
-
})), '__diff.json');
|
|
608
|
-
zipfile.end();
|
|
609
|
-
await writePromise;
|
|
610
|
-
}
|
|
611
|
-
async function diffFromPackage(origin, next, output, originBundleName, transformPackagePath = (v)=>v) {
|
|
612
|
-
_fsextra.ensureDirSync(_path.default.dirname(output));
|
|
613
|
-
const originEntries = {};
|
|
614
|
-
const originMap = {};
|
|
615
|
-
let originSource;
|
|
616
|
-
await enumZipEntries(origin, (entry, zipFile)=>{
|
|
617
|
-
if (!/\/$/.test(entry.fileName)) {
|
|
618
|
-
const fn = transformPackagePath(entry.fileName);
|
|
619
|
-
if (!fn) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
//console.log(fn);
|
|
623
|
-
// isFile
|
|
624
|
-
originEntries[fn] = entry.crc32;
|
|
625
|
-
originMap[entry.crc32] = fn;
|
|
626
|
-
if (fn === originBundleName) {
|
|
627
|
-
// This is source.
|
|
628
|
-
return readEntry(entry, zipFile).then((v)=>originSource = v);
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
if (!originSource) {
|
|
633
|
-
throw new Error((0, _i18n.t)('bundleFileNotFound'));
|
|
634
|
-
}
|
|
635
|
-
const copies = {};
|
|
636
|
-
const zipfile = new _yazl.ZipFile();
|
|
637
|
-
const writePromise = new Promise((resolve, reject)=>{
|
|
638
|
-
zipfile.outputStream.on('error', (err)=>{
|
|
639
|
-
throw err;
|
|
640
|
-
});
|
|
641
|
-
zipfile.outputStream.pipe(_fsextra.createWriteStream(output)).on('close', ()=>{
|
|
642
|
-
resolve(void 0);
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
await enumZipEntries(next, (entry, nextZipfile)=>{
|
|
646
|
-
if (/\/$/.test(entry.fileName)) {
|
|
647
|
-
// Directory
|
|
648
|
-
zipfile.addEmptyDirectory(entry.fileName);
|
|
649
|
-
} else if ((0, _constants.isPPKBundleFileName)(entry.fileName)) {
|
|
650
|
-
//console.log('Found bundle');
|
|
651
|
-
return readEntry(entry, nextZipfile).then((newSource)=>{
|
|
652
|
-
//console.log('Begin diff');
|
|
653
|
-
zipfile.addBuffer(diff(originSource, newSource), `${entry.fileName}.patch`);
|
|
654
|
-
//console.log('End diff');
|
|
655
|
-
});
|
|
656
|
-
} else {
|
|
657
|
-
// If same file.
|
|
658
|
-
if (originEntries[entry.fileName] === entry.crc32) {
|
|
659
|
-
copies[entry.fileName] = '';
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
// If moved from other place
|
|
663
|
-
if (originMap[entry.crc32]) {
|
|
664
|
-
copies[entry.fileName] = originMap[entry.crc32];
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
return new Promise((resolve, reject)=>{
|
|
668
|
-
nextZipfile.openReadStream(entry, (err, readStream)=>{
|
|
669
|
-
if (err) {
|
|
670
|
-
return reject(err);
|
|
671
|
-
}
|
|
672
|
-
zipfile.addReadStream(readStream, entry.fileName);
|
|
673
|
-
readStream.on('end', ()=>{
|
|
674
|
-
//console.log('add finished');
|
|
675
|
-
resolve(void 0);
|
|
676
|
-
});
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
}
|
|
680
|
-
});
|
|
681
|
-
zipfile.addBuffer(Buffer.from(JSON.stringify({
|
|
682
|
-
copies
|
|
683
|
-
})), '__diff.json');
|
|
684
|
-
zipfile.end();
|
|
685
|
-
await writePromise;
|
|
686
|
-
}
|
|
687
|
-
async function enumZipEntries(zipFn, callback, nestedPath = '') {
|
|
688
|
-
return new Promise((resolve, reject)=>{
|
|
689
|
-
(0, _yauzl.open)(zipFn, {
|
|
690
|
-
lazyEntries: true
|
|
691
|
-
}, async (err, zipfile)=>{
|
|
692
|
-
if (err) {
|
|
693
|
-
return reject(err);
|
|
694
|
-
}
|
|
695
|
-
zipfile.on('end', resolve);
|
|
696
|
-
zipfile.on('error', reject);
|
|
697
|
-
zipfile.on('entry', async (entry)=>{
|
|
698
|
-
const fullPath = nestedPath + entry.fileName;
|
|
699
|
-
try {
|
|
700
|
-
if (!entry.fileName.endsWith('/') && entry.fileName.toLowerCase().endsWith('.hap')) {
|
|
701
|
-
const tempDir = _path.default.join(_os.default.tmpdir(), `nested_zip_${Date.now()}`);
|
|
702
|
-
await _fsextra.ensureDir(tempDir);
|
|
703
|
-
const tempZipPath = _path.default.join(tempDir, 'temp.zip');
|
|
704
|
-
await new Promise((res, rej)=>{
|
|
705
|
-
zipfile.openReadStream(entry, async (err, readStream)=>{
|
|
706
|
-
if (err) return rej(err);
|
|
707
|
-
const writeStream = _fsextra.createWriteStream(tempZipPath);
|
|
708
|
-
readStream.pipe(writeStream);
|
|
709
|
-
writeStream.on('finish', ()=>res(void 0));
|
|
710
|
-
writeStream.on('error', rej);
|
|
711
|
-
});
|
|
712
|
-
});
|
|
713
|
-
await enumZipEntries(tempZipPath, callback, `${fullPath}/`);
|
|
714
|
-
await _fsextra.remove(tempDir);
|
|
715
|
-
}
|
|
716
|
-
const result = callback(entry, zipfile, fullPath);
|
|
717
|
-
if (result && typeof result.then === 'function') {
|
|
718
|
-
await result;
|
|
719
|
-
}
|
|
720
|
-
} catch (error) {
|
|
721
|
-
console.error((0, _i18n.t)('processingError', {
|
|
722
|
-
error
|
|
723
|
-
}));
|
|
724
|
-
}
|
|
725
|
-
zipfile.readEntry();
|
|
726
|
-
});
|
|
727
|
-
zipfile.readEntry();
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
}
|
|
731
|
-
function diffArgsCheck(args, options, diffFn) {
|
|
732
|
-
const [origin, next] = args;
|
|
733
|
-
if (!origin || !next) {
|
|
734
|
-
console.error((0, _i18n.t)('usageDiff', {
|
|
735
|
-
command: diffFn
|
|
736
|
-
}));
|
|
737
|
-
process.exit(1);
|
|
738
|
-
}
|
|
739
|
-
if (diffFn.startsWith('hdiff')) {
|
|
740
|
-
if (!hdiff) {
|
|
741
|
-
console.error((0, _i18n.t)('nodeHdiffpatchRequired', {
|
|
742
|
-
scriptName: _constants.scriptName
|
|
743
|
-
}));
|
|
744
|
-
process.exit(1);
|
|
745
|
-
}
|
|
746
|
-
diff = hdiff;
|
|
747
|
-
} else {
|
|
748
|
-
if (!bsdiff) {
|
|
749
|
-
console.error((0, _i18n.t)('nodeBsdiffRequired', {
|
|
750
|
-
scriptName: _constants.scriptName
|
|
751
|
-
}));
|
|
752
|
-
process.exit(1);
|
|
753
|
-
}
|
|
754
|
-
diff = bsdiff;
|
|
755
|
-
}
|
|
756
|
-
const { output } = (0, _utils.translateOptions)({
|
|
757
|
-
...options,
|
|
758
|
-
tempDir: _constants.tempDir
|
|
759
|
-
});
|
|
760
|
-
return {
|
|
761
|
-
origin,
|
|
762
|
-
next,
|
|
763
|
-
realOutput: output.replace(/\$\{time\}/g, `${Date.now()}`)
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
450
|
const bundleCommands = {
|
|
767
451
|
bundle: async ({ options })=>{
|
|
768
452
|
const platform = await (0, _app.getPlatform)(options.platform);
|
|
@@ -837,67 +521,5 @@ const bundleCommands = {
|
|
|
837
521
|
}
|
|
838
522
|
}
|
|
839
523
|
}
|
|
840
|
-
},
|
|
841
|
-
async diff ({ args, options }) {
|
|
842
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diff');
|
|
843
|
-
await diffFromPPK(origin, next, realOutput);
|
|
844
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
845
|
-
output: realOutput
|
|
846
|
-
}));
|
|
847
|
-
},
|
|
848
|
-
async hdiff ({ args, options }) {
|
|
849
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiff');
|
|
850
|
-
await diffFromPPK(origin, next, realOutput);
|
|
851
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
852
|
-
output: realOutput
|
|
853
|
-
}));
|
|
854
|
-
},
|
|
855
|
-
async diffFromApk ({ args, options }) {
|
|
856
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diffFromApk');
|
|
857
|
-
await diffFromPackage(origin, next, realOutput, 'assets/index.android.bundle');
|
|
858
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
859
|
-
output: realOutput
|
|
860
|
-
}));
|
|
861
|
-
},
|
|
862
|
-
async hdiffFromApk ({ args, options }) {
|
|
863
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiffFromApk');
|
|
864
|
-
await diffFromPackage(origin, next, realOutput, 'assets/index.android.bundle');
|
|
865
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
866
|
-
output: realOutput
|
|
867
|
-
}));
|
|
868
|
-
},
|
|
869
|
-
async diffFromApp ({ args, options }) {
|
|
870
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diffFromApp');
|
|
871
|
-
await diffFromPackage(origin, next, realOutput, 'resources/rawfile/bundle.harmony.js');
|
|
872
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
873
|
-
output: realOutput
|
|
874
|
-
}));
|
|
875
|
-
},
|
|
876
|
-
async hdiffFromApp ({ args, options }) {
|
|
877
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiffFromApp');
|
|
878
|
-
await diffFromPackage(origin, next, realOutput, 'resources/rawfile/bundle.harmony.js');
|
|
879
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
880
|
-
output: realOutput
|
|
881
|
-
}));
|
|
882
|
-
},
|
|
883
|
-
async diffFromIpa ({ args, options }) {
|
|
884
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'diffFromIpa');
|
|
885
|
-
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v)=>{
|
|
886
|
-
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
887
|
-
return m == null ? void 0 : m[1];
|
|
888
|
-
});
|
|
889
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
890
|
-
output: realOutput
|
|
891
|
-
}));
|
|
892
|
-
},
|
|
893
|
-
async hdiffFromIpa ({ args, options }) {
|
|
894
|
-
const { origin, next, realOutput } = diffArgsCheck(args, options, 'hdiffFromIpa');
|
|
895
|
-
await diffFromPackage(origin, next, realOutput, 'main.jsbundle', (v)=>{
|
|
896
|
-
const m = /^Payload\/[^/]+\/(.+)$/.exec(v);
|
|
897
|
-
return m == null ? void 0 : m[1];
|
|
898
|
-
});
|
|
899
|
-
console.log((0, _i18n.t)('diffPackageGenerated', {
|
|
900
|
-
output: realOutput
|
|
901
|
-
}));
|
|
902
524
|
}
|
|
903
525
|
};
|