@bedrock-core/builder-validation 0.1.0 → 0.2.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.
- package/CHANGELOG.md +32 -15
- package/dist/package.json +1 -1
- package/dist/src/index.d.ts +9 -3
- package/dist/src/index.js +69 -19
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
|
-
# @bedrock-core/builder-validation
|
|
2
|
-
|
|
3
|
-
## 0.
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
# @bedrock-core/builder-validation
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 930de95: Require script manifest entries to name their authored source files and publish TypeScript entries as JavaScript paths. Report missing sources and conflicting outputs in build diagnostics.
|
|
8
|
+
|
|
9
|
+
Configure content schema validation as strict, warn, or skip while retaining manifest and JSON syntax checks. Validate sound definitions with bare paths and named sound objects.
|
|
10
|
+
- 930de95: Require Node.js 26.13.0 or newer for Builder packages, the CLI, and new projects.
|
|
11
|
+
|
|
12
|
+
Use TypeScript 7.1 for Builder's source analysis, declaration emission, and release compilation. New script and full projects use TypeScript 7.1 for typechecking and retain a compatible compiler for ESLint.
|
|
13
|
+
|
|
14
|
+
## 0.1.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- aed8e9b: Validate infinite spell effects, mixed client render-controller entries and numeric geometry vectors against the pinned schema catalog.
|
|
19
|
+
|
|
20
|
+
## 0.1.0
|
|
21
|
+
|
|
22
|
+
### Minor Changes
|
|
23
|
+
|
|
24
|
+
- 09203ce: Expose package-owned `./plugin` entrypoints through the shared build context and
|
|
25
|
+
plugin contracts. Declare public export paths explicitly and keep implementation
|
|
26
|
+
helpers private. Bundler extensions contribute compiler plugins, virtual modules,
|
|
27
|
+
resolution settings and tracked inputs with conservative cache reuse. Standalone
|
|
28
|
+
packages load using their own declared dependencies.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 59ca6b9: Accept single terrain texture paths alongside path arrays when validating with the pinned Mojang schema catalog.
|
package/dist/package.json
CHANGED
package/dist/src/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface ContentPack {
|
|
|
9
9
|
}
|
|
10
10
|
/** Validation failure located by pack, file and JSON pointer. */
|
|
11
11
|
export interface ContentDiagnostic {
|
|
12
|
+
/** Whether the parser or a content schema reported the problem. */
|
|
13
|
+
kind?: 'syntax' | 'schema';
|
|
12
14
|
/** Configured pack ID. */
|
|
13
15
|
pack: string;
|
|
14
16
|
/** JSON file path relative to the pack directory, using forward slashes. */
|
|
@@ -33,15 +35,19 @@ export interface ContentFileResult {
|
|
|
33
35
|
}
|
|
34
36
|
/** Schema catalog version and validation coverage for all checked files. */
|
|
35
37
|
export interface ContentValidationResult {
|
|
36
|
-
/** Resolved Mojang schema catalog version. */
|
|
38
|
+
/** Resolved Mojang schema catalog version, or an empty string when schema checks are skipped. */
|
|
37
39
|
schemaVersion: string;
|
|
38
40
|
/** Per-file checks and schema coverage. */
|
|
39
41
|
files: ContentFileResult[];
|
|
40
42
|
}
|
|
43
|
+
/** How to handle schema checks. Invalid JSON syntax always fails. */
|
|
44
|
+
export type ContentValidationMode = 'strict' | 'warn' | 'skip';
|
|
41
45
|
/** Pack selection, schema catalog and optional validation-reuse integration. */
|
|
42
46
|
export interface ContentValidationOptions {
|
|
43
47
|
/** Final pack directories to validate. */
|
|
44
48
|
packs: readonly ContentPack[];
|
|
49
|
+
/** Schema validation mode, defaulting to warn. */
|
|
50
|
+
mode?: ContentValidationMode;
|
|
45
51
|
/** Custom installed Mojang schema catalog directory. */
|
|
46
52
|
schemaRoot?: string;
|
|
47
53
|
/** Cooperative validation cancellation. */
|
|
@@ -57,8 +63,8 @@ export declare class ContentValidationError extends Error {
|
|
|
57
63
|
constructor(diagnostics: ContentDiagnostic[]);
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
|
-
* Validate
|
|
66
|
+
* Validate JSON syntax and apply content schemas according to the selected mode.
|
|
61
67
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
62
|
-
* @returns
|
|
68
|
+
* @returns Per-file coverage and diagnostics. Syntax errors and strict schema errors throw ContentValidationError.
|
|
63
69
|
*/
|
|
64
70
|
export declare function validatePackContent(options: ContentValidationOptions): Promise<ContentValidationResult>;
|
package/dist/src/index.js
CHANGED
|
@@ -23,22 +23,25 @@ function within(root, file) {
|
|
|
23
23
|
return relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Validate
|
|
26
|
+
* Validate JSON syntax and apply content schemas according to the selected mode.
|
|
27
27
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
28
|
-
* @returns
|
|
28
|
+
* @returns Per-file coverage and diagnostics. Syntax errors and strict schema errors throw ContentValidationError.
|
|
29
29
|
*/
|
|
30
30
|
export async function validatePackContent(options) {
|
|
31
|
+
const mode = options.mode ?? 'warn';
|
|
32
|
+
const skip = mode === 'skip';
|
|
31
33
|
const require = createRequire(import.meta.url);
|
|
32
|
-
const root = await realpath(options.schemaRoot ?? path.dirname(require.resolve('@minecraft/bedrock-schemas/catalog.json')));
|
|
34
|
+
const root = skip ? '' : await realpath(options.schemaRoot ?? path.dirname(require.resolve('@minecraft/bedrock-schemas/catalog.json')));
|
|
33
35
|
const catalogFile = path.join(root, 'catalog.json');
|
|
34
|
-
const catalog = JSON.parse(await readFile(catalogFile, 'utf8'));
|
|
36
|
+
const catalog = skip ? { schemas: [] } : JSON.parse(await readFile(catalogFile, 'utf8'));
|
|
35
37
|
const metadataFile = path.join(root, 'package.json');
|
|
36
|
-
const metadata = JSON.parse(await readFile(metadataFile, 'utf8'));
|
|
38
|
+
const metadata = skip ? { version: '' } : JSON.parse(await readFile(metadataFile, 'utf8'));
|
|
39
|
+
const catalogInputs = skip ? [] : [catalogFile, metadataFile];
|
|
37
40
|
const validators = new Map();
|
|
38
41
|
const unavailable = new Map();
|
|
39
42
|
const documents = new Map();
|
|
40
43
|
const referencesByFile = new Map();
|
|
41
|
-
const ajv = new Ajv({ allErrors: true, strict: false, validateFormats: false, logger: false });
|
|
44
|
+
const ajv = skip ? undefined : new Ajv({ allErrors: true, strict: false, validateFormats: false, logger: false });
|
|
42
45
|
async function load(file, inputs) {
|
|
43
46
|
options.signal?.throwIfAborted();
|
|
44
47
|
file = await realpath(file);
|
|
@@ -65,6 +68,52 @@ export async function validatePackContent(options) {
|
|
|
65
68
|
const entry = properties.texture_data.additionalProperties;
|
|
66
69
|
entry.properties.textures = { anyOf: [{ type: 'string' }, entry.properties.textures] };
|
|
67
70
|
}
|
|
71
|
+
if (!options.schemaRoot && metadata.version === '1.26.50') {
|
|
72
|
+
if (file === path.join(root, 'schemas/rp/sounds/index.schema.json')) {
|
|
73
|
+
// Sound definitions accept bare paths and objects with a file name and playback settings.
|
|
74
|
+
const fields = document.properties;
|
|
75
|
+
const events = fields.sound_definitions.additionalProperties;
|
|
76
|
+
const sounds = events.properties.sounds;
|
|
77
|
+
sounds.items = { anyOf: [{ type: 'string', minLength: 1 }, { ...sounds.items, required: ['name'] }] };
|
|
78
|
+
}
|
|
79
|
+
if (file === path.join(root, 'schemas/bp/entities/entity_minecraft_spell_effects.schema.json')) {
|
|
80
|
+
// Effects accept numeric seconds or the documented infinite duration.
|
|
81
|
+
// https://learn.microsoft.com/minecraft/creator/reference/content/entityreference/examples/entitycomponents/minecraftcomponent_spell_effects
|
|
82
|
+
const fields = document.properties;
|
|
83
|
+
const additions = fields.add_effects;
|
|
84
|
+
const item = additions.items;
|
|
85
|
+
const properties = item.properties;
|
|
86
|
+
properties.duration = { anyOf: [properties.duration, { const: 'infinite' }] };
|
|
87
|
+
}
|
|
88
|
+
if (['description.schema.json', 'description_2.schema.json'].some(name => file === path.join(root, 'schemas/rp/entity', name))) {
|
|
89
|
+
// Client entities can mix unconditional controllers and conditional entries.
|
|
90
|
+
const fields = document.properties;
|
|
91
|
+
const controllers = fields.render_controllers;
|
|
92
|
+
const alternatives = controllers.anyOf;
|
|
93
|
+
const items = alternatives.filter(entry => entry.type === 'array').map(entry => entry.items);
|
|
94
|
+
alternatives.push({ type: 'array', items: { anyOf: items } });
|
|
95
|
+
}
|
|
96
|
+
if (file.startsWith(path.join(root, 'schemas/rp/models') + path.sep)) {
|
|
97
|
+
// Geometry vectors accept numeric coordinates and Molang expressions.
|
|
98
|
+
const vectors = new Set(['visible_bounds_offset', 'pivot', 'rotation', 'origin', 'size', 'uv', 'uv_size', 'translation', 'scale']);
|
|
99
|
+
const visit = (value, vector = false) => {
|
|
100
|
+
if (Array.isArray(value)) {
|
|
101
|
+
value.forEach(entry => visit(entry, vector));
|
|
102
|
+
}
|
|
103
|
+
else if (value && typeof value === 'object') {
|
|
104
|
+
const node = value;
|
|
105
|
+
const items = node.items;
|
|
106
|
+
if (vector && node.type === 'array' && items?.type === 'string') {
|
|
107
|
+
items.type = ['string', 'number'];
|
|
108
|
+
}
|
|
109
|
+
for (const [key, entry] of Object.entries(node)) {
|
|
110
|
+
visit(entry, vector || vectors.has(key));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
visit(document);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
68
117
|
function normalize(value) {
|
|
69
118
|
if (Array.isArray(value)) {
|
|
70
119
|
value.forEach(normalize);
|
|
@@ -100,20 +149,20 @@ export async function validatePackContent(options) {
|
|
|
100
149
|
}
|
|
101
150
|
return document;
|
|
102
151
|
}
|
|
103
|
-
async function validator(file) {
|
|
152
|
+
async function validator(file, compiler) {
|
|
104
153
|
const previous = validators.get(file);
|
|
105
154
|
if (previous) {
|
|
106
155
|
return previous;
|
|
107
156
|
}
|
|
108
|
-
const inputs = new Set(
|
|
157
|
+
const inputs = new Set(catalogInputs);
|
|
109
158
|
const document = await load(file, inputs);
|
|
110
159
|
for (const schema of documents.values()) {
|
|
111
160
|
// Register the complete graph before compiling cyclic or shared references.
|
|
112
|
-
if (!
|
|
113
|
-
|
|
161
|
+
if (!compiler.schemas[schema.$id]) {
|
|
162
|
+
compiler.addSchema(schema);
|
|
114
163
|
}
|
|
115
164
|
}
|
|
116
|
-
const validate =
|
|
165
|
+
const validate = compiler.getSchema(document.$id) ?? compiler.compile(document);
|
|
117
166
|
const result = { validate, inputs: [...inputs] };
|
|
118
167
|
validators.set(file, result);
|
|
119
168
|
return result;
|
|
@@ -145,13 +194,13 @@ export async function validatePackContent(options) {
|
|
|
145
194
|
const selected = matches[0];
|
|
146
195
|
let compiled;
|
|
147
196
|
let schemaIssue = selected ? unavailable.get(selected.url) : undefined;
|
|
148
|
-
if (pack.kind === 'resource' && relative === 'texts/languages.json') {
|
|
197
|
+
if (ajv && pack.kind === 'resource' && relative === 'texts/languages.json') {
|
|
149
198
|
const file = fileURLToPath(new URL('../schemas/languages.schema.json', import.meta.url));
|
|
150
|
-
compiled = { validate: ajv.compile(JSON.parse(await readFile(file, 'utf8'))), inputs: [file,
|
|
199
|
+
compiled = { validate: ajv.compile(JSON.parse(await readFile(file, 'utf8'))), inputs: [file, ...catalogInputs] };
|
|
151
200
|
}
|
|
152
|
-
else if (selected && !schemaIssue) {
|
|
201
|
+
else if (ajv && selected && !schemaIssue) {
|
|
153
202
|
try {
|
|
154
|
-
compiled = await validator(path.resolve(root, selected.url));
|
|
203
|
+
compiled = await validator(path.resolve(root, selected.url), ajv);
|
|
155
204
|
}
|
|
156
205
|
catch (error) {
|
|
157
206
|
options.signal?.throwIfAborted();
|
|
@@ -160,11 +209,12 @@ export async function validatePackContent(options) {
|
|
|
160
209
|
unavailable.set(selected.url, schemaIssue);
|
|
161
210
|
}
|
|
162
211
|
}
|
|
163
|
-
const inputs = compiled?.inputs ??
|
|
212
|
+
const inputs = compiled?.inputs ?? catalogInputs;
|
|
164
213
|
async function check() {
|
|
165
214
|
const errors = [];
|
|
166
215
|
const document = parse(await readFile(source, 'utf8'), errors, { allowTrailingComma: true });
|
|
167
216
|
const diagnostics = errors.map(error => ({
|
|
217
|
+
kind: 'syntax',
|
|
168
218
|
pack: pack.id,
|
|
169
219
|
file: relative,
|
|
170
220
|
pointer: '',
|
|
@@ -172,7 +222,7 @@ export async function validatePackContent(options) {
|
|
|
172
222
|
}));
|
|
173
223
|
if (!errors.length && compiled && !compiled.validate(document)) {
|
|
174
224
|
for (const error of compiled.validate.errors ?? []) {
|
|
175
|
-
diagnostics.push({ pack: pack.id, file: relative, pointer: error.instancePath, message: error.message ?? error.keyword });
|
|
225
|
+
diagnostics.push({ kind: 'schema', pack: pack.id, file: relative, pointer: error.instancePath, message: error.message ?? error.keyword });
|
|
176
226
|
}
|
|
177
227
|
}
|
|
178
228
|
return {
|
|
@@ -183,13 +233,13 @@ export async function validatePackContent(options) {
|
|
|
183
233
|
diagnostics,
|
|
184
234
|
};
|
|
185
235
|
}
|
|
186
|
-
const fileRevision = createHash('sha256').update(JSON.stringify({ revision, pack: pack.id, relative, schema: selected?.url, schemaIssue })).digest('hex');
|
|
236
|
+
const fileRevision = createHash('sha256').update(JSON.stringify({ revision, pack: pack.id, relative, skip, schema: selected?.url, schemaIssue })).digest('hex');
|
|
187
237
|
files.push(await (options.reuse?.(source, inputs, fileRevision, check) ?? check()));
|
|
188
238
|
}
|
|
189
239
|
}
|
|
190
240
|
await visit(packRoot);
|
|
191
241
|
}
|
|
192
|
-
const diagnostics = files.flatMap(file => file.diagnostics);
|
|
242
|
+
const diagnostics = files.flatMap(file => file.diagnostics).filter(issue => mode !== 'warn' || issue.kind !== 'schema');
|
|
193
243
|
if (diagnostics.length) {
|
|
194
244
|
throw new ContentValidationError(diagnostics);
|
|
195
245
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock-core/builder-validation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Standalone pack content validation against Mojang's Bedrock schema catalog",
|
|
6
6
|
"exports": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=
|
|
13
|
+
"node": ">=26.13.0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@minecraft/bedrock-schemas": "1.26.50",
|