shiplane 0.4.1 → 0.5.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 (30) hide show
  1. package/README.md +28 -7
  2. package/dist/cli.js +2 -2
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{index-CxyLUqKJ.d.ts → index-CpQPaO28.d.ts} +4 -2
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +5 -5
  7. package/dist/memory.d.ts +1 -1
  8. package/dist/memory.js +1 -1
  9. package/dist/{package-registry.fake-D6e0c_iA.js → package-registry.fake-BuiTldHL.js} +2 -2
  10. package/dist/{package-registry.fake-D6e0c_iA.js.map → package-registry.fake-BuiTldHL.js.map} +1 -1
  11. package/dist/{package-registry.fake-DOI4N4yu.d.ts → package-registry.fake-CPAwyGn_.d.ts} +2 -2
  12. package/dist/{perEnv-B7AiYnW_.js → perEnv-n2qFRplP.js} +1 -1
  13. package/dist/{perEnv-B7AiYnW_.js.map → perEnv-n2qFRplP.js.map} +1 -1
  14. package/dist/plugin.d.ts +3 -3
  15. package/dist/plugin.js +5 -5
  16. package/dist/{readStatus-Dd_pBt-6.js → readStatus-QU-K9Czb.js} +244 -20
  17. package/dist/readStatus-QU-K9Czb.js.map +1 -0
  18. package/dist/{shell-server-hosting.adapter-DobfDqFm.js → shell-server-hosting.adapter-C7_5MWrl.js} +4 -3
  19. package/dist/shell-server-hosting.adapter-C7_5MWrl.js.map +1 -0
  20. package/dist/{src-Dqo5lgrW.js → src-DO7WyrfV.js} +3 -3
  21. package/dist/{src-Dqo5lgrW.js.map → src-DO7WyrfV.js.map} +1 -1
  22. package/dist/{static-hosting.port-DaIJfr1x.d.ts → static-hosting.port-pfDvRESk.d.ts} +44 -2
  23. package/dist/testing.d.ts +7 -5
  24. package/dist/testing.js +3 -3
  25. package/dist/{web-app.module-6KrXIU7j.js → web-app.module-Cg3SYqSo.js} +47 -2
  26. package/dist/web-app.module-Cg3SYqSo.js.map +1 -0
  27. package/package.json +20 -11
  28. package/dist/readStatus-Dd_pBt-6.js.map +0 -1
  29. package/dist/shell-server-hosting.adapter-DobfDqFm.js.map +0 -1
  30. package/dist/web-app.module-6KrXIU7j.js.map +0 -1
@@ -8,4 +8,4 @@ const perEnv = (value) => z.union([value, z.strictObject({
8
8
  //#endregion
9
9
  export { perEnv as t };
10
10
 
11
- //# sourceMappingURL=perEnv-B7AiYnW_.js.map
11
+ //# sourceMappingURL=perEnv-n2qFRplP.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"perEnv-B7AiYnW_.js","names":[],"sources":["../src/application/config/perEnv.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { Environment } from \"../../domain/environment\";\n\n/** A value that is the same everywhere, or written once per environment. */\nexport const perEnv = <Value extends z.ZodType>(value: Value) =>\n z.union([value, z.strictObject({ preview: value, production: value })]);\n\nexport type PerEnv<Value> = Value | Record<Environment, Value>;\n"],"mappings":";;;AAKA,MAAa,UAAmC,UAC9C,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa;CAAE,SAAS;CAAO,YAAY;CAAO,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"perEnv-n2qFRplP.js","names":[],"sources":["../src/application/config/perEnv.ts"],"sourcesContent":["import { z } from \"zod\";\n\nimport type { Environment } from \"../../domain/environment\";\n\n/** A value that is the same everywhere, or written once per environment. */\nexport const perEnv = <Value extends z.ZodType>(value: Value) =>\n z.union([value, z.strictObject({ preview: value, production: value })]);\n\nexport type PerEnv<Value> = Value | Record<Environment, Value>;\n"],"mappings":";;;AAKA,MAAa,UAAmC,UAC9C,EAAE,MAAM,CAAC,OAAO,EAAE,aAAa;CAAE,SAAS;CAAO,YAAY;CAAO,CAAC,CAAC,CAAC"}
package/dist/plugin.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as releaseSource, B as LinkedPr, F as ShellResult, I as CiPipelinePort, J as onlyVersionFiles, K as deployRunTitle, L as CodeHostPort, M as CommandFailed, O as SourceControlPort, P as Shell, R as Deploy, U as actionsMinutes, V as issueName, W as billedMinutes, _ as Refusal, a as VersioningPort, b as VersionChoice, c as DeliveryAdapter, ct as ReleaseUnit, d as DecideContext, dt as MascotMoment, f as Decision, g as JobInput, h as Job, i as MobileDistributionPort, it as StatusPlan, j as yesAllowed, k as GitPosition, l as ServiceAdapter, m as Health, mt as Environment, n as ServerHostingPort, nt as BumpLevel, o as Adapter, ot as appBumps, pt as progressBar, q as deployState, r as PackageRegistryPort, rt as PlannedChangeset, s as AdapterContext, t as StaticHostingPort, tt as AppBump, u as Command, ut as Mascot, v as Requirement, y as Resolved, z as IssueRef } from "./static-hosting.port-DaIJfr1x.js";
2
- import { A as perEnv, C as DEFAULT_TAG_FORMAT, D as isReleaseSubject, E as TagFormatName, O as tagName, S as Shipped, T as TAG_FORMATS, _ as Feature, a as mobileApp, b as ReleaseFlow, c as backendService, d as definePackageRegistry, f as defineServerHosting, g as AfterShipContext, h as defineRelease, i as publishedPackage, k as PerEnv, l as releaseFlow, m as ReleaseConfig, n as shellServerHosting, o as internalTool, p as defineStaticHosting, r as webApp, s as agentPlugin, t as z, u as defineMobileDistribution, v as FollowUp, x as ReleaseModule } from "./index-CxyLUqKJ.js";
1
+ import { A as releaseSource, B as LinkedPr, F as ShellResult, I as CiPipelinePort, J as onlyVersionFiles, K as deployRunTitle, L as CodeHostPort, M as CommandFailed, O as SourceControlPort, P as Shell, R as Deploy, U as actionsMinutes, V as issueName, W as billedMinutes, _ as Refusal, _t as Environment, a as VersioningPort, b as VersionChoice, c as DeliveryAdapter, ct as PlatformEnvPort, d as DecideContext, dt as isEnvVarName, f as Decision, g as JobInput, gt as progressBar, h as Job, i as MobileDistributionPort, it as StatusPlan, j as yesAllowed, k as GitPosition, l as ServiceAdapter, lt as ReleaseUnit, m as Health, mt as MascotMoment, n as ServerHostingPort, nt as BumpLevel, o as Adapter, ot as appBumps, pt as Mascot, q as deployState, r as PackageRegistryPort, rt as PlannedChangeset, s as AdapterContext, t as StaticHostingPort, tt as AppBump, u as Command, ut as EnvVarName, v as Requirement, y as Resolved, z as IssueRef } from "./static-hosting.port-pfDvRESk.js";
2
+ import { A as perEnv, C as DEFAULT_TAG_FORMAT, D as isReleaseSubject, E as TagFormatName, O as tagName, S as Shipped, T as TAG_FORMATS, _ as Feature, a as mobileApp, b as ReleaseFlow, c as backendService, d as definePackageRegistry, f as defineServerHosting, g as AfterShipContext, h as defineRelease, i as publishedPackage, k as PerEnv, l as releaseFlow, m as ReleaseConfig, n as shellServerHosting, o as internalTool, p as defineStaticHosting, r as webApp, s as agentPlugin, t as z, u as defineMobileDistribution, v as FollowUp, x as ReleaseModule } from "./index-CpQPaO28.js";
3
3
 
4
4
  //#region src/domain/versions.d.ts
5
5
  /** Negative, zero or positive, like a sort comparator: "0.1.10" is after "0.1.9". */
@@ -19,5 +19,5 @@ declare const workspacePatterns: (from: string | WorkspaceReader) => string[];
19
19
  /** Folders matching `dir/*` or an exact path, sorted. Negations and deeper globs are skipped. */
20
20
  declare const expandPatterns: (from: string | WorkspaceReader, patterns: readonly string[]) => string[];
21
21
  //#endregion
22
- export { Adapter, AdapterContext, type AfterShipContext, type AppBump, type BumpLevel, CiPipelinePort, CodeHostPort, type Command, CommandFailed, DEFAULT_TAG_FORMAT, type DecideContext, type Decision, DeliveryAdapter, type Deploy, Environment, Feature, type FollowUp, type GitPosition, type Health, type IssueRef, type Job, type JobInput, type LinkedPr, Mascot, MascotMoment, MobileDistributionPort, PackageRegistryPort, PerEnv, type PlannedChangeset, type Refusal, ReleaseConfig, ReleaseFlow, ReleaseModule, ReleaseUnit, type Requirement, type Resolved, ServerHostingPort, ServiceAdapter, type Shell, type ShellResult, type Shipped, SourceControlPort, StaticHostingPort, type StatusPlan, TAG_FORMATS, type TagFormatName, type VersionChoice, VersioningPort, actionsMinutes, agentPlugin, appBumps, backendService, billedMinutes, compareVersions, defineMobileDistribution, definePackageRegistry, defineRelease, defineServerHosting, defineStaticHosting, deployRunTitle, deployState, expandPatterns, internalTool, isReleaseSubject, issueName, mobileApp, nextPatch, onlyVersionFiles, perEnv, progressBar, publishedPackage, releaseFlow, releaseSource, shellServerHosting, tagName, webApp, workspacePatterns, yesAllowed, z };
22
+ export { Adapter, AdapterContext, type AfterShipContext, type AppBump, type BumpLevel, CiPipelinePort, CodeHostPort, type Command, CommandFailed, DEFAULT_TAG_FORMAT, type DecideContext, type Decision, DeliveryAdapter, type Deploy, EnvVarName, Environment, Feature, type FollowUp, type GitPosition, type Health, type IssueRef, type Job, type JobInput, type LinkedPr, Mascot, MascotMoment, MobileDistributionPort, PackageRegistryPort, PerEnv, type PlannedChangeset, PlatformEnvPort, type Refusal, ReleaseConfig, ReleaseFlow, ReleaseModule, ReleaseUnit, type Requirement, type Resolved, ServerHostingPort, ServiceAdapter, type Shell, type ShellResult, type Shipped, SourceControlPort, StaticHostingPort, type StatusPlan, TAG_FORMATS, type TagFormatName, type VersionChoice, VersioningPort, actionsMinutes, agentPlugin, appBumps, backendService, billedMinutes, compareVersions, defineMobileDistribution, definePackageRegistry, defineRelease, defineServerHosting, defineStaticHosting, deployRunTitle, deployState, expandPatterns, internalTool, isEnvVarName, isReleaseSubject, issueName, mobileApp, nextPatch, onlyVersionFiles, perEnv, progressBar, publishedPackage, releaseFlow, releaseSource, shellServerHosting, tagName, webApp, workspacePatterns, yesAllowed, z };
23
23
  //# sourceMappingURL=plugin.d.ts.map
package/dist/plugin.js CHANGED
@@ -1,8 +1,8 @@
1
- import { t as perEnv } from "./perEnv-B7AiYnW_.js";
2
- import { i as defineRelease, n as internalTool, r as agentPlugin, t as z } from "./src-Dqo5lgrW.js";
3
- import { a as defineStaticHosting, i as defineServerHosting, n as defineMobileDistribution, r as definePackageRegistry, t as shellServerHosting } from "./shell-server-hosting.adapter-DobfDqFm.js";
4
- import { a as releaseFlow, i as backendService, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-6KrXIU7j.js";
1
+ import { a as releaseFlow, i as backendService, l as isEnvVarName, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-Cg3SYqSo.js";
2
+ import { t as perEnv } from "./perEnv-n2qFRplP.js";
3
+ import { i as defineRelease, n as internalTool, r as agentPlugin, t as z } from "./src-DO7WyrfV.js";
4
+ import { a as defineStaticHosting, i as defineServerHosting, n as defineMobileDistribution, r as definePackageRegistry, t as shellServerHosting } from "./shell-server-hosting.adapter-C7_5MWrl.js";
5
5
  import { A as workspacePatterns, O as tagName, T as isReleaseSubject, a as CommandFailed, b as DEFAULT_TAG_FORMAT, c as onlyVersionFiles, d as appBumps, g as nextPatch, h as compareVersions, k as expandPatterns, n as billedMinutes, o as deployRunTitle, s as deployState, t as actionsMinutes, v as releaseSource, x as TAG_FORMATS, y as yesAllowed } from "./budget-BTnKtGF6.js";
6
6
  import { t as progressBar } from "./display-IqkJ6uCw.js";
7
7
  import { t as issueName } from "./issues-TcWtMTv5.js";
8
- export { CommandFailed, DEFAULT_TAG_FORMAT, TAG_FORMATS, actionsMinutes, agentPlugin, appBumps, backendService, billedMinutes, compareVersions, defineMobileDistribution, definePackageRegistry, defineRelease, defineServerHosting, defineStaticHosting, deployRunTitle, deployState, expandPatterns, internalTool, isReleaseSubject, issueName, mobileApp, nextPatch, onlyVersionFiles, perEnv, progressBar, publishedPackage, releaseFlow, releaseSource, shellServerHosting, tagName, webApp, workspacePatterns, yesAllowed, z };
8
+ export { CommandFailed, DEFAULT_TAG_FORMAT, TAG_FORMATS, actionsMinutes, agentPlugin, appBumps, backendService, billedMinutes, compareVersions, defineMobileDistribution, definePackageRegistry, defineRelease, defineServerHosting, defineStaticHosting, deployRunTitle, deployState, expandPatterns, internalTool, isEnvVarName, isReleaseSubject, issueName, mobileApp, nextPatch, onlyVersionFiles, perEnv, progressBar, publishedPackage, releaseFlow, releaseSource, shellServerHosting, tagName, webApp, workspacePatterns, yesAllowed, z };
@@ -1,4 +1,4 @@
1
- import { a as releaseFlow, i as backendService, n as publishedPackage, r as mobileApp, t as webApp } from "./web-app.module-6KrXIU7j.js";
1
+ import { a as releaseFlow, c as findUnset, i as backendService, l as isEnvVarName, n as publishedPackage, o as ENV_VAR_NAME, r as mobileApp, s as EnvToCheck, t as webApp } from "./web-app.module-Cg3SYqSo.js";
2
2
  import { A as workspacePatterns, C as changelogSection, D as tagFormatNamed, E as releaseTags, O as tagName, S as cameWithRelease, _ as nextVersion, a as CommandFailed, b as DEFAULT_TAG_FORMAT, c as onlyVersionFiles, d as appBumps, f as changesetApps, i as minutesBudget, k as expandPatterns, l as shipsFrom, m as splitChangesets, o as deployRunTitle, p as packageBumps, r as deployEstimate, u as webShip, v as releaseSource, w as firstRelease, x as TAG_FORMATS } from "./budget-BTnKtGF6.js";
3
3
  import { z } from "zod";
4
4
  import fs from "node:fs";
@@ -135,10 +135,22 @@ const keysAt = (schema, at) => {
135
135
  const child = def.shape?.[String(first)];
136
136
  return child ? keysAt(child, rest) : [];
137
137
  };
138
+ const envVarNames$1 = z.array(z.string().regex(ENV_VAR_NAME, "an env var name is UPPER_SNAKE, like SENTRY_DSN")).describe("Env var names, one per line");
139
+ const onlyOn = (environment) => envVarNames$1.optional().describe(`Checked on ${environment} only, on top of all`);
140
+ const environmentLists = {
141
+ preview: onlyOn("preview"),
142
+ production: onlyOn("production")
143
+ };
144
+ /** One list for every environment, or `all` plus a list per environment. */
145
+ const checkEnvBeforeDeploySchema = z.union([envVarNames$1, z.strictObject({
146
+ all: envVarNames$1.optional().describe("Checked on every environment, current and future"),
147
+ ...environmentLists
148
+ })]).describe("Before each deploy, shiplane checks these env var names are set on the platform; you set the values");
138
149
  /** What a unit file naming this module may hold: `module`, then its adapter's settings. */
139
150
  const unitSchema = (module) => z.strictObject({
140
151
  module: z.literal(module.name).describe(`The module that ships this app, with ${module.provider}`),
141
152
  buildCommand: z.string().optional().describe("How to build this app, when its package.json has no \"build\" script"),
153
+ checkEnvBeforeDeploy: checkEnvBeforeDeploySchema.optional(),
142
154
  ...mapShape(module.settings.shape, deepStrict)
143
155
  });
144
156
  /** The JSON Schema editors read for `shiplane.unit.yml`: the module an app names picks its keys. */
@@ -182,8 +194,17 @@ const locate = (doc, counter) => (at, key) => {
182
194
  const offset = node?.range?.[0];
183
195
  return offset === void 0 ? void 0 : counter.linePos(offset).line;
184
196
  };
197
+ /** Of a union's branches, the one written in the right shape: its problems are inside, not the shape. */
198
+ const closestBranch = (branches) => branches.find((issues) => issues.every(({ code, path }) => !(code === "invalid_type" && path.length === 0)));
185
199
  const describeIssue = (issue, file, module, lineAt) => {
186
200
  const at = issue.path;
201
+ if (issue.code === "invalid_union") {
202
+ const branch = closestBranch(issue.errors);
203
+ if (branch) return branch.flatMap((inner) => describeIssue({
204
+ ...inner,
205
+ path: [...at, ...inner.path]
206
+ }, file, module, lineAt));
207
+ }
187
208
  if (issue.code === "unrecognized_keys") return issue.keys.map((key) => ({
188
209
  file,
189
210
  line: lineAt(at, key),
@@ -202,6 +223,17 @@ const describeIssue = (issue, file, module, lineAt) => {
202
223
  message: `"${name}": ${issue.message}`
203
224
  }];
204
225
  };
226
+ const CORE_KEYS = new Set([
227
+ "module",
228
+ "buildCommand",
229
+ "checkEnvBeforeDeploy"
230
+ ]);
231
+ const envVarNames = (list = []) => list.filter(isEnvVarName);
232
+ const envToCheck = (written) => new EnvToCheck(Array.isArray(written) ? envVarNames(written) : {
233
+ all: envVarNames(written.all),
234
+ preview: envVarNames(written.preview),
235
+ production: envVarNames(written.production)
236
+ });
205
237
  const problem = (file, line, message, hint) => ({ problems: [{
206
238
  file,
207
239
  line,
@@ -233,12 +265,14 @@ const readUnitFile = (file, text, modules, features = []) => {
233
265
  if (!module) return problem(file, lineAt(["module"]), `no module named "${named}" in shiplane.config.ts`, didYouMean(named, names) ?? oneOf);
234
266
  const parsed = unitSchema(module).safeParse(data);
235
267
  if (!parsed.success) return { problems: parsed.error.issues.flatMap((issue) => describeIssue(issue, file, module, lineAt)) };
236
- const options = Object.fromEntries(Object.entries(data).filter(([key]) => key !== "module" && key !== "buildCommand"));
268
+ const options = Object.fromEntries(Object.entries(data).filter(([key]) => !CORE_KEYS.has(key)));
237
269
  const buildCommand = typeof data.buildCommand === "string" ? data.buildCommand : void 0;
270
+ const written = parsed.data.checkEnvBeforeDeploy;
238
271
  return {
239
272
  unit: {
240
273
  module: named,
241
274
  ...buildCommand ? { buildCommand } : {},
275
+ ...written ? { checkEnvBeforeDeploy: envToCheck(written) } : {},
242
276
  options,
243
277
  lineOf: (at) => lineAt(at)
244
278
  },
@@ -441,27 +475,183 @@ const destination = (context, units, environment) => {
441
475
  return label === "live" ? label : `to ${label}`;
442
476
  };
443
477
  //#endregion
478
+ //#region src/application/checkEnvBeforeDeploy.ts
479
+ const STEP = "Check env before deploy";
480
+ const SET_THEM = "Are they set now?";
481
+ const READ_AGAIN = "Read the platform again?";
482
+ /** The units that list env to check, each with its list. */
483
+ const listing = (units) => units.flatMap((unit) => unit.checkEnvBeforeDeploy ? [{
484
+ unit,
485
+ toCheck: unit.checkEnvBeforeDeploy
486
+ }] : []);
487
+ /** The unit's platform env, or the provider that cannot list names. */
488
+ const platformEnvOf = ({ release, shell }, unit) => {
489
+ const module = release.modules.find(({ name }) => name === unit.module);
490
+ if (!module?.env) return { cannotList: module?.provider ?? unit.module };
491
+ const port = module.env({
492
+ root: release.root,
493
+ shell
494
+ });
495
+ const options = (environment) => resolvedOptions(module, unit, environment, release.units);
496
+ return {
497
+ listNames: (input) => port.listNames({
498
+ ...input,
499
+ options: options(input.environment)
500
+ }),
501
+ setCommand: (input) => port.setCommand({
502
+ ...input,
503
+ options: options(input.environment)
504
+ })
505
+ };
506
+ };
507
+ const line = ({ output }, mark, text) => output.line(`${mark} ${paint("bold", STEP)} ${text}`);
508
+ /** The names the platform holds, or null when the person stops, or CI cannot read it. */
509
+ const readNames = async (context, port, input) => {
510
+ try {
511
+ return await port.listNames(input);
512
+ } catch (error) {
513
+ const reason = error instanceof Error ? error.message : String(error);
514
+ line(context, paint("red", "✗"), `${input.unit.name} on ${input.environment}: ${reason}`);
515
+ return context.prompter.interactive && !context.options.yes && await context.prompter.confirm(READ_AGAIN, true) ? readNames(context, port, input) : null;
516
+ }
517
+ };
518
+ const canWait = ({ prompter, options }) => prompter.interactive && !options.yes;
519
+ /** One unit on one environment: true once every listed name is on its platform. */
520
+ const checkUnit = async (context, port, { unit, toCheck }, environment) => {
521
+ const expected = toCheck.for(environment);
522
+ const where = `${unit.name} on ${environment}`;
523
+ const setOnPlatform = await readNames(context, port, {
524
+ unit,
525
+ environment
526
+ });
527
+ if (!setOnPlatform) return false;
528
+ const unset = findUnset({
529
+ expected,
530
+ setOnPlatform
531
+ });
532
+ if (unset.isEmpty()) {
533
+ line(context, paint("green", "✓"), `${where}: ${expected.size} of ${expected.size} set`);
534
+ return true;
535
+ }
536
+ const { output } = context;
537
+ const command = port.setCommand({
538
+ unit,
539
+ environment,
540
+ names: unset.names()
541
+ });
542
+ line(context, paint("yellow", "!"), `${where}: ${unset.names().length} unset env vars, the deploy waits`);
543
+ unset.names().forEach((name) => output.line(` ${name}`));
544
+ if (!canWait(context)) {
545
+ output.line(` ${paint("dim", "Nothing was written. Set them, then run again:")}`);
546
+ output.line(` ${command}`);
547
+ return false;
548
+ }
549
+ output.line(` ${paint("dim", "You set these values; shiplane never does. Run, with your values:")}`);
550
+ output.line(` ${command}`);
551
+ if (!await context.prompter.confirm(SET_THEM, true)) return false;
552
+ return checkUnit(context, port, {
553
+ unit,
554
+ toCheck
555
+ }, environment);
556
+ };
557
+ /**
558
+ * Before a deploy: each unit that lists env to check has every name on its platform. A person sets
559
+ * the values; shiplane only reads names. False when a name is still unset and nothing should ship.
560
+ */
561
+ const checkEnvBeforeDeploy = async (context, { environment, units }) => {
562
+ for (const entry of listing(units)) {
563
+ const port = platformEnvOf(context, entry.unit);
564
+ if ("cannotList" in port) {
565
+ line(context, paint("yellow", "!"), `${entry.unit.name}: can't check env on ${port.cannotList}, the deploy goes on`);
566
+ continue;
567
+ }
568
+ if (!await checkUnit(context, port, entry, environment)) return false;
569
+ }
570
+ return true;
571
+ };
572
+ //#endregion
573
+ //#region src/application/reportEnvToCheck.ts
574
+ const doctorLine = (output, mark, text) => output.line(`${paint("dim", "│")} ${mark} ${text}`);
575
+ /** One unit on one environment, for doctor: true when every listed name is on its platform. */
576
+ const reportUnit = async (output, port, { unit, toCheck }, environment) => {
577
+ const expected = toCheck.for(environment);
578
+ const where = `${unit.name} on ${environment}`;
579
+ const setOnPlatform = await port.listNames({
580
+ unit,
581
+ environment
582
+ }).catch((error) => {
583
+ const reason = error instanceof Error ? error.message : String(error);
584
+ doctorLine(output, paint("red", "✗"), `${where}: ${reason}`);
585
+ return null;
586
+ });
587
+ if (!setOnPlatform) return false;
588
+ const unset = findUnset({
589
+ expected,
590
+ setOnPlatform
591
+ });
592
+ if (unset.isEmpty()) {
593
+ doctorLine(output, paint("green", "✓"), `${where}: ${expected.size} of ${expected.size} set`);
594
+ return true;
595
+ }
596
+ const names = unset.names();
597
+ doctorLine(output, paint("red", "✗"), `${where}: ${names.length} unset env vars: ${names.join(", ")}`);
598
+ output.line(`${paint("dim", "│")} ${paint("dim", `you set them: ${port.setCommand({
599
+ unit,
600
+ environment,
601
+ names
602
+ })}`)}`);
603
+ return false;
604
+ };
605
+ /**
606
+ * `doctor`'s env section: each unit that lists env to check, on every environment. Prints nothing
607
+ * when no unit lists any. False when a name is unset or a platform cannot be read.
608
+ */
609
+ const reportEnvToCheck = async ({ release, shell, output }) => {
610
+ const checked = listing(release.units);
611
+ if (checked.length === 0) return true;
612
+ doctorLine(output, "", paint("bold", STEP));
613
+ let allSet = true;
614
+ for (const entry of checked) {
615
+ entry.toCheck.listedTwice().forEach((name) => doctorLine(output, paint("yellow", "!"), `${entry.unit.name}: ${name} is in all and listed again`));
616
+ const port = platformEnvOf({
617
+ release,
618
+ shell
619
+ }, entry.unit);
620
+ if ("cannotList" in port) {
621
+ doctorLine(output, paint("yellow", "!"), `${entry.unit.name}: can't check env on ${port.cannotList}`);
622
+ continue;
623
+ }
624
+ for (const environment of ENVIRONMENTS) allSet = await reportUnit(output, port, entry, environment) && allSet;
625
+ }
626
+ return allSet;
627
+ };
628
+ //#endregion
444
629
  //#region src/application/requirements.ts
445
630
  /**
446
631
  * Every tool and sign-in the flow, the features and the modules need, once each. With `apps`, only
447
632
  * the modules shipping one of those apps count.
448
633
  */
449
634
  const requirementsOf = (release, apps) => {
450
- const appsOf = (name) => release.units.filter(({ module, name: app }) => module === name && (!apps || apps.has(app)));
451
- const required = [
635
+ return onceEach([
452
636
  ...[
453
637
  release.flow.sourceControl,
454
638
  release.flow.codeHost,
455
639
  release.flow.ciPipeline,
456
640
  release.flow.versioning
457
641
  ].flatMap((adapter) => adapter.requirements?.() ?? []),
458
- ...release.modules.flatMap((module) => {
459
- const shipped = appsOf(module.name);
460
- return apps && shipped.length === 0 ? [] : module.requirements?.(shipped) ?? [];
461
- }),
642
+ ...modulesRequire(release, apps),
462
643
  ...release.features.flatMap((feature) => feature.requirements?.() ?? [])
463
- ];
464
- return required.filter((requirement, index) => required.findIndex(({ label }) => label === requirement.label) === index);
644
+ ]);
645
+ };
646
+ /** The sign-ins only the modules shipping those apps need, once each. */
647
+ const signInsOf = (release, apps) => onceEach(modulesRequire(release, apps));
648
+ const modulesRequire = (release, apps) => release.modules.flatMap((module) => {
649
+ const shipped = release.units.filter(({ module: name, name: app }) => name === module.name && (!apps || apps.has(app)));
650
+ return apps && shipped.length === 0 ? [] : module.requirements?.(shipped) ?? [];
651
+ });
652
+ const onceEach = (required) => {
653
+ const seen = /* @__PURE__ */ new Set();
654
+ return required.filter(({ label }) => !seen.has(label) && Boolean(seen.add(label)));
465
655
  };
466
656
  /** A requirement's check run from the root: its exit status, 127 when the tool is missing. */
467
657
  const checkStatus = async (shell, root, { check }) => (await shell.capture(check.command, check.args, {
@@ -472,10 +662,15 @@ const checkStatus = async (shell, root, { check }) => (await shell.capture(check
472
662
  * Before a release writes anything: each sign-in its picked units need. A failing one offers its
473
663
  * fix, then is checked again. False, with the commands to run, when one still fails.
474
664
  */
475
- const preflight = async (context, apps) => {
665
+ const preflight = (context, apps) => signIn(context, {
666
+ requirements: requirementsOf(context.release, apps),
667
+ again: "run the release again"
668
+ });
669
+ /** Each requirement checked; a failing one offers its fix. False, with the commands, when one still fails. */
670
+ const signIn = async (context, { requirements, again }) => {
476
671
  const { shell, prompter, options, release } = context;
477
672
  const failing = [];
478
- for (const requirement of requirementsOf(release, apps)) {
673
+ for (const requirement of requirements) {
479
674
  const status = await checkStatus(shell, release.root, requirement);
480
675
  if (status === 0) continue;
481
676
  const { fix } = requirement;
@@ -489,7 +684,7 @@ const preflight = async (context, apps) => {
489
684
  failing.push(requirement);
490
685
  }
491
686
  if (failing.length === 0) return true;
492
- fail(context, `Not signed in: ${failing.map(({ label }) => label).join(", ")}`, "nothing was written. Sign in, then run the release again.", [...failing.flatMap(({ fix }) => fix ? [commandLine(fix)] : []), "shiplane"]);
687
+ fail(context, `Not signed in: ${failing.map(({ label }) => label).join(", ")}`, `nothing was written. Sign in, then ${again}.`, [...failing.flatMap(({ fix }) => fix ? [commandLine(fix)] : []), "shiplane"]);
493
688
  return false;
494
689
  };
495
690
  //#endregion
@@ -795,8 +990,14 @@ const doctor = async (context) => {
795
990
  env: fix.env
796
991
  });
797
992
  }
798
- output.line(`${paint("dim", "└")} Next: ${paint("cyan", failing.length > 0 ? "shiplane doctor" : "shiplane status")}`);
799
- return failing.length === 0;
993
+ const envSet = await reportEnvToCheck({
994
+ release,
995
+ shell,
996
+ output
997
+ });
998
+ const passed = failing.length === 0 && envSet;
999
+ output.line(`${paint("dim", "└")} Next: ${paint("cyan", passed ? "shiplane status" : "shiplane doctor")}`);
1000
+ return passed;
800
1001
  };
801
1002
  //#endregion
802
1003
  //#region src/application/initRelease.ts
@@ -1274,6 +1475,7 @@ const loadRelease = async (root, options = {}) => {
1274
1475
  version: manifest.version,
1275
1476
  module: result.unit.module,
1276
1477
  ...result.unit.buildCommand ? { buildCommand: result.unit.buildCommand } : {},
1478
+ ...result.unit.checkEnvBeforeDeploy ? { checkEnvBeforeDeploy: result.unit.checkEnvBeforeDeploy } : {},
1277
1479
  options: result.unit.options,
1278
1480
  after: []
1279
1481
  },
@@ -2481,7 +2683,7 @@ const waitForMerge = async (context, pr) => {
2481
2683
  /**
2482
2684
  * A small PR a plugin needs merged before it ships, such as production's version moving: branch,
2483
2685
  * write, commit, push, open, back to main, wait for the merge, pull. `declined` when the person
2484
- * said no.
2686
+ * said no, or the PR was left waiting for approval.
2485
2687
  */
2486
2688
  const pullRequestFirst = async (context, request) => {
2487
2689
  const { output, services } = context;
@@ -2519,10 +2721,15 @@ const pullRequestFirst = async (context, request) => {
2519
2721
  const { pr } = created;
2520
2722
  if (!opened || !pr) return "failed";
2521
2723
  output.line();
2522
- if (!await waitForMerge(context, pr)) {
2724
+ const outcome = await waitForMerge(context, pr);
2725
+ if (outcome === "closed") {
2523
2726
  fail(context, `#${pr.number} was closed without a merge`, "nothing shipped.", ["shiplane"]);
2524
2727
  return "failed";
2525
2728
  }
2729
+ if (outcome === "left") {
2730
+ output.line(paint("dim", ` Left #${pr.number} waiting. Run shiplane once it's merged.`));
2731
+ return "declined";
2732
+ }
2526
2733
  return await runSteps(context, [{
2527
2734
  label: "pull main",
2528
2735
  run: () => services.sourceControl.pull()
@@ -2733,7 +2940,7 @@ const shipQuestion = (going, paths, environment, context) => {
2733
2940
  * triggered: EAS builds and workflows go on on their own, a Fly deploy from here once rolled out.
2734
2941
  * Production asks for its name first. False on a failure.
2735
2942
  */
2736
- const shipTo = async (context, environment, { scope, via }) => {
2943
+ const shipTo = async (context, environment, { scope, via, envChecked = /* @__PURE__ */ new Set() }) => {
2737
2944
  const { output, prompter, options, services } = context;
2738
2945
  if (environment === "production" && !options.ci) {
2739
2946
  if (options.yes) {
@@ -2751,6 +2958,16 @@ const shipTo = async (context, environment, { scope, via }) => {
2751
2958
  context.progress.say("resting", paint("dim", `Nothing to ship ${destination(context, scope ?? [], environment)}.`));
2752
2959
  return true;
2753
2960
  }
2961
+ const toCheck = ready.map(({ unit }) => unit).filter(({ name }) => !envChecked.has(name));
2962
+ const listing = new Set(toCheck.filter((unit) => unit.checkEnvBeforeDeploy).map(({ name }) => name));
2963
+ if (!(listing.size === 0 || await signIn(context, {
2964
+ requirements: signInsOf(context.release, listing),
2965
+ again: "ship again"
2966
+ }))) return false;
2967
+ if (!await checkEnvBeforeDeploy(context, {
2968
+ environment,
2969
+ units: toCheck
2970
+ })) return false;
2754
2971
  const forced = options.ci ? "local" : via;
2755
2972
  const paths = /* @__PURE__ */ new Map();
2756
2973
  const unanswered = [];
@@ -3024,6 +3241,10 @@ const releaseToPreview = async (context) => {
3024
3241
  return true;
3025
3242
  }
3026
3243
  if (!await preflight(context, picked.scope)) return false;
3244
+ if (!await checkEnvBeforeDeploy(context, {
3245
+ environment: "preview",
3246
+ units: context.release.units.filter(({ name }) => picked.scope.has(name))
3247
+ })) return false;
3027
3248
  const covered = picked.info.filter(({ app }) => picked.scope.has(app));
3028
3249
  const [releasePrs, missing] = await progress.during("Looking for an open release PR and versions not tagged yet", "thinking", () => Promise.all([services.codeHost.openPrsFrom(RELEASE_BRANCH_PREFIX), missingTags(context)]));
3029
3250
  const step = nextStep({
@@ -3090,7 +3311,10 @@ const releaseToPreview = async (context) => {
3090
3311
  if (tags.length > 0) stage("Tags");
3091
3312
  if (!await tagRelease(current, tags)) return false;
3092
3313
  stage("Ship");
3093
- return shipTo(current, "preview", { scope: new Set([...picked.scope, ...tags.map(({ app }) => app)]) });
3314
+ return shipTo(current, "preview", {
3315
+ scope: new Set([...picked.scope, ...tags.map(({ app }) => app)]),
3316
+ envChecked: picked.scope
3317
+ });
3094
3318
  };
3095
3319
  //#endregion
3096
3320
  //#region src/application/customAdapter.ts
@@ -3955,4 +4179,4 @@ const readStatus = async (context, environment) => {
3955
4179
  //#endregion
3956
4180
  export { refreshEditorSchema as C, keysAt as D, ENVIRONMENTS as E, nodeFiles as O, CONFIG_FILE as S, optionsFor as T, loadRelease as _, releaseToPreview as a, initRelease as b, promote as c, pickScope as d, openReleasePr as f, findConfig as g, docsFor as h, setup as i, shipTo as l, newAdapter as m, systemShell as n, missingTags as o, prepareRelease as p, liveLine as r, tagRelease as s, readStatus as t, planShips as u, addUnit as v, environmentLabel as w, doctor as x, removeUnit as y };
3957
4181
 
3958
- //# sourceMappingURL=readStatus-Dd_pBt-6.js.map
4182
+ //# sourceMappingURL=readStatus-QU-K9Czb.js.map