Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(core): add convenience subpath exports for Heading, Code, HStack, VStack (#2420)

Cindy Zhang3f1c99e0d1fe
diff --git a/packages/cli/src/lib/component-discovery.mjs b/packages/cli/src/lib/component-discovery.mjs
index 5f59403fca..0c6c01e4f5 100644
--- a/packages/cli/src/lib/component-discovery.mjs
+++ b/packages/cli/src/lib/component-discovery.mjs
@@ -270,20 +270,26 @@ export function findComponentSource(coreDir, name) {
*/
export function resolveImportPath(coreDir, componentName) {
const srcDir = path.join(coreDir, 'src');
+ const pkgPath = path.join(coreDir, 'package.json');
+ const pkg = fs.existsSync(pkgPath)
+ ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
+ : null;
+
+ // Priority 1: exact subpath export matching the component name (e.g. ./Heading)
+ // This allows convenience re-export directories to win over the source directory.
+ if (pkg?.exports?.[`./${componentName}`]) {
+ return `@xds/core/${componentName}`;
+ }
+
const sourcePath = findComponentSource(coreDir, componentName);
if (!sourcePath) return '@xds/core';
- // Get the top-level directory under src/ from the source path
+ // Priority 2: subpath export matching the top-level source directory
const relToSrc = path.relative(srcDir, sourcePath);
const topDir = relToSrc.split(path.sep)[0];
- // Check package.json exports for ./${topDir}
- const pkgPath = path.join(coreDir, 'package.json');
- if (fs.existsSync(pkgPath)) {
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
- if (pkg.exports && pkg.exports[`./${topDir}`]) {
- return `@xds/core/${topDir}`;
- }
+ if (pkg?.exports?.[`./${topDir}`]) {
+ return `@xds/core/${topDir}`;
}
return '@xds/core';
diff --git a/packages/core/package.json b/packages/core/package.json
index 4e6fcc642e..fa03b7b66a 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -163,6 +163,11 @@
"types": "./dist/ClickableCard/index.d.ts",
"default": "./dist/ClickableCard/index.js"
},
+ "./Code": {
+ "source": "./src/Code/index.ts",
+ "types": "./dist/Code/index.d.ts",
+ "default": "./dist/Code/index.js"
+ },
"./CodeBlock": {
"source": "./src/CodeBlock/index.ts",
"types": "./dist/CodeBlock/index.d.ts",
@@ -238,6 +243,16 @@
"types": "./dist/Grid/index.d.ts",
"default": "./dist/Grid/index.js"
},
+ "./HStack": {
+ "source": "./src/HStack/index.ts",
+ "types": "./dist/HStack/index.d.ts",
+ "default": "./dist/HStack/index.js"
+ },
+ "./Heading": {
+ "source": "./src/Heading/index.ts",
+ "types": "./dist/Heading/index.d.ts",
+ "default": "./dist/Heading/index.js"
+ },
"./HoverCard": {
"source": "./src/HoverCard/index.ts",
"types": "./dist/HoverCard/index.d.ts",
@@ -523,6 +538,11 @@
"types": "./dist/Typeahead/index.d.ts",
"default": "./dist/Typeahead/index.js"
},
+ "./VStack": {
+ "source": "./src/VStack/index.ts",
+ "types": "./dist/VStack/index.d.ts",
+ "default": "./dist/VStack/index.js"
+ },
"./hooks": {
"source": "./src/hooks/index.ts",
"types": "./dist/hooks/index.d.ts",
diff --git a/packages/core/src/Code/index.ts b/packages/core/src/Code/index.ts
new file mode 100644
index 0000000000..fa4e241cb5
--- /dev/null
+++ b/packages/core/src/Code/index.ts
@@ -0,0 +1,11 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Convenience re-export for XDSCode
+ * @position Subpath export so `@xds/core/Code` resolves correctly
+ *
+ * XDSCode lives in the CodeBlock directory (shared code rendering internals),
+ * but agents and developers naturally expect `@xds/core/Code` to work.
+ */
+
+export {XDSCode, type XDSCodeProps} from '../CodeBlock';
diff --git a/packages/core/src/HStack/index.ts b/packages/core/src/HStack/index.ts
new file mode 100644
index 0000000000..47a52ff1e0
--- /dev/null
+++ b/packages/core/src/HStack/index.ts
@@ -0,0 +1,8 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Convenience re-export for XDSHStack
+ * @position Subpath export so `@xds/core/HStack` resolves correctly
+ */
+
+export {XDSHStack, type XDSHStackProps} from '../Stack';
diff --git a/packages/core/src/Heading/index.ts b/packages/core/src/Heading/index.ts
new file mode 100644
index 0000000000..9b96382b7d
--- /dev/null
+++ b/packages/core/src/Heading/index.ts
@@ -0,0 +1,16 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Convenience re-export for XDSHeading
+ * @position Subpath export so `@xds/core/Heading` resolves correctly
+ *
+ * XDSHeading lives in the Text directory (shared typography internals),
+ * but agents and developers naturally expect `@xds/core/Heading` to work.
+ */
+
+export {
+ XDSHeading,
+ type XDSHeadingProps,
+ type XDSHeadingLevel,
+ type XDSHeadingType,
+} from '../Text';
diff --git a/packages/core/src/VStack/index.ts b/packages/core/src/VStack/index.ts
new file mode 100644
index 0000000000..e4d2d6255a
--- /dev/null
+++ b/packages/core/src/VStack/index.ts
@@ -0,0 +1,8 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Convenience re-export for XDSVStack
+ * @position Subpath export so `@xds/core/VStack` resolves correctly
+ */
+
+export {XDSVStack, type XDSVStackProps} from '../Stack';