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(core): explicitly define CopyWebpackPlugin toType: 'dir' #8481

Merged
merged 1 commit into from Dec 27, 2022

Conversation

Thomascogez
Copy link
Contributor

@Thomascogez Thomascogez commented Dec 23, 2022

Note

Since it's my first PR here, I am not sure about the process.
And we be pleased to have some guidance.

Pre-flight checklist

Motivation

I have a project where the convention is using bracket [] in folder name.
The actual version of docusaurus if failing at build stage when there is a folder with bracket in the name.

What I did

After some investigation, I found that the issue is coming from the copy-webpack-plugin.
It actually report the folder has a file.

Here the actual config

/packages/docusaurus/src/commands/build.ts line 199

    serverConfig = merge(serverConfig, {
      plugins: [
        new CopyWebpackPlugin({
          patterns: staticDirectories.map((dir) => ({from: dir, to: outDir})),
        }),
      ],
    });

Proposed change

Since outDir is of course always a dir we can set the toType option to dir to solve this issue, this actually solve the false report of the outdir has a file by copy-webpack-plugin

    serverConfig = merge(serverConfig, {
      plugins: [
        new CopyWebpackPlugin({
          patterns: staticDirectories.map((dir) => ({from: dir, to: outDir, toType: 'dir'})),
        }),
      ],
    });

Test Plan

I will need some guidance for this part as I am not sure how to test this change.

Test links

Bug reproduction: https://github.com/Thomascogez/docusaurus-bracket-in-path-bug-repro

Deploy preview: https://deploy-preview-_____--docusaurus-2.netlify.app/

Related issues/PRs

#8480

@facebook-github-bot
Copy link
Contributor

Hi @Thomascogez!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link

netlify bot commented Dec 23, 2022

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 344ceab
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/63a623b3b2642d000890b5c5
😎 Deploy Preview https://deploy-preview-8481--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 85 🟢 97 🟢 100 🟢 100 🟢 90 Report
/docs/installation 🟠 76 🟢 100 🟢 100 🟢 100 🟢 90 Report

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Dec 23, 2022
@Josh-Cena
Copy link
Collaborator

Could you add a static directory in our own website with brackets in its path, and compare the build results on main vs. on this branch? (Maybe also test if this fixes #8135 by adding another static directory with dots?)

Also, could you illuminate me about why your fix works?

@Josh-Cena Josh-Cena changed the title fix(core/build): explicitly define CopyWebpackPlugin toType to 'dir' fix(core): explicitly define CopyWebpackPlugin toType: 'dir' Dec 23, 2022
@Josh-Cena Josh-Cena added the pr: bug fix This PR fixes a bug in a past release. label Dec 23, 2022
@Thomascogez
Copy link
Contributor Author

After intense local testing, I was able to determine that the point of failure was during webpack build, more especially when copy-webpack-plugin is run. After doing some searching if found this issue webpack-contrib/copy-webpack-plugin#434 which is describing is similar bug.

copy-webpack-plugin has a logic to determine (if not explicitly set) the type of input (dir, file or glob).
My thought is that copy-webpack-plugin is wrongly reporting path containing [] or . as file.

After that some fs operation are run based on the determined type of input, in this case it's running fs operation targeting a file that why EISDIR error is popping

Hope it's clear 😅

@Josh-Cena
Copy link
Collaborator

Makes sense, thanks :) Could you add two test directories under website/_dogfooding?

@Thomascogez
Copy link
Contributor Author

I tested locally to reproduce #8135 and it build successfully with this fix 👍.
Ok i'm on it !

@Thomascogez
Copy link
Contributor Author

I misspoke in my first edit,
I had said:

Since the staticDirectories is an array of folder path, I propose to use the toType option set to dir to avoid false file detection.

but edited to:

Since outDir is of course always a dir we can set the toType option to dir to solve this issue, this actually solve the false report of the outdir has a file by copy-webpack-plugin

Should my tests be under _dogfooding since it's the outDir causing the issue ?

I'm still exploring the project and the folder structure of the tests

@Josh-Cena
Copy link
Collaborator

If the dots issue can't be reproduced with a subdirectory of outDir, we can just forgo the test, as long as you've tested it locally. What about square brackets?

@Thomascogez
Copy link
Contributor Author

It's actually the outDir which is actually miss interpreted by copy-webpack-plugin (tooption) (sorry for misleading you with my first assumption).

So static subfolder with bracket or dots are actually building.

Here my tests:

Main branch

Bracket

Without --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/[bracket]'

yarn build

output:

[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/[bracket]/build'
[ERROR] Unable to build website for locale en.
[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/[bracket]/build'

With --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/[bracket]'

yarn build --out-dir "build/[bracket]"

output:

[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/[bracket]/build/[bracket]'
[ERROR] Unable to build website for locale en.
[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/[bracket]/build/[bracket]'

Dot

Without --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/6.0

yarn build

output:

[SUCCESS] Generated static files in "build".
[INFO] Use `npm run serve` command to test your build locally.

With --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/6.0

yarn build --out-dir "build/6.0" 

output:

[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/6.0/build/6.0'
[ERROR] Unable to build website for locale en.
[ERROR] Error: EISDIR: illegal operation on a directory, open '/Users/thomascogez--allix/Documents/dev/personnal/docusaurus-bracket-in-path-bug-repro/6.0/build/6.0'

Fix branch

Bracket

Without --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/[bracket]'

yarn build

output:

[SUCCESS] Generated static files in "build".
[INFO] Use `npm run serve` command to test your build locally.

With --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/[bracket]'

yarn build --out-dir "build/[bracket]"

output:

[SUCCESS] Generated static files in "build/[bracket]".
[INFO] Use `npm run serve` command to test your build locally.

Dot

Without --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/6.0

yarn build

output:

[SUCCESS] Generated static files in "build".
[INFO] Use `npm run serve` command to test your build locally.

With --out-dir arg

project path /docusaurus-bracket-in-path-bug-repro/6.0

yarn build --out-dir "build/6.0" 

output:

[SUCCESS] Generated static files in "build/6.0".
[INFO] Use `npm run serve` command to test your build locally.

Copy link
Collaborator

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

Sounds fair :)

@Thomascogez
Copy link
Contributor Author

Great ! Thanks for your time 👍

@slorber
Copy link
Collaborator

slorber commented Dec 27, 2022

LGTM thanks ;)

@slorber slorber merged commit 0371d57 into facebook:main Dec 27, 2022
@slorber slorber added the to backport This PR is planned to be backported to a stable version of Docusaurus label Dec 27, 2022
slorber pushed a commit that referenced this pull request Jan 26, 2023
@slorber slorber added backported This PR has been backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
4 participants