netlify-cli 17.3.2 → 17.4.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/README.md +2 -138
- package/npm-shrinkwrap.json +76 -76
- package/package.json +16 -15
- package/src/commands/addons/addons-auth.mjs +27 -30
- package/src/commands/addons/addons-config.mjs +145 -154
- package/src/commands/addons/addons-create.mjs +94 -108
- package/src/commands/addons/addons-delete.mjs +36 -41
- package/src/commands/addons/addons-list.mjs +38 -42
- package/src/commands/addons/addons.mjs +26 -28
- package/src/commands/addons/index.mjs +1 -1
- package/src/commands/api/api.mjs +45 -53
- package/src/commands/api/index.mjs +1 -1
- package/src/commands/base-command.mjs +597 -684
- package/src/commands/blobs/blobs-delete.mjs +35 -0
- package/src/commands/blobs/blobs-get.mjs +44 -0
- package/src/commands/blobs/blobs-list.mjs +48 -0
- package/src/commands/blobs/blobs-set.mjs +54 -0
- package/src/commands/blobs/blobs.mjs +32 -0
- package/src/commands/blobs/index.mjs +1 -0
- package/src/commands/build/build.mjs +55 -67
- package/src/commands/build/index.mjs +1 -1
- package/src/commands/completion/completion.mjs +41 -46
- package/src/commands/completion/index.mjs +1 -1
- package/src/commands/deploy/deploy.mjs +675 -710
- package/src/commands/deploy/index.mjs +1 -1
- package/src/commands/dev/dev-exec.mjs +20 -32
- package/src/commands/dev/dev.mjs +217 -302
- package/src/commands/dev/index.mjs +1 -1
- package/src/commands/dev/types.d.ts +30 -0
- package/src/commands/env/env-clone.mjs +157 -184
- package/src/commands/env/env-get.mjs +49 -68
- package/src/commands/env/env-import.mjs +100 -119
- package/src/commands/env/env-list.mjs +104 -129
- package/src/commands/env/env-set.mjs +160 -185
- package/src/commands/env/env-unset.mjs +104 -122
- package/src/commands/env/env.mjs +28 -30
- package/src/commands/env/index.mjs +1 -1
- package/src/commands/functions/functions-build.mjs +29 -41
- package/src/commands/functions/functions-create.mjs +533 -601
- package/src/commands/functions/functions-invoke.mjs +193 -216
- package/src/commands/functions/functions-list.mjs +45 -55
- package/src/commands/functions/functions-serve.mjs +51 -61
- package/src/commands/functions/functions.mjs +26 -32
- package/src/commands/functions/index.mjs +1 -1
- package/src/commands/index.mjs +2 -2
- package/src/commands/init/index.mjs +1 -1
- package/src/commands/init/init.mjs +138 -167
- package/src/commands/integration/deploy.mjs +337 -399
- package/src/commands/integration/index.mjs +12 -13
- package/src/commands/link/index.mjs +1 -1
- package/src/commands/link/link.mjs +298 -317
- package/src/commands/lm/index.mjs +1 -1
- package/src/commands/lm/lm-info.mjs +23 -31
- package/src/commands/lm/lm-install.mjs +13 -17
- package/src/commands/lm/lm-setup.mjs +80 -84
- package/src/commands/lm/lm-uninstall.mjs +7 -12
- package/src/commands/lm/lm.mjs +18 -22
- package/src/commands/login/index.mjs +1 -1
- package/src/commands/login/login.mjs +35 -41
- package/src/commands/logout/index.mjs +1 -1
- package/src/commands/logout/logout.mjs +25 -31
- package/src/commands/main.mjs +166 -201
- package/src/commands/open/index.mjs +1 -1
- package/src/commands/open/open-admin.mjs +15 -18
- package/src/commands/open/open-site.mjs +16 -19
- package/src/commands/open/open.mjs +24 -27
- package/src/commands/recipes/common.mjs +23 -34
- package/src/commands/recipes/index.mjs +1 -1
- package/src/commands/recipes/recipes-list.mjs +13 -20
- package/src/commands/recipes/recipes.mjs +59 -72
- package/src/commands/serve/index.mjs +1 -1
- package/src/commands/serve/serve.mjs +142 -189
- package/src/commands/sites/index.mjs +2 -2
- package/src/commands/sites/sites-create-template.mjs +214 -236
- package/src/commands/sites/sites-create.mjs +145 -157
- package/src/commands/sites/sites-delete.mjs +75 -81
- package/src/commands/sites/sites-list.mjs +63 -66
- package/src/commands/sites/sites.mjs +18 -20
- package/src/commands/status/index.mjs +1 -1
- package/src/commands/status/status-hooks.mjs +32 -34
- package/src/commands/status/status.mjs +99 -106
- package/src/commands/switch/index.mjs +1 -1
- package/src/commands/switch/switch.mjs +32 -37
- package/src/commands/types.d.ts +31 -0
- package/src/commands/unlink/index.mjs +1 -1
- package/src/commands/unlink/unlink.mjs +23 -29
- package/src/commands/watch/index.mjs +1 -1
- package/src/commands/watch/watch.mjs +91 -105
- package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
- package/src/lib/account.mjs +4 -5
- package/src/lib/api.mjs +22 -20
- package/src/lib/blobs/blobs.mjs +36 -45
- package/src/lib/build.mjs +82 -85
- package/src/lib/completion/constants.mjs +2 -4
- package/src/lib/completion/generate-autocompletion.mjs +33 -36
- package/src/lib/completion/get-autocompletion.mjs +31 -35
- package/src/lib/completion/index.mjs +1 -1
- package/src/lib/completion/script.mjs +12 -19
- package/src/lib/edge-functions/bootstrap.mjs +3 -5
- package/src/lib/edge-functions/consts.mjs +9 -10
- package/src/lib/edge-functions/deploy.mjs +28 -34
- package/src/lib/edge-functions/editor-helper.mjs +29 -42
- package/src/lib/edge-functions/headers.mjs +24 -26
- package/src/lib/edge-functions/internal.mjs +38 -44
- package/src/lib/edge-functions/proxy.mjs +229 -228
- package/src/lib/edge-functions/registry.mjs +473 -574
- package/src/lib/exec-fetcher.mjs +115 -122
- package/src/lib/fs.mjs +28 -27
- package/src/lib/functions/background.mjs +16 -20
- package/src/lib/functions/config.mjs +12 -9
- package/src/lib/functions/form-submissions-handler.mjs +143 -149
- package/src/lib/functions/local-proxy.mjs +40 -44
- package/src/lib/functions/memoized-build.mjs +19 -21
- package/src/lib/functions/netlify-function.mjs +269 -249
- package/src/lib/functions/registry.mjs +509 -568
- package/src/lib/functions/runtimes/go/index.mjs +62 -71
- package/src/lib/functions/runtimes/index.mjs +8 -15
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
- package/src/lib/functions/runtimes/js/constants.mjs +1 -1
- package/src/lib/functions/runtimes/js/index.mjs +92 -109
- package/src/lib/functions/runtimes/js/worker.mjs +43 -45
- package/src/lib/functions/runtimes/rust/index.mjs +64 -73
- package/src/lib/functions/scheduled.mjs +70 -88
- package/src/lib/functions/server.mjs +269 -327
- package/src/lib/functions/synchronous.mjs +118 -147
- package/src/lib/functions/utils.mjs +38 -46
- package/src/lib/geo-location.mjs +69 -81
- package/src/lib/http-agent.mjs +87 -90
- package/src/lib/images/proxy.mjs +97 -99
- package/src/lib/log.mjs +6 -9
- package/src/lib/path.mjs +2 -1
- package/src/lib/render-error-template.mjs +19 -20
- package/src/lib/settings.mjs +17 -19
- package/src/lib/spinner.mjs +21 -23
- package/src/lib/string.mjs +4 -2
- package/src/recipes/vscode/index.mjs +69 -85
- package/src/recipes/vscode/settings.mjs +53 -58
- package/src/utils/addons/compare.mjs +31 -32
- package/src/utils/addons/diffs/index.mjs +16 -17
- package/src/utils/addons/diffs/options.mjs +99 -101
- package/src/utils/addons/prepare.mjs +100 -97
- package/src/utils/addons/prompts.mjs +73 -76
- package/src/utils/addons/render.mjs +33 -36
- package/src/utils/addons/validation.mjs +19 -15
- package/src/utils/banner.mjs +11 -16
- package/src/utils/build-info.mjs +65 -66
- package/src/utils/command-helpers.mjs +185 -199
- package/src/utils/create-deferred.mjs +9 -12
- package/src/utils/create-stream-promise.mjs +54 -47
- package/src/utils/deploy/constants.mjs +9 -11
- package/src/utils/deploy/deploy-site.mjs +162 -182
- package/src/utils/deploy/hash-config.mjs +21 -21
- package/src/utils/deploy/hash-files.mjs +34 -38
- package/src/utils/deploy/hash-fns.mjs +149 -154
- package/src/utils/deploy/hasher-segments.mjs +58 -52
- package/src/utils/deploy/upload-files.mjs +99 -113
- package/src/utils/deploy/util.mjs +85 -91
- package/src/utils/detect-server-settings.mjs +236 -268
- package/src/utils/dev.mjs +163 -178
- package/src/utils/dot-env.mjs +37 -42
- package/src/utils/env/index.mjs +148 -148
- package/src/utils/execa.mjs +9 -13
- package/src/utils/feature-flags.mjs +6 -5
- package/src/utils/framework-server.mjs +43 -52
- package/src/utils/functions/constants.mjs +1 -1
- package/src/utils/functions/functions.mjs +30 -40
- package/src/utils/functions/get-functions.mjs +28 -29
- package/src/utils/functions/index.mjs +3 -3
- package/src/utils/get-global-config.mjs +33 -36
- package/src/utils/get-package-json.mjs +14 -15
- package/src/utils/get-repo-data.mjs +54 -64
- package/src/utils/get-site.mjs +14 -14
- package/src/utils/gh-auth.mjs +79 -100
- package/src/utils/gitignore.mjs +37 -40
- package/src/utils/headers.mjs +33 -35
- package/src/utils/hooks/requires-site-info.mjs +26 -22
- package/src/utils/init/config-github.mjs +207 -219
- package/src/utils/init/config-manual.mjs +83 -100
- package/src/utils/init/config.mjs +25 -26
- package/src/utils/init/node-version.mjs +23 -30
- package/src/utils/init/plugins.mjs +12 -8
- package/src/utils/init/utils.mjs +152 -172
- package/src/utils/live-tunnel.mjs +118 -141
- package/src/utils/lm/install.mjs +220 -259
- package/src/utils/lm/requirements.mjs +54 -63
- package/src/utils/lm/steps.mjs +31 -31
- package/src/utils/lm/ui.mjs +13 -20
- package/src/utils/open-browser.mjs +31 -32
- package/src/utils/parse-raw-flags.mjs +39 -35
- package/src/utils/proxy-server.mjs +84 -71
- package/src/utils/proxy.mjs +696 -750
- package/src/utils/read-repo-url.mjs +48 -47
- package/src/utils/redirects.mjs +49 -49
- package/src/utils/request-id.mjs +2 -4
- package/src/utils/rules-proxy.mjs +96 -100
- package/src/utils/run-build.mjs +109 -132
- package/src/utils/shell.mjs +99 -106
- package/src/utils/sign-redirect.mjs +14 -14
- package/src/utils/sites/utils.mjs +48 -55
- package/src/utils/state-config.mjs +101 -101
- package/src/utils/static-server.mjs +28 -34
- package/src/utils/telemetry/index.mjs +2 -2
- package/src/utils/telemetry/report-error.mjs +45 -49
- package/src/utils/telemetry/request.mjs +36 -43
- package/src/utils/telemetry/telemetry.mjs +90 -105
- package/src/utils/telemetry/utils.mjs +5 -6
- package/src/utils/telemetry/validation.mjs +55 -53
- package/src/utils/types.d.ts +46 -0
- package/src/utils/validation.mjs +10 -13
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _EdgeFunctionsRegistry_instances, _a, _EdgeFunctionsRegistry_bundler, _EdgeFunctionsRegistry_configPath, _EdgeFunctionsRegistry_debug, _EdgeFunctionsRegistry_directories, _EdgeFunctionsRegistry_internalDirectories, _EdgeFunctionsRegistry_getUpdatedConfig, _EdgeFunctionsRegistry_runIsolate, _EdgeFunctionsRegistry_buildError, _EdgeFunctionsRegistry_declarationsFromDeployConfig, _EdgeFunctionsRegistry_declarationsFromTOML, _EdgeFunctionsRegistry_env, _EdgeFunctionsRegistry_directoryWatchers, _EdgeFunctionsRegistry_dependencyPaths, _EdgeFunctionsRegistry_functionPaths, _EdgeFunctionsRegistry_manifest, _EdgeFunctionsRegistry_userFunctions, _EdgeFunctionsRegistry_internalFunctions, _EdgeFunctionsRegistry_initialScan, _EdgeFunctionsRegistry_routes, _EdgeFunctionsRegistry_servePath, _EdgeFunctionsRegistry_doInitialScan, _EdgeFunctionsRegistry_functions_get, _EdgeFunctionsRegistry_build, _EdgeFunctionsRegistry_buildRoutes, _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions, _EdgeFunctionsRegistry_getDeclarationsFromTOML, _EdgeFunctionsRegistry_getEnvironmentVariables, _EdgeFunctionsRegistry_handleFileChange, _EdgeFunctionsRegistry_logEvent, _EdgeFunctionsRegistry_processGraph, _EdgeFunctionsRegistry_runBuild, _EdgeFunctionsRegistry_scanForFunctions, _EdgeFunctionsRegistry_setupWatchers, _EdgeFunctionsRegistry_setupWatcherForDirectory, _EdgeFunctionsRegistry_getDisplayName;
|
|
13
|
+
import { fileURLToPath } from 'url';
|
|
14
|
+
import { NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, chalk, log, warn, watchDebounced, } from '../../utils/command-helpers.mjs';
|
|
14
15
|
/** @typedef {import('@netlify/edge-bundler').Declaration} Declaration */
|
|
15
16
|
/** @typedef {import('@netlify/edge-bundler').EdgeFunction} EdgeFunction */
|
|
16
17
|
/**
|
|
@@ -21,619 +22,517 @@ import {
|
|
|
21
22
|
/** @typedef {import('@netlify/edge-bundler').ModuleGraph} ModuleGraph */
|
|
22
23
|
/** @typedef {Awaited<ReturnType<typeof import('@netlify/edge-bundler').serve>>} RunIsolate */
|
|
23
24
|
/** @typedef {Omit<Manifest["routes"][0], "pattern"> & { pattern: RegExp }} Route */
|
|
24
|
-
|
|
25
|
-
const featureFlags = { edge_functions_correct_order: true }
|
|
26
|
-
|
|
25
|
+
const featureFlags = { edge_functions_correct_order: true };
|
|
27
26
|
export class EdgeFunctionsRegistry {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @param {Object} opts
|
|
29
|
+
* @param {import('@netlify/edge-bundler')} opts.bundler
|
|
30
|
+
* @param {object} opts.config
|
|
31
|
+
* @param {string} opts.configPath
|
|
32
|
+
* @param {boolean} opts.debug
|
|
33
|
+
* @param {string[]} opts.directories
|
|
34
|
+
* @param {Record<string, { sources: string[], value: string}>} opts.env
|
|
35
|
+
* @param {() => Promise<object>} opts.getUpdatedConfig
|
|
36
|
+
* @param {string[]} opts.internalDirectories
|
|
37
|
+
* @param {Declaration[]} opts.internalFunctions
|
|
38
|
+
* @param {string} opts.projectDir
|
|
39
|
+
* @param {RunIsolate} opts.runIsolate
|
|
40
|
+
* @param {string} opts.servePath
|
|
41
|
+
*/
|
|
42
|
+
constructor({
|
|
43
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'bundler' implicitly has an 'any' ... Remove this comment to see the full error message
|
|
44
|
+
bundler,
|
|
45
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
46
|
+
config,
|
|
47
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'configPath' implicitly has an 'an... Remove this comment to see the full error message
|
|
48
|
+
configPath,
|
|
49
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'debug' implicitly has an 'any' ty... Remove this comment to see the full error message
|
|
50
|
+
debug,
|
|
51
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'directories' implicitly has an 'a... Remove this comment to see the full error message
|
|
52
|
+
directories,
|
|
53
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'env' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
54
|
+
env,
|
|
55
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'getUpdatedConfig' implicitly has ... Remove this comment to see the full error message
|
|
56
|
+
getUpdatedConfig,
|
|
57
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'internalDirectories' implicitly h... Remove this comment to see the full error message
|
|
58
|
+
internalDirectories,
|
|
59
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'internalFunctions' implicitly has... Remove this comment to see the full error message
|
|
60
|
+
internalFunctions,
|
|
61
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message
|
|
62
|
+
projectDir,
|
|
63
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'runIsolate' implicitly has an 'an... Remove this comment to see the full error message
|
|
64
|
+
runIsolate,
|
|
65
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'servePath' implicitly has an 'any... Remove this comment to see the full error message
|
|
66
|
+
servePath, }) {
|
|
67
|
+
_EdgeFunctionsRegistry_instances.add(this);
|
|
68
|
+
/** @type {import('@netlify/edge-bundler')} */
|
|
69
|
+
_EdgeFunctionsRegistry_bundler.set(this, void 0);
|
|
70
|
+
/** @type {string} */
|
|
71
|
+
_EdgeFunctionsRegistry_configPath.set(this, void 0);
|
|
72
|
+
/** @type {boolean} */
|
|
73
|
+
_EdgeFunctionsRegistry_debug.set(this, void 0);
|
|
74
|
+
/** @type {string[]} */
|
|
75
|
+
_EdgeFunctionsRegistry_directories.set(this, void 0);
|
|
76
|
+
/** @type {string[]} */
|
|
77
|
+
_EdgeFunctionsRegistry_internalDirectories.set(this, void 0);
|
|
78
|
+
/** @type {() => Promise<object>} */
|
|
79
|
+
_EdgeFunctionsRegistry_getUpdatedConfig.set(this, void 0);
|
|
80
|
+
/** @type {RunIsolate} */
|
|
81
|
+
_EdgeFunctionsRegistry_runIsolate.set(this, void 0);
|
|
82
|
+
/** @type {Error | null} */
|
|
83
|
+
_EdgeFunctionsRegistry_buildError.set(this, null
|
|
84
|
+
/** @type {Declaration[]} */
|
|
85
|
+
);
|
|
86
|
+
/** @type {Declaration[]} */
|
|
87
|
+
_EdgeFunctionsRegistry_declarationsFromDeployConfig.set(this, void 0);
|
|
88
|
+
/** @type {Declaration[]} */
|
|
89
|
+
_EdgeFunctionsRegistry_declarationsFromTOML.set(this, void 0);
|
|
90
|
+
/** @type {Record<string, string>} */
|
|
91
|
+
_EdgeFunctionsRegistry_env.set(this, void 0);
|
|
92
|
+
/** @type {Map<string, import('chokidar').FSWatcher>} */
|
|
93
|
+
_EdgeFunctionsRegistry_directoryWatchers.set(this, new Map()
|
|
94
|
+
/** @type {Map<string, string[]>} */
|
|
95
|
+
);
|
|
96
|
+
/** @type {Map<string, string[]>} */
|
|
97
|
+
_EdgeFunctionsRegistry_dependencyPaths.set(this, new Map()
|
|
98
|
+
/** @type {Map<string, string>} */
|
|
99
|
+
);
|
|
100
|
+
/** @type {Map<string, string>} */
|
|
101
|
+
_EdgeFunctionsRegistry_functionPaths.set(this, new Map()
|
|
102
|
+
/** @type {Manifest | null} */
|
|
103
|
+
);
|
|
104
|
+
/** @type {Manifest | null} */
|
|
105
|
+
_EdgeFunctionsRegistry_manifest.set(this, null
|
|
106
|
+
/** @type {EdgeFunction[]} */
|
|
107
|
+
);
|
|
108
|
+
/** @type {EdgeFunction[]} */
|
|
109
|
+
_EdgeFunctionsRegistry_userFunctions.set(this, []
|
|
110
|
+
/** @type {EdgeFunction[]} */
|
|
111
|
+
);
|
|
112
|
+
/** @type {EdgeFunction[]} */
|
|
113
|
+
_EdgeFunctionsRegistry_internalFunctions.set(this, []
|
|
114
|
+
/** @type {Promise<void>} */
|
|
115
|
+
);
|
|
116
|
+
/** @type {Promise<void>} */
|
|
117
|
+
_EdgeFunctionsRegistry_initialScan.set(this, void 0);
|
|
118
|
+
/** @type {Route[]} */
|
|
119
|
+
_EdgeFunctionsRegistry_routes.set(this, []
|
|
120
|
+
/** @type {string} */
|
|
121
|
+
);
|
|
122
|
+
/** @type {string} */
|
|
123
|
+
_EdgeFunctionsRegistry_servePath.set(this, void 0);
|
|
124
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_bundler, bundler, "f");
|
|
125
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_configPath, configPath, "f");
|
|
126
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_debug, debug, "f");
|
|
127
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_directories, directories, "f");
|
|
128
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_internalDirectories, internalDirectories, "f");
|
|
129
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_getUpdatedConfig, getUpdatedConfig, "f");
|
|
130
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_runIsolate, runIsolate, "f");
|
|
131
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_servePath, servePath, "f");
|
|
132
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_declarationsFromDeployConfig, internalFunctions, "f");
|
|
133
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_declarationsFromTOML, __classPrivateFieldGet(EdgeFunctionsRegistry, _a, "m", _EdgeFunctionsRegistry_getDeclarationsFromTOML).call(EdgeFunctionsRegistry, config), "f");
|
|
134
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_env, __classPrivateFieldGet(EdgeFunctionsRegistry, _a, "m", _EdgeFunctionsRegistry_getEnvironmentVariables).call(EdgeFunctionsRegistry, env), "f");
|
|
135
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_buildError, null, "f");
|
|
136
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_directoryWatchers, new Map(), "f");
|
|
137
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_dependencyPaths, new Map(), "f");
|
|
138
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_functionPaths, new Map(), "f");
|
|
139
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_userFunctions, [], "f");
|
|
140
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_internalFunctions, [], "f");
|
|
141
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_initialScan, __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_doInitialScan).call(this), "f");
|
|
142
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_setupWatchers).call(this, projectDir);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* @return {Promise<void>}
|
|
146
|
+
*/
|
|
147
|
+
async initialize() {
|
|
148
|
+
return await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_initialScan, "f");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the functions in the registry that should run for a given URL path
|
|
152
|
+
* and HTTP method, based on the routes registered for each function.
|
|
153
|
+
*
|
|
154
|
+
* @param {string} urlPath
|
|
155
|
+
* @param {string} method
|
|
156
|
+
*/
|
|
157
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'urlPath' implicitly has an 'any' type.
|
|
158
|
+
matchURLPath(urlPath, method) {
|
|
159
|
+
/** @type string[] */
|
|
160
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'functionNames' implicitly has type 'any[... Remove this comment to see the full error message
|
|
161
|
+
const functionNames = [];
|
|
162
|
+
/** @type number[] */
|
|
163
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'routeIndexes' implicitly has type 'any[]... Remove this comment to see the full error message
|
|
164
|
+
const routeIndexes = [];
|
|
165
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_routes, "f").forEach((route, index) => {
|
|
166
|
+
// @ts-expect-error TS(2339) FIXME: Property 'methods' does not exist on type 'never'.
|
|
167
|
+
if (route.methods && route.methods.length !== 0 && !route.methods.includes(method)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// @ts-expect-error TS(2339) FIXME: Property 'pattern' does not exist on type 'never'.
|
|
171
|
+
if (!route.pattern.test(urlPath)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// @ts-expect-error TS(2339) FIXME: Property 'function_config' does not exist on type ... Remove this comment to see the full error message
|
|
175
|
+
const isExcluded = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_manifest, "f")?.function_config[route.function]?.excluded_patterns?.some((pattern) => new RegExp(pattern).test(urlPath));
|
|
176
|
+
if (isExcluded) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
// @ts-expect-error TS(2339) FIXME: Property 'function' does not exist on type 'never'... Remove this comment to see the full error message
|
|
180
|
+
functionNames.push(route.function);
|
|
181
|
+
routeIndexes.push(index);
|
|
182
|
+
});
|
|
183
|
+
const invocationMetadata = {
|
|
184
|
+
// @ts-expect-error TS(2339) FIXME: Property 'function_config' does not exist on type ... Remove this comment to see the full error message
|
|
185
|
+
function_config: __classPrivateFieldGet(this, _EdgeFunctionsRegistry_manifest, "f")?.function_config,
|
|
186
|
+
// @ts-expect-error TS(7005) FIXME: Variable 'routeIndexes' implicitly has an 'any[]' ... Remove this comment to see the full error message
|
|
187
|
+
req_routes: routeIndexes,
|
|
188
|
+
// @ts-expect-error TS(2339) FIXME: Property 'routes' does not exist on type 'never'.
|
|
189
|
+
routes: __classPrivateFieldGet(this, _EdgeFunctionsRegistry_manifest, "f")?.routes.map((route) => ({
|
|
190
|
+
function: route.function,
|
|
191
|
+
path: route.path,
|
|
192
|
+
pattern: route.pattern,
|
|
193
|
+
})),
|
|
194
|
+
};
|
|
195
|
+
// @ts-expect-error TS(7005) FIXME: Variable 'functionNames' implicitly has an 'any[]'... Remove this comment to see the full error message
|
|
196
|
+
return { functionNames, invocationMetadata };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
_a = EdgeFunctionsRegistry, _EdgeFunctionsRegistry_bundler = new WeakMap(), _EdgeFunctionsRegistry_configPath = new WeakMap(), _EdgeFunctionsRegistry_debug = new WeakMap(), _EdgeFunctionsRegistry_directories = new WeakMap(), _EdgeFunctionsRegistry_internalDirectories = new WeakMap(), _EdgeFunctionsRegistry_getUpdatedConfig = new WeakMap(), _EdgeFunctionsRegistry_runIsolate = new WeakMap(), _EdgeFunctionsRegistry_buildError = new WeakMap(), _EdgeFunctionsRegistry_declarationsFromDeployConfig = new WeakMap(), _EdgeFunctionsRegistry_declarationsFromTOML = new WeakMap(), _EdgeFunctionsRegistry_env = new WeakMap(), _EdgeFunctionsRegistry_directoryWatchers = new WeakMap(), _EdgeFunctionsRegistry_dependencyPaths = new WeakMap(), _EdgeFunctionsRegistry_functionPaths = new WeakMap(), _EdgeFunctionsRegistry_manifest = new WeakMap(), _EdgeFunctionsRegistry_userFunctions = new WeakMap(), _EdgeFunctionsRegistry_internalFunctions = new WeakMap(), _EdgeFunctionsRegistry_initialScan = new WeakMap(), _EdgeFunctionsRegistry_routes = new WeakMap(), _EdgeFunctionsRegistry_servePath = new WeakMap(), _EdgeFunctionsRegistry_instances = new WeakSet(), _EdgeFunctionsRegistry_doInitialScan =
|
|
200
|
+
/**
|
|
201
|
+
* @returns {Promise<void>}
|
|
202
|
+
*/
|
|
203
|
+
async function _EdgeFunctionsRegistry_doInitialScan() {
|
|
204
|
+
await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_scanForFunctions).call(this);
|
|
148
205
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
206
|
+
const { warnings } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_build).call(this);
|
|
207
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get).forEach((func) => {
|
|
208
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ functionName: any; warnings: a... Remove this comment to see the full error message
|
|
209
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'loaded', { functionName: func.name, warnings: warnings[func.name] });
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// no-op
|
|
156
214
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @return {Promise<{warnings: Record<string, string[]>}>}
|
|
168
|
-
*/
|
|
169
|
-
async #build() {
|
|
215
|
+
}, _EdgeFunctionsRegistry_functions_get = function _EdgeFunctionsRegistry_functions_get() {
|
|
216
|
+
return [...__classPrivateFieldGet(this, _EdgeFunctionsRegistry_internalFunctions, "f"), ...__classPrivateFieldGet(this, _EdgeFunctionsRegistry_userFunctions, "f")];
|
|
217
|
+
}, _EdgeFunctionsRegistry_build =
|
|
218
|
+
/**
|
|
219
|
+
* @return {Promise<{warnings: Record<string, string[]>}>}
|
|
220
|
+
*/
|
|
221
|
+
async function _EdgeFunctionsRegistry_build() {
|
|
170
222
|
/**
|
|
171
223
|
* @type Record<string, string[]>
|
|
172
224
|
*/
|
|
173
|
-
const warnings = {}
|
|
174
|
-
|
|
225
|
+
const warnings = {};
|
|
175
226
|
try {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
/** @type {Record<string, FunctionConfig>} */
|
|
189
|
-
const internalFunctionConfigs = this.#internalFunctions.reduce(
|
|
227
|
+
const { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_runBuild).call(this);
|
|
228
|
+
if (!success) {
|
|
229
|
+
throw new Error('Build error');
|
|
230
|
+
}
|
|
231
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_buildError, null, "f");
|
|
232
|
+
// We use one index to loop over both internal and user function, because we know that this.#functions has internalFunctions first.
|
|
233
|
+
// functionsConfig therefore contains first all internal functionConfigs and then user functionConfigs
|
|
234
|
+
let index = 0;
|
|
235
|
+
/** @type {Record<string, FunctionConfig>} */
|
|
236
|
+
const internalFunctionConfigs = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_internalFunctions, "f").reduce(
|
|
237
|
+
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'never'.
|
|
190
238
|
// eslint-disable-next-line no-plusplus
|
|
191
|
-
(acc, func) => ({ ...acc, [func.name]: functionsConfig[index++] }),
|
|
192
|
-
{}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/** @type {Record<string, FunctionConfig>} */
|
|
196
|
-
const userFunctionConfigs = this.#userFunctions.reduce(
|
|
239
|
+
(acc, func) => ({ ...acc, [func.name]: functionsConfig[index++] }), {});
|
|
240
|
+
/** @type {Record<string, FunctionConfig>} */
|
|
241
|
+
const userFunctionConfigs = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_userFunctions, "f").reduce(
|
|
242
|
+
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'never'.
|
|
197
243
|
// eslint-disable-next-line no-plusplus
|
|
198
|
-
(acc, func) => ({ ...acc, [func.name]: functionsConfig[index++] }),
|
|
199
|
-
{},
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
244
|
+
(acc, func) => ({ ...acc, [func.name]: functionsConfig[index++] }), {});
|
|
245
|
+
const { manifest, routes, unroutedFunctions } = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_buildRoutes).call(this, internalFunctionConfigs, userFunctionConfigs);
|
|
246
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_manifest, manifest, "f");
|
|
247
|
+
// @ts-expect-error TS(2322) FIXME: Type 'any[]' is not assignable to type 'never[]'.
|
|
248
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_routes, routes, "f");
|
|
249
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
|
|
250
|
+
unroutedFunctions.forEach((name) => {
|
|
251
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
252
|
+
warnings[name] = warnings[name] || [];
|
|
253
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
254
|
+
warnings[name].push(`Edge function is not accessible because it does not have a path configured. Learn more at https://ntl.fyi/edge-create.`);
|
|
255
|
+
});
|
|
256
|
+
for (const functionName in userFunctionConfigs) {
|
|
257
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
258
|
+
if ('paths' in userFunctionConfigs[functionName]) {
|
|
259
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
260
|
+
warnings[functionName] = warnings[functionName] || [];
|
|
261
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
262
|
+
warnings[functionName].push(`Unknown 'paths' configuration property. Did you mean 'path'?`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_processGraph).call(this, graph);
|
|
266
|
+
if (npmSpecifiersWithExtraneousFiles.length !== 0) {
|
|
267
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
|
|
268
|
+
const modules = npmSpecifiersWithExtraneousFiles.map((name) => chalk.yellow(name)).join(', ');
|
|
269
|
+
log(`${NETLIFYDEVWARN} The following npm modules, which are directly or indirectly imported by an edge function, may not be supported: ${modules}. For more information, visit https://ntl.fyi/edge-functions-npm.`);
|
|
218
270
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
log(
|
|
227
|
-
`${NETLIFYDEVWARN} The following npm modules, which are directly or indirectly imported by an edge function, may not be supported: ${modules}. For more information, visit https://ntl.fyi/edge-functions-npm.`,
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return { warnings }
|
|
232
|
-
} catch (error) {
|
|
233
|
-
this.#buildError = error
|
|
234
|
-
|
|
235
|
-
throw error
|
|
271
|
+
return { warnings };
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
// @ts-expect-error TS(2322) FIXME: Type 'unknown' is not assignable to type 'null'.
|
|
275
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_buildError, error, "f");
|
|
276
|
+
throw error;
|
|
236
277
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
* @param {Record<string, FunctionConfig>} userFunctionConfigs
|
|
247
|
-
*/
|
|
248
|
-
#buildRoutes(internalFunctionConfigs, userFunctionConfigs) {
|
|
249
|
-
const declarations = this.#bundler.mergeDeclarations(
|
|
250
|
-
this.#declarationsFromTOML,
|
|
251
|
-
userFunctionConfigs,
|
|
252
|
-
internalFunctionConfigs,
|
|
253
|
-
this.#declarationsFromDeployConfig,
|
|
254
|
-
featureFlags,
|
|
255
|
-
)
|
|
256
|
-
const { declarationsWithoutFunction, manifest, unroutedFunctions } = this.#bundler.generateManifest({
|
|
257
|
-
declarations,
|
|
258
|
-
userFunctionConfig: userFunctionConfigs,
|
|
259
|
-
internalFunctionConfig: internalFunctionConfigs,
|
|
260
|
-
functions: this.#functions,
|
|
261
|
-
featureFlags,
|
|
262
|
-
})
|
|
278
|
+
}, _EdgeFunctionsRegistry_buildRoutes = function _EdgeFunctionsRegistry_buildRoutes(internalFunctionConfigs, userFunctionConfigs) {
|
|
279
|
+
const declarations = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_bundler, "f").mergeDeclarations(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_declarationsFromTOML, "f"), userFunctionConfigs, internalFunctionConfigs, __classPrivateFieldGet(this, _EdgeFunctionsRegistry_declarationsFromDeployConfig, "f"), featureFlags);
|
|
280
|
+
const { declarationsWithoutFunction, manifest, unroutedFunctions } = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_bundler, "f").generateManifest({
|
|
281
|
+
declarations,
|
|
282
|
+
userFunctionConfig: userFunctionConfigs,
|
|
283
|
+
internalFunctionConfig: internalFunctionConfigs,
|
|
284
|
+
functions: __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get),
|
|
285
|
+
featureFlags,
|
|
286
|
+
});
|
|
263
287
|
const routes = [...manifest.routes, ...manifest.post_cache_routes].map((route) => ({
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}))
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
async #checkForAddedOrDeletedFunctions() {
|
|
275
|
-
const { deleted: deletedFunctions, new: newFunctions } = await this.#scanForFunctions()
|
|
276
|
-
|
|
288
|
+
...route,
|
|
289
|
+
pattern: new RegExp(route.pattern),
|
|
290
|
+
}));
|
|
291
|
+
return { declarationsWithoutFunction, manifest, routes, unroutedFunctions };
|
|
292
|
+
}, _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions =
|
|
293
|
+
/**
|
|
294
|
+
* @returns {Promise<void>}
|
|
295
|
+
*/
|
|
296
|
+
async function _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions() {
|
|
297
|
+
const { deleted: deletedFunctions, new: newFunctions } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_scanForFunctions).call(this);
|
|
277
298
|
if (newFunctions.length === 0 && deletedFunctions.length === 0) {
|
|
278
|
-
|
|
299
|
+
return;
|
|
279
300
|
}
|
|
280
|
-
|
|
281
301
|
try {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
} catch {
|
|
292
|
-
// no-op
|
|
302
|
+
const { warnings } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_build).call(this);
|
|
303
|
+
deletedFunctions.forEach((func) => {
|
|
304
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ functionName: any; warnings: a... Remove this comment to see the full error message
|
|
305
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'removed', { functionName: func.name, warnings: warnings[func.name] });
|
|
306
|
+
});
|
|
307
|
+
newFunctions.forEach((func) => {
|
|
308
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ functionName: any; warnings: a... Remove this comment to see the full error message
|
|
309
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'loaded', { functionName: func.name, warnings: warnings[func.name] });
|
|
310
|
+
});
|
|
293
311
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
return edgeFunctions
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* @param {Record<string, { sources:string[], value:string }>} envConfig
|
|
308
|
-
* @returns {Record<string, string>}
|
|
309
|
-
*/
|
|
310
|
-
static #getEnvironmentVariables(envConfig) {
|
|
311
|
-
const env = Object.create(null)
|
|
312
|
+
catch {
|
|
313
|
+
// no-op
|
|
314
|
+
}
|
|
315
|
+
}, _EdgeFunctionsRegistry_getDeclarationsFromTOML = function _EdgeFunctionsRegistry_getDeclarationsFromTOML(config) {
|
|
316
|
+
const { edge_functions: edgeFunctions = [] } = config;
|
|
317
|
+
return edgeFunctions;
|
|
318
|
+
}, _EdgeFunctionsRegistry_getEnvironmentVariables = function _EdgeFunctionsRegistry_getEnvironmentVariables(envConfig) {
|
|
319
|
+
const env = Object.create(null);
|
|
312
320
|
Object.entries(envConfig).forEach(([key, variable]) => {
|
|
313
|
-
|
|
321
|
+
if (
|
|
322
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
314
323
|
variable.sources.includes('ui') ||
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
324
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
325
|
+
variable.sources.includes('account') ||
|
|
326
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
327
|
+
variable.sources.includes('addons') ||
|
|
328
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
329
|
+
variable.sources.includes('internal') ||
|
|
330
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
331
|
+
variable.sources.some((source) => source.startsWith('.env'))) {
|
|
332
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
333
|
+
env[key] = variable.value;
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
env.DENO_REGION = 'local';
|
|
337
|
+
return env;
|
|
338
|
+
}, _EdgeFunctionsRegistry_handleFileChange =
|
|
339
|
+
/**
|
|
340
|
+
* @param {string[]} paths
|
|
341
|
+
* @returns {Promise<void>}
|
|
342
|
+
*/
|
|
343
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'paths' implicitly has an 'any' type.
|
|
344
|
+
async function _EdgeFunctionsRegistry_handleFileChange(paths) {
|
|
345
|
+
const matchingFunctions = new Set([
|
|
346
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'path' implicitly has an 'any' type.
|
|
347
|
+
...paths.map((path) => __classPrivateFieldGet(this, _EdgeFunctionsRegistry_functionPaths, "f").get(path)),
|
|
348
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'path' implicitly has an 'any' type.
|
|
349
|
+
...paths.flatMap((path) => __classPrivateFieldGet(this, _EdgeFunctionsRegistry_dependencyPaths, "f").get(path)),
|
|
350
|
+
].filter(Boolean));
|
|
341
351
|
// If the file is not associated with any function, there's no point in
|
|
342
352
|
// building. However, it might be that the path is in fact associated with
|
|
343
353
|
// a function but we just haven't registered it due to a build error. So if
|
|
344
354
|
// there was a build error, let's always build.
|
|
345
|
-
if (matchingFunctions.size === 0 && this
|
|
346
|
-
|
|
355
|
+
if (matchingFunctions.size === 0 && __classPrivateFieldGet(this, _EdgeFunctionsRegistry_buildError, "f") === null) {
|
|
356
|
+
return;
|
|
347
357
|
}
|
|
348
|
-
|
|
349
|
-
this
|
|
350
|
-
|
|
358
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{}' is not assignable to paramet... Remove this comment to see the full error message
|
|
359
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'reloading', {});
|
|
351
360
|
try {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
361
|
+
const { warnings } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_build).call(this);
|
|
362
|
+
const functionNames = [...matchingFunctions];
|
|
363
|
+
if (functionNames.length === 0) {
|
|
364
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{}' is not assignable to paramet... Remove this comment to see the full error message
|
|
365
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'reloaded', {});
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
functionNames.forEach((functionName) => {
|
|
369
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ functionName: any; warnings: a... Remove this comment to see the full error message
|
|
370
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'reloaded', { functionName, warnings: warnings[functionName] });
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ buildError: any; }' is not ass... Remove this comment to see the full error message
|
|
376
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_logEvent).call(this, 'buildError', { buildError: error?.message });
|
|
364
377
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* @return {Promise<void>}
|
|
369
|
-
*/
|
|
370
|
-
async initialize() {
|
|
371
|
-
return await this.#initialScan
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Logs an event associated with functions.
|
|
376
|
-
*
|
|
377
|
-
* @param {EdgeFunctionEvent} event
|
|
378
|
-
* @param {object} data
|
|
379
|
-
* @param {Error} [data.buildError]
|
|
380
|
-
* @param {string} [data.functionName]
|
|
381
|
-
* @param {string[]} [data.warnings]
|
|
382
|
-
* @returns
|
|
383
|
-
*/
|
|
384
|
-
#logEvent(event, { buildError, functionName, warnings = [] }) {
|
|
378
|
+
}, _EdgeFunctionsRegistry_logEvent = function _EdgeFunctionsRegistry_logEvent(event, { buildError, functionName, warnings = [] }) {
|
|
385
379
|
const subject = functionName
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const warningsText =
|
|
389
|
-
warnings.length === 0 ? '' : ` with warnings:\n${warnings.map((warning) => ` - ${warning}`).join('\n')}`
|
|
390
|
-
|
|
380
|
+
? `edge function ${chalk.yellow(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_getDisplayName).call(this, functionName))}`
|
|
381
|
+
: 'edge functions';
|
|
382
|
+
const warningsText = warnings.length === 0 ? '' : ` with warnings:\n${warnings.map((warning) => ` - ${warning}`).join('\n')}`;
|
|
391
383
|
if (event === 'buildError') {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
return
|
|
384
|
+
log(`${NETLIFYDEVERR} ${chalk.red('Failed to load')} ${subject}: ${buildError}`);
|
|
385
|
+
return;
|
|
395
386
|
}
|
|
396
|
-
|
|
397
387
|
if (event === 'loaded') {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return
|
|
388
|
+
const icon = warningsText ? NETLIFYDEVWARN : NETLIFYDEVLOG;
|
|
389
|
+
const color = warningsText ? chalk.yellow : chalk.green;
|
|
390
|
+
log(`${icon} ${color('Loaded')} ${subject}${warningsText}`);
|
|
391
|
+
return;
|
|
404
392
|
}
|
|
405
|
-
|
|
406
393
|
if (event === 'reloaded') {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
return
|
|
394
|
+
const icon = warningsText ? NETLIFYDEVWARN : NETLIFYDEVLOG;
|
|
395
|
+
const color = warningsText ? chalk.yellow : chalk.green;
|
|
396
|
+
log(`${icon} ${color('Reloaded')} ${subject}${warningsText}`);
|
|
397
|
+
return;
|
|
413
398
|
}
|
|
414
|
-
|
|
415
399
|
if (event === 'reloading') {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
return
|
|
400
|
+
log(`${NETLIFYDEVLOG} ${chalk.magenta('Reloading')} ${subject}...`);
|
|
401
|
+
return;
|
|
419
402
|
}
|
|
420
|
-
|
|
421
403
|
if (event === 'removed') {
|
|
422
|
-
|
|
404
|
+
log(`${NETLIFYDEVLOG} ${chalk.magenta('Removed')} ${subject}`);
|
|
423
405
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
/**
|
|
427
|
-
* Returns the functions in the registry that should run for a given URL path
|
|
428
|
-
* and HTTP method, based on the routes registered for each function.
|
|
429
|
-
*
|
|
430
|
-
* @param {string} urlPath
|
|
431
|
-
* @param {string} method
|
|
432
|
-
*/
|
|
433
|
-
matchURLPath(urlPath, method) {
|
|
434
|
-
/** @type string[] */
|
|
435
|
-
const functionNames = []
|
|
436
|
-
|
|
437
|
-
/** @type number[] */
|
|
438
|
-
const routeIndexes = []
|
|
439
|
-
|
|
440
|
-
this.#routes.forEach((route, index) => {
|
|
441
|
-
if (route.methods && route.methods.length !== 0 && !route.methods.includes(method)) {
|
|
442
|
-
return
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if (!route.pattern.test(urlPath)) {
|
|
446
|
-
return
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
const isExcluded = this.#manifest?.function_config[route.function]?.excluded_patterns?.some((pattern) =>
|
|
450
|
-
new RegExp(pattern).test(urlPath),
|
|
451
|
-
)
|
|
452
|
-
|
|
453
|
-
if (isExcluded) {
|
|
454
|
-
return
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
functionNames.push(route.function)
|
|
458
|
-
routeIndexes.push(index)
|
|
459
|
-
})
|
|
460
|
-
const invocationMetadata = {
|
|
461
|
-
function_config: this.#manifest?.function_config,
|
|
462
|
-
req_routes: routeIndexes,
|
|
463
|
-
routes: this.#manifest?.routes.map((route) => ({
|
|
464
|
-
function: route.function,
|
|
465
|
-
path: route.path,
|
|
466
|
-
pattern: route.pattern,
|
|
467
|
-
})),
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return { functionNames, invocationMetadata }
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Takes the module graph returned from the server and tracks dependencies of
|
|
475
|
-
* each function.
|
|
476
|
-
*
|
|
477
|
-
* @param {ModuleGraph} graph
|
|
478
|
-
*/
|
|
479
|
-
#processGraph(graph) {
|
|
406
|
+
}, _EdgeFunctionsRegistry_processGraph = function _EdgeFunctionsRegistry_processGraph(graph) {
|
|
480
407
|
if (!graph) {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return
|
|
408
|
+
warn('Could not process edge functions dependency graph. Live reload will not be available.');
|
|
409
|
+
return;
|
|
484
410
|
}
|
|
485
|
-
|
|
486
411
|
// Creating a Map from `this.#functions` that map function paths to function
|
|
487
412
|
// names. This allows us to match modules against functions in O(1) time as
|
|
488
413
|
// opposed to O(n).
|
|
414
|
+
// @ts-expect-error TS(2339) FIXME: Property 'path' does not exist on type 'never'.
|
|
489
415
|
// eslint-disable-next-line unicorn/prefer-spread
|
|
490
|
-
const functionPaths = new Map(Array.from(this
|
|
491
|
-
|
|
416
|
+
const functionPaths = new Map(Array.from(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get), (func) => [func.path, func.name]));
|
|
492
417
|
// Mapping file URLs to names of functions that use them as dependencies.
|
|
493
|
-
const dependencyPaths = new Map()
|
|
494
|
-
|
|
418
|
+
const dependencyPaths = new Map();
|
|
419
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'specifier' implicitly has an 'any... Remove this comment to see the full error message
|
|
495
420
|
graph.modules.forEach(({ dependencies = [], specifier }) => {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
const path = fileURLToPath(specifier)
|
|
501
|
-
const functionMatch = functionPaths.get(path)
|
|
502
|
-
|
|
503
|
-
if (!functionMatch) {
|
|
504
|
-
return
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
dependencies.forEach((dependency) => {
|
|
508
|
-
// We're interested in tracking local dependencies, so we only look at
|
|
509
|
-
// specifiers with the `file:` protocol.
|
|
510
|
-
if (
|
|
511
|
-
dependency.code === undefined ||
|
|
512
|
-
typeof dependency.code.specifier !== 'string' ||
|
|
513
|
-
!dependency.code.specifier.startsWith('file://')
|
|
514
|
-
) {
|
|
515
|
-
return
|
|
421
|
+
if (!specifier.startsWith('file://')) {
|
|
422
|
+
return;
|
|
516
423
|
}
|
|
517
|
-
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
424
|
+
const path = fileURLToPath(specifier);
|
|
425
|
+
const functionMatch = functionPaths.get(path);
|
|
426
|
+
if (!functionMatch) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
dependencies.forEach((dependency) => {
|
|
430
|
+
// We're interested in tracking local dependencies, so we only look at
|
|
431
|
+
// specifiers with the `file:` protocol.
|
|
432
|
+
if (
|
|
433
|
+
// @ts-expect-error TS(2339) FIXME: Property 'code' does not exist on type 'never'.
|
|
434
|
+
dependency.code === undefined ||
|
|
435
|
+
// @ts-expect-error TS(2339) FIXME: Property 'code' does not exist on type 'never'.
|
|
436
|
+
typeof dependency.code.specifier !== 'string' ||
|
|
437
|
+
// @ts-expect-error TS(2339) FIXME: Property 'code' does not exist on type 'never'.
|
|
438
|
+
!dependency.code.specifier.startsWith('file://')) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
// @ts-expect-error TS(2339) FIXME: Property 'code' does not exist on type 'never'.
|
|
442
|
+
const { specifier: dependencyURL } = dependency.code;
|
|
443
|
+
const dependencyPath = fileURLToPath(dependencyURL);
|
|
444
|
+
const functions = dependencyPaths.get(dependencyPath) || [];
|
|
445
|
+
dependencyPaths.set(dependencyPath, [...functions, functionMatch]);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_dependencyPaths, dependencyPaths, "f");
|
|
449
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_functionPaths, functionPaths, "f");
|
|
450
|
+
}, _EdgeFunctionsRegistry_runBuild =
|
|
451
|
+
/**
|
|
452
|
+
* Thin wrapper for `#runIsolate` that skips running a build and returns an
|
|
453
|
+
* empty response if there are no functions in the registry.
|
|
454
|
+
*/
|
|
455
|
+
async function _EdgeFunctionsRegistry_runBuild() {
|
|
456
|
+
if (__classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get).length === 0) {
|
|
457
|
+
return {
|
|
458
|
+
functionsConfig: [],
|
|
459
|
+
graph: {
|
|
460
|
+
modules: [],
|
|
461
|
+
},
|
|
462
|
+
npmSpecifiersWithExtraneousFiles: [],
|
|
463
|
+
success: true,
|
|
464
|
+
};
|
|
544
465
|
}
|
|
545
|
-
|
|
546
|
-
const { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success } = await this.#runIsolate(
|
|
547
|
-
this.#functions,
|
|
548
|
-
this.#env,
|
|
549
|
-
{
|
|
466
|
+
const { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success } = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_runIsolate, "f").call(this, __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get), __classPrivateFieldGet(this, _EdgeFunctionsRegistry_env, "f"), {
|
|
550
467
|
getFunctionsConfig: true,
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
* @returns {Promise<{all: EdgeFunction[], new: EdgeFunction[], deleted: EdgeFunction[]}>}
|
|
559
|
-
*/
|
|
560
|
-
async #scanForFunctions() {
|
|
468
|
+
});
|
|
469
|
+
return { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success };
|
|
470
|
+
}, _EdgeFunctionsRegistry_scanForFunctions =
|
|
471
|
+
/**
|
|
472
|
+
* @returns {Promise<{all: EdgeFunction[], new: EdgeFunction[], deleted: EdgeFunction[]}>}
|
|
473
|
+
*/
|
|
474
|
+
async function _EdgeFunctionsRegistry_scanForFunctions() {
|
|
561
475
|
const [internalFunctions, userFunctions] = await Promise.all([
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
])
|
|
565
|
-
|
|
566
|
-
const functions = [...internalFunctions, ...userFunctions]
|
|
567
|
-
|
|
476
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_bundler, "f").find(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_internalDirectories, "f")),
|
|
477
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_bundler, "f").find(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_directories, "f")),
|
|
478
|
+
]);
|
|
479
|
+
const functions = [...internalFunctions, ...userFunctions];
|
|
568
480
|
const newFunctions = functions.filter((func) => {
|
|
569
|
-
|
|
570
|
-
(
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
(func) => func.name === existingFunc.name && func.path === existingFunc.path
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
this.#declarationsFromTOML = EdgeFunctionsRegistry.#getDeclarationsFromTOML(newConfig)
|
|
601
|
-
|
|
602
|
-
await this.#checkForAddedOrDeletedFunctions()
|
|
603
|
-
},
|
|
604
|
-
})
|
|
481
|
+
const functionExists = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get).some(
|
|
482
|
+
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'never'.
|
|
483
|
+
(existingFunc) => func.name === existingFunc.name && func.path === existingFunc.path);
|
|
484
|
+
return !functionExists;
|
|
485
|
+
});
|
|
486
|
+
const deletedFunctions = __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "a", _EdgeFunctionsRegistry_functions_get).filter((existingFunc) => {
|
|
487
|
+
const functionExists = functions.some(
|
|
488
|
+
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'never'.
|
|
489
|
+
(func) => func.name === existingFunc.name && func.path === existingFunc.path);
|
|
490
|
+
return !functionExists;
|
|
491
|
+
});
|
|
492
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_internalFunctions, internalFunctions, "f");
|
|
493
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_userFunctions, userFunctions, "f");
|
|
494
|
+
return { all: functions, new: newFunctions, deleted: deletedFunctions };
|
|
495
|
+
}, _EdgeFunctionsRegistry_setupWatchers =
|
|
496
|
+
/**
|
|
497
|
+
* @param {string} projectDir
|
|
498
|
+
*/
|
|
499
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'projectDir' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
500
|
+
async function _EdgeFunctionsRegistry_setupWatchers(projectDir) {
|
|
501
|
+
if (__classPrivateFieldGet(this, _EdgeFunctionsRegistry_configPath, "f")) {
|
|
502
|
+
// Creating a watcher for the config file. When it changes, we update the
|
|
503
|
+
// declarations and see if we need to register or unregister any functions.
|
|
504
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ onChange: () => Promise<void>;... Remove this comment to see the full error message
|
|
505
|
+
await watchDebounced(__classPrivateFieldGet(this, _EdgeFunctionsRegistry_configPath, "f"), {
|
|
506
|
+
onChange: async () => {
|
|
507
|
+
const newConfig = await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_getUpdatedConfig, "f").call(this);
|
|
508
|
+
__classPrivateFieldSet(this, _EdgeFunctionsRegistry_declarationsFromTOML, __classPrivateFieldGet(EdgeFunctionsRegistry, _a, "m", _EdgeFunctionsRegistry_getDeclarationsFromTOML).call(EdgeFunctionsRegistry, newConfig), "f");
|
|
509
|
+
await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions).call(this);
|
|
510
|
+
},
|
|
511
|
+
});
|
|
605
512
|
}
|
|
606
|
-
|
|
607
513
|
// While functions are guaranteed to be inside one of the configured
|
|
608
514
|
// directories, they might be importing files that are located in
|
|
609
515
|
// parent directories. So we watch the entire project directory for
|
|
610
516
|
// changes.
|
|
611
|
-
await this
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const ignored = [`${this
|
|
517
|
+
await __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_setupWatcherForDirectory).call(this, projectDir);
|
|
518
|
+
}, _EdgeFunctionsRegistry_setupWatcherForDirectory =
|
|
519
|
+
/**
|
|
520
|
+
* @param {string} directory
|
|
521
|
+
* @returns {Promise<void>}
|
|
522
|
+
*/
|
|
523
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'directory' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
524
|
+
async function _EdgeFunctionsRegistry_setupWatcherForDirectory(directory) {
|
|
525
|
+
const ignored = [`${__classPrivateFieldGet(this, _EdgeFunctionsRegistry_servePath, "f")}/**`];
|
|
620
526
|
const watcher = await watchDebounced(directory, {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
*/
|
|
634
|
-
#getDisplayName(func) {
|
|
635
|
-
const declarations = [...this.#declarationsFromTOML, ...this.#declarationsFromDeployConfig]
|
|
636
|
-
|
|
637
|
-
return declarations.find((declaration) => declaration.function === func)?.name ?? func
|
|
638
|
-
}
|
|
639
|
-
}
|
|
527
|
+
// @ts-expect-error TS(2322) FIXME: Type 'string[]' is not assignable to type 'never[]... Remove this comment to see the full error message
|
|
528
|
+
ignored,
|
|
529
|
+
onAdd: () => __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions).call(this),
|
|
530
|
+
// @ts-expect-error TS(2322) FIXME: Type '(paths: any) => Promise<void>' is not assign... Remove this comment to see the full error message
|
|
531
|
+
onChange: (paths) => __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_handleFileChange).call(this, paths),
|
|
532
|
+
onUnlink: () => __classPrivateFieldGet(this, _EdgeFunctionsRegistry_instances, "m", _EdgeFunctionsRegistry_checkForAddedOrDeletedFunctions).call(this),
|
|
533
|
+
});
|
|
534
|
+
__classPrivateFieldGet(this, _EdgeFunctionsRegistry_directoryWatchers, "f").set(directory, watcher);
|
|
535
|
+
}, _EdgeFunctionsRegistry_getDisplayName = function _EdgeFunctionsRegistry_getDisplayName(func) {
|
|
536
|
+
const declarations = [...__classPrivateFieldGet(this, _EdgeFunctionsRegistry_declarationsFromTOML, "f"), ...__classPrivateFieldGet(this, _EdgeFunctionsRegistry_declarationsFromDeployConfig, "f")];
|
|
537
|
+
return declarations.find((declaration) => declaration.function === func)?.name ?? func;
|
|
538
|
+
};
|