@stylexjs/rollup-plugin 0.2.0-beta.9 → 0.4.0
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/.babelrc.cjs +17 -0
- package/README.md +31 -1
- package/__tests__/__fixtures__/index.js +9 -0
- package/__tests__/__fixtures__/npmStyles.js +9 -0
- package/__tests__/__fixtures__/otherStyles.js +9 -0
- package/__tests__/index-test.js +129 -61
- package/flow_modules/@babel/core/index.js.flow +854 -0
- package/flow_modules/@babel/generator/index.js.flow +216 -0
- package/flow_modules/@babel/parser/index.js.flow +253 -0
- package/flow_modules/@babel/traverse/index.js.flow +1002 -0
- package/flow_modules/@babel/types/index.js.flow +5224 -0
- package/flow_modules/rollup/index.js +1098 -0
- package/lib/index.d.ts +34 -0
- package/lib/index.js +91 -0
- package/lib/index.js.flow +25 -0
- package/package.json +12 -14
- package/src/index.js +74 -22
package/.babelrc.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
assumptions: {
|
|
3
|
+
iterableIsArray: true,
|
|
4
|
+
},
|
|
5
|
+
presets: [
|
|
6
|
+
[
|
|
7
|
+
'@babel/preset-env',
|
|
8
|
+
{
|
|
9
|
+
exclude: ['@babel/plugin-transform-typeof-symbol'],
|
|
10
|
+
targets: 'defaults',
|
|
11
|
+
modules: process.env.NODE_ENV === 'test' ? 'commonjs' : false,
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
'@babel/preset-flow',
|
|
15
|
+
],
|
|
16
|
+
plugins: [['babel-plugin-syntax-hermes-parser', { flow: 'detect' }]],
|
|
17
|
+
};
|
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
1
|
# @stylexjs/rollup-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Documentation Website
|
|
4
|
+
[https://stylexjs.com](https://stylexjs.com)
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install the package by using:
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-dev @stylexjs/rollup-plugin
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or with yarn:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
yarn add --dev @stylexjs/rollup-plugin
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Add the following to you `rollup.config.mjs`
|
|
20
|
+
```javascript
|
|
21
|
+
import stylexPlugin from '@stylexjs/rollup-plugin';
|
|
22
|
+
|
|
23
|
+
const config = {
|
|
24
|
+
input: './index.js',
|
|
25
|
+
output: {
|
|
26
|
+
file: './.build/bundle.js',
|
|
27
|
+
format: 'es',
|
|
28
|
+
},
|
|
29
|
+
plugins: [stylexPlugin({ fileName: 'stylex.css' })],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export default config;
|
|
33
|
+
```
|
package/__tests__/index-test.js
CHANGED
|
@@ -3,23 +3,29 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
'use strict';
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import rollup from 'rollup';
|
|
14
|
+
import { babel } from '@rollup/plugin-babel';
|
|
15
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
16
|
+
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
17
|
+
import stylexPlugin from '../src/index';
|
|
16
18
|
|
|
17
19
|
describe('rollup-plugin-stylex', () => {
|
|
18
20
|
async function runStylex(options) {
|
|
19
21
|
// Configure a rollup bundle
|
|
20
22
|
const bundle = await rollup.rollup({
|
|
21
23
|
// Remove stylex runtime from bundle
|
|
22
|
-
external: [
|
|
24
|
+
external: [
|
|
25
|
+
'stylex',
|
|
26
|
+
'@stylexjs/stylex',
|
|
27
|
+
'@stylexjs/stylex/lib/stylex-inject',
|
|
28
|
+
],
|
|
23
29
|
input: path.resolve(__dirname, '__fixtures__/index.js'),
|
|
24
30
|
plugins: [
|
|
25
31
|
nodeResolve(),
|
|
@@ -29,7 +35,7 @@ describe('rollup-plugin-stylex', () => {
|
|
|
29
35
|
configFile: path.resolve(__dirname, '__fixtures__/.babelrc.json'),
|
|
30
36
|
exclude: [/npmStyles\.js/],
|
|
31
37
|
}),
|
|
32
|
-
stylexPlugin(options),
|
|
38
|
+
stylexPlugin({ useCSSLayers: true, ...options }),
|
|
33
39
|
],
|
|
34
40
|
});
|
|
35
41
|
|
|
@@ -56,58 +62,94 @@ describe('rollup-plugin-stylex', () => {
|
|
|
56
62
|
const { css, js } = await runStylex({ fileName: 'stylex.css' });
|
|
57
63
|
|
|
58
64
|
expect(css).toMatchInlineSnapshot(`
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
.
|
|
65
|
+
"
|
|
66
|
+
@layer priority1, priority2, priority3, priority4;
|
|
67
|
+
@layer priority1{
|
|
68
|
+
@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}
|
|
69
|
+
}
|
|
70
|
+
@layer priority2{
|
|
71
|
+
.x1oz5o6v:hover{background:red}
|
|
72
|
+
}
|
|
73
|
+
@layer priority3{
|
|
74
|
+
.xeuoslp{animation-name:xgnty7z-B}
|
|
75
|
+
.x1lliihq{display:block}
|
|
76
|
+
.x78zum5{display:flex}
|
|
77
|
+
.xt0psk2{display:inline}
|
|
78
|
+
.x1hm9lzh{margin-inline-start:10px}
|
|
79
|
+
}
|
|
80
|
+
@layer priority4{
|
|
81
|
+
.x1egiwwb{height:500px}
|
|
82
|
+
.xlrshdv{margin-top:99px}
|
|
83
|
+
.xh8yej3{width:100%}
|
|
84
|
+
.x3hqpx7{width:50%}
|
|
85
|
+
}"
|
|
70
86
|
`);
|
|
71
87
|
|
|
72
88
|
expect(js).toMatchInlineSnapshot(`
|
|
73
89
|
"import stylex from 'stylex';
|
|
74
90
|
|
|
75
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the MIT license found in the
|
|
95
|
+
* LICENSE file in the root directory of this source tree.
|
|
96
|
+
*
|
|
97
|
+
*
|
|
98
|
+
*/
|
|
99
|
+
|
|
76
100
|
var styles$2 = {
|
|
77
101
|
bar: {
|
|
78
|
-
display: "
|
|
79
|
-
width: "
|
|
102
|
+
display: "x1lliihq",
|
|
103
|
+
width: "xh8yej3",
|
|
80
104
|
$$css: true
|
|
81
105
|
}
|
|
82
106
|
};
|
|
83
107
|
|
|
84
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
110
|
+
*
|
|
111
|
+
* This source code is licensed under the MIT license found in the
|
|
112
|
+
* LICENSE file in the root directory of this source tree.
|
|
113
|
+
*
|
|
114
|
+
*
|
|
115
|
+
*/
|
|
116
|
+
|
|
85
117
|
const styles$1 = {
|
|
86
118
|
baz: {
|
|
87
|
-
display: "
|
|
88
|
-
height: "
|
|
89
|
-
width: "
|
|
119
|
+
display: "xt0psk2",
|
|
120
|
+
height: "x1egiwwb",
|
|
121
|
+
width: "x3hqpx7",
|
|
90
122
|
$$css: true
|
|
91
123
|
}
|
|
92
124
|
};
|
|
93
125
|
|
|
94
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
128
|
+
*
|
|
129
|
+
* This source code is licensed under the MIT license found in the
|
|
130
|
+
* LICENSE file in the root directory of this source tree.
|
|
131
|
+
*
|
|
132
|
+
*
|
|
133
|
+
*/
|
|
134
|
+
|
|
95
135
|
var styles = {
|
|
96
136
|
foo: {
|
|
97
|
-
animationName: "
|
|
98
|
-
display: "
|
|
99
|
-
marginInlineStart: "
|
|
137
|
+
animationName: "xeuoslp",
|
|
138
|
+
display: "x78zum5",
|
|
139
|
+
marginInlineStart: "x1hm9lzh",
|
|
100
140
|
marginLeft: null,
|
|
101
141
|
marginRight: null,
|
|
102
|
-
marginTop: "
|
|
103
|
-
height: "
|
|
104
|
-
":hover_background": "
|
|
142
|
+
marginTop: "xlrshdv",
|
|
143
|
+
height: "x1egiwwb",
|
|
144
|
+
":hover_background": "x1oz5o6v",
|
|
105
145
|
":hover_backgroundAttachment": null,
|
|
106
146
|
":hover_backgroundClip": null,
|
|
107
147
|
":hover_backgroundColor": null,
|
|
108
148
|
":hover_backgroundImage": null,
|
|
109
149
|
":hover_backgroundOrigin": null,
|
|
110
150
|
":hover_backgroundPosition": null,
|
|
151
|
+
":hover_backgroundPositionX": null,
|
|
152
|
+
":hover_backgroundPositionY": null,
|
|
111
153
|
":hover_backgroundRepeat": null,
|
|
112
154
|
":hover_backgroundSize": null,
|
|
113
155
|
$$css: true
|
|
@@ -126,65 +168,91 @@ describe('rollup-plugin-stylex', () => {
|
|
|
126
168
|
it('preserves stylex.inject calls and does not extract CSS', async () => {
|
|
127
169
|
const { css, js } = await runStylex({
|
|
128
170
|
dev: true,
|
|
129
|
-
fileName: 'stylex.css',
|
|
130
171
|
});
|
|
131
172
|
|
|
132
173
|
expect(css).toBeUndefined();
|
|
133
174
|
|
|
134
175
|
expect(js).toMatchInlineSnapshot(`
|
|
135
|
-
"import
|
|
176
|
+
"import _inject from '@stylexjs/stylex/lib/stylex-inject';
|
|
177
|
+
import stylex from 'stylex';
|
|
136
178
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
181
|
+
*
|
|
182
|
+
* This source code is licensed under the MIT license found in the
|
|
183
|
+
* LICENSE file in the root directory of this source tree.
|
|
184
|
+
*
|
|
185
|
+
*
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
_inject(".x1lliihq{display:block}", 3000);
|
|
189
|
+
_inject(".xh8yej3{width:100%}", 4000);
|
|
140
190
|
var styles$2 = {
|
|
141
191
|
bar: {
|
|
142
192
|
"otherStyles__styles.bar": "otherStyles__styles.bar",
|
|
143
|
-
display: "
|
|
144
|
-
width: "
|
|
193
|
+
display: "x1lliihq",
|
|
194
|
+
width: "xh8yej3",
|
|
145
195
|
$$css: true
|
|
146
196
|
}
|
|
147
197
|
};
|
|
148
198
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
199
|
+
/**
|
|
200
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
201
|
+
*
|
|
202
|
+
* This source code is licensed under the MIT license found in the
|
|
203
|
+
* LICENSE file in the root directory of this source tree.
|
|
204
|
+
*
|
|
205
|
+
*
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
_inject(".xt0psk2{display:inline}", 3000);
|
|
209
|
+
_inject(".x1egiwwb{height:500px}", 4000);
|
|
210
|
+
_inject(".x3hqpx7{width:50%}", 4000);
|
|
153
211
|
const styles$1 = {
|
|
154
212
|
baz: {
|
|
155
213
|
"npmStyles__styles.baz": "npmStyles__styles.baz",
|
|
156
|
-
display: "
|
|
157
|
-
height: "
|
|
158
|
-
width: "
|
|
214
|
+
display: "xt0psk2",
|
|
215
|
+
height: "x1egiwwb",
|
|
216
|
+
width: "x3hqpx7",
|
|
159
217
|
$$css: true
|
|
160
218
|
}
|
|
161
219
|
};
|
|
162
220
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
223
|
+
*
|
|
224
|
+
* This source code is licensed under the MIT license found in the
|
|
225
|
+
* LICENSE file in the root directory of this source tree.
|
|
226
|
+
*
|
|
227
|
+
*
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
_inject("@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}", 1);
|
|
231
|
+
_inject(".xeuoslp{animation-name:xgnty7z-B}", 3000);
|
|
232
|
+
_inject(".x78zum5{display:flex}", 3000);
|
|
233
|
+
_inject(".x1hm9lzh{margin-inline-start:10px}", 3000);
|
|
234
|
+
_inject(".xlrshdv{margin-top:99px}", 4000);
|
|
235
|
+
_inject(".x1egiwwb{height:500px}", 4000);
|
|
236
|
+
_inject(".x1oz5o6v:hover{background:red}", 1130);
|
|
171
237
|
var styles = {
|
|
172
238
|
foo: {
|
|
173
239
|
"index__styles.foo": "index__styles.foo",
|
|
174
|
-
animationName: "
|
|
175
|
-
display: "
|
|
176
|
-
marginInlineStart: "
|
|
240
|
+
animationName: "xeuoslp",
|
|
241
|
+
display: "x78zum5",
|
|
242
|
+
marginInlineStart: "x1hm9lzh",
|
|
177
243
|
marginLeft: null,
|
|
178
244
|
marginRight: null,
|
|
179
|
-
marginTop: "
|
|
180
|
-
height: "
|
|
181
|
-
":hover_background": "
|
|
245
|
+
marginTop: "xlrshdv",
|
|
246
|
+
height: "x1egiwwb",
|
|
247
|
+
":hover_background": "x1oz5o6v",
|
|
182
248
|
":hover_backgroundAttachment": null,
|
|
183
249
|
":hover_backgroundClip": null,
|
|
184
250
|
":hover_backgroundColor": null,
|
|
185
251
|
":hover_backgroundImage": null,
|
|
186
252
|
":hover_backgroundOrigin": null,
|
|
187
253
|
":hover_backgroundPosition": null,
|
|
254
|
+
":hover_backgroundPositionX": null,
|
|
255
|
+
":hover_backgroundPositionY": null,
|
|
188
256
|
":hover_backgroundRepeat": null,
|
|
189
257
|
":hover_backgroundSize": null,
|
|
190
258
|
$$css: true
|