From 93da6dfe9e0777218fb5e64224b801c8b3316b55 Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Wed, 2 Oct 2024 13:37:18 +0200 Subject: [PATCH 1/3] Align rollup plugin order in tests to blueprint --- tests/scenarios/v2-addon-dev-test.ts | 14 +++++++++----- tests/scenarios/v2-addon-dev-watch-test.ts | 11 ++++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) 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(), ], }; From 37fa5f470d9f15c1bd25f3e9446ae106f7c611be Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Wed, 2 Oct 2024 15:12:33 +0200 Subject: [PATCH 2/3] Enforce running the gjs transform before any others --- packages/addon-dev/src/rollup-gjs-plugin.ts | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) 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, + }; + }, }, }; } From 8f53b7adadd86fd4afac00dcde2c511ad979d099 Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Wed, 2 Oct 2024 15:19:44 +0200 Subject: [PATCH 3/3] Enforce running the hbs transform before any others --- packages/addon-dev/src/rollup-hbs-plugin.ts | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) 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); + }, }, }; }