Skip to content

feat: support new monorepo setup #2260

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

Merged
merged 3 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
4 changes: 3 additions & 1 deletion packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,11 @@ export const getEdgeFunctionPatternForPage = ({
export const writeEdgeFunctions = async ({
netlifyConfig,
routesManifest,
constants: { PACKAGE_PATH = '' },
}: {
netlifyConfig: NetlifyConfig
routesManifest: RoutesManifest
constants: NetlifyPluginConstants
}) => {
const generator = await getPluginVersion()

Expand All @@ -366,7 +368,7 @@ export const writeEdgeFunctions = async ({
version: 1,
}

const edgeFunctionRoot = resolve('.netlify', 'edge-functions')
const edgeFunctionRoot = resolve(PACKAGE_PATH, '.netlify', 'edge-functions')
await emptyDir(edgeFunctionRoot)

const { publish } = netlifyConfig.build
Expand Down
19 changes: 15 additions & 4 deletions packages/runtime/src/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ export interface APILambda extends SSRLambda {
}

export const generateFunctions = async (
{ FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }: NetlifyPluginConstants,
{
INTERNAL_FUNCTIONS_SRC,
PUBLISH_DIR,
PACKAGE_PATH = '',
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
}: NetlifyPluginConstants,
appDir: string,
apiLambdas: APILambda[],
ssrLambdas: SSRLambda[],
Expand Down Expand Up @@ -171,20 +176,26 @@ export const generateFunctions = async (
*/
export const generatePagesResolver = async ({
INTERNAL_FUNCTIONS_SRC,
FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC,
PUBLISH_DIR,
PACKAGE_PATH = '',
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
}: NetlifyPluginConstants): Promise<void> => {
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC

const jsSource = await getResolverForPages(PUBLISH_DIR)
const jsSource = await getResolverForPages(PUBLISH_DIR, PACKAGE_PATH)

await writeFile(join(functionsPath, ODB_FUNCTION_NAME, 'pages.js'), jsSource)
await writeFile(join(functionsPath, HANDLER_FUNCTION_NAME, 'pages.js'), jsSource)
}

// Move our next/image function into the correct functions directory
export const setupImageFunction = async ({
constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, IS_LOCAL },
constants: {
IS_LOCAL,
INTERNAL_FUNCTIONS_SRC,
PACKAGE_PATH = '',
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
},
imageconfig = {},
netlifyConfig,
basePath,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const plugin: NetlifyPlugin = {
apiLambdas,
})

await writeEdgeFunctions({ netlifyConfig, routesManifest })
await writeEdgeFunctions({ constants, netlifyConfig, routesManifest })
},

async onPostBuild({
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/templates/getPageResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export const getResolverForDependencies = ({
`
}

export const getResolverForPages = async (publish: string) => {
const functionDir = resolve('.netlify', 'functions', HANDLER_FUNCTION_NAME)
export const getResolverForPages = async (publish: string, packagePath: string) => {
const functionDir = resolve(packagePath, '.netlify', 'functions', HANDLER_FUNCTION_NAME)
const dependencies = await getAllPageDependencies(publish)
return getResolverForDependencies({ dependencies, functionDir })
}
Expand Down