@zeropress/build-core 0.5.2 → 0.6.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.
@@ -11,7 +11,7 @@ export async function loadThemePackageFromDir(themeDir) {
11
11
 
12
12
  const validation = await validateThemeFiles(fileMap);
13
13
  if (!validation.ok) {
14
- throw new Error(`Theme validation failed: ${validation.errors[0]?.message || 'Unknown error'}`);
14
+ throw new Error(formatThemeValidationFailure(validation));
15
15
  }
16
16
 
17
17
  const rawThemeJson = String(fileMap.get('theme.json'));
@@ -58,6 +58,61 @@ export async function loadThemePackageFromDir(themeDir) {
58
58
  };
59
59
  }
60
60
 
61
+ function formatThemeValidationFailure(validation) {
62
+ const blocks = [
63
+ [
64
+ 'Theme validation failed',
65
+ `Errors: ${validation.errors.length}`,
66
+ `Checked files: ${validation.checkedFiles}`,
67
+ ].join('\n'),
68
+ ...validation.errors.map((issue) => formatThemeValidationIssue(issue)),
69
+ ];
70
+ return blocks.join('\n\n');
71
+ }
72
+
73
+ function formatThemeValidationIssue(issue) {
74
+ if (!issue) {
75
+ return 'Reason: Unknown error';
76
+ }
77
+
78
+ const lines = [`ERROR ${issue.code || 'THEME_VALIDATION_ERROR'}`];
79
+ const location = splitIssuePath(issue.path);
80
+ if (location.file) {
81
+ lines.push(`File: ${location.file}`);
82
+ }
83
+ if (location.path) {
84
+ lines.push(`Path: ${location.path}`);
85
+ }
86
+ if (Number.isInteger(issue.line) && Number.isInteger(issue.column)) {
87
+ lines.push(`Line: ${issue.line}, Column: ${issue.column}`);
88
+ }
89
+ if (issue.category) {
90
+ lines.push(`Category: ${issue.category}`);
91
+ }
92
+ lines.push(`Reason: ${issue.message || 'Unknown error'}`);
93
+ if (issue.snippet) {
94
+ const lineLabel = Number.isInteger(issue.line) ? String(issue.line) : '';
95
+ lines.push('', `${lineLabel} | ${issue.snippet.line}`, `${' '.repeat(lineLabel.length)} | ${issue.snippet.pointer}`);
96
+ }
97
+ if (issue.hint) {
98
+ lines.push('', 'Hint:', issue.hint);
99
+ }
100
+
101
+ return lines.join('\n');
102
+ }
103
+
104
+ function splitIssuePath(issuePath) {
105
+ const normalizedPath = String(issuePath || '');
106
+ if (normalizedPath.startsWith('theme.json.')) {
107
+ return {
108
+ file: 'theme.json',
109
+ path: normalizedPath.slice('theme.json.'.length),
110
+ };
111
+ }
112
+
113
+ return { file: normalizedPath, path: '' };
114
+ }
115
+
61
116
  async function readThemeDir(fs, path, rootDir, currentDir, fileMap) {
62
117
  const entries = await fs.readdir(currentDir, { withFileTypes: true });
63
118