Skip to content

Commit

Permalink
Merge pull request #2217 from embroider-build/fix-declarations-import-fn
Browse files Browse the repository at this point in the history
Fix declarations plugin to cover import()
  • Loading branch information
ef4 authored Dec 19, 2024
2 parents 0fc9d1e + 9d4c2a8 commit 40e69d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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')`);
});
});

0 comments on commit 40e69d5

Please sign in to comment.