netlify-cli 17.3.1 → 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 +3 -139
- package/npm-shrinkwrap.json +82 -82
- 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 -89
- 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
package/src/lib/http-agent.mjs
CHANGED
|
@@ -1,99 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import waitPort from 'wait-port'
|
|
6
|
-
|
|
7
|
-
import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.mjs'
|
|
8
|
-
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import HttpsProxyAgent from 'https-proxy-agent';
|
|
3
|
+
import waitPort from 'wait-port';
|
|
4
|
+
import { NETLIFYDEVERR, NETLIFYDEVWARN, exit, log } from '../utils/command-helpers.mjs';
|
|
9
5
|
// https://github.com/TooTallNate/node-https-proxy-agent/issues/89
|
|
10
6
|
// Maybe replace with https://github.com/delvedor/hpagent
|
|
7
|
+
// @ts-expect-error TS(2507) FIXME: Type 'typeof createHttpsProxyAgent' is not a const... Remove this comment to see the full error message
|
|
11
8
|
class HttpsProxyAgentWithCA extends HttpsProxyAgent {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'opts' implicitly has an 'any' type.
|
|
10
|
+
constructor(opts) {
|
|
11
|
+
super(opts);
|
|
12
|
+
// @ts-expect-error TS(2339) FIXME: Property 'ca' does not exist on type 'HttpsProxyAg... Remove this comment to see the full error message
|
|
13
|
+
this.ca = opts.ca;
|
|
14
|
+
}
|
|
15
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
|
|
16
|
+
callback(req, opts) {
|
|
17
|
+
return super.callback(req, {
|
|
18
|
+
...opts,
|
|
19
|
+
// @ts-expect-error TS(2339) FIXME: Property 'ca' does not exist on type 'HttpsProxyAg... Remove this comment to see the full error message
|
|
20
|
+
...(this.ca && { ca: this.ca }),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const DEFAULT_HTTPS_PORT = 443
|
|
24
|
+
const DEFAULT_HTTP_PORT = 80;
|
|
25
|
+
const DEFAULT_HTTPS_PORT = 443;
|
|
27
26
|
// 50 seconds
|
|
28
|
-
const AGENT_PORT_TIMEOUT = 50
|
|
29
|
-
|
|
27
|
+
const AGENT_PORT_TIMEOUT = 50;
|
|
28
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'certificateFile' implicitly has a... Remove this comment to see the full error message
|
|
30
29
|
export const tryGetAgent = async ({ certificateFile, httpProxy }) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let proxyUrl
|
|
36
|
-
try {
|
|
37
|
-
proxyUrl = new URL(httpProxy)
|
|
38
|
-
} catch {
|
|
39
|
-
return { error: `${httpProxy} is not a valid URL` }
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const scheme = proxyUrl.protocol.slice(0, -1)
|
|
43
|
-
if (!['http', 'https'].includes(scheme)) {
|
|
44
|
-
return { error: `${httpProxy} must have a scheme of http or https` }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
let port
|
|
48
|
-
try {
|
|
49
|
-
port = await waitPort({
|
|
50
|
-
port: Number.parseInt(proxyUrl.port) || (scheme === 'http' ? DEFAULT_HTTP_PORT : DEFAULT_HTTPS_PORT),
|
|
51
|
-
host: proxyUrl.hostname,
|
|
52
|
-
timeout: AGENT_PORT_TIMEOUT,
|
|
53
|
-
output: 'silent',
|
|
54
|
-
})
|
|
55
|
-
} catch (error) {
|
|
56
|
-
// unknown error
|
|
57
|
-
return { error: `${httpProxy} is not available.`, message: error.message }
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (!port.open) {
|
|
61
|
-
// timeout error
|
|
62
|
-
return { error: `Could not connect to '${httpProxy}'` }
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
let response = {}
|
|
66
|
-
|
|
67
|
-
let certificate
|
|
68
|
-
if (certificateFile) {
|
|
30
|
+
if (!httpProxy) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
let proxyUrl;
|
|
69
34
|
try {
|
|
70
|
-
|
|
71
|
-
} catch (error) {
|
|
72
|
-
response = { warning: `Could not read certificate file '${certificateFile}'.`, message: error.message }
|
|
35
|
+
proxyUrl = new URL(httpProxy);
|
|
73
36
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
37
|
+
catch {
|
|
38
|
+
return { error: `${httpProxy} is not a valid URL` };
|
|
39
|
+
}
|
|
40
|
+
const scheme = proxyUrl.protocol.slice(0, -1);
|
|
41
|
+
if (!['http', 'https'].includes(scheme)) {
|
|
42
|
+
return { error: `${httpProxy} must have a scheme of http or https` };
|
|
43
|
+
}
|
|
44
|
+
let port;
|
|
45
|
+
try {
|
|
46
|
+
port = await waitPort({
|
|
47
|
+
port: Number.parseInt(proxyUrl.port) || (scheme === 'http' ? DEFAULT_HTTP_PORT : DEFAULT_HTTPS_PORT),
|
|
48
|
+
host: proxyUrl.hostname,
|
|
49
|
+
timeout: AGENT_PORT_TIMEOUT,
|
|
50
|
+
output: 'silent',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// unknown error
|
|
55
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
56
|
+
return { error: `${httpProxy} is not available.`, message: error.message };
|
|
57
|
+
}
|
|
58
|
+
if (!port.open) {
|
|
59
|
+
// timeout error
|
|
60
|
+
return { error: `Could not connect to '${httpProxy}'` };
|
|
61
|
+
}
|
|
62
|
+
let response = {};
|
|
63
|
+
let certificate;
|
|
64
|
+
if (certificateFile) {
|
|
65
|
+
try {
|
|
66
|
+
certificate = await readFile(certificateFile);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
70
|
+
response = { warning: `Could not read certificate file '${certificateFile}'.`, message: error.message };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const opts = {
|
|
74
|
+
port: proxyUrl.port,
|
|
75
|
+
host: proxyUrl.host,
|
|
76
|
+
hostname: proxyUrl.hostname,
|
|
77
|
+
protocol: proxyUrl.protocol,
|
|
78
|
+
ca: certificate,
|
|
79
|
+
};
|
|
80
|
+
const agent = new HttpsProxyAgentWithCA(opts);
|
|
81
|
+
response = { ...response, agent };
|
|
82
|
+
return response;
|
|
83
|
+
};
|
|
84
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'certificateFile' implicitly has a... Remove this comment to see the full error message
|
|
89
85
|
export const getAgent = async ({ certificateFile, httpProxy }) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
86
|
+
// @ts-expect-error TS(2339) FIXME: Property 'agent' does not exist on type '{ error?:... Remove this comment to see the full error message
|
|
87
|
+
const { agent, error, message, warning } = await tryGetAgent({ httpProxy, certificateFile });
|
|
88
|
+
if (error) {
|
|
89
|
+
log(NETLIFYDEVERR, error, message || '');
|
|
90
|
+
exit(1);
|
|
91
|
+
}
|
|
92
|
+
if (warning) {
|
|
93
|
+
log(NETLIFYDEVWARN, warning, message || '');
|
|
94
|
+
}
|
|
95
|
+
return agent;
|
|
96
|
+
};
|
package/src/lib/images/proxy.mjs
CHANGED
|
@@ -1,97 +1,105 @@
|
|
|
1
|
-
import express from 'express'
|
|
2
|
-
import { createIPX, ipxFSStorage, ipxHttpStorage, createIPXNodeServer } from 'ipx'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export const IMAGE_URL_PATTERN = '/.netlify/images'
|
|
7
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { createIPX, ipxFSStorage, ipxHttpStorage, createIPXNodeServer } from 'ipx';
|
|
3
|
+
import { log, NETLIFYDEVERR } from '../../utils/command-helpers.mjs';
|
|
4
|
+
export const IMAGE_URL_PATTERN = '/.netlify/images';
|
|
5
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'config' implicitly has an 'any' type.
|
|
8
6
|
export const parseAllDomains = function (config) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const remoteDomains = []
|
|
15
|
-
const errors = []
|
|
16
|
-
|
|
17
|
-
for (const patternString of domains) {
|
|
18
|
-
try {
|
|
19
|
-
const url = new URL(patternString)
|
|
20
|
-
if (url.hostname) {
|
|
21
|
-
remoteDomains.push(url.hostname)
|
|
22
|
-
} else {
|
|
23
|
-
errors.push(`The URL '${patternString}' does not have a valid hostname.`)
|
|
24
|
-
}
|
|
25
|
-
} catch (error) {
|
|
26
|
-
errors.push(`Invalid URL '${patternString}': ${error.message}`)
|
|
7
|
+
const domains = config?.images?.remote_images;
|
|
8
|
+
if (!domains) {
|
|
9
|
+
return { errors: [], remoteDomains: [] };
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
const remoteDomains = [];
|
|
12
|
+
const errors = [];
|
|
13
|
+
for (const patternString of domains) {
|
|
14
|
+
try {
|
|
15
|
+
const url = new URL(patternString);
|
|
16
|
+
if (url.hostname) {
|
|
17
|
+
remoteDomains.push(url.hostname);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
errors.push(`The URL '${patternString}' does not have a valid hostname.`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
25
|
+
errors.push(`Invalid URL '${patternString}': ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { errors, remoteDomains };
|
|
29
|
+
};
|
|
30
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'message' implicitly has an 'any' ... Remove this comment to see the full error message
|
|
33
31
|
const getErrorMessage = function ({ message }) {
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
32
|
+
return message;
|
|
33
|
+
};
|
|
34
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'errors' implicitly has an 'any' type.
|
|
37
35
|
export const handleImageDomainsErrors = async function (errors) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
if (errors.length === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const errorMessage = await errors.map(getErrorMessage).join('\n\n');
|
|
40
|
+
log(NETLIFYDEVERR, `Image domains syntax errors:\n${errorMessage}`);
|
|
41
|
+
};
|
|
42
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
46
43
|
export const parseRemoteImageDomains = async function ({ config }) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
44
|
+
if (!config) {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
const { errors, remoteDomains } = await parseAllDomains(config);
|
|
48
|
+
await handleImageDomainsErrors(errors);
|
|
49
|
+
return remoteDomains;
|
|
50
|
+
};
|
|
51
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
|
|
56
52
|
export const isImageRequest = function (req) {
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
53
|
+
return req.url.startsWith(IMAGE_URL_PATTERN);
|
|
54
|
+
};
|
|
55
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'query' implicitly has an 'any' type.
|
|
60
56
|
export const transformImageParams = function (query) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
const params = {};
|
|
58
|
+
const width = query.w || query.width || null;
|
|
59
|
+
const height = query.h || query.height || null;
|
|
60
|
+
if (width && height) {
|
|
61
|
+
// @ts-expect-error TS(2339) FIXME: Property 's' does not exist on type '{}'.
|
|
62
|
+
// eslint-disable-next-line id-length
|
|
63
|
+
params.s = `${width}x${height}`;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// @ts-expect-error TS(2339) FIXME: Property 'w' does not exist on type '{}'.
|
|
67
|
+
// eslint-disable-next-line id-length
|
|
68
|
+
params.w = width;
|
|
69
|
+
// @ts-expect-error TS(2339) FIXME: Property 'j' does not exist on type '{}'.
|
|
70
|
+
// eslint-disable-next-line id-length
|
|
71
|
+
params.h = height;
|
|
72
|
+
}
|
|
73
|
+
// @ts-expect-error TS(2339) FIXME: Property 'quality' does not exist on type '{}'.
|
|
74
|
+
params.quality = query.q || query.quality || null;
|
|
75
|
+
// @ts-expect-error TS(2339) FIXME: Property 'format' does not exist on type '{}'.
|
|
76
|
+
params.format = query.fm || null;
|
|
77
|
+
const fit = query.fit || null;
|
|
78
|
+
// @ts-expect-error TS(2339) FIXME: Property 'fit' does not exist on type '{}'.
|
|
79
|
+
params.fit = fit === 'contain' ? 'inside' : fit;
|
|
80
|
+
// @ts-expect-error TS(2339) FIXME: Property 'position' does not exist on type '{}'.
|
|
81
|
+
params.position = query.position || null;
|
|
82
|
+
return Object.entries(params)
|
|
83
|
+
.filter(([, value]) => value !== null)
|
|
84
|
+
.map(([key, value]) => `${key}_${value}`)
|
|
85
|
+
.join(',');
|
|
86
|
+
};
|
|
87
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
77
88
|
export const initializeProxy = async function ({ config }) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return app
|
|
97
|
-
}
|
|
89
|
+
const remoteDomains = await parseRemoteImageDomains({ config });
|
|
90
|
+
const ipx = createIPX({
|
|
91
|
+
storage: ipxFSStorage({ dir: config?.build?.publish ?? './public' }),
|
|
92
|
+
httpStorage: ipxHttpStorage({ domains: remoteDomains }),
|
|
93
|
+
});
|
|
94
|
+
const handler = createIPXNodeServer(ipx);
|
|
95
|
+
const app = express();
|
|
96
|
+
app.use(IMAGE_URL_PATTERN, async (req, res) => {
|
|
97
|
+
const { url, ...query } = req.query;
|
|
98
|
+
const modifiers = await transformImageParams(query);
|
|
99
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type 'string | string[] | ParsedQs | P... Remove this comment to see the full error message
|
|
100
|
+
const path = `/${modifiers}/${encodeURIComponent(url)}`;
|
|
101
|
+
req.url = path;
|
|
102
|
+
handler(req, res);
|
|
103
|
+
});
|
|
104
|
+
return app;
|
|
105
|
+
};
|
package/src/lib/log.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { chalk } from '../utils/command-helpers.mjs'
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
|
|
1
|
+
import { chalk } from '../utils/command-helpers.mjs';
|
|
2
|
+
const RED_BACKGROUND = chalk.red('-background');
|
|
3
|
+
const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan));
|
|
5
4
|
export const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
|
|
6
5
|
Your team’s current plan doesn’t support Background Functions, which have names ending in \`${RED_BACKGROUND}\`.
|
|
7
6
|
To be able to deploy this function successfully either:
|
|
8
7
|
- change the function name to remove \`${RED_BACKGROUND}\` and execute it synchronously
|
|
9
8
|
- upgrade your team plan to a level that supports Background Functions (${PRO}, ${BUSINESS}, or ${ENTERPRISE})
|
|
10
|
-
|
|
11
|
-
export const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow(
|
|
12
|
-
'aws-sdk',
|
|
13
|
-
)}.
|
|
9
|
+
`;
|
|
10
|
+
export const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow('aws-sdk')}.
|
|
14
11
|
You should add this module to the project's dependencies, using your package manager of choice:
|
|
15
12
|
|
|
16
13
|
${chalk.yellow('npm install aws-sdk --save')} or ${chalk.yellow('yarn add aws-sdk')}
|
|
17
14
|
|
|
18
|
-
For more information, see https://ntl.fyi/cli-aws-sdk
|
|
15
|
+
For more information, see https://ntl.fyi/cli-aws-sdk.`;
|
package/src/lib/path.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'path' implicitly has an 'any' type.
|
|
2
|
+
export const normalizeBackslash = (path) => path.replace(/\\/g, '/');
|
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises'
|
|
2
|
-
import { dirname, join } from 'path'
|
|
3
|
-
import { fileURLToPath } from 'url'
|
|
4
|
-
|
|
5
|
-
let errorTemplateFile
|
|
6
|
-
const dir = dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
// @ts-expect-error TS(7034) FIXME: Variable 'errorTemplateFile' implicitly has type '... Remove this comment to see the full error message
|
|
5
|
+
let errorTemplateFile;
|
|
6
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'errString' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
8
8
|
const renderErrorTemplate = async (errString, templatePath, functionType) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export default renderErrorTemplate
|
|
9
|
+
const errorDetailsRegex = /<!--@ERROR-DETAILS-->/g;
|
|
10
|
+
const functionTypeRegex = /<!--@FUNCTION-TYPE-->/g;
|
|
11
|
+
try {
|
|
12
|
+
// @ts-expect-error TS(7005) FIXME: Variable 'errorTemplateFile' implicitly has an 'an... Remove this comment to see the full error message
|
|
13
|
+
errorTemplateFile = errorTemplateFile || (await readFile(join(dir, templatePath), 'utf-8'));
|
|
14
|
+
return errorTemplateFile.replace(errorDetailsRegex, errString).replace(functionTypeRegex, functionType);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return errString;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export default renderErrorTemplate;
|
package/src/lib/settings.mjs
CHANGED
|
@@ -1,38 +1,36 @@
|
|
|
1
|
-
import os from 'os'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const OSBasedPaths = envPaths('netlify', { suffix: '' })
|
|
7
|
-
const NETLIFY_HOME = '.netlify'
|
|
8
|
-
|
|
1
|
+
import os from 'os';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import envPaths from 'env-paths';
|
|
4
|
+
const OSBasedPaths = envPaths('netlify', { suffix: '' });
|
|
5
|
+
const NETLIFY_HOME = '.netlify';
|
|
9
6
|
/**
|
|
10
7
|
* Deprecated method to get netlify's home config - ~/.netlify/...
|
|
11
8
|
* @deprecated
|
|
12
9
|
* @param {string[]} paths
|
|
13
10
|
* @returns {string}
|
|
14
11
|
*/
|
|
12
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'paths' implicitly has an 'any' type.
|
|
15
13
|
export const getLegacyPathInHome = (paths) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
14
|
+
const pathInHome = path.join(os.homedir(), NETLIFY_HOME, ...paths);
|
|
15
|
+
return pathInHome;
|
|
16
|
+
};
|
|
20
17
|
/**
|
|
21
18
|
* get a global path on the os base path
|
|
22
19
|
* @param {string[]} paths
|
|
23
20
|
* @returns {string}
|
|
24
21
|
*/
|
|
22
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'paths' implicitly has an 'any' type.
|
|
25
23
|
export const getPathInHome = (paths) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
24
|
+
const pathInHome = path.join(OSBasedPaths.config, ...paths);
|
|
25
|
+
return pathInHome;
|
|
26
|
+
};
|
|
30
27
|
/**
|
|
31
28
|
* get a path inside the project folder
|
|
32
29
|
* @param {string[]} paths
|
|
33
30
|
* @returns {string}
|
|
34
31
|
*/
|
|
32
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'paths' implicitly has an 'any' type.
|
|
35
33
|
export const getPathInProject = (paths) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
34
|
+
const pathInProject = path.join(NETLIFY_HOME, ...paths);
|
|
35
|
+
return pathInProject;
|
|
36
|
+
};
|
package/src/lib/spinner.mjs
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import ora from 'ora'
|
|
4
|
-
|
|
1
|
+
import logSymbols from 'log-symbols';
|
|
2
|
+
import ora from 'ora';
|
|
5
3
|
/**
|
|
6
4
|
* Creates a spinner with the following text
|
|
7
5
|
* @param {object} config
|
|
8
6
|
* @param {string} config.text
|
|
9
7
|
* @returns {ora.Ora}
|
|
10
8
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'text' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
10
|
+
export const startSpinner = ({ text }) => ora({
|
|
13
11
|
text,
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
}).start();
|
|
16
13
|
/**
|
|
17
14
|
* Stops the spinner with the following text
|
|
18
15
|
* @param {object} config
|
|
@@ -21,26 +18,27 @@ export const startSpinner = ({ text }) =>
|
|
|
21
18
|
* @param {string} [config.text]
|
|
22
19
|
* @returns {void}
|
|
23
20
|
*/
|
|
21
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'error' implicitly has an 'any' ty... Remove this comment to see the full error message
|
|
24
22
|
export const stopSpinner = ({ error, spinner, text }) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
23
|
+
if (!spinner) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
// TODO: refactor no package needed `log-symbols` for that
|
|
27
|
+
const symbol = error ? logSymbols.error : logSymbols.success;
|
|
28
|
+
spinner.stopAndPersist({
|
|
29
|
+
text,
|
|
30
|
+
symbol,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
36
33
|
/**
|
|
37
34
|
* Clears the spinner
|
|
38
35
|
* @param {object} config
|
|
39
36
|
* @param {ora.Ora} config.spinner
|
|
40
37
|
* @returns {void}
|
|
41
38
|
*/
|
|
39
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'spinner' implicitly has an 'any' ... Remove this comment to see the full error message
|
|
42
40
|
export const clearSpinner = ({ spinner }) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
41
|
+
if (spinner) {
|
|
42
|
+
spinner.stop();
|
|
43
|
+
}
|
|
44
|
+
};
|
package/src/lib/string.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 't' implicitly has an 'any' type.
|
|
1
2
|
export const capitalize = function (t) {
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'string' implicitly has an 'any' type.
|
|
4
|
+
return t.replace(/(^\w|\s\w)/g, (string) => string.toUpperCase());
|
|
5
|
+
};
|