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.
Files changed (210) hide show
  1. package/README.md +3 -139
  2. package/npm-shrinkwrap.json +82 -82
  3. package/package.json +16 -15
  4. package/src/commands/addons/addons-auth.mjs +27 -30
  5. package/src/commands/addons/addons-config.mjs +145 -154
  6. package/src/commands/addons/addons-create.mjs +94 -108
  7. package/src/commands/addons/addons-delete.mjs +36 -41
  8. package/src/commands/addons/addons-list.mjs +38 -42
  9. package/src/commands/addons/addons.mjs +26 -28
  10. package/src/commands/addons/index.mjs +1 -1
  11. package/src/commands/api/api.mjs +45 -53
  12. package/src/commands/api/index.mjs +1 -1
  13. package/src/commands/base-command.mjs +597 -684
  14. package/src/commands/blobs/blobs-delete.mjs +35 -0
  15. package/src/commands/blobs/blobs-get.mjs +44 -0
  16. package/src/commands/blobs/blobs-list.mjs +48 -0
  17. package/src/commands/blobs/blobs-set.mjs +54 -0
  18. package/src/commands/blobs/blobs.mjs +32 -0
  19. package/src/commands/blobs/index.mjs +1 -0
  20. package/src/commands/build/build.mjs +55 -67
  21. package/src/commands/build/index.mjs +1 -1
  22. package/src/commands/completion/completion.mjs +41 -46
  23. package/src/commands/completion/index.mjs +1 -1
  24. package/src/commands/deploy/deploy.mjs +675 -710
  25. package/src/commands/deploy/index.mjs +1 -1
  26. package/src/commands/dev/dev-exec.mjs +20 -32
  27. package/src/commands/dev/dev.mjs +217 -302
  28. package/src/commands/dev/index.mjs +1 -1
  29. package/src/commands/dev/types.d.ts +30 -0
  30. package/src/commands/env/env-clone.mjs +157 -184
  31. package/src/commands/env/env-get.mjs +49 -68
  32. package/src/commands/env/env-import.mjs +100 -119
  33. package/src/commands/env/env-list.mjs +104 -129
  34. package/src/commands/env/env-set.mjs +160 -185
  35. package/src/commands/env/env-unset.mjs +104 -122
  36. package/src/commands/env/env.mjs +28 -30
  37. package/src/commands/env/index.mjs +1 -1
  38. package/src/commands/functions/functions-build.mjs +29 -41
  39. package/src/commands/functions/functions-create.mjs +533 -601
  40. package/src/commands/functions/functions-invoke.mjs +193 -216
  41. package/src/commands/functions/functions-list.mjs +45 -55
  42. package/src/commands/functions/functions-serve.mjs +51 -61
  43. package/src/commands/functions/functions.mjs +26 -32
  44. package/src/commands/functions/index.mjs +1 -1
  45. package/src/commands/index.mjs +2 -2
  46. package/src/commands/init/index.mjs +1 -1
  47. package/src/commands/init/init.mjs +138 -167
  48. package/src/commands/integration/deploy.mjs +337 -399
  49. package/src/commands/integration/index.mjs +12 -13
  50. package/src/commands/link/index.mjs +1 -1
  51. package/src/commands/link/link.mjs +298 -317
  52. package/src/commands/lm/index.mjs +1 -1
  53. package/src/commands/lm/lm-info.mjs +23 -31
  54. package/src/commands/lm/lm-install.mjs +13 -17
  55. package/src/commands/lm/lm-setup.mjs +80 -84
  56. package/src/commands/lm/lm-uninstall.mjs +7 -12
  57. package/src/commands/lm/lm.mjs +18 -22
  58. package/src/commands/login/index.mjs +1 -1
  59. package/src/commands/login/login.mjs +35 -41
  60. package/src/commands/logout/index.mjs +1 -1
  61. package/src/commands/logout/logout.mjs +25 -31
  62. package/src/commands/main.mjs +166 -201
  63. package/src/commands/open/index.mjs +1 -1
  64. package/src/commands/open/open-admin.mjs +15 -18
  65. package/src/commands/open/open-site.mjs +16 -19
  66. package/src/commands/open/open.mjs +24 -27
  67. package/src/commands/recipes/common.mjs +23 -34
  68. package/src/commands/recipes/index.mjs +1 -1
  69. package/src/commands/recipes/recipes-list.mjs +13 -20
  70. package/src/commands/recipes/recipes.mjs +59 -72
  71. package/src/commands/serve/index.mjs +1 -1
  72. package/src/commands/serve/serve.mjs +142 -189
  73. package/src/commands/sites/index.mjs +2 -2
  74. package/src/commands/sites/sites-create-template.mjs +214 -236
  75. package/src/commands/sites/sites-create.mjs +145 -157
  76. package/src/commands/sites/sites-delete.mjs +75 -81
  77. package/src/commands/sites/sites-list.mjs +63 -66
  78. package/src/commands/sites/sites.mjs +18 -20
  79. package/src/commands/status/index.mjs +1 -1
  80. package/src/commands/status/status-hooks.mjs +32 -34
  81. package/src/commands/status/status.mjs +99 -106
  82. package/src/commands/switch/index.mjs +1 -1
  83. package/src/commands/switch/switch.mjs +32 -37
  84. package/src/commands/types.d.ts +31 -0
  85. package/src/commands/unlink/index.mjs +1 -1
  86. package/src/commands/unlink/unlink.mjs +23 -29
  87. package/src/commands/watch/index.mjs +1 -1
  88. package/src/commands/watch/watch.mjs +91 -105
  89. package/src/functions-templates/javascript/hello/{{name}}.js +2 -3
  90. package/src/lib/account.mjs +4 -5
  91. package/src/lib/api.mjs +22 -20
  92. package/src/lib/blobs/blobs.mjs +36 -45
  93. package/src/lib/build.mjs +82 -85
  94. package/src/lib/completion/constants.mjs +2 -4
  95. package/src/lib/completion/generate-autocompletion.mjs +33 -36
  96. package/src/lib/completion/get-autocompletion.mjs +31 -35
  97. package/src/lib/completion/index.mjs +1 -1
  98. package/src/lib/completion/script.mjs +12 -19
  99. package/src/lib/edge-functions/bootstrap.mjs +3 -5
  100. package/src/lib/edge-functions/consts.mjs +9 -10
  101. package/src/lib/edge-functions/deploy.mjs +28 -34
  102. package/src/lib/edge-functions/editor-helper.mjs +29 -42
  103. package/src/lib/edge-functions/headers.mjs +24 -26
  104. package/src/lib/edge-functions/internal.mjs +38 -44
  105. package/src/lib/edge-functions/proxy.mjs +229 -228
  106. package/src/lib/edge-functions/registry.mjs +473 -574
  107. package/src/lib/exec-fetcher.mjs +115 -122
  108. package/src/lib/fs.mjs +28 -27
  109. package/src/lib/functions/background.mjs +16 -20
  110. package/src/lib/functions/config.mjs +12 -9
  111. package/src/lib/functions/form-submissions-handler.mjs +143 -149
  112. package/src/lib/functions/local-proxy.mjs +40 -44
  113. package/src/lib/functions/memoized-build.mjs +19 -21
  114. package/src/lib/functions/netlify-function.mjs +269 -249
  115. package/src/lib/functions/registry.mjs +509 -568
  116. package/src/lib/functions/runtimes/go/index.mjs +62 -71
  117. package/src/lib/functions/runtimes/index.mjs +8 -15
  118. package/src/lib/functions/runtimes/js/builders/netlify-lambda.mjs +55 -64
  119. package/src/lib/functions/runtimes/js/builders/zisi.mjs +135 -154
  120. package/src/lib/functions/runtimes/js/constants.mjs +1 -1
  121. package/src/lib/functions/runtimes/js/index.mjs +92 -109
  122. package/src/lib/functions/runtimes/js/worker.mjs +43 -45
  123. package/src/lib/functions/runtimes/rust/index.mjs +64 -73
  124. package/src/lib/functions/scheduled.mjs +70 -88
  125. package/src/lib/functions/server.mjs +269 -327
  126. package/src/lib/functions/synchronous.mjs +118 -147
  127. package/src/lib/functions/utils.mjs +38 -46
  128. package/src/lib/geo-location.mjs +69 -81
  129. package/src/lib/http-agent.mjs +87 -90
  130. package/src/lib/images/proxy.mjs +97 -89
  131. package/src/lib/log.mjs +6 -9
  132. package/src/lib/path.mjs +2 -1
  133. package/src/lib/render-error-template.mjs +19 -20
  134. package/src/lib/settings.mjs +17 -19
  135. package/src/lib/spinner.mjs +21 -23
  136. package/src/lib/string.mjs +4 -2
  137. package/src/recipes/vscode/index.mjs +69 -85
  138. package/src/recipes/vscode/settings.mjs +53 -58
  139. package/src/utils/addons/compare.mjs +31 -32
  140. package/src/utils/addons/diffs/index.mjs +16 -17
  141. package/src/utils/addons/diffs/options.mjs +99 -101
  142. package/src/utils/addons/prepare.mjs +100 -97
  143. package/src/utils/addons/prompts.mjs +73 -76
  144. package/src/utils/addons/render.mjs +33 -36
  145. package/src/utils/addons/validation.mjs +19 -15
  146. package/src/utils/banner.mjs +11 -16
  147. package/src/utils/build-info.mjs +65 -66
  148. package/src/utils/command-helpers.mjs +185 -199
  149. package/src/utils/create-deferred.mjs +9 -12
  150. package/src/utils/create-stream-promise.mjs +54 -47
  151. package/src/utils/deploy/constants.mjs +9 -11
  152. package/src/utils/deploy/deploy-site.mjs +162 -182
  153. package/src/utils/deploy/hash-config.mjs +21 -21
  154. package/src/utils/deploy/hash-files.mjs +34 -38
  155. package/src/utils/deploy/hash-fns.mjs +149 -154
  156. package/src/utils/deploy/hasher-segments.mjs +58 -52
  157. package/src/utils/deploy/upload-files.mjs +99 -113
  158. package/src/utils/deploy/util.mjs +85 -91
  159. package/src/utils/detect-server-settings.mjs +236 -268
  160. package/src/utils/dev.mjs +163 -178
  161. package/src/utils/dot-env.mjs +37 -42
  162. package/src/utils/env/index.mjs +148 -148
  163. package/src/utils/execa.mjs +9 -13
  164. package/src/utils/feature-flags.mjs +6 -5
  165. package/src/utils/framework-server.mjs +43 -52
  166. package/src/utils/functions/constants.mjs +1 -1
  167. package/src/utils/functions/functions.mjs +30 -40
  168. package/src/utils/functions/get-functions.mjs +28 -29
  169. package/src/utils/functions/index.mjs +3 -3
  170. package/src/utils/get-global-config.mjs +33 -36
  171. package/src/utils/get-package-json.mjs +14 -15
  172. package/src/utils/get-repo-data.mjs +54 -64
  173. package/src/utils/get-site.mjs +14 -14
  174. package/src/utils/gh-auth.mjs +79 -100
  175. package/src/utils/gitignore.mjs +37 -40
  176. package/src/utils/headers.mjs +33 -35
  177. package/src/utils/hooks/requires-site-info.mjs +26 -22
  178. package/src/utils/init/config-github.mjs +207 -219
  179. package/src/utils/init/config-manual.mjs +83 -100
  180. package/src/utils/init/config.mjs +25 -26
  181. package/src/utils/init/node-version.mjs +23 -30
  182. package/src/utils/init/plugins.mjs +12 -8
  183. package/src/utils/init/utils.mjs +152 -172
  184. package/src/utils/live-tunnel.mjs +118 -141
  185. package/src/utils/lm/install.mjs +220 -259
  186. package/src/utils/lm/requirements.mjs +54 -63
  187. package/src/utils/lm/steps.mjs +31 -31
  188. package/src/utils/lm/ui.mjs +13 -20
  189. package/src/utils/open-browser.mjs +31 -32
  190. package/src/utils/parse-raw-flags.mjs +39 -35
  191. package/src/utils/proxy-server.mjs +84 -71
  192. package/src/utils/proxy.mjs +696 -750
  193. package/src/utils/read-repo-url.mjs +48 -47
  194. package/src/utils/redirects.mjs +49 -49
  195. package/src/utils/request-id.mjs +2 -4
  196. package/src/utils/rules-proxy.mjs +96 -100
  197. package/src/utils/run-build.mjs +109 -132
  198. package/src/utils/shell.mjs +99 -106
  199. package/src/utils/sign-redirect.mjs +14 -14
  200. package/src/utils/sites/utils.mjs +48 -55
  201. package/src/utils/state-config.mjs +101 -101
  202. package/src/utils/static-server.mjs +28 -34
  203. package/src/utils/telemetry/index.mjs +2 -2
  204. package/src/utils/telemetry/report-error.mjs +45 -49
  205. package/src/utils/telemetry/request.mjs +36 -43
  206. package/src/utils/telemetry/telemetry.mjs +90 -105
  207. package/src/utils/telemetry/utils.mjs +5 -6
  208. package/src/utils/telemetry/validation.mjs +55 -53
  209. package/src/utils/types.d.ts +46 -0
  210. package/src/utils/validation.mjs +10 -13
@@ -1,56 +1,57 @@
1
- import { error } from '../command-helpers.mjs'
2
-
3
- export const AVAILABLE_CONTEXTS = ['all', 'production', 'deploy-preview', 'branch-deploy', 'dev']
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
- if (!context) {
12
- return context
13
- }
14
- const CONTEXT_SYNONYMS = {
15
- dp: 'deploy-preview',
16
- prod: 'production',
17
- }
18
- context = context.toLowerCase()
19
- if (context in CONTEXT_SYNONYMS) {
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
- }
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
- export const findValueInValues = (values, context) =>
37
- values.find((val) => {
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
- // the "context" option passed in is actually the name of a branch
40
- return val.context === 'all' || val.context_parameter === context
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
- export const filterEnvBySource = (env, source) =>
52
- Object.fromEntries(Object.entries(env).filter(([, variable]) => variable.sources[0] === source))
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
- if (accountId === undefined) {
64
- return {}
65
- }
66
- try {
67
- // if a single key is passed, fetch that single env var
68
- if (key) {
69
- const envelopeItem = await api.getEnvVar({ accountId, key, siteId })
70
- return [envelopeItem]
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
- // otherwise, fetch the entire list of env vars
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
- export const formatEnvelopeData = ({ context = 'dev', envelopeItems = [], scope = 'any', source }) =>
106
- envelopeItems
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
- const { context: ctx, context_parameter: branch, value } = findValueInValues(cur.values, context)
116
- return {
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
- context: ctx,
120
- branch,
121
- scopes: cur.scopes,
122
- sources: [source],
123
- value,
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
- const { account_slug: accountId, id: siteId } = siteInfo
141
-
142
- const [accountEnvelopeItems, siteEnvelopeItems] = await Promise.all([
143
- fetchEnvelopeItems({ api, accountId, key }),
144
- fetchEnvelopeItems({ api, accountId, key, siteId }),
145
- ])
146
-
147
- const accountEnv = formatEnvelopeData({ context, envelopeItems: accountEnvelopeItems, scope, source: 'account' })
148
- const siteEnv = formatEnvelopeData({ context, envelopeItems: siteEnvelopeItems, scope, source: 'ui' })
149
-
150
- if (raw) {
151
- const entries = Object.entries({ ...accountEnv, ...siteEnv })
152
- return entries.reduce(
153
- (obj, [envVarKey, metadata]) => ({
154
- ...obj,
155
- [envVarKey]: metadata.value,
156
- }),
157
- {},
158
- )
159
- }
160
-
161
- const generalEnv = filterEnvBySource(env, 'general')
162
- const internalEnv = filterEnvBySource(env, 'internal')
163
- const addonsEnv = filterEnvBySource(env, 'addons')
164
- const configFileEnv = filterEnvBySource(env, 'configFile')
165
-
166
- // filter out configFile env vars if a non-configFile scope is passed
167
- const includeConfigEnvVars = /any|builds|post[-_]processing/.test(scope)
168
-
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
- }
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
- 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
- return scopes.map((scope) => SCOPES_MAP[scope]).join(', ')
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
- 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
-
223
- return envVars
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
- envVars
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
- const envVar = cur.values.find((val) => [context, 'all'].includes(val.context_parameter || val.context))
237
- if (envVar && envVar.value) {
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
- ...acc,
240
- [cur.key]: envVar.value,
241
- }
242
- }
243
- return acc
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
+ }, {});
@@ -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
- const execaMock = await import(env.NETLIFY_CLI_EXECA_PATH)
17
- execa = execaMock.default
18
- } else {
19
- execa = execaLib
12
+ const execaMock = await import(env.NETLIFY_CLI_EXECA_PATH);
13
+ execa = execaMock.default;
20
14
  }
21
-
22
- export default execa
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
- if (siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false) {
16
- return true
17
- }
18
- return false
19
- }
16
+ if (siteInfo.feature_flags && siteInfo.feature_flags[flagName] !== false) {
17
+ return true;
18
+ }
19
+ return false;
20
+ };
@@ -1,20 +1,14 @@
1
- // @ts-check
2
- import waitPort from 'wait-port'
3
-
4
- import { startSpinner, stopSpinner } from '../lib/spinner.mjs'
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
- if (settings.useStaticServer) {
27
- if (settings.command) {
28
- runCommand(settings.command, { env: settings.env, cwd })
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
- await startStaticServer({ settings })
31
-
32
- return {}
33
- }
34
-
35
- log(`${NETLIFYDEVLOG} Starting Netlify Dev with ${settings.framework || 'custom config'}`)
36
-
37
- const spinner = startSpinner({
38
- text: `Waiting for framework port ${settings.frameworkPort}. This can be configured using the 'targetPort' property in the netlify.toml`,
39
- })
40
-
41
- runCommand(settings.command, { env: settings.env, spinner, cwd })
42
-
43
- let port
44
- try {
45
- port = await waitPort({
46
- port: settings.frameworkPort,
47
- host: 'localhost',
48
- output: 'silent',
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
- stopSpinner({ error: false, spinner })
58
- } catch (error_) {
59
- stopSpinner({ error: true, spinner })
60
- log(NETLIFYDEVERR, `Netlify Dev could not start or connect to localhost:${settings.frameworkPort}.`)
61
- log(NETLIFYDEVERR, `Please make sure your framework server is running on port ${settings.frameworkPort}`)
62
- error(error_)
63
- exit(1)
64
- }
65
-
66
- return { ipVersion: port?.ipVersion }
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
- // @ts-check
2
- import { promises as fs } from 'fs'
3
- import { resolve } from 'path'
4
-
5
- import { isDirectoryAsync, isFileAsync } from '../../lib/fs.mjs'
6
- import { getPathInProject } from '../../lib/settings.mjs'
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
- export const getFunctionsDir = ({ config, options }, defaultValue) =>
20
- options.functions || config.dev?.functions || config.functionsDirectory || config.dev?.Functions || defaultValue
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
- const path = resolve(base, packagePath, getPathInProject(['functions', 'manifest.json']))
24
- const isFile = await isFileAsync(path)
25
-
26
- return isFile ? path : null
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
- const path = resolve(base, packagePath, getPathInProject(['functions']))
31
- const isDirectory = await isDirectoryAsync(path)
32
-
33
- return isDirectory ? path : null
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
- const path = resolve(base, packagePath, getPathInProject([SERVE_FUNCTIONS_FOLDER]))
38
-
39
- return path
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
- const path = resolve(base, packagePath, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]))
52
-
53
- if (ensureExists) {
54
- await fs.mkdir(path, { recursive: true })
55
- }
56
-
57
- const isDirectory = await isDirectoryAsync(path)
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
+ };