Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate .js component stubs for .ts components #1273

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/compat/src/synthesize-template-only-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ export default templateOnlyComponent();`;

const templateExtension = '.hbs';

// we don't need to worry about all resolvable extensions in here (like .ts)
// because by the time we see the code it has already been preprocessed down to
// js.
const jsExtension = '.js';
const jsExtensions = ['.js', '.ts', '.mjs', '.mts'];

export default class SynthesizeTemplateOnlyComponents extends Plugin {
private emitted = new Set() as Set<string>;
Expand Down Expand Up @@ -59,14 +56,17 @@ export default class SynthesizeTemplateOnlyComponents extends Plugin {
}

function crawl(dir: string) {
let needed = new Set<string>();
let seen = new Set<string>();
const needed = new Set<string>();
const seen = new Set<string>();
if (pathExistsSync(dir)) {
for (let file of walkSync(dir, { directories: false })) {
if (file.endsWith(templateExtension)) {
needed.add(file.slice(0, -1 * templateExtension.length));
} else if (file.endsWith(jsExtension)) {
seen.add(file.slice(0, -1 * jsExtension.length));
} else {
const jsExtension = jsExtensions.find(ext => file.endsWith(ext));
if (jsExtension) {
seen.add(file.slice(0, -1 * jsExtension.length));
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/scenarios/compat-template-colocation-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let scenarios = appScenarios.map('compat-template-colocation', app => {
templates: {
'index.hbs': `
<HasColocatedTemplate />
<HasColocatedTSTemplate />
<TemplateOnlyComponent />
`,
},
Expand All @@ -27,6 +28,11 @@ let scenarios = appScenarios.map('compat-template-colocation', app => {
export default class extends Component {}
`,
'has-colocated-template.hbs': `<div>{{this.title}}</div>`,
'has-colocated-ts-template.ts': `
import Component from '@glimmer/component';
export default class extends Component {}
`,
'has-colocated-ts-template.hbs': `<div>{{this.title}}</div>`,
'template-only-component.hbs': `<div>I am template only</div>`,
},
},
Expand Down Expand Up @@ -112,6 +118,11 @@ scenarios
);
});

test(`app's colocated TS component is NOT synthesized`, function () {
let assertFile = expectFile('components/has-colocated-ts-template.js');
assertFile.doesNotExist('component stub was not created');
});

test(`app's colocated components are implicitly included correctly`, function () {
let assertFile = expectFile('assets/my-app.js');
assertFile.matches(
Expand Down