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

improve addon-dev clean #1855

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

patricklx
Copy link
Contributor

@patricklx patricklx commented Mar 26, 2024

this now only updates changed files in dist. And deletes removed files in dist.
otherwise all files are deleted on each change, which makes HMR less useful

@patricklx patricklx force-pushed the improve-addon-clean branch 2 times, most recently from aa83374 to 3883ada Compare March 26, 2024 09:26
NullVoxPopuli
NullVoxPopuli previously approved these changes Apr 10, 2024
Copy link
Collaborator

@NullVoxPopuli NullVoxPopuli left a comment

Choose a reason for hiding this comment

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

Logically, it seems good.
Do we have any tests for this behavior? I don't remember: 😅

Copy link
Member

@mansona mansona left a comment

Choose a reason for hiding this comment

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

so one thing that I would like to do before we actually move forward on this is that we verify that this Plugin works correctly with the bug scenario that #1448 was originally trying to fix. Ideally we would cover this in the v2 addon dev watch tests

@patricklx
Copy link
Contributor Author

patricklx commented Apr 10, 2024

so one thing that I would like to do before we actually move forward on this is that we verify that this Plugin works correctly with the bug scenario that #1448 was originally trying to fix. Ideally we would cover this in the v2 addon dev watch tests

I think what this actually does now is more like a sync. When a file gets deleted in src, the corresponding generated file in dist also gets deleted.
there is the option runOnce https://github.com/vladshcherbin/rollup-plugin-delete?tab=readme-ov-file#runonce, which only deletes the files only once at start. Which is already better, but it leaves the deleted files during dev.

I think this also fixes the original issue. As long as files are copied as part of the bundle, by e.g emit, and not using manual copy. This will work correctly.

@NullVoxPopuli NullVoxPopuli dismissed their stale review April 29, 2024 14:43

can we add a test? I could not reproduce the issue that caused the need for this

@mansona
Copy link
Member

mansona commented Apr 29, 2024

I think this also fixes the original issue

The problem I have with this PR is that I want more confidence that it fixes the original issue before we move forward with it. Myself and @NullVoxPopuli tried to recreate the issue on the Triage meeting and we couldn't get it to fail so we can't tell if this makes any difference 🙃

I would really like a failing test that shows the problem in a repeatable way before we try to fix it by altering the underlying implementation. If this is not possible (because maybe it's an OS level race condition 🤷) then at the very least we need to coordinate with @simonihmig because he said he would be looking into the original issue over the next while: embroider-build/addon-blueprint#32 (comment)

@patricklx
Copy link
Contributor Author

I'm not sure how to add a test for this

@patricklx
Copy link
Contributor Author

@mansona i improved this even more and added some tests

@patricklx patricklx force-pushed the improve-addon-clean branch 3 times, most recently from 94f3ccb to f472a50 Compare May 6, 2024 07:54
Copy link
Collaborator

@simonihmig simonihmig left a comment

Choose a reason for hiding this comment

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

I tested this locally with a real project and yarn link. I found some minor issues, see inline comments. But the good part is that this seems to also fix some of the issues discussed in embroider-build/addon-blueprint#32 (comment).

The main issue I was hoping to get fixed by a revised clean plugin was the fact that an app watching the dist folder of an addon would often pick up changes as they were written but before the addon's rebuild has finished.
Leading to multiple app rebuilds, with the first ones often picking up interim build errors. Which would quickly go away, when the addon's rebuild has finished, but that's still annoying...

And testing this change here locally indeed seems to fix that issue! 🎉

@@ -14,11 +13,10 @@ export default function rollupGjsPlugin(
return {
name: PLUGIN_NAME,

load(id: string) {
transform(input: string, id: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change and the one on the hbs plugin are unrelated to the actual scope of the PR, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's required to have hbs pass through transform to have thrm incremental.

addon.publicEntrypoints(['components/**/*.js']),
addon.appReexports(['components/**/*.js']),
addon.publicEntrypoints(['components/**/*.{gts,js}']),
addon.appReexports(['components/**/*.{gts,js}']),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these changes needed? IIRC, the inputs to these plugin were meant to relate to the final output, which is always .js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, maybe it wasn't needed

},
generateBundle(options, bundle) {
if (existsSync(options.dir!)) {
const files = walkSync(options.dir!, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

any concerns about this file walking being potentially too expensive to do on every rebuild?

Copy link
Contributor Author

@patricklx patricklx May 6, 2024

Choose a reason for hiding this comment

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

It's required to delete files that are not part of the bundle. We could also do this with diffing between builds and only do a walkSync at start.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I improved this ti only walk once

for (const file of files) {
if (!bundle[file]) {
generatedAssets.delete(file);
rmSync(join(options.dir!, file));
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems watchChange provides us the information what files have changed or were deleted. Could we track these events and apply the syncing based on those, instead of the file diffing here?

Does that make any sense even? Not saying this is better or might not even work, just curious...

Copy link
Contributor Author

@patricklx patricklx May 6, 2024

Choose a reason for hiding this comment

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

generated assets with emitfile do not pass through transform/watchchange. So it's not detectable

// rollup already supports incremental transforms of files,
// this extends it to the dist files
clean() {
return clean();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we consider this a breaking change? If not, this PR could target the stable branch, not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we consider this breaking, we could still release this on stable as a minor version, by exposing this as a separate plugin, and updating the blueprint to use the new one instead of addon.clean()! 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants