@vercel/build-utils 14.15.0 → 14.17.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.
@@ -8,5 +8,22 @@ export type VercelJsonSchedule = Omit<Schedule, 'target'> & {
8
8
  entrypoint: string;
9
9
  };
10
10
  };
11
+ declare const FLAT_TARGET_KEYS: readonly ["path", "function", "topic", "entrypoint"];
12
+ type FlatTargetKey = (typeof FLAT_TARGET_KEYS)[number];
13
+ /**
14
+ * Name for a flat schedule without one: a hex hash of `type|ref|expression`,
15
+ * which always satisfies the schedule name pattern. Build Output omits these
16
+ * names (except for entrypoint schedules) and the API derives its own; using
17
+ * the same hash keeps `vercel dev` names the same as deployed ones.
18
+ */
19
+ export declare function defaultScheduleName(type: FlatTargetKey, ref: string, expression: string): string;
11
20
  export declare function parseScheduleDefinition(raw: unknown): VercelJsonSchedule;
12
- export declare function formatBuildOutputSchedule(schedule: Schedule): FlatBuildOutputSchedule;
21
+ /**
22
+ * Format a schedule for Build Output `config.json`. Pass `includeName: false`
23
+ * for a name derived by `parseScheduleDefinition`; the API derives the same
24
+ * name for a flat Build Output schedule without one.
25
+ */
26
+ export declare function formatBuildOutputSchedule(schedule: Schedule, { includeName }?: {
27
+ includeName?: boolean;
28
+ }): FlatBuildOutputSchedule;
29
+ export {};
package/dist/schedules.js CHANGED
@@ -18,11 +18,17 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var schedules_exports = {};
20
20
  __export(schedules_exports, {
21
+ defaultScheduleName: () => defaultScheduleName,
21
22
  formatBuildOutputSchedule: () => formatBuildOutputSchedule,
22
23
  parseScheduleDefinition: () => parseScheduleDefinition
23
24
  });
24
25
  module.exports = __toCommonJS(schedules_exports);
26
+ var import_crypto = require("crypto");
25
27
  const FLAT_TARGET_KEYS = ["path", "function", "topic", "entrypoint"];
28
+ const DEFAULT_NAME_HASH_LENGTH = 12;
29
+ function defaultScheduleName(type, ref, expression) {
30
+ return (0, import_crypto.createHash)("sha1").update(`${type}|${ref}|${expression}`).digest("hex").slice(0, DEFAULT_NAME_HASH_LENGTH);
31
+ }
26
32
  function isRecord(value) {
27
33
  return value != null && typeof value === "object" && !Array.isArray(value);
28
34
  }
@@ -87,7 +93,7 @@ function parseLegacySchedule(obj) {
87
93
  }
88
94
  function parseFlatSchedule(obj) {
89
95
  const { name, schedule, timezone, jitter } = obj;
90
- if (typeof name !== "string") {
96
+ if (name !== void 0 && typeof name !== "string") {
91
97
  throw new Error("Schedule `name` must be a string.");
92
98
  }
93
99
  if (typeof schedule !== "string") {
@@ -108,7 +114,7 @@ function parseFlatSchedule(obj) {
108
114
  [targetKey]: targetValue
109
115
  };
110
116
  return {
111
- name,
117
+ name: name ?? defaultScheduleName(targetKey, targetValue, schedule),
112
118
  expression: {
113
119
  cron: schedule,
114
120
  ...jitter !== void 0 ? { jitter } : {}
@@ -129,12 +135,12 @@ function parseScheduleDefinition(raw) {
129
135
  return parseFlatSchedule(raw);
130
136
  }
131
137
  throw new Error(
132
- "Schedule must use either the legacy shape (`expression`, `target`, `name`) or the flat shape (`schedule`, `name`, and one target field)."
138
+ "Schedule must use either the legacy shape (`expression`, `target`, `name`) or the flat shape (`schedule` and one target field)."
133
139
  );
134
140
  }
135
- function formatBuildOutputSchedule(schedule) {
141
+ function formatBuildOutputSchedule(schedule, { includeName = true } = {}) {
136
142
  return {
137
- name: schedule.name,
143
+ ...includeName ? { name: schedule.name } : {},
138
144
  schedule: schedule.expression.cron,
139
145
  ...schedule.target,
140
146
  ...schedule.timezone !== void 0 ? { timezone: schedule.timezone } : {},
@@ -143,6 +149,7 @@ function formatBuildOutputSchedule(schedule) {
143
149
  }
144
150
  // Annotate the CommonJS export names for ESM import in node:
145
151
  0 && (module.exports = {
152
+ defaultScheduleName,
146
153
  formatBuildOutputSchedule,
147
154
  parseScheduleDefinition
148
155
  });
@@ -8,6 +8,10 @@
8
8
  * Reserved internal namespace used by services routing/runtime plumbing.
9
9
  */
10
10
  export declare const INTERNAL_SERVICE_PREFIX = "/_svc";
11
+ /**
12
+ * Valid service names, which are also used as path segments.
13
+ */
14
+ export declare const SERVICE_NAME_PATTERN = "^[a-z]([a-z_-]*[a-z])?$";
11
15
  export declare function getInternalServiceFunctionPath(serviceName: string): string;
12
16
  export declare function getInternalServiceCronPathPrefix(serviceName: string): string;
13
17
  export declare function getInternalServiceCronPath(serviceName: string, entrypoint: string, handler?: string): string;
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var service_path_utils_exports = {};
20
20
  __export(service_path_utils_exports, {
21
21
  INTERNAL_SERVICE_PREFIX: () => INTERNAL_SERVICE_PREFIX,
22
+ SERVICE_NAME_PATTERN: () => SERVICE_NAME_PATTERN,
22
23
  getInternalServiceCronPath: () => getInternalServiceCronPath,
23
24
  getInternalServiceCronPathPrefix: () => getInternalServiceCronPathPrefix,
24
25
  getInternalServiceFunctionPath: () => getInternalServiceFunctionPath,
@@ -27,6 +28,7 @@ __export(service_path_utils_exports, {
27
28
  });
28
29
  module.exports = __toCommonJS(service_path_utils_exports);
29
30
  const INTERNAL_SERVICE_PREFIX = "/_svc";
31
+ const SERVICE_NAME_PATTERN = "^[a-z]([a-z_-]*[a-z])?$";
30
32
  function normalizeInternalServiceEntrypoint(entrypoint) {
31
33
  const normalized = entrypoint.replace(/\\/g, "/").replace(/^\/+/, "").replace(/\.[^/.]+$/, "");
32
34
  return normalized || "index";
@@ -51,6 +53,7 @@ function getInternalServiceWorkerPath(serviceName, entrypoint, handler = "worker
51
53
  // Annotate the CommonJS export names for ESM import in node:
52
54
  0 && (module.exports = {
53
55
  INTERNAL_SERVICE_PREFIX,
56
+ SERVICE_NAME_PATTERN,
54
57
  getInternalServiceCronPath,
55
58
  getInternalServiceCronPathPrefix,
56
59
  getInternalServiceFunctionPath,
package/dist/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { Lambda, LambdaAffinity, LambdaArchitecture } from './lambda';
5
5
  import type { Prerender } from './prerender';
6
6
  import type { EdgeFunction } from './edge-function';
7
7
  import type { ContainerImage } from './container-image';
8
+ import type { DaemonConfig, DaemonOutput } from './daemons';
8
9
  import type { Span } from './trace';
9
10
  import type { HasField, Route, Rewrite, Redirect, Header } from '@vercel/routing-utils';
10
11
  export interface Env {
@@ -73,10 +74,18 @@ export interface Config {
73
74
  buildpack?: string;
74
75
  /** Set when this build produces a function for schedule entrypoints. */
75
76
  scheduleFunction?: ScheduleFunctionBuildConfig;
77
+ /** Set when this build produces the named daemon. */
78
+ daemon?: DaemonConfig & {
79
+ name: string;
80
+ };
76
81
  [key: string]: unknown;
77
82
  }
78
83
  export type { HasField };
79
84
  export interface Meta {
85
+ daemonContext?: {
86
+ projectRoot: string;
87
+ daemons: Record<string, DaemonConfig>;
88
+ };
80
89
  isDev?: boolean;
81
90
  devCacheDir?: string;
82
91
  skipDownload?: boolean;
@@ -671,7 +680,8 @@ export interface Schedule {
671
680
  }
672
681
  /** Flat schedule shape in Build Output API `config.json`. */
673
682
  export type FlatBuildOutputSchedule = {
674
- name: string;
683
+ /** Defaults to a hash of the target and cron expression. */
684
+ name?: string;
675
685
  schedule: string;
676
686
  timezone?: string;
677
687
  jitter?: number;
@@ -826,6 +836,8 @@ export interface BuildResultV2Typical {
826
836
  */
827
837
  deploymentId?: string;
828
838
  crons?: Cron[];
839
+ /** Daemon descriptors, written to `daemons/<name>/.vc-config.json`. */
840
+ daemons?: Record<string, DaemonOutput>;
829
841
  }
830
842
  export type BuildResultVX = {
831
843
  resultVersion: 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "14.15.0",
3
+ "version": "14.17.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",