Skip to content

Commit

Permalink
make sure the plugin works with gts files correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Jul 20, 2023
1 parent 6f3964a commit 3cb8249
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/addon-dev/src/rollup-gjs-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3cb8249

Please sign in to comment.