Skip to content

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

TypeScript

chore(docsite): fail fast with a clear message when workspace packages are not built (#4426)

nynexman44645eec8d913977
diff --git a/apps/docsite/package.json b/apps/docsite/package.json
index d7207ee8ff..8e6f0273fa 100644
--- a/apps/docsite/package.json
+++ b/apps/docsite/package.json
@@ -4,7 +4,7 @@
"private": true,
"scripts": {
"build:theme": "astryx theme build src/themes/astryxTheme.ts --out src/themes/astryx.css",
- "generate": "pnpm build:theme && node scripts/generate-data.mjs && node scripts/generate-scope.mjs && node scripts/generate-playground-types.mjs && node scripts/copy-vendor.mjs",
+ "generate": "node scripts/check-workspace-build.mjs && pnpm build:theme && node scripts/generate-data.mjs && node scripts/generate-scope.mjs && node scripts/generate-playground-types.mjs && node scripts/copy-vendor.mjs",
"dev": "pnpm generate && next dev --webpack",
"build": "pnpm generate && next build --webpack",
"start": "next start",
diff --git a/apps/docsite/scripts/check-workspace-build.mjs b/apps/docsite/scripts/check-workspace-build.mjs
new file mode 100644
index 0000000000..6b09a667c3
--- /dev/null
+++ b/apps/docsite/scripts/check-workspace-build.mjs
@@ -0,0 +1,57 @@
+#!/usr/bin/env node
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * Preflight for the docsite: fail fast when @astryxdesign/core isn't built.
+ *
+ * The docsite's `generate` step runs `astryx theme build`, which imports the
+ * compiled @astryxdesign/core theme entry (dist/theme/index.js). In a fresh
+ * clone/worktree that dist/ doesn't exist until `pnpm build` runs at the repo
+ * root, and the raw failure points at an internal node_modules/.../dist path
+ * with no hint of the fix. This check runs first in `generate` (so both `dev`
+ * and `build` gate on it) and prints a clear, actionable message.
+ *
+ * Scope note: this only gates on core, which is the shared prerequisite for
+ * `generate` + `test` (matching CI's docsite-test job, which builds only
+ * core). Theme-package CSS is a `next dev`/`next build` runtime concern, not a
+ * `generate` prerequisite, so it is intentionally not required here.
+ *
+ * Usage: node scripts/check-workspace-build.mjs
+ */
+
+import {existsSync} from 'node:fs';
+import {join, dirname} from 'node:path';
+import {fileURLToPath} from 'node:url';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+// scripts -> docsite -> apps -> repo root
+const ROOT = join(__dirname, '..', '..', '..');
+
+// Representative built artifact for the failure `generate` actually hits:
+// core's built theme module. `build:theme` (astryx theme build) imports the
+// compiled @astryxdesign/core/theme entry, so if this file is missing, the
+// very first step of `generate` dies with a cryptic "Cannot find module
+// .../dist/theme/index.js".
+//
+// We intentionally do NOT require the theme packages' built theme.css here.
+// The `generate` + `test` path only needs core built (this is how CI's
+// docsite-test job runs — it builds only @astryxdesign/core). The theme CSS
+// is a runtime/`next build` concern, not a `generate` prerequisite, so
+// requiring it would fail CI where main is green today.
+const REQUIRED = ['packages/core/dist/theme/index.js'];
+
+const missing = REQUIRED.filter(rel => !existsSync(join(ROOT, rel)));
+
+if (missing.length > 0) {
+ console.error(
+ [
+ '',
+ '⚠ Astryx workspace packages aren\'t built yet.',
+ ' The docsite consumes the built output of @astryxdesign/core.',
+ ' Run `pnpm build` from the repo root first, then re-run `pnpm run docsite`.',
+ ` (missing: ${missing.join(', ')})`,
+ '',
+ ].join('\n'),
+ );
+ process.exit(1);
+}