Skip to content

Commit

Permalink
feat(compile route templates): skip template-colocation-plugin for ro…
Browse files Browse the repository at this point in the history
…ute templates
  • Loading branch information
BlueCutOfficial committed Mar 27, 2024
1 parent 894d238 commit 3718cf3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/shared-internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"typescript-memoize": "^1.0.1",
"fs-extra": "^9.1.0",
"lodash": "^4.17.21",
"minimatch": "^3.0.4",
"semver": "^7.3.5"
},
"devDependencies": {
Expand All @@ -47,6 +48,7 @@
"@types/fs-extra": "^9.0.12",
"@types/lodash": "^4.14.170",
"@types/js-string-escape": "^1.0.0",
"@types/minimatch": "^3.0.4",
"@types/semver": "^7.3.6",
"@types/tmp": "^0.1.0",
"fixturify": "^2.1.1",
Expand Down
14 changes: 14 additions & 0 deletions packages/shared-internals/src/template-colocation-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { dirname } from 'path';
import { explicitRelative, PackageCache } from '.';
import { ImportUtil } from 'babel-import-util';
import makeDebug from 'debug';
import minimatch from 'minimatch';
import { cleanUrl } from './paths';

const debug = makeDebug('embroider:template-colocation-plugin');
Expand Down Expand Up @@ -36,6 +37,14 @@ export interface Options {
// This option is used by Embroider itself to help with v1 addon
// compatibility, other users should probably not use it.
templateExtensions?: string[];

// Default to []
//
// Skip the plugin for files that match the specified globs.
//
// This option is used to prevent the plugin to transform the
// compiled output of hbs files that are not colocated components.
exclude?: string[];
}

interface State {
Expand Down Expand Up @@ -66,6 +75,11 @@ export default function main(babel: typeof Babel) {
}
}

if (state.opts.exclude?.some(glob => minimatch(filename, glob))) {
debug('not handling colocation for %s', filename);
return;
}

debug('handling colocation for %s', filename);
let extensions = state.opts.templateExtensions ?? ['.hbs'];
for (let ext of extensions) {
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/scenarios/v2-addon-dev-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ appScenarios
'babel.config.json': `
{
"plugins": [
"@embroider/addon-dev/template-colocation-plugin",
["@embroider/addon-dev/template-colocation-plugin", {
exclude: ['**/just-a-template.js'],
}],
"@babel/plugin-transform-class-static-block",
["babel-plugin-ember-template-compilation", {
targetFormat: 'hbs',
Expand Down Expand Up @@ -286,9 +288,7 @@ appScenarios
expectFile(
'dist/components/demo/just-a-template.js'
).equalsCode(`import { precompileTemplate } from '@ember/template-compilation';
import { setComponentTemplate } from '@ember/component';
var TEMPLATE = precompileTemplate("<p>I am not a component but a template.</p>");
var justATemplate = setComponentTemplate(TEMPLATE, precompileTemplate("<p>I am not a component but a template.</p>"));
var justATemplate = precompileTemplate("<p>I am not a component but a template.</p>");
export { justATemplate as default };
//# sourceMappingURL=just-a-template.js.map`);
});
Expand Down

0 comments on commit 3718cf3

Please sign in to comment.