|
1 | 1 | import fs from "fs"; |
2 | 2 | import path from "path"; |
3 | | -import yauzl from "yauzl"; |
4 | 3 | import { bundleCodePush } from "../bundleCommand/bundleCodePush.js"; |
5 | 4 | import { addToReleaseHistory } from "./addToReleaseHistory.js"; |
6 | 5 | import type { CliConfigInterface } from "../../../typings/react-native-code-push.d.ts"; |
7 | 6 | import { generatePackageHashFromDirectory } from "../../utils/hash-utils.js"; |
| 7 | +import { unzip } from "../../utils/unzip.js"; |
8 | 8 |
|
9 | 9 | export async function release( |
10 | 10 | bundleUploader: CliConfigInterface['bundleUploader'], |
@@ -81,41 +81,21 @@ function readBundleFileNameFrom(bundleDirectory: string): string { |
81 | 81 | return path.basename(bundleFilePath); |
82 | 82 | } |
83 | 83 |
|
84 | | -function calcHashFromBundleFile(bundleFilePath: string): Promise<string> { |
| 84 | +async function calcHashFromBundleFile(bundleFilePath: string): Promise<string> { |
85 | 85 | const tempDir = path.join(path.dirname(bundleFilePath), 'temp_contents_for_hash_calc'); |
86 | | - console.log('🔥 🔥 🔥 tempDir', tempDir); |
87 | | - fs.mkdirSync(tempDir); |
| 86 | + const zipFilePath = path.resolve(bundleFilePath); |
88 | 87 |
|
89 | | - // unzip |
90 | | - yauzl.open(bundleFilePath, { lazyEntries: true }, (err, zipFile) => { |
91 | | - if (err) throw err; |
92 | | - zipFile.readEntry(); |
93 | | - zipFile.on("entry", (entry) => { |
94 | | - if (/\/$/.test(entry.fileName)) { |
95 | | - // Directory file names end with '/'. |
96 | | - // Note that entries for directories themselves are optional. |
97 | | - // An entry's fileName implicitly requires its parent directories to exist. |
98 | | - zipFile.readEntry(); |
99 | | - } else { |
100 | | - // file entry |
101 | | - zipFile.openReadStream(entry, (err, readStream) => { |
102 | | - if (err) throw err; |
103 | | - readStream.on("end", () => { |
104 | | - zipFile.readEntry(); |
105 | | - }); |
106 | | - readStream.pipe(fs.createWriteStream(tempDir)); |
107 | | - }); |
108 | | - } |
109 | | - }); |
110 | | - }); |
111 | | - |
112 | | - // calc hash |
113 | | - const hash = generatePackageHashFromDirectory(tempDir, path.join(tempDir, '..')); |
114 | | - |
115 | | - // cleanup |
116 | | - fs.rmSync(tempDir, { recursive: true }); |
117 | | - |
118 | | - console.log('🔥 🔥 🔥 hash', hash); |
| 88 | + if (fs.existsSync(tempDir)) { |
| 89 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 90 | + } |
| 91 | + fs.mkdirSync(tempDir, { recursive: true }); |
119 | 92 |
|
120 | | - return hash; |
| 93 | + try { |
| 94 | + await unzip(zipFilePath, tempDir); |
| 95 | + const hash = await generatePackageHashFromDirectory(tempDir, tempDir); |
| 96 | + console.log(`log: Calculated package hash from existing bundle file: ${hash}`); |
| 97 | + return hash; |
| 98 | + } finally { |
| 99 | + fs.rmSync(tempDir, { recursive: true, force: true }); |
| 100 | + } |
121 | 101 | } |
0 commit comments