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

Optimize watched directories #623

Merged
merged 8 commits into from
Sep 12, 2024

Conversation

simonihmig
Copy link
Contributor

@simonihmig simonihmig commented May 2, 2024

With watchDependencies defined, eai is currently creating a WatchDir based on the package's root folder for handling imports of v2 addons.

The problem with this is that it will trigger a rebuild of the app when something changes outside of the folders where the actual importable files live in (which is in ./dist, assuming the conventional setup of v2 addons), most notably the ./src folder. This would make the app watcher fire multiple times in succession: once for the change in ./src, and later (when the rollup build has finished) for the change in ./dist. See also: embroider-build/embroider#1901

Instead of watching the whole package folder, this PR is looking at the package.json exports (if existing) as the source of truth for what is importable, and derives a minimal set of folders containing these files, which are as close as possible to these files. For example, when an addon has ./dist/components/foo.js and ./dist/components/bar.js as the only files covered by exports, this would make ./dist/components be the only folder being watched, ignoring any changes in e.g. ./src or ./declarations.

Note that I am only referring to ./src or ./dist as examples, the code has none of these hard-coded (with one exception, see inline-comment), but as said above derives everything from the package.json. So the change here should work also in v2 setups not following our conventional setup based on the blueprint.

This is one puzzle piece of fixing embroider-build/addon-blueprint#32. Again, I tested this in a local installation, and it did have the desired effect (when combined with the other PR): when changing only source files and not having the addon's build running in parallel, the app would not rebuild, as it would be expected.

@@ -0,0 +1,42 @@
diff --git a/node_modules/pkg-entry-points/.DS_Store b/node_modules/pkg-entry-points/.DS_Store

This comment was marked as resolved.

@simonihmig
Copy link
Contributor Author

simonihmig commented May 3, 2024

The failing test is a weird one: there is an unexpected file (./mod/index.js,) in the scenario-tester project that fails the test. However, this file seems to be generated in a different test suite here, so seems something is leaking here. And indeed, when running the watch-utils tests in isolation, they do pass! Or maybe I am missing something stupid, maybe some scenario-tester expert is able to chime in here?

@simonihmig simonihmig marked this pull request as ready for review May 3, 2024 14:03
@simonihmig simonihmig requested a review from a team May 3, 2024 14:03
@ef4
Copy link
Collaborator

ef4 commented May 7, 2024

Discussed in tooling meeting, this seems fine and can move ahead when it has passing tests.

@simonihmig
Copy link
Contributor Author

The failing test is a weird one: there is an unexpected file (./mod/index.js,) in the scenario-tester project that fails the test.

@mansona I think when we discussed this PR, you mentioned an issue about leaking stuff in scenario-tester that is being worked on. Has this been fixed meanwhile, or could you point me to an issue/PR I can track?

@mansona
Copy link
Member

mansona commented Jun 13, 2024

@simonihmig yes this would be included in this PR: embroider-build/scenario-tester#34 which was released in scenario-tester@4 embroider-build/scenario-tester#35

The underlying issue was in fixiturify project: stefanpenner/node-fixturify-project#87

@simonihmig
Copy link
Contributor Author

I see, thank you @mansona! So next step is getting us to 4.0.0 here, right?

This was only flagged a major because you could rely on the wrong behaviour that could break tests now, is that correct? Or any other things to be aware of?

@mansona
Copy link
Member

mansona commented Jun 13, 2024

I'm pretty sure that's the only notable change that is included in the major, there may be a few other type changes and one other API change but there is a 1-1 replacement if those changes are hit 👍 I think just trying it and working through should be good enough without too much other investigation

@simonihmig
Copy link
Contributor Author

Tried to upgrade scenario-tester to v4 today, but getting a good amount of TS errors:

image

We are on a very outdated version of TS here (4.3.5), probably we have to get us to some more recent version first!? 😔

@simonihmig simonihmig force-pushed the optimize-watched-directories branch from 2da1dd0 to de5f6e5 Compare September 10, 2024 15:45
@simonihmig
Copy link
Contributor Author

With updates to TS and scenario-tester merged and this one rebased, this is now finally having a green build! 🎉

Thus ready for a final review! cc @ef4 @mansona

package.json Outdated
@@ -13,6 +13,7 @@
"types/*"
],
"dependencies": {
"pkg-entry-points": "^1.0.2",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is in the wrong package.json?

@ef4 ef4 merged commit 73b6acd into embroider-build:main Sep 12, 2024
156 checks passed
@github-actions github-actions bot mentioned this pull request Sep 12, 2024
@simonihmig simonihmig added bug Something isn't working enhancement New feature or request and removed bug Something isn't working labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants