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: respect build plugins changing build.publish #6133

Merged
merged 5 commits into from
Nov 9, 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
10 changes: 7 additions & 3 deletions src/utils/run-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const runNetlifyBuild = async ({ command, env = {}, options, settings, ti
}

// Run Netlify Build using the main entry point.
const { success } = await buildSite(buildSiteOptions)
const { netlifyConfig, success } = await buildSite(buildSiteOptions)

if (!success) {
error('Could not start local server due to a build error')
Expand All @@ -120,10 +120,14 @@ export const runNetlifyBuild = async ({ command, env = {}, options, settings, ti

// Start the dev server, forcing the usage of a static server as opposed to
// the framework server.
await devCommand({
const settingsOverrides = {
command: undefined,
useStaticServer: true,
})
}
if (!options.dir && netlifyConfig?.build?.publish) {
settingsOverrides.dist = netlifyConfig.build.publish
}
await devCommand(settingsOverrides)

return { configPath: tempConfigPath }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello World!
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[[plugins]]
package="/plugin"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
onBuild({netlifyConfig}){
netlifyConfig.build.publish = "dist"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: change-publish-dir
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "module" }
10 changes: 10 additions & 0 deletions tests/integration/commands/dev/serve.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, test } from 'vitest'

import { FixtureTestContext, setupFixtureTests } from '../../utils/fixture.js'

setupFixtureTests('plugin-changing-publish-dir', { devServer: { serve: true } }, () => {
test<FixtureTestContext>('ntl serve should respect plugins changing publish dir', async ({ devServer }) => {
const response = await fetch(`http://localhost:${devServer.port}/`)
expect(response.status).toBe(200)
})
})
3 changes: 2 additions & 1 deletion tests/integration/utils/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface FixtureTestContext {
type LifecycleHook = (context: FixtureTestContext) => Promise<void> | void

export interface FixtureOptions {
devServer?: boolean
devServer?: boolean | { serve?: boolean }
mockApi?: MockApiOptions
/**
* Executed after fixture setup, but before tests run
Expand Down Expand Up @@ -148,6 +148,7 @@ export async function setupFixtureTests(

if (options.devServer) {
devServer = await startDevServer({
serve: typeof options.devServer === 'object' && options.devServer.serve,
cwd: fixture.directory,
offline: !mockApi,
args: ['--country', 'DE'],
Expand Down
Loading