Skip to content

Commit

Permalink
Merge pull request #2136 from embroider-build/fix-addon-dev-gjs-order
Browse files Browse the repository at this point in the history
Enforce correct plugin order in addon-dev
  • Loading branch information
simonihmig authored Oct 8, 2024
2 parents d67c9ef + 8f53b7a commit 1ac0d49
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
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(),
addon.gjs(),
addon.publicAssets('custom-public'),
addon.clean(),
],
};
Expand Down

0 comments on commit 1ac0d49

Please sign in to comment.