netlify-cli 15.1.0 → 15.2.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.
@@ -15,7 +15,7 @@ import {
15
15
  watchDebounced,
16
16
  } from '../../utils/command-helpers.mjs'
17
17
  import { INTERNAL_FUNCTIONS_FOLDER, SERVE_FUNCTIONS_FOLDER } from '../../utils/functions/functions.mjs'
18
- import { getLogMessage } from '../log.mjs'
18
+ import { BACKGROUND_FUNCTIONS_WARNING } from '../log.mjs'
19
19
  import { getPathInProject } from '../settings.mjs'
20
20
 
21
21
  import NetlifyFunction from './netlify-function.mjs'
@@ -140,7 +140,7 @@ export class FunctionsRegistry {
140
140
  }
141
141
 
142
142
  if (func.isBackground && this.isConnected && !this.capabilities.backgroundFunctions) {
143
- warn(getLogMessage('functions.backgroundNotSupported'))
143
+ warn(BACKGROUND_FUNCTIONS_WARNING)
144
144
  }
145
145
 
146
146
  if (!func.hasValidName()) {
@@ -3,7 +3,7 @@ import { createRequire } from 'module'
3
3
  import path from 'path'
4
4
 
5
5
  import decache from 'decache'
6
- import readPkgUp from 'read-pkg-up'
6
+ import { readPackageUp } from 'read-pkg-up'
7
7
  import sourceMapSupport from 'source-map-support'
8
8
 
9
9
  import { NETLIFYDEVERR } from '../../../../../utils/command-helpers.mjs'
@@ -112,7 +112,7 @@ const netlifyConfigToZisiConfig = ({ config, projectRoot }) =>
112
112
  export default async function handler({ config, directory, errorExit, func, projectRoot }) {
113
113
  const functionsConfig = netlifyConfigToZisiConfig({ config, projectRoot })
114
114
 
115
- const packageJson = await readPkgUp(func.mainFile)
115
+ const packageJson = await readPackageUp(func.mainFile)
116
116
  const hasTypeModule = packageJson && packageJson.packageJson.type === 'module'
117
117
 
118
118
  // We must use esbuild for certain file extensions.
@@ -1,5 +1,4 @@
1
1
  // @ts-check
2
- import { get } from 'dot-prop'
3
2
  import jwtDecode from 'jwt-decode'
4
3
 
5
4
  import { NETLIFYDEVERR, NETLIFYDEVLOG, error as errorExit, log } from '../../utils/command-helpers.mjs'
@@ -94,7 +93,7 @@ export const createHandler = function (options) {
94
93
  {},
95
94
  )
96
95
  const rawQuery = new URLSearchParams(request.query).toString()
97
- const protocol = get(options, 'config.dev.https') ? 'https' : 'http'
96
+ const protocol = options.config?.dev?.https ? 'https' : 'http'
98
97
  const url = new URL(requestPath, `${protocol}://${request.get('host') || 'localhost'}`)
99
98
  url.search = rawQuery
100
99
  const rawUrl = url.toString()
@@ -1,12 +1,12 @@
1
1
  // @ts-check
2
2
  import { chalk, warn } from '../../utils/command-helpers.mjs'
3
- import { getLogMessage } from '../log.mjs'
3
+ import { MISSING_AWS_SDK_WARNING } from '../log.mjs'
4
4
 
5
5
  export const detectAwsSdkError = ({ error }) => {
6
6
  const isAwsSdkError = error && error.errorMessage && error.errorMessage.includes("Cannot find module 'aws-sdk'")
7
7
 
8
8
  if (isAwsSdkError) {
9
- warn(getLogMessage('functions.missingAwsSdk'))
9
+ warn(MISSING_AWS_SDK_WARNING)
10
10
  }
11
11
  }
12
12
 
package/src/lib/log.mjs CHANGED
@@ -1,27 +1,18 @@
1
- import dotProp from 'dot-prop'
2
-
3
1
  import { chalk } from '../utils/command-helpers.mjs'
4
2
 
5
3
  const RED_BACKGROUND = chalk.red('-background')
6
4
  const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
7
- const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
5
+ export const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
8
6
  Your team’s current plan doesn’t support Background Functions, which have names ending in \`${RED_BACKGROUND}\`.
9
7
  To be able to deploy this function successfully either:
10
8
  - change the function name to remove \`${RED_BACKGROUND}\` and execute it synchronously
11
9
  - upgrade your team plan to a level that supports Background Functions (${PRO}, ${BUSINESS}, or ${ENTERPRISE})
12
10
  `
13
- const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow('aws-sdk')}.
11
+ export const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow(
12
+ 'aws-sdk',
13
+ )}.
14
14
  You should add this module to the project's dependencies, using your package manager of choice:
15
15
 
16
16
  ${chalk.yellow('npm install aws-sdk --save')} or ${chalk.yellow('yarn add aws-sdk')}
17
17
 
18
18
  For more information, see https://ntl.fyi/cli-aws-sdk.`
19
-
20
- const messages = {
21
- functions: {
22
- backgroundNotSupported: BACKGROUND_FUNCTIONS_WARNING,
23
- missingAwsSdk: MISSING_AWS_SDK_WARNING,
24
- },
25
- }
26
-
27
- export const getLogMessage = (key) => dotProp.get(messages, key, 'Missing Log Message Key')
package/src/utils/dev.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  // @ts-check
2
2
  import process from 'process'
3
3
 
4
- import { get } from 'dot-prop'
5
4
  import getPort from 'get-port'
6
5
  import isEmpty from 'lodash/isEmpty.js'
7
6
 
@@ -112,7 +111,7 @@ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => {
112
111
  backgroundFunctions: supportsBackgroundFunctions(account),
113
112
  },
114
113
  timeouts: {
115
- syncFunctions: get(siteInfo, 'functions_config.timeout', SYNCHRONOUS_FUNCTION_TIMEOUT),
114
+ syncFunctions: siteInfo.functions_config?.timeout ?? SYNCHRONOUS_FUNCTION_TIMEOUT,
116
115
  backgroundFunctions: BACKGROUND_FUNCTION_TIMEOUT,
117
116
  },
118
117
  }
@@ -0,0 +1,16 @@
1
+ import { error } from './command-helpers.mjs'
2
+
3
+ export const getSiteByName = async (api, siteName) => {
4
+ try {
5
+ const sites = await api.listSites({ name: siteName, filter: 'all' })
6
+ const siteFoundByName = sites.find((filteredSite) => filteredSite.name === siteName)
7
+
8
+ if (!siteFoundByName) {
9
+ throw Error
10
+ }
11
+
12
+ return siteFoundByName
13
+ } catch {
14
+ error('Site not found. Please rerun "netlify link"')
15
+ }
16
+ }
@@ -0,0 +1,29 @@
1
+ import { error, warn } from '../command-helpers.mjs'
2
+ /**
3
+ * A preAction hook that errors out if siteInfo is an empty object
4
+ * @param {*} command
5
+ */
6
+ const requiresSiteInfo = async (command) => {
7
+ const { api, site } = command.netlify
8
+ const siteId = site.id
9
+ if (!siteId) {
10
+ warn('Did you run `netlify link` yet?')
11
+ return error(`You don't appear to be in a folder that is linked to a site`)
12
+ }
13
+ try {
14
+ await api.getSite({ siteId })
15
+ } catch (error_) {
16
+ // unauthorized
17
+ if (error_.status === 401) {
18
+ warn(`Log in with a different account or re-link to a site you have permission for`)
19
+ return error(`Not authorized to view the currently linked site (${siteId})`)
20
+ }
21
+ // missing
22
+ if (error_.status === 404) {
23
+ return error(`The site this folder is linked to can't be found`)
24
+ }
25
+ return error(error_)
26
+ }
27
+ }
28
+
29
+ export default requiresSiteInfo
@@ -11,7 +11,7 @@ import zlib from 'zlib'
11
11
 
12
12
  import contentType from 'content-type'
13
13
  import cookie from 'cookie'
14
- import { get } from 'dot-prop'
14
+ import { getProperty } from 'dot-prop'
15
15
  import generateETag from 'etag'
16
16
  import getAvailablePort from 'get-port'
17
17
  import httpProxy from 'http-proxy'
@@ -210,7 +210,7 @@ const serveRedirect = async function ({ env, match, options, proxy, req, res, si
210
210
  if ((jwtValue.exp || 0) < Math.round(Date.now() / MILLISEC_TO_SEC)) {
211
211
  console.warn(NETLIFYDEVWARN, 'Expired JWT provided in request', req.url)
212
212
  } else {
213
- const presentedRoles = get(jwtValue, options.jwtRolePath) || []
213
+ const presentedRoles = getProperty(jwtValue, options.jwtRolePath) || []
214
214
  if (!Array.isArray(presentedRoles)) {
215
215
  console.warn(NETLIFYDEVWARN, `Invalid roles value provided in JWT ${options.jwtRolePath}`, presentedRoles)
216
216
  res.writeHead(400)
@@ -2,7 +2,7 @@ import fs from 'fs'
2
2
  import path from 'path'
3
3
  import process from 'process'
4
4
 
5
- import dotProp from 'dot-prop'
5
+ import { deleteProperty, getProperty, hasProperty, setProperty } from 'dot-prop'
6
6
  import { findUpSync } from 'find-up'
7
7
  import writeFileAtomic from 'write-file-atomic'
8
8
 
@@ -75,7 +75,7 @@ export default class StateConfig {
75
75
  // TODO figure out cleaner way of grabbing ENV vars
76
76
  return process.env.NETLIFY_SITE_ID
77
77
  }
78
- return dotProp.get(this.all, key)
78
+ return getProperty(this.all, key)
79
79
  }
80
80
 
81
81
  set(...args) {
@@ -84,22 +84,22 @@ export default class StateConfig {
84
84
 
85
85
  if (args.length === 1) {
86
86
  Object.entries(key).forEach(([keyPart, value]) => {
87
- dotProp.set(config, keyPart, value)
87
+ setProperty(config, keyPart, value)
88
88
  })
89
89
  } else {
90
- dotProp.set(config, key, val)
90
+ setProperty(config, key, val)
91
91
  }
92
92
 
93
93
  this.all = config
94
94
  }
95
95
 
96
96
  has(key) {
97
- return dotProp.has(this.all, key)
97
+ return hasProperty(this.all, key)
98
98
  }
99
99
 
100
100
  delete(key) {
101
101
  const config = this.all
102
- dotProp.delete(config, key)
102
+ deleteProperty(config, key)
103
103
  this.all = config
104
104
  }
105
105