diff --git a/packages/addon-dev/src/rollup-gjs-plugin.ts b/packages/addon-dev/src/rollup-gjs-plugin.ts index 375f9dce5..8dc5e34a5 100644 --- a/packages/addon-dev/src/rollup-gjs-plugin.ts +++ b/packages/addon-dev/src/rollup-gjs-plugin.ts @@ -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, + }; + }, }, }; } diff --git a/packages/addon-dev/src/rollup-hbs-plugin.ts b/packages/addon-dev/src/rollup-hbs-plugin.ts index a0841511b..0dce20c2b 100644 --- a/packages/addon-dev/src/rollup-hbs-plugin.ts +++ b/packages/addon-dev/src/rollup-hbs-plugin.ts @@ -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); + }, }, }; } diff --git a/tests/scenarios/v2-addon-dev-test.ts b/tests/scenarios/v2-addon-dev-test.ts index 52d6ad05b..a488869a1 100644 --- a/tests/scenarios/v2-addon-dev-test.ts +++ b/tests/scenarios/v2-addon-dev-test.ts @@ -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(), ], @@ -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(), ], diff --git a/tests/scenarios/v2-addon-dev-watch-test.ts b/tests/scenarios/v2-addon-dev-watch-test.ts index e57bd905d..6c18e91eb 100644 --- a/tests/scenarios/v2-addon-dev-watch-test.ts +++ b/tests/scenarios/v2-addon-dev-watch-test.ts @@ -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(), ], };