From 82abf15fdfdd106917be051188959fece953d750 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 19:18:56 +0000 Subject: [PATCH] fix(deps): update dependency dot-prop to v7 (#5737) * fix(deps): update dependency dot-prop to v8 * Revert "fix(deps): update dependency dot-prop to v8" This reverts commit 81afc516aa6e1227c3d31e8ba48ba4918d7111b2. * fix(deps): update dependency dot-prop to v7 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Daniel Tschinder <231804+danez@users.noreply.github.com> --- package-lock.json | 98 +++++++++++----------- package.json | 2 +- src/commands/deploy/deploy.mjs | 27 +++--- src/commands/init/init.mjs | 11 ++- src/commands/status/status-hooks.mjs | 5 +- src/lib/functions/registry.mjs | 4 +- src/lib/functions/server.mjs | 3 +- src/lib/functions/utils.mjs | 4 +- src/lib/log.mjs | 17 +--- src/utils/dev.mjs | 3 +- src/utils/proxy.mjs | 4 +- src/utils/state-config.mjs | 12 +-- tests/integration/100.command.dev.test.cjs | 10 +-- 13 files changed, 95 insertions(+), 105 deletions(-) diff --git a/package-lock.json b/package-lock.json index 04bce6a91f7..8e4b93ae4aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,7 +42,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", @@ -2731,20 +2731,6 @@ "node": "^14.16.0 || >=16.0.0" } }, - "node_modules/@netlify/config/node_modules/dot-prop": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-7.2.0.tgz", - "integrity": "sha512-Ol/IPXUARn9CSbkrdV4VJo7uCy1I3VuSiWCaFSg+8BdUOzF9n3jefIpcgAydvUZbTdEBZs2vEiTiS9m61ssiDA==", - "dependencies": { - "type-fest": "^2.11.2" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@netlify/config/node_modules/escape-string-regexp": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", @@ -2912,17 +2898,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/@netlify/config/node_modules/type-fest": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", - "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@netlify/config/node_modules/yocto-queue": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", @@ -8114,6 +8089,20 @@ "url": "https://github.com/yeoman/configstore?sponsor=1" } }, + "node_modules/configstore/node_modules/dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "dependencies": { + "is-obj": "^2.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/configstore/node_modules/write-file-atomic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -9495,14 +9484,25 @@ } }, "node_modules/dot-prop": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", - "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-7.2.0.tgz", + "integrity": "sha512-Ol/IPXUARn9CSbkrdV4VJo7uCy1I3VuSiWCaFSg+8BdUOzF9n3jefIpcgAydvUZbTdEBZs2vEiTiS9m61ssiDA==", "dependencies": { - "is-obj": "^2.0.0" + "type-fest": "^2.11.2" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/dot-prop/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "engines": { + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -24380,14 +24380,6 @@ "yargs": "^17.6.0" }, "dependencies": { - "dot-prop": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-7.2.0.tgz", - "integrity": "sha512-Ol/IPXUARn9CSbkrdV4VJo7uCy1I3VuSiWCaFSg+8BdUOzF9n3jefIpcgAydvUZbTdEBZs2vEiTiS9m61ssiDA==", - "requires": { - "type-fest": "^2.11.2" - } - }, "escape-string-regexp": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz", @@ -24480,11 +24472,6 @@ "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-3.0.0.tgz", "integrity": "sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==" }, - "type-fest": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", - "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==" - }, "yocto-queue": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", @@ -28157,6 +28144,14 @@ "xdg-basedir": "^5.0.1" }, "dependencies": { + "dot-prop": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", + "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "requires": { + "is-obj": "^2.0.0" + } + }, "write-file-atomic": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-3.0.3.tgz", @@ -29176,11 +29171,18 @@ } }, "dot-prop": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", - "integrity": "sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-7.2.0.tgz", + "integrity": "sha512-Ol/IPXUARn9CSbkrdV4VJo7uCy1I3VuSiWCaFSg+8BdUOzF9n3jefIpcgAydvUZbTdEBZs2vEiTiS9m61ssiDA==", "requires": { - "is-obj": "^2.0.0" + "type-fest": "^2.11.2" + }, + "dependencies": { + "type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==" + } } }, "dotenv": { diff --git a/package.json b/package.json index f8e00ae0e92..2ccfd940c97 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/commands/deploy/deploy.mjs b/src/commands/deploy/deploy.mjs index 479af31a807..275ac2265e5 100644 --- a/src/commands/deploy/deploy.mjs +++ b/src/commands/deploy/deploy.mjs @@ -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' @@ -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, @@ -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) { @@ -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 } @@ -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`) @@ -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, @@ -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, diff --git a/src/commands/init/init.mjs b/src/commands/init/init.mjs index 75af4d00b6e..18a3f2b30f7 100644 --- a/src/commands/init/init.mjs +++ b/src/commands/init/init.mjs @@ -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' @@ -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() @@ -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 }) } @@ -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 }) } diff --git a/src/commands/status/status-hooks.mjs b/src/commands/status/status-hooks.mjs index 58acd9961f3..43776a30af8 100644 --- a/src/commands/status/status-hooks.mjs +++ b/src/commands/status/status-hooks.mjs @@ -1,5 +1,4 @@ // @ts-check -import { get } from 'dot-prop' import prettyjson from 'prettyjson' import { error, log, warn } from '../../utils/command-helpers.mjs' @@ -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(`─────────────────┐ diff --git a/src/lib/functions/registry.mjs b/src/lib/functions/registry.mjs index ff8e5772b7f..a206ff2699e 100644 --- a/src/lib/functions/registry.mjs +++ b/src/lib/functions/registry.mjs @@ -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' @@ -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()) { diff --git a/src/lib/functions/server.mjs b/src/lib/functions/server.mjs index df8281303a6..2840d9fd114 100644 --- a/src/lib/functions/server.mjs +++ b/src/lib/functions/server.mjs @@ -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' @@ -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() diff --git a/src/lib/functions/utils.mjs b/src/lib/functions/utils.mjs index 974abfd1cb9..bc66ae149af 100644 --- a/src/lib/functions/utils.mjs +++ b/src/lib/functions/utils.mjs @@ -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) } } diff --git a/src/lib/log.mjs b/src/lib/log.mjs index 6ab741e9df0..7a390027870 100644 --- a/src/lib/log.mjs +++ b/src/lib/log.mjs @@ -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') diff --git a/src/utils/dev.mjs b/src/utils/dev.mjs index d263bc2deea..af18351c4a3 100644 --- a/src/utils/dev.mjs +++ b/src/utils/dev.mjs @@ -1,7 +1,6 @@ // @ts-check import process from 'process' -import { get } from 'dot-prop' import getPort from 'get-port' import isEmpty from 'lodash/isEmpty.js' @@ -112,7 +111,7 @@ export const getSiteInformation = async ({ api, offline, site, siteInfo }) => { backgroundFunctions: supportsBackgroundFunctions(account), }, timeouts: { - syncFunctions: get(siteInfo, 'functions_config.timeout', SYNCHRONOUS_FUNCTION_TIMEOUT), + syncFunctions: siteInfo.functions_config?.timeout ?? SYNCHRONOUS_FUNCTION_TIMEOUT, backgroundFunctions: BACKGROUND_FUNCTION_TIMEOUT, }, } diff --git a/src/utils/proxy.mjs b/src/utils/proxy.mjs index 1e386f1e9c6..0f093fb0a2f 100644 --- a/src/utils/proxy.mjs +++ b/src/utils/proxy.mjs @@ -11,7 +11,7 @@ import zlib from 'zlib' import contentType from 'content-type' import cookie from 'cookie' -import { get } from 'dot-prop' +import { getProperty } from 'dot-prop' import generateETag from 'etag' import getAvailablePort from 'get-port' import httpProxy from 'http-proxy' @@ -210,7 +210,7 @@ const serveRedirect = async function ({ env, match, options, proxy, req, res, si if ((jwtValue.exp || 0) < Math.round(Date.now() / MILLISEC_TO_SEC)) { console.warn(NETLIFYDEVWARN, 'Expired JWT provided in request', req.url) } else { - const presentedRoles = get(jwtValue, options.jwtRolePath) || [] + const presentedRoles = getProperty(jwtValue, options.jwtRolePath) || [] if (!Array.isArray(presentedRoles)) { console.warn(NETLIFYDEVWARN, `Invalid roles value provided in JWT ${options.jwtRolePath}`, presentedRoles) res.writeHead(400) diff --git a/src/utils/state-config.mjs b/src/utils/state-config.mjs index 8a8d049b705..3053e780268 100644 --- a/src/utils/state-config.mjs +++ b/src/utils/state-config.mjs @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import process from 'process' -import dotProp from 'dot-prop' +import { deleteProperty, getProperty, hasProperty, setProperty } from 'dot-prop' import { findUpSync } from 'find-up' import writeFileAtomic from 'write-file-atomic' @@ -75,7 +75,7 @@ export default class StateConfig { // TODO figure out cleaner way of grabbing ENV vars return process.env.NETLIFY_SITE_ID } - return dotProp.get(this.all, key) + return getProperty(this.all, key) } set(...args) { @@ -84,22 +84,22 @@ export default class StateConfig { if (args.length === 1) { Object.entries(key).forEach(([keyPart, value]) => { - dotProp.set(config, keyPart, value) + setProperty(config, keyPart, value) }) } else { - dotProp.set(config, key, val) + setProperty(config, key, val) } this.all = config } has(key) { - return dotProp.has(this.all, key) + return hasProperty(this.all, key) } delete(key) { const config = this.all - dotProp.delete(config, key) + deleteProperty(config, key) this.all = config } diff --git a/tests/integration/100.command.dev.test.cjs b/tests/integration/100.command.dev.test.cjs index ea6384ec92d..f70e5873415 100644 --- a/tests/integration/100.command.dev.test.cjs +++ b/tests/integration/100.command.dev.test.cjs @@ -3,7 +3,6 @@ const path = require('path') // eslint-disable-next-line ava/use-test const avaTest = require('ava') const { isCI } = require('ci-info') -const dotProp = require('dot-prop') const getAvailablePort = require('get-port') const jwt = require('jsonwebtoken') const { Response } = require('node-fetch') @@ -17,12 +16,13 @@ const { withSiteBuilder } = require('./utils/site-builder.cjs') const test = isCI ? avaTest.serial.bind(avaTest) : avaTest const JWT_EXPIRY = 1_893_456_000 -const getToken = ({ jwtRolePath = 'app_metadata.authorization.roles', jwtSecret = 'secret', roles }) => { +const getToken = async ({ jwtRolePath = 'app_metadata.authorization.roles', jwtSecret = 'secret', roles }) => { + const { setProperty } = await import('dot-prop') const payload = { exp: JWT_EXPIRY, sub: '12345678', } - return jwt.sign(dotProp.set(payload, jwtRolePath, roles), jwtSecret) + return jwt.sign(setProperty(payload, jwtRolePath, roles), jwtSecret) } const setupRoleBasedRedirectsSite = (builder) => { @@ -44,8 +44,8 @@ const setupRoleBasedRedirectsSite = (builder) => { } const validateRoleBasedRedirectsSite = async ({ builder, jwtRolePath, jwtSecret, t }) => { - const adminToken = getToken({ jwtSecret, jwtRolePath, roles: ['admin'] }) - const editorToken = getToken({ jwtSecret, jwtRolePath, roles: ['editor'] }) + const adminToken = await getToken({ jwtSecret, jwtRolePath, roles: ['admin'] }) + const editorToken = await getToken({ jwtSecret, jwtRolePath, roles: ['editor'] }) await withDevServer({ cwd: builder.directory }, async (server) => { const unauthenticatedResponse = await got(`${server.url}/admin`, { throwHttpErrors: false })