@valbuild/cli 0.136.10 → 0.138.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 +51 -0
- package/cli/dist/valbuild-cli-cli.cjs.dev.js +557 -44
- package/cli/dist/valbuild-cli-cli.cjs.prod.js +557 -44
- package/cli/dist/valbuild-cli-cli.esm.js +557 -45
- package/package.json +29 -7
- package/src/ciReport.ts +39 -0
- package/src/cli.ts +41 -10
- package/src/publish/__fixtures__/buildPublishProbe.ts +226 -0
- package/src/publish/artifacts.ts +4 -4
- package/src/publish/buildArtifacts.ts +340 -0
- package/src/publish/buildPublish.test.ts +108 -0
- package/src/publish/client.ts +8 -0
- package/src/publish/fakeContent.ts +60 -5
- package/src/publish/reportCiRun.test.ts +110 -0
- package/src/publish/reportCiRun.ts +105 -0
- package/src/publish/runPublish.ts +105 -23
|
@@ -15,6 +15,7 @@ var JSZip = require('jszip');
|
|
|
15
15
|
var readline = require('readline');
|
|
16
16
|
var crypto = require('crypto');
|
|
17
17
|
var zlib = require('zlib');
|
|
18
|
+
var os = require('os');
|
|
18
19
|
|
|
19
20
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
20
21
|
|
|
@@ -47,6 +48,7 @@ var JSZip__default = /*#__PURE__*/_interopDefault(JSZip);
|
|
|
47
48
|
var readline__default = /*#__PURE__*/_interopDefault(readline);
|
|
48
49
|
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
49
50
|
var zlib__default = /*#__PURE__*/_interopDefault(zlib);
|
|
51
|
+
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
50
52
|
|
|
51
53
|
function error(message) {
|
|
52
54
|
console.error(chalk__default["default"].red("❌Error: ") + message);
|
|
@@ -2129,10 +2131,10 @@ function confirm(question) {
|
|
|
2129
2131
|
* imports it at, so a normalised name produces a bundle whose imports resolve
|
|
2130
2132
|
* to nothing, at runtime, in the isolate.
|
|
2131
2133
|
*
|
|
2132
|
-
* **This is the seam with the build.**
|
|
2133
|
-
*
|
|
2134
|
-
*
|
|
2135
|
-
*
|
|
2134
|
+
* **This is the seam with the build.** Whatever built the project writes this
|
|
2135
|
+
* directory, and this reads it: `buildArtifacts` when `val publish` builds the
|
|
2136
|
+
* checkout itself, or anything else that lays out the same keys, handed over
|
|
2137
|
+
* with `--artifacts`. One path for bytes to leave by, whoever built them.
|
|
2136
2138
|
*/
|
|
2137
2139
|
async function collectArtifacts(dir) {
|
|
2138
2140
|
const artifacts = [];
|
|
@@ -2284,6 +2286,287 @@ function resolveArtifactsDir(options) {
|
|
|
2284
2286
|
};
|
|
2285
2287
|
}
|
|
2286
2288
|
|
|
2289
|
+
/**
|
|
2290
|
+
* `val publish`'s build: the site, built from the checkout, as the artifacts
|
|
2291
|
+
* the publish API takes (valbuild/home, docs/app-mode.md, "Briefing:
|
|
2292
|
+
* val-publish" and "Flow B").
|
|
2293
|
+
*
|
|
2294
|
+
* The same builder the Studio runs in a tab -- `@valbuild/tanstack-build` --
|
|
2295
|
+
* plus the half a tab cannot run: the project's dependency layer, built from
|
|
2296
|
+
* its own `node_modules` (`@valbuild/tanstack-build/node`). So a CI checkout
|
|
2297
|
+
* and a Studio build of the same content produce the same site, and the layer
|
|
2298
|
+
* is the one thing only this side can make.
|
|
2299
|
+
*
|
|
2300
|
+
* Against content's build target, never the loader's: content is the only
|
|
2301
|
+
* address a publisher has, and it answers what the platform expects.
|
|
2302
|
+
*
|
|
2303
|
+
* Written to a directory, and then published by the upload path `val publish
|
|
2304
|
+
* --artifacts` has always had: one path for bytes to leave by, whoever built
|
|
2305
|
+
* them.
|
|
2306
|
+
*/
|
|
2307
|
+
|
|
2308
|
+
/** What `val publish` hands on to the upload. */
|
|
2309
|
+
|
|
2310
|
+
/**
|
|
2311
|
+
* The builder, loaded only when a build is asked for: it brings rolldown's
|
|
2312
|
+
* native binary with it, and `val validate` has no use for one.
|
|
2313
|
+
*/
|
|
2314
|
+
async function loadBuilder() {
|
|
2315
|
+
try {
|
|
2316
|
+
const [build, node] = await Promise.all([Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@valbuild/tanstack-build')); }), Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@valbuild/tanstack-build/node')); })]);
|
|
2317
|
+
return {
|
|
2318
|
+
status: "ok",
|
|
2319
|
+
build,
|
|
2320
|
+
node
|
|
2321
|
+
};
|
|
2322
|
+
} catch (e) {
|
|
2323
|
+
return {
|
|
2324
|
+
status: "error",
|
|
2325
|
+
message: "`val publish` builds the site with @valbuild/tanstack-build and rolldown, and " + `they could not be loaded: ${e instanceof Error ? e.message : String(e)}\n\n` + "Install them in the project:\n\n" + " npm install --save-dev @valbuild/tanstack-build rolldown @tanstack/router-generator @tanstack/router-plugin\n\n" + "or publish a build made elsewhere with --artifacts <dir>."
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
|
|
2330
|
+
/**
|
|
2331
|
+
* Never the project's own files, at any depth: installed packages. Dot
|
|
2332
|
+
* directories (`.git`, `.tanstack`, `.val`, `.output`) are tooling too.
|
|
2333
|
+
*/
|
|
2334
|
+
const IGNORED_DIRS = new Set(["node_modules"]);
|
|
2335
|
+
|
|
2336
|
+
/**
|
|
2337
|
+
* Build output, at the project's root only: `src/routes/build/` is a route
|
|
2338
|
+
* called "build", not a previous build.
|
|
2339
|
+
*/
|
|
2340
|
+
const ROOT_OUTPUT_DIRS = new Set(["dist", "build"]);
|
|
2341
|
+
|
|
2342
|
+
/** Lockfiles are JSON, and nothing imports them. */
|
|
2343
|
+
const ROOT_LOCKFILES = new Set(["package-lock.json"]);
|
|
2344
|
+
const CODE_FILE = /\.(tsx?|jsx?|mjs|cjs|css)$/;
|
|
2345
|
+
|
|
2346
|
+
/**
|
|
2347
|
+
* JSON is the project's too: `tsconfig.json` and `tsr.config.json` are read
|
|
2348
|
+
* by the build, a `.val.json` holds a `.jsonValues()` entry no import points
|
|
2349
|
+
* at, and a module may import one -- the starter's `val.server.ts` imports
|
|
2350
|
+
* `.prettierrc.json`, which is also why a dot FILE is read.
|
|
2351
|
+
*/
|
|
2352
|
+
const JSON_FILE = /\.json$/;
|
|
2353
|
+
|
|
2354
|
+
/**
|
|
2355
|
+
* The project's own files: its source as text, and the binaries it imports
|
|
2356
|
+
* (an image, a font) base64, as `BuildInput.assets` takes them. `public/` is
|
|
2357
|
+
* neither: it is served as is, and read by `readPublicFiles`.
|
|
2358
|
+
*/
|
|
2359
|
+
function readProjectFiles(root, isAsset) {
|
|
2360
|
+
const sources = {};
|
|
2361
|
+
const assets = {};
|
|
2362
|
+
const walk = dir => {
|
|
2363
|
+
let entries;
|
|
2364
|
+
try {
|
|
2365
|
+
entries = fs__default$1["default"].readdirSync(dir, {
|
|
2366
|
+
withFileTypes: true
|
|
2367
|
+
});
|
|
2368
|
+
} catch {
|
|
2369
|
+
return;
|
|
2370
|
+
}
|
|
2371
|
+
for (const entry of entries) {
|
|
2372
|
+
const full = path__default["default"].join(dir, entry.name);
|
|
2373
|
+
if (entry.isDirectory()) {
|
|
2374
|
+
if (entry.name.startsWith(".") || IGNORED_DIRS.has(entry.name)) continue;
|
|
2375
|
+
if (dir === root && ROOT_OUTPUT_DIRS.has(entry.name)) continue;
|
|
2376
|
+
if (dir === root && entry.name === "public") continue;
|
|
2377
|
+
walk(full);
|
|
2378
|
+
continue;
|
|
2379
|
+
}
|
|
2380
|
+
const key = path__default["default"].relative(root, full).split(path__default["default"].sep).join("/");
|
|
2381
|
+
if (CODE_FILE.test(entry.name)) {
|
|
2382
|
+
sources[key] = fs__default$1["default"].readFileSync(full, "utf8");
|
|
2383
|
+
} else if (JSON_FILE.test(entry.name)) {
|
|
2384
|
+
if (!ROOT_LOCKFILES.has(key)) {
|
|
2385
|
+
sources[key] = fs__default$1["default"].readFileSync(full, "utf8");
|
|
2386
|
+
}
|
|
2387
|
+
} else if (isAsset(key)) {
|
|
2388
|
+
assets[key] = fs__default$1["default"].readFileSync(full).toString("base64");
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
walk(root);
|
|
2393
|
+
return {
|
|
2394
|
+
sources,
|
|
2395
|
+
assets
|
|
2396
|
+
};
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
/** Files under `public/`, base64, keyed `public/<path>` as the build takes them. */
|
|
2400
|
+
function readPublicFiles(root) {
|
|
2401
|
+
const out = {};
|
|
2402
|
+
const base = path__default["default"].join(root, "public");
|
|
2403
|
+
const walk = dir => {
|
|
2404
|
+
let entries;
|
|
2405
|
+
try {
|
|
2406
|
+
entries = fs__default$1["default"].readdirSync(dir, {
|
|
2407
|
+
withFileTypes: true
|
|
2408
|
+
});
|
|
2409
|
+
} catch {
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
for (const entry of entries) {
|
|
2413
|
+
const full = path__default["default"].join(dir, entry.name);
|
|
2414
|
+
if (entry.isDirectory()) walk(full);else {
|
|
2415
|
+
const key = path__default["default"].relative(root, full).split(path__default["default"].sep).join("/");
|
|
2416
|
+
out[key] = fs__default$1["default"].readFileSync(full).toString("base64");
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
};
|
|
2420
|
+
walk(base);
|
|
2421
|
+
return out;
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
/** The project's build-time variables: `PUBLIC_*` reach the browser, by the builder's rule. */
|
|
2425
|
+
function publicEnv(env) {
|
|
2426
|
+
const out = {};
|
|
2427
|
+
for (const [key, value] of Object.entries(env)) {
|
|
2428
|
+
if (key.startsWith("PUBLIC_") && value !== undefined) out[key] = value;
|
|
2429
|
+
}
|
|
2430
|
+
return out;
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
/**
|
|
2434
|
+
* The target, with this project's layer as built here rather than as content
|
|
2435
|
+
* last stored it: a build has to link against the layer it ships with.
|
|
2436
|
+
*/
|
|
2437
|
+
function targetWithLayer(target, layer) {
|
|
2438
|
+
return {
|
|
2439
|
+
...target,
|
|
2440
|
+
project: {
|
|
2441
|
+
...target.project,
|
|
2442
|
+
rev: (layer === null || layer === void 0 ? void 0 : layer.rev) ?? null,
|
|
2443
|
+
modules: (layer === null || layer === void 0 ? void 0 : layer.modules) ?? {},
|
|
2444
|
+
css: (layer === null || layer === void 0 ? void 0 : layer.css) ?? {},
|
|
2445
|
+
workerOnly: (layer === null || layer === void 0 ? void 0 : layer.workerOnly) ?? []
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
function writeArtifact(dir, key, body) {
|
|
2450
|
+
const file = path__default["default"].join(dir, ...key.split("/"));
|
|
2451
|
+
fs__default$1["default"].mkdirSync(path__default["default"].dirname(file), {
|
|
2452
|
+
recursive: true
|
|
2453
|
+
});
|
|
2454
|
+
fs__default$1["default"].writeFileSync(file, body);
|
|
2455
|
+
}
|
|
2456
|
+
async function buildArtifacts(options) {
|
|
2457
|
+
const log = options.log ?? (() => {});
|
|
2458
|
+
const loaded = await loadBuilder();
|
|
2459
|
+
if (loaded.status === "error") return loaded;
|
|
2460
|
+
const {
|
|
2461
|
+
build: builder,
|
|
2462
|
+
node
|
|
2463
|
+
} = loaded;
|
|
2464
|
+
const {
|
|
2465
|
+
root,
|
|
2466
|
+
target
|
|
2467
|
+
} = options;
|
|
2468
|
+
const warnings = [];
|
|
2469
|
+
try {
|
|
2470
|
+
/*
|
|
2471
|
+
* Wired for the platform at publish time, as the Studio's builds are: the
|
|
2472
|
+
* wired `val.server.ts` reads its files from a module the BUILD emits, so
|
|
2473
|
+
* no checkout can carry it. `rebakeGit` would be the tab's spelling of the
|
|
2474
|
+
* same thing for a record that is already wired.
|
|
2475
|
+
*/
|
|
2476
|
+
const {
|
|
2477
|
+
sources: onDisk,
|
|
2478
|
+
assets
|
|
2479
|
+
} = readProjectFiles(root, builder.isAsset);
|
|
2480
|
+
const wiring = builder.isValProject(onDisk) && !builder.isWired(onDisk) ? builder.wireUp(onDisk, {
|
|
2481
|
+
project: options.project,
|
|
2482
|
+
loader: options.contentHost,
|
|
2483
|
+
...(options.git ? {
|
|
2484
|
+
git: options.git
|
|
2485
|
+
} : {})
|
|
2486
|
+
}) : null;
|
|
2487
|
+
// Less the one about the layer, which is the thing this goes on to build.
|
|
2488
|
+
warnings.push(...((wiring === null || wiring === void 0 ? void 0 : wiring.warnings) ?? []).filter(warning => !warning.includes("dependency layer built for it")));
|
|
2489
|
+
const sources = (wiring === null || wiring === void 0 ? void 0 : wiring.files) ?? onDisk;
|
|
2490
|
+
|
|
2491
|
+
// The dependency layer: from what the project imports, of what it declares.
|
|
2492
|
+
log("Building the dependency layer");
|
|
2493
|
+
const manifest = (() => {
|
|
2494
|
+
try {
|
|
2495
|
+
return JSON.parse(sources["package.json"] ?? "{}");
|
|
2496
|
+
} catch {
|
|
2497
|
+
return {};
|
|
2498
|
+
}
|
|
2499
|
+
})();
|
|
2500
|
+
const deps = node.layerDepsOf(manifest, sources);
|
|
2501
|
+
const css = await node.collectDependencyCss(root, node.cssSpecifiersOf(sources));
|
|
2502
|
+
const layer = await node.buildVendorLayer(root, deps, css, {
|
|
2503
|
+
base: target.base,
|
|
2504
|
+
// A project on the platform layers its own copies; only the platform's
|
|
2505
|
+
// own checkout carries pinned ones.
|
|
2506
|
+
resolvePlatformModule: () => null,
|
|
2507
|
+
// No built base layer here: the export audit is skipped, not failed.
|
|
2508
|
+
baseLayerDir: null
|
|
2509
|
+
});
|
|
2510
|
+
log("Building the site");
|
|
2511
|
+
const fileBased = await node.isFileBased(root);
|
|
2512
|
+
const files = fileBased ? await node.generateRouteTree(root, sources) : sources;
|
|
2513
|
+
/*
|
|
2514
|
+
* The project's copy of the splitter first, then the one beside this CLI
|
|
2515
|
+
* -- where a package manager puts an optional peer the project installed
|
|
2516
|
+
* but did not hoist. Neither is a build that does not split, which costs
|
|
2517
|
+
* size and not behaviour.
|
|
2518
|
+
*/
|
|
2519
|
+
const splitter = (await node.routeSplitter(root)) ?? (typeof __dirname === "string" ? await node.routeSplitter(__dirname) : null);
|
|
2520
|
+
if (splitter === null) {
|
|
2521
|
+
warnings.push("Routes are not code-split: @tanstack/router-plugin is not installed.");
|
|
2522
|
+
}
|
|
2523
|
+
const built = await builder.buildUserApp({
|
|
2524
|
+
files,
|
|
2525
|
+
target: targetWithLayer(target, layer),
|
|
2526
|
+
env: publicEnv(options.env ?? process.env),
|
|
2527
|
+
publicFiles: readPublicFiles(root),
|
|
2528
|
+
assets,
|
|
2529
|
+
// The project's own files, without the generated tree: what the next
|
|
2530
|
+
// publish -- the Studio's included -- starts from.
|
|
2531
|
+
projectSource: sources,
|
|
2532
|
+
loadCssModule: node.cssModuleLoader(root),
|
|
2533
|
+
...(splitter ? {
|
|
2534
|
+
routeSplitter: splitter
|
|
2535
|
+
} : {}),
|
|
2536
|
+
rsc: target.project.rsc
|
|
2537
|
+
});
|
|
2538
|
+
const artifacts = await builder.publishArtifacts(built, {
|
|
2539
|
+
projectSource: sources
|
|
2540
|
+
});
|
|
2541
|
+
const dir = options.outDir ?? fs__default$1["default"].mkdtempSync(path__default["default"].join(os__default["default"].tmpdir(), "val-publish-"));
|
|
2542
|
+
for (const artifact of artifacts) {
|
|
2543
|
+
writeArtifact(dir, artifact.key, artifact.body);
|
|
2544
|
+
}
|
|
2545
|
+
/*
|
|
2546
|
+
* The layer: sent when content does not hold this one, named when it
|
|
2547
|
+
* does. The rev is a digest of the built chunks, so "content has this" is
|
|
2548
|
+
* a fact rather than a hope.
|
|
2549
|
+
*/
|
|
2550
|
+
let layerRev;
|
|
2551
|
+
if (layer === null) layerRev = null;else if (layer.rev === target.project.rev) layerRev = layer.rev;else writeArtifact(dir, "layer", zlib__default["default"].gzipSync(JSON.stringify(layer)));
|
|
2552
|
+
return {
|
|
2553
|
+
status: "built",
|
|
2554
|
+
dir,
|
|
2555
|
+
buildHash: built.hash,
|
|
2556
|
+
linksOwnCss: built.linksOwnCss,
|
|
2557
|
+
...(layerRev !== undefined ? {
|
|
2558
|
+
layerRev
|
|
2559
|
+
} : {}),
|
|
2560
|
+
warnings
|
|
2561
|
+
};
|
|
2562
|
+
} catch (e) {
|
|
2563
|
+
return {
|
|
2564
|
+
status: "error",
|
|
2565
|
+
message: `The site could not be built: ${e instanceof Error ? e.message.split("\n")[0] : String(e)}`
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
|
|
2287
2570
|
/**
|
|
2288
2571
|
* The one host `val publish` talks to.
|
|
2289
2572
|
*
|
|
@@ -2430,6 +2713,11 @@ function createPublishClient(options) {
|
|
|
2430
2713
|
};
|
|
2431
2714
|
const publishUrl = (publishId, step) => `${host}/v1/publish/${encodeURIComponent(publishId)}${step ? `/${step}` : ""}`;
|
|
2432
2715
|
return {
|
|
2716
|
+
buildTarget: async () => internal.parseBuildTarget(await getJson({
|
|
2717
|
+
url: `${host}/v1/build-target`,
|
|
2718
|
+
headers,
|
|
2719
|
+
fetchImpl
|
|
2720
|
+
})),
|
|
2433
2721
|
declare: async body => internal.parseDeclare(await postJson({
|
|
2434
2722
|
url: `${host}/v1/publish`,
|
|
2435
2723
|
headers,
|
|
@@ -2769,40 +3057,33 @@ const DECLARE_ROUNDS = 3;
|
|
|
2769
3057
|
* that could reach either.
|
|
2770
3058
|
*/
|
|
2771
3059
|
async function runPublish(options) {
|
|
3060
|
+
var _built;
|
|
2772
3061
|
const env = options.env ?? process.env;
|
|
2773
3062
|
const log = options.log ?? (line => console.log(line));
|
|
2774
3063
|
const sleep = options.sleep ?? (ms => new Promise(resolve => setTimeout(resolve, ms)));
|
|
2775
3064
|
const root = options.root ? path__default["default"].resolve(options.root) : process.cwd();
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
message: dir.message
|
|
2786
|
-
};
|
|
2787
|
-
}
|
|
2788
|
-
const collected = await collectArtifacts(dir.dir);
|
|
2789
|
-
for (const skipped of collected.skipped) {
|
|
2790
|
-
log(`Skipped ${skipped}`);
|
|
2791
|
-
}
|
|
2792
|
-
if (collected.artifacts.length === 0) {
|
|
3065
|
+
|
|
3066
|
+
/*
|
|
3067
|
+
* Upload-only when there is a build to upload: `--artifacts`, or the
|
|
3068
|
+
* directory it defaults to. Otherwise this builds the checkout -- which is
|
|
3069
|
+
* what a CI runner has, and `.val/` is never committed, so a fresh checkout
|
|
3070
|
+
* always builds.
|
|
3071
|
+
*/
|
|
3072
|
+
const prebuilt = options.artifacts !== undefined || fs__default$1["default"].existsSync(path__default["default"].join(root, DEFAULT_ARTIFACTS_DIR));
|
|
3073
|
+
if (!prebuilt && !fs__default$1["default"].existsSync(path__default["default"].join(root, "package.json"))) {
|
|
2793
3074
|
return {
|
|
2794
3075
|
status: "error",
|
|
2795
|
-
message: `
|
|
3076
|
+
message: `Nothing to publish: ${root} has no package.json to build, and no --artifacts were given.\n\n` + "Run this in the project, or point at a build made elsewhere:\n\n" + " npx val publish --artifacts <directory>"
|
|
2796
3077
|
};
|
|
2797
3078
|
}
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
3079
|
+
let collected = null;
|
|
3080
|
+
let layerRev = null;
|
|
3081
|
+
if (prebuilt) {
|
|
3082
|
+
const fromDir = await collectPrebuilt(root, options.artifacts, log);
|
|
3083
|
+
if (fromDir.status === "error") return fromDir;
|
|
3084
|
+
collected = fromDir.collected;
|
|
3085
|
+
layerRev = fromDir.layerRev;
|
|
2804
3086
|
}
|
|
2805
|
-
const layerRev = options.layerRev ?? layer.layerRev;
|
|
2806
3087
|
const git = await resolveGit({
|
|
2807
3088
|
root,
|
|
2808
3089
|
options,
|
|
@@ -2812,9 +3093,10 @@ async function runPublish(options) {
|
|
|
2812
3093
|
return git;
|
|
2813
3094
|
}
|
|
2814
3095
|
const config = await server.findAndEvalValConfigFile(root).catch(() => null);
|
|
3096
|
+
const project = (config === null || config === void 0 ? void 0 : config.project) ?? env.VAL_PROJECT ?? null;
|
|
2815
3097
|
const credential = await resolvePublishCredential({
|
|
2816
3098
|
root,
|
|
2817
|
-
project
|
|
3099
|
+
project,
|
|
2818
3100
|
env,
|
|
2819
3101
|
...(options.fetchImpl ? {
|
|
2820
3102
|
fetchImpl: options.fetchImpl
|
|
@@ -2826,16 +3108,52 @@ async function runPublish(options) {
|
|
|
2826
3108
|
message: credential.message
|
|
2827
3109
|
};
|
|
2828
3110
|
}
|
|
3111
|
+
const contentHost = getContentHost(env);
|
|
2829
3112
|
const client = createPublishClient({
|
|
2830
|
-
host:
|
|
3113
|
+
host: contentHost,
|
|
2831
3114
|
token: credential.credential.token,
|
|
2832
3115
|
...(options.fetchImpl ? {
|
|
2833
3116
|
fetchImpl: options.fetchImpl
|
|
2834
3117
|
} : {})
|
|
2835
3118
|
});
|
|
2836
|
-
|
|
3119
|
+
let built = null;
|
|
3120
|
+
try {
|
|
3121
|
+
if (collected === null) {
|
|
3122
|
+
log("Asking content what to build against");
|
|
3123
|
+
const target = await client.buildTarget();
|
|
3124
|
+
const build = await buildArtifacts({
|
|
3125
|
+
root,
|
|
3126
|
+
target,
|
|
3127
|
+
project: project ?? "",
|
|
3128
|
+
contentHost,
|
|
3129
|
+
git: {
|
|
3130
|
+
commit: git.commit,
|
|
3131
|
+
branch: git.branch
|
|
3132
|
+
},
|
|
3133
|
+
env,
|
|
3134
|
+
log
|
|
3135
|
+
});
|
|
3136
|
+
if (build.status === "error") {
|
|
3137
|
+
return {
|
|
3138
|
+
status: "error",
|
|
3139
|
+
message: build.message
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
built = build;
|
|
3143
|
+
for (const warning of build.warnings) log(`warn: ${warning}`);
|
|
3144
|
+
const fromBuild = await collectPrebuilt(root, build.dir, log);
|
|
3145
|
+
if (fromBuild.status === "error") return fromBuild;
|
|
3146
|
+
collected = fromBuild.collected;
|
|
3147
|
+
// Named when content already holds it; otherwise it is in the directory.
|
|
3148
|
+
layerRev = build.layerRev !== undefined ? build.layerRev : fromBuild.layerRev;
|
|
3149
|
+
}
|
|
3150
|
+
} catch (err) {
|
|
3151
|
+
return errorFrom(err);
|
|
3152
|
+
}
|
|
3153
|
+
const buildHash = options.buildHash ?? ((_built = built) === null || _built === void 0 ? void 0 : _built.buildHash) ?? buildHashOf(collected.artifacts);
|
|
2837
3154
|
log(`${count(collected.artifacts.length, "artifact")}, ${formatBytes(collected.totalBytes)}` + `, at ${git.commit.slice(0, 7)} on ${git.branch}`);
|
|
2838
3155
|
try {
|
|
3156
|
+
var _built2;
|
|
2839
3157
|
return await publishDeclaredBuild({
|
|
2840
3158
|
client,
|
|
2841
3159
|
log,
|
|
@@ -2846,8 +3164,8 @@ async function runPublish(options) {
|
|
|
2846
3164
|
buildHash,
|
|
2847
3165
|
commit: git.commit,
|
|
2848
3166
|
branch: git.branch,
|
|
2849
|
-
layerRev,
|
|
2850
|
-
linksOwnCss: options.linksOwnCss ?? null,
|
|
3167
|
+
layerRev: options.layerRev ?? layerRev,
|
|
3168
|
+
linksOwnCss: options.linksOwnCss ?? ((_built2 = built) === null || _built2 === void 0 ? void 0 : _built2.linksOwnCss) ?? null,
|
|
2851
3169
|
artifacts: collected.artifacts.map(({
|
|
2852
3170
|
key,
|
|
2853
3171
|
sha256,
|
|
@@ -2862,8 +3180,54 @@ async function runPublish(options) {
|
|
|
2862
3180
|
});
|
|
2863
3181
|
} catch (err) {
|
|
2864
3182
|
return errorFrom(err);
|
|
3183
|
+
} finally {
|
|
3184
|
+
// Ours to remove: a build is written to a fresh temporary directory.
|
|
3185
|
+
if (built !== null) {
|
|
3186
|
+
fs__default$1["default"].rmSync(built.dir, {
|
|
3187
|
+
recursive: true,
|
|
3188
|
+
force: true
|
|
3189
|
+
});
|
|
3190
|
+
}
|
|
2865
3191
|
}
|
|
2866
3192
|
}
|
|
3193
|
+
|
|
3194
|
+
/** A build on disk: its artifacts, and the layer it sends or names. */
|
|
3195
|
+
async function collectPrebuilt(root, artifacts, log) {
|
|
3196
|
+
const dir = resolveArtifactsDir({
|
|
3197
|
+
root,
|
|
3198
|
+
...(artifacts ? {
|
|
3199
|
+
dir: artifacts
|
|
3200
|
+
} : {})
|
|
3201
|
+
});
|
|
3202
|
+
if (dir.status === "error") {
|
|
3203
|
+
return {
|
|
3204
|
+
status: "error",
|
|
3205
|
+
message: dir.message
|
|
3206
|
+
};
|
|
3207
|
+
}
|
|
3208
|
+
const collected = await collectArtifacts(dir.dir);
|
|
3209
|
+
for (const skipped of collected.skipped) {
|
|
3210
|
+
log(`Skipped ${skipped}`);
|
|
3211
|
+
}
|
|
3212
|
+
if (collected.artifacts.length === 0) {
|
|
3213
|
+
return {
|
|
3214
|
+
status: "error",
|
|
3215
|
+
message: `There is nothing in ${dir.dir}. Build the project before publishing it.`
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
const layer = await layerRevOf(collected.artifacts);
|
|
3219
|
+
if (layer.status === "error") {
|
|
3220
|
+
return {
|
|
3221
|
+
status: "error",
|
|
3222
|
+
message: layer.message
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
return {
|
|
3226
|
+
status: "ok",
|
|
3227
|
+
collected,
|
|
3228
|
+
layerRev: layer.layerRev
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
2867
3231
|
async function publishDeclaredBuild(args) {
|
|
2868
3232
|
const {
|
|
2869
3233
|
client,
|
|
@@ -3356,6 +3720,125 @@ function printProblem(problem) {
|
|
|
3356
3720
|
}
|
|
3357
3721
|
}
|
|
3358
3722
|
|
|
3723
|
+
/**
|
|
3724
|
+
* `val ci-report` -- CI saying how its build of a commit went.
|
|
3725
|
+
*
|
|
3726
|
+
* The last step of a connected project's workflow, run whether the build
|
|
3727
|
+
* passed or not. Content learns a build failed from this and nothing else,
|
|
3728
|
+
* so it needs no GitHub permission to tell an editor "Published, not on the
|
|
3729
|
+
* site yet: the build failed" (valbuild/home, docs/app-mode.md, "Failures":
|
|
3730
|
+
* after the seal). The run's address goes with it, for "View run".
|
|
3731
|
+
*
|
|
3732
|
+
* Everything has a default from GitHub Actions' own environment -- the
|
|
3733
|
+
* commit it checked out, the branch it ran for, the run's URL -- so the step
|
|
3734
|
+
* is one line. Never fails the job over a report it could not send: the
|
|
3735
|
+
* build's own result is what the job's status is, and a report is advice.
|
|
3736
|
+
*/
|
|
3737
|
+
|
|
3738
|
+
function ciReportFromEnv(options, env = process.env) {
|
|
3739
|
+
const status = options.status;
|
|
3740
|
+
if (status !== "failed" && status !== "succeeded") {
|
|
3741
|
+
return {
|
|
3742
|
+
status: "error",
|
|
3743
|
+
message: `--status is "failed" or "succeeded"${status === undefined ? "" : `, not "${status}"`}.`
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
const commit = options.commit ?? env.GITHUB_SHA ?? env.VAL_GIT_COMMIT;
|
|
3747
|
+
if (!commit) {
|
|
3748
|
+
return {
|
|
3749
|
+
status: "error",
|
|
3750
|
+
message: "No commit to report on: pass --commit, or run this in GitHub Actions (GITHUB_SHA)."
|
|
3751
|
+
};
|
|
3752
|
+
}
|
|
3753
|
+
const branch = options.branch ?? env.GITHUB_REF_NAME ?? env.VAL_GIT_BRANCH;
|
|
3754
|
+
const url = options.url ?? (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_RUN_ID ? `${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}` : undefined);
|
|
3755
|
+
return {
|
|
3756
|
+
status: "ok",
|
|
3757
|
+
report: {
|
|
3758
|
+
status,
|
|
3759
|
+
commit,
|
|
3760
|
+
...(branch ? {
|
|
3761
|
+
branch
|
|
3762
|
+
} : {}),
|
|
3763
|
+
...(url ? {
|
|
3764
|
+
url
|
|
3765
|
+
} : {})
|
|
3766
|
+
}
|
|
3767
|
+
};
|
|
3768
|
+
}
|
|
3769
|
+
async function reportCiRun(options) {
|
|
3770
|
+
const env = options.env ?? process.env;
|
|
3771
|
+
const config = await server.findAndEvalValConfigFile(options.root).catch(() => null);
|
|
3772
|
+
const credential = await resolvePublishCredential({
|
|
3773
|
+
root: options.root,
|
|
3774
|
+
project: (config === null || config === void 0 ? void 0 : config.project) ?? env.VAL_PROJECT ?? null,
|
|
3775
|
+
env,
|
|
3776
|
+
...(options.fetchImpl ? {
|
|
3777
|
+
fetchImpl: options.fetchImpl
|
|
3778
|
+
} : {})
|
|
3779
|
+
});
|
|
3780
|
+
if (credential.status === "error") {
|
|
3781
|
+
return {
|
|
3782
|
+
status: "error",
|
|
3783
|
+
message: credential.message
|
|
3784
|
+
};
|
|
3785
|
+
}
|
|
3786
|
+
const body = options.report;
|
|
3787
|
+
try {
|
|
3788
|
+
await postJson({
|
|
3789
|
+
url: `${getContentHost(env)}/v1/ci-runs`,
|
|
3790
|
+
headers: {
|
|
3791
|
+
Authorization: `Bearer ${credential.credential.token}`
|
|
3792
|
+
},
|
|
3793
|
+
body,
|
|
3794
|
+
...(options.fetchImpl ? {
|
|
3795
|
+
fetchImpl: options.fetchImpl
|
|
3796
|
+
} : {})
|
|
3797
|
+
});
|
|
3798
|
+
return {
|
|
3799
|
+
status: "reported"
|
|
3800
|
+
};
|
|
3801
|
+
} catch (e) {
|
|
3802
|
+
return {
|
|
3803
|
+
status: "error",
|
|
3804
|
+
message: e instanceof ContentHostError ? `Content did not take the report (${e.statusCode}): ${e.message}` : e instanceof Error ? e.message : String(e)
|
|
3805
|
+
};
|
|
3806
|
+
}
|
|
3807
|
+
}
|
|
3808
|
+
|
|
3809
|
+
/**
|
|
3810
|
+
* `val ci-report` -- a thin shell around `reportCiRun`. It never fails the
|
|
3811
|
+
* job: the build's own result is what the job's status is, and a report that
|
|
3812
|
+
* could not be sent is said and then left.
|
|
3813
|
+
*/
|
|
3814
|
+
async function ciReport(options) {
|
|
3815
|
+
const read = ciReportFromEnv({
|
|
3816
|
+
status: options.status,
|
|
3817
|
+
...(options.commit ? {
|
|
3818
|
+
commit: options.commit
|
|
3819
|
+
} : {}),
|
|
3820
|
+
...(options.branch ? {
|
|
3821
|
+
branch: options.branch
|
|
3822
|
+
} : {}),
|
|
3823
|
+
...(options.url ? {
|
|
3824
|
+
url: options.url
|
|
3825
|
+
} : {})
|
|
3826
|
+
});
|
|
3827
|
+
if (read.status === "error") {
|
|
3828
|
+
console.error(pc__default["default"].yellow(`val ci-report: ${read.message}`));
|
|
3829
|
+
return;
|
|
3830
|
+
}
|
|
3831
|
+
const sent = await reportCiRun({
|
|
3832
|
+
root: options.root ?? process.cwd(),
|
|
3833
|
+
report: read.report
|
|
3834
|
+
});
|
|
3835
|
+
if (sent.status === "error") {
|
|
3836
|
+
console.error(pc__default["default"].yellow(`val ci-report: not reported. ${sent.message}`));
|
|
3837
|
+
return;
|
|
3838
|
+
}
|
|
3839
|
+
console.log(pc__default["default"].dim(`Reported the build of ${read.report.commit.slice(0, 7)} as ${read.report.status}.`));
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3359
3842
|
async function main() {
|
|
3360
3843
|
const {
|
|
3361
3844
|
input,
|
|
@@ -3398,19 +3881,35 @@ async function main() {
|
|
|
3398
3881
|
Options:
|
|
3399
3882
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
|
3400
3883
|
|
|
3884
|
+
Command: ci-report
|
|
3885
|
+
Description: tell content how CI's build of a commit went, for a connected
|
|
3886
|
+
project's workflow. Run as its last step, whatever the build did:
|
|
3887
|
+
a failed build then reads "Published, not on the site yet" in the
|
|
3888
|
+
Studio, with a link to the run. Never fails the job.
|
|
3889
|
+
Options:
|
|
3890
|
+
--status [failed|succeeded] How the build went
|
|
3891
|
+
--commit [sha] The commit built (default GITHUB_SHA)
|
|
3892
|
+
--branch [name] Its branch (default GITHUB_REF_NAME, else the project's)
|
|
3893
|
+
--url [url] The run (default this GitHub Actions run)
|
|
3894
|
+
|
|
3401
3895
|
Command: publish
|
|
3402
|
-
Description:
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3896
|
+
Description: build this project and publish it through content.val.build.
|
|
3897
|
+
Asks content what to build against, builds the site and its dependency layer from
|
|
3898
|
+
the checkout (needs @valbuild/tanstack-build, rolldown, @tanstack/router-generator
|
|
3899
|
+
and @tanstack/router-plugin installed), declares the artifacts, uploads the ones
|
|
3900
|
+
content does not already hold, and has content verify it by building and rendering
|
|
3901
|
+
a canary before the site changes. With --artifacts, or a .val/publish directory,
|
|
3902
|
+
it publishes that build instead of making one. Authenticates with VAL_PROJECT_TOKEN,
|
|
3903
|
+
or with the "val login" token in .val/pat.json (which needs the project, as
|
|
3904
|
+
"<org>/<project>", in val.config or VAL_PROJECT). Never as a flag: an argument is
|
|
3905
|
+
visible to anyone who can list processes, and it is kept in shell history and in
|
|
3906
|
+
every CI log.
|
|
3409
3907
|
Options:
|
|
3410
3908
|
--root [root], -r [root] Set project root directory (default process.cwd())
|
|
3411
|
-
--artifacts [dir]
|
|
3412
|
-
|
|
3413
|
-
|
|
3909
|
+
--artifacts [dir] Publish a build made elsewhere (default: build the checkout,
|
|
3910
|
+
unless <root>/.val/publish exists). The path of each file
|
|
3911
|
+
under it is its artifact key: server, client, css, rsc,
|
|
3912
|
+
layer, source, or a path under chunk/server, chunk/client,
|
|
3414
3913
|
chunk/rsc, asset, public
|
|
3415
3914
|
--commit [sha] The commit this build is of (default VAL_GIT_COMMIT,
|
|
3416
3915
|
else GITHUB_SHA, else git HEAD)
|
|
@@ -3519,6 +4018,12 @@ async function main() {
|
|
|
3519
4018
|
},
|
|
3520
4019
|
verbose: {
|
|
3521
4020
|
type: "boolean"
|
|
4021
|
+
},
|
|
4022
|
+
status: {
|
|
4023
|
+
type: "string"
|
|
4024
|
+
},
|
|
4025
|
+
url: {
|
|
4026
|
+
type: "string"
|
|
3522
4027
|
}
|
|
3523
4028
|
},
|
|
3524
4029
|
hardRejection: false
|
|
@@ -3562,6 +4067,14 @@ async function main() {
|
|
|
3562
4067
|
yes: flags.yes,
|
|
3563
4068
|
verbose: flags.verbose
|
|
3564
4069
|
});
|
|
4070
|
+
case "ci-report":
|
|
4071
|
+
return ciReport({
|
|
4072
|
+
root: flags.root,
|
|
4073
|
+
status: flags.status,
|
|
4074
|
+
commit: flags.commit,
|
|
4075
|
+
branch: flags.branch,
|
|
4076
|
+
url: flags.url
|
|
4077
|
+
});
|
|
3565
4078
|
case "publish":
|
|
3566
4079
|
return publish({
|
|
3567
4080
|
root: flags.root,
|