@stylexjs/rollup-plugin 0.1.0-beta.6 → 0.1.0-beta.7

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.
@@ -77,7 +77,8 @@ describe('rollup-plugin-stylex', () => {
77
77
  var styles$2 = {
78
78
  bar: {
79
79
  display: "xntgbld",
80
- width: "x6mlivy"
80
+ width: "x6mlivy",
81
+ $$css: true
81
82
  }
82
83
  };
83
84
 
@@ -86,7 +87,8 @@ describe('rollup-plugin-stylex', () => {
86
87
  baz: {
87
88
  display: "x1wdx05y",
88
89
  height: "x1je5kxa",
89
- width: "x1u78jha"
90
+ width: "x1u78jha",
91
+ $$css: true
90
92
  }
91
93
  };
92
94
 
@@ -98,7 +100,8 @@ describe('rollup-plugin-stylex', () => {
98
100
  marginStart: "x1n8p6zw",
99
101
  marginBlockStart: "x188knyk",
100
102
  height: "x1je5kxa",
101
- ":hover_background": "x1kflwvg"
103
+ ":hover_background": "x1kflwvg",
104
+ $$css: true
102
105
  }
103
106
  };
104
107
  function App() {
@@ -129,7 +132,8 @@ describe('rollup-plugin-stylex', () => {
129
132
  bar: {
130
133
  "otherStyles__styles.bar": "otherStyles__styles.bar",
131
134
  display: "xntgbld",
132
- width: "x6mlivy"
135
+ width: "x6mlivy",
136
+ $$css: true
133
137
  }
134
138
  };
135
139
 
@@ -142,7 +146,8 @@ describe('rollup-plugin-stylex', () => {
142
146
  "npmStyles__styles.baz": "npmStyles__styles.baz",
143
147
  display: "x1wdx05y",
144
148
  height: "x1je5kxa",
145
- width: "x1u78jha"
149
+ width: "x1u78jha",
150
+ $$css: true
146
151
  }
147
152
  };
148
153
 
@@ -162,7 +167,8 @@ describe('rollup-plugin-stylex', () => {
162
167
  marginStart: "x1n8p6zw",
163
168
  marginBlockStart: "x188knyk",
164
169
  height: "x1je5kxa",
165
- ":hover_background": "x1kflwvg"
170
+ ":hover_background": "x1kflwvg",
171
+ $$css: true
166
172
  }
167
173
  };
168
174
  function App() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stylexjs/rollup-plugin",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0-beta.7",
4
4
  "description": "Rollup plugin for stylex",
5
5
  "main": "src/index.js",
6
6
  "repository": "https://www.github.com/facebookexternal/stylex",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/core": "^7.16.0",
21
- "@stylexjs/babel-plugin": "0.1.0-beta.6"
21
+ "@stylexjs/babel-plugin": "0.1.0-beta.7"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@babel/preset-env": "^7.16.8",
@@ -26,6 +26,6 @@
26
26
  "@rollup/plugin-commonjs": "^23.0.1",
27
27
  "@rollup/plugin-node-resolve": "^15.0.0",
28
28
  "rollup": "^3.2.3",
29
- "@stylexjs/stylex": "0.1.0-beta.6"
29
+ "@stylexjs/stylex": "0.1.0-beta.7"
30
30
  }
31
31
  }
package/src/index.js CHANGED
@@ -15,17 +15,19 @@ const IS_DEV_ENV =
15
15
  module.exports = function stylexPlugin({
16
16
  dev = IS_DEV_ENV,
17
17
  fileName = 'stylex.css',
18
+ babelConig: { plugins = [], presets = [] } = {},
18
19
  } = {}) {
19
- let stylexRules = [];
20
+ let stylexRules = {};
20
21
 
21
22
  return {
22
23
  name: 'rollup-plugin-stylex',
23
24
  buildStart() {
24
- stylexRules = [];
25
+ stylexRules = {};
25
26
  },
26
27
  generateBundle() {
27
- if (stylexRules.length > 0) {
28
- const collectedCSS = stylexBabelPlugin.processStylexRules(stylexRules);
28
+ const rules = Object.values(stylexRules).flat();
29
+ if (rules.length > 0) {
30
+ const collectedCSS = stylexBabelPlugin.processStylexRules(rules);
29
31
 
30
32
  this.emitFile({
31
33
  fileName,
@@ -34,18 +36,26 @@ module.exports = function stylexPlugin({
34
36
  });
35
37
  }
36
38
  },
39
+ shouldTransformCachedModule({ code, id, cache, meta }) {
40
+ stylexRules[id] = meta.stylex;
41
+ return false;
42
+ },
37
43
  async transform(inputCode, id) {
38
44
  const { code, map, metadata } = await babel.transformAsync(inputCode, {
39
45
  babelrc: false,
40
46
  filename: id,
41
- plugins: [[stylexBabelPlugin, { dev, stylexSheetName: fileName }]],
47
+ presets,
48
+ plugins: [
49
+ ...plugins,
50
+ [stylexBabelPlugin, { dev, stylexSheetName: fileName }],
51
+ ],
42
52
  });
43
53
 
44
54
  if (!dev && metadata.stylex != null && metadata.stylex.length > 0) {
45
- stylexRules = stylexRules.concat(metadata.stylex);
55
+ stylexRules[id] = metadata.stylex;
46
56
  }
47
57
 
48
- return { code, map };
58
+ return { code, map, meta: metadata };
49
59
  },
50
60
  };
51
61
  };