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

Enforce correct plugin order in addon-dev #2136

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/addon-dev/src/rollup-gjs-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ export default function rollupGjsPlugin(
return {
name: PLUGIN_NAME,

transform(input: string, id: string) {
if (!gjsFilter(id)) {
return null;
}
let code = processor.process(input, {
filename: id,
inline_source_map,
});
return {
code,
};
transform: {
// Enforce running the gjs transform before any others like babel that expect valid JS
order: 'pre',
handler(input: string, id: string) {
if (!gjsFilter(id)) {
return null;
}
let code = processor.process(input, {
filename: id,
inline_source_map,
});
return {
code,
};
},
},
};
}
Expand Down
26 changes: 15 additions & 11 deletions packages/addon-dev/src/rollup-hbs-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ export default function rollupHbsPlugin({
}
},

transform(code: string, id: string) {
let hbsFilename = id.replace(/\.\w{1,3}$/, '') + '.hbs';
if (hbsFilename !== id) {
this.addWatchFile(hbsFilename);
if (getMeta(this, id)?.type === 'template-only-component-js') {
this.addWatchFile(id);
transform: {
// Enforce running the hbs transform before any others like babel that expect valid JS
order: 'pre',
handler(code: string, id: string) {
let hbsFilename = id.replace(/\.\w{1,3}$/, '') + '.hbs';
if (hbsFilename !== id) {
this.addWatchFile(hbsFilename);
if (getMeta(this, id)?.type === 'template-only-component-js') {
this.addWatchFile(id);
}
}
}
if (!hbsFilter(id)) {
return null;
}
return hbsToJS(code);
if (!hbsFilter(id)) {
return null;
}
return hbsToJS(code);
},
},
};
}
Expand Down
14 changes: 9 additions & 5 deletions tests/scenarios/v2-addon-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,17 @@ appScenarios
exclude: ['**/-excluded/**/*'],
}),

addon.dependencies(),

babel({ babelHelpers: 'bundled', extensions: ['.js', '.hbs', '.gjs'] }),

addon.hbs({
excludeColocation: ['**/just-a-template.hbs'],
}),

addon.gjs(),
addon.dependencies(),
addon.publicAssets('public'),

babel({ babelHelpers: 'bundled', extensions: ['.js', '.hbs', '.gjs'] }),
addon.publicAssets('public'),

addon.clean(),
],
Expand Down Expand Up @@ -210,10 +213,11 @@ appScenarios
exclude: ['**/-excluded/**/*'],
}),

babel({ babelHelpers: 'bundled', extensions: ['.js', '.hbs', '.gjs'] }),

addon.hbs(),
addon.publicAssets('public', { namespace: '' }),

babel({ babelHelpers: 'bundled', extensions: ['.js', '.hbs', '.gjs'] }),
addon.publicAssets('public', { namespace: '' }),

addon.clean(),
],
Expand Down
11 changes: 8 additions & 3 deletions tests/scenarios/v2-addon-dev-watch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ Scenarios.fromProject(() => baseV2Addon())

plugins: [
addon.publicEntrypoints(['components/**/*.js']),

addon.appReexports(['components/**/*.js']),
addon.gjs(),
addon.hbs(),

addon.dependencies(),
addon.publicAssets('custom-public'),

babel({ babelHelpers: 'bundled' }),

addon.hbs(),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think babel must be the last. whats the issue with the order?

Copy link
Contributor

@patricklx patricklx Oct 2, 2024

Choose a reason for hiding this comment

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

ah, I see, thats how the blueprint is.
But the recent PR changed hbs & gjs plugins to use transform hook. So the order of the blueprint must be changed.
the tests in embroider were already at correct order before the change... I wonder why it wasnt the same order in the blueprint

Copy link
Contributor

@patricklx patricklx Oct 2, 2024

Choose a reason for hiding this comment

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

looks like the PR i did was more of a breaking change then?
ah, but it was included into a breaking release anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, exactly. It should have at least a notice on the breaking change in the changelog. But I think it could be fixed maybe, trying this out in this draft PR! Will ping you once I'm ready.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, the blueprint should really have the babel plugin as last.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@patricklx ready to go now, see the PR description!

well, the blueprint should really have the babel plugin as last.

We can still decide to make that change in the blueprint if we feel this is the safer path forward. But the change in this PR makes this optional, which I think is better than forcing this on users by running into build errors...


addon.gjs(),

addon.publicAssets('custom-public'),

addon.clean(),
],
};
Expand Down