Skip to content

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

TypeScript

build(core): fail the core build on unsupported StyleX declarations (#6830)

홍규진328a1c788744
diff --git a/.changeset/core-stylex-throw-validation.md b/.changeset/core-stylex-throw-validation.md
new file mode 100644
index 0000000000..fd763e31ac
--- /dev/null
+++ b/.changeset/core-stylex-throw-validation.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[chore] The core build now fails when StyleX rejects a declaration such as a `border`, `background`, or `all` shorthand, instead of silently dropping it from the shipped CSS. The emitted `dist/` is unchanged. No API change.
+
+@kyu-rong
diff --git a/packages/core/babel.config.json b/packages/core/babel.config.json
index bb109db361..ded9763439 100644
--- a/packages/core/babel.config.json
+++ b/packages/core/babel.config.json
@@ -10,6 +10,7 @@
{
"dev": false,
"runtimeInjection": false,
+ "propertyValidationMode": "throw",
"genConditionalClasses": true,
"treeshakeCompensation": true,
"unstable_moduleResolution": {
diff --git a/packages/core/src/stylexValidation.source-build.test.mjs b/packages/core/src/stylexValidation.source-build.test.mjs
new file mode 100644
index 0000000000..ef1da7dfe1
--- /dev/null
+++ b/packages/core/src/stylexValidation.source-build.test.mjs
@@ -0,0 +1,42 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file stylexValidation.source-build.test.mjs
+ * @input Uses Babel and the core StyleX build config
+ * @output Verifies unsupported StyleX declarations fail the core build
+ * @position Regression test for the core build's propertyValidationMode
+ */
+
+import path from 'node:path';
+import {fileURLToPath} from 'node:url';
+import {transformAsync} from '@babel/core';
+import {describe, expect, it} from 'vitest';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const CORE_ROOT = path.resolve(__dirname, '..');
+
+function compile(declaration) {
+ const source = `import * as stylex from '@stylexjs/stylex';
+export const styles = stylex.create({root: {${declaration}}});`;
+ return transformAsync(source, {
+ babelrc: false,
+ configFile: path.join(CORE_ROOT, 'babel.config.json'),
+ filename: path.join(__dirname, 'unsupported-declaration.tsx'),
+ });
+}
+
+describe('core StyleX property validation', () => {
+ // In StyleX's default `silent` mode each of these compiles successfully and
+ // the declaration never reaches the shipped CSS, so a green build proves
+ // nothing. The core build must fail instead.
+ it.each([
+ ['border', "border: 'none'", /border is not supported/],
+ ['background', "background: 'none'", /background is not supported/],
+ ['all', "all: 'unset'", /all is not supported/],
+ ])(
+ 'rejects the %s shorthand instead of dropping it',
+ async (_name, declaration, message) => {
+ await expect(compile(declaration)).rejects.toThrow(message);
+ },
+ );
+});