@astryxdesign/build 0.7.6-canary.f73623d → 0.7.6-canary.f78b205

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/build",
3
- "version": "0.7.6-canary.f73623d",
3
+ "version": "0.7.6-canary.f78b205",
4
4
  "description": "Build plugins for Astryx source builds — babel, PostCSS, and Vite integrations",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -33,7 +33,20 @@
33
33
  },
34
34
  "files": [
35
35
  "src",
36
- "dist"
36
+ "dist",
37
+ "!**/*.test.*",
38
+ "!**/*.spec.js",
39
+ "!**/*.spec.jsx",
40
+ "!**/*.spec.mjs",
41
+ "!**/*.spec.cjs",
42
+ "!**/*.spec.ts",
43
+ "!**/*.spec.tsx",
44
+ "!**/*.spec.mts",
45
+ "!**/*.spec.cts",
46
+ "!**/*.spec.d.ts",
47
+ "!**/__tests__/**",
48
+ "!**/__mocks__/**",
49
+ "!**/*.bench.*"
37
50
  ],
38
51
  "peerDependencies": {
39
52
  "@babel/core": ">=7.0.0",
@@ -62,6 +75,7 @@
62
75
  }
63
76
  },
64
77
  "scripts": {
78
+ "api:report": "node ../../scripts/api-report/cli.mjs --package .",
65
79
  "build": "node build.mjs"
66
80
  }
67
81
  }
package/src/index.js CHANGED
@@ -42,12 +42,12 @@ const LIBRARY_PATTERNS = [
42
42
  const STYLEX_IMPORT_SOURCE = '@stylexjs/stylex';
43
43
 
44
44
  /**
45
- * Globs for the source each installed Astryx package publishes: each `files`
46
- * entry, a directory (the files below it) or a file, or the whole package when
47
- * it has none; an entry with glob characters or a leading `!` is refused, not
48
- * approximated. A package's own `node_modules` is never scanned: in a
49
- * workspace its links can lead back to the package (here, core's dev
50
- * dependency `@astryxdesign/cli` links core again).
45
+ * Globs for the source each installed Astryx package publishes: each positive
46
+ * `files` entry is a directory (the files below it) or a file, while negated
47
+ * entries become discovery exclusions. Positive entries with glob characters
48
+ * are refused rather than approximated. A package's own `node_modules` is never
49
+ * scanned: in a workspace its links can lead back to the package (here, core's
50
+ * dev dependency `@astryxdesign/cli` links core again).
51
51
  */
52
52
  function libraryGlobs(cwd) {
53
53
  const include = [];
@@ -69,10 +69,14 @@ function libraryGlobs(cwd) {
69
69
  continue;
70
70
  }
71
71
  for (const entry of files) {
72
- // isGlob also flags a leading `!`.
72
+ if (entry.startsWith('!')) {
73
+ const excluded = entry.slice(1).replace(/^\.?\/|\/$/g, '');
74
+ if (excluded) ignore.push(`${base}/${excluded}`);
75
+ continue;
76
+ }
73
77
  if (isGlob(entry)) {
74
78
  throw new Error(
75
- `@astryxdesign/build reads plain files entries only; @astryxdesign/${name} lists "${entry}"`,
79
+ `@astryxdesign/build reads plain positive files entries only; @astryxdesign/${name} lists "${entry}"`,
76
80
  );
77
81
  }
78
82
  const plain = entry.replace(/^\.?\/|\/$/g, '');
@@ -1,111 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file babel.test.mjs
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.
8
- */
9
-
10
- import {describe, it, expect} from 'vitest';
11
- import {createRequire} from 'node:module';
12
-
13
- const require = createRequire(import.meta.url);
14
- const babel = require('@babel/core');
15
- const astryxBabelPlugin = require('./babel.js');
16
- const {stylexOptions: buildStylexOptions} = require('./config.js');
17
-
18
- const SOURCE = `
19
- import * as stylex from '@stylexjs/stylex';
20
- export const styles = stylex.create({
21
- box: {color: 'red'},
22
- });
23
- `;
24
-
25
- const INVALID_BORDER_SOURCE = `
26
- import * as stylex from '@stylexjs/stylex';
27
- export const styles = stylex.create({
28
- box: {borderTop: '1px solid var(--color-border)'},
29
- });
30
- `;
31
-
32
- /**
33
- * Transform a StyleX source through the Astryx babel wrapper as if it were an
34
- * Astryx library file, returning the emitted code. `libraryPrefix` controls the
35
- * atomic class-name prefix for library files.
36
- */
37
- function transformLibraryFile(
38
- libraryPrefix,
39
- source = SOURCE,
40
- stylexOptions = {},
41
- ) {
42
- const result = babel.transformSync(source, {
43
- // A path matching one of the library patterns so the wrapper routes it
44
- // through the library plugin instance.
45
- filename: 'node_modules/@astryxdesign/core/src/Box/AstryxBox.tsx',
46
- babelrc: false,
47
- configFile: false,
48
- plugins: [
49
- [
50
- astryxBabelPlugin,
51
- {
52
- ...(libraryPrefix ? {libraryPrefix} : {}),
53
- unstable_moduleResolution: {type: 'commonJS', rootDir: process.cwd()},
54
- ...stylexOptions,
55
- },
56
- ],
57
- ],
58
- });
59
- return result?.code ?? '';
60
- }
61
-
62
- /** Extract the StyleX atomic class names referenced in the emitted code. */
63
- function atomicClasses(code) {
64
- // StyleX emits atoms like "xds1a2b3c" / "astryx1a2b3c" in the compiled output.
65
- return code.match(/\b(?:xds|astryx|lib)[a-z0-9]{4,}\b/g) ?? [];
66
- }
67
-
68
- describe('Astryx babel wrapper -- library StyleX prefix', () => {
69
- it('defaults library atoms to the `astryx` prefix', () => {
70
- const code = transformLibraryFile(undefined);
71
- const atoms = atomicClasses(code);
72
- expect(atoms.length).toBeGreaterThan(0);
73
- expect(atoms.every(c => c.startsWith('astryx'))).toBe(true);
74
- expect(
75
- atoms.some(c => c.startsWith('xds') && !c.startsWith('astryx')),
76
- ).toBe(false);
77
- });
78
-
79
- it('uses a configured custom prefix for library atoms', () => {
80
- const code = transformLibraryFile('lib');
81
- const atoms = atomicClasses(code);
82
- expect(atoms.length).toBeGreaterThan(0);
83
- expect(atoms.every(c => c.startsWith('lib'))).toBe(true);
84
- });
85
-
86
- it('rejects declarations that StyleX would otherwise drop silently', () => {
87
- expect(() =>
88
- transformLibraryFile(undefined, INVALID_BORDER_SOURCE),
89
- ).toThrow(
90
- /borderTop is not supported.*borderTopWidth.*borderTopStyle.*borderTopColor/s,
91
- );
92
- });
93
-
94
- it('keeps the upstream validation mode override available', () => {
95
- expect(() =>
96
- transformLibraryFile(undefined, INVALID_BORDER_SOURCE, {
97
- propertyValidationMode: 'silent',
98
- }),
99
- ).not.toThrow();
100
- });
101
-
102
- it('uses the same strict default in generated Babel and PostCSS configs', () => {
103
- expect(buildStylexOptions(process.cwd()).propertyValidationMode).toBe(
104
- 'throw',
105
- );
106
- expect(
107
- buildStylexOptions(process.cwd(), {propertyValidationMode: 'warn'})
108
- .propertyValidationMode,
109
- ).toBe('warn');
110
- });
111
- });