Skip to content

Commit 3a050ee

Browse files
authored
fix(build): stop dts emit leaking @commercetools-frontend/ui-kit into published types (#3254)
* fix(build): stop dts emit leaking @commercetools-frontend/ui-kit into published types The compound components (Constraints, RadioInput, ViewSwitcher) emitted import("@commercetools-frontend/ui-kit").T...Props in their published .d.ts. Strict consumers installing only the granular @commercetools-uikit/* packages don't have the aggregate preset, so the reference resolved to any (TS7006). Root cause: @commercetools-frontend/ui-kit is a root devDependency (so the .visualroute/bundlespec fixtures resolve under strict pnpm), which makes the bare specifier resolvable during preconstruct's declaration emit, and TS prefers it over the in-package relative path. The build now hides that symlink for the preconstruct build step only (trap-guarded restore), forcing the correct relative specifier. No component API or source changed. Refs: commercetools/identity#757 * build: assert no aggregate-preset leak in emitted declarations Add a post-emit regression guard to scripts/build.sh that fails the build if any granular package's published declarations reference the aggregate @commercetools-frontend/ui-kit preset by its bare specifier. Future-proofs the FEC-938 declaration-emit workaround against being dropped, preconstruct changing resolution, or a new compound component reintroducing the pattern. Also reword the changeset to be consumer-facing.
1 parent bd4ccb7 commit 3a050ee

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@commercetools-uikit/constraints": patch
3+
"@commercetools-uikit/radio-input": patch
4+
"@commercetools-uikit/view-switcher": patch
5+
---
6+
7+
fix: correct leaked type references in `Constraints`, `RadioInput`, and `ViewSwitcher` declarations
8+
9+
Their published `.d.ts` referenced the aggregate `@commercetools-frontend/ui-kit`
10+
package, which isn't installed when you depend only on the granular
11+
`@commercetools-uikit/*` packages. That unresolved reference collapsed the
12+
affected prop types to `any`, surfacing as `TS7006` errors in strict
13+
TypeScript setups. The declarations now use in-package relative references, so
14+
the prop types resolve correctly. No component API or runtime behavior changed.

scripts/build.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,49 @@ pnpm generate-icons
66
pnpm design-tokens:build
77
pnpm compile-intl
88

9+
# --- declaration-emit leak workaround (FEC-938) ---
10+
# `@commercetools-frontend/ui-kit` (the aggregate preset) is a root
11+
# devDependency because the .visualroute/bundlespec fixtures import it. Under
12+
# strict pnpm that puts a `node_modules/@commercetools-frontend/ui-kit` symlink
13+
# in place, and preconstruct's declaration emit then prefers that resolvable
14+
# bare specifier over the in-package relative path — leaking
15+
# `import("@commercetools-frontend/ui-kit").T...Props` into the published .d.ts
16+
# of the compound components (constraints, radio-input, view-switcher). Strict
17+
# consumers can't resolve it, so those prop types collapse to `any`.
18+
#
19+
# preconstruct does not need that symlink (the fixtures aren't part of the dts
20+
# program), so we hide it during the build to force the correct relative
21+
# specifier, and restore it afterwards (and on any exit).
22+
META_SYMLINK="node_modules/@commercetools-frontend/ui-kit"
23+
META_SYMLINK_TARGET=""
24+
restore_meta_symlink() {
25+
if [ -n "$META_SYMLINK_TARGET" ] && [ ! -e "$META_SYMLINK" ]; then
26+
ln -s "$META_SYMLINK_TARGET" "$META_SYMLINK"
27+
fi
28+
}
29+
if [ -L "$META_SYMLINK" ]; then
30+
META_SYMLINK_TARGET="$(readlink "$META_SYMLINK")"
31+
trap restore_meta_symlink EXIT
32+
rm "$META_SYMLINK"
33+
fi
34+
935
pnpm preconstruct build
1036

37+
restore_meta_symlink
38+
trap - EXIT
39+
40+
# Regression guard: assert the leak stays gone. No granular package's emitted
41+
# declarations should reference the aggregate `@commercetools-frontend/ui-kit`
42+
# preset by its bare specifier — strict consumers can't resolve it (see above).
43+
# Catches a future reintroduction (workaround dropped, preconstruct resolution
44+
# change, a new compound component). Excludes the preset's own dist.
45+
leaks="$(find packages -type d -name declarations -path '*/dist/*' -prune -exec grep -rl 'import("@commercetools-frontend/ui-kit")' {} + 2>/dev/null || true)"
46+
if [ -n "$leaks" ]; then
47+
echo "ERROR: published declarations leak the @commercetools-frontend/ui-kit aggregate preset:" >&2
48+
echo "$leaks" | sed 's/^/ - /' >&2
49+
echo "See the FEC-938 declaration-emit workaround above in scripts/build.sh." >&2
50+
exit 1
51+
fi
52+
# --- end workaround ---
53+
1154
pnpm --filter @commercetools-frontend/ui-kit run copy-assets

0 commit comments

Comments
 (0)