Skip to content

Commit

Permalink
fix: use packagePath to compute internal functions directories (#5944)
Browse files Browse the repository at this point in the history
* fix: use `packagePath` to compute internal functions directories

* chore: oops
  • Loading branch information
eduardoboucas authored Aug 14, 2023
1 parent c0bec84 commit 43ce9cc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/commands/deploy/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ const runDeploy = async ({
deployToProduction,
functionsConfig,
functionsFolder,
packagePath,
silent,
site,
siteData,
Expand All @@ -345,13 +346,13 @@ const runDeploy = async ({
results = await api.createSiteDeploy({ siteId, title, body: { draft, branch: alias } })
deployId = results.id

const internalFunctionsFolder = await getInternalFunctionsDir({ base: site.root })
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 manifestPath = skipFunctionsCache ? null : await getFunctionsManifestPath({ base: site.root })
const manifestPath = skipFunctionsCache ? null : await getFunctionsManifestPath({ base: site.root, packagePath })

// @ts-ignore
results = await deploySite(api, siteId, deployFolder, {
Expand All @@ -367,6 +368,7 @@ const runDeploy = async ({
workingDir: command.workingDir,
manifestPath,
skipFunctionsCache,
siteRoot: site.root,
})
} catch (error_) {
if (deployId) {
Expand Down Expand Up @@ -657,6 +659,7 @@ const deploy = async (options, command) => {
functionsConfig,
// pass undefined functionsFolder if doesn't exist
functionsFolder: functionsFolderStat && functionsFolder,
packagePath: command.workspacePackage,
silent: options.json || options.silent,
site,
siteData,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/deploy/deploy-site.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const deploySite = async (
// API calls this the 'title'
message: title,
siteEnv,
siteRoot,
skipFunctionsCache,
statusCb = () => {
/* default to noop */
Expand Down Expand Up @@ -78,6 +79,7 @@ export const deploySite = async (
manifestPath,
skipFunctionsCache,
siteEnv,
rootDir: siteRoot,
}),
])
const edgeFunctionsCount = Object.keys(files).filter(isEdgeFunctionFile).length
Expand Down
4 changes: 2 additions & 2 deletions src/utils/deploy/hash-fns.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const getFunctionZips = async ({
directories,
functionsConfig,
manifestPath,
rootDir,
skipFunctionsCache,
statusCb,
tmpDir,
workingDir,
}) => {
statusCb({
type: 'functions-manifest',
Expand Down Expand Up @@ -68,7 +68,7 @@ const getFunctionZips = async ({
}

return await zipFunctions(directories, tmpDir, {
basePath: workingDir,
basePath: rootDir,
configFileDirectories: [getPathInProject([INTERNAL_FUNCTIONS_FOLDER])],
config: functionsConfig,
})
Expand Down
13 changes: 7 additions & 6 deletions src/utils/functions/functions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ export const SERVE_FUNCTIONS_FOLDER = 'functions-serve'
export const getFunctionsDir = ({ config, options }, defaultValue) =>
options.functions || config.dev?.functions || config.functionsDirectory || config.dev?.Functions || defaultValue

export const getFunctionsManifestPath = async ({ base }) => {
const path = resolve(base, getPathInProject(['functions', 'manifest.json']))
export const getFunctionsManifestPath = async ({ base, packagePath = '' }) => {
const path = resolve(base, packagePath, getPathInProject(['functions', 'manifest.json']))
const isFile = await isFileAsync(path)

return isFile ? path : null
}

export const getFunctionsDistPath = async ({ base }) => {
const path = resolve(base, getPathInProject(['functions']))
export const getFunctionsDistPath = async ({ base, packagePath = '' }) => {
const path = resolve(base, packagePath, getPathInProject(['functions']))
const isDirectory = await isDirectoryAsync(path)

return isDirectory ? path : null
Expand All @@ -38,10 +38,11 @@ export const getFunctionsDistPath = async ({ base }) => {
* @param {object} config
* @param {string} config.base
* @param {boolean=} config.ensureExists
* @param {string} config.packagePath
* @returns
*/
export const getInternalFunctionsDir = async ({ base, ensureExists }) => {
const path = resolve(base, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]))
export const getInternalFunctionsDir = async ({ base, ensureExists, packagePath = '' }) => {
const path = resolve(base, packagePath, getPathInProject([INTERNAL_FUNCTIONS_FOLDER]))

if (ensureExists) {
await fs.mkdir(path, { recursive: true })
Expand Down

2 comments on commit 43ce9cc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,313
  • Package size: 271 MB

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

  • Dependency count: 1,313
  • Package size: 271 MB

Please sign in to comment.