@bedrock-core/builder 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.
Files changed (46) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/bin/api-library.d.ts +1 -0
  3. package/dist/bin/api-library.js +10 -0
  4. package/dist/bin/audit-paths.d.ts +1 -0
  5. package/dist/bin/audit-paths.js +44 -0
  6. package/dist/bin/build.js +1 -1
  7. package/dist/bin/builder.js +13 -2
  8. package/dist/bin/migrate.js +2 -6
  9. package/dist/bin/plan.js +2 -2
  10. package/dist/bin/watch.js +1 -1
  11. package/dist/package.json +11 -10
  12. package/dist/schemas/config.schema.json +28 -8
  13. package/dist/schemas/guides.schema.json +0 -5
  14. package/dist/schemas/i18n.schema.json +0 -5
  15. package/dist/schemas/pack-manifest.schema.json +243 -0
  16. package/dist/schemas/ui-compiler.schema.json +0 -5
  17. package/dist/src/config.d.ts +7 -3
  18. package/dist/src/config.js +3 -0
  19. package/dist/src/contract.d.ts +2 -0
  20. package/dist/src/export.d.ts +7 -5
  21. package/dist/src/export.js +274 -47
  22. package/dist/src/migrate.js +13 -10
  23. package/dist/src/migration/exports.js +1 -1
  24. package/dist/src/migration/filters.js +3 -2
  25. package/dist/src/migration/local-filter.js +1 -1
  26. package/dist/src/migration/project.js +17 -8
  27. package/dist/src/migration/types.d.ts +0 -2
  28. package/dist/src/path-audit.d.ts +29 -0
  29. package/dist/src/path-audit.js +110 -0
  30. package/dist/src/plan.js +2 -2
  31. package/dist/src/plugin-routing.js +1 -1
  32. package/dist/src/plugins.js +10 -1
  33. package/dist/src/project.d.ts +1 -3
  34. package/dist/src/project.js +1 -12
  35. package/dist/src/regolith.js +2 -2
  36. package/dist/src/run.js +67 -30
  37. package/dist/src/staging.d.ts +4 -0
  38. package/dist/src/staging.js +297 -0
  39. package/dist/src/validation.d.ts +1 -1
  40. package/dist/src/watch.js +48 -20
  41. package/package.json +24 -14
  42. package/schemas/config.schema.json +28 -8
  43. package/schemas/guides.schema.json +0 -5
  44. package/schemas/i18n.schema.json +0 -5
  45. package/schemas/pack-manifest.schema.json +243 -0
  46. package/schemas/ui-compiler.schema.json +0 -5
@@ -1,4 +1,62 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
1
53
  import path from 'node:path';
54
+ import { existsSync } from 'node:fs';
55
+ import { lstat, readFile, readdir, realpath } from 'node:fs/promises';
56
+ import { isStringLiteral } from 'typescript-native/ast';
57
+ import { ModuleResolutionKind } from 'typescript-native/sync';
58
+ import { findConfigFile, moduleResolutionOptions, trackedCompiler } from '@bedrock-core/builder-bundler/dependencies';
59
+ import { planBuild } from './plan.js';
2
60
  const contains = (root, file) => {
3
61
  const relative = path.relative(root, file);
4
62
  return relative === '' || (relative !== '..' && !relative.startsWith('..' + path.sep) && !path.isAbsolute(relative));
@@ -23,3 +81,242 @@ export function stagingExclusions(project, config, configPath = path.join(projec
23
81
  return [...result];
24
82
  }
25
83
  export const isStagingExcluded = (file, exclusions) => exclusions.some(directory => contains(directory, file));
84
+ /** A selected source or one of its ancestors needed to preserve project-relative paths. */
85
+ export const isStagingInput = (file, inputs) => inputs.some(input => contains(input, file) || contains(file, input));
86
+ /** Discover authored inputs without entering unrelated project directories or executing code. */
87
+ export async function stagingInputs(project, config, profile = 'default', configPath = path.join(project, 'config.json'), outputs = [], signal) {
88
+ const env_1 = { stack: [], error: void 0, hasError: false };
89
+ try {
90
+ const exclusions = stagingExclusions(project, config, configPath);
91
+ const roots = new Set();
92
+ const pending = [];
93
+ const visited = new Set();
94
+ let wholeProject = false;
95
+ const normalized = (file) => process.platform === 'win32' ? file.toLowerCase() : file;
96
+ const ignored = (file) => !contains(project, file)
97
+ || path.relative(project, file).split(path.sep).some(part => ['.git', 'node_modules', '.bedrock-core'].includes(part) || part.includes('.builder-data-'))
98
+ || isStagingExcluded(file, exclusions)
99
+ || outputs.some(output => contains(output, file) || normalized(file).startsWith(`${normalized(output)}.builder-`));
100
+ function add(file, module = false) {
101
+ file = path.resolve(project, file);
102
+ if (ignored(file) || (file === project && !wholeProject)) {
103
+ return;
104
+ }
105
+ if (module && file !== project && path.dirname(file) !== project) {
106
+ file = path.dirname(file);
107
+ }
108
+ if (ignored(file)) {
109
+ return;
110
+ }
111
+ if (!roots.has(file)) {
112
+ roots.add(file);
113
+ pending.push(file);
114
+ }
115
+ }
116
+ add(configPath);
117
+ add('package.json');
118
+ for (const entry of await readdir(project, { withFileTypes: true })) {
119
+ if (entry.isFile() && (/^tsconfig(?:\..+)?\.json$/i.test(entry.name) || /\.d\.[cm]?ts$/i.test(entry.name)
120
+ || /^(?:licen[sc]e|copying)(?:\.(?:txt|md))?$/i.test(entry.name))) {
121
+ add(entry.name);
122
+ }
123
+ }
124
+ for (const source of config.bedrockCore.staging?.include ?? []) {
125
+ if (path.isAbsolute(source) || path.win32.isAbsolute(source) || /^[A-Za-z]:/.test(source) || /[*?\0]/.test(source)
126
+ || !contains(project, path.resolve(project, source.replaceAll('\\', '/')))) {
127
+ throw new Error(`Staging inputs must be literal project-relative paths: ${source}`);
128
+ }
129
+ const input = path.resolve(project, source.replaceAll('\\', '/'));
130
+ if (input === project) {
131
+ wholeProject = true;
132
+ }
133
+ add(input);
134
+ }
135
+ for (const source of Object.values(config.packs)) {
136
+ add(source);
137
+ }
138
+ for (const source of config.bedrockCore.profiles[profile]?.watch?.paths ?? []) {
139
+ add(source);
140
+ }
141
+ const stages = config.bedrockCore.profiles[profile]?.stages;
142
+ const generator = stages?.generator;
143
+ const selectors = typeof generator === 'object' ? generator.include : undefined;
144
+ for (const source of [selectors ?? []].flat()) {
145
+ if (typeof source === 'string' && !/[*?[\]{}()]/.test(source)) {
146
+ add(source);
147
+ }
148
+ }
149
+ const ui = stages?.['ui-compiler'];
150
+ const screens = typeof ui === 'object' && Array.isArray(ui.screens) ? ui.screens : [];
151
+ const manifest = stages?.manifest;
152
+ const manifestPaths = typeof manifest === 'object' ? manifest.manifestPath : undefined;
153
+ for (const source of typeof manifestPaths === 'string' ? [manifestPaths] : Array.isArray(manifestPaths) ? manifestPaths : []) {
154
+ if (typeof source === 'string') {
155
+ add(source);
156
+ }
157
+ }
158
+ for (const step of planBuild(config, profile)) {
159
+ if (step.kind !== 'plugin') {
160
+ continue;
161
+ }
162
+ if (step.module !== undefined) {
163
+ if (step.module.startsWith('.') || path.isAbsolute(step.module)) {
164
+ add(step.module, true);
165
+ }
166
+ }
167
+ else {
168
+ add(path.resolve(project, step.filterDir ?? '.', step.script), true);
169
+ add(step.dataPath ?? 'data');
170
+ }
171
+ }
172
+ try {
173
+ const metadata = JSON.parse(await readFile(path.join(project, 'package.json'), 'utf8'));
174
+ const visit = (entry) => {
175
+ if (typeof entry === 'string' && entry.startsWith('./')) {
176
+ add(entry, true);
177
+ }
178
+ else if (entry && typeof entry === 'object') {
179
+ Object.values(entry).forEach(visit);
180
+ }
181
+ };
182
+ visit(metadata.exports);
183
+ }
184
+ catch (error) {
185
+ if (error.code !== 'ENOENT') {
186
+ throw error;
187
+ }
188
+ }
189
+ const bundler = stages?.bundler;
190
+ const explicitConfig = typeof bundler === 'object' && typeof bundler.tsconfig === 'string' ? path.resolve(project, bundler.tsconfig) : undefined;
191
+ const resolvers = new Map();
192
+ const nearest = new Map();
193
+ const defaults = { moduleResolution: ModuleResolutionKind.Bundler, allowJs: true, resolveJsonModule: true };
194
+ const api = __addDisposableResource(env_1, trackedCompiler(add, (directory) => {
195
+ if (!ignored(directory) && !existsSync(directory)) {
196
+ add(directory);
197
+ }
198
+ }), false);
199
+ function resolverFor(directory) {
200
+ if (!explicitConfig && !nearest.has(directory)) {
201
+ nearest.set(directory, findConfigFile(directory, add, 'tsconfig.json', project));
202
+ }
203
+ const configFile = explicitConfig ?? nearest.get(directory);
204
+ const cached = resolvers.get(configFile);
205
+ if (cached) {
206
+ return cached;
207
+ }
208
+ const parsed = configFile ? api.parseConfigFile(configFile) : undefined;
209
+ const resolver = api.createModuleResolver(parsed ? { ...defaults, ...moduleResolutionOptions(parsed.options) } : defaults);
210
+ resolvers.set(configFile, resolver);
211
+ if (configFile) {
212
+ const raw = parsed?.raw;
213
+ const directory = path.dirname(configFile);
214
+ for (const source of Array.isArray(raw?.files) ? raw.files : []) {
215
+ if (typeof source === 'string') {
216
+ add(path.resolve(directory, source));
217
+ }
218
+ }
219
+ for (const pattern of Array.isArray(raw?.include) ? raw.include : []) {
220
+ if (typeof pattern === 'string') {
221
+ const prefix = pattern.split(/[*?]/)[0];
222
+ if (prefix && prefix !== './' && prefix !== '.') {
223
+ add(path.resolve(directory, prefix));
224
+ }
225
+ }
226
+ }
227
+ }
228
+ return resolver;
229
+ }
230
+ async function scan(file) {
231
+ signal?.throwIfAborted();
232
+ if (ignored(file) || visited.has(file)) {
233
+ return;
234
+ }
235
+ visited.add(file);
236
+ let info;
237
+ try {
238
+ info = await lstat(file);
239
+ }
240
+ catch (error) {
241
+ if (['ENOENT', 'ENOTDIR'].includes(error.code ?? '')) {
242
+ return;
243
+ }
244
+ throw error;
245
+ }
246
+ if (info.isSymbolicLink() || path.relative(await realpath(file), file) !== '') {
247
+ throw new Error(`Symlinks are unsupported in staged sources: ${file}`);
248
+ }
249
+ if (info.isDirectory()) {
250
+ for (const entry of await readdir(file, { withFileTypes: true })) {
251
+ await scan(path.join(file, entry.name));
252
+ }
253
+ }
254
+ else if (/\.[cm]?[jt]sx?$/i.test(file)) {
255
+ const env_2 = { stack: [], error: void 0, hasError: false };
256
+ try {
257
+ const parsed = __addDisposableResource(env_2, api.createSourceFile(file, await readFile(file, 'utf8')), false);
258
+ const source = parsed.sourceFile;
259
+ for (const reference of source.referencedFiles) {
260
+ add(path.resolve(path.dirname(file), reference.fileName));
261
+ }
262
+ for (const reference of source.typeReferenceDirectives) {
263
+ if (reference.fileName.startsWith('.')) {
264
+ add(path.resolve(path.dirname(file), reference.fileName));
265
+ }
266
+ }
267
+ const directory = path.dirname(file);
268
+ for (const imported of source.imports) {
269
+ if (!isStringLiteral(imported)) {
270
+ continue;
271
+ }
272
+ const resolution = resolverFor(directory).resolveModuleName(imported.text, directory).resolvedModule;
273
+ if (resolution) {
274
+ add(resolution.resolvedFileName);
275
+ }
276
+ }
277
+ }
278
+ catch (e_2) {
279
+ env_2.error = e_2;
280
+ env_2.hasError = true;
281
+ }
282
+ finally {
283
+ __disposeResources(env_2);
284
+ }
285
+ }
286
+ else if (file.endsWith('.json')) {
287
+ let document;
288
+ try {
289
+ document = JSON.parse(await readFile(file, 'utf8'));
290
+ }
291
+ catch {
292
+ // Stages own syntax diagnostics, including JSON templates awaiting expansion.
293
+ return;
294
+ }
295
+ if (typeof document?.extends === 'string' && /^\.\.?[\\/]/.test(document.extends)) {
296
+ add(path.resolve(path.dirname(file), document.extends));
297
+ }
298
+ }
299
+ }
300
+ resolverFor(project);
301
+ for (const source of screens) {
302
+ if (typeof source === 'string' && source.startsWith('.')) {
303
+ add(source);
304
+ const resolved = resolverFor(project).resolveModuleName(source, project).resolvedModule;
305
+ if (resolved) {
306
+ add(resolved.resolvedFileName);
307
+ }
308
+ }
309
+ }
310
+ for (let index = 0; index < pending.length; index++) {
311
+ await scan(pending[index]);
312
+ }
313
+ return [...roots].filter(file => ![...roots].some(other => other !== file && contains(other, file)));
314
+ }
315
+ catch (e_1) {
316
+ env_1.error = e_1;
317
+ env_1.hasError = true;
318
+ }
319
+ finally {
320
+ __disposeResources(env_1);
321
+ }
322
+ }
@@ -1,2 +1,2 @@
1
1
  export { validatePackContent, ContentValidationError } from '@bedrock-core/builder-validation';
2
- export type { ContentPack, ContentDiagnostic, ContentFileResult, ContentValidationOptions, ContentValidationResult } from '@bedrock-core/builder-validation';
2
+ export type { ContentPack, ContentDiagnostic, ContentFileResult, ContentValidationMode, ContentValidationOptions, ContentValidationResult } from '@bedrock-core/builder-validation';
package/dist/src/watch.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { watch } from 'node:fs';
2
2
  import { lstat, readFile, readdir, realpath, stat } from 'node:fs/promises';
3
3
  import path from 'node:path';
4
- import { validateConfig } from "./config.js";
5
- import { isStagingExcluded, stagingExclusions } from "./staging.js";
6
- import { resolveExportPaths } from "./export.js";
7
- import { runBuild } from "./run.js";
8
- import { inputLocations } from "./file-cache.js";
9
- import { observeSourceWrites } from "./source-writes.js";
4
+ import { validateConfig } from './config.js';
5
+ import { isStagingExcluded, isStagingInput, stagingExclusions, stagingInputs } from './staging.js';
6
+ import { resolveExportPaths, resolveApiPackagePath } from './export.js';
7
+ import { hasApiExports } from '@bedrock-core/builder-manifest';
8
+ import { runBuild } from './run.js';
9
+ import { inputLocations } from './file-cache.js';
10
+ import { observeSourceWrites } from './source-writes.js';
10
11
  function contains(root, file) {
11
12
  const relative = path.relative(root, file);
12
13
  return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
@@ -26,12 +27,14 @@ export async function watchBuild(options) {
26
27
  const project = path.dirname(configPath);
27
28
  const external = new Map();
28
29
  const recursiveExternal = new Map();
30
+ const externalIdentities = new Map();
29
31
  let externalTargets = new Map();
30
32
  let outputRoots = new Set();
31
33
  let extraPaths = [];
32
34
  let exclusions = [];
33
35
  let dependencies = [];
34
36
  let dependencyLocations = new Set();
37
+ let sourceRoots = [configPath, path.join(project, 'package.json'), path.join(project, 'tsconfig.json')];
35
38
  let debounceMs = 100;
36
39
  let dirty = false;
37
40
  let stopped = false;
@@ -41,8 +44,17 @@ export async function watchBuild(options) {
41
44
  const signatures = new Map();
42
45
  const ownedWrites = new Set();
43
46
  let removeAbortListener = () => { };
44
- function exportRoots(config) {
47
+ async function exportRoots(config) {
45
48
  const selected = config.bedrockCore.profiles[profile];
49
+ let metadata;
50
+ try {
51
+ metadata = JSON.parse(await readFile(path.join(project, 'package.json'), 'utf8'));
52
+ }
53
+ catch (error) {
54
+ if (error.code !== 'ENOENT') {
55
+ throw error;
56
+ }
57
+ }
46
58
  if (selected?.export) {
47
59
  resolveExportPaths(project, config.packs, selected.export);
48
60
  }
@@ -51,7 +63,8 @@ export async function watchBuild(options) {
51
63
  return [];
52
64
  }
53
65
  try {
54
- return Object.values(resolveExportPaths(project, config.packs, settings.export));
66
+ const paths = resolveExportPaths(project, config.packs, settings.export);
67
+ return [...Object.values(paths), ...(hasApiExports(metadata) && settings.api !== false ? [resolveApiPackagePath(project, config.packs, paths, settings.api ?? 'dist/api')] : [])];
55
68
  }
56
69
  catch {
57
70
  return [];
@@ -72,7 +85,8 @@ export async function watchBuild(options) {
72
85
  return true;
73
86
  }
74
87
  }
75
- return false;
88
+ return file !== project && !isStagingInput(file, sourceRoots)
89
+ && !dependencies.some(dependency => dependency !== project && contains(dependency, file));
76
90
  }
77
91
  function report(error) {
78
92
  logger.error?.(`@bedrock-core/builder: ${error instanceof Error ? error.message : String(error)}`);
@@ -99,7 +113,7 @@ export async function watchBuild(options) {
99
113
  }, debounceMs);
100
114
  }
101
115
  async function updateExternalWatchers() {
102
- const targets = new Set([...extraPaths, ...dependencies].filter(file => !contains(project, file) || path.relative(project, file).split(path.sep).includes('node_modules')));
116
+ const targets = new Set([...sourceRoots, ...extraPaths, ...dependencies].filter(file => !contains(project, file) || path.relative(project, file).split(path.sep).includes('node_modules') || !ignored(file)));
103
117
  const directories = new Map();
104
118
  for (const target of targets) {
105
119
  let directory = dependencyLocations.has(target) ? path.dirname(target) : target;
@@ -126,11 +140,15 @@ export async function watchBuild(options) {
126
140
  watcher.close();
127
141
  external.delete(directory);
128
142
  recursiveExternal.delete(directory);
143
+ externalIdentities.delete(directory);
129
144
  }
130
145
  }
131
146
  for (const directory of externalTargets.keys()) {
132
- const recursive = [...externalTargets.get(directory)].some(target => target === directory && !dependencyLocations.has(target));
133
- if (external.has(directory) && recursiveExternal.get(directory) === recursive) {
147
+ const recursive = [...externalTargets.get(directory)].some(target => target === directory && !dependencyLocations.has(target)
148
+ && (directory !== project || sourceRoots.includes(project)));
149
+ const info = await stat(directory);
150
+ const identity = `${info.dev}:${info.ino}`;
151
+ if (external.has(directory) && recursiveExternal.get(directory) === recursive && externalIdentities.get(directory) === identity) {
134
152
  continue;
135
153
  }
136
154
  external.get(directory)?.close();
@@ -138,17 +156,24 @@ export async function watchBuild(options) {
138
156
  const changed = filename ? path.resolve(directory, filename.toString()) : directory;
139
157
  const relevant = [...(externalTargets.get(directory) ?? [])].some(target => contains(target, changed) || contains(changed, target));
140
158
  if (relevant && ![...outputRoots].some(root => contains(root, changed))) {
141
- requestBuild();
159
+ if (contains(project, changed) && !path.relative(project, changed).split(path.sep).includes('node_modules')) {
160
+ void changedInput(changed).catch(report);
161
+ }
162
+ else {
163
+ requestBuild();
164
+ }
142
165
  }
143
166
  });
144
167
  watcher.on('error', (error) => {
145
168
  watcher.close();
146
169
  external.delete(directory);
147
170
  recursiveExternal.delete(directory);
171
+ externalIdentities.delete(directory);
148
172
  report(error);
149
173
  });
150
174
  external.set(directory, watcher);
151
175
  recursiveExternal.set(directory, recursive);
176
+ externalIdentities.set(directory, identity);
152
177
  }
153
178
  }
154
179
  async function rebuild() {
@@ -160,7 +185,7 @@ export async function watchBuild(options) {
160
185
  if (!settings) {
161
186
  throw new Error(`Unknown profile: ${profile}`);
162
187
  }
163
- const roots = new Set(exportRoots(config));
188
+ const roots = new Set(await exportRoots(config));
164
189
  exclusions = stagingExclusions(project, config, configPath);
165
190
  const generator = settings.stages?.generator;
166
191
  if (generator && typeof generator === 'object' && generator.types !== false && typeof generator.typesDir === 'string' && generator.typesDir) {
@@ -168,6 +193,7 @@ export async function watchBuild(options) {
168
193
  }
169
194
  // Retain former outputs as ignored paths after profile edits.
170
195
  outputRoots = new Set([...outputRoots, ...roots]);
196
+ sourceRoots = await stagingInputs(project, config, profile, configPath, [...outputRoots], signal);
171
197
  debounceMs = settings.watch?.debounceMs ?? 100;
172
198
  extraPaths = (settings.watch?.paths ?? []).map(file => path.resolve(project, file));
173
199
  await updateExternalWatchers();
@@ -202,7 +228,7 @@ export async function watchBuild(options) {
202
228
  }
203
229
  visible.push(`${entry.name}:${entry.isDirectory() ? 'directory' : 'file'}`);
204
230
  }
205
- return visible.sort().join('|');
231
+ return visible.length ? `${info.ino}:${visible.sort().join('|')}` : '';
206
232
  }
207
233
  return `${info.mtimeNs}:${info.size}:${info.ino}`;
208
234
  }
@@ -228,7 +254,7 @@ export async function watchBuild(options) {
228
254
  }
229
255
  }
230
256
  }
231
- async function changed(file) {
257
+ async function changedInput(file) {
232
258
  // Windows may emit unchanged directory events while recursive watches are attached.
233
259
  file = file.startsWith('\\\\?\\') ? file.slice(4) : file;
234
260
  if (ignored(file) || [...ownedWrites].some(root => contains(root, file))) {
@@ -240,7 +266,7 @@ export async function watchBuild(options) {
240
266
  }
241
267
  const previous = signatures.get(file);
242
268
  // A new empty directory may contain only ignored output paths.
243
- if (current === '' && (previous === undefined || previous === 'missing')) {
269
+ if (current === '' && (previous === undefined || previous === 'missing') && !sourceRoots.some(root => contains(file, root))) {
244
270
  signatures.set(file, current);
245
271
  return;
246
272
  }
@@ -253,9 +279,10 @@ export async function watchBuild(options) {
253
279
  const config = validateConfig(JSON.parse(await readFile(configPath, 'utf8')));
254
280
  const settings = config.bedrockCore.profiles[profile];
255
281
  exclusions = stagingExclusions(project, config, configPath);
256
- for (const directory of exportRoots(config)) {
282
+ for (const directory of await exportRoots(config)) {
257
283
  outputRoots.add(directory);
258
284
  }
285
+ sourceRoots = await stagingInputs(project, config, profile, configPath, [...outputRoots], signal);
259
286
  const generator = settings?.stages?.generator;
260
287
  if (generator && typeof generator === 'object' && generator.types !== false && typeof generator.typesDir === 'string' && generator.typesDir) {
261
288
  outputRoots.add(path.resolve(project, generator.typesDir));
@@ -265,9 +292,9 @@ export async function watchBuild(options) {
265
292
  // A malformed config stays observable so editing it can recover the build.
266
293
  }
267
294
  await snapshot(project);
268
- const watcher = watch(project, { recursive: true }, (_event, filename) => {
295
+ const watcher = watch(project, { recursive: false }, (_event, filename) => {
269
296
  const file = filename ? path.resolve(project, filename.toString()) : project;
270
- void changed(file).catch(report);
297
+ void changedInput(file).catch(report);
271
298
  });
272
299
  const stopObservingWrites = observeSourceWrites(project, (writes) => {
273
300
  const directories = writes.map(write => write.directory);
@@ -285,6 +312,7 @@ export async function watchBuild(options) {
285
312
  await snapshot(directory);
286
313
  signatures.set(path.dirname(directory), await signature(path.dirname(directory)));
287
314
  }
315
+ await updateExternalWatchers();
288
316
  if ((await Promise.all(writes.map(write => write.matches()))).some(matches => !matches)) {
289
317
  requestBuild();
290
318
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@bedrock-core/builder",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Build one or many Minecraft Bedrock packs from a JavaScript or TypeScript project",
6
6
  "exports": {
7
7
  "./schemas/config.schema.json": "./schemas/config.schema.json",
8
+ "./schemas/pack-manifest.schema.json": "./schemas/pack-manifest.schema.json",
8
9
  "./export": {
9
10
  "types": "./dist/src/export.d.ts",
10
11
  "default": "./dist/src/export.js"
@@ -48,7 +49,7 @@
48
49
  "test": "node --test",
49
50
  "plan": "node bin/plan.ts",
50
51
  "build": "node bin/build.ts",
51
- "typecheck": "tsc --noEmit",
52
+ "typecheck": "node node_modules/typescript-native/bin/tsc --noEmit",
52
53
  "lint": "eslint . --max-warnings=0",
53
54
  "lint:fix": "eslint . --fix --max-warnings=0",
54
55
  "format": "eslint . --fix --max-warnings=0",
@@ -62,31 +63,39 @@
62
63
  "prepare-release": "node scripts/prepare-release.ts",
63
64
  "pack-release": "yarn prepare-release && node scripts/pack-release.ts",
64
65
  "test:packages": "node scripts/verify-packages.ts",
66
+ "prepare:acceptance": "node scripts/prepare-acceptance.ts",
65
67
  "acceptance": "node scripts/acceptance.ts",
66
68
  "acceptance:native": "node scripts/acceptance.ts --native",
69
+ "acceptance:api": "node scripts/api-acceptance.ts",
70
+ "acceptance:api:native": "node scripts/api-acceptance.ts --native",
71
+ "acceptance:api-packages": "node scripts/api-package-acceptance.mjs",
72
+ "acceptance:api-packages:native": "node scripts/api-package-acceptance.mjs --native",
73
+ "acceptance:navigation-api": "node scripts/navigation-api-acceptance.mjs",
74
+ "acceptance:navigation-api:native": "node scripts/navigation-api-acceptance.mjs --native",
67
75
  "release": "yarn check && yarn acceptance && yarn pack-release && yarn test:packages",
68
76
  "publish-release": "node scripts/publish-release.ts",
69
77
  "changeset": "changeset",
70
78
  "changeset:status": "changeset status --verbose",
71
- "version:packages": "changeset version",
79
+ "version:packages": "changeset version && node scripts/sync-cli-template.mjs --builder-only && yarn install --mode=update-lockfile",
72
80
  "tag-release": "node scripts/tag-release.ts",
73
- "test:release": "node --test scripts/publish-release.test.ts scripts/cli-artifact.test.mjs scripts/sync-cli-template.test.mjs scripts/release-versions.test.ts",
81
+ "test:release": "node --test scripts/publish-release.test.ts scripts/cli-artifact.test.mjs scripts/sync-cli-template.test.mjs scripts/release-versions.test.ts scripts/acceptance-archives.test.ts",
74
82
  "publish:ci": "yarn publish-release --scope \"$RELEASE_SCOPE\" && yarn tag-release --scope \"$RELEASE_SCOPE\""
75
83
  },
76
84
  "engines": {
77
- "node": ">=22.18"
85
+ "node": ">=26.13.0"
78
86
  },
79
87
  "dependencies": {
80
- "@bedrock-core/builder-bundler": "0.1.0",
81
- "@bedrock-core/builder-generator": "0.1.0",
82
- "@bedrock-core/builder-guides": "0.1.1",
83
- "@bedrock-core/builder-i18n": "0.1.0",
84
- "@bedrock-core/builder-manifest": "0.1.0",
85
- "@bedrock-core/builder-plugin": "0.1.0",
86
- "@bedrock-core/builder-ui": "0.2.0",
87
- "@bedrock-core/builder-validation": "0.1.1",
88
+ "@bedrock-core/builder-bundler": "0.2.0",
89
+ "@bedrock-core/builder-generator": "0.2.0",
90
+ "@bedrock-core/builder-guides": "0.2.0",
91
+ "@bedrock-core/builder-i18n": "0.2.0",
92
+ "@bedrock-core/builder-manifest": "0.2.0",
93
+ "@bedrock-core/builder-plugin": "0.2.0",
94
+ "@bedrock-core/builder-ui": "0.3.0",
95
+ "@bedrock-core/builder-validation": "0.2.0",
88
96
  "@types/node": "25.9.9",
89
- "ajv": "8.17.1"
97
+ "ajv": "8.17.1",
98
+ "typescript-native": "npm:typescript@7.1.0-beta"
90
99
  },
91
100
  "devDependencies": {
92
101
  "@changesets/cli": "3.0.3",
@@ -123,6 +132,7 @@
123
132
  },
124
133
  "exports": {
125
134
  "./schemas/config.schema.json": "./schemas/config.schema.json",
135
+ "./schemas/pack-manifest.schema.json": "./schemas/pack-manifest.schema.json",
126
136
  "./export": {
127
137
  "types": "./dist/src/export.d.ts",
128
138
  "default": "./dist/src/export.js"
@@ -3,9 +3,13 @@
3
3
  "title": "@bedrock-core project configuration",
4
4
  "description": "Minecraft Bedrock project metadata and @bedrock-core profiles.",
5
5
  "type": "object",
6
+ "not": {
7
+ "required": [
8
+ "namespace"
9
+ ]
10
+ },
6
11
  "required": [
7
12
  "targetVersion",
8
- "namespace",
9
13
  "name",
10
14
  "authors",
11
15
  "packs",
@@ -19,13 +23,6 @@
19
23
  "targetVersion": {
20
24
  "$ref": "#/definitions/nonempty"
21
25
  },
22
- "namespace": {
23
- "type": "string",
24
- "pattern": "^[a-z0-9_]+$",
25
- "not": {
26
- "const": "minecraft"
27
- }
28
- },
29
26
  "name": {
30
27
  "$ref": "#/definitions/nonempty"
31
28
  },
@@ -124,6 +121,12 @@
124
121
  "type": "object",
125
122
  "additionalProperties": false,
126
123
  "properties": {
124
+ "include": {
125
+ "type": "array",
126
+ "uniqueItems": true,
127
+ "items": { "$ref": "#/definitions/nonempty" },
128
+ "description": "Additional literal project-relative files or directories copied into staging and observed by watch mode, including plugin data read without imports."
129
+ },
127
130
  "exclude": {
128
131
  "type": "array",
129
132
  "uniqueItems": true,
@@ -418,6 +421,23 @@
418
421
  "type": "boolean",
419
422
  "default": true,
420
423
  "description": "Reuse deterministic compiler output when its inputs match. Set false to rebuild it."
424
+ },
425
+ "validation": {
426
+ "enum": ["strict", "warn", "skip"],
427
+ "default": "warn",
428
+ "description": "Content schema validation mode. JSON syntax and pack manifests are always checked."
429
+ },
430
+ "api": {
431
+ "description": "Portable addon API package output; defaults to dist/api when public addon exports are declared. Set false to disable.",
432
+ "anyOf": [
433
+ {
434
+ "const": false
435
+ },
436
+ {
437
+ "type": "string",
438
+ "pattern": "\\S"
439
+ }
440
+ ]
421
441
  }
422
442
  }
423
443
  },
@@ -8,11 +8,6 @@
8
8
  "type": "boolean",
9
9
  "description": "Stage override for the profile debug setting."
10
10
  },
11
- "namespace": {
12
- "type": "string",
13
- "pattern": "^[a-z0-9_]+$",
14
- "description": "Overrides the project namespace for guide keys."
15
- },
16
11
  "sourceDir": {
17
12
  "type": "string",
18
13
  "minLength": 1,