unplugin-stylex 0.0.1 → 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/.eslintignore +4 -0
- package/.eslintrc.json +12 -1
- package/.github/actions/setup-and-cache/action.yml +18 -0
- package/.github/workflows/ci.yml +43 -0
- package/.github/workflows/release.yml +26 -0
- 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 +4 -1
- package/dist/rspack.d.ts +4 -1
- package/dist/rspack.js +2 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +6 -7
- package/dist/types.d.ts +6 -7
- package/dist/types.js +1 -0
- package/dist/vite.cjs +3 -2
- package/dist/vite.d.cts +4 -1
- package/dist/vite.d.ts +4 -1
- package/dist/vite.js +2 -1
- package/package.json +19 -11
- 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 +77 -17
- package/src/rspack.ts +1 -1
- package/src/types.ts +6 -7
- package/src/vite.ts +1 -1
- package/tsconfig.json +5 -0
- package/vitest.config.ts +13 -0
- package/dist/chunk-5FLQNHMU.cjs +0 -131
- package/dist/chunk-R3ITJTXO.js +0 -131
package/dist/chunk-R3ITJTXO.js
DELETED
|
@@ -1,131 +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
|
-
const { id, source, options } = context;
|
|
45
|
-
const stylex = options.stylex;
|
|
46
|
-
const extname2 = path.extname(id);
|
|
47
|
-
const stylexRules = {};
|
|
48
|
-
if (stylex.stylexImports.some((importName) => source.includes(importName))) {
|
|
49
|
-
const originSource = stylex.babelConfig.babelrc ? await fs.readFile(id, "utf-8") : source;
|
|
50
|
-
const { code, map, metadata } = await transformAsync(
|
|
51
|
-
originSource,
|
|
52
|
-
{
|
|
53
|
-
babelrc: stylex.babelConfig.babelrc,
|
|
54
|
-
filename: id,
|
|
55
|
-
plugins: [
|
|
56
|
-
...stylex.babelConfig.plugins || [],
|
|
57
|
-
extname2 === ".ts" ? typescriptSyntaxPlugin : extname2 === ".tsx" ? [typescriptSyntaxPlugin, { isTSX: true }] : flowSyntaxPlugin,
|
|
58
|
-
jsxSyntaxPlugin,
|
|
59
|
-
[
|
|
60
|
-
stylexBabelPlugin,
|
|
61
|
-
{
|
|
62
|
-
dev: options.dev,
|
|
63
|
-
unstable_moduleResolution: stylex.unstable_moduleResolution,
|
|
64
|
-
importSources: stylex.stylexImports,
|
|
65
|
-
...stylex
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
],
|
|
69
|
-
presets: stylex.babelConfig.presets
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
if (metadata.stylex && metadata.stylex.length > 0) {
|
|
73
|
-
stylexRules[id] = metadata.stylex;
|
|
74
|
-
}
|
|
75
|
-
if (!stylex.babelConfig.babelrc) {
|
|
76
|
-
return { code, map, stylexRules };
|
|
77
|
-
}
|
|
78
|
-
return { code, stylexRules };
|
|
79
|
-
}
|
|
80
|
-
return { code: source };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/index.ts
|
|
84
|
-
var unpluginFactory = (rawOptions = {}, meta) => {
|
|
85
|
-
const options = getOptions(rawOptions);
|
|
86
|
-
const filter = createFilter(options.include, options.exclude);
|
|
87
|
-
const stylexRules = {};
|
|
88
|
-
return {
|
|
89
|
-
name: PLUGIN_NAME,
|
|
90
|
-
enforce: options.enforce,
|
|
91
|
-
transformInclude(id) {
|
|
92
|
-
return filter(id);
|
|
93
|
-
},
|
|
94
|
-
async transform(source, id) {
|
|
95
|
-
const context = {
|
|
96
|
-
pluginContext: this,
|
|
97
|
-
options,
|
|
98
|
-
source,
|
|
99
|
-
id
|
|
100
|
-
};
|
|
101
|
-
try {
|
|
102
|
-
const result = await transformer(context);
|
|
103
|
-
if (result.stylexRules && result.stylexRules[id]) {
|
|
104
|
-
stylexRules[id] = result.stylexRules[id];
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
} catch (error) {
|
|
108
|
-
this.error(error);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
buildEnd() {
|
|
112
|
-
const rules = Object.values(stylexRules).flat();
|
|
113
|
-
if (rules.length > 0) {
|
|
114
|
-
const collectedCSS = stylexBabelPlugin2.processStylexRules(rules, options.stylex.useCSSLayers);
|
|
115
|
-
this.emitFile({
|
|
116
|
-
fileName: options.stylex.filename,
|
|
117
|
-
source: collectedCSS,
|
|
118
|
-
type: "asset"
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
var unplugin = createUnplugin(unpluginFactory);
|
|
125
|
-
var src_default = unplugin;
|
|
126
|
-
|
|
127
|
-
export {
|
|
128
|
-
unpluginFactory,
|
|
129
|
-
unplugin,
|
|
130
|
-
src_default
|
|
131
|
-
};
|