shiplane 0.4.1 → 0.4.2

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 (29) hide show
  1. package/README.md +9 -0
  2. package/dist/cli.js +2 -2
  3. package/dist/{index-CxyLUqKJ.d.ts → index-CpQPaO28.d.ts} +4 -2
  4. package/dist/index.d.ts +3 -3
  5. package/dist/index.js +5 -5
  6. package/dist/memory.d.ts +1 -1
  7. package/dist/memory.js +1 -1
  8. package/dist/{package-registry.fake-D6e0c_iA.js → package-registry.fake-BuiTldHL.js} +2 -2
  9. package/dist/{package-registry.fake-D6e0c_iA.js.map → package-registry.fake-BuiTldHL.js.map} +1 -1
  10. package/dist/{package-registry.fake-DOI4N4yu.d.ts → package-registry.fake-CPAwyGn_.d.ts} +2 -2
  11. package/dist/{perEnv-B7AiYnW_.js → perEnv-n2qFRplP.js} +1 -1
  12. package/dist/{perEnv-B7AiYnW_.js.map → perEnv-n2qFRplP.js.map} +1 -1
  13. package/dist/plugin.d.ts +3 -3
  14. package/dist/plugin.js +5 -5
  15. package/dist/{readStatus-Dd_pBt-6.js → readStatus-BnEVjKc8.js} +237 -18
  16. package/dist/readStatus-BnEVjKc8.js.map +1 -0
  17. package/dist/{shell-server-hosting.adapter-DobfDqFm.js → shell-server-hosting.adapter-C7_5MWrl.js} +4 -3
  18. package/dist/shell-server-hosting.adapter-C7_5MWrl.js.map +1 -0
  19. package/dist/{src-Dqo5lgrW.js → src-DO7WyrfV.js} +3 -3
  20. package/dist/{src-Dqo5lgrW.js.map → src-DO7WyrfV.js.map} +1 -1
  21. package/dist/{static-hosting.port-DaIJfr1x.d.ts → static-hosting.port-pfDvRESk.d.ts} +44 -2
  22. package/dist/testing.d.ts +7 -5
  23. package/dist/testing.js +3 -3
  24. package/dist/{web-app.module-6KrXIU7j.js → web-app.module-Cg3SYqSo.js} +47 -2
  25. package/dist/web-app.module-Cg3SYqSo.js.map +1 -0
  26. package/package.json +1 -1
  27. package/dist/readStatus-Dd_pBt-6.js.map +0 -1
  28. package/dist/shell-server-hosting.adapter-DobfDqFm.js.map +0 -1
  29. package/dist/web-app.module-6KrXIU7j.js.map +0 -1
@@ -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
  },
@@ -2733,7 +2935,7 @@ const shipQuestion = (going, paths, environment, context) => {
2733
2935
  * triggered: EAS builds and workflows go on on their own, a Fly deploy from here once rolled out.
2734
2936
  * Production asks for its name first. False on a failure.
2735
2937
  */
2736
- const shipTo = async (context, environment, { scope, via }) => {
2938
+ const shipTo = async (context, environment, { scope, via, envChecked = /* @__PURE__ */ new Set() }) => {
2737
2939
  const { output, prompter, options, services } = context;
2738
2940
  if (environment === "production" && !options.ci) {
2739
2941
  if (options.yes) {
@@ -2751,6 +2953,16 @@ const shipTo = async (context, environment, { scope, via }) => {
2751
2953
  context.progress.say("resting", paint("dim", `Nothing to ship ${destination(context, scope ?? [], environment)}.`));
2752
2954
  return true;
2753
2955
  }
2956
+ const toCheck = ready.map(({ unit }) => unit).filter(({ name }) => !envChecked.has(name));
2957
+ const listing = new Set(toCheck.filter((unit) => unit.checkEnvBeforeDeploy).map(({ name }) => name));
2958
+ if (!(listing.size === 0 || await signIn(context, {
2959
+ requirements: signInsOf(context.release, listing),
2960
+ again: "ship again"
2961
+ }))) return false;
2962
+ if (!await checkEnvBeforeDeploy(context, {
2963
+ environment,
2964
+ units: toCheck
2965
+ })) return false;
2754
2966
  const forced = options.ci ? "local" : via;
2755
2967
  const paths = /* @__PURE__ */ new Map();
2756
2968
  const unanswered = [];
@@ -3024,6 +3236,10 @@ const releaseToPreview = async (context) => {
3024
3236
  return true;
3025
3237
  }
3026
3238
  if (!await preflight(context, picked.scope)) return false;
3239
+ if (!await checkEnvBeforeDeploy(context, {
3240
+ environment: "preview",
3241
+ units: context.release.units.filter(({ name }) => picked.scope.has(name))
3242
+ })) return false;
3027
3243
  const covered = picked.info.filter(({ app }) => picked.scope.has(app));
3028
3244
  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
3245
  const step = nextStep({
@@ -3090,7 +3306,10 @@ const releaseToPreview = async (context) => {
3090
3306
  if (tags.length > 0) stage("Tags");
3091
3307
  if (!await tagRelease(current, tags)) return false;
3092
3308
  stage("Ship");
3093
- return shipTo(current, "preview", { scope: new Set([...picked.scope, ...tags.map(({ app }) => app)]) });
3309
+ return shipTo(current, "preview", {
3310
+ scope: new Set([...picked.scope, ...tags.map(({ app }) => app)]),
3311
+ envChecked: picked.scope
3312
+ });
3094
3313
  };
3095
3314
  //#endregion
3096
3315
  //#region src/application/customAdapter.ts
@@ -3955,4 +4174,4 @@ const readStatus = async (context, environment) => {
3955
4174
  //#endregion
3956
4175
  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
4176
 
3958
- //# sourceMappingURL=readStatus-Dd_pBt-6.js.map
4177
+ //# sourceMappingURL=readStatus-BnEVjKc8.js.map