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

Dot files not copied over from public folder if not running build from root folder #9740

Closed
1 task done
taktran opened this issue Jan 19, 2024 · 7 comments · Fixed by #9741
Closed
1 task done

Dot files not copied over from public folder if not running build from root folder #9740

taktran opened this issue Jan 19, 2024 · 7 comments · Fixed by #9741
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)

Comments

@taktran
Copy link
Contributor

taktran commented Jan 19, 2024

Astro Info

✗ npx astro info
Astro                    v3.6.4
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/markdoc
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I have a public/.htaccess file and when running astro build, it doesn't get copied over to the dist folder. I also have a custom outDir set to something like ../../dist/packages/folder.

The strange thing is, I can't quite replicate it on stackblitz. This is my attempt, where the .htaccess does get generated when you run npm run build in the terminal: https://stackblitz.com/edit/github-es2mdg-rajrjb?file=README.md (it can be reproduced when run from another directory - see stackblitz below)

However, looking at the code and patching the file locally, it does fix it on my local machine:

https://github.com/withastro/astro/blob/main/packages/astro/src/core/build/static-build.ts#L439-L445

From

if (out.toString() !== opts.settings.config.outDir.toString()) {
  // Copy assets before cleaning directory if outside root
  await copyFiles(out, opts.settings.config.outDir);
  await fs.promises.rm(out, { recursive: true });
  return;
}

// Where
copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles = false) 

it looks like copyFiles should set includedDotfiles parameter to true ie,

await copyFiles(out, opts.settings.config.outDir, true);

The out.toString() !== opts.settings.config.outDir.toString() check seems to match with my scenario where outDir is set, and I can't think of a reason why it wouldn't copy dot files (or a least make it configurable somewhere).

The includedDotfiles parameter seems to have been added in #5832, if that is useful.

Am I missing something?

What's the expected result?

Expect .htaccess to appear in the dist folder when running astro build. Don't see the bug in the attached stackblitz, but can replicate locally and looking at the code, it does seem like it's a legitimate bug.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-es2mdg-rajrjb (not a reproducible example, but it's the gist of the steps - see above)

https://stackblitz.com/edit/github-es2mdg-xzyijr?file=README.md (actual reproducible example)

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 19, 2024
@taktran
Copy link
Contributor Author

taktran commented Jan 19, 2024

Oh, I checked out the stackblitz (https://stackblitz.com/edit/github-es2mdg-rajrjb) that was working locally, and looked at out.toString() !== opts.settings.config.outDir.toString(), which turns out to be false ie, out and opts.settings.config.outDir are the same on this simple example. So my original set up isn't so simple. It's using nx and @nxtensions/astro (actually, we don't use that anymore, it's using astro build and a different cwd, which could be affecting this), which might be causing the differences in the out folders (I need to dig into this more).

However, although I'm not able to replicate atm, the code still does seem like there's an issue here in situations where the out folders are different.

[Edit: clear up nx setup]

@lilnasy
Copy link
Contributor

lilnasy commented Jan 19, 2024

Thanks for looking into it. Even from a different folder, I could not reproduce the issue.

video.mp4

@lilnasy lilnasy added the needs repro Issue needs a reproduction label Jan 19, 2024
Copy link
Contributor

Hello @taktran. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jan 19, 2024
@taktran
Copy link
Contributor Author

taktran commented Jan 19, 2024

@lilnasy, actually when you run npx astro build, you need to use -- to pass in arguments to astro from npx. Thanks for the --root tip though ⭐ , I was trying to figure out how to do that. I've managed to replicate the bug by creating another folder where astro is installed.

See https://stackblitz.com/edit/github-es2mdg-xzyijr

Steps to reproduce

  1. Stop the terminal with ctrl-c in stackblitz

  2. Run npm run build

  3. Check the other-dist folder for the .htaccess file - it should be there

  4. Go to the another-astro folder and run the build

    npm run astro build -- --root ../
    

    Check the other-dist folder for the .htaccess file - it is missing

@taktran
Copy link
Contributor Author

taktran commented Jan 19, 2024

Actually my initial assumption that it was related to the outDir was wrong, it's just about running astro build in another folder and using the --root parameter. Here is an example of the bug without changing the default outDir: https://stackblitz.com/edit/github-es2mdg-tnkbfm?file=README.md

@lilnasy lilnasy added - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs repro Issue needs a reproduction labels Jan 19, 2024
@taktran taktran changed the title Dot file not copied over from public folder in build if outDir is set Dot files not copied over from public folder if not running build from root folder Jan 19, 2024
taktran added a commit to taktran/astro that referenced this issue Jan 19, 2024
When running `astro build` outside of where the astro files are, dotfiles are not copied over because the `includeDotfiles` parameter is not passed in.
taktran added a commit to taktran/astro that referenced this issue Jan 19, 2024
When running `astro build` outside of where the astro files are, dotfiles are not copied over because the `includeDotfiles` parameter is not passed in.
@lilnasy
Copy link
Contributor

lilnasy commented Jan 19, 2024

You seem to have identified the right place for the fix from the PR you linked. A PR would be welcome. Feel free to ask if you want pointers.

@taktran
Copy link
Contributor Author

taktran commented Jan 19, 2024

@lilnasy , have set up a PR here: #9741 - give me a shout if it requires any more changes

ematipico pushed a commit that referenced this issue Jan 22, 2024
* Fix dot files not being copied over on non-root builds (#9740)

When running `astro build` outside of where the astro files are, dotfiles are not copied over because the `includeDotfiles` parameter is not passed in.

* update changeset

* Update changeset description

---------

Co-authored-by: Arsh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants