@hot-updater/bare 0.31.4 → 0.33.0
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/dist/index.cjs +117 -7
- package/dist/index.mjs +111 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJSMin = (cb, mod) => () => (mod ||
|
|
9
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
10
10
|
var __copyProps = (to, from, except, desc) => {
|
|
11
11
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
12
|
key = keys[i];
|
|
@@ -22,23 +22,24 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
|
+
let crypto = require("crypto");
|
|
25
26
|
let fs_promises = require("fs/promises");
|
|
26
|
-
fs_promises = __toESM(fs_promises
|
|
27
|
+
fs_promises = __toESM(fs_promises);
|
|
27
28
|
let path = require("path");
|
|
28
|
-
path = __toESM(path
|
|
29
|
+
path = __toESM(path);
|
|
29
30
|
let _hot_updater_cli_tools = require("@hot-updater/cli-tools");
|
|
30
31
|
let node_url = require("node:url");
|
|
31
32
|
let node_child_process = require("node:child_process");
|
|
32
33
|
let node_string_decoder = require("node:string_decoder");
|
|
33
34
|
let node_util = require("node:util");
|
|
34
35
|
let node_process = require("node:process");
|
|
35
|
-
node_process = __toESM(node_process
|
|
36
|
+
node_process = __toESM(node_process);
|
|
36
37
|
let node_tty = require("node:tty");
|
|
37
|
-
node_tty = __toESM(node_tty
|
|
38
|
+
node_tty = __toESM(node_tty);
|
|
38
39
|
let node_path = require("node:path");
|
|
39
|
-
node_path = __toESM(node_path
|
|
40
|
+
node_path = __toESM(node_path);
|
|
40
41
|
let fs = require("fs");
|
|
41
|
-
fs = __toESM(fs
|
|
42
|
+
fs = __toESM(fs);
|
|
42
43
|
let node_timers_promises = require("node:timers/promises");
|
|
43
44
|
let node_os = require("node:os");
|
|
44
45
|
let node_events = require("node:events");
|
|
@@ -6317,12 +6318,111 @@ async function compileHermes({ cwd, sourcemap, inputJsFile }) {
|
|
|
6317
6318
|
}
|
|
6318
6319
|
//#endregion
|
|
6319
6320
|
//#region src/bare.ts
|
|
6321
|
+
const BARE_BUILD_CACHE_VERSION = 1;
|
|
6322
|
+
function hashText(value) {
|
|
6323
|
+
return (0, crypto.createHash)("sha256").update(value).digest("hex");
|
|
6324
|
+
}
|
|
6325
|
+
async function pathExists(filePath) {
|
|
6326
|
+
try {
|
|
6327
|
+
await fs_promises.default.access(filePath);
|
|
6328
|
+
return true;
|
|
6329
|
+
} catch {
|
|
6330
|
+
return false;
|
|
6331
|
+
}
|
|
6332
|
+
}
|
|
6333
|
+
function resolveCacheRoot(cwd) {
|
|
6334
|
+
const cacheDir = process.env.HOT_UPDATER_BARE_BUILD_CACHE_DIR?.trim();
|
|
6335
|
+
if (!cacheDir) return null;
|
|
6336
|
+
return path.default.resolve(cwd, cacheDir);
|
|
6337
|
+
}
|
|
6338
|
+
function resolveCacheKey({ enableHermes, entryFile, platform, resetCache, sourcemap }) {
|
|
6339
|
+
const inputKey = process.env.HOT_UPDATER_BARE_BUILD_CACHE_KEY?.trim();
|
|
6340
|
+
if (!inputKey) return null;
|
|
6341
|
+
return hashText(JSON.stringify({
|
|
6342
|
+
cacheVersion: BARE_BUILD_CACHE_VERSION,
|
|
6343
|
+
enableHermes,
|
|
6344
|
+
entryFile,
|
|
6345
|
+
inputKey,
|
|
6346
|
+
platform,
|
|
6347
|
+
resetCache,
|
|
6348
|
+
sourcemap
|
|
6349
|
+
}));
|
|
6350
|
+
}
|
|
6351
|
+
function resolveCachePaths({ cwd, enableHermes, entryFile, platform, resetCache, sourcemap }) {
|
|
6352
|
+
const root = resolveCacheRoot(cwd);
|
|
6353
|
+
const key = resolveCacheKey({
|
|
6354
|
+
enableHermes,
|
|
6355
|
+
entryFile,
|
|
6356
|
+
platform,
|
|
6357
|
+
resetCache,
|
|
6358
|
+
sourcemap
|
|
6359
|
+
});
|
|
6360
|
+
if (!root || !key) return null;
|
|
6361
|
+
const entryDir = path.default.join(root, key);
|
|
6362
|
+
return {
|
|
6363
|
+
entryDir,
|
|
6364
|
+
filesDir: path.default.join(entryDir, "files"),
|
|
6365
|
+
key,
|
|
6366
|
+
manifestPath: path.default.join(entryDir, "manifest.json"),
|
|
6367
|
+
root
|
|
6368
|
+
};
|
|
6369
|
+
}
|
|
6370
|
+
async function restoreBundleBuildFromCache({ buildPath, cachePaths }) {
|
|
6371
|
+
if (!await pathExists(cachePaths.manifestPath)) return null;
|
|
6372
|
+
try {
|
|
6373
|
+
const metadata = JSON.parse(await fs_promises.default.readFile(cachePaths.manifestPath, "utf8"));
|
|
6374
|
+
await fs_promises.default.cp(cachePaths.filesDir, buildPath, { recursive: true });
|
|
6375
|
+
_hot_updater_cli_tools.log.normal(`[bare] reused build cache ${cachePaths.key.slice(0, 12)}\n`);
|
|
6376
|
+
return { stdout: typeof metadata.stdout === "string" ? metadata.stdout : null };
|
|
6377
|
+
} catch {
|
|
6378
|
+
return null;
|
|
6379
|
+
}
|
|
6380
|
+
}
|
|
6381
|
+
async function saveBundleBuildToCache({ buildPath, cachePaths, stdout }) {
|
|
6382
|
+
if (await pathExists(cachePaths.manifestPath)) return;
|
|
6383
|
+
const tempDir = path.default.join(cachePaths.root, `${cachePaths.key}.${process.pid}.${Date.now()}.tmp`);
|
|
6384
|
+
await fs_promises.default.rm(tempDir, {
|
|
6385
|
+
recursive: true,
|
|
6386
|
+
force: true
|
|
6387
|
+
});
|
|
6388
|
+
await fs_promises.default.mkdir(path.default.dirname(tempDir), { recursive: true });
|
|
6389
|
+
await fs_promises.default.cp(buildPath, path.default.join(tempDir, "files"), { recursive: true });
|
|
6390
|
+
await fs_promises.default.writeFile(path.default.join(tempDir, "manifest.json"), `${JSON.stringify({
|
|
6391
|
+
cacheVersion: BARE_BUILD_CACHE_VERSION,
|
|
6392
|
+
stdout
|
|
6393
|
+
})}\n`);
|
|
6394
|
+
try {
|
|
6395
|
+
await fs_promises.default.rename(tempDir, cachePaths.entryDir);
|
|
6396
|
+
_hot_updater_cli_tools.log.normal(`[bare] saved build cache ${cachePaths.key.slice(0, 12)}\n`);
|
|
6397
|
+
} catch {
|
|
6398
|
+
await fs_promises.default.rm(tempDir, {
|
|
6399
|
+
recursive: true,
|
|
6400
|
+
force: true
|
|
6401
|
+
});
|
|
6402
|
+
}
|
|
6403
|
+
}
|
|
6320
6404
|
const runBundle = async ({ entryFile, cwd, platform, buildPath, sourcemap, enableHermes, resetCache }) => {
|
|
6321
6405
|
const reactNativePath = require.resolve("react-native/package.json", { paths: [cwd] });
|
|
6322
6406
|
const cliPath = path.default.join(path.default.dirname(reactNativePath), "cli.js");
|
|
6323
6407
|
const filename = `index.${platform}`;
|
|
6324
6408
|
const bundleOutput = path.default.join(buildPath, `${filename}.bundle`);
|
|
6325
6409
|
const bundleId = (0, uuidv7.uuidv7)();
|
|
6410
|
+
const cachePaths = resolveCachePaths({
|
|
6411
|
+
cwd,
|
|
6412
|
+
enableHermes,
|
|
6413
|
+
entryFile,
|
|
6414
|
+
platform,
|
|
6415
|
+
resetCache,
|
|
6416
|
+
sourcemap
|
|
6417
|
+
});
|
|
6418
|
+
const cached = cachePaths ? await restoreBundleBuildFromCache({
|
|
6419
|
+
buildPath,
|
|
6420
|
+
cachePaths
|
|
6421
|
+
}) : null;
|
|
6422
|
+
if (cached) return {
|
|
6423
|
+
bundleId,
|
|
6424
|
+
stdout: cached.stdout
|
|
6425
|
+
};
|
|
6326
6426
|
const args = [
|
|
6327
6427
|
"bundle",
|
|
6328
6428
|
"--assets-dest",
|
|
@@ -6355,11 +6455,21 @@ const runBundle = async ({ entryFile, cwd, platform, buildPath, sourcemap, enabl
|
|
|
6355
6455
|
inputJsFile: bundleOutput,
|
|
6356
6456
|
sourcemap
|
|
6357
6457
|
});
|
|
6458
|
+
if (cachePaths) await saveBundleBuildToCache({
|
|
6459
|
+
buildPath,
|
|
6460
|
+
cachePaths,
|
|
6461
|
+
stdout: hermesVersion
|
|
6462
|
+
});
|
|
6358
6463
|
return {
|
|
6359
6464
|
bundleId,
|
|
6360
6465
|
stdout: hermesVersion
|
|
6361
6466
|
};
|
|
6362
6467
|
}
|
|
6468
|
+
if (cachePaths) await saveBundleBuildToCache({
|
|
6469
|
+
buildPath,
|
|
6470
|
+
cachePaths,
|
|
6471
|
+
stdout: null
|
|
6472
|
+
});
|
|
6363
6473
|
return {
|
|
6364
6474
|
bundleId,
|
|
6365
6475
|
stdout: null
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { createHash } from "crypto";
|
|
2
3
|
import fs from "fs/promises";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { getReactNativeMetadatas, log } from "@hot-updater/cli-tools";
|
|
@@ -26,7 +27,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
26
27
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
27
28
|
var __getProtoOf = Object.getPrototypeOf;
|
|
28
29
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
29
|
-
var __commonJSMin = (cb, mod) => () => (mod ||
|
|
30
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
30
31
|
var __copyProps = (to, from, except, desc) => {
|
|
31
32
|
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
32
33
|
key = keys[i];
|
|
@@ -6312,12 +6313,111 @@ async function compileHermes({ cwd, sourcemap, inputJsFile }) {
|
|
|
6312
6313
|
}
|
|
6313
6314
|
//#endregion
|
|
6314
6315
|
//#region src/bare.ts
|
|
6316
|
+
const BARE_BUILD_CACHE_VERSION = 1;
|
|
6317
|
+
function hashText(value) {
|
|
6318
|
+
return createHash("sha256").update(value).digest("hex");
|
|
6319
|
+
}
|
|
6320
|
+
async function pathExists(filePath) {
|
|
6321
|
+
try {
|
|
6322
|
+
await fs.access(filePath);
|
|
6323
|
+
return true;
|
|
6324
|
+
} catch {
|
|
6325
|
+
return false;
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6328
|
+
function resolveCacheRoot(cwd) {
|
|
6329
|
+
const cacheDir = process.env.HOT_UPDATER_BARE_BUILD_CACHE_DIR?.trim();
|
|
6330
|
+
if (!cacheDir) return null;
|
|
6331
|
+
return path.resolve(cwd, cacheDir);
|
|
6332
|
+
}
|
|
6333
|
+
function resolveCacheKey({ enableHermes, entryFile, platform, resetCache, sourcemap }) {
|
|
6334
|
+
const inputKey = process.env.HOT_UPDATER_BARE_BUILD_CACHE_KEY?.trim();
|
|
6335
|
+
if (!inputKey) return null;
|
|
6336
|
+
return hashText(JSON.stringify({
|
|
6337
|
+
cacheVersion: BARE_BUILD_CACHE_VERSION,
|
|
6338
|
+
enableHermes,
|
|
6339
|
+
entryFile,
|
|
6340
|
+
inputKey,
|
|
6341
|
+
platform,
|
|
6342
|
+
resetCache,
|
|
6343
|
+
sourcemap
|
|
6344
|
+
}));
|
|
6345
|
+
}
|
|
6346
|
+
function resolveCachePaths({ cwd, enableHermes, entryFile, platform, resetCache, sourcemap }) {
|
|
6347
|
+
const root = resolveCacheRoot(cwd);
|
|
6348
|
+
const key = resolveCacheKey({
|
|
6349
|
+
enableHermes,
|
|
6350
|
+
entryFile,
|
|
6351
|
+
platform,
|
|
6352
|
+
resetCache,
|
|
6353
|
+
sourcemap
|
|
6354
|
+
});
|
|
6355
|
+
if (!root || !key) return null;
|
|
6356
|
+
const entryDir = path.join(root, key);
|
|
6357
|
+
return {
|
|
6358
|
+
entryDir,
|
|
6359
|
+
filesDir: path.join(entryDir, "files"),
|
|
6360
|
+
key,
|
|
6361
|
+
manifestPath: path.join(entryDir, "manifest.json"),
|
|
6362
|
+
root
|
|
6363
|
+
};
|
|
6364
|
+
}
|
|
6365
|
+
async function restoreBundleBuildFromCache({ buildPath, cachePaths }) {
|
|
6366
|
+
if (!await pathExists(cachePaths.manifestPath)) return null;
|
|
6367
|
+
try {
|
|
6368
|
+
const metadata = JSON.parse(await fs.readFile(cachePaths.manifestPath, "utf8"));
|
|
6369
|
+
await fs.cp(cachePaths.filesDir, buildPath, { recursive: true });
|
|
6370
|
+
log.normal(`[bare] reused build cache ${cachePaths.key.slice(0, 12)}\n`);
|
|
6371
|
+
return { stdout: typeof metadata.stdout === "string" ? metadata.stdout : null };
|
|
6372
|
+
} catch {
|
|
6373
|
+
return null;
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
async function saveBundleBuildToCache({ buildPath, cachePaths, stdout }) {
|
|
6377
|
+
if (await pathExists(cachePaths.manifestPath)) return;
|
|
6378
|
+
const tempDir = path.join(cachePaths.root, `${cachePaths.key}.${process.pid}.${Date.now()}.tmp`);
|
|
6379
|
+
await fs.rm(tempDir, {
|
|
6380
|
+
recursive: true,
|
|
6381
|
+
force: true
|
|
6382
|
+
});
|
|
6383
|
+
await fs.mkdir(path.dirname(tempDir), { recursive: true });
|
|
6384
|
+
await fs.cp(buildPath, path.join(tempDir, "files"), { recursive: true });
|
|
6385
|
+
await fs.writeFile(path.join(tempDir, "manifest.json"), `${JSON.stringify({
|
|
6386
|
+
cacheVersion: BARE_BUILD_CACHE_VERSION,
|
|
6387
|
+
stdout
|
|
6388
|
+
})}\n`);
|
|
6389
|
+
try {
|
|
6390
|
+
await fs.rename(tempDir, cachePaths.entryDir);
|
|
6391
|
+
log.normal(`[bare] saved build cache ${cachePaths.key.slice(0, 12)}\n`);
|
|
6392
|
+
} catch {
|
|
6393
|
+
await fs.rm(tempDir, {
|
|
6394
|
+
recursive: true,
|
|
6395
|
+
force: true
|
|
6396
|
+
});
|
|
6397
|
+
}
|
|
6398
|
+
}
|
|
6315
6399
|
const runBundle = async ({ entryFile, cwd, platform, buildPath, sourcemap, enableHermes, resetCache }) => {
|
|
6316
6400
|
const reactNativePath = __require.resolve("react-native/package.json", { paths: [cwd] });
|
|
6317
6401
|
const cliPath = path.join(path.dirname(reactNativePath), "cli.js");
|
|
6318
6402
|
const filename = `index.${platform}`;
|
|
6319
6403
|
const bundleOutput = path.join(buildPath, `${filename}.bundle`);
|
|
6320
6404
|
const bundleId = uuidv7();
|
|
6405
|
+
const cachePaths = resolveCachePaths({
|
|
6406
|
+
cwd,
|
|
6407
|
+
enableHermes,
|
|
6408
|
+
entryFile,
|
|
6409
|
+
platform,
|
|
6410
|
+
resetCache,
|
|
6411
|
+
sourcemap
|
|
6412
|
+
});
|
|
6413
|
+
const cached = cachePaths ? await restoreBundleBuildFromCache({
|
|
6414
|
+
buildPath,
|
|
6415
|
+
cachePaths
|
|
6416
|
+
}) : null;
|
|
6417
|
+
if (cached) return {
|
|
6418
|
+
bundleId,
|
|
6419
|
+
stdout: cached.stdout
|
|
6420
|
+
};
|
|
6321
6421
|
const args = [
|
|
6322
6422
|
"bundle",
|
|
6323
6423
|
"--assets-dest",
|
|
@@ -6350,11 +6450,21 @@ const runBundle = async ({ entryFile, cwd, platform, buildPath, sourcemap, enabl
|
|
|
6350
6450
|
inputJsFile: bundleOutput,
|
|
6351
6451
|
sourcemap
|
|
6352
6452
|
});
|
|
6453
|
+
if (cachePaths) await saveBundleBuildToCache({
|
|
6454
|
+
buildPath,
|
|
6455
|
+
cachePaths,
|
|
6456
|
+
stdout: hermesVersion
|
|
6457
|
+
});
|
|
6353
6458
|
return {
|
|
6354
6459
|
bundleId,
|
|
6355
6460
|
stdout: hermesVersion
|
|
6356
6461
|
};
|
|
6357
6462
|
}
|
|
6463
|
+
if (cachePaths) await saveBundleBuildToCache({
|
|
6464
|
+
buildPath,
|
|
6465
|
+
cachePaths,
|
|
6466
|
+
stdout: null
|
|
6467
|
+
});
|
|
6358
6468
|
return {
|
|
6359
6469
|
bundleId,
|
|
6360
6470
|
stdout: null
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/bare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"uuidv7": "^1.0.2",
|
|
25
|
-
"@hot-updater/cli-tools": "0.
|
|
26
|
-
"@hot-updater/plugin-core": "0.
|
|
25
|
+
"@hot-updater/cli-tools": "0.33.0",
|
|
26
|
+
"@hot-updater/plugin-core": "0.33.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^20",
|