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

addon-dev: incremental updates to output #1855

Merged
merged 1 commit into from
Sep 18, 2024

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! 🎉

packages/addon-dev/src/rollup-gjs-plugin.ts Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
packages/addon-dev/src/rollup-incremental-plugin.ts Outdated Show resolved Hide resolved
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()! 🤔

packages/addon-dev/src/rollup-incremental-plugin.ts Outdated Show resolved Hide resolved
packages/addon-dev/src/rollup-incremental-plugin.ts Outdated Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
packages/addon-dev/src/rollup-hbs-plugin.ts Show resolved Hide resolved
packages/addon-dev/src/rollup-incremental-plugin.ts Outdated Show resolved Hide resolved
packages/addon-dev/src/rollup-gjs-plugin.ts Show resolved Hide resolved
@patricklx patricklx requested a review from ef4 June 17, 2024 10:48
@patricklx patricklx force-pushed the improve-addon-clean branch 5 times, most recently from 0106e1e to 3b98560 Compare June 17, 2024 11:21
tests/scenarios/compat-stage2-test.ts Outdated Show resolved Hide resolved
@@ -73,6 +73,8 @@ appScenarios
exclude: ['**/-excluded/**/*'],
}),

addon.clean(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change in order required? If so, then this is clearly a breaking change!

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 think it is. I need to revalidate

Copy link
Collaborator

Choose a reason for hiding this comment

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

Any news on this @patricklx?

With ~250 addons in our monorepo (not all v2 though), I'd rather not have to write a codemod to change the order! 😏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi @simonihmig I reverted the change and the tests passed. (other unrelated failed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hold that, i forgot one, lets see

Copy link
Collaborator

Choose a reason for hiding this comment

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

There was a timeout in one test job. I restarted and it is all green now! 🎉

Thanks for getting back to this, I think this revert is helpful, as it shows we are not introducing breaking changes here!

tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
tests/scenarios/v2-addon-dev-watch-test.ts Outdated Show resolved Hide resolved
@mansona mansona removed their request for review July 29, 2024 14:45
@AskerFED
Copy link

image

I have faced the ENOENT error for the addon.clean() which triggers file deletion event while rollup watch but it is not build stopping issue just error thrown and started build once dist was replaced. After @NullVoxPopuli suggestion to try this addon-dev branch now ENOENT error resolved. But the below warning is shown but is harmless I guess...

image

@patricklx patricklx requested review from ef4 and mansona August 7, 2024 07:44
@@ -14,11 +13,10 @@ export default function rollupGjsPlugin(
return {
name: PLUGIN_NAME,

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

Choose a reason for hiding this comment

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

@ef4 I noticed that now the gjs plugin must come before the babel plugin in the rollup config. That would make this a breaking change

@@ -12,6 +12,10 @@ export default function rollupHbsPlugin({
return {
name: 'rollup-hbs-plugin',
async resolveId(source: string, importer: string | undefined, options) {
let hbsFilename = source.replace(/\.\w{1,3}$/, '') + '.hbs';
if (hbsFilename !== source) {
this.addWatchFile(hbsFilename);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ef4 I had to add addWatchFile to all 3 methods to get this to work correctly on windows

@ef4
Copy link
Contributor

ef4 commented Aug 20, 2024

This is hard for me to follow. Can we take advantage of the cleanup that has happened in the vite hbs plugin to use the same patterns here?

@patricklx
Copy link
Contributor Author

patricklx commented Aug 21, 2024

This is hard for me to follow. Can we take advantage of the cleanup that has happened in the vite hbs plugin to use the same patterns here?

I updated the hbs plugin to be similar to the one in vite hbs.
only a with a few changes. there is no generic extension search setup, it could be setup with @rollup/plugin-node-resolve
I added the extension search for .hbs extension in the hbs plugin.

also added the addWatchFile calls to get tests working

}
}

let syntheticId = needsSyntheticComponentJS(source, resolution.id);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we do not have a packageCache here

@@ -63,6 +63,7 @@ export default function rollupHbsPlugin({
let syntheticId = needsSyntheticComponentJS(source, resolution.id);
if (syntheticId) {
this.addWatchFile(source);
this.addWatchFile(syntheticId);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this change did not work @ef4 .
I think transform does have its own specific cache.
https://rollupjs.org/plugin-development/#transform

let syntheticId = needsSyntheticComponentJS(source, resolution.id, resolverLoader.resolver.packageCache);
if (syntheticId) {
let syntheticId = needsSyntheticComponentJS(source, resolution.id);
if (syntheticId && isInComponents(resolution.id, resolverLoader.resolver.packageCache)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ef4 is this okay like this?

@patricklx patricklx changed the title improve addon-dev clean addon-dev: incremental updates to output Sep 4, 2024
@mansona mansona dismissed their stale review September 18, 2024 08:28

no longer my PR :)

@ef4 ef4 merged commit 2e5e933 into embroider-build:main Sep 18, 2024
152 checks passed
@github-actions github-actions bot mentioned this pull request Sep 18, 2024
patricklx added a commit to patricklx/embroider that referenced this pull request Sep 20, 2024
patricklx added a commit to patricklx/embroider that referenced this pull request Sep 20, 2024
@mansona mansona added the enhancement New feature or request label Sep 23, 2024
ef4 added a commit that referenced this pull request Sep 24, 2024
…-to-output

backport #1855 addon-dev: incremental updates to output
@github-actions github-actions bot mentioned this pull request Sep 24, 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.

6 participants