@wyw-in-js/vite 1.0.9 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/types/index.js CHANGED
@@ -1,44 +1,49 @@
1
- "use strict";
2
1
  /**
3
2
  * This file contains a Vite loader for wyw-in-js.
4
3
  * It uses the transform.ts function to generate class names from source code,
5
4
  * returns transformed code without template literals and attaches generated source maps
6
5
  */
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.default = wywInJS;
12
- const fs_1 = require("fs");
13
- const path_1 = __importDefault(require("path"));
14
- const vite_1 = require("vite");
15
- const shared_1 = require("@wyw-in-js/shared");
16
- const transform_1 = require("@wyw-in-js/transform");
6
+ import { existsSync } from 'fs';
7
+ import path from 'path';
8
+ import { createFilter, loadEnv } from 'vite';
9
+ import { asyncResolverFactory, logger, syncResolve } from '@wyw-in-js/shared';
10
+ import * as transformPkg from '@wyw-in-js/transform';
11
+ const { createTransformManifest, createFileReporter, disposeEvalBroker, getFileIdx, stringifyTransformManifest, transform, TransformCacheCollection, } = transformPkg;
12
+ const createMetadataManifest = (metadata, context) => typeof createTransformManifest === 'function'
13
+ ? createTransformManifest(metadata, context)
14
+ : {
15
+ ...metadata,
16
+ ...context,
17
+ version: 1,
18
+ };
19
+ const stringifyMetadataManifest = (manifest) => typeof stringifyTransformManifest === 'function'
20
+ ? stringifyTransformManifest(manifest)
21
+ : `${JSON.stringify(manifest, null, 2)}\n`;
17
22
  const isWindowsAbsolutePath = (value) => /^[a-zA-Z]:[\\/]/.test(value);
18
- const normalizeToPosix = (value) => value.replace(/\\/g, path_1.default.posix.sep);
23
+ const normalizeToPosix = (value) => value.replace(/\\/g, path.posix.sep);
19
24
  const isInside = (childPath, parentPath) => {
20
- const rel = path_1.default.relative(parentPath, childPath);
21
- return rel === '' || (!rel.startsWith('..') && !path_1.default.isAbsolute(rel));
25
+ const rel = path.relative(parentPath, childPath);
26
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
22
27
  };
23
28
  const isWywCssAssetName = (value) => value.endsWith('.wyw-in-js.css');
24
29
  const normalizeAssetRelativePath = (value) => {
25
- const normalized = path_1.default.posix.normalize(normalizeToPosix(value).replace(/^\/+/, ''));
26
- if (normalized.startsWith('..') || path_1.default.posix.isAbsolute(normalized)) {
30
+ const normalized = path.posix.normalize(normalizeToPosix(value).replace(/^\/+/, ''));
31
+ if (normalized.startsWith('..') || path.posix.isAbsolute(normalized)) {
27
32
  return null;
28
33
  }
29
34
  return normalized;
30
35
  };
31
36
  const stripExtension = (value) => {
32
- const ext = path_1.default.posix.extname(value);
37
+ const ext = path.posix.extname(value);
33
38
  return ext ? value.slice(0, -ext.length) : value;
34
39
  };
35
40
  const getComparableAssetPaths = (value, rootDir) => {
36
41
  const variants = new Set();
37
42
  const normalized = normalizeToPosix(value);
38
43
  variants.add(normalized);
39
- if (path_1.default.isAbsolute(value) || isWindowsAbsolutePath(normalized)) {
44
+ if (path.isAbsolute(value) || isWindowsAbsolutePath(normalized)) {
40
45
  if (isInside(value, rootDir)) {
41
- const relativeToRoot = normalizeAssetRelativePath(path_1.default.relative(rootDir, value));
46
+ const relativeToRoot = normalizeAssetRelativePath(path.relative(rootDir, value));
42
47
  if (relativeToRoot) {
43
48
  variants.add(relativeToRoot);
44
49
  }
@@ -100,8 +105,8 @@ const findWywCssAssetFileName = (bundle, cssFilename, rootDir) => {
100
105
  return null;
101
106
  };
102
107
  const getRelativeImportPath = (fromFileName, toFileName) => {
103
- const fromDir = path_1.default.posix.dirname(normalizeToPosix(fromFileName));
104
- const relativePath = path_1.default.posix.relative(fromDir, normalizeToPosix(toFileName));
108
+ const fromDir = path.posix.dirname(normalizeToPosix(fromFileName));
109
+ const relativePath = path.posix.relative(fromDir, normalizeToPosix(toFileName));
105
110
  return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
106
111
  };
107
112
  const escapeForRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -144,7 +149,7 @@ const safeDecodeURIComponent = (value) => {
144
149
  };
145
150
  const normalizeViteFsPath = (value) => {
146
151
  const fsPath = value.slice(VITE_FS_PREFIX.length);
147
- return path_1.default.normalize(safeDecodeURIComponent(fsPath));
152
+ return path.normalize(safeDecodeURIComponent(fsPath));
148
153
  };
149
154
  const isCssReloadTarget = (value) => {
150
155
  if (!value || typeof value !== 'object')
@@ -173,12 +178,12 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
173
178
  const preserveModulesRootValue = output.preserveModulesRoot;
174
179
  let preserveModulesRootAbs = null;
175
180
  if (typeof preserveModulesRootValue === 'string') {
176
- preserveModulesRootAbs = path_1.default.isAbsolute(preserveModulesRootValue)
181
+ preserveModulesRootAbs = path.isAbsolute(preserveModulesRootValue)
177
182
  ? preserveModulesRootValue
178
- : path_1.default.resolve(rootDir, preserveModulesRootValue);
183
+ : path.resolve(rootDir, preserveModulesRootValue);
179
184
  }
180
185
  const preserveModulesRootRel = preserveModulesRootAbs && isInside(preserveModulesRootAbs, rootDir)
181
- ? normalizeToPosix(path_1.default.relative(rootDir, preserveModulesRootAbs))
186
+ ? normalizeToPosix(path.relative(rootDir, preserveModulesRootAbs))
182
187
  : null;
183
188
  return (assetInfo) => {
184
189
  const template = typeof originalAssetFileNames === 'function'
@@ -193,18 +198,18 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
193
198
  }
194
199
  let relativePath = null;
195
200
  const assetNameNormalized = normalizeToPosix(assetName);
196
- if (path_1.default.isAbsolute(assetName) ||
201
+ if (path.isAbsolute(assetName) ||
197
202
  isWindowsAbsolutePath(assetNameNormalized)) {
198
203
  const preserveRel = preserveModulesRootAbs && isInside(assetName, preserveModulesRootAbs)
199
- ? path_1.default.relative(preserveModulesRootAbs, assetName)
204
+ ? path.relative(preserveModulesRootAbs, assetName)
200
205
  : null;
201
206
  if (preserveRel &&
202
- !path_1.default.isAbsolute(preserveRel) &&
207
+ !path.isAbsolute(preserveRel) &&
203
208
  !preserveRel.startsWith('..')) {
204
209
  relativePath = preserveRel;
205
210
  }
206
211
  else if (isInside(assetName, rootDir)) {
207
- relativePath = path_1.default.relative(rootDir, assetName);
212
+ relativePath = path.relative(rootDir, assetName);
208
213
  }
209
214
  }
210
215
  else if (preserveModulesRootRel &&
@@ -222,13 +227,13 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
222
227
  }
223
228
  const withoutExt = stripExtension(normalized);
224
229
  if (template.includes('[name]')) {
225
- const dir = path_1.default.posix.dirname(withoutExt);
230
+ const dir = path.posix.dirname(withoutExt);
226
231
  if (dir === '.' || dir === '') {
227
232
  return template;
228
233
  }
229
234
  return template.replace(/\[name\]/g, `${dir}/[name]`);
230
235
  }
231
- const dir = path_1.default.posix.dirname(withoutExt);
236
+ const dir = path.posix.dirname(withoutExt);
232
237
  if (dir === '.' || dir === '') {
233
238
  return template;
234
239
  }
@@ -243,16 +248,38 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
243
248
  return `${prefix}${dir}/${template.slice(idx)}`;
244
249
  };
245
250
  };
246
- function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepComments, prefixer, preprocessor, ssrDevCss, ssrDevCssPath, transformLibraries, ...rest } = {}) {
247
- const filter = (0, vite_1.createFilter)(include, exclude);
251
+ export default function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepComments, prefixer, preprocessor, ssrDevCss, ssrDevCssPath, transformLibraries, ...rest } = {}) {
252
+ const supportedModuleExtensions = new Set([
253
+ '.cjs',
254
+ '.cts',
255
+ '.js',
256
+ '.jsx',
257
+ '.mjs',
258
+ '.mts',
259
+ '.ts',
260
+ '.tsx',
261
+ ]);
262
+ const filter = createFilter(include, exclude);
248
263
  const cssLookup = {};
249
264
  const cssFileLookup = {};
265
+ const metadataLookup = {};
250
266
  const cssFilesByModuleId = new Map();
251
267
  const pendingCssReloads = new WeakMap();
252
268
  let ssrDevCssVersion = 0;
253
269
  let config;
254
270
  let devServer;
255
271
  let importMetaEnvForEval = null;
272
+ const buildOverrideContext = (getEnv) => (context, filename) => {
273
+ const env = getEnv();
274
+ const withEnv = env
275
+ ? { ...context, __wyw_import_meta_env: env }
276
+ : context;
277
+ return rest.overrideContext
278
+ ? rest.overrideContext(withEnv, filename)
279
+ : withEnv;
280
+ };
281
+ const overrideContextClient = buildOverrideContext(() => importMetaEnvForEval?.client);
282
+ const overrideContextSsr = buildOverrideContext(() => importMetaEnvForEval?.ssr);
256
283
  const ssrDevCssEnabled = Boolean(ssrDevCss);
257
284
  const [ssrDevCssPathname, ssrDevCssQuery] = (ssrDevCssPath ?? '/_wyw-in-js/ssr.css').split('?', 2);
258
285
  const ssrDevCssRoute = ssrDevCssPathname.startsWith('/')
@@ -275,7 +302,35 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
275
302
  .join('\n');
276
303
  return `${merged}\n`;
277
304
  };
278
- const { emitter, onDone } = (0, transform_1.createFileReporter)(debug ?? false);
305
+ const { emitter, onDone } = createFileReporter(debug ?? false);
306
+ const isSafeAssetPath = (fileName) => fileName !== '' &&
307
+ fileName !== '..' &&
308
+ !fileName.startsWith(`..${path.posix.sep}`) &&
309
+ !path.posix.isAbsolute(fileName) &&
310
+ !isWindowsAbsolutePath(fileName);
311
+ const replaceModuleExtension = (filename, nextExtension) => {
312
+ const extension = path.extname(filename);
313
+ return supportedModuleExtensions.has(extension)
314
+ ? `${filename.slice(0, -extension.length)}${nextExtension}`
315
+ : `${filename}${nextExtension}`;
316
+ };
317
+ const toBundleRelativePath = (filename) => {
318
+ const relativePath = normalizeToPosix(path.relative(config.root, filename));
319
+ if (isSafeAssetPath(relativePath)) {
320
+ return relativePath;
321
+ }
322
+ if (!path.isAbsolute(relativePath) &&
323
+ !isWindowsAbsolutePath(relativePath)) {
324
+ return path.posix.join('_wyw-in-js', 'external', ...relativePath
325
+ .split(path.posix.sep)
326
+ .filter(Boolean)
327
+ .map((segment) => (segment === '..' ? '__up__' : segment)));
328
+ }
329
+ return path.posix.join('_wyw-in-js', 'external', ...normalizeToPosix(path.resolve(filename))
330
+ .split(path.posix.sep)
331
+ .filter(Boolean)
332
+ .map((segment) => segment.replace(/:$/, '')));
333
+ };
279
334
  const scheduleCssReload = (reloadTarget, cssFilename) => {
280
335
  let state = pendingCssReloads.get(reloadTarget);
281
336
  if (!state) {
@@ -299,18 +354,27 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
299
354
  };
300
355
  // <dependency id, targets>
301
356
  const targets = [];
302
- const clientCache = new transform_1.TransformCacheCollection();
303
- const ssrCache = new transform_1.TransformCacheCollection();
357
+ const clientCache = new TransformCacheCollection();
358
+ const ssrCache = new TransformCacheCollection();
304
359
  const caches = new Set([clientCache, ssrCache]);
360
+ let evalBrokersDisposed = false;
361
+ const disposeEvalBrokers = () => {
362
+ if (evalBrokersDisposed)
363
+ return;
364
+ evalBrokersDisposed = true;
365
+ for (const cache of caches) {
366
+ disposeEvalBroker(cache);
367
+ }
368
+ };
305
369
  const getCache = (isSsr) => isSsr ? ssrCache : clientCache;
306
370
  const isInsideCacheDir = (filename) => {
307
371
  if (!config.cacheDir) {
308
372
  return false;
309
373
  }
310
- const relative = path_1.default.relative(config.cacheDir, filename);
374
+ const relative = path.relative(config.cacheDir, filename);
311
375
  return (relative !== '' &&
312
376
  !relative.startsWith('..') &&
313
- !path_1.default.isAbsolute(relative));
377
+ !path.isAbsolute(relative));
314
378
  };
315
379
  const getDepsOptimizer = () => {
316
380
  if (!devServer)
@@ -347,8 +411,8 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
347
411
  }
348
412
  return viteResolver(what, importer, false, true);
349
413
  };
350
- const createAsyncResolver = (0, shared_1.asyncResolverFactory)(async (resolved, what, importer, stack) => {
351
- const log = shared_1.logger.extend('vite').extend((0, transform_1.getFileIdx)(importer));
414
+ const createAsyncResolver = asyncResolverFactory(async (resolved, what, importer, stack) => {
415
+ const log = logger.extend('vite').extend(getFileIdx(importer));
352
416
  if (resolved) {
353
417
  log("resolve ✅ '%s'@'%s -> %O\n%s", what, importer, resolved);
354
418
  // Vite adds param like `?v=667939b3` to cached modules
@@ -364,7 +428,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
364
428
  if (resolvedId.startsWith('/@')) {
365
429
  return null;
366
430
  }
367
- if (!(0, fs_1.existsSync)(resolvedId)) {
431
+ if (!existsSync(resolvedId)) {
368
432
  // When Vite resolves to an optimized deps entry (cacheDir) it may not be written yet.
369
433
  // Wait for Vite's optimizer instead of calling optimizeDeps() manually (deprecated in Vite 7).
370
434
  try {
@@ -376,19 +440,19 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
376
440
  // Vite can return an optimized deps entry (from cacheDir) before it's written to disk.
377
441
  // Manually calling optimizeDeps is deprecated in Vite 7 and can also get called many times.
378
442
  // Instead, fall back to resolving the original module path directly.
379
- if (!(0, fs_1.existsSync)(resolvedId) && isInsideCacheDir(resolvedId)) {
443
+ if (!existsSync(resolvedId) && isInsideCacheDir(resolvedId)) {
380
444
  try {
381
- return (0, shared_1.syncResolve)(what, importer, stack);
445
+ return syncResolve(what, importer, stack);
382
446
  }
383
447
  catch {
384
448
  // Fall through to preserve previous behavior: return resolvedId and let WyW surface the error.
385
449
  }
386
450
  }
387
451
  }
388
- if (!(0, fs_1.existsSync)(resolvedId) && !path_1.default.isAbsolute(resolvedId)) {
452
+ if (!existsSync(resolvedId) && !path.isAbsolute(resolvedId)) {
389
453
  // Vite can resolve an import to a bare specifier when bundling for SSR and marking it as external.
390
454
  // In that case we still need a real file path for WyW evaluation.
391
- return (0, shared_1.syncResolve)(what, importer, stack);
455
+ return syncResolve(what, importer, stack);
392
456
  }
393
457
  return resolvedId;
394
458
  }
@@ -399,19 +463,30 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
399
463
  }
400
464
  if (!what.startsWith('.') &&
401
465
  !what.startsWith('/') &&
402
- !path_1.default.isAbsolute(what)) {
466
+ !path.isAbsolute(what)) {
403
467
  // Keep compatibility with SSR externalization: fall back to Node resolution for bare specifiers.
404
- return (0, shared_1.syncResolve)(what, importer, stack);
468
+ return syncResolve(what, importer, stack);
405
469
  }
406
470
  throw new Error(`Could not resolve ${what}`);
407
- }, (what, importer) => [what, importer]);
471
+ }, (what, importer) => [
472
+ what,
473
+ importer,
474
+ ]);
408
475
  const asyncResolveClient = createAsyncResolver(resolveClient);
409
476
  const asyncResolveSsr = createAsyncResolver(resolveSsr);
410
477
  return {
411
478
  name: 'wyw-in-js',
412
479
  enforce: 'post',
480
+ buildStart() {
481
+ Object.keys(metadataLookup).forEach((key) => {
482
+ delete metadataLookup[key];
483
+ });
484
+ },
413
485
  buildEnd() {
414
486
  onDone(process.cwd());
487
+ if (config.command === 'build') {
488
+ disposeEvalBrokers();
489
+ }
415
490
  },
416
491
  configResolved(resolvedConfig) {
417
492
  config = resolvedConfig;
@@ -444,7 +519,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
444
519
  'envDir' in config && typeof config.envDir === 'string'
445
520
  ? config.envDir
446
521
  : config.root;
447
- const loaded = (0, vite_1.loadEnv)(config.mode, envDir, envPrefix);
522
+ const loaded = loadEnv(config.mode, envDir, envPrefix);
448
523
  const base = {
449
524
  ...loaded,
450
525
  BASE_URL: config.base,
@@ -459,32 +534,33 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
459
534
  },
460
535
  configureServer(_server) {
461
536
  devServer = _server;
462
- if (!ssrDevCssEnabled || config.command !== 'serve')
463
- return;
464
- devServer.middlewares.use((req, res, next) => {
465
- const { url } = req;
466
- if (!url) {
467
- next();
468
- return;
469
- }
470
- const [pathname] = url.split('?', 1);
471
- if (pathname !== ssrDevCssRoute) {
472
- next();
473
- return;
474
- }
475
- const etag = `W/"${ssrDevCssVersion}"`;
476
- const ifNoneMatch = req.headers['if-none-match'];
477
- if (ifNoneMatch === etag) {
478
- res.statusCode = 304;
479
- res.end();
480
- return;
481
- }
482
- res.statusCode = 200;
483
- res.setHeader('Content-Type', 'text/css; charset=utf-8');
484
- res.setHeader('Cache-Control', 'no-cache');
485
- res.setHeader('ETag', etag);
486
- res.end(getSsrDevCssContents());
487
- });
537
+ devServer.httpServer?.once('close', disposeEvalBrokers);
538
+ if (ssrDevCssEnabled && config.command === 'serve') {
539
+ devServer.middlewares.use((req, res, next) => {
540
+ const { url } = req;
541
+ if (!url) {
542
+ next();
543
+ return;
544
+ }
545
+ const [pathname] = url.split('?', 1);
546
+ if (pathname !== ssrDevCssRoute) {
547
+ next();
548
+ return;
549
+ }
550
+ const etag = `W/"${ssrDevCssVersion}"`;
551
+ const ifNoneMatch = req.headers['if-none-match'];
552
+ if (ifNoneMatch === etag) {
553
+ res.statusCode = 304;
554
+ res.end();
555
+ return;
556
+ }
557
+ res.statusCode = 200;
558
+ res.setHeader('Content-Type', 'text/css; charset=utf-8');
559
+ res.setHeader('Cache-Control', 'no-cache');
560
+ res.setHeader('ETag', etag);
561
+ res.end(getSsrDevCssContents());
562
+ });
563
+ }
488
564
  },
489
565
  transformIndexHtml(html) {
490
566
  if (!ssrDevCssEnabled || config.command !== 'serve')
@@ -534,6 +610,13 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
534
610
  .filter((m) => !!m);
535
611
  },
536
612
  generateBundle(outputOptions, bundle) {
613
+ Object.entries(metadataLookup).forEach(([fileName, source]) => {
614
+ this.emitFile({
615
+ fileName,
616
+ source,
617
+ type: 'asset',
618
+ });
619
+ });
537
620
  if (config.command !== 'build')
538
621
  return;
539
622
  if (!outputOptions.preserveModules)
@@ -571,20 +654,14 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
571
654
  !filter(url) ||
572
655
  id in cssLookup)
573
656
  return;
574
- const log = shared_1.logger.extend('vite').extend((0, transform_1.getFileIdx)(id));
657
+ const log = logger.extend('vite').extend(getFileIdx(id));
575
658
  log('transform %s', id);
576
659
  const isSsr = typeof transformOptions === 'boolean'
577
660
  ? transformOptions
578
661
  : Boolean(transformOptions?.ssr);
579
- const overrideContext = (context, filename) => {
580
- const env = importMetaEnvForEval?.[isSsr ? 'ssr' : 'client'];
581
- const withEnv = env
582
- ? { ...context, __wyw_import_meta_env: env }
583
- : context;
584
- return rest.overrideContext
585
- ? rest.overrideContext(withEnv, filename)
586
- : withEnv;
587
- };
662
+ const overrideContext = isSsr
663
+ ? overrideContextSsr
664
+ : overrideContextClient;
588
665
  const transformServices = {
589
666
  options: {
590
667
  filename: id,
@@ -602,7 +679,34 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
602
679
  eventEmitter: emitter,
603
680
  };
604
681
  const asyncResolve = isSsr ? asyncResolveSsr : asyncResolveClient;
605
- const result = await (0, transform_1.transform)(transformServices, code, asyncResolve);
682
+ const result = await transform(transformServices, code, asyncResolve);
683
+ result.diagnostics?.forEach((diagnostic) => {
684
+ this.warn({
685
+ id: diagnostic.filename,
686
+ loc: diagnostic.start
687
+ ? {
688
+ column: diagnostic.start.column,
689
+ file: diagnostic.filename,
690
+ line: diagnostic.start.line,
691
+ }
692
+ : undefined,
693
+ message: `[wyw-in-js] ${diagnostic.severity} [${diagnostic.category}] ${diagnostic.message}`,
694
+ pluginCode: diagnostic.category,
695
+ });
696
+ });
697
+ const relativeId = normalizeToPosix(path.relative(config.root, id));
698
+ const metadataFilename = replaceModuleExtension(id, '.wyw-in-js.json');
699
+ const metadataRelativePath = toBundleRelativePath(metadataFilename);
700
+ delete metadataLookup[metadataRelativePath];
701
+ if (result.metadata) {
702
+ const cssFile = typeof result.cssText === 'string' && result.cssText !== ''
703
+ ? replaceModuleExtension(relativeId, '.wyw-in-js.css')
704
+ : undefined;
705
+ metadataLookup[metadataRelativePath] = stringifyMetadataManifest(createMetadataManifest(result.metadata, {
706
+ cssFile,
707
+ source: relativeId,
708
+ }));
709
+ }
606
710
  let { cssText, dependencies } = result;
607
711
  // Heads up, there are three cases:
608
712
  // 1. cssText is undefined, it means that file was not transformed
@@ -621,13 +725,9 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
621
725
  };
622
726
  }
623
727
  dependencies ??= [];
624
- const cssFilename = path_1.default
625
- .normalize(`${id.replace(/\.[jt]sx?$/, '')}.wyw-in-js.css`)
626
- .replace(/\\/g, path_1.default.posix.sep);
728
+ const cssFilename = normalizeToPosix(replaceModuleExtension(id, '.wyw-in-js.css'));
627
729
  cssFilesByModuleId.set(id, cssFilename);
628
- const cssRelativePath = path_1.default
629
- .relative(config.root, cssFilename)
630
- .replace(/\\/g, path_1.default.posix.sep);
730
+ const cssRelativePath = normalizeToPosix(path.relative(config.root, cssFilename));
631
731
  const cssId = `/${cssRelativePath}`;
632
732
  if (sourceMap && result.cssSourceMapText) {
633
733
  const map = Buffer.from(result.cssSourceMapText).toString('base64');