@netlify/functions-dev 1.1.11 → 1.2.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/main.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { DevEventHandler, Geolocation } from '@netlify/dev-utils';
1
+ import { Reactive, DevEventHandler, FileWatcher, Geolocation } from '@netlify/dev-utils';
2
2
  import { Manifest } from '@netlify/zip-it-and-ship-it';
3
3
  import { EnvironmentContext } from '@netlify/blobs';
4
4
 
5
5
  interface FunctionRegistryOptions {
6
6
  blobsContext?: EnvironmentContext;
7
7
  destPath: string;
8
- config: any;
8
+ config: Reactive<any>;
9
9
  debug?: boolean;
10
10
  eventHandler?: DevEventHandler;
11
11
  frameworksAPIFunctionsPath?: string;
@@ -17,7 +17,7 @@ interface FunctionRegistryOptions {
17
17
  syncFunctions?: number;
18
18
  backgroundFunctions?: number;
19
19
  };
20
- watch?: boolean;
20
+ fileWatcher?: FileWatcher;
21
21
  }
22
22
 
23
23
  interface FunctionMatch {
package/dist/main.js CHANGED
@@ -6,7 +6,6 @@ import { stat } from "fs/promises";
6
6
  import { createRequire as createRequire2 } from "module";
7
7
  import { basename as basename2, extname as extname2, isAbsolute, join, resolve } from "path";
8
8
  import { env } from "process";
9
- import { watchDebounced } from "@netlify/dev-utils";
10
9
  import { SYNCHRONOUS_FUNCTION_TIMEOUT, BACKGROUND_FUNCTION_TIMEOUT } from "@netlify/functions";
11
10
  import { listFunctions } from "@netlify/zip-it-and-ship-it";
12
11
  import extractZip from "extract-zip";
@@ -657,8 +656,8 @@ var FunctionsRegistry = class {
657
656
  */
658
657
  functions = /* @__PURE__ */ new Map();
659
658
  /**
660
- * File watchers for function files. Maps function names to objects built
661
- * by the `watchDebounced` utility.
659
+ * File watchers for function files. Maps function names to subscription
660
+ * handles from the shared `FileWatcher`.
662
661
  */
663
662
  functionWatchers = /* @__PURE__ */ new Map();
664
663
  /**
@@ -678,7 +677,7 @@ var FunctionsRegistry = class {
678
677
  projectRoot;
679
678
  timeouts;
680
679
  settings;
681
- watch;
680
+ fileWatcher;
682
681
  constructor({
683
682
  blobsContext,
684
683
  config,
@@ -691,7 +690,7 @@ var FunctionsRegistry = class {
691
690
  projectRoot,
692
691
  settings,
693
692
  timeouts,
694
- watch
693
+ fileWatcher
695
694
  }) {
696
695
  this.blobsContext = blobsContext;
697
696
  this.config = config;
@@ -702,7 +701,8 @@ var FunctionsRegistry = class {
702
701
  });
703
702
  this.internalFunctionsPath = internalFunctionsPath;
704
703
  this.projectRoot = projectRoot;
705
- const siteTimeout = config?.siteInfo?.functions_timeout ?? config?.siteInfo?.functions_config?.timeout;
704
+ const configValue = config.get();
705
+ const siteTimeout = configValue?.siteInfo?.functions_timeout ?? configValue?.siteInfo?.functions_config?.timeout;
706
706
  this.timeouts = {
707
707
  syncFunctions: timeouts?.syncFunctions ?? siteTimeout ?? SYNCHRONOUS_FUNCTION_TIMEOUT,
708
708
  // NOTE: This isn't documented, but the generically named "functions timeout" config fields only
@@ -710,7 +710,7 @@ var FunctionsRegistry = class {
710
710
  backgroundFunctions: timeouts?.backgroundFunctions ?? BACKGROUND_FUNCTION_TIMEOUT
711
711
  };
712
712
  this.settings = settings;
713
- this.watch = watch === true;
713
+ this.fileWatcher = fileWatcher;
714
714
  this.buildCache = {};
715
715
  this.directoryWatchers = /* @__PURE__ */ new Map();
716
716
  this.manifest = manifest;
@@ -753,27 +753,29 @@ var FunctionsRegistry = class {
753
753
  if (!srcFilesDiff) {
754
754
  return;
755
755
  }
756
- if (!this.watch) {
756
+ if (!this.fileWatcher) {
757
757
  return;
758
758
  }
759
- const watcher = this.functionWatchers.get(func.name);
760
- if (watcher) {
759
+ const handle = this.functionWatchers.get(func.name);
760
+ if (handle) {
761
761
  srcFilesDiff.deleted.forEach((path2) => {
762
- watcher.unwatch(path2);
762
+ handle.unwatch(path2);
763
763
  });
764
764
  srcFilesDiff.added.forEach((path2) => {
765
- watcher.add(path2);
765
+ handle.add(path2);
766
766
  });
767
767
  return;
768
768
  }
769
769
  if (srcFilesDiff.added.size !== 0) {
770
770
  const filesToWatch = [...srcFilesDiff.added, ...includedFiles];
771
- const newWatcher = await watchDebounced(filesToWatch, {
771
+ const newHandle = this.fileWatcher.subscribe({
772
+ paths: filesToWatch,
773
+ decache: true,
772
774
  onChange: () => {
773
775
  this.buildFunctionAndWatchFiles(func, false);
774
776
  }
775
777
  });
776
- this.functionWatchers.set(func.name, newWatcher);
778
+ this.functionWatchers.set(func.name, newHandle);
777
779
  }
778
780
  }
779
781
  set eventHandler(handler) {
@@ -849,7 +851,7 @@ var FunctionsRegistry = class {
849
851
  } catch {
850
852
  func.mainFile = join(unzippedDirectory, basename2(manifestEntry.mainFile));
851
853
  }
852
- } else if (this.watch) {
854
+ } else if (this.fileWatcher) {
853
855
  this.buildFunctionAndWatchFiles(func, !isReload);
854
856
  }
855
857
  this.functions.set(name, func);
@@ -876,7 +878,7 @@ var FunctionsRegistry = class {
876
878
  buildRustSource: env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE === "true"
877
879
  },
878
880
  configFileDirectories: [this.internalFunctionsPath].filter(Boolean),
879
- config: this.config.functions,
881
+ config: this.config.get().functions,
880
882
  parseISC: true
881
883
  });
882
884
  const ignoredFunctions = new Set(
@@ -913,7 +915,7 @@ var FunctionsRegistry = class {
913
915
  }
914
916
  const func = new NetlifyFunction({
915
917
  blobsContext: this.blobsContext,
916
- config: this.config,
918
+ config: this.config.get(),
917
919
  directory,
918
920
  displayName,
919
921
  excludedRoutes,
@@ -938,7 +940,7 @@ var FunctionsRegistry = class {
938
940
  }
939
941
  this.handleEvent({ function: func, name: "FunctionRemovedEvent" });
940
942
  });
941
- if (this.watch) {
943
+ if (this.fileWatcher) {
942
944
  await Promise.all(directories.map((path2) => this.setupDirectoryWatcher(path2)));
943
945
  }
944
946
  }
@@ -951,7 +953,8 @@ var FunctionsRegistry = class {
951
953
  if (this.directoryWatchers.has(directory)) {
952
954
  return;
953
955
  }
954
- const watcher = await watchDebounced(directory, {
956
+ const handle = this.fileWatcher.subscribe({
957
+ paths: directory,
955
958
  depth: 1,
956
959
  onAdd: () => {
957
960
  this.scan([directory]);
@@ -960,7 +963,7 @@ var FunctionsRegistry = class {
960
963
  this.scan([directory]);
961
964
  }
962
965
  });
963
- this.directoryWatchers.set(directory, watcher);
966
+ this.directoryWatchers.set(directory, handle);
964
967
  }
965
968
  /**
966
969
  * Removes a function from the registry and closes its file watchers.
@@ -968,9 +971,9 @@ var FunctionsRegistry = class {
968
971
  async unregisterFunction(func) {
969
972
  const { name } = func;
970
973
  this.functions.delete(name);
971
- const watcher = this.functionWatchers.get(name);
972
- if (watcher) {
973
- await watcher.close();
974
+ const handle = this.functionWatchers.get(name);
975
+ if (handle) {
976
+ handle.unsubscribe();
974
977
  }
975
978
  this.functionWatchers.delete(name);
976
979
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  }
12
12
  }
13
13
  },
14
- "version": "1.1.11",
14
+ "version": "1.2.0",
15
15
  "description": "Local dev emulation of Netlify Functions",
16
16
  "files": [
17
17
  "dist/**/*.js",
@@ -42,10 +42,10 @@
42
42
  },
43
43
  "author": "Netlify Inc.",
44
44
  "dependencies": {
45
- "@netlify/blobs": "10.7.0",
46
- "@netlify/dev-utils": "4.3.3",
45
+ "@netlify/blobs": "10.7.1",
46
+ "@netlify/dev-utils": "4.4.0",
47
47
  "@netlify/functions": "5.1.2",
48
- "@netlify/zip-it-and-ship-it": "^14.3.1",
48
+ "@netlify/zip-it-and-ship-it": "^14.3.2",
49
49
  "cron-parser": "^4.9.0",
50
50
  "decache": "^4.6.2",
51
51
  "extract-zip": "^2.0.1",