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

Fix declarations plugin to cover import() #2217

Merged
merged 1 commit into from
Dec 19, 2024
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
6 changes: 5 additions & 1 deletion packages/addon-dev/src/rollup-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@ async function fixDeclarationsInMatchingFiles(dir: string) {
// Strip any .gts extension from imports in d.ts files, as these won't resolve. See https://github.com/typed-ember/glint/issues/628
// Once Glint v2 is available, this shouldn't be needed anymore.
function fixDeclarations(content: string) {
return content.replace(/from\s+['"]([^'"]+)\.gts['"]/g, `from '$1'`);
return content
.replace(/from\s+'([^']+)\.gts'/g, `from '$1'`)
.replace(/from\s+"([^"]+)\.gts"/g, `from '$1'`)
.replace(/import\("([^"]+)\.gts"\)/g, `import('$1')`)
.replace(/import\('([^']+)\.gts'\)/g, `import('$1')`);
}
7 changes: 7 additions & 0 deletions packages/addon-dev/tests/declarations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const projectBoilerplate = {
'tsconfig.json': JSON.stringify({
include: ['src/**/*'],
compilerOptions: {
target: 'es2022',
module: 'esnext',
declaration: true,
declarationDir: 'declarations',
emitDeclarationOnly: true,
Expand Down Expand Up @@ -90,6 +92,10 @@ describe('declarations', function () {
import bar from './bar.gts';
import baz from './baz.ts';
export { foo, bar, baz };

export class Foo {
bar = import('./bar.gts')
}
`,
'foo.gts': 'export default 123',
'bar.gts': 'export default 234',
Expand All @@ -108,5 +114,6 @@ describe('declarations', function () {
expect(output).toContain(`import foo from './foo';`);
expect(output).toContain(`import bar from './bar';`);
expect(output).toContain(`import baz from './baz.ts';`);
expect(output).toContain(`import('./bar')`);
});
});
Loading