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 correct publishDir when building from CLI with cwd option #1264

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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: 2 additions & 2 deletions src/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
import bridgeFile from '@vercel/node-bridge'
import { copyFile, ensureDir, writeFile, writeJSON } from 'fs-extra'
import type { ImageConfigComplete } from 'next/dist/server/image-config'
import { join, relative } from 'pathe'
import { join, relative, resolve } from 'pathe'

import { HANDLER_FUNCTION_NAME, ODB_FUNCTION_NAME, IMAGE_FUNCTION_NAME, DEFAULT_FUNCTIONS_SRC } from '../constants'
import { getHandler } from '../templates/getHandler'
Expand All @@ -14,7 +14,7 @@ export const generateFunctions = async (
): Promise<void> => {
const functionsDir = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC
const functionDir = join(process.cwd(), functionsDir, HANDLER_FUNCTION_NAME)
const publishDir = relative(functionDir, join(process.cwd(), PUBLISH_DIR))
const publishDir = relative(functionDir, resolve(PUBLISH_DIR))

const writeHandler = async (func: string, isODB: boolean) => {
const handlerSource = await getHandler({ isODB, publishDir, appDir: relative(functionDir, appDir) })
Expand Down
7 changes: 2 additions & 5 deletions src/helpers/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ export const checkNextSiteHasBuilt = ({
: `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`

return failBuild(outdent`
The directory "${path.relative(
process.cwd(),
publish,
)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
The directory "${publish}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
${outWarning}
If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
`)
Expand All @@ -93,7 +90,7 @@ export const checkForRootPublish = ({
}): void | never => {
if (path.resolve(publish) === path.resolve('.')) {
failBuild(outdent`
Your publish directory is pointing to the base directory of your site. This is not supported for Next.js sites, and is probably a mistake.
Your publish directory is pointing to the base directory of your site. This is not supported for Next.js sites, and is probably a mistake.
In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config, or the Next site is in a subdirectory.
`)
}
Expand Down
24 changes: 12 additions & 12 deletions test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -677,73 +677,73 @@ Array [
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/1.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/1.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/1",
"from": "/getStaticProps/withRevalidate/withFallback/1",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/2.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/2.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/2",
"from": "/getStaticProps/withRevalidate/withFallback/2",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/1.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallbackBlocking/1.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/withFallback/1",
"from": "/getStaticProps/withRevalidate/withFallbackBlocking/1",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallback/2.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallbackBlocking/2.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/withFallback/2",
"from": "/getStaticProps/withRevalidate/withFallbackBlocking/2",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallbackBlocking/1.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/1.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/withFallbackBlocking/1",
"from": "/getStaticProps/withRevalidate/1",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/withFallbackBlocking/2.json",
"from": "/_next/data/build-id/en/getStaticProps/withRevalidate/2.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": true,
"from": "/getStaticProps/withRevalidate/withFallbackBlocking/2",
"from": "/getStaticProps/withRevalidate/2",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Expand Down