Skip to content

Commit 6a9b906

Browse files
author
Lukas Holzer
committed
feat: support new monorepo setup
1 parent 112bb9f commit 6a9b906

File tree

11 files changed

+48
-35
lines changed

11 files changed

+48
-35
lines changed

demos/base-path/netlify.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
2-
command = "next build"
3-
publish = ".next"
2+
command = "npm --workspace base-path-demo run build"
3+
publish = "/demos/base-path/.next"
44
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
55

66
[build.environment]
@@ -16,4 +16,4 @@ package = "@netlify/plugin-nextjs"
1616
package = "@netlify/plugin-local-install-core"
1717

1818
[[plugins]]
19-
package = "../plugin-wrapper"
19+
package = "/demos/plugin-wrapper"

demos/canary/netlify.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
2-
command = "next build"
3-
publish = ".next"
2+
command = "npm --workspace canary run build"
3+
publish = "/demos/canary/.next"
44
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
55

66
[build.environment]
@@ -15,4 +15,4 @@ package = "@netlify/plugin-nextjs"
1515
package = "@netlify/plugin-local-install-core"
1616

1717
[[plugins]]
18-
package = "../plugin-wrapper"
18+
package = "/demos/plugin-wrapper"

demos/custom-routes/netlify.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
2-
command = "next build"
3-
publish = ".next"
2+
command = "npm --workspace custom-routes run build"
3+
publish = "/demos/custom-routes/.next"
44
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
55

66
[[plugins]]
@@ -11,4 +11,4 @@ package = "@netlify/plugin-nextjs"
1111
package = "@netlify/plugin-local-install-core"
1212

1313
[[plugins]]
14-
package = "../plugin-wrapper"
14+
package = "/demos/plugin-wrapper"

demos/default/netlify.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
[build]
2-
command = "next build"
3-
publish = ".next"
2+
command = "npm --workspace default-demo run build"
43
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
4+
publish = "/demos/default/.next"
55

66
[build.environment]
77
# cache Cypress binary in local "node_modules" folder
88
# so Netlify caches it
99
CYPRESS_CACHE_FOLDER = "../node_modules/.CypressBinary"
1010
# set TERM variable for terminal output
11-
TERM = "xterm"
12-
NODE_VERSION = "16.15.1"
13-
NEXT_SPLIT_API_ROUTES = "true"
1411
NEXT_BUNDLE_BASED_ON_NFT_FILES = "true"
12+
NEXT_SPLIT_API_ROUTES = "true"
13+
NODE_VERSION = "16.15.1"
14+
TERM = "xterm"
1515

1616
[[headers]]
1717
for = "/_next/image/*"
@@ -28,4 +28,4 @@ package = "@netlify/plugin-nextjs"
2828
package = "@netlify/plugin-local-install-core"
2929

3030
[[plugins]]
31-
package = "../plugin-wrapper"
31+
package = "/demos/plugin-wrapper"

demos/middleware/netlify.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build]
2-
command = "npm run build"
3-
publish = ".next"
2+
command = "npm --workspace middleware run build"
3+
publish = "/demos/middleware/.next"
44
ignore = "if [ $CACHED_COMMIT_REF == $COMMIT_REF ]; then (exit 1); else git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF ../..; fi;"
55

66
[build.environment]
@@ -15,7 +15,7 @@ package = "@netlify/plugin-nextjs"
1515
package = "@netlify/plugin-local-install-core"
1616

1717
[[plugins]]
18-
package = "../plugin-wrapper"
18+
package = "/demos/plugin-wrapper"
1919
# Uncomment this if testing the built files rather than dev
2020
# [dev]
2121
# framework = "#static"

package-lock.json

+8-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@babel/preset-env": "^7.15.8",
5454
"@babel/preset-typescript": "^7.16.0",
5555
"@delucis/if-env": "^1.1.2",
56-
"@netlify/build": "^29.20.1",
56+
"@netlify/build": "^29.20.3",
5757
"@netlify/eslint-config-node": "^7.0.1",
5858
"@testing-library/cypress": "^9.0.0",
5959
"@types/fs-extra": "^9.0.13",

packages/runtime/src/helpers/edge.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,11 @@ export const getEdgeFunctionPatternForPage = ({
354354
export const writeEdgeFunctions = async ({
355355
netlifyConfig,
356356
routesManifest,
357+
constants: { PACKAGE_PATH = '' },
357358
}: {
358359
netlifyConfig: NetlifyConfig
359360
routesManifest: RoutesManifest
361+
constants: NetlifyPluginConstants
360362
}) => {
361363
const generator = await getPluginVersion()
362364

@@ -366,7 +368,7 @@ export const writeEdgeFunctions = async ({
366368
version: 1,
367369
}
368370

369-
const edgeFunctionRoot = resolve('.netlify', 'edge-functions')
371+
const edgeFunctionRoot = resolve(PACKAGE_PATH, '.netlify', 'edge-functions')
370372
await emptyDir(edgeFunctionRoot)
371373

372374
const { publish } = netlifyConfig.build

packages/runtime/src/helpers/functions.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export interface APILambda extends SSRLambda {
5858
}
5959

6060
export const generateFunctions = async (
61-
{ FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }: NetlifyPluginConstants,
61+
{
62+
INTERNAL_FUNCTIONS_SRC,
63+
PUBLISH_DIR,
64+
PACKAGE_PATH = '',
65+
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
66+
}: NetlifyPluginConstants,
6267
appDir: string,
6368
apiLambdas: APILambda[],
6469
ssrLambdas: SSRLambda[],
@@ -171,20 +176,26 @@ export const generateFunctions = async (
171176
*/
172177
export const generatePagesResolver = async ({
173178
INTERNAL_FUNCTIONS_SRC,
174-
FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC,
175179
PUBLISH_DIR,
180+
PACKAGE_PATH = '',
181+
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
176182
}: NetlifyPluginConstants): Promise<void> => {
177183
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
178184

179-
const jsSource = await getResolverForPages(PUBLISH_DIR)
185+
const jsSource = await getResolverForPages(PUBLISH_DIR, PACKAGE_PATH)
180186

181187
await writeFile(join(functionsPath, ODB_FUNCTION_NAME, 'pages.js'), jsSource)
182188
await writeFile(join(functionsPath, HANDLER_FUNCTION_NAME, 'pages.js'), jsSource)
183189
}
184190

185191
// Move our next/image function into the correct functions directory
186192
export const setupImageFunction = async ({
187-
constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = DEFAULT_FUNCTIONS_SRC, IS_LOCAL },
193+
constants: {
194+
IS_LOCAL,
195+
INTERNAL_FUNCTIONS_SRC,
196+
PACKAGE_PATH = '',
197+
FUNCTIONS_SRC = join(PACKAGE_PATH, DEFAULT_FUNCTIONS_SRC),
198+
},
188199
imageconfig = {},
189200
netlifyConfig,
190201
basePath,

packages/runtime/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const plugin: NetlifyPlugin = {
213213
apiLambdas,
214214
})
215215

216-
await writeEdgeFunctions({ netlifyConfig, routesManifest })
216+
await writeEdgeFunctions({ constants, netlifyConfig, routesManifest })
217217
},
218218

219219
async onPostBuild({

packages/runtime/src/templates/getPageResolver.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export const getResolverForDependencies = ({
4343
`
4444
}
4545

46-
export const getResolverForPages = async (publish: string) => {
47-
const functionDir = resolve('.netlify', 'functions', HANDLER_FUNCTION_NAME)
46+
export const getResolverForPages = async (publish: string, packagePath: string) => {
47+
const functionDir = resolve(packagePath, '.netlify', 'functions', HANDLER_FUNCTION_NAME)
4848
const dependencies = await getAllPageDependencies(publish)
4949
return getResolverForDependencies({ dependencies, functionDir })
5050
}

0 commit comments

Comments
 (0)