unplugin-stylex 0.6.2 → 0.6.3

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +143 -84
  3. package/dist/astro.cjs +15 -15
  4. package/dist/astro.d.ts +38 -16
  5. package/dist/astro.d.ts.map +1 -0
  6. package/dist/astro.js +3 -3
  7. package/dist/{chunk-KKH6K7RE.cjs → chunk-45JWH4GZ.cjs} +14 -11
  8. package/dist/{chunk-WUKLRLI4.js → chunk-5RGNKABP.js} +1 -1
  9. package/dist/{chunk-FEGNQ7CQ.js → chunk-SSMUIUHR.js} +14 -11
  10. package/dist/{chunk-O4FQWPVV.cjs → chunk-WDYGV6FU.cjs} +2 -2
  11. package/dist/core/build.d.ts +5 -0
  12. package/dist/core/build.d.ts.map +1 -0
  13. package/dist/core/options.d.ts +5 -0
  14. package/dist/core/options.d.ts.map +1 -0
  15. package/dist/core/plugins.d.ts +2 -0
  16. package/dist/core/plugins.d.ts.map +1 -0
  17. package/dist/core/transformers/astro.d.ts +3 -0
  18. package/dist/core/transformers/astro.d.ts.map +1 -0
  19. package/dist/core/transformers/default.d.ts +3 -0
  20. package/dist/core/transformers/default.d.ts.map +1 -0
  21. package/dist/core/transformers/index.d.ts +3 -0
  22. package/dist/core/transformers/index.d.ts.map +1 -0
  23. package/dist/core/transformers/svelte.d.ts +3 -0
  24. package/dist/core/transformers/svelte.d.ts.map +1 -0
  25. package/dist/esbuild.cjs +2 -2
  26. package/dist/esbuild.d.ts +18 -8
  27. package/dist/esbuild.d.ts.map +1 -0
  28. package/dist/esbuild.js +1 -1
  29. package/dist/farm.cjs +2 -2
  30. package/dist/farm.d.ts +19 -6
  31. package/dist/farm.d.ts.map +1 -0
  32. package/dist/farm.js +1 -1
  33. package/dist/index.cjs +2 -2
  34. package/dist/index.d.ts +7 -11
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +1 -1
  37. package/dist/rolldown.cjs +2 -2
  38. package/dist/rolldown.d.ts +20 -8
  39. package/dist/rolldown.d.ts.map +1 -0
  40. package/dist/rolldown.js +1 -1
  41. package/dist/rollup.cjs +2 -2
  42. package/dist/rollup.d.ts +17 -8
  43. package/dist/rollup.d.ts.map +1 -0
  44. package/dist/rollup.js +1 -1
  45. package/dist/rspack.cjs +2 -2
  46. package/dist/rspack.d.ts +17 -8
  47. package/dist/rspack.d.ts.map +1 -0
  48. package/dist/rspack.js +1 -1
  49. package/dist/types.d.ts +16 -10
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/utils/constants.d.ts +4 -0
  52. package/dist/utils/constants.d.ts.map +1 -0
  53. package/dist/utils/get-aliases.d.ts +4 -0
  54. package/dist/utils/get-aliases.d.ts.map +1 -0
  55. package/dist/utils/index.d.ts +5 -0
  56. package/dist/utils/index.d.ts.map +1 -0
  57. package/dist/utils/store.d.ts +4 -0
  58. package/dist/utils/store.d.ts.map +1 -0
  59. package/dist/utils/stylex-path.d.ts +4 -0
  60. package/dist/utils/stylex-path.d.ts.map +1 -0
  61. package/dist/vite.cjs +3 -3
  62. package/dist/vite.d.ts +18 -8
  63. package/dist/vite.d.ts.map +1 -0
  64. package/dist/vite.js +2 -2
  65. package/dist/webpack.cjs +2 -2
  66. package/dist/webpack.d.ts +17 -8
  67. package/dist/webpack.d.ts.map +1 -0
  68. package/dist/webpack.js +1 -1
  69. package/jsr.json +1 -1
  70. package/package.json +9 -7
  71. package/tsconfig.json +2 -5
  72. package/dist/astro.d.cts +0 -39
  73. package/dist/esbuild.d.cts +0 -14
  74. package/dist/farm.d.cts +0 -11
  75. package/dist/index.d.cts +0 -20
  76. package/dist/rolldown.d.cts +0 -14
  77. package/dist/rollup.d.cts +0 -14
  78. package/dist/rspack.d.cts +0 -15
  79. package/dist/types.d.cts +0 -41
  80. package/dist/vite.d.cts +0 -14
  81. package/dist/webpack.d.cts +0 -14
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # unplugin-stylex
2
2
 
3
+ ## 0.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#321](https://github.com/eryue0220/unplugin-stylex/pull/321) [`cfd5f0b`](https://github.com/eryue0220/unplugin-stylex/commit/cfd5f0bbb9ca21026fd8f9094655e0b0bababcf3) Thanks [@eryue0220](https://github.com/eryue0220)! - update deps
8
+
3
9
  ## 0.6.2
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -1,29 +1,46 @@
1
1
  # unplugin-stylex · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/eryue0220/unplugin-stylex/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/unplugin-stylex.svg?style=flat)](https://www.npmjs.com/package/unplugin-stylex)
2
2
 
3
- ## Installation
3
+ `unplugin-stylex` brings StyleX transform support to multiple bundlers via [unplugin](https://github.com/unjs/unplugin).
4
4
 
5
- Install the package from the following command
5
+ ## Installation
6
6
 
7
- ```shell
8
- npm install unplugin-stylex --save-dev
7
+ ```bash
8
+ npm i -D unplugin-stylex @stylexjs/stylex
9
9
  ```
10
10
 
11
- or with yarn:
11
+ or
12
12
 
13
- ```shell
14
- yarn add unplugin-stylex --save-dev
13
+ ```bash
14
+ yarn add -D unplugin-stylex @stylexjs/stylex
15
15
  ```
16
16
 
17
- or with pnpm:
17
+ or
18
18
 
19
- ```shell
20
- pnpm i unplugin-stylex --save-dev
19
+ ```bash
20
+ pnpm add -D unplugin-stylex @stylexjs/stylex
21
21
  ```
22
22
 
23
- ## Configuration
23
+ ## Requirements
24
+
25
+ - Node.js: `^20.19.0 || >=22.12.0`
26
+ - Peer dependency: `@stylexjs/stylex@0.x`
27
+
28
+ ## Supported Targets
29
+
30
+ - Vite (`unplugin-stylex/vite`)
31
+ - Astro integration (`unplugin-stylex/astro`)
32
+ - Esbuild (`unplugin-stylex/esbuild`)
33
+ - Farm (`unplugin-stylex/farm`)
34
+ - Rspack (`unplugin-stylex/rspack`)
35
+ - RSBuild (through Rspack plugin in `tools.rspack.plugins`)
36
+ - Rolldown (`unplugin-stylex/rolldown`)
37
+ - Rollup (`unplugin-stylex/rollup`)
38
+ - Webpack (`unplugin-stylex/webpack`)
39
+
40
+ ## Quick Start
24
41
 
25
42
  <details>
26
- <summary>vite</summary><br>
43
+ <summary>Vite</summary>
27
44
 
28
45
  ```js
29
46
  // vite.config.js
@@ -32,32 +49,50 @@ import stylexPlugin from 'unplugin-stylex/vite'
32
49
 
33
50
  export default defineConfig({
34
51
  plugins: [
35
- stylexPlugin({ /* options */}),
52
+ stylexPlugin(),
53
+ ],
54
+ })
55
+ ```
56
+
57
+ </details>
58
+
59
+ <details>
60
+ <summary>Astro</summary>
61
+
62
+ ```js
63
+ // astro.config.mjs
64
+ import { defineConfig } from 'astro/config'
65
+ import stylexAstroPlugin from 'unplugin-stylex/astro'
66
+
67
+ export default defineConfig({
68
+ integrations: [
69
+ stylexAstroPlugin(),
36
70
  ],
37
71
  })
38
72
  ```
39
73
 
40
- </br></details>
74
+ </details>
41
75
 
42
76
  <details>
43
- <summary>esbuild</summary><br>
77
+ <summary>Esbuild</summary>
44
78
 
45
79
  ```js
46
80
  // esbuild.config.js
47
81
  import { build } from 'esbuild'
48
82
  import stylexPlugin from 'unplugin-stylex/esbuild'
49
83
 
50
- export default {
51
- plugins: [
52
- stylexPlugin({ /* options */ }),
53
- ],
54
- }
84
+ build({
85
+ entryPoints: ['src/index.tsx'],
86
+ bundle: true,
87
+ outfile: 'dist/out.js',
88
+ plugins: [stylexPlugin()],
89
+ })
55
90
  ```
56
91
 
57
- </br></details>
92
+ </details>
58
93
 
59
94
  <details>
60
- <summary>farm</summary><br>
95
+ <summary>Farm</summary>
61
96
 
62
97
  ```js
63
98
  // farm.config.js
@@ -65,117 +100,141 @@ import { defineConfig } from '@farmfe/core'
65
100
  import stylexPlugin from 'unplugin-stylex/farm'
66
101
 
67
102
  export default defineConfig({
68
- // other rollup config
69
- plugins: [
70
- stylexPlugin({ /* options */}),
71
- ],
103
+ plugins: [stylexPlugin()],
72
104
  })
73
105
  ```
74
106
 
75
- </br></details>
107
+ </details>
76
108
 
77
109
  <details>
78
- <summary>rspack</summary><br>
110
+ <summary>Rspack</summary>
79
111
 
80
112
  ```js
81
113
  // rspack.config.js
82
114
  import stylexPlugin from 'unplugin-stylex/rspack'
83
115
 
84
- module.exports = {
85
- // other rspack config
86
- plugins: [
87
- stylexPlugin({ /* options */}),
88
- ],
116
+ export default {
117
+ plugins: [stylexPlugin()],
89
118
  }
90
119
  ```
91
120
 
92
- </br></details>
121
+ </details>
93
122
 
94
123
  <details>
95
- <summary>rolldown</summary><br>
124
+ <summary>RSBuild</summary>
125
+
126
+ ```ts
127
+ // rsbuild.config.ts
128
+ import { defineConfig } from '@rsbuild/core'
129
+ import stylexPlugin from 'unplugin-stylex/rspack'
130
+
131
+ export default defineConfig({
132
+ tools: {
133
+ rspack: {
134
+ plugins: [stylexPlugin()],
135
+ },
136
+ },
137
+ })
138
+ ```
139
+
140
+ </details>
141
+
142
+ <details>
143
+ <summary>Rolldown</summary>
96
144
 
97
145
  ```js
98
- // rolldown.config.js
99
- import stylexRolldownPlugin from 'unplugin-stylex/rolldown'
146
+ // rolldown.config.mjs
147
+ import { defineConfig } from 'rolldown'
148
+ import stylexPlugin from 'unplugin-stylex/rolldown'
100
149
 
101
- export default {
102
- // other rolldown config
103
- plugins: [
104
- stylexRolldownPlugin({ /* options */}),
105
- ],
106
- }
150
+ export default defineConfig({
151
+ plugins: [stylexPlugin()],
152
+ })
107
153
  ```
108
154
 
109
- </br></details>
155
+ </details>
110
156
 
111
157
  <details>
112
- <summary>rollup</summary><br>
158
+ <summary>Rollup</summary>
113
159
 
114
160
  ```js
115
161
  // rollup.config.js
116
- import stylexRollupPlugin from 'unplugin-stylex/rollup'
162
+ import stylexPlugin from 'unplugin-stylex/rollup'
117
163
 
118
164
  export default {
119
- // other rollup config
120
- plugins: [
121
- stylexRollupPlugin({ /* options */}),
122
- ],
165
+ plugins: [stylexPlugin()],
123
166
  }
124
167
  ```
125
168
 
126
- </br></details>
169
+ </details>
127
170
 
128
171
  <details>
129
- <summary>webpack</summary><br>
172
+ <summary>Webpack</summary>
130
173
 
131
174
  ```js
132
175
  // webpack.config.js
133
- import stylexWebpackPlugin from 'unplugin-stylex/webpack'
176
+ const stylexPlugin = require('unplugin-stylex/webpack').default
134
177
 
135
178
  module.exports = {
136
- // other webpack config
137
- plugins: [
138
- stylexWebpackPlugin({ /* options */}),
139
- ],
179
+ plugins: [stylexPlugin()],
140
180
  }
141
181
  ```
142
182
 
143
- </br></details>
144
-
145
- ## Usage
146
-
147
- More detail usage can check [examples](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
183
+ </details>
148
184
 
149
185
  ## Options
150
186
 
151
- Current support argument, which may have change in the future
152
-
153
- ### options.dev
154
-
155
- #### options.stylex.runtimeInjection
156
-
157
- #### options.stylex.classNamePrefix
158
-
159
- #### options.stylex.useCSSLayers
160
-
161
- #### options.stylex.babelConfig
187
+ ```ts
188
+ type UnpluginStylexOptions = {
189
+ validExts?: RegExp | string[]
190
+ dev?: boolean
191
+ stylex?: {
192
+ filename?: string
193
+ aliases?: Record<string, string | string[]>
194
+ stylexImports?: string[]
195
+ classNamePrefix?: string
196
+ unstable_moduleResolution?: {
197
+ type: 'commonJS' | 'haste'
198
+ rootDir: string
199
+ }
200
+ babelConfig?: {
201
+ plugins: unknown[]
202
+ presets: unknown[]
203
+ babelrc: boolean
204
+ }
205
+ useCSSLayers?: boolean
206
+ genConditionalClasses?: boolean
207
+ treeshakeCompensation?: boolean
208
+ runtimeInjection?: boolean
209
+ }
210
+ }
211
+ ```
162
212
 
163
- #### options.stylex.stylexImports
213
+ ### Defaults
164
214
 
165
- #### options.stylex.unstable_moduleResolution
215
+ - `validExts`: `/\.[mc]?[jt]sx?$|\.svelte$|\.vue$/`
216
+ - `dev`: inferred from environment (`NODE_ENV` / `BABEL_ENV`) unless explicitly set
217
+ - `stylex.filename`: `'stylex.css'`
218
+ - `stylex.stylexImports`: `['@stylexjs/stylex']`
219
+ - `stylex.runtimeInjection`: follows `dev` by default
220
+ - `stylex.aliases`: auto-reads from project config (TS paths + bundler aliases when available)
221
+ - `stylex.useCSSLayers`: `false`
222
+ - `stylex.unstable_moduleResolution`: `{ type: 'commonJS', rootDir: process.cwd() }`
223
+ - `stylex.babelConfig`: `{ babelrc: false, plugins: [], presets: [] }`
166
224
 
167
- ## Monorepo
225
+ ## Notes
168
226
 
169
- 本仓库使用 [Turborepo](https://turbo.build/repo) 管理 monorepo。在根目录可执行:
227
+ - The plugin only transforms modules containing at least one `stylexImports` source.
228
+ - Output CSS is emitted as an asset file (`stylex.css` by default).
229
+ - Vite and Astro integrations also handle dev server CSS serving and HTML injection.
230
+ - Astro integration defaults `validExts` to include `.astro` and `.stylex`.
231
+ - For Farm projects, `treeshakeCompensation: true` is usually needed (see example config).
170
232
 
171
- - `pnpm turbo:build` — 按依赖顺序构建所有包(主包与 examples)
172
- - `pnpm turbo:test` — 在所有包中运行测试
173
- - `pnpm turbo:lint` / `pnpm turbo:check` — 在所有包中运行 lint / check
174
- - `pnpm turbo:dev` — 并行启动所有包的 dev 脚本
233
+ ## Examples
175
234
 
176
- 仅构建主包:`pnpm turbo run build --filter=unplugin-stylex`。仅构建某个 example:`pnpm turbo run build --filter=vite-example`。
235
+ - See runnable examples in [`examples`](https://github.com/eryue0220/unplugin-stylex/tree/main/examples)
177
236
 
178
- # Acknowledgments
237
+ ## Acknowledgments
179
238
 
180
239
  - [@stylexjs/rollup-plugin](https://github.com/facebook/stylex/tree/main/packages/rollup-plugin)
181
- - [vite-plugin-stylex](https://github.com/HorusGoul/vite-plugin-stylex)
240
+ - [vite-plugin-stylex](https://github.com/HorusGoul/vite-plugin-stylex)
package/dist/astro.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkO4FQWPVVcjs = require('./chunk-O4FQWPVV.cjs');
3
+ var _chunkWDYGV6FUcjs = require('./chunk-WDYGV6FU.cjs');
4
4
 
5
5
 
6
6
 
@@ -9,15 +9,15 @@ var _chunkO4FQWPVVcjs = require('./chunk-O4FQWPVV.cjs');
9
9
 
10
10
 
11
11
 
12
- var _chunkKKH6K7REcjs = require('./chunk-KKH6K7RE.cjs');
12
+ var _chunk45JWH4GZcjs = require('./chunk-45JWH4GZ.cjs');
13
13
  require('./chunk-ZBPRDZS4.cjs');
14
14
 
15
15
  // src/astro.ts
16
16
  function astro(options = {}) {
17
- const configured = _chunkKKH6K7REcjs.getOptions.call(void 0, { ...options, framework: "vite" });
18
- const filename = configured.stylex.filename;
17
+ const configured = _chunk45JWH4GZcjs.getOptions.call(void 0, { ...options, framework: "vite" });
18
+ const filename = _nullishCoalesce(configured.stylex.filename, () => ( "stylex.css"));
19
19
  return {
20
- name: _chunkKKH6K7REcjs.PLUGIN_NAME,
20
+ name: _chunk45JWH4GZcjs.PLUGIN_NAME,
21
21
  hooks: {
22
22
  "astro:config:setup": async ({ config, updateConfig, injectScript }) => {
23
23
  var _a, _b;
@@ -25,19 +25,19 @@ function astro(options = {}) {
25
25
  ...options,
26
26
  validExts: _nullishCoalesce(options.validExts, () => ( /\.[mc]?[jt]sx?$|\.astro$|\.stylex$/))
27
27
  };
28
- if (!_chunkKKH6K7REcjs.stylexRulesStore.has(_chunkKKH6K7REcjs.STORE_KEY)) {
29
- _chunkKKH6K7REcjs.stylexRulesStore.set(_chunkKKH6K7REcjs.STORE_KEY, {});
28
+ if (!_chunk45JWH4GZcjs.stylexRulesStore.has(_chunk45JWH4GZcjs.STORE_KEY)) {
29
+ _chunk45JWH4GZcjs.stylexRulesStore.set(_chunk45JWH4GZcjs.STORE_KEY, {});
30
30
  }
31
31
  config.vite.plugins ??= [];
32
- const basePlugin = _chunkO4FQWPVVcjs.vite_default.call(void 0, astroOptions);
32
+ const basePlugin = _chunkWDYGV6FUcjs.vite_default.call(void 0, astroOptions);
33
33
  const wrappedPlugin = {
34
34
  ...basePlugin,
35
- getStylexRules: () => _chunkKKH6K7REcjs.stylexRulesStore.get(_chunkKKH6K7REcjs.STORE_KEY) || {}
35
+ getStylexRules: () => _chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY) || {}
36
36
  };
37
37
  const base = _nullishCoalesce(config.base, () => ( "/"));
38
38
  const assetsDir = typeof ((_a = config.build) == null ? void 0 : _a.assets) === "string" ? config.build.assets : "_astro";
39
- const fileName = _chunkKKH6K7REcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
40
- const cssPath = _chunkKKH6K7REcjs.getStylexPublicPath.call(void 0, base, fileName);
39
+ const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
40
+ const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, base, fileName);
41
41
  injectScript(
42
42
  "head-inline",
43
43
  `
@@ -67,12 +67,12 @@ function astro(options = {}) {
67
67
  server.middlewares.use((req, res, next) => {
68
68
  var _a, _b;
69
69
  const assetsDir = "_astro";
70
- const fileName = _chunkKKH6K7REcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
71
- const cssPath = _chunkKKH6K7REcjs.getStylexPublicPath.call(void 0, "/", fileName);
70
+ const fileName = _chunk45JWH4GZcjs.getStylexAssetFileName.call(void 0, filename, assetsDir);
71
+ const cssPath = _chunk45JWH4GZcjs.getStylexPublicPath.call(void 0, "/", fileName);
72
72
  const normalizedUrl = (_a = req.url) == null ? void 0 : _a.split("?")[0];
73
73
  if (normalizedUrl === cssPath || normalizedUrl === `/${filename}` || (normalizedUrl == null ? void 0 : normalizedUrl.endsWith(`/${filename}`)) || normalizedUrl === filename) {
74
- const stylexRules = _nullishCoalesce(_chunkKKH6K7REcjs.stylexRulesStore.get(_chunkKKH6K7REcjs.STORE_KEY), () => ( {}));
75
- const collectedCSS = _chunkKKH6K7REcjs.buildStylexRules.call(void 0, stylexRules, _nullishCoalesce(((_b = options.stylex) == null ? void 0 : _b.useCSSLayers), () => ( false)));
74
+ const stylexRules = _nullishCoalesce(_chunk45JWH4GZcjs.stylexRulesStore.get(_chunk45JWH4GZcjs.STORE_KEY), () => ( {}));
75
+ const collectedCSS = _chunk45JWH4GZcjs.buildStylexRules.call(void 0, stylexRules, _nullishCoalesce(((_b = options.stylex) == null ? void 0 : _b.useCSSLayers), () => ( false)));
76
76
  res.setHeader("Content-Type", "text/css");
77
77
  res.setHeader("Cache-Control", "no-cache");
78
78
  res.end(_nullishCoalesce(collectedCSS, () => ( "")));
package/dist/astro.d.ts CHANGED
@@ -1,13 +1,41 @@
1
- import { UnpluginStylexOptions } from './types.js';
2
- import '@babel/core';
3
- import '@stylexjs/babel-plugin';
4
-
5
1
  /**
6
2
  * This entry file is for astro plugin.
7
3
  *
8
4
  * @module
9
5
  */
10
-
6
+ import type { IncomingMessage, ServerResponse } from 'node:http';
7
+ import type { UnpluginStylexOptions } from './types';
8
+ type AstroConfigSetupContext = {
9
+ config: {
10
+ base?: string;
11
+ build?: {
12
+ assets?: string;
13
+ };
14
+ vite: {
15
+ plugins?: unknown[];
16
+ ssr?: {
17
+ noExternal?: unknown;
18
+ };
19
+ };
20
+ };
21
+ updateConfig: (config: {
22
+ vite: {
23
+ ssr: {
24
+ noExternal: string[];
25
+ };
26
+ };
27
+ }) => void;
28
+ injectScript: (stage: string, content: string) => void;
29
+ };
30
+ type AstroServerSetupContext = {
31
+ server: {
32
+ middlewares: {
33
+ use: (handler: (req: IncomingMessage & {
34
+ url?: string;
35
+ }, res: ServerResponse, next: () => void) => void) => void;
36
+ };
37
+ };
38
+ };
11
39
  /**
12
40
  * Astro plugin
13
41
  *
@@ -22,18 +50,12 @@ import '@stylexjs/babel-plugin';
22
50
  * ],
23
51
  * })
24
52
  */
25
- declare function astro(options?: UnpluginStylexOptions): {
53
+ export default function astro(options?: UnpluginStylexOptions): {
26
54
  name: string;
27
55
  hooks: {
28
- 'astro:config:setup': ({ config, updateConfig, injectScript }: {
29
- config: any;
30
- updateConfig: any;
31
- injectScript: any;
32
- }) => Promise<void>;
33
- 'astro:server:setup': ({ server }: {
34
- server: any;
35
- }) => void;
56
+ 'astro:config:setup': ({ config, updateConfig, injectScript }: AstroConfigSetupContext) => Promise<void>;
57
+ 'astro:server:setup': ({ server }: AstroServerSetupContext) => void;
36
58
  };
37
59
  };
38
-
39
- export { astro as default };
60
+ export {};
61
+ //# sourceMappingURL=astro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../src/astro.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAGhE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAIpD,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,KAAK,CAAC,EAAE;YACN,MAAM,CAAC,EAAE,MAAM,CAAA;SAChB,CAAA;QACD,IAAI,EAAE;YACJ,OAAO,CAAC,EAAE,OAAO,EAAE,CAAA;YACnB,GAAG,CAAC,EAAE;gBACJ,UAAU,CAAC,EAAE,OAAO,CAAA;aACrB,CAAA;SACF,CAAA;KACF,CAAA;IACD,YAAY,EAAE,CAAC,MAAM,EAAE;QACrB,IAAI,EAAE;YACJ,GAAG,EAAE;gBACH,UAAU,EAAE,MAAM,EAAE,CAAA;aACrB,CAAA;SACF,CAAA;KACF,KAAK,IAAI,CAAA;IACV,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CACvD,CAAA;AAED,KAAK,uBAAuB,GAAG;IAC7B,MAAM,EAAE;QACN,WAAW,EAAE;YACX,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,eAAe,GAAG;gBAAE,GAAG,CAAC,EAAE,MAAM,CAAA;aAAE,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,KAAK,IAAI,CAAA;SACjH,CAAA;KACF,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;GAaG;AAEH,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,OAAO,GAAE,qBAA0B;;;uEAQU,uBAAuB;2CAyDzD,uBAAuB;;EA2B/D"}
package/dist/astro.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  vite_default
3
- } from "./chunk-WUKLRLI4.js";
3
+ } from "./chunk-5RGNKABP.js";
4
4
  import {
5
5
  PLUGIN_NAME,
6
6
  STORE_KEY,
@@ -9,13 +9,13 @@ import {
9
9
  getStylexAssetFileName,
10
10
  getStylexPublicPath,
11
11
  stylexRulesStore
12
- } from "./chunk-FEGNQ7CQ.js";
12
+ } from "./chunk-SSMUIUHR.js";
13
13
  import "./chunk-6F4PWJZI.js";
14
14
 
15
15
  // src/astro.ts
16
16
  function astro(options = {}) {
17
17
  const configured = getOptions({ ...options, framework: "vite" });
18
- const filename = configured.stylex.filename;
18
+ const filename = configured.stylex.filename ?? "stylex.css";
19
19
  return {
20
20
  name: PLUGIN_NAME,
21
21
  hooks: {
@@ -429,10 +429,13 @@ var transformers = {
429
429
  // src/index.ts
430
430
  var unpluginFactory = (rawOptions, meta) => {
431
431
  const options = getOptions({ ...rawOptions || {}, framework: meta.framework });
432
+ const stylexFilename = _nullishCoalesce(options.stylex.filename, () => ( "stylex.css"));
433
+ const stylexImports = _nullishCoalesce(options.stylex.stylexImports, () => ( ["@stylexjs/stylex"]));
434
+ const useCSSLayers = _nullishCoalesce(options.stylex.useCSSLayers, () => ( false));
432
435
  if (!stylexRulesStore.has(STORE_KEY)) {
433
436
  stylexRulesStore.set(STORE_KEY, {});
434
437
  }
435
- const stylexRules = stylexRulesStore.get(STORE_KEY);
438
+ const stylexRules = _nullishCoalesce(stylexRulesStore.get(STORE_KEY), () => ( {}));
436
439
  let viteConfig = null;
437
440
  return {
438
441
  name: PLUGIN_NAME,
@@ -449,7 +452,7 @@ var unpluginFactory = (rawOptions, meta) => {
449
452
  const normalizedFile = normalizePath(file);
450
453
  const normalizedId = normalizePath(id);
451
454
  const extname2 = path3.extname(file).slice(1);
452
- if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
455
+ if (!stylexImports.some((importName) => code.includes(importName))) {
453
456
  return;
454
457
  }
455
458
  const context = {
@@ -468,12 +471,12 @@ var unpluginFactory = (rawOptions, meta) => {
468
471
  return result;
469
472
  } catch (error) {
470
473
  console.error("transform::error::", error);
471
- this.error(error);
474
+ this.error(error instanceof Error ? error.message : String(error));
472
475
  }
473
476
  },
474
477
  buildEnd() {
475
- const fileName = options.stylex.filename;
476
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
478
+ const fileName = stylexFilename;
479
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
477
480
  if (!collectedCSS) return;
478
481
  this.emitFile({
479
482
  fileName,
@@ -495,14 +498,14 @@ var unpluginFactory = (rawOptions, meta) => {
495
498
  next();
496
499
  return;
497
500
  }
498
- const fileName = getStylexAssetFileName(options.stylex.filename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
501
+ const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
499
502
  const cssPath = getStylexPublicPath(viteConfig == null ? void 0 : viteConfig.base, fileName);
500
503
  const basePath = (_nullishCoalesce((viteConfig == null ? void 0 : viteConfig.base), () => ( "/"))).replace(/\/+$/, "") || "/";
501
- const filename = options.stylex.filename;
504
+ const filename = stylexFilename;
502
505
  const normalizedUrl = req.url.split("?")[0];
503
506
  const isCSSRequest = normalizedUrl === cssPath || normalizedUrl === `${basePath}/${filename}` || normalizedUrl === `/${filename}` || normalizedUrl.endsWith(`/${filename}`) || normalizedUrl === filename;
504
507
  if (isCSSRequest) {
505
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
508
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
506
509
  res.setHeader("Content-Type", "text/css");
507
510
  res.setHeader("Cache-Control", "no-cache");
508
511
  res.end(collectedCSS || "");
@@ -513,8 +516,8 @@ var unpluginFactory = (rawOptions, meta) => {
513
516
  },
514
517
  buildEnd() {
515
518
  var _a;
516
- const fileName = getStylexAssetFileName(options.stylex.filename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
517
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
519
+ const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
520
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
518
521
  if (!collectedCSS) return;
519
522
  this.emitFile({
520
523
  fileName,
@@ -524,7 +527,7 @@ var unpluginFactory = (rawOptions, meta) => {
524
527
  },
525
528
  transformIndexHtml(html, ctx) {
526
529
  var _a, _b;
527
- const fileName = getStylexAssetFileName(options.stylex.filename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
530
+ const fileName = getStylexAssetFileName(stylexFilename, _nullishCoalesce(((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir), () => ( "assets")));
528
531
  const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
529
532
  if (!css) {
530
533
  return html;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  unpluginFactory
3
- } from "./chunk-FEGNQ7CQ.js";
3
+ } from "./chunk-SSMUIUHR.js";
4
4
 
5
5
  // src/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
@@ -429,10 +429,13 @@ var transformers = {
429
429
  // src/index.ts
430
430
  var unpluginFactory = (rawOptions, meta) => {
431
431
  const options = getOptions({ ...rawOptions || {}, framework: meta.framework });
432
+ const stylexFilename = options.stylex.filename ?? "stylex.css";
433
+ const stylexImports = options.stylex.stylexImports ?? ["@stylexjs/stylex"];
434
+ const useCSSLayers = options.stylex.useCSSLayers ?? false;
432
435
  if (!stylexRulesStore.has(STORE_KEY)) {
433
436
  stylexRulesStore.set(STORE_KEY, {});
434
437
  }
435
- const stylexRules = stylexRulesStore.get(STORE_KEY);
438
+ const stylexRules = stylexRulesStore.get(STORE_KEY) ?? {};
436
439
  let viteConfig = null;
437
440
  return {
438
441
  name: PLUGIN_NAME,
@@ -449,7 +452,7 @@ var unpluginFactory = (rawOptions, meta) => {
449
452
  const normalizedFile = normalizePath(file);
450
453
  const normalizedId = normalizePath(id);
451
454
  const extname2 = path3.extname(file).slice(1);
452
- if (!options.stylex.stylexImports.some((importName) => code.includes(importName))) {
455
+ if (!stylexImports.some((importName) => code.includes(importName))) {
453
456
  return;
454
457
  }
455
458
  const context = {
@@ -468,12 +471,12 @@ var unpluginFactory = (rawOptions, meta) => {
468
471
  return result;
469
472
  } catch (error) {
470
473
  console.error("transform::error::", error);
471
- this.error(error);
474
+ this.error(error instanceof Error ? error.message : String(error));
472
475
  }
473
476
  },
474
477
  buildEnd() {
475
- const fileName = options.stylex.filename;
476
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
478
+ const fileName = stylexFilename;
479
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
477
480
  if (!collectedCSS) return;
478
481
  this.emitFile({
479
482
  fileName,
@@ -495,14 +498,14 @@ var unpluginFactory = (rawOptions, meta) => {
495
498
  next();
496
499
  return;
497
500
  }
498
- const fileName = getStylexAssetFileName(options.stylex.filename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
501
+ const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
499
502
  const cssPath = getStylexPublicPath(viteConfig == null ? void 0 : viteConfig.base, fileName);
500
503
  const basePath = ((viteConfig == null ? void 0 : viteConfig.base) ?? "/").replace(/\/+$/, "") || "/";
501
- const filename = options.stylex.filename;
504
+ const filename = stylexFilename;
502
505
  const normalizedUrl = req.url.split("?")[0];
503
506
  const isCSSRequest = normalizedUrl === cssPath || normalizedUrl === `${basePath}/${filename}` || normalizedUrl === `/${filename}` || normalizedUrl.endsWith(`/${filename}`) || normalizedUrl === filename;
504
507
  if (isCSSRequest) {
505
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
508
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
506
509
  res.setHeader("Content-Type", "text/css");
507
510
  res.setHeader("Cache-Control", "no-cache");
508
511
  res.end(collectedCSS || "");
@@ -513,8 +516,8 @@ var unpluginFactory = (rawOptions, meta) => {
513
516
  },
514
517
  buildEnd() {
515
518
  var _a;
516
- const fileName = getStylexAssetFileName(options.stylex.filename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
517
- const collectedCSS = buildStylexRules(stylexRules, options.stylex.useCSSLayers);
519
+ const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
520
+ const collectedCSS = buildStylexRules(stylexRules, useCSSLayers);
518
521
  if (!collectedCSS) return;
519
522
  this.emitFile({
520
523
  fileName,
@@ -524,7 +527,7 @@ var unpluginFactory = (rawOptions, meta) => {
524
527
  },
525
528
  transformIndexHtml(html, ctx) {
526
529
  var _a, _b;
527
- const fileName = getStylexAssetFileName(options.stylex.filename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
530
+ const fileName = getStylexAssetFileName(stylexFilename, ((_a = viteConfig == null ? void 0 : viteConfig.build) == null ? void 0 : _a.assetsDir) ?? "assets");
528
531
  const css = (_b = ctx.bundle) == null ? void 0 : _b[fileName];
529
532
  if (!css) {
530
533
  return html;