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: clear dist directory before Dev for Nuxt #6242

Merged
merged 3 commits into from
Dec 20, 2023
Merged

fix: clear dist directory before Dev for Nuxt #6242

merged 3 commits into from
Dec 20, 2023

Conversation

Skn0tt
Copy link
Contributor

@Skn0tt Skn0tt commented Dec 4, 2023

Part of https://linear.app/netlify/issue/COM-184/nuxt-netlify-dev-doesnt-work. Running ntl build and then ntl dev on a Nuxt project leads to Dev picking up dist/_redirects and dist/_headers, even though the Nitro dev server will handle all of this on its own. This is breaking local dev currently.

In unjs/nitro#1970, the Nitro team suggests we add rm -rf to the dev command. I tried doing that in netlify/build#5429, but since we don't spawn a full shell for the dev process, we can't use command concatenation like &&.

This PR contains an alternative fix, where we manually remove the dist directory just for Nuxt projects.

@Skn0tt Skn0tt requested a review from a team as a code owner December 4, 2023 14:07
@Skn0tt Skn0tt self-assigned this Dec 4, 2023
const useStaticServer = !(command && frameworkPort)

// workaround for https://github.com/unjs/nitro/issues/1970
const clearDist = frameworkSettings.framework?.includes('Nuxt')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, I don't really like that we're storing this within the CLI. Should live within build-info, ideally - let me see if I can open a PR there.

Copy link
Contributor Author

@Skn0tt Skn0tt Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a PR to add this info to build-info: netlify/build#5430
Turned this into draft until that landed.

Copy link

github-actions bot commented Dec 4, 2023

📊 Benchmark results

Comparing with a882392

  • Dependency count: 1,399 (no change)
  • Package size: 405 MB (no change)
  • Number of ts-expect-error directives: 1,282 ⬇️ 0.70% decrease vs. a882392

@Skn0tt
Copy link
Contributor Author

Skn0tt commented Dec 20, 2023

I couldn't find an easy way of writing a test for this :/

@Skn0tt Skn0tt marked this pull request as ready for review December 20, 2023 14:46
@@ -38,12 +41,17 @@ export const startFrameworkServer = async function ({ cwd, settings }) {
text: `Waiting for framework port ${settings.frameworkPort}. This can be configured using the 'targetPort' property in the netlify.toml`,
})

if (settings.clearPublishDirectory && settings.dist) {
await rm(settings.dist, { recursive: true, force: true })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the main change, all the rest is typescript conversion stuff

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha I feel you just opened a just change types PR before performing the actual change

@Skn0tt Skn0tt merged commit 6014df5 into main Dec 20, 2023
35 checks passed
@Skn0tt Skn0tt deleted the nuxt-clear-dist branch December 20, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants