Skip to content

Commit

Permalink
Merge pull request #1852 from patricklx/patch-14
Browse files Browse the repository at this point in the history
vite fix hbs loader for v1 addons
  • Loading branch information
ef4 authored Mar 26, 2024
2 parents bac2415 + 19ee8e9 commit 11f2c70
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/hbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async function maybeSynthesizeComponentJS(context: PluginContext, source: string
};
}

const hbsFilter = createFilter('**/*.hbs?(\\?)*');
const hbsFilter = createFilter('**/*.hbs?([?]*)');

function maybeRewriteHBS(resolution: ResolvedId) {
if (!hbsFilter(resolution.id)) {
Expand Down
102 changes: 101 additions & 1 deletion tests/scenarios/vite-app-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { viteAppScenarios } from './scenarios';
import { baseAddon, viteAppScenarios } from './scenarios';
import type { PreparedApp } from 'scenario-tester';
import QUnit from 'qunit';
import { exec } from 'child_process';
Expand All @@ -24,7 +24,107 @@ function execPromise(command: string): Promise<string> {

viteAppScenarios
.map('vite-app-basics', project => {
let addon = baseAddon();
addon.pkg.name = 'my-addon';
// setup addon that triggers packages/compat/src/hbs-to-js-broccoli-plugin.ts
addon.mergeFiles({
'index.js': `
module.exports = {
name: 'my-addon',
setupPreprocessorRegistry(type, registry) {
// we want custom ast transforms for own addon
if (type === 'parent') {
return;
}
const plugin = this._buildPlugin();
plugin.parallelBabel = {
requireFile: __filename,
buildUsing: '_buildPlugin',
params: {},
};
registry.add('htmlbars-ast-plugin', plugin);
},
_buildPlugin(options) {
return {
name: 'test-transform',
plugin: () => {
return {
name: "test-transform",
visitor: {
Template() {}
},
};
},
baseDir() {
return __dirname;
},
};
},
}
`,
app: {
components: {
'component-one.js': `export { default } from 'my-addon/components/component-one';`,
},
},
addon: {
components: {
'component-one.js': `
import Component from '@glimmer/component';
export default class ComponentOne extends Component {}
`,
'component-one.hbs': `component one template`,
},
},
});

project.addDevDependency(addon);

let addon2 = baseAddon();
addon2.pkg.name = 'my-addon2';
addon2.mergeFiles({
app: {
components: {
'component-two.js': `export { default } from 'my-addon2/components/component-two';`,
},
},
addon: {
components: {
'component-two.hbs': `component two template: "{{this}}"`,
},
},
});

project.addDevDependency(addon2);
project.mergeFiles({
tests: {
integration: {
'test-colocated-addon-component.js': `
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, rerender } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | component one template from addon', (hooks) => {
setupRenderingTest(hooks);
test('should have component one template from addon', async function (assert) {
await render(hbs\`
<ComponentOne></ComponentOne>
<ComponentTwo />
\`);
await rerender();
assert.dom().includesText('component one template');
assert.dom().includesText('component two template: ""');
assert.dom().doesNotIncludeText('export default precompileTemplate');
});
});
`,
},
},
app: {
adapters: {
'post.js': `
Expand Down
2 changes: 1 addition & 1 deletion tests/vite-app/tests/integration/example-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, click, rerender, settled } from '@ember/test-helpers';
import { render, rerender } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | Example', (hooks) => {
Expand Down

0 comments on commit 11f2c70

Please sign in to comment.