@vercel/build-utils 14.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @vercel/build-utils
2
2
 
3
+ ## 14.17.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 28a7ab7: Build top-level `daemons` when `VERCEL_ENABLE_DAEMONS_BOA=1`: `vercel build` builds the project as usual, pushes each daemon's Dockerfile image, and writes a Build Output API descriptor to `daemons/<name>/.vc-config.json`.
8
+
9
+ ### Patch Changes
10
+
11
+ - 28a7ab7: Prevent static deployments from accidentally publishing daemon source files. Both static builders skip nested daemon roots with a warning and reject publishing a directory that is itself a daemon root. Build scripts can still deliberately publish files through a separate output directory.
12
+
3
13
  ## 14.16.0
4
14
 
5
15
  ### Minor Changes
@@ -0,0 +1,10 @@
1
+ import type { Meta } from './types';
2
+ /**
3
+ * Prevents automatic static publishing from including daemon sources.
4
+ * A separate public directory is allowed inside a shared build context.
5
+ */
6
+ export declare function createDaemonStaticFileFilter({ context, publishPath, serviceName, }: {
7
+ context: Meta['daemonContext'];
8
+ publishPath: string;
9
+ serviceName?: string;
10
+ }): Promise<(sourcePath: string) => Promise<boolean>>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var daemon_static_publishing_exports = {};
20
+ __export(daemon_static_publishing_exports, {
21
+ createDaemonStaticFileFilter: () => createDaemonStaticFileFilter
22
+ });
23
+ module.exports = __toCommonJS(daemon_static_publishing_exports);
24
+ var import_promises = require("fs/promises");
25
+ var import_path = require("path");
26
+ var import_errors = require("./errors");
27
+ function contains(directory, file) {
28
+ const path = (0, import_path.relative)(directory, file);
29
+ return path === "" || !(0, import_path.isAbsolute)(path) && path !== ".." && !path.startsWith(`..${import_path.sep}`);
30
+ }
31
+ async function createDaemonStaticFileFilter({
32
+ context,
33
+ publishPath,
34
+ serviceName
35
+ }) {
36
+ if (!context || Object.keys(context.daemons).length === 0)
37
+ return async () => true;
38
+ const publish = (0, import_path.resolve)(publishPath);
39
+ const realPublish = await (0, import_promises.realpath)(publish);
40
+ const daemons = await Promise.all(
41
+ Object.entries(context.daemons).map(async ([name, daemon]) => {
42
+ const root = (0, import_path.resolve)(context.projectRoot, daemon.root);
43
+ const dockerfile = (0, import_path.resolve)(root, daemon.entrypoint);
44
+ const [realRoot, realDockerfile] = await Promise.all([
45
+ (0, import_promises.realpath)(root),
46
+ (0, import_promises.realpath)(dockerfile)
47
+ ]);
48
+ return { name, root, dockerfile, realRoot, realDockerfile };
49
+ })
50
+ );
51
+ for (const daemon of daemons) {
52
+ if (publish === daemon.root || realPublish === daemon.realRoot) {
53
+ const publisher = serviceName ? `Service "${serviceName}"` : "The app";
54
+ throw new import_errors.NowBuildError({
55
+ code: "INVALID_DAEMON_ROOT",
56
+ message: `Can't build daemon "${daemon.name}": ${publisher} publishes "${(0, import_path.relative)(context.projectRoot, publish) || "."}" as static files, but that is the daemon's root directory. Choose a separate output directory.`
57
+ });
58
+ }
59
+ }
60
+ let warned = false;
61
+ return async (sourcePath) => {
62
+ const source = (0, import_path.resolve)(sourcePath);
63
+ const realSource = await (0, import_promises.realpath)(source);
64
+ const excluded = daemons.some(
65
+ (daemon) => source === daemon.dockerfile || realSource === daemon.realDockerfile || // Directory symlinks can expose daemon sources the glob doesn't list.
66
+ contains(source, daemon.root) || contains(realSource, daemon.realRoot) || contains(daemon.root, source) && (!contains(daemon.root, publish) || !contains(publish, source)) || contains(daemon.realRoot, realSource) && (!contains(daemon.realRoot, realPublish) || !contains(realPublish, realSource))
67
+ );
68
+ if (excluded && !warned) {
69
+ console.warn(
70
+ "Warning: Skipping static files under daemon roots. To publish them intentionally, copy them into a separate build output directory."
71
+ );
72
+ warned = true;
73
+ }
74
+ return !excluded;
75
+ };
76
+ }
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ createDaemonStaticFileFilter
80
+ });
package/dist/daemons.d.ts CHANGED
@@ -21,6 +21,14 @@ export interface DaemonConfig {
21
21
  export declare const DAEMON_NAME_PATTERN = "^[a-z]+(?:(?:_|__|-+)[a-z]+)*$";
22
22
  /** Map of daemon name to daemon configuration for `vercel.json#daemons`. */
23
23
  export type Daemons = Record<string, DaemonConfig>;
24
+ /** Build Output API descriptor written to `daemons/<name>/.vc-config.json`. */
25
+ export interface DaemonOutput {
26
+ runtime: 'container';
27
+ image: string;
28
+ command?: string[];
29
+ replicas: DaemonReplicas;
30
+ resources?: DaemonResources;
31
+ }
24
32
  /**
25
33
  * Names of the daemons in `vercel.json#daemons`. Safe on unvalidated config,
26
34
  * where `daemons` may not be an object.
@@ -28,3 +36,10 @@ export type Daemons = Record<string, DaemonConfig>;
28
36
  export declare function getDaemonNames(config: {
29
37
  daemons?: unknown;
30
38
  } | null | undefined): string[];
39
+ /**
40
+ * The VCR repository a daemon's image is pushed to, under the project's
41
+ * namespace. Service names can't contain `.`, so it never matches a service's
42
+ * repository, which is named after the service. Repeated dashes collapse like
43
+ * they do for services, so `a-b` and `a--b` share one.
44
+ */
45
+ export declare function getDaemonImageRepository(name: string): string;
package/dist/daemons.js CHANGED
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var daemons_exports = {};
20
20
  __export(daemons_exports, {
21
21
  DAEMON_NAME_PATTERN: () => DAEMON_NAME_PATTERN,
22
+ getDaemonImageRepository: () => getDaemonImageRepository,
22
23
  getDaemonNames: () => getDaemonNames
23
24
  });
24
25
  module.exports = __toCommonJS(daemons_exports);
@@ -30,8 +31,12 @@ function getDaemonNames(config) {
30
31
  }
31
32
  return Object.keys(daemons);
32
33
  }
34
+ function getDaemonImageRepository(name) {
35
+ return `daemon.${name.replace(/-+/g, "-")}`;
36
+ }
33
37
  // Annotate the CommonJS export names for ESM import in node:
34
38
  0 && (module.exports = {
35
39
  DAEMON_NAME_PATTERN,
40
+ getDaemonImageRepository,
36
41
  getDaemonNames
37
42
  });
package/dist/index.d.ts CHANGED
@@ -23,6 +23,7 @@ import { hardLinkDir } from './hard-link-dir';
23
23
  import { getNodeExecPath } from './get-node-exec-path';
24
24
  import { validateNpmrc } from './validate-npmrc';
25
25
  export type { NodejsLambdaOptions, PrerenderInitialMetadata, PrerenderOnMiss };
26
+ export { createDaemonStaticFileFilter } from './daemon-static-publishing';
26
27
  export type { LambdaAffinity } from './lambda';
27
28
  export { FileBlob, FileFsRef, FileRef, Lambda, NodejsLambda, createLambda, Prerender, download, downloadFile, type DownloadedFiles, getWriteableDirectory, glob, type GlobOptions, rename, spawnAsync, getScriptName, installDependencies, runPackageJsonScript, execCommand, spawnCommand, walkParentDirs, getNodeBinPath, getNodeBinPaths, getNodeExecPath, getSupportedNodeVersion, isBunVersion, getSupportedBunVersion, getOrCreateBunBinary, detectPackageManager, runNpmInstall, type NpmInstallOutput, runBundleInstall, runPipInstall, type PipInstallResult, runShellScript, runCustomInstallCommand, resetCustomInstallCommandSet, getEnvForPackageManager, getNodeVersion, getPathForPackageManager, getLatestNodeVersion, getDiscontinuedNodeVersions, getSpawnOptions, getPlatformEnv, getPrefixedEnvVars, getServiceUrlEnvVars, getExperimentalServiceUrlEnvVars, streamToBuffer, streamToBufferChunks, debug, isSymbolicLink, isDirectory, isExternalSymlink, isExternalSymlinkTarget, getSymlinkTarget, findMatchingFunction, getLambdaOptionsFromFunction, sanitizeConsumerName, scanParentDirs, findPackageJson, getIgnoreFilter, cloneEnv, hardLinkDir, traverseUpDirectories, validateNpmrc, type CliType, };
28
29
  export { EdgeFunction } from './edge-function';
@@ -52,7 +53,7 @@ export { isNodeEntrypoint } from './node-entrypoint';
52
53
  export * from './service-path-utils';
53
54
  export * from './schedule-path-utils';
54
55
  export * from './schedules';
55
- export { DAEMON_NAME_PATTERN, getDaemonNames, type DaemonConfig, type DaemonReplicas, type DaemonResources, type Daemons, } from './daemons';
56
+ export { DAEMON_NAME_PATTERN, getDaemonImageRepository, getDaemonNames, type DaemonConfig, type DaemonOutput, type DaemonReplicas, type DaemonResources, type Daemons, } from './daemons';
56
57
  export { getEncryptedEnv, type EncryptedEnvFile, } from './process-serverless/get-encrypted-env-file';
57
58
  export { getLambdaEnvironment } from './process-serverless/get-lambda-environment';
58
59
  export { getLambdaPreloadScripts, type BytecodeCachingOptions, } from './process-serverless/get-lambda-preload-scripts';