@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.
- package/CHANGELOG.md +56 -0
- 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 +2 -6
- package/dist/bin/plan.js +2 -2
- package/dist/bin/watch.js +1 -1
- package/dist/package.json +11 -10
- package/dist/schemas/config.schema.json +28 -8
- package/dist/schemas/guides.schema.json +0 -5
- package/dist/schemas/i18n.schema.json +0 -5
- package/dist/schemas/pack-manifest.schema.json +243 -0
- package/dist/schemas/ui-compiler.schema.json +0 -5
- package/dist/src/config.d.ts +7 -3
- package/dist/src/config.js +3 -0
- package/dist/src/contract.d.ts +2 -0
- package/dist/src/export.d.ts +7 -5
- package/dist/src/export.js +274 -47
- package/dist/src/migrate.js +13 -10
- package/dist/src/migration/exports.js +1 -1
- package/dist/src/migration/filters.js +3 -2
- package/dist/src/migration/local-filter.js +1 -1
- package/dist/src/migration/project.js +17 -8
- package/dist/src/migration/types.d.ts +0 -2
- package/dist/src/path-audit.d.ts +29 -0
- package/dist/src/path-audit.js +110 -0
- package/dist/src/plan.js +2 -2
- 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.js +2 -2
- package/dist/src/run.js +67 -30
- package/dist/src/staging.d.ts +4 -0
- package/dist/src/staging.js +297 -0
- package/dist/src/validation.d.ts +1 -1
- package/dist/src/watch.js +48 -20
- package/package.json +24 -14
- package/schemas/config.schema.json +28 -8
- package/schemas/guides.schema.json +0 -5
- package/schemas/i18n.schema.json +0 -5
- package/schemas/pack-manifest.schema.json +243 -0
- package/schemas/ui-compiler.schema.json +0 -5
package/dist/src/export.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface ExportedPack {
|
|
|
16
16
|
/** Absolute published directory. */
|
|
17
17
|
path: string;
|
|
18
18
|
}
|
|
19
|
-
type PublishPacks = (packs: Record<string, string>, signal?: AbortSignal) => Promise<ExportedPack[]>;
|
|
19
|
+
type PublishPacks = (packs: Record<string, string>, signal?: AbortSignal, apiPackage?: string) => Promise<ExportedPack[]>;
|
|
20
20
|
/**
|
|
21
21
|
* Expand `%NAME%`, `$NAME` and `${NAME}`, then resolve destinations relative to the project.
|
|
22
22
|
* @param project Absolute directory containing config.json.
|
|
@@ -28,20 +28,22 @@ type PublishPacks = (packs: Record<string, string>, signal?: AbortSignal) => Pro
|
|
|
28
28
|
* @throws For missing variables/pack IDs, overlapping paths or unsafe source destinations.
|
|
29
29
|
*/
|
|
30
30
|
export declare function resolveExportPaths(project: string, packs: Record<string, string>, selection: Record<string, string>, environment?: NodeJS.ProcessEnv): Record<string, string>;
|
|
31
|
+
/** Resolve a dedicated API package destination with the pack publication safety rules. */
|
|
32
|
+
export declare function resolveApiPackagePath(project: string, packs: Record<string, string>, paths: Record<string, string>, destination: string): string;
|
|
31
33
|
/**
|
|
32
34
|
* Hold destination locks while the callback prepares and publishes validated packs.
|
|
33
35
|
* @param paths Dedicated nonoverlapping pack destination directories.
|
|
34
36
|
* @param build Callback receiving the guarded publication function.
|
|
35
37
|
* @returns The callback result, with destination locks released on completion.
|
|
36
|
-
* @remarks
|
|
38
|
+
* @remarks Locks are keyed by destination in the OS temporary directory. The callback owns preparation and any additional validation.
|
|
37
39
|
* @throws If a destination is unsafe or already locked, or the callback fails.
|
|
38
40
|
*/
|
|
39
|
-
export declare function withExportPaths<T>(paths: Record<string, string>, build: (publish: PublishPacks) => Promise<T
|
|
41
|
+
export declare function withExportPaths<T>(paths: Record<string, string>, build: (publish: PublishPacks) => Promise<T>, apiPath?: string): Promise<T>;
|
|
40
42
|
/**
|
|
41
43
|
* Publish pack folders with manifest checks, locks and rollback, without the build runner.
|
|
42
44
|
* @returns Published pack IDs and absolute destination directories.
|
|
43
|
-
* @remarks JSON schema validation is separate
|
|
44
|
-
* @throws If manifest checks or publication fail
|
|
45
|
+
* @remarks Updates files in place without renaming pack roots. Snapshots and locks stay in the OS temporary directory. JSON schema validation is separate; use validatePackContent when content checks are required.
|
|
46
|
+
* @throws If manifest checks or publication fail. Failed rollback reports a retained recovery directory.
|
|
45
47
|
*/
|
|
46
48
|
export declare function exportPacks({ packs, paths, signal, environment }: ExportOptions): Promise<ExportedPack[]>;
|
|
47
49
|
export {};
|
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 JSON schema validation is separate
|
|
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. JSON schema validation is separate; use validatePackContent when content checks are required.
|
|
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.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 } 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 });
|
|
@@ -106,12 +106,15 @@ export function migrateRegolithConfig(input, options = {}) {
|
|
|
106
106
|
}
|
|
107
107
|
delete config.worlds;
|
|
108
108
|
config.targetVersion = options.targetVersion ?? config.targetVersion;
|
|
109
|
-
|
|
109
|
+
if (typeof config.namespace === 'string') {
|
|
110
|
+
namespaces.add(config.namespace);
|
|
111
|
+
}
|
|
112
|
+
delete config.namespace;
|
|
110
113
|
if (config.targetVersion === undefined) {
|
|
111
114
|
report('target-version', '/targetVersion', 'Set targetVersion or pass --target-version with the intended Minecraft version.');
|
|
112
115
|
}
|
|
113
|
-
if (
|
|
114
|
-
report('namespace', '/
|
|
116
|
+
if (namespaces.size) {
|
|
117
|
+
report('manifest-namespace', '/packs', `Declare a namespace in each owner manifest.json. Source namespace values: ${[...namespaces].join(', ')}.`, 'warning');
|
|
115
118
|
}
|
|
116
119
|
config.$schema = options.schema ?? new URL('../schemas/config.schema.json', import.meta.url).href;
|
|
117
120
|
config.bedrockCore = { formatVersion: '1.0.0', profiles: Object.fromEntries(migrated) };
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { stages } from
|
|
3
|
-
import { isRecord, pointer } from
|
|
2
|
+
import { stages } from '../plan.js';
|
|
3
|
+
import { isRecord, pointer } from './types.js';
|
|
4
4
|
const keys = {
|
|
5
5
|
'manifest': ['manifestPath', 'pretty'],
|
|
6
6
|
'generator': ['include', 'exclude', 'pretty', 'types', 'schemaVersion', 'typesDir', 'strict', 'typePrefix', 'maxAgeHours'],
|
|
@@ -166,6 +166,7 @@ export function convertFilters(name, profiles, definitions, packs, dataPath, opt
|
|
|
166
166
|
if (typeof settings.namespace === 'string' && settings.namespace) {
|
|
167
167
|
namespaces.add(settings.namespace);
|
|
168
168
|
}
|
|
169
|
+
delete settings.namespace;
|
|
169
170
|
entries.push({ stage, settings, location });
|
|
170
171
|
}
|
|
171
172
|
function visit(profileName, parents) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { realpath } from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import { stages } from
|
|
3
|
+
import { stages } from '../plan.js';
|
|
4
4
|
/** Recognize canonical wrapper files in an explicitly trusted checkout without executing them. */
|
|
5
5
|
export async function localFilterKind(script, directory) {
|
|
6
6
|
const canonical = await realpath(script);
|
|
@@ -2,13 +2,14 @@ import { lstat, readFile, realpath, rename, rm, writeFile } from 'node:fs/promis
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { randomUUID } from 'node:crypto';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { migrateRegolithConfig } from
|
|
6
|
-
import { readManifest } from
|
|
7
|
-
import { inspectPack } from
|
|
8
|
-
import { resolveExportPaths } from
|
|
9
|
-
import { localFilterKind } from
|
|
10
|
-
import { validateConfig } from
|
|
11
|
-
import {
|
|
5
|
+
import { migrateRegolithConfig } from '../migrate.js';
|
|
6
|
+
import { readManifest } from '../manifest.js';
|
|
7
|
+
import { inspectPack } from '../packs.js';
|
|
8
|
+
import { resolveExportPaths } from '../export.js';
|
|
9
|
+
import { localFilterKind } from './local-filter.js';
|
|
10
|
+
import { validateConfig } from '../config.js';
|
|
11
|
+
import { scriptSource } from '@bedrock-core/builder-bundler/entries';
|
|
12
|
+
import { isRecord, pointer } from './types.js';
|
|
12
13
|
/**
|
|
13
14
|
* Inspect pack metadata and known local wrappers without importing any project code.
|
|
14
15
|
* @param options Project inputs, settings and optional integrations for this operation.
|
|
@@ -36,8 +37,16 @@ export async function migrateRegolithProject(configPath = 'config.json', options
|
|
|
36
37
|
continue;
|
|
37
38
|
}
|
|
38
39
|
try {
|
|
39
|
-
const manifest = await readManifest(id, packPath);
|
|
40
|
+
const manifest = await readManifest(id, packPath, true);
|
|
40
41
|
inferred.packKinds[id] = (await inspectPack(id, packPath)).kind;
|
|
42
|
+
for (const module of manifest.modules.filter(module => module.type === 'script')) {
|
|
43
|
+
try {
|
|
44
|
+
await scriptSource(id, path.resolve(packPath, module.entry), packPath);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
diagnostics.push({ severity: 'error', code: 'script-entry', path: `/packs/${pointer(id)}`, message: error instanceof Error ? error.message : String(error) });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
41
50
|
for (const uuid of [manifest.header.uuid, ...manifest.modules.map(module => module.uuid)]) {
|
|
42
51
|
if (identities.has(uuid.toLowerCase())) {
|
|
43
52
|
diagnostics.push({ severity: 'error', code: 'manifest-identity', path: `/packs/${pointer(id)}`, message: `Manifest UUID ${uuid} is repeated. Pack and module UUIDs must be unique.` });
|
|
@@ -15,8 +15,6 @@ export interface MigrationDiagnostic {
|
|
|
15
15
|
}
|
|
16
16
|
/** Explicit metadata, profile, filter and destination mappings for Regolith configuration conversion. */
|
|
17
17
|
export interface MigrationOptions {
|
|
18
|
-
/** Supply a missing project namespace. */
|
|
19
|
-
namespace?: string;
|
|
20
18
|
/** Supply a missing target Minecraft version. */
|
|
21
19
|
targetVersion?: string;
|
|
22
20
|
/** Profile names to convert; omission selects all profiles. */
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface PathAuditOptions {
|
|
2
|
+
maxLength: number;
|
|
3
|
+
folders?: {
|
|
4
|
+
creator: string;
|
|
5
|
+
pack: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
interface PathFinding {
|
|
9
|
+
rule: 'path-length' | 'path-depth' | 'asset-folder';
|
|
10
|
+
path: string;
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
/** Audit the file names of an existing pack or unpacked add-on. */
|
|
14
|
+
export declare function auditPackPaths(directory: string, { maxLength, folders }: PathAuditOptions): Promise<{
|
|
15
|
+
limits: {
|
|
16
|
+
length: number;
|
|
17
|
+
depth: number;
|
|
18
|
+
};
|
|
19
|
+
packs: {
|
|
20
|
+
path: string;
|
|
21
|
+
files: number;
|
|
22
|
+
longest: {
|
|
23
|
+
path: string;
|
|
24
|
+
length: number;
|
|
25
|
+
};
|
|
26
|
+
findings: PathFinding[];
|
|
27
|
+
}[];
|
|
28
|
+
}>;
|
|
29
|
+
export {};
|