@netlify/dev 4.1.2 → 4.1.4

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/main.cjs CHANGED
@@ -345,37 +345,50 @@ var NetlifyDev = class {
345
345
  this.#projectRoot = projectRoot;
346
346
  this.#staticHandlerAdditionalDirectories = options.staticFiles?.directories ?? [];
347
347
  }
348
- async handleInEphemeralDirectory(matchRequest, getHandleRequest, destPath, options = {}) {
349
- const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(matchRequest);
348
+ /**
349
+ * Runs a request through the Netlify request chain and returns a `Response`
350
+ * if there's a match. We must not disturb the incoming request unless we
351
+ * know we will be returning a response, so this method takes a read-only
352
+ * request that is safe to access (used for matching) and a getter for the
353
+ * actual request (used for handling matches).
354
+ *
355
+ * @param readRequest Read-only version of the request (without a body)
356
+ * @param getWriteRequest Getter for the actual request (with a body)
357
+ * @param destPath Destination directory for compiled files
358
+ * @param options Options object
359
+ * @returns
360
+ */
361
+ async handleInEphemeralDirectory(readRequest, getWriteRequest, destPath, options = {}) {
362
+ const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(readRequest);
350
363
  if (edgeFunctionMatch) {
351
364
  return {
352
- response: await edgeFunctionMatch.handle(getHandleRequest()),
365
+ response: await edgeFunctionMatch.handle(getWriteRequest()),
353
366
  type: "edge-function"
354
367
  };
355
368
  }
356
- const functionMatch = await this.#functionsHandler?.match(matchRequest, destPath);
369
+ const functionMatch = await this.#functionsHandler?.match(readRequest, destPath);
357
370
  if (functionMatch) {
358
371
  if (functionMatch.preferStatic) {
359
- const staticMatch2 = await this.#staticHandler?.match(matchRequest);
372
+ const staticMatch2 = await this.#staticHandler?.match(readRequest);
360
373
  if (staticMatch2) {
361
374
  const response = await staticMatch2.handle();
362
- await this.#headersHandler?.apply(matchRequest, response, options.headersCollector);
375
+ await this.#headersHandler?.apply(readRequest, response, options.headersCollector);
363
376
  return { response, type: "static" };
364
377
  }
365
378
  }
366
- return { response: await functionMatch.handle(getHandleRequest()), type: "function" };
379
+ return { response: await functionMatch.handle(getWriteRequest()), type: "function" };
367
380
  }
368
- const redirectMatch = await this.#redirectsHandler?.match(matchRequest);
381
+ const redirectMatch = await this.#redirectsHandler?.match(readRequest);
369
382
  if (redirectMatch) {
370
383
  const functionMatch2 = await this.#functionsHandler?.match(new Request(redirectMatch.target), destPath);
371
384
  if (functionMatch2 && !functionMatch2.preferStatic) {
372
385
  return {
373
- response: await functionMatch2.handle(getHandleRequest()),
386
+ response: await functionMatch2.handle(getWriteRequest()),
374
387
  type: "function"
375
388
  };
376
389
  }
377
390
  const response = await this.#redirectsHandler?.handle(
378
- getHandleRequest(),
391
+ getWriteRequest(),
379
392
  redirectMatch,
380
393
  async (maybeStaticFile) => {
381
394
  const staticMatch2 = await this.#staticHandler?.match(maybeStaticFile);
@@ -393,17 +406,17 @@ var NetlifyDev = class {
393
406
  return { response, type: "redirect" };
394
407
  }
395
408
  }
396
- const { pathname } = new URL(matchRequest.url);
409
+ const { pathname } = new URL(readRequest.url);
397
410
  if (pathname.startsWith("/.netlify/images")) {
398
411
  this.#logger.error(
399
412
  `The Netlify Image CDN is currently only supported in the Netlify CLI. Run ${(0, import_dev_utils.netlifyCommand)("npx netlify dev")} to get started.`
400
413
  );
401
414
  return;
402
415
  }
403
- const staticMatch = await this.#staticHandler?.match(matchRequest);
416
+ const staticMatch = await this.#staticHandler?.match(readRequest);
404
417
  if (staticMatch) {
405
418
  const response = await staticMatch.handle();
406
- await this.#headersHandler?.apply(matchRequest, response, options.headersCollector);
419
+ await this.#headersHandler?.apply(readRequest, response, options.headersCollector);
407
420
  return { response, type: "static" };
408
421
  }
409
422
  }
@@ -424,10 +437,19 @@ var NetlifyDev = class {
424
437
  });
425
438
  return config;
426
439
  }
440
+ /**
441
+ * Runs a `Request` through the Netlify request chain. If there is a match,
442
+ * it returns the resulting `Response` object; if not, it returns `undefined`.
443
+ */
427
444
  async handle(request, options = {}) {
428
445
  const result = await this.handleAndIntrospect(request, options);
429
446
  return result?.response;
430
447
  }
448
+ /**
449
+ * Runs a `Request` through the Netlify request chain. If there is a match,
450
+ * it returns an object with the resulting `Response` object and information
451
+ * about the match; if not, it returns `undefined`.
452
+ */
431
453
  async handleAndIntrospect(request, options = {}) {
432
454
  await import_node_fs2.promises.mkdir(this.#functionsServePath, { recursive: true });
433
455
  const destPath = await import_node_fs2.promises.mkdtemp(import_node_path2.default.join(this.#functionsServePath, `_`));
@@ -443,6 +465,11 @@ var NetlifyDev = class {
443
465
  }
444
466
  }
445
467
  }
468
+ /**
469
+ * Runs a Node.js `IncomingMessage` through the Netlify request chain. If
470
+ * there is a match, it returns an object with the resulting `Response`
471
+ * object and information about the match; if not, it returns `undefined`.
472
+ */
446
473
  async handleAndIntrospectNodeRequest(request, options = {}) {
447
474
  await import_node_fs2.promises.mkdir(this.#functionsServePath, { recursive: true });
448
475
  const destPath = await import_node_fs2.promises.mkdtemp(import_node_path2.default.join(this.#functionsServePath, `_`));
package/dist/main.d.cts CHANGED
@@ -87,13 +87,40 @@ type ResponseType = 'edge-function' | 'function' | 'redirect' | 'static';
87
87
  declare class NetlifyDev {
88
88
  #private;
89
89
  constructor(options: NetlifyDevOptions);
90
+ /**
91
+ * Runs a request through the Netlify request chain and returns a `Response`
92
+ * if there's a match. We must not disturb the incoming request unless we
93
+ * know we will be returning a response, so this method takes a read-only
94
+ * request that is safe to access (used for matching) and a getter for the
95
+ * actual request (used for handling matches).
96
+ *
97
+ * @param readRequest Read-only version of the request (without a body)
98
+ * @param getWriteRequest Getter for the actual request (with a body)
99
+ * @param destPath Destination directory for compiled files
100
+ * @param options Options object
101
+ * @returns
102
+ */
90
103
  private handleInEphemeralDirectory;
91
104
  private getConfig;
105
+ /**
106
+ * Runs a `Request` through the Netlify request chain. If there is a match,
107
+ * it returns the resulting `Response` object; if not, it returns `undefined`.
108
+ */
92
109
  handle(request: Request, options?: HandleOptions): Promise<Response | undefined>;
110
+ /**
111
+ * Runs a `Request` through the Netlify request chain. If there is a match,
112
+ * it returns an object with the resulting `Response` object and information
113
+ * about the match; if not, it returns `undefined`.
114
+ */
93
115
  handleAndIntrospect(request: Request, options?: HandleOptions): Promise<{
94
116
  response: Response;
95
117
  type: ResponseType;
96
118
  } | undefined>;
119
+ /**
120
+ * Runs a Node.js `IncomingMessage` through the Netlify request chain. If
121
+ * there is a match, it returns an object with the resulting `Response`
122
+ * object and information about the match; if not, it returns `undefined`.
123
+ */
97
124
  handleAndIntrospectNodeRequest(request: IncomingMessage, options?: HandleOptions): Promise<{
98
125
  response: Response;
99
126
  type: ResponseType;
package/dist/main.d.ts CHANGED
@@ -87,13 +87,40 @@ type ResponseType = 'edge-function' | 'function' | 'redirect' | 'static';
87
87
  declare class NetlifyDev {
88
88
  #private;
89
89
  constructor(options: NetlifyDevOptions);
90
+ /**
91
+ * Runs a request through the Netlify request chain and returns a `Response`
92
+ * if there's a match. We must not disturb the incoming request unless we
93
+ * know we will be returning a response, so this method takes a read-only
94
+ * request that is safe to access (used for matching) and a getter for the
95
+ * actual request (used for handling matches).
96
+ *
97
+ * @param readRequest Read-only version of the request (without a body)
98
+ * @param getWriteRequest Getter for the actual request (with a body)
99
+ * @param destPath Destination directory for compiled files
100
+ * @param options Options object
101
+ * @returns
102
+ */
90
103
  private handleInEphemeralDirectory;
91
104
  private getConfig;
105
+ /**
106
+ * Runs a `Request` through the Netlify request chain. If there is a match,
107
+ * it returns the resulting `Response` object; if not, it returns `undefined`.
108
+ */
92
109
  handle(request: Request, options?: HandleOptions): Promise<Response | undefined>;
110
+ /**
111
+ * Runs a `Request` through the Netlify request chain. If there is a match,
112
+ * it returns an object with the resulting `Response` object and information
113
+ * about the match; if not, it returns `undefined`.
114
+ */
93
115
  handleAndIntrospect(request: Request, options?: HandleOptions): Promise<{
94
116
  response: Response;
95
117
  type: ResponseType;
96
118
  } | undefined>;
119
+ /**
120
+ * Runs a Node.js `IncomingMessage` through the Netlify request chain. If
121
+ * there is a match, it returns an object with the resulting `Response`
122
+ * object and information about the match; if not, it returns `undefined`.
123
+ */
97
124
  handleAndIntrospectNodeRequest(request: IncomingMessage, options?: HandleOptions): Promise<{
98
125
  response: Response;
99
126
  type: ResponseType;
package/dist/main.js CHANGED
@@ -318,37 +318,50 @@ var NetlifyDev = class {
318
318
  this.#projectRoot = projectRoot;
319
319
  this.#staticHandlerAdditionalDirectories = options.staticFiles?.directories ?? [];
320
320
  }
321
- async handleInEphemeralDirectory(matchRequest, getHandleRequest, destPath, options = {}) {
322
- const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(matchRequest);
321
+ /**
322
+ * Runs a request through the Netlify request chain and returns a `Response`
323
+ * if there's a match. We must not disturb the incoming request unless we
324
+ * know we will be returning a response, so this method takes a read-only
325
+ * request that is safe to access (used for matching) and a getter for the
326
+ * actual request (used for handling matches).
327
+ *
328
+ * @param readRequest Read-only version of the request (without a body)
329
+ * @param getWriteRequest Getter for the actual request (with a body)
330
+ * @param destPath Destination directory for compiled files
331
+ * @param options Options object
332
+ * @returns
333
+ */
334
+ async handleInEphemeralDirectory(readRequest, getWriteRequest, destPath, options = {}) {
335
+ const edgeFunctionMatch = await this.#edgeFunctionsHandler?.match(readRequest);
323
336
  if (edgeFunctionMatch) {
324
337
  return {
325
- response: await edgeFunctionMatch.handle(getHandleRequest()),
338
+ response: await edgeFunctionMatch.handle(getWriteRequest()),
326
339
  type: "edge-function"
327
340
  };
328
341
  }
329
- const functionMatch = await this.#functionsHandler?.match(matchRequest, destPath);
342
+ const functionMatch = await this.#functionsHandler?.match(readRequest, destPath);
330
343
  if (functionMatch) {
331
344
  if (functionMatch.preferStatic) {
332
- const staticMatch2 = await this.#staticHandler?.match(matchRequest);
345
+ const staticMatch2 = await this.#staticHandler?.match(readRequest);
333
346
  if (staticMatch2) {
334
347
  const response = await staticMatch2.handle();
335
- await this.#headersHandler?.apply(matchRequest, response, options.headersCollector);
348
+ await this.#headersHandler?.apply(readRequest, response, options.headersCollector);
336
349
  return { response, type: "static" };
337
350
  }
338
351
  }
339
- return { response: await functionMatch.handle(getHandleRequest()), type: "function" };
352
+ return { response: await functionMatch.handle(getWriteRequest()), type: "function" };
340
353
  }
341
- const redirectMatch = await this.#redirectsHandler?.match(matchRequest);
354
+ const redirectMatch = await this.#redirectsHandler?.match(readRequest);
342
355
  if (redirectMatch) {
343
356
  const functionMatch2 = await this.#functionsHandler?.match(new Request(redirectMatch.target), destPath);
344
357
  if (functionMatch2 && !functionMatch2.preferStatic) {
345
358
  return {
346
- response: await functionMatch2.handle(getHandleRequest()),
359
+ response: await functionMatch2.handle(getWriteRequest()),
347
360
  type: "function"
348
361
  };
349
362
  }
350
363
  const response = await this.#redirectsHandler?.handle(
351
- getHandleRequest(),
364
+ getWriteRequest(),
352
365
  redirectMatch,
353
366
  async (maybeStaticFile) => {
354
367
  const staticMatch2 = await this.#staticHandler?.match(maybeStaticFile);
@@ -366,17 +379,17 @@ var NetlifyDev = class {
366
379
  return { response, type: "redirect" };
367
380
  }
368
381
  }
369
- const { pathname } = new URL(matchRequest.url);
382
+ const { pathname } = new URL(readRequest.url);
370
383
  if (pathname.startsWith("/.netlify/images")) {
371
384
  this.#logger.error(
372
385
  `The Netlify Image CDN is currently only supported in the Netlify CLI. Run ${netlifyCommand("npx netlify dev")} to get started.`
373
386
  );
374
387
  return;
375
388
  }
376
- const staticMatch = await this.#staticHandler?.match(matchRequest);
389
+ const staticMatch = await this.#staticHandler?.match(readRequest);
377
390
  if (staticMatch) {
378
391
  const response = await staticMatch.handle();
379
- await this.#headersHandler?.apply(matchRequest, response, options.headersCollector);
392
+ await this.#headersHandler?.apply(readRequest, response, options.headersCollector);
380
393
  return { response, type: "static" };
381
394
  }
382
395
  }
@@ -397,10 +410,19 @@ var NetlifyDev = class {
397
410
  });
398
411
  return config;
399
412
  }
413
+ /**
414
+ * Runs a `Request` through the Netlify request chain. If there is a match,
415
+ * it returns the resulting `Response` object; if not, it returns `undefined`.
416
+ */
400
417
  async handle(request, options = {}) {
401
418
  const result = await this.handleAndIntrospect(request, options);
402
419
  return result?.response;
403
420
  }
421
+ /**
422
+ * Runs a `Request` through the Netlify request chain. If there is a match,
423
+ * it returns an object with the resulting `Response` object and information
424
+ * about the match; if not, it returns `undefined`.
425
+ */
404
426
  async handleAndIntrospect(request, options = {}) {
405
427
  await fs2.mkdir(this.#functionsServePath, { recursive: true });
406
428
  const destPath = await fs2.mkdtemp(path2.join(this.#functionsServePath, `_`));
@@ -416,6 +438,11 @@ var NetlifyDev = class {
416
438
  }
417
439
  }
418
440
  }
441
+ /**
442
+ * Runs a Node.js `IncomingMessage` through the Netlify request chain. If
443
+ * there is a match, it returns an object with the resulting `Response`
444
+ * object and information about the match; if not, it returns `undefined`.
445
+ */
419
446
  async handleAndIntrospectNodeRequest(request, options = {}) {
420
447
  await fs2.mkdir(this.#functionsServePath, { recursive: true });
421
448
  const destPath = await fs2.mkdtemp(path2.join(this.#functionsServePath, `_`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/dev",
3
- "version": "4.1.2",
3
+ "version": "4.1.4",
4
4
  "description": "Emulation of the Netlify environment for local development",
5
5
  "type": "module",
6
6
  "engines": {
@@ -47,19 +47,19 @@
47
47
  "author": "Netlify Inc.",
48
48
  "devDependencies": {
49
49
  "@netlify/api": "^14.0.3",
50
- "@netlify/types": "2.0.1",
50
+ "@netlify/types": "2.0.2",
51
51
  "tsup": "^8.0.0",
52
52
  "vitest": "^3.0.0"
53
53
  },
54
54
  "dependencies": {
55
55
  "@netlify/blobs": "9.1.5",
56
- "@netlify/config": "^23.0.8",
56
+ "@netlify/config": "^23.0.10",
57
57
  "@netlify/dev-utils": "3.1.1",
58
- "@netlify/edge-functions": "2.14.1",
59
- "@netlify/functions": "4.1.2",
58
+ "@netlify/edge-functions": "2.14.3",
59
+ "@netlify/functions": "4.1.3",
60
60
  "@netlify/headers": "2.0.1",
61
61
  "@netlify/redirects": "3.0.1",
62
- "@netlify/runtime": "4.0.1",
62
+ "@netlify/runtime": "4.0.2",
63
63
  "@netlify/static": "3.0.1",
64
64
  "ulid": "^3.0.0"
65
65
  }