@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 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
+ ```
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
1
10
  // index.js
2
11
 
3
12
  'use strict';
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
1
10
  // npmStyles.js
2
11
 
3
12
  'use strict';
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ */
9
+
1
10
  // otherStyles.js
2
11
 
3
12
  'use strict';
@@ -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
- const path = require('path');
11
- const rollup = require('rollup');
12
- const { babel } = require('@rollup/plugin-babel');
13
- const commonjs = require('@rollup/plugin-commonjs');
14
- const { nodeResolve } = require('@rollup/plugin-node-resolve');
15
- const stylexPlugin = require('../src/index');
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: ['stylex'],
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
- "@keyframes x11gtny7-B{0%{opacity:.25;}100%{opacity:1;}}
60
- .x1nrqb13{animation-name:x11gtny7-B}
61
- .xntgbld{display:block}
62
- .x1c4r43l{display:flex}
63
- .x1wdx05y{display:inline}
64
- .x1je5kxa{height:500px}
65
- .xo3gju4{margin-inline-start:10px}
66
- .x1h9ru99{margin-top:99px}
67
- .x6mlivy{width:100%}
68
- .x1u78jha{width:50%}
69
- .x1kflwvg:hover{background:red}"
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
- // otherStyles.js
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: "xntgbld",
79
- width: "x6mlivy",
102
+ display: "x1lliihq",
103
+ width: "xh8yej3",
80
104
  $$css: true
81
105
  }
82
106
  };
83
107
 
84
- // npmStyles.js
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: "x1wdx05y",
88
- height: "x1je5kxa",
89
- width: "x1u78jha",
119
+ display: "xt0psk2",
120
+ height: "x1egiwwb",
121
+ width: "x3hqpx7",
90
122
  $$css: true
91
123
  }
92
124
  };
93
125
 
94
- // index.js
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: "x1nrqb13",
98
- display: "x1c4r43l",
99
- marginInlineStart: "xo3gju4",
137
+ animationName: "xeuoslp",
138
+ display: "x78zum5",
139
+ marginInlineStart: "x1hm9lzh",
100
140
  marginLeft: null,
101
141
  marginRight: null,
102
- marginTop: "x1h9ru99",
103
- height: "x1je5kxa",
104
- ":hover_background": "x1kflwvg",
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 stylex from 'stylex';
176
+ "import _inject from '@stylexjs/stylex/lib/stylex-inject';
177
+ import stylex from 'stylex';
136
178
 
137
- // otherStyles.js
138
- stylex.inject(".xntgbld{display:block}", 4);
139
- stylex.inject(".x6mlivy{width:100%}", 4);
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: "xntgbld",
144
- width: "x6mlivy",
193
+ display: "x1lliihq",
194
+ width: "xh8yej3",
145
195
  $$css: true
146
196
  }
147
197
  };
148
198
 
149
- // npmStyles.js
150
- stylex.inject(".x1wdx05y{display:inline}", 4);
151
- stylex.inject(".x1je5kxa{height:500px}", 4);
152
- stylex.inject(".x1u78jha{width:50%}", 4);
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: "x1wdx05y",
157
- height: "x1je5kxa",
158
- width: "x1u78jha",
214
+ display: "xt0psk2",
215
+ height: "x1egiwwb",
216
+ width: "x3hqpx7",
159
217
  $$css: true
160
218
  }
161
219
  };
162
220
 
163
- // index.js
164
- stylex.inject("@keyframes x11gtny7-B{0%{opacity:.25;}100%{opacity:1;}}", 1);
165
- stylex.inject(".x1nrqb13{animation-name:x11gtny7-B}", 4);
166
- stylex.inject(".x1c4r43l{display:flex}", 4);
167
- stylex.inject(".xo3gju4{margin-inline-start:10px}", 4);
168
- stylex.inject(".x1h9ru99{margin-top:99px}", 4);
169
- stylex.inject(".x1je5kxa{height:500px}", 4);
170
- stylex.inject(".x1kflwvg:hover{background:red}", 16);
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: "x1nrqb13",
175
- display: "x1c4r43l",
176
- marginInlineStart: "xo3gju4",
240
+ animationName: "xeuoslp",
241
+ display: "x78zum5",
242
+ marginInlineStart: "x1hm9lzh",
177
243
  marginLeft: null,
178
244
  marginRight: null,
179
- marginTop: "x1h9ru99",
180
- height: "x1je5kxa",
181
- ":hover_background": "x1kflwvg",
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