@gigadrive/network-config 1.0.0 → 1.1.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/build-output-v3/index.d.ts +120 -0
- package/dist/build-output-v3/parse.d.ts +17 -0
- package/dist/build-output-v3/parse.js +1 -1
- package/dist/build-output-v3/parse.js.map +3 -3
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/normalized-config.d.ts +125 -0
- package/dist/parse-raw-config.d.ts +1 -0
- package/dist/regions.d.ts +4 -0
- package/dist/runtime.d.ts +4 -0
- package/dist/v4/index.d.ts +162 -0
- package/dist/v4/parse.d.ts +10 -0
- package/dist/v4/parse.js +1 -1
- package/dist/v4/parse.js.map +3 -3
- package/dist/v4/schema.json +334 -0
- package/package.json +26 -5
- package/src/v4/schema.json +334 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export type Config = {
|
|
2
|
+
version: 3;
|
|
3
|
+
routes?: Route[];
|
|
4
|
+
images?: ImagesConfig;
|
|
5
|
+
wildcard?: WildcardConfig;
|
|
6
|
+
overrides?: OverrideConfig;
|
|
7
|
+
cache?: string[];
|
|
8
|
+
crons?: CronsConfig;
|
|
9
|
+
};
|
|
10
|
+
export type Route = Source | Handler;
|
|
11
|
+
export type Source = {
|
|
12
|
+
src: string;
|
|
13
|
+
dest?: string;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
methods?: string[];
|
|
16
|
+
continue?: boolean;
|
|
17
|
+
caseSensitive?: boolean;
|
|
18
|
+
check?: boolean;
|
|
19
|
+
status?: number;
|
|
20
|
+
has?: Array<HostHasField | HeaderHasField | CookieHasField | QueryHasField>;
|
|
21
|
+
missing?: Array<HostHasField | HeaderHasField | CookieHasField | QueryHasField>;
|
|
22
|
+
locale?: Locale;
|
|
23
|
+
middlewareRawSrc?: string[];
|
|
24
|
+
middlewarePath?: string;
|
|
25
|
+
};
|
|
26
|
+
export type Locale = {
|
|
27
|
+
redirect?: Record<string, string>;
|
|
28
|
+
cookie?: string;
|
|
29
|
+
};
|
|
30
|
+
export type HostHasField = {
|
|
31
|
+
type: 'host';
|
|
32
|
+
value: string;
|
|
33
|
+
};
|
|
34
|
+
export type HeaderHasField = {
|
|
35
|
+
type: 'header';
|
|
36
|
+
key: string;
|
|
37
|
+
value?: string;
|
|
38
|
+
};
|
|
39
|
+
export type CookieHasField = {
|
|
40
|
+
type: 'cookie';
|
|
41
|
+
key: string;
|
|
42
|
+
value?: string;
|
|
43
|
+
};
|
|
44
|
+
export type QueryHasField = {
|
|
45
|
+
type: 'query';
|
|
46
|
+
key: string;
|
|
47
|
+
value?: string;
|
|
48
|
+
};
|
|
49
|
+
export type HandleValue = 'rewrite' | 'filesystem' | 'resource' | 'miss' | 'hit' | 'error';
|
|
50
|
+
type Handler = {
|
|
51
|
+
handle: HandleValue;
|
|
52
|
+
src?: string;
|
|
53
|
+
dest?: string;
|
|
54
|
+
status?: number;
|
|
55
|
+
};
|
|
56
|
+
export type ImageFormat = 'image/avif' | 'image/webp';
|
|
57
|
+
export type RemotePattern = {
|
|
58
|
+
protocol?: 'http' | 'https';
|
|
59
|
+
hostname: string;
|
|
60
|
+
port?: string;
|
|
61
|
+
pathname?: string;
|
|
62
|
+
};
|
|
63
|
+
export type ImagesConfig = {
|
|
64
|
+
sizes: number[];
|
|
65
|
+
domains: string[];
|
|
66
|
+
remotePatterns?: RemotePattern[];
|
|
67
|
+
minimumCacheTTL?: number;
|
|
68
|
+
formats?: ImageFormat[];
|
|
69
|
+
dangerouslyAllowSVG?: boolean;
|
|
70
|
+
contentSecurityPolicy?: string;
|
|
71
|
+
contentDispositionType?: string;
|
|
72
|
+
};
|
|
73
|
+
export type WildCard = {
|
|
74
|
+
domain: string;
|
|
75
|
+
value: string;
|
|
76
|
+
};
|
|
77
|
+
export type WildcardConfig = Array<WildCard>;
|
|
78
|
+
export type Override = {
|
|
79
|
+
path?: string;
|
|
80
|
+
contentType?: string;
|
|
81
|
+
};
|
|
82
|
+
export type OverrideConfig = Record<string, Override>;
|
|
83
|
+
export type Cache = string[];
|
|
84
|
+
export type Cron = {
|
|
85
|
+
path: string;
|
|
86
|
+
schedule: string;
|
|
87
|
+
};
|
|
88
|
+
export type CronsConfig = Cron[];
|
|
89
|
+
export type ServerlessFunctionConfig = {
|
|
90
|
+
handler: string;
|
|
91
|
+
runtime: string;
|
|
92
|
+
memory?: number;
|
|
93
|
+
maxDuration?: number;
|
|
94
|
+
environment?: Record<string, string>[];
|
|
95
|
+
regions?: string[];
|
|
96
|
+
supportsWrapper?: boolean;
|
|
97
|
+
supportsResponseStreaming?: boolean;
|
|
98
|
+
experimentalResponseStreaming?: boolean;
|
|
99
|
+
filePathMap?: Record<string, string>;
|
|
100
|
+
};
|
|
101
|
+
export type NodejsServerlessFunctionConfig = ServerlessFunctionConfig & {
|
|
102
|
+
launcherType: 'Nodejs';
|
|
103
|
+
shouldAddHelpers?: boolean;
|
|
104
|
+
shouldAddSourceMapSupport?: boolean;
|
|
105
|
+
};
|
|
106
|
+
export type EdgeFunctionConfig = {
|
|
107
|
+
runtime: 'edge';
|
|
108
|
+
entrypoint: string;
|
|
109
|
+
envVarsInUse?: string[];
|
|
110
|
+
regions?: 'all' | string | string[];
|
|
111
|
+
};
|
|
112
|
+
export type PrerenderFunctionConfig = {
|
|
113
|
+
expiration: number | false;
|
|
114
|
+
group?: number;
|
|
115
|
+
bypassToken?: string;
|
|
116
|
+
fallback?: string;
|
|
117
|
+
allowQuery?: string[];
|
|
118
|
+
passQuery?: boolean;
|
|
119
|
+
};
|
|
120
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Config } from '.';
|
|
2
|
+
import type { NormalizedConfig } from '../normalized-config';
|
|
3
|
+
import type { Runtime } from '../runtime';
|
|
4
|
+
/**
|
|
5
|
+
* Transforms a parsed config file using Vercel's Build Output API v3
|
|
6
|
+
* @param parseResult The result of parsing the existing config file
|
|
7
|
+
* @param projectFolder The path to the project folder
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseVercelBuildOutputV3: (parseResult: NormalizedConfig, projectFolder: string) => Promise<NormalizedConfig>;
|
|
11
|
+
export declare const loadFunctions: (config: Config, parseResult: NormalizedConfig, projectFolder: string) => Promise<void>;
|
|
12
|
+
export declare const readConfigFile: <T>(configFilePath: string) => Promise<T | null>;
|
|
13
|
+
export declare const translateVercelRuntime: (runtime: string) => Runtime | null;
|
|
14
|
+
/**
|
|
15
|
+
* @link https://vercel.com/docs/edge-network/regions#region-list
|
|
16
|
+
*/
|
|
17
|
+
export declare const translateVercelRegion: (region: string) => string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import w from"fs";import s from"path";import".";import{
|
|
1
|
+
import{getFilesForPattern as w}from"@gigadrive/build-utils/get-files-for-pattern";import j from"fs";import s from"path";import".";import{parseRawConfig as z}from"../parse-raw-config";const R=".vercel/output/config.json",S=".vercel/output/functions/*.func/.vc-config.json",A=async(o,n)=>{const e=await h(s.join(n,R));return!e||e.version<3||(await E(e,o,n),await b(e,o)),o},b=async(o,n)=>{n.assets||(n.assets={paths:[],prefixToStrip:""}),n.assets.overrides={...n.assets.overrides??{},...o.overrides}},E=async(o,n,e)=>{const C=await w(S,e);for(const c of C){const i=await h(s.join(e,c));if(!i){n.errors.push(`Failed to read function config at ${c}`);continue}const r=s.basename(s.dirname(c)).replace(/\.func$/,""),a=M(i.runtime);if(!a){n.errors.push(`Unsupported runtime for function ${r}: ${i.runtime}`);continue}const y=`.vercel/output/functions/${r}.func`,u=i.handler,N=i.maxDuration,v=i.memory;n.regions=Array.from(new Set([...n.regions??[],...(i.regions??["us-east-1"]).map(t=>O(t))]));const d={},f=i.environment;if(f!=null&&typeof f=="object")for(const t of Object.values(f))for(const[m,x]of Object.entries(t))d[m]=x;const g=a==null||a.startsWith("node-")||a.startsWith("bun-"),p={};for(const[t,m]of Object.entries(i.filePathMap??{}))p[s.join(e,t)]=m;n.entrypoints.push({displayName:r,runtime:a,path:u,memory:v??1024,maxDuration:N??15,environmentVariables:d,streaming:g,package:{rootOverwrite:s.join(e,y),filePathMap:p}});const l=g?"SERVERLESS_FUNCTION_STREAMING":"SERVERLESS_FUNCTION";[{path:`/${r}`,methods:["ANY"],headers:{},destination:u,handler:l},...o.routes?.filter(t=>t.dest===`/${r}`).map(t=>({path:t.src??`/${r}`,methods:["ANY"],headers:{},destination:u,handler:l}))??[]].forEach(t=>{n.routes.push(t)})}},h=async o=>j.existsSync(o)?await z(o):null,M=o=>{switch(o){case"nodejs12.x":case"nodejs14.x":case"nodejs16.x":case"nodejs18.x":return"node-18";case"nodejs20.x":case"nodejs22.x":return"node-20";default:return null}},O=o=>({arn1:"eu-north-1",bom1:"ap-south-1",cdg1:"eu-west-3",cle1:"us-east-2",cpt1:"af-south-1",dub1:"eu-west-1",fra1:"eu-central-1",gru1:"sa-east-1",hkg1:"ap-east-1",hnd1:"ap-northeast-1",iad1:"us-east-1",icn1:"ap-northeast-2",kix1:"ap-northeast-3",lhr1:"eu-west-2",pdx1:"us-west-2",sfo1:"us-west-1",sin1:"ap-southeast-1",syd1:"ap-southeast-2"})[o.toLowerCase()]??"us-east-1";export{E as loadFunctions,A as parseVercelBuildOutputV3,h as readConfigFile,O as translateVercelRegion,M as translateVercelRuntime};
|
|
2
2
|
//# sourceMappingURL=parse.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/build-output-v3/parse.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs';\nimport path from 'path';\nimport { type Config, type Route, type ServerlessFunctionConfig } from '.';\nimport
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["import { getFilesForPattern } from '@gigadrive/build-utils/get-files-for-pattern';\nimport fs from 'fs';\nimport path from 'path';\nimport { type Config, type Route, type ServerlessFunctionConfig } from '.';\nimport type {\n NormalizedConfig,\n NormalizedConfigRoute,\n NormalizedConfigRouteHandler,\n NormalizedConfigRouteMethod,\n} from '../normalized-config';\nimport { parseRawConfig } from '../parse-raw-config';\nimport type { Region } from '../regions';\nimport type { Runtime } from '../runtime';\n\nconst configPath = '.vercel/output/config.json';\nconst functionConfigsPattern = '.vercel/output/functions/*.func/.vc-config.json';\n\n/**\n * Transforms a parsed config file using Vercel's Build Output API v3\n * @param parseResult The result of parsing the existing config file\n * @param projectFolder The path to the project folder\n * @returns\n */\nexport const parseVercelBuildOutputV3 = async (\n parseResult: NormalizedConfig,\n projectFolder: string\n): Promise<NormalizedConfig> => {\n // read config file\n const config = await readConfigFile<Config>(path.join(projectFolder, configPath));\n\n if (!config || config.version < 3) {\n // TODO: Log error\n return parseResult;\n }\n\n // TODO: Routes\n // TODO: Images\n // TODO: Wildcards\n // TODO: Cache\n // TODO: Cron\n // TODO: Edge Functions\n // TODO: Prerender Functions\n\n await loadFunctions(config, parseResult, projectFolder);\n await loadAssetOverrides(config, parseResult);\n\n return parseResult;\n};\n\nconst loadAssetOverrides = async (config: Config, parseResult: NormalizedConfig) => {\n if (!parseResult.assets) {\n parseResult.assets = {\n paths: [],\n prefixToStrip: '',\n };\n }\n\n parseResult.assets.overrides = {\n ...(parseResult.assets.overrides ?? {}),\n ...config.overrides,\n };\n};\n\nexport const loadFunctions = async (config: Config, parseResult: NormalizedConfig, projectFolder: string) => {\n const functionConfigs = await getFilesForPattern(functionConfigsPattern, projectFolder);\n\n // console.debug('functionConfigs', functionConfigs);\n\n for (const functionConfigPath of functionConfigs) {\n const functionConfig = await readConfigFile<ServerlessFunctionConfig>(path.join(projectFolder, functionConfigPath));\n\n if (!functionConfig) {\n parseResult.errors.push(`Failed to read function config at ${functionConfigPath}`);\n continue;\n }\n\n const functionName: string = path.basename(path.dirname(functionConfigPath)).replace(/\\.func$/, '');\n const runtime = translateVercelRuntime(functionConfig.runtime);\n\n if (!runtime) {\n parseResult.errors.push(`Unsupported runtime for function ${functionName}: ${functionConfig.runtime}`);\n continue;\n }\n\n const functionDirectory = `.vercel/output/functions/${functionName}.func`;\n const handler = functionConfig.handler;\n const maxDuration = functionConfig.maxDuration;\n const memory = functionConfig.memory;\n\n // add regions and filter duplicates\n parseResult.regions = Array.from(\n new Set([\n ...(parseResult.regions ?? []),\n ...(functionConfig.regions ?? ['us-east-1']).map((r) => translateVercelRegion(r)),\n ])\n ) as Region[];\n\n const environmentVariables: Record<string, string> = {};\n\n const functionEnv = functionConfig.environment;\n\n if (functionEnv != null && typeof functionEnv === 'object') {\n for (const env of Object.values(functionEnv)) {\n for (const [key, value] of Object.entries(env)) {\n environmentVariables[key] = value;\n }\n }\n }\n\n const streaming: boolean = runtime == null || runtime.startsWith('node-') || runtime.startsWith('bun-');\n\n // translate filePathMap relative paths to absolute paths\n const filePathMap: Record<string, string> = {};\n for (const [key, value] of Object.entries(functionConfig.filePathMap ?? {})) {\n filePathMap[path.join(projectFolder, key)] = value;\n }\n\n parseResult.entrypoints.push({\n displayName: functionName,\n runtime,\n path: handler,\n memory: memory ?? 1024,\n maxDuration: maxDuration ?? 15,\n environmentVariables,\n streaming,\n package: {\n rootOverwrite: path.join(projectFolder, functionDirectory),\n filePathMap: filePathMap,\n },\n });\n\n const handlerType: NormalizedConfigRouteHandler = streaming\n ? 'SERVERLESS_FUNCTION_STREAMING'\n : 'SERVERLESS_FUNCTION';\n\n (\n [\n {\n path: `/${functionName}`,\n methods: ['ANY'],\n headers: {},\n destination: handler,\n handler: handlerType,\n },\n ...(config.routes\n ?.filter((r) => r.dest === `/${functionName}`)\n .map((r: Route) => ({\n path: r.src ?? `/${functionName}`,\n methods: ['ANY'] as NormalizedConfigRouteMethod[],\n headers: {},\n destination: handler,\n handler: handlerType,\n })) ?? []),\n ] as NormalizedConfigRoute[]\n ).forEach((route) => {\n parseResult.routes.push(route);\n });\n }\n};\n\nexport const readConfigFile = async <T>(configFilePath: string): Promise<T | null> => {\n if (!fs.existsSync(configFilePath)) {\n // skip vercel transformation if no vercel output exists\n return null;\n }\n\n const parsed = await parseRawConfig(configFilePath);\n\n return parsed as T;\n};\n\nexport const translateVercelRuntime = (runtime: string): Runtime | null => {\n switch (runtime) {\n case 'nodejs12.x':\n case 'nodejs14.x':\n case 'nodejs16.x':\n case 'nodejs18.x':\n return 'node-18';\n case 'nodejs20.x':\n case 'nodejs22.x': // TODO: Update when Lambda supports Node.js 22\n return 'node-20';\n default:\n return null;\n }\n};\n\n/**\n * @link https://vercel.com/docs/edge-network/regions#region-list\n */\nexport const translateVercelRegion = (region: string): string => {\n const regionMap: Record<string, string> = {\n arn1: 'eu-north-1',\n bom1: 'ap-south-1',\n cdg1: 'eu-west-3',\n cle1: 'us-east-2',\n cpt1: 'af-south-1',\n dub1: 'eu-west-1',\n fra1: 'eu-central-1',\n gru1: 'sa-east-1',\n hkg1: 'ap-east-1',\n hnd1: 'ap-northeast-1',\n iad1: 'us-east-1',\n icn1: 'ap-northeast-2',\n kix1: 'ap-northeast-3',\n lhr1: 'eu-west-2',\n pdx1: 'us-west-2',\n sfo1: 'us-west-1',\n sin1: 'ap-southeast-1',\n syd1: 'ap-southeast-2',\n };\n\n return regionMap[region.toLowerCase()] ?? 'us-east-1';\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,sBAAAA,MAA0B,+CACnC,OAAOC,MAAQ,KACf,OAAOC,MAAU,OACjB,MAAuE,IAOvE,OAAS,kBAAAC,MAAsB,sBAI/B,MAAMC,EAAa,6BACbC,EAAyB,kDAQlBC,EAA2B,MACtCC,EACAC,IAC8B,CAE9B,MAAMC,EAAS,MAAMC,EAAuBR,EAAK,KAAKM,EAAeJ,CAAU,CAAC,EAEhF,MAAI,CAACK,GAAUA,EAAO,QAAU,IAahC,MAAME,EAAcF,EAAQF,EAAaC,CAAa,EACtD,MAAMI,EAAmBH,EAAQF,CAAW,GAErCA,CACT,EAEMK,EAAqB,MAAOH,EAAgBF,IAAkC,C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N,KAAM,YACN,KAAM,iBACN,KAAM,gBACR,GAEiBA,EAAO,YAAY,CAAC,GAAK",
|
|
6
|
+
"names": ["getFilesForPattern", "fs", "path", "parseRawConfig", "configPath", "functionConfigsPattern", "parseVercelBuildOutputV3", "parseResult", "projectFolder", "config", "readConfigFile", "loadFunctions", "loadAssetOverrides", "functionConfigs", "functionConfigPath", "functionConfig", "functionName", "runtime", "translateVercelRuntime", "functionDirectory", "handler", "maxDuration", "memory", "r", "translateVercelRegion", "environmentVariables", "functionEnv", "env", "key", "value", "streaming", "filePathMap", "handlerType", "route", "configFilePath", "region"]
|
|
7
7
|
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NormalizedConfig } from './normalized-config';
|
|
2
|
+
export declare const ALLOWED_CONFIG_NAMES: string[];
|
|
3
|
+
/**
|
|
4
|
+
* Finds a config file in the project folder.
|
|
5
|
+
* @param projectFolder The folder to search for a config file in.
|
|
6
|
+
* @returns The path to the config file, or null if no config file is found.
|
|
7
|
+
*/
|
|
8
|
+
export declare const findConfig: (projectFolder: string) => string | null;
|
|
9
|
+
export declare const parseConfig: (filePath: string, projectFolder: string) => Promise<NormalizedConfig>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import f from"ajv";import d from"ajv-formats";import l from"fs";import c from"path";import{parseVercelBuildOutputV3 as g}from"./build-output-v3/parse";import{parseRawConfig as u}from"./parse-raw-config";import{parseConfigV4 as h}from"./v4/parse";const v=JSON.parse(l.readFileSync(c.join(__dirname,"./v4/schema.json"),"utf8")),y=["gigadrive.yaml","gigadrive.yml","nebula.yaml","nebula.yml","nebula.json"],O=r=>{for(const n of y){const o=c.join(r,n);if(l.existsSync(o))return o}return null},R=async(r,n)=>{const o=await u(r),t=o.version,m={4:v},i=r.replace("/tmp/unzipped/",""),a=m[t];if(!a)throw new Error(`Config file at ${i} has an unsupported version: ${t}`);const s=new f;d(s);const p=s.compile(a);if(!p(o))throw new Error(`Config file at ${i} is invalid: ${s.errorsText(p.errors)}`);let e=await{4:h}[t](o,n);return e=await g(e,n),e.entrypoints.length===0&&(e.assets?.paths?.length||0)===0?e.warnings.push("The current project does not have any functions or assets to deploy."):e.entrypoints.length===0&&(e.assets?.paths?.length||0)===0&&e.routes.length===0&&e.errors.push("The current project config does not resolve to any functions, assets or routes and can not be deployed."),e};export{y as ALLOWED_CONFIG_NAMES,O as findConfig,R as parseConfig};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Ajv from 'ajv';\nimport addFormats from 'ajv-formats';\nimport fs from 'fs';\nimport path from 'path';\nimport { parseVercelBuildOutputV3 } from './build-output-v3/parse';\nimport type { NormalizedConfig } from './normalized-config';\nimport { parseRawConfig } from './parse-raw-config';\nimport { parseConfigV4 } from './v4/parse';\
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAS,MAChB,OAAOC,MAAgB,cACvB,OAAOC,MAAQ,KACf,OAAOC,MAAU,OACjB,OAAS,4BAAAC,MAAgC,0BAEzC,OAAS,kBAAAC,MAAsB,qBAC/B,OAAS,iBAAAC,MAAqB,
|
|
4
|
+
"sourcesContent": ["import Ajv from 'ajv';\nimport addFormats from 'ajv-formats';\nimport fs from 'fs';\nimport path from 'path';\nimport { parseVercelBuildOutputV3 } from './build-output-v3/parse';\nimport type { NormalizedConfig } from './normalized-config';\nimport { parseRawConfig } from './parse-raw-config';\nimport { parseConfigV4 } from './v4/parse';\n\nconst schemaV4 = JSON.parse(fs.readFileSync(path.join(__dirname, './v4/schema.json'), 'utf8'));\n\nexport const ALLOWED_CONFIG_NAMES = ['gigadrive.yaml', 'gigadrive.yml', 'nebula.yaml', 'nebula.yml', 'nebula.json'];\n\n/**\n * Finds a config file in the project folder.\n * @param projectFolder The folder to search for a config file in.\n * @returns The path to the config file, or null if no config file is found.\n */\nexport const findConfig = (projectFolder: string): string | null => {\n for (const name of ALLOWED_CONFIG_NAMES) {\n const filePath = path.join(projectFolder, name);\n if (fs.existsSync(filePath)) {\n return filePath;\n }\n }\n return null;\n};\n\nexport const parseConfig = async (filePath: string, projectFolder: string): Promise<NormalizedConfig> => {\n const parsed = await parseRawConfig(filePath);\n const version = parsed.version;\n\n const schemaMap: Record<number, object> = {\n /*1: schemaV1,\n 2: schemaV2,\n 3: schemaV3,*/\n 4: schemaV4,\n };\n\n // build the path to the config file relative to the project root (strip /tmp/unzipped prefix)\n const relativePath = filePath.replace('/tmp/unzipped/', '');\n\n const schema = schemaMap[version];\n\n if (!schema) {\n throw new Error(`Config file at ${relativePath} has an unsupported version: ${version}`);\n }\n\n // validate the config file\n const ajv = new Ajv();\n addFormats(ajv);\n\n const validate = ajv.compile(schema);\n\n const valid = validate(parsed);\n if (!valid) {\n throw new Error(`Config file at ${relativePath} is invalid: ${ajv.errorsText(validate.errors)}`);\n }\n\n // @ts-ignore\n const parserMap: Record<number, (config, projectFolder) => Promise<NormalizedConfig>> = {\n /*1: parseConfigV1,\n 2: parseConfigV2,\n 3: parseConfigV3,*/\n 4: parseConfigV4,\n };\n\n let parseResult: NormalizedConfig = await parserMap[version](parsed, projectFolder);\n\n // TODO: apply transformers\n parseResult = await parseVercelBuildOutputV3(parseResult, projectFolder);\n\n // if the config does not resolve to any resources, warn the user\n if (parseResult.entrypoints.length === 0 && (parseResult.assets?.paths?.length || 0) === 0) {\n parseResult.warnings.push('The current project does not have any functions or assets to deploy.');\n } else if (\n parseResult.entrypoints.length === 0 &&\n (parseResult.assets?.paths?.length || 0) === 0 &&\n parseResult.routes.length === 0\n ) {\n parseResult.errors.push(\n 'The current project config does not resolve to any functions, assets or routes and can not be deployed.'\n );\n }\n\n return parseResult;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAS,MAChB,OAAO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AAO,GAC7CA,EAAY,OAAO,SAAW,GAE9BA,EAAY,OAAO,KACjB,yGACF,EAGKA,CACT",
|
|
6
6
|
"names": ["Ajv", "addFormats", "fs", "path", "parseVercelBuildOutputV3", "parseRawConfig", "parseConfigV4", "schemaV4", "ALLOWED_CONFIG_NAMES", "findConfig", "projectFolder", "name", "filePath", "parseConfig", "parsed", "version", "schemaMap", "relativePath", "schema", "ajv", "validate", "parseResult"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type Region } from './regions';
|
|
2
|
+
import { type Runtime } from './runtime';
|
|
3
|
+
/**
|
|
4
|
+
* The object structure that all config versions will be parsed into.
|
|
5
|
+
* This is done to provide a consistent interface for the rest of the codebase and easily provision the necessary resources, regardless of the config version.
|
|
6
|
+
*/
|
|
7
|
+
export interface NormalizedConfig {
|
|
8
|
+
/**
|
|
9
|
+
* The regions to deploy the project to.
|
|
10
|
+
*/
|
|
11
|
+
regions: Region[];
|
|
12
|
+
assets?: {
|
|
13
|
+
/**
|
|
14
|
+
* The relative file paths of the static assets to be deployed to the edge.
|
|
15
|
+
*/
|
|
16
|
+
paths?: string[];
|
|
17
|
+
/**
|
|
18
|
+
* The prefix to strip from the asset path when serving.
|
|
19
|
+
*/
|
|
20
|
+
prefixToStrip?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Overrides for specific assets. Can be used to change the path or Content-Type of an asset.
|
|
23
|
+
*/
|
|
24
|
+
overrides?: Record<string, {
|
|
25
|
+
path?: string;
|
|
26
|
+
contentType?: string;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Whether routes for the assets should be generated during deployment.
|
|
30
|
+
*/
|
|
31
|
+
dynamicRoutes?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If true, the assets will be cached at the edge during deployment.
|
|
34
|
+
*/
|
|
35
|
+
populateCache?: boolean;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Additional environment variables to set during runtime and build.
|
|
39
|
+
*/
|
|
40
|
+
environmentVariables: Record<string, string>;
|
|
41
|
+
/**
|
|
42
|
+
* The bash commands that will be run to build the project.
|
|
43
|
+
*/
|
|
44
|
+
commands: string[];
|
|
45
|
+
entrypoints: Array<NormalizedConfigEntrypoint>;
|
|
46
|
+
routes: Array<NormalizedConfigRoute>;
|
|
47
|
+
services?: Array<NormalizedConfigService>;
|
|
48
|
+
/**
|
|
49
|
+
* Warning codes to be printed to the output during deployment.
|
|
50
|
+
*/
|
|
51
|
+
warnings: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Error codes to be printed to the output during deployment.
|
|
54
|
+
*/
|
|
55
|
+
errors: string[];
|
|
56
|
+
}
|
|
57
|
+
export interface NormalizedConfigService {
|
|
58
|
+
type: NormalizedConfigServiceType;
|
|
59
|
+
}
|
|
60
|
+
export type NormalizedConfigServiceType = 'redis' | 'postgres';
|
|
61
|
+
export type UpstashAWSRegion = 'us-east-1' | 'us-east-2' | 'us-west-1' | 'us-west-2' | 'eu-central-1' | 'eu-west-1' | 'eu-west-2' | 'sa-east-1' | 'ap-south-1' | 'ap-northeast-1' | 'ap-southeast-1' | 'ap-southeast-2';
|
|
62
|
+
export interface NormalizedConfigServiceRedis extends NormalizedConfigService {
|
|
63
|
+
envBindings?: Record<'url' | 'host' | 'port' | 'password' | 'db' | 'ssl', string>;
|
|
64
|
+
primaryRegion?: UpstashAWSRegion | 'us-central1';
|
|
65
|
+
readRegions?: UpstashAWSRegion[];
|
|
66
|
+
eviction?: boolean;
|
|
67
|
+
}
|
|
68
|
+
export type NeonAWSRegion = 'us-east-1' | 'us-east-2' | 'us-west-2' | 'ap-southeast-1' | 'ap-southeast-2' | 'eu-central-1' | 'eu-west-2' | 'sa-east-1';
|
|
69
|
+
export interface NormalizedConfigServicePostgres extends NormalizedConfigService {
|
|
70
|
+
envBindings?: Record<'url' | 'host' | 'port' | 'user' | 'password' | 'database', string>;
|
|
71
|
+
postgresVersion?: '17' | '16' | '15' | '14';
|
|
72
|
+
region?: NeonAWSRegion;
|
|
73
|
+
}
|
|
74
|
+
export interface NormalizedConfigEntrypoint {
|
|
75
|
+
displayName?: string;
|
|
76
|
+
path: string;
|
|
77
|
+
runtime: Runtime;
|
|
78
|
+
memory: number;
|
|
79
|
+
maxDuration: number;
|
|
80
|
+
schedule?: string;
|
|
81
|
+
symlinks?: Record<string, string>;
|
|
82
|
+
environmentVariables?: Record<string, string>;
|
|
83
|
+
streaming?: boolean;
|
|
84
|
+
package?: {
|
|
85
|
+
rootOverwrite?: string;
|
|
86
|
+
filePathMap?: Record<string, string>;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export interface NormalizedConfigRoute {
|
|
90
|
+
path: string;
|
|
91
|
+
destination: string;
|
|
92
|
+
handler: NormalizedConfigRouteHandler | undefined;
|
|
93
|
+
methods: NormalizedConfigRouteMethod[];
|
|
94
|
+
headers: Record<string, string>;
|
|
95
|
+
positiveRequirements?: NormalizedConfigRouteMatchRequirements;
|
|
96
|
+
negativeRequirements?: NormalizedConfigRouteMatchRequirements;
|
|
97
|
+
status?: number;
|
|
98
|
+
}
|
|
99
|
+
export type NormalizedConfigRouteHandler = 'SERVERLESS_FUNCTION' | 'SERVERLESS_FUNCTION_STREAMING' | 'HTTP_REDIRECT' | 'HTTP_PROXY' | 'ASSET';
|
|
100
|
+
export type NormalizedConfigRouteMethod = 'ANY' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS';
|
|
101
|
+
export type NormalizedConfigRouteMatchRequirements = [] | [
|
|
102
|
+
{
|
|
103
|
+
/**
|
|
104
|
+
* The type of request element to check
|
|
105
|
+
*/
|
|
106
|
+
type: 'host';
|
|
107
|
+
/**
|
|
108
|
+
* A regular expression used to match the value. Named groups can be used in the destination
|
|
109
|
+
*/
|
|
110
|
+
value: string;
|
|
111
|
+
} | {
|
|
112
|
+
/**
|
|
113
|
+
* The type of request element to check
|
|
114
|
+
*/
|
|
115
|
+
type: 'header' | 'cookie' | 'query';
|
|
116
|
+
/**
|
|
117
|
+
* The name of the element contained in the particular type
|
|
118
|
+
*/
|
|
119
|
+
key: string;
|
|
120
|
+
/**
|
|
121
|
+
* A regular expression used to match the value. Named groups can be used in the destination
|
|
122
|
+
*/
|
|
123
|
+
value?: string;
|
|
124
|
+
}
|
|
125
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const parseRawConfig: (filePath: string) => Promise<any>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const REGION_DEFINITIONS: readonly ["us-east-1", "us-east-2", "us-west-1", "us-west-2", "ap-south-1", "ap-northeast-3", "ap-northeast-2", "ap-southeast-1", "ap-southeast-2", "ap-northeast-1", "ca-central-1", "eu-central-1", "eu-west-1", "eu-west-2", "eu-west-3", "eu-north-1", "sa-east-1"];
|
|
2
|
+
export type Region = (typeof REGION_DEFINITIONS)[number];
|
|
3
|
+
export declare const AVAILABLE_REGIONS: Region[];
|
|
4
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { NeonAWSRegion, NormalizedConfigRouteMatchRequirements, NormalizedConfigRouteMethod, NormalizedConfigServiceType, UpstashAWSRegion } from '../normalized-config';
|
|
2
|
+
import type { Runtime } from '../runtime';
|
|
3
|
+
export interface ConfigV4 {
|
|
4
|
+
version: 4;
|
|
5
|
+
/**
|
|
6
|
+
* A list of presets to apply to the project. Each preset will be applied in order.
|
|
7
|
+
*/
|
|
8
|
+
presets?: string[] | null;
|
|
9
|
+
/**
|
|
10
|
+
* The folder which holds the assets to be deployed to the edge. Defaults to none.
|
|
11
|
+
*/
|
|
12
|
+
assets?: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* If true, the assets will be cached at the edge during deployment. This may increase the deployment time, depending on the size of the assets. Defaults to false.
|
|
15
|
+
*/
|
|
16
|
+
populateAssetCache?: boolean | null;
|
|
17
|
+
/**
|
|
18
|
+
* The regions to which the project will be deployed. Use "global" to deploy to all regions. More regions will incur higher costs.
|
|
19
|
+
*/
|
|
20
|
+
regions?: string[] | null;
|
|
21
|
+
/**
|
|
22
|
+
* The commands to run to build the project. For example, `bun install` or `npm install`.
|
|
23
|
+
*/
|
|
24
|
+
build_commands?: string[] | null;
|
|
25
|
+
/**
|
|
26
|
+
* The serverless functions to deploy.
|
|
27
|
+
*/
|
|
28
|
+
functions?: {
|
|
29
|
+
/**
|
|
30
|
+
* The pattern to match the file path of the function. May be a glob pattern or a regular expression.
|
|
31
|
+
*/
|
|
32
|
+
[pattern: string]: ConfigV4FunctionSettings;
|
|
33
|
+
} | null;
|
|
34
|
+
/**
|
|
35
|
+
* A list of route definitions.
|
|
36
|
+
*
|
|
37
|
+
* @maxItems 1024
|
|
38
|
+
*/
|
|
39
|
+
routes?: {
|
|
40
|
+
/**
|
|
41
|
+
* A pattern that matches each incoming pathname (excluding querystring).
|
|
42
|
+
*/
|
|
43
|
+
source: string;
|
|
44
|
+
/**
|
|
45
|
+
* An absolute pathname to an existing resource or an external URL.
|
|
46
|
+
*/
|
|
47
|
+
destination: string;
|
|
48
|
+
/**
|
|
49
|
+
* An array of requirements that are needed to match
|
|
50
|
+
*
|
|
51
|
+
* @maxItems 16
|
|
52
|
+
*/
|
|
53
|
+
has?: NormalizedConfigRouteMatchRequirements;
|
|
54
|
+
/**
|
|
55
|
+
* An array of requirements that are needed to match
|
|
56
|
+
*
|
|
57
|
+
* @maxItems 16
|
|
58
|
+
*/
|
|
59
|
+
missing?: NormalizedConfigRouteMatchRequirements;
|
|
60
|
+
/**
|
|
61
|
+
* An optional integer to override the status code of the response.
|
|
62
|
+
*/
|
|
63
|
+
statusCode?: number;
|
|
64
|
+
/**
|
|
65
|
+
* An optional boolean to force a redirect response.
|
|
66
|
+
*/
|
|
67
|
+
redirect?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The HTTP methods to match for the route. Defaults to all methods.
|
|
70
|
+
*/
|
|
71
|
+
methods?: NormalizedConfigRouteMethod[];
|
|
72
|
+
/**
|
|
73
|
+
* Additional headers to add to the response.
|
|
74
|
+
*/
|
|
75
|
+
headers?: {
|
|
76
|
+
[k: string]: string;
|
|
77
|
+
};
|
|
78
|
+
}[] | null;
|
|
79
|
+
/**
|
|
80
|
+
* Additional environment variables to set during runtime and build.
|
|
81
|
+
*/
|
|
82
|
+
env: Record<string, string>;
|
|
83
|
+
/**
|
|
84
|
+
* Optioanlly, specify additional services like databases to deploy.
|
|
85
|
+
*/
|
|
86
|
+
services?: {
|
|
87
|
+
[type in NormalizedConfigServiceType]?: ConfigV4Service | null;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
export interface ConfigV4Service {
|
|
91
|
+
}
|
|
92
|
+
export interface ConfigV4ServiceRedis extends ConfigV4Service {
|
|
93
|
+
/**
|
|
94
|
+
* Optionally, specify what environment variables the credentials will be bound to.
|
|
95
|
+
* For example: `{ url: 'REDIS_URL' }` will bind the `url` environment variable to the Redis URL.
|
|
96
|
+
* If you don't specify any bindings, they will be bound to the REDIS_URL, REDIS_HOST, REDIS_PORT, REDIS_PASSWORD, REDIS_DB, and REDIS_SSL environment variables.
|
|
97
|
+
*/
|
|
98
|
+
envBindings?: Record<'url' | 'host' | 'port' | 'password' | 'db' | 'ssl', string>;
|
|
99
|
+
/**
|
|
100
|
+
* The primary region to deploy the Redis instance to.
|
|
101
|
+
*/
|
|
102
|
+
primaryRegion?: UpstashAWSRegion | 'us-central1';
|
|
103
|
+
/**
|
|
104
|
+
* Optionally, add additional regions to read from. More regions will incur higher costs.
|
|
105
|
+
*/
|
|
106
|
+
readRegions?: UpstashAWSRegion[];
|
|
107
|
+
/**
|
|
108
|
+
* Optionally, enable Redis eviction. This will evict the least recently used keys in order to make space for new ones.
|
|
109
|
+
*/
|
|
110
|
+
eviction?: boolean;
|
|
111
|
+
}
|
|
112
|
+
export interface ConfigV4ServicePostgres extends ConfigV4Service {
|
|
113
|
+
/**
|
|
114
|
+
* Optionally, specify what environment variables the credentials will be bound to.
|
|
115
|
+
* For example: `{ url: 'POSTGRES_URL' }` will bind the `url` environment variable to the Postgres URL.
|
|
116
|
+
* If you don't specify any bindings, they will be bound to the POSTGRES_URL, POSTGRES_HOST, POSTGRES_PORT, POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DATABASE environment variables.
|
|
117
|
+
*/
|
|
118
|
+
envBindings?: Record<'url' | 'host' | 'port' | 'user' | 'password' | 'database', string>;
|
|
119
|
+
/**
|
|
120
|
+
* The version of Postgres to deploy.
|
|
121
|
+
*/
|
|
122
|
+
postgresVersion?: '17' | '16' | '15' | '14';
|
|
123
|
+
/**
|
|
124
|
+
* The region to deploy the Postgres instance to.
|
|
125
|
+
*/
|
|
126
|
+
region?: NeonAWSRegion;
|
|
127
|
+
}
|
|
128
|
+
export interface ConfigV4FunctionSettings {
|
|
129
|
+
/**
|
|
130
|
+
* The memory limit for the function in MB.
|
|
131
|
+
*/
|
|
132
|
+
memory?: number;
|
|
133
|
+
/**
|
|
134
|
+
* The maximum duration of the function in seconds. May not be higher than 15 minutes.
|
|
135
|
+
*/
|
|
136
|
+
max_duration?: number;
|
|
137
|
+
/**
|
|
138
|
+
* The runtime to use for the function.
|
|
139
|
+
*/
|
|
140
|
+
runtime?: Runtime;
|
|
141
|
+
/**
|
|
142
|
+
* Use to create symlinks on the final function. This is useful for applications that require use of the file system, since serverless functions are ephemeral and have read-only file systems, except for /tmp.
|
|
143
|
+
*/
|
|
144
|
+
symlinks?: {
|
|
145
|
+
/**
|
|
146
|
+
* Left side is where the symlink will be created, right side is the target path.
|
|
147
|
+
*/
|
|
148
|
+
[path: string]: string;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* A glob pattern to match files that should be excluded from your Serverless Function. If you’re using a Community Runtime, the behavior might vary.
|
|
152
|
+
*/
|
|
153
|
+
excludeFiles?: string | string[];
|
|
154
|
+
/**
|
|
155
|
+
* A glob pattern to match files that should be included in your Serverless Function. If you’re using a Community Runtime, the behavior might vary.
|
|
156
|
+
*/
|
|
157
|
+
includeFiles?: string | string[];
|
|
158
|
+
/**
|
|
159
|
+
* Optionally, provide a schedule to run the function on periodically. Examples: `rate(1 hour)`, `rate(1 day)`, `cron(0 12 * * *)`.
|
|
160
|
+
*/
|
|
161
|
+
schedule?: string;
|
|
162
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ConfigV4, ConfigV4FunctionSettings } from '.';
|
|
2
|
+
import type { NormalizedConfig } from '../normalized-config';
|
|
3
|
+
export declare const parseConfigV4: (config: ConfigV4, projectFolder: string) => Promise<NormalizedConfig>;
|
|
4
|
+
/**
|
|
5
|
+
* Gets the runtime, memory and max duration for a given path.
|
|
6
|
+
* @param path
|
|
7
|
+
* @param config
|
|
8
|
+
* @returns The runtime, memory and max duration for the given path. Should return undefined when a path should not be deployed as a function.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getFunctionSettings: (path: string, config: ConfigV4) => ConfigV4FunctionSettings | undefined;
|
package/dist/v4/parse.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{getFilesForPattern as y}from"@gigadrive/build-utils/get-files-for-pattern";import m from"fs";import{minimatch as C}from"minimatch";import{AVAILABLE_REGIONS as R}from"../regions";const w=async(t,r)=>{const n=t.regions?.includes("global")===!0?R:t.regions?.filter(e=>e!=="global")??["global"],l=t.populateAssetCache??!1,s=t.env??{},f=t.build_commands??[],d=[],h=[],p=[];if(t.functions!=null)for(const[e,o]of Object.entries(t.functions)){const i=x(e,t);if(i==null)throw new Error(`Settings invalid for function at path '${e}'`);(await y(e,r,o.excludeFiles)).forEach(a=>{d.find(u=>u.path===a)||t.functions!=null&&Object.keys(t.functions).find(u=>u===a&&u!==e)||d.push({path:a,runtime:i.runtime??"node-20",memory:i.memory??128,maxDuration:i.max_duration??30,schedule:o.schedule,symlinks:o.symlinks,streaming:i.runtime==null||i.runtime.startsWith("node-")||i.runtime.startsWith("bun-")})})}const c=[];if(t.assets!=null){const e=`${r}/${t.assets}`;if(m.existsSync(e)&&m.statSync(e).isDirectory())for(const o of m.readdirSync(`${r}/${t.assets}`,{recursive:!0})){if(m.statSync(`${r}/${t.assets}/${o}`).isDirectory())continue;const i=[".htaccess",".htpasswd"],a=o.toString();i.some(u=>a.toLowerCase().endsWith(u.toLowerCase()))||c.push(`${t.assets}/${a}`)}}const g=t.routes??[];return{regions:n,assets:{paths:c.sort(),prefixToStrip:(t.assets??"")+"/",dynamicRoutes:!0,populateCache:l},environmentVariables:s,commands:f,entrypoints:d,errors:h,warnings:p,routes:g.map(e=>{const o=e.destination.toLowerCase().startsWith("http://")||e.destination.toLowerCase().startsWith("https://")?e.redirect===!0?"HTTP_REDIRECT":"HTTP_PROXY":e.redirect===!0?"HTTP_REDIRECT":"SERVERLESS_FUNCTION";return{path:e.source,destination:e.destination,handler:o,headers:e.headers??{},methods:e.methods??["ANY"],positiveRequirements:e.has,negativeRequirements:e.missing,status:e.statusCode}})}},x=(t,r)=>{let n;for(const[l,s]of Object.entries(r.functions??{}))(C(t,l)||new RegExp(l).test(t))&&(n==null&&(n={memory:128,max_duration:30,schedule:void 0,symlinks:void 0,excludeFiles:void 0,includeFiles:void 0}),s.runtime!=null&&(n.runtime=s.runtime),s.memory!=null&&(n.memory=s.memory),s.max_duration!=null&&(n.max_duration=s.max_duration),s.schedule!=null&&(n.schedule=s.schedule),s.symlinks!=null&&(n.symlinks=s.symlinks),s.excludeFiles!=null&&(n.excludeFiles=s.excludeFiles),s.includeFiles!=null&&(n.includeFiles=s.includeFiles));return n};export{x as getFunctionSettings,w as parseConfigV4};
|
|
2
2
|
//# sourceMappingURL=parse.js.map
|