1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-11-22 23:46:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

...

11 Commits

12 changed files with 113 additions and 168 deletions

View File

@@ -7,7 +7,7 @@
"@react-native-oh/react-native-harmony": "^0.72.59",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-update": "^10.35.0",
"react-native-update": "^10.35.4",
},
"devDependencies": {
"@babel/core": "^7.20.0",
@@ -1399,7 +1399,7 @@
"react-native": ["react-native@0.72.5", "", { "dependencies": { "@jest/create-cache-key-function": "^29.2.1", "@react-native-community/cli": "11.3.7", "@react-native-community/cli-platform-android": "11.3.7", "@react-native-community/cli-platform-ios": "11.3.7", "@react-native/assets-registry": "^0.72.0", "@react-native/codegen": "^0.72.7", "@react-native/gradle-plugin": "^0.72.11", "@react-native/js-polyfills": "^0.72.1", "@react-native/normalize-colors": "^0.72.0", "@react-native/virtualized-lists": "^0.72.8", "abort-controller": "^3.0.0", "anser": "^1.4.9", "base64-js": "^1.1.2", "deprecated-react-native-prop-types": "4.1.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.5", "invariant": "^2.2.4", "jest-environment-node": "^29.2.1", "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", "metro-runtime": "0.76.8", "metro-source-map": "0.76.8", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", "pretty-format": "^26.5.2", "promise": "^8.3.0", "react-devtools-core": "^4.27.2", "react-refresh": "^0.4.0", "react-shallow-renderer": "^16.15.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.24.0-canary-efb381bbf-20230505", "stacktrace-parser": "^0.1.10", "use-sync-external-store": "^1.0.0", "whatwg-fetch": "^3.0.0", "ws": "^6.2.2", "yargs": "^17.6.2" }, "peerDependencies": { "react": "18.2.0" }, "bin": { "react-native": "cli.js" } }, "sha512-oIewslu5DBwOmo7x5rdzZlZXCqDIna0R4dUwVpfmVteORYLr4yaZo5wQnMeR+H7x54GaMhmgeqp0ZpULtulJFg=="],
"react-native-update": ["react-native-update@10.35.0", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-jTFtTAmOec05Gf06ununz+bLFkLC7bu7GV2y5/VjEx3XDhk+/ohvpefIFYuaDub23+0Tbq85aIg9WlDa72tReQ=="],
"react-native-update": ["react-native-update@10.35.4", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-daSbe0EtQhihy+ldHaivmBdAUQ0WjQgS8t++icMcxOsS5vD5F5IdLusrb5LVFLmCLZQ7Z81e5CwbKUSn5o087A=="],
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],

View File

@@ -1,44 +1,9 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import fs from 'fs';
import path from 'path';
export function generatePushyBuildTime(str?: string) {
return {
pluginId: 'PushyBuildTimePlugin',
apply(pluginContext) {
pluginContext.registerTask({
name: 'pushy_build_time',
run: (taskContext) => {
const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json');
const dirPath = path.dirname(metaFilePath);
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
const moduleJsonPath = path.resolve(__dirname, '../AppScope/app.json5');
let versionName = '';
if (fs.existsSync(moduleJsonPath)) {
const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8');
const versionMatch = moduleContent.match(/"versionName":\s*"([^"]+)"/);
if (versionMatch && versionMatch[1]) {
versionName = versionMatch[1];
}
}
const buildTime = new Date().toISOString();
const metaContent = {
pushy_build_time: buildTime,
versionName: versionName
};
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
console.log(`Build time written to ${metaFilePath}`);
},
dependencies: [],
postDependencies: ['default@BuildJS']
})
}
}
}
import {hapTasks} from '@ohos/hvigor-ohos-plugin';
import {reactNativeUpdatePlugin} from 'pushy/hvigor-plugin';
export default {
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
}
system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
plugins: [
reactNativeUpdatePlugin(),
] /* Custom plugin to extend the functionality of Hvigor. */,
};

View File

@@ -6,15 +6,15 @@
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
"@rnoh/react-native-openharmony@0.72.96": "@rnoh/react-native-openharmony@0.72.96",
"pushy@../../node_modules/react-native-update/harmony/pushy": "pushy@../../node_modules/react-native-update/harmony/pushy"
},
"packages": {
"@rnoh/react-native-openharmony@0.72.38": {
"@rnoh/react-native-openharmony@0.72.96": {
"name": "",
"version": "0.72.38",
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
"version": "0.72.96",
"integrity": "sha512-gBbm8LLyqi5UE7qHWdZYeQnjyncfEpCczKZUP/9M2U1Z7exR0Kya8PMKMwr1ta5ujy7w/hZVC2LomEV4QvBeqA==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.96.har",
"registryType": "ohpm"
},
"pushy@../../node_modules/react-native-update/harmony/pushy": {

View File

@@ -1,6 +1,7 @@
{
"modelVersion": "5.0.0",
"dependencies": {
pushy: 'file:../../node_modules/react-native-update/harmony/pushy'
},
"execution": {
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */

View File

@@ -8,7 +8,7 @@
"lint": "eslint .",
"start": "npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start",
"codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/react_native_openharmony",
"build": "pushy bundle --platform harmony",
"build": "pushy bundle --platform harmony --no-interactive",
"test": "jest",
"hdiffFromPPK": "pushy hdiffFromPPK .pushy/output/harmony.1735052610653.ppk .pushy/output/harmony.1735052678646.ppk .pushy/output/hdiff.ppk-patch",
"hdiffFromApp": "pushy hdiffFromApp .pushy/output/version-1.0.0.app .pushy/output/harmony.1735052610653.ppk .pushy/output/hdiff.app-patch",
@@ -18,7 +18,7 @@
"@react-native-oh/react-native-harmony": "^0.72.59",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-update": "^10.35.0"
"react-native-update": "^10.35.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
@@ -40,4 +40,4 @@
"engines": {
"node": ">=16"
}
}
}

View File

@@ -273,6 +273,7 @@ public class UpdateContext {
if (lastVersion == null) {
editor.remove("currentVersion");
} else {
editor.remove("lastVersion");
editor.putString("currentVersion", lastVersion);
}
editor.putBoolean("firstTimeOk", true);

View File

@@ -0,0 +1,39 @@
import fs from 'fs';
import path from 'path';
export function reactNativeUpdatePlugin() {
return {
pluginId: 'reactNativeUpdatePlugin',
apply(node) {
node.registerTask({
name: 'reactNativeUpdatePlugin',
run: () => {
const cwd = process.cwd();
const metaFilePath = path.resolve(
cwd,
'entry/src/main/resources/rawfile/meta.json',
);
fs.mkdirSync(path.dirname(metaFilePath), { recursive: true });
const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5');
let versionName = '';
if (fs.existsSync(moduleJsonPath)) {
const content = fs.readFileSync(moduleJsonPath, 'utf-8');
const match = content.match(
/(?:"versionName"|versionName):\s*["']([^"']+)["']/,
);
versionName = match?.[1] || '';
}
const metaContent = {
pushy_build_time: new Date().toISOString(),
versionName,
};
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 2));
console.log(`Build time written to ${metaFilePath}`);
},
});
},
};
}

View File

@@ -1,10 +1,7 @@
import http from '@ohos.net.http';
import fileIo from '@ohos.file.fs';
import util from '@ohos.util';
import common from '@ohos.app.ability.common';
import { BusinessError } from '@kit.BasicServicesKit';
import { buffer } from '@kit.ArkTS';
import zip from '@ohos.zlib';
import { zlib } from '@kit.BasicServicesKit';
import { EventHub } from './EventHub';
import { DownloadTaskParams } from './DownloadTaskParams';
import Pushy from 'librnupdate.so';
@@ -37,7 +34,9 @@ export class DownloadTask {
if (stat.isDirectory()) {
const files = await fileIo.listFile(path);
for (const file of files) {
if (file === '.' || file === '..') continue;
if (file === '.' || file === '..') {
continue;
}
await this.removeDirectory(`${path}/${file}`);
}
await fileIo.rmdir(path);
@@ -128,64 +127,12 @@ export class DownloadTask {
});
}
private async copyFile(from: string, to: string): Promise<void> {
let reader;
let writer;
try {
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
writer = fileIo.openSync(
to,
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
);
const arrayBuffer = new ArrayBuffer(4096);
let bytesRead: number;
do {
bytesRead = await fileIo
.read(reader.fd, arrayBuffer)
.catch((err: BusinessError) => {
throw Error(
`Error reading file: ${err.message}, code: ${err.code}`,
);
});
if (bytesRead > 0) {
const buf = buffer.from(arrayBuffer, 0, bytesRead);
await fileIo
.write(writer.fd, buf.buffer, {
offset: 0,
length: bytesRead,
})
.catch((err: BusinessError) => {
throw Error(
`Error writing file: ${err.message}, code: ${err.code}`,
);
});
}
} while (bytesRead > 0);
console.info('File copied successfully');
} catch (error) {
console.error('Copy file failed:', error);
throw error;
} finally {
if (reader !== undefined) {
fileIo.closeSync(reader);
}
if (writer !== undefined) {
fileIo.closeSync(writer);
}
}
}
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
await this.downloadFile(params);
await this.removeDirectory(params.unzipDirectory);
await fileIo.mkdir(params.unzipDirectory);
try {
await zip.decompressFile(params.targetFile, params.unzipDirectory);
} catch (error) {
console.error('Unzip failed:', error);
throw error;
}
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
}
private async processUnzippedFiles(directory: string): Promise<ZipFile> {
@@ -193,7 +140,9 @@ export class DownloadTask {
try {
const files = await fileIo.listFile(directory);
for (const file of files) {
if (file === '.' || file === '..') continue;
if (file === '.' || file === '..') {
continue;
}
const filePath = `${directory}/${file}`;
const stat = await fileIo.stat(filePath);
@@ -230,7 +179,7 @@ export class DownloadTask {
let foundDiff = false;
let foundBundlePatch = false;
const copyList: Map<string, Array<any>> = new Map();
await zip.decompressFile(params.targetFile, params.unzipDirectory);
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
for (const entry of zipFile.entries) {
const fn = entry.filename;
@@ -246,7 +195,7 @@ export class DownloadTask {
const copies = obj.copies;
for (const to in copies) {
let from = copies[to];
let from = copies[to].replace('resources/rawfile/', '');
if (from === '') {
from = to;
}
@@ -295,10 +244,6 @@ export class DownloadTask {
throw error;
}
}
if (fn !== '.DS_Store') {
await zip.decompressFile(fn, params.unzipDirectory);
}
}
if (!foundDiff) {
@@ -317,14 +262,20 @@ export class DownloadTask {
let foundDiff = false;
let foundBundlePatch = false;
const copyList: Map<string, Array<any>> = new Map();
await zip.decompressFile(params.targetFile, params.unzipDirectory);
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
for (const entry of zipFile.entries) {
const fn = entry.filename;
if (fn === '__diff.json') {
foundDiff = true;
await fileIo
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
.catch(error => {
console.error('copy error:', error);
});
let jsonContent = '';
const bufferArray = new Uint8Array(entry.content);
for (let i = 0; i < bufferArray.length; i++) {
@@ -332,22 +283,23 @@ export class DownloadTask {
}
const obj = JSON.parse(jsonContent);
const copies = obj.copies;
for (const to in copies) {
let from = copies[to];
if (from === '') {
from = to;
}
if (!copyList.has(from)) {
copyList.set(from, []);
}
const target = copyList.get(from);
if (target) {
const toFile = `${params.unzipDirectory}/${to}`;
target.push(toFile);
}
const { copies, deletes } = obj;
for (const [to, from] of Object.entries(copies)) {
await fileIo
.copyFile(
`${params.originDirectory}/${from}`,
`${params.unzipDirectory}/${to}`,
)
.catch(error => {
console.error('copy error:', error);
});
}
for (const fileToDelete of Object.keys(deletes)) {
await fileIo
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
.catch(error => {
console.error('delete error:', error);
});
}
continue;
}
@@ -389,8 +341,6 @@ export class DownloadTask {
}
}
}
await zip.decompressFile(entry.filename, params.unzipDirectory);
}
if (!foundDiff) {
@@ -406,27 +356,14 @@ export class DownloadTask {
copyList: Map<string, Array<string>>,
): Promise<void> {
try {
const bundlePath = this.context.bundleCodeDir;
const resourceManager = this.context.resourceManager;
const files = await fileIo.listFile(bundlePath);
for (const file of files) {
if (file === '.' || file === '..') continue;
const targets = copyList.get(file);
if (targets) {
let lastTarget: string | undefined;
for (const target of targets) {
console.info(`Copying from resource ${file} to ${target}`);
if (lastTarget) {
await this.copyFile(lastTarget, target);
} else {
const sourcePath = `${bundlePath}/${file}`;
await this.copyFile(sourcePath, target);
lastTarget = target;
}
}
for (const [from, targets] of copyList.entries()) {
const fromContent = await resourceManager.getRawFileContent(from);
for (const target of targets) {
const fileStream = fileIo.createStreamSync(target, 'w+');
fileStream.writeSync(fromContent.buffer);
fileStream.close();
}
}
} catch (error) {
@@ -443,7 +380,9 @@ export class DownloadTask {
try {
const files = await fileIo.listFile(params.unzipDirectory);
for (const file of files) {
if (file.startsWith('.')) continue;
if (file.startsWith('.')) {
continue;
}
const filePath = `${params.unzipDirectory}/${file}`;
const stat = await fileIo.stat(filePath);

View File

@@ -26,14 +26,13 @@ export class PushyFileJSBundleProvider extends JSBundleProvider {
if (!this.path) {
throw new JSBundleProviderError({
whatHappened: 'No pushy bundle found. using default bundle',
howCanItBeFixed: ['']
})
}
try {
const status = await fs.access(this.path, fs.OpenMode.READ_ONLY);
if (status) {
return {
filePath: this.path
}
await fs.access(this.path, fs.OpenMode.READ_ONLY);
return {
filePath: this.path
}
} catch (error) {
throw new JSBundleProviderError({

View File

@@ -245,6 +245,7 @@ export class UpdateContext {
if (!lastVersion) {
this.preferences.deleteSync('currentVersion');
} else {
this.preferences.deleteSync('lastVersion');
this.preferences.putSync('currentVersion', lastVersion);
}
this.preferences.putSync('firstTimeOk', true);

View File

@@ -78,7 +78,7 @@ RCT_EXPORT_MODULE(RCTPushy);
NSString *storedBuildTime = [defaults stringForKey:paramBuildTime];
// If stored versions don't exist, write current versions first
if (!storedPackageVersion || !storedBuildTime) {
if (!storedPackageVersion && !storedBuildTime) {
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
[defaults setObject:curBuildTime forKey:paramBuildTime];
storedPackageVersion = curPackageVersion;
@@ -86,7 +86,7 @@ RCT_EXPORT_MODULE(RCTPushy);
}
BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion];
BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime];
BOOL buildTimeChanged = curBuildTime && ![curBuildTime isEqualToString:storedBuildTime];
if (packageVersionChanged || buildTimeChanged) {
// Clear all update data and store new versions
@@ -304,8 +304,8 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options
if (hash.length) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *lastVersion = nil;
if ([defaults objectForKey:keyPushyInfo]) {
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo];
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo]
if (pushyInfo) {
lastVersion = pushyInfo[paramCurrentVersion];
}

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.35.1",
"version": "10.35.5",
"description": "react-native hot update",
"main": "src/index",
"scripts": {