netlify-cli 17.6.0 → 17.8.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/bin/{run.mjs → run.js} +3 -3
- package/npm-shrinkwrap.json +4 -4
- package/package.json +8 -9
- package/scripts/{postinstall.mjs → postinstall.js} +3 -4
- package/src/commands/addons/addons-auth.js +22 -0
- package/src/commands/addons/{addons-config.mjs → addons-config.js} +9 -34
- package/src/commands/addons/{addons-create.mjs → addons-create.js} +7 -33
- package/src/commands/addons/addons-delete.js +33 -0
- package/src/commands/addons/{addons-list.mjs → addons-list.js} +3 -25
- package/src/commands/addons/addons.js +68 -0
- package/src/commands/addons/index.js +1 -0
- package/src/commands/api/{api.mjs → api.js} +2 -24
- package/src/commands/api/index.js +13 -0
- package/src/commands/{base-command.mjs → base-command.js} +7 -7
- package/src/commands/blobs/blobs-delete.js +20 -0
- package/src/commands/blobs/{blobs-get.mjs → blobs-get.js} +2 -15
- package/src/commands/blobs/{blobs-list.mjs → blobs-list.js} +2 -16
- package/src/commands/blobs/{blobs-set.mjs → blobs-set.js} +2 -17
- package/src/commands/blobs/blobs.js +74 -0
- package/src/commands/blobs/index.js +1 -0
- package/src/commands/build/{build.mjs → build.js} +7 -28
- package/src/commands/build/index.js +13 -0
- package/src/commands/completion/completion.js +29 -0
- package/src/commands/completion/index.js +26 -0
- package/src/commands/deploy/{deploy.mjs → deploy.js} +17 -133
- package/src/commands/deploy/index.js +106 -0
- package/src/commands/dev/{dev-exec.mjs → dev-exec.js} +3 -15
- package/src/commands/dev/{dev.mjs → dev.js} +19 -38
- package/src/commands/dev/index.js +1 -0
- package/src/commands/env/{env-clone.mjs → env-clone.js} +71 -94
- package/src/commands/env/env-get.js +34 -0
- package/src/commands/env/{env-import.mjs → env-import.js} +38 -65
- package/src/commands/env/{env-list.mjs → env-list.js} +3 -37
- package/src/commands/env/{env-set.mjs → env-set.js} +36 -81
- package/src/commands/env/{env-unset.mjs → env-unset.js} +30 -62
- package/src/commands/env/env.js +127 -0
- package/src/commands/env/index.js +1 -0
- package/src/commands/functions/{functions-build.mjs → functions-build.js} +3 -22
- package/src/commands/functions/{functions-create.mjs → functions-create.js} +20 -47
- package/src/commands/functions/{functions-invoke.mjs → functions-invoke.js} +3 -41
- package/src/commands/functions/{functions-list.mjs → functions-list.js} +3 -27
- package/src/commands/functions/{functions-serve.mjs → functions-serve.js} +6 -28
- package/src/commands/functions/functions.js +98 -0
- package/src/commands/functions/index.js +1 -0
- package/src/commands/index.js +2 -0
- package/src/commands/init/index.js +12 -0
- package/src/commands/init/{init.mjs → init.js} +10 -31
- package/src/commands/integration/{deploy.mjs → deploy.js} +7 -28
- package/src/commands/integration/index.js +26 -0
- package/src/commands/link/index.js +13 -0
- package/src/commands/link/{link.mjs → link.js} +6 -28
- package/src/commands/lm/index.js +1 -0
- package/src/commands/lm/{lm-info.mjs → lm-info.js} +2 -9
- package/src/commands/lm/lm-install.js +8 -0
- package/src/commands/lm/{lm-setup.mjs → lm-setup.js} +6 -25
- package/src/commands/lm/lm-uninstall.js +7 -0
- package/src/commands/lm/lm.js +46 -0
- package/src/commands/login/index.js +9 -0
- package/src/commands/login/{login.mjs → login.js} +1 -19
- package/src/commands/logout/index.js +7 -0
- package/src/commands/logout/{logout.mjs → logout.js} +3 -16
- package/src/commands/logs/{build.mjs → build.js} +3 -8
- package/src/commands/logs/{functions.mjs → functions.js} +4 -27
- package/src/commands/logs/index.js +39 -0
- package/src/commands/logs/log-levels.js +11 -0
- package/src/commands/{main.mjs → main.js} +32 -32
- package/src/commands/open/index.js +31 -0
- package/src/commands/open/open-admin.js +11 -0
- package/src/commands/open/open-site.js +12 -0
- package/src/commands/open/open.js +13 -0
- package/src/commands/recipes/{common.mjs → common.js} +2 -2
- package/src/commands/recipes/index.js +20 -0
- package/src/commands/recipes/recipes-list.js +14 -0
- package/src/commands/recipes/{recipes.mjs → recipes.js} +8 -32
- package/src/commands/serve/index.js +27 -0
- package/src/commands/serve/{serve.mjs → serve.js} +14 -51
- package/src/commands/sites/index.js +1 -0
- package/src/commands/sites/{sites-create-template.mjs → sites-create-template.js} +9 -38
- package/src/commands/sites/{sites-create.mjs → sites-create.js} +5 -38
- package/src/commands/sites/{sites-delete.mjs → sites-delete.js} +2 -22
- package/src/commands/sites/{sites-list.mjs → sites-list.js} +4 -24
- package/src/commands/sites/sites.js +77 -0
- package/src/commands/status/index.js +19 -0
- package/src/commands/status/{status-hooks.mjs → status-hooks.js} +2 -20
- package/src/commands/status/{status.mjs → status.js} +2 -23
- package/src/commands/switch/index.js +7 -0
- package/src/commands/switch/{switch.mjs → switch.js} +3 -16
- package/src/commands/unlink/index.js +7 -0
- package/src/commands/unlink/unlink.js +21 -0
- package/src/commands/watch/index.js +8 -0
- package/src/commands/watch/{watch.mjs → watch.js} +4 -21
- package/src/lib/{api.mjs → api.js} +1 -1
- package/src/lib/blobs/{blobs.mjs → blobs.js} +2 -2
- package/src/lib/{build.mjs → build.js} +3 -3
- package/src/lib/completion/{constants.mjs → constants.js} +1 -1
- package/src/lib/completion/{generate-autocompletion.mjs → generate-autocompletion.js} +3 -3
- package/src/lib/completion/{index.mjs → index.js} +1 -1
- package/src/lib/completion/{script.mjs → script.js} +3 -3
- package/src/lib/edge-functions/{deploy.mjs → deploy.js} +2 -2
- package/src/lib/edge-functions/{editor-helper.mjs → editor-helper.js} +1 -1
- package/src/lib/edge-functions/{internal.mjs → internal.js} +2 -2
- package/src/lib/edge-functions/{proxy.mjs → proxy.js} +10 -11
- package/src/lib/edge-functions/{registry.mjs → registry.js} +4 -2
- package/src/lib/{exec-fetcher.mjs → exec-fetcher.js} +2 -2
- package/src/lib/functions/{background.mjs → background.js} +2 -2
- package/src/lib/functions/{form-submissions-handler.mjs → form-submissions-handler.js} +3 -3
- package/src/lib/functions/{local-proxy.mjs → local-proxy.js} +1 -1
- package/src/lib/functions/{netlify-function.mjs → netlify-function.js} +18 -63
- package/src/lib/functions/{registry.mjs → registry.js} +33 -96
- package/src/lib/functions/runtimes/go/{index.mjs → index.js} +2 -2
- package/src/lib/functions/runtimes/{index.mjs → index.js} +3 -4
- package/src/lib/functions/runtimes/js/builders/{netlify-lambda.mjs → netlify-lambda.js} +3 -3
- package/src/lib/functions/runtimes/js/builders/{zisi.mjs → zisi.js} +6 -6
- package/src/lib/functions/runtimes/js/{index.mjs → index.js} +4 -4
- package/src/lib/functions/runtimes/rust/{index.mjs → index.js} +4 -4
- package/src/lib/functions/{scheduled.mjs → scheduled.js} +2 -2
- package/src/lib/functions/{server.mjs → server.js} +16 -15
- package/src/lib/functions/{synchronous.mjs → synchronous.js} +3 -3
- package/src/lib/functions/{utils.mjs → utils.js} +2 -2
- package/src/lib/{geo-location.mjs → geo-location.js} +1 -1
- package/src/lib/{http-agent.mjs → http-agent.js} +1 -1
- package/src/lib/images/{proxy.mjs → proxy.js} +3 -3
- package/src/lib/{log.mjs → log.js} +1 -1
- package/src/recipes/vscode/{index.mjs → index.js} +2 -2
- package/src/recipes/vscode/{settings.mjs → settings.js} +0 -1
- package/src/utils/addons/diffs/{index.mjs → index.js} +1 -1
- package/src/utils/addons/diffs/{options.mjs → options.js} +0 -1
- package/src/utils/addons/{prepare.mjs → prepare.js} +2 -2
- package/src/utils/addons/{prompts.mjs → prompts.js} +1 -1
- package/src/utils/addons/{render.mjs → render.js} +1 -1
- package/src/utils/{banner.mjs → banner.js} +1 -1
- package/src/utils/{build-info.mjs → build-info.js} +3 -3
- package/src/utils/{command-helpers.mjs → command-helpers.js} +4 -9
- package/src/utils/deploy/{deploy-site.mjs → deploy-site.js} +8 -8
- package/src/utils/deploy/{hash-files.mjs → hash-files.js} +1 -1
- package/src/utils/deploy/{hash-fns.mjs → hash-fns.js} +3 -3
- package/src/utils/deploy/{hasher-segments.mjs → hasher-segments.js} +1 -1
- package/src/utils/deploy/{upload-files.mjs → upload-files.js} +1 -1
- package/src/utils/deploy/{util.mjs → util.js} +1 -1
- package/src/utils/{detect-server-settings.mjs → detect-server-settings.js} +6 -7
- package/src/utils/{dev.mjs → dev.js} +3 -3
- package/src/utils/{dot-env.mjs → dot-env.js} +2 -2
- package/src/utils/env/{index.mjs → index.js} +1 -1
- package/src/utils/{framework-server.mjs → framework-server.js} +4 -4
- package/src/utils/functions/{functions.mjs → functions.js} +2 -2
- package/src/utils/functions/{get-functions.mjs → get-functions.js} +1 -1
- package/src/utils/functions/index.js +3 -0
- package/src/utils/{get-global-config.mjs → get-global-config.js} +1 -1
- package/src/utils/{get-repo-data.mjs → get-repo-data.js} +1 -1
- package/src/utils/{get-site.mjs → get-site.js} +1 -1
- package/src/utils/{gh-auth.mjs → gh-auth.js} +3 -3
- package/src/utils/{gitignore.mjs → gitignore.js} +2 -2
- package/src/utils/{headers.mjs → headers.js} +1 -1
- package/src/utils/hooks/{requires-site-info.mjs → requires-site-info.js} +1 -1
- package/src/utils/init/{config-github.mjs → config-github.js} +4 -4
- package/src/utils/init/{config-manual.mjs → config-manual.js} +5 -5
- package/src/utils/init/{config.mjs → config.js} +4 -4
- package/src/utils/init/{node-version.mjs → node-version.js} +1 -1
- package/src/utils/init/{utils.mjs → utils.js} +7 -7
- package/src/utils/{live-tunnel.mjs → live-tunnel.js} +4 -4
- package/src/utils/lm/{install.mjs → install.js} +6 -6
- package/src/utils/lm/{requirements.mjs → requirements.js} +1 -1
- package/src/utils/lm/{steps.mjs → steps.js} +2 -2
- package/src/utils/lm/{ui.mjs → ui.js} +2 -2
- package/src/utils/{open-browser.mjs → open-browser.js} +1 -1
- package/src/utils/{proxy-server.mjs → proxy-server.js} +5 -5
- package/src/utils/{proxy.mjs → proxy.js} +18 -16
- package/src/utils/{redirects.mjs → redirects.js} +1 -1
- package/src/utils/{rules-proxy.mjs → rules-proxy.js} +3 -3
- package/src/utils/{run-build.mjs → run-build.js} +8 -8
- package/src/utils/{shell.mjs → shell.js} +2 -2
- package/src/utils/{state-config.mjs → state-config.js} +1 -1
- package/src/utils/{static-server.mjs → static-server.js} +1 -1
- package/src/utils/telemetry/index.js +2 -0
- package/src/utils/telemetry/{report-error.mjs → report-error.js} +4 -4
- package/src/utils/telemetry/{request.mjs → request.js} +1 -1
- package/src/utils/telemetry/{telemetry.mjs → telemetry.js} +5 -5
- package/src/utils/telemetry/{utils.mjs → utils.js} +1 -1
- package/src/utils/telemetry/{validation.mjs → validation.js} +1 -1
- package/src/utils/{validation.mjs → validation.js} +1 -1
- package/src/commands/addons/addons-auth.mjs +0 -45
- package/src/commands/addons/addons-delete.mjs +0 -53
- package/src/commands/addons/addons.mjs +0 -39
- package/src/commands/addons/index.mjs +0 -1
- package/src/commands/api/index.mjs +0 -1
- package/src/commands/blobs/blobs-delete.mjs +0 -35
- package/src/commands/blobs/blobs.mjs +0 -32
- package/src/commands/blobs/index.mjs +0 -1
- package/src/commands/build/index.mjs +0 -1
- package/src/commands/completion/completion.mjs +0 -53
- package/src/commands/completion/index.mjs +0 -1
- package/src/commands/deploy/index.mjs +0 -1
- package/src/commands/dev/index.mjs +0 -1
- package/src/commands/dev/types.d.ts +0 -30
- package/src/commands/env/env-get.mjs +0 -66
- package/src/commands/env/env.mjs +0 -41
- package/src/commands/env/index.mjs +0 -1
- package/src/commands/functions/functions.mjs +0 -39
- package/src/commands/functions/index.mjs +0 -1
- package/src/commands/index.mjs +0 -2
- package/src/commands/init/index.mjs +0 -1
- package/src/commands/integration/index.mjs +0 -24
- package/src/commands/link/index.mjs +0 -1
- package/src/commands/lm/index.mjs +0 -1
- package/src/commands/lm/lm-install.mjs +0 -27
- package/src/commands/lm/lm-uninstall.mjs +0 -18
- package/src/commands/lm/lm.mjs +0 -30
- package/src/commands/login/index.mjs +0 -1
- package/src/commands/logout/index.mjs +0 -1
- package/src/commands/logs/index.mjs +0 -12
- package/src/commands/open/index.mjs +0 -1
- package/src/commands/open/open-admin.mjs +0 -30
- package/src/commands/open/open-site.mjs +0 -31
- package/src/commands/open/open.mjs +0 -36
- package/src/commands/recipes/index.mjs +0 -1
- package/src/commands/recipes/recipes-list.mjs +0 -25
- package/src/commands/serve/index.mjs +0 -1
- package/src/commands/sites/index.mjs +0 -2
- package/src/commands/sites/sites.mjs +0 -30
- package/src/commands/status/index.mjs +0 -1
- package/src/commands/switch/index.mjs +0 -1
- package/src/commands/types.d.ts +0 -31
- package/src/commands/unlink/index.mjs +0 -1
- package/src/commands/unlink/unlink.mjs +0 -34
- package/src/commands/watch/index.mjs +0 -1
- package/src/functions-templates/typescript/abtest/{{name}}.ts +0 -31
- package/src/functions-templates/typescript/geolocation/{{name}}.ts +0 -24
- package/src/functions-templates/typescript/hello-world/{{name}}.ts +0 -12
- package/src/functions-templates/typescript/json/{{name}}.ts +0 -5
- package/src/functions-templates/typescript/log/{{name}}.ts +0 -9
- package/src/functions-templates/typescript/scheduled-function/{{name}}.ts +0 -12
- package/src/functions-templates/typescript/set-cookies/{{name}}.ts +0 -29
- package/src/functions-templates/typescript/set-req-header/{{name}}.ts +0 -5
- package/src/functions-templates/typescript/set-res-header/{{name}}.ts +0 -7
- package/src/functions-templates/typescript/transform-response/{{name}}.ts +0 -13
- package/src/utils/functions/index.mjs +0 -3
- package/src/utils/telemetry/index.mjs +0 -2
- package/src/utils/types.d.ts +0 -46
- /package/src/functions-templates/go/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/hello/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/identity-signup/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/image-external/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/localized-content/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/sanity-create/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/sanity-groq/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/scheduled-function/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-cookies/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-req-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/set-res-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/submission-created/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/javascript/transform-response/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/rust/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/abtest/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/geolocation/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/hello-world/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/json/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/log/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/scheduled-function/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-cookies/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-req-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/set-res-header/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/functions-templates/typescript/transform-response/{.netlify-function-template.mjs → .netlify-function-template.js} +0 -0
- /package/src/lib/{account.mjs → account.js} +0 -0
- /package/src/lib/completion/{get-autocompletion.mjs → get-autocompletion.js} +0 -0
- /package/src/lib/edge-functions/{bootstrap.mjs → bootstrap.js} +0 -0
- /package/src/lib/edge-functions/{consts.mjs → consts.js} +0 -0
- /package/src/lib/edge-functions/{headers.mjs → headers.js} +0 -0
- /package/src/lib/{fs.mjs → fs.js} +0 -0
- /package/src/lib/functions/{config.mjs → config.js} +0 -0
- /package/src/lib/functions/{memoized-build.mjs → memoized-build.js} +0 -0
- /package/src/lib/functions/runtimes/js/{constants.mjs → constants.js} +0 -0
- /package/src/lib/functions/runtimes/js/{worker.mjs → worker.js} +0 -0
- /package/src/lib/{path.mjs → path.js} +0 -0
- /package/src/lib/{render-error-template.mjs → render-error-template.js} +0 -0
- /package/src/lib/{settings.mjs → settings.js} +0 -0
- /package/src/lib/{spinner.mjs → spinner.js} +0 -0
- /package/src/lib/{string.mjs → string.js} +0 -0
- /package/src/utils/addons/{compare.mjs → compare.js} +0 -0
- /package/src/utils/addons/{validation.mjs → validation.js} +0 -0
- /package/src/utils/{create-deferred.mjs → create-deferred.js} +0 -0
- /package/src/utils/{create-stream-promise.mjs → create-stream-promise.js} +0 -0
- /package/src/utils/deploy/{constants.mjs → constants.js} +0 -0
- /package/src/utils/deploy/{hash-config.mjs → hash-config.js} +0 -0
- /package/src/utils/{execa.mjs → execa.js} +0 -0
- /package/src/utils/{feature-flags.mjs → feature-flags.js} +0 -0
- /package/src/utils/functions/{constants.mjs → constants.js} +0 -0
- /package/src/utils/{get-package-json.mjs → get-package-json.js} +0 -0
- /package/src/utils/init/{plugins.mjs → plugins.js} +0 -0
- /package/src/utils/{parse-raw-flags.mjs → parse-raw-flags.js} +0 -0
- /package/src/utils/{read-repo-url.mjs → read-repo-url.js} +0 -0
- /package/src/utils/{request-id.mjs → request-id.js} +0 -0
- /package/src/utils/{sign-redirect.mjs → sign-redirect.js} +0 -0
- /package/src/utils/sites/{utils.mjs → utils.js} +0 -0
- /package/src/utils/websockets/{index.mjs → index.js} +0 -0
|
@@ -3,14 +3,12 @@ import { basename, extname } from 'path';
|
|
|
3
3
|
import { version as nodeVersion } from 'process';
|
|
4
4
|
import CronParser from 'cron-parser';
|
|
5
5
|
import semver from 'semver';
|
|
6
|
-
import { error as errorExit } from '../../utils/command-helpers.
|
|
7
|
-
import { BACKGROUND } from '../../utils/functions/get-functions.
|
|
6
|
+
import { error as errorExit } from '../../utils/command-helpers.js';
|
|
7
|
+
import { BACKGROUND } from '../../utils/functions/get-functions.js';
|
|
8
8
|
const TYPESCRIPT_EXTENSIONS = new Set(['.cts', '.mts', '.ts']);
|
|
9
9
|
const V2_MIN_NODE_VERSION = '18.14.0';
|
|
10
10
|
// Returns a new set with all elements of `setA` that don't exist in `setB`.
|
|
11
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'setA' implicitly has an 'any' type.
|
|
12
11
|
const difference = (setA, setB) => new Set([...setA].filter((item) => !setB.has(item)));
|
|
13
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'schedule' implicitly has an 'any' type.
|
|
14
12
|
const getNextRun = function (schedule) {
|
|
15
13
|
const cron = CronParser.parseExpression(schedule, {
|
|
16
14
|
tz: 'Etc/UTC',
|
|
@@ -41,60 +39,40 @@ export default class NetlifyFunction {
|
|
|
41
39
|
timeoutBackground,
|
|
42
40
|
// @ts-expect-error TS(7031) FIXME: Binding element 'timeoutSynchronous' implicitly ha... Remove this comment to see the full error message
|
|
43
41
|
timeoutSynchronous, }) {
|
|
44
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
45
|
-
this.blobsContext = blobsContext;
|
|
46
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildError' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
47
42
|
this.buildError = null;
|
|
43
|
+
// List of the function's source files. This starts out as an empty set
|
|
44
|
+
// and will get populated on every build.
|
|
45
|
+
this.srcFiles = new Set();
|
|
46
|
+
this.blobsContext = blobsContext;
|
|
48
47
|
// @ts-expect-error TS(2339) FIXME: Property 'config' does not exist on type 'NetlifyF... Remove this comment to see the full error message
|
|
49
48
|
this.config = config;
|
|
50
|
-
// @ts-expect-error TS(2339) FIXME: Property 'directory' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
51
49
|
this.directory = directory;
|
|
52
|
-
// @ts-expect-error TS(2339) FIXME: Property 'errorExit' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
53
|
-
this.errorExit = errorExit;
|
|
54
|
-
// @ts-expect-error TS(2339) FIXME: Property 'mainFile' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
55
50
|
this.mainFile = mainFile;
|
|
56
|
-
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'NetlifyFun... Remove this comment to see the full error message
|
|
57
51
|
this.name = name;
|
|
58
|
-
// @ts-expect-error TS(2339) FIXME: Property 'displayName' does not exist on type 'Net... Remove this comment to see the full error message
|
|
59
52
|
this.displayName = displayName ?? name;
|
|
60
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Net... Remove this comment to see the full error message
|
|
61
53
|
this.projectRoot = projectRoot;
|
|
62
54
|
// @ts-expect-error TS(2339) FIXME: Property 'runtime' does not exist on type 'Netlify... Remove this comment to see the full error message
|
|
63
55
|
this.runtime = runtime;
|
|
64
|
-
// @ts-expect-error TS(2339) FIXME: Property 'timeoutBackground' does not exist on typ... Remove this comment to see the full error message
|
|
65
56
|
this.timeoutBackground = timeoutBackground;
|
|
66
|
-
// @ts-expect-error TS(2339) FIXME: Property 'timeoutSynchronous' does not exist on ty... Remove this comment to see the full error message
|
|
67
57
|
this.timeoutSynchronous = timeoutSynchronous;
|
|
68
58
|
// @ts-expect-error TS(2339) FIXME: Property 'settings' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
69
59
|
this.settings = settings;
|
|
70
|
-
// Determines whether this is a background function based on the function
|
|
71
|
-
// name.
|
|
72
|
-
// @ts-expect-error TS(2339) FIXME: Property 'isBackground' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
73
60
|
this.isBackground = name.endsWith(BACKGROUND);
|
|
74
61
|
const functionConfig = config.functions && config.functions[name];
|
|
75
|
-
// @ts-expect-error TS(2339) FIXME: Property 'schedule' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
76
62
|
this.schedule = functionConfig && functionConfig.schedule;
|
|
77
|
-
// List of the function's source files. This starts out as an empty set
|
|
78
|
-
// and will get populated on every build.
|
|
79
|
-
// @ts-expect-error TS(2339) FIXME: Property 'srcFiles' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
80
63
|
this.srcFiles = new Set();
|
|
81
64
|
}
|
|
82
65
|
get filename() {
|
|
83
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
84
66
|
if (!this.buildData?.mainFile) {
|
|
85
67
|
return null;
|
|
86
68
|
}
|
|
87
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
88
69
|
return basename(this.buildData.mainFile);
|
|
89
70
|
}
|
|
90
71
|
getRecommendedExtension() {
|
|
91
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
92
72
|
if (this.buildData?.runtimeAPIVersion !== 2) {
|
|
93
73
|
return;
|
|
94
74
|
}
|
|
95
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
96
75
|
const extension = this.buildData?.mainFile ? extname(this.buildData.mainFile) : undefined;
|
|
97
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
98
76
|
const moduleFormat = this.buildData?.outputModuleFormat;
|
|
99
77
|
if (moduleFormat === 'esm') {
|
|
100
78
|
return;
|
|
@@ -103,23 +81,19 @@ export default class NetlifyFunction {
|
|
|
103
81
|
return '.mts';
|
|
104
82
|
}
|
|
105
83
|
if (extension === '.js') {
|
|
106
|
-
return '.
|
|
84
|
+
return '.js';
|
|
107
85
|
}
|
|
108
86
|
}
|
|
109
87
|
hasValidName() {
|
|
110
88
|
// same as https://github.com/netlify/bitballoon/blob/fbd7881e6c8e8c48e7a0145da4ee26090c794108/app/models/deploy.rb#L482
|
|
111
|
-
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'NetlifyFun... Remove this comment to see the full error message
|
|
112
89
|
// eslint-disable-next-line unicorn/better-regex
|
|
113
90
|
return /^[A-Za-z0-9_-]+$/.test(this.name);
|
|
114
91
|
}
|
|
115
92
|
async isScheduled() {
|
|
116
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
117
93
|
await this.buildQueue;
|
|
118
|
-
// @ts-expect-error TS(2339) FIXME: Property 'schedule' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
119
94
|
return Boolean(this.schedule);
|
|
120
95
|
}
|
|
121
96
|
isSupported() {
|
|
122
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
123
97
|
return !(this.buildData?.runtimeAPIVersion === 2 && semver.lt(nodeVersion, V2_MIN_NODE_VERSION));
|
|
124
98
|
}
|
|
125
99
|
isTypeScript() {
|
|
@@ -132,7 +106,7 @@ export default class NetlifyFunction {
|
|
|
132
106
|
if (!(await this.isScheduled())) {
|
|
133
107
|
return null;
|
|
134
108
|
}
|
|
135
|
-
// @
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
136
110
|
return getNextRun(this.schedule);
|
|
137
111
|
}
|
|
138
112
|
// The `build` method transforms source files into invocable functions. Its
|
|
@@ -146,24 +120,17 @@ export default class NetlifyFunction {
|
|
|
146
120
|
const buildFunction = await this.runtime.getBuildFunction({
|
|
147
121
|
// @ts-expect-error TS(2339) FIXME: Property 'config' does not exist on type 'NetlifyF... Remove this comment to see the full error message
|
|
148
122
|
config: this.config,
|
|
149
|
-
// @ts-expect-error TS(2339) FIXME: Property 'directory' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
150
123
|
directory: this.directory,
|
|
151
|
-
|
|
152
|
-
errorExit: this.errorExit,
|
|
124
|
+
errorExit,
|
|
153
125
|
func: this,
|
|
154
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Net... Remove this comment to see the full error message
|
|
155
126
|
projectRoot: this.projectRoot,
|
|
156
127
|
});
|
|
157
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
158
128
|
this.buildQueue = buildFunction({ cache });
|
|
159
129
|
try {
|
|
160
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
161
130
|
const { includedFiles = [], schedule, srcFiles, ...buildData } = await this.buildQueue;
|
|
162
131
|
const srcFilesSet = new Set(srcFiles);
|
|
163
132
|
const srcFilesDiff = this.getSrcFilesDiff(srcFilesSet);
|
|
164
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
165
133
|
this.buildData = buildData;
|
|
166
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildError' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
167
134
|
this.buildError = null;
|
|
168
135
|
// @ts-expect-error TS(2339) FIXME: Property 'srcFiles' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
169
136
|
this.srcFiles = srcFilesSet;
|
|
@@ -175,24 +142,18 @@ export default class NetlifyFunction {
|
|
|
175
142
|
return { includedFiles, srcFilesDiff };
|
|
176
143
|
}
|
|
177
144
|
catch (error) {
|
|
178
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildError' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
179
145
|
this.buildError = error;
|
|
180
146
|
return { error };
|
|
181
147
|
}
|
|
182
148
|
}
|
|
183
149
|
async getBuildData() {
|
|
184
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
185
150
|
await this.buildQueue;
|
|
186
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
187
151
|
return this.buildData;
|
|
188
152
|
}
|
|
189
153
|
// Compares a new set of source files against a previous one, returning an
|
|
190
154
|
// object with two Sets, one with added and the other with deleted files.
|
|
191
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'newSrcFiles' implicitly has an 'any' ty... Remove this comment to see the full error message
|
|
192
155
|
getSrcFilesDiff(newSrcFiles) {
|
|
193
|
-
// @ts-expect-error TS(2339) FIXME: Property 'srcFiles' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
194
156
|
const added = difference(newSrcFiles, this.srcFiles);
|
|
195
|
-
// @ts-expect-error TS(2339) FIXME: Property 'srcFiles' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
196
157
|
const deleted = difference(this.srcFiles, newSrcFiles);
|
|
197
158
|
return {
|
|
198
159
|
added,
|
|
@@ -201,22 +162,16 @@ export default class NetlifyFunction {
|
|
|
201
162
|
}
|
|
202
163
|
// Invokes the function and returns its response object.
|
|
203
164
|
async invoke(event = {}, context = {}) {
|
|
204
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
205
165
|
await this.buildQueue;
|
|
206
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildError' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
207
166
|
if (this.buildError) {
|
|
208
167
|
// @ts-expect-error TS(2339) FIXME: Property 'buildError' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
209
168
|
return { result: null, error: { errorMessage: this.buildError.message } };
|
|
210
169
|
}
|
|
211
|
-
// @ts-expect-error TS(2339) FIXME: Property 'isBackground' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
212
170
|
const timeout = this.isBackground ? this.timeoutBackground : this.timeoutSynchronous;
|
|
213
171
|
const environment = {};
|
|
214
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
215
172
|
if (this.blobsContext) {
|
|
216
173
|
const payload = JSON.stringify({
|
|
217
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
218
174
|
url: this.blobsContext.edgeURL,
|
|
219
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Ne... Remove this comment to see the full error message
|
|
220
175
|
token: this.blobsContext.token,
|
|
221
176
|
});
|
|
222
177
|
// @ts-expect-error TS(2339) FIXME: Property 'blobs' does not exist on type '{}'.
|
|
@@ -239,20 +194,15 @@ export default class NetlifyFunction {
|
|
|
239
194
|
}
|
|
240
195
|
/**
|
|
241
196
|
* Matches all routes agains the incoming request. If a match is found, then the matched route is returned.
|
|
242
|
-
* @param {string} rawPath
|
|
243
|
-
* @param {string} method
|
|
244
197
|
* @returns matched route
|
|
245
198
|
*/
|
|
246
|
-
|
|
247
|
-
async matchURLPath(rawPath, method) {
|
|
248
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildQueue' does not exist on type 'Netl... Remove this comment to see the full error message
|
|
199
|
+
async matchURLPath(rawPath, method, hasStaticFile) {
|
|
249
200
|
await this.buildQueue;
|
|
250
201
|
let path = rawPath !== '/' && rawPath.endsWith('/') ? rawPath.slice(0, -1) : rawPath;
|
|
251
202
|
path = path.toLowerCase();
|
|
252
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
253
203
|
const { routes = [] } = this.buildData;
|
|
254
204
|
// @ts-expect-error TS(7031) FIXME: Binding element 'expression' implicitly has an 'an... Remove this comment to see the full error message
|
|
255
|
-
|
|
205
|
+
const route = routes.find(({ expression, literal, methods }) => {
|
|
256
206
|
if (methods.length !== 0 && !methods.includes(method)) {
|
|
257
207
|
return false;
|
|
258
208
|
}
|
|
@@ -265,9 +215,15 @@ export default class NetlifyFunction {
|
|
|
265
215
|
}
|
|
266
216
|
return false;
|
|
267
217
|
});
|
|
218
|
+
if (!route) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (route.prefer_static && (await hasStaticFile())) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
return route;
|
|
268
225
|
}
|
|
269
226
|
get runtimeAPIVersion() {
|
|
270
|
-
// @ts-expect-error TS(2339) FIXME: Property 'buildData' does not exist on type 'Netli... Remove this comment to see the full error message
|
|
271
227
|
return this.buildData?.runtimeAPIVersion ?? 1;
|
|
272
228
|
}
|
|
273
229
|
get url() {
|
|
@@ -278,7 +234,6 @@ export default class NetlifyFunction {
|
|
|
278
234
|
const port = this.settings.port || this.settings.functionsPort;
|
|
279
235
|
// @ts-expect-error TS(2339) FIXME: Property 'settings' does not exist on type 'Netlif... Remove this comment to see the full error message
|
|
280
236
|
const protocol = this.settings.https ? 'https' : 'http';
|
|
281
|
-
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'NetlifyFun... Remove this comment to see the full error message
|
|
282
237
|
const url = new URL(`/.netlify/functions/${this.name}`, `${protocol}://localhost:${port}`);
|
|
283
238
|
return url.href;
|
|
284
239
|
}
|
|
@@ -4,12 +4,12 @@ import { basename, extname, isAbsolute, join, resolve } from 'path';
|
|
|
4
4
|
import { env } from 'process';
|
|
5
5
|
import { listFunctions } from '@netlify/zip-it-and-ship-it';
|
|
6
6
|
import extractZip from 'extract-zip';
|
|
7
|
-
import { chalk, log, getTerminalLink, NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, warn, watchDebounced, } from '../../utils/command-helpers.
|
|
8
|
-
import { INTERNAL_FUNCTIONS_FOLDER, SERVE_FUNCTIONS_FOLDER } from '../../utils/functions/functions.
|
|
9
|
-
import { BACKGROUND_FUNCTIONS_WARNING } from '../log.
|
|
10
|
-
import { getPathInProject } from '../settings.
|
|
11
|
-
import NetlifyFunction from './netlify-function.
|
|
12
|
-
import runtimes from './runtimes/index.
|
|
7
|
+
import { chalk, log, getTerminalLink, NETLIFYDEVERR, NETLIFYDEVLOG, NETLIFYDEVWARN, warn, watchDebounced, } from '../../utils/command-helpers.js';
|
|
8
|
+
import { INTERNAL_FUNCTIONS_FOLDER, SERVE_FUNCTIONS_FOLDER } from '../../utils/functions/functions.js';
|
|
9
|
+
import { BACKGROUND_FUNCTIONS_WARNING } from '../log.js';
|
|
10
|
+
import { getPathInProject } from '../settings.js';
|
|
11
|
+
import NetlifyFunction from './netlify-function.js';
|
|
12
|
+
import runtimes from './runtimes/index.js';
|
|
13
13
|
export const DEFAULT_FUNCTION_URL_EXPRESSION = /^\/.netlify\/(functions|builders)\/([^/]+).*/;
|
|
14
14
|
const TYPES_PACKAGE = '@netlify/functions';
|
|
15
15
|
const ZIP_EXTENSION = '.zip';
|
|
@@ -17,9 +17,7 @@ const ZIP_EXTENSION = '.zip';
|
|
|
17
17
|
* @typedef {"buildError" | "extracted" | "loaded" | "missing-types-package" | "reloaded" | "reloading" | "removed"} FunctionEvent
|
|
18
18
|
*/
|
|
19
19
|
export class FunctionsRegistry {
|
|
20
|
-
constructor({
|
|
21
|
-
// @ts-expect-error TS(7031) FIXME: Binding element 'blobsContext' implicitly has an '... Remove this comment to see the full error message
|
|
22
|
-
blobsContext,
|
|
20
|
+
constructor({ blobsContext,
|
|
23
21
|
// @ts-expect-error TS(7031) FIXME: Binding element 'capabilities' implicitly has an '... Remove this comment to see the full error message
|
|
24
22
|
capabilities,
|
|
25
23
|
// @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
@@ -27,33 +25,36 @@ export class FunctionsRegistry {
|
|
|
27
25
|
// @ts-expect-error TS(7031) FIXME: Binding element 'logLambdaCompat' implicitly has a... Remove this comment to see the full error message
|
|
28
26
|
logLambdaCompat,
|
|
29
27
|
// @ts-expect-error TS(7031) FIXME: Binding element 'manifest' implicitly has an 'any'... Remove this comment to see the full error message
|
|
30
|
-
manifest,
|
|
31
|
-
// @ts-expect-error TS(7031) FIXME: Binding element 'projectRoot' implicitly has an 'a... Remove this comment to see the full error message
|
|
32
|
-
projectRoot,
|
|
28
|
+
manifest, projectRoot,
|
|
33
29
|
// @ts-expect-error TS(7031) FIXME: Binding element 'settings' implicitly has an 'any'... Remove this comment to see the full error message
|
|
34
30
|
settings,
|
|
35
31
|
// @ts-expect-error TS(7031) FIXME: Binding element 'timeouts' implicitly has an 'any'... Remove this comment to see the full error message
|
|
36
32
|
timeouts, }) {
|
|
33
|
+
/**
|
|
34
|
+
* The functions held by the registry
|
|
35
|
+
*/
|
|
36
|
+
this.functions = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* File watchers for function files. Maps function names to objects built
|
|
39
|
+
* by the `watchDebounced` utility.
|
|
40
|
+
*/
|
|
41
|
+
this.functionWatchers = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* Keeps track of whether we've checked whether `TYPES_PACKAGE` is
|
|
44
|
+
* installed.
|
|
45
|
+
*/
|
|
46
|
+
this.hasCheckedTypesPackage = false;
|
|
37
47
|
// @ts-expect-error TS(2339) FIXME: Property 'capabilities' does not exist on type 'Fu... Remove this comment to see the full error message
|
|
38
48
|
this.capabilities = capabilities;
|
|
39
49
|
// @ts-expect-error TS(2339) FIXME: Property 'config' does not exist on type 'Function... Remove this comment to see the full error message
|
|
40
50
|
this.config = config;
|
|
41
|
-
// @ts-expect-error TS(2339) FIXME: Property 'debug' does not exist on type 'Functions... Remove this comment to see the full error message
|
|
42
51
|
this.debug = debug;
|
|
43
|
-
// @ts-expect-error TS(2339) FIXME: Property 'isConnected' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
44
52
|
this.isConnected = isConnected;
|
|
45
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
46
53
|
this.projectRoot = projectRoot;
|
|
47
54
|
// @ts-expect-error TS(2339) FIXME: Property 'timeouts' does not exist on type 'Functi... Remove this comment to see the full error message
|
|
48
55
|
this.timeouts = timeouts;
|
|
49
56
|
// @ts-expect-error TS(2339) FIXME: Property 'settings' does not exist on type 'Functi... Remove this comment to see the full error message
|
|
50
57
|
this.settings = settings;
|
|
51
|
-
/**
|
|
52
|
-
* Context object for Netlify Blobs
|
|
53
|
-
*
|
|
54
|
-
* @type {import("../blobs/blobs.mjs").BlobsContext}
|
|
55
|
-
*/
|
|
56
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Fu... Remove this comment to see the full error message
|
|
57
58
|
this.blobsContext = blobsContext;
|
|
58
59
|
/**
|
|
59
60
|
* An object to be shared among all functions in the registry. It can be
|
|
@@ -73,27 +74,6 @@ export class FunctionsRegistry {
|
|
|
73
74
|
*/
|
|
74
75
|
// @ts-expect-error TS(2339) FIXME: Property 'directoryWatchers' does not exist on typ... Remove this comment to see the full error message
|
|
75
76
|
this.directoryWatchers = new Map();
|
|
76
|
-
/**
|
|
77
|
-
* The functions held by the registry
|
|
78
|
-
*
|
|
79
|
-
* @type {Map<string, NetlifyFunction>}
|
|
80
|
-
*/
|
|
81
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
82
|
-
this.functions = new Map();
|
|
83
|
-
/**
|
|
84
|
-
* File watchers for function files. Maps function names to objects built
|
|
85
|
-
* by the `watchDebounced` utility.
|
|
86
|
-
*
|
|
87
|
-
* @type {Map<string, Awaited<ReturnType<watchDebounced>>>}
|
|
88
|
-
*/
|
|
89
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functionWatchers' does not exist on type... Remove this comment to see the full error message
|
|
90
|
-
this.functionWatchers = new Map();
|
|
91
|
-
/**
|
|
92
|
-
* Keeps track of whether we've checked whether `TYPES_PACKAGE` is
|
|
93
|
-
* installed.
|
|
94
|
-
*/
|
|
95
|
-
// @ts-expect-error TS(2339) FIXME: Property 'hasCheckedTypesPackage' does not exist o... Remove this comment to see the full error message
|
|
96
|
-
this.hasCheckedTypesPackage = false;
|
|
97
77
|
/**
|
|
98
78
|
* Whether to log V1 functions as using the "Lambda compatibility mode"
|
|
99
79
|
*
|
|
@@ -111,16 +91,12 @@ export class FunctionsRegistry {
|
|
|
111
91
|
this.manifest = manifest;
|
|
112
92
|
}
|
|
113
93
|
checkTypesPackage() {
|
|
114
|
-
// @ts-expect-error TS(2339) FIXME: Property 'hasCheckedTypesPackage' does not exist o... Remove this comment to see the full error message
|
|
115
94
|
if (this.hasCheckedTypesPackage) {
|
|
116
95
|
return;
|
|
117
96
|
}
|
|
118
|
-
// @ts-expect-error TS(2339) FIXME: Property 'hasCheckedTypesPackage' does not exist o... Remove this comment to see the full error message
|
|
119
97
|
this.hasCheckedTypesPackage = true;
|
|
120
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
121
98
|
const require = createRequire(this.projectRoot);
|
|
122
99
|
try {
|
|
123
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
124
100
|
require.resolve(TYPES_PACKAGE, { paths: [this.projectRoot] });
|
|
125
101
|
}
|
|
126
102
|
catch (error) {
|
|
@@ -135,10 +111,7 @@ export class FunctionsRegistry {
|
|
|
135
111
|
* Runs before `scan` and calls any `onDirectoryScan` hooks defined by the
|
|
136
112
|
* runtime before the directory is read. This gives runtime the opportunity
|
|
137
113
|
* to run additional logic when a directory is scanned.
|
|
138
|
-
*
|
|
139
|
-
* @param {string} directory
|
|
140
114
|
*/
|
|
141
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'directory' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
142
115
|
static async prepareDirectoryScan(directory) {
|
|
143
116
|
await mkdir(directory, { recursive: true });
|
|
144
117
|
// We give runtimes the opportunity to react to a directory scan and run
|
|
@@ -156,12 +129,7 @@ export class FunctionsRegistry {
|
|
|
156
129
|
/**
|
|
157
130
|
* Builds a function and sets up the appropriate file watchers so that any
|
|
158
131
|
* changes will trigger another build.
|
|
159
|
-
*
|
|
160
|
-
* @param {NetlifyFunction} func
|
|
161
|
-
* @param {boolean} [firstLoad ]
|
|
162
|
-
* @returns
|
|
163
132
|
*/
|
|
164
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'func' implicitly has an 'any' type.
|
|
165
133
|
async buildFunctionAndWatchFiles(func, firstLoad = false) {
|
|
166
134
|
if (!firstLoad) {
|
|
167
135
|
FunctionsRegistry.logEvent('reloading', { func });
|
|
@@ -196,16 +164,13 @@ export class FunctionsRegistry {
|
|
|
196
164
|
if (!srcFilesDiff) {
|
|
197
165
|
return;
|
|
198
166
|
}
|
|
199
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functionWatchers' does not exist on type... Remove this comment to see the full error message
|
|
200
167
|
const watcher = this.functionWatchers.get(func.name);
|
|
201
168
|
// If there is already a watcher for this function, we need to unwatch any
|
|
202
169
|
// files that have been removed and watch any files that have been added.
|
|
203
170
|
if (watcher) {
|
|
204
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'path' implicitly has an 'any' type.
|
|
205
171
|
srcFilesDiff.deleted.forEach((path) => {
|
|
206
172
|
watcher.unwatch(path);
|
|
207
173
|
});
|
|
208
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'path' implicitly has an 'any' type.
|
|
209
174
|
srcFilesDiff.added.forEach((path) => {
|
|
210
175
|
watcher.add(path);
|
|
211
176
|
});
|
|
@@ -220,18 +185,13 @@ export class FunctionsRegistry {
|
|
|
220
185
|
this.buildFunctionAndWatchFiles(func, false);
|
|
221
186
|
},
|
|
222
187
|
});
|
|
223
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functionWatchers' does not exist on type... Remove this comment to see the full error message
|
|
224
188
|
this.functionWatchers.set(func.name, newWatcher);
|
|
225
189
|
}
|
|
226
190
|
}
|
|
227
191
|
/**
|
|
228
192
|
* Returns a function by name.
|
|
229
|
-
*
|
|
230
|
-
* @param {string} name
|
|
231
193
|
*/
|
|
232
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'name' implicitly has an 'any' type.
|
|
233
194
|
get(name) {
|
|
234
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
235
195
|
return this.functions.get(name);
|
|
236
196
|
}
|
|
237
197
|
/**
|
|
@@ -240,17 +200,13 @@ export class FunctionsRegistry {
|
|
|
240
200
|
* matches the default functions URL (i.e. can only be for a function) but no
|
|
241
201
|
* function with the given name exists, returns an object with the function
|
|
242
202
|
* and the route set to `null`. Otherwise, `undefined` is returned,
|
|
243
|
-
*
|
|
244
|
-
* @param {string} url
|
|
245
|
-
* @param {string} method
|
|
246
203
|
*/
|
|
247
|
-
|
|
248
|
-
async getFunctionForURLPath(url, method) {
|
|
204
|
+
async getFunctionForURLPath(urlPath, method, hasStaticFile) {
|
|
249
205
|
// We're constructing a URL object just so that we can extract the path from
|
|
250
206
|
// the incoming URL. It doesn't really matter that we don't have the actual
|
|
251
207
|
// local URL with the correct port.
|
|
252
|
-
const
|
|
253
|
-
const defaultURLMatch =
|
|
208
|
+
const url = new URL(`http://localhost${urlPath}`);
|
|
209
|
+
const defaultURLMatch = url.pathname.match(DEFAULT_FUNCTION_URL_EXPRESSION);
|
|
254
210
|
if (defaultURLMatch) {
|
|
255
211
|
const func = this.get(defaultURLMatch[2]);
|
|
256
212
|
if (!func) {
|
|
@@ -260,14 +216,13 @@ export class FunctionsRegistry {
|
|
|
260
216
|
if (routes.length !== 0) {
|
|
261
217
|
// @ts-expect-error TS(7006) FIXME: Parameter 'route' implicitly has an 'any' type.
|
|
262
218
|
const paths = routes.map((route) => chalk.underline(route.pattern)).join(', ');
|
|
263
|
-
warn(`Function ${chalk.yellow(func.name)} cannot be invoked on ${chalk.underline(
|
|
219
|
+
warn(`Function ${chalk.yellow(func.name)} cannot be invoked on ${chalk.underline(url.pathname)}, because the function has the following URL paths defined: ${paths}`);
|
|
264
220
|
return;
|
|
265
221
|
}
|
|
266
222
|
return { func, route: null };
|
|
267
223
|
}
|
|
268
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
269
224
|
for (const func of this.functions.values()) {
|
|
270
|
-
const route = await func.matchURLPath(
|
|
225
|
+
const route = await func.matchURLPath(url.pathname, method, hasStaticFile);
|
|
271
226
|
if (route) {
|
|
272
227
|
return { func, route };
|
|
273
228
|
}
|
|
@@ -352,7 +307,6 @@ export class FunctionsRegistry {
|
|
|
352
307
|
// the new location.
|
|
353
308
|
if (extname(func.mainFile) === ZIP_EXTENSION) {
|
|
354
309
|
const unzippedDirectory = await this.unzipFunction(func);
|
|
355
|
-
// @ts-expect-error TS(2339) FIXME: Property 'debug' does not exist on type 'Functions... Remove this comment to see the full error message
|
|
356
310
|
if (this.debug) {
|
|
357
311
|
FunctionsRegistry.logEvent('extracted', { func });
|
|
358
312
|
}
|
|
@@ -360,9 +314,12 @@ export class FunctionsRegistry {
|
|
|
360
314
|
// the build data.
|
|
361
315
|
// @ts-expect-error TS(2339) FIXME: Property 'manifest' does not exist on type 'Functi... Remove this comment to see the full error message
|
|
362
316
|
const manifestEntry = (this.manifest?.functions || []).find((manifestFunc) => manifestFunc.name === func.name);
|
|
363
|
-
func.buildData =
|
|
317
|
+
func.buildData = {
|
|
318
|
+
...manifestEntry?.buildData,
|
|
319
|
+
routes: manifestEntry.routes,
|
|
320
|
+
};
|
|
364
321
|
// When we look at an unzipped function, we don't know whether it uses
|
|
365
|
-
// the legacy entry file format (i.e. `[function name].
|
|
322
|
+
// the legacy entry file format (i.e. `[function name].mjs`) or the new
|
|
366
323
|
// one (i.e. `___netlify-entry-point.mjs`). Let's look for the new one
|
|
367
324
|
// and use it if it exists, otherwise use the old one.
|
|
368
325
|
try {
|
|
@@ -377,7 +334,6 @@ export class FunctionsRegistry {
|
|
|
377
334
|
else {
|
|
378
335
|
this.buildFunctionAndWatchFiles(func, !isReload);
|
|
379
336
|
}
|
|
380
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
381
337
|
this.functions.set(name, func);
|
|
382
338
|
}
|
|
383
339
|
/**
|
|
@@ -419,7 +375,6 @@ export class FunctionsRegistry {
|
|
|
419
375
|
});
|
|
420
376
|
// Before registering any functions, we look for any functions that were on
|
|
421
377
|
// the previous list but are missing from the new one. We unregister them.
|
|
422
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
423
378
|
const deletedFunctions = [...this.functions.values()].filter((oldFunc) => {
|
|
424
379
|
const isFound = functions.some((newFunc) => newFunc.name === oldFunc.name && newFunc.mainFile === oldFunc.mainFile);
|
|
425
380
|
return !isFound;
|
|
@@ -438,12 +393,10 @@ export class FunctionsRegistry {
|
|
|
438
393
|
return;
|
|
439
394
|
}
|
|
440
395
|
// If this function has already been registered, we skip it.
|
|
441
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
442
396
|
if (this.functions.has(name)) {
|
|
443
397
|
return;
|
|
444
398
|
}
|
|
445
399
|
const func = new NetlifyFunction({
|
|
446
|
-
// @ts-expect-error TS(2339) FIXME: Property 'blobsContext' does not exist on type 'Fu... Remove this comment to see the full error message
|
|
447
400
|
blobsContext: this.blobsContext,
|
|
448
401
|
// @ts-expect-error TS(2339) FIXME: Property 'config' does not exist on type 'Function... Remove this comment to see the full error message
|
|
449
402
|
config: this.config,
|
|
@@ -452,7 +405,6 @@ export class FunctionsRegistry {
|
|
|
452
405
|
mainFile,
|
|
453
406
|
name,
|
|
454
407
|
displayName,
|
|
455
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
456
408
|
projectRoot: this.projectRoot,
|
|
457
409
|
runtime,
|
|
458
410
|
// @ts-expect-error TS(2339) FIXME: Property 'timeouts' does not exist on type 'Functi... Remove this comment to see the full error message
|
|
@@ -469,7 +421,6 @@ export class FunctionsRegistry {
|
|
|
469
421
|
await this.registerFunction(name, func, isReload);
|
|
470
422
|
return func;
|
|
471
423
|
}));
|
|
472
|
-
// @ts-expect-error TS(2339) FIXME: Property 'name' does not exist on type 'NetlifyFun... Remove this comment to see the full error message
|
|
473
424
|
const addedFunctionNames = new Set(addedFunctions.filter(Boolean).map((func) => func?.name));
|
|
474
425
|
deletedFunctions.forEach((func) => {
|
|
475
426
|
// If a function we've unregistered was also registered in this run, then
|
|
@@ -486,10 +437,7 @@ export class FunctionsRegistry {
|
|
|
486
437
|
* Creates a watcher that looks at files being added or removed from a
|
|
487
438
|
* functions directory. It doesn't care about files being changed, because
|
|
488
439
|
* those will be handled by each functions' watcher.
|
|
489
|
-
*
|
|
490
|
-
* @param {string} directory
|
|
491
440
|
*/
|
|
492
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'directory' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
493
441
|
async setupDirectoryWatcher(directory) {
|
|
494
442
|
// @ts-expect-error TS(2339) FIXME: Property 'directoryWatchers' does not exist on typ... Remove this comment to see the full error message
|
|
495
443
|
if (this.directoryWatchers.has(directory)) {
|
|
@@ -509,32 +457,21 @@ export class FunctionsRegistry {
|
|
|
509
457
|
}
|
|
510
458
|
/**
|
|
511
459
|
* Removes a function from the registry and closes its file watchers.
|
|
512
|
-
*
|
|
513
|
-
* @param {NetlifyFunction} func
|
|
514
460
|
*/
|
|
515
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'func' implicitly has an 'any' type.
|
|
516
461
|
async unregisterFunction(func) {
|
|
517
462
|
const { name } = func;
|
|
518
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type 'Funct... Remove this comment to see the full error message
|
|
519
463
|
this.functions.delete(name);
|
|
520
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functionWatchers' does not exist on type... Remove this comment to see the full error message
|
|
521
464
|
const watcher = this.functionWatchers.get(name);
|
|
522
465
|
if (watcher) {
|
|
523
466
|
await watcher.close();
|
|
524
467
|
}
|
|
525
|
-
// @ts-expect-error TS(2339) FIXME: Property 'functionWatchers' does not exist on type... Remove this comment to see the full error message
|
|
526
468
|
this.functionWatchers.delete(name);
|
|
527
469
|
}
|
|
528
470
|
/**
|
|
529
471
|
* Takes a zipped function and extracts its contents to an internal directory.
|
|
530
|
-
*
|
|
531
|
-
* @param {NetlifyFunction} func
|
|
532
472
|
*/
|
|
533
|
-
// @ts-expect-error TS(7006) FIXME: Parameter 'func' implicitly has an 'any' type.
|
|
534
473
|
async unzipFunction(func) {
|
|
535
|
-
const targetDirectory = resolve(
|
|
536
|
-
// @ts-expect-error TS(2339) FIXME: Property 'projectRoot' does not exist on type 'Fun... Remove this comment to see the full error message
|
|
537
|
-
this.projectRoot, getPathInProject([SERVE_FUNCTIONS_FOLDER, '.unzipped', func.name]));
|
|
474
|
+
const targetDirectory = resolve(this.projectRoot, getPathInProject([SERVE_FUNCTIONS_FOLDER, '.unzipped', func.name]));
|
|
538
475
|
await extractZip(func.mainFile, { dir: targetDirectory });
|
|
539
476
|
return targetDirectory;
|
|
540
477
|
}
|
|
@@ -2,8 +2,8 @@ import { dirname, extname } from 'path';
|
|
|
2
2
|
import { platform } from 'process';
|
|
3
3
|
import { temporaryFile } from 'tempy';
|
|
4
4
|
// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
|
|
5
|
-
import execa from '../../../../utils/execa.
|
|
6
|
-
import { runFunctionsProxy } from '../../local-proxy.
|
|
5
|
+
import execa from '../../../../utils/execa.js';
|
|
6
|
+
import { runFunctionsProxy } from '../../local-proxy.js';
|
|
7
7
|
const isWindows = platform === 'win32';
|
|
8
8
|
export const name = 'go';
|
|
9
9
|
// @ts-expect-error TS(7031) FIXME: Binding element 'binaryPath' implicitly has an 'an... Remove this comment to see the full error message
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import * as
|
|
3
|
-
import * as
|
|
4
|
-
import * as rust from './rust/index.mjs';
|
|
1
|
+
import * as go from './go/index.js';
|
|
2
|
+
import * as js from './js/index.js';
|
|
3
|
+
import * as rust from './rust/index.js';
|
|
5
4
|
/* eslint-enable import/no-namespace */
|
|
6
5
|
/**
|
|
7
6
|
* @callback BuildFunction
|
|
@@ -2,9 +2,9 @@ import { readFile } from 'fs/promises';
|
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import minimist from 'minimist';
|
|
4
4
|
// @ts-expect-error TS(7034) FIXME: Variable 'execa' implicitly has type 'any' in some... Remove this comment to see the full error message
|
|
5
|
-
import execa from '../../../../../utils/execa.
|
|
6
|
-
import { fileExistsAsync } from '../../../../fs.
|
|
7
|
-
import { memoizedBuild } from '../../../memoized-build.
|
|
5
|
+
import execa from '../../../../../utils/execa.js';
|
|
6
|
+
import { fileExistsAsync } from '../../../../fs.js';
|
|
7
|
+
import { memoizedBuild } from '../../../memoized-build.js';
|
|
8
8
|
// @ts-expect-error TS(2525) FIXME: Initializer provides no value for this binding ele... Remove this comment to see the full error message
|
|
9
9
|
export const detectNetlifyLambda = async function ({ packageJson } = {}) {
|
|
10
10
|
const { dependencies, devDependencies, scripts } = packageJson || {};
|
|
@@ -6,11 +6,11 @@ import decache from 'decache';
|
|
|
6
6
|
import { readPackageUp } from 'read-pkg-up';
|
|
7
7
|
// @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'sour... Remove this comment to see the full error message
|
|
8
8
|
import sourceMapSupport from 'source-map-support';
|
|
9
|
-
import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.
|
|
10
|
-
import { SERVE_FUNCTIONS_FOLDER } from '../../../../../utils/functions/functions.
|
|
11
|
-
import { getPathInProject } from '../../../../settings.
|
|
12
|
-
import { normalizeFunctionsConfig } from '../../../config.
|
|
13
|
-
import { memoizedBuild } from '../../../memoized-build.
|
|
9
|
+
import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.js';
|
|
10
|
+
import { SERVE_FUNCTIONS_FOLDER } from '../../../../../utils/functions/functions.js';
|
|
11
|
+
import { getPathInProject } from '../../../../settings.js';
|
|
12
|
+
import { normalizeFunctionsConfig } from '../../../config.js';
|
|
13
|
+
import { memoizedBuild } from '../../../memoized-build.js';
|
|
14
14
|
const require = createRequire(import.meta.url);
|
|
15
15
|
// @ts-expect-error TS(7006) FIXME: Parameter 'config' implicitly has an 'any' type.
|
|
16
16
|
const addFunctionsConfigDefaults = (config) => ({
|
|
@@ -142,7 +142,7 @@ export default async function handler({ config, directory, errorExit, func, meta
|
|
|
142
142
|
}
|
|
143
143
|
else {
|
|
144
144
|
// We must use esbuild for certain file extensions.
|
|
145
|
-
const mustTranspile = ['.
|
|
145
|
+
const mustTranspile = ['.js', '.ts', '.mts', '.cts'].includes(path.extname(func.mainFile));
|
|
146
146
|
const mustUseEsbuild = hasTypeModule || mustTranspile;
|
|
147
147
|
if (mustUseEsbuild && !functionsConfig['*'].nodeBundler) {
|
|
148
148
|
functionsConfig['*'].nodeBundler = 'esbuild';
|