@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/export.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { cp, lstat, mkdir, readdir,
|
|
2
|
-
import {
|
|
1
|
+
import { copyFile, cp, lstat, mkdir, mkdtemp, open, readdir, readFile, realpath, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
5
|
import path from 'node:path';
|
|
4
|
-
import { readManifest, validatePackManifests } from
|
|
6
|
+
import { readManifest, validatePackManifests } from './manifest.js';
|
|
7
|
+
import { apiPackageMetadata } from '@bedrock-core/builder-manifest';
|
|
5
8
|
function contains(root, file) {
|
|
6
9
|
const relative = path.relative(root, file);
|
|
7
10
|
return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
@@ -103,6 +106,10 @@ function expandExportPath(directory, environment) {
|
|
|
103
106
|
export function resolveExportPaths(project, packs, selection, environment = process.env) {
|
|
104
107
|
checkPackIds(packs, selection);
|
|
105
108
|
const paths = Object.fromEntries(Object.entries(selection).map(([id, directory]) => [id, path.resolve(project, expandExportPath(directory, environment))]));
|
|
109
|
+
validateDestinations(project, packs, paths);
|
|
110
|
+
return paths;
|
|
111
|
+
}
|
|
112
|
+
function validateDestinations(project, packs, paths) {
|
|
106
113
|
checkDestinations(paths);
|
|
107
114
|
for (const destination of Object.values(paths)) {
|
|
108
115
|
if (contains(destination, project) || (contains(project, destination)
|
|
@@ -116,67 +123,273 @@ export function resolveExportPaths(project, packs, selection, environment = proc
|
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
|
-
return paths;
|
|
120
126
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
/** Resolve a dedicated API package destination with the pack publication safety rules. */
|
|
128
|
+
export function resolveApiPackagePath(project, packs, paths, destination) {
|
|
129
|
+
const output = path.resolve(project, expandExportPath(destination, process.env));
|
|
130
|
+
validateDestinations(project, packs, { ...paths, '\0api-package': output });
|
|
131
|
+
return output;
|
|
132
|
+
}
|
|
133
|
+
async function inspectSource(root) {
|
|
134
|
+
const entries = new Map();
|
|
135
|
+
async function visit(directory) {
|
|
136
|
+
await assertDirectory(directory);
|
|
137
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
138
|
+
const file = path.join(directory, entry.name);
|
|
139
|
+
if (entry.isSymbolicLink()) {
|
|
140
|
+
throw new Error(`Export source contains a symlink: ${file}`);
|
|
141
|
+
}
|
|
142
|
+
entries.set(path.relative(root, file), entry);
|
|
143
|
+
if (entry.isDirectory()) {
|
|
144
|
+
await visit(file);
|
|
145
|
+
}
|
|
126
146
|
}
|
|
127
|
-
|
|
128
|
-
|
|
147
|
+
}
|
|
148
|
+
await visit(root);
|
|
149
|
+
return entries;
|
|
150
|
+
}
|
|
151
|
+
/** Check the complete inventory and compare bytes before allocating publication snapshots. */
|
|
152
|
+
async function sameTree(source, destination, inputs, outputs, signal) {
|
|
153
|
+
if (inputs.size !== outputs.size) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
const files = [];
|
|
157
|
+
for (const [file, input] of inputs) {
|
|
158
|
+
const output = outputs.get(file);
|
|
159
|
+
if (!output || (input.isDirectory() ? !output.isDirectory() : !input.isFile() || !output.isFile())) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (input.isFile()) {
|
|
163
|
+
files.push(file);
|
|
129
164
|
}
|
|
130
165
|
}
|
|
166
|
+
for (let offset = 0; offset < files.length; offset += 8) {
|
|
167
|
+
const compared = await Promise.allSettled(files.slice(offset, offset + 8).map(async (file) => {
|
|
168
|
+
signal?.throwIfAborted();
|
|
169
|
+
const paths = [path.join(source, file), path.join(destination, file)];
|
|
170
|
+
const before = await Promise.all(paths.map(file => lstat(file)));
|
|
171
|
+
if (!before.every(info => info.isFile()) || before[0].size !== before[1].size
|
|
172
|
+
|| !await sameContents(paths[0], paths[1], before[0].size, signal)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
const after = await Promise.all(paths.map(file => lstat(file)));
|
|
176
|
+
return before.every((info, index) => {
|
|
177
|
+
const current = after[index];
|
|
178
|
+
return current.isFile() && current.dev === info.dev && current.ino === info.ino && current.size === info.size
|
|
179
|
+
&& current.mtimeMs === info.mtimeMs && current.ctimeMs === info.ctimeMs;
|
|
180
|
+
});
|
|
181
|
+
}));
|
|
182
|
+
for (const result of compared) {
|
|
183
|
+
if (result.status === 'rejected') {
|
|
184
|
+
throw result.reason;
|
|
185
|
+
}
|
|
186
|
+
if (!result.value) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return true;
|
|
131
192
|
}
|
|
132
|
-
async function
|
|
193
|
+
async function apiPackageName(directory, packs) {
|
|
194
|
+
const metadata = JSON.parse(await readFile(path.join(directory, 'package.json'), 'utf8'));
|
|
195
|
+
const api = apiPackageMetadata(metadata);
|
|
196
|
+
if (typeof metadata.name !== 'string' || !api) {
|
|
197
|
+
throw new Error(`Export directory does not identify a portable API package: ${directory}`);
|
|
198
|
+
}
|
|
199
|
+
if (packs) {
|
|
200
|
+
const identities = await Promise.all(Object.entries(packs).map(([id, directory]) => readManifest(id, directory)));
|
|
201
|
+
for (const relative of new Set(Object.values(api.manifests))) {
|
|
202
|
+
const file = path.resolve(directory, relative);
|
|
203
|
+
if (!contains(directory, file)) {
|
|
204
|
+
throw new Error('API owner manifests must stay inside the published package');
|
|
205
|
+
}
|
|
206
|
+
const owner = JSON.parse(await readFile(file, 'utf8'));
|
|
207
|
+
if (!identities.some(pack => pack.header.uuid === owner.header?.uuid && pack.header.version === owner.header.version)) {
|
|
208
|
+
throw new Error(`API owner identity does not match a final pack manifest: ${relative}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return metadata.name;
|
|
213
|
+
}
|
|
214
|
+
async function updateFileSystem(operation, signal) {
|
|
215
|
+
for (let attempt = 0;; attempt++) {
|
|
216
|
+
signal?.throwIfAborted();
|
|
217
|
+
try {
|
|
218
|
+
await operation();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (attempt === 3 || !['EBUSY', 'EPERM', 'EACCES', 'ENOTEMPTY'].includes(error.code ?? '')) {
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
await delay(50 * (attempt + 1), undefined, { signal });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async function readChunk(file, buffer, length, position, signal) {
|
|
230
|
+
let read = 0;
|
|
231
|
+
while (read < length) {
|
|
232
|
+
signal?.throwIfAborted();
|
|
233
|
+
const { bytesRead } = await file.read(buffer, read, length - read, position + read);
|
|
234
|
+
if (!bytesRead) {
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
read += bytesRead;
|
|
238
|
+
}
|
|
239
|
+
return read;
|
|
240
|
+
}
|
|
241
|
+
/** Compare exact bytes with bounded memory, including equal-size files with equal timestamps. */
|
|
242
|
+
async function sameContents(source, destination, size, signal) {
|
|
243
|
+
const input = await open(source, 'r');
|
|
244
|
+
try {
|
|
245
|
+
const output = await open(destination, 'r');
|
|
246
|
+
try {
|
|
247
|
+
const left = Buffer.allocUnsafe(Math.min(size, 64 * 1024));
|
|
248
|
+
const right = Buffer.allocUnsafe(left.length);
|
|
249
|
+
for (let position = 0; position < size; position += left.length) {
|
|
250
|
+
const length = Math.min(left.length, size - position);
|
|
251
|
+
const [a, b] = await Promise.all([readChunk(input, left, length, position, signal), readChunk(output, right, length, position, signal)]);
|
|
252
|
+
if (a !== length || b !== length || !left.subarray(0, length).equals(right.subarray(0, length))) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return (await output.stat()).size === size;
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
await output.close();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
finally {
|
|
263
|
+
await input.close();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** Preserve directory and unchanged-file identities while applying a complete snapshot. */
|
|
267
|
+
async function synchronize(source, destination, signal) {
|
|
268
|
+
signal?.throwIfAborted();
|
|
269
|
+
await ensureDirectory(destination);
|
|
270
|
+
const pending = new Set(await readdir(destination));
|
|
271
|
+
const entries = await readdir(source, { withFileTypes: true });
|
|
272
|
+
// Publish the root manifest after the files it can reference.
|
|
273
|
+
entries.sort((a, b) => Number(a.name === 'manifest.json') - Number(b.name === 'manifest.json'));
|
|
274
|
+
// Only inspection runs concurrently; mutations retain manifest-last order.
|
|
275
|
+
for (let offset = 0; offset < entries.length; offset += 8) {
|
|
276
|
+
const inspected = await Promise.allSettled(entries.slice(offset, offset + 8).map(async (entry) => {
|
|
277
|
+
signal?.throwIfAborted();
|
|
278
|
+
const input = path.join(source, entry.name);
|
|
279
|
+
const output = path.join(destination, entry.name);
|
|
280
|
+
const current = await lstat(output).catch((error) => {
|
|
281
|
+
if (error.code !== 'ENOENT') {
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
return undefined;
|
|
285
|
+
});
|
|
286
|
+
let unchanged = false;
|
|
287
|
+
if (!entry.isDirectory() && current?.isFile()) {
|
|
288
|
+
const incoming = await lstat(input);
|
|
289
|
+
unchanged = incoming.size === current.size && await sameContents(input, output, incoming.size, signal);
|
|
290
|
+
}
|
|
291
|
+
return { entry, input, output, current, unchanged };
|
|
292
|
+
}));
|
|
293
|
+
for (const result of inspected) {
|
|
294
|
+
signal?.throwIfAborted();
|
|
295
|
+
if (result.status === 'rejected') {
|
|
296
|
+
throw result.reason;
|
|
297
|
+
}
|
|
298
|
+
const { entry, input, output, unchanged } = result.value;
|
|
299
|
+
let { current } = result.value;
|
|
300
|
+
pending.delete(entry.name);
|
|
301
|
+
if (current?.isSymbolicLink()) {
|
|
302
|
+
throw new Error(`Export destination contains a symlink: ${output}`);
|
|
303
|
+
}
|
|
304
|
+
if (current && current.isDirectory() !== entry.isDirectory()) {
|
|
305
|
+
await updateFileSystem(() => rm(output, { recursive: true, force: true }), signal);
|
|
306
|
+
current = undefined;
|
|
307
|
+
}
|
|
308
|
+
if (entry.isDirectory()) {
|
|
309
|
+
await synchronize(input, output, signal);
|
|
310
|
+
}
|
|
311
|
+
else if (!unchanged) {
|
|
312
|
+
if (current && (!current.isFile() || current.nlink > 1)) {
|
|
313
|
+
throw new Error(`Export requires an independent regular file: ${output}`);
|
|
314
|
+
}
|
|
315
|
+
await updateFileSystem(() => copyFile(input, output), signal);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
for (const name of pending) {
|
|
320
|
+
signal?.throwIfAborted();
|
|
321
|
+
await updateFileSystem(() => rm(path.join(destination, name), { recursive: true, force: true }), signal);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function publishPacks({ packs, paths, signal }, api) {
|
|
133
325
|
checkPackIds(packs, paths);
|
|
134
326
|
await validatePackManifests(packs);
|
|
135
327
|
const jobs = [];
|
|
328
|
+
let workspace;
|
|
136
329
|
let preserveBackups = false;
|
|
137
330
|
try {
|
|
138
|
-
|
|
331
|
+
const directories = Object.entries(packs).map(([id, source]) => ({ id, source, destination: paths[id], api: false }));
|
|
332
|
+
if (api) {
|
|
333
|
+
directories.push({ id: '\0api-package', source: api.source, destination: api.path, api: true });
|
|
334
|
+
}
|
|
335
|
+
for (const { id, source: directory, destination, api: isApi } of directories) {
|
|
139
336
|
signal?.throwIfAborted();
|
|
140
337
|
const source = path.resolve(directory);
|
|
141
|
-
const
|
|
142
|
-
await
|
|
338
|
+
const inputs = await inspectSource(source);
|
|
339
|
+
const packageName = isApi ? await apiPackageName(source, packs) : undefined;
|
|
143
340
|
if (await exists(destination)) {
|
|
144
|
-
await
|
|
145
|
-
if (
|
|
341
|
+
const outputs = await inspectSource(destination);
|
|
342
|
+
if (outputs.size) {
|
|
146
343
|
try {
|
|
147
|
-
|
|
344
|
+
if (isApi) {
|
|
345
|
+
if (await apiPackageName(destination) !== packageName) {
|
|
346
|
+
throw new Error('API package name does not match the existing export');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
await readManifest(id, destination);
|
|
351
|
+
}
|
|
148
352
|
}
|
|
149
353
|
catch (cause) {
|
|
150
354
|
throw new Error(`Export destination does not identify a pack: ${destination}`, { cause });
|
|
151
355
|
}
|
|
152
356
|
}
|
|
357
|
+
if (await sameTree(source, destination, inputs, outputs, signal)) {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
153
360
|
}
|
|
154
|
-
|
|
361
|
+
workspace ??= await mkdtemp(path.join(await realpath(tmpdir()), 'bedrock-core-export-'));
|
|
362
|
+
const job = {
|
|
363
|
+
path: destination, candidate: path.join(workspace, `${jobs.length}-next`),
|
|
364
|
+
backup: await exists(destination) ? path.join(workspace, `${jobs.length}-previous`) : undefined,
|
|
365
|
+
started: false,
|
|
366
|
+
};
|
|
155
367
|
jobs.push(job);
|
|
156
368
|
await cp(source, job.candidate, { recursive: true });
|
|
369
|
+
if (job.backup) {
|
|
370
|
+
await cp(destination, job.backup, { recursive: true });
|
|
371
|
+
}
|
|
157
372
|
}
|
|
158
373
|
for (const job of jobs) {
|
|
159
374
|
signal?.throwIfAborted();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
await rename(job.path, job.backup);
|
|
163
|
-
}
|
|
164
|
-
await rename(job.candidate, job.path);
|
|
165
|
-
job.installed = true;
|
|
375
|
+
job.started = true;
|
|
376
|
+
await synchronize(job.candidate, job.path, signal);
|
|
166
377
|
}
|
|
167
378
|
signal?.throwIfAborted();
|
|
168
|
-
return
|
|
379
|
+
return Object.keys(packs).map(id => ({ id, path: paths[id] }));
|
|
169
380
|
}
|
|
170
381
|
catch (error) {
|
|
171
382
|
const rollbackErrors = [];
|
|
172
383
|
for (const job of [...jobs].reverse()) {
|
|
384
|
+
if (!job.started) {
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
173
387
|
try {
|
|
174
|
-
if (job.
|
|
175
|
-
await
|
|
388
|
+
if (job.backup) {
|
|
389
|
+
await synchronize(job.backup, job.path);
|
|
176
390
|
}
|
|
177
|
-
|
|
178
|
-
await
|
|
179
|
-
job.backup = undefined;
|
|
391
|
+
else {
|
|
392
|
+
await updateFileSystem(() => rm(job.path, { recursive: true, force: true }));
|
|
180
393
|
}
|
|
181
394
|
}
|
|
182
395
|
catch (rollbackError) {
|
|
@@ -185,17 +398,13 @@ async function publishPacks({ packs, paths, signal }) {
|
|
|
185
398
|
}
|
|
186
399
|
if (rollbackErrors.length) {
|
|
187
400
|
preserveBackups = true;
|
|
188
|
-
|
|
189
|
-
throw new AggregateError([error, ...rollbackErrors], `Export rollback failed; backups retained at ${backups.join(', ')}`, { cause: error });
|
|
401
|
+
throw new AggregateError([error, ...rollbackErrors], `Export rollback failed; recovery files retained at ${workspace}`, { cause: error });
|
|
190
402
|
}
|
|
191
403
|
throw error;
|
|
192
404
|
}
|
|
193
405
|
finally {
|
|
194
|
-
|
|
195
|
-
await rm(
|
|
196
|
-
if (job.backup && !preserveBackups) {
|
|
197
|
-
await rm(job.backup, { recursive: true, force: true });
|
|
198
|
-
}
|
|
406
|
+
if (workspace && !preserveBackups) {
|
|
407
|
+
await rm(workspace, { recursive: true, force: true, maxRetries: 3 });
|
|
199
408
|
}
|
|
200
409
|
}
|
|
201
410
|
}
|
|
@@ -204,24 +413,42 @@ async function publishPacks({ packs, paths, signal }) {
|
|
|
204
413
|
* @param paths Dedicated nonoverlapping pack destination directories.
|
|
205
414
|
* @param build Callback receiving the guarded publication function.
|
|
206
415
|
* @returns The callback result, with destination locks released on completion.
|
|
207
|
-
* @remarks
|
|
416
|
+
* @remarks Locks are keyed by destination in the OS temporary directory. The callback owns preparation and any additional validation.
|
|
208
417
|
* @throws If a destination is unsafe or already locked, or the callback fails.
|
|
209
418
|
*/
|
|
210
|
-
export async function withExportPaths(paths, build) {
|
|
419
|
+
export async function withExportPaths(paths, build, apiPath) {
|
|
211
420
|
paths = Object.fromEntries(Object.entries(paths).map(([id, directory]) => [id, path.resolve(directory)]));
|
|
212
|
-
|
|
421
|
+
const destinations = apiPath ? { ...paths, '\0api-package': path.resolve(apiPath) } : paths;
|
|
422
|
+
checkDestinations(destinations);
|
|
423
|
+
const lockRoot = path.join(await realpath(tmpdir()), 'bedrock-core-export-locks');
|
|
424
|
+
await ensureDirectory(lockRoot);
|
|
213
425
|
const locks = [];
|
|
214
426
|
try {
|
|
215
|
-
for (const destination of Object.values(
|
|
427
|
+
for (const destination of Object.values(destinations).sort()) {
|
|
216
428
|
await ensureDirectory(path.dirname(destination));
|
|
217
429
|
if (await exists(destination)) {
|
|
218
430
|
await assertDirectory(destination);
|
|
219
431
|
}
|
|
220
|
-
const
|
|
221
|
-
|
|
432
|
+
const identity = process.platform === 'win32' ? destination.toLowerCase() : destination;
|
|
433
|
+
const lock = path.join(lockRoot, createHash('sha256').update(identity).digest('hex'));
|
|
434
|
+
try {
|
|
435
|
+
await mkdir(lock);
|
|
436
|
+
}
|
|
437
|
+
catch (cause) {
|
|
438
|
+
if (cause.code !== 'EEXIST') {
|
|
439
|
+
throw cause;
|
|
440
|
+
}
|
|
441
|
+
throw Object.assign(new Error(`Export destination is locked: ${destination}; lock: ${lock}`, { cause }), { code: 'EEXIST' });
|
|
442
|
+
}
|
|
222
443
|
locks.push(lock);
|
|
444
|
+
await writeFile(path.join(lock, 'owner.json'), JSON.stringify({ pid: process.pid, destination }));
|
|
223
445
|
}
|
|
224
|
-
return await build((packs, signal) =>
|
|
446
|
+
return await build((packs, signal, apiPackage) => {
|
|
447
|
+
if (apiPackage && !apiPath) {
|
|
448
|
+
throw new Error('API package publication needs a reserved destination');
|
|
449
|
+
}
|
|
450
|
+
return publishPacks({ packs, paths, signal }, apiPackage ? { source: apiPackage, path: apiPath } : undefined);
|
|
451
|
+
});
|
|
225
452
|
}
|
|
226
453
|
finally {
|
|
227
454
|
for (const lock of locks.reverse()) {
|
|
@@ -232,8 +459,8 @@ export async function withExportPaths(paths, build) {
|
|
|
232
459
|
/**
|
|
233
460
|
* Publish pack folders with manifest checks, locks and rollback, without the build runner.
|
|
234
461
|
* @returns Published pack IDs and absolute destination directories.
|
|
235
|
-
* @remarks
|
|
236
|
-
* @throws If manifest checks or publication fail
|
|
462
|
+
* @remarks Updates files in place without renaming pack roots. Snapshots and locks stay in the OS temporary directory. Use validatePackContent to check pack JSON before export.
|
|
463
|
+
* @throws If manifest checks or publication fail. Failed rollback reports a retained recovery directory.
|
|
237
464
|
*/
|
|
238
465
|
export async function exportPacks({ packs, paths, signal, environment = process.env }) {
|
|
239
466
|
signal?.throwIfAborted();
|
package/dist/src/migrate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MigrationOptions, MigrationResult } from './migration/types.ts';
|
|
2
|
-
export type {
|
|
2
|
+
export type { MigrationDiagnostic, MigrationOptions, MigrationResult } from './migration/types.ts';
|
|
3
3
|
export { migrateRegolithProject, writeMigration } from './migration/project.ts';
|
|
4
4
|
export type { ProjectMigration } from './migration/project.ts';
|
|
5
5
|
/**
|
package/dist/src/migrate.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { validateConfig } from
|
|
2
|
-
import { planBuild } from
|
|
3
|
-
import { convertExport } from
|
|
4
|
-
import { convertFilters } from
|
|
5
|
-
import { isRecord, pointer } from
|
|
6
|
-
export { migrateRegolithProject, writeMigration } from
|
|
1
|
+
import { validateConfig } from './config.js';
|
|
2
|
+
import { planBuild, stages } from './plan.js';
|
|
3
|
+
import { convertExport } from './migration/exports.js';
|
|
4
|
+
import { convertFilters } from './migration/filters.js';
|
|
5
|
+
import { isRecord, pointer } from './migration/types.js';
|
|
6
|
+
export { migrateRegolithProject, writeMigration } from './migration/project.js';
|
|
7
7
|
/**
|
|
8
8
|
* Produce a reviewable config and diagnostics without evaluating or executing filters.
|
|
9
9
|
* @param input Source data accepted by this operation.
|
|
@@ -14,7 +14,7 @@ export { migrateRegolithProject, writeMigration } from "./migration/project.js";
|
|
|
14
14
|
export function migrateRegolithConfig(input, options = {}) {
|
|
15
15
|
const config = isRecord(input) ? structuredClone(input) : {};
|
|
16
16
|
const diagnostics = [];
|
|
17
|
-
const metadata = ['$schema', 'targetVersion', '
|
|
17
|
+
const metadata = ['$schema', 'targetVersion', 'name', 'description', 'authors'];
|
|
18
18
|
const report = (code, location, message, severity = 'error') => {
|
|
19
19
|
if (!diagnostics.some(item => item.code === code && item.path === location && item.message === message)) {
|
|
20
20
|
diagnostics.push({ severity, code, path: location, message });
|
|
@@ -60,8 +60,12 @@ export function migrateRegolithConfig(input, options = {}) {
|
|
|
60
60
|
const profiles = regolith.profiles;
|
|
61
61
|
const definitions = isRecord(regolith.filterDefinitions) ? regolith.filterDefinitions : {};
|
|
62
62
|
const selectedNames = options.profiles ?? Object.keys(profiles);
|
|
63
|
-
const
|
|
63
|
+
const plugins = new Map();
|
|
64
64
|
const migrated = [];
|
|
65
|
+
const dataPath = typeof regolith.dataPath === 'string' && regolith.dataPath.trim() ? regolith.dataPath : undefined;
|
|
66
|
+
if (regolith.dataPath !== undefined && dataPath === undefined) {
|
|
67
|
+
report('data-source', '/regolith/dataPath', 'Set dataPath to a project-relative directory.');
|
|
68
|
+
}
|
|
65
69
|
if (!selectedNames.length || new Set(selectedNames).size !== selectedNames.length) {
|
|
66
70
|
report('profile-selection', '/regolith/profiles', 'Select at least one distinct profile.');
|
|
67
71
|
}
|
|
@@ -77,11 +81,8 @@ export function migrateRegolithConfig(input, options = {}) {
|
|
|
77
81
|
report('profile-selection', location, 'Selected profile must exist and be an object.');
|
|
78
82
|
continue;
|
|
79
83
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
namespaces.add(namespace);
|
|
83
|
-
}
|
|
84
|
-
const profile = { stages: converted.stages };
|
|
84
|
+
const steps = convertFilters(name, profiles, definitions, plugins, dataPath, report);
|
|
85
|
+
const profile = { stages: Object.fromEntries(stages.map(stage => [stage, false])), steps };
|
|
85
86
|
const destinations = convertExport(source.export, packs, config.name, name, options, report, `${location}/export`);
|
|
86
87
|
if (destinations) {
|
|
87
88
|
profile.export = destinations;
|
|
@@ -106,15 +107,20 @@ export function migrateRegolithConfig(input, options = {}) {
|
|
|
106
107
|
}
|
|
107
108
|
delete config.worlds;
|
|
108
109
|
config.targetVersion = options.targetVersion ?? config.targetVersion;
|
|
109
|
-
|
|
110
|
+
const namespace = config.namespace;
|
|
111
|
+
delete config.namespace;
|
|
110
112
|
if (config.targetVersion === undefined) {
|
|
111
113
|
report('target-version', '/targetVersion', 'Set targetVersion or pass --target-version with the intended Minecraft version.');
|
|
112
114
|
}
|
|
113
|
-
if (
|
|
114
|
-
report('namespace', '/
|
|
115
|
+
if (typeof namespace === 'string') {
|
|
116
|
+
report('manifest-namespace', '/packs', `Declare the ${namespace} namespace in the owning pack manifest.`, 'warning');
|
|
115
117
|
}
|
|
116
118
|
config.$schema = options.schema ?? new URL('../schemas/config.schema.json', import.meta.url).href;
|
|
117
|
-
config.bedrockCore = {
|
|
119
|
+
config.bedrockCore = {
|
|
120
|
+
formatVersion: '1.0.0',
|
|
121
|
+
...(plugins.size ? { plugins: Object.fromEntries(plugins) } : {}),
|
|
122
|
+
profiles: Object.fromEntries(migrated),
|
|
123
|
+
};
|
|
118
124
|
try {
|
|
119
125
|
const validated = validateConfig(config);
|
|
120
126
|
for (const name of selectedNames) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { isRecord } from
|
|
2
|
+
import { isRecord } from './types.js';
|
|
3
3
|
function literalPath(value) {
|
|
4
4
|
return typeof value === 'string' && Boolean(value.trim()) && !/%[^%]+%|\$\{[^}]+\}|\$[A-Za-z_][A-Za-z0-9_]*/.test(value);
|
|
5
5
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
/** Flatten profile references
|
|
4
|
-
export declare function convertFilters(name: string, profiles: Record<string, unknown>, definitions: Record<string, unknown>,
|
|
5
|
-
stages: Partial<Record<StageName, StageSelection>>;
|
|
6
|
-
namespaces: string[];
|
|
7
|
-
};
|
|
1
|
+
import type { NodePluginDefinition, PluginStep } from '../config.ts';
|
|
2
|
+
import type { ReportDiagnostic } from './types.ts';
|
|
3
|
+
/** Flatten profile references into ordered steps for standalone Node filters. */
|
|
4
|
+
export declare function convertFilters(name: string, profiles: Record<string, unknown>, definitions: Record<string, unknown>, plugins: Map<string, NodePluginDefinition>, dataPath: string | undefined, report: ReportDiagnostic): PluginStep[];
|