@aspruyt/xfg 5.0.2 → 5.1.2

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.
@@ -15,8 +15,9 @@ export interface MergeContext {
15
15
  */
16
16
  export declare function deepMerge(base: Record<string, unknown>, overlay: Record<string, unknown>, ctx: MergeContext): Record<string, unknown>;
17
17
  /**
18
- * Strip merge directive keys ($arrayMerge, $override, etc.) from an object.
18
+ * Strip xfg merge directive keys ($arrayMerge, $values) from an object.
19
19
  * Works recursively on nested objects and arrays.
20
+ * Standard $-prefixed keys ($schema, $id, $ref, etc.) are preserved.
20
21
  */
21
22
  export declare function stripMergeDirectives(obj: Record<string, unknown>): Record<string, unknown>;
22
23
  /**
@@ -3,6 +3,12 @@
3
3
  * Supports per-field array merge strategies via $arrayMerge + $values directives.
4
4
  */
5
5
  import { isPlainObject } from "../shared/type-guards.js";
6
+ /**
7
+ * Keys reserved for xfg merge directives.
8
+ * Only these are stripped during merge — standard $-prefixed keys
9
+ * like $schema, $id, $ref, $generated are preserved.
10
+ */
11
+ const XFG_DIRECTIVES = new Set(["$arrayMerge", "$values"]);
6
12
  /**
7
13
  * Strategy map for array merge operations.
8
14
  * Extensible: add new strategies by adding to this map.
@@ -34,7 +40,7 @@ export function deepMerge(base, overlay, ctx) {
34
40
  const result = { ...base };
35
41
  for (const [key, overlayValue] of Object.entries(overlay)) {
36
42
  // Skip directive keys in output
37
- if (key.startsWith("$"))
43
+ if (XFG_DIRECTIVES.has(key))
38
44
  continue;
39
45
  const baseValue = base[key];
40
46
  // Per-field $arrayMerge + $values directive
@@ -66,14 +72,15 @@ export function deepMerge(base, overlay, ctx) {
66
72
  return result;
67
73
  }
68
74
  /**
69
- * Strip merge directive keys ($arrayMerge, $override, etc.) from an object.
75
+ * Strip xfg merge directive keys ($arrayMerge, $values) from an object.
70
76
  * Works recursively on nested objects and arrays.
77
+ * Standard $-prefixed keys ($schema, $id, $ref, etc.) are preserved.
71
78
  */
72
79
  export function stripMergeDirectives(obj) {
73
80
  const result = {};
74
81
  for (const [key, value] of Object.entries(obj)) {
75
- // Skip all $-prefixed keys (reserved for directives)
76
- if (key.startsWith("$"))
82
+ // Skip xfg directive keys only
83
+ if (XFG_DIRECTIVES.has(key))
77
84
  continue;
78
85
  if (isPlainObject(value)) {
79
86
  result[key] = stripMergeDirectives(value);
@@ -7,9 +7,9 @@ export declare function getFileStatus(exists: boolean, changed: boolean): FileSt
7
7
  */
8
8
  export declare function formatDiffLine(line: string): string;
9
9
  /**
10
- * Check if a file is a structured data file (JSON, JSON5, YAML, YML).
10
+ * Check if a file is likely binary based on its extension.
11
11
  */
12
- export declare function isStructuredDataFile(fileName: string): boolean;
12
+ export declare function isBinaryFile(fileName: string): boolean;
13
13
  /**
14
14
  * Compute a unified diff between old and new content.
15
15
  * Returns raw diff lines (no ANSI formatting).
@@ -17,11 +17,52 @@ export function formatDiffLine(line) {
17
17
  return chalk.cyan(line);
18
18
  return line;
19
19
  }
20
+ const BINARY_EXTENSIONS = new Set([
21
+ ".png",
22
+ ".jpg",
23
+ ".jpeg",
24
+ ".gif",
25
+ ".bmp",
26
+ ".ico",
27
+ ".webp",
28
+ ".svg",
29
+ ".woff",
30
+ ".woff2",
31
+ ".ttf",
32
+ ".eot",
33
+ ".otf",
34
+ ".pdf",
35
+ ".zip",
36
+ ".tar",
37
+ ".gz",
38
+ ".bz2",
39
+ ".7z",
40
+ ".rar",
41
+ ".exe",
42
+ ".dll",
43
+ ".so",
44
+ ".dylib",
45
+ ".bin",
46
+ ".dat",
47
+ ".db",
48
+ ".sqlite",
49
+ ".jar",
50
+ ".class",
51
+ ".pyc",
52
+ ".wasm",
53
+ ".mp3",
54
+ ".mp4",
55
+ ".wav",
56
+ ".avi",
57
+ ".mov",
58
+ ".mkv",
59
+ ]);
20
60
  /**
21
- * Check if a file is a structured data file (JSON, JSON5, YAML, YML).
61
+ * Check if a file is likely binary based on its extension.
22
62
  */
23
- export function isStructuredDataFile(fileName) {
24
- return /\.(json|json5|ya?ml)$/i.test(fileName);
63
+ export function isBinaryFile(fileName) {
64
+ const ext = fileName.slice(fileName.lastIndexOf(".")).toLowerCase();
65
+ return BINARY_EXTENSIONS.has(ext);
25
66
  }
26
67
  /**
27
68
  * Compute a unified diff between old and new content.
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { convertContentToString } from "../config/formatter.js";
4
4
  import { interpolateXfgContent } from "../shared/xfg-template.js";
5
- import { getFileStatus, generateDiff, createDiffStats, incrementDiffStats, computeUnifiedDiff, isStructuredDataFile, } from "./diff-utils.js";
5
+ import { getFileStatus, generateDiff, createDiffStats, incrementDiffStats, computeUnifiedDiff, isBinaryFile, } from "./diff-utils.js";
6
6
  /**
7
7
  * Determines if a file should be marked as executable.
8
8
  * .sh files are auto-executable unless explicit executable: false is set.
@@ -70,8 +70,8 @@ export class FileWriter {
70
70
  content: fileContent,
71
71
  action,
72
72
  };
73
- // Compute raw diff lines for structured data files (all modes)
74
- if (isStructuredDataFile(file.fileName)) {
73
+ // Compute raw diff lines for text files (all modes)
74
+ if (!isBinaryFile(file.fileName)) {
75
75
  writeResult.diffLines = computeUnifiedDiff(existingContent, fileContent);
76
76
  }
77
77
  fileChanges.set(file.fileName, writeResult);
@@ -1,4 +1,4 @@
1
1
  export type { DiffStats } from "./diff-utils.js";
2
- export { computeUnifiedDiff, isStructuredDataFile, formatDiffLine, } from "./diff-utils.js";
2
+ export { computeUnifiedDiff, isBinaryFile, formatDiffLine, } from "./diff-utils.js";
3
3
  export type { FileChangeDetail, GitOpsFactory, IAuthOptionsBuilder, IBranchManager, ICommitPushManager, IFileSyncOrchestrator, IPRMergeHandler, IRepositoryProcessor, IRepositorySession, IWorkStrategy, ProcessorResult, SessionContext, WorkResult, } from "./types.js";
4
4
  export { RepositoryProcessor } from "./repository-processor.js";
@@ -1,2 +1,2 @@
1
- export { computeUnifiedDiff, isStructuredDataFile, formatDiffLine, } from "./diff-utils.js";
1
+ export { computeUnifiedDiff, isBinaryFile, formatDiffLine, } from "./diff-utils.js";
2
2
  export { RepositoryProcessor } from "./repository-processor.js";
@@ -1,7 +1,7 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { loadManifest, saveManifest, updateManifest, MANIFEST_FILENAME, } from "./manifest.js";
4
- import { computeUnifiedDiff, isStructuredDataFile } from "./diff-utils.js";
4
+ import { computeUnifiedDiff, isBinaryFile } from "./diff-utils.js";
5
5
  /**
6
6
  * Handles manifest loading, saving, and orphan detection.
7
7
  */
@@ -35,7 +35,7 @@ export class ManifestManager {
35
35
  content: null,
36
36
  action: "delete",
37
37
  };
38
- if (isStructuredDataFile(fileName)) {
38
+ if (!isBinaryFile(fileName)) {
39
39
  const existingContent = gitOps.getFileContent(fileName);
40
40
  if (existingContent !== null) {
41
41
  writeResult.diffLines = computeUnifiedDiff(existingContent, null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aspruyt/xfg",
3
- "version": "5.0.2",
3
+ "version": "5.1.2",
4
4
  "description": "Manage files, settings, and repositories across GitHub, Azure DevOps, and GitLab — declaratively, from a single YAML config",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",