1
0
mirror of https://gitcode.com/github-mirrors/react-native-update-cli.git synced 2025-09-16 09:41:38 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Improve file filtering during bundle packing

# Conflicts:
#	package.json
#	src/bundle.js
This commit is contained in:
sunny.luo
2025-02-10 17:21:44 +08:00
parent d7da311c5e
commit f16aff5674
2 changed files with 51 additions and 45 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update-cli", "name": "react-native-update-cli",
"version": "1.39.1", "version": "1.39.2",
"description": "Command tools for javaScript updater with `pushy` service for react native apps.", "description": "Command tools for javaScript updater with `pushy` service for react native apps.",
"main": "index.js", "main": "index.js",
"bin": { "bin": {

View File

@@ -22,16 +22,20 @@ try {
hdiff = require('node-hdiffpatch').diff; hdiff = require('node-hdiffpatch').diff;
} catch (e) {} } catch (e) {}
async function runReactNativeBundleCommand( async function runReactNativeBundleCommand(
bundleName, bundleName: string,
development, development: string,
entryFile, entryFile: string,
outputFolder, outputFolder: string,
platform, platform: string,
sourcemapOutput, sourcemapOutput: string,
config, config: string,
) { ) {
let gradleConfig = {}; let gradleConfig: {
crunchPngs?: boolean;
enableHermes?: boolean;
} = {};
if (platform === 'android') { if (platform === 'android') {
gradleConfig = await checkGradleConfig(); gradleConfig = await checkGradleConfig();
if (gradleConfig.crunchPngs !== false) { if (gradleConfig.crunchPngs !== false) {
@@ -41,7 +45,7 @@ async function runReactNativeBundleCommand(
} }
} }
const reactNativeBundleArgs = []; const reactNativeBundleArgs: string[] = [];
const envArgs = process.env.PUSHY_ENV_ARGS; const envArgs = process.env.PUSHY_ENV_ARGS;
@@ -158,17 +162,17 @@ async function runReactNativeBundleCommand(
), ),
); );
} else { } else {
let hermesEnabled = false; let hermesEnabled: boolean | undefined = false;
if (platform === 'android') { if (platform === 'android') {
const gradlePropeties = await new Promise((resolve) => { const gradlePropeties = await new Promise<{ hermesEnabled?: boolean }>((resolve) => {
properties.parse( properties.parse(
'./android/gradle.properties', './android/gradle.properties',
{ path: true }, { path: true },
(error, props) => { (error: any, props: { hermesEnabled?: boolean }) => {
if (error) { if (error) {
console.error(error); console.error(error);
resolve(null); resolve({});
} }
resolve(props); resolve(props);
@@ -201,7 +205,7 @@ async function runReactNativeBundleCommand(
}); });
} }
async function copyHarmonyBundle(outputFolder) { async function copyHarmonyBundle(outputFolder: string) {
const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile'; const harmonyRawPath = 'harmony/entry/src/main/resources/rawfile';
try { try {
await fs.ensureDir(harmonyRawPath); await fs.ensureDir(harmonyRawPath);
@@ -215,7 +219,7 @@ async function copyHarmonyBundle(outputFolder) {
await fs.ensureDir(outputFolder); await fs.ensureDir(outputFolder);
await fs.copy(harmonyRawPath, outputFolder); await fs.copy(harmonyRawPath, outputFolder);
} catch (error) { } catch (error: any) {
console.error('copyHarmonyBundle 错误:', error); console.error('copyHarmonyBundle 错误:', error);
throw new Error(`复制文件失败: ${error.message}`); throw new Error(`复制文件失败: ${error.message}`);
} }
@@ -253,10 +257,10 @@ async function checkGradleConfig() {
} }
async function compileHermesByteCode( async function compileHermesByteCode(
bundleName, bundleName: string,
outputFolder, outputFolder: string,
sourcemapOutput, sourcemapOutput: string,
shouldCleanSourcemap, shouldCleanSourcemap: boolean,
) { ) {
console.log('Hermes enabled, now compiling to hermes bytecode:\n'); console.log('Hermes enabled, now compiling to hermes bytecode:\n');
// >= rn 0.69 // >= rn 0.69
@@ -318,7 +322,7 @@ async function compileHermesByteCode(
} }
} }
async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) { async function copyDebugidForSentry(bundleName: string, outputFolder: string, sourcemapOutput: string) {
if (sourcemapOutput) { if (sourcemapOutput) {
let copyDebugidPath; let copyDebugidPath;
try { try {
@@ -355,10 +359,10 @@ async function copyDebugidForSentry(bundleName, outputFolder, sourcemapOutput) {
} }
async function uploadSourcemapForSentry( async function uploadSourcemapForSentry(
bundleName, bundleName: string,
outputFolder, outputFolder: string,
sourcemapOutput, sourcemapOutput: string,
version, version: string,
) { ) {
if (sourcemapOutput) { if (sourcemapOutput) {
let sentryCliPath; let sentryCliPath;
@@ -405,19 +409,21 @@ async function uploadSourcemapForSentry(
} }
} }
async function pack(dir, output) { const ignorePackingFileNames = ['.', '..', 'index.bundlejs.map'];
const ignorePackingExtensions = ['DS_Store'];
async function pack(dir: string, output: string) {
console.log('Packing'); console.log('Packing');
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));
await new Promise((resolve, reject) => { await new Promise<void>((resolve, reject) => {
const zipfile = new ZipFile(); const zipfile = new ZipFile();
function addDirectory(root, rel) { function addDirectory(root: string, rel: string) {
if (rel) { if (rel) {
zipfile.addEmptyDirectory(rel); zipfile.addEmptyDirectory(rel);
} }
const childs = fs.readdirSync(root); const childs = fs.readdirSync(root);
for (const name of childs) { for (const name of childs) {
if (name === '.' || name === '..' || name === 'index.bundlejs.map' || name === 'index.bundlejs.txt.map') { if (ignorePackingFileNames.includes(name) || ignorePackingExtensions.some(ext => name.endsWith(`.${ext}`))) {
continue; continue;
} }
const fullPath = path.join(root, name); const fullPath = path.join(root, name);
@@ -434,7 +440,7 @@ async function pack(dir, output) {
addDirectory(dir, ''); addDirectory(dir, '');
zipfile.outputStream.on('error', (err) => reject(err)); zipfile.outputStream.on('error', (err: any) => reject(err));
zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => { zipfile.outputStream.pipe(fs.createWriteStream(output)).on('close', () => {
resolve(); resolve();
}); });
@@ -443,12 +449,12 @@ async function pack(dir, output) {
console.log(`ppk热更包已生成并保存到: ${output}`); console.log(`ppk热更包已生成并保存到: ${output}`);
} }
export function readEntire(entry, zipFile) { export function readEntire(entry: string, zipFile: ZipFile) {
const buffers = []; const buffers: Buffer[] = [];
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
zipFile.openReadStream(entry, (err, stream) => { zipFile.openReadStream(entry, (err: any, stream: any) => {
stream.pipe({ stream.pipe({
write(chunk) { write(chunk: Buffer) {
buffers.push(chunk); buffers.push(chunk);
}, },
end() { end() {
@@ -463,12 +469,12 @@ export function readEntire(entry, zipFile) {
}); });
} }
function basename(fn) { function basename(fn: string) {
const m = /^(.+\/)[^\/]+\/?$/.exec(fn); const m = /^(.+\/)[^\/]+\/?$/.exec(fn);
return m?.[1]; return m?.[1];
} }
async function diffFromPPK(origin, next, output) { async function diffFromPPK(origin: string, next: string, output: string) {
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));
const originEntries = {}; const originEntries = {};
@@ -513,7 +519,7 @@ async function diffFromPPK(origin, next, output) {
const addedEntry = {}; const addedEntry = {};
function addEntry(fn) { function addEntry(fn: string) {
//console.log(fn); //console.log(fn);
if (!fn || addedEntry[fn]) { if (!fn || addedEntry[fn]) {
return; return;
@@ -610,11 +616,11 @@ async function diffFromPPK(origin, next, output) {
} }
async function diffFromPackage( async function diffFromPackage(
origin, origin: string,
next, next: string,
output, output: string,
originBundleName, originBundleName: string,
transformPackagePath = (v) => v, transformPackagePath = (v: string) => v,
) { ) {
fs.ensureDirSync(path.dirname(output)); fs.ensureDirSync(path.dirname(output));
@@ -623,7 +629,7 @@ async function diffFromPackage(
let originSource; let originSource;
await enumZipEntries(origin, (entry, zipFile) => { await enumZipEntries(origin, (entry: any, zipFile: any) => {
if (!/\/$/.test(entry.fileName)) { if (!/\/$/.test(entry.fileName)) {
const fn = transformPackagePath(entry.fileName); const fn = transformPackagePath(entry.fileName);
if (!fn) { if (!fn) {
@@ -717,9 +723,9 @@ async function diffFromPackage(
await writePromise; await writePromise;
} }
export async function enumZipEntries(zipFn, callback, nestedPath = '') { export async function enumZipEntries(zipFn: string, callback: (entry: any, zipFile: any) => void, nestedPath = '') {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
openZipFile(zipFn, { lazyEntries: true }, async (err, zipfile) => { openZipFile(zipFn, { lazyEntries: true }, async (err: any, zipfile: ZipFile) => {
if (err) { if (err) {
return reject(err); return reject(err);
} }