Skip to content

Commit

Permalink
refactor: some cleanup now that we're always starting the functions s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
Skn0tt committed Dec 7, 2023
1 parent 8127e3e commit e80ae3c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
12 changes: 7 additions & 5 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ const runDeploy = async ({
deployToProduction,
// @ts-expect-error TS(7031) FIXME: Binding element 'functionsConfig' implicitly has a... Remove this comment to see the full error message
functionsConfig,
// @ts-expect-error TS(7031) FIXME: Binding element 'functionsFolder' implicitly has a... Remove this comment to see the full error message
functionsFolder,
// @ts-expect-error TS(7031) FIXME: Binding element 'options' implicitly has an 'a... Remove this comment to see the full error message
options,
Expand All @@ -429,6 +428,8 @@ const runDeploy = async ({
skipFunctionsCache,
// @ts-expect-error TS(7031) FIXME: Binding element 'title' implicitly has an 'any' ty... Remove this comment to see the full error message
title,
}: {
functionsFolder?: string
}) => {
let results
let deployId
Expand All @@ -444,13 +445,14 @@ const runDeploy = async ({
results = await api.createSiteDeploy({ siteId, title, body: { draft, branch: alias } })
deployId = results.id

// @ts-expect-error TS(2345) FIXME: Argument of type '{ base: any; packagePath: any; }... Remove this comment to see the full error message
const internalFunctionsFolder = await getInternalFunctionsDir({ base: site.root, packagePath })

// The order of the directories matter: zip-it-and-ship-it will prioritize
// functions from the rightmost directories. In this case, we want user
// functions to take precedence over internal functions.
const functionDirectories = [internalFunctionsFolder, functionsFolder].filter(Boolean)
const functionDirectories = [internalFunctionsFolder, functionsFolder].filter((folder): folder is string =>
Boolean(folder),
)
const manifestPath = skipFunctionsCache ? null : await getFunctionsManifestPath({ base: site.root, packagePath })

const redirectsPath = `${deployFolder}/_redirects`
Expand All @@ -475,11 +477,10 @@ const runDeploy = async ({
uploadDeployBlobs({ deployId, siteId, silent, options, cachedConfig: command.netlify.cachedConfig })

results = await deploySite(api, siteId, deployFolder, {
// @ts-expect-error FIXME
config,
// @ts-expect-error TS(2322) FIXME: Type 'any[]' is not assignable to type 'never[]'.
fnDir: functionDirectories,
functionsConfig,
// @ts-expect-error TS(2322) FIXME: Type '(event: any) => void' is not assignable to t... Remove this comment to see the full error message
statusCb: silent ? () => {} : deployProgressCb(),
deployTimeout,
syncFileLimit: SYNC_FILE_LIMIT,
Expand Down Expand Up @@ -732,6 +733,7 @@ const prepAndRunDeploy = async ({
})

const results = await runDeploy({
// @ts-expect-error FIXME
alias,
api,
command,
Expand Down
3 changes: 1 addition & 2 deletions src/lib/functions/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,8 @@ export const startFunctionsServer = async (options) => {
siteUrl,
timeouts,
} = options
// @ts-expect-error TS(2345) FIXME: Argument of type '{ base: any; }' is not assignabl... Remove this comment to see the full error message
const internalFunctionsDir = await getInternalFunctionsDir({ base: site.root })
const functionsDirectories = []
const functionsDirectories: string[] = []
let manifest

// If the `loadDistFunctions` parameter is sent, the functions server will
Expand Down
16 changes: 10 additions & 6 deletions src/utils/deploy/deploy-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,18 @@ export const deploySite = async (
tmpDir = temporaryDirectory(),
// @ts-expect-error TS(2525) FIXME: Initializer provides no value for this binding ele... Remove this comment to see the full error message
workingDir,
}: {
concurrentHash?: number
concurrentUpload?: number
deployTimeout?: number
draft?: boolean
maxRetry?: number
statusCb?: (status: { type: string; msg: string; phase: string }) => void
syncFileLimit?: number
tmpDir?: string
fnDir?: string[]
} = {},
) => {
// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'hashing',
msg: `Hashing files...`,
Expand Down Expand Up @@ -115,7 +124,6 @@ export const deploySite = async (
edgeFunctionsCount > 0 && 'edge functions',
])

// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'hashing',
msg: `Finished hashing ${stats}`,
Expand All @@ -141,7 +149,6 @@ instead of manual deployment.
For more information, visit https://ntl.fyi/cli-native-modules.`)
}

// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'create-deploy',
msg: 'CDN diffing files...',
Expand All @@ -168,7 +175,6 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)

const { required: requiredFiles, required_functions: requiredFns } = deploy

// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'create-deploy',
msg: `CDN requesting ${requiredFiles.length} files${
Expand All @@ -183,15 +189,13 @@ For more information, visit https://ntl.fyi/cli-native-modules.`)

await uploadFiles(api, deployId, uploadList, { concurrentUpload, statusCb, maxRetry })

// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'wait-for-deploy',
msg: 'Waiting for deploy to go live...',
phase: 'start',
})
deploy = await waitForDeploy(api, deployId, siteId, deployTimeout)

// @ts-expect-error TS(2554) FIXME: Expected 0 arguments, but got 1.
statusCb({
type: 'wait-for-deploy',
msg: draft ? 'Draft deploy is live!' : 'Deploy is live!',
Expand Down
6 changes: 1 addition & 5 deletions src/utils/detect-server-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import getPort from 'get-port'
import { detectFrameworkSettings } from './build-info.js'
import { NETLIFYDEVWARN, chalk, log } from './command-helpers.js'
import { acquirePort } from './dev.js'
import { getInternalFunctionsDir } from './functions/functions.js'
import { getPluginsToAutoInstall } from './init/utils.js'

/** @param {string} str */
Expand Down Expand Up @@ -342,17 +341,14 @@ const detectServerSettings = async (devConfig, flags, command) => {
})
// @ts-expect-error TS(2339) FIXME: Property 'functions' does not exist on type '{}'.
const functionsDir = devConfig.functions || settings.functions
// @ts-expect-error TS(2345) FIXME: Argument of type '{ base: any; }' is not assignabl... Remove this comment to see the full error message
const internalFunctionsDir = await getInternalFunctionsDir({ base: command.workingDir })
const shouldStartFunctionsServer = Boolean(functionsDir || internalFunctionsDir)

return {
...settings,
port: acquiredPort,
jwtSecret: devConfig.jwtSecret || 'secret',
jwtRolePath: devConfig.jwtRolePath || 'app_metadata.authorization.roles',
functions: functionsDir,
...(shouldStartFunctionsServer && { functionsPort: await getPort({ port: devConfig.functionsPort || 0 }) }),
functionsPort: await getPort({ port: devConfig.functionsPort || 0 }),
...(devConfig.https && { https: await readHttpsSettings(devConfig.https) }),
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/utils/functions/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ export const getFunctionsServePath = ({ base, packagePath = '' }) => {

/**
* Retrieves the internal functions directory and creates it if ensureExists is provided
* @param {object} config
* @param {string} config.base
* @param {boolean=} config.ensureExists
* @param {string} config.packagePath
* @returns
*/
// @ts-expect-error TS(7031) FIXME: Binding element 'base' implicitly has an 'any' typ... Remove this comment to see the full error message
export const getInternalFunctionsDir = async ({ base, ensureExists, packagePath = '' }) => {
export const getInternalFunctionsDir = async ({
base,
ensureExists,
packagePath = '',
}: {
base: string
ensureExists?: boolean
packagePath?: string
}) => {
const path = resolve(base, packagePath, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]))

if (ensureExists) {
Expand Down

0 comments on commit e80ae3c

Please sign in to comment.