`addon.declarations()` strip off `.gts` in import paths and produces incomplete declarations
Snippet from my index.ts file in a v2/vite addon, as per typed-ember/glint#628
// src/index.ts
export { default as Popover } from './components/popover.gts';
export { default as popover } from './helpers/popover.ts';
Extensions are included for the import paths. Transpiling to js in dist works just fine.
But my declarations are broken, using rollup --config:
// rollup.config.mjs
const configs = {
babel: resolve(import.meta.dirname, './babel.publish.config.mjs'),
ts: resolve(import.meta.dirname, './tsconfig.publish.json')
};
export default {
output: addon.output(),
plugins: [
// ... snip
// Emit .d.ts declaration files
// apparently, running glint this way does something other than running
// glint itself on the CLI. Manually running it generates the types
// appropriately. Running it as param here will produce broken declarations
// It strips the `.gts` from the imports.
addon.declarations('declarations', `glint --declaration --project ${configs.ts}`),
]
};
Here is the output:
// declarations/index.d.ts
export { default as Popover } from './components/popover';
export { default as popover } from './helpers/popover.ts';
So I tried running glint --declaration --project tsconfig.publish.json manually... and this is the result:
// declarations/index.d.ts
export { default as Popover } from './components/popover.gts';
export { default as popover } from './helpers/popover.ts';
Huh?
At this point I dunno what is happening 😵💫
I did this: addon.declarations('declarations', 'which glint')
That assured me, the glint from node_modules in the package is used.
Workaround
As a workaround, comment out addon.declarations() and move it to package.json:
{
"scripts": {
"build": "pnpm run '/^build:.*/'",
"build:js": "rollup --config",
"build:declarations": "glint --declaration --project tsconfig.publish.json",
}
}
Are you using addon-dev latest? Only latest supports specifying the project
Ah, deps used:
{
"devDependencies": {
"@embroider/addon-dev": "^8.1.0",
"@glint/core": "^2.0.0-alpha.3",
"@glint/environment-ember-loose": "^2.0.0-alpha.3",
"@glint/environment-ember-template-imports": "^2.0.0-alpha.3",
"@glint/template": "^1.6.0-alpha.2",
}
}
That's the reason: https://github.com/embroider-build/embroider/blob/48261fc415b2ca2444b1743bf6189c4bfc82a8c0/packages/addon-dev/src/rollup-declarations.ts#L78-L84
Alternatively: https://github.com/typed-ember/glint/blob/8b0442e9cc6b43db9214926c94db7193568cc43c/packages/core/src/cli/run-volar-tsc.ts#L12-L14
I think these two are incompatible to each other right now?
Ye, i think fix declarations is only needed for glint v1