Skip to content

Conversation

@arcanis
Copy link
Contributor

@arcanis arcanis commented Jan 31, 2019

Basically with Yarn v2 we'll make it possible to load files directly from within the zip archive. For now this will be implemented by patching the fs module so that Node is able to see the files within the archive. The problem is that in order to work well with rimraf and similar crawlers, the archive itself mustn't be stat'd as a directory. This is problematic in Prettier because you actually check it by default.

With this change the node_modules isDirectory check will succeed, and will shortcut the one to check whether its parent directory is a directory.

@kachkaev
Copy link
Member

I'm wondering if this new behaviour could be tested somehow 🤔 Otherwise, it won't take long for someone to break it 😅

// In some fringe cases (ex: files "mounted" as virtual directories), the
// isDirectory(resolvedPluginSearchDir) check might be false even though
// the node_modules actually exists.
if (!isDirectory(nodeModulesDir) && !isDirectory(resolvedPluginSearchDir)) {
Copy link
Member

Choose a reason for hiding this comment

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

From CI:

✘  prettier/prettier  Replace `!isDirectory(nodeModulesDir)·&&·!isDirectory(resolvedPluginSearchDir)` with `⏎········!isDirectory(nodeModulesDir)·&&⏎········!isDirectory(resolvedPluginSearchDir)⏎······`  
   src/common/load-plugins.js:63:11
         if (!isDirectory(nodeModulesDir) && !isDirectory(resolvedPluginSearchDir)) {
              ^
 
✘ 1 problem (1 error, 0 warnings)

@arcanis
Copy link
Contributor Author

arcanis commented Jan 31, 2019

Maybe by adding a mock that would call the real stat? Like here:

https://github.com/prettier/prettier/blob/master/tests_integration/runPrettier.js#L54-L56

@arcanis
Copy link
Contributor Author

arcanis commented Jan 31, 2019

Added a test 😃

@kachkaev
Copy link
Member

kachkaev commented Feb 1, 2019

Linting is failing again in CI:

cross-env EFF_NO_LINK_RULES=true eslint . --format node_modules/eslint-friendly-formatter

  ✘  prettier/prettier  Delete `,`                         
  tests_integration/__tests__/plugin-virtual-directory.js:14:14
      write: [],
                ^

  ✘  no-else-return     Unnecessary 'else' after 'return'  
  tests_integration/runPrettier.js:63:12
      } else {
              ^

✘ 2 problems (2 errors, 0 warnings)

The first error should be fixed by running this:

./node_modules/.bin/prettier --write tests_integration/**/*.*

In the second case, the answer seems to be:

    if (path.basename(filename) === `virtualDirectory`) {
      return origStatSync(path.join(__dirname, __filename));
    }
    return origStatSync(filename);

@arcanis
Copy link
Contributor Author

arcanis commented Feb 1, 2019

Woops, forgot to commit the fix, here it is!

@arcanis
Copy link
Contributor Author

arcanis commented Feb 5, 2019

Ping? 🙂

@j-f1 j-f1 merged commit 9793154 into prettier:master Feb 5, 2019
@j-f1
Copy link
Member

j-f1 commented Feb 5, 2019

Thanks for contributing!

@arcanis arcanis mentioned this pull request Feb 24, 2019
1 task
@arcanis
Copy link
Contributor Author

arcanis commented Feb 24, 2019

Any idea when this could be released? It would fix a problem that blocks us from using prettier within the Yarn repo 😀

@j-f1
Copy link
Member

j-f1 commented Feb 25, 2019

I’m not sure, but in the meantime you can install prettier/prettier to pull the latest code from GitHub.

@lipis lipis added this to the 1.17 milestone Mar 15, 2019
@kachkaev kachkaev mentioned this pull request May 16, 2019
3 tasks
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jun 13, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jun 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants