@homepages/concrete 13.0.0 → 14.0.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +4 -5
  3. package/codemods/manifest.json +11 -0
  4. package/dist/artifact/playground/client/assets/index-DZbV6Ucf.js +1338 -0
  5. package/dist/artifact/playground/client/index.html +1 -1
  6. package/dist/artifact/playground/host.mjs +22 -22
  7. package/dist/cli/build/manifest.js +1 -1
  8. package/dist/cli/build/record.js +1 -1
  9. package/dist/cli/check/load-workspace.js +3 -6
  10. package/dist/cli/commands.js +63 -15
  11. package/dist/cli/media/deriver-plugin.js +10 -1
  12. package/dist/cli/publish/artifact.js +18 -40
  13. package/dist/cli/publish/fixtures.js +1 -1
  14. package/dist/cli/publish/index.js +90 -115
  15. package/dist/cli/publish/report.js +36 -56
  16. package/dist/cli/publish/send.js +142 -0
  17. package/dist/cli/publish/target.js +33 -31
  18. package/dist/cli/publish/verdict.js +65 -0
  19. package/dist/cli/release/client.js +69 -0
  20. package/dist/cli/release/index.js +143 -0
  21. package/dist/cli/release/report.js +73 -0
  22. package/dist/cli/upgrade/fixture-modules.js +3 -5
  23. package/dist/cli.js +1 -0
  24. package/dist/css/graph.js +29 -40
  25. package/dist/fixtures/media-plugin.js +7 -25
  26. package/dist/fixtures/package-stylesheets.js +12 -48
  27. package/dist/packages/external/concrete/package.js +1 -1
  28. package/dist/packages/internal/media-resolution/dist/image.js +23 -0
  29. package/dist/packages/internal/playground/dist/fixture-formats.js +5 -1
  30. package/dist/packages/internal/playground/dist/host/built.js +4 -12
  31. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +0 -1
  32. package/dist/packages/internal/playground/dist/host/download.js +1 -8
  33. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +3 -4
  34. package/dist/packages/internal/playground/dist/host/program.js +1 -2
  35. package/dist/packages/internal/playground/dist/host/serve.js +4 -30
  36. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +2 -9
  37. package/dist/packages/internal/playground/dist/layout.js +5 -5
  38. package/dist/packages/internal/playground/dist/send-wire.js +9 -0
  39. package/dist/packages/internal/playground/dist/server/changes.js +0 -1
  40. package/dist/packages/internal/playground/dist/server/listen.js +2 -19
  41. package/dist/packages/internal/property-facts/dist/registry-facts.js +0 -7
  42. package/dist/packages/internal/template-artifact/dist/framework-floor.js +33 -0
  43. package/dist/packages/internal/template-artifact/dist/index.js +3 -3
  44. package/dist/packages/internal/template-artifact/dist/layout.js +2 -39
  45. package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
  46. package/dist/packages/internal/template-artifact/dist/verify.js +6 -57
  47. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +1 -1
  48. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  49. package/dist/template/logic-build.js +38 -19
  50. package/guide/reference/cli/INDEX.md +5 -4
  51. package/guide/reference/cli/build.md +1 -1
  52. package/guide/reference/cli/check.md +1 -1
  53. package/guide/reference/cli/dev.md +1 -1
  54. package/guide/reference/cli/install.md +1 -1
  55. package/guide/reference/cli/property-add.md +1 -1
  56. package/guide/reference/cli/property-list.md +1 -1
  57. package/guide/reference/cli/publish.md +17 -16
  58. package/guide/reference/cli/release.md +57 -0
  59. package/guide/reference/cli/upgrade.md +1 -1
  60. package/guide/reference/rules/INDEX.md +1 -1
  61. package/package.json +7 -5
  62. package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +0 -1338
  63. package/dist/cli/publish/captures.js +0 -61
  64. package/dist/cli/publish/client.js +0 -118
  65. package/dist/cli/publish/pack.js +0 -77
  66. package/dist/cli/publish/playground.js +0 -27
  67. package/dist/cli/publish/wire.js +0 -23
@@ -19,7 +19,7 @@ function fixtureListOf(template) {
19
19
  async function buildManifest(input) {
20
20
  const { template } = input;
21
21
  const fields = {
22
- artifact_schema: 5,
22
+ artifact_schema: 6,
23
23
  framework_version: CONCRETE_CLI_VERSION,
24
24
  key: template.key,
25
25
  display_name: template.name,
@@ -98,7 +98,7 @@ async function stampTree(dir, hash) {
98
98
  }
99
99
  entries.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
100
100
  for (const entry of entries) {
101
- if (entry.name === ".concrete" || entry.name === "node_modules") continue;
101
+ if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
102
102
  const path = join(at, entry.name);
103
103
  if (entry.isDirectory()) await visit(path);
104
104
  else if (entry.isFile()) hash.update(`${path}\0${await stampOf(path)}\n`);
@@ -1,7 +1,7 @@
1
1
  import { isTemplate } from "../../template/define-template.js";
2
2
  import { workspacePath } from "../../platform/paths.js";
3
3
  import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
4
- import { createPackageStylesheetsPlugin } from "../../fixtures/package-stylesheets.js";
4
+ import { emptyPackageStylesheets } from "../../fixtures/package-stylesheets.js";
5
5
  import { runningCopyPlugin } from "../../template/running-copy.js";
6
6
  import { listModules } from "../../section/discovery.js";
7
7
  import { claimLoadOutdir } from "./load-outdir.js";
@@ -31,7 +31,7 @@ async function loadWorkspace(root) {
31
31
  };
32
32
  const files = listModules(root);
33
33
  const media = createFixtureMediaPlugin(root);
34
- const stylesheets = await createPackageStylesheetsPlugin(root);
34
+ emptyPackageStylesheets();
35
35
  const outdir = await claimLoadOutdir(root);
36
36
  let result;
37
37
  try {
@@ -54,8 +54,7 @@ async function loadWorkspace(root) {
54
54
  plugins: [
55
55
  runningCopyPlugin(),
56
56
  externalOutsideWorkspace(root),
57
- media.plugin,
58
- stylesheets.plugin
57
+ media.plugin
59
58
  ],
60
59
  sourcemap: "inline",
61
60
  metafile: true,
@@ -77,8 +76,6 @@ async function loadWorkspace(root) {
77
76
  message: m.text
78
77
  }))
79
78
  };
80
- } finally {
81
- await stylesheets.dispose();
82
79
  }
83
80
  process.setSourceMapsEnabled(true);
84
81
  const outputByInput = /* @__PURE__ */ new Map();
@@ -183,50 +183,98 @@ const DECLARED_COMMANDS = [
183
183
  },
184
184
  {
185
185
  name: "publish",
186
- summary: "Publish the template to HomePages",
186
+ summary: "Send the template to the development console",
187
+ flags: [{
188
+ name: "json",
189
+ type: "boolean",
190
+ default: false,
191
+ summary: "Print the version, its playground link, the merge and the verdict on stdout instead of the summary"
192
+ }, {
193
+ name: "env-file",
194
+ type: "string",
195
+ valueLabel: "<path>",
196
+ summary: "Read `CONCRETE_CONSOLE_KEY` and `CONCRETE_CONSOLE_URL` from this dotenv file instead of the workspace's `.env`"
197
+ }],
198
+ exits: [
199
+ {
200
+ code: 0,
201
+ when: "the template was sent and the platform loads and renders the version's build"
202
+ },
203
+ {
204
+ code: 1,
205
+ when: "`check` is not green, the console refuses the send, or the version's build fails verification"
206
+ },
207
+ {
208
+ code: 2,
209
+ when: "no console key is set, the key is malformed or not accepted, the console cannot be reached or gives no verdict, or it runs outside a workspace"
210
+ }
211
+ ],
212
+ constraints: [
213
+ "The key is the environment: `CONCRETE_CONSOLE_KEY`, the team's console key, names production, staging or dev in its prefix (`cck_prod_…`), and publish sends to that environment's console. There is no environment flag.",
214
+ "Reads `CONCRETE_CONSOLE_KEY` from the environment, then from the workspace's `.env`, and refuses before anything is built or sent when it is missing. `CONCRETE_CONSOLE_URL` replaces the console the key's prefix names.",
215
+ "`--env-file <path>` names the key file instead, relative to the current directory: its values win over the environment and the workspace's `.env` is not read. It is how a library holding one key file per environment picks one, in any shell.",
216
+ "Builds and checks on every run, then sends the template — the build and the authored fixtures — to the development console, which merges it with the work already there as a new version and serves its playground. Nothing is reused.",
217
+ "Then asks the console for the version's verdict: whether the platform loads and renders its build. A failing verdict prints its problems and exits 1; the version stays on the console, and its playground shows the build.",
218
+ "Asks nothing of HomePages: a sent version reaches customers only when `concrete release` hands it over. The last line names the `concrete release --version <n>` that does.",
219
+ "Prints the version, the playground's link and every fixture where the console's work was replaced or kept, and warns when the build's @homepages/concrete is older than the console's.",
220
+ "Prints one line per stage on stderr as it settles: console, build, send, verify.",
221
+ "Has no dry run: `concrete release --dry-run` is the run that asks without changing anything.",
222
+ "Under `--json` the outcome is the only thing written to stdout; every stage line goes to stderr.",
223
+ "Never prompts, in any environment."
224
+ ]
225
+ },
226
+ {
227
+ name: "release",
228
+ summary: "Hand a version on the development console to HomePages",
187
229
  flags: [
230
+ {
231
+ name: "version",
232
+ type: "string",
233
+ valueLabel: "<n>",
234
+ summary: "Release this version instead of the template's current one"
235
+ },
188
236
  {
189
237
  name: "dry-run",
190
238
  type: "boolean",
191
239
  default: false,
192
- summary: "Upload and verify the artifact, report what publishing would change, and write nothing"
240
+ summary: "Report what releasing would change, and change nothing in HomePages"
193
241
  },
194
242
  {
195
243
  name: "json",
196
244
  type: "boolean",
197
245
  default: false,
198
- summary: "Print the settled publication record on stdout instead of the summary"
246
+ summary: "Print the release's outcome on stdout instead of the summary"
199
247
  },
200
248
  {
201
249
  name: "env-file",
202
250
  type: "string",
203
251
  valueLabel: "<path>",
204
- summary: "Read `CONCRETE_TOKEN` and `CONCRETE_API_URL` from this dotenv file instead of the workspace's `.env`"
252
+ summary: "Read `CONCRETE_CONSOLE_KEY` and `CONCRETE_CONSOLE_URL` from this dotenv file instead of the workspace's `.env`"
205
253
  }
206
254
  ],
207
255
  exits: [
208
256
  {
209
257
  code: 0,
210
- when: "the template was published, the environment already held it as current, or a dry run passed verification"
258
+ when: "the version was released, HomePages already held its build, or a dry run found it would release"
211
259
  },
212
260
  {
213
261
  code: 1,
214
- when: "`check` is not green, a capture failed, or the platform refuses the publication, fails its verification or cannot finish it"
262
+ when: "the console or HomePages refuses the release: the build failed verification, its audience is outside the team's, it drops a format deliverables still hold, or the console holds no such version"
215
263
  },
216
264
  {
217
265
  code: 2,
218
- when: "no publisher key is set, the key is malformed or not accepted, the endpoint cannot be reached, or it runs outside a workspace"
266
+ when: "no console key is set, the key is malformed or not accepted, the console cannot be reached, HomePages could not take the release, or it runs outside a workspace"
219
267
  }
220
268
  ],
221
269
  constraints: [
222
- "The key is the environment: `CONCRETE_TOKEN` names production, staging or dev in its prefix (`cpt_prod_…`), and publish goes where it points. There is no environment flag.",
223
- "Reads `CONCRETE_TOKEN` from the environment, then from the workspace's `.env`. `CONCRETE_API_URL` replaces the endpoint the key's prefix names.",
224
- "`--env-file <path>` names the key file instead, relative to the current directory: its values win over the environment and the workspace's `.env` is not read. It is how a library holding one key file per environment picks one, in any shell.",
225
- "Builds and checks on every run, then assembles the artifact — the built files, the authored fixtures, the playground and, for an image or document template, the captures — and uploads it. An artifact is never reused.",
226
- "An image or document template's captures are every authored fixture at every declared format, taken exactly as `dev`'s *Download* takes it — the enabled pages and their zip, or the PDF. They sit outside the artifact hash, and are taken with the Chromium build the platform renders with: on a machine without it, publish refuses with the one command that installs it.",
227
- "Prints one line per stage on stderr as it settles: target, build, upload, verify, write, adopt.",
228
- "Publishing a tree the environment already holds as current changes nothing, says so, and exits 0. Rolling back is publishing the older tree.",
229
- "Under `--json` the publication record is the only thing written to stdout; every stage line goes to stderr.",
270
+ "The key is the environment: `CONCRETE_CONSOLE_KEY`, the team's console key, names production, staging or dev in its prefix (`cck_prod_…`), and release asks that environment's console. There is no environment flag.",
271
+ "Reads `CONCRETE_CONSOLE_KEY` from the environment, then from the workspace's `.env`; `--env-file <path>` names the key file instead. `CONCRETE_CONSOLE_URL` replaces the console the key's prefix names.",
272
+ "Builds and sends nothing: the console holds every version a send made, its build and its verdict. The template is the one the workspace's `template.ts` declares.",
273
+ "Without `--version` the template's current version is released, and the first line names it, with when and with which key its build was sent.",
274
+ "Prints the audience, what changed, and how many deliverables are adopting the build. A refusal prints its problems.",
275
+ "While the console is still verifying the build or delivering it, release asks again on its own.",
276
+ "When HomePages could not take the release it says why and exits 2: nothing says the build is unfit, and the same command can be run again.",
277
+ "Under `--json` the outcome is the only thing written to stdout; every other line goes to stderr.",
230
278
  "Never prompts, in any environment."
231
279
  ]
232
280
  }
@@ -1,5 +1,7 @@
1
+ import { isFileSpecifier } from "../../platform/paths.js";
1
2
  import { DERIVABLE_EXTENSIONS, cachedAuthorImage, deriveAuthorImage, masterOnlyDerivation } from "./derive.js";
2
- import { extname } from "node:path";
3
+ import { existsSync } from "node:fs";
4
+ import { extname, resolve } from "node:path";
3
5
  import { readFile } from "node:fs/promises";
4
6
 
5
7
  //#region src/cli/media/deriver-plugin.ts
@@ -20,6 +22,13 @@ function createMediaDeriver(opts = {}) {
20
22
  if (args.pluginData === RESOLVING) return null;
21
23
  if (args.kind !== "import-statement") return null;
22
24
  if (!DERIVABLE_EXTENSIONS.has(extname(args.path).toLowerCase())) return null;
25
+ if (isFileSpecifier(args.path)) {
26
+ const written = resolve(args.resolveDir, args.path);
27
+ if (existsSync(written)) return {
28
+ path: written,
29
+ namespace: NAMESPACE
30
+ };
31
+ }
23
32
  const resolved = await build.resolve(args.path, {
24
33
  importer: args.importer,
25
34
  namespace: args.namespace,
@@ -1,16 +1,13 @@
1
1
  import { qualify } from "../../rules/registry.js";
2
- import { MANIFEST_FILE, fixturePath } from "../../packages/internal/template-artifact/dist/layout.js";
2
+ import { MANIFEST_FILE, builtTreePath } from "../../packages/internal/template-artifact/dist/layout.js";
3
3
  import { ArtifactManifest } from "../../packages/internal/template-artifact/dist/manifest.js";
4
- import { verifyArtifact } from "../../packages/internal/template-artifact/dist/verify.js";
4
+ import { verifyBuild } from "../../packages/internal/template-artifact/dist/verify.js";
5
5
  import "../../packages/internal/template-artifact/dist/index.js";
6
6
  import { unportablePaths } from "../../platform/names.js";
7
7
  import { readBuiltFiles } from "../build/template-build.js";
8
8
  import { analyzeWorkspace } from "../check/analyze.js";
9
- import { captureFiles } from "./captures.js";
10
9
  import { fixtureFiles } from "./fixtures.js";
11
- import { playgroundFiles } from "./playground.js";
12
- import { dirname, join, relative } from "node:path";
13
- import { mkdir, writeFile } from "node:fs/promises";
10
+ import { relative } from "node:path";
14
11
 
15
12
  //#region src/cli/publish/artifact.ts
16
13
  async function gather(options) {
@@ -25,8 +22,7 @@ async function gather(options) {
25
22
  report
26
23
  };
27
24
  const { build, fixtureFiles: fixtureSet } = context;
28
- const template = build.workspace.template;
29
- if (build.output === null || template === null || fixtureSet === void 0) throw new Error("publish: check passed without a written build and the fixtures an artifact carries.");
25
+ if (build.output === null || build.workspace.template === null || fixtureSet === void 0) throw new Error("publish: check passed without a written build and the fixtures a send carries.");
30
26
  const passthrough = build.sections.flatMap((section) => section.bundles?.ok === true ? [...section.bundles.value.passthrough] : []);
31
27
  if (passthrough.length > 0) throw new Error(`The template imports images that could not be derived because \`sharp\` did not load: ${passthrough.map((p) => relative(root, p)).join(", ")}. An artifact carries every image's responsive ladder; reinstall so sharp's native binary lands, then publish again.`);
32
28
  const built = await readBuiltFiles(build.output);
@@ -34,55 +30,37 @@ async function gather(options) {
34
30
  if (written === void 0) throw new Error(`publish: the build wrote no ${MANIFEST_FILE}.`);
35
31
  const manifest = ArtifactManifest.parse(JSON.parse(new TextDecoder().decode(written)));
36
32
  if (manifest.fixture_list !== fixtureSet.list) throw new Error(`publish: the build's ${MANIFEST_FILE} names the fixture list ${manifest.fixture_list}; check read ${fixtureSet.list}.`);
33
+ const fixtures = await fixtureFiles({
34
+ root,
35
+ files: fixtureSet.files
36
+ });
37
+ const unportable = unportablePaths(fixtures.keys());
38
+ if (unportable.length > 0) throw new Error(`the fixtures would not write the same files on Windows and macOS (${qualify("workspace/unportable-name")}):\n` + unportable.map((found) => ` ${found.paths.join(" and ")}: ${found.reason}`).join("\n") + "\nRename the source files these names come from.");
37
39
  return {
38
40
  ok: true,
39
41
  report,
40
42
  manifest,
41
43
  built,
42
- fixtures: await fixtureFiles({
43
- root,
44
- files: fixtureSet.files
45
- }),
46
- captureInput: {
47
- root,
48
- output: template.output,
49
- build: build.output
50
- }
44
+ fixtures
51
45
  };
52
46
  }
53
47
  const byPath = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
48
+ function sendableOf(gathered) {
49
+ const files = [...gathered.fixtures, ...[...gathered.built].map(([path, bytes]) => [builtTreePath(path), bytes])];
50
+ return new Map(files.sort(byPath));
51
+ }
54
52
  async function assembleArtifact(options) {
55
53
  const gathered = await gather(options);
56
54
  if (!gathered.ok) return gathered;
57
55
  const { report, manifest } = gathered;
58
- const files = new Map(gathered.built);
59
- const put = (path, bytes) => {
60
- const prior = files.get(path);
61
- if (prior !== void 0 && Buffer.compare(prior, bytes) !== 0) throw new Error(`Two different files would be written as ${path}. Content-addressed names cannot collide; rename one of the sources.`);
62
- files.set(path, bytes);
63
- };
64
- for (const [path, bytes] of gathered.fixtures) put(fixturePath(path), bytes);
65
- for (const [path, bytes] of await playgroundFiles()) put(path, bytes);
66
- const captures = await captureFiles({
67
- ...gathered.captureInput,
68
- ...options.browser === void 0 ? {} : { browser: options.browser }
69
- });
70
- for (const [path, bytes] of captures) put(path, bytes);
71
- const verdict = verifyArtifact(files);
56
+ const verdict = verifyBuild(gathered.built);
72
57
  if (verdict.problems.length > 0) throw new Error(`publish: the artifact failed its own verification:\n${verdict.problems.map((p) => ` ${p.path}: ${p.message}`).join("\n")}`);
73
- const unportable = unportablePaths(files.keys());
74
- if (unportable.length > 0) throw new Error(`the artifact would not write the same files on Windows and macOS (${qualify("workspace/unportable-name")}):\n` + unportable.map((found) => ` ${found.paths.join(" and ")}: ${found.reason}`).join("\n") + "\nRename the source files these names come from.");
75
- const sorted = [...files].sort(byPath);
76
- for (const [path, bytes] of sorted) {
77
- const target = join(options.out, ...path.split("/"));
78
- await mkdir(dirname(target), { recursive: true });
79
- await writeFile(target, bytes);
80
- }
81
58
  return {
82
59
  ok: true,
83
60
  report,
84
61
  manifest,
85
- files: new Map(sorted)
62
+ sendable: sendableOf(gathered),
63
+ files: new Map([...gathered.built].sort(byPath))
86
64
  };
87
65
  }
88
66
 
@@ -7,7 +7,7 @@ import { readFile } from "node:fs/promises";
7
7
  async function fixtureFiles(input) {
8
8
  const out = /* @__PURE__ */ new Map();
9
9
  for (const path of [...input.files].sort()) {
10
- if (!isFixtureFilePath(path)) throw new Error(`The fixture file ${path} cannot ride in an artifact: a published fixture file's path is segments of letters, digits, ".", "_" and "-". Rename it.`);
10
+ if (!isFixtureFilePath(path)) throw new Error(`The fixture file ${path} cannot be sent: a sent fixture file's path is segments of letters, digits, ".", "_" and "-". Rename it.`);
11
11
  out.set(path, new Uint8Array(await readFile(join(input.root, ...path.split("/")))));
12
12
  }
13
13
  return out;
@@ -1,30 +1,30 @@
1
1
  import { DEFAULT_BUILD_DIR, booleanFlag, parseSpec, stringFlag } from "../commands.js";
2
- import { removeTree } from "../../platform/fs.js";
3
2
  import { findWorkspaceRoot } from "../workspace.js";
4
3
  import { formatHuman } from "../check/report.js";
5
- import { TERMINAL_STATES } from "./wire.js";
6
- import { publicationClient } from "./client.js";
7
4
  import { readSourceFacts } from "./git.js";
8
- import { packArtifact } from "./pack.js";
9
- import { API_URL_VARIABLE, TOKEN_VARIABLE, TargetError, maskToken, resolveTarget } from "./target.js";
10
- import { adoptText, builtText, refusalText, stageLine, summaryText, targetText, uploadText, writeText } from "./report.js";
11
- import { join, resolve } from "node:path";
12
- import { mkdtemp, stat } from "node:fs/promises";
13
- import { tmpdir } from "node:os";
5
+ import { CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, resolveConsoleTarget } from "./target.js";
6
+ import { behindText, builtText, consoleText, notReleasedText, refusedText, sendLines, stageLine, verdictText } from "./report.js";
7
+ import { askVerdict } from "./verdict.js";
8
+ import { resolve } from "node:path";
14
9
  import { parseArgs } from "node:util";
15
10
 
16
11
  //#region src/cli/publish/index.ts
17
12
  const EXIT_OK = 0;
18
13
  const EXIT_REFUSED = 1;
19
- const EXIT_USAGE = 2;
20
- const POLL_INTERVAL_MS = 2e3;
21
- const POLL_FAILURES_TOLERATED = 30;
14
+ const EXIT_FAILED = 2;
15
+ const VERDICT_ASKS_TOLERATED = 10;
22
16
  const DEFAULT_DEPS = {
23
17
  artifact: async (options) => (await import("./artifact.js")).assembleArtifact(options),
24
- client: publicationClient,
25
- sourceFacts: readSourceFacts,
26
- sleep: (ms) => new Promise((done) => setTimeout(done, ms)),
27
- pollIntervalMs: POLL_INTERVAL_MS
18
+ send: async (target, input) => (await import("./send.js")).sendTemplate({
19
+ console: target.console,
20
+ key: target.key
21
+ }, input),
22
+ verdict: (target, template, version) => askVerdict(target.console, target.key, {
23
+ template,
24
+ version,
25
+ wait: 60
26
+ }),
27
+ sourceFacts: readSourceFacts
28
28
  };
29
29
  var Ending = class extends Error {
30
30
  code;
@@ -36,115 +36,90 @@ var Ending = class extends Error {
36
36
  }
37
37
  };
38
38
  const say = (sentence) => `concrete publish: ${sentence}\n`;
39
- function endingFor(answer, target, doing) {
40
- switch (answer.kind) {
41
- case "unreachable": return new Ending(EXIT_USAGE, say(`could not reach ${target.endpoint} while ${doing} (${answer.reason}); check the connection${target.overridden ? ` and ${API_URL_VARIABLE}` : ""}, then run again.`));
42
- case "unexpected": return new Ending(EXIT_USAGE, say(`${target.endpoint} did not answer as the publication endpoint while ${doing} (${answer.reason}); ${target.overridden ? `check that ${API_URL_VARIABLE} names the HomePages API` : "run again, and report it if it repeats"}.`));
43
- case "refused": {
44
- if (answer.status === 401) return new Ending(EXIT_USAGE, say(`${target.endpoint} did not accept ${TOKEN_VARIABLE} (${maskToken(target.token)}): the key is unknown or revoked; ask a HomePages admin for a key.`));
45
- const detail = answer.problem?.detail;
46
- if (answer.problem?.code === "publisher_token_wrong_environment") return new Ending(EXIT_USAGE, say(detail ?? `${"CONCRETE_TOKEN"} is a key for another environment than ${target.endpoint} serves.`));
47
- return new Ending(EXIT_REFUSED, say(detail ?? `${target.endpoint} refused the publication while ${doing} (HTTP ${String(answer.status)}); run again, and report it if it repeats.`));
48
- }
49
- }
39
+ function failureEnding(answer, target, doing, after) {
40
+ const where = target.console;
41
+ if (answer.kind === "unreachable") return new Ending(EXIT_FAILED, say(`could not reach ${where} while ${doing} (${answer.reason}); check the connection${target.overridden ? ` and ${CONSOLE_URL_VARIABLE}` : ""}, then run again.${after}`));
42
+ return new Ending(EXIT_FAILED, say(`${where} did not answer as the console while ${doing} (${answer.reason}); ${target.overridden ? `check that ${CONSOLE_URL_VARIABLE} names the development console` : "run again, and report it if it repeats"}.${after}`));
43
+ }
44
+ function sendEnding(answer, target) {
45
+ if (answer.kind !== "refused") return failureEnding(answer, target, "sending", "");
46
+ const detail = answer.refusal?.detail ?? `${target.console} refused the send (HTTP ${String(answer.status)}).`;
47
+ if (answer.status === 401) return new Ending(EXIT_FAILED, say(`${target.console} did not accept ${CONSOLE_KEY_VARIABLE} (${maskToken(target.key)}): ${detail}`));
48
+ return new Ending(EXIT_REFUSED, say(detail));
50
49
  }
51
- function unwrap(answer, target, doing) {
52
- if (answer.kind === "ok") return answer.value;
53
- throw endingFor(answer, target, doing);
50
+ function verdictEnding(answer, target, version) {
51
+ const after = ` Version ${version} is on the console; \`concrete release --version ${version}\` asks for its verdict again before it releases.`;
52
+ if (answer.kind !== "refused") return failureEnding(answer, target, "asking for the verdict", after);
53
+ const detail = answer.refusal?.detail ?? `${target.console} gave no verdict (HTTP ${String(answer.status)}).`;
54
+ return new Ending(EXIT_FAILED, say(`${detail}${after}`));
54
55
  }
55
- async function produceArtifact(run, root, out) {
56
+ async function produceArtifact(run, root) {
56
57
  const { io, deps } = run;
57
58
  let outcome;
58
59
  try {
59
60
  outcome = await deps.artifact({
60
61
  root,
61
- buildDir: resolve(root, DEFAULT_BUILD_DIR),
62
- out
62
+ buildDir: resolve(root, DEFAULT_BUILD_DIR)
63
63
  });
64
64
  } catch (cause) {
65
65
  throw new Ending(EXIT_REFUSED, say(`the build failed: ${cause instanceof Error ? cause.message : String(cause)}`));
66
66
  }
67
67
  if (!outcome.ok) {
68
68
  io.stderr.write(formatHuman(outcome.report));
69
- throw new Ending(EXIT_REFUSED, say("check is not green, so nothing was built or published; fix the findings above and run again."));
69
+ throw new Ending(EXIT_REFUSED, say("check is not green, so nothing was built or sent; fix the findings above and run again."));
70
70
  }
71
71
  io.stderr.write(stageLine("build", builtText(outcome.manifest)));
72
- return outcome.manifest;
72
+ return outcome;
73
73
  }
74
- async function follow(run, client, target, first) {
75
- const { io, deps } = run;
76
- const printed = /* @__PURE__ */ new Set();
77
- const print = (stage, text) => {
78
- if (printed.has(stage)) return;
79
- printed.add(stage);
80
- io.stderr.write(stageLine(stage, text));
81
- };
82
- let record = first;
83
- let failures = 0;
84
- for (;;) {
85
- const { state } = record;
86
- if (state === "writing" || state === "adopting" || state === "published" || state === "dry_run") print("verify", "ok");
87
- if (state === "adopting" || state === "published" || state === "dry_run") print("write", writeText(record));
88
- if (state === "published") print("adopt", adoptText(record));
89
- if (TERMINAL_STATES.includes(state)) {
90
- if (state === "refused" || state === "failed") print([
91
- "verify",
92
- "write",
93
- "adopt"
94
- ].find((candidate) => !printed.has(candidate)) ?? "adopt", `${state}${record.refusal === null ? "" : ` (${record.refusal.code})`}`);
95
- return record;
96
- }
97
- await deps.sleep(deps.pollIntervalMs);
98
- const answer = await client.read(record.id);
99
- if (answer.kind === "unreachable" && failures < POLL_FAILURES_TOLERATED) {
100
- failures += 1;
101
- continue;
102
- }
103
- if (answer.kind !== "ok") {
104
- const ending = endingFor(answer, target, `following publication ${record.id}`);
105
- throw new Ending(ending.code, `${ending.sentence.trimEnd()} The publication may still finish; a later run reports it already current if it did.\n`);
106
- }
107
- failures = 0;
108
- record = answer.value;
74
+ async function sendToConsole(run, root, built) {
75
+ const { io, deps, target } = run;
76
+ const { manifest } = built;
77
+ const answer = await deps.send(target, {
78
+ template: manifest.key,
79
+ frameworkVersion: manifest.framework_version,
80
+ files: built.sendable,
81
+ source: await deps.sourceFacts(root)
82
+ });
83
+ if (answer.kind !== "merged") throw sendEnding(answer, target);
84
+ const [first, ...rest] = sendLines(answer);
85
+ io.stderr.write(stageLine("send", first ?? ""));
86
+ for (const line of rest) io.stderr.write(stageLine(null, line));
87
+ const behind = behindText(manifest.framework_version, answer.merged.concrete_version);
88
+ if (behind !== null) io.stderr.write(behind);
89
+ return answer;
90
+ }
91
+ async function awaitVerdict(run, template, version) {
92
+ const { io, deps, target } = run;
93
+ for (let asks = 1;; asks++) {
94
+ const answer = await deps.verdict(target, template, version);
95
+ if (answer.kind === "given") return answer.verdict;
96
+ if (answer.kind !== "pending") throw verdictEnding(answer, target, version);
97
+ if (asks === 1) io.stderr.write(stageLine("verify", `the console is verifying version ${version}…`));
98
+ if (asks >= 10) throw new Ending(EXIT_FAILED, say(`the console has not verified version ${version} after ${String(asks)} asks. It is on the console; \`concrete release --version ${version}\` asks for its verdict again before it releases.`));
109
99
  }
110
100
  }
111
- async function publishWorkspace(run, root, target) {
112
- const { io, deps } = run;
113
- io.stderr.write(stageLine("target", targetText(target)));
114
- const scratch = await mkdtemp(join(tmpdir(), "concrete-publish-"));
115
- try {
116
- const out = join(scratch, "artifact");
117
- const manifest = await produceArtifact(run, root, out);
118
- const tarball = join(scratch, "artifact.tar.gz");
119
- await packArtifact(out, tarball);
120
- const size = (await stat(tarball)).size;
121
- const facts = await deps.sourceFacts(root);
122
- const client = deps.client(target.endpoint, target.token);
123
- const created = unwrap(await client.create({
124
- key: manifest.key,
125
- artifact_hash: manifest.template.content_hash,
126
- artifact_schema: manifest.artifact_schema,
127
- framework_version: manifest.framework_version,
128
- scope: manifest.scope,
129
- size_bytes: size,
130
- source_digest: manifest.source_digest,
131
- source_commit: facts.commit,
132
- source_remote: facts.remote
133
- }), target, "creating the publication");
134
- unwrap(await client.upload(created.upload, tarball), target, "uploading the artifact");
135
- io.stderr.write(stageLine("upload", uploadText(manifest, size, created.publication.publisher.name)));
136
- const settled = await follow(run, client, target, unwrap(await client.submit(created.publication.id, run.dryRun ? { dry_run: true } : null), target, "submitting the publication").publication);
137
- if (run.json) io.stdout.write(`${JSON.stringify(settled, null, 2)}\n`);
138
- if (settled.state === "refused" || settled.state === "failed") {
139
- io.stderr.write(refusalText(settled));
140
- return EXIT_REFUSED;
141
- }
142
- if (settled.review_url !== null) io.stderr.write(stageLine("review", settled.review_url));
143
- io.stderr.write(`${summaryText(settled)}\n`);
144
- return EXIT_OK;
145
- } finally {
146
- await removeTree(scratch);
101
+ async function publishWorkspace(run, root) {
102
+ const { io } = run;
103
+ io.stderr.write(stageLine("console", consoleText(run.target)));
104
+ const sent = await sendToConsole(run, root, await produceArtifact(run, root));
105
+ const verdict = await awaitVerdict(run, sent.merged.template, sent.merged.version);
106
+ io.stderr.write(stageLine("verify", verdictText(verdict)));
107
+ if (run.json) {
108
+ const outcome = {
109
+ template: sent.merged.template,
110
+ version: sent.merged.version,
111
+ link: sent.link,
112
+ merge: sent.merged.merge,
113
+ verdict
114
+ };
115
+ io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
116
+ }
117
+ if (!verdict.passed) {
118
+ io.stderr.write(refusedText(verdict));
119
+ return EXIT_REFUSED;
147
120
  }
121
+ io.stderr.write(notReleasedText(verdict));
122
+ return EXIT_OK;
148
123
  }
149
124
  async function publish(argv, io, deps) {
150
125
  let values;
@@ -155,29 +130,29 @@ async function publish(argv, io, deps) {
155
130
  }));
156
131
  } catch (cause) {
157
132
  io.stderr.write(say(`${cause instanceof Error ? cause.message : String(cause)}; run \`concrete --help\` for the flags publish takes.`));
158
- return EXIT_USAGE;
133
+ return EXIT_FAILED;
159
134
  }
160
135
  try {
161
136
  let root;
162
137
  try {
163
138
  root = await findWorkspaceRoot(io.cwd);
164
139
  } catch (cause) {
165
- throw new Ending(EXIT_USAGE, say(cause instanceof Error ? cause.message : String(cause)));
140
+ throw new Ending(EXIT_FAILED, say(cause instanceof Error ? cause.message : String(cause)));
166
141
  }
167
142
  let target;
168
143
  try {
169
- const envFile = stringFlag(values, "env-file");
170
- target = await resolveTarget(root, io.env, envFile === null ? void 0 : resolve(io.cwd, envFile));
144
+ const flag = stringFlag(values, "env-file");
145
+ target = await resolveConsoleTarget(root, io.env, flag === null ? void 0 : resolve(io.cwd, flag));
171
146
  } catch (cause) {
172
- if (cause instanceof TargetError) throw new Ending(EXIT_USAGE, say(cause.message));
147
+ if (cause instanceof TargetError) throw new Ending(EXIT_FAILED, say(cause.message));
173
148
  throw cause;
174
149
  }
175
150
  return await publishWorkspace({
176
151
  io,
177
152
  deps,
178
- json: booleanFlag(values, "json"),
179
- dryRun: booleanFlag(values, "dry-run")
180
- }, root, target);
153
+ target,
154
+ json: booleanFlag(values, "json")
155
+ }, root);
181
156
  } catch (cause) {
182
157
  if (cause instanceof Ending) {
183
158
  io.stderr.write(cause.sentence);
@@ -189,4 +164,4 @@ async function publish(argv, io, deps) {
189
164
  const runPublish = (argv, io) => publish(argv, io, DEFAULT_DEPS);
190
165
 
191
166
  //#endregion
192
- export { DEFAULT_DEPS, POLL_INTERVAL_MS, publish, runPublish };
167
+ export { DEFAULT_DEPS, publish, runPublish };