Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency dot-prop to v7 #5737

Merged
merged 5 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 50 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"cron-parser": "4.8.1",
"debug": "4.3.4",
"decache": "4.6.1",
"dot-prop": "6.0.1",
"dot-prop": "7.2.0",
"dotenv": "16.0.3",
"env-paths": "3.0.0",
"envinfo": "7.8.1",
Expand Down
27 changes: 12 additions & 15 deletions src/commands/deploy/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { cwd, env } from 'process'
import { runCoreSteps } from '@netlify/build'
import { restoreConfig, updateConfig } from '@netlify/config'
import { Option } from 'commander'
import { get } from 'dot-prop'
import inquirer from 'inquirer'
import isObject from 'lodash/isObject.js'
import prettyjson from 'prettyjson'
Expand All @@ -15,7 +14,7 @@ import { cancelDeploy } from '../../lib/api.mjs'
import { getBuildOptions, runBuild } from '../../lib/build.mjs'
import { featureFlags as edgeFunctionsFeatureFlags } from '../../lib/edge-functions/consts.mjs'
import { normalizeFunctionsConfig } from '../../lib/functions/config.mjs'
import { getLogMessage } from '../../lib/log.mjs'
import { BACKGROUND_FUNCTIONS_WARNING } from '../../lib/log.mjs'
import { startSpinner, stopSpinner } from '../../lib/spinner.mjs'
import {
chalk,
Expand Down Expand Up @@ -74,10 +73,10 @@ const getDeployFolder = async ({ config, options, site, siteData }) => {
let deployFolder
if (options.dir) {
deployFolder = resolve(cwd(), options.dir)
} else if (get(config, 'build.publish')) {
deployFolder = resolve(site.root, get(config, 'build.publish'))
} else if (get(siteData, 'build_settings.dir')) {
deployFolder = resolve(site.root, get(siteData, 'build_settings.dir'))
} else if (config?.build?.publish) {
deployFolder = resolve(site.root, config.build.publish)
} else if (siteData?.build_settings?.dir) {
deployFolder = resolve(site.root, siteData.build_settings.dir)
}

if (!deployFolder) {
Expand Down Expand Up @@ -138,8 +137,8 @@ const getFunctionsFolder = ({ config, options, site, siteData }) => {
functionsFolder = resolve(cwd(), options.functions)
} else if (funcConfig) {
functionsFolder = resolve(site.root, funcConfig)
} else if (get(siteData, 'build_settings.functions_dir')) {
functionsFolder = resolve(site.root, get(siteData, 'build_settings.functions_dir'))
} else if (siteData?.build_settings?.functions_dir) {
functionsFolder = resolve(site.root, siteData.build_settings.functions_dir)
}
return functionsFolder
}
Expand Down Expand Up @@ -232,14 +231,12 @@ const hasErrorMessage = (actual, expected) => {
return false
}

const getJsonErrorMessage = (error_) => get(error_, 'json.message', '')

const reportDeployError = ({ error_, failAndExit }) => {
switch (true) {
case error_.name === 'JSONHTTPError': {
const message = getJsonErrorMessage(error)
const message = error_?.json?.message ?? ''
if (hasErrorMessage(message, 'Background Functions not allowed by team plan')) {
return failAndExit(`\n${getLogMessage('functions.backgroundNotSupported')}`)
return failAndExit(`\n${BACKGROUND_FUNCTIONS_WARNING}`)
}
warn(`JSONHTTPError: ${message} ${error_.status}`)
warn(`\n${JSON.stringify(error_, null, ' ')}\n`)
Expand Down Expand Up @@ -358,8 +355,8 @@ const runDeploy = async ({
}

const siteUrl = results.deploy.ssl_url || results.deploy.url
const deployUrl = get(results, 'deploy.deploy_ssl_url') || get(results, 'deploy.deploy_url')
const logsUrl = `${get(results, 'deploy.admin_url')}/deploys/${get(results, 'deploy.id')}`
const deployUrl = results.deploy.deploy_ssl_url || results.deploy.deploy_url
const logsUrl = `${results.deploy.admin_url}/deploys/${results.deploy.id}`

return {
siteId: results.deploy.site_id,
Expand Down Expand Up @@ -616,7 +613,7 @@ const deploy = async (options, command) => {
scope: 'functions',
siteInfo: siteData,
})
: get(siteData, 'build_settings.env')
: siteData?.build_settings?.env

const functionsConfig = normalizeFunctionsConfig({
functionsConfig: config.functions,
Expand Down
11 changes: 7 additions & 4 deletions src/commands/init/init.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
import { Option } from 'commander'
import dotProp from 'dot-prop'
import inquirer from 'inquirer'
import isEmpty from 'lodash/isEmpty.js'

Expand All @@ -17,7 +16,11 @@ const persistState = ({ siteInfo, state }) => {
state.set('siteId', siteInfo.id)
}

const getRepoUrl = ({ siteInfo }) => dotProp.get(siteInfo, 'build_settings.repo_url')
/**
* @param {{} | undefined} siteInfo
* @returns {string | undefined}
*/
const getRepoUrl = (siteInfo) => siteInfo?.build_settings?.repo_url

const logExistingAndExit = ({ siteInfo }) => {
log()
Expand Down Expand Up @@ -187,7 +190,7 @@ export const init = async (options, command) => {
// Add .netlify to .gitignore file
await ensureNetlifyIgnore(repositoryRoot)

const repoUrl = getRepoUrl({ siteInfo })
const repoUrl = getRepoUrl(siteInfo)
if (repoUrl && !options.force) {
logExistingAndExit({ siteInfo })
}
Expand All @@ -205,7 +208,7 @@ export const init = async (options, command) => {
log()

// Check for existing CI setup
const remoteBuildRepo = getRepoUrl({ siteInfo })
const remoteBuildRepo = getRepoUrl(siteInfo)
if (remoteBuildRepo && !options.force) {
logExistingRepoSetupAndExit({ siteName: siteInfo.name, repoUrl: remoteBuildRepo })
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/status/status-hooks.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-check
import { get } from 'dot-prop'
import prettyjson from 'prettyjson'

import { error, log, warn } from '../../utils/command-helpers.mjs'
Expand Down Expand Up @@ -48,8 +47,8 @@ const statusHooks = async (options, command) => {
id: hook.id,
disabled: hook.disabled,
}
if (get(siteData, 'build_settings.repo_url')) {
data.hooks[hook.id].repo_url = get(siteData, 'build_settings.repo_url')
if (siteData.build_settings?.repo_url) {
data.hooks[hook.id].repo_url = siteData.build_settings.repo_url
}
})
log(`─────────────────┐
Expand Down
4 changes: 2 additions & 2 deletions src/lib/functions/registry.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
watchDebounced,
} from '../../utils/command-helpers.mjs'
import { INTERNAL_FUNCTIONS_FOLDER, SERVE_FUNCTIONS_FOLDER } from '../../utils/functions/functions.mjs'
import { getLogMessage } from '../log.mjs'
import { BACKGROUND_FUNCTIONS_WARNING } from '../log.mjs'
import { getPathInProject } from '../settings.mjs'

import NetlifyFunction from './netlify-function.mjs'
Expand Down Expand Up @@ -140,7 +140,7 @@ export class FunctionsRegistry {
}

if (func.isBackground && this.isConnected && !this.capabilities.backgroundFunctions) {
warn(getLogMessage('functions.backgroundNotSupported'))
warn(BACKGROUND_FUNCTIONS_WARNING)
}

if (!func.hasValidName()) {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/functions/server.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-check
import { get } from 'dot-prop'
import jwtDecode from 'jwt-decode'

import { NETLIFYDEVERR, NETLIFYDEVLOG, error as errorExit, log } from '../../utils/command-helpers.mjs'
Expand Down Expand Up @@ -94,7 +93,7 @@ export const createHandler = function (options) {
{},
)
const rawQuery = new URLSearchParams(request.query).toString()
const protocol = get(options, 'config.dev.https') ? 'https' : 'http'
const protocol = options.config?.dev?.https ? 'https' : 'http'
const url = new URL(requestPath, `${protocol}://${request.get('host') || 'localhost'}`)
url.search = rawQuery
const rawUrl = url.toString()
Expand Down
4 changes: 2 additions & 2 deletions src/lib/functions/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @ts-check
import { chalk, warn } from '../../utils/command-helpers.mjs'
import { getLogMessage } from '../log.mjs'
import { MISSING_AWS_SDK_WARNING } from '../log.mjs'

export const detectAwsSdkError = ({ error }) => {
const isAwsSdkError = error && error.errorMessage && error.errorMessage.includes("Cannot find module 'aws-sdk'")

if (isAwsSdkError) {
warn(getLogMessage('functions.missingAwsSdk'))
warn(MISSING_AWS_SDK_WARNING)
}
}

Expand Down
17 changes: 4 additions & 13 deletions src/lib/log.mjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
import dotProp from 'dot-prop'

import { chalk } from '../utils/command-helpers.mjs'

const RED_BACKGROUND = chalk.red('-background')
const [PRO, BUSINESS, ENTERPRISE] = ['Pro', 'Business', 'Enterprise'].map((plan) => chalk.magenta(plan))
const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
export const BACKGROUND_FUNCTIONS_WARNING = `A serverless function ending in \`${RED_BACKGROUND}\` was detected.
Your team’s current plan doesn’t support Background Functions, which have names ending in \`${RED_BACKGROUND}\`.
To be able to deploy this function successfully either:
- change the function name to remove \`${RED_BACKGROUND}\` and execute it synchronously
- upgrade your team plan to a level that supports Background Functions (${PRO}, ${BUSINESS}, or ${ENTERPRISE})
`
const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow('aws-sdk')}.
export const MISSING_AWS_SDK_WARNING = `A function has thrown an error due to a missing dependency: ${chalk.yellow(
'aws-sdk',
)}.
You should add this module to the project's dependencies, using your package manager of choice:

${chalk.yellow('npm install aws-sdk --save')} or ${chalk.yellow('yarn add aws-sdk')}

For more information, see https://ntl.fyi/cli-aws-sdk.`

const messages = {
functions: {
backgroundNotSupported: BACKGROUND_FUNCTIONS_WARNING,
missingAwsSdk: MISSING_AWS_SDK_WARNING,
},
}

export const getLogMessage = (key) => dotProp.get(messages, key, 'Missing Log Message Key')
Loading