Skip to content

fix: more robust static site detection #505

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 6 commits into from
Jul 12, 2021
Merged

fix: more robust static site detection #505

merged 6 commits into from
Jul 12, 2021

Conversation

ascorbic
Copy link
Contributor

@ascorbic ascorbic commented Jul 9, 2021

We skip running the plugin if we detect that next export is being called. Previously we only checked if it was either the build command, or in the npm script that was called by the build command. This meant it missed build commands that were called indirectly, e.g. when the build script calls npm run export.

To fix this, I have used a package called parse-npm-script, which is designed for exactly this. However it misses a lot of edge cases, so I have vendored it and added support for parsing npm-run-all and cross-env calls. I've not done an upstream PR, because I've also removed features as I want it to be sync.

Finally, I've added support for an env var NEXT_IS_STATIC_EXPORT which can be set and will enforce this too.

Fixes #503

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jul 9, 2021
@ascorbic ascorbic requested a review from lindsaylevine July 9, 2021 14:42
Copy link

@lindsaylevine lindsaylevine left a comment

Choose a reason for hiding this comment

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

this is so awesome!! my only question is -- i was thinking the env var would be more generic. like NETLIFY_OPT_OUT_NEXT_PLUGIN or something. any reason it's so specific right now vs being an overall opt out?

@ascorbic
Copy link
Contributor Author

Good point. I've removed the env var, as I think it needs more discussing separately from this

@ascorbic ascorbic requested a review from lindsaylevine July 12, 2021 12:10
@ascorbic ascorbic enabled auto-merge (squash) July 12, 2021 16:13
@ascorbic ascorbic merged commit b1fd513 into main Jul 12, 2021
@ascorbic ascorbic deleted the fix/static-detection branch July 12, 2021 16:25
serhalp pushed a commit that referenced this pull request Jun 13, 2024
Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Co-authored-by: Matt Kane <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isStaticExport logic fails if the build command doesn't contain "next export"
2 participants