Skip to content

Commit

Permalink
fix: use heuristics for build and deploy command as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasholzer committed Jul 10, 2024
1 parent f830a87 commit 0265b47
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/commands/build/build.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OptionValues } from 'commander'

import { getBuildOptions, runBuild } from '../../lib/build.js'
import { detectFrameworkSettings } from '../../utils/build-info.js'
import { detectFrameworkSettings, getDefaultConfig } from '../../utils/build-info.js'
import { error, exit, getToken } from '../../utils/command-helpers.js'
import { getEnvelopeEnv } from '../../utils/env/index.js'
import BaseCommand from '../base-command.js'
Expand Down Expand Up @@ -31,14 +31,9 @@ export const build = async (options: OptionValues, command: BaseCommand) => {
const [token] = await getToken()
const settings = await detectFrameworkSettings(command, 'build')

// override the build command with the detection result if no command is specified through the config
if (!cachedConfig.config.build.command) {
cachedConfig.config.build.command = settings?.buildCommand
cachedConfig.config.build.commandOrigin = 'heuristics'
}

const buildOptions = await getBuildOptions({
cachedConfig,
defaultConfig: getDefaultConfig(settings),
packagePath: command.workspacePackage,
currentDir: command.workingDir,
token,
Expand Down
6 changes: 5 additions & 1 deletion src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { featureFlags as edgeFunctionsFeatureFlags } from '../../lib/edge-functi
import { normalizeFunctionsConfig } from '../../lib/functions/config.js'
import { BACKGROUND_FUNCTIONS_WARNING } from '../../lib/log.js'
import { startSpinner, stopSpinner } from '../../lib/spinner.js'
import { detectFrameworkSettings, getDefaultConfig } from '../../utils/build-info.js'
import {
NETLIFYDEV,
NETLIFYDEVERR,
Expand Down Expand Up @@ -558,14 +559,15 @@ const runDeploy = async ({
* @returns
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'cachedConfig' implicitly has an '... Remove this comment to see the full error message
const handleBuild = async ({ cachedConfig, currentDir, deployHandler, options, packagePath }) => {
const handleBuild = async ({ cachedConfig, currentDir, defaultConfig, deployHandler, options, packagePath }) => {
if (!options.build) {
return {}
}
// @ts-expect-error TS(2554) FIXME: Expected 1 arguments, but got 0.
const [token] = await getToken()
const resolvedOptions = await getBuildOptions({
cachedConfig,
defaultConfig,
packagePath,
token,
options,
Expand Down Expand Up @@ -784,6 +786,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
const { workingDir } = command
const { api, site, siteInfo } = command.netlify
const alias = options.alias || options.branch
const settings = await detectFrameworkSettings(command, 'build')

command.setAnalyticsPayload({ open: options.open, prod: options.prod, json: options.json, alias: Boolean(alias) })

Expand Down Expand Up @@ -847,6 +850,7 @@ export const deploy = async (options: OptionValues, command: BaseCommand) => {
await handleBuild({
packagePath: command.workspacePackage,
cachedConfig: command.netlify.cachedConfig,
defaultConfig: getDefaultConfig(settings),
currentDir: command.workingDir,
options,
// @ts-expect-error TS(7031) FIXME: Binding element 'netlifyConfig' implicitly has an ... Remove this comment to see the full error message
Expand Down
3 changes: 3 additions & 0 deletions src/lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export const getBuildOptions = async ({
cachedConfig,
// @ts-expect-error TS(7031) FIXME: Binding element 'currentDir' implicitly has an 'an... Remove this comment to see the full error message
currentDir,
// @ts-expect-error TS(7031) FIXME: Binding element 'defaultConfig' implicitly has an '... Remove this comment to see the full error message
defaultConfig,
// @ts-expect-error TS(7031) FIXME: Binding element 'deployHandler' implicitly has an ... Remove this comment to see the full error message
deployHandler,
// @ts-expect-error TS(7031) FIXME: Binding element 'context' implicitly has an 'any' ... Remove this comment to see the full error message
Expand Down Expand Up @@ -71,6 +73,7 @@ export const getBuildOptions = async ({

return {
cachedConfig,
defaultConfig,
siteId: cachedConfig.siteInfo.id,
packagePath,
token,
Expand Down
31 changes: 31 additions & 0 deletions src/utils/build-info.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { NetlifyConfig } from '@netlify/build'
import { NetlifyPlugin } from '@netlify/build'
import { Settings } from '@netlify/build-info'
import { isCI } from 'ci-info'
import fuzzy from 'fuzzy'
import inquirer from 'inquirer'

import BaseCommand from '../commands/base-command.js'
import { $TSFixMe } from '../commands/types.js'

import { chalk, log } from './command-helpers.js'

Expand Down Expand Up @@ -122,3 +125,31 @@ command = "${chosenSettings.devCommand}"
return chosenSettings
}
}

/**
* Merges the settings from the heuristics with the cached config.
* Returns the updated cached config
* @param cachedConfig The cached config
* @param settings The settings from the heuristics
*/
export const getDefaultConfig = (settings?: Settings): NetlifyConfig | undefined => {
if (!settings) {
return undefined
}
const config = { build: {} } as NetlifyConfig

if (settings.buildCommand) {
config.build.command = settings.buildCommand
config.build.commandOrigin = 'default'

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 22.x)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / package-size

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 22.x)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / verify-docs

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, *)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, *)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 4/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 3/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (windows-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 2/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 22)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 18.14.0)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 1/4)

Property 'commandOrigin' does not exist on type 'Build'.

Check failure on line 143 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 20.12.2)

Property 'commandOrigin' does not exist on type 'Build'.
}

if (settings.dist) {
config.build.publish = settings.dist
config.build.publishOrigin = 'default'

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 22.x)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / package-size

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (ubuntu-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 22.x)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (macOS-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / verify-docs

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, *)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, *)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (ubuntu-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E (macOS-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 20.12.2, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 18.14.0, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (ubuntu-latest, 22, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 22, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (macOS-latest, 20.12.2, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 4/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 3/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Unit (windows-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 2/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 22)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 18.14.0)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / Integration (windows-latest, 20.12.2, 1/4)

Property 'publishOrigin' does not exist on type 'Build'.

Check failure on line 148 in src/utils/build-info.ts

View workflow job for this annotation

GitHub Actions / E2E Windows tests (windows-latest, 20.12.2)

Property 'publishOrigin' does not exist on type 'Build'.
}

// @ts-expect-error Types are off
config.plugins = settings.plugins_recommended.map((plugin) => ({ package: plugin }))

return config
}
4 changes: 3 additions & 1 deletion src/utils/deploy/deploy-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export const deploySite = async (
}

if (functionsWithNativeModules.length !== 0) {
const functionsWithNativeModulesMessage = functionsWithNativeModules.map(({ name }) => `- ${name}`).join('\n')
const functionsWithNativeModulesMessage = functionsWithNativeModules
.map(({ name }: { name: string }) => `- ${name}`)
.join('\n')
warn(`Modules with native dependencies\n
${functionsWithNativeModulesMessage}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/deploy/hash-fns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const hashFns = async (
statusCb: $TSFixMe
tmpDir: $TSFixMe
},
) => {
): Promise<$TSFixMe> => {
const {
assetType = 'function',
concurrentHash,
Expand Down Expand Up @@ -166,8 +166,8 @@ const hashFns = async (
priority,
runtime,
runtimeVersion,
trafficRules,
timeout,
trafficRules,
}) => ({
filepath: functionPath,
root: tmpDir,
Expand Down

0 comments on commit 0265b47

Please sign in to comment.