@hot-updater/one 0.0.0-stage → 1.2.0-rc.25

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,192 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_tag = require("./tag-Tofi6ZMX.cjs");
3
+ let node_path = require("node:path");
4
+ node_path = require_tag.__toESM(node_path);
5
+ let node_fs = require("node:fs");
6
+ node_fs = require_tag.__toESM(node_fs);
7
+ let node_crypto = require("node:crypto");
8
+ node_crypto = require_tag.__toESM(node_crypto);
9
+ //#region src/patches.ts
10
+ const IOS_CHANNEL_KEY = "HOT_UPDATER_CHANNEL";
11
+ const IOS_PUBLIC_KEY_KEY = "HOT_UPDATER_PUBLIC_KEY";
12
+ const IOS_FINGERPRINT_HASH_KEY = "HOT_UPDATER_FINGERPRINT_HASH";
13
+ const ANDROID_CHANNEL_KEY = "com.hotupdater.CHANNEL";
14
+ const ANDROID_PUBLIC_KEY_KEY = "com.hotupdater.PUBLIC_KEY";
15
+ const ANDROID_FINGERPRINT_HASH_KEY = "com.hotupdater.FINGERPRINT_HASH";
16
+ const escapeXml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
17
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
18
+ /**
19
+ * An Android string resource value, escaped as `expo/config-plugins`'
20
+ * `XML.escapeAndroidString` escapes it, so the manifest holds what the Expo
21
+ * config plugin writes.
22
+ */
23
+ const escapeAndroidString = (value) => {
24
+ const escaped = value.replace(/[\n\r\t'"@]/g, (character) => {
25
+ switch (character) {
26
+ case "\n": return "\\n";
27
+ case "\r": return "\\r";
28
+ case " ": return "\\t";
29
+ default: return `\\${character}`;
30
+ }
31
+ });
32
+ return /(^\s|\s$)/.test(escaped) ? `"${escaped}"` : escaped;
33
+ };
34
+ const missingAnchor = (file, anchor) => {
35
+ throw new Error(`[hot-updater] cannot patch ${file}: expected ${anchor} in it. Leave native.app.updates unset, or update @hot-updater/one.`);
36
+ };
37
+ /** Removes `key` and its value from the plist's top-level dict. */
38
+ const removePlistKey = (content, key) => content.replace(new RegExp(`\\n?[ \\t]*<key>${escapeRegExp(key)}</key>\\s*<string>[^<]*</string>`, "g"), "");
39
+ /** Sets `key` to `value` in the plist's top-level dict. */
40
+ const setPlistString = (content, key, value) => {
41
+ const removed = removePlistKey(content, key);
42
+ const root = /<plist[^>]*>\s*<dict>/.exec(removed);
43
+ if (root === null) return missingAnchor("Info.plist", "<plist><dict>");
44
+ const at = root.index + root[0].length;
45
+ return `${removed.slice(0, at)}\n\t<key>${key}</key>\n\t<string>${escapeXml(value)}</string>${removed.slice(at)}`;
46
+ };
47
+ /** Removes the `<meta-data>` named `name` from the manifest. */
48
+ const removeMetaData = (content, name) => content.replace(new RegExp(`\\n?[ \\t]*<meta-data\\b[^>]*android:name="${escapeRegExp(name)}"[^>]*/>`, "g"), "");
49
+ /** Sets the `<meta-data>` named `name` in the manifest's application. */
50
+ const setMetaData = (content, name, value) => {
51
+ const removed = removeMetaData(content, name);
52
+ const end = /\n?([ \t]*)<\/application>/.exec(removed);
53
+ if (end === null) return missingAnchor("AndroidManifest.xml", "</application>");
54
+ const indent = `${end[1]} `;
55
+ return `${removed.slice(0, end.index)}\n${indent}<meta-data android:name="${name}" android:value="${escapeXml(value)}"/>${removed.slice(end.index)}`;
56
+ };
57
+ const IOS_BUNDLE_URL = "Bundle.main.url(forResource: \"main\", withExtension: \"jsbundle\")";
58
+ const IOS_HOT_UPDATER_BUNDLE_URL = "HotUpdater.bundleURL()";
59
+ const ANDROID_IMPORT_ANCHOR = "import com.facebook.react.ReactApplication";
60
+ const ANDROID_IMPORT = "import com.hotupdater.HotUpdater";
61
+ const ANDROID_REACT_HOST_CALL = "getDefaultReactHost(";
62
+ /** Makes the release AppDelegate load Hot Updater's bundle. */
63
+ const patchAppDelegate = (content) => {
64
+ let patched = content;
65
+ if (!patched.includes(IOS_HOT_UPDATER_BUNDLE_URL)) {
66
+ if (!patched.includes(IOS_BUNDLE_URL)) return missingAnchor("AppDelegate.swift", IOS_BUNDLE_URL);
67
+ patched = patched.replace(IOS_BUNDLE_URL, IOS_HOT_UPDATER_BUNDLE_URL);
68
+ }
69
+ if (/^import HotUpdater$/m.test(patched)) return patched;
70
+ const imports = patched.match(/^import .*$/gm);
71
+ if (imports === null) return missingAnchor("AppDelegate.swift", "import");
72
+ const lastImport = imports[imports.length - 1];
73
+ return patched.replace(lastImport, `${lastImport}\nimport HotUpdater`);
74
+ };
75
+ /** Passes Hot Updater's bundle to `getDefaultReactHost` in release builds. */
76
+ const patchMainApplication = (content) => {
77
+ let patched = content;
78
+ if (!patched.includes(ANDROID_IMPORT)) {
79
+ if (!patched.includes(ANDROID_IMPORT_ANCHOR)) return missingAnchor("MainApplication.kt", ANDROID_IMPORT_ANCHOR);
80
+ patched = patched.replace(ANDROID_IMPORT_ANCHOR, `${ANDROID_IMPORT_ANCHOR}\n${ANDROID_IMPORT}`);
81
+ }
82
+ const start = patched.indexOf(ANDROID_REACT_HOST_CALL);
83
+ if (start === -1) return missingAnchor("MainApplication.kt", ANDROID_REACT_HOST_CALL);
84
+ let depth = 0;
85
+ let end = start + 20 - 1;
86
+ for (; end < patched.length; end += 1) if (patched[end] === "(") depth += 1;
87
+ else if (patched[end] === ")" && --depth === 0) break;
88
+ const call = patched.slice(start, end);
89
+ if (call.includes("jsBundleFilePath")) return patched;
90
+ const indent = /\(\n([ \t]+)\S/.exec(call)?.[1];
91
+ const closingLine = patched.lastIndexOf("\n", end);
92
+ if (end === patched.length || indent === void 0 || closingLine < start) return missingAnchor("MainApplication.kt", ANDROID_REACT_HOST_CALL);
93
+ const before = patched.slice(0, closingLine).trimEnd();
94
+ const argument = [
95
+ `${indent}jsBundleFilePath = if (BuildConfig.DEBUG) {`,
96
+ `${indent} null`,
97
+ `${indent}} else {`,
98
+ `${indent} HotUpdater.getJSBundleFile(applicationContext)`,
99
+ `${indent}},`
100
+ ].join("\n");
101
+ return `${before}${before.endsWith(",") ? "" : ","}\n${argument}${patched.slice(closingLine)}`;
102
+ };
103
+ /**
104
+ * The SPKI PEM in `publicKeyPath`, checked as the CLI checks a bundle signing
105
+ * public key: an RSA key of at least 2048 bits.
106
+ */
107
+ const readPublicKey = (cwd, publicKeyPath) => {
108
+ let pem;
109
+ try {
110
+ pem = node_fs.default.readFileSync(node_path.default.resolve(cwd, publicKeyPath), "utf8").trim();
111
+ } catch {
112
+ throw new Error(`[hot-updater] cannot read the bundle signing public key file ${publicKeyPath}.`);
113
+ }
114
+ let key;
115
+ try {
116
+ if (pem.startsWith("-----BEGIN PUBLIC KEY-----") && pem.endsWith("-----END PUBLIC KEY-----")) key = node_crypto.default.createPublicKey(pem);
117
+ } catch {
118
+ key = void 0;
119
+ }
120
+ if (key === void 0 || key.asymmetricKeyType !== "rsa" || (key.asymmetricKeyDetails?.modulusLength ?? 0) < 2048) throw new Error(`[hot-updater] ${publicKeyPath} must be an RSA SPKI PEM public key of at least 2048 bits.`);
121
+ return key.export({
122
+ type: "spki",
123
+ format: "pem"
124
+ }).toString().trim();
125
+ };
126
+ /**
127
+ * The `native.app.patches` entries that set up Hot Updater in the native
128
+ * files `one prebuild` generates: the AppDelegate and MainApplication load
129
+ * Hot Updater's bundle, and Info.plist and AndroidManifest.xml carry the
130
+ * channel and, with `publicKeyPath`, the bundle signing public key.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import { hotUpdaterPatches } from "@hot-updater/one/patches";
135
+ *
136
+ * one({
137
+ * native: {
138
+ * app: {
139
+ * patches: hotUpdaterPatches({ channel: "production" }),
140
+ * },
141
+ * },
142
+ * });
143
+ * ```
144
+ */
145
+ const hotUpdaterPatches = (options = {}) => {
146
+ const { publicKeyPath } = options;
147
+ if (publicKeyPath !== void 0 && (typeof publicKeyPath !== "string" || !publicKeyPath.trim())) throw new Error("[hot-updater] publicKeyPath must be a non-empty path.");
148
+ const channel = options.channel || "production";
149
+ const cwd = process.cwd();
150
+ let publicKey;
151
+ const getPublicKey = (file) => {
152
+ publicKey ??= readPublicKey(cwd, file);
153
+ return publicKey;
154
+ };
155
+ const patches = [
156
+ {
157
+ platform: "ios",
158
+ file: "AppDelegate.swift",
159
+ patch: patchAppDelegate
160
+ },
161
+ {
162
+ platform: "ios",
163
+ file: "Info.plist",
164
+ patch: (content) => {
165
+ let patched = setPlistString(content, IOS_CHANNEL_KEY, channel);
166
+ patched = removePlistKey(patched, IOS_FINGERPRINT_HASH_KEY);
167
+ return publicKeyPath === void 0 ? removePlistKey(patched, IOS_PUBLIC_KEY_KEY) : setPlistString(patched, IOS_PUBLIC_KEY_KEY, getPublicKey(publicKeyPath));
168
+ }
169
+ },
170
+ {
171
+ platform: "android",
172
+ file: "MainApplication.kt",
173
+ patch: patchMainApplication
174
+ },
175
+ {
176
+ platform: "android",
177
+ file: "main/AndroidManifest.xml",
178
+ patch: (content) => {
179
+ let patched = setMetaData(content, ANDROID_CHANNEL_KEY, channel);
180
+ patched = removeMetaData(patched, ANDROID_FINGERPRINT_HASH_KEY);
181
+ return publicKeyPath === void 0 ? removeMetaData(patched, ANDROID_PUBLIC_KEY_KEY) : setMetaData(patched, ANDROID_PUBLIC_KEY_KEY, escapeAndroidString(getPublicKey(publicKeyPath)));
182
+ }
183
+ }
184
+ ];
185
+ const tag = {
186
+ ...options.channel === void 0 ? {} : { channel: options.channel },
187
+ ...publicKeyPath === void 0 ? {} : { publicKeyPath }
188
+ };
189
+ return patches.map((patch) => Object.defineProperty(patch, require_tag.HOT_UPDATER_PATCH, { value: tag }));
190
+ };
191
+ //#endregion
192
+ exports.hotUpdaterPatches = hotUpdaterPatches;
@@ -0,0 +1,49 @@
1
+ //#region src/tag.d.ts
2
+ interface HotUpdaterPatchesOptions {
3
+ /**
4
+ * The channel the native build embeds.
5
+ * @default "production"
6
+ */
7
+ channel?: string;
8
+ /**
9
+ * The bundle signing public key file the native build embeds, relative to
10
+ * the app root, such as the file `hot-updater keys export-public --output`
11
+ * writes.
12
+ */
13
+ publicKeyPath?: string;
14
+ }
15
+ //#endregion
16
+ //#region src/patches.d.ts
17
+ /**
18
+ * One's `NativeAppPatch`: an edit `one prebuild` runs on one generated native
19
+ * file. Declared here so this entry loads without `one`'s types.
20
+ */
21
+ interface OneNativeAppPatch {
22
+ platform: "ios" | "android";
23
+ /** A path suffix that matches exactly one generated file. */
24
+ file: string;
25
+ /** Returns the new contents; returns its input when the edit is there. */
26
+ patch: (content: string) => string;
27
+ }
28
+ /**
29
+ * The `native.app.patches` entries that set up Hot Updater in the native
30
+ * files `one prebuild` generates: the AppDelegate and MainApplication load
31
+ * Hot Updater's bundle, and Info.plist and AndroidManifest.xml carry the
32
+ * channel and, with `publicKeyPath`, the bundle signing public key.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { hotUpdaterPatches } from "@hot-updater/one/patches";
37
+ *
38
+ * one({
39
+ * native: {
40
+ * app: {
41
+ * patches: hotUpdaterPatches({ channel: "production" }),
42
+ * },
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ declare const hotUpdaterPatches: (options?: HotUpdaterPatchesOptions) => OneNativeAppPatch[];
48
+ //#endregion
49
+ export { type HotUpdaterPatchesOptions, OneNativeAppPatch, hotUpdaterPatches };
@@ -0,0 +1,49 @@
1
+ //#region src/tag.d.ts
2
+ interface HotUpdaterPatchesOptions {
3
+ /**
4
+ * The channel the native build embeds.
5
+ * @default "production"
6
+ */
7
+ channel?: string;
8
+ /**
9
+ * The bundle signing public key file the native build embeds, relative to
10
+ * the app root, such as the file `hot-updater keys export-public --output`
11
+ * writes.
12
+ */
13
+ publicKeyPath?: string;
14
+ }
15
+ //#endregion
16
+ //#region src/patches.d.ts
17
+ /**
18
+ * One's `NativeAppPatch`: an edit `one prebuild` runs on one generated native
19
+ * file. Declared here so this entry loads without `one`'s types.
20
+ */
21
+ interface OneNativeAppPatch {
22
+ platform: "ios" | "android";
23
+ /** A path suffix that matches exactly one generated file. */
24
+ file: string;
25
+ /** Returns the new contents; returns its input when the edit is there. */
26
+ patch: (content: string) => string;
27
+ }
28
+ /**
29
+ * The `native.app.patches` entries that set up Hot Updater in the native
30
+ * files `one prebuild` generates: the AppDelegate and MainApplication load
31
+ * Hot Updater's bundle, and Info.plist and AndroidManifest.xml carry the
32
+ * channel and, with `publicKeyPath`, the bundle signing public key.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { hotUpdaterPatches } from "@hot-updater/one/patches";
37
+ *
38
+ * one({
39
+ * native: {
40
+ * app: {
41
+ * patches: hotUpdaterPatches({ channel: "production" }),
42
+ * },
43
+ * },
44
+ * });
45
+ * ```
46
+ */
47
+ declare const hotUpdaterPatches: (options?: HotUpdaterPatchesOptions) => OneNativeAppPatch[];
48
+ //#endregion
49
+ export { type HotUpdaterPatchesOptions, OneNativeAppPatch, hotUpdaterPatches };
@@ -0,0 +1,188 @@
1
+ import { t as HOT_UPDATER_PATCH } from "./tag-DfkRm14L.mjs";
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+ import crypto from "node:crypto";
5
+ //#region src/patches.ts
6
+ const IOS_CHANNEL_KEY = "HOT_UPDATER_CHANNEL";
7
+ const IOS_PUBLIC_KEY_KEY = "HOT_UPDATER_PUBLIC_KEY";
8
+ const IOS_FINGERPRINT_HASH_KEY = "HOT_UPDATER_FINGERPRINT_HASH";
9
+ const ANDROID_CHANNEL_KEY = "com.hotupdater.CHANNEL";
10
+ const ANDROID_PUBLIC_KEY_KEY = "com.hotupdater.PUBLIC_KEY";
11
+ const ANDROID_FINGERPRINT_HASH_KEY = "com.hotupdater.FINGERPRINT_HASH";
12
+ const escapeXml = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13
+ const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
14
+ /**
15
+ * An Android string resource value, escaped as `expo/config-plugins`'
16
+ * `XML.escapeAndroidString` escapes it, so the manifest holds what the Expo
17
+ * config plugin writes.
18
+ */
19
+ const escapeAndroidString = (value) => {
20
+ const escaped = value.replace(/[\n\r\t'"@]/g, (character) => {
21
+ switch (character) {
22
+ case "\n": return "\\n";
23
+ case "\r": return "\\r";
24
+ case " ": return "\\t";
25
+ default: return `\\${character}`;
26
+ }
27
+ });
28
+ return /(^\s|\s$)/.test(escaped) ? `"${escaped}"` : escaped;
29
+ };
30
+ const missingAnchor = (file, anchor) => {
31
+ throw new Error(`[hot-updater] cannot patch ${file}: expected ${anchor} in it. Leave native.app.updates unset, or update @hot-updater/one.`);
32
+ };
33
+ /** Removes `key` and its value from the plist's top-level dict. */
34
+ const removePlistKey = (content, key) => content.replace(new RegExp(`\\n?[ \\t]*<key>${escapeRegExp(key)}</key>\\s*<string>[^<]*</string>`, "g"), "");
35
+ /** Sets `key` to `value` in the plist's top-level dict. */
36
+ const setPlistString = (content, key, value) => {
37
+ const removed = removePlistKey(content, key);
38
+ const root = /<plist[^>]*>\s*<dict>/.exec(removed);
39
+ if (root === null) return missingAnchor("Info.plist", "<plist><dict>");
40
+ const at = root.index + root[0].length;
41
+ return `${removed.slice(0, at)}\n\t<key>${key}</key>\n\t<string>${escapeXml(value)}</string>${removed.slice(at)}`;
42
+ };
43
+ /** Removes the `<meta-data>` named `name` from the manifest. */
44
+ const removeMetaData = (content, name) => content.replace(new RegExp(`\\n?[ \\t]*<meta-data\\b[^>]*android:name="${escapeRegExp(name)}"[^>]*/>`, "g"), "");
45
+ /** Sets the `<meta-data>` named `name` in the manifest's application. */
46
+ const setMetaData = (content, name, value) => {
47
+ const removed = removeMetaData(content, name);
48
+ const end = /\n?([ \t]*)<\/application>/.exec(removed);
49
+ if (end === null) return missingAnchor("AndroidManifest.xml", "</application>");
50
+ const indent = `${end[1]} `;
51
+ return `${removed.slice(0, end.index)}\n${indent}<meta-data android:name="${name}" android:value="${escapeXml(value)}"/>${removed.slice(end.index)}`;
52
+ };
53
+ const IOS_BUNDLE_URL = "Bundle.main.url(forResource: \"main\", withExtension: \"jsbundle\")";
54
+ const IOS_HOT_UPDATER_BUNDLE_URL = "HotUpdater.bundleURL()";
55
+ const ANDROID_IMPORT_ANCHOR = "import com.facebook.react.ReactApplication";
56
+ const ANDROID_IMPORT = "import com.hotupdater.HotUpdater";
57
+ const ANDROID_REACT_HOST_CALL = "getDefaultReactHost(";
58
+ /** Makes the release AppDelegate load Hot Updater's bundle. */
59
+ const patchAppDelegate = (content) => {
60
+ let patched = content;
61
+ if (!patched.includes(IOS_HOT_UPDATER_BUNDLE_URL)) {
62
+ if (!patched.includes(IOS_BUNDLE_URL)) return missingAnchor("AppDelegate.swift", IOS_BUNDLE_URL);
63
+ patched = patched.replace(IOS_BUNDLE_URL, IOS_HOT_UPDATER_BUNDLE_URL);
64
+ }
65
+ if (/^import HotUpdater$/m.test(patched)) return patched;
66
+ const imports = patched.match(/^import .*$/gm);
67
+ if (imports === null) return missingAnchor("AppDelegate.swift", "import");
68
+ const lastImport = imports[imports.length - 1];
69
+ return patched.replace(lastImport, `${lastImport}\nimport HotUpdater`);
70
+ };
71
+ /** Passes Hot Updater's bundle to `getDefaultReactHost` in release builds. */
72
+ const patchMainApplication = (content) => {
73
+ let patched = content;
74
+ if (!patched.includes(ANDROID_IMPORT)) {
75
+ if (!patched.includes(ANDROID_IMPORT_ANCHOR)) return missingAnchor("MainApplication.kt", ANDROID_IMPORT_ANCHOR);
76
+ patched = patched.replace(ANDROID_IMPORT_ANCHOR, `${ANDROID_IMPORT_ANCHOR}\n${ANDROID_IMPORT}`);
77
+ }
78
+ const start = patched.indexOf(ANDROID_REACT_HOST_CALL);
79
+ if (start === -1) return missingAnchor("MainApplication.kt", ANDROID_REACT_HOST_CALL);
80
+ let depth = 0;
81
+ let end = start + 20 - 1;
82
+ for (; end < patched.length; end += 1) if (patched[end] === "(") depth += 1;
83
+ else if (patched[end] === ")" && --depth === 0) break;
84
+ const call = patched.slice(start, end);
85
+ if (call.includes("jsBundleFilePath")) return patched;
86
+ const indent = /\(\n([ \t]+)\S/.exec(call)?.[1];
87
+ const closingLine = patched.lastIndexOf("\n", end);
88
+ if (end === patched.length || indent === void 0 || closingLine < start) return missingAnchor("MainApplication.kt", ANDROID_REACT_HOST_CALL);
89
+ const before = patched.slice(0, closingLine).trimEnd();
90
+ const argument = [
91
+ `${indent}jsBundleFilePath = if (BuildConfig.DEBUG) {`,
92
+ `${indent} null`,
93
+ `${indent}} else {`,
94
+ `${indent} HotUpdater.getJSBundleFile(applicationContext)`,
95
+ `${indent}},`
96
+ ].join("\n");
97
+ return `${before}${before.endsWith(",") ? "" : ","}\n${argument}${patched.slice(closingLine)}`;
98
+ };
99
+ /**
100
+ * The SPKI PEM in `publicKeyPath`, checked as the CLI checks a bundle signing
101
+ * public key: an RSA key of at least 2048 bits.
102
+ */
103
+ const readPublicKey = (cwd, publicKeyPath) => {
104
+ let pem;
105
+ try {
106
+ pem = fs.readFileSync(path.resolve(cwd, publicKeyPath), "utf8").trim();
107
+ } catch {
108
+ throw new Error(`[hot-updater] cannot read the bundle signing public key file ${publicKeyPath}.`);
109
+ }
110
+ let key;
111
+ try {
112
+ if (pem.startsWith("-----BEGIN PUBLIC KEY-----") && pem.endsWith("-----END PUBLIC KEY-----")) key = crypto.createPublicKey(pem);
113
+ } catch {
114
+ key = void 0;
115
+ }
116
+ if (key === void 0 || key.asymmetricKeyType !== "rsa" || (key.asymmetricKeyDetails?.modulusLength ?? 0) < 2048) throw new Error(`[hot-updater] ${publicKeyPath} must be an RSA SPKI PEM public key of at least 2048 bits.`);
117
+ return key.export({
118
+ type: "spki",
119
+ format: "pem"
120
+ }).toString().trim();
121
+ };
122
+ /**
123
+ * The `native.app.patches` entries that set up Hot Updater in the native
124
+ * files `one prebuild` generates: the AppDelegate and MainApplication load
125
+ * Hot Updater's bundle, and Info.plist and AndroidManifest.xml carry the
126
+ * channel and, with `publicKeyPath`, the bundle signing public key.
127
+ *
128
+ * @example
129
+ * ```ts
130
+ * import { hotUpdaterPatches } from "@hot-updater/one/patches";
131
+ *
132
+ * one({
133
+ * native: {
134
+ * app: {
135
+ * patches: hotUpdaterPatches({ channel: "production" }),
136
+ * },
137
+ * },
138
+ * });
139
+ * ```
140
+ */
141
+ const hotUpdaterPatches = (options = {}) => {
142
+ const { publicKeyPath } = options;
143
+ if (publicKeyPath !== void 0 && (typeof publicKeyPath !== "string" || !publicKeyPath.trim())) throw new Error("[hot-updater] publicKeyPath must be a non-empty path.");
144
+ const channel = options.channel || "production";
145
+ const cwd = process.cwd();
146
+ let publicKey;
147
+ const getPublicKey = (file) => {
148
+ publicKey ??= readPublicKey(cwd, file);
149
+ return publicKey;
150
+ };
151
+ const patches = [
152
+ {
153
+ platform: "ios",
154
+ file: "AppDelegate.swift",
155
+ patch: patchAppDelegate
156
+ },
157
+ {
158
+ platform: "ios",
159
+ file: "Info.plist",
160
+ patch: (content) => {
161
+ let patched = setPlistString(content, IOS_CHANNEL_KEY, channel);
162
+ patched = removePlistKey(patched, IOS_FINGERPRINT_HASH_KEY);
163
+ return publicKeyPath === void 0 ? removePlistKey(patched, IOS_PUBLIC_KEY_KEY) : setPlistString(patched, IOS_PUBLIC_KEY_KEY, getPublicKey(publicKeyPath));
164
+ }
165
+ },
166
+ {
167
+ platform: "android",
168
+ file: "MainApplication.kt",
169
+ patch: patchMainApplication
170
+ },
171
+ {
172
+ platform: "android",
173
+ file: "main/AndroidManifest.xml",
174
+ patch: (content) => {
175
+ let patched = setMetaData(content, ANDROID_CHANNEL_KEY, channel);
176
+ patched = removeMetaData(patched, ANDROID_FINGERPRINT_HASH_KEY);
177
+ return publicKeyPath === void 0 ? removeMetaData(patched, ANDROID_PUBLIC_KEY_KEY) : setMetaData(patched, ANDROID_PUBLIC_KEY_KEY, escapeAndroidString(getPublicKey(publicKeyPath)));
178
+ }
179
+ }
180
+ ];
181
+ const tag = {
182
+ ...options.channel === void 0 ? {} : { channel: options.channel },
183
+ ...publicKeyPath === void 0 ? {} : { publicKeyPath }
184
+ };
185
+ return patches.map((patch) => Object.defineProperty(patch, HOT_UPDATER_PATCH, { value: tag }));
186
+ };
187
+ //#endregion
188
+ export { hotUpdaterPatches };
@@ -0,0 +1,16 @@
1
+ //#region src/tag.ts
2
+ /**
3
+ * The key a patch from `hotUpdaterPatches` carries its options under, so the
4
+ * `one()` build adapter finds them in `native.app.patches`.
5
+ */
6
+ const HOT_UPDATER_PATCH = Symbol.for("@hot-updater/one/patches");
7
+ /** The options of the first patch in `patches` that `hotUpdaterPatches` made. */
8
+ const findHotUpdaterPatchesOptions = (patches) => {
9
+ if (!Array.isArray(patches)) return void 0;
10
+ for (const patch of patches) if (typeof patch === "object" && patch !== null) {
11
+ const options = Reflect.get(patch, HOT_UPDATER_PATCH);
12
+ if (typeof options === "object" && options !== null) return options;
13
+ }
14
+ };
15
+ //#endregion
16
+ export { findHotUpdaterPatchesOptions as n, HOT_UPDATER_PATCH as t };
@@ -0,0 +1,62 @@
1
+ //#region \0rolldown/runtime.js
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 __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ //#region src/tag.ts
25
+ /**
26
+ * The key a patch from `hotUpdaterPatches` carries its options under, so the
27
+ * `one()` build adapter finds them in `native.app.patches`.
28
+ */
29
+ const HOT_UPDATER_PATCH = Symbol.for("@hot-updater/one/patches");
30
+ /** The options of the first patch in `patches` that `hotUpdaterPatches` made. */
31
+ const findHotUpdaterPatchesOptions = (patches) => {
32
+ if (!Array.isArray(patches)) return void 0;
33
+ for (const patch of patches) if (typeof patch === "object" && patch !== null) {
34
+ const options = Reflect.get(patch, HOT_UPDATER_PATCH);
35
+ if (typeof options === "object" && options !== null) return options;
36
+ }
37
+ };
38
+ //#endregion
39
+ Object.defineProperty(exports, "HOT_UPDATER_PATCH", {
40
+ enumerable: true,
41
+ get: function() {
42
+ return HOT_UPDATER_PATCH;
43
+ }
44
+ });
45
+ Object.defineProperty(exports, "__commonJSMin", {
46
+ enumerable: true,
47
+ get: function() {
48
+ return __commonJSMin;
49
+ }
50
+ });
51
+ Object.defineProperty(exports, "__toESM", {
52
+ enumerable: true,
53
+ get: function() {
54
+ return __toESM;
55
+ }
56
+ });
57
+ Object.defineProperty(exports, "findHotUpdaterPatchesOptions", {
58
+ enumerable: true,
59
+ get: function() {
60
+ return findHotUpdaterPatchesOptions;
61
+ }
62
+ });
package/package.json CHANGED
@@ -1,6 +1,79 @@
1
1
  {
2
2
  "name": "@hot-updater/one",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.2.0-rc.25",
4
+ "description": "Hot Updater build adapter and native patches for One",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.cts",
8
+ "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/gronxb/hot-updater"
12
+ },
13
+ "author": "gronxb <gron1gh1@gmail.com> (https://github.com/gronxb)",
14
+ "bugs": {
15
+ "url": "https://github.com/gronxb/hot-updater/issues"
16
+ },
17
+ "homepage": "https://github.com/gronxb/hot-updater#readme",
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "package.json"
24
+ ],
25
+ "dependencies": {
26
+ "fast-glob": "3.3.3",
27
+ "@hot-updater/bare": "1.2.0-rc.25",
28
+ "@hot-updater/plugin-core": "1.2.0-rc.25",
29
+ "@hot-updater/cli-tools": "1.2.0-rc.25"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^20",
33
+ "execa": "9.5.2",
34
+ "vitest": "4.1.4"
35
+ },
36
+ "exports": {
37
+ ".": {
38
+ "import": "./dist/index.mjs",
39
+ "require": "./dist/index.cjs"
40
+ },
41
+ "./patches": {
42
+ "import": "./dist/patches.mjs",
43
+ "require": "./dist/patches.cjs"
44
+ },
45
+ "./package.json": "./package.json"
46
+ },
47
+ "inlinedDependencies": {
48
+ "@sec-ant/readable-stream": "0.4.1",
49
+ "@sindresorhus/merge-streams": "4.0.0",
50
+ "cross-spawn": "7.0.6",
51
+ "execa": "9.5.2",
52
+ "figures": "6.1.0",
53
+ "get-stream": "9.0.1",
54
+ "human-signals": "8.0.1",
55
+ "is-plain-obj": "4.1.0",
56
+ "is-stream": "4.0.1",
57
+ "is-unicode-supported": "2.1.0",
58
+ "isexe": "2.0.0",
59
+ "npm-run-path": "6.0.0",
60
+ "parse-ms": "4.0.0",
61
+ "path-key": [
62
+ "3.1.1",
63
+ "4.0.0"
64
+ ],
65
+ "pretty-ms": "9.3.0",
66
+ "shebang-command": "2.0.0",
67
+ "shebang-regex": "3.0.0",
68
+ "signal-exit": "4.1.0",
69
+ "strip-final-newline": "4.0.0",
70
+ "unicorn-magic": "0.3.0",
71
+ "which": "2.0.2",
72
+ "yoctocolors": "2.1.2"
73
+ },
74
+ "scripts": {
75
+ "build": "tsdown",
76
+ "test": "vitest run",
77
+ "test:type": "tsc --noEmit"
78
+ }
6
79
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.