unplugin-stylex 0.0.2 → 0.1.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/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7MXMBS5H.js +190 -0
- package/dist/chunk-NVMQARFA.cjs +190 -0
- package/dist/chunk-ZBPRDZS4.cjs +1 -0
- package/dist/esbuild.cjs +3 -2
- package/dist/esbuild.d.cts +0 -1
- package/dist/esbuild.d.ts +0 -1
- package/dist/esbuild.js +2 -1
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/rspack.cjs +3 -2
- package/dist/rspack.d.cts +0 -1
- package/dist/rspack.d.ts +0 -1
- package/dist/rspack.js +2 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +4 -5
- package/dist/types.d.ts +4 -5
- package/dist/types.js +1 -0
- package/dist/vite.cjs +3 -2
- package/dist/vite.d.cts +0 -1
- package/dist/vite.d.ts +0 -1
- package/dist/vite.js +2 -1
- package/package.json +15 -14
- package/src/core/build.ts +9 -0
- package/src/core/{utils.ts → options.ts} +9 -9
- package/src/core/plugins.ts +12 -0
- package/src/core/transformer.ts +31 -48
- package/src/index.ts +61 -22
- package/src/types.ts +4 -5
- package/dist/chunk-D3OQCQYP.cjs +0 -152
- package/dist/chunk-XQ5JPTTJ.js +0 -152
|
File without changes
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PLUGIN_NAME,
|
|
3
|
+
isDevelopment
|
|
4
|
+
} from "./chunk-36ARBXVP.js";
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import { createUnplugin } from "unplugin";
|
|
9
|
+
|
|
10
|
+
// src/core/build.ts
|
|
11
|
+
import stylex from "@stylexjs/babel-plugin";
|
|
12
|
+
function buildStylexRules(stylexRules, useCSSLayers) {
|
|
13
|
+
const rules = Object.values(stylexRules).flat();
|
|
14
|
+
if (rules.length === 0)
|
|
15
|
+
return "";
|
|
16
|
+
return stylex.processStylexRules(rules, useCSSLayers);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/core/options.ts
|
|
20
|
+
function getOptions(options) {
|
|
21
|
+
const stylex2 = options.stylex || {};
|
|
22
|
+
const isDev = options.dev || isDevelopment;
|
|
23
|
+
return {
|
|
24
|
+
...options,
|
|
25
|
+
dev: options.dev || isDev,
|
|
26
|
+
stylex: {
|
|
27
|
+
filename: stylex2.filename || "stylex.css",
|
|
28
|
+
stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
|
|
29
|
+
runtimeInjection: stylex2.runtimeInjection ?? isDev,
|
|
30
|
+
aliases: stylex2.aliases,
|
|
31
|
+
useCSSLayers: stylex2.useCSSLayers || false,
|
|
32
|
+
unstable_moduleResolution: stylex2.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
33
|
+
babelConfig: {
|
|
34
|
+
babelrc: (stylex2.babelConfig || {}).babelrc || false,
|
|
35
|
+
plugins: (stylex2.babelConfig || {}).plugins || [],
|
|
36
|
+
presets: (stylex2.babelConfig || {}).presets || []
|
|
37
|
+
},
|
|
38
|
+
...stylex2
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/core/transformer.ts
|
|
44
|
+
import { extname as pathExtname } from "node:path";
|
|
45
|
+
import { transformAsync } from "@babel/core";
|
|
46
|
+
import jsxSyntaxPlugin from "@babel/plugin-syntax-jsx";
|
|
47
|
+
import stylexBabelPlugin from "@stylexjs/babel-plugin";
|
|
48
|
+
|
|
49
|
+
// src/core/plugins.ts
|
|
50
|
+
import typescriptSyntaxPlugin from "@babel/plugin-syntax-typescript";
|
|
51
|
+
import flowSyntaxPlugin from "@babel/plugin-syntax-flow";
|
|
52
|
+
function getSyntaxPlugins(extname) {
|
|
53
|
+
const TSPlugin = extname === ".tsx" ? [[typescriptSyntaxPlugin, { isTSX: true }]] : [typescriptSyntaxPlugin];
|
|
54
|
+
return [".js", ".jsx"].includes(extname) ? [flowSyntaxPlugin] : TSPlugin;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/core/transformer.ts
|
|
58
|
+
async function transformer(context) {
|
|
59
|
+
var _a, _b, _c, _d;
|
|
60
|
+
const { id, inputCode, options } = context;
|
|
61
|
+
const stylex2 = options.stylex;
|
|
62
|
+
const extname = pathExtname(id);
|
|
63
|
+
const stylexRules = {};
|
|
64
|
+
const stylexBabelPluginOptions = {
|
|
65
|
+
dev: options.dev,
|
|
66
|
+
importSources: stylex2.stylexImports,
|
|
67
|
+
...stylex2
|
|
68
|
+
};
|
|
69
|
+
const plugins = [
|
|
70
|
+
...((_a = stylex2.babelConfig) == null ? void 0 : _a.plugins) || [],
|
|
71
|
+
...getSyntaxPlugins(extname),
|
|
72
|
+
jsxSyntaxPlugin,
|
|
73
|
+
stylexBabelPlugin.withOptions(stylexBabelPluginOptions)
|
|
74
|
+
];
|
|
75
|
+
const { code, map, metadata } = await transformAsync(
|
|
76
|
+
inputCode,
|
|
77
|
+
{
|
|
78
|
+
babelrc: (_b = stylex2.babelConfig) == null ? void 0 : _b.babelrc,
|
|
79
|
+
filename: id,
|
|
80
|
+
presets: (_c = stylex2.babelConfig) == null ? void 0 : _c.presets,
|
|
81
|
+
plugins
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
85
|
+
stylexRules[id] = metadata.stylex;
|
|
86
|
+
}
|
|
87
|
+
if (!((_d = stylex2.babelConfig) == null ? void 0 : _d.babelrc)) {
|
|
88
|
+
return { code, map, stylexRules };
|
|
89
|
+
}
|
|
90
|
+
return { code, stylexRules };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/index.ts
|
|
94
|
+
var unpluginFactory = (rawOptions = {}) => {
|
|
95
|
+
const options = getOptions(rawOptions);
|
|
96
|
+
const stylexRules = {};
|
|
97
|
+
let viteConfig = null;
|
|
98
|
+
return {
|
|
99
|
+
name: PLUGIN_NAME,
|
|
100
|
+
async transform(code, id) {
|
|
101
|
+
const dir = path.dirname(id);
|
|
102
|
+
const basename2 = path.basename(id);
|
|
103
|
+
const file = path.join(dir, basename2.includes("?") ? basename2.split("?")[0] : basename2);
|
|
104
|
+
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const context = {
|
|
108
|
+
id: file,
|
|
109
|
+
inputCode: code,
|
|
110
|
+
pluginContext: this,
|
|
111
|
+
options
|
|
112
|
+
};
|
|
113
|
+
try {
|
|
114
|
+
const result = await transformer(context);
|
|
115
|
+
if (result.stylexRules && result.stylexRules[id]) {
|
|
116
|
+
stylexRules[id] = result.stylexRules[id];
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("transform::error::", error);
|
|
121
|
+
this.error(error);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
buildEnd() {
|
|
125
|
+
const fileName = options.stylex.filename;
|
|
126
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
|
|
127
|
+
if (!collectedCSS)
|
|
128
|
+
return;
|
|
129
|
+
this.emitFile({
|
|
130
|
+
fileName,
|
|
131
|
+
source: collectedCSS,
|
|
132
|
+
type: "asset"
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
vite: {
|
|
136
|
+
config(config) {
|
|
137
|
+
viteConfig = {
|
|
138
|
+
build: config.build,
|
|
139
|
+
base: config.base
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
configResolved(config) {
|
|
143
|
+
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
144
|
+
config.optimizeDeps.exclude.push("@stylexjs/open-props");
|
|
145
|
+
},
|
|
146
|
+
buildEnd() {
|
|
147
|
+
var _a;
|
|
148
|
+
const fileName = `${((_a = viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
|
|
149
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
|
|
150
|
+
if (!collectedCSS)
|
|
151
|
+
return;
|
|
152
|
+
this.emitFile({
|
|
153
|
+
fileName,
|
|
154
|
+
source: collectedCSS,
|
|
155
|
+
type: "asset"
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
transformIndexHtml(html, ctx) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
const fileName = `${((_a = viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
|
|
161
|
+
const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
|
|
162
|
+
if (!css) {
|
|
163
|
+
return html;
|
|
164
|
+
}
|
|
165
|
+
const publicPath = path.posix.join(
|
|
166
|
+
viteConfig.base ?? "/",
|
|
167
|
+
fileName.replace(/\\/g, "/")
|
|
168
|
+
);
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
tag: "link",
|
|
172
|
+
attrs: {
|
|
173
|
+
rel: "stylesheet",
|
|
174
|
+
href: publicPath
|
|
175
|
+
},
|
|
176
|
+
injectTo: "head"
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
var unplugin = createUnplugin(unpluginFactory);
|
|
184
|
+
var src_default = unplugin;
|
|
185
|
+
|
|
186
|
+
export {
|
|
187
|
+
unpluginFactory,
|
|
188
|
+
unplugin,
|
|
189
|
+
src_default
|
|
190
|
+
};
|
|
@@ -0,0 +1,190 @@
|
|
|
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(); } }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkN4Z3Z2PUcjs = require('./chunk-N4Z3Z2PU.cjs');
|
|
5
|
+
|
|
6
|
+
// src/index.ts
|
|
7
|
+
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
8
|
+
var _unplugin = require('unplugin');
|
|
9
|
+
|
|
10
|
+
// src/core/build.ts
|
|
11
|
+
var _babelplugin = require('@stylexjs/babel-plugin'); var _babelplugin2 = _interopRequireDefault(_babelplugin);
|
|
12
|
+
function buildStylexRules(stylexRules, useCSSLayers) {
|
|
13
|
+
const rules = Object.values(stylexRules).flat();
|
|
14
|
+
if (rules.length === 0)
|
|
15
|
+
return "";
|
|
16
|
+
return _babelplugin2.default.processStylexRules(rules, useCSSLayers);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/core/options.ts
|
|
20
|
+
function getOptions(options) {
|
|
21
|
+
const stylex2 = options.stylex || {};
|
|
22
|
+
const isDev = options.dev || _chunkN4Z3Z2PUcjs.isDevelopment;
|
|
23
|
+
return {
|
|
24
|
+
...options,
|
|
25
|
+
dev: options.dev || isDev,
|
|
26
|
+
stylex: {
|
|
27
|
+
filename: stylex2.filename || "stylex.css",
|
|
28
|
+
stylexImports: stylex2.stylexImports || ["@stylexjs/stylex"],
|
|
29
|
+
runtimeInjection: _nullishCoalesce(stylex2.runtimeInjection, () => ( isDev)),
|
|
30
|
+
aliases: stylex2.aliases,
|
|
31
|
+
useCSSLayers: stylex2.useCSSLayers || false,
|
|
32
|
+
unstable_moduleResolution: stylex2.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
33
|
+
babelConfig: {
|
|
34
|
+
babelrc: (stylex2.babelConfig || {}).babelrc || false,
|
|
35
|
+
plugins: (stylex2.babelConfig || {}).plugins || [],
|
|
36
|
+
presets: (stylex2.babelConfig || {}).presets || []
|
|
37
|
+
},
|
|
38
|
+
...stylex2
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/core/transformer.ts
|
|
44
|
+
|
|
45
|
+
var _core = require('@babel/core');
|
|
46
|
+
var _pluginsyntaxjsx = require('@babel/plugin-syntax-jsx'); var _pluginsyntaxjsx2 = _interopRequireDefault(_pluginsyntaxjsx);
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// src/core/plugins.ts
|
|
50
|
+
var _pluginsyntaxtypescript = require('@babel/plugin-syntax-typescript'); var _pluginsyntaxtypescript2 = _interopRequireDefault(_pluginsyntaxtypescript);
|
|
51
|
+
var _pluginsyntaxflow = require('@babel/plugin-syntax-flow'); var _pluginsyntaxflow2 = _interopRequireDefault(_pluginsyntaxflow);
|
|
52
|
+
function getSyntaxPlugins(extname) {
|
|
53
|
+
const TSPlugin = extname === ".tsx" ? [[_pluginsyntaxtypescript2.default, { isTSX: true }]] : [_pluginsyntaxtypescript2.default];
|
|
54
|
+
return [".js", ".jsx"].includes(extname) ? [_pluginsyntaxflow2.default] : TSPlugin;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/core/transformer.ts
|
|
58
|
+
async function transformer(context) {
|
|
59
|
+
var _a, _b, _c, _d;
|
|
60
|
+
const { id, inputCode, options } = context;
|
|
61
|
+
const stylex2 = options.stylex;
|
|
62
|
+
const extname = _path.extname.call(void 0, id);
|
|
63
|
+
const stylexRules = {};
|
|
64
|
+
const stylexBabelPluginOptions = {
|
|
65
|
+
dev: options.dev,
|
|
66
|
+
importSources: stylex2.stylexImports,
|
|
67
|
+
...stylex2
|
|
68
|
+
};
|
|
69
|
+
const plugins = [
|
|
70
|
+
...((_a = stylex2.babelConfig) == null ? void 0 : _a.plugins) || [],
|
|
71
|
+
...getSyntaxPlugins(extname),
|
|
72
|
+
_pluginsyntaxjsx2.default,
|
|
73
|
+
_babelplugin2.default.withOptions(stylexBabelPluginOptions)
|
|
74
|
+
];
|
|
75
|
+
const { code, map, metadata } = await _core.transformAsync.call(void 0,
|
|
76
|
+
inputCode,
|
|
77
|
+
{
|
|
78
|
+
babelrc: (_b = stylex2.babelConfig) == null ? void 0 : _b.babelrc,
|
|
79
|
+
filename: id,
|
|
80
|
+
presets: (_c = stylex2.babelConfig) == null ? void 0 : _c.presets,
|
|
81
|
+
plugins
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
85
|
+
stylexRules[id] = metadata.stylex;
|
|
86
|
+
}
|
|
87
|
+
if (!((_d = stylex2.babelConfig) == null ? void 0 : _d.babelrc)) {
|
|
88
|
+
return { code, map, stylexRules };
|
|
89
|
+
}
|
|
90
|
+
return { code, stylexRules };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/index.ts
|
|
94
|
+
var unpluginFactory = (rawOptions = {}) => {
|
|
95
|
+
const options = getOptions(rawOptions);
|
|
96
|
+
const stylexRules = {};
|
|
97
|
+
let viteConfig = null;
|
|
98
|
+
return {
|
|
99
|
+
name: _chunkN4Z3Z2PUcjs.PLUGIN_NAME,
|
|
100
|
+
async transform(code, id) {
|
|
101
|
+
const dir = path.dirname(id);
|
|
102
|
+
const basename2 = path.basename(id);
|
|
103
|
+
const file = path.join(dir, basename2.includes("?") ? basename2.split("?")[0] : basename2);
|
|
104
|
+
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const context = {
|
|
108
|
+
id: file,
|
|
109
|
+
inputCode: code,
|
|
110
|
+
pluginContext: this,
|
|
111
|
+
options
|
|
112
|
+
};
|
|
113
|
+
try {
|
|
114
|
+
const result = await transformer(context);
|
|
115
|
+
if (result.stylexRules && result.stylexRules[id]) {
|
|
116
|
+
stylexRules[id] = result.stylexRules[id];
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("transform::error::", error);
|
|
121
|
+
this.error(error);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
buildEnd() {
|
|
125
|
+
const fileName = options.stylex.filename;
|
|
126
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
|
|
127
|
+
if (!collectedCSS)
|
|
128
|
+
return;
|
|
129
|
+
this.emitFile({
|
|
130
|
+
fileName,
|
|
131
|
+
source: collectedCSS,
|
|
132
|
+
type: "asset"
|
|
133
|
+
});
|
|
134
|
+
},
|
|
135
|
+
vite: {
|
|
136
|
+
config(config) {
|
|
137
|
+
viteConfig = {
|
|
138
|
+
build: config.build,
|
|
139
|
+
base: config.base
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
configResolved(config) {
|
|
143
|
+
config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
|
|
144
|
+
config.optimizeDeps.exclude.push("@stylexjs/open-props");
|
|
145
|
+
},
|
|
146
|
+
buildEnd() {
|
|
147
|
+
var _a;
|
|
148
|
+
const fileName = `${_nullishCoalesce(((_a = viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
|
|
149
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
|
|
150
|
+
if (!collectedCSS)
|
|
151
|
+
return;
|
|
152
|
+
this.emitFile({
|
|
153
|
+
fileName,
|
|
154
|
+
source: collectedCSS,
|
|
155
|
+
type: "asset"
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
transformIndexHtml(html, ctx) {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
const fileName = `${_nullishCoalesce(((_a = viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
|
|
161
|
+
const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
|
|
162
|
+
if (!css) {
|
|
163
|
+
return html;
|
|
164
|
+
}
|
|
165
|
+
const publicPath = path.posix.join(
|
|
166
|
+
_nullishCoalesce(viteConfig.base, () => ( "/")),
|
|
167
|
+
fileName.replace(/\\/g, "/")
|
|
168
|
+
);
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
tag: "link",
|
|
172
|
+
attrs: {
|
|
173
|
+
rel: "stylesheet",
|
|
174
|
+
href: publicPath
|
|
175
|
+
},
|
|
176
|
+
injectTo: "head"
|
|
177
|
+
}
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
var unplugin = _unplugin.createUnplugin.call(void 0, unpluginFactory);
|
|
184
|
+
var src_default = unplugin;
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin; exports.src_default = src_default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
4
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
4
5
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
5
6
|
|
|
6
7
|
// src/esbuild.ts
|
|
7
8
|
var _unplugin = require('unplugin');
|
|
8
|
-
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0,
|
|
9
|
+
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
exports.default = esbuild_default;
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
6
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
6
7
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
11
|
-
exports.default =
|
|
12
|
+
exports.default = _chunkNVMQARFAcjs.src_default; exports.unplugin = _chunkNVMQARFAcjs.unplugin; exports.unpluginFactory = _chunkNVMQARFAcjs.unpluginFactory;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as unplugin$1 from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
3
|
import { UnpluginStylexOptions } from './types.cjs';
|
|
4
|
-
|
|
4
|
+
export { BabelConfig, StylexOptions } from './types.cjs';
|
|
5
5
|
|
|
6
6
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>;
|
|
7
7
|
declare const unplugin: unplugin$1.UnpluginInstance<UnpluginStylexOptions, boolean>;
|
|
8
8
|
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
9
|
+
export { UnpluginStylexOptions, unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as unplugin$1 from 'unplugin';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
3
|
import { UnpluginStylexOptions } from './types.js';
|
|
4
|
-
|
|
4
|
+
export { BabelConfig, StylexOptions } from './types.js';
|
|
5
5
|
|
|
6
6
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>;
|
|
7
7
|
declare const unplugin: unplugin$1.UnpluginInstance<UnpluginStylexOptions, boolean>;
|
|
8
8
|
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
9
|
+
export { UnpluginStylexOptions, unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
4
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
4
5
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
5
6
|
|
|
6
7
|
// src/rspack.ts
|
|
7
8
|
var _unplugin = require('unplugin');
|
|
8
|
-
var rspack_default = _unplugin.createRspackPlugin.call(void 0,
|
|
9
|
+
var rspack_default = _unplugin.createRspackPlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
exports.default = rspack_default;
|
package/dist/rspack.d.cts
CHANGED
package/dist/rspack.d.ts
CHANGED
package/dist/rspack.js
CHANGED
package/dist/types.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";require('./chunk-ZBPRDZS4.cjs');
|
package/dist/types.d.cts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
-
|
|
3
1
|
type BabelConfig = {
|
|
4
2
|
plugins: unknown[];
|
|
5
3
|
presets: unknown[];
|
|
@@ -15,13 +13,14 @@ type StylexOptions = {
|
|
|
15
13
|
rootDir: string;
|
|
16
14
|
};
|
|
17
15
|
babelConfig?: BabelConfig;
|
|
16
|
+
runtimeInjection: boolean;
|
|
17
|
+
aliases?: string[];
|
|
18
18
|
};
|
|
19
19
|
type UnpluginStylexOptions = {
|
|
20
|
+
compiler?: string;
|
|
20
21
|
dev?: boolean;
|
|
21
|
-
include?: FilterPattern;
|
|
22
|
-
exclude?: FilterPattern;
|
|
23
22
|
enforce?: "post" | "pre";
|
|
24
23
|
stylex?: StylexOptions;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
export type { BabelConfig, UnpluginStylexOptions };
|
|
26
|
+
export type { BabelConfig, StylexOptions, UnpluginStylexOptions };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
2
|
-
|
|
3
1
|
type BabelConfig = {
|
|
4
2
|
plugins: unknown[];
|
|
5
3
|
presets: unknown[];
|
|
@@ -15,13 +13,14 @@ type StylexOptions = {
|
|
|
15
13
|
rootDir: string;
|
|
16
14
|
};
|
|
17
15
|
babelConfig?: BabelConfig;
|
|
16
|
+
runtimeInjection: boolean;
|
|
17
|
+
aliases?: string[];
|
|
18
18
|
};
|
|
19
19
|
type UnpluginStylexOptions = {
|
|
20
|
+
compiler?: string;
|
|
20
21
|
dev?: boolean;
|
|
21
|
-
include?: FilterPattern;
|
|
22
|
-
exclude?: FilterPattern;
|
|
23
22
|
enforce?: "post" | "pre";
|
|
24
23
|
stylex?: StylexOptions;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
export type { BabelConfig, UnpluginStylexOptions };
|
|
26
|
+
export type { BabelConfig, StylexOptions, UnpluginStylexOptions };
|
package/dist/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./chunk-6F4PWJZI.js";
|
package/dist/vite.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkNVMQARFAcjs = require('./chunk-NVMQARFA.cjs');
|
|
4
|
+
require('./chunk-ZBPRDZS4.cjs');
|
|
4
5
|
require('./chunk-N4Z3Z2PU.cjs');
|
|
5
6
|
|
|
6
7
|
// src/vite.ts
|
|
7
8
|
var _unplugin = require('unplugin');
|
|
8
|
-
var vite_default = _unplugin.createVitePlugin.call(void 0,
|
|
9
|
+
var vite_default = _unplugin.createVitePlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
exports.default = vite_default;
|
package/dist/vite.d.cts
CHANGED
package/dist/vite.d.ts
CHANGED
package/dist/vite.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-stylex",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"packageManager": "pnpm@8.11.0",
|
|
5
5
|
"description": "Unplugin for stylex",
|
|
6
6
|
"repository": "https://github.com/eryue0220/unplugin-stylex",
|
|
@@ -46,16 +46,6 @@
|
|
|
46
46
|
},
|
|
47
47
|
"./*": "./*"
|
|
48
48
|
},
|
|
49
|
-
"scripts": {
|
|
50
|
-
"dev": "tsup src/*ts --watch src",
|
|
51
|
-
"build": "tsup src/*.ts --format cjs,esm --dts --splitting --clean",
|
|
52
|
-
"test": "vitest",
|
|
53
|
-
"test:update": "vitest -u",
|
|
54
|
-
"test:cov": "vitest --coverage",
|
|
55
|
-
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
|
|
56
|
-
"check": "pnpm run lint && pnpm run typecheck",
|
|
57
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
58
|
-
},
|
|
59
49
|
"engines": {
|
|
60
50
|
"node": ">=16.14.0"
|
|
61
51
|
},
|
|
@@ -65,18 +55,29 @@
|
|
|
65
55
|
"@babel/plugin-syntax-jsx": "^7.23.3",
|
|
66
56
|
"@babel/plugin-syntax-typescript": "^7.23.3",
|
|
67
57
|
"@rollup/pluginutils": "^5.1.0",
|
|
68
|
-
"@stylexjs/babel-plugin": "^0.
|
|
69
|
-
"unplugin": "^1.
|
|
58
|
+
"@stylexjs/babel-plugin": "^0.5.1",
|
|
59
|
+
"unplugin": "^1.7.1"
|
|
70
60
|
},
|
|
71
61
|
"devDependencies": {
|
|
72
62
|
"@types/node": "^20.10.5",
|
|
73
63
|
"@typescript-eslint/eslint-plugin": "^6.16.0",
|
|
74
64
|
"@typescript-eslint/parser": "^6.16.0",
|
|
75
65
|
"@vitest/coverage-v8": "^1.1.1",
|
|
66
|
+
"babel-plugin-syntax-hermes-parser": "^0.19.1",
|
|
76
67
|
"eslint": "^8.56.0",
|
|
77
68
|
"tsup": "^8.0.1",
|
|
78
69
|
"typescript": "^5.3.3",
|
|
79
70
|
"vite": "^5.0.10",
|
|
80
71
|
"vitest": "^1.1.0"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"dev": "tsup src/*ts --watch src",
|
|
75
|
+
"build": "tsup src/*.ts --format cjs,esm --dts --splitting --clean",
|
|
76
|
+
"test": "vitest",
|
|
77
|
+
"test:update": "vitest -u",
|
|
78
|
+
"test:cov": "vitest --coverage",
|
|
79
|
+
"lint": "eslint . --ext .ts,.tsx,.js,.jsx",
|
|
80
|
+
"check": "pnpm run lint && pnpm run typecheck",
|
|
81
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import stylex from '@stylexjs/babel-plugin'
|
|
2
|
+
import type { Rule } from '@stylexjs/babel-plugin'
|
|
3
|
+
|
|
4
|
+
export function buildStylexRules(stylexRules: { [key: string]: Rule[] }, useCSSLayers: boolean): string {
|
|
5
|
+
const rules = Object.values(stylexRules).flat()
|
|
6
|
+
if (rules.length === 0) return ''
|
|
7
|
+
|
|
8
|
+
return stylex.processStylexRules(rules, useCSSLayers)
|
|
9
|
+
}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import type { UnpluginStylexOptions } from '@/types'
|
|
1
|
+
import type { StylexOptions, UnpluginStylexOptions } from '@/types'
|
|
2
2
|
import { isDevelopment } from './constants'
|
|
3
3
|
|
|
4
|
-
export function getOptions(options: UnpluginStylexOptions
|
|
5
|
-
const stylex = options.stylex || {}
|
|
4
|
+
export function getOptions(options: UnpluginStylexOptions) {
|
|
5
|
+
const stylex = options.stylex || ({} as StylexOptions)
|
|
6
|
+
const isDev = options.dev || isDevelopment
|
|
6
7
|
|
|
7
8
|
return {
|
|
8
9
|
...options,
|
|
9
|
-
dev: options.dev ||
|
|
10
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
11
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
12
|
-
enforce: options.enforce || 'pre',
|
|
10
|
+
dev: options.dev || isDev,
|
|
13
11
|
stylex: {
|
|
14
|
-
...stylex,
|
|
15
12
|
filename: stylex.filename || 'stylex.css',
|
|
16
|
-
stylexImports: stylex.stylexImports || ['
|
|
13
|
+
stylexImports: stylex.stylexImports || ['@stylexjs/stylex'],
|
|
14
|
+
runtimeInjection: stylex.runtimeInjection ?? isDev,
|
|
15
|
+
aliases: stylex.aliases,
|
|
17
16
|
useCSSLayers: stylex.useCSSLayers || false,
|
|
18
17
|
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: 'commonJS', rootDir: process.cwd() },
|
|
19
18
|
babelConfig: {
|
|
@@ -21,6 +20,7 @@ export function getOptions(options: UnpluginStylexOptions = ({} as UnpluginStyle
|
|
|
21
20
|
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
22
21
|
presets: (stylex.babelConfig || {}).presets || [],
|
|
23
22
|
},
|
|
23
|
+
...stylex,
|
|
24
24
|
},
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript'
|
|
2
|
+
import flowSyntaxPlugin from '@babel/plugin-syntax-flow'
|
|
3
|
+
|
|
4
|
+
export function getSyntaxPlugins(extname: string) {
|
|
5
|
+
const TSPlugin = extname === '.tsx'
|
|
6
|
+
? [[typescriptSyntaxPlugin, { isTSX: true }]]
|
|
7
|
+
: [typescriptSyntaxPlugin]
|
|
8
|
+
|
|
9
|
+
return ['.js', '.jsx'].includes(extname)
|
|
10
|
+
? [flowSyntaxPlugin]
|
|
11
|
+
: TSPlugin
|
|
12
|
+
}
|
package/src/core/transformer.ts
CHANGED
|
@@ -1,61 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as path from 'path'
|
|
3
|
-
|
|
1
|
+
import { extname as pathExtname } from 'node:path'
|
|
4
2
|
import { transformAsync } from '@babel/core'
|
|
5
|
-
import flowSyntaxPlugin from '@babel/plugin-syntax-flow'
|
|
6
3
|
import jsxSyntaxPlugin from '@babel/plugin-syntax-jsx'
|
|
7
|
-
import typescriptSyntaxPlugin from '@babel/plugin-syntax-typescript'
|
|
8
4
|
import stylexBabelPlugin from '@stylexjs/babel-plugin'
|
|
9
5
|
|
|
6
|
+
import { getSyntaxPlugins } from './plugins'
|
|
7
|
+
|
|
10
8
|
export async function transformer(context) {
|
|
11
|
-
const { id,
|
|
9
|
+
const { id, inputCode, options } = context
|
|
12
10
|
const stylex = options.stylex
|
|
13
|
-
const extname =
|
|
11
|
+
const extname = pathExtname(id)
|
|
14
12
|
const stylexRules = {}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
jsxSyntaxPlugin,
|
|
35
|
-
[
|
|
36
|
-
stylexBabelPlugin,
|
|
37
|
-
{
|
|
38
|
-
dev: options.dev,
|
|
39
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
40
|
-
importSources: stylex.stylexImports,
|
|
41
|
-
...stylex,
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
],
|
|
45
|
-
presets: stylex.babelConfig.presets,
|
|
46
|
-
}
|
|
47
|
-
)
|
|
48
|
-
|
|
49
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
50
|
-
stylexRules[id] = metadata.stylex
|
|
13
|
+
const stylexBabelPluginOptions = {
|
|
14
|
+
dev: options.dev,
|
|
15
|
+
importSources: stylex.stylexImports,
|
|
16
|
+
...stylex,
|
|
17
|
+
}
|
|
18
|
+
const plugins = [
|
|
19
|
+
...(stylex.babelConfig?.plugins || []),
|
|
20
|
+
...getSyntaxPlugins(extname),
|
|
21
|
+
jsxSyntaxPlugin,
|
|
22
|
+
stylexBabelPlugin.withOptions(stylexBabelPluginOptions),
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
const { code, map, metadata } = await transformAsync(
|
|
26
|
+
inputCode,
|
|
27
|
+
{
|
|
28
|
+
babelrc: stylex.babelConfig?.babelrc,
|
|
29
|
+
filename: id,
|
|
30
|
+
presets: stylex.babelConfig?.presets,
|
|
31
|
+
plugins,
|
|
51
32
|
}
|
|
33
|
+
)
|
|
52
34
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
36
|
+
stylexRules[id] = metadata.stylex
|
|
37
|
+
}
|
|
56
38
|
|
|
57
|
-
|
|
39
|
+
if (!stylex.babelConfig?.babelrc) {
|
|
40
|
+
return { code, map, stylexRules }
|
|
58
41
|
}
|
|
59
42
|
|
|
60
|
-
return { code
|
|
43
|
+
return { code, stylexRules }
|
|
61
44
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import * as path from 'node:path'
|
|
2
|
+
|
|
3
3
|
import { createUnplugin } from 'unplugin'
|
|
4
4
|
import type { UnpluginFactory } from 'unplugin'
|
|
5
5
|
|
|
6
|
+
import { buildStylexRules } from './core/build'
|
|
6
7
|
import { PLUGIN_NAME } from './core/constants'
|
|
7
|
-
import { getOptions } from './core/
|
|
8
|
+
import { getOptions } from './core/options'
|
|
8
9
|
import { transformer } from './core/transformer'
|
|
9
10
|
import type { UnpluginStylexOptions } from './types'
|
|
10
11
|
|
|
11
12
|
export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined> = (rawOptions = {}) => {
|
|
12
13
|
const options = getOptions(rawOptions)
|
|
13
|
-
const filter = createFilter(options.include, options.exclude)
|
|
14
14
|
const stylexRules = {}
|
|
15
|
-
let
|
|
15
|
+
let viteConfig = null
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
18
|
name: PLUGIN_NAME,
|
|
19
|
-
enforce: options.enforce,
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
async transform(code, id) {
|
|
21
|
+
const dir = path.dirname(id)
|
|
22
|
+
const basename = path.basename(id)
|
|
23
|
+
const file = path.join(dir, basename.includes('?') ? basename.split('?')[0] : basename)
|
|
24
|
+
|
|
25
|
+
if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
24
28
|
|
|
25
|
-
async transform(source, id) {
|
|
26
29
|
const context = {
|
|
30
|
+
id: file,
|
|
31
|
+
inputCode: code,
|
|
27
32
|
pluginContext: this,
|
|
28
33
|
options,
|
|
29
|
-
source,
|
|
30
|
-
id,
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
try {
|
|
@@ -39,16 +42,16 @@ export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>
|
|
|
39
42
|
|
|
40
43
|
return result
|
|
41
44
|
} catch (error) {
|
|
45
|
+
console.error('transform::error::', error)
|
|
42
46
|
this.error(error)
|
|
43
47
|
}
|
|
44
48
|
},
|
|
45
49
|
|
|
46
50
|
buildEnd() {
|
|
47
|
-
const rules = Object.values(stylexRules).flat()
|
|
48
|
-
if (rules.length === 0) return
|
|
49
|
-
|
|
50
|
-
const collectedCSS = (stylexBabelPlugin as any).processStylexRules(rules, options.stylex.useCSSLayers)
|
|
51
51
|
const fileName = options.stylex.filename
|
|
52
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
53
|
+
|
|
54
|
+
if (!collectedCSS) return
|
|
52
55
|
|
|
53
56
|
this.emitFile({
|
|
54
57
|
fileName,
|
|
@@ -56,27 +59,63 @@ export const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>
|
|
|
56
59
|
type: 'asset',
|
|
57
60
|
})
|
|
58
61
|
},
|
|
62
|
+
|
|
59
63
|
vite: {
|
|
60
64
|
config(config) {
|
|
61
|
-
|
|
65
|
+
viteConfig = {
|
|
66
|
+
build: config.build,
|
|
67
|
+
base: config.base,
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
configResolved(config) {
|
|
72
|
+
config.optimizeDeps.exclude = config.optimizeDeps.exclude || []
|
|
73
|
+
config.optimizeDeps.exclude.push('@stylexjs/open-props')
|
|
62
74
|
},
|
|
75
|
+
|
|
63
76
|
buildEnd() {
|
|
64
|
-
const
|
|
65
|
-
|
|
77
|
+
const fileName = `${viteConfig.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
78
|
+
const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers)
|
|
66
79
|
|
|
67
|
-
|
|
68
|
-
const fileName = `${viteBuildConfig.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
80
|
+
if (!collectedCSS) return
|
|
69
81
|
|
|
70
82
|
this.emitFile({
|
|
71
83
|
fileName,
|
|
72
84
|
source: collectedCSS,
|
|
73
85
|
type: 'asset',
|
|
74
86
|
})
|
|
75
|
-
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
transformIndexHtml(html, ctx) {
|
|
90
|
+
const fileName = `${viteConfig.build?.assetsDir ?? 'assets'}/${options.stylex.filename}`
|
|
91
|
+
const css = ctx.bundle?.[fileName]
|
|
92
|
+
|
|
93
|
+
if (!css) {
|
|
94
|
+
return html
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const publicPath = path.posix.join(
|
|
98
|
+
viteConfig.base ?? '/',
|
|
99
|
+
fileName.replace(/\\/g, '/')
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return [
|
|
103
|
+
{
|
|
104
|
+
tag: 'link',
|
|
105
|
+
attrs: {
|
|
106
|
+
rel: 'stylesheet',
|
|
107
|
+
href: publicPath,
|
|
108
|
+
},
|
|
109
|
+
injectTo: 'head',
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
},
|
|
76
113
|
},
|
|
77
114
|
}
|
|
78
115
|
}
|
|
79
116
|
|
|
80
117
|
export const unplugin = createUnplugin(unpluginFactory)
|
|
81
118
|
|
|
119
|
+
export * from './types'
|
|
120
|
+
|
|
82
121
|
export default unplugin
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type { FilterPattern } from '@rollup/pluginutils'
|
|
2
|
-
|
|
3
1
|
export type BabelConfig = {
|
|
4
2
|
plugins: unknown[]
|
|
5
3
|
presets: unknown[]
|
|
6
4
|
babelrc: boolean
|
|
7
5
|
}
|
|
8
6
|
|
|
9
|
-
type StylexOptions = {
|
|
7
|
+
export type StylexOptions = {
|
|
10
8
|
filename?: string
|
|
11
9
|
stylexImports?: string[]
|
|
12
10
|
classNamePrefix?: string
|
|
@@ -16,12 +14,13 @@ type StylexOptions = {
|
|
|
16
14
|
rootDir: string
|
|
17
15
|
}
|
|
18
16
|
babelConfig?: BabelConfig
|
|
17
|
+
runtimeInjection: boolean
|
|
18
|
+
aliases?: string[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type UnpluginStylexOptions = {
|
|
22
|
+
compiler?: string
|
|
22
23
|
dev?: boolean
|
|
23
|
-
include?: FilterPattern
|
|
24
|
-
exclude?: FilterPattern
|
|
25
24
|
enforce?: "post" | "pre"
|
|
26
25
|
stylex?: StylexOptions
|
|
27
26
|
}
|
package/dist/chunk-D3OQCQYP.cjs
DELETED
|
@@ -1,152 +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(); } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkN4Z3Z2PUcjs = require('./chunk-N4Z3Z2PU.cjs');
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
var _pluginutils = require('@rollup/pluginutils');
|
|
8
|
-
var _babelplugin = require('@stylexjs/babel-plugin'); var _babelplugin2 = _interopRequireDefault(_babelplugin);
|
|
9
|
-
var _unplugin = require('unplugin');
|
|
10
|
-
|
|
11
|
-
// src/core/utils.ts
|
|
12
|
-
function getOptions(options = {}) {
|
|
13
|
-
const stylex = options.stylex || {};
|
|
14
|
-
return {
|
|
15
|
-
...options,
|
|
16
|
-
dev: options.dev || _chunkN4Z3Z2PUcjs.isDevelopment,
|
|
17
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
18
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
19
|
-
enforce: options.enforce || "pre",
|
|
20
|
-
stylex: {
|
|
21
|
-
...stylex,
|
|
22
|
-
filename: stylex.filename || "stylex.css",
|
|
23
|
-
stylexImports: stylex.stylexImports || ["stylex", "@stylexjs/stylex"],
|
|
24
|
-
useCSSLayers: stylex.useCSSLayers || false,
|
|
25
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
26
|
-
babelConfig: {
|
|
27
|
-
babelrc: (stylex.babelConfig || {}).babelrc || false,
|
|
28
|
-
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
29
|
-
presets: (stylex.babelConfig || {}).presets || []
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/transformer.ts
|
|
36
|
-
var _promises = require('fs/promises'); var fs = _interopRequireWildcard(_promises);
|
|
37
|
-
var _path = require('path'); var path = _interopRequireWildcard(_path);
|
|
38
|
-
var _core = require('@babel/core');
|
|
39
|
-
var _pluginsyntaxflow = require('@babel/plugin-syntax-flow'); var _pluginsyntaxflow2 = _interopRequireDefault(_pluginsyntaxflow);
|
|
40
|
-
var _pluginsyntaxjsx = require('@babel/plugin-syntax-jsx'); var _pluginsyntaxjsx2 = _interopRequireDefault(_pluginsyntaxjsx);
|
|
41
|
-
var _pluginsyntaxtypescript = require('@babel/plugin-syntax-typescript'); var _pluginsyntaxtypescript2 = _interopRequireDefault(_pluginsyntaxtypescript);
|
|
42
|
-
|
|
43
|
-
async function transformer(context) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
const { id, source, options } = context;
|
|
46
|
-
const stylex = options.stylex;
|
|
47
|
-
const extname2 = path.extname(id);
|
|
48
|
-
const stylexRules = {};
|
|
49
|
-
if ((_b = (_a = stylex.stylexImports) == null ? void 0 : _a.some) == null ? void 0 : _b.call(_a, (importName) => source.includes(importName))) {
|
|
50
|
-
const originSource = stylex.babelConfig.babelrc ? await fs.readFile(id, "utf-8") : source;
|
|
51
|
-
const { code, map, metadata } = await _core.transformAsync.call(void 0,
|
|
52
|
-
originSource,
|
|
53
|
-
{
|
|
54
|
-
babelrc: stylex.babelConfig.babelrc,
|
|
55
|
-
filename: id,
|
|
56
|
-
plugins: [
|
|
57
|
-
...stylex.babelConfig.plugins || [],
|
|
58
|
-
extname2 === ".ts" ? _pluginsyntaxtypescript2.default : extname2 === ".tsx" ? [_pluginsyntaxtypescript2.default, { isTSX: true }] : _pluginsyntaxflow2.default,
|
|
59
|
-
_pluginsyntaxjsx2.default,
|
|
60
|
-
[
|
|
61
|
-
_babelplugin2.default,
|
|
62
|
-
{
|
|
63
|
-
dev: options.dev,
|
|
64
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
65
|
-
importSources: stylex.stylexImports,
|
|
66
|
-
...stylex
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
],
|
|
70
|
-
presets: stylex.babelConfig.presets
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
74
|
-
stylexRules[id] = metadata.stylex;
|
|
75
|
-
}
|
|
76
|
-
if (!stylex.babelConfig.babelrc) {
|
|
77
|
-
return { code, map, stylexRules };
|
|
78
|
-
}
|
|
79
|
-
return { code, stylexRules };
|
|
80
|
-
}
|
|
81
|
-
return { code: source };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/index.ts
|
|
85
|
-
var unpluginFactory = (rawOptions = {}) => {
|
|
86
|
-
const options = getOptions(rawOptions);
|
|
87
|
-
const filter = _pluginutils.createFilter.call(void 0, options.include, options.exclude);
|
|
88
|
-
const stylexRules = {};
|
|
89
|
-
let viteBuildConfig = null;
|
|
90
|
-
return {
|
|
91
|
-
name: _chunkN4Z3Z2PUcjs.PLUGIN_NAME,
|
|
92
|
-
enforce: options.enforce,
|
|
93
|
-
transformInclude(id) {
|
|
94
|
-
return filter(id);
|
|
95
|
-
},
|
|
96
|
-
async transform(source, id) {
|
|
97
|
-
const context = {
|
|
98
|
-
pluginContext: this,
|
|
99
|
-
options,
|
|
100
|
-
source,
|
|
101
|
-
id
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
const result = await transformer(context);
|
|
105
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
106
|
-
stylexRules[id] = result.stylexRules[id];
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.error(error);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
buildEnd() {
|
|
114
|
-
const rules = Object.values(stylexRules).flat();
|
|
115
|
-
if (rules.length === 0)
|
|
116
|
-
return;
|
|
117
|
-
const collectedCSS = _babelplugin2.default.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
118
|
-
const fileName = options.stylex.filename;
|
|
119
|
-
this.emitFile({
|
|
120
|
-
fileName,
|
|
121
|
-
source: collectedCSS,
|
|
122
|
-
type: "asset"
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
vite: {
|
|
126
|
-
config(config) {
|
|
127
|
-
viteBuildConfig = config.build;
|
|
128
|
-
},
|
|
129
|
-
buildEnd() {
|
|
130
|
-
var _a;
|
|
131
|
-
const rules = Object.values(stylexRules).flat();
|
|
132
|
-
if (!viteBuildConfig || rules.length === 0)
|
|
133
|
-
return;
|
|
134
|
-
const collectedCSS = _babelplugin2.default.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
135
|
-
const fileName = `${_nullishCoalesce(((_a = viteBuildConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets"))}/${options.stylex.filename}`;
|
|
136
|
-
this.emitFile({
|
|
137
|
-
fileName,
|
|
138
|
-
source: collectedCSS,
|
|
139
|
-
type: "asset"
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
var unplugin = _unplugin.createUnplugin.call(void 0, unpluginFactory);
|
|
146
|
-
var src_default = unplugin;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
exports.unpluginFactory = unpluginFactory; exports.unplugin = unplugin; exports.src_default = src_default;
|
package/dist/chunk-XQ5JPTTJ.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PLUGIN_NAME,
|
|
3
|
-
isDevelopment
|
|
4
|
-
} from "./chunk-36ARBXVP.js";
|
|
5
|
-
|
|
6
|
-
// src/index.ts
|
|
7
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
8
|
-
import stylexBabelPlugin2 from "@stylexjs/babel-plugin";
|
|
9
|
-
import { createUnplugin } from "unplugin";
|
|
10
|
-
|
|
11
|
-
// src/core/utils.ts
|
|
12
|
-
function getOptions(options = {}) {
|
|
13
|
-
const stylex = options.stylex || {};
|
|
14
|
-
return {
|
|
15
|
-
...options,
|
|
16
|
-
dev: options.dev || isDevelopment,
|
|
17
|
-
include: options.include || [/\.[jt]sx?$/],
|
|
18
|
-
exclude: options.exclude || [/node_modules/, /\.git/],
|
|
19
|
-
enforce: options.enforce || "pre",
|
|
20
|
-
stylex: {
|
|
21
|
-
...stylex,
|
|
22
|
-
filename: stylex.filename || "stylex.css",
|
|
23
|
-
stylexImports: stylex.stylexImports || ["stylex", "@stylexjs/stylex"],
|
|
24
|
-
useCSSLayers: stylex.useCSSLayers || false,
|
|
25
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution || { type: "commonJS", rootDir: process.cwd() },
|
|
26
|
-
babelConfig: {
|
|
27
|
-
babelrc: (stylex.babelConfig || {}).babelrc || false,
|
|
28
|
-
plugins: (stylex.babelConfig || {}).plugins || [],
|
|
29
|
-
presets: (stylex.babelConfig || {}).presets || []
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/core/transformer.ts
|
|
36
|
-
import * as fs from "fs/promises";
|
|
37
|
-
import * as path from "path";
|
|
38
|
-
import { transformAsync } from "@babel/core";
|
|
39
|
-
import flowSyntaxPlugin from "@babel/plugin-syntax-flow";
|
|
40
|
-
import jsxSyntaxPlugin from "@babel/plugin-syntax-jsx";
|
|
41
|
-
import typescriptSyntaxPlugin from "@babel/plugin-syntax-typescript";
|
|
42
|
-
import stylexBabelPlugin from "@stylexjs/babel-plugin";
|
|
43
|
-
async function transformer(context) {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
const { id, source, options } = context;
|
|
46
|
-
const stylex = options.stylex;
|
|
47
|
-
const extname2 = path.extname(id);
|
|
48
|
-
const stylexRules = {};
|
|
49
|
-
if ((_b = (_a = stylex.stylexImports) == null ? void 0 : _a.some) == null ? void 0 : _b.call(_a, (importName) => source.includes(importName))) {
|
|
50
|
-
const originSource = stylex.babelConfig.babelrc ? await fs.readFile(id, "utf-8") : source;
|
|
51
|
-
const { code, map, metadata } = await transformAsync(
|
|
52
|
-
originSource,
|
|
53
|
-
{
|
|
54
|
-
babelrc: stylex.babelConfig.babelrc,
|
|
55
|
-
filename: id,
|
|
56
|
-
plugins: [
|
|
57
|
-
...stylex.babelConfig.plugins || [],
|
|
58
|
-
extname2 === ".ts" ? typescriptSyntaxPlugin : extname2 === ".tsx" ? [typescriptSyntaxPlugin, { isTSX: true }] : flowSyntaxPlugin,
|
|
59
|
-
jsxSyntaxPlugin,
|
|
60
|
-
[
|
|
61
|
-
stylexBabelPlugin,
|
|
62
|
-
{
|
|
63
|
-
dev: options.dev,
|
|
64
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
65
|
-
importSources: stylex.stylexImports,
|
|
66
|
-
...stylex
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
],
|
|
70
|
-
presets: stylex.babelConfig.presets
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
74
|
-
stylexRules[id] = metadata.stylex;
|
|
75
|
-
}
|
|
76
|
-
if (!stylex.babelConfig.babelrc) {
|
|
77
|
-
return { code, map, stylexRules };
|
|
78
|
-
}
|
|
79
|
-
return { code, stylexRules };
|
|
80
|
-
}
|
|
81
|
-
return { code: source };
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/index.ts
|
|
85
|
-
var unpluginFactory = (rawOptions = {}) => {
|
|
86
|
-
const options = getOptions(rawOptions);
|
|
87
|
-
const filter = createFilter(options.include, options.exclude);
|
|
88
|
-
const stylexRules = {};
|
|
89
|
-
let viteBuildConfig = null;
|
|
90
|
-
return {
|
|
91
|
-
name: PLUGIN_NAME,
|
|
92
|
-
enforce: options.enforce,
|
|
93
|
-
transformInclude(id) {
|
|
94
|
-
return filter(id);
|
|
95
|
-
},
|
|
96
|
-
async transform(source, id) {
|
|
97
|
-
const context = {
|
|
98
|
-
pluginContext: this,
|
|
99
|
-
options,
|
|
100
|
-
source,
|
|
101
|
-
id
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
const result = await transformer(context);
|
|
105
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
106
|
-
stylexRules[id] = result.stylexRules[id];
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
} catch (error) {
|
|
110
|
-
this.error(error);
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
buildEnd() {
|
|
114
|
-
const rules = Object.values(stylexRules).flat();
|
|
115
|
-
if (rules.length === 0)
|
|
116
|
-
return;
|
|
117
|
-
const collectedCSS = stylexBabelPlugin2.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
118
|
-
const fileName = options.stylex.filename;
|
|
119
|
-
this.emitFile({
|
|
120
|
-
fileName,
|
|
121
|
-
source: collectedCSS,
|
|
122
|
-
type: "asset"
|
|
123
|
-
});
|
|
124
|
-
},
|
|
125
|
-
vite: {
|
|
126
|
-
config(config) {
|
|
127
|
-
viteBuildConfig = config.build;
|
|
128
|
-
},
|
|
129
|
-
buildEnd() {
|
|
130
|
-
var _a;
|
|
131
|
-
const rules = Object.values(stylexRules).flat();
|
|
132
|
-
if (!viteBuildConfig || rules.length === 0)
|
|
133
|
-
return;
|
|
134
|
-
const collectedCSS = stylexBabelPlugin2.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
135
|
-
const fileName = `${((_a = viteBuildConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets"}/${options.stylex.filename}`;
|
|
136
|
-
this.emitFile({
|
|
137
|
-
fileName,
|
|
138
|
-
source: collectedCSS,
|
|
139
|
-
type: "asset"
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
var unplugin = createUnplugin(unpluginFactory);
|
|
146
|
-
var src_default = unplugin;
|
|
147
|
-
|
|
148
|
-
export {
|
|
149
|
-
unpluginFactory,
|
|
150
|
-
unplugin,
|
|
151
|
-
src_default
|
|
152
|
-
};
|