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

Handle builds with outDir outside of cwd #4736

Merged
merged 3 commits into from
Sep 14, 2022
Merged

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Sep 13, 2022

Changes

Fix #4006

If outDir is out of process.cwd(), build the ssr output to <cwd>/.astro instead. This directory will be removed after the build, unless an error occurs during the build, which it's preserved for debuggability.

Testing

No test added as the monorepo structure makes it tricky to test this edge case (brings false positive). I did test with a separate project though and it works.

Docs

This PR handles static output only (output: 'static'). For server output, the outDir MUST be inside the current working directory as most integrations requires this for the deployment output to work. (e.g. netlify, vercel, cloudflare)

Should we document this? On the other hand, setting outDir outside of cwd feels like a special case.

/cc @withastro/maintainers-docs for feedback!

@changeset-bot
Copy link

changeset-bot bot commented Sep 13, 2022

🦋 Changeset detected

Latest commit: dcd9e68

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
astro Patch
@e2e/astro-component Patch
@e2e/error-cyclic Patch
@e2e/error-react-spectrum Patch
@e2e/error-sass Patch
@e2e/errors Patch
@e2e/hydration-race Patch
@e2e/lit-component Patch
@e2e/preact-component Patch
@e2e/react-component Patch
@e2e/solid-component Patch
@e2e/solid-recurse Patch
@e2e/svelte-component Patch
@e2e/e2e-tailwindcss Patch
@e2e/ts-resolution Patch
@e2e/third-party-astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Sep 13, 2022
@matthewp
Copy link
Contributor

Given that we cannot build outside of the projectRoot when output: 'server', can we error when someone attempts it?

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Looks great, had one small suggestion but not blocking in any way.

import type { AstroConfig, RouteType } from '../../@types/astro';
import { appendForwardSlash } from '../../core/path.js';

const STATUS_CODE_PAGES = new Set(['/404', '/500']);
const FALLBACK_OUT_DIR_NAME = './.astro-temp/';
Copy link
Member

Choose a reason for hiding this comment

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

I'd be fine with .astro, personally? Not a huge deal but it's a bit more clean.

Suggested change
const FALLBACK_OUT_DIR_NAME = './.astro-temp/';
const FALLBACK_OUT_DIR_NAME = './.astro/';

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with this too. I thought that in the case where the build fails, and .astro-temp is not removed (for debugging), it sends a clearer message that it's a temporary folder that can be removed.

Copy link
Member

@natemoo-re natemoo-re Sep 13, 2022

Choose a reason for hiding this comment

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

That's fine with me! I'd probably also add the directory to the .gitignore files in our examples just to be safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

@natemoo-re I updated to use .astro. I think a .gitignore change shouldn't be needed at the meantime since this special directory is only created if someone specifies a outDir outside of the project. Perhaps if there's a request for it you can add that too.

Copy link
Contributor

@matthewp matthewp left a comment

Choose a reason for hiding this comment

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

Let's go ahead and error when attempting this with output: 'server'

@bluwy
Copy link
Member Author

bluwy commented Sep 14, 2022

@matthewp Actually through further testing, output: 'server' seem unaffected as we don't invoke the SSR output for generating pages. This seems to be fine then. The PR should be good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: outDir that doesn't have package.json with node_modules fails
3 participants