hot-updater 0.18.4 → 0.19.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.
@@ -0,0 +1,39 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
+ key = keys[i];
14
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
+ value: mod,
23
+ enumerable: true
24
+ }) : target, mod));
25
+
26
+ //#endregion
27
+
28
+ Object.defineProperty(exports, '__commonJS', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return __commonJS;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, '__toESM', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return __toESM;
38
+ }
39
+ });
package/dist/config.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ const require_fingerprint = require('./fingerprint-w8QPkdqq.cjs');
1
2
 
2
3
  //#region src/config.ts
3
4
  const defineConfig = (config) => {
@@ -5,4 +6,8 @@ const defineConfig = (config) => {
5
6
  };
6
7
 
7
8
  //#endregion
8
- exports.defineConfig = defineConfig;
9
+ exports.createFingerprintJson = require_fingerprint.createFingerprintJson;
10
+ exports.defineConfig = defineConfig;
11
+ exports.generateFingerprint = require_fingerprint.generateFingerprint;
12
+ exports.generateFingerprints = require_fingerprint.generateFingerprints;
13
+ exports.readLocalFingerprint = require_fingerprint.readLocalFingerprint;
package/dist/config.d.cts CHANGED
@@ -1,6 +1,31 @@
1
1
  import { ConfigInput, HotUpdaterConfigOptions } from "@hot-updater/plugin-core";
2
+ import { FingerprintSource } from "@expo/fingerprint";
2
3
 
4
+ //#region src/utils/fingerprint/index.d.ts
5
+
6
+ type FingerprintResult = {
7
+ hash: string;
8
+ sources: FingerprintSource[];
9
+ };
10
+ /**
11
+ * Calculates the fingerprint of the native parts project of the project.
12
+ */
13
+
14
+ declare const generateFingerprints: () => Promise<{
15
+ ios: FingerprintResult;
16
+ android: FingerprintResult;
17
+ }>;
18
+ declare const generateFingerprint: (platform: "ios" | "android") => Promise<FingerprintResult>;
19
+ declare const createFingerprintJson: () => Promise<{
20
+ ios: FingerprintResult;
21
+ android: FingerprintResult;
22
+ }>;
23
+ declare const readLocalFingerprint: () => Promise<{
24
+ ios: FingerprintResult | null;
25
+ android: FingerprintResult | null;
26
+ } | null>;
27
+ //#endregion
3
28
  //#region src/config.d.ts
4
29
  declare const defineConfig: (config: ConfigInput | ((options: HotUpdaterConfigOptions) => ConfigInput)) => ConfigInput | ((options: HotUpdaterConfigOptions) => ConfigInput);
5
30
  //#endregion
6
- export { defineConfig };
31
+ export { createFingerprintJson, defineConfig, generateFingerprint, generateFingerprints, readLocalFingerprint };
package/dist/config.d.ts CHANGED
@@ -1,6 +1,31 @@
1
1
  import { ConfigInput, HotUpdaterConfigOptions } from "@hot-updater/plugin-core";
2
+ import { FingerprintSource } from "@expo/fingerprint";
2
3
 
4
+ //#region src/utils/fingerprint/index.d.ts
5
+
6
+ type FingerprintResult = {
7
+ hash: string;
8
+ sources: FingerprintSource[];
9
+ };
10
+ /**
11
+ * Calculates the fingerprint of the native parts project of the project.
12
+ */
13
+
14
+ declare const generateFingerprints: () => Promise<{
15
+ ios: FingerprintResult;
16
+ android: FingerprintResult;
17
+ }>;
18
+ declare const generateFingerprint: (platform: "ios" | "android") => Promise<FingerprintResult>;
19
+ declare const createFingerprintJson: () => Promise<{
20
+ ios: FingerprintResult;
21
+ android: FingerprintResult;
22
+ }>;
23
+ declare const readLocalFingerprint: () => Promise<{
24
+ ios: FingerprintResult | null;
25
+ android: FingerprintResult | null;
26
+ } | null>;
27
+ //#endregion
3
28
  //#region src/config.d.ts
4
29
  declare const defineConfig: (config: ConfigInput | ((options: HotUpdaterConfigOptions) => ConfigInput)) => ConfigInput | ((options: HotUpdaterConfigOptions) => ConfigInput);
5
30
  //#endregion
6
- export { defineConfig };
31
+ export { createFingerprintJson, defineConfig, generateFingerprint, generateFingerprints, readLocalFingerprint };
package/dist/config.js CHANGED
@@ -1,7 +1,9 @@
1
+ import { createFingerprintJson, generateFingerprint, generateFingerprints, readLocalFingerprint } from "./fingerprint-m6lqnvbJ.js";
2
+
1
3
  //#region src/config.ts
2
4
  const defineConfig = (config) => {
3
5
  return config;
4
6
  };
5
7
 
6
8
  //#endregion
7
- export { defineConfig };
9
+ export { createFingerprintJson, defineConfig, generateFingerprint, generateFingerprints, readLocalFingerprint };
@@ -0,0 +1,119 @@
1
+ import { getCwd, loadConfig } from "@hot-updater/plugin-core";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import * as p from "@clack/prompts";
5
+ import { createFingerprintAsync } from "@expo/fingerprint";
6
+ import fs$1 from "node:fs";
7
+ import { globbySync } from "globby";
8
+
9
+ //#region src/utils/fingerprint/processExtraSources.ts
10
+ /**
11
+ * Processes extra source files and directories for fingerprinting.
12
+ * @param extraSources Array of file paths, directory paths, or glob patterns
13
+ * @param cwd Current working directory for resolving paths
14
+ * @param ignorePaths Optional array of paths to ignore
15
+ * @returns Array of processed sources with their contents or directory information
16
+ */
17
+ function processExtraSources(extraSources, cwd, ignorePaths) {
18
+ const processedSources = [];
19
+ for (const source of extraSources) try {
20
+ const matches = globbySync(source, {
21
+ cwd,
22
+ ignore: ignorePaths ?? [],
23
+ absolute: true,
24
+ onlyFiles: false
25
+ });
26
+ for (const absolutePath of matches) if (fs$1.existsSync(absolutePath)) {
27
+ const stats = fs$1.statSync(absolutePath);
28
+ if (stats.isDirectory()) processedSources.push({
29
+ type: "dir",
30
+ filePath: absolutePath,
31
+ reasons: ["custom-user-config"]
32
+ });
33
+ else processedSources.push({
34
+ type: "contents",
35
+ id: absolutePath,
36
+ contents: fs$1.readFileSync(absolutePath, "utf-8"),
37
+ reasons: ["custom-user-config"]
38
+ });
39
+ }
40
+ } catch (error) {
41
+ console.warn(`Error processing extra source "${source}": ${error}`);
42
+ }
43
+ return processedSources;
44
+ }
45
+
46
+ //#endregion
47
+ //#region src/utils/fingerprint/index.ts
48
+ function removeHotUpdaterFieldsFromStringsXml(contents) {
49
+ return contents.replaceAll(/<string name="hot_updater_fingerprint_hash" moduleConfig="true">[^<]+<\/string>/g, "").replaceAll(/<string name="hot_updater_channel" moduleConfig="true">[^<]+<\/string>/g, "");
50
+ }
51
+ function removeHotUpdaterFieldsFromInfoPlist(contents) {
52
+ return contents.replaceAll(/<key>HOT_UPDATER_FINGERPRINT_HASH<\/key>\s*<string>[^<]+<\/string>/g, "").replaceAll(/<key>HOT_UPDATER_CHANNEL<\/key>\s*<string>[^<]+<\/string>/g, "");
53
+ }
54
+ function fileHookTransform(source, chunk) {
55
+ if (source.type !== "file" || !chunk) return chunk;
56
+ const chunkString = chunk.toString("utf-8");
57
+ if (source.filePath.endsWith(".xml")) return Buffer.from(removeHotUpdaterFieldsFromStringsXml(chunkString));
58
+ if (source.filePath.endsWith(".plist")) return Buffer.from(removeHotUpdaterFieldsFromInfoPlist(chunkString));
59
+ return chunk;
60
+ }
61
+ /**
62
+ * Calculates the fingerprint of the native parts project of the project.
63
+ */
64
+ async function nativeFingerprint(path$1, options) {
65
+ const platform = options.platform;
66
+ return createFingerprintAsync(path$1, {
67
+ platforms: [platform],
68
+ ignorePaths: options.ignorePaths,
69
+ fileHookTransform,
70
+ extraSources: processExtraSources(options.extraSources, path$1, options.ignorePaths)
71
+ });
72
+ }
73
+ const ensureFingerprintConfig = async () => {
74
+ const config = await loadConfig(null);
75
+ if (config.updateStrategy === "appVersion") {
76
+ p.log.error("The updateStrategy in hot-updater.config.ts is set to 'appVersion'. This command only works with 'fingerprint' strategy.");
77
+ process.exit(1);
78
+ }
79
+ return config.fingerprint;
80
+ };
81
+ const generateFingerprints = async () => {
82
+ const fingerprintConfig = await ensureFingerprintConfig();
83
+ const [ios, android] = await Promise.all([nativeFingerprint(getCwd(), {
84
+ platform: "ios",
85
+ ...fingerprintConfig
86
+ }), nativeFingerprint(getCwd(), {
87
+ platform: "android",
88
+ ...fingerprintConfig
89
+ })]);
90
+ return {
91
+ ios,
92
+ android
93
+ };
94
+ };
95
+ const generateFingerprint = async (platform) => {
96
+ const fingerprintConfig = await ensureFingerprintConfig();
97
+ return nativeFingerprint(getCwd(), {
98
+ platform,
99
+ ...fingerprintConfig
100
+ });
101
+ };
102
+ const createFingerprintJson = async () => {
103
+ const FINGERPRINT_FILE_PATH = path.join(getCwd(), "fingerprint.json");
104
+ const newFingerprint = await generateFingerprints();
105
+ await fs.promises.writeFile(FINGERPRINT_FILE_PATH, JSON.stringify(newFingerprint, null, 2));
106
+ return newFingerprint;
107
+ };
108
+ const readLocalFingerprint = async () => {
109
+ const FINGERPRINT_FILE_PATH = path.join(getCwd(), "fingerprint.json");
110
+ try {
111
+ const content = await fs.promises.readFile(FINGERPRINT_FILE_PATH, "utf-8");
112
+ return JSON.parse(content);
113
+ } catch {
114
+ return null;
115
+ }
116
+ };
117
+
118
+ //#endregion
119
+ export { createFingerprintJson, generateFingerprint, generateFingerprints, nativeFingerprint, readLocalFingerprint };
@@ -0,0 +1,149 @@
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const __hot_updater_plugin_core = require_chunk.__toESM(require("@hot-updater/plugin-core"));
3
+ const fs = require_chunk.__toESM(require("fs"));
4
+ const path = require_chunk.__toESM(require("path"));
5
+ const __clack_prompts = require_chunk.__toESM(require("@clack/prompts"));
6
+ const __expo_fingerprint = require_chunk.__toESM(require("@expo/fingerprint"));
7
+ const node_fs = require_chunk.__toESM(require("node:fs"));
8
+ const globby = require_chunk.__toESM(require("globby"));
9
+
10
+ //#region src/utils/fingerprint/processExtraSources.ts
11
+ /**
12
+ * Processes extra source files and directories for fingerprinting.
13
+ * @param extraSources Array of file paths, directory paths, or glob patterns
14
+ * @param cwd Current working directory for resolving paths
15
+ * @param ignorePaths Optional array of paths to ignore
16
+ * @returns Array of processed sources with their contents or directory information
17
+ */
18
+ function processExtraSources(extraSources, cwd, ignorePaths) {
19
+ const processedSources = [];
20
+ for (const source of extraSources) try {
21
+ const matches = (0, globby.globbySync)(source, {
22
+ cwd,
23
+ ignore: ignorePaths ?? [],
24
+ absolute: true,
25
+ onlyFiles: false
26
+ });
27
+ for (const absolutePath of matches) if (node_fs.default.existsSync(absolutePath)) {
28
+ const stats = node_fs.default.statSync(absolutePath);
29
+ if (stats.isDirectory()) processedSources.push({
30
+ type: "dir",
31
+ filePath: absolutePath,
32
+ reasons: ["custom-user-config"]
33
+ });
34
+ else processedSources.push({
35
+ type: "contents",
36
+ id: absolutePath,
37
+ contents: node_fs.default.readFileSync(absolutePath, "utf-8"),
38
+ reasons: ["custom-user-config"]
39
+ });
40
+ }
41
+ } catch (error) {
42
+ console.warn(`Error processing extra source "${source}": ${error}`);
43
+ }
44
+ return processedSources;
45
+ }
46
+
47
+ //#endregion
48
+ //#region src/utils/fingerprint/index.ts
49
+ function removeHotUpdaterFieldsFromStringsXml(contents) {
50
+ return contents.replaceAll(/<string name="hot_updater_fingerprint_hash" moduleConfig="true">[^<]+<\/string>/g, "").replaceAll(/<string name="hot_updater_channel" moduleConfig="true">[^<]+<\/string>/g, "");
51
+ }
52
+ function removeHotUpdaterFieldsFromInfoPlist(contents) {
53
+ return contents.replaceAll(/<key>HOT_UPDATER_FINGERPRINT_HASH<\/key>\s*<string>[^<]+<\/string>/g, "").replaceAll(/<key>HOT_UPDATER_CHANNEL<\/key>\s*<string>[^<]+<\/string>/g, "");
54
+ }
55
+ function fileHookTransform(source, chunk) {
56
+ if (source.type !== "file" || !chunk) return chunk;
57
+ const chunkString = chunk.toString("utf-8");
58
+ if (source.filePath.endsWith(".xml")) return Buffer.from(removeHotUpdaterFieldsFromStringsXml(chunkString));
59
+ if (source.filePath.endsWith(".plist")) return Buffer.from(removeHotUpdaterFieldsFromInfoPlist(chunkString));
60
+ return chunk;
61
+ }
62
+ /**
63
+ * Calculates the fingerprint of the native parts project of the project.
64
+ */
65
+ async function nativeFingerprint(path$2, options) {
66
+ const platform = options.platform;
67
+ return (0, __expo_fingerprint.createFingerprintAsync)(path$2, {
68
+ platforms: [platform],
69
+ ignorePaths: options.ignorePaths,
70
+ fileHookTransform,
71
+ extraSources: processExtraSources(options.extraSources, path$2, options.ignorePaths)
72
+ });
73
+ }
74
+ const ensureFingerprintConfig = async () => {
75
+ const config = await (0, __hot_updater_plugin_core.loadConfig)(null);
76
+ if (config.updateStrategy === "appVersion") {
77
+ __clack_prompts.log.error("The updateStrategy in hot-updater.config.ts is set to 'appVersion'. This command only works with 'fingerprint' strategy.");
78
+ process.exit(1);
79
+ }
80
+ return config.fingerprint;
81
+ };
82
+ const generateFingerprints = async () => {
83
+ const fingerprintConfig = await ensureFingerprintConfig();
84
+ const [ios, android] = await Promise.all([nativeFingerprint((0, __hot_updater_plugin_core.getCwd)(), {
85
+ platform: "ios",
86
+ ...fingerprintConfig
87
+ }), nativeFingerprint((0, __hot_updater_plugin_core.getCwd)(), {
88
+ platform: "android",
89
+ ...fingerprintConfig
90
+ })]);
91
+ return {
92
+ ios,
93
+ android
94
+ };
95
+ };
96
+ const generateFingerprint = async (platform) => {
97
+ const fingerprintConfig = await ensureFingerprintConfig();
98
+ return nativeFingerprint((0, __hot_updater_plugin_core.getCwd)(), {
99
+ platform,
100
+ ...fingerprintConfig
101
+ });
102
+ };
103
+ const createFingerprintJson = async () => {
104
+ const FINGERPRINT_FILE_PATH = path.default.join((0, __hot_updater_plugin_core.getCwd)(), "fingerprint.json");
105
+ const newFingerprint = await generateFingerprints();
106
+ await fs.default.promises.writeFile(FINGERPRINT_FILE_PATH, JSON.stringify(newFingerprint, null, 2));
107
+ return newFingerprint;
108
+ };
109
+ const readLocalFingerprint = async () => {
110
+ const FINGERPRINT_FILE_PATH = path.default.join((0, __hot_updater_plugin_core.getCwd)(), "fingerprint.json");
111
+ try {
112
+ const content = await fs.default.promises.readFile(FINGERPRINT_FILE_PATH, "utf-8");
113
+ return JSON.parse(content);
114
+ } catch {
115
+ return null;
116
+ }
117
+ };
118
+
119
+ //#endregion
120
+ Object.defineProperty(exports, 'createFingerprintJson', {
121
+ enumerable: true,
122
+ get: function () {
123
+ return createFingerprintJson;
124
+ }
125
+ });
126
+ Object.defineProperty(exports, 'generateFingerprint', {
127
+ enumerable: true,
128
+ get: function () {
129
+ return generateFingerprint;
130
+ }
131
+ });
132
+ Object.defineProperty(exports, 'generateFingerprints', {
133
+ enumerable: true,
134
+ get: function () {
135
+ return generateFingerprints;
136
+ }
137
+ });
138
+ Object.defineProperty(exports, 'nativeFingerprint', {
139
+ enumerable: true,
140
+ get: function () {
141
+ return nativeFingerprint;
142
+ }
143
+ });
144
+ Object.defineProperty(exports, 'readLocalFingerprint', {
145
+ enumerable: true,
146
+ get: function () {
147
+ return readLocalFingerprint;
148
+ }
149
+ });