@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.
@@ -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,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
- "@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}"
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
- // otherStyles.js
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: "xntgbld",
79
- width: "x6mlivy",
98
+ display: "x1lliihq",
99
+ width: "xh8yej3",
80
100
  $$css: true
81
101
  }
82
102
  };
83
103
 
84
- // npmStyles.js
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: "x1wdx05y",
88
- height: "x1je5kxa",
89
- width: "x1u78jha",
115
+ display: "xt0psk2",
116
+ height: "x1egiwwb",
117
+ width: "x3hqpx7",
90
118
  $$css: true
91
119
  }
92
120
  };
93
121
 
94
- // index.js
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: "x1nrqb13",
98
- display: "x1c4r43l",
99
- marginInlineStart: "xo3gju4",
133
+ animationName: "xeuoslp",
134
+ display: "x78zum5",
135
+ marginInlineStart: "x1hm9lzh",
100
136
  marginLeft: null,
101
137
  marginRight: null,
102
- marginTop: "x1h9ru99",
103
- height: "x1je5kxa",
104
- ":hover_background": "x1kflwvg",
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
- // otherStyles.js
138
- stylex.inject(".xntgbld{display:block}", 4);
139
- stylex.inject(".x6mlivy{width:100%}", 4);
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: "xntgbld",
144
- width: "x6mlivy",
188
+ display: "x1lliihq",
189
+ width: "xh8yej3",
145
190
  $$css: true
146
191
  }
147
192
  };
148
193
 
149
- // npmStyles.js
150
- stylex.inject(".x1wdx05y{display:inline}", 4);
151
- stylex.inject(".x1je5kxa{height:500px}", 4);
152
- stylex.inject(".x1u78jha{width:50%}", 4);
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: "x1wdx05y",
157
- height: "x1je5kxa",
158
- width: "x1u78jha",
209
+ display: "xt0psk2",
210
+ height: "x1egiwwb",
211
+ width: "x3hqpx7",
159
212
  $$css: true
160
213
  }
161
214
  };
162
215
 
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);
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: "x1nrqb13",
175
- display: "x1c4r43l",
176
- marginInlineStart: "xo3gju4",
235
+ animationName: "xeuoslp",
236
+ display: "x78zum5",
237
+ marginInlineStart: "x1hm9lzh",
177
238
  marginLeft: null,
178
239
  marginRight: null,
179
- marginTop: "x1h9ru99",
180
- height: "x1je5kxa",
181
- ":hover_background": "x1kflwvg",
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.2.0-beta.9",
4
- "description": "Rollup plugin for stylex",
3
+ "version": "0.3.0",
4
+ "description": "Rollup plugin for StyleX",
5
5
  "main": "src/index.js",
6
- "repository": "https://www.github.com/facebookexternal/stylex",
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.2.0-beta.9"
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": "^23.0.1",
26
+ "@rollup/plugin-commonjs": "^25.0.3",
27
27
  "@rollup/plugin-node-resolve": "^15.0.0",
28
- "rollup": "^3.2.3",
29
- "@stylexjs/stylex": "0.2.0-beta.9"
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
- babelConig: { plugins = [], presets = [] } = {},
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, stylexSheetName: fileName }],
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
  };