betterstart-cli 0.0.82 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -25696,12 +25696,25 @@ function runVercel(runner, args, options) {
25696
25696
  let stdout = "";
25697
25697
  let stderr = "";
25698
25698
  let timedOut = false;
25699
+ let closed = false;
25700
+ let effectiveTimeoutMs = timeoutMs;
25701
+ let timeout;
25702
+ const armTimeout = (ms) => {
25703
+ if (closed) return;
25704
+ clearTimeout(timeout);
25705
+ effectiveTimeoutMs = ms;
25706
+ timeout = setTimeout(() => {
25707
+ timedOut = true;
25708
+ child.kill("SIGTERM");
25709
+ }, ms);
25710
+ };
25711
+ const runControl = { extendTimeout: armTimeout };
25699
25712
  const onOutputLine = options.onOutputLine;
25700
25713
  const createOutputObserver = () => {
25701
25714
  if (!onOutputLine) return void 0;
25702
25715
  return createFilteredLineForwarder(
25703
25716
  (line) => line.length > 0,
25704
- (text7) => onOutputLine(stripVTControlCharacters3(text7).trim())
25717
+ (text7) => onOutputLine(stripVTControlCharacters3(text7).trim(), runControl)
25705
25718
  );
25706
25719
  };
25707
25720
  const stdoutObserver = createOutputObserver();
@@ -25748,11 +25761,9 @@ function runVercel(runner, args, options) {
25748
25761
  errForwarder.flush();
25749
25762
  });
25750
25763
  }
25751
- const timeout = setTimeout(() => {
25752
- timedOut = true;
25753
- child.kill("SIGTERM");
25754
- }, timeoutMs);
25764
+ armTimeout(timeoutMs);
25755
25765
  child.on("close", (code, signal) => {
25766
+ closed = true;
25756
25767
  clearTimeout(timeout);
25757
25768
  stdoutObserver?.flush();
25758
25769
  stderrObserver?.flush();
@@ -25764,7 +25775,7 @@ function runVercel(runner, args, options) {
25764
25775
  stdout,
25765
25776
  stderr,
25766
25777
  timedOut: true,
25767
- errorMessage: `Vercel command timed out after ${Math.floor(timeoutMs / 1e3)}s`
25778
+ errorMessage: `Vercel command timed out after ${Math.floor(effectiveTimeoutMs / 1e3)}s`
25768
25779
  });
25769
25780
  return;
25770
25781
  }
@@ -25779,6 +25790,7 @@ function runVercel(runner, args, options) {
25779
25790
  });
25780
25791
  });
25781
25792
  child.on("error", (err) => {
25793
+ closed = true;
25782
25794
  clearTimeout(timeout);
25783
25795
  stdoutObserver?.flush();
25784
25796
  stderrObserver?.flush();
@@ -25961,6 +25973,14 @@ function versionedVercelProjectName(base, attempt) {
25961
25973
  }
25962
25974
  async function createVercelProject(runner, cwd, name, options = {}) {
25963
25975
  const base = sanitizeVercelProjectName(name);
25976
+ const scoped = await createAndLinkProject(runner, cwd, base, options);
25977
+ if (scoped.linked || !options.scope) return scoped;
25978
+ return createAndLinkProject(runner, cwd, base, {
25979
+ env: options.env,
25980
+ preferredScope: options.scope
25981
+ });
25982
+ }
25983
+ async function createAndLinkProject(runner, cwd, base, options) {
25964
25984
  let projectName = base;
25965
25985
  for (let attempt = 1; attempt <= MAX_NAME_ATTEMPTS; attempt++) {
25966
25986
  const candidate = versionedVercelProjectName(base, attempt);
@@ -25990,7 +26010,7 @@ ${add.stderr}`)) continue;
25990
26010
  fs37.rmSync(path48.join(cwd, ".vercel", "project.json"), { force: true });
25991
26011
  } catch {
25992
26012
  }
25993
- const link = await runVercel(
26013
+ let link = await runVercel(
25994
26014
  runner,
25995
26015
  withScope(["link", "--project", projectName, "--yes"], options.scope),
25996
26016
  {
@@ -25999,6 +26019,24 @@ ${add.stderr}`)) continue;
25999
26019
  env: options.env
26000
26020
  }
26001
26021
  );
26022
+ if (!link.success) {
26023
+ const fallbackScope = resolveMissingScopeChoice(
26024
+ `${link.stdout}
26025
+ ${link.stderr}`,
26026
+ options.scope ?? options.preferredScope
26027
+ );
26028
+ if (fallbackScope && fallbackScope !== options.scope) {
26029
+ link = await runVercel(
26030
+ runner,
26031
+ withScope(["link", "--project", projectName, "--yes"], fallbackScope),
26032
+ {
26033
+ cwd,
26034
+ mode: "capture",
26035
+ env: options.env
26036
+ }
26037
+ );
26038
+ }
26039
+ }
26002
26040
  return {
26003
26041
  name: projectName,
26004
26042
  linked: link.success,
@@ -26008,6 +26046,19 @@ ${add.stderr}`)) continue;
26008
26046
  function withScope(args, scope) {
26009
26047
  return scope ? [...args, "--scope", scope] : args;
26010
26048
  }
26049
+ function resolveMissingScopeChoice(output, preferred) {
26050
+ if (!/missing_scope/.test(output)) return void 0;
26051
+ const payload = parseVercelJson(output);
26052
+ if (payload?.reason !== "missing_scope") return void 0;
26053
+ const names = (payload.choices ?? []).map((choice) => choice.name).filter((name) => typeof name === "string" && name.length > 0);
26054
+ if (names.length === 0) return void 0;
26055
+ if (names.length === 1) return names[0];
26056
+ if (preferred) {
26057
+ const match = names.find((name) => name === preferred || name.startsWith(preferred));
26058
+ if (match) return match;
26059
+ }
26060
+ return names[0];
26061
+ }
26011
26062
  function readLinkedProjectId(cwd) {
26012
26063
  return readLinkedProjectJson(cwd)?.projectId;
26013
26064
  }
@@ -26309,14 +26360,36 @@ import * as p20 from "@clack/prompts";
26309
26360
  import pc7 from "picocolors";
26310
26361
  var PROVISION_TIMEOUT_MS2 = 18e4;
26311
26362
  var INTERACTIVE_PROVISION_TIMEOUT_MS2 = 6e5;
26363
+ var ACCEPT_TERMS_URL_PATTERN = /https:\/\/vercel\.com\/\S+\/integrations\/accept-terms\/\S+/i;
26364
+ var TERMS_ACCEPTED_PATTERN = /terms accepted/i;
26365
+ function findAcceptTermsUrl(line) {
26366
+ return ACCEPT_TERMS_URL_PATTERN.exec(line)?.[0];
26367
+ }
26312
26368
  async function provisionNeonInteractive(runner, cwd, options) {
26313
26369
  const quietSpinner = spinner2();
26314
26370
  quietSpinner.start("Creating your Neon database");
26371
+ let waitingOnTerms = false;
26315
26372
  const quiet = await runVercel(runner, neonAddArgs(options), {
26316
26373
  cwd,
26317
26374
  mode: "capture",
26318
26375
  timeoutMs: PROVISION_TIMEOUT_MS2,
26319
- env: options.env
26376
+ env: options.env,
26377
+ onOutputLine: (line, run) => {
26378
+ if (!waitingOnTerms) {
26379
+ const termsUrl = findAcceptTermsUrl(line);
26380
+ if (!termsUrl) return;
26381
+ waitingOnTerms = true;
26382
+ run.extendTimeout(INTERACTIVE_PROVISION_TIMEOUT_MS2);
26383
+ quietSpinner.clear();
26384
+ p20.log.info(`Please accept the Neon terms in your browser
26385
+ ${pc7.dim(termsUrl)}`);
26386
+ quietSpinner.start("Waiting for the terms to be accepted");
26387
+ return;
26388
+ }
26389
+ if (TERMS_ACCEPTED_PATTERN.test(line)) {
26390
+ quietSpinner.message("Creating your Neon database");
26391
+ }
26392
+ }
26320
26393
  });
26321
26394
  if (quiet.success) {
26322
26395
  quietSpinner.clear();