@bedrock-core/builder-validation 0.1.1 → 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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @bedrock-core/builder-validation
2
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
+
3
14
  ## 0.1.1
4
15
 
5
16
  ### Patch Changes
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock-core/builder-validation",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@minecraft/bedrock-schemas": "1.26.50",
@@ -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 every JSON document; catalog matches additionally receive schema checks.
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 Schema catalog version and per-file coverage; invalid documents throw ContentValidationError.
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 every JSON document; catalog matches additionally receive schema checks.
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 Schema catalog version and per-file coverage; invalid documents throw ContentValidationError.
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);
@@ -66,6 +69,13 @@ export async function validatePackContent(options) {
66
69
  entry.properties.textures = { anyOf: [{ type: 'string' }, entry.properties.textures] };
67
70
  }
68
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
+ }
69
79
  if (file === path.join(root, 'schemas/bp/entities/entity_minecraft_spell_effects.schema.json')) {
70
80
  // Effects accept numeric seconds or the documented infinite duration.
71
81
  // https://learn.microsoft.com/minecraft/creator/reference/content/entityreference/examples/entitycomponents/minecraftcomponent_spell_effects
@@ -139,20 +149,20 @@ export async function validatePackContent(options) {
139
149
  }
140
150
  return document;
141
151
  }
142
- async function validator(file) {
152
+ async function validator(file, compiler) {
143
153
  const previous = validators.get(file);
144
154
  if (previous) {
145
155
  return previous;
146
156
  }
147
- const inputs = new Set([catalogFile, metadataFile]);
157
+ const inputs = new Set(catalogInputs);
148
158
  const document = await load(file, inputs);
149
159
  for (const schema of documents.values()) {
150
160
  // Register the complete graph before compiling cyclic or shared references.
151
- if (!ajv.schemas[schema.$id]) {
152
- ajv.addSchema(schema);
161
+ if (!compiler.schemas[schema.$id]) {
162
+ compiler.addSchema(schema);
153
163
  }
154
164
  }
155
- const validate = ajv.getSchema(document.$id) ?? ajv.compile(document);
165
+ const validate = compiler.getSchema(document.$id) ?? compiler.compile(document);
156
166
  const result = { validate, inputs: [...inputs] };
157
167
  validators.set(file, result);
158
168
  return result;
@@ -184,13 +194,13 @@ export async function validatePackContent(options) {
184
194
  const selected = matches[0];
185
195
  let compiled;
186
196
  let schemaIssue = selected ? unavailable.get(selected.url) : undefined;
187
- if (pack.kind === 'resource' && relative === 'texts/languages.json') {
197
+ if (ajv && pack.kind === 'resource' && relative === 'texts/languages.json') {
188
198
  const file = fileURLToPath(new URL('../schemas/languages.schema.json', import.meta.url));
189
- compiled = { validate: ajv.compile(JSON.parse(await readFile(file, 'utf8'))), inputs: [file, catalogFile, metadataFile] };
199
+ compiled = { validate: ajv.compile(JSON.parse(await readFile(file, 'utf8'))), inputs: [file, ...catalogInputs] };
190
200
  }
191
- else if (selected && !schemaIssue) {
201
+ else if (ajv && selected && !schemaIssue) {
192
202
  try {
193
- compiled = await validator(path.resolve(root, selected.url));
203
+ compiled = await validator(path.resolve(root, selected.url), ajv);
194
204
  }
195
205
  catch (error) {
196
206
  options.signal?.throwIfAborted();
@@ -199,11 +209,12 @@ export async function validatePackContent(options) {
199
209
  unavailable.set(selected.url, schemaIssue);
200
210
  }
201
211
  }
202
- const inputs = compiled?.inputs ?? [catalogFile, metadataFile];
212
+ const inputs = compiled?.inputs ?? catalogInputs;
203
213
  async function check() {
204
214
  const errors = [];
205
215
  const document = parse(await readFile(source, 'utf8'), errors, { allowTrailingComma: true });
206
216
  const diagnostics = errors.map(error => ({
217
+ kind: 'syntax',
207
218
  pack: pack.id,
208
219
  file: relative,
209
220
  pointer: '',
@@ -211,7 +222,7 @@ export async function validatePackContent(options) {
211
222
  }));
212
223
  if (!errors.length && compiled && !compiled.validate(document)) {
213
224
  for (const error of compiled.validate.errors ?? []) {
214
- 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 });
215
226
  }
216
227
  }
217
228
  return {
@@ -222,13 +233,13 @@ export async function validatePackContent(options) {
222
233
  diagnostics,
223
234
  };
224
235
  }
225
- 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');
226
237
  files.push(await (options.reuse?.(source, inputs, fileRevision, check) ?? check()));
227
238
  }
228
239
  }
229
240
  await visit(packRoot);
230
241
  }
231
- const diagnostics = files.flatMap(file => file.diagnostics);
242
+ const diagnostics = files.flatMap(file => file.diagnostics).filter(issue => mode !== 'warn' || issue.kind !== 'schema');
232
243
  if (diagnostics.length) {
233
244
  throw new ContentValidationError(diagnostics);
234
245
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrock-core/builder-validation",
3
- "version": "0.1.1",
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": ">=22.18"
13
+ "node": ">=26.13.0"
14
14
  },
15
15
  "dependencies": {
16
16
  "@minecraft/bedrock-schemas": "1.26.50",