@wallavi/vercel-build 0.1.8 → 0.1.9

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/index.d.ts CHANGED
@@ -969,10 +969,6 @@ declare function ejecutarMedir(opciones: OpcionesMedir): number;
969
969
  declare function comandoMedir(args: string[], entorno: Entorno): number;
970
970
  declare const medir: typeof comandoMedir;
971
971
 
972
- declare const INTERVALO_POLL_DEPLOY_MS = 5000;
973
- declare const TIMEOUT_POLL_DEPLOY_MS = 600000;
974
- type Dormir = (ms: number) => void;
975
- declare const dormirSincrono: Dormir;
976
972
  declare const esquemaDeploymentPromocion: z.ZodEffects<z.ZodEffects<z.ZodObject<{
977
973
  id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
978
974
  uid: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -1346,6 +1342,11 @@ declare const esquemaListaDeploymentsPromocion: z.ZodObject<{
1346
1342
  }, z.ZodTypeAny, "passthrough">>, "many">;
1347
1343
  }, z.ZodTypeAny, "passthrough">>;
1348
1344
  type DeploymentPromocion = z.infer<typeof esquemaDeploymentPromocion>;
1345
+
1346
+ declare const INTERVALO_POLL_DEPLOY_MS = 5000;
1347
+ declare const TIMEOUT_POLL_DEPLOY_MS = 600000;
1348
+ type Dormir = (ms: number) => void;
1349
+ declare const dormirSincrono: Dormir;
1349
1350
  declare function limpiarIdOUrlDeploy(valor: string): string | null;
1350
1351
  declare function extraerIdOUrlDeploy(salida: string, error?: string): string | null;
1351
1352
  declare function extraerAliasProduccion(d: DeploymentPromocion): string | null;
package/dist/index.js CHANGED
@@ -751,15 +751,6 @@ function leerArgumentosDesplegar(args) {
751
751
  }
752
752
  };
753
753
  }
754
- var INTERVALO_POLL_DEPLOY_MS = 5e3;
755
- var TIMEOUT_POLL_DEPLOY_MS = 6e5;
756
- var REGEX_ANSI = new RegExp(
757
- `${String.fromCharCode(27)}\\[[0-9;]*[a-zA-Z]`,
758
- "g"
759
- );
760
- var dormirSincrono = (ms) => {
761
- if (ms > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
762
- };
763
754
  var esquemaDeploymentPromocion = zod.z.object({
764
755
  id: zod.z.string().min(1).nullable().optional(),
765
756
  uid: zod.z.string().min(1).nullable().optional(),
@@ -779,60 +770,13 @@ var esquemaDeploymentPromocion = zod.z.object({
779
770
  "el deployment debe incluir state o readyState"
780
771
  );
781
772
  var esquemaListaDeploymentsPromocion = zod.z.object({ deployments: zod.z.array(esquemaDeploymentPromocion) }).passthrough();
782
- function limpiarIdOUrlDeploy(valor) {
783
- return valor.replace(REGEX_ANSI, "").trim().replace(/^https?:\/\//i, "").replace(/[/?#].*$/, "").replace(/[.,;]+$/, "").trim() || null;
784
- }
785
- function extraerIdOUrlDeploy(salida, error = "") {
786
- const stdout = salida.replace(REGEX_ANSI, "");
787
- const texto = `${error}
788
- ${salida}`.replace(REGEX_ANSI, "");
789
- const reLinea = /^\s*(https?:\/\/[^\s\]"')>]+)/gim;
790
- const urlsStdout = Array.from(stdout.matchAll(reLinea), (m) => m[1]);
791
- const prod = /\bProduction\s*:\s*(https?:\/\/[^\s\]"')>]+)/i.exec(texto)?.[1];
792
- const alias = /\bAlias(?:ed)?\s*:\s*(https?:\/\/[^\s\]"')>]+)/i.exec(
793
- texto
794
- )?.[1];
795
- for (const candidata of [...urlsStdout, prod, alias]) {
796
- const limpio = candidata ? limpiarIdOUrlDeploy(candidata) : null;
797
- if (limpio && limpio !== "vercel.com") return limpio;
798
- }
799
- return /\b(dpl_[a-zA-Z0-9]+)\b/.exec(texto)?.[1] ?? null;
800
- }
801
- function normalizarUrlHttps(u) {
802
- const s = u.trim().replace(/[.,;/]+$/, "");
803
- return /^https?:\/\//i.test(s) ? s : `https://${s}`;
804
- }
805
- function esDominioVercelApp(u) {
806
- const h = (limpiarIdOUrlDeploy(u) ?? "").toLowerCase();
807
- return h === "vercel.app" || h.endsWith(".vercel.app");
808
- }
773
+ var err = (motivo) => ({ ok: false, motivo });
774
+ var esMotivoIdentidad = (motivo) => motivo.startsWith("el deploy ");
775
+ var sinDeployment = (ctx) => `no se encontr\xF3 deployment de producci\xF3n para el SHA ${ctx.sha}`;
809
776
  function listaAliases(d) {
810
777
  const crudos = Array.isArray(d.alias) ? d.alias : d.alias ? [d.alias] : [];
811
778
  return [...crudos, ...d.aliases ?? []].map((c) => c.trim()).filter(Boolean);
812
779
  }
813
- function extraerAliasProduccion(d) {
814
- const c = listaAliases(d);
815
- const u = c.find((x) => !esDominioVercelApp(x)) ?? c[0] ?? (d.url && !esDominioVercelApp(d.url) ? d.url : null);
816
- return u ? normalizarUrlHttps(u) : null;
817
- }
818
- function obtenerShaCommit(opc, ej) {
819
- const explicito = opc.sha?.trim() || opc.env?.VERCEL_GIT_COMMIT_SHA?.trim();
820
- if (explicito) return explicito;
821
- for (const dir of [opc.carpeta, opc.cwd]) {
822
- if (!dir) continue;
823
- const cwd = ubicarEnRepo(dir, ej)?.raiz ?? dir;
824
- const opcGit = { cwd, ...opc.env ? { env: opc.env } : {} };
825
- const r = ej("git", ["rev-parse", "HEAD"], opcGit);
826
- if (r.codigo === 0 && r.salida.trim() !== "") return r.salida.trim();
827
- }
828
- return null;
829
- }
830
- var err = (motivo) => ({ ok: false, motivo });
831
- var fallo = (motivo) => ({
832
- ok: false,
833
- codigo: 1,
834
- motivo
835
- });
836
780
  function llamarApiVercel(rutaQuery, ctx, metodo = "GET") {
837
781
  try {
838
782
  const auth = { Authorization: `Bearer ${ctx.token}` };
@@ -852,6 +796,7 @@ function obtenerShaDeployment(d) {
852
796
  }
853
797
  return "";
854
798
  }
799
+ var motivoShaAjeno = (id, sha, ctx) => `el deploy ${id} corresponde al SHA ${sha || "desconocido"} y no a ${ctx.sha}`;
855
800
  function validarIdentidadDeployment(d, ctx, fijar = false) {
856
801
  const id = d.id ?? d.uid;
857
802
  if (d.projectId !== ctx.projectId)
@@ -863,9 +808,7 @@ function validarIdentidadDeployment(d, ctx, fijar = false) {
863
808
  `el deploy ${id} no es de producci\xF3n (target=${JSON.stringify(d.target) ?? "ausente"}; esperado production)`
864
809
  );
865
810
  const sha = obtenerShaDeployment(d);
866
- return sha && sha === ctx.sha ? { ok: true, valor: d, id, fijar } : err(
867
- `el deploy ${id} corresponde al SHA ${sha || "desconocido"} y no a ${ctx.sha}`
868
- );
811
+ return sha && sha === ctx.sha ? { ok: true, valor: d, id, fijar } : err(motivoShaAjeno(id, sha, ctx));
869
812
  }
870
813
  function pedirDeploymentsV6(ruta, ctx) {
871
814
  const resp = llamarApiVercel(ruta, ctx, "GET");
@@ -881,9 +824,7 @@ function pedirDeploymentsV6(ruta, ctx) {
881
824
  if (raw.length === 0 || deployments.length > 0)
882
825
  return { ok: true, deployments };
883
826
  }
884
- return err(
885
- `no se encontr\xF3 deployment de producci\xF3n para el SHA ${ctx.sha}`
886
- );
827
+ return err(sinDeployment(ctx));
887
828
  } catch (e) {
888
829
  return err(`JSON inv\xE1lido en GET ${ruta} (${e.message})`);
889
830
  }
@@ -917,31 +858,102 @@ function hidratarCandidatoV6(d, ctx) {
917
858
  valor.readySubstate = v.readySubstate ?? d.readySubstate;
918
859
  return { ok: true, id: detalle.id, fijar: true, valor };
919
860
  }
920
- return detalle.motivo.startsWith("el deploy ") ? detalle : base;
861
+ return esMotivoIdentidad(detalle.motivo) ? detalle : base;
862
+ }
863
+ function resolverCandidatos(xs, ctx, vacio) {
864
+ const propios = xs.filter((x) => obtenerShaDeployment(x) === ctx.sha);
865
+ const sinSha = xs.filter((x) => !obtenerShaDeployment(x));
866
+ let motivo = vacio;
867
+ for (const d of [...propios, ...sinSha]) {
868
+ const r = hidratarCandidatoV6(d, ctx);
869
+ if (r.ok) return r;
870
+ if (esMotivoIdentidad(r.motivo) || !esMotivoIdentidad(motivo))
871
+ motivo = r.motivo;
872
+ }
873
+ return err(motivo);
921
874
  }
922
875
  function resolverDeployment(idOrUrl, ctx) {
923
876
  const qBase = `${ctx.qTeam}&projectId=${encodeURIComponent(ctx.projectId)}&target=production`;
924
- const elegir = (xs) => xs.find((x) => obtenerShaDeployment(x) === ctx.sha) ?? xs.find((x) => !obtenerShaDeployment(x));
925
877
  const respaldoV6 = () => {
926
878
  const r = pedirDeploymentsV6(`/v6/deployments?${qBase}`, ctx);
927
- if (!r.ok) return r;
928
- const d = elegir(r.deployments);
929
- return d ? hidratarCandidatoV6(d, ctx) : err(`no se encontr\xF3 deployment de producci\xF3n para el SHA ${ctx.sha}`);
879
+ return r.ok ? resolverCandidatos(r.deployments, ctx, sinDeployment(ctx)) : r;
930
880
  };
931
881
  if (idOrUrl) {
932
882
  const c = consultarDeploymentV13(idOrUrl, ctx);
933
883
  if (c.ok || idOrUrl.startsWith("dpl_")) return c;
934
884
  const respaldo = respaldoV6();
935
885
  if (respaldo.ok) return respaldo;
936
- return c.motivo.startsWith("el deploy ") || !respaldo.motivo.startsWith("el deploy ") ? c : respaldo;
886
+ return esMotivoIdentidad(c.motivo) || !esMotivoIdentidad(respaldo.motivo) ? c : respaldo;
937
887
  }
938
888
  const qSha = `/v6/deployments?${qBase}&sha=${encodeURIComponent(ctx.sha)}`;
939
889
  const lista = pedirDeploymentsV6(qSha, ctx);
940
890
  if (!lista.ok) return lista;
941
891
  if (lista.deployments.length === 0) return respaldoV6();
942
- const actual = elegir(lista.deployments) ?? lista.deployments[0];
943
- return hidratarCandidatoV6(actual, ctx);
892
+ const primero = lista.deployments[0];
893
+ const shaPrimero = obtenerShaDeployment(primero);
894
+ const vacio = shaPrimero && shaPrimero !== ctx.sha ? motivoShaAjeno(primero.id ?? primero.uid, shaPrimero, ctx) : sinDeployment(ctx);
895
+ return resolverCandidatos(lista.deployments, ctx, vacio);
896
+ }
897
+
898
+ // src/comandos/promover.ts
899
+ var INTERVALO_POLL_DEPLOY_MS = 5e3;
900
+ var TIMEOUT_POLL_DEPLOY_MS = 6e5;
901
+ var REGEX_ANSI = new RegExp(
902
+ `${String.fromCharCode(27)}\\[[0-9;]*[a-zA-Z]`,
903
+ "g"
904
+ );
905
+ var dormirSincrono = (ms) => {
906
+ if (ms > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
907
+ };
908
+ function limpiarIdOUrlDeploy(valor) {
909
+ return valor.replace(REGEX_ANSI, "").trim().replace(/^https?:\/\//i, "").replace(/[/?#].*$/, "").replace(/[.,;]+$/, "").trim() || null;
910
+ }
911
+ function extraerIdOUrlDeploy(salida, error = "") {
912
+ const stdout = salida.replace(REGEX_ANSI, "");
913
+ const texto = `${error}
914
+ ${salida}`.replace(REGEX_ANSI, "");
915
+ const reLinea = /^\s*(https?:\/\/[^\s\]"')>]+)/gim;
916
+ const urlsStdout = Array.from(stdout.matchAll(reLinea), (m) => m[1]);
917
+ const prod = /\bProduction\s*:\s*(https?:\/\/[^\s\]"')>]+)/i.exec(texto)?.[1];
918
+ const alias = /\bAlias(?:ed)?\s*:\s*(https?:\/\/[^\s\]"')>]+)/i.exec(
919
+ texto
920
+ )?.[1];
921
+ for (const candidata of [...urlsStdout, prod, alias]) {
922
+ const limpio = candidata ? limpiarIdOUrlDeploy(candidata) : null;
923
+ if (limpio && limpio !== "vercel.com") return limpio;
924
+ }
925
+ return /\b(dpl_[a-zA-Z0-9]+)\b/.exec(texto)?.[1] ?? null;
944
926
  }
927
+ function normalizarUrlHttps(u) {
928
+ const s = u.trim().replace(/[.,;/]+$/, "");
929
+ return /^https?:\/\//i.test(s) ? s : `https://${s}`;
930
+ }
931
+ function esDominioVercelApp(u) {
932
+ const h = (limpiarIdOUrlDeploy(u) ?? "").toLowerCase();
933
+ return h === "vercel.app" || h.endsWith(".vercel.app");
934
+ }
935
+ function extraerAliasProduccion(d) {
936
+ const c = listaAliases(d);
937
+ const u = c.find((x) => !esDominioVercelApp(x)) ?? c[0] ?? (d.url && !esDominioVercelApp(d.url) ? d.url : null);
938
+ return u ? normalizarUrlHttps(u) : null;
939
+ }
940
+ function obtenerShaCommit(opc, ej) {
941
+ const explicito = opc.sha?.trim() || opc.env?.VERCEL_GIT_COMMIT_SHA?.trim();
942
+ if (explicito) return explicito;
943
+ for (const dir of [opc.carpeta, opc.cwd]) {
944
+ if (!dir) continue;
945
+ const cwd = ubicarEnRepo(dir, ej)?.raiz ?? dir;
946
+ const opcGit = { cwd, ...opc.env ? { env: opc.env } : {} };
947
+ const r = ej("git", ["rev-parse", "HEAD"], opcGit);
948
+ if (r.codigo === 0 && r.salida.trim() !== "") return r.salida.trim();
949
+ }
950
+ return null;
951
+ }
952
+ var fallo = (motivo) => ({
953
+ ok: false,
954
+ codigo: 1,
955
+ motivo
956
+ });
945
957
  function esperarYPromoverDeploy(opc) {
946
958
  const ej = opc.ejecutar ?? ejecutar;
947
959
  const solicitar = opc.solicitar ?? solicitarVercel;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallavi/vercel-build",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "private": false,
5
5
  "description": "Detección de cambios y despliegue compartidos para los proyectos de Vercel del monorepo",
6
6
  "license": "MIT",