@stylexjs/rollup-plugin 0.2.0-beta.9 → 0.3.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/__tests__/index-test.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
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';
|
|
@@ -56,58 +58,94 @@ describe('rollup-plugin-stylex', () => {
|
|
|
56
58
|
const { css, js } = await runStylex({ fileName: 'stylex.css' });
|
|
57
59
|
|
|
58
60
|
expect(css).toMatchInlineSnapshot(`
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
.
|
|
61
|
+
"
|
|
62
|
+
@layer priority1, priority2, priority3, priority4;
|
|
63
|
+
@layer priority1{
|
|
64
|
+
@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}
|
|
65
|
+
}
|
|
66
|
+
@layer priority2{
|
|
67
|
+
.x1oz5o6v:hover{background:red}
|
|
68
|
+
}
|
|
69
|
+
@layer priority3{
|
|
70
|
+
.xeuoslp{animation-name:xgnty7z-B}
|
|
71
|
+
.x1lliihq{display:block}
|
|
72
|
+
.x78zum5{display:flex}
|
|
73
|
+
.xt0psk2{display:inline}
|
|
74
|
+
.x1hm9lzh{margin-inline-start:10px}
|
|
75
|
+
}
|
|
76
|
+
@layer priority4{
|
|
77
|
+
.x1egiwwb{height:500px}
|
|
78
|
+
.xlrshdv{margin-top:99px}
|
|
79
|
+
.xh8yej3{width:100%}
|
|
80
|
+
.x3hqpx7{width:50%}
|
|
81
|
+
}"
|
|
70
82
|
`);
|
|
71
83
|
|
|
72
84
|
expect(js).toMatchInlineSnapshot(`
|
|
73
85
|
"import stylex from 'stylex';
|
|
74
86
|
|
|
75
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
89
|
+
*
|
|
90
|
+
* This source code is licensed under the MIT license found in the
|
|
91
|
+
* LICENSE file in the root directory of this source tree.
|
|
92
|
+
*
|
|
93
|
+
*
|
|
94
|
+
*/
|
|
95
|
+
|
|
76
96
|
var styles$2 = {
|
|
77
97
|
bar: {
|
|
78
|
-
display: "
|
|
79
|
-
width: "
|
|
98
|
+
display: "x1lliihq",
|
|
99
|
+
width: "xh8yej3",
|
|
80
100
|
$$css: true
|
|
81
101
|
}
|
|
82
102
|
};
|
|
83
103
|
|
|
84
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
106
|
+
*
|
|
107
|
+
* This source code is licensed under the MIT license found in the
|
|
108
|
+
* LICENSE file in the root directory of this source tree.
|
|
109
|
+
*
|
|
110
|
+
*
|
|
111
|
+
*/
|
|
112
|
+
|
|
85
113
|
const styles$1 = {
|
|
86
114
|
baz: {
|
|
87
|
-
display: "
|
|
88
|
-
height: "
|
|
89
|
-
width: "
|
|
115
|
+
display: "xt0psk2",
|
|
116
|
+
height: "x1egiwwb",
|
|
117
|
+
width: "x3hqpx7",
|
|
90
118
|
$$css: true
|
|
91
119
|
}
|
|
92
120
|
};
|
|
93
121
|
|
|
94
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
124
|
+
*
|
|
125
|
+
* This source code is licensed under the MIT license found in the
|
|
126
|
+
* LICENSE file in the root directory of this source tree.
|
|
127
|
+
*
|
|
128
|
+
*
|
|
129
|
+
*/
|
|
130
|
+
|
|
95
131
|
var styles = {
|
|
96
132
|
foo: {
|
|
97
|
-
animationName: "
|
|
98
|
-
display: "
|
|
99
|
-
marginInlineStart: "
|
|
133
|
+
animationName: "xeuoslp",
|
|
134
|
+
display: "x78zum5",
|
|
135
|
+
marginInlineStart: "x1hm9lzh",
|
|
100
136
|
marginLeft: null,
|
|
101
137
|
marginRight: null,
|
|
102
|
-
marginTop: "
|
|
103
|
-
height: "
|
|
104
|
-
":hover_background": "
|
|
138
|
+
marginTop: "xlrshdv",
|
|
139
|
+
height: "x1egiwwb",
|
|
140
|
+
":hover_background": "x1oz5o6v",
|
|
105
141
|
":hover_backgroundAttachment": null,
|
|
106
142
|
":hover_backgroundClip": null,
|
|
107
143
|
":hover_backgroundColor": null,
|
|
108
144
|
":hover_backgroundImage": null,
|
|
109
145
|
":hover_backgroundOrigin": null,
|
|
110
146
|
":hover_backgroundPosition": null,
|
|
147
|
+
":hover_backgroundPositionX": null,
|
|
148
|
+
":hover_backgroundPositionY": null,
|
|
111
149
|
":hover_backgroundRepeat": null,
|
|
112
150
|
":hover_backgroundSize": null,
|
|
113
151
|
$$css: true
|
|
@@ -126,7 +164,6 @@ describe('rollup-plugin-stylex', () => {
|
|
|
126
164
|
it('preserves stylex.inject calls and does not extract CSS', async () => {
|
|
127
165
|
const { css, js } = await runStylex({
|
|
128
166
|
dev: true,
|
|
129
|
-
fileName: 'stylex.css',
|
|
130
167
|
});
|
|
131
168
|
|
|
132
169
|
expect(css).toBeUndefined();
|
|
@@ -134,57 +171,83 @@ describe('rollup-plugin-stylex', () => {
|
|
|
134
171
|
expect(js).toMatchInlineSnapshot(`
|
|
135
172
|
"import stylex from 'stylex';
|
|
136
173
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
174
|
+
/**
|
|
175
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
176
|
+
*
|
|
177
|
+
* This source code is licensed under the MIT license found in the
|
|
178
|
+
* LICENSE file in the root directory of this source tree.
|
|
179
|
+
*
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
|
|
183
|
+
stylex.inject(".x1lliihq{display:block}", 3000);
|
|
184
|
+
stylex.inject(".xh8yej3{width:100%}", 4000);
|
|
140
185
|
var styles$2 = {
|
|
141
186
|
bar: {
|
|
142
187
|
"otherStyles__styles.bar": "otherStyles__styles.bar",
|
|
143
|
-
display: "
|
|
144
|
-
width: "
|
|
188
|
+
display: "x1lliihq",
|
|
189
|
+
width: "xh8yej3",
|
|
145
190
|
$$css: true
|
|
146
191
|
}
|
|
147
192
|
};
|
|
148
193
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
196
|
+
*
|
|
197
|
+
* This source code is licensed under the MIT license found in the
|
|
198
|
+
* LICENSE file in the root directory of this source tree.
|
|
199
|
+
*
|
|
200
|
+
*
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
stylex.inject(".xt0psk2{display:inline}", 3000);
|
|
204
|
+
stylex.inject(".x1egiwwb{height:500px}", 4000);
|
|
205
|
+
stylex.inject(".x3hqpx7{width:50%}", 4000);
|
|
153
206
|
const styles$1 = {
|
|
154
207
|
baz: {
|
|
155
208
|
"npmStyles__styles.baz": "npmStyles__styles.baz",
|
|
156
|
-
display: "
|
|
157
|
-
height: "
|
|
158
|
-
width: "
|
|
209
|
+
display: "xt0psk2",
|
|
210
|
+
height: "x1egiwwb",
|
|
211
|
+
width: "x3hqpx7",
|
|
159
212
|
$$css: true
|
|
160
213
|
}
|
|
161
214
|
};
|
|
162
215
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
218
|
+
*
|
|
219
|
+
* This source code is licensed under the MIT license found in the
|
|
220
|
+
* LICENSE file in the root directory of this source tree.
|
|
221
|
+
*
|
|
222
|
+
*
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
stylex.inject("@keyframes xgnty7z-B{0%{opacity:.25;}100%{opacity:1;}}", 1);
|
|
226
|
+
stylex.inject(".xeuoslp{animation-name:xgnty7z-B}", 3000);
|
|
227
|
+
stylex.inject(".x78zum5{display:flex}", 3000);
|
|
228
|
+
stylex.inject(".x1hm9lzh{margin-inline-start:10px}", 3000);
|
|
229
|
+
stylex.inject(".xlrshdv{margin-top:99px}", 4000);
|
|
230
|
+
stylex.inject(".x1egiwwb{height:500px}", 4000);
|
|
231
|
+
stylex.inject(".x1oz5o6v:hover{background:red}", 1130);
|
|
171
232
|
var styles = {
|
|
172
233
|
foo: {
|
|
173
234
|
"index__styles.foo": "index__styles.foo",
|
|
174
|
-
animationName: "
|
|
175
|
-
display: "
|
|
176
|
-
marginInlineStart: "
|
|
235
|
+
animationName: "xeuoslp",
|
|
236
|
+
display: "x78zum5",
|
|
237
|
+
marginInlineStart: "x1hm9lzh",
|
|
177
238
|
marginLeft: null,
|
|
178
239
|
marginRight: null,
|
|
179
|
-
marginTop: "
|
|
180
|
-
height: "
|
|
181
|
-
":hover_background": "
|
|
240
|
+
marginTop: "xlrshdv",
|
|
241
|
+
height: "x1egiwwb",
|
|
242
|
+
":hover_background": "x1oz5o6v",
|
|
182
243
|
":hover_backgroundAttachment": null,
|
|
183
244
|
":hover_backgroundClip": null,
|
|
184
245
|
":hover_backgroundColor": null,
|
|
185
246
|
":hover_backgroundImage": null,
|
|
186
247
|
":hover_backgroundOrigin": null,
|
|
187
248
|
":hover_backgroundPosition": null,
|
|
249
|
+
":hover_backgroundPositionX": null,
|
|
250
|
+
":hover_backgroundPositionY": null,
|
|
188
251
|
":hover_backgroundRepeat": null,
|
|
189
252
|
":hover_backgroundSize": null,
|
|
190
253
|
$$css: true
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexjs/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Rollup plugin for
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Rollup plugin for StyleX",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"repository": "https://www.github.com/
|
|
6
|
+
"repository": "https://www.github.com/facebook/stylex",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"test": "jest"
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/core": "^7.16.0",
|
|
21
|
-
"@stylexjs/babel-plugin": "0.
|
|
21
|
+
"@stylexjs/babel-plugin": "0.3.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@babel/preset-env": "^7.16.8",
|
|
25
25
|
"@rollup/plugin-babel": "^6.0.0",
|
|
26
|
-
"@rollup/plugin-commonjs": "^
|
|
26
|
+
"@rollup/plugin-commonjs": "^25.0.3",
|
|
27
27
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
28
|
-
"rollup": "^3.
|
|
29
|
-
"@stylexjs/stylex": "0.
|
|
28
|
+
"rollup": "^3.26.3 || ^4.0.2",
|
|
29
|
+
"@stylexjs/stylex": "0.3.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
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
|
+
* @format
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
const babel = require('@babel/core');
|
|
@@ -18,11 +20,12 @@ const IS_DEV_ENV =
|
|
|
18
20
|
|
|
19
21
|
module.exports = function stylexPlugin({
|
|
20
22
|
dev = IS_DEV_ENV,
|
|
23
|
+
unstable_moduleResolution = { type: 'commonJS', rootDir: process.cwd() },
|
|
21
24
|
fileName = 'stylex.css',
|
|
22
|
-
|
|
25
|
+
babelConfig: { plugins = [], presets = [] } = {},
|
|
26
|
+
...options
|
|
23
27
|
} = {}) {
|
|
24
28
|
let stylexRules = {};
|
|
25
|
-
|
|
26
29
|
return {
|
|
27
30
|
name: 'rollup-plugin-stylex',
|
|
28
31
|
buildStart() {
|
|
@@ -31,8 +34,7 @@ module.exports = function stylexPlugin({
|
|
|
31
34
|
generateBundle() {
|
|
32
35
|
const rules = Object.values(stylexRules).flat();
|
|
33
36
|
if (rules.length > 0) {
|
|
34
|
-
const collectedCSS = stylexBabelPlugin.processStylexRules(rules);
|
|
35
|
-
|
|
37
|
+
const collectedCSS = stylexBabelPlugin.processStylexRules(rules, true);
|
|
36
38
|
this.emitFile({
|
|
37
39
|
fileName,
|
|
38
40
|
source: collectedCSS,
|
|
@@ -40,7 +42,7 @@ module.exports = function stylexPlugin({
|
|
|
40
42
|
});
|
|
41
43
|
}
|
|
42
44
|
},
|
|
43
|
-
shouldTransformCachedModule({ code, id, cache, meta }) {
|
|
45
|
+
shouldTransformCachedModule({ code: _code, id, cache: _cache, meta }) {
|
|
44
46
|
stylexRules[id] = meta.stylex;
|
|
45
47
|
return false;
|
|
46
48
|
},
|
|
@@ -55,14 +57,13 @@ module.exports = function stylexPlugin({
|
|
|
55
57
|
? flowSyntaxPlugin
|
|
56
58
|
: typescriptSyntaxPlugin,
|
|
57
59
|
jsxSyntaxPlugin,
|
|
58
|
-
[stylexBabelPlugin, { dev,
|
|
60
|
+
[stylexBabelPlugin, { dev, unstable_moduleResolution, ...options }],
|
|
59
61
|
],
|
|
60
62
|
});
|
|
61
63
|
|
|
62
64
|
if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
|
|
63
65
|
stylexRules[id] = metadata.stylex;
|
|
64
66
|
}
|
|
65
|
-
|
|
66
67
|
return { code, map, meta: metadata };
|
|
67
68
|
},
|
|
68
69
|
};
|