@firstdraft.com/cli 0.2.1 → 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/RELEASING.md +13 -1
- package/docs/commands.md +131 -14
- package/docs/errors.md +24 -3
- package/docs/release-history.md +21 -0
- package/package.json +1 -1
- package/src/cli.js +20 -10
- package/src/commands/compilation.js +136 -109
- package/src/commands/plan-compile.js +46 -41
- package/src/commands/plan-init.js +5 -2
- package/src/compilation-artifact.js +121 -17
- package/src/root-output.js +1512 -0
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
MAX_ARTIFACT_BYTES,
|
|
11
11
|
materializeCompilationArtifact,
|
|
12
12
|
parseCompilationArtifact,
|
|
13
|
+
prepareCompilationOutputTarget,
|
|
14
|
+
releaseCompilationOutputTarget,
|
|
13
15
|
resolveOutputTarget,
|
|
14
16
|
} from "../compilation-artifact.js";
|
|
15
17
|
import {
|
|
@@ -312,43 +314,47 @@ export async function downloadCompilation({
|
|
|
312
314
|
createRequestSignal = (timeoutMs) => AbortSignal.timeout(timeoutMs),
|
|
313
315
|
}) {
|
|
314
316
|
const context = readContext({ cwd, compilationId, fileSystem });
|
|
315
|
-
const outputTarget =
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
317
|
+
const outputTarget = prepareCompilationOutputTarget({ cwd, output });
|
|
318
|
+
try {
|
|
319
|
+
const current = await readCompilationStatus({
|
|
320
|
+
...context,
|
|
321
|
+
fetchFunction,
|
|
322
|
+
createRequestSignal,
|
|
323
|
+
requestTimeout: REQUEST_TIMEOUT_MS,
|
|
324
|
+
});
|
|
325
|
+
if (current.compilation.status !== "succeeded") {
|
|
326
|
+
throw new CompilationNotSucceededError(current);
|
|
327
|
+
}
|
|
325
328
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
329
|
+
const metadata =
|
|
330
|
+
/** @type {{path: string, sha256: string, media_type: string, byte_size: number}} */ (
|
|
331
|
+
current.compilation.artifact
|
|
332
|
+
);
|
|
333
|
+
const source = await downloadArtifact({
|
|
334
|
+
apiUrl: context.apiUrl,
|
|
335
|
+
metadata,
|
|
336
|
+
fetchFunction,
|
|
337
|
+
createRequestSignal,
|
|
338
|
+
});
|
|
339
|
+
const artifact = parseCompilationArtifact(source, {
|
|
340
|
+
projectId: context.projectId,
|
|
341
|
+
compilationId: current.compilation.id,
|
|
342
|
+
graphVersion: current.compilation.graph_version,
|
|
343
|
+
headSourceSha256: current.compilation.head_source_sha256,
|
|
344
|
+
analysisRunId: current.compilation.analysis_run_id,
|
|
345
|
+
compilerRelease: current.compilation.compiler_release,
|
|
346
|
+
target: current.compilation.target,
|
|
347
|
+
});
|
|
348
|
+
const materialized = materializeCompilationArtifact(artifact, outputTarget);
|
|
346
349
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
return {
|
|
351
|
+
project: current.project,
|
|
352
|
+
compilation: current.compilation,
|
|
353
|
+
output: materialized,
|
|
354
|
+
};
|
|
355
|
+
} finally {
|
|
356
|
+
releaseCompilationOutputTarget(outputTarget);
|
|
357
|
+
}
|
|
352
358
|
}
|
|
353
359
|
|
|
354
360
|
/**
|
|
@@ -367,6 +373,7 @@ export async function downloadCompilation({
|
|
|
367
373
|
* @property {string} expectedEtag
|
|
368
374
|
* @property {CurrentCompilationIdentity} expected
|
|
369
375
|
* @property {string} output
|
|
376
|
+
* @property {string | import("../root-output.js").RootOutputTarget} [outputTarget]
|
|
370
377
|
* @property {typeof globalThis.fetch} [fetchFunction]
|
|
371
378
|
* @property {import("../plan-state.js").PlanStateFileSystem} [fileSystem]
|
|
372
379
|
* @property {(timeoutMs: number) => AbortSignal} [createRequestSignal]
|
|
@@ -378,7 +385,8 @@ export async function downloadCompilation({
|
|
|
378
385
|
/**
|
|
379
386
|
* Start one Compilation for the exact Plan and reviewed Analysis accepted by
|
|
380
387
|
* the current command, wait for that retained Compilation, and materialize its
|
|
381
|
-
* authenticated artifact into an absent destination
|
|
388
|
+
* authenticated artifact into an absent destination or the eligible current
|
|
389
|
+
* directory.
|
|
382
390
|
*
|
|
383
391
|
* @param {CompileAndDownloadOptions} options
|
|
384
392
|
*/
|
|
@@ -387,6 +395,7 @@ export async function compileAndDownload({
|
|
|
387
395
|
expectedEtag,
|
|
388
396
|
expected,
|
|
389
397
|
output,
|
|
398
|
+
outputTarget: suppliedOutputTarget,
|
|
390
399
|
fetchFunction = globalThis.fetch,
|
|
391
400
|
fileSystem = DEFAULT_FILE_SYSTEM,
|
|
392
401
|
createRequestSignal = (timeoutMs) => AbortSignal.timeout(timeoutMs),
|
|
@@ -394,89 +403,107 @@ export async function compileAndDownload({
|
|
|
394
403
|
now = Date.now,
|
|
395
404
|
onProgress = () => {},
|
|
396
405
|
}) {
|
|
397
|
-
const
|
|
398
|
-
const
|
|
399
|
-
cwd,
|
|
400
|
-
expectedEtag,
|
|
401
|
-
expected,
|
|
402
|
-
fileSystem,
|
|
403
|
-
});
|
|
404
|
-
const deadline = now() + WAIT_TIMEOUT_MS;
|
|
405
|
-
|
|
406
|
-
onProgress({ phase: "compilation", status: "waiting" });
|
|
407
|
-
const initial = await startCompilation({
|
|
408
|
-
...context,
|
|
409
|
-
expected,
|
|
410
|
-
fetchFunction,
|
|
411
|
-
createRequestSignal,
|
|
412
|
-
});
|
|
413
|
-
let current = initial;
|
|
414
|
-
|
|
406
|
+
const ownsOutputTarget = suppliedOutputTarget === undefined;
|
|
407
|
+
const outputTarget =
|
|
408
|
+
suppliedOutputTarget ?? prepareCompilationOutputTarget({ cwd, output });
|
|
415
409
|
try {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
410
|
+
const context = readStartContext({
|
|
411
|
+
cwd,
|
|
412
|
+
expectedEtag,
|
|
413
|
+
expected,
|
|
414
|
+
fileSystem,
|
|
415
|
+
});
|
|
416
|
+
if (
|
|
417
|
+
suppliedOutputTarget !== undefined &&
|
|
418
|
+
typeof outputTarget === "string"
|
|
419
|
+
) {
|
|
420
|
+
resolveOutputTarget({ cwd, output });
|
|
421
|
+
}
|
|
422
|
+
const deadline = now() + WAIT_TIMEOUT_MS;
|
|
419
423
|
|
|
420
|
-
|
|
421
|
-
|
|
424
|
+
onProgress({ phase: "compilation", status: "waiting" });
|
|
425
|
+
const initial = await startCompilation({
|
|
426
|
+
...context,
|
|
427
|
+
expected,
|
|
428
|
+
fetchFunction,
|
|
429
|
+
createRequestSignal,
|
|
430
|
+
});
|
|
431
|
+
let current = initial;
|
|
432
|
+
|
|
433
|
+
try {
|
|
434
|
+
while (!TERMINAL_STATUSES.has(current.compilation.status)) {
|
|
435
|
+
const remaining = deadline - now();
|
|
436
|
+
if (remaining <= 0) throw new CompilationTimeoutError(current);
|
|
437
|
+
|
|
438
|
+
await sleep(Math.min(POLL_INTERVAL_MS, remaining));
|
|
439
|
+
if (now() >= deadline) throw new CompilationTimeoutError(current);
|
|
440
|
+
|
|
441
|
+
const next = await readCompilationStatus({
|
|
442
|
+
apiUrl: context.apiUrl,
|
|
443
|
+
projectId: context.projectId,
|
|
444
|
+
compilationId: initial.compilation.id,
|
|
445
|
+
fetchFunction,
|
|
446
|
+
createRequestSignal,
|
|
447
|
+
requestTimeout: Math.max(
|
|
448
|
+
1,
|
|
449
|
+
Math.min(REQUEST_TIMEOUT_MS, deadline - now()),
|
|
450
|
+
),
|
|
451
|
+
});
|
|
452
|
+
if (
|
|
453
|
+
!sameCompilation(initial, next) ||
|
|
454
|
+
!validTransition(current, next)
|
|
455
|
+
) {
|
|
456
|
+
throw new CompilationChangedError(next);
|
|
457
|
+
}
|
|
458
|
+
current = next;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
if (current.compilation.status === "failed") {
|
|
462
|
+
throw new CompilationFailedError(current);
|
|
463
|
+
}
|
|
464
|
+
if (current.compilation.status === "cancelled") {
|
|
465
|
+
throw new CompilationCancelledError(current);
|
|
466
|
+
}
|
|
422
467
|
|
|
423
|
-
|
|
468
|
+
onProgress({ phase: "compilation", status: "succeeded" });
|
|
469
|
+
const metadata =
|
|
470
|
+
/** @type {{path: string, sha256: string, media_type: string, byte_size: number}} */ (
|
|
471
|
+
current.compilation.artifact
|
|
472
|
+
);
|
|
473
|
+
const source = await downloadArtifact({
|
|
424
474
|
apiUrl: context.apiUrl,
|
|
425
|
-
|
|
426
|
-
compilationId: initial.compilation.id,
|
|
475
|
+
metadata,
|
|
427
476
|
fetchFunction,
|
|
428
477
|
createRequestSignal,
|
|
429
|
-
requestTimeout: Math.max(
|
|
430
|
-
1,
|
|
431
|
-
Math.min(REQUEST_TIMEOUT_MS, deadline - now()),
|
|
432
|
-
),
|
|
433
478
|
});
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
onProgress({ phase: "compilation", status: "succeeded" });
|
|
448
|
-
const metadata =
|
|
449
|
-
/** @type {{path: string, sha256: string, media_type: string, byte_size: number}} */ (
|
|
450
|
-
current.compilation.artifact
|
|
479
|
+
const artifact = parseCompilationArtifact(source, {
|
|
480
|
+
projectId: context.projectId,
|
|
481
|
+
compilationId: current.compilation.id,
|
|
482
|
+
graphVersion: current.compilation.graph_version,
|
|
483
|
+
headSourceSha256: current.compilation.head_source_sha256,
|
|
484
|
+
analysisRunId: current.compilation.analysis_run_id,
|
|
485
|
+
compilerRelease: current.compilation.compiler_release,
|
|
486
|
+
target: current.compilation.target,
|
|
487
|
+
});
|
|
488
|
+
const materialized = materializeCompilationArtifact(
|
|
489
|
+
artifact,
|
|
490
|
+
outputTarget,
|
|
451
491
|
);
|
|
452
|
-
const source = await downloadArtifact({
|
|
453
|
-
apiUrl: context.apiUrl,
|
|
454
|
-
metadata,
|
|
455
|
-
fetchFunction,
|
|
456
|
-
createRequestSignal,
|
|
457
|
-
});
|
|
458
|
-
const artifact = parseCompilationArtifact(source, {
|
|
459
|
-
projectId: context.projectId,
|
|
460
|
-
compilationId: current.compilation.id,
|
|
461
|
-
graphVersion: current.compilation.graph_version,
|
|
462
|
-
headSourceSha256: current.compilation.head_source_sha256,
|
|
463
|
-
analysisRunId: current.compilation.analysis_run_id,
|
|
464
|
-
compilerRelease: current.compilation.compiler_release,
|
|
465
|
-
target: current.compilation.target,
|
|
466
|
-
});
|
|
467
|
-
const materialized = materializeCompilationArtifact(artifact, outputTarget);
|
|
468
492
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
493
|
+
return {
|
|
494
|
+
project: current.project,
|
|
495
|
+
compilation: current.compilation,
|
|
496
|
+
output: materialized,
|
|
497
|
+
};
|
|
498
|
+
} catch (error) {
|
|
499
|
+
if (requiresRetainedRecovery(error)) {
|
|
500
|
+
throw new CompilationRetainedError(error, current);
|
|
501
|
+
}
|
|
478
502
|
|
|
479
|
-
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
} finally {
|
|
506
|
+
if (ownsOutputTarget) releaseCompilationOutputTarget(outputTarget);
|
|
480
507
|
}
|
|
481
508
|
}
|
|
482
509
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { publishPlan } from "./plan-publish.js";
|
|
2
2
|
import { compileAndDownload } from "./compilation.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
prepareCompilationOutputTarget,
|
|
5
|
+
releaseCompilationOutputTarget,
|
|
6
|
+
} from "../compilation-artifact.js";
|
|
4
7
|
import {
|
|
5
8
|
PlanPushNetworkError,
|
|
6
9
|
PlanPushProtocolError,
|
|
@@ -130,8 +133,9 @@ export async function compilePlan({
|
|
|
130
133
|
|
|
131
134
|
/**
|
|
132
135
|
* Submit and analyze the exact current local Plan, then start one direct
|
|
133
|
-
* Compilation and materialize its verified artifact into an absent directory
|
|
134
|
-
* GitHub Publication remains the no-output
|
|
136
|
+
* Compilation and materialize its verified artifact into an absent directory
|
|
137
|
+
* or the eligible current directory. GitHub Publication remains the no-output
|
|
138
|
+
* mode owned by compilePlan.
|
|
135
139
|
*
|
|
136
140
|
* @param {CompilePlanToDirectoryOptions} options
|
|
137
141
|
*/
|
|
@@ -152,45 +156,46 @@ export async function compilePlanToDirectory({
|
|
|
152
156
|
readStatus = readPlanStatus,
|
|
153
157
|
compile = compileAndDownload,
|
|
154
158
|
}) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
readStatus,
|
|
172
|
-
});
|
|
173
|
-
const body = prepared.status.body;
|
|
159
|
+
const outputTarget = prepareCompilationOutputTarget({ cwd, output });
|
|
160
|
+
try {
|
|
161
|
+
const prepared = await preparePlan({
|
|
162
|
+
cwd,
|
|
163
|
+
apiUrl,
|
|
164
|
+
fetchFunction,
|
|
165
|
+
fileSystem,
|
|
166
|
+
createTemporaryId,
|
|
167
|
+
createRequestSignal,
|
|
168
|
+
analysisSleep,
|
|
169
|
+
analysisNow,
|
|
170
|
+
onProgress,
|
|
171
|
+
push,
|
|
172
|
+
readStatus,
|
|
173
|
+
});
|
|
174
|
+
const body = prepared.status.body;
|
|
174
175
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
return await compile({
|
|
177
|
+
cwd,
|
|
178
|
+
expectedEtag: prepared.pushed.etag,
|
|
179
|
+
expected: {
|
|
180
|
+
projectId: body.project.id,
|
|
181
|
+
graphVersion: body.project.graph_version,
|
|
182
|
+
headSourceSha256: body.analysis.head_source_sha256,
|
|
183
|
+
analysisRunId: body.analysis.id,
|
|
184
|
+
compilerRelease: body.analysis.compiler_release,
|
|
185
|
+
target: body.analysis.target,
|
|
186
|
+
},
|
|
187
|
+
output,
|
|
188
|
+
outputTarget,
|
|
189
|
+
fetchFunction,
|
|
190
|
+
fileSystem,
|
|
191
|
+
createRequestSignal,
|
|
192
|
+
sleep: compilationSleep,
|
|
193
|
+
now: compilationNow,
|
|
194
|
+
onProgress,
|
|
195
|
+
});
|
|
196
|
+
} finally {
|
|
197
|
+
releaseCompilationOutputTarget(outputTarget);
|
|
198
|
+
}
|
|
194
199
|
}
|
|
195
200
|
|
|
196
201
|
/**
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
FOUNDATION_PLAN_FORMAT,
|
|
6
|
+
RAILS_TARGET_PROFILE,
|
|
7
|
+
} from "../compilation-artifact.js";
|
|
5
8
|
|
|
6
9
|
/**
|
|
7
10
|
* @typedef {object} FileSystem
|
|
@@ -58,7 +61,7 @@ function emptyPlan(applicationKey, name) {
|
|
|
58
61
|
format: FOUNDATION_PLAN_FORMAT,
|
|
59
62
|
target: {
|
|
60
63
|
id: "rails",
|
|
61
|
-
profile:
|
|
64
|
+
profile: RAILS_TARGET_PROFILE,
|
|
62
65
|
},
|
|
63
66
|
application: {
|
|
64
67
|
key: applicationKey,
|
|
@@ -14,11 +14,20 @@ import path from "node:path";
|
|
|
14
14
|
|
|
15
15
|
import { isFileSystemError } from "./file-system.js";
|
|
16
16
|
import { isUuidV7 } from "./plan-state.js";
|
|
17
|
+
import {
|
|
18
|
+
materializeRootOutput,
|
|
19
|
+
prepareRootOutput,
|
|
20
|
+
releaseRootOutput,
|
|
21
|
+
resolveRootOutputPath,
|
|
22
|
+
RootOutputMaterializationError,
|
|
23
|
+
RootOutputPathError,
|
|
24
|
+
} from "./root-output.js";
|
|
17
25
|
|
|
18
26
|
export const ARTIFACT_MEDIA_TYPE =
|
|
19
27
|
"application/vnd.firstdraft.compilation-artifact+json";
|
|
20
28
|
export const ARTIFACT_FORMAT = "firstdraft.compilation-artifact/1";
|
|
21
|
-
export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.
|
|
29
|
+
export const FOUNDATION_PLAN_FORMAT = "firstdraft.foundation-plan.sketch/0.20";
|
|
30
|
+
export const RAILS_TARGET_PROFILE = "rails-sketch/2026-09";
|
|
22
31
|
export const MAX_ARTIFACT_BYTES = 128 * 1024 * 1024;
|
|
23
32
|
|
|
24
33
|
const ARTIFACT_KEYS = ["format", "provenance", "manifest_sha256", "files"];
|
|
@@ -61,8 +70,21 @@ const DIRECTORY_MODE = 0o755;
|
|
|
61
70
|
const POSIX_MODE_BITS_SUPPORTED = process.platform !== "win32";
|
|
62
71
|
|
|
63
72
|
export class CompilationArtifactInvalidError extends Error {}
|
|
64
|
-
export class CompilationMaterializationError extends Error {
|
|
65
|
-
|
|
73
|
+
export class CompilationMaterializationError extends Error {
|
|
74
|
+
/** @param {string} message @param {{cause?: unknown, reason?: string, recoveryPath?: string}} [options] */
|
|
75
|
+
constructor(message, options = {}) {
|
|
76
|
+
super(message, options);
|
|
77
|
+
this.reason = options.reason;
|
|
78
|
+
this.recoveryPath = options.recoveryPath;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export class CompilationOutputPathError extends Error {
|
|
82
|
+
/** @param {string} message @param {{cause?: unknown, reason?: string}} [options] */
|
|
83
|
+
constructor(message, options = {}) {
|
|
84
|
+
super(message, options);
|
|
85
|
+
this.reason = options.reason;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
66
88
|
|
|
67
89
|
/**
|
|
68
90
|
* @typedef {object} ValidatedCompilationProvenance
|
|
@@ -171,13 +193,15 @@ export function resolveOutputTarget({ cwd, output }) {
|
|
|
171
193
|
|
|
172
194
|
const target = path.resolve(cwd, output);
|
|
173
195
|
const parent = path.dirname(target);
|
|
196
|
+
const targetIsAbsent = isInitiallyAbsent(target);
|
|
174
197
|
if (
|
|
175
198
|
target === parent ||
|
|
176
199
|
path.basename(target).length === 0 ||
|
|
177
|
-
!
|
|
200
|
+
!targetIsAbsent
|
|
178
201
|
) {
|
|
179
202
|
throw new CompilationOutputPathError(
|
|
180
203
|
"The compilation output path must be absent.",
|
|
204
|
+
targetIsAbsent ? undefined : { reason: "destination_exists" },
|
|
181
205
|
);
|
|
182
206
|
}
|
|
183
207
|
|
|
@@ -201,11 +225,80 @@ export function resolveOutputTarget({ cwd, output }) {
|
|
|
201
225
|
return target;
|
|
202
226
|
}
|
|
203
227
|
|
|
228
|
+
/**
|
|
229
|
+
* Validate an ordinary absent output or reserve root adoption before requests.
|
|
230
|
+
*
|
|
231
|
+
* @param {object} options
|
|
232
|
+
* @param {string} options.cwd
|
|
233
|
+
* @param {string} options.output
|
|
234
|
+
*/
|
|
235
|
+
export function prepareCompilationOutputTarget({ cwd, output }) {
|
|
236
|
+
if (
|
|
237
|
+
typeof output !== "string" ||
|
|
238
|
+
output.length === 0 ||
|
|
239
|
+
output.includes("\0")
|
|
240
|
+
) {
|
|
241
|
+
throw new CompilationOutputPathError(
|
|
242
|
+
"The compilation output path is invalid.",
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const root = resolveRootOutputPath({ cwd, output });
|
|
247
|
+
if (root === null) return resolveOutputTarget({ cwd, output });
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
return prepareRootOutput({ root });
|
|
251
|
+
} catch (error) {
|
|
252
|
+
if (!(error instanceof RootOutputPathError)) throw error;
|
|
253
|
+
throw new CompilationOutputPathError(error.message, {
|
|
254
|
+
cause: error,
|
|
255
|
+
reason: error.reason,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** @param {string | import("./root-output.js").RootOutputTarget} target */
|
|
261
|
+
export function releaseCompilationOutputTarget(target) {
|
|
262
|
+
if (typeof target === "string") return;
|
|
263
|
+
try {
|
|
264
|
+
releaseRootOutput(target);
|
|
265
|
+
} catch (error) {
|
|
266
|
+
if (!(error instanceof RootOutputMaterializationError)) throw error;
|
|
267
|
+
throw new CompilationMaterializationError(error.message, {
|
|
268
|
+
cause: error,
|
|
269
|
+
reason: error.reason,
|
|
270
|
+
recoveryPath: error.recoveryPath,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
204
275
|
/**
|
|
205
276
|
* @param {ValidatedCompilationArtifact} artifact
|
|
206
|
-
* @param {string} target
|
|
277
|
+
* @param {string | import("./root-output.js").RootOutputTarget} target
|
|
207
278
|
*/
|
|
208
279
|
export function materializeCompilationArtifact(artifact, target) {
|
|
280
|
+
if (typeof target !== "string") {
|
|
281
|
+
try {
|
|
282
|
+
return materializeRootOutput(target, artifact, {
|
|
283
|
+
writeArtifact: (root) => {
|
|
284
|
+
writeArtifactTree(artifact.files, root);
|
|
285
|
+
applyMode(root, DIRECTORY_MODE);
|
|
286
|
+
},
|
|
287
|
+
verifyArtifact: (root, ignoredPaths) =>
|
|
288
|
+
verifyArtifactTree(artifact.files, root, ignoredPaths, {
|
|
289
|
+
verifyRootMode: ignoredPaths === undefined,
|
|
290
|
+
}),
|
|
291
|
+
});
|
|
292
|
+
} catch (error) {
|
|
293
|
+
if (!(error instanceof RootOutputMaterializationError)) throw error;
|
|
294
|
+
throw new CompilationMaterializationError(error.message, {
|
|
295
|
+
cause: error,
|
|
296
|
+
reason: error.reason,
|
|
297
|
+
recoveryPath: error.recoveryPath,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
209
302
|
const parent = path.dirname(target);
|
|
210
303
|
const prefix = path.join(parent, `.firstdraft-${path.basename(target)}-`);
|
|
211
304
|
let temporaryDirectory = null;
|
|
@@ -222,10 +315,8 @@ export function materializeCompilationArtifact(artifact, target) {
|
|
|
222
315
|
renameSync(temporaryDirectory, target);
|
|
223
316
|
temporaryDirectory = null;
|
|
224
317
|
} catch (error) {
|
|
225
|
-
if (
|
|
226
|
-
|
|
227
|
-
isFileSystemError(error)
|
|
228
|
-
) {
|
|
318
|
+
if (error instanceof CompilationMaterializationError) throw error;
|
|
319
|
+
if (isFileSystemError(error)) {
|
|
229
320
|
throw new CompilationMaterializationError(
|
|
230
321
|
"The compilation artifact could not be materialized.",
|
|
231
322
|
{ cause: error },
|
|
@@ -271,6 +362,7 @@ function parseProvenance(value, expected) {
|
|
|
271
362
|
!hasExactKeys(value.target, TARGET_KEYS) ||
|
|
272
363
|
value.target.id !== expected.target.id ||
|
|
273
364
|
value.target.profile !== expected.target.profile ||
|
|
365
|
+
value.target.profile !== RAILS_TARGET_PROFILE ||
|
|
274
366
|
!hasExactKeys(value.core, CORE_KEYS) ||
|
|
275
367
|
!isRepository(value.core.repository) ||
|
|
276
368
|
typeof value.core.revision !== "string" ||
|
|
@@ -502,12 +594,22 @@ function writeArtifactTree(files, root) {
|
|
|
502
594
|
}
|
|
503
595
|
}
|
|
504
596
|
|
|
505
|
-
/**
|
|
506
|
-
|
|
597
|
+
/**
|
|
598
|
+
* @param {ValidatedArtifactFile[]} files
|
|
599
|
+
* @param {string} root
|
|
600
|
+
* @param {Set<string>} [ignoredPaths]
|
|
601
|
+
* @param {{verifyRootMode?: boolean}} [options]
|
|
602
|
+
*/
|
|
603
|
+
function verifyArtifactTree(
|
|
604
|
+
files,
|
|
605
|
+
root,
|
|
606
|
+
ignoredPaths = new Set(),
|
|
607
|
+
{ verifyRootMode = true } = {},
|
|
608
|
+
) {
|
|
507
609
|
const expectedFiles = new Map(files.map((file) => [file.path, file]));
|
|
508
610
|
const expectedDirectories = new Set();
|
|
509
|
-
for (const
|
|
510
|
-
const components =
|
|
611
|
+
for (const relativePath of [...expectedFiles.keys(), ...ignoredPaths]) {
|
|
612
|
+
const components = relativePath.split("/");
|
|
511
613
|
for (let index = 1; index < components.length; index += 1) {
|
|
512
614
|
expectedDirectories.add(components.slice(0, index).join("/"));
|
|
513
615
|
}
|
|
@@ -519,13 +621,13 @@ function verifyArtifactTree(files, root) {
|
|
|
519
621
|
if (
|
|
520
622
|
!rootStat.isDirectory() ||
|
|
521
623
|
rootStat.isSymbolicLink() ||
|
|
522
|
-
!hasExpectedMode(rootStat.mode, DIRECTORY_MODE)
|
|
624
|
+
(verifyRootMode && !hasExpectedMode(rootStat.mode, DIRECTORY_MODE))
|
|
523
625
|
) {
|
|
524
626
|
throw new CompilationMaterializationError(
|
|
525
627
|
"The materialized compilation root is invalid.",
|
|
526
628
|
);
|
|
527
629
|
}
|
|
528
|
-
walkTree(root, "", actualFiles, actualDirectories);
|
|
630
|
+
walkTree(root, "", actualFiles, actualDirectories, ignoredPaths);
|
|
529
631
|
if (
|
|
530
632
|
!setsEqual(actualFiles, new Set(expectedFiles.keys())) ||
|
|
531
633
|
!setsEqual(actualDirectories, expectedDirectories)
|
|
@@ -581,16 +683,18 @@ function hasExpectedMode(actual, expected) {
|
|
|
581
683
|
* @param {string} relative
|
|
582
684
|
* @param {Set<string>} files
|
|
583
685
|
* @param {Set<string>} directories
|
|
686
|
+
* @param {Set<string>} ignoredPaths
|
|
584
687
|
*/
|
|
585
|
-
function walkTree(root, relative, files, directories) {
|
|
688
|
+
function walkTree(root, relative, files, directories, ignoredPaths) {
|
|
586
689
|
const directory = relative ? path.join(root, ...relative.split("/")) : root;
|
|
587
690
|
const entries = readdirSync(directory, { withFileTypes: true });
|
|
588
691
|
|
|
589
692
|
for (const entry of entries) {
|
|
590
693
|
const entryRelative = relative ? `${relative}/${entry.name}` : entry.name;
|
|
694
|
+
if (ignoredPaths.has(entryRelative)) continue;
|
|
591
695
|
if (entry.isDirectory()) {
|
|
592
696
|
directories.add(entryRelative);
|
|
593
|
-
walkTree(root, entryRelative, files, directories);
|
|
697
|
+
walkTree(root, entryRelative, files, directories, ignoredPaths);
|
|
594
698
|
} else if (entry.isFile()) {
|
|
595
699
|
files.add(entryRelative);
|
|
596
700
|
} else {
|