@astryxdesign/build 0.6.2-canary.ff6777a → 0.6.3-canary.00af005

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @astryxdesign/build
2
2
 
3
- Build plugins for XDS source builds. Provides babel, PostCSS, and Vite integrations that compile XDS library and product code with separate class name prefixes, which enables independent CSS layers:
3
+ Build plugins for Astryx source builds. Provides babel, PostCSS, and Vite integrations that compile Astryx library and product code with separate class name prefixes, which enables independent CSS layers:
4
4
 
5
5
  ```
6
6
  reset < astryx-base (library, astryx prefix) < astryx-theme < product (app, x prefix)
@@ -12,7 +12,7 @@ StyleX generates atomic CSS: same declaration = same class name. Without separat
12
12
 
13
13
  `@astryxdesign/build` solves this by:
14
14
 
15
- 1. Compiling XDS library code with `astryx` prefix (`.astryx78zum5`)
15
+ 1. Compiling Astryx library code with `astryx` prefix (`.astryx78zum5`)
16
16
  2. Compiling product code with default `x` prefix (`.x78zum5`)
17
17
  3. Placing each group in its own CSS `@layer`
18
18
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@astryxdesign/build",
3
- "version": "0.6.2-canary.ff6777a",
4
- "description": "Build plugins for XDS source builds — babel, PostCSS, and Vite integrations",
3
+ "version": "0.6.3-canary.00af005",
4
+ "description": "Build plugins for Astryx source builds — babel, PostCSS, and Vite integrations",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/facebook/astryx#readme",
@@ -36,15 +36,18 @@
36
36
  "dist"
37
37
  ],
38
38
  "peerDependencies": {
39
- "@stylexjs/babel-plugin": ">=0.18.0",
40
39
  "@babel/core": ">=7.0.0",
40
+ "@stylexjs/babel-plugin": ">=0.18.0",
41
41
  "@stylexjs/unplugin": ">=0.18.0",
42
42
  "vite": "^8.1.3"
43
43
  },
44
44
  "dependencies": {
45
+ "autoprefixer": "^10.5.2",
46
+ "browserslist": "^4.28.4",
45
47
  "fast-glob": "^3.3.0",
46
48
  "glob-parent": "^6.0.0",
47
- "is-glob": "^4.0.0"
49
+ "is-glob": "^4.0.0",
50
+ "lightningcss": "^1.32.0"
48
51
  },
49
52
  "devDependencies": {
50
53
  "esbuild": "^0.28.1"
@@ -2,10 +2,9 @@
2
2
 
3
3
  /**
4
4
  * @file babel.test.mjs
5
- * @description Verifies that the XDS babel wrapper applies the configured
6
- * library StyleX class-name prefix to XDS library files. Part of the
7
- * the library atom prefix defaults to `astryx` and is configurable
8
- * before the final cutover.
5
+ * @description Verifies that the Astryx babel wrapper applies the configured
6
+ * library StyleX class-name prefix to Astryx library files. The prefix
7
+ * defaults to `astryx` and remains configurable.
9
8
  */
10
9
 
11
10
  import {describe, it, expect} from 'vitest';
@@ -23,15 +22,15 @@ export const styles = stylex.create({
23
22
  `;
24
23
 
25
24
  /**
26
- * Transform a StyleX source through the XDS babel wrapper as if it were a
27
- * library file, returning the emitted code. `libraryPrefix` controls the
25
+ * Transform a StyleX source through the Astryx babel wrapper as if it were an
26
+ * Astryx library file, returning the emitted code. `libraryPrefix` controls the
28
27
  * atomic class-name prefix for library files.
29
28
  */
30
29
  function transformLibraryFile(libraryPrefix) {
31
30
  const result = babel.transformSync(SOURCE, {
32
31
  // A path matching one of the library patterns so the wrapper routes it
33
32
  // through the library plugin instance.
34
- filename: 'node_modules/@astryxdesign/core/src/Box/XDSBox.tsx',
33
+ filename: 'node_modules/@astryxdesign/core/src/Box/AstryxBox.tsx',
35
34
  babelrc: false,
36
35
  configFile: false,
37
36
  plugins: [
@@ -53,7 +52,7 @@ function atomicClasses(code) {
53
52
  return code.match(/\b(?:xds|astryx|lib)[a-z0-9]{4,}\b/g) ?? [];
54
53
  }
55
54
 
56
- describe('xds babel wrapper -- library StyleX prefix', () => {
55
+ describe('Astryx babel wrapper -- library StyleX prefix', () => {
57
56
  it('defaults library atoms to the `astryx` prefix', () => {
58
57
  const code = transformLibraryFile(undefined);
59
58
  const atoms = atomicClasses(code);
package/src/config.js CHANGED
@@ -1,17 +1,19 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- "use strict";
3
+ 'use strict';
4
4
 
5
5
  /**
6
6
  * @astryxdesign/build
7
7
  *
8
- * Unified build configuration for Astryx source builds.
9
- *
8
+ * Unified build configuration for Astryx source builds. The complete PostCSS
9
+ * helper resolves its bundled Autoprefixer from this package rather than from
10
+ * the consuming project's dependency graph.
11
+ *
10
12
  * Usage:
11
13
  * // babel.config.js
12
14
  * const {babel} = require('@astryxdesign/build');
13
15
  * module.exports = babel(__dirname);
14
- *
16
+ *
15
17
  * // postcss.config.js
16
18
  * const {postcss} = require('@astryxdesign/build');
17
19
  * module.exports = postcss(__dirname);
@@ -51,7 +53,7 @@ function stylexOptions(rootDir, overrides = {}) {
51
53
 
52
54
  /**
53
55
  * Generate a complete babel.config.js for Astryx source builds.
54
- *
56
+ *
55
57
  * @param {string} rootDir — __dirname of the project root
56
58
  * @param {object} [overrides] — extra StyleX options to merge
57
59
  * @returns {object} babel config object
@@ -79,7 +81,7 @@ function babel(rootDir, overrides = {}) {
79
81
 
80
82
  /**
81
83
  * Generate a complete postcss.config.js for Astryx source builds.
82
- *
84
+ *
83
85
  * @param {string} rootDir — __dirname of the project root
84
86
  * @param {object} [overrides] — extra options (appDir, extraInclude, etc.)
85
87
  * @returns {object} postcss config object
@@ -96,7 +98,7 @@ function postcss(rootDir, overrides = {}) {
96
98
  ],
97
99
  extraInclude,
98
100
  },
99
- autoprefixer: {},
101
+ [require.resolve('autoprefixer')]: {},
100
102
  },
101
103
  };
102
104
  }
package/src/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
- "use strict";
3
+ 'use strict';
4
4
 
5
5
  /**
6
6
  * @astryxdesign/postcss-plugin
@@ -12,12 +12,12 @@
12
12
  * reset < astryx-base (library, prefix: 'astryx') < astryx-theme < product (prefix: 'x')
13
13
  *
14
14
  * The separate prefixes ensure atomic classes don't collide between
15
- * layers, which would break theme overrides.
15
+ * layers, which would break theme overrides. Generated replacement CSS is
16
+ * parsed by the host PostCSS instance so consumers do not load a second copy.
16
17
  */
17
18
 
18
19
  const path = require('node:path');
19
20
  const fs = require('node:fs');
20
- const postcss = require('postcss');
21
21
  const babel = require('@babel/core');
22
22
  const stylexBabelPlugin = require('@stylexjs/babel-plugin');
23
23
  const {globSync} = require('fast-glob');
@@ -27,7 +27,11 @@ const globParent = require('glob-parent');
27
27
  const PLUGIN_NAME = '@astryxdesign/postcss-plugin';
28
28
 
29
29
  const LIBRARY_GLOB = 'node_modules/@astryxdesign/**/*.{ts,tsx}';
30
- const LIBRARY_PATTERNS = ['node_modules/@astryxdesign/', 'packages/core/', 'packages/themes/'];
30
+ const LIBRARY_PATTERNS = [
31
+ 'node_modules/@astryxdesign/',
32
+ 'packages/core/',
33
+ 'packages/themes/',
34
+ ];
31
35
  const STYLEX_IMPORT_SOURCE = '@stylexjs/stylex';
32
36
 
33
37
  function parseDependency(fileOrGlob, cwd) {
@@ -117,7 +121,7 @@ function createPlugin() {
117
121
  const fileName = result.opts.from;
118
122
 
119
123
  let styleXAtRule = null;
120
- root.walkAtRules((atRule) => {
124
+ root.walkAtRules(atRule => {
121
125
  if (atRule.name === 'stylex' && !atRule.params) {
122
126
  styleXAtRule = atRule;
123
127
  }
@@ -193,7 +197,7 @@ function createPlugin() {
193
197
  rulesMap.set(filePath, stylex);
194
198
  }
195
199
  })
196
- .catch((error) => {
200
+ .catch(error => {
197
201
  if (shouldSkipTransformError) {
198
202
  console.warn(
199
203
  `[${PLUGIN_NAME}] Failed to transform "${filePath}": ${error.message}`,
@@ -231,9 +235,9 @@ function createPlugin() {
231
235
  parts.push(`@layer ${layers.product} {\n${productCss}\n}`);
232
236
  }
233
237
 
234
- const finalCss = parts.join('\n\n');
235
- const parsed = await postcss.parse(finalCss, {from: fileName});
236
- styleXAtRule.replaceWith(parsed);
238
+ // Let the host PostCSS instance parse the replacement so this plugin
239
+ // does not need or load a second copy of PostCSS.
240
+ styleXAtRule.replaceWith(parts.join('\n\n'));
237
241
  result.root = root;
238
242
 
239
243
  if (!shouldSkipTransformError) {
@@ -0,0 +1,186 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file packed-consumer.test.mjs
5
+ * @input Packs @astryxdesign/build, reconstructs only the dependencies declared
6
+ * by its tarball, and exercises the public PostCSS helper and Vite plugin
7
+ * @output Proves shipped build integrations need no ambient workspace packages
8
+ * and preserve generated browser compatibility CSS
9
+ * @position Consumer-package regression for @astryxdesign/build
10
+ */
11
+
12
+ import {execFileSync} from 'node:child_process';
13
+ import {
14
+ mkdtempSync,
15
+ mkdirSync,
16
+ readFileSync,
17
+ readdirSync,
18
+ realpathSync,
19
+ rmSync,
20
+ symlinkSync,
21
+ writeFileSync,
22
+ } from 'node:fs';
23
+ import {tmpdir} from 'node:os';
24
+ import path from 'node:path';
25
+ import {fileURLToPath} from 'node:url';
26
+ import {afterAll, beforeAll, describe, expect, it} from 'vitest';
27
+
28
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
29
+ const packageDir = path.resolve(__dirname, '..');
30
+ const repoRoot = path.resolve(packageDir, '../..');
31
+
32
+ function run(command, args, cwd) {
33
+ try {
34
+ return execFileSync(command, args, {
35
+ cwd,
36
+ encoding: 'utf8',
37
+ env: {...process.env, NODE_PATH: undefined},
38
+ stdio: ['ignore', 'pipe', 'pipe'],
39
+ });
40
+ } catch (error) {
41
+ const stdout = error.stdout?.toString() || '';
42
+ const stderr = error.stderr?.toString() || '';
43
+ throw new Error(
44
+ `${command} ${args.join(' ')} failed in ${cwd}\n${stdout}${stderr}`,
45
+ {cause: error},
46
+ );
47
+ }
48
+ }
49
+
50
+ function linkPackage(sourceRoot, name, targetRoot) {
51
+ const source = realpathSync(path.join(sourceRoot, 'node_modules', name));
52
+ const target = path.join(targetRoot, 'node_modules', name);
53
+ mkdirSync(path.dirname(target), {recursive: true});
54
+ symlinkSync(source, target, 'junction');
55
+ }
56
+
57
+ describe('the packed @astryxdesign/build consumer contract', () => {
58
+ let root;
59
+ let appDir;
60
+ let packedPackageDir;
61
+
62
+ beforeAll(() => {
63
+ root = mkdtempSync(path.join(tmpdir(), 'astryx-build-consumer-'));
64
+ const packDir = path.join(root, 'pack');
65
+ appDir = path.join(root, 'app');
66
+ packedPackageDir = path.join(root, 'packed-build');
67
+ mkdirSync(packDir);
68
+ mkdirSync(path.join(appDir, 'node_modules/@astryxdesign'), {
69
+ recursive: true,
70
+ });
71
+ mkdirSync(path.join(appDir, 'src'), {recursive: true});
72
+ mkdirSync(packedPackageDir);
73
+
74
+ run('pnpm', ['pack', '--pack-destination', packDir], packageDir);
75
+ const tarball = path.join(
76
+ packDir,
77
+ readdirSync(packDir).find(name => name.endsWith('.tgz')),
78
+ );
79
+ run(
80
+ 'tar',
81
+ ['-xzf', tarball, '-C', packedPackageDir, '--strip-components=1'],
82
+ root,
83
+ );
84
+
85
+ const manifest = JSON.parse(
86
+ readFileSync(path.join(packedPackageDir, 'package.json'), 'utf8'),
87
+ );
88
+ // Recreate strict dependency visibility from the packed manifest rather
89
+ // than letting the monorepo's hoisted packages satisfy missing entries.
90
+ for (const dependency of Object.keys(manifest.dependencies || {})) {
91
+ linkPackage(packageDir, dependency, packedPackageDir);
92
+ }
93
+ for (const peer of Object.keys(manifest.peerDependencies || {})) {
94
+ linkPackage(packageDir, peer, packedPackageDir);
95
+ linkPackage(packageDir, peer, appDir);
96
+ }
97
+
98
+ symlinkSync(
99
+ packedPackageDir,
100
+ path.join(appDir, 'node_modules/@astryxdesign/build'),
101
+ 'junction',
102
+ );
103
+ const virtualStoreRoot = path.join(repoRoot, 'node_modules/.pnpm');
104
+ linkPackage(virtualStoreRoot, 'postcss', appDir);
105
+ linkPackage(virtualStoreRoot, '@stylexjs/stylex', appDir);
106
+
107
+ writeFileSync(
108
+ path.join(appDir, 'package.json'),
109
+ JSON.stringify({
110
+ name: 'astryx-build-consumer-contract',
111
+ private: true,
112
+ type: 'module',
113
+ }),
114
+ );
115
+ writeFileSync(
116
+ path.join(appDir, 'index.html'),
117
+ '<!doctype html><html><body><script type="module" src="/src/main.js"></script></body></html>\n',
118
+ );
119
+ writeFileSync(
120
+ path.join(appDir, 'src/main.js'),
121
+ [
122
+ "import * as stylex from '@stylexjs/stylex';",
123
+ "const styles = stylex.create({item: {userSelect: 'none'}});",
124
+ 'document.body.className = stylex.props(styles.item).className;',
125
+ '',
126
+ ].join('\n'),
127
+ );
128
+ writeFileSync(
129
+ path.join(appDir, 'vite.config.mjs'),
130
+ [
131
+ "import {astryxStylex} from '@astryxdesign/build/vite';",
132
+ 'export default {plugins: [...astryxStylex({rootDir: process.cwd()})]};',
133
+ '',
134
+ ].join('\n'),
135
+ );
136
+ writeFileSync(
137
+ path.join(appDir, 'check-postcss.cjs'),
138
+ [
139
+ "const path = require('node:path');",
140
+ "const postcss = require('postcss');",
141
+ "const {postcss: buildPostcss} = require('@astryxdesign/build');",
142
+ "for (const dependency of ['autoprefixer', 'browserslist', 'lightningcss']) {",
143
+ ' try {',
144
+ ' require.resolve(dependency);',
145
+ ' throw new Error(`${dependency} leaked into the consumer root`);',
146
+ ' } catch (error) {',
147
+ " if (error.code !== 'MODULE_NOT_FOUND') throw error;",
148
+ ' }',
149
+ '}',
150
+ 'const config = buildPostcss(__dirname);',
151
+ 'const plugins = Object.entries(config.plugins).map(([id, options]) => {',
152
+ ' if (!path.isAbsolute(id)) throw new Error(`unowned PostCSS plugin: ${id}`);',
153
+ ' return require(id)(options);',
154
+ '});',
155
+ "postcss(plugins).process('@stylex;', {from: 'input.css'}).then(() => {",
156
+ " process.stdout.write('postcss-ok\\n');",
157
+ '});',
158
+ '',
159
+ ].join('\n'),
160
+ );
161
+ }, 120_000);
162
+
163
+ afterAll(() => {
164
+ if (root) rmSync(root, {recursive: true, force: true});
165
+ });
166
+
167
+ it('loads the public PostCSS helper without undeclared consumer packages', () => {
168
+ expect(run(process.execPath, ['check-postcss.cjs'], appDir)).toBe(
169
+ 'postcss-ok\n',
170
+ );
171
+ });
172
+
173
+ it('keeps the Vite compatibility pass inside the package boundary', () => {
174
+ const viteCli = path.join(
175
+ packedPackageDir,
176
+ 'node_modules/vite/bin/vite.js',
177
+ );
178
+ run(process.execPath, [viteCli, 'build'], appDir);
179
+ const assetsDir = path.join(appDir, 'dist/assets');
180
+ const cssFile = readdirSync(assetsDir).find(name => name.endsWith('.css'));
181
+ expect(cssFile).toBeDefined();
182
+ expect(readFileSync(path.join(assetsDir, cssFile), 'utf8')).toContain(
183
+ '-webkit-user-select',
184
+ );
185
+ });
186
+ });
package/src/vite.test.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  * @file vite.test.ts
5
- * @description Verifies CSS layer-order injection in the XDS Vite plugin.
5
+ * @description Verifies CSS layer-order injection in the Astryx Vite plugin.
6
6
  * The library layer name is configurable (default `astryx-base`); the
7
7
  * theme layer name is fixed at `astryx-theme`.
8
8
  */