@stylexswc/unplugin 0.17.0-rc.2 → 0.17.0-rc.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.
- package/README.md +47 -0
- package/dist/astro.cjs +2 -2
- package/dist/astro.js +1 -1
- package/dist/{chunk-I43XNUJV.cjs → chunk-6KFXJPTK.cjs} +2 -2
- package/dist/{chunk-NUYT2WWJ.cjs → chunk-FIIRNHWY.cjs} +2 -2
- package/dist/{chunk-VXGDBTUT.cjs → chunk-FYEXHH45.cjs} +123 -47
- package/dist/{chunk-JDL3R5RP.js → chunk-JXPUCXE6.js} +123 -47
- package/dist/{chunk-AHGTDBFS.js → chunk-QS5OGKES.js} +1 -1
- package/dist/{chunk-JCKQLIX6.js → chunk-VFU3MJQV.js} +1 -1
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.js +1 -1
- package/dist/farm.cjs +2 -2
- package/dist/farm.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/nuxt.cjs +5 -5
- package/dist/nuxt.js +3 -3
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +1 -1
- package/dist/types.d.cts +24 -1
- package/dist/types.d.ts +24 -1
- package/dist/vite.cjs +3 -3
- package/dist/vite.js +2 -2
- package/dist/webpack.cjs +3 -3
- package/dist/webpack.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -203,6 +203,53 @@ build({
|
|
|
203
203
|
- Default: `['js', 'jsx', 'ts', 'tsx', 'mjs', 'mts']`
|
|
204
204
|
- Description: File extensions to process for StyleX transformations.
|
|
205
205
|
|
|
206
|
+
#### `transformCss`
|
|
207
|
+
|
|
208
|
+
- Type: `CSSTransformer`
|
|
209
|
+
- Optional
|
|
210
|
+
- Description: Transforms the extracted StyleX CSS before it is emitted or
|
|
211
|
+
injected. Matches the `@stylexswc/webpack-plugin` API. Use it to run the
|
|
212
|
+
generated CSS through PostCSS, LightningCSS, a minifier, or any custom
|
|
213
|
+
post-processing step.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
type CSSTransformer = (
|
|
217
|
+
css: string,
|
|
218
|
+
filePath: string | undefined
|
|
219
|
+
) => string | Buffer | Promise<string | Buffer>;
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import postcss from 'postcss';
|
|
224
|
+
import autoprefixer from 'autoprefixer';
|
|
225
|
+
|
|
226
|
+
StylexRsPlugin({
|
|
227
|
+
async transformCss(css) {
|
|
228
|
+
const result = await postcss([autoprefixer]).process(css, {
|
|
229
|
+
from: undefined,
|
|
230
|
+
});
|
|
231
|
+
return result.css;
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The `filePath` argument identifies the CSS destination and is
|
|
237
|
+
bundler-specific:
|
|
238
|
+
|
|
239
|
+
- webpack/rspack/rollup injection: the output asset name (e.g. `app.css`)
|
|
240
|
+
- esbuild disk writes: the absolute path of the written file
|
|
241
|
+
- Vite placeholder replacement: the id of the CSS module being loaded
|
|
242
|
+
- generated assets: the configured `fileName`, with `[hash]` left unresolved
|
|
243
|
+
(the hash is computed from the transformed CSS, so it cannot be known
|
|
244
|
+
earlier)
|
|
245
|
+
- `undefined` when no destination is known
|
|
246
|
+
|
|
247
|
+
> [!NOTE]
|
|
248
|
+
> `Buffer` results are decoded as UTF-8. Results are memoized per `filePath`
|
|
249
|
+
> while the input CSS is unchanged, so the callback must be a pure function of
|
|
250
|
+
> its arguments — the same input may be served from cache instead of invoking
|
|
251
|
+
> the callback again.
|
|
252
|
+
|
|
206
253
|
#### `useCssPlaceholder`
|
|
207
254
|
|
|
208
255
|
- Type: `boolean | string`
|
package/dist/astro.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/astro.ts
|
|
@@ -10,7 +10,7 @@ var astro_default = (options) => ({
|
|
|
10
10
|
"astro:config:setup": async (astro) => {
|
|
11
11
|
var _a;
|
|
12
12
|
(_a = astro.config.vite).plugins || (_a.plugins = []);
|
|
13
|
-
astro.config.vite.plugins.push(
|
|
13
|
+
astro.config.vite.plugins.push(_chunkFYEXHH45cjs.index_default.vite(options));
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
});
|
package/dist/astro.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
|
|
5
5
|
// src/webpack.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var webpack_default = _unplugin.createWebpackPlugin.call(void 0,
|
|
7
|
+
var webpack_default = _unplugin.createWebpackPlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
|
|
5
5
|
// src/vite.ts
|
|
6
6
|
var _unplugin = require('unplugin');
|
|
7
|
-
var vite_default = _unplugin.createVitePlugin.call(void 0,
|
|
7
|
+
var vite_default = _unplugin.createVitePlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -34,8 +34,9 @@ function getStyleXRules(stylexRules, transformedOptions) {
|
|
|
34
34
|
// src/utils/normalizeOptions.ts
|
|
35
35
|
var _rscompiler = require('@stylexswc/rs-compiler');
|
|
36
36
|
var DEFAULT_CSS_PLACEHOLDER = "@stylex;";
|
|
37
|
+
var identityTransformCss = (css) => css;
|
|
37
38
|
function normalizeOptions(options) {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
+
var _a, _b, _c, _d;
|
|
39
40
|
let useCssPlaceholder = false;
|
|
40
41
|
if (options.useCssPlaceholder === true) {
|
|
41
42
|
useCssPlaceholder = DEFAULT_CSS_PLACEHOLDER;
|
|
@@ -52,6 +53,7 @@ function normalizeOptions(options) {
|
|
|
52
53
|
pageExtensions: (_b = options.pageExtensions) != null ? _b : ["tsx", "jsx", "js", "ts"],
|
|
53
54
|
rsOptions: normalizedRsOptions,
|
|
54
55
|
extractCSS: (_c = options.extractCSS) != null ? _c : true,
|
|
56
|
+
transformCss: (_d = options.transformCss) != null ? _d : identityTransformCss,
|
|
55
57
|
useCssPlaceholder,
|
|
56
58
|
enableLTRRTLComments: normalizedRsOptions.enableLTRRTLComments,
|
|
57
59
|
legacyDisableLayers: normalizedRsOptions.legacyDisableLayers
|
|
@@ -124,7 +126,7 @@ async function invalidateAndCollectCssModules(server, placeholder) {
|
|
|
124
126
|
);
|
|
125
127
|
return cssModules;
|
|
126
128
|
}
|
|
127
|
-
function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, updateAsset, emitAsset, createRawSource) {
|
|
129
|
+
async function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, normalizedOptions, updateAsset, emitAsset, createRawSource) {
|
|
128
130
|
const cssAssets = Object.keys(assets).filter((f) => f.endsWith(".css"));
|
|
129
131
|
let injected = false;
|
|
130
132
|
for (const fileName of cssAssets) {
|
|
@@ -132,7 +134,8 @@ function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, u
|
|
|
132
134
|
if (!asset) continue;
|
|
133
135
|
const source = asset.source().toString();
|
|
134
136
|
if (source.includes(injectMarker)) {
|
|
135
|
-
const
|
|
137
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fileName, normalizedOptions);
|
|
138
|
+
const newSource = source.replace(injectMarker, () => finalCSS);
|
|
136
139
|
updateAsset(fileName, createRawSource(newSource));
|
|
137
140
|
injected = true;
|
|
138
141
|
break;
|
|
@@ -144,14 +147,16 @@ function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, u
|
|
|
144
147
|
const asset = assets[targetAsset];
|
|
145
148
|
if (asset) {
|
|
146
149
|
const existing = asset.source().toString();
|
|
147
|
-
const
|
|
150
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, targetAsset, normalizedOptions);
|
|
151
|
+
const newSource = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
148
152
|
updateAsset(targetAsset, createRawSource(newSource));
|
|
149
153
|
injected = true;
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
if (!injected) {
|
|
154
|
-
|
|
158
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fallbackFileName, normalizedOptions);
|
|
159
|
+
emitAsset(fallbackFileName, createRawSource(finalCSS));
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
var unpluginFactory = (options = {}) => {
|
|
@@ -247,7 +252,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
247
252
|
this.error(new Error(enhancedMessage, { cause: error }));
|
|
248
253
|
}
|
|
249
254
|
},
|
|
250
|
-
buildEnd() {
|
|
255
|
+
async buildEnd() {
|
|
251
256
|
var _a;
|
|
252
257
|
const framework = (_a = this.getNativeBuildContext) == null ? void 0 : _a.call(this).framework;
|
|
253
258
|
if (framework === "esbuild") {
|
|
@@ -256,7 +261,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
256
261
|
if (normalizedOptions.useCssPlaceholder) {
|
|
257
262
|
return;
|
|
258
263
|
}
|
|
259
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
264
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
260
265
|
stylexRules,
|
|
261
266
|
normalizedOptions,
|
|
262
267
|
transformedOptions
|
|
@@ -299,11 +304,11 @@ var unpluginFactory = (options = {}) => {
|
|
|
299
304
|
if (!(collectedCSS == null ? void 0 : collectedCSS.trim())) {
|
|
300
305
|
replacementCSS = isDevMode ? "/* StyleX styles will load after transformation */" : "/* No StyleX styles */";
|
|
301
306
|
} else {
|
|
302
|
-
replacementCSS = collectedCSS;
|
|
307
|
+
replacementCSS = await transformStyleXCSS(collectedCSS, id, normalizedOptions);
|
|
303
308
|
}
|
|
304
|
-
return cssContent.replace(normalizedOptions.useCssPlaceholder, replacementCSS);
|
|
309
|
+
return cssContent.replace(normalizedOptions.useCssPlaceholder, () => replacementCSS);
|
|
305
310
|
},
|
|
306
|
-
generateBundle(_options, bundle) {
|
|
311
|
+
async generateBundle(_options, bundle) {
|
|
307
312
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
308
313
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
309
314
|
if (!collectedCSS) return;
|
|
@@ -318,7 +323,12 @@ var unpluginFactory = (options = {}) => {
|
|
|
318
323
|
if (output.type !== "asset") continue;
|
|
319
324
|
const source = output.source.toString();
|
|
320
325
|
if (normalizedOptions.useCssPlaceholder && source.includes(normalizedOptions.useCssPlaceholder)) {
|
|
321
|
-
|
|
326
|
+
const finalCSS = await transformStyleXCSS(
|
|
327
|
+
collectedCSS,
|
|
328
|
+
output.fileName,
|
|
329
|
+
normalizedOptions
|
|
330
|
+
);
|
|
331
|
+
output.source = source.replace(normalizedOptions.useCssPlaceholder, () => finalCSS);
|
|
322
332
|
injected = true;
|
|
323
333
|
break;
|
|
324
334
|
}
|
|
@@ -328,19 +338,29 @@ var unpluginFactory = (options = {}) => {
|
|
|
328
338
|
const target = cssAssets.find((a) => a.fileName === targetName);
|
|
329
339
|
if (target && target.output.type === "asset") {
|
|
330
340
|
const existing = target.output.source.toString();
|
|
331
|
-
|
|
341
|
+
const finalCSS = await transformStyleXCSS(
|
|
342
|
+
collectedCSS,
|
|
343
|
+
target.fileName,
|
|
344
|
+
normalizedOptions
|
|
345
|
+
);
|
|
346
|
+
target.output.source = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
332
347
|
injected = true;
|
|
333
348
|
}
|
|
334
349
|
}
|
|
335
350
|
if (!injected) {
|
|
351
|
+
const finalCSS = await transformStyleXCSS(
|
|
352
|
+
collectedCSS,
|
|
353
|
+
normalizedOptions.fileName,
|
|
354
|
+
normalizedOptions
|
|
355
|
+
);
|
|
336
356
|
this.emitFile({
|
|
337
357
|
type: "asset",
|
|
338
358
|
fileName: normalizedOptions.fileName,
|
|
339
|
-
source:
|
|
359
|
+
source: finalCSS
|
|
340
360
|
});
|
|
341
361
|
}
|
|
342
362
|
},
|
|
343
|
-
buildEnd() {
|
|
363
|
+
async buildEnd() {
|
|
344
364
|
var _a, _b;
|
|
345
365
|
if (normalizedOptions.useCssPlaceholder) {
|
|
346
366
|
return;
|
|
@@ -349,7 +369,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
349
369
|
if (isDev) {
|
|
350
370
|
return;
|
|
351
371
|
}
|
|
352
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
372
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
353
373
|
stylexRules,
|
|
354
374
|
normalizedOptions,
|
|
355
375
|
transformedOptions,
|
|
@@ -370,13 +390,17 @@ var unpluginFactory = (options = {}) => {
|
|
|
370
390
|
server.middlewares.use(
|
|
371
391
|
(req, res, next) => {
|
|
372
392
|
var _a;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
res.end(collectedCSS);
|
|
393
|
+
const requestedCssFileName = cssFileName;
|
|
394
|
+
if (!requestedCssFileName || !((_a = req.url) == null ? void 0 : _a.includes(requestedCssFileName))) {
|
|
395
|
+
next();
|
|
377
396
|
return;
|
|
378
397
|
}
|
|
379
|
-
|
|
398
|
+
void (async () => {
|
|
399
|
+
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
400
|
+
const finalCSS = collectedCSS ? await transformStyleXCSS(collectedCSS, requestedCssFileName, normalizedOptions) : collectedCSS;
|
|
401
|
+
res.setHeader("Content-Type", "text/css");
|
|
402
|
+
res.end(finalCSS);
|
|
403
|
+
})().catch(next);
|
|
380
404
|
}
|
|
381
405
|
);
|
|
382
406
|
},
|
|
@@ -402,7 +426,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
402
426
|
return;
|
|
403
427
|
}
|
|
404
428
|
transformStyleXCode(file, inputCode, normalizedOptions, stylexRules, id);
|
|
405
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
429
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
406
430
|
stylexRules,
|
|
407
431
|
normalizedOptions,
|
|
408
432
|
transformedOptions,
|
|
@@ -434,13 +458,13 @@ var unpluginFactory = (options = {}) => {
|
|
|
434
458
|
}
|
|
435
459
|
}
|
|
436
460
|
},
|
|
437
|
-
transformIndexHtml: (html, ctx) => {
|
|
461
|
+
transformIndexHtml: async (html, ctx) => {
|
|
438
462
|
var _a, _b;
|
|
439
463
|
if (normalizedOptions.useCssPlaceholder) {
|
|
440
464
|
return html;
|
|
441
465
|
}
|
|
442
466
|
const isDev = !!ctx.server;
|
|
443
|
-
const { processedFileName } = generateCSSAssets(
|
|
467
|
+
const { processedFileName } = await generateCSSAssets(
|
|
444
468
|
stylexRules,
|
|
445
469
|
normalizedOptions,
|
|
446
470
|
transformedOptions,
|
|
@@ -494,7 +518,12 @@ var unpluginFactory = (options = {}) => {
|
|
|
494
518
|
const { readFile } = await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises")));
|
|
495
519
|
const content = await readFile(cssFile, "utf8");
|
|
496
520
|
if (content.includes(injectMarker)) {
|
|
497
|
-
const
|
|
521
|
+
const finalCSS = await transformStyleXCSS(
|
|
522
|
+
collectedCSS,
|
|
523
|
+
cssFile,
|
|
524
|
+
normalizedOptions
|
|
525
|
+
);
|
|
526
|
+
const newContent = content.replace(injectMarker, () => finalCSS);
|
|
498
527
|
await writeFile(cssFile, newContent, "utf8");
|
|
499
528
|
injected = true;
|
|
500
529
|
break;
|
|
@@ -505,12 +534,17 @@ var unpluginFactory = (options = {}) => {
|
|
|
505
534
|
if (!injected && cssFiles.length > 0) {
|
|
506
535
|
const targetFile = pickCssAsset(cssFiles.map((f) => path.basename(f)));
|
|
507
536
|
if (targetFile) {
|
|
508
|
-
const fullPath = cssFiles.find((f) =>
|
|
537
|
+
const fullPath = cssFiles.find((f) => path.basename(f) === targetFile);
|
|
509
538
|
if (fullPath) {
|
|
510
539
|
try {
|
|
511
540
|
const { readFile } = await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises")));
|
|
512
541
|
const existing = await readFile(fullPath, "utf8");
|
|
513
|
-
const
|
|
542
|
+
const finalCSS = await transformStyleXCSS(
|
|
543
|
+
collectedCSS,
|
|
544
|
+
fullPath,
|
|
545
|
+
normalizedOptions
|
|
546
|
+
);
|
|
547
|
+
const newContent = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
514
548
|
await writeFile(fullPath, newContent, "utf8");
|
|
515
549
|
injected = true;
|
|
516
550
|
} catch (e) {
|
|
@@ -520,26 +554,37 @@ var unpluginFactory = (options = {}) => {
|
|
|
520
554
|
}
|
|
521
555
|
if (!injected) {
|
|
522
556
|
const generatedCSSFileName = path.join(outDir, fileName);
|
|
557
|
+
const finalCSS = await transformStyleXCSS(
|
|
558
|
+
collectedCSS,
|
|
559
|
+
generatedCSSFileName,
|
|
560
|
+
normalizedOptions
|
|
561
|
+
);
|
|
523
562
|
await mkdir(path.dirname(generatedCSSFileName), { recursive: true });
|
|
524
|
-
await writeFile(generatedCSSFileName,
|
|
563
|
+
await writeFile(generatedCSSFileName, finalCSS, "utf8");
|
|
525
564
|
}
|
|
526
565
|
return;
|
|
527
566
|
}
|
|
528
567
|
if (shouldWriteToDisk) {
|
|
529
568
|
const generatedCSSFileName = path.join(process.cwd(), fileName);
|
|
569
|
+
const finalCSS = await transformStyleXCSS(
|
|
570
|
+
collectedCSS,
|
|
571
|
+
generatedCSSFileName,
|
|
572
|
+
normalizedOptions
|
|
573
|
+
);
|
|
530
574
|
await mkdir(path.dirname(generatedCSSFileName), {
|
|
531
575
|
recursive: true
|
|
532
576
|
});
|
|
533
|
-
await writeFile(generatedCSSFileName,
|
|
577
|
+
await writeFile(generatedCSSFileName, finalCSS, "utf8");
|
|
534
578
|
return;
|
|
535
579
|
}
|
|
536
580
|
if (outputFiles !== void 0) {
|
|
581
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fileName, normalizedOptions);
|
|
537
582
|
outputFiles.push({
|
|
538
583
|
path: "<stdout>",
|
|
539
|
-
contents: new TextEncoder().encode(
|
|
540
|
-
hash: generateHash(
|
|
584
|
+
contents: new TextEncoder().encode(finalCSS),
|
|
585
|
+
hash: generateHash(finalCSS),
|
|
541
586
|
get text() {
|
|
542
|
-
return
|
|
587
|
+
return finalCSS;
|
|
543
588
|
}
|
|
544
589
|
});
|
|
545
590
|
}
|
|
@@ -548,16 +593,16 @@ var unpluginFactory = (options = {}) => {
|
|
|
548
593
|
},
|
|
549
594
|
farm: {
|
|
550
595
|
transformHtml: {
|
|
551
|
-
executor(resource) {
|
|
596
|
+
async executor(resource) {
|
|
552
597
|
if (normalizedOptions.useCssPlaceholder) {
|
|
553
|
-
return
|
|
598
|
+
return resource.htmlResource;
|
|
554
599
|
}
|
|
555
|
-
if (!hasCssToExtract) return
|
|
600
|
+
if (!hasCssToExtract) return resource.htmlResource;
|
|
556
601
|
const htmlResource = resource.htmlResource;
|
|
557
602
|
let htmlContent = Buffer.from(htmlResource.bytes).toString("utf-8");
|
|
558
603
|
htmlContent = `${htmlContent}<link rel="stylesheet" href="/${normalizedOptions.fileName}" />`;
|
|
559
604
|
htmlResource.bytes = [...Buffer.from(htmlContent, "utf-8")];
|
|
560
|
-
return
|
|
605
|
+
return resource.htmlResource;
|
|
561
606
|
}
|
|
562
607
|
}
|
|
563
608
|
// Farm uses Rollup-like bundle hooks, so generateBundle handles CSS injection
|
|
@@ -567,19 +612,20 @@ var unpluginFactory = (options = {}) => {
|
|
|
567
612
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
568
613
|
const injectMarker = normalizedOptions.useCssPlaceholder;
|
|
569
614
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
570
|
-
compilation.hooks.processAssets.
|
|
615
|
+
compilation.hooks.processAssets.tapPromise(
|
|
571
616
|
{
|
|
572
617
|
name: PLUGIN_NAME,
|
|
573
618
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
574
619
|
},
|
|
575
|
-
(assets) => {
|
|
620
|
+
async (assets) => {
|
|
576
621
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
577
622
|
if (!collectedCSS) return;
|
|
578
|
-
injectStyleXCss(
|
|
623
|
+
await injectStyleXCss(
|
|
579
624
|
assets,
|
|
580
625
|
injectMarker,
|
|
581
626
|
collectedCSS,
|
|
582
627
|
normalizedOptions.fileName,
|
|
628
|
+
normalizedOptions,
|
|
583
629
|
(fileName, source) => compilation.updateAsset(fileName, source),
|
|
584
630
|
(fileName, source) => compilation.emitAsset(fileName, source),
|
|
585
631
|
(content) => new compiler.webpack.sources.RawSource(content)
|
|
@@ -592,19 +638,20 @@ var unpluginFactory = (options = {}) => {
|
|
|
592
638
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
593
639
|
const injectMarker = normalizedOptions.useCssPlaceholder;
|
|
594
640
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
595
|
-
compilation.hooks.processAssets.
|
|
641
|
+
compilation.hooks.processAssets.tapPromise(
|
|
596
642
|
{
|
|
597
643
|
name: PLUGIN_NAME,
|
|
598
644
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
599
645
|
},
|
|
600
|
-
(assets) => {
|
|
646
|
+
async (assets) => {
|
|
601
647
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
602
648
|
if (!collectedCSS) return;
|
|
603
|
-
injectStyleXCss(
|
|
649
|
+
await injectStyleXCss(
|
|
604
650
|
assets,
|
|
605
651
|
injectMarker,
|
|
606
652
|
collectedCSS,
|
|
607
653
|
normalizedOptions.fileName,
|
|
654
|
+
normalizedOptions,
|
|
608
655
|
(fileName, source) => compilation.updateAsset(fileName, source),
|
|
609
656
|
(fileName, source) => compilation.emitAsset(fileName, source),
|
|
610
657
|
(content) => new compiler.webpack.sources.RawSource(content)
|
|
@@ -618,10 +665,36 @@ var unpluginFactory = (options = {}) => {
|
|
|
618
665
|
function ensureLeadingSlash(filePath) {
|
|
619
666
|
return filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
620
667
|
}
|
|
621
|
-
function generateCSSAssets(stylexRules, normalizedOptions, transformedOptions, assetsDir) {
|
|
668
|
+
async function generateCSSAssets(stylexRules, normalizedOptions, transformedOptions, assetsDir) {
|
|
669
|
+
var _a;
|
|
622
670
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
623
|
-
const
|
|
624
|
-
|
|
671
|
+
const finalCSS = collectedCSS ? await transformStyleXCSS(
|
|
672
|
+
collectedCSS,
|
|
673
|
+
(_a = getCssFilePathTemplate(normalizedOptions, assetsDir)) != null ? _a : void 0,
|
|
674
|
+
normalizedOptions
|
|
675
|
+
) : collectedCSS;
|
|
676
|
+
const processedFileName = getProcessedFileName(normalizedOptions, finalCSS || "", assetsDir);
|
|
677
|
+
return { processedFileName, collectedCSS: finalCSS };
|
|
678
|
+
}
|
|
679
|
+
var transformCssCache = /* @__PURE__ */ new WeakMap();
|
|
680
|
+
async function transformStyleXCSS(css, filePath, normalizedOptions) {
|
|
681
|
+
const { transformCss } = normalizedOptions;
|
|
682
|
+
if (transformCss === identityTransformCss) {
|
|
683
|
+
return css;
|
|
684
|
+
}
|
|
685
|
+
let cache = transformCssCache.get(transformCss);
|
|
686
|
+
if (!cache) {
|
|
687
|
+
cache = /* @__PURE__ */ new Map();
|
|
688
|
+
transformCssCache.set(transformCss, cache);
|
|
689
|
+
}
|
|
690
|
+
const cacheKey = filePath != null ? filePath : "";
|
|
691
|
+
const cached = cache.get(cacheKey);
|
|
692
|
+
if (cached && cached.css === css) {
|
|
693
|
+
return cached.result;
|
|
694
|
+
}
|
|
695
|
+
const result = (await transformCss(css, filePath)).toString();
|
|
696
|
+
cache.set(cacheKey, { css, result });
|
|
697
|
+
return result;
|
|
625
698
|
}
|
|
626
699
|
function hasStyleXCode(normalizedOptions, inputCode) {
|
|
627
700
|
var _a;
|
|
@@ -640,10 +713,13 @@ function transformStyleXCode(file, inputCode, normalizedOptions, stylexRules, id
|
|
|
640
713
|
}
|
|
641
714
|
return result;
|
|
642
715
|
}
|
|
643
|
-
function
|
|
716
|
+
function getCssFilePathTemplate(normalizedOptions, assetsDir) {
|
|
644
717
|
if (!normalizedOptions.fileName) return null;
|
|
645
|
-
|
|
646
|
-
|
|
718
|
+
return assetsDir ? path.posix.join(assetsDir, normalizedOptions.fileName) : normalizedOptions.fileName;
|
|
719
|
+
}
|
|
720
|
+
function getProcessedFileName(normalizedOptions, collectedCSS, assetsDir) {
|
|
721
|
+
const template = getCssFilePathTemplate(normalizedOptions, assetsDir);
|
|
722
|
+
return template ? replaceFileName(template, collectedCSS || "") : null;
|
|
647
723
|
}
|
|
648
724
|
var unplugin = _unplugin.createUnplugin.call(void 0, unpluginFactory);
|
|
649
725
|
var index_default = unplugin;
|
|
@@ -34,8 +34,9 @@ function getStyleXRules(stylexRules, transformedOptions) {
|
|
|
34
34
|
// src/utils/normalizeOptions.ts
|
|
35
35
|
import { normalizeRsOptions } from "@stylexswc/rs-compiler";
|
|
36
36
|
var DEFAULT_CSS_PLACEHOLDER = "@stylex;";
|
|
37
|
+
var identityTransformCss = (css) => css;
|
|
37
38
|
function normalizeOptions(options) {
|
|
38
|
-
var _a, _b, _c;
|
|
39
|
+
var _a, _b, _c, _d;
|
|
39
40
|
let useCssPlaceholder = false;
|
|
40
41
|
if (options.useCssPlaceholder === true) {
|
|
41
42
|
useCssPlaceholder = DEFAULT_CSS_PLACEHOLDER;
|
|
@@ -52,6 +53,7 @@ function normalizeOptions(options) {
|
|
|
52
53
|
pageExtensions: (_b = options.pageExtensions) != null ? _b : ["tsx", "jsx", "js", "ts"],
|
|
53
54
|
rsOptions: normalizedRsOptions,
|
|
54
55
|
extractCSS: (_c = options.extractCSS) != null ? _c : true,
|
|
56
|
+
transformCss: (_d = options.transformCss) != null ? _d : identityTransformCss,
|
|
55
57
|
useCssPlaceholder,
|
|
56
58
|
enableLTRRTLComments: normalizedRsOptions.enableLTRRTLComments,
|
|
57
59
|
legacyDisableLayers: normalizedRsOptions.legacyDisableLayers
|
|
@@ -124,7 +126,7 @@ async function invalidateAndCollectCssModules(server, placeholder) {
|
|
|
124
126
|
);
|
|
125
127
|
return cssModules;
|
|
126
128
|
}
|
|
127
|
-
function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, updateAsset, emitAsset, createRawSource) {
|
|
129
|
+
async function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, normalizedOptions, updateAsset, emitAsset, createRawSource) {
|
|
128
130
|
const cssAssets = Object.keys(assets).filter((f) => f.endsWith(".css"));
|
|
129
131
|
let injected = false;
|
|
130
132
|
for (const fileName of cssAssets) {
|
|
@@ -132,7 +134,8 @@ function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, u
|
|
|
132
134
|
if (!asset) continue;
|
|
133
135
|
const source = asset.source().toString();
|
|
134
136
|
if (source.includes(injectMarker)) {
|
|
135
|
-
const
|
|
137
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fileName, normalizedOptions);
|
|
138
|
+
const newSource = source.replace(injectMarker, () => finalCSS);
|
|
136
139
|
updateAsset(fileName, createRawSource(newSource));
|
|
137
140
|
injected = true;
|
|
138
141
|
break;
|
|
@@ -144,14 +147,16 @@ function injectStyleXCss(assets, injectMarker, collectedCSS, fallbackFileName, u
|
|
|
144
147
|
const asset = assets[targetAsset];
|
|
145
148
|
if (asset) {
|
|
146
149
|
const existing = asset.source().toString();
|
|
147
|
-
const
|
|
150
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, targetAsset, normalizedOptions);
|
|
151
|
+
const newSource = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
148
152
|
updateAsset(targetAsset, createRawSource(newSource));
|
|
149
153
|
injected = true;
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
if (!injected) {
|
|
154
|
-
|
|
158
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fallbackFileName, normalizedOptions);
|
|
159
|
+
emitAsset(fallbackFileName, createRawSource(finalCSS));
|
|
155
160
|
}
|
|
156
161
|
}
|
|
157
162
|
var unpluginFactory = (options = {}) => {
|
|
@@ -247,7 +252,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
247
252
|
this.error(new Error(enhancedMessage, { cause: error }));
|
|
248
253
|
}
|
|
249
254
|
},
|
|
250
|
-
buildEnd() {
|
|
255
|
+
async buildEnd() {
|
|
251
256
|
var _a;
|
|
252
257
|
const framework = (_a = this.getNativeBuildContext) == null ? void 0 : _a.call(this).framework;
|
|
253
258
|
if (framework === "esbuild") {
|
|
@@ -256,7 +261,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
256
261
|
if (normalizedOptions.useCssPlaceholder) {
|
|
257
262
|
return;
|
|
258
263
|
}
|
|
259
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
264
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
260
265
|
stylexRules,
|
|
261
266
|
normalizedOptions,
|
|
262
267
|
transformedOptions
|
|
@@ -299,11 +304,11 @@ var unpluginFactory = (options = {}) => {
|
|
|
299
304
|
if (!(collectedCSS == null ? void 0 : collectedCSS.trim())) {
|
|
300
305
|
replacementCSS = isDevMode ? "/* StyleX styles will load after transformation */" : "/* No StyleX styles */";
|
|
301
306
|
} else {
|
|
302
|
-
replacementCSS = collectedCSS;
|
|
307
|
+
replacementCSS = await transformStyleXCSS(collectedCSS, id, normalizedOptions);
|
|
303
308
|
}
|
|
304
|
-
return cssContent.replace(normalizedOptions.useCssPlaceholder, replacementCSS);
|
|
309
|
+
return cssContent.replace(normalizedOptions.useCssPlaceholder, () => replacementCSS);
|
|
305
310
|
},
|
|
306
|
-
generateBundle(_options, bundle) {
|
|
311
|
+
async generateBundle(_options, bundle) {
|
|
307
312
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
308
313
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
309
314
|
if (!collectedCSS) return;
|
|
@@ -318,7 +323,12 @@ var unpluginFactory = (options = {}) => {
|
|
|
318
323
|
if (output.type !== "asset") continue;
|
|
319
324
|
const source = output.source.toString();
|
|
320
325
|
if (normalizedOptions.useCssPlaceholder && source.includes(normalizedOptions.useCssPlaceholder)) {
|
|
321
|
-
|
|
326
|
+
const finalCSS = await transformStyleXCSS(
|
|
327
|
+
collectedCSS,
|
|
328
|
+
output.fileName,
|
|
329
|
+
normalizedOptions
|
|
330
|
+
);
|
|
331
|
+
output.source = source.replace(normalizedOptions.useCssPlaceholder, () => finalCSS);
|
|
322
332
|
injected = true;
|
|
323
333
|
break;
|
|
324
334
|
}
|
|
@@ -328,19 +338,29 @@ var unpluginFactory = (options = {}) => {
|
|
|
328
338
|
const target = cssAssets.find((a) => a.fileName === targetName);
|
|
329
339
|
if (target && target.output.type === "asset") {
|
|
330
340
|
const existing = target.output.source.toString();
|
|
331
|
-
|
|
341
|
+
const finalCSS = await transformStyleXCSS(
|
|
342
|
+
collectedCSS,
|
|
343
|
+
target.fileName,
|
|
344
|
+
normalizedOptions
|
|
345
|
+
);
|
|
346
|
+
target.output.source = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
332
347
|
injected = true;
|
|
333
348
|
}
|
|
334
349
|
}
|
|
335
350
|
if (!injected) {
|
|
351
|
+
const finalCSS = await transformStyleXCSS(
|
|
352
|
+
collectedCSS,
|
|
353
|
+
normalizedOptions.fileName,
|
|
354
|
+
normalizedOptions
|
|
355
|
+
);
|
|
336
356
|
this.emitFile({
|
|
337
357
|
type: "asset",
|
|
338
358
|
fileName: normalizedOptions.fileName,
|
|
339
|
-
source:
|
|
359
|
+
source: finalCSS
|
|
340
360
|
});
|
|
341
361
|
}
|
|
342
362
|
},
|
|
343
|
-
buildEnd() {
|
|
363
|
+
async buildEnd() {
|
|
344
364
|
var _a, _b;
|
|
345
365
|
if (normalizedOptions.useCssPlaceholder) {
|
|
346
366
|
return;
|
|
@@ -349,7 +369,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
349
369
|
if (isDev) {
|
|
350
370
|
return;
|
|
351
371
|
}
|
|
352
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
372
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
353
373
|
stylexRules,
|
|
354
374
|
normalizedOptions,
|
|
355
375
|
transformedOptions,
|
|
@@ -370,13 +390,17 @@ var unpluginFactory = (options = {}) => {
|
|
|
370
390
|
server.middlewares.use(
|
|
371
391
|
(req, res, next) => {
|
|
372
392
|
var _a;
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
res.end(collectedCSS);
|
|
393
|
+
const requestedCssFileName = cssFileName;
|
|
394
|
+
if (!requestedCssFileName || !((_a = req.url) == null ? void 0 : _a.includes(requestedCssFileName))) {
|
|
395
|
+
next();
|
|
377
396
|
return;
|
|
378
397
|
}
|
|
379
|
-
|
|
398
|
+
void (async () => {
|
|
399
|
+
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
400
|
+
const finalCSS = collectedCSS ? await transformStyleXCSS(collectedCSS, requestedCssFileName, normalizedOptions) : collectedCSS;
|
|
401
|
+
res.setHeader("Content-Type", "text/css");
|
|
402
|
+
res.end(finalCSS);
|
|
403
|
+
})().catch(next);
|
|
380
404
|
}
|
|
381
405
|
);
|
|
382
406
|
},
|
|
@@ -402,7 +426,7 @@ var unpluginFactory = (options = {}) => {
|
|
|
402
426
|
return;
|
|
403
427
|
}
|
|
404
428
|
transformStyleXCode(file, inputCode, normalizedOptions, stylexRules, id);
|
|
405
|
-
const { processedFileName, collectedCSS } = generateCSSAssets(
|
|
429
|
+
const { processedFileName, collectedCSS } = await generateCSSAssets(
|
|
406
430
|
stylexRules,
|
|
407
431
|
normalizedOptions,
|
|
408
432
|
transformedOptions,
|
|
@@ -434,13 +458,13 @@ var unpluginFactory = (options = {}) => {
|
|
|
434
458
|
}
|
|
435
459
|
}
|
|
436
460
|
},
|
|
437
|
-
transformIndexHtml: (html, ctx) => {
|
|
461
|
+
transformIndexHtml: async (html, ctx) => {
|
|
438
462
|
var _a, _b;
|
|
439
463
|
if (normalizedOptions.useCssPlaceholder) {
|
|
440
464
|
return html;
|
|
441
465
|
}
|
|
442
466
|
const isDev = !!ctx.server;
|
|
443
|
-
const { processedFileName } = generateCSSAssets(
|
|
467
|
+
const { processedFileName } = await generateCSSAssets(
|
|
444
468
|
stylexRules,
|
|
445
469
|
normalizedOptions,
|
|
446
470
|
transformedOptions,
|
|
@@ -494,7 +518,12 @@ var unpluginFactory = (options = {}) => {
|
|
|
494
518
|
const { readFile } = await import("fs/promises");
|
|
495
519
|
const content = await readFile(cssFile, "utf8");
|
|
496
520
|
if (content.includes(injectMarker)) {
|
|
497
|
-
const
|
|
521
|
+
const finalCSS = await transformStyleXCSS(
|
|
522
|
+
collectedCSS,
|
|
523
|
+
cssFile,
|
|
524
|
+
normalizedOptions
|
|
525
|
+
);
|
|
526
|
+
const newContent = content.replace(injectMarker, () => finalCSS);
|
|
498
527
|
await writeFile(cssFile, newContent, "utf8");
|
|
499
528
|
injected = true;
|
|
500
529
|
break;
|
|
@@ -505,12 +534,17 @@ var unpluginFactory = (options = {}) => {
|
|
|
505
534
|
if (!injected && cssFiles.length > 0) {
|
|
506
535
|
const targetFile = pickCssAsset(cssFiles.map((f) => path.basename(f)));
|
|
507
536
|
if (targetFile) {
|
|
508
|
-
const fullPath = cssFiles.find((f) =>
|
|
537
|
+
const fullPath = cssFiles.find((f) => path.basename(f) === targetFile);
|
|
509
538
|
if (fullPath) {
|
|
510
539
|
try {
|
|
511
540
|
const { readFile } = await import("fs/promises");
|
|
512
541
|
const existing = await readFile(fullPath, "utf8");
|
|
513
|
-
const
|
|
542
|
+
const finalCSS = await transformStyleXCSS(
|
|
543
|
+
collectedCSS,
|
|
544
|
+
fullPath,
|
|
545
|
+
normalizedOptions
|
|
546
|
+
);
|
|
547
|
+
const newContent = existing ? existing + "\n" + finalCSS : finalCSS;
|
|
514
548
|
await writeFile(fullPath, newContent, "utf8");
|
|
515
549
|
injected = true;
|
|
516
550
|
} catch (e) {
|
|
@@ -520,26 +554,37 @@ var unpluginFactory = (options = {}) => {
|
|
|
520
554
|
}
|
|
521
555
|
if (!injected) {
|
|
522
556
|
const generatedCSSFileName = path.join(outDir, fileName);
|
|
557
|
+
const finalCSS = await transformStyleXCSS(
|
|
558
|
+
collectedCSS,
|
|
559
|
+
generatedCSSFileName,
|
|
560
|
+
normalizedOptions
|
|
561
|
+
);
|
|
523
562
|
await mkdir(path.dirname(generatedCSSFileName), { recursive: true });
|
|
524
|
-
await writeFile(generatedCSSFileName,
|
|
563
|
+
await writeFile(generatedCSSFileName, finalCSS, "utf8");
|
|
525
564
|
}
|
|
526
565
|
return;
|
|
527
566
|
}
|
|
528
567
|
if (shouldWriteToDisk) {
|
|
529
568
|
const generatedCSSFileName = path.join(process.cwd(), fileName);
|
|
569
|
+
const finalCSS = await transformStyleXCSS(
|
|
570
|
+
collectedCSS,
|
|
571
|
+
generatedCSSFileName,
|
|
572
|
+
normalizedOptions
|
|
573
|
+
);
|
|
530
574
|
await mkdir(path.dirname(generatedCSSFileName), {
|
|
531
575
|
recursive: true
|
|
532
576
|
});
|
|
533
|
-
await writeFile(generatedCSSFileName,
|
|
577
|
+
await writeFile(generatedCSSFileName, finalCSS, "utf8");
|
|
534
578
|
return;
|
|
535
579
|
}
|
|
536
580
|
if (outputFiles !== void 0) {
|
|
581
|
+
const finalCSS = await transformStyleXCSS(collectedCSS, fileName, normalizedOptions);
|
|
537
582
|
outputFiles.push({
|
|
538
583
|
path: "<stdout>",
|
|
539
|
-
contents: new TextEncoder().encode(
|
|
540
|
-
hash: generateHash(
|
|
584
|
+
contents: new TextEncoder().encode(finalCSS),
|
|
585
|
+
hash: generateHash(finalCSS),
|
|
541
586
|
get text() {
|
|
542
|
-
return
|
|
587
|
+
return finalCSS;
|
|
543
588
|
}
|
|
544
589
|
});
|
|
545
590
|
}
|
|
@@ -548,16 +593,16 @@ var unpluginFactory = (options = {}) => {
|
|
|
548
593
|
},
|
|
549
594
|
farm: {
|
|
550
595
|
transformHtml: {
|
|
551
|
-
executor(resource) {
|
|
596
|
+
async executor(resource) {
|
|
552
597
|
if (normalizedOptions.useCssPlaceholder) {
|
|
553
|
-
return
|
|
598
|
+
return resource.htmlResource;
|
|
554
599
|
}
|
|
555
|
-
if (!hasCssToExtract) return
|
|
600
|
+
if (!hasCssToExtract) return resource.htmlResource;
|
|
556
601
|
const htmlResource = resource.htmlResource;
|
|
557
602
|
let htmlContent = Buffer.from(htmlResource.bytes).toString("utf-8");
|
|
558
603
|
htmlContent = `${htmlContent}<link rel="stylesheet" href="/${normalizedOptions.fileName}" />`;
|
|
559
604
|
htmlResource.bytes = [...Buffer.from(htmlContent, "utf-8")];
|
|
560
|
-
return
|
|
605
|
+
return resource.htmlResource;
|
|
561
606
|
}
|
|
562
607
|
}
|
|
563
608
|
// Farm uses Rollup-like bundle hooks, so generateBundle handles CSS injection
|
|
@@ -567,19 +612,20 @@ var unpluginFactory = (options = {}) => {
|
|
|
567
612
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
568
613
|
const injectMarker = normalizedOptions.useCssPlaceholder;
|
|
569
614
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
570
|
-
compilation.hooks.processAssets.
|
|
615
|
+
compilation.hooks.processAssets.tapPromise(
|
|
571
616
|
{
|
|
572
617
|
name: PLUGIN_NAME,
|
|
573
618
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
574
619
|
},
|
|
575
|
-
(assets) => {
|
|
620
|
+
async (assets) => {
|
|
576
621
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
577
622
|
if (!collectedCSS) return;
|
|
578
|
-
injectStyleXCss(
|
|
623
|
+
await injectStyleXCss(
|
|
579
624
|
assets,
|
|
580
625
|
injectMarker,
|
|
581
626
|
collectedCSS,
|
|
582
627
|
normalizedOptions.fileName,
|
|
628
|
+
normalizedOptions,
|
|
583
629
|
(fileName, source) => compilation.updateAsset(fileName, source),
|
|
584
630
|
(fileName, source) => compilation.emitAsset(fileName, source),
|
|
585
631
|
(content) => new compiler.webpack.sources.RawSource(content)
|
|
@@ -592,19 +638,20 @@ var unpluginFactory = (options = {}) => {
|
|
|
592
638
|
if (!normalizedOptions.useCssPlaceholder) return;
|
|
593
639
|
const injectMarker = normalizedOptions.useCssPlaceholder;
|
|
594
640
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
595
|
-
compilation.hooks.processAssets.
|
|
641
|
+
compilation.hooks.processAssets.tapPromise(
|
|
596
642
|
{
|
|
597
643
|
name: PLUGIN_NAME,
|
|
598
644
|
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
|
599
645
|
},
|
|
600
|
-
(assets) => {
|
|
646
|
+
async (assets) => {
|
|
601
647
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
602
648
|
if (!collectedCSS) return;
|
|
603
|
-
injectStyleXCss(
|
|
649
|
+
await injectStyleXCss(
|
|
604
650
|
assets,
|
|
605
651
|
injectMarker,
|
|
606
652
|
collectedCSS,
|
|
607
653
|
normalizedOptions.fileName,
|
|
654
|
+
normalizedOptions,
|
|
608
655
|
(fileName, source) => compilation.updateAsset(fileName, source),
|
|
609
656
|
(fileName, source) => compilation.emitAsset(fileName, source),
|
|
610
657
|
(content) => new compiler.webpack.sources.RawSource(content)
|
|
@@ -618,10 +665,36 @@ var unpluginFactory = (options = {}) => {
|
|
|
618
665
|
function ensureLeadingSlash(filePath) {
|
|
619
666
|
return filePath.startsWith("/") ? filePath : `/${filePath}`;
|
|
620
667
|
}
|
|
621
|
-
function generateCSSAssets(stylexRules, normalizedOptions, transformedOptions, assetsDir) {
|
|
668
|
+
async function generateCSSAssets(stylexRules, normalizedOptions, transformedOptions, assetsDir) {
|
|
669
|
+
var _a;
|
|
622
670
|
const collectedCSS = getStyleXRules(stylexRules, transformedOptions);
|
|
623
|
-
const
|
|
624
|
-
|
|
671
|
+
const finalCSS = collectedCSS ? await transformStyleXCSS(
|
|
672
|
+
collectedCSS,
|
|
673
|
+
(_a = getCssFilePathTemplate(normalizedOptions, assetsDir)) != null ? _a : void 0,
|
|
674
|
+
normalizedOptions
|
|
675
|
+
) : collectedCSS;
|
|
676
|
+
const processedFileName = getProcessedFileName(normalizedOptions, finalCSS || "", assetsDir);
|
|
677
|
+
return { processedFileName, collectedCSS: finalCSS };
|
|
678
|
+
}
|
|
679
|
+
var transformCssCache = /* @__PURE__ */ new WeakMap();
|
|
680
|
+
async function transformStyleXCSS(css, filePath, normalizedOptions) {
|
|
681
|
+
const { transformCss } = normalizedOptions;
|
|
682
|
+
if (transformCss === identityTransformCss) {
|
|
683
|
+
return css;
|
|
684
|
+
}
|
|
685
|
+
let cache = transformCssCache.get(transformCss);
|
|
686
|
+
if (!cache) {
|
|
687
|
+
cache = /* @__PURE__ */ new Map();
|
|
688
|
+
transformCssCache.set(transformCss, cache);
|
|
689
|
+
}
|
|
690
|
+
const cacheKey = filePath != null ? filePath : "";
|
|
691
|
+
const cached = cache.get(cacheKey);
|
|
692
|
+
if (cached && cached.css === css) {
|
|
693
|
+
return cached.result;
|
|
694
|
+
}
|
|
695
|
+
const result = (await transformCss(css, filePath)).toString();
|
|
696
|
+
cache.set(cacheKey, { css, result });
|
|
697
|
+
return result;
|
|
625
698
|
}
|
|
626
699
|
function hasStyleXCode(normalizedOptions, inputCode) {
|
|
627
700
|
var _a;
|
|
@@ -640,10 +713,13 @@ function transformStyleXCode(file, inputCode, normalizedOptions, stylexRules, id
|
|
|
640
713
|
}
|
|
641
714
|
return result;
|
|
642
715
|
}
|
|
643
|
-
function
|
|
716
|
+
function getCssFilePathTemplate(normalizedOptions, assetsDir) {
|
|
644
717
|
if (!normalizedOptions.fileName) return null;
|
|
645
|
-
|
|
646
|
-
|
|
718
|
+
return assetsDir ? path.posix.join(assetsDir, normalizedOptions.fileName) : normalizedOptions.fileName;
|
|
719
|
+
}
|
|
720
|
+
function getProcessedFileName(normalizedOptions, collectedCSS, assetsDir) {
|
|
721
|
+
const template = getCssFilePathTemplate(normalizedOptions, assetsDir);
|
|
722
|
+
return template ? replaceFileName(template, collectedCSS || "") : null;
|
|
647
723
|
}
|
|
648
724
|
var unplugin = createUnplugin(unpluginFactory);
|
|
649
725
|
var index_default = unplugin;
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/esbuild.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0,
|
|
8
|
+
var esbuild_default = _unplugin.createEsbuildPlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = esbuild_default;
|
package/dist/esbuild.js
CHANGED
package/dist/farm.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/farm.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var plugin = _unplugin.createFarmPlugin.call(void 0,
|
|
8
|
+
var plugin = _unplugin.createFarmPlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
9
9
|
var farm_default = plugin;
|
|
10
10
|
|
|
11
11
|
|
package/dist/farm.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
6
6
|
require('./chunk-ZBPRDZS4.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.default =
|
|
11
|
+
exports.default = _chunkFYEXHH45cjs.index_default; exports.unplugin = _chunkFYEXHH45cjs.unplugin; exports.unpluginFactory = _chunkFYEXHH45cjs.unpluginFactory;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UnpluginInstance, UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { UnpluginStylexRSOptions } from './types.cjs';
|
|
3
|
+
export { CSSTransformer } from './types.cjs';
|
|
3
4
|
import '@stylexswc/rs-compiler';
|
|
4
5
|
|
|
5
6
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexRSOptions | undefined>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UnpluginInstance, UnpluginFactory } from 'unplugin';
|
|
2
2
|
import { UnpluginStylexRSOptions } from './types.js';
|
|
3
|
+
export { CSSTransformer } from './types.js';
|
|
3
4
|
import '@stylexswc/rs-compiler';
|
|
4
5
|
|
|
5
6
|
declare const unpluginFactory: UnpluginFactory<UnpluginStylexRSOptions | undefined>;
|
package/dist/index.js
CHANGED
package/dist/nuxt.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFIIRNHWYcjs = require('./chunk-FIIRNHWY.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
require('./chunk-
|
|
6
|
+
var _chunk6KFXJPTKcjs = require('./chunk-6KFXJPTK.cjs');
|
|
7
|
+
require('./chunk-FYEXHH45.cjs');
|
|
8
8
|
require('./chunk-ZBPRDZS4.cjs');
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
|
@@ -19,8 +19,8 @@ var nuxt_default = _kit.defineNuxtModule.call(void 0, {
|
|
|
19
19
|
// ...default options
|
|
20
20
|
},
|
|
21
21
|
setup(options, _nuxt) {
|
|
22
|
-
_kit.addVitePlugin.call(void 0, () =>
|
|
23
|
-
_kit.addWebpackPlugin.call(void 0, () =>
|
|
22
|
+
_kit.addVitePlugin.call(void 0, () => _chunkFIIRNHWYcjs.vite_default.call(void 0, options));
|
|
23
|
+
_kit.addWebpackPlugin.call(void 0, () => _chunk6KFXJPTKcjs.webpack_default.call(void 0, options));
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
|
package/dist/nuxt.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
vite_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QS5OGKES.js";
|
|
4
4
|
import {
|
|
5
5
|
webpack_default
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-VFU3MJQV.js";
|
|
7
|
+
import "./chunk-JXPUCXE6.js";
|
|
8
8
|
import "./chunk-6F4PWJZI.js";
|
|
9
9
|
|
|
10
10
|
// src/nuxt.ts
|
package/dist/rollup.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/rollup.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var rollup_default = _unplugin.createRollupPlugin.call(void 0,
|
|
8
|
+
var rollup_default = _unplugin.createRollupPlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = rollup_default;
|
package/dist/rollup.js
CHANGED
package/dist/rspack.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFYEXHH45cjs = require('./chunk-FYEXHH45.cjs');
|
|
4
4
|
require('./chunk-ZBPRDZS4.cjs');
|
|
5
5
|
|
|
6
6
|
// src/rspack.ts
|
|
7
7
|
var _unplugin = require('unplugin');
|
|
8
|
-
var rspack_default = _unplugin.createRspackPlugin.call(void 0,
|
|
8
|
+
var rspack_default = _unplugin.createRspackPlugin.call(void 0, _chunkFYEXHH45cjs.unpluginFactory);
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
exports.default = rspack_default;
|
package/dist/rspack.js
CHANGED
package/dist/types.d.cts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { TransformedOptions, StyleXOptions } from '@stylexswc/rs-compiler';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Transforms extracted StyleX CSS before it is emitted or injected.
|
|
5
|
+
*
|
|
6
|
+
* `filePath` identifies the CSS destination and is bundler-specific:
|
|
7
|
+
* - webpack/rspack/rollup injection: the output asset name (e.g. `app.css`)
|
|
8
|
+
* - esbuild disk writes: the absolute path of the written file
|
|
9
|
+
* - Vite placeholder replacement: the id of the CSS module being loaded
|
|
10
|
+
* - generated assets: the configured `fileName`, with `[hash]` left unresolved
|
|
11
|
+
* (the hash is computed from the transformed CSS, so it cannot be known earlier)
|
|
12
|
+
* - `undefined` when no destination is known
|
|
13
|
+
*
|
|
14
|
+
* Buffer results are decoded as UTF-8. Results are memoized per `filePath`
|
|
15
|
+
* while the input CSS is unchanged, so the callback must be a pure function
|
|
16
|
+
* of its arguments.
|
|
17
|
+
*/
|
|
18
|
+
type CSSTransformer = (css: string, filePath: string | undefined) => string | Buffer | Promise<string | Buffer>;
|
|
3
19
|
interface UnpluginStylexRSOptions {
|
|
4
20
|
fileName?: string;
|
|
5
21
|
useCSSLayers?: TransformedOptions['useLayers'];
|
|
6
22
|
pageExtensions?: string[];
|
|
7
23
|
rsOptions?: StyleXOptions;
|
|
8
24
|
extractCSS?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Transform the extracted StyleX CSS before it is emitted or injected.
|
|
27
|
+
*
|
|
28
|
+
* This matches the webpack plugin API and receives the generated CSS plus the
|
|
29
|
+
* target CSS asset path when one is known.
|
|
30
|
+
*/
|
|
31
|
+
transformCss?: CSSTransformer;
|
|
9
32
|
/**
|
|
10
33
|
* Enable CSS injection into CSS files via placeholder marker.
|
|
11
34
|
*
|
|
@@ -36,4 +59,4 @@ interface UnpluginStylexRSOptions {
|
|
|
36
59
|
useCssPlaceholder?: boolean | string;
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
export type { UnpluginStylexRSOptions };
|
|
62
|
+
export type { CSSTransformer, UnpluginStylexRSOptions };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { TransformedOptions, StyleXOptions } from '@stylexswc/rs-compiler';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Transforms extracted StyleX CSS before it is emitted or injected.
|
|
5
|
+
*
|
|
6
|
+
* `filePath` identifies the CSS destination and is bundler-specific:
|
|
7
|
+
* - webpack/rspack/rollup injection: the output asset name (e.g. `app.css`)
|
|
8
|
+
* - esbuild disk writes: the absolute path of the written file
|
|
9
|
+
* - Vite placeholder replacement: the id of the CSS module being loaded
|
|
10
|
+
* - generated assets: the configured `fileName`, with `[hash]` left unresolved
|
|
11
|
+
* (the hash is computed from the transformed CSS, so it cannot be known earlier)
|
|
12
|
+
* - `undefined` when no destination is known
|
|
13
|
+
*
|
|
14
|
+
* Buffer results are decoded as UTF-8. Results are memoized per `filePath`
|
|
15
|
+
* while the input CSS is unchanged, so the callback must be a pure function
|
|
16
|
+
* of its arguments.
|
|
17
|
+
*/
|
|
18
|
+
type CSSTransformer = (css: string, filePath: string | undefined) => string | Buffer | Promise<string | Buffer>;
|
|
3
19
|
interface UnpluginStylexRSOptions {
|
|
4
20
|
fileName?: string;
|
|
5
21
|
useCSSLayers?: TransformedOptions['useLayers'];
|
|
6
22
|
pageExtensions?: string[];
|
|
7
23
|
rsOptions?: StyleXOptions;
|
|
8
24
|
extractCSS?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Transform the extracted StyleX CSS before it is emitted or injected.
|
|
27
|
+
*
|
|
28
|
+
* This matches the webpack plugin API and receives the generated CSS plus the
|
|
29
|
+
* target CSS asset path when one is known.
|
|
30
|
+
*/
|
|
31
|
+
transformCss?: CSSTransformer;
|
|
9
32
|
/**
|
|
10
33
|
* Enable CSS injection into CSS files via placeholder marker.
|
|
11
34
|
*
|
|
@@ -36,4 +59,4 @@ interface UnpluginStylexRSOptions {
|
|
|
36
59
|
useCssPlaceholder?: boolean | string;
|
|
37
60
|
}
|
|
38
61
|
|
|
39
|
-
export type { UnpluginStylexRSOptions };
|
|
62
|
+
export type { CSSTransformer, UnpluginStylexRSOptions };
|
package/dist/vite.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var _chunkFIIRNHWYcjs = require('./chunk-FIIRNHWY.cjs');
|
|
4
|
+
require('./chunk-FYEXHH45.cjs');
|
|
5
5
|
require('./chunk-ZBPRDZS4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = _chunkFIIRNHWYcjs.vite_default;
|
|
9
9
|
|
|
10
10
|
module.exports = exports.default;
|
package/dist/vite.js
CHANGED
package/dist/webpack.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var _chunk6KFXJPTKcjs = require('./chunk-6KFXJPTK.cjs');
|
|
4
|
+
require('./chunk-FYEXHH45.cjs');
|
|
5
5
|
require('./chunk-ZBPRDZS4.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
exports.default =
|
|
8
|
+
exports.default = _chunk6KFXJPTKcjs.webpack_default;
|
|
9
9
|
|
|
10
10
|
module.exports = exports.default;
|
package/dist/webpack.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stylexswc/unplugin",
|
|
3
3
|
"description": "Unplugin for StyleX RS compiler",
|
|
4
|
-
"version": "0.17.0-rc.
|
|
4
|
+
"version": "0.17.0-rc.3",
|
|
5
5
|
"bugs": "https://github.com/Dwlad90/stylex-swc-plugin/issues",
|
|
6
6
|
"config": {
|
|
7
7
|
"scripty": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@stylexjs/babel-plugin": "^0.19.0",
|
|
13
|
-
"@stylexswc/rs-compiler": "0.17.0-rc.
|
|
13
|
+
"@stylexswc/rs-compiler": "0.17.0-rc.3",
|
|
14
14
|
"unplugin": "^3.0.0",
|
|
15
15
|
"vite": "^8.1.2"
|
|
16
16
|
},
|