Commit 854d498
authored
fix(compiler): fix typedef file generated for dist-custom-elements (#3468)
This fixes the typedef file generated for the `index.js` file produced
by `dist-custom-elements`. Previously it was mistakenly assuming that
the path to a component's `d.ts` file could be generated on the basis of
the `tag` set on the component. This _is_ the case if the component's
filename is equal to it's tag, but there is no requirement that that be
the case.
This changes the way that the relative path from
`${outputDir}/components/index.d.ts` to the `.d.ts` file for a specific
component is generated.
Previously we were doing something like:
```ts
${outputDir}/types/components/${component.tagName}/${component.tagName}
```
This doesn't work if a component is saved in
`src/components/button/button.tsx` but has a tag like `custom-button`.
So to fix this we can instead:
- find the relative path from the source root to the component, giving
us e.g. `components/button/button.tsx`
- join that relative path with the relative path from where `index.d.ts`
is going to be saved (`${outputDir}/components/index.d.ts`) to the
directory where types are written (e.g. `${outputDir}/types`)
This will give us an import in `index.d.ts` that looks like:
```ts
export { Button as CustomButton } from '../types/components/button/button.tsx';
```1 parent b9fbe85 commit 854d498
3 files changed
Lines changed: 22 additions & 7 deletions
File tree
- src/compiler/output-targets
- dist-custom-elements
- test
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| |||
Lines changed: 12 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
35 | 42 | | |
| 43 | + | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
| |||
47 | 55 | | |
48 | 56 | | |
49 | 57 | | |
50 | | - | |
| 58 | + | |
51 | 59 | | |
52 | 60 | | |
53 | | - | |
54 | | - | |
| 61 | + | |
| 62 | + | |
55 | 63 | | |
56 | 64 | | |
57 | 65 | | |
| |||
0 commit comments