@astryxdesign/build 0.7.5 → 0.7.6-canary.0bd3b37
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 +2 -0
- package/dist/undefinedVariables.d.ts +32 -0
- package/dist/vite.mjs +107 -10
- package/package.json +15 -2
- package/src/index.js +12 -8
- package/src/undefinedVariables.ts +57 -0
- package/src/vite.ts +145 -6
- package/src/babel.test.mjs +0 -111
- package/src/next.test.mjs +0 -753
- package/src/packed-consumer.test.mjs +0 -186
- package/src/postcss.data-defaults.test.mjs +0 -168
- package/src/postcss.test.mjs +0 -135
- package/src/postcss.workspace-links.test.mjs +0 -163
- package/src/vite.build.test.ts +0 -347
- package/src/vite.test.ts +0 -274
package/src/babel.test.mjs
DELETED
|
@@ -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
|
-
});
|