Skip to content

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

TypeScript

fix: generate TypeScript-safe integration imports (#6288)

Joey6c6c14e21363
diff --git a/.changeset/extensionless-integration-imports.md b/.changeset/extensionless-integration-imports.md
new file mode 100644
index 0000000000..5a8ade9c54
--- /dev/null
+++ b/.changeset/extensionless-integration-imports.md
@@ -0,0 +1,18 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] Use extensionless subpath specifiers for generated integration imports
+
+`integrationAddComponent` and `integrationAddTemplate` now emit extensionless
+public import specifiers (`@pkg/components/MyWidget` instead of
+`@pkg/components/MyWidget.tsx`) and map them to source files through the
+package `exports` field. Consumer imports no longer expose the package's source
+extension or require `allowImportingTsExtensions`.
+
+`integrationPackCheck` now rejects public specifiers ending in `.tsx` or `.ts`
+and validates each exact import from the packed artifact through Node's package
+resolver. Packages without a usable public export fail the check, and the
+result does not depend on project-local TypeScript.
+
+@josephfarina
diff --git a/docs/architecture/cli-surface.md b/docs/architecture/cli-surface.md
index d8e79b657a..602200c8d4 100644
--- a/docs/architecture/cli-surface.md
+++ b/docs/architecture/cli-surface.md
@@ -3,11 +3,11 @@ schema_version: 1
template_version: 1
kind: architecture
id: architecture:cli-surface
-authority: draft
+authority: current
archive_reason: null
superseded_by: null
-approved_by: null
-approved_at: null
+approved_by: cixzhang
+approved_at: 2026-09-13
owners: [josephfarina]
applies_to: [packages/cli]
verified_by:
@@ -144,14 +144,20 @@ test, applicable text, and consumer-documentation projections.
- **INV16 — Authoring preserves package policy and local source wins while it is
being edited.** Writers never create `files` or `exports`; when either field
already exists, they add only the required manifest, root, or public subpath
- and preserve every author-owned entry. The integration beside the current
- package.json replaces the same installed package in place, preserving its
- configured order while making working bytes authoritative.
+ and preserve every author-owned entry. Generated component and template export
+ keys are extensionless public subpaths even when they target authored `.ts` or
+ `.tsx` source. The integration beside the current package.json replaces the
+ same installed package in place, preserving its configured order while making
+ working bytes authoritative.
- **INV17 — Pack verification examines the artifact consumers receive.**
`integration pack --check` runs the package lifecycle through `npm pack`,
compares the required file inventory with the actual tarball, extracts that
- tarball into a scratch consumer, reruns contribution discovery, and verifies
- advertised component and template imports through Node's package resolver.
+ tarball into a scratch consumer, and reruns contribution discovery. It rejects
+ advertised component imports ending in `.ts` or `.tsx`, resolves every exact
+ advertised component and inferred template import through Node's package
+ resolver, and fails when the packed artifact has no usable public export. This
+ contract does not require project-local TypeScript or promise validation under
+ TypeScript's Node16 or bundler resolution modes.
- **INV18 — Integration diagnostics are read-only and package-specific.** Doctor
validation reports malformed or unreachable roots and contribution conflicts
without rewriting the package. Everyday discovery skips a broken integration
@@ -178,9 +184,10 @@ updated in the same pull request when it moves an invariant:
- adding a formatter, or writing to stdout from anywhere other than `emit` and
`jsonOut`;
- changing the file layout under `clients/cli/commands`;
-- changing an integration writer's receipt, no-clobber/rollback behavior, or
- package.json mutation policy;
-- changing what `integration pack --check` executes or proves about the tarball;
+- changing an integration writer's receipt, no-clobber/rollback behavior,
+ package.json mutation policy, or public subpath spelling;
+- changing what `integration pack --check` executes, resolves, or proves about
+ the tarball;
- changing local, configured, or autolinked integration precedence;
- changing the integration theme catalog or consumer copy contract.
diff --git a/packages/cli/api/integration/add-contribution.mjs b/packages/cli/api/integration/add-contribution.mjs
index 14cccdddee..5a293c49bd 100644
--- a/packages/cli/api/integration/add-contribution.mjs
+++ b/packages/cli/api/integration/add-contribution.mjs
@@ -250,7 +250,8 @@ async function addComponent(name, options) {
}
const sourcePath = projectPath(path.relative(packageDir, sourceFile));
- const importSpecifier = `${owner}/${sourcePath}`;
+ const extensionlessPath = sourcePath.replace(/\.tsx?$/u, '');
+ const importSpecifier = `${owner}/${extensionlessPath}`;
const docContents = `export default {\n type: 'component',\n name: '${name}',\n import: ${JSON.stringify(importSpecifier)},\n description: '${name} component.',\n props: [],\n};\n`;
const sourceContents = `export function ${name}() {\n return <div>${name}</div>;\n}\n`;
@@ -263,7 +264,7 @@ async function addComponent(name, options) {
packageFile,
rootPath,
path.basename(manifestFile),
- [{subpath: sourcePath, target: sourcePath}],
+ [{subpath: extensionlessPath, target: sourcePath}],
);
if (pkgUpdate != null) {
plans.push({
@@ -576,6 +577,7 @@ async function addTemplate(name, options) {
const pascalName = kebabToPascal(name);
const sourcePath = projectPath(path.relative(packageDir, sourceFile));
+ const extensionlessPath = sourcePath.replace(/\.tsx?$/u, '');
const specContents = `export default {\n type: '${templateType}',\n name: '${name}',\n description: '${kebabToTitle(name)} template.',\n};\n`;
const sourceContents = `export default function ${pascalName}() {\n return <div>${kebabToTitle(name)}</div>;\n}\n`;
@@ -588,7 +590,7 @@ async function addTemplate(name, options) {
packageFile,
rootPath,
path.basename(manifestFile),
- [{subpath: sourcePath, target: sourcePath}],
+ [{subpath: extensionlessPath, target: sourcePath}],
);
if (pkgUpdate != null) {
plans.push({
diff --git a/packages/cli/api/integration/add-contribution.test.mjs b/packages/cli/api/integration/add-contribution.test.mjs
index 40d1d0b698..813806f256 100644
--- a/packages/cli/api/integration/add-contribution.test.mjs
+++ b/packages/cli/api/integration/add-contribution.test.mjs
@@ -118,14 +118,14 @@ describe('integrationAdd component', () => {
);
expect(pkg.exports).toEqual({
'.': './index.mjs',
- './components/MyWidget.tsx': './components/MyWidget.tsx',
+ './components/MyWidget': './components/MyWidget.tsx',
});
expect(
fs.readFileSync(
path.join(tmpDir, 'components/MyWidget.doc.mjs'),
'utf-8',
),
- ).toContain('import: "@acme/integration/components/MyWidget.tsx"');
+ ).toContain('import: "@acme/integration/components/MyWidget"');
});
it('does not create exports when the package has no exports map', async () => {
@@ -143,7 +143,7 @@ describe('integrationAdd component', () => {
setup({
exports: {
'.': './index.mjs',
- './components/MyWidget.tsx': './different.tsx',
+ './components/MyWidget': './different.tsx',
},
});
@@ -421,7 +421,7 @@ describe('integrationAdd template', () => {
);
expect(pkg.exports).toEqual({
'.': './index.mjs',
- './templates/my-widget.tsx': './templates/my-widget.tsx',
+ './templates/my-widget': './templates/my-widget.tsx',
});
});
diff --git a/packages/cli/api/integration/pack-check.mjs b/packages/cli/api/integration/pack-check.mjs
index 68c96c463a..b7af96fb8e 100644
--- a/packages/cli/api/integration/pack-check.mjs
+++ b/packages/cli/api/integration/pack-check.mjs
@@ -388,6 +388,14 @@ async function validatePackedComponentExports(integration, scratchBase) {
components.map(component => component.specifier),
scratchBase,
);
+ issues.push(
+ ...validateSpecifierExtensions(
+ components.map(({name, specifier}) => ({
+ label: `Component "${name}"`,
+ specifier,
+ })),
+ ),
+ );
for (const {name, specifier} of components) {
const result = resolved.get(specifier);
if (!result?.url || result.error) {
@@ -427,19 +435,27 @@ async function validatePackedComponentExports(integration, scratchBase) {
*/
async function validatePackedTemplateExports(integration, scratchBase) {
const {templates} = await discoverIntegrationTemplatesForOne(integration);
- const entries = templates.map(template => ({
- id: template.dirName,
- specifier: `${integration.name}/${path
+ const entries = templates.map(template => {
+ const relPath = path
.relative(integration.__packageDir, template.filePath)
.split(path.sep)
- .join('/')}`,
- }));
+ .join('/');
+ const extensionless = relPath.replace(/\.tsx?$/u, '');
+ return {
+ id: template.dirName,
+ specifier: `${integration.name}/${extensionless}`,
+ };
+ });
const resolved = resolveConsumerSpecifiers(
entries.map(entry => entry.specifier),
scratchBase,
);
- /** @type {Issue[]} */
- const issues = [];
+ const issues = validateSpecifierExtensions(
+ entries.map(({id, specifier}) => ({
+ label: `Template "${id}"`,
+ specifier,
+ })),
+ );
for (const {id, specifier} of entries) {
const result = resolved.get(specifier);
if (!result?.url || result.error) {
@@ -469,6 +485,32 @@ async function validatePackedTemplateExports(integration, scratchBase) {
return issues;
}
+const TS_EXTENSION_RE = /\.tsx?$/u;
+
+/**
+ * Reject specifiers that end in a TypeScript extension — they fail under
+ * default `moduleResolution` with TS5097/TS2307 unless the consumer enables
+ * `allowImportingTsExtensions`.
+ *
+ * @param {Array<{label: string, specifier: string}>} entries
+ * @returns {Issue[]}
+ */
+function validateSpecifierExtensions(entries) {
+ /** @type {Issue[]} */
+ const issues = [];
+ for (const {label, specifier} of entries) {
+ if (TS_EXTENSION_RE.test(specifier)) {
+ issues.push(
+ error(
+ 'typescript_extension_in_specifier',
+ `${label} advertises import "${specifier}", which ends in a TypeScript extension. A consumer with default moduleResolution will reject it (TS5097). Use an extensionless specifier mapped through the package exports.`,
+ ),
+ );
+ }
+ }
+ return issues;
+}
+
/**
* Verify an integration package is ready to publish.
*
diff --git a/packages/cli/api/integration/pack-check.test.mjs b/packages/cli/api/integration/pack-check.test.mjs
index b6aabd8bea..12f1789a02 100644
--- a/packages/cli/api/integration/pack-check.test.mjs
+++ b/packages/cli/api/integration/pack-check.test.mjs
@@ -567,3 +567,252 @@ describe('pack-check mutation tests', () => {
}
});
});
+
+describe('extensionless subpath resolution', () => {
+ it('rejects .tsx public specifiers before publishing', async () => {
+ // Manually construct a package with OLD-style .tsx exports keys
+ writePackage({
+ manifest: "export default {components: './components'};\n",
+ files: ['astryx.integration.mjs', 'components', 'index.mjs'],
+ themes: false,
+ });
+ const pkgFile = path.join(tmpDir, 'package.json');
+ const pkg = JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
+ pkg.exports = {
+ '.': './index.mjs',
+ './components/AcmeWidget.tsx': './components/AcmeWidget.tsx',
+ };
+ fs.writeFileSync(pkgFile, `${JSON.stringify(pkg, null, 2)}\n`);
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ fs.mkdirSync(path.join(tmpDir, 'components'));
+ fs.writeFileSync(
+ path.join(tmpDir, 'components', 'AcmeWidget.doc.mjs'),
+ `export default {type: 'component', name: 'AcmeWidget', import: '@acme/widgets/components/AcmeWidget.tsx', description: 'Widget.', props: []};\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'components', 'AcmeWidget.tsx'),
+ 'export function AcmeWidget() { return null; }\n',
+ );
+
+ const result = await integrationPackCheck({cwd: tmpDir});
+
+ // The .tsx extension in the specifier must be caught
+ expect(result.data.packable).toBe(false);
+ expect(result.data.issues).toContainEqual(
+ expect.objectContaining({
+ code: 'typescript_extension_in_specifier',
+ message: expect.stringContaining('.tsx'),
+ }),
+ );
+ });
+
+ it('generated extensionless component specifier resolves through exports map', async () => {
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['index.mjs'],
+ exports: {'.': './index.mjs'},
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
+
+ // Verify the exports map has extensionless key → .tsx target
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
+ );
+ expect(pkg.exports['./components/AcmeWidget']).toBe(
+ './components/AcmeWidget.tsx',
+ );
+ expect(pkg.exports['./components/AcmeWidget.tsx']).toBeUndefined();
+
+ const result = await integrationPackCheck({cwd: tmpDir});
+
+ expect(result.data.packable).toBe(true);
+ expect(result.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'typescript_extension_in_specifier'}),
+ );
+ expect(result.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'component_import_unresolvable'}),
+ );
+ });
+
+ it('validates generated imports without project-local TypeScript', async () => {
+ fs.rmSync(tmpDir, {recursive: true, force: true});
+ tmpDir = fs.mkdtempSync(
+ path.join(os.tmpdir(), 'astryx-pack-check-no-typescript-'),
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['index.mjs'],
+ exports: {'.': './index.mjs'},
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
+
+ const result = await integrationPackCheck({cwd: tmpDir});
+
+ expect(result.data.packable).toBe(true);
+ expect(result.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'component_import_unresolvable'}),
+ );
+ });
+
+ it('generated extensionless template specifiers resolve for page and block types', async () => {
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['index.mjs'],
+ exports: {'.': './index.mjs'},
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ await integrationAddTemplate('account-page', {cwd: tmpDir, type: 'page'});
+ await integrationAddTemplate('info-card', {cwd: tmpDir, type: 'block'});
+
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
+ );
+ expect(pkg.exports['./templates/account-page']).toBe(
+ './templates/account-page.tsx',
+ );
+ expect(pkg.exports['./templates/info-card']).toBe(
+ './templates/info-card.tsx',
+ );
+
+ const result = await integrationPackCheck({cwd: tmpDir});
+
+ expect(result.data.packable).toBe(true);
+ expect(result.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'template_import_unresolvable'}),
+ );
+ expect(result.data.issues).not.toContainEqual(
+ expect.objectContaining({code: 'typescript_extension_in_specifier'}),
+ );
+ });
+
+ it('preserves condition-style exports sugar without creating a map', async () => {
+ // Package with condition-only exports (sugar, no subpaths)
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['index.mjs'],
+ exports: {import: './index.mjs', require: './index.cjs'},
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ fs.writeFileSync(path.join(tmpDir, 'index.cjs'), 'exports.existing = 1;\n');
+ fs.writeFileSync(
+ path.join(tmpDir, 'astryx.integration.mjs'),
+ 'export default {};\n',
+ );
+
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
+
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
+ );
+ // Condition sugar wrapped into subpath map with the component added
+ expect(pkg.exports['.']).toEqual({
+ import: './index.mjs',
+ require: './index.cjs',
+ });
+ expect(pkg.exports['./components/AcmeWidget']).toBe(
+ './components/AcmeWidget.tsx',
+ );
+ });
+
+ it('no-map: pack-check fails when generated component has no exports map', async () => {
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['dist'],
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'astryx.integration.mjs'),
+ 'export default {};\n',
+ );
+
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
+ await integrationAddTemplate('hero-page', {cwd: tmpDir, type: 'page'});
+
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
+ );
+ // No exports map created
+ expect(pkg.exports).toBeUndefined();
+
+ const result = await integrationPackCheck({cwd: tmpDir});
+
+ // The extensionless import cannot resolve without an exports map —
+ // pack-check must fail closed, not false-green.
+ expect(result.data.packable).toBe(false);
+ expect(result.data.issues).toContainEqual(
+ expect.objectContaining({
+ severity: 'error',
+ message: expect.stringContaining('AcmeWidget'),
+ }),
+ );
+ });
+
+ it('idempotent when extensionless export already exists', async () => {
+ fs.writeFileSync(
+ path.join(tmpDir, 'package.json'),
+ `${JSON.stringify({
+ name: '@acme/widgets',
+ version: '1.0.0',
+ files: ['index.mjs'],
+ exports: {
+ '.': './index.mjs',
+ './components/AcmeWidget': './components/AcmeWidget.tsx',
+ },
+ })}\n`,
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'index.mjs'),
+ 'export const existing = 1;\n',
+ );
+ fs.writeFileSync(
+ path.join(tmpDir, 'astryx.integration.mjs'),
+ 'export default {};\n',
+ );
+
+ await integrationAddComponent('AcmeWidget', {cwd: tmpDir});
+
+ const pkg = JSON.parse(
+ fs.readFileSync(path.join(tmpDir, 'package.json'), 'utf-8'),
+ );
+ // Export preserved, no duplicate
+ expect(
+ Object.keys(pkg.exports).filter(k => k.includes('AcmeWidget')),
+ ).toEqual(['./components/AcmeWidget']);
+ });
+});
diff --git a/packages/cli/clients/cli/commands/integration-authoring.test.mjs b/packages/cli/clients/cli/commands/integration-authoring.test.mjs
index b51de6d637..5610432c3a 100644
--- a/packages/cli/clients/cli/commands/integration-authoring.test.mjs
+++ b/packages/cli/clients/cli/commands/integration-authoring.test.mjs
@@ -120,7 +120,7 @@ describe('integration authoring CLI', () => {
);
});
- it('packs the generated contribution and proves the consumer inventory', async () => {
+ it('pack-check rejects a generated component without an exports map (no-map false green)', async () => {
const added = await runCli(
['integration', 'add', 'component', 'AcmeWidget', '--json'],
tmpDir,
@@ -131,19 +131,23 @@ describe('integration authoring CLI', () => {
['integration', 'pack', '--check', '--json'],
tmpDir,
);
- expect(checked.status).toBe(0);
- expect(parseEnvelope(checked.stdout)).toMatchObject({
+ // Without an exports map, the extensionless import cannot resolve —
+ // pack-check must fail, not false-green.
+ expect(checked.status).not.toBe(0);
+ const envelope = parseEnvelope(checked.stdout);
+ expect(envelope).toMatchObject({
type: 'integration.pack-check',
data: {
name: '@acme/widgets',
- version: '1.0.0',
- packable: true,
- contributions: {
- local: {components: ['AcmeWidget']},
- packed: {components: ['AcmeWidget']},
- },
+ packable: false,
},
});
+ expect(envelope.data.issues).toContainEqual(
+ expect.objectContaining({
+ severity: 'error',
+ message: expect.stringContaining('AcmeWidget'),
+ }),
+ );
});
it('requires the explicit --check gate on pack', async () => {