unplugin-stylex 0.5.3 → 0.5.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-stylex",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Unplugin for stylex",
5
5
  "repository": "https://github.com/eryue0220/unplugin-stylex",
6
6
  "keywords": [
@@ -76,26 +76,26 @@
76
76
  "@stylexjs/stylex": "0.x"
77
77
  },
78
78
  "dependencies": {
79
- "@babel/core": "^7.26.0",
80
- "@babel/plugin-syntax-flow": "^7.26.0",
81
- "@babel/plugin-syntax-jsx": "^7.25.9",
82
- "@babel/plugin-syntax-typescript": "^7.25.9",
83
- "@rollup/pluginutils": "^5.1.3",
79
+ "@babel/core": "^7.27.1",
80
+ "@babel/plugin-syntax-flow": "^7.27.1",
81
+ "@babel/plugin-syntax-jsx": "^7.27.1",
82
+ "@babel/plugin-syntax-typescript": "^7.27.1",
83
+ "@rollup/pluginutils": "^5.1.4",
84
84
  "@stylexjs/babel-plugin": "^0.12.0",
85
- "unplugin": "^1.15.0"
85
+ "@types/node": "^24.0.15",
86
+ "@vitest/coverage-v8": "^3.2.4",
87
+ "unplugin": "^1.16.1"
86
88
  },
87
89
  "devDependencies": {
88
90
  "@biomejs/biome": "1.9.4",
89
- "@changesets/changelog-github": "^0.5.0",
90
- "@changesets/cli": "^2.27.10",
91
- "@types/node": "^20.17.2",
92
- "@vitest/coverage-v8": "^3.0.9",
91
+ "@changesets/changelog-github": "^0.5.1",
92
+ "@changesets/cli": "^2.29.2",
93
93
  "babel-plugin-syntax-hermes-parser": "^0.19.2",
94
- "jsr": "^0.13.2",
95
- "tsup": "^8.3.5",
96
- "typescript": "^5.6.3",
97
- "vite": "^5.4.14",
98
- "vitest": "^3.0.9"
94
+ "jsr": "^0.13.4",
95
+ "tsup": "^8.4.0",
96
+ "typescript": "^5.8.3",
97
+ "vite": "^7.0.5",
98
+ "vitest": "^3.2.4"
99
99
  },
100
100
  "scripts": {
101
101
  "dev": "tsup src/*ts --watch src",
@@ -1,196 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/index.ts
2
- var _path = require('path'); var path = _interopRequireWildcard(_path);
3
- var _unplugin = require('unplugin');
4
-
5
- // src/core/build.ts
6
- var _babelplugin = require('@stylexjs/babel-plugin'); var _babelplugin2 = _interopRequireDefault(_babelplugin);
7
- function buildStylexRules(stylexRules, useCSSLayers) {
8
- const rules = Object.values(stylexRules).flat();
9
- if (rules.length === 0) return "";
10
- return _babelplugin2.default.processStylexRules(rules, useCSSLayers);
11
- }
12
-
13
- // src/core/constants.ts
14
- var PLUGIN_NAME = "unplugin-stylex";
15
- var isDevelopment = process.env.NODE_ENV !== "production" || process.env.BABEL_ENV !== "production";
16
-
17
- // src/core/options.ts
18
- function getOptions(options) {
19
- var _a, _b, _c;
20
- const stylex2 = options.stylex || {};
21
- const isDev = options.dev || isDevelopment;
22
- return {
23
- ...options,
24
- dev: isDev,
25
- // .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts
26
- validExts: _nullishCoalesce(options.validExts, () => ( /\.[mc]?[jt]sx?$/)),
27
- stylex: {
28
- filename: stylex2.filename || "stylex.css",
29
- stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
30
- runtimeInjection: _nullishCoalesce(stylex2.runtimeInjection, () => ( isDev)),
31
- aliases: stylex2.aliases,
32
- useCSSLayers: stylex2.useCSSLayers || false,
33
- unstable_moduleResolution: stylex2.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
34
- babelConfig: {
35
- babelrc: _nullishCoalesce(((_a = stylex2.babelConfig) == null ? void 0 : _a.babelrc), () => ( false)),
36
- plugins: _nullishCoalesce(((_b = stylex2.babelConfig) == null ? void 0 : _b.plugins), () => ( [])),
37
- presets: _nullishCoalesce(((_c = stylex2.babelConfig) == null ? void 0 : _c.presets), () => ( []))
38
- },
39
- ...stylex2
40
- }
41
- };
42
- }
43
-
44
- // src/core/transformer.ts
45
-
46
- var _core = require('@babel/core');
47
- var _pluginsyntaxjsx = require('@babel/plugin-syntax-jsx'); var _pluginsyntaxjsx2 = _interopRequireDefault(_pluginsyntaxjsx);
48
-
49
-
50
- // src/core/plugins.ts
51
- var _pluginsyntaxflow = require('@babel/plugin-syntax-flow'); var _pluginsyntaxflow2 = _interopRequireDefault(_pluginsyntaxflow);
52
- var _pluginsyntaxtypescript = require('@babel/plugin-syntax-typescript'); var _pluginsyntaxtypescript2 = _interopRequireDefault(_pluginsyntaxtypescript);
53
- function getSyntaxPlugins(extname2) {
54
- const TSPlugin = extname2 === ".tsx" ? [[_pluginsyntaxtypescript2.default, { isTSX: true }]] : [_pluginsyntaxtypescript2.default];
55
- return [".js", ".jsx"].includes(extname2) ? [_pluginsyntaxflow2.default] : TSPlugin;
56
- }
57
-
58
- // src/core/transformer.ts
59
- async function transformer(context) {
60
- var _a, _b, _c, _d;
61
- const { id, inputCode, options } = context;
62
- const stylex2 = options.stylex;
63
- const extname2 = _path.extname.call(void 0, id);
64
- const stylexRules = {};
65
- const stylexBabelPluginOptions = {
66
- dev: options.dev,
67
- importSources: stylex2.stylexImports,
68
- ...stylex2
69
- };
70
- const plugins = [
71
- ...((_a = stylex2.babelConfig) == null ? void 0 : _a.plugins) || [],
72
- ...getSyntaxPlugins(extname2),
73
- _pluginsyntaxjsx2.default,
74
- _babelplugin2.default.withOptions(stylexBabelPluginOptions)
75
- ];
76
- const { code, map, metadata } = await _core.transformAsync.call(void 0, inputCode, {
77
- babelrc: (_b = stylex2.babelConfig) == null ? void 0 : _b.babelrc,
78
- filename: id,
79
- presets: (_c = stylex2.babelConfig) == null ? void 0 : _c.presets,
80
- plugins
81
- });
82
- if (metadata.stylex && metadata.stylex.length > 0) {
83
- stylexRules[id] = metadata.stylex;
84
- }
85
- if (!((_d = stylex2.babelConfig) == null ? void 0 : _d.babelrc)) {
86
- return {
87
- code,
88
- // compatible for farm, null will occur an error
89
- map: map || void 0,
90
- stylexRules
91
- };
92
- }
93
- return { code, stylexRules };
94
- }
95
-
96
- // src/index.ts
97
- var unpluginFactory = (rawOptions = {}) => {
98
- const options = getOptions(rawOptions);
99
- const stylexRules = {};
100
- let viteConfig = null;
101
- return {
102
- name: PLUGIN_NAME,
103
- transformInclude(id) {
104
- const validExts = options.validExts;
105
- const extname2 = path.extname(id);
106
- const questionMarkIndex = extname2.indexOf("?");
107
- const validExtName = questionMarkIndex > -1 ? extname2.slice(0, questionMarkIndex) : extname2;
108
- return validExts instanceof RegExp ? validExts.test(validExtName) : validExts.includes(validExtName);
109
- },
110
- async transform(code, id) {
111
- var _a;
112
- const dir = path.dirname(id);
113
- const basename2 = path.basename(id);
114
- const file = path.join(dir, basename2.includes("?") ? basename2.split("?")[0] : basename2);
115
- if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
116
- return;
117
- }
118
- const context = {
119
- id: file,
120
- inputCode: code,
121
- pluginContext: this,
122
- options
123
- };
124
- try {
125
- const result = await transformer(context);
126
- if ((_a = result.stylexRules) == null ? void 0 : _a[id]) {
127
- stylexRules[id] = result.stylexRules[id];
128
- }
129
- return result;
130
- } catch (error) {
131
- console.error("transform::error::", error);
132
- this.error(error);
133
- }
134
- },
135
- buildEnd() {
136
- const fileName = options.stylex.filename;
137
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
138
- if (!collectedCSS) return;
139
- this.emitFile({
140
- fileName,
141
- source: collectedCSS,
142
- type: "asset"
143
- });
144
- },
145
- vite: {
146
- config(config) {
147
- viteConfig = {
148
- build: config.build,
149
- base: config.base
150
- };
151
- },
152
- configResolved(config) {
153
- config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
154
- config.optimizeDeps.exclude.push("@stylexjs/open-props");
155
- },
156
- buildEnd() {
157
- var _a;
158
- const fileName = `${_nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
159
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
160
- if (!collectedCSS) return;
161
- this.emitFile({
162
- fileName,
163
- source: collectedCSS,
164
- type: "asset"
165
- });
166
- },
167
- transformIndexHtml(html, ctx) {
168
- var _a, _b;
169
- const fileName = `${_nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
170
- const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
171
- if (!css) {
172
- return html;
173
- }
174
- const publicPath = path.posix.join(_nullishCoalesce((viteConfig == null ? void 0 : viteConfig.base), () => ( "/")), fileName.replace(/\\/g, "/"));
175
- return [
176
- {
177
- tag: "link",
178
- attrs: {
179
- rel: "stylesheet",
180
- href: publicPath
181
- },
182
- injectTo: "head"
183
- }
184
- ];
185
- }
186
- }
187
- };
188
- };
189
- var unplugin = _unplugin.createUnplugin.call(void 0, unpluginFactory);
190
- var index_default = unplugin;
191
-
192
-
193
-
194
-
195
-
196
- exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin; exports.index_default = index_default;
@@ -1,196 +0,0 @@
1
- // src/index.ts
2
- import * as path from "node:path";
3
- import { createUnplugin } from "unplugin";
4
-
5
- // src/core/build.ts
6
- import stylex from "@stylexjs/babel-plugin";
7
- function buildStylexRules(stylexRules, useCSSLayers) {
8
- const rules = Object.values(stylexRules).flat();
9
- if (rules.length === 0) return "";
10
- return stylex.processStylexRules(rules, useCSSLayers);
11
- }
12
-
13
- // src/core/constants.ts
14
- var PLUGIN_NAME = "unplugin-stylex";
15
- var isDevelopment = process.env.NODE_ENV !== "production" || process.env.BABEL_ENV !== "production";
16
-
17
- // src/core/options.ts
18
- function getOptions(options) {
19
- var _a, _b, _c;
20
- const stylex2 = options.stylex || {};
21
- const isDev = options.dev || isDevelopment;
22
- return {
23
- ...options,
24
- dev: isDev,
25
- // .js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .cts
26
- validExts: options.validExts ?? /\.[mc]?[jt]sx?$/,
27
- stylex: {
28
- filename: stylex2.filename || "stylex.css",
29
- stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
30
- runtimeInjection: stylex2.runtimeInjection ?? isDev,
31
- aliases: stylex2.aliases,
32
- useCSSLayers: stylex2.useCSSLayers || false,
33
- unstable_moduleResolution: stylex2.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
34
- babelConfig: {
35
- babelrc: ((_a = stylex2.babelConfig) == null ? void 0 : _a.babelrc) ?? false,
36
- plugins: ((_b = stylex2.babelConfig) == null ? void 0 : _b.plugins) ?? [],
37
- presets: ((_c = stylex2.babelConfig) == null ? void 0 : _c.presets) ?? []
38
- },
39
- ...stylex2
40
- }
41
- };
42
- }
43
-
44
- // src/core/transformer.ts
45
- import { extname as pathExtname } from "node:path";
46
- import { transformAsync } from "@babel/core";
47
- import jsxSyntaxPlugin from "@babel/plugin-syntax-jsx";
48
- import stylexBabelPlugin from "@stylexjs/babel-plugin";
49
-
50
- // src/core/plugins.ts
51
- import flowSyntaxPlugin from "@babel/plugin-syntax-flow";
52
- import typescriptSyntaxPlugin from "@babel/plugin-syntax-typescript";
53
- function getSyntaxPlugins(extname2) {
54
- const TSPlugin = extname2 === ".tsx" ? [[typescriptSyntaxPlugin, { isTSX: true }]] : [typescriptSyntaxPlugin];
55
- return [".js", ".jsx"].includes(extname2) ? [flowSyntaxPlugin] : TSPlugin;
56
- }
57
-
58
- // src/core/transformer.ts
59
- async function transformer(context) {
60
- var _a, _b, _c, _d;
61
- const { id, inputCode, options } = context;
62
- const stylex2 = options.stylex;
63
- const extname2 = pathExtname(id);
64
- const stylexRules = {};
65
- const stylexBabelPluginOptions = {
66
- dev: options.dev,
67
- importSources: stylex2.stylexImports,
68
- ...stylex2
69
- };
70
- const plugins = [
71
- ...((_a = stylex2.babelConfig) == null ? void 0 : _a.plugins) || [],
72
- ...getSyntaxPlugins(extname2),
73
- jsxSyntaxPlugin,
74
- stylexBabelPlugin.withOptions(stylexBabelPluginOptions)
75
- ];
76
- const { code, map, metadata } = await transformAsync(inputCode, {
77
- babelrc: (_b = stylex2.babelConfig) == null ? void 0 : _b.babelrc,
78
- filename: id,
79
- presets: (_c = stylex2.babelConfig) == null ? void 0 : _c.presets,
80
- plugins
81
- });
82
- if (metadata.stylex && metadata.stylex.length > 0) {
83
- stylexRules[id] = metadata.stylex;
84
- }
85
- if (!((_d = stylex2.babelConfig) == null ? void 0 : _d.babelrc)) {
86
- return {
87
- code,
88
- // compatible for farm, null will occur an error
89
- map: map || void 0,
90
- stylexRules
91
- };
92
- }
93
- return { code, stylexRules };
94
- }
95
-
96
- // src/index.ts
97
- var unpluginFactory = (rawOptions = {}) => {
98
- const options = getOptions(rawOptions);
99
- const stylexRules = {};
100
- let viteConfig = null;
101
- return {
102
- name: PLUGIN_NAME,
103
- transformInclude(id) {
104
- const validExts = options.validExts;
105
- const extname2 = path.extname(id);
106
- const questionMarkIndex = extname2.indexOf("?");
107
- const validExtName = questionMarkIndex > -1 ? extname2.slice(0, questionMarkIndex) : extname2;
108
- return validExts instanceof RegExp ? validExts.test(validExtName) : validExts.includes(validExtName);
109
- },
110
- async transform(code, id) {
111
- var _a;
112
- const dir = path.dirname(id);
113
- const basename2 = path.basename(id);
114
- const file = path.join(dir, basename2.includes("?") ? basename2.split("?")[0] : basename2);
115
- if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
116
- return;
117
- }
118
- const context = {
119
- id: file,
120
- inputCode: code,
121
- pluginContext: this,
122
- options
123
- };
124
- try {
125
- const result = await transformer(context);
126
- if ((_a = result.stylexRules) == null ? void 0 : _a[id]) {
127
- stylexRules[id] = result.stylexRules[id];
128
- }
129
- return result;
130
- } catch (error) {
131
- console.error("transform::error::", error);
132
- this.error(error);
133
- }
134
- },
135
- buildEnd() {
136
- const fileName = options.stylex.filename;
137
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
138
- if (!collectedCSS) return;
139
- this.emitFile({
140
- fileName,
141
- source: collectedCSS,
142
- type: "asset"
143
- });
144
- },
145
- vite: {
146
- config(config) {
147
- viteConfig = {
148
- build: config.build,
149
- base: config.base
150
- };
151
- },
152
- configResolved(config) {
153
- config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
154
- config.optimizeDeps.exclude.push("@stylexjs/open-props");
155
- },
156
- buildEnd() {
157
- var _a;
158
- const fileName = `${((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
159
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
160
- if (!collectedCSS) return;
161
- this.emitFile({
162
- fileName,
163
- source: collectedCSS,
164
- type: "asset"
165
- });
166
- },
167
- transformIndexHtml(html, ctx) {
168
- var _a, _b;
169
- const fileName = `${((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
170
- const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
171
- if (!css) {
172
- return html;
173
- }
174
- const publicPath = path.posix.join((viteConfig == null ? void 0 : viteConfig.base) ?? "/", fileName.replace(/\\/g, "/"));
175
- return [
176
- {
177
- tag: "link",
178
- attrs: {
179
- rel: "stylesheet",
180
- href: publicPath
181
- },
182
- injectTo: "head"
183
- }
184
- ];
185
- }
186
- }
187
- };
188
- };
189
- var unplugin = createUnplugin(unpluginFactory);
190
- var index_default = unplugin;
191
-
192
- export {
193
- unpluginFactory,
194
- unplugin,
195
- index_default
196
- };