@hot-updater/cli-tools 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/dist/index.mjs +46 -31
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -44704,7 +44704,7 @@ const mergeHotUpdaterConfigText = (existingText, scaffold) => {
44704
44704
  if (MANAGED_IMPORT_PACKAGES.has(pkg) && !(nextObject.keptBuild && BUILD_IMPORT_PACKAGES.has(pkg)) && keptReferences && !keptReferences.has(specifier.local.name)) continue;
44705
44705
  const scaffoldImport = scaffoldNames.get(specifier.local.name);
44706
44706
  const imported = specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" ? specifier.imported.name : null;
44707
- if (scaffoldImport !== void 0 && (scaffoldImport.imported !== imported || scaffoldImport.pkg !== pkg && !(scaffoldImport.pkg === "hot-updater/plugins" && pkg === "@hot-updater/server/plugins"))) return { reason: `The import of ${specifier.local.name} from "${pkg}" takes the name init imports from "${scaffoldImport.pkg}".` };
44707
+ if (scaffoldImport !== void 0 && (scaffoldImport.imported !== imported || scaffoldImport.pkg !== pkg && !MANAGED_IMPORT_PACKAGES.has(pkg))) return { reason: `The import of ${specifier.local.name} from "${pkg}" takes the name init imports from "${scaffoldImport.pkg}".` };
44708
44708
  }
44709
44709
  }
44710
44710
  return { text: applyTextEdits(existingText, [
@@ -45048,64 +45048,72 @@ function isUnsafeProperty(key) {
45048
45048
  return key === "__proto__";
45049
45049
  }
45050
45050
  //#endregion
45051
- //#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/merge.mjs
45051
+ //#region ../../node_modules/.pnpm/es-toolkit@1.47.0/node_modules/es-toolkit/dist/object/mergeWith.mjs
45052
45052
  /**
45053
45053
  * Merges the properties of the source object into the target object.
45054
45054
  *
45055
- * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
45056
- * If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
45057
- * If a property in the source object is undefined, it will not overwrite a defined property in the target object.
45055
+ * You can provide a custom `merge` function to control how properties are merged. It should return the value to be set in the target object.
45056
+ *
45057
+ * If it returns `undefined`, a default deep merge will be applied for arrays and objects:
45058
+ *
45059
+ * - If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
45060
+ * - If a property in the source object is undefined, it will not overwrite a defined property in the target object.
45058
45061
  *
45059
45062
  * Note that this function mutates the target object.
45060
45063
  *
45061
45064
  * @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
45062
45065
  * @param {S} source - The source object whose properties will be merged into the target object.
45066
+ * @param {(targetValue: any, sourceValue: any, key: string, target: T, source: S) => any} merge - A custom merge function that defines how properties should be combined. It receives the following arguments:
45067
+ * - `targetValue`: The current value of the property in the target object.
45068
+ * - `sourceValue`: The value of the property in the source object.
45069
+ * - `key`: The key of the property being merged.
45070
+ * - `target`: The target object.
45071
+ * - `source`: The source object.
45072
+ *
45063
45073
  * @returns {T & S} The updated target object with properties from the source object merged in.
45064
45074
  *
45065
45075
  * @template T - Type of the target object.
45066
45076
  * @template S - Type of the source object.
45067
45077
  *
45068
45078
  * @example
45069
- * const target = { a: 1, b: { x: 1, y: 2 } };
45070
- * const source = { b: { y: 3, z: 4 }, c: 5 };
45071
- *
45072
- * const result = merge(target, source);
45073
- * console.log(result);
45074
- * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
45079
+ * const target = { a: 1, b: 2 };
45080
+ * const source = { b: 3, c: 4 };
45075
45081
  *
45082
+ * mergeWith(target, source, (targetValue, sourceValue) => {
45083
+ * if (typeof targetValue === 'number' && typeof sourceValue === 'number') {
45084
+ * return targetValue + sourceValue;
45085
+ * }
45086
+ * });
45087
+ * // Returns { a: 1, b: 5, c: 4 }
45076
45088
  * @example
45077
- * const target = { a: [1, 2], b: { x: 1 } };
45078
- * const source = { a: [3], b: { y: 2 } };
45089
+ * const target = { a: [1], b: [2] };
45090
+ * const source = { a: [3], b: [4] };
45079
45091
  *
45080
- * const result = merge(target, source);
45081
- * console.log(result);
45082
- * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
45092
+ * const result = mergeWith(target, source, (objValue, srcValue) => {
45093
+ * if (Array.isArray(objValue)) {
45094
+ * return objValue.concat(srcValue);
45095
+ * }
45096
+ * });
45083
45097
  *
45084
- * @example
45085
- * const target = { a: null };
45086
- * const source = { a: [1, 2, 3] };
45087
- *
45088
- * const result = merge(target, source);
45089
- * console.log(result);
45090
- * // Output: { a: [1, 2, 3] }
45098
+ * expect(result).toEqual({ a: [1, 3], b: [2, 4] });
45091
45099
  */
45092
- function merge(target, source) {
45100
+ function mergeWith(target, source, merge) {
45093
45101
  const sourceKeys = Object.keys(source);
45094
45102
  for (let i = 0; i < sourceKeys.length; i++) {
45095
45103
  const key = sourceKeys[i];
45096
45104
  if (isUnsafeProperty(key)) continue;
45097
45105
  const sourceValue = source[key];
45098
45106
  const targetValue = target[key];
45099
- if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) target[key] = merge(targetValue, sourceValue);
45100
- else if (Array.isArray(sourceValue)) target[key] = merge([], sourceValue);
45101
- else if (isPlainObject(sourceValue)) target[key] = merge({}, sourceValue);
45107
+ const merged = merge(targetValue, sourceValue, key, target, source);
45108
+ if (merged !== void 0) target[key] = merged;
45109
+ else if (Array.isArray(sourceValue)) if (Array.isArray(targetValue)) target[key] = mergeWith(targetValue, sourceValue, merge);
45110
+ else target[key] = mergeWith([], sourceValue, merge);
45111
+ else if (isPlainObject(sourceValue)) if (isPlainObject(targetValue)) target[key] = mergeWith(targetValue, sourceValue, merge);
45112
+ else target[key] = mergeWith({}, sourceValue, merge);
45102
45113
  else if (targetValue === void 0 || sourceValue !== void 0) target[key] = sourceValue;
45103
45114
  }
45104
45115
  return target;
45105
45116
  }
45106
- function isMergeableValue(value) {
45107
- return isPlainObject(value) || Array.isArray(value);
45108
- }
45109
45117
  //#endregion
45110
45118
  //#region src/loadConfig.ts
45111
45119
  var import_out = /* @__PURE__ */ __toESM(require_out(), 1);
@@ -45162,8 +45170,15 @@ const getDefaultConfig = () => {
45162
45170
  plugins: []
45163
45171
  };
45164
45172
  };
45173
+ /**
45174
+ * An array in the config replaces the default one. A plain deep merge goes
45175
+ * index by index, so `infoPlistPaths: ["ios/App/Info.plist"]` over three
45176
+ * discovered Info.plist files only overwrote the first and kept the others.
45177
+ * The array is still copied deeply, as `merge` copied it.
45178
+ */
45179
+ const replaceArrays = (_targetValue, sourceValue) => Array.isArray(sourceValue) ? mergeWith([], sourceValue, replaceArrays) : void 0;
45165
45180
  const mergeConfigSources = (...sources) => {
45166
- const mergedConfig = sources.reduceRight((mergedConfig, source) => merge(mergedConfig, source ?? {}), {});
45181
+ const mergedConfig = sources.reduceRight((mergedConfig, source) => mergeWith(mergedConfig, source ?? {}, replaceArrays), {});
45167
45182
  const database = sources.find((source) => source?.database)?.database;
45168
45183
  const plugins = sources.find((source) => source?.plugins)?.plugins;
45169
45184
  const signing = sources.find((source) => source?.signing)?.signing;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/cli-tools",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"
@@ -49,9 +49,9 @@
49
49
  "oxc-parser": "0.141.0",
50
50
  "oxc-transform": "0.141.0",
51
51
  "unconfig": "7.5.0",
52
- "@hot-updater/server": "1.0.2",
53
- "@hot-updater/plugin-core": "1.0.2",
54
- "@hot-updater/protocol": "1.0.2"
52
+ "@hot-updater/protocol": "1.0.4",
53
+ "@hot-updater/plugin-core": "1.0.4",
54
+ "@hot-updater/server": "1.0.4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@clack/prompts": "1.7.0",
@@ -65,7 +65,7 @@
65
65
  "tar": "^7.5.16",
66
66
  "verkit": "0.4.0",
67
67
  "workspace-tools": "^0.41.7",
68
- "@hot-updater/test-utils": "1.0.2"
68
+ "@hot-updater/test-utils": "1.0.4"
69
69
  },
70
70
  "inlinedDependencies": {
71
71
  "@babel/code-frame": "7.29.0",