netlify-cli 15.8.1 → 15.9.1-rc.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 (52) hide show
  1. package/npm-shrinkwrap.json +512 -414
  2. package/package.json +9 -10
  3. package/scripts/postinstall.mjs +8 -8
  4. package/src/commands/base-command.mjs +195 -59
  5. package/src/commands/deploy/deploy.mjs +21 -9
  6. package/src/commands/dev/dev.mjs +24 -16
  7. package/src/commands/functions/functions-build.mjs +2 -2
  8. package/src/commands/functions/functions-create.mjs +0 -3
  9. package/src/commands/functions/functions-invoke.mjs +8 -5
  10. package/src/commands/functions/functions-serve.mjs +2 -1
  11. package/src/commands/init/init.mjs +1 -1
  12. package/src/commands/link/link.mjs +5 -5
  13. package/src/commands/main.mjs +1 -1
  14. package/src/commands/serve/serve.mjs +14 -6
  15. package/src/commands/sites/sites-create-template.mjs +1 -1
  16. package/src/commands/sites/sites-create.mjs +1 -1
  17. package/src/functions-templates/javascript/auth-fetch/package-lock.json +6 -6
  18. package/src/functions-templates/javascript/google-analytics/package-lock.json +6 -6
  19. package/src/functions-templates/typescript/hello-world/package-lock.json +6 -6
  20. package/src/functions-templates/typescript/transform-response/{{name}}.ts +0 -1
  21. package/src/lib/completion/generate-autocompletion.mjs +4 -4
  22. package/src/lib/edge-functions/bootstrap.mjs +1 -1
  23. package/src/lib/edge-functions/headers.mjs +1 -0
  24. package/src/lib/edge-functions/internal.mjs +5 -3
  25. package/src/lib/edge-functions/proxy.mjs +39 -5
  26. package/src/lib/edge-functions/registry.mjs +11 -9
  27. package/src/lib/functions/registry.mjs +1 -3
  28. package/src/lib/functions/runtimes/js/builders/zisi.mjs +3 -8
  29. package/src/lib/functions/server.mjs +7 -6
  30. package/src/lib/spinner.mjs +1 -1
  31. package/src/recipes/vscode/index.mjs +1 -1
  32. package/src/utils/build-info.mjs +19 -0
  33. package/src/utils/command-helpers.mjs +16 -7
  34. package/src/utils/deploy/hash-fns.mjs +1 -2
  35. package/src/utils/detect-server-settings.mjs +148 -200
  36. package/src/utils/dev.mjs +1 -0
  37. package/src/utils/execa.mjs +4 -2
  38. package/src/utils/framework-server.mjs +2 -2
  39. package/src/utils/functions/functions.mjs +7 -0
  40. package/src/utils/functions/get-functions.mjs +2 -2
  41. package/src/utils/get-repo-data.mjs +5 -6
  42. package/src/utils/init/config-github.mjs +2 -2
  43. package/src/utils/init/config-manual.mjs +24 -7
  44. package/src/utils/init/utils.mjs +62 -63
  45. package/src/utils/proxy-server.mjs +9 -4
  46. package/src/utils/proxy.mjs +6 -0
  47. package/src/utils/run-build.mjs +58 -7
  48. package/src/utils/shell.mjs +14 -3
  49. package/src/utils/state-config.mjs +5 -1
  50. package/src/utils/static-server.mjs +4 -0
  51. package/src/utils/telemetry/report-error.mjs +8 -4
  52. package/src/utils/init/frameworks.mjs +0 -23
@@ -2,6 +2,7 @@ import { mkdir, writeFile } from 'fs/promises'
2
2
  import { createRequire } from 'module'
3
3
  import path from 'path'
4
4
 
5
+ import { zipFunction, listFunction } from '@netlify/zip-it-and-ship-it'
5
6
  import decache from 'decache'
6
7
  import { readPackageUp } from 'read-pkg-up'
7
8
  import sourceMapSupport from 'source-map-support'
@@ -44,9 +45,6 @@ const buildFunction = async ({
44
45
  }
45
46
  const functionDirectory = path.dirname(func.mainFile)
46
47
 
47
- // performance
48
- const { zipFunction } = await import('@netlify/zip-it-and-ship-it')
49
-
50
48
  // If we have a function at `functions/my-func/index.js` and we pass
51
49
  // that path to `zipFunction`, it will lack the context of the whole
52
50
  // functions directory and will infer the name of the function to be
@@ -92,15 +90,12 @@ const buildFunction = async ({
92
90
  * @param {string} params.mainFile
93
91
  * @param {string} params.projectRoot
94
92
  */
95
- export const parseFunctionForMetadata = async ({ config, mainFile, projectRoot }) => {
96
- const { listFunction } = await import('@netlify/zip-it-and-ship-it')
97
-
98
- return await listFunction(mainFile, {
93
+ export const parseFunctionForMetadata = async ({ config, mainFile, projectRoot }) =>
94
+ await listFunction(mainFile, {
99
95
  config: netlifyConfigToZisiConfig({ config, projectRoot }),
100
96
  featureFlags: { zisi_functions_api_v2: true },
101
97
  parseISC: true,
102
98
  })
103
- }
104
99
 
105
100
  // Clears the cache for any files inside the directory from which functions are
106
101
  // served.
@@ -1,4 +1,8 @@
1
1
  // @ts-check
2
+ import { Buffer } from 'buffer'
3
+
4
+ import express from 'express'
5
+ import expressLogging from 'express-logging'
2
6
  import jwtDecode from 'jwt-decode'
3
7
 
4
8
  import { NETLIFYDEVERR, NETLIFYDEVLOG, error as errorExit, log } from '../../utils/command-helpers.mjs'
@@ -45,7 +49,6 @@ const hasBody = (req) =>
45
49
  // eslint-disable-next-line unicorn/prefer-number-properties
46
50
  (req.header('transfer-encoding') !== undefined || !isNaN(req.header('content-length'))) &&
47
51
  // we expect a string or a buffer, because we use the two bodyParsers(text, raw) from express
48
- // eslint-disable-next-line n/prefer-global/buffer
49
52
  (typeof req.body === 'string' || Buffer.isBuffer(req.body))
50
53
 
51
54
  export const createHandler = function (options) {
@@ -111,7 +114,8 @@ export const createHandler = function (options) {
111
114
  ...request.headers,
112
115
  'client-ip': [remoteAddress],
113
116
  'x-nf-client-connection-ip': [remoteAddress],
114
- [efHeaders.Geo]: JSON.stringify(geoLocation),
117
+ 'x-nf-account-id': [options.accountId],
118
+ [efHeaders.Geo]: Buffer.from(JSON.stringify(geoLocation)).toString('base64'),
115
119
  }).reduce((prev, [key, value]) => ({ ...prev, [key]: Array.isArray(value) ? value : [value] }), {})
116
120
  const rawQuery = new URLSearchParams(requestQuery).toString()
117
121
  const protocol = options.config?.dev?.https ? 'https' : 'http'
@@ -184,11 +188,8 @@ export const createHandler = function (options) {
184
188
  }
185
189
  }
186
190
 
187
- const getFunctionsServer = async function (options) {
191
+ const getFunctionsServer = (options) => {
188
192
  const { buildersPrefix = '', functionsPrefix = '', functionsRegistry, siteUrl } = options
189
- // performance optimization, load express on demand
190
- const { default: express } = await import('express')
191
- const { default: expressLogging } = await import('express-logging')
192
193
  const app = express()
193
194
  const functionHandler = createHandler(options)
194
195
 
@@ -17,7 +17,7 @@ export const startSpinner = ({ text }) =>
17
17
  * Stops the spinner with the following text
18
18
  * @param {object} config
19
19
  * @param {ora.Ora} config.spinner
20
- * @param {object} [config.error]
20
+ * @param {boolean} [config.error]
21
21
  * @param {string} [config.text]
22
22
  * @returns {void}
23
23
  */
@@ -1,5 +1,6 @@
1
1
  import { join } from 'path'
2
2
 
3
+ import { DenoBridge } from '@netlify/edge-bundler'
3
4
  import execa from 'execa'
4
5
  import inquirer from 'inquirer'
5
6
 
@@ -49,7 +50,6 @@ const getDenoExtPrompt = () => {
49
50
  }
50
51
 
51
52
  export const run = async ({ config, repositoryRoot }) => {
52
- const { DenoBridge } = await import('@netlify/edge-bundler')
53
53
  const deno = new DenoBridge({
54
54
  onBeforeDownload: () =>
55
55
  log(`${NETLIFYDEVWARN} Setting up the Edge Functions environment. This may take a couple of minutes.`),
@@ -0,0 +1,19 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * Detects and filters the build setting for a project and a command
5
+ * @param {import('../commands/base-command.mjs').default} command
6
+ */
7
+ export const detectBuildSettings = async (command) => {
8
+ const { project, workspacePackage } = command
9
+ const buildSettings = await project.getBuildSettings(project.workspace ? workspacePackage : '')
10
+ return buildSettings
11
+ .filter((setting) => {
12
+ if (project.workspace && project.relativeBaseDirectory && setting.packagePath) {
13
+ return project.relativeBaseDirectory.startsWith(setting.packagePath)
14
+ }
15
+
16
+ return true
17
+ })
18
+ .filter((setting) => setting.devCommand)
19
+ }
@@ -24,7 +24,7 @@ const argv = process.argv.slice(2)
24
24
  * Chalk instance for CLI that can be initialized with no colors mode
25
25
  * needed for json outputs where we don't want to have colors
26
26
  * @param {boolean} noColors - disable chalk colors
27
- * @return {object} - default or custom chalk instance
27
+ * @return {import('chalk').ChalkInstance} - default or custom chalk instance
28
28
  */
29
29
  const safeChalk = function (noColors) {
30
30
  if (noColors) {
@@ -174,12 +174,18 @@ export const warn = (message = '') => {
174
174
 
175
175
  /**
176
176
  * throws an error or log it
177
- * @param {string|Error} message
177
+ * @param {unknown} message
178
178
  * @param {object} [options]
179
179
  * @param {boolean} [options.exit]
180
180
  */
181
181
  export const error = (message = '', options = {}) => {
182
- const err = message instanceof Error ? message : new Error(message)
182
+ const err =
183
+ message instanceof Error
184
+ ? message
185
+ : // eslint-disable-next-line unicorn/no-nested-ternary
186
+ typeof message === 'string'
187
+ ? new Error(message)
188
+ : /** @type {Error} */ ({ message, stack: undefined, name: 'Error' })
183
189
 
184
190
  if (options.exit === false) {
185
191
  const bang = chalk.red(BANG)
@@ -198,10 +204,13 @@ export const exit = (code = 0) => {
198
204
  process.exit(code)
199
205
  }
200
206
 
201
- // When `build.publish` is not set by the user, the CLI behavior differs in
202
- // several ways. It detects it by checking if `build.publish` is `undefined`.
203
- // However, `@netlify/config` adds a default value to `build.publish`.
204
- // This removes 'publish' and 'publishOrigin' in this case.
207
+ /**
208
+ * When `build.publish` is not set by the user, the CLI behavior differs in
209
+ * several ways. It detects it by checking if `build.publish` is `undefined`.
210
+ * However, `@netlify/config` adds a default value to `build.publish`.
211
+ * This removes 'publish' and 'publishOrigin' in this case.
212
+ * @param {*} config
213
+ */
205
214
  export const normalizeConfig = (config) => {
206
215
  // Unused var here is in order to omit 'publish' from build config
207
216
  // eslint-disable-next-line no-unused-vars
@@ -2,6 +2,7 @@ import { readFile } from 'fs/promises'
2
2
  import path from 'path'
3
3
  import { promisify } from 'util'
4
4
 
5
+ import { zipFunctions } from '@netlify/zip-it-and-ship-it'
5
6
  import fromArray from 'from2-array'
6
7
  import pumpModule from 'pump'
7
8
 
@@ -66,8 +67,6 @@ const getFunctionZips = async ({
66
67
  })
67
68
  }
68
69
 
69
- const { zipFunctions } = await import('@netlify/zip-it-and-ship-it')
70
-
71
70
  return await zipFunctions(directories, tmpDir, {
72
71
  basePath: rootDir,
73
72
  configFileDirectories: [getPathInProject([INTERNAL_FUNCTIONS_FOLDER])],