Skip to content

Commit

Permalink
Merge pull request #1007 from dcyriller/pods-components
Browse files Browse the repository at this point in the history
Fix exclusion of the hbs file of the pod components when `podModulePrefix === ''`
  • Loading branch information
ef4 authored Oct 19, 2021
2 parents 1c4d39c + b5f3a80 commit 82cb439
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 3 deletions.
89 changes: 89 additions & 0 deletions packages/compat/tests/template-colocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,92 @@ describe('template colocation with staticComponents', function () {
assertFile.get(['ember-addon', 'implicit-modules']).equals(undefined);
});
});

describe('not to be confused with the pod component', function () {
jest.setTimeout(120000);
let expectFile: ExpectFile;
let build: BuildResult;
let app: Project;

throwOnWarnings();

beforeAll(async function () {
app = Project.emberNew();

merge(app.files, {
config: {
'environment.js': `module.exports = function(environment) {
let ENV = {
modulePrefix: 'my-app',
podModulePrefix: '',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
},
EXTEND_PROTOTYPES: {
Date: false
}
},
APP: {}
};
return ENV;
};`,
},
app: {
templates: {
'index.hbs': `
<PodComponent />
<TemplateOnly />
`,
},
components: {
'pod-component': {
'component.js': `
import Component from '@glimmer/component';
export default class extends Component {}
`,
'template.hbs': `<div>{{this.title}}</div>`,
},
'template-only': {
'template.hbs': `<div>I am template only</div>`,
},
},
},
});

let options: Options = {
// our tests are going to check for how the components get implicitly
// included, so this must be false.
staticComponents: false,
};

build = await BuildResult.build(app, {
stage: 2,
type: 'app',
emberAppOptions: {
tests: false,
},
embroiderOptions: options,
});
expectFile = expectFilesAt(build.outputPath);
});

afterAll(async function () {
await build.cleanup();
});

test(`app's pod components and templates are implicitly included correctly`, function () {
let assertFile = expectFile('assets/my-app.js');
assertFile.matches(
/d\(["']my-app\/components\/pod-component\/component["'], function\(\)\s*\{\s*return i\(["']\.\.\/components\/pod-component\/component\.js['"]\);\}\)/
);
assertFile.matches(
/d\(["']my-app\/components\/pod-component\/template["'], function\(\)\s*\{\s*return i\(["']\.\.\/components\/pod-component\/template\.hbs['"]\);\}\)/
);
assertFile.matches(
/d\(["']my-app\/components\/template-only\/template["'], function\(\)\s*\{\s*return i\(["']\.\.\/components\/template-only\/template\.hbs['"]\);\s*\}/
);
});
});
6 changes: 3 additions & 3 deletions packages/core/src/app-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class AppFiles {
continue;
}

// hbs files are resolvable, but not when they're inside the components
// directory (where they are used for colocation only)
if (relativePath.startsWith('components/')) {
if (!relativePath.endsWith('.hbs')) {
// hbs files are resolvable, but not when they're inside the components
// directory and used for colocation
if (!relativePath.endsWith('.hbs') || relativePath.endsWith('/template.hbs')) {
components.push(relativePath);
}
continue;
Expand Down

0 comments on commit 82cb439

Please sign in to comment.