diff --git a/eslint-suppressions.json b/eslint-suppressions.json index a6cf561216c..856ead5a651 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -112,9 +112,6 @@ "@typescript-eslint/no-empty-function": { "count": 7 }, - "@typescript-eslint/no-unnecessary-condition": { - "count": 4 - }, "@typescript-eslint/prefer-nullish-coalescing": { "count": 9 }, diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 6558e96d908..fd4873d52fe 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -79,7 +79,7 @@ import { anyEdgeFunctionsDirectoryExists } from '../../lib/edge-functions/get-di type DeploySite = NetlifySite & { root: string } // FIXME(@netlify/api): `SiteInfo['build_settings']` is missing `functions_dir` -type DeploySiteData = { build_settings?: SiteInfo['build_settings'] & { functions_dir?: string } } | undefined +type DeploySiteData = { build_settings?: SiteInfo['build_settings'] & { functions_dir?: string } } // FIXME(@netlify/api): the `createSiteDeploy` types omit the source zip fields and make `id` optional type CreatedDeploy = Omit>, 'id'> & { @@ -136,7 +136,7 @@ const getDeployFolder = async ({ config: DeployConfig options: DeployOptionValues site: DeploySite - siteData: DeploySiteData + siteData?: DeploySiteData }): Promise => { let deployFolder: string | undefined // if the `--dir .` flag is provided we should resolve it to the working directory. @@ -146,7 +146,7 @@ const getDeployFolder = async ({ deployFolder = command.workspacePackage ? resolve(command.jsWorkspaceRoot || site.root, options.dir) : resolve(command.workingDir, options.dir) - } else if (config?.build?.publish) { + } 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) @@ -215,7 +215,7 @@ const getFunctionsFolder = ({ config: DeployConfig options: DeployOptionValues site: DeploySite - siteData: DeploySiteData + siteData?: DeploySiteData /** The process working directory where the build command is executed */ workingDir: string }): string | undefined => { @@ -386,12 +386,7 @@ const prepareProductionDeploy = async ({ options: DeployOptionValues command: BaseCommand }) => { - if ( - typeof siteData.published_deploy === 'object' && - // eslint-disable-next-line @typescript-eslint/prefer-optional-chain -- FIXME: a non-object `published_deploy` must not count as locked - siteData.published_deploy !== null && - siteData.published_deploy.locked - ) { + if (siteData.published_deploy?.locked) { log(`\n${NETLIFYDEVERR} Deployments are "locked" for production context of this project\n`) const overrideCommand = generateDeployCommand({ ...options, prodIfUnlocked: true, prod: false }, [], command) @@ -417,6 +412,38 @@ const prepareProductionDeploy = async ({ } } +const createDeploy = async ({ + alias, + api, + command, + deployToProduction, + options, + siteData, + siteId, +}: { + alias: string | undefined + api: NetlifyAPI + command: BaseCommand + deployToProduction: boolean + options: DeployOptionValues + siteData: SiteInfo + siteId: string +}): Promise => { + if (deployToProduction) { + await prepareProductionDeploy({ siteData, api, options, command }) + } + + const draft = options.draft || (!deployToProduction && !alias) + const createDeployBody = { + draft, + branch: alias, + include_upload_url: options.uploadSourceZip, + ...getDeploySourceFields(), + } + + return (await api.createSiteDeploy({ siteId, title: options.message, body: createDeployBody })) as CreatedDeploy +} + const hasErrorMessage = (actual: unknown, expected: string): boolean => { if (typeof actual === 'string') { return actual.includes(expected) @@ -565,7 +592,6 @@ const runDeploy = async ({ siteData, siteId, skipFunctionsCache, - title, deployId: existingDeployId, }: { alias: string | undefined @@ -585,7 +611,6 @@ const runDeploy = async ({ siteData: SiteInfo siteId: string skipFunctionsCache: boolean - title: string | undefined }): Promise<{ siteId: string siteName: string @@ -605,23 +630,15 @@ const runDeploy = async ({ // We won't have a deploy ID if we run the command with `--no-build`. // In this case, we must create the deploy. if (!deployId) { - if (deployToProduction) { - await prepareProductionDeploy({ siteData, api, options, command }) - } - - const draft = options.draft || (!deployToProduction && !alias) - const createDeployBody = { - draft, - branch: alias, - include_upload_url: options.uploadSourceZip, - ...getDeploySourceFields(), - } - - const createDeployResponse = (await api.createSiteDeploy({ + const createDeployResponse = await createDeploy({ + alias, + api, + command, + deployToProduction, + options, + siteData, siteId, - title, - body: createDeployBody, - })) as CreatedDeploy + }) deployId = createDeployResponse.id if ( @@ -698,7 +715,7 @@ const runDeploy = async ({ workingDir: command.workingDir, manifestPath: manifestPath ?? undefined, packagePath, - serverEnabled: Boolean(siteData?.feature_flags?.netlify_build_server_standalone), + serverEnabled: Boolean(siteData.feature_flags?.netlify_build_server_standalone), serverManifestPath: serverManifestPath ?? undefined, skipFunctionsCache, siteRoot: site.root, @@ -1049,7 +1066,6 @@ const prepAndRunDeploy = async ({ siteData, siteId, skipFunctionsCache: options.skipFunctionsCache, - title: options.message, deployId, }) @@ -1198,7 +1214,7 @@ const anonymousDeploy = async (options: DeployOptionValues, command: BaseCommand } const checkForFunctions = async () => { - const functionsFolder = getFunctionsFolder({ config, options, site, siteData: {}, workingDir }) + const functionsFolder = getFunctionsFolder({ config, options, site, workingDir }) const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root }) const frameworksFunctionsDir = command.netlify.frameworksAPIPaths.functions.path @@ -1238,10 +1254,9 @@ const anonymousDeploy = async (options: DeployOptionValues, command: BaseCommand const deployFolder = await getDeployFolder({ command, - config: command.netlify.config, + config, options, site, - siteData: {}, }) await validateDeployFolder(deployFolder) @@ -1408,24 +1423,8 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand) let results = {} as Awaited> if (options.build) { - if (deployToProduction) { - await prepareProductionDeploy({ siteData, api, options, command }) - } - - const draft = options.draft || (!deployToProduction && !alias) - const createDeployBody = { - draft, - branch: alias, - include_upload_url: options.uploadSourceZip, - ...getDeploySourceFields(), - } - - const deployMetadata = (await api.createSiteDeploy({ - siteId, - title: options.message, - body: createDeployBody, - })) as CreatedDeploy - const deployId = deployMetadata.id || '' + const deployMetadata = await createDeploy({ alias, api, command, deployToProduction, options, siteData, siteId }) + const deployId = deployMetadata.id const skewProtectionToken = deployMetadata.skew_protection_token let sourceZipFileName: string | undefined