unplugin-stylex 0.0.2 → 0.2.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/.eslintrc.json +4 -6
- package/.github/renovate.json +27 -0
- package/.github/workflows/release.yml +13 -0
- package/.github/workflows/typos.yml +15 -0
- package/README.md +9 -7
- 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 +4 -2
- package/dist/esbuild.d.cts +10 -5
- package/dist/esbuild.d.ts +10 -5
- package/dist/esbuild.js +4 -2
- package/dist/index.cjs +3 -2
- package/dist/index.d.cts +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +2 -1
- package/dist/rollup.cjs +1 -1
- package/dist/rollup.d.cts +12 -1
- package/dist/rollup.d.ts +12 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +4 -2
- package/dist/rspack.d.cts +11 -5
- package/dist/rspack.d.ts +11 -5
- package/dist/rspack.js +4 -2
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +7 -7
- package/dist/types.d.ts +7 -7
- package/dist/types.js +1 -0
- package/dist/vite.cjs +4 -2
- package/dist/vite.d.cts +10 -5
- package/dist/vite.d.ts +10 -5
- package/dist/vite.js +4 -2
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.d.cts +12 -1
- package/dist/webpack.d.ts +12 -1
- package/dist/webpack.js +1 -1
- package/jsr.json +20 -0
- package/package.json +8 -3
- 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/esbuild.ts +27 -2
- package/src/index.ts +64 -24
- package/src/rollup.ts +12 -2
- package/src/rspack.ts +27 -2
- package/src/types.ts +8 -7
- package/src/vite.ts +26 -2
- package/src/webpack.ts +12 -2
- package/typos.toml +10 -0
- package/vitest.config.ts +2 -2
- package/dist/chunk-D3OQCQYP.cjs +0 -152
- package/dist/chunk-XQ5JPTTJ.js +0 -152
package/.eslintrc.json
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
"env": {
|
|
3
3
|
"node": true
|
|
4
4
|
},
|
|
5
|
-
"extends": [
|
|
6
|
-
"eslint:recommended",
|
|
7
|
-
"plugin:@typescript-eslint/recommended"
|
|
8
|
-
],
|
|
9
5
|
"parser": "@typescript-eslint/parser",
|
|
10
|
-
"plugins": ["@
|
|
6
|
+
"plugins": ["@stylistic/ts"],
|
|
11
7
|
"root": true,
|
|
12
8
|
"rules": {
|
|
13
|
-
"
|
|
9
|
+
"max-len": ["error", { "code": 120 }],
|
|
10
|
+
"semi": ["error", "never"],
|
|
11
|
+
"quotes": ["error", "single"],
|
|
14
12
|
"@typescript-eslint/no-explicit-any": "off"
|
|
15
13
|
}
|
|
16
14
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
|
3
|
+
"extends": ["config:base"],
|
|
4
|
+
"lockFileMaintenance": {"enabled": true, "automerge": false},
|
|
5
|
+
"rangeStrategy": "replace",
|
|
6
|
+
"postUpdateOptions": ["pnpmDedupe"],
|
|
7
|
+
"packageRules": [
|
|
8
|
+
{
|
|
9
|
+
"matchPackageNames": ["@tsd/typescript", "typescript"],
|
|
10
|
+
"groupName": "typescript"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"matchPackageNames": [
|
|
14
|
+
"@babel/core",
|
|
15
|
+
"@babel/plugin-syntax-flow",
|
|
16
|
+
"@babel/plugin-syntax-jsx",
|
|
17
|
+
"@babel/plugin-syntax-typescript"
|
|
18
|
+
],
|
|
19
|
+
"groupName": "babel"
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
{
|
|
23
|
+
"matchPackageNames": ["@stylexjs/stylex", "@stylexjs/babel-plugin"],
|
|
24
|
+
"groupName": "stylex"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -24,3 +24,16 @@ jobs:
|
|
|
24
24
|
- run: npx changelogithub
|
|
25
25
|
env:
|
|
26
26
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
27
|
+
|
|
28
|
+
publish-jsr:
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
|
|
31
|
+
permissions:
|
|
32
|
+
contents: read
|
|
33
|
+
id-token: write
|
|
34
|
+
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v4
|
|
37
|
+
|
|
38
|
+
- name: Publish package
|
|
39
|
+
run: npx jsr publish
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: Spell Check
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "main"
|
|
7
|
+
jobs:
|
|
8
|
+
typos:
|
|
9
|
+
name: Spell Check with Typos
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout Actions Repository
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
- name: Check spelling
|
|
15
|
+
uses: crate-ci/typos@master
|
package/README.md
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
# unplugin-stylex
|
|
1
|
+
# unplugin-stylex · [](https://github.com/eryue0220/unplugin-stylex/blob/main/LICENSE) [](https://www.npmjs.com/package/unplugin-stylex)
|
|
2
|
+
|
|
3
|
+
> [!WARNING]
|
|
4
|
+
> This plugin is in early development and may not work as expected. Please report any issues you find.
|
|
2
5
|
|
|
3
6
|
## Installation
|
|
4
7
|
|
|
@@ -75,11 +78,9 @@ module.exports = {
|
|
|
75
78
|
|
|
76
79
|
## Options
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
### options.enforce
|
|
81
|
+
Current support argument, which may have change in the future
|
|
81
82
|
|
|
82
|
-
### options.
|
|
83
|
+
### options.dev
|
|
83
84
|
|
|
84
85
|
#### options.stylex.runtimeInjection
|
|
85
86
|
|
|
@@ -93,6 +94,7 @@ module.exports = {
|
|
|
93
94
|
|
|
94
95
|
#### options.stylex.unstable_moduleResolution
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
# Acknowledgments
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
- [@stylexjs/rollup-plugin](https://github.com/facebook/stylex/tree/main/packages/rollup-plugin)
|
|
100
|
+
- [vite-plugin-stylex](https://github.com/HorusGoul/vite-plugin-stylex)
|
|
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,13 @@
|
|
|
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
|
|
9
|
+
var esbuildPlugin = _unplugin.createEsbuildPlugin.call(void 0, _chunkNVMQARFAcjs.unpluginFactory);
|
|
10
|
+
var esbuild_default = esbuildPlugin;
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
exports.default = esbuild_default;
|
package/dist/esbuild.d.cts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { EsbuildPlugin } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.cjs';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
declare const esbuildPlugin: UnpluginStylexInstance<EsbuildPlugin | EsbuildPlugin[]>;
|
|
11
|
+
|
|
12
|
+
export { esbuildPlugin as default };
|
package/dist/esbuild.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import '@rollup/pluginutils';
|
|
1
|
+
import { EsbuildPlugin } from 'unplugin';
|
|
2
|
+
import { UnpluginStylexInstance } from './types.js';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* This entry file is for esbuild plugin. Requires esbuild >= 0.15
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
declare const esbuildPlugin: UnpluginStylexInstance<EsbuildPlugin | EsbuildPlugin[]>;
|
|
11
|
+
|
|
12
|
+
export { esbuildPlugin as default };
|
package/dist/esbuild.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
unpluginFactory
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7MXMBS5H.js";
|
|
4
|
+
import "./chunk-6F4PWJZI.js";
|
|
4
5
|
import "./chunk-36ARBXVP.js";
|
|
5
6
|
|
|
6
7
|
// src/esbuild.ts
|
|
7
8
|
import { createEsbuildPlugin } from "unplugin";
|
|
8
|
-
var
|
|
9
|
+
var esbuildPlugin = createEsbuildPlugin(unpluginFactory);
|
|
10
|
+
var esbuild_default = esbuildPlugin;
|
|
9
11
|
export {
|
|
10
12
|
esbuild_default as default
|
|
11
13
|
};
|
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,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
1
|
+
import { UnpluginFactory, UnpluginInstance } from 'unplugin';
|
|
3
2
|
import { UnpluginStylexOptions } from './types.cjs';
|
|
4
|
-
|
|
3
|
+
export { BabelConfig, StylexOptions, UnpluginStylexInstance } from './types.cjs';
|
|
5
4
|
|
|
6
5
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>;
|
|
7
|
-
declare const unplugin:
|
|
6
|
+
declare const unplugin: UnpluginInstance<UnpluginStylexOptions | undefined, boolean>;
|
|
8
7
|
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
8
|
+
export { UnpluginStylexOptions, unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
1
|
+
import { UnpluginFactory, UnpluginInstance } from 'unplugin';
|
|
3
2
|
import { UnpluginStylexOptions } from './types.js';
|
|
4
|
-
|
|
3
|
+
export { BabelConfig, StylexOptions, UnpluginStylexInstance } from './types.js';
|
|
5
4
|
|
|
6
5
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexOptions | undefined>;
|
|
7
|
-
declare const unplugin:
|
|
6
|
+
declare const unplugin: UnpluginInstance<UnpluginStylexOptions | undefined, boolean>;
|
|
8
7
|
|
|
9
|
-
export { unplugin as default, unplugin, unpluginFactory };
|
|
8
|
+
export { UnpluginStylexOptions, unplugin as default, unplugin, unpluginFactory };
|
package/dist/index.js
CHANGED
package/dist/rollup.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var _chunkN4Z3Z2PUcjs = require('./chunk-N4Z3Z2PU.cjs');
|
|
|
5
5
|
// src/rollup.ts
|
|
6
6
|
var rollup_default = (options) => {
|
|
7
7
|
if (_chunkN4Z3Z2PUcjs.isDevelopment || (options == null ? void 0 : options.dev)) {
|
|
8
|
-
throw new Error(
|
|
8
|
+
throw new Error('If you want to use this plugin through rollup, please use "@stylexjs/rollup-plugin" instead');
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
|
package/dist/rollup.d.cts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { UnpluginStylexOptions } from './types.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This entry file is for Rollup plugin.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Note: Current, please use @stylexjs/rollup-plugin
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: (options?: UnpluginStylexOptions) => void;
|
|
2
13
|
|
|
3
14
|
export { _default as default };
|
package/dist/rollup.d.ts
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { UnpluginStylexOptions } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This entry file is for Rollup plugin.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Note: Current, please use @stylexjs/rollup-plugin
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: (options?: UnpluginStylexOptions) => void;
|
|
2
13
|
|
|
3
14
|
export { _default as default };
|