redwoodjs / redwood

The App Framework for Startups
https://redwoodjs.com
MIT License
17.32k stars 994 forks source link

rwfw project:sync loses sync after setup commands or yarn installs #3128

Open dac09 opened 3 years ago

dac09 commented 3 years ago

Steps to reproduce

  1. Create e2e test project using ./tasks/run-e2e
  2. Go to project folder, and run yarn rw setup tailwind
  3. At this point the project will become "unsynced" i.e. the framework won't be in use in the project anymore

This also applies if you run yarn rwfw project:sync in an existing project. If you run yarn install (or install a new module, lets say), the project becomes "unsynced"

Ideal behaviour

Project should retain sync even after an install

peterp commented 3 years ago

Ok, so the root cause is that running yarn install installs the packages and "undoes" the files that are copied.

I assume a temporary fix would be that a user needs to run yarn rwfw project:copy again? The part that we're missing is the ability to perform this action after a yarn install?

@dac09 Is my understanding of the problem correct?

I guess we could add a postinstall script to the <rootDir>/package.json that runs yarn rwfw project:copy

@jtoar Does that sound like a reasonable approach to you?

dac09 commented 3 years ago

Yep - that's right @peterp. This happens due to yarn overwriting the copied files in node_modules/@redwoodjs/*

It seems like a reasonable change to me. For the two-step one (i.e. the test project generator) - I'll add it in now.

dac09 commented 3 years ago

Actually on second pass, something to note, if the setup command runs in web/api - like tailwind - the postinstall doesn't get picked up (if you put it on the root package.json).

See https://github.com/yarnpkg/yarn/issues/7121

jtoar commented 3 years ago

@peterp as @dac09 said, that case won't cover setup commands like tailwind, but for things like dbAuth which just add boilerplate, that fix will do the trick.

Wondering, in the tailwind case, if there's a way to tell yarn to just leave certain packages alone on install? Instead of rebuilding everything

jtoar commented 3 years ago

Note that this has been solved for the time being by adding an option to the tailwind setup command to not install packages

dac09 commented 3 years ago

I think we need to extract the code that adds the post install script to the project:sync script too (see build test project script)