Skip to content
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
3 changes: 0 additions & 3 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
101 changes: 50 additions & 51 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Awaited<ReturnType<NetlifyAPI['createSiteDeploy']>>, 'id'> & {
Expand Down Expand Up @@ -136,7 +136,7 @@ const getDeployFolder = async ({
config: DeployConfig
options: DeployOptionValues
site: DeploySite
siteData: DeploySiteData
siteData?: DeploySiteData
}): Promise<string> => {
let deployFolder: string | undefined
// if the `--dir .` flag is provided we should resolve it to the working directory.
Expand All @@ -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)
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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)
Expand All @@ -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<CreatedDeploy> => {
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)
Expand Down Expand Up @@ -565,7 +592,6 @@ const runDeploy = async ({
siteData,
siteId,
skipFunctionsCache,
title,
deployId: existingDeployId,
}: {
alias: string | undefined
Expand All @@ -585,7 +611,6 @@ const runDeploy = async ({
siteData: SiteInfo
siteId: string
skipFunctionsCache: boolean
title: string | undefined
}): Promise<{
siteId: string
siteName: string
Expand All @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1049,7 +1066,6 @@ const prepAndRunDeploy = async ({
siteData,
siteId,
skipFunctionsCache: options.skipFunctionsCache,
title: options.message,
deployId,
})

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1408,24 +1423,8 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand)
let results = {} as Awaited<ReturnType<typeof prepAndRunDeploy>>

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

Expand Down
Loading