@vercel/backends 0.5.0 → 0.7.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/dist/index.d.mts +8 -2
- package/dist/index.mjs +47 -16
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import * as _vercel_build_utils0 from "@vercel/build-utils";
|
|
2
|
-
import { BuildOptions, BuildV2, Files, PrepareCache, Span } from "@vercel/build-utils";
|
|
2
|
+
import { BuildOptions, BuildV2, DetectEntrypointFn, Files, PrepareCache, Span } from "@vercel/build-utils";
|
|
3
3
|
import { ParseArgsConfig } from "node:util";
|
|
4
4
|
|
|
5
5
|
//#region src/find-entrypoint.d.ts
|
|
6
6
|
declare const findEntrypoint: (cwd: string) => Promise<string | undefined>;
|
|
7
7
|
declare const findEntrypointOrThrow: (cwd: string) => Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Normalized entrypoint detector for Node services. Wraps {@link findEntrypoint}
|
|
10
|
+
* and returns the result in the shared {@link DetectedEntrypoint} shape consumed
|
|
11
|
+
* by services auto-detection.
|
|
12
|
+
*/
|
|
13
|
+
declare const detectEntrypoint: DetectEntrypointFn;
|
|
8
14
|
//#endregion
|
|
9
15
|
//#region src/cervel/types.d.ts
|
|
10
16
|
/**
|
|
@@ -104,4 +110,4 @@ declare const version = 2;
|
|
|
104
110
|
declare const build: BuildV2;
|
|
105
111
|
declare const prepareCache: PrepareCache;
|
|
106
112
|
//#endregion
|
|
107
|
-
export { type CervelBuildOptions, type CervelServeOptions, type PathOptions, build, build$1 as cervelBuild, serve as cervelServe, diagnostics, findEntrypoint, findEntrypointOrThrow, getBuildSummary, introspectApp, nodeFileTrace, prepareCache, srvxOptions, version };
|
|
113
|
+
export { type CervelBuildOptions, type CervelServeOptions, type PathOptions, build, build$1 as cervelBuild, serve as cervelServe, detectEntrypoint, diagnostics, findEntrypoint, findEntrypointOrThrow, getBuildSummary, introspectApp, nodeFileTrace, prepareCache, srvxOptions, version };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { builtinModules, createRequire } from "node:module";
|
|
2
2
|
import { createWriteStream, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
4
|
-
import { delimiter, dirname as dirname$1, join as join$1 } from "path";
|
|
3
|
+
import { basename, delimiter, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { delimiter as delimiter$1, dirname as dirname$1, join as join$1 } from "path";
|
|
5
5
|
import { FileBlob, FileFsRef, NodejsLambda, Span, createDiagnostics, debug, defaultCachePathGlob, download, execCommand, generateProjectManifest, getEnvForPackageManager, getInternalServiceCronPath, getLambdaOptionsFromFunction, getNodeBinPaths, getNodeVersion, getReportedServiceType, glob, isBackendFramework, isBunVersion, isExperimentalBackendsWithoutIntrospectionEnabled, isScheduleTriggeredService, runNpmInstall, runPackageJsonScript, scanParentDirs } from "@vercel/build-utils";
|
|
6
6
|
import { lstat, readFile, rm, stat } from "node:fs/promises";
|
|
7
7
|
import { build as build$2 } from "rolldown";
|
|
@@ -53,11 +53,11 @@ async function maybeExecBuildCommand(args, { spawnEnv }) {
|
|
|
53
53
|
const nodeBinPath = getNodeBinPaths({
|
|
54
54
|
base: args.repoRootPath || args.workPath,
|
|
55
55
|
start: args.workPath
|
|
56
|
-
}).join(delimiter);
|
|
56
|
+
}).join(delimiter$1);
|
|
57
57
|
return execCommand(projectBuildCommand, {
|
|
58
58
|
env: {
|
|
59
59
|
...spawnEnv,
|
|
60
|
-
PATH: `${nodeBinPath}${delimiter}${spawnEnv?.PATH || process.env.PATH}`
|
|
60
|
+
PATH: `${nodeBinPath}${delimiter$1}${spawnEnv?.PATH || process.env.PATH}`
|
|
61
61
|
},
|
|
62
62
|
cwd: args.workPath
|
|
63
63
|
});
|
|
@@ -582,6 +582,19 @@ const findEntrypointOrThrow = async (cwd) => {
|
|
|
582
582
|
if (!entrypoint) throw new Error(`No entrypoint found in "${cwd}". Set package.json "main" to a server file, or add one of: ${entrypoints.join(", ")}`);
|
|
583
583
|
return entrypoint;
|
|
584
584
|
};
|
|
585
|
+
/**
|
|
586
|
+
* Normalized entrypoint detector for Node services. Wraps {@link findEntrypoint}
|
|
587
|
+
* and returns the result in the shared {@link DetectedEntrypoint} shape consumed
|
|
588
|
+
* by services auto-detection.
|
|
589
|
+
*/
|
|
590
|
+
const detectEntrypoint = async ({ workPath }) => {
|
|
591
|
+
const file = await findEntrypoint(workPath);
|
|
592
|
+
if (!file) return null;
|
|
593
|
+
return {
|
|
594
|
+
kind: "file",
|
|
595
|
+
entrypoint: file
|
|
596
|
+
};
|
|
597
|
+
};
|
|
585
598
|
|
|
586
599
|
//#endregion
|
|
587
600
|
//#region src/cervel/index.ts
|
|
@@ -923,10 +936,10 @@ async function resolveShimFormat(args) {
|
|
|
923
936
|
//#endregion
|
|
924
937
|
//#region src/crons.ts
|
|
925
938
|
const DYNAMIC_SCHEDULE = "<dynamic>";
|
|
926
|
-
/** Build the JSON route table embedded in
|
|
939
|
+
/** Build the JSON route table embedded in the dispatcher shim. */
|
|
927
940
|
function buildCronRouteTable(crons) {
|
|
928
941
|
const table = {};
|
|
929
|
-
for (const cron of crons) table[cron.path] =
|
|
942
|
+
for (const cron of crons) table[cron.path] = cron.exportName;
|
|
930
943
|
return table;
|
|
931
944
|
}
|
|
932
945
|
/**
|
|
@@ -935,13 +948,8 @@ function buildCronRouteTable(crons) {
|
|
|
935
948
|
* Mirrors `packages/python/src/crons.ts` for static schedules. Returns
|
|
936
949
|
* `undefined` when the service is not schedule-triggered. Throws on
|
|
937
950
|
* `<dynamic>` schedules — that path is reserved for a follow-up.
|
|
938
|
-
*
|
|
939
|
-
* v1 always invokes the user module's default export, so this returns
|
|
940
|
-
* plain `Cron[]` (no handler-name field). When `handlerFunction` or
|
|
941
|
-
* `<dynamic>` support lands, this will need to grow a per-path handler
|
|
942
|
-
* name back.
|
|
943
951
|
*/
|
|
944
|
-
function getServiceCrons(opts) {
|
|
952
|
+
async function getServiceCrons(opts) {
|
|
945
953
|
const { service, entrypoint } = opts;
|
|
946
954
|
if (!service || !isScheduleTriggeredService(service)) return;
|
|
947
955
|
if (!service.name || typeof service.schedule !== "string") return;
|
|
@@ -949,7 +957,8 @@ function getServiceCrons(opts) {
|
|
|
949
957
|
if (service.schedule === DYNAMIC_SCHEDULE) throw new Error("Dynamic cron schedules (\"<dynamic>\") are not yet supported for JavaScript/TypeScript services. Use a static cron expression in vercel.json.");
|
|
950
958
|
return [{
|
|
951
959
|
path: getInternalServiceCronPath(service.name, entrypoint, "cron"),
|
|
952
|
-
schedule: service.schedule
|
|
960
|
+
schedule: service.schedule,
|
|
961
|
+
exportName: "default"
|
|
953
962
|
}];
|
|
954
963
|
}
|
|
955
964
|
|
|
@@ -1664,12 +1673,31 @@ const build = async (args) => {
|
|
|
1664
1673
|
const entrypoint = explicit && existsSync(join(args.workPath, explicit)) ? explicit : await findEntrypointOrThrow(args.workPath);
|
|
1665
1674
|
debug("Entrypoint", entrypoint);
|
|
1666
1675
|
args.entrypoint = entrypoint;
|
|
1667
|
-
const cronEntries = getServiceCrons({
|
|
1676
|
+
const cronEntries = await getServiceCrons({
|
|
1668
1677
|
service: args.service,
|
|
1669
1678
|
entrypoint
|
|
1670
1679
|
});
|
|
1671
1680
|
const isCronService = cronEntries !== void 0;
|
|
1672
1681
|
const userBuildResult = await maybeDoBuildCommand(args, downloadResult);
|
|
1682
|
+
const preDeployCommand = args.config.preDeployCommand;
|
|
1683
|
+
if (args.registerPreDeploy && typeof preDeployCommand === "string") {
|
|
1684
|
+
const nodeBinPath = getNodeBinPaths({
|
|
1685
|
+
base: args.repoRootPath || args.workPath,
|
|
1686
|
+
start: args.workPath
|
|
1687
|
+
}).join(delimiter);
|
|
1688
|
+
const capturedEnv = {
|
|
1689
|
+
...downloadResult.spawnEnv,
|
|
1690
|
+
PATH: `${nodeBinPath}${delimiter}${downloadResult.spawnEnv?.PATH || process.env.PATH}`
|
|
1691
|
+
};
|
|
1692
|
+
const capturedCwd = args.workPath;
|
|
1693
|
+
args.registerPreDeploy(async () => {
|
|
1694
|
+
debug(`Running pre-deploy command: \`${preDeployCommand}\``);
|
|
1695
|
+
await execCommand(preDeployCommand, {
|
|
1696
|
+
env: capturedEnv,
|
|
1697
|
+
cwd: capturedCwd
|
|
1698
|
+
});
|
|
1699
|
+
});
|
|
1700
|
+
}
|
|
1673
1701
|
const functionConfig = args.config.functions?.[entrypoint];
|
|
1674
1702
|
if (functionConfig) {
|
|
1675
1703
|
args.config.includeFiles = [...normalizeArray(args.config.includeFiles), ...normalizeArray(functionConfig.includeFiles)];
|
|
@@ -1801,7 +1829,10 @@ const build = async (args) => {
|
|
|
1801
1829
|
return {
|
|
1802
1830
|
routes,
|
|
1803
1831
|
output,
|
|
1804
|
-
...cronEntries ? { crons: cronEntries }
|
|
1832
|
+
...cronEntries ? { crons: cronEntries.map(({ path, schedule }) => ({
|
|
1833
|
+
path,
|
|
1834
|
+
schedule
|
|
1835
|
+
})) } : {}
|
|
1805
1836
|
};
|
|
1806
1837
|
});
|
|
1807
1838
|
};
|
|
@@ -1838,4 +1869,4 @@ const escapeForRegex = (value) => value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
|
|
|
1838
1869
|
const toRegexSource = (value) => escapeForRegex(value).replaceAll("/", "\\/");
|
|
1839
1870
|
|
|
1840
1871
|
//#endregion
|
|
1841
|
-
export { build, build$1 as cervelBuild, serve as cervelServe, diagnostics, findEntrypoint, findEntrypointOrThrow, getBuildSummary, introspectApp, nodeFileTrace, prepareCache, srvxOptions, version };
|
|
1872
|
+
export { build, build$1 as cervelBuild, serve as cervelServe, detectEntrypoint, diagnostics, findEntrypoint, findEntrypointOrThrow, getBuildSummary, introspectApp, nodeFileTrace, prepareCache, srvxOptions, version };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/backends",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"homepage": "https://vercel.com/docs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"srvx": "0.8.9",
|
|
36
36
|
"tsx": "4.21.0",
|
|
37
37
|
"zod": "3.22.4",
|
|
38
|
-
"@vercel/build-utils": "13.
|
|
38
|
+
"@vercel/build-utils": "13.25.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/express": "5.0.3",
|