@wallavi/vercel-build 0.1.2 → 0.1.3

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
@@ -92,6 +92,19 @@ declare function ejecutarIgnorar(opciones: OpcionesIgnorar): number;
92
92
  declare function comandoIgnorar(args: string[], entorno: Entorno): number;
93
93
  declare const ignorar: typeof comandoIgnorar;
94
94
 
95
+ interface ArgumentosDesplegar {
96
+ carpeta: string;
97
+ antes?: string;
98
+ urlSalud?: string;
99
+ }
100
+ declare function leerArgumentosDesplegar(args: readonly string[]): {
101
+ ok: true;
102
+ valor: ArgumentosDesplegar;
103
+ } | {
104
+ ok: false;
105
+ motivo: string;
106
+ };
107
+
95
108
  declare const API_VERCEL_URL = "https://api.vercel.com";
96
109
  declare const LIMITE_PAGINA_VERCEL = 100;
97
110
  declare const MAX_PAGINAS_VERCEL = 1000;
@@ -1344,18 +1357,6 @@ declare const VARIABLES_VERCEL: readonly ["VERCEL_TOKEN", "VERCEL_ORG_ID", "VERC
1344
1357
  declare const PASOS_VERCEL: readonly [readonly ["pull", "--yes", "--environment=production"], readonly ["build", "--prod"], readonly ["deploy", "--prebuilt", "--prod"]];
1345
1358
  declare const PASO_DEPLOY_REMOTO: readonly ["deploy", "--prod", "--yes", "--no-wait"];
1346
1359
  declare const ARCHIVO_ENV_PRODUCCION: string;
1347
- interface ArgumentosDesplegar {
1348
- carpeta: string;
1349
- antes?: string;
1350
- urlSalud?: string;
1351
- }
1352
- declare function leerArgumentosDesplegar(args: readonly string[]): {
1353
- ok: true;
1354
- valor: ArgumentosDesplegar;
1355
- } | {
1356
- ok: false;
1357
- motivo: string;
1358
- };
1359
1360
  declare function tieneVariablesSensibles(carpeta: string): boolean;
1360
1361
  declare function extraerUrlSalud(salida: string, error?: string): string | null;
1361
1362
  interface OpcionesDesplegar extends Entorno {
package/dist/index.js CHANGED
@@ -702,6 +702,55 @@ function evaluarCambios(opciones) {
702
702
  motivo: `turbo: ${nombre} sin paquetes afectados`
703
703
  };
704
704
  }
705
+
706
+ // src/comandos/desplegar-argumentos.ts
707
+ function leerArgumentosDesplegar(args) {
708
+ let carpeta;
709
+ let antes;
710
+ let urlSalud;
711
+ for (let i = 0; i < args.length; i++) {
712
+ const arg = args[i] ?? "";
713
+ if (arg === "--carpeta" || arg.startsWith("--carpeta=")) {
714
+ const valor = arg === "--carpeta" ? args[++i] : arg.slice("--carpeta=".length);
715
+ if (!valor || valor.trim() === "" || valor.startsWith("-")) {
716
+ return { ok: false, motivo: "falta el valor de --carpeta <ruta>" };
717
+ }
718
+ carpeta = valor.trim();
719
+ continue;
720
+ }
721
+ if (arg === "--antes" || arg.startsWith("--antes=")) {
722
+ const valor = arg === "--antes" ? args[++i] : arg.slice("--antes=".length);
723
+ if (!valor || valor.trim() === "" || valor.startsWith("-")) {
724
+ return { ok: false, motivo: "falta el valor de --antes <sha>" };
725
+ }
726
+ antes = valor.trim();
727
+ continue;
728
+ }
729
+ if (arg === "--url-salud" || arg.startsWith("--url-salud=")) {
730
+ const valor = arg === "--url-salud" ? args[++i] : arg.slice("--url-salud=".length);
731
+ if (!valor || valor.trim() === "" || valor.startsWith("-")) {
732
+ return { ok: false, motivo: "falta el valor de --url-salud <url>" };
733
+ }
734
+ urlSalud = valor.trim();
735
+ continue;
736
+ }
737
+ return { ok: false, motivo: `argumento no reconocido: ${arg}` };
738
+ }
739
+ if (!carpeta) {
740
+ return {
741
+ ok: false,
742
+ motivo: "falta la opci\xF3n obligatoria --carpeta <ruta>"
743
+ };
744
+ }
745
+ return {
746
+ ok: true,
747
+ valor: {
748
+ carpeta,
749
+ ...antes !== void 0 ? { antes } : {},
750
+ ...urlSalud !== void 0 ? { urlSalud } : {}
751
+ }
752
+ };
753
+ }
705
754
  var INTERVALO_POLL_DEPLOY_MS = 5e3;
706
755
  var TIMEOUT_POLL_DEPLOY_MS = 6e5;
707
756
  var REGEX_ANSI = new RegExp(
@@ -988,53 +1037,6 @@ var REGEX_ANSI2 = new RegExp(
988
1037
  `${String.fromCharCode(27)}\\[[0-9;]*[a-zA-Z]`,
989
1038
  "g"
990
1039
  );
991
- function leerArgumentosDesplegar(args) {
992
- let carpeta;
993
- let antes;
994
- let urlSalud;
995
- for (let i = 0; i < args.length; i++) {
996
- const arg = args[i] ?? "";
997
- if (arg === "--carpeta" || arg.startsWith("--carpeta=")) {
998
- const valor = arg === "--carpeta" ? args[++i] : arg.slice("--carpeta=".length);
999
- if (!valor || valor.trim() === "" || valor.startsWith("-")) {
1000
- return { ok: false, motivo: "falta el valor de --carpeta <ruta>" };
1001
- }
1002
- carpeta = valor.trim();
1003
- continue;
1004
- }
1005
- if (arg === "--antes" || arg.startsWith("--antes=")) {
1006
- const valor = arg === "--antes" ? args[++i] : arg.slice("--antes=".length);
1007
- if (!valor || valor.trim() === "" || valor.startsWith("-")) {
1008
- return { ok: false, motivo: "falta el valor de --antes <sha>" };
1009
- }
1010
- antes = valor.trim();
1011
- continue;
1012
- }
1013
- if (arg === "--url-salud" || arg.startsWith("--url-salud=")) {
1014
- const valor = arg === "--url-salud" ? args[++i] : arg.slice("--url-salud=".length);
1015
- if (!valor || valor.trim() === "" || valor.startsWith("-")) {
1016
- return { ok: false, motivo: "falta el valor de --url-salud <url>" };
1017
- }
1018
- urlSalud = valor.trim();
1019
- continue;
1020
- }
1021
- return { ok: false, motivo: `argumento no reconocido: ${arg}` };
1022
- }
1023
- if (!carpeta) {
1024
- return {
1025
- ok: false,
1026
- motivo: "falta la opci\xF3n obligatoria --carpeta <ruta>"
1027
- };
1028
- }
1029
- return {
1030
- ok: true,
1031
- valor: {
1032
- carpeta,
1033
- ...antes !== void 0 ? { antes } : {},
1034
- ...urlSalud !== void 0 ? { urlSalud } : {}
1035
- }
1036
- };
1037
- }
1038
1040
  function tieneVariablesSensibles(carpeta) {
1039
1041
  const archivo = path3__namespace.join(carpeta, ARCHIVO_ENV_PRODUCCION);
1040
1042
  return fs.existsSync(archivo) && fs.statSync(archivo).isFile() && fs.readFileSync(archivo, "utf8").includes(MARCADOR_SENSITIVE);
@@ -1100,6 +1102,26 @@ function ejecutarDesplegar(opciones) {
1100
1102
  opciones.error(`wallavi-vercel desplegar: faltan ${faltan.join(", ")}`);
1101
1103
  return 2;
1102
1104
  }
1105
+ const head = ej("git", ["rev-parse", "HEAD"], { cwd: rutaCarpeta });
1106
+ const sha = head.salida.trim();
1107
+ if (head.codigo !== 0 || !/^[0-9a-f]{40}$/.test(sha)) {
1108
+ opciones.error("wallavi-vercel desplegar: no se pudo verificar HEAD");
1109
+ return 1;
1110
+ }
1111
+ for (const nombre of ["WORKFLOW_RUN_HEAD_SHA", "VERCEL_GIT_COMMIT_SHA"]) {
1112
+ const esperado = opciones.env[nombre]?.trim();
1113
+ if (esperado && esperado !== sha) {
1114
+ opciones.error(
1115
+ `wallavi-vercel desplegar: HEAD no coincide con el SHA de ${nombre}`
1116
+ );
1117
+ return 1;
1118
+ }
1119
+ }
1120
+ const identidad = {
1121
+ sha,
1122
+ proyecto: opciones.env.VERCEL_PROJECT_ID.trim(),
1123
+ carpeta: opciones.carpeta
1124
+ };
1103
1125
  const evaluacion = evaluar({
1104
1126
  carpeta: rutaCarpeta,
1105
1127
  ...opciones.antes !== void 0 ? { antes: opciones.antes } : {},
@@ -1110,6 +1132,13 @@ function ejecutarDesplegar(opciones) {
1110
1132
  opciones.salida(
1111
1133
  `wallavi-vercel desplegar: sin cambios (${evaluacion.motivo})`
1112
1134
  );
1135
+ opciones.salida(
1136
+ JSON.stringify({
1137
+ resultado: "omitido",
1138
+ motivo: "sin-cambios",
1139
+ ...identidad
1140
+ })
1141
+ );
1113
1142
  return 0;
1114
1143
  }
1115
1144
  const rPull = correrPasoVercel(ej, PASOS_VERCEL[0], rutaCarpeta, opciones);
@@ -1142,8 +1171,10 @@ function ejecutarDesplegar(opciones) {
1142
1171
  }
1143
1172
  let aliasPromovido = null;
1144
1173
  let urlDeployPromovido = null;
1145
- if (haySensibles) {
1174
+ let deploymentId;
1175
+ {
1146
1176
  const promocion = esperarYPromoverDeploy({
1177
+ sha,
1147
1178
  cwd: opciones.cwd,
1148
1179
  carpeta: rutaCarpeta,
1149
1180
  env: opciones.env,
@@ -1168,6 +1199,7 @@ function ejecutarDesplegar(opciones) {
1168
1199
  }
1169
1200
  aliasPromovido = promocion.alias;
1170
1201
  urlDeployPromovido = promocion.url;
1202
+ deploymentId = promocion.deploymentId;
1171
1203
  }
1172
1204
  const urlSalud = opciones.urlSalud?.trim() || opciones.env.VERCEL_HEALTHCHECK_URL?.trim() || aliasPromovido || extraerUrlSalud(ultimoDeploy.salida, ultimoDeploy.error) || urlDeployPromovido;
1173
1205
  if (!urlSalud) {
@@ -1203,6 +1235,14 @@ function ejecutarDesplegar(opciones) {
1203
1235
  opciones.salida(
1204
1236
  `wallavi-vercel desplegar: desplegado (${evaluacion.motivo})`
1205
1237
  );
1238
+ opciones.salida(
1239
+ JSON.stringify({
1240
+ resultado: "desplegado",
1241
+ ...identidad,
1242
+ deploymentId,
1243
+ urlSalud
1244
+ })
1245
+ );
1206
1246
  return 0;
1207
1247
  }
1208
1248
  function comandoDesplegar(args, entorno) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wallavi/vercel-build",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
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",
@@ -24,8 +24,8 @@
24
24
  "tsup": "^8.3.5",
25
25
  "tsx": "^4.19.2",
26
26
  "typescript": "^5.7.3",
27
- "@wallavi/eslint-config": "0.0.1",
28
- "@wallavi/typescript-config": "0.0.1"
27
+ "@wallavi/typescript-config": "0.0.1",
28
+ "@wallavi/eslint-config": "0.0.1"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsup",