Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use packagePath to compute internal functions directories #5944

Merged
merged 2 commits into from
Aug 14, 2023
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
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
Loading