netlify-cli 17.3.2 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -138
- package/npm-shrinkwrap.json +76 -76
- package/package.json +16 -15
- package/src/commands/addons/addons-auth.mjs +27 -30
- package/src/commands/addons/addons-config.mjs +145 -154
- package/src/commands/addons/addons-create.mjs +94 -108
- package/src/commands/addons/addons-delete.mjs +36 -41
- package/src/commands/addons/addons-list.mjs +38 -42
- package/src/commands/addons/addons.mjs +26 -28
- package/src/commands/addons/index.mjs +1 -1
- package/src/commands/api/api.mjs +45 -53
- package/src/commands/api/index.mjs +1 -1
- package/src/commands/base-command.mjs +597 -684
- package/src/commands/blobs/blobs-delete.mjs +35 -0
- package/src/commands/blobs/blobs-get.mjs +44 -0
- package/src/commands/blobs/blobs-list.mjs +48 -0
- package/src/commands/blobs/blobs-set.mjs +54 -0
- package/src/commands/blobs/blobs.mjs +32 -0
- package/src/commands/blobs/index.mjs +1 -0
- package/src/commands/build/build.mjs +55 -67
- package/src/commands/build/index.mjs +1 -1
- package/src/commands/completion/completion.mjs +41 -46
- package/src/commands/completion/index.mjs +1 -1
- package/src/commands/deploy/deploy.mjs +675 -710
- package/src/commands/deploy/index.mjs +1 -1
- package/src/commands/dev/dev-exec.mjs +20 -32
- package/src/commands/dev/dev.mjs +217 -302
- package/src/commands/dev/index.mjs +1 -1
- package/src/commands/dev/types.d.ts +30 -0
- package/src/commands/env/env-clone.mjs +157 -184
- package/src/commands/env/env-get.mjs +49 -68
- package/src/commands/env/env-import.mjs +100 -119
- package/src/commands/env/env-list.mjs +104 -129
- package/src/commands/env/env-set.mjs +160 -185
- package/src/commands/env/env-unset.mjs +104 -122
- package/src/commands/env/env.mjs +28 -30
- package/src/commands/env/index.mjs +1 -1
- package/src/commands/functions/functions-build.mjs +29 -41
- package/src/commands/functions/functions-create.mjs +533 -601
- package/src/commands/functions/functions-invoke.mjs +193 -216
- package/src/commands/functions/functions-list.mjs +45 -55
- package/src/commands/functions/functions-serve.mjs +51 -61
- package/src/commands/functions/functions.mjs +26 -32
- package/src/commands/functions/index.mjs +1 -1
- package/src/commands/index.mjs +2 -2
- package/src/commands/init/index.mjs +1 -1
- package/src/commands/init/init.mjs +138 -167
- package/src/commands/integration/deploy.mjs +337 -399
- package/src/commands/integration/index.mjs +12 -13
- package/src/commands/link/index.mjs +1 -1
- package/src/commands/link/link.mjs +298 -317
- package/src/commands/lm/index.mjs +1 -1
- package/src/commands/lm/lm-info.mjs +23 -31
- package/src/commands/lm/lm-install.mjs +13 -17
- package/src/commands/lm/lm-setup.mjs +80 -84
- package/src/commands/lm/lm-uninstall.mjs +7 -12
- package/src/commands/lm/lm.mjs +18 -22
- package/src/commands/login/index.mjs +1 -1
- package/src/commands/login/login.mjs +35 -41
- package/src/commands/logout/index.mjs +1 -1
- package/src/commands/logout/logout.mjs +25 -31
- package/src/commands/main.mjs +166 -201
- package/src/commands/open/index.mjs +1 -1
- package/src/commands/open/open-admin.mjs +15 -18
- package/src/commands/open/open-site.mjs +16 -19
- package/src/commands/open/open.mjs +24 -27
- package/src/commands/recipes/common.mjs +23 -34
- package/src/commands/recipes/index.mjs +1 -1
- package/src/commands/recipes/recipes-list.mjs +13 -20
- package/src/commands/recipes/recipes.mjs +59 -72
- package/src/commands/serve/index.mjs +1 -1
- package/src/commands/serve/serve.mjs +142 -189
- package/src/commands/sites/index.mjs +2 -2
- package/src/commands/sites/sites-create-template.mjs +214 -236
- package/src/commands/sites/sites-create.mjs +145 -157
- package/src/commands/sites/sites-delete.mjs +75 -81
- package/src/commands/sites/sites-list.mjs +63 -66
- package/src/commands/sites/sites.mjs +18 -20
- package/src/commands/status/index.mjs +1 -1
- package/src/commands/status/status-hooks.mjs +32 -34
- package/src/commands/status/status.mjs +99 -106
- package/src/commands/switch/index.mjs +1 -1
- package/src/commands/switch/switch.mjs +32 -37
- package/src/commands/types.d.ts +31 -0
- package/src/commands/unlink/index.mjs +1 -1
- package/src/commands/unlink/unlink.mjs +23 -29
- package/src/commands/watch/index.mjs +1 -1
- package/src/commands/watch/watch.mjs +91 -105
- package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
- package/src/lib/account.mjs +4 -5
- package/src/lib/api.mjs +22 -20
- package/src/lib/blobs/blobs.mjs +36 -45
- package/src/lib/build.mjs +82 -85
- package/src/lib/completion/constants.mjs +2 -4
- package/src/lib/completion/generate-autocompletion.mjs +33 -36
- package/src/lib/completion/get-autocompletion.mjs +31 -35
- package/src/lib/completion/index.mjs +1 -1
- package/src/lib/completion/script.mjs +12 -19
- package/src/lib/edge-functions/bootstrap.mjs +3 -5
- package/src/lib/edge-functions/consts.mjs +9 -10
- package/src/lib/edge-functions/deploy.mjs +28 -34
- package/src/lib/edge-functions/editor-helper.mjs +29 -42
- package/src/lib/edge-functions/headers.mjs +24 -26
- package/src/lib/edge-functions/internal.mjs +38 -44
- package/src/lib/edge-functions/proxy.mjs +229 -228
- package/src/lib/edge-functions/registry.mjs +473 -574
- package/src/lib/exec-fetcher.mjs +115 -122
- package/src/lib/fs.mjs +28 -27
- package/src/lib/functions/background.mjs +16 -20
- package/src/lib/functions/config.mjs +12 -9
- package/src/lib/functions/form-submissions-handler.mjs +143 -149
- package/src/lib/functions/local-proxy.mjs +40 -44
- package/src/lib/functions/memoized-build.mjs +19 -21
- package/src/lib/functions/netlify-function.mjs +269 -249
- package/src/lib/functions/registry.mjs +509 -568
- package/src/lib/functions/runtimes/go/index.mjs +62 -71
- package/src/lib/functions/runtimes/index.mjs +8 -15
- package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
- package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
- package/src/lib/functions/runtimes/js/constants.mjs +1 -1
- package/src/lib/functions/runtimes/js/index.mjs +92 -109
- package/src/lib/functions/runtimes/js/worker.mjs +43 -45
- package/src/lib/functions/runtimes/rust/index.mjs +64 -73
- package/src/lib/functions/scheduled.mjs +70 -88
- package/src/lib/functions/server.mjs +269 -327
- package/src/lib/functions/synchronous.mjs +118 -147
- package/src/lib/functions/utils.mjs +38 -46
- package/src/lib/geo-location.mjs +69 -81
- package/src/lib/http-agent.mjs +87 -90
- package/src/lib/images/proxy.mjs +97 -99
- package/src/lib/log.mjs +6 -9
- package/src/lib/path.mjs +2 -1
- package/src/lib/render-error-template.mjs +19 -20
- package/src/lib/settings.mjs +17 -19
- package/src/lib/spinner.mjs +21 -23
- package/src/lib/string.mjs +4 -2
- package/src/recipes/vscode/index.mjs +69 -85
- package/src/recipes/vscode/settings.mjs +53 -58
- package/src/utils/addons/compare.mjs +31 -32
- package/src/utils/addons/diffs/index.mjs +16 -17
- package/src/utils/addons/diffs/options.mjs +99 -101
- package/src/utils/addons/prepare.mjs +100 -97
- package/src/utils/addons/prompts.mjs +73 -76
- package/src/utils/addons/render.mjs +33 -36
- package/src/utils/addons/validation.mjs +19 -15
- package/src/utils/banner.mjs +11 -16
- package/src/utils/build-info.mjs +65 -66
- package/src/utils/command-helpers.mjs +185 -199
- package/src/utils/create-deferred.mjs +9 -12
- package/src/utils/create-stream-promise.mjs +54 -47
- package/src/utils/deploy/constants.mjs +9 -11
- package/src/utils/deploy/deploy-site.mjs +162 -182
- package/src/utils/deploy/hash-config.mjs +21 -21
- package/src/utils/deploy/hash-files.mjs +34 -38
- package/src/utils/deploy/hash-fns.mjs +149 -154
- package/src/utils/deploy/hasher-segments.mjs +58 -52
- package/src/utils/deploy/upload-files.mjs +99 -113
- package/src/utils/deploy/util.mjs +85 -91
- package/src/utils/detect-server-settings.mjs +236 -268
- package/src/utils/dev.mjs +163 -178
- package/src/utils/dot-env.mjs +37 -42
- package/src/utils/env/index.mjs +148 -148
- package/src/utils/execa.mjs +9 -13
- package/src/utils/feature-flags.mjs +6 -5
- package/src/utils/framework-server.mjs +43 -52
- package/src/utils/functions/constants.mjs +1 -1
- package/src/utils/functions/functions.mjs +30 -40
- package/src/utils/functions/get-functions.mjs +28 -29
- package/src/utils/functions/index.mjs +3 -3
- package/src/utils/get-global-config.mjs +33 -36
- package/src/utils/get-package-json.mjs +14 -15
- package/src/utils/get-repo-data.mjs +54 -64
- package/src/utils/get-site.mjs +14 -14
- package/src/utils/gh-auth.mjs +79 -100
- package/src/utils/gitignore.mjs +37 -40
- package/src/utils/headers.mjs +33 -35
- package/src/utils/hooks/requires-site-info.mjs +26 -22
- package/src/utils/init/config-github.mjs +207 -219
- package/src/utils/init/config-manual.mjs +83 -100
- package/src/utils/init/config.mjs +25 -26
- package/src/utils/init/node-version.mjs +23 -30
- package/src/utils/init/plugins.mjs +12 -8
- package/src/utils/init/utils.mjs +152 -172
- package/src/utils/live-tunnel.mjs +118 -141
- package/src/utils/lm/install.mjs +220 -259
- package/src/utils/lm/requirements.mjs +54 -63
- package/src/utils/lm/steps.mjs +31 -31
- package/src/utils/lm/ui.mjs +13 -20
- package/src/utils/open-browser.mjs +31 -32
- package/src/utils/parse-raw-flags.mjs +39 -35
- package/src/utils/proxy-server.mjs +84 -71
- package/src/utils/proxy.mjs +696 -750
- package/src/utils/read-repo-url.mjs +48 -47
- package/src/utils/redirects.mjs +49 -49
- package/src/utils/request-id.mjs +2 -4
- package/src/utils/rules-proxy.mjs +96 -100
- package/src/utils/run-build.mjs +109 -132
- package/src/utils/shell.mjs +99 -106
- package/src/utils/sign-redirect.mjs +14 -14
- package/src/utils/sites/utils.mjs +48 -55
- package/src/utils/state-config.mjs +101 -101
- package/src/utils/static-server.mjs +28 -34
- package/src/utils/telemetry/index.mjs +2 -2
- package/src/utils/telemetry/report-error.mjs +45 -49
- package/src/utils/telemetry/request.mjs +36 -43
- package/src/utils/telemetry/telemetry.mjs +90 -105
- package/src/utils/telemetry/utils.mjs +5 -6
- package/src/utils/telemetry/validation.mjs +55 -53
- package/src/utils/types.d.ts +46 -0
- package/src/utils/validation.mjs +10 -13
package/src/utils/env/index.mjs
CHANGED
|
@@ -1,56 +1,57 @@
|
|
|
1
|
-
import { error } from '../command-helpers.mjs'
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
export const AVAILABLE_SCOPES = ['builds', 'functions', 'runtime', 'post_processing']
|
|
5
|
-
|
|
1
|
+
import { error } from '../command-helpers.mjs';
|
|
2
|
+
export const AVAILABLE_CONTEXTS = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev'];
|
|
3
|
+
export const AVAILABLE_SCOPES = ['builds', 'functions', 'runtime', 'post_processing'];
|
|
6
4
|
/**
|
|
7
5
|
* @param {string|undefined} context - The deploy context or branch of the environment variable value
|
|
8
6
|
* @returns {Array<string|undefined>} The normalized context or branch name
|
|
9
7
|
*/
|
|
8
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'context' implicitly has an 'any' type.
|
|
10
9
|
export const normalizeContext = (context) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
10
|
+
if (!context) {
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
const CONTEXT_SYNONYMS = {
|
|
14
|
+
dp: 'deploy-preview',
|
|
15
|
+
prod: 'production',
|
|
16
|
+
};
|
|
17
|
+
context = context.toLowerCase();
|
|
18
|
+
if (context in CONTEXT_SYNONYMS) {
|
|
19
|
+
// @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
|
|
20
|
+
context = CONTEXT_SYNONYMS[context];
|
|
21
|
+
}
|
|
22
|
+
const forbiddenContexts = AVAILABLE_CONTEXTS.map((ctx) => `branch:${ctx}`);
|
|
23
|
+
if (forbiddenContexts.includes(context)) {
|
|
24
|
+
error(`The context ${context} includes a reserved keyword and is not allowed`);
|
|
25
|
+
}
|
|
26
|
+
context = context.replace(/^branch:/, '');
|
|
27
|
+
return context;
|
|
28
|
+
};
|
|
30
29
|
/**
|
|
31
30
|
* Finds a matching environment variable value from a given context
|
|
32
31
|
* @param {Array<object>} values - An array of environment variable values from Envelope
|
|
33
32
|
* @param {string} context - The deploy context or branch of the environment variable value
|
|
34
33
|
* @returns {object<context: enum<dev,branch-deploy,deploy-preview,production,branch>, context_parameter: <string>, value: string>} The matching environment variable value object
|
|
35
34
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'values' implicitly has an 'any' type.
|
|
36
|
+
export const findValueInValues = (values, context) =>
|
|
37
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'val' implicitly has an 'any' type.
|
|
38
|
+
values.find((val) => {
|
|
38
39
|
if (!AVAILABLE_CONTEXTS.includes(context)) {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
// the "context" option passed in is actually the name of a branch
|
|
41
|
+
return val.context === 'all' || val.context_parameter === context;
|
|
41
42
|
}
|
|
42
|
-
return [context, 'all'].includes(val.context)
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
return [context, 'all'].includes(val.context);
|
|
44
|
+
});
|
|
45
45
|
/**
|
|
46
46
|
* Finds environment variables that match a given source
|
|
47
47
|
* @param {object} env - The dictionary of environment variables
|
|
48
48
|
* @param {enum<general,account,addons,ui,configFile>} source - The source of the environment variable
|
|
49
49
|
* @returns {object} The dictionary of env vars that match the given source
|
|
50
50
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'env' implicitly has an 'any' type.
|
|
52
|
+
export const filterEnvBySource = (env, source) =>
|
|
53
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
54
|
+
Object.fromEntries(Object.entries(env).filter(([, variable]) => variable.sources[0] === source));
|
|
54
55
|
/**
|
|
55
56
|
* Fetches data from Envelope
|
|
56
57
|
* @param {string} accountId - The account id
|
|
@@ -59,26 +60,27 @@ export const filterEnvBySource = (env, source) =>
|
|
|
59
60
|
* @param {string} siteId - The site id
|
|
60
61
|
* @returns {Array<object>} An array of environment variables from the Envelope service
|
|
61
62
|
*/
|
|
63
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'accountId' implicitly has an 'any... Remove this comment to see the full error message
|
|
62
64
|
const fetchEnvelopeItems = async function ({ accountId, api, key, siteId }) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
if (accountId === undefined) {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
// if a single key is passed, fetch that single env var
|
|
70
|
+
if (key) {
|
|
71
|
+
const envelopeItem = await api.getEnvVar({ accountId, key, siteId });
|
|
72
|
+
return [envelopeItem];
|
|
73
|
+
}
|
|
74
|
+
// otherwise, fetch the entire list of env vars
|
|
75
|
+
const envelopeItems = await api.getEnvVars({ accountId, siteId });
|
|
76
|
+
return envelopeItems;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Collaborators aren't allowed to read shared env vars,
|
|
80
|
+
// so return an empty array silently in that case
|
|
81
|
+
return [];
|
|
71
82
|
}
|
|
72
|
-
|
|
73
|
-
const envelopeItems = await api.getEnvVars({ accountId, siteId })
|
|
74
|
-
return envelopeItems
|
|
75
|
-
} catch {
|
|
76
|
-
// Collaborators aren't allowed to read shared env vars,
|
|
77
|
-
// so return an empty array silently in that case
|
|
78
|
-
return []
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
83
|
+
};
|
|
82
84
|
/**
|
|
83
85
|
* Filters and sorts data from Envelope by a given context and/or scope
|
|
84
86
|
* @param {string} context - The deploy context or branch of the environment variable value
|
|
@@ -102,29 +104,33 @@ const fetchEnvelopeItems = async function ({ accountId, api, key, siteId }) {
|
|
|
102
104
|
* },
|
|
103
105
|
* }
|
|
104
106
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'source' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
108
|
+
export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any', source }) => envelopeItems
|
|
107
109
|
// filter by context
|
|
108
110
|
.filter(({ values }) => Boolean(findValueInValues(values, context)))
|
|
109
111
|
// filter by scope
|
|
112
|
+
// @ts-expect-error TS(2339) FIXME: Property 'includes' does not exist on type 'never'... Remove this comment to see the full error message
|
|
110
113
|
.filter(({ scopes }) => (scope === 'any' ? true : scopes.includes(scope)))
|
|
111
114
|
// sort alphabetically, case insensitive
|
|
115
|
+
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
|
|
112
116
|
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
|
|
113
117
|
// format the data
|
|
114
118
|
.reduce((acc, cur) => {
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
// @ts-expect-error TS(2339) FIXME: Property 'values' does not exist on type 'never'.
|
|
120
|
+
const { context: ctx, context_parameter: branch, value } = findValueInValues(cur.values, context);
|
|
121
|
+
return {
|
|
117
122
|
...acc,
|
|
123
|
+
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
|
|
118
124
|
[cur.key]: {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
context: ctx,
|
|
126
|
+
branch,
|
|
127
|
+
// @ts-expect-error TS(2339) FIXME: Property 'scopes' does not exist on type 'never'.
|
|
128
|
+
scopes: cur.scopes,
|
|
129
|
+
sources: [source],
|
|
130
|
+
value,
|
|
124
131
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
132
|
+
};
|
|
133
|
+
}, {});
|
|
128
134
|
/**
|
|
129
135
|
* Collects env vars from multiple sources and arranges them in the correct order of precedence
|
|
130
136
|
* @param {object} api - The api singleton object
|
|
@@ -136,109 +142,103 @@ export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope
|
|
|
136
142
|
* @param {object} siteInfo - The site object
|
|
137
143
|
* @returns {object} An object of environment variables keys and their metadata
|
|
138
144
|
*/
|
|
145
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
139
146
|
export const getEnvelopeEnv = async ({ api, context = 'dev', env, key = '', raw = false, scope = 'any', siteInfo }) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
...accountEnv,
|
|
173
|
-
...(includeConfigEnvVars ? addonsEnv : {}),
|
|
174
|
-
...siteEnv,
|
|
175
|
-
...(includeConfigEnvVars ? configFileEnv : {}),
|
|
176
|
-
...internalEnv,
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
147
|
+
const { account_slug: accountId, id: siteId } = siteInfo;
|
|
148
|
+
const [accountEnvelopeItems, siteEnvelopeItems] = await Promise.all([
|
|
149
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ api: any; accountId: any; key:... Remove this comment to see the full error message
|
|
150
|
+
fetchEnvelopeItems({ api, accountId, key }),
|
|
151
|
+
fetchEnvelopeItems({ api, accountId, key, siteId }),
|
|
152
|
+
]);
|
|
153
|
+
const accountEnv = formatEnvelopeData({ context, envelopeItems: accountEnvelopeItems, scope, source: 'account' });
|
|
154
|
+
const siteEnv = formatEnvelopeData({ context, envelopeItems: siteEnvelopeItems, scope, source: 'ui' });
|
|
155
|
+
if (raw) {
|
|
156
|
+
const entries = Object.entries({ ...accountEnv, ...siteEnv });
|
|
157
|
+
return entries.reduce((obj, [envVarKey, metadata]) => ({
|
|
158
|
+
...obj,
|
|
159
|
+
// @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
|
|
160
|
+
[envVarKey]: metadata.value,
|
|
161
|
+
}), {});
|
|
162
|
+
}
|
|
163
|
+
const generalEnv = filterEnvBySource(env, 'general');
|
|
164
|
+
const internalEnv = filterEnvBySource(env, 'internal');
|
|
165
|
+
const addonsEnv = filterEnvBySource(env, 'addons');
|
|
166
|
+
const configFileEnv = filterEnvBySource(env, 'configFile');
|
|
167
|
+
// filter out configFile env vars if a non-configFile scope is passed
|
|
168
|
+
const includeConfigEnvVars = /any|builds|post[-_]processing/.test(scope);
|
|
169
|
+
// Sources of environment variables, in ascending order of precedence.
|
|
170
|
+
return {
|
|
171
|
+
...generalEnv,
|
|
172
|
+
...accountEnv,
|
|
173
|
+
...(includeConfigEnvVars ? addonsEnv : {}),
|
|
174
|
+
...siteEnv,
|
|
175
|
+
...(includeConfigEnvVars ? configFileEnv : {}),
|
|
176
|
+
...internalEnv,
|
|
177
|
+
};
|
|
178
|
+
};
|
|
180
179
|
/**
|
|
181
180
|
* Returns a human-readable, comma-separated list of scopes
|
|
182
181
|
* @param {Array<enum<builds,functions,runtime,post_processing>>} scopes - An array of scopes
|
|
183
182
|
* @returns {string} A human-readable, comma-separated list of scopes
|
|
184
183
|
*/
|
|
184
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'scopes' implicitly has an 'any' type.
|
|
185
185
|
export const getHumanReadableScopes = (scopes) => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
186
|
+
const HUMAN_SCOPES = ['Builds', 'Functions', 'Runtime', 'Post processing'];
|
|
187
|
+
const SCOPES_MAP = {
|
|
188
|
+
builds: HUMAN_SCOPES[0],
|
|
189
|
+
functions: HUMAN_SCOPES[1],
|
|
190
|
+
runtime: HUMAN_SCOPES[2],
|
|
191
|
+
post_processing: HUMAN_SCOPES[3],
|
|
192
|
+
'post-processing': HUMAN_SCOPES[3],
|
|
193
|
+
};
|
|
194
|
+
if (!scopes) {
|
|
195
|
+
// if `scopes` is not available, the env var comes from netlify.toml
|
|
196
|
+
// env vars specified in netlify.toml are present in the `builds` and `post_processing` scope
|
|
197
|
+
return 'Builds, Post processing';
|
|
198
|
+
}
|
|
199
|
+
if (scopes.length === Object.keys(HUMAN_SCOPES).length) {
|
|
200
|
+
// shorthand instead of listing every available scope
|
|
201
|
+
return 'All';
|
|
202
|
+
}
|
|
203
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'scope' implicitly has an 'any' type.
|
|
204
|
+
return scopes.map((scope) => SCOPES_MAP[scope]).join(', ');
|
|
205
|
+
};
|
|
206
206
|
/**
|
|
207
207
|
* Translates a Mongo env into an Envelope env
|
|
208
208
|
* @param {object} env - The site's env as it exists in Mongo
|
|
209
209
|
* @returns {Array<object>} The array of Envelope env vars
|
|
210
210
|
*/
|
|
211
211
|
export const translateFromMongoToEnvelope = (env = {}) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
212
|
+
const envVars = Object.entries(env).map(([key, value]) => ({
|
|
213
|
+
key,
|
|
214
|
+
scopes: AVAILABLE_SCOPES,
|
|
215
|
+
values: [
|
|
216
|
+
{
|
|
217
|
+
context: 'all',
|
|
218
|
+
value,
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
}));
|
|
222
|
+
return envVars;
|
|
223
|
+
};
|
|
226
224
|
/**
|
|
227
225
|
* Translates an Envelope env into a Mongo env
|
|
228
226
|
* @param {Array<object>} envVars - The array of Envelope env vars
|
|
229
227
|
* @param {string} context - The deploy context or branch of the environment variable
|
|
230
228
|
* @returns {object} The env object as compatible with Mongo
|
|
231
229
|
*/
|
|
232
|
-
export const translateFromEnvelopeToMongo = (envVars = [], context = 'dev') =>
|
|
233
|
-
|
|
230
|
+
export const translateFromEnvelopeToMongo = (envVars = [], context = 'dev') => envVars
|
|
231
|
+
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
|
|
234
232
|
.sort((left, right) => (left.key.toLowerCase() < right.key.toLowerCase() ? -1 : 1))
|
|
235
233
|
.reduce((acc, cur) => {
|
|
236
|
-
|
|
237
|
-
|
|
234
|
+
// @ts-expect-error TS(2339) FIXME: Property 'values' does not exist on type 'never'.
|
|
235
|
+
const envVar = cur.values.find((val) => [context, 'all'].includes(val.context_parameter || val.context));
|
|
236
|
+
if (envVar && envVar.value) {
|
|
238
237
|
return {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
...acc,
|
|
239
|
+
// @ts-expect-error TS(2339) FIXME: Property 'key' does not exist on type 'never'.
|
|
240
|
+
[cur.key]: envVar.value,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return acc;
|
|
244
|
+
}, {});
|
package/src/utils/execa.mjs
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { env } from 'process'
|
|
2
|
-
|
|
3
|
-
import execaLib from 'execa'
|
|
4
|
-
|
|
1
|
+
import { env } from 'process';
|
|
2
|
+
import execaLib from 'execa';
|
|
5
3
|
// This is a thin layer on top of `execa` that allows consumers to provide an
|
|
6
4
|
// alternative path to the module location, making it easier to mock its logic
|
|
7
5
|
// in tests (see `tests/utils/mock-execa.js`).
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* @type {import('execa')}
|
|
11
8
|
*/
|
|
12
9
|
// eslint-disable-next-line import/no-mutable-exports
|
|
13
|
-
let execa
|
|
14
|
-
|
|
10
|
+
let execa;
|
|
15
11
|
if (env.NETLIFY_CLI_EXECA_PATH) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} else {
|
|
19
|
-
execa = execaLib
|
|
12
|
+
const execaMock = await import(env.NETLIFY_CLI_EXECA_PATH);
|
|
13
|
+
execa = execaMock.default;
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
else {
|
|
16
|
+
execa = execaLib;
|
|
17
|
+
}
|
|
18
|
+
export default execa;
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @returns {boolean}
|
|
13
13
|
*/
|
|
14
|
+
// @ts-expect-error TS(7006) FIXME: Parameter 'flagName' implicitly has an 'any' type.
|
|
14
15
|
export const isFeatureFlagEnabled = (flagName, siteInfo) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
16
|
+
if (siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
};
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { error, exit, log, NETLIFYDEVERR, NETLIFYDEVLOG } from './command-helpers.mjs'
|
|
7
|
-
import { runCommand } from './shell.mjs'
|
|
8
|
-
import { startStaticServer } from './static-server.mjs'
|
|
9
|
-
|
|
1
|
+
import waitPort from 'wait-port';
|
|
2
|
+
import { startSpinner, stopSpinner } from '../lib/spinner.mjs';
|
|
3
|
+
import { error, exit, log, NETLIFYDEVERR, NETLIFYDEVLOG } from './command-helpers.mjs';
|
|
4
|
+
import { runCommand } from './shell.mjs';
|
|
5
|
+
import { startStaticServer } from './static-server.mjs';
|
|
10
6
|
// 10 minutes
|
|
11
|
-
const FRAMEWORK_PORT_TIMEOUT = 6e5
|
|
12
|
-
|
|
7
|
+
const FRAMEWORK_PORT_TIMEOUT = 6e5;
|
|
13
8
|
/**
|
|
14
9
|
* @typedef StartReturnObject
|
|
15
10
|
* @property {4 | 6 | undefined=} ipVersion The version the open port was found on
|
|
16
11
|
*/
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* Start a static server if the `useStaticServer` is provided or a framework specific server
|
|
20
14
|
* @param {object} config
|
|
@@ -22,46 +16,43 @@ const FRAMEWORK_PORT_TIMEOUT = 6e5
|
|
|
22
16
|
* @param {string} config.cwd
|
|
23
17
|
* @returns {Promise<StartReturnObject>}
|
|
24
18
|
*/
|
|
19
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'cwd' implicitly has an 'any' type... Remove this comment to see the full error message
|
|
25
20
|
export const startFrameworkServer = async function ({ cwd, settings }) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
if (settings.useStaticServer) {
|
|
22
|
+
if (settings.command) {
|
|
23
|
+
runCommand(settings.command, { env: settings.env, cwd });
|
|
24
|
+
}
|
|
25
|
+
await startStaticServer({ settings });
|
|
26
|
+
return {};
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
timeout: FRAMEWORK_PORT_TIMEOUT,
|
|
50
|
-
...(settings.pollingStrategies?.includes('HTTP') && { protocol: 'http' }),
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
if (!port.open) {
|
|
54
|
-
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`)
|
|
28
|
+
log(`${NETLIFYDEVLOG} Starting Netlify Dev with ${settings.framework || 'custom config'}`);
|
|
29
|
+
const spinner = startSpinner({
|
|
30
|
+
text: `Waiting for framework port ${settings.frameworkPort}. This can be configured using the 'targetPort' property in the netlify.toml`,
|
|
31
|
+
});
|
|
32
|
+
runCommand(settings.command, { env: settings.env, spinner, cwd });
|
|
33
|
+
let port;
|
|
34
|
+
try {
|
|
35
|
+
port = await waitPort({
|
|
36
|
+
port: settings.frameworkPort,
|
|
37
|
+
host: 'localhost',
|
|
38
|
+
output: 'silent',
|
|
39
|
+
timeout: FRAMEWORK_PORT_TIMEOUT,
|
|
40
|
+
...(settings.pollingStrategies?.includes('HTTP') && { protocol: 'http' }),
|
|
41
|
+
});
|
|
42
|
+
if (!port.open) {
|
|
43
|
+
throw new Error(`Timed out waiting for port '${settings.frameworkPort}' to be open`);
|
|
44
|
+
}
|
|
45
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ error: boolean; spinner: Ora; ... Remove this comment to see the full error message
|
|
46
|
+
stopSpinner({ error: false, spinner });
|
|
55
47
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
48
|
+
catch (error_) {
|
|
49
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type '{ error: boolean; spinner: Ora; ... Remove this comment to see the full error message
|
|
50
|
+
stopSpinner({ error: true, spinner });
|
|
51
|
+
log(NETLIFYDEVERR, `Netlify Dev could not start or connect to localhost:${settings.frameworkPort}.`);
|
|
52
|
+
log(NETLIFYDEVERR, `Please make sure your framework server is running on port ${settings.frameworkPort}`);
|
|
53
|
+
// @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
|
|
54
|
+
error(error_);
|
|
55
|
+
exit(1);
|
|
56
|
+
}
|
|
57
|
+
return { ipVersion: port?.ipVersion };
|
|
58
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLOCKWORK_USERAGENT = 'Netlify Clockwork'
|
|
1
|
+
export const CLOCKWORK_USERAGENT = 'Netlify Clockwork';
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const INTERNAL_FUNCTIONS_FOLDER = 'functions-internal'
|
|
9
|
-
export const SERVE_FUNCTIONS_FOLDER = 'functions-serve'
|
|
10
|
-
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { isDirectoryAsync, isFileAsync } from '../../lib/fs.mjs';
|
|
4
|
+
import { getPathInProject } from '../../lib/settings.mjs';
|
|
5
|
+
export const INTERNAL_FUNCTIONS_FOLDER = 'functions-internal';
|
|
6
|
+
export const SERVE_FUNCTIONS_FOLDER = 'functions-serve';
|
|
11
7
|
/**
|
|
12
8
|
* retrieves the function directory out of the flags or config
|
|
13
9
|
* @param {object} param
|
|
@@ -16,29 +12,25 @@ export const SERVE_FUNCTIONS_FOLDER = 'functions-serve'
|
|
|
16
12
|
* @param {string} [defaultValue]
|
|
17
13
|
* @returns {string}
|
|
18
14
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'config' implicitly has an 'any' t... Remove this comment to see the full error message
|
|
16
|
+
export const getFunctionsDir = ({ config, options }, defaultValue) => options.functions || config.dev?.functions || config.functionsDirectory || config.dev?.Functions || defaultValue;
|
|
17
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
22
18
|
export const getFunctionsManifestPath = async ({ base, packagePath = '' }) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const path = resolve(base, packagePath, getPathInProject(['functions', 'manifest.json']));
|
|
20
|
+
const isFile = await isFileAsync(path);
|
|
21
|
+
return isFile ? path : null;
|
|
22
|
+
};
|
|
23
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
29
24
|
export const getFunctionsDistPath = async ({ base, packagePath = '' }) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
const path = resolve(base, packagePath, getPathInProject(['functions']));
|
|
26
|
+
const isDirectory = await isDirectoryAsync(path);
|
|
27
|
+
return isDirectory ? path : null;
|
|
28
|
+
};
|
|
29
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
36
30
|
export const getFunctionsServePath = ({ base, packagePath = '' }) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
31
|
+
const path = resolve(base, packagePath, getPathInProject([SERVE_FUNCTIONS_FOLDER]));
|
|
32
|
+
return path;
|
|
33
|
+
};
|
|
42
34
|
/**
|
|
43
35
|
* Retrieves the internal functions directory and creates it if ensureExists is provided
|
|
44
36
|
* @param {object} config
|
|
@@ -47,14 +39,12 @@ export const getFunctionsServePath = ({ base, packagePath = '' }) => {
|
|
|
47
39
|
* @param {string} config.packagePath
|
|
48
40
|
* @returns
|
|
49
41
|
*/
|
|
42
|
+
// @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
|
|
50
43
|
export const getInternalFunctionsDir = async ({ base, ensureExists, packagePath = '' }) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return isDirectory ? path : null
|
|
60
|
-
}
|
|
44
|
+
const path = resolve(base, packagePath, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]));
|
|
45
|
+
if (ensureExists) {
|
|
46
|
+
await fs.mkdir(path, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
const isDirectory = await isDirectoryAsync(path);
|
|
49
|
+
return isDirectory ? path : null;
|
|
50
|
+
};
|