netlify-cli 17.14.1 → 17.15.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/commands/dev/dev.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAU,MAAM,WAAW,CAAA;AA0BhD,OAAO,WAAW,MAAM,oBAAoB,CAAA;AA4D5C,eAAO,MAAM,GAAG,YAAmB,YAAY,WAAW,WAAW,kBAgJpE,CAAA;AAED,eAAO,MAAM,gBAAgB,YAAa,WAAW,gBAuGpD,CAAA"}
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/commands/dev/dev.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAU,MAAM,WAAW,CAAA;AA0BhD,OAAO,WAAW,MAAM,oBAAoB,CAAA;AA4D5C,eAAO,MAAM,GAAG,YAAmB,YAAY,WAAW,WAAW,kBA+IpE,CAAA;AAED,eAAO,MAAM,gBAAgB,YAAa,WAAW,gBAuGpD,CAAA"}
@@ -124,7 +124,6 @@ export const dev = async (options, command) => {
124
124
  },
125
125
  });
126
126
  const functionsRegistry = await startFunctionsServer({
127
- api,
128
127
  blobsContext,
129
128
  command,
130
129
  config,
@@ -1 +1 @@
1
- {"version":3,"file":"functions-serve.d.ts","sourceRoot":"","sources":["../../../src/commands/functions/functions-serve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAOxC,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAI5C,eAAO,MAAM,cAAc,YAAmB,YAAY,WAAW,WAAW,kBA8C/E,CAAA"}
1
+ {"version":3,"file":"functions-serve.d.ts","sourceRoot":"","sources":["../../../src/commands/functions/functions-serve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAcxC,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAI5C,eAAO,MAAM,cAAc,YAAmB,YAAY,WAAW,WAAW,kBAkD/E,CAAA"}
@@ -1,7 +1,8 @@
1
1
  import { join } from 'path';
2
+ import { getBlobsContext } from '../../lib/blobs/blobs.js';
2
3
  import { startFunctionsServer } from '../../lib/functions/server.js';
3
4
  import { printBanner } from '../../utils/banner.js';
4
- import { acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables } from '../../utils/dev.js';
5
+ import { UNLINKED_SITE_MOCK_ID, acquirePort, getDotEnvVariables, getSiteInformation, injectEnvVariables, } from '../../utils/dev.js';
5
6
  import { getFunctionsDir } from '../../utils/functions/index.js';
6
7
  import { getProxyUrl } from '../../utils/proxy.js';
7
8
  const DEFAULT_PORT = 9999;
@@ -23,19 +24,22 @@ export const functionsServe = async (options, command) => {
23
24
  defaultPort: DEFAULT_PORT,
24
25
  errorMessage: 'Could not acquire configured functions port',
25
26
  });
27
+ const blobsContext = await getBlobsContext({
28
+ debug: options.debug,
29
+ projectRoot: command.workingDir,
30
+ siteID: site.id ?? UNLINKED_SITE_MOCK_ID,
31
+ });
26
32
  await startFunctionsServer({
33
+ blobsContext,
27
34
  config,
28
35
  debug: options.debug,
29
36
  command,
30
- api,
31
37
  settings: { functions: functionsDir, functionsPort },
32
38
  site,
33
39
  siteInfo,
34
40
  siteUrl,
35
41
  capabilities,
36
42
  timeouts,
37
- functionsPrefix: '/.netlify/functions/',
38
- buildersPrefix: '/.netlify/builders/',
39
43
  geolocationMode: options.geo,
40
44
  geoCountry: options.country,
41
45
  offline: options.offline,
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/commands/serve/serve.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAwBxC,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAG5C,eAAO,MAAM,KAAK,YAAmB,YAAY,WAAW,WAAW,uBA4ItE,CAAA"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../../src/commands/serve/serve.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAwBxC,OAAO,WAAW,MAAM,oBAAoB,CAAA;AAG5C,eAAO,MAAM,KAAK,YAAmB,YAAY,WAAW,WAAW,uBA2ItE,CAAA"}
@@ -72,7 +72,6 @@ export const serve = async (options, command) => {
72
72
  options,
73
73
  });
74
74
  const functionsRegistry = await startFunctionsServer({
75
- api,
76
75
  blobsContext,
77
76
  command,
78
77
  config,
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/edge-functions/proxy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAgB3C,QAAA,MAAM,aAAa,eAAmC,CAAA;AA4BtD,eAAO,MAAM,kBAAkB,mCAI9B,CAAA;AAKD,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,eAAO,MAAM,oBAAoB,aAAc,QAAQ,YAAY,MAAM,WAKxE,CAAA;AAED,eAAO,MAAM,uBAAuB,8BAMnC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;oBA8DP,eAAe,GAAG;IAAE,eAAe,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,iCAkDjF,CAAA;AAGD,eAAO,MAAM,sBAAsB,uBAA4C,CAAA"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/lib/edge-functions/proxy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AAiB3C,QAAA,MAAM,aAAa,eAAmC,CAAA;AA4BtD,eAAO,MAAM,kBAAkB,mCAI9B,CAAA;AAKD,UAAU,QAAQ;IAChB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,eAAO,MAAM,oBAAoB,aAAc,QAAQ,YAAY,MAAM,WAKxE,CAAA;AAED,eAAO,MAAM,uBAAuB,8BAMnC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;oBA4DP,eAAe,GAAG;IAAE,eAAe,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,iCAkDjF,CAAA;AAGD,eAAO,MAAM,sBAAsB,uBAA4C,CAAA"}
@@ -4,6 +4,7 @@ import { join, resolve } from 'path';
4
4
  import * as bundler from '@netlify/edge-bundler';
5
5
  import getAvailablePort from 'get-port';
6
6
  import { NETLIFYDEVERR, chalk, error as printError } from '../../utils/command-helpers.js';
7
+ import { getFeatureFlagsFromSiteInfo } from '../../utils/feature-flags.js';
7
8
  import { getGeoLocation } from '../geo-location.js';
8
9
  import { getPathInProject } from '../settings.js';
9
10
  import { startSpinner, stopSpinner } from '../spinner.js';
@@ -112,11 +113,9 @@ siteInfo,
112
113
  state, }) => {
113
114
  const userFunctionsPath = config.build.edge_functions;
114
115
  const isolatePort = await getAvailablePort();
115
- const buildFeatureFlags = {
116
- edge_functions_npm_modules: true,
117
- };
118
116
  const runtimeFeatureFlags = ['edge_functions_bootstrap_failure_mode', 'edge_functions_bootstrap_populate_environment'];
119
117
  const protocol = settings.https ? 'https' : 'http';
118
+ const buildFeatureFlags = { ...getFeatureFlagsFromSiteInfo(siteInfo), edge_functions_npm_modules: true };
120
119
  // Initializes the server, bootstrapping the Deno CLI and downloading it from
121
120
  // the network if needed. We don't want to wait for that to be completed, or
122
121
  // the command will be left hanging.
@@ -223,6 +222,7 @@ repositoryRoot, }) => {
223
222
  debug,
224
223
  directories: [directory].filter(Boolean),
225
224
  env: configEnv,
225
+ featureFlags,
226
226
  getUpdatedConfig,
227
227
  importMapFromTOML: config.functions['*'].deno_import_map,
228
228
  projectDir,
@@ -1,4 +1,5 @@
1
1
  import type { Declaration } from '@netlify/edge-bundler';
2
+ import type { FeatureFlags } from '../../utils/feature-flags.js';
2
3
  interface Config {
3
4
  edge_functions?: Declaration[];
4
5
  [key: string]: unknown;
@@ -14,6 +15,7 @@ interface EdgeFunctionsRegistryOptions {
14
15
  sources: string[];
15
16
  value: string;
16
17
  }>;
18
+ featureFlags: FeatureFlags;
17
19
  getUpdatedConfig: () => Promise<Config>;
18
20
  projectDir: string;
19
21
  runIsolate: RunIsolate;
@@ -21,10 +23,10 @@ interface EdgeFunctionsRegistryOptions {
21
23
  importMapFromTOML?: string;
22
24
  }
23
25
  export declare class EdgeFunctionsRegistry {
26
+ importMapFromDeployConfig?: string;
24
27
  private buildError;
25
28
  private bundler;
26
29
  private configPath;
27
- importMapFromDeployConfig?: string;
28
30
  private importMapFromTOML?;
29
31
  private declarationsFromDeployConfig;
30
32
  private declarationsFromTOML;
@@ -32,6 +34,7 @@ export declare class EdgeFunctionsRegistry {
32
34
  private directories;
33
35
  private directoryWatchers;
34
36
  private env;
37
+ private featureFlags;
35
38
  private userFunctions;
36
39
  private internalFunctions;
37
40
  private functionPaths;
@@ -42,7 +45,7 @@ export declare class EdgeFunctionsRegistry {
42
45
  private runIsolate;
43
46
  private servePath;
44
47
  private projectDir;
45
- constructor({ bundler, config, configPath, directories, env, getUpdatedConfig, importMapFromTOML, projectDir, runIsolate, servePath, }: EdgeFunctionsRegistryOptions);
48
+ constructor({ bundler, config, configPath, directories, env, featureFlags, getUpdatedConfig, importMapFromTOML, projectDir, runIsolate, servePath, }: EdgeFunctionsRegistryOptions);
46
49
  private doInitialScan;
47
50
  private get functions();
48
51
  private build;
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../src/lib/edge-functions/registry.ts"],"names":[],"mappings":"AAIA,OAAO,K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C/C,OAAO,CAAC,WAAW,CAAe;IAClC,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,UAAU,CAAQ;gBAEd,EACV,OAAO,EACP,MAAM,EACN,UAAU,EACV,WAAW,EACX,GAAG,EACH,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,UAAU,EACV,SAAS,GACV,EAAE,4BAA4B;YAmBjB,aAAa;IAc3B,OAAO,KAAK,SAAS,GAEpB;YAEa,KAAK;IAmEnB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;YA0BL,+BAA+B;IAsB7C,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAMtC,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,MAAM,CAAC,uBAAuB;YAoBxB,gBAAgB;IAoCxB,UAAU;IAIhB;;OAEG;IACH,OAAO,CAAC,QAAQ;IA2ChB;;;OAGG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;;;;;;;;;IAuC5C;;;OAGG;IACH,OAAO,CAAC,YAAY;IA0CpB;;;OAGG;YACW,QAAQ;IAqBtB,OAAO,KAAK,iBAAiB,GAE5B;YAEa,gBAAgB;YAShB,mBAAmB;YAgBnB,gBAAgB;YA+BhB,aAAa;YAwBb,wBAAwB;CAWvC"}
@@ -5,7 +5,6 @@ import { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, nonNullable, chalk, log,
5
5
  import { MultiMap } from '../../utils/multimap.js';
6
6
  import { getPathInProject } from '../settings.js';
7
7
  import { INTERNAL_EDGE_FUNCTIONS_FOLDER } from './consts.js';
8
- const featureFlags = { edge_functions_correct_order: true };
9
8
  /**
10
9
  * Helper method which, given a edge bundler graph module and an index of modules by path, traverses its dependency tree
11
10
  * and returns an array of all of ist local dependencies
@@ -31,7 +30,7 @@ function traverseLocalDependencies({ dependencies = [] }, modulesByPath) {
31
30
  });
32
31
  }
33
32
  export class EdgeFunctionsRegistry {
34
- constructor({ bundler, config, configPath, directories, env, getUpdatedConfig, importMapFromTOML, projectDir, runIsolate, servePath, }) {
33
+ constructor({ bundler, config, configPath, directories, env, featureFlags, getUpdatedConfig, importMapFromTOML, projectDir, runIsolate, servePath, }) {
35
34
  this.buildError = null;
36
35
  this.declarationsFromDeployConfig = [];
37
36
  // Mapping file URLs to names of functions that use them as dependencies.
@@ -48,6 +47,7 @@ export class EdgeFunctionsRegistry {
48
47
  this.bundler = bundler;
49
48
  this.configPath = configPath;
50
49
  this.directories = directories;
50
+ this.featureFlags = featureFlags;
51
51
  this.getUpdatedConfig = getUpdatedConfig;
52
52
  this.runIsolate = runIsolate;
53
53
  this.servePath = servePath;
@@ -124,13 +124,13 @@ export class EdgeFunctionsRegistry {
124
124
  * found in both internal and user functions.
125
125
  */
126
126
  buildRoutes(internalFunctionConfigs, userFunctionConfigs) {
127
- const declarations = this.bundler.mergeDeclarations(this.declarationsFromTOML, userFunctionConfigs, internalFunctionConfigs, this.declarationsFromDeployConfig, featureFlags);
127
+ const declarations = this.bundler.mergeDeclarations(this.declarationsFromTOML, userFunctionConfigs, internalFunctionConfigs, this.declarationsFromDeployConfig, this.featureFlags);
128
128
  const { declarationsWithoutFunction, manifest, unroutedFunctions } = this.bundler.generateManifest({
129
129
  declarations,
130
130
  userFunctionConfig: userFunctionConfigs,
131
131
  internalFunctionConfig: internalFunctionConfigs,
132
132
  functions: this.functions,
133
- featureFlags,
133
+ featureFlags: this.featureFlags,
134
134
  });
135
135
  const routes = [...manifest.routes, ...manifest.post_cache_routes].map((route) => ({
136
136
  ...route,
@@ -1,5 +1,7 @@
1
- export declare const createFormSubmissionHandler: ({ functionsRegistry, siteUrl }: {
2
- functionsRegistry: any;
3
- siteUrl: any;
4
- }) => (req: any, res: any, next: any) => Promise<any>;
1
+ import type { RequestHandler } from 'express';
2
+ import type { FunctionsRegistry } from './registry.js';
3
+ export declare const createFormSubmissionHandler: ({ functionsRegistry, siteUrl, }: {
4
+ functionsRegistry: FunctionsRegistry;
5
+ siteUrl: string;
6
+ }) => RequestHandler;
5
7
  //# sourceMappingURL=form-submissions-handler.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form-submissions-handler.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/form-submissions-handler.ts"],"names":[],"mappings":"AAgCA,eAAO,MAAM,2BAA2B;;;qDAyIvC,CAAA"}
1
+ {"version":3,"file":"form-submissions-handler.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/form-submissions-handler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAS7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAqBtD,eAAO,MAAM,2BAA2B;uBAInB,iBAAiB;aAC3B,MAAM;MACb,cAwIH,CAAA"}
@@ -22,13 +22,11 @@ const getFormHandler = function ({ functionsRegistry }) {
22
22
  }
23
23
  return handlers[0];
24
24
  };
25
- // @ts-expect-error TS(7031) FIXME: Binding element 'functionsRegistry' implicitly has... Remove this comment to see the full error message
26
- export const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl }) {
27
- // @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
25
+ export const createFormSubmissionHandler = function ({ functionsRegistry, siteUrl, }) {
28
26
  return async function formSubmissionHandler(req, res, next) {
29
27
  if (req.url.startsWith('/.netlify/') ||
30
28
  req.method !== 'POST' ||
31
- (await functionsRegistry.getFunctionForURLPath(req.url, req.method)))
29
+ (await functionsRegistry.getFunctionForURLPath(req.url, req.method, () => Promise.resolve(false))))
32
30
  return next();
33
31
  const fakeRequest = new Readable({
34
32
  read() {
@@ -137,7 +135,7 @@ export const createFormSubmissionHandler = function ({ functionsRegistry, siteUr
137
135
  req.body = data;
138
136
  req.headers = {
139
137
  ...req.headers,
140
- 'content-length': data.length,
138
+ 'content-length': String(data.length),
141
139
  'content-type': 'application/json',
142
140
  'x-netlify-original-pathname': originalUrl.pathname,
143
141
  'x-netlify-original-search': originalUrl.search,
@@ -9,7 +9,7 @@ export default class NetlifyFunction {
9
9
  private readonly blobsContext;
10
10
  private readonly timeoutBackground;
11
11
  private readonly timeoutSynchronous;
12
- private readonly isBackground;
12
+ readonly isBackground: boolean;
13
13
  private buildQueue?;
14
14
  private buildData?;
15
15
  buildError: Error | null;
@@ -1 +1 @@
1
- {"version":3,"file":"netlify-function.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/netlify-function.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,SAAgB,IAAI,EAAE,MAAM,CAAA;IAC5B,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC,SAAgB,WAAW,EAAE,MAAM,CAAA;IACnC,SAAgB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjC,SAAgB,OAAO,EAAE,MAAM,CAAA;IAE/B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAQ;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAI3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC,OAAO,CAAC,UAAU,CAAC,CAAiB;IACpC,OAAO,CAAC,SAAS,CAAC,CAAQ;IACnB,UAAU,EAAE,KAAK,GAAG,IAAI,CAAO;IAItC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;gBAEjC,EAEV,YAAY,EAEZ,MAAM,EAEN,SAAS,EAET,WAAW,EAEX,QAAQ,EAER,IAAI,EAEJ,WAAW,EAEX,OAAO,EAEP,QAAQ,EAER,iBAAiB,EAEjB,kBAAkB,GACnB;;;;;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AAoB;gBAEjC,EAEV,YAAY,EAEZ,MAAM,EAEN,SAAS,EAET,WAAW,EAEX,QAAQ,EAER,IAAI,EAEJ,WAAW,EAEX,OAAO,EAEP,QAAQ,EAER,iBAAiB,EAEjB,kBAAkB,GACnB;;;;;;;;;;;;KAAA;IAuBD,IAAI,QAAQ,kBAMX;IAED,uBAAuB;IAqBvB,YAAY;IAMN,WAAW;IAMjB,WAAW;IAIX,YAAY;IAQN,UAAU;IAeV,KAAK,CAAC,EAAE,KAAK,EAAE;;KAAA;;;;;;;;;;;;IA2Cf,YAAY;IAQlB,eAAe,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC;;;;IAWlC,MAAM,CAAC,KAAK,KAAK,EAAE,OAAO,KAAK;;;;;;;IAmCrC;;;OAGG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC;IAoCzF,IAAI,iBAAiB,QAEpB;IAED,IAAI,GAAG,WAWN;CACF"}
@@ -200,7 +200,7 @@ export default class NetlifyFunction {
200
200
  await this.buildQueue;
201
201
  let path = rawPath !== '/' && rawPath.endsWith('/') ? rawPath.slice(0, -1) : rawPath;
202
202
  path = path.toLowerCase();
203
- const { routes = [] } = this.buildData;
203
+ const { routes = [] } = this.buildData ?? {};
204
204
  // @ts-expect-error TS(7031) FIXME: Binding element 'expression' implicitly has an 'an... Remove this comment to see the full error message
205
205
  const route = routes.find(({ expression, literal, methods }) => {
206
206
  if (methods.length !== 0 && !methods.includes(method)) {
@@ -212,7 +212,7 @@ export class FunctionsRegistry {
212
212
  if (!func) {
213
213
  return { func: null, route: null };
214
214
  }
215
- const { routes = [] } = await func.getBuildData();
215
+ const { routes = [] } = (await func.getBuildData()) ?? {};
216
216
  if (routes.length !== 0) {
217
217
  // @ts-expect-error TS(7006) FIXME: Parameter 'route' implicitly has an 'any' type.
218
218
  const paths = routes.map((route) => chalk.underline(route.pattern)).join(', ');
@@ -44,7 +44,7 @@ export const getBuildFunction = async ({ config, directory, errorExit, func, pro
44
44
  const workerURL = new URL('worker.js', import.meta.url);
45
45
  // @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
46
46
  export const invokeFunction = async ({ context, environment, event, func, timeout }) => {
47
- if (func.buildData.runtimeAPIVersion !== 2) {
47
+ if (func.buildData?.runtimeAPIVersion !== 2) {
48
48
  return await invokeFunctionDirectly({ context, event, func, timeout });
49
49
  }
50
50
  const workerData = {
@@ -1,20 +1,31 @@
1
+ import { type RequestHandler } from 'express';
2
+ import type BaseCommand from '../../commands/base-command.js';
3
+ import type { $TSFixMe } from '../../commands/types.js';
4
+ import type { BlobsContext } from '../blobs/blobs.js';
1
5
  import { FunctionsRegistry } from './registry.js';
2
- export declare const createHandler: (options: any) => (request: any, response: any) => Promise<void>;
3
- /**
4
- *
5
- * @param {object} options
6
- * @param {import("../blobs/blobs.js").BlobsContext} options.blobsContext
7
- * @param {import('../../commands/base-command.js').default} options.command
8
- * @param {*} options.capabilities
9
- * @param {*} options.config
10
- * @param {boolean} options.debug
11
- * @param {*} options.loadDistFunctions
12
- * @param {*} options.settings
13
- * @param {*} options.site
14
- * @param {*} options.siteInfo
15
- * @param {string} options.siteUrl
16
- * @param {*} options.timeouts
17
- * @returns {Promise<import('./registry.js').FunctionsRegistry | undefined>}
18
- */
19
- export declare const startFunctionsServer: (options: any) => Promise<FunctionsRegistry | undefined>;
6
+ export declare const createHandler: (options: GetFunctionsServerOptions) => RequestHandler;
7
+ interface GetFunctionsServerOptions {
8
+ functionsRegistry: FunctionsRegistry;
9
+ siteUrl: string;
10
+ siteInfo?: $TSFixMe;
11
+ accountId: string;
12
+ geoCountry: string;
13
+ offline: boolean;
14
+ state: $TSFixMe;
15
+ config: $TSFixMe;
16
+ geolocationMode: 'cache' | 'update' | 'mock';
17
+ }
18
+ export declare const startFunctionsServer: (options: {
19
+ blobsContext: BlobsContext;
20
+ command: BaseCommand;
21
+ config: $TSFixMe;
22
+ capabilities: $TSFixMe;
23
+ debug: boolean;
24
+ loadDistFunctions?: boolean;
25
+ settings: $TSFixMe;
26
+ site: $TSFixMe;
27
+ siteInfo: $TSFixMe;
28
+ timeouts: $TSFixMe;
29
+ } & Omit<GetFunctionsServerOptions, 'functionsRegistry'>) => Promise<FunctionsRegistry | undefined>;
30
+ export {};
20
31
  //# sourceMappingURL=server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/server.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AA0DjD,eAAO,MAAM,aAAa,kEA0JzB,CAAA;AA8BD;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,oBAAoB,0DAiFhC,CAAA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../../src/lib/functions/server.ts"],"names":[],"mappings":"AAIA,OAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAKtD,OAAO,KAAK,WAAW,MAAM,gCAAgC,CAAA;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAUvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAMrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAyDjD,eAAO,MAAM,aAAa,YAAsB,yBAAyB,KAAG,cA8J3E,CAAA;AAED,UAAU,yBAAyB;IACjC,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,QAAQ,CAAA;IACf,MAAM,EAAE,QAAQ,CAAA;IAChB,eAAe,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;CAC7C;AA4BD,eAAO,MAAM,oBAAoB,YACtB;IACP,YAAY,EAAE,YAAY,CAAA;IAC1B,OAAO,EAAE,WAAW,CAAA;IACpB,MAAM,EAAE,QAAQ,CAAA;IAChB,YAAY,EAAE,QAAQ,CAAA;IACtB,KAAK,EAAE,OAAO,CAAA;IACd,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,QAAQ,CAAA;IACd,QAAQ,EAAE,QAAQ,CAAA;IAClB,QAAQ,EAAE,QAAQ,CAAA;CACnB,GAAG,KAAK,yBAAyB,EAAE,mBAAmB,CAAC,KACvD,QAAQ,iBAAiB,GAAG,SAAS,CAiFvC,CAAA"}
@@ -64,10 +64,8 @@ const hasBody = (req) =>
64
64
  (req.header('transfer-encoding') !== undefined || !isNaN(req.header('content-length'))) &&
65
65
  // we expect a string or a buffer, because we use the two bodyParsers(text, raw) from express
66
66
  (typeof req.body === 'string' || Buffer.isBuffer(req.body));
67
- // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
68
67
  export const createHandler = function (options) {
69
68
  const { functionsRegistry } = options;
70
- // @ts-expect-error TS(7006) FIXME: Parameter 'request' implicitly has an 'any' type.
71
69
  return async function handler(request, response) {
72
70
  // If these headers are set, it means we've already matched a function and we
73
71
  // can just grab its name directly. We delete the header from the request
@@ -76,13 +74,18 @@ export const createHandler = function (options) {
76
74
  delete request.headers[NFFunctionName];
77
75
  const functionRoute = request.header(NFFunctionRoute);
78
76
  delete request.headers[NFFunctionRoute];
79
- // If we didn't match a function with a custom route, let's try to match
80
- // using the fixed URL format.
77
+ // If there's still no function found, we check the functionsRegistry again.
78
+ // This is needed for the functions:serve command, where the dev server that normally does the matching doesn't run.
79
+ // It also matches the default URL (.netlify/functions/builders)
81
80
  if (!functionName) {
82
- const cleanPath = request.path.replace(/^\/.netlify\/(functions|builders)/, '');
83
- functionName = cleanPath.split('/').find(Boolean);
81
+ const match = await functionsRegistry.getFunctionForURLPath(request.url, request.method,
82
+ // we're pretending there's no static file at the same URL.
83
+ // This is wrong, but in local dev we already did the matching
84
+ // in a downstream server where we had access to the file system, so this never hits.
85
+ () => Promise.resolve(false));
86
+ functionName = match?.func?.name;
84
87
  }
85
- const func = functionsRegistry.get(functionName);
88
+ const func = functionsRegistry.get(functionName ?? '');
86
89
  if (func === undefined) {
87
90
  response.statusCode = 404;
88
91
  response.end('Function not found...');
@@ -99,15 +102,13 @@ export const createHandler = function (options) {
99
102
  body = request.body.toString(isBase64Encoded ? 'base64' : 'utf8');
100
103
  }
101
104
  let remoteAddress = request.header('x-forwarded-for') || request.connection.remoteAddress || '';
102
- remoteAddress = remoteAddress
103
- .split(remoteAddress.includes('.') ? ':' : ',')
104
- .pop()
105
- .trim();
106
- let requestPath = request.path;
107
- if (request.header('x-netlify-original-pathname')) {
108
- requestPath = request.header('x-netlify-original-pathname');
109
- delete request.headers['x-netlify-original-pathname'];
110
- }
105
+ remoteAddress =
106
+ remoteAddress
107
+ .split(remoteAddress.includes('.') ? ':' : ',')
108
+ .pop()
109
+ ?.trim() ?? '';
110
+ const requestPath = request.header('x-netlify-original-pathname') ?? request.path;
111
+ delete request.headers['x-netlify-original-pathname'];
111
112
  let requestQuery = request.query;
112
113
  if (request.header('x-netlify-original-search')) {
113
114
  const newRequestQuery = {};
@@ -120,7 +121,7 @@ export const createHandler = function (options) {
120
121
  delete request.headers['x-netlify-original-search'];
121
122
  }
122
123
  const queryParams = Object.entries(requestQuery).reduce((prev, [key, value]) => ({ ...prev, [key]: Array.isArray(value) ? value : [value] }), {});
123
- const geoLocation = await getGeoLocation({ ...options, mode: options.geo });
124
+ const geoLocation = await getGeoLocation({ ...options, mode: options.geolocationMode });
124
125
  const headers = Object.entries({
125
126
  ...request.headers,
126
127
  'client-ip': [remoteAddress],
@@ -191,9 +192,8 @@ export const createHandler = function (options) {
191
192
  }
192
193
  };
193
194
  };
194
- // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
195
195
  const getFunctionsServer = (options) => {
196
- const { buildersPrefix = '', functionsPrefix = '', functionsRegistry, siteUrl } = options;
196
+ const { functionsRegistry, siteUrl } = options;
197
197
  const app = express();
198
198
  const functionHandler = createHandler(options);
199
199
  app.set('query parser', 'simple');
@@ -206,27 +206,9 @@ const getFunctionsServer = (options) => {
206
206
  app.use(expressLogging(console, {
207
207
  blacklist: ['/favicon.ico'],
208
208
  }));
209
- app.all(`${functionsPrefix}*`, functionHandler);
210
- app.all(`${buildersPrefix}*`, functionHandler);
209
+ app.all('*', functionHandler);
211
210
  return app;
212
211
  };
213
- /**
214
- *
215
- * @param {object} options
216
- * @param {import("../blobs/blobs.js").BlobsContext} options.blobsContext
217
- * @param {import('../../commands/base-command.js').default} options.command
218
- * @param {*} options.capabilities
219
- * @param {*} options.config
220
- * @param {boolean} options.debug
221
- * @param {*} options.loadDistFunctions
222
- * @param {*} options.settings
223
- * @param {*} options.site
224
- * @param {*} options.siteInfo
225
- * @param {string} options.siteUrl
226
- * @param {*} options.timeouts
227
- * @returns {Promise<import('./registry.js').FunctionsRegistry | undefined>}
228
- */
229
- // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
230
212
  export const startFunctionsServer = async (options) => {
231
213
  const { blobsContext, capabilities, command, config, debug, loadDistFunctions, settings, site, siteInfo, siteUrl, timeouts, } = options;
232
214
  const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root });
@@ -283,29 +265,20 @@ export const startFunctionsServer = async (options) => {
283
265
  timeouts,
284
266
  });
285
267
  await functionsRegistry.scan(functionsDirectories);
286
- const server = getFunctionsServer(Object.assign(options, { functionsRegistry }));
268
+ const server = getFunctionsServer({ ...options, functionsRegistry });
287
269
  await startWebServer({ server, settings, debug });
288
270
  return functionsRegistry;
289
271
  };
290
- /**
291
- *
292
- * @param {object} config
293
- * @param {boolean} config.debug
294
- * @param {ReturnType<Awaited<typeof getFunctionsServer>>} config.server
295
- * @param {*} config.settings
296
- */
297
- // @ts-expect-error TS(7031) FIXME: Binding element 'debug' implicitly has an 'any' ty... Remove this comment to see the full error message
298
- const startWebServer = async ({ debug, server, settings }) => {
299
- await new Promise((/** @type {(resolve: void) => void} */ resolve) => {
272
+ const startWebServer = async ({ debug, server, settings, }) => {
273
+ await new Promise((resolve) => {
300
274
  // @ts-expect-error TS(7006) FIXME: Parameter 'err' implicitly has an 'any' type.
301
- server.listen(settings.functionsPort, (/** @type {unknown} */ err) => {
275
+ server.listen(settings.functionsPort, (err) => {
302
276
  if (err) {
303
277
  errorExit(`${NETLIFYDEVERR} Unable to start functions server: ${err}`);
304
278
  }
305
279
  else if (debug) {
306
280
  log(`${NETLIFYDEVLOG} Functions server is listening on ${settings.functionsPort}`);
307
281
  }
308
- // @ts-expect-error TS(2794) FIXME: Expected 1 arguments, but got 0. Did you forget to... Remove this comment to see the full error message
309
282
  resolve();
310
283
  });
311
284
  });