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.
Files changed (210) hide show
  1. package/README.md +2 -138
  2. package/npm-shrinkwrap.json +76 -76
  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 -99
  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,19 +1,14 @@
1
- // @ts-check
2
- import pWaitFor from 'p-wait-for'
3
- import prettyjson from 'prettyjson'
4
-
5
- import { startSpinner, stopSpinner } from '../../lib/spinner.mjs'
6
- import { chalk, error, log } from '../../utils/command-helpers.mjs'
7
- import { init } from '../init/index.mjs'
8
-
1
+ import pWaitFor from 'p-wait-for';
2
+ import prettyjson from 'prettyjson';
3
+ import { startSpinner, stopSpinner } from '../../lib/spinner.mjs';
4
+ import { chalk, error, log } from '../../utils/command-helpers.mjs';
5
+ import { init } from '../init/index.mjs';
9
6
  // 1 second
10
- const INIT_WAIT = 1e3
11
-
7
+ const INIT_WAIT = 1e3;
12
8
  // 1 second
13
- const BUILD_FINISH_INTERVAL = 1e3
9
+ const BUILD_FINISH_INTERVAL = 1e3;
14
10
  // 20 minutes
15
- const BUILD_FINISH_TIMEOUT = 12e5
16
-
11
+ const BUILD_FINISH_TIMEOUT = 12e5;
17
12
  /**
18
13
  *
19
14
  * @param {import('netlify').NetlifyAPI} api
@@ -21,111 +16,102 @@ const BUILD_FINISH_TIMEOUT = 12e5
21
16
  * @param {import('ora').Ora} spinner
22
17
  * @returns {Promise<boolean>}
23
18
  */
19
+ // @ts-expect-error TS(7006) FIXME: Parameter 'api' implicitly has an 'any' type.
24
20
  const waitForBuildFinish = async function (api, siteId, spinner) {
25
- let firstPass = true
26
-
27
- const waitForBuildToFinish = async function () {
28
- const builds = await api.listSiteBuilds({ siteId })
29
- // build.error
30
- const currentBuilds = builds.filter((build) => !build.done)
31
-
32
- // if build.error
33
- // @TODO implement build error messages into this
34
-
35
- if (!currentBuilds || currentBuilds.length === 0) {
36
- stopSpinner({ spinner })
37
- return true
38
- }
39
- firstPass = false
40
- return false
41
- }
42
-
43
- await pWaitFor(waitForBuildToFinish, {
44
- interval: BUILD_FINISH_INTERVAL,
45
- timeout: {
46
- milliseconds: BUILD_FINISH_TIMEOUT,
47
- message: 'Timeout while waiting for deploy to finish',
48
- },
49
- })
50
-
51
- // return only when build done or timeout happens
52
- return firstPass
53
- }
54
-
21
+ let firstPass = true;
22
+ const waitForBuildToFinish = async function () {
23
+ const builds = await api.listSiteBuilds({ siteId });
24
+ // build.error
25
+ // @ts-expect-error TS(7006) FIXME: Parameter 'build' implicitly has an 'any' type.
26
+ const currentBuilds = builds.filter((build) => !build.done);
27
+ // if build.error
28
+ // @TODO implement build error messages into this
29
+ if (!currentBuilds || currentBuilds.length === 0) {
30
+ // @ts-expect-error TS(2345) FIXME: Argument of type '{ spinner: any; }' is not assign... Remove this comment to see the full error message
31
+ stopSpinner({ spinner });
32
+ return true;
33
+ }
34
+ firstPass = false;
35
+ return false;
36
+ };
37
+ await pWaitFor(waitForBuildToFinish, {
38
+ interval: BUILD_FINISH_INTERVAL,
39
+ timeout: {
40
+ milliseconds: BUILD_FINISH_TIMEOUT,
41
+ message: 'Timeout while waiting for deploy to finish',
42
+ },
43
+ });
44
+ // return only when build done or timeout happens
45
+ return firstPass;
46
+ };
55
47
  /**
56
48
  * The watch command
57
49
  * @param {import('commander').OptionValues} options
58
50
  * @param {import('../base-command.mjs').default} command
59
51
  */
52
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
60
53
  const watch = async (options, command) => {
61
- await command.authenticate()
62
- const client = command.netlify.api
63
- let siteId = command.netlify.site.id
64
-
65
- if (!siteId) {
66
- // TODO: build init command
67
- const siteData = await init({}, command)
68
- siteId = siteData.id
69
- }
70
-
71
- // wait for 1 sec for everything to kickoff
72
- console.time('Deploy time')
73
- await new Promise((resolve) => {
74
- setTimeout(() => resolve(), INIT_WAIT)
75
- })
76
-
77
- // Get latest commit and look for that
78
- // git rev-parse HEAD
79
-
80
- // if no sha, its a manual "triggered deploy"
81
- //
82
- // {
83
- // "id": "5b4e23db82d3f1780abd74f3",
84
- // "deploy_id": "5b4e23db82d3f1780abd74f2",
85
- // "sha": "pull/1/head",
86
- // "log": [],
87
- // "done": false,
88
- // "error": null,
89
- // "created_at": "2018-07-17T17:14:03.423Z"
90
- // }
91
- //
92
- const spinner = startSpinner({ text: 'Waiting for active site deploys to complete' })
93
- try {
94
- // Fetch all builds!
95
- // const builds = await client.listSiteBuilds({siteId})
54
+ await command.authenticate();
55
+ const client = command.netlify.api;
56
+ let siteId = command.netlify.site.id;
57
+ if (!siteId) {
58
+ // TODO: build init command
59
+ const siteData = await init({}, command);
60
+ siteId = siteData.id;
61
+ }
62
+ // wait for 1 sec for everything to kickoff
63
+ console.time('Deploy time');
64
+ await new Promise((resolve) => {
65
+ // @ts-expect-error TS(2794) FIXME: Expected 1 arguments, but got 0. Did you forget to... Remove this comment to see the full error message
66
+ setTimeout(() => resolve(), INIT_WAIT);
67
+ });
68
+ // Get latest commit and look for that
69
+ // git rev-parse HEAD
70
+ // if no sha, its a manual "triggered deploy"
71
+ //
72
+ // {
73
+ // "id": "5b4e23db82d3f1780abd74f3",
74
+ // "deploy_id": "5b4e23db82d3f1780abd74f2",
75
+ // "sha": "pull/1/head",
76
+ // "log": [],
77
+ // "done": false,
78
+ // "error": null,
79
+ // "created_at": "2018-07-17T17:14:03.423Z"
80
+ // }
96
81
  //
97
- // // Filter down to any that are not done
98
- // const buildsToWatch = builds.filter((build) => {
99
- // return !build.done
100
- // })
101
-
102
- const noActiveBuilds = await waitForBuildFinish(client, siteId, spinner)
103
-
104
- const siteData = await client.getSite({ siteId })
105
-
106
- const message = chalk.cyanBright.bold.underline(noActiveBuilds ? 'Last build' : 'Deploy complete')
107
- log()
108
- log(message)
109
- log(
110
- prettyjson.render({
111
- URL: siteData.ssl_url || siteData.url,
112
- Admin: siteData.admin_url,
113
- }),
114
- )
115
- console.timeEnd('Deploy time')
116
- } catch (error_) {
117
- error(error_)
118
- }
119
- }
120
-
82
+ const spinner = startSpinner({ text: 'Waiting for active site deploys to complete' });
83
+ try {
84
+ // Fetch all builds!
85
+ // const builds = await client.listSiteBuilds({siteId})
86
+ //
87
+ // // Filter down to any that are not done
88
+ // const buildsToWatch = builds.filter((build) => {
89
+ // return !build.done
90
+ // })
91
+ const noActiveBuilds = await waitForBuildFinish(client, siteId, spinner);
92
+ const siteData = await client.getSite({ siteId });
93
+ const message = chalk.cyanBright.bold.underline(noActiveBuilds ? 'Last build' : 'Deploy complete');
94
+ log();
95
+ log(message);
96
+ log(prettyjson.render({
97
+ URL: siteData.ssl_url || siteData.url,
98
+ Admin: siteData.admin_url,
99
+ }));
100
+ console.timeEnd('Deploy time');
101
+ }
102
+ catch (error_) {
103
+ // @ts-expect-error TS(2345) FIXME: Argument of type 'unknown' is not assignable to pa... Remove this comment to see the full error message
104
+ error(error_);
105
+ }
106
+ };
121
107
  /**
122
108
  * Creates the `netlify watch` command
123
109
  * @param {import('../base-command.mjs').default} program
124
110
  * @returns
125
111
  */
126
- export const createWatchCommand = (program) =>
127
- program
112
+ // @ts-expect-error TS(7006) FIXME: Parameter 'program' implicitly has an 'any' type.
113
+ export const createWatchCommand = (program) => program
128
114
  .command('watch')
129
115
  .description('Watch for site deploy to finish')
130
116
  .addExamples([`netlify watch`, `git push && netlify watch`])
131
- .action(watch)
117
+ .action(watch);
@@ -1,5 +1,4 @@
1
- export default async (request) => {
2
- return new Response('Hello, World!', {
1
+ export default async (request) =>
2
+ new Response('Hello, World!', {
3
3
  headers: { 'content-type': 'text/html' },
4
4
  })
5
- }
@@ -1,14 +1,13 @@
1
- // @ts-check
2
-
3
1
  /**
4
2
  * @param {any} account
5
3
  * @param {string} capability
6
4
  * @returns {boolean}
7
5
  */
8
- const supportsBooleanCapability = (account, capability) => Boolean(account?.capabilities?.[capability]?.included)
9
-
6
+ // @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
7
+ const supportsBooleanCapability = (account, capability) => Boolean(account?.capabilities?.[capability]?.included);
10
8
  /**
11
9
  * @param {any} account
12
10
  * @returns {boolean}
13
11
  */
14
- export const supportsBackgroundFunctions = (account) => supportsBooleanCapability(account, 'background_functions')
12
+ // @ts-expect-error TS(7006) FIXME: Parameter 'account' implicitly has an 'any' type.
13
+ export const supportsBackgroundFunctions = (account) => supportsBooleanCapability(account, 'background_functions');
package/src/lib/api.mjs CHANGED
@@ -1,22 +1,24 @@
1
- import { warn } from '../utils/command-helpers.mjs'
2
-
1
+ import { warn } from '../utils/command-helpers.mjs';
2
+ // @ts-expect-error TS(7031) FIXME: Binding element 'api' implicitly has an 'any' type... Remove this comment to see the full error message
3
3
  export const cancelDeploy = async ({ api, deployId }) => {
4
- try {
5
- await api.cancelSiteDeploy({ deploy_id: deployId })
6
- } catch (error) {
7
- warn(`Failed canceling deploy with id ${deployId}: ${error.message}`)
8
- }
9
- }
10
-
11
- const FIRST_PAGE = 1
12
- const MAX_PAGES = 10
13
- const MAX_PER_PAGE = 100
4
+ try {
5
+ await api.cancelSiteDeploy({ deploy_id: deployId });
6
+ }
7
+ catch (error) {
8
+ // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'.
9
+ warn(`Failed canceling deploy with id ${deployId}: ${error.message}`);
10
+ }
11
+ };
12
+ const FIRST_PAGE = 1;
13
+ const MAX_PAGES = 10;
14
+ const MAX_PER_PAGE = 100;
15
+ // @ts-expect-error TS(7023) FIXME: 'listSites' implicitly has return type 'any' becau... Remove this comment to see the full error message
14
16
  export const listSites = async ({ api, options }) => {
15
- const { maxPages = MAX_PAGES, page = FIRST_PAGE, ...rest } = options
16
- const sites = await api.listSites({ page, per_page: MAX_PER_PAGE, ...rest })
17
- // TODO: use pagination headers when js-client returns them
18
- if (sites.length === MAX_PER_PAGE && page + 1 <= maxPages) {
19
- return [...sites, ...(await listSites({ api, options: { page: page + 1, maxPages, ...rest } }))]
20
- }
21
- return sites
22
- }
17
+ const { maxPages = MAX_PAGES, page = FIRST_PAGE, ...rest } = options;
18
+ const sites = await api.listSites({ page, per_page: MAX_PER_PAGE, ...rest });
19
+ // TODO: use pagination headers when js-client returns them
20
+ if (sites.length === MAX_PER_PAGE && page + 1 <= maxPages) {
21
+ return [...sites, ...(await listSites({ api, options: { page: page + 1, maxPages, ...rest } }))];
22
+ }
23
+ return sites;
24
+ };
@@ -1,50 +1,41 @@
1
- import path from 'path'
2
-
3
- import { BlobsServer } from '@netlify/blobs'
4
- import { v4 as uuidv4 } from 'uuid'
5
-
6
- import { getPathInProject } from '../settings.mjs'
7
-
8
- /**
9
- * @typedef BlobsContext
10
- * @type {object}
11
- * @property {string} edgeURL
12
- * @property {string} deployID
13
- * @property {string} siteID
14
- * @property {string} token
15
- */
16
-
1
+ import path from 'path';
2
+ import { BlobsServer } from '@netlify/blobs';
3
+ import { v4 as uuidv4 } from 'uuid';
4
+ import { log, NETLIFYDEVLOG } from '../../utils/command-helpers.mjs';
5
+ import { getPathInProject } from '../settings.mjs';
6
+ let hasPrintedLocalBlobsNotice = false;
7
+ const printLocalBlobsNotice = () => {
8
+ if (hasPrintedLocalBlobsNotice) {
9
+ return;
10
+ }
11
+ hasPrintedLocalBlobsNotice = true;
12
+ log(`${NETLIFYDEVLOG} Netlify Blobs running in sandbox mode for local development. Refer to https://ntl.fyi/local-blobs for more information.`);
13
+ };
14
+ const startBlobsServer = async (debug, projectRoot, token) => {
15
+ const directory = path.resolve(projectRoot, getPathInProject(['blobs-serves']));
16
+ const server = new BlobsServer({
17
+ debug,
18
+ directory,
19
+ onRequest: () => {
20
+ printLocalBlobsNotice();
21
+ },
22
+ token,
23
+ });
24
+ const { port } = await server.start();
25
+ return { port };
26
+ };
17
27
  /**
18
28
  * Starts a local Blobs server and returns a context object that lets functions
19
29
  * connect to it.
20
- *
21
- * @param {object} options
22
- * @param {boolean} options.debug
23
- * @param {string} options.projectRoot
24
- * @param {string} options.siteID
25
- * @returns {Promise<BlobsContext>}
26
30
  */
27
31
  export const getBlobsContext = async ({ debug, projectRoot, siteID }) => {
28
- const token = uuidv4()
29
- const { port } = await startBlobsServer({ debug, projectRoot, token })
30
- const context = {
31
- deployID: '0',
32
- edgeURL: `http://localhost:${port}`,
33
- siteID,
34
- token,
35
- }
36
-
37
- return context
38
- }
39
-
40
- const startBlobsServer = async ({ debug, projectRoot, token }) => {
41
- const directory = path.resolve(projectRoot, getPathInProject(['blobs']))
42
- const server = new BlobsServer({
43
- debug,
44
- directory,
45
- token,
46
- })
47
- const { port } = await server.start()
48
-
49
- return { port }
50
- }
32
+ const token = uuidv4();
33
+ const { port } = await startBlobsServer(debug, projectRoot, token);
34
+ const context = {
35
+ deployID: '0',
36
+ edgeURL: `http://localhost:${port}`,
37
+ siteID,
38
+ token,
39
+ };
40
+ return context;
41
+ };
package/src/lib/build.mjs CHANGED
@@ -1,21 +1,16 @@
1
- // @ts-check
2
- import fs from 'fs'
3
- import process from 'process'
4
-
5
- import build from '@netlify/build'
6
- import tomlify from 'tomlify-j0.4'
7
-
8
- import { isFeatureFlagEnabled } from '../utils/feature-flags.mjs'
9
-
10
- import { getBootstrapURL } from './edge-functions/bootstrap.mjs'
11
- import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.mjs'
12
-
1
+ import fs from 'fs';
2
+ import process from 'process';
3
+ import build from '@netlify/build';
4
+ // @ts-expect-error TS(7016) FIXME: Could not find a declaration file for module 'toml... Remove this comment to see the full error message
5
+ import tomlify from 'tomlify-j0.4';
6
+ import { isFeatureFlagEnabled } from '../utils/feature-flags.mjs';
7
+ import { getBootstrapURL } from './edge-functions/bootstrap.mjs';
8
+ import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/consts.mjs';
13
9
  /**
14
10
  * The buildConfig + a missing cachedConfig
15
11
  * @typedef BuildConfig
16
12
  * @type {Parameters<import('@netlify/build/src/core/main.js')>[0] & {cachedConfig: any}}
17
13
  */
18
-
19
14
  // We have already resolved the configuration using `@netlify/config`
20
15
  // This is stored as `netlify.cachedConfig` and can be passed to
21
16
  // `@netlify/build --cachedConfig`.
@@ -30,88 +25,90 @@ import { featureFlags as edgeFunctionsFeatureFlags } from './edge-functions/cons
30
25
  * @param {*} config.deployHandler
31
26
  * @returns {BuildConfig}
32
27
  */
33
- export const getBuildOptions = ({
34
- cachedConfig,
35
- currentDir,
36
- deployHandler,
37
- options: { context, cwd, debug, dry, json, offline, silent },
38
- packagePath,
39
- token,
40
- }) => {
41
- const eventHandlers = {
42
- onEnd: {
43
- handler: ({ netlifyConfig }) => {
44
- const string = tomlify.toToml(netlifyConfig)
45
-
46
- if (!fs.existsSync(`${currentDir}/.netlify`)) {
47
- fs.mkdirSync(`${currentDir}/.netlify`, { recursive: true })
48
- }
49
- fs.writeFileSync(`${currentDir}/.netlify/netlify.toml`, string)
50
-
51
- return {}
52
- },
53
- description: 'Save updated config',
54
- },
55
- }
56
-
57
- if (deployHandler) {
58
- eventHandlers.onPostBuild = {
59
- handler: deployHandler,
60
- description: 'Deploy Site',
28
+ export const getBuildOptions = ({
29
+ // @ts-expect-error TS(7031) FIXME: Binding element 'cachedConfig' implicitly has an '... Remove this comment to see the full error message
30
+ cachedConfig,
31
+ // @ts-expect-error TS(7031) FIXME: Binding element 'currentDir' implicitly has an 'an... Remove this comment to see the full error message
32
+ currentDir,
33
+ // @ts-expect-error TS(7031) FIXME: Binding element 'deployHandler' implicitly has an ... Remove this comment to see the full error message
34
+ deployHandler,
35
+ // @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
36
+ options: { context, cwd, debug, dry, json, offline, silent },
37
+ // @ts-expect-error TS(7031) FIXME: Binding element 'packagePath' implicitly has an 'a... Remove this comment to see the full error message
38
+ packagePath,
39
+ // @ts-expect-error TS(7031) FIXME: Binding element 'token' implicitly has an 'any' ty... Remove this comment to see the full error message
40
+ token, }) => {
41
+ const eventHandlers = {
42
+ onEnd: {
43
+ // @ts-expect-error TS(7031) FIXME: Binding element 'netlifyConfig' implicitly has an ... Remove this comment to see the full error message
44
+ handler: ({ netlifyConfig }) => {
45
+ const string = tomlify.toToml(netlifyConfig);
46
+ if (!fs.existsSync(`${currentDir}/.netlify`)) {
47
+ fs.mkdirSync(`${currentDir}/.netlify`, { recursive: true });
48
+ }
49
+ fs.writeFileSync(`${currentDir}/.netlify/netlify.toml`, string);
50
+ return {};
51
+ },
52
+ description: 'Save updated config',
53
+ },
54
+ };
55
+ if (deployHandler) {
56
+ // @ts-expect-error TS(2339) FIXME: Property 'onPostBuild' does not exist on type '{ o... Remove this comment to see the full error message
57
+ eventHandlers.onPostBuild = {
58
+ handler: deployHandler,
59
+ description: 'Deploy Site',
60
+ };
61
61
  }
62
- }
63
-
64
- return {
65
- cachedConfig,
66
- siteId: cachedConfig.siteInfo.id,
67
- packagePath,
68
- token,
69
- dry,
70
- debug,
71
- context,
72
- mode: 'cli',
73
- telemetry: false,
74
- // buffer = true will not stream output
75
- buffer: json || silent,
76
- offline,
77
- cwd,
78
- featureFlags: {
79
- ...edgeFunctionsFeatureFlags,
80
- ...getFeatureFlagsFromSiteInfo(cachedConfig.siteInfo),
81
- functionsBundlingManifest: true,
82
- },
83
- eventHandlers,
84
- edgeFunctionsBootstrapURL: getBootstrapURL(),
85
- }
86
- }
87
-
62
+ return {
63
+ cachedConfig,
64
+ siteId: cachedConfig.siteInfo.id,
65
+ packagePath,
66
+ token,
67
+ dry,
68
+ debug,
69
+ context,
70
+ mode: 'cli',
71
+ telemetry: false,
72
+ // buffer = true will not stream output
73
+ buffer: json || silent,
74
+ offline,
75
+ cwd,
76
+ featureFlags: {
77
+ ...edgeFunctionsFeatureFlags,
78
+ ...getFeatureFlagsFromSiteInfo(cachedConfig.siteInfo),
79
+ functionsBundlingManifest: true,
80
+ },
81
+ eventHandlers,
82
+ edgeFunctionsBootstrapURL: getBootstrapURL(),
83
+ };
84
+ };
88
85
  /**
89
86
  * @param {*} siteInfo
90
87
  * @returns {Record<string, any>}
91
88
  */
89
+ // @ts-expect-error TS(7006) FIXME: Parameter 'siteInfo' implicitly has an 'any' type.
92
90
  const getFeatureFlagsFromSiteInfo = (siteInfo) => ({
93
- ...siteInfo.feature_flags,
94
- // see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
95
- zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
96
- })
97
-
91
+ ...siteInfo.feature_flags,
92
+ // see https://github.com/netlify/pod-dev-foundations/issues/581#issuecomment-1731022753
93
+ zisi_golang_use_al2: isFeatureFlagEnabled('cli_golang_use_al2', siteInfo),
94
+ });
98
95
  /**
99
96
  * run the build command
100
97
  * @param {BuildConfig} options
101
98
  * @returns
102
99
  */
100
+ // @ts-expect-error TS(7006) FIXME: Parameter 'options' implicitly has an 'any' type.
103
101
  export const runBuild = async (options) => {
104
- // If netlify NETLIFY_API_URL is set we need to pass this information to @netlify/build
105
- // TODO don't use testOpts, but add real properties to do this.
106
- if (process.env.NETLIFY_API_URL) {
107
- const apiUrl = new URL(process.env.NETLIFY_API_URL)
108
- const testOpts = {
109
- scheme: apiUrl.protocol.slice(0, -1),
110
- host: apiUrl.host,
102
+ // If netlify NETLIFY_API_URL is set we need to pass this information to @netlify/build
103
+ // TODO don't use testOpts, but add real properties to do this.
104
+ if (process.env.NETLIFY_API_URL) {
105
+ const apiUrl = new URL(process.env.NETLIFY_API_URL);
106
+ const testOpts = {
107
+ scheme: apiUrl.protocol.slice(0, -1),
108
+ host: apiUrl.host,
109
+ };
110
+ options = { ...options, testOpts };
111
111
  }
112
- options = { ...options, testOpts }
113
- }
114
-
115
- const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options)
116
- return { exitCode, newConfig, configMutations }
117
- }
112
+ const { configMutations, netlifyConfig: newConfig, severityCode: exitCode } = await build(options);
113
+ return { exitCode, newConfig, configMutations };
114
+ };
@@ -1,4 +1,2 @@
1
- // @ts-check
2
- import { getPathInHome } from '../settings.mjs'
3
-
4
- export const AUTOCOMPLETION_FILE = getPathInHome(['autocompletion.json'])
1
+ import { getPathInHome } from '../settings.mjs';
2
+ export const AUTOCOMPLETION_FILE = getPathInHome(['autocompletion.json']);