From 3cb8249a26af12cfbf356407c417bc6fbdc5e523 Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Thu, 20 Jul 2023 11:48:24 -0700 Subject: [PATCH] make sure the plugin works with gts files correctly --- packages/addon-dev/src/rollup-gjs-plugin.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/addon-dev/src/rollup-gjs-plugin.ts b/packages/addon-dev/src/rollup-gjs-plugin.ts index 4fb5d9fa2..273f0f40b 100644 --- a/packages/addon-dev/src/rollup-gjs-plugin.ts +++ b/packages/addon-dev/src/rollup-gjs-plugin.ts @@ -51,17 +51,29 @@ function getMeta(context: PluginContext, id: string): Meta | null { } } -const gjsFilter = createFilter('**/*.gjs'); +const gjsFilter = createFilter('**/*.g{j,t}s'); function maybeRewriteGJS(resolution: ResolvedId) { if (!gjsFilter(resolution.id)) { return null; } - // This creates an `*.gjs.js` that we will populate in `load()` hook. + let id; + + if (resolution.id.endsWith('.gjs')) { + id = resolution.id.replace(/\.gjs$/, '.js'); + } else if (resolution.id.endsWith('.gts')) { + id = resolution.id.replace(/\.gts$/, '.ts'); + } else { + throw new Error( + 'Unexpected issues in the plugin-rollup-gjs - an unexpected file made its way throught the pluginUtils filter' + ); + } + + // This creates an `*.js` or `*.ts` that **replaces** the .gjs or .gts file that we will populate in `load()` hook. return { ...resolution, - id: resolution.id.replace(/\.gjs$/, '') + '.js', + id, meta: { [PLUGIN_NAME]: { originalId: resolution.id,