@astryxdesign/build 0.7.0-canary.0686fad → 0.7.0-canary.0f2d2ed

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vite.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import type { Plugin } from 'vite';
2
2
  import stylex from '@stylexjs/unplugin';
3
3
  /**
4
- * Browser targets for lightningcss (opt-in).
5
- * Only needed if your StyleX version lowers light-dark() without them.
6
- * Exported for consumers who want to opt in explicitly.
4
+ * Browser targets matching Astryx's native `light-dark()` support floor.
5
+ *
6
+ * These are the source-build default so Lightning CSS preserves
7
+ * `light-dark()` instead of lowering it into helper variables. Consumers may
8
+ * supply a stricter supported floor when their product requires one.
7
9
  */
8
10
  export declare const LIGHTNINGCSS_TARGETS: {
9
11
  chrome: number;
@@ -50,10 +52,12 @@ export interface AstryxVitePluginOptions {
50
52
  product?: string;
51
53
  };
52
54
  /**
53
- * LightningCSS browser targets. Only needed if your StyleX version
54
- * lowers light-dark() without them. Most recent versions preserve
55
- * light-dark() by default.
56
- * @default undefined (no targets set)
55
+ * Lightning CSS browser targets.
56
+ *
57
+ * Defaults to Astryx's native `light-dark()` support floor. Older targets
58
+ * may lower `light-dark()` and are outside the supported theme contract.
59
+ *
60
+ * @default LIGHTNINGCSS_TARGETS
57
61
  */
58
62
  lightningcssTargets?: Record<string, number>;
59
63
  /**
package/dist/vite.mjs CHANGED
@@ -26,12 +26,13 @@ function astryxStylex(options = {}) {
26
26
  rootDir = process.cwd(),
27
27
  libraryPattern = LIBRARY_PATTERN,
28
28
  layers = {},
29
- lightningcssTargets,
29
+ lightningcssTargets = LIGHTNINGCSS_TARGETS,
30
30
  stylexPrefix = "astryx",
31
31
  stylexOverrides = {}
32
32
  } = opts;
33
33
  const libraryLayer = layers.library ?? "astryx-base";
34
34
  const productLayer = layers.product ?? "product";
35
+ const overrideLightningcssOptions = stylexOverrides.lightningcssOptions;
35
36
  const stylexOptions = {
36
37
  dev,
37
38
  runtimeInjection: false,
@@ -41,10 +42,11 @@ function astryxStylex(options = {}) {
41
42
  type: "commonJS",
42
43
  rootDir
43
44
  },
44
- ...lightningcssTargets && {
45
- lightningcssOptions: { targets: lightningcssTargets }
46
- },
47
- ...stylexOverrides
45
+ ...stylexOverrides,
46
+ lightningcssOptions: {
47
+ targets: lightningcssTargets,
48
+ ...overrideLightningcssOptions
49
+ }
48
50
  };
49
51
  const astryxBabelPlugin = path.resolve(__dirname, "../src/babel.js");
50
52
  const basePlugin = stylex.vite({
@@ -305,9 +307,14 @@ function astryxStylexLegacy(options) {
305
307
  } = options;
306
308
  const libraryLayer = layers.library ?? "astryx-base";
307
309
  const productLayer = layers.product ?? "product";
310
+ const legacyLightningcssOptions = stylexOptions.lightningcssOptions;
308
311
  const validatedStylexOptions = {
309
312
  propertyValidationMode: "throw",
310
- ...stylexOptions
313
+ ...stylexOptions,
314
+ lightningcssOptions: {
315
+ targets: LIGHTNINGCSS_TARGETS,
316
+ ...legacyLightningcssOptions
317
+ }
311
318
  };
312
319
  const astryxBabelPlugin = path.resolve(__dirname, "../src/babel.js");
313
320
  const existingPlugins = validatedStylexOptions.babelConfig?.plugins ?? [];
@@ -382,7 +389,7 @@ function astryxStylexLegacy(options) {
382
389
  libraryPattern,
383
390
  libraryLayer,
384
391
  productLayer,
385
- lightningcssOptions: stylexOptions?.lightningcssOptions
392
+ lightningcssOptions: validatedStylexOptions.lightningcssOptions
386
393
  })
387
394
  ];
388
395
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/build",
3
- "version": "0.7.0-canary.0686fad",
3
+ "version": "0.7.0-canary.0f2d2ed",
4
4
  "description": "Build plugins for Astryx source builds — babel, PostCSS, and Vite integrations",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -210,6 +210,17 @@ function itSplitsCorrectly(get: () => Built) {
210
210
  expect(get().css).toContain('-webkit-user-select');
211
211
  });
212
212
 
213
+ // Source-built tokens must stay native at the same browser floor Astryx
214
+ // documents. Lowering `light-dark()` here rewrites root variables through
215
+ // mode helpers that exist only on Theme wrappers, so inherited data colors
216
+ // become invalid before a theme can use them.
217
+ it('preserves native light-dark() token values', () => {
218
+ const {css} = get();
219
+ expect(css).toContain('light-dark(');
220
+ expect(css).not.toContain('--lightningcss-light');
221
+ expect(css).not.toContain('--lightningcss-dark');
222
+ });
223
+
213
224
  it('links the stylesheet from the page', () => {
214
225
  const {html, cssName} = get();
215
226
  expect(html).toContain(cssName);
package/src/vite.test.ts CHANGED
@@ -12,7 +12,8 @@ import {mkdtempSync, mkdirSync, rmSync} from 'node:fs';
12
12
  import {tmpdir} from 'node:os';
13
13
  import path from 'node:path';
14
14
  import {fileURLToPath, pathToFileURL} from 'node:url';
15
- import {astryxStylex} from './vite';
15
+ import stylex from '@stylexjs/unplugin';
16
+ import {astryxStylex, LIGHTNINGCSS_TARGETS} from './vite';
16
17
 
17
18
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
18
19
 
@@ -73,6 +74,44 @@ describe('astryxStylex layer order (legacy API)', () => {
73
74
  });
74
75
  });
75
76
 
77
+ describe('astryxStylex Lightning CSS defaults (modern API)', () => {
78
+ type StylexOptions = {
79
+ lightningcssOptions: {
80
+ targets: Record<string, number>;
81
+ drafts?: {nesting: boolean};
82
+ };
83
+ };
84
+
85
+ function getStylexOptions(
86
+ options: Parameters<typeof astryxStylex>[0] = {},
87
+ ): StylexOptions {
88
+ const vite = vi.spyOn(stylex, 'vite');
89
+ try {
90
+ astryxStylex(options);
91
+ return vite.mock.calls.at(-1)?.[0] as StylexOptions;
92
+ } finally {
93
+ vite.mockRestore();
94
+ }
95
+ }
96
+
97
+ it('preserves native light-dark() at the supported browser floor', () => {
98
+ expect(getStylexOptions().lightningcssOptions.targets).toEqual(
99
+ LIGHTNINGCSS_TARGETS,
100
+ );
101
+ });
102
+
103
+ it('keeps the floor when a consumer supplies another Lightning CSS option', () => {
104
+ const options = getStylexOptions({
105
+ stylexOverrides: {lightningcssOptions: {drafts: {nesting: true}}},
106
+ }).lightningcssOptions;
107
+
108
+ expect(options).toEqual({
109
+ targets: LIGHTNINGCSS_TARGETS,
110
+ drafts: {nesting: true},
111
+ });
112
+ });
113
+ });
114
+
76
115
  /**
77
116
  * A production build had no equivalent of the dev server's split-layer plugin,
78
117
  * so StyleX's `@layer priorityN` blocks sat outside the declared order and
package/src/vite.ts CHANGED
@@ -15,9 +15,11 @@ const LIBRARY_PATTERN = 'node_modules/@astryxdesign/';
15
15
  const STYLEX_CSS_PATH = '/virtual:stylex.css';
16
16
 
17
17
  /**
18
- * Browser targets for lightningcss (opt-in).
19
- * Only needed if your StyleX version lowers light-dark() without them.
20
- * Exported for consumers who want to opt in explicitly.
18
+ * Browser targets matching Astryx's native `light-dark()` support floor.
19
+ *
20
+ * These are the source-build default so Lightning CSS preserves
21
+ * `light-dark()` instead of lowering it into helper variables. Consumers may
22
+ * supply a stricter supported floor when their product requires one.
21
23
  */
22
24
  export const LIGHTNINGCSS_TARGETS = {
23
25
  chrome: 123 << 16,
@@ -70,10 +72,12 @@ export interface AstryxVitePluginOptions {
70
72
  };
71
73
 
72
74
  /**
73
- * LightningCSS browser targets. Only needed if your StyleX version
74
- * lowers light-dark() without them. Most recent versions preserve
75
- * light-dark() by default.
76
- * @default undefined (no targets set)
75
+ * Lightning CSS browser targets.
76
+ *
77
+ * Defaults to Astryx's native `light-dark()` support floor. Older targets
78
+ * may lower `light-dark()` and are outside the supported theme contract.
79
+ *
80
+ * @default LIGHTNINGCSS_TARGETS
77
81
  */
78
82
  lightningcssTargets?: Record<string, number>;
79
83
 
@@ -125,7 +129,7 @@ export function astryxStylex(
125
129
  rootDir = process.cwd(),
126
130
  libraryPattern = LIBRARY_PATTERN,
127
131
  layers = {},
128
- lightningcssTargets,
132
+ lightningcssTargets = LIGHTNINGCSS_TARGETS,
129
133
  stylexPrefix = 'astryx',
130
134
  stylexOverrides = {},
131
135
  } = opts;
@@ -133,7 +137,13 @@ export function astryxStylex(
133
137
  const libraryLayer = layers.library ?? 'astryx-base';
134
138
  const productLayer = layers.product ?? 'product';
135
139
 
136
- // Build StyleX options with sensible defaults
140
+ const overrideLightningcssOptions = (
141
+ stylexOverrides as {lightningcssOptions?: Record<string, unknown>}
142
+ ).lightningcssOptions;
143
+
144
+ // Build StyleX options with sensible defaults. Merge Lightning CSS options
145
+ // separately so an unrelated override cannot silently discard the browser
146
+ // floor that keeps theme values native.
137
147
  const stylexOptions: Record<string, unknown> = {
138
148
  dev,
139
149
  runtimeInjection: false,
@@ -143,10 +153,11 @@ export function astryxStylex(
143
153
  type: 'commonJS',
144
154
  rootDir,
145
155
  },
146
- ...(lightningcssTargets && {
147
- lightningcssOptions: {targets: lightningcssTargets},
148
- }),
149
156
  ...stylexOverrides,
157
+ lightningcssOptions: {
158
+ targets: lightningcssTargets,
159
+ ...overrideLightningcssOptions,
160
+ },
150
161
  };
151
162
 
152
163
  // Inject our babel wrapper as a user plugin — it runs before the
@@ -570,9 +581,16 @@ function astryxStylexLegacy(options: AstryxVitePluginLegacyOptions): Plugin[] {
570
581
  const libraryLayer = layers.library ?? 'astryx-base';
571
582
  const productLayer = layers.product ?? 'product';
572
583
 
584
+ const legacyLightningcssOptions = (
585
+ stylexOptions as {lightningcssOptions?: Record<string, unknown>}
586
+ ).lightningcssOptions;
573
587
  const validatedStylexOptions = {
574
588
  propertyValidationMode: 'throw',
575
589
  ...(stylexOptions as any),
590
+ lightningcssOptions: {
591
+ targets: LIGHTNINGCSS_TARGETS,
592
+ ...legacyLightningcssOptions,
593
+ },
576
594
  };
577
595
  const astryxBabelPlugin = path.resolve(__dirname, 'babel.js');
578
596
  const existingPlugins = validatedStylexOptions.babelConfig?.plugins ?? [];
@@ -656,8 +674,9 @@ function astryxStylexLegacy(options: AstryxVitePluginLegacyOptions): Plugin[] {
656
674
  libraryPattern,
657
675
  libraryLayer,
658
676
  productLayer,
659
- lightningcssOptions: (stylexOptions as {lightningcssOptions?: unknown})
660
- ?.lightningcssOptions,
677
+ lightningcssOptions: (
678
+ validatedStylexOptions as {lightningcssOptions?: unknown}
679
+ ).lightningcssOptions,
661
680
  }),
662
681
  ];
663
682
  }