Skip to content

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

TypeScript

ci(native): typecheck the native package and every platform type it emits (#8024)

Cindy Zhang563dc5307a10
diff --git a/.github/scripts/ci-native-typecheck.test.mjs b/.github/scripts/ci-native-typecheck.test.mjs
new file mode 100644
index 0000000000..096b9e8041
--- /dev/null
+++ b/.github/scripts/ci-native-typecheck.test.mjs
@@ -0,0 +1,60 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file Routing contract for the TypeScript checks of @astryxdesign/native.
+ *
+ * The native package is outside the root `pnpm build`, and Vitest neither
+ * typechecks its source nor loads the declaration file of every platform
+ * condition. The `typecheck` job is the only gate over both, so it must run
+ * the package's typecheck, its build, and the check of the emitted platform
+ * types, in that order.
+ */
+
+import fs from 'node:fs';
+import path from 'node:path';
+
+import {describe, expect, it} from 'vitest';
+import yaml from 'yaml';
+
+const root = path.resolve(import.meta.dirname, '../..');
+const ci = yaml.parse(
+ fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8'),
+);
+const native = JSON.parse(
+ fs.readFileSync(path.join(root, 'packages/native/package.json'), 'utf8'),
+);
+const tsconfigTypes = JSON.parse(
+ fs.readFileSync(
+ path.join(root, 'packages/native/tsconfig.types.json'),
+ 'utf8',
+ ),
+);
+
+const NATIVE_COMMANDS = [
+ 'pnpm -F @astryxdesign/native typecheck',
+ 'pnpm -F @astryxdesign/native build',
+ 'pnpm -F @astryxdesign/native typecheck:types',
+];
+
+describe('native TypeScript checks', () => {
+ it('run in the typecheck job, after the root build, in order', () => {
+ const runs = ci.jobs.typecheck.steps.map(step => step.run?.trim() ?? '');
+ const indexes = NATIVE_COMMANDS.map(command => runs.indexOf(command));
+ for (const [i, index] of indexes.entries()) {
+ expect(index, NATIVE_COMMANDS[i]).toBeGreaterThan(
+ runs.indexOf('pnpm build'),
+ );
+ }
+ expect([...indexes].sort((a, b) => a - b)).toEqual(indexes);
+ });
+
+ it('check every emitted platform declaration file', () => {
+ expect(native.scripts['typecheck:types']).toBe(
+ 'tsc --project tsconfig.types.json',
+ );
+ expect(native.scripts.build).toContain('generate.mjs --types');
+ expect(tsconfigTypes.include).toEqual(['dist/types/*.d.ts']);
+ // The root config skips declaration files, which are all this checks.
+ expect(tsconfigTypes.compilerOptions.skipLibCheck).toBe(false);
+ });
+});
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 97ae84963f..b8a7bd15d1 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1187,6 +1187,22 @@ jobs:
if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
run: pnpm -F @astryxdesign/a11y-spec typecheck
+ # The canary-only @astryxdesign/native is outside the root build, and
+ # Vitest neither typechecks its source nor loads every platform's types.
+ # Its build emits one declaration file per type-resolution condition
+ # (ios, android, macos, windows, shared); the last step checks them all.
+ - name: Typecheck native
+ if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
+ run: pnpm -F @astryxdesign/native typecheck
+
+ - name: Build native platform types
+ if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
+ run: pnpm -F @astryxdesign/native build
+
+ - name: Typecheck native platform types
+ if: needs.check-scope.outputs.docsite_only != 'true' && needs.check-scope.outputs.spec_only != 'true' && needs.check-scope.outputs.tooling_only != 'true'
+ run: pnpm -F @astryxdesign/native typecheck:types
+
# Sandbox preview build — the single slowest piece of PR CI (~4min), run as
# its own job so it overlaps build-storybook instead of serializing after it.
# PR-only: merge_group runs never deploy previews, and docsite-only PRs skip
diff --git a/packages/native/README.md b/packages/native/README.md
index ca182a0aa8..4c433ad09c 100644
--- a/packages/native/README.md
+++ b/packages/native/README.md
@@ -124,7 +124,9 @@ const bridge = connectBridge(core, {
## Working on it
```sh
+pnpm -F @astryxdesign/native typecheck # source and tests
pnpm -F @astryxdesign/native build # dist/, including platform types
+pnpm -F @astryxdesign/native typecheck:types # every platform's types, after build
pnpm -F @astryxdesign/native generate:apple # regenerate apple/Sources/.../Generated
pnpm vitest run --project node packages/native
```
diff --git a/packages/native/package.json b/packages/native/package.json
index fa7cf635cb..a4bce47ed2 100644
--- a/packages/native/package.json
+++ b/packages/native/package.json
@@ -74,7 +74,8 @@
"build": "node ../../scripts/clean-dist.mjs && tsc --project tsconfig.build.json && node scripts/generate.mjs --types",
"generate:apple": "pnpm build && node scripts/generate.mjs --apple",
"test": "vitest run --root ../.. packages/native",
- "typecheck": "tsc --project tsconfig.json --noEmit"
+ "typecheck": "tsc --project tsconfig.json --noEmit",
+ "typecheck:types": "tsc --project tsconfig.types.json"
},
"peerDependencies": {
"@astryxdesign/core": "0.7.5"
diff --git a/packages/native/tsconfig.types.json b/packages/native/tsconfig.types.json
new file mode 100644
index 0000000000..7fb252e451
--- /dev/null
+++ b/packages/native/tsconfig.types.json
@@ -0,0 +1,11 @@
+{
+ "extends": "../../tsconfig.json",
+ "compilerOptions": {
+ "lib": ["ES2022"],
+ "types": [],
+ "skipLibCheck": false,
+ "noEmit": true
+ },
+ "include": ["dist/types/*.d.ts"],
+ "exclude": []
+}