@bedrock-core/builder 0.1.2 → 0.3.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 +84 -1
- package/dist/bin/api-library.d.ts +1 -0
- package/dist/bin/api-library.js +10 -0
- package/dist/bin/audit-paths.d.ts +1 -0
- package/dist/bin/audit-paths.js +44 -0
- package/dist/bin/build.js +1 -1
- package/dist/bin/builder.js +13 -2
- package/dist/bin/migrate.js +1 -15
- package/dist/bin/plan.js +2 -2
- package/dist/bin/watch.js +1 -1
- package/dist/package.json +12 -10
- package/dist/schemas/bundler.schema.json +5 -0
- package/dist/schemas/config.schema.json +40 -10
- package/dist/schemas/generator.schema.json +11 -29
- package/dist/schemas/guides.schema.json +0 -5
- package/dist/schemas/i18n.schema.json +0 -5
- package/dist/schemas/pack-manifest.schema.json +294 -0
- package/dist/schemas/ui-compiler.schema.json +0 -15
- package/dist/src/config.d.ts +21 -7
- package/dist/src/config.js +3 -0
- package/dist/src/contract.d.ts +5 -2
- package/dist/src/export.d.ts +7 -5
- package/dist/src/export.js +274 -47
- package/dist/src/migrate.d.ts +1 -1
- package/dist/src/migrate.js +23 -17
- package/dist/src/migration/exports.js +1 -1
- package/dist/src/migration/filters.d.ts +4 -7
- package/dist/src/migration/filters.js +41 -234
- package/dist/src/migration/project.d.ts +1 -2
- package/dist/src/migration/project.js +35 -25
- package/dist/src/migration/types.d.ts +1 -8
- package/dist/src/path-audit.d.ts +29 -0
- package/dist/src/path-audit.js +110 -0
- package/dist/src/plan.d.ts +1 -0
- package/dist/src/plan.js +7 -7
- package/dist/src/plugin-routing.js +1 -1
- package/dist/src/plugins.js +10 -1
- package/dist/src/project.d.ts +1 -3
- package/dist/src/project.js +1 -12
- package/dist/src/regolith.d.ts +3 -3
- package/dist/src/regolith.js +26 -4
- package/dist/src/run.js +86 -38
- package/dist/src/staging.d.ts +4 -0
- package/dist/src/staging.js +305 -0
- package/dist/src/validation.d.ts +1 -1
- package/dist/src/watch.js +48 -29
- package/package.json +41 -20
- package/schemas/bundler.schema.json +5 -0
- package/schemas/config.schema.json +40 -10
- package/schemas/generator.schema.json +11 -29
- package/schemas/guides.schema.json +0 -5
- package/schemas/i18n.schema.json +0 -5
- package/schemas/pack-manifest.schema.json +294 -0
- package/schemas/ui-compiler.schema.json +0 -15
- package/dist/src/migration/local-filter.d.ts +0 -3
- package/dist/src/migration/local-filter.js +0 -20
package/dist/src/staging.js
CHANGED
|
@@ -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,250 @@ 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
|
+
if (step.script !== undefined) {
|
|
169
|
+
add(path.resolve(project, step.filterDir ?? '.', step.script), true);
|
|
170
|
+
}
|
|
171
|
+
add(step.dataPath ?? 'data');
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const metadata = JSON.parse(await readFile(path.join(project, 'package.json'), 'utf8'));
|
|
176
|
+
const visit = (entry) => {
|
|
177
|
+
if (typeof entry === 'string' && entry.startsWith('./')) {
|
|
178
|
+
add(entry, true);
|
|
179
|
+
}
|
|
180
|
+
else if (entry && typeof entry === 'object') {
|
|
181
|
+
Object.values(entry).forEach(visit);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
visit(metadata.exports);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (error.code !== 'ENOENT') {
|
|
188
|
+
throw error;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const bundler = stages?.bundler;
|
|
192
|
+
const explicitConfig = typeof bundler === 'object' && typeof bundler.tsconfig === 'string' ? path.resolve(project, bundler.tsconfig) : undefined;
|
|
193
|
+
const resolvers = new Map();
|
|
194
|
+
const nearest = new Map();
|
|
195
|
+
const defaults = { moduleResolution: ModuleResolutionKind.Bundler, allowJs: true, resolveJsonModule: true };
|
|
196
|
+
const api = __addDisposableResource(env_1, trackedCompiler(add, (directory) => {
|
|
197
|
+
if (!ignored(directory) && !existsSync(directory)) {
|
|
198
|
+
add(directory);
|
|
199
|
+
}
|
|
200
|
+
}), false);
|
|
201
|
+
function resolverFor(directory) {
|
|
202
|
+
if (!explicitConfig && !nearest.has(directory)) {
|
|
203
|
+
nearest.set(directory, findConfigFile(directory, add, 'tsconfig.json', project));
|
|
204
|
+
}
|
|
205
|
+
const configFile = explicitConfig ?? nearest.get(directory);
|
|
206
|
+
const cached = resolvers.get(configFile);
|
|
207
|
+
if (cached) {
|
|
208
|
+
return cached;
|
|
209
|
+
}
|
|
210
|
+
const parsed = configFile ? api.parseConfigFile(configFile) : undefined;
|
|
211
|
+
const resolver = api.createModuleResolver(parsed ? { ...defaults, ...moduleResolutionOptions(parsed.options) } : defaults);
|
|
212
|
+
resolvers.set(configFile, resolver);
|
|
213
|
+
if (configFile) {
|
|
214
|
+
const raw = parsed?.raw;
|
|
215
|
+
const directory = path.dirname(configFile);
|
|
216
|
+
for (const source of Array.isArray(raw?.files) ? raw.files : []) {
|
|
217
|
+
if (typeof source === 'string') {
|
|
218
|
+
add(path.resolve(directory, source));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const pattern of Array.isArray(raw?.include) ? raw.include : []) {
|
|
222
|
+
if (typeof pattern === 'string') {
|
|
223
|
+
const prefix = pattern.split(/[*?]/)[0];
|
|
224
|
+
if (prefix && prefix !== './' && prefix !== '.') {
|
|
225
|
+
add(path.resolve(directory, prefix));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return resolver;
|
|
231
|
+
}
|
|
232
|
+
async function scan(file) {
|
|
233
|
+
signal?.throwIfAborted();
|
|
234
|
+
if (ignored(file) || visited.has(file)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
visited.add(file);
|
|
238
|
+
let info;
|
|
239
|
+
try {
|
|
240
|
+
info = await lstat(file);
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
if (['ENOENT', 'ENOTDIR'].includes(error.code ?? '')) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
if (info.isSymbolicLink() || path.relative(await realpath(file), file) !== '') {
|
|
249
|
+
throw new Error(`Symlinks are unsupported in staged sources: ${file}`);
|
|
250
|
+
}
|
|
251
|
+
if (info.isDirectory()) {
|
|
252
|
+
for (const entry of await readdir(file, { withFileTypes: true })) {
|
|
253
|
+
await scan(path.join(file, entry.name));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (/\.[cm]?[jt]sx?$/i.test(file)) {
|
|
257
|
+
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
258
|
+
try {
|
|
259
|
+
const parsed = __addDisposableResource(env_2, api.createSourceFile(file, await readFile(file, 'utf8')), false);
|
|
260
|
+
const source = parsed.sourceFile;
|
|
261
|
+
for (const reference of source.referencedFiles) {
|
|
262
|
+
add(path.resolve(path.dirname(file), reference.fileName));
|
|
263
|
+
}
|
|
264
|
+
for (const reference of source.typeReferenceDirectives) {
|
|
265
|
+
if (reference.fileName.startsWith('.')) {
|
|
266
|
+
add(path.resolve(path.dirname(file), reference.fileName));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const directory = path.dirname(file);
|
|
270
|
+
for (const imported of source.imports) {
|
|
271
|
+
if (!isStringLiteral(imported)) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const resolution = resolverFor(directory).resolveModuleName(imported.text, directory).resolvedModule;
|
|
275
|
+
if (resolution) {
|
|
276
|
+
add(resolution.resolvedFileName);
|
|
277
|
+
// A typed asset resolves to e.g. heads.d.json.ts. Bundle its runtime file too.
|
|
278
|
+
const extension = path.extname(imported.text);
|
|
279
|
+
const suffix = '.d' + extension + '.ts';
|
|
280
|
+
if (extension && resolution.resolvedFileName.endsWith(suffix)) {
|
|
281
|
+
add(resolution.resolvedFileName.slice(0, -suffix.length) + extension);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (e_2) {
|
|
287
|
+
env_2.error = e_2;
|
|
288
|
+
env_2.hasError = true;
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
__disposeResources(env_2);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else if (file.endsWith('.json')) {
|
|
295
|
+
let document;
|
|
296
|
+
try {
|
|
297
|
+
document = JSON.parse(await readFile(file, 'utf8'));
|
|
298
|
+
}
|
|
299
|
+
catch {
|
|
300
|
+
// Stages own syntax diagnostics, including JSON templates awaiting expansion.
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
if (typeof document?.extends === 'string' && /^\.\.?[\\/]/.test(document.extends)) {
|
|
304
|
+
add(path.resolve(path.dirname(file), document.extends));
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
resolverFor(project);
|
|
309
|
+
for (const source of screens) {
|
|
310
|
+
if (typeof source === 'string' && source.startsWith('.')) {
|
|
311
|
+
add(source);
|
|
312
|
+
const resolved = resolverFor(project).resolveModuleName(source, project).resolvedModule;
|
|
313
|
+
if (resolved) {
|
|
314
|
+
add(resolved.resolvedFileName);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
for (let index = 0; index < pending.length; index++) {
|
|
319
|
+
await scan(pending[index]);
|
|
320
|
+
}
|
|
321
|
+
return [...roots].filter(file => ![...roots].some(other => other !== file && contains(other, file)));
|
|
322
|
+
}
|
|
323
|
+
catch (e_1) {
|
|
324
|
+
env_1.error = e_1;
|
|
325
|
+
env_1.hasError = true;
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
__disposeResources(env_1);
|
|
329
|
+
}
|
|
330
|
+
}
|
package/dist/src/validation.d.ts
CHANGED
|
@@ -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, CreatorToolsDiagnostic, CreatorToolsResult, CreatorToolsValidationOptions } 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
|
|
5
|
-
import { isStagingExcluded, stagingExclusions } from
|
|
6
|
-
import { resolveExportPaths } from
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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,14 +185,11 @@ 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
|
-
const generator = settings.stages?.generator;
|
|
166
|
-
if (generator && typeof generator === 'object' && generator.types !== false && typeof generator.typesDir === 'string' && generator.typesDir) {
|
|
167
|
-
roots.add(path.resolve(project, generator.typesDir));
|
|
168
|
-
}
|
|
169
190
|
// Retain former outputs as ignored paths after profile edits.
|
|
170
191
|
outputRoots = new Set([...outputRoots, ...roots]);
|
|
192
|
+
sourceRoots = await stagingInputs(project, config, profile, configPath, [...outputRoots], signal);
|
|
171
193
|
debounceMs = settings.watch?.debounceMs ?? 100;
|
|
172
194
|
extraPaths = (settings.watch?.paths ?? []).map(file => path.resolve(project, file));
|
|
173
195
|
await updateExternalWatchers();
|
|
@@ -202,7 +224,7 @@ export async function watchBuild(options) {
|
|
|
202
224
|
}
|
|
203
225
|
visible.push(`${entry.name}:${entry.isDirectory() ? 'directory' : 'file'}`);
|
|
204
226
|
}
|
|
205
|
-
return visible.sort().join('|');
|
|
227
|
+
return visible.length ? `${info.ino}:${visible.sort().join('|')}` : '';
|
|
206
228
|
}
|
|
207
229
|
return `${info.mtimeNs}:${info.size}:${info.ino}`;
|
|
208
230
|
}
|
|
@@ -228,7 +250,7 @@ export async function watchBuild(options) {
|
|
|
228
250
|
}
|
|
229
251
|
}
|
|
230
252
|
}
|
|
231
|
-
async function
|
|
253
|
+
async function changedInput(file) {
|
|
232
254
|
// Windows may emit unchanged directory events while recursive watches are attached.
|
|
233
255
|
file = file.startsWith('\\\\?\\') ? file.slice(4) : file;
|
|
234
256
|
if (ignored(file) || [...ownedWrites].some(root => contains(root, file))) {
|
|
@@ -240,7 +262,7 @@ export async function watchBuild(options) {
|
|
|
240
262
|
}
|
|
241
263
|
const previous = signatures.get(file);
|
|
242
264
|
// A new empty directory may contain only ignored output paths.
|
|
243
|
-
if (current === '' && (previous === undefined || previous === 'missing')) {
|
|
265
|
+
if (current === '' && (previous === undefined || previous === 'missing') && !sourceRoots.some(root => contains(file, root))) {
|
|
244
266
|
signatures.set(file, current);
|
|
245
267
|
return;
|
|
246
268
|
}
|
|
@@ -251,23 +273,19 @@ export async function watchBuild(options) {
|
|
|
251
273
|
}
|
|
252
274
|
try {
|
|
253
275
|
const config = validateConfig(JSON.parse(await readFile(configPath, 'utf8')));
|
|
254
|
-
const settings = config.bedrockCore.profiles[profile];
|
|
255
276
|
exclusions = stagingExclusions(project, config, configPath);
|
|
256
|
-
for (const directory of exportRoots(config)) {
|
|
277
|
+
for (const directory of await exportRoots(config)) {
|
|
257
278
|
outputRoots.add(directory);
|
|
258
279
|
}
|
|
259
|
-
|
|
260
|
-
if (generator && typeof generator === 'object' && generator.types !== false && typeof generator.typesDir === 'string' && generator.typesDir) {
|
|
261
|
-
outputRoots.add(path.resolve(project, generator.typesDir));
|
|
262
|
-
}
|
|
280
|
+
sourceRoots = await stagingInputs(project, config, profile, configPath, [...outputRoots], signal);
|
|
263
281
|
}
|
|
264
282
|
catch {
|
|
265
283
|
// A malformed config stays observable so editing it can recover the build.
|
|
266
284
|
}
|
|
267
285
|
await snapshot(project);
|
|
268
|
-
const watcher = watch(project, { recursive:
|
|
286
|
+
const watcher = watch(project, { recursive: false }, (_event, filename) => {
|
|
269
287
|
const file = filename ? path.resolve(project, filename.toString()) : project;
|
|
270
|
-
void
|
|
288
|
+
void changedInput(file).catch(report);
|
|
271
289
|
});
|
|
272
290
|
const stopObservingWrites = observeSourceWrites(project, (writes) => {
|
|
273
291
|
const directories = writes.map(write => write.directory);
|
|
@@ -285,6 +303,7 @@ export async function watchBuild(options) {
|
|
|
285
303
|
await snapshot(directory);
|
|
286
304
|
signatures.set(path.dirname(directory), await signature(path.dirname(directory)));
|
|
287
305
|
}
|
|
306
|
+
await updateExternalWatchers();
|
|
288
307
|
if ((await Promise.all(writes.map(write => write.matches()))).some(matches => !matches)) {
|
|
289
308
|
requestBuild();
|
|
290
309
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bedrock-core/builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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"
|
|
@@ -45,15 +46,15 @@
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
|
-
"test": "node --test",
|
|
49
|
+
"test": "node --test test \"scripts/*.test.*\" \"packages/*/test/**/*.{js,mjs,cjs,ts,mts,cts}\"",
|
|
49
50
|
"plan": "node bin/plan.ts",
|
|
50
|
-
"build": "node bin/build.ts",
|
|
51
|
-
"typecheck": "tsc --noEmit",
|
|
51
|
+
"build": "yarn prepare:types && node bin/build.ts",
|
|
52
|
+
"typecheck": "yarn prepare:types && node node_modules/typescript-native/bin/tsc --noEmit && node node_modules/typescript-native/bin/tsc -p packages/bedrock-types/tsconfig.json --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",
|
|
55
56
|
"check": "yarn lint && yarn typecheck && yarn test",
|
|
56
|
-
"watch": "node bin/watch.ts",
|
|
57
|
+
"watch": "yarn prepare:types && node bin/watch.ts",
|
|
57
58
|
"migrate": "node bin/migrate.ts",
|
|
58
59
|
"scaffold": "node packages/cli/src/index.ts",
|
|
59
60
|
"test:cli": "yarn workspace @bedrock-core/cli test",
|
|
@@ -62,31 +63,47 @@
|
|
|
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",
|
|
67
|
+
"registry": "node scripts/local-registry.mjs",
|
|
68
|
+
"local:publish": "node scripts/local-packages.mjs publish",
|
|
69
|
+
"local:check": "node scripts/local-packages.mjs check",
|
|
70
|
+
"test:local-packages": "node --test scripts/local-registry.test.mjs scripts/local-packages.test.mjs",
|
|
65
71
|
"acceptance": "node scripts/acceptance.ts",
|
|
66
72
|
"acceptance:native": "node scripts/acceptance.ts --native",
|
|
73
|
+
"acceptance:api": "node scripts/api-acceptance.ts",
|
|
74
|
+
"acceptance:api:native": "node scripts/api-acceptance.ts --native",
|
|
75
|
+
"acceptance:api-packages": "node scripts/api-package-acceptance.mjs",
|
|
76
|
+
"acceptance:api-packages:native": "node scripts/api-package-acceptance.mjs --native",
|
|
77
|
+
"acceptance:navigation-api": "node scripts/navigation-api-acceptance.mjs",
|
|
78
|
+
"acceptance:navigation-api:native": "node scripts/navigation-api-acceptance.mjs --native",
|
|
67
79
|
"release": "yarn check && yarn acceptance && yarn pack-release && yarn test:packages",
|
|
68
80
|
"publish-release": "node scripts/publish-release.ts",
|
|
69
81
|
"changeset": "changeset",
|
|
70
82
|
"changeset:status": "changeset status --verbose",
|
|
71
|
-
"version:packages": "changeset version && node scripts/sync-cli-template.mjs --builder-only",
|
|
83
|
+
"version:packages": "changeset version && node scripts/sync-cli-template.mjs --builder-only && yarn install --mode=update-lockfile",
|
|
72
84
|
"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",
|
|
74
|
-
"publish:ci": "yarn publish-release --scope \"$RELEASE_SCOPE\" && yarn tag-release --scope \"$RELEASE_SCOPE\""
|
|
85
|
+
"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",
|
|
86
|
+
"publish:ci": "yarn publish-release --scope \"$RELEASE_SCOPE\" && yarn tag-release --scope \"$RELEASE_SCOPE\"",
|
|
87
|
+
"prepare:types": "node packages/bedrock-types/src/build.ts",
|
|
88
|
+
"prepare:assets": "node packages/asset-maps/src/build.ts",
|
|
89
|
+
"setup": "yarn install && yarn prepare:types"
|
|
75
90
|
},
|
|
76
91
|
"engines": {
|
|
77
|
-
"node": ">=
|
|
92
|
+
"node": ">=26.13.0"
|
|
78
93
|
},
|
|
79
94
|
"dependencies": {
|
|
80
|
-
"@bedrock-core/builder-bundler": "0.
|
|
81
|
-
"@bedrock-core/builder-generator": "0.
|
|
82
|
-
"@bedrock-core/builder-guides": "0.
|
|
83
|
-
"@bedrock-core/builder-i18n": "0.1
|
|
84
|
-
"@bedrock-core/builder-manifest": "0.
|
|
85
|
-
"@bedrock-core/builder-plugin": "0.
|
|
86
|
-
"@bedrock-core/builder-ui": "0.
|
|
87
|
-
"@bedrock-core/builder-validation": "0.
|
|
95
|
+
"@bedrock-core/builder-bundler": "0.3.0",
|
|
96
|
+
"@bedrock-core/builder-generator": "0.3.0",
|
|
97
|
+
"@bedrock-core/builder-guides": "0.2.0",
|
|
98
|
+
"@bedrock-core/builder-i18n": "0.2.1",
|
|
99
|
+
"@bedrock-core/builder-manifest": "0.2.0",
|
|
100
|
+
"@bedrock-core/builder-plugin": "0.2.0",
|
|
101
|
+
"@bedrock-core/builder-ui": "0.4.0",
|
|
102
|
+
"@bedrock-core/builder-validation": "0.3.0",
|
|
88
103
|
"@types/node": "25.9.9",
|
|
89
|
-
"ajv": "8.17.1"
|
|
104
|
+
"ajv": "8.17.1",
|
|
105
|
+
"import-meta-resolve": "^4.2.0",
|
|
106
|
+
"typescript-native": "npm:typescript@7.1.0-beta"
|
|
90
107
|
},
|
|
91
108
|
"devDependencies": {
|
|
92
109
|
"@changesets/cli": "3.0.3",
|
|
@@ -95,7 +112,8 @@
|
|
|
95
112
|
"eslint": "10.5.0",
|
|
96
113
|
"globals": "17.7.0",
|
|
97
114
|
"typescript": "5.9.3",
|
|
98
|
-
"typescript-eslint": "8.62.0"
|
|
115
|
+
"typescript-eslint": "8.62.0",
|
|
116
|
+
"verdaccio": "7.1.0"
|
|
99
117
|
},
|
|
100
118
|
"workspaces": [
|
|
101
119
|
".",
|
|
@@ -107,7 +125,9 @@
|
|
|
107
125
|
"packages/validation",
|
|
108
126
|
"packages/plugin",
|
|
109
127
|
"packages/manifest",
|
|
110
|
-
"packages/cli"
|
|
128
|
+
"packages/cli",
|
|
129
|
+
"packages/bedrock-types",
|
|
130
|
+
"packages/asset-maps"
|
|
111
131
|
],
|
|
112
132
|
"packageManager": "yarn@4.16.0",
|
|
113
133
|
"license": "MIT",
|
|
@@ -123,6 +143,7 @@
|
|
|
123
143
|
},
|
|
124
144
|
"exports": {
|
|
125
145
|
"./schemas/config.schema.json": "./schemas/config.schema.json",
|
|
146
|
+
"./schemas/pack-manifest.schema.json": "./schemas/pack-manifest.schema.json",
|
|
126
147
|
"./export": {
|
|
127
148
|
"types": "./dist/src/export.d.ts",
|
|
128
149
|
"default": "./dist/src/export.js"
|
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"debug": {
|
|
31
31
|
"type": "boolean"
|
|
32
32
|
},
|
|
33
|
+
"vanillaAssets": {
|
|
34
|
+
"type": "boolean",
|
|
35
|
+
"default": false,
|
|
36
|
+
"description": "Include the checked shared vanilla asset catalog and generated atlas. Authored addon assets publish automatically regardless of this setting."
|
|
37
|
+
},
|
|
33
38
|
"target": {
|
|
34
39
|
"type": "string",
|
|
35
40
|
"pattern": "\\S"
|