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

Clear dist only when the new files are ready #578

Closed
etienne-dldc opened this issue Mar 11, 2020 · 4 comments
Closed

Clear dist only when the new files are ready #578

etienne-dldc opened this issue Mar 11, 2020 · 4 comments
Labels
kind: feature New feature or request PR welcome scope: integration Related to an integration, not necessarily to core (but could influence core) scope: upstream Issue in upstream dependency solution: duplicate This issue or pull request already exists solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved topic: monorepo Related to Lerna monorepos

Comments

@etienne-dldc
Copy link
Contributor

Current Behavior

When working with a monorepo or with linked package if your package was build and you have another bundler using the files in dist. If you either build or start the compilation it will start by deleting the content of dist which does not make bundler happy. In most cases you have to restart the bundler.

Example:

Let say you have two packages app is a create-react-app and b is using tsdx. app is using b.

You build the b package, then start working on app (react-scripts start in app). But then you need to change something in b so you change some file then build b (tsdx build in b) at that point react-scripts will crash because one file is missing and it will not recover even when the file are back. You have to restart app to make it work again.

Desired Behavior

When tsdx build is run, it would be nice if the dist folder was not cleared until the next build output is ready. This way react-scripts and other bundlers would not fail.

Suggested Solution

I guess it should be possible to build to a temp directory then move the files at the end.

Who does this impact? Who is this for?

People working with Monorepo or with linked packages.

Describe alternatives you've considered

Just restart the script when it fail but it's annoying...

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 11, 2020

Hmmm, looking at clean-webpack-plugin's code, this is actually somewhat involved -- it tracks the difference between previous output and current output and deletes stale output.

Maybe we can do something less involved by just deleting everything other than the current output. That would work for an initial build too, not just watch.

Notably tracking wouldn't fully work for certain features -- like setting useTsconfigDeclarationDir makes rpts2 pass the emit step to TS, meaning that declarations are created out-of-band and therefore not tracked by Rollup.

Existing plugins like rollup-plugin-delete (probably has the most options out of it, rollup-plugin-clean, rollup-plugin-cleaner) don't do any tracking and so aren't much different from what TSDX currently does. Would basically have to make a new plugin


You can also disable cleaning with --noClean if that helps as a workaround

@agilgur5 agilgur5 added kind: feature New feature or request scope: integration Related to an integration, not necessarily to core (but could influence core) labels Mar 11, 2020
@etienne-dldc
Copy link
Contributor Author

Um, I didn't knew about --noClean... Any reason it's not a default on watch command ?

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 14, 2020

I think that's more to do that this exists as a workaround for this issue, see #282 and #272 . This seems actually to be a duplicate of #260, which should be renamed for clarity

--noClean does create potential for there to be stale build artifacts left in your dist/ directory, e.g. assets that were later removed or changed.
That would mean, for instance, if you had a dev server serving those assets, they would continue to be served even after removal from the build, as the folder hadn't been cleared.

@agilgur5 agilgur5 added solution: duplicate This issue or pull request already exists PR welcome scope: upstream Issue in upstream dependency topic: monorepo Related to Lerna monorepos and removed PR welcome labels Mar 14, 2020
@etienne-dldc
Copy link
Contributor Author

Closing this because the --noClean option works for my use case.

@agilgur5 agilgur5 added the solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved label Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request PR welcome scope: integration Related to an integration, not necessarily to core (but could influence core) scope: upstream Issue in upstream dependency solution: duplicate This issue or pull request already exists solution: unresolved Issue has been closed by OP but root cause has not necessarily been resolved topic: monorepo Related to Lerna monorepos
Projects
None yet
Development

No branches or pull requests

2 participants