@wyw-in-js/vite 1.1.0 → 2.0.0-alpha.1
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 +8 -0
- package/esm/index.mjs +636 -656
- package/esm/index.mjs.map +1 -1
- package/package.json +12 -13
- package/types/index.d.ts +1 -1
- package/types/index.js +112 -127
- package/lib/index.js +0 -695
- package/lib/index.js.map +0 -1
package/types/index.js
CHANGED
|
@@ -1,53 +1,14 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(o, k2, desc);
|
|
14
|
-
}) : (function(o, m, k, k2) {
|
|
15
|
-
if (k2 === undefined) k2 = k;
|
|
16
|
-
o[k2] = m[k];
|
|
17
|
-
}));
|
|
18
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
19
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
20
|
-
}) : function(o, v) {
|
|
21
|
-
o["default"] = v;
|
|
22
|
-
});
|
|
23
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
24
|
-
var ownKeys = function(o) {
|
|
25
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
26
|
-
var ar = [];
|
|
27
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
28
|
-
return ar;
|
|
29
|
-
};
|
|
30
|
-
return ownKeys(o);
|
|
31
|
-
};
|
|
32
|
-
return function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
})();
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.default = wywInJS;
|
|
45
|
-
const fs_1 = require("fs");
|
|
46
|
-
const path_1 = __importDefault(require("path"));
|
|
47
|
-
const vite_1 = require("vite");
|
|
48
|
-
const shared_1 = require("@wyw-in-js/shared");
|
|
49
|
-
const transformPkg = __importStar(require("@wyw-in-js/transform"));
|
|
50
|
-
const { createTransformManifest, createFileReporter, getFileIdx, stringifyTransformManifest, transform, TransformCacheCollection, } = transformPkg;
|
|
6
|
+
import { existsSync } from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { createFilter, loadEnv } from 'vite';
|
|
9
|
+
import { asyncResolverFactory, logger, mergeOxcResolverAlias, syncResolve, toNativeResolverAlias, } from '@wyw-in-js/shared';
|
|
10
|
+
import * as transformPkg from '@wyw-in-js/transform';
|
|
11
|
+
const { createTransformManifest, createFileReporter, disposeEvalBroker, getFileIdx, stringifyTransformManifest, transform, TransformCacheCollection, } = transformPkg;
|
|
51
12
|
const createMetadataManifest = (metadata, context) => typeof createTransformManifest === 'function'
|
|
52
13
|
? createTransformManifest(metadata, context)
|
|
53
14
|
: {
|
|
@@ -59,30 +20,30 @@ const stringifyMetadataManifest = (manifest) => typeof stringifyTransformManifes
|
|
|
59
20
|
? stringifyTransformManifest(manifest)
|
|
60
21
|
: `${JSON.stringify(manifest, null, 2)}\n`;
|
|
61
22
|
const isWindowsAbsolutePath = (value) => /^[a-zA-Z]:[\\/]/.test(value);
|
|
62
|
-
const normalizeToPosix = (value) => value.replace(/\\/g,
|
|
23
|
+
const normalizeToPosix = (value) => value.replace(/\\/g, path.posix.sep);
|
|
63
24
|
const isInside = (childPath, parentPath) => {
|
|
64
|
-
const rel =
|
|
65
|
-
return rel === '' || (!rel.startsWith('..') && !
|
|
25
|
+
const rel = path.relative(parentPath, childPath);
|
|
26
|
+
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
|
|
66
27
|
};
|
|
67
28
|
const isWywCssAssetName = (value) => value.endsWith('.wyw-in-js.css');
|
|
68
29
|
const normalizeAssetRelativePath = (value) => {
|
|
69
|
-
const normalized =
|
|
70
|
-
if (normalized.startsWith('..') ||
|
|
30
|
+
const normalized = path.posix.normalize(normalizeToPosix(value).replace(/^\/+/, ''));
|
|
31
|
+
if (normalized.startsWith('..') || path.posix.isAbsolute(normalized)) {
|
|
71
32
|
return null;
|
|
72
33
|
}
|
|
73
34
|
return normalized;
|
|
74
35
|
};
|
|
75
36
|
const stripExtension = (value) => {
|
|
76
|
-
const ext =
|
|
37
|
+
const ext = path.posix.extname(value);
|
|
77
38
|
return ext ? value.slice(0, -ext.length) : value;
|
|
78
39
|
};
|
|
79
40
|
const getComparableAssetPaths = (value, rootDir) => {
|
|
80
41
|
const variants = new Set();
|
|
81
42
|
const normalized = normalizeToPosix(value);
|
|
82
43
|
variants.add(normalized);
|
|
83
|
-
if (
|
|
44
|
+
if (path.isAbsolute(value) || isWindowsAbsolutePath(normalized)) {
|
|
84
45
|
if (isInside(value, rootDir)) {
|
|
85
|
-
const relativeToRoot = normalizeAssetRelativePath(
|
|
46
|
+
const relativeToRoot = normalizeAssetRelativePath(path.relative(rootDir, value));
|
|
86
47
|
if (relativeToRoot) {
|
|
87
48
|
variants.add(relativeToRoot);
|
|
88
49
|
}
|
|
@@ -144,8 +105,8 @@ const findWywCssAssetFileName = (bundle, cssFilename, rootDir) => {
|
|
|
144
105
|
return null;
|
|
145
106
|
};
|
|
146
107
|
const getRelativeImportPath = (fromFileName, toFileName) => {
|
|
147
|
-
const fromDir =
|
|
148
|
-
const relativePath =
|
|
108
|
+
const fromDir = path.posix.dirname(normalizeToPosix(fromFileName));
|
|
109
|
+
const relativePath = path.posix.relative(fromDir, normalizeToPosix(toFileName));
|
|
149
110
|
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
150
111
|
};
|
|
151
112
|
const escapeForRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -188,7 +149,7 @@ const safeDecodeURIComponent = (value) => {
|
|
|
188
149
|
};
|
|
189
150
|
const normalizeViteFsPath = (value) => {
|
|
190
151
|
const fsPath = value.slice(VITE_FS_PREFIX.length);
|
|
191
|
-
return
|
|
152
|
+
return path.normalize(safeDecodeURIComponent(fsPath));
|
|
192
153
|
};
|
|
193
154
|
const isCssReloadTarget = (value) => {
|
|
194
155
|
if (!value || typeof value !== 'object')
|
|
@@ -217,12 +178,12 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
|
|
|
217
178
|
const preserveModulesRootValue = output.preserveModulesRoot;
|
|
218
179
|
let preserveModulesRootAbs = null;
|
|
219
180
|
if (typeof preserveModulesRootValue === 'string') {
|
|
220
|
-
preserveModulesRootAbs =
|
|
181
|
+
preserveModulesRootAbs = path.isAbsolute(preserveModulesRootValue)
|
|
221
182
|
? preserveModulesRootValue
|
|
222
|
-
:
|
|
183
|
+
: path.resolve(rootDir, preserveModulesRootValue);
|
|
223
184
|
}
|
|
224
185
|
const preserveModulesRootRel = preserveModulesRootAbs && isInside(preserveModulesRootAbs, rootDir)
|
|
225
|
-
? normalizeToPosix(
|
|
186
|
+
? normalizeToPosix(path.relative(rootDir, preserveModulesRootAbs))
|
|
226
187
|
: null;
|
|
227
188
|
return (assetInfo) => {
|
|
228
189
|
const template = typeof originalAssetFileNames === 'function'
|
|
@@ -237,18 +198,18 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
|
|
|
237
198
|
}
|
|
238
199
|
let relativePath = null;
|
|
239
200
|
const assetNameNormalized = normalizeToPosix(assetName);
|
|
240
|
-
if (
|
|
201
|
+
if (path.isAbsolute(assetName) ||
|
|
241
202
|
isWindowsAbsolutePath(assetNameNormalized)) {
|
|
242
203
|
const preserveRel = preserveModulesRootAbs && isInside(assetName, preserveModulesRootAbs)
|
|
243
|
-
?
|
|
204
|
+
? path.relative(preserveModulesRootAbs, assetName)
|
|
244
205
|
: null;
|
|
245
206
|
if (preserveRel &&
|
|
246
|
-
!
|
|
207
|
+
!path.isAbsolute(preserveRel) &&
|
|
247
208
|
!preserveRel.startsWith('..')) {
|
|
248
209
|
relativePath = preserveRel;
|
|
249
210
|
}
|
|
250
211
|
else if (isInside(assetName, rootDir)) {
|
|
251
|
-
relativePath =
|
|
212
|
+
relativePath = path.relative(rootDir, assetName);
|
|
252
213
|
}
|
|
253
214
|
}
|
|
254
215
|
else if (preserveModulesRootRel &&
|
|
@@ -266,13 +227,13 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
|
|
|
266
227
|
}
|
|
267
228
|
const withoutExt = stripExtension(normalized);
|
|
268
229
|
if (template.includes('[name]')) {
|
|
269
|
-
const dir =
|
|
230
|
+
const dir = path.posix.dirname(withoutExt);
|
|
270
231
|
if (dir === '.' || dir === '') {
|
|
271
232
|
return template;
|
|
272
233
|
}
|
|
273
234
|
return template.replace(/\[name\]/g, `${dir}/[name]`);
|
|
274
235
|
}
|
|
275
|
-
const dir =
|
|
236
|
+
const dir = path.posix.dirname(withoutExt);
|
|
276
237
|
if (dir === '.' || dir === '') {
|
|
277
238
|
return template;
|
|
278
239
|
}
|
|
@@ -287,7 +248,7 @@ const getWywCssAssetFileNames = (resolvedConfig, output, originalAssetFileNames)
|
|
|
287
248
|
return `${prefix}${dir}/${template.slice(idx)}`;
|
|
288
249
|
};
|
|
289
250
|
};
|
|
290
|
-
function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepComments, prefixer, preprocessor, ssrDevCss, ssrDevCssPath, transformLibraries, ...rest } = {}) {
|
|
251
|
+
export default function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepComments, prefixer, preprocessor, ssrDevCss, ssrDevCssPath, transformLibraries, ...rest } = {}) {
|
|
291
252
|
const supportedModuleExtensions = new Set([
|
|
292
253
|
'.cjs',
|
|
293
254
|
'.cts',
|
|
@@ -298,7 +259,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
298
259
|
'.ts',
|
|
299
260
|
'.tsx',
|
|
300
261
|
]);
|
|
301
|
-
const filter =
|
|
262
|
+
const filter = createFilter(include, exclude);
|
|
302
263
|
const cssLookup = {};
|
|
303
264
|
const cssFileLookup = {};
|
|
304
265
|
const metadataLookup = {};
|
|
@@ -308,6 +269,18 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
308
269
|
let config;
|
|
309
270
|
let devServer;
|
|
310
271
|
let importMetaEnvForEval = null;
|
|
272
|
+
let nativeResolverAlias = {};
|
|
273
|
+
const buildOverrideContext = (getEnv) => (context, filename) => {
|
|
274
|
+
const env = getEnv();
|
|
275
|
+
const withEnv = env
|
|
276
|
+
? { ...context, __wyw_import_meta_env: env }
|
|
277
|
+
: context;
|
|
278
|
+
return rest.overrideContext
|
|
279
|
+
? rest.overrideContext(withEnv, filename)
|
|
280
|
+
: withEnv;
|
|
281
|
+
};
|
|
282
|
+
const overrideContextClient = buildOverrideContext(() => importMetaEnvForEval?.client);
|
|
283
|
+
const overrideContextSsr = buildOverrideContext(() => importMetaEnvForEval?.ssr);
|
|
311
284
|
const ssrDevCssEnabled = Boolean(ssrDevCss);
|
|
312
285
|
const [ssrDevCssPathname, ssrDevCssQuery] = (ssrDevCssPath ?? '/_wyw-in-js/ssr.css').split('?', 2);
|
|
313
286
|
const ssrDevCssRoute = ssrDevCssPathname.startsWith('/')
|
|
@@ -333,29 +306,29 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
333
306
|
const { emitter, onDone } = createFileReporter(debug ?? false);
|
|
334
307
|
const isSafeAssetPath = (fileName) => fileName !== '' &&
|
|
335
308
|
fileName !== '..' &&
|
|
336
|
-
!fileName.startsWith(`..${
|
|
337
|
-
!
|
|
309
|
+
!fileName.startsWith(`..${path.posix.sep}`) &&
|
|
310
|
+
!path.posix.isAbsolute(fileName) &&
|
|
338
311
|
!isWindowsAbsolutePath(fileName);
|
|
339
312
|
const replaceModuleExtension = (filename, nextExtension) => {
|
|
340
|
-
const extension =
|
|
313
|
+
const extension = path.extname(filename);
|
|
341
314
|
return supportedModuleExtensions.has(extension)
|
|
342
315
|
? `${filename.slice(0, -extension.length)}${nextExtension}`
|
|
343
316
|
: `${filename}${nextExtension}`;
|
|
344
317
|
};
|
|
345
318
|
const toBundleRelativePath = (filename) => {
|
|
346
|
-
const relativePath = normalizeToPosix(
|
|
319
|
+
const relativePath = normalizeToPosix(path.relative(config.root, filename));
|
|
347
320
|
if (isSafeAssetPath(relativePath)) {
|
|
348
321
|
return relativePath;
|
|
349
322
|
}
|
|
350
|
-
if (!
|
|
323
|
+
if (!path.isAbsolute(relativePath) &&
|
|
351
324
|
!isWindowsAbsolutePath(relativePath)) {
|
|
352
|
-
return
|
|
353
|
-
.split(
|
|
325
|
+
return path.posix.join('_wyw-in-js', 'external', ...relativePath
|
|
326
|
+
.split(path.posix.sep)
|
|
354
327
|
.filter(Boolean)
|
|
355
328
|
.map((segment) => (segment === '..' ? '__up__' : segment)));
|
|
356
329
|
}
|
|
357
|
-
return
|
|
358
|
-
.split(
|
|
330
|
+
return path.posix.join('_wyw-in-js', 'external', ...normalizeToPosix(path.resolve(filename))
|
|
331
|
+
.split(path.posix.sep)
|
|
359
332
|
.filter(Boolean)
|
|
360
333
|
.map((segment) => segment.replace(/:$/, '')));
|
|
361
334
|
};
|
|
@@ -385,15 +358,24 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
385
358
|
const clientCache = new TransformCacheCollection();
|
|
386
359
|
const ssrCache = new TransformCacheCollection();
|
|
387
360
|
const caches = new Set([clientCache, ssrCache]);
|
|
361
|
+
let evalBrokersDisposed = false;
|
|
362
|
+
const disposeEvalBrokers = () => {
|
|
363
|
+
if (evalBrokersDisposed)
|
|
364
|
+
return;
|
|
365
|
+
evalBrokersDisposed = true;
|
|
366
|
+
for (const cache of caches) {
|
|
367
|
+
disposeEvalBroker(cache);
|
|
368
|
+
}
|
|
369
|
+
};
|
|
388
370
|
const getCache = (isSsr) => isSsr ? ssrCache : clientCache;
|
|
389
371
|
const isInsideCacheDir = (filename) => {
|
|
390
372
|
if (!config.cacheDir) {
|
|
391
373
|
return false;
|
|
392
374
|
}
|
|
393
|
-
const relative =
|
|
375
|
+
const relative = path.relative(config.cacheDir, filename);
|
|
394
376
|
return (relative !== '' &&
|
|
395
377
|
!relative.startsWith('..') &&
|
|
396
|
-
!
|
|
378
|
+
!path.isAbsolute(relative));
|
|
397
379
|
};
|
|
398
380
|
const getDepsOptimizer = () => {
|
|
399
381
|
if (!devServer)
|
|
@@ -430,8 +412,8 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
430
412
|
}
|
|
431
413
|
return viteResolver(what, importer, false, true);
|
|
432
414
|
};
|
|
433
|
-
const createAsyncResolver =
|
|
434
|
-
const log =
|
|
415
|
+
const createAsyncResolver = asyncResolverFactory(async (resolved, what, importer, stack) => {
|
|
416
|
+
const log = logger.extend('vite').extend(getFileIdx(importer));
|
|
435
417
|
if (resolved) {
|
|
436
418
|
log("resolve ✅ '%s'@'%s -> %O\n%s", what, importer, resolved);
|
|
437
419
|
// Vite adds param like `?v=667939b3` to cached modules
|
|
@@ -447,7 +429,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
447
429
|
if (resolvedId.startsWith('/@')) {
|
|
448
430
|
return null;
|
|
449
431
|
}
|
|
450
|
-
if (!
|
|
432
|
+
if (!existsSync(resolvedId)) {
|
|
451
433
|
// When Vite resolves to an optimized deps entry (cacheDir) it may not be written yet.
|
|
452
434
|
// Wait for Vite's optimizer instead of calling optimizeDeps() manually (deprecated in Vite 7).
|
|
453
435
|
try {
|
|
@@ -459,19 +441,19 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
459
441
|
// Vite can return an optimized deps entry (from cacheDir) before it's written to disk.
|
|
460
442
|
// Manually calling optimizeDeps is deprecated in Vite 7 and can also get called many times.
|
|
461
443
|
// Instead, fall back to resolving the original module path directly.
|
|
462
|
-
if (!
|
|
444
|
+
if (!existsSync(resolvedId) && isInsideCacheDir(resolvedId)) {
|
|
463
445
|
try {
|
|
464
|
-
return
|
|
446
|
+
return syncResolve(what, importer, stack);
|
|
465
447
|
}
|
|
466
448
|
catch {
|
|
467
449
|
// Fall through to preserve previous behavior: return resolvedId and let WyW surface the error.
|
|
468
450
|
}
|
|
469
451
|
}
|
|
470
452
|
}
|
|
471
|
-
if (!
|
|
453
|
+
if (!existsSync(resolvedId) && !path.isAbsolute(resolvedId)) {
|
|
472
454
|
// Vite can resolve an import to a bare specifier when bundling for SSR and marking it as external.
|
|
473
455
|
// In that case we still need a real file path for WyW evaluation.
|
|
474
|
-
return
|
|
456
|
+
return syncResolve(what, importer, stack);
|
|
475
457
|
}
|
|
476
458
|
return resolvedId;
|
|
477
459
|
}
|
|
@@ -482,12 +464,15 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
482
464
|
}
|
|
483
465
|
if (!what.startsWith('.') &&
|
|
484
466
|
!what.startsWith('/') &&
|
|
485
|
-
!
|
|
467
|
+
!path.isAbsolute(what)) {
|
|
486
468
|
// Keep compatibility with SSR externalization: fall back to Node resolution for bare specifiers.
|
|
487
|
-
return
|
|
469
|
+
return syncResolve(what, importer, stack);
|
|
488
470
|
}
|
|
489
471
|
throw new Error(`Could not resolve ${what}`);
|
|
490
|
-
}, (what, importer) => [
|
|
472
|
+
}, (what, importer) => [
|
|
473
|
+
what,
|
|
474
|
+
importer,
|
|
475
|
+
]);
|
|
491
476
|
const asyncResolveClient = createAsyncResolver(resolveClient);
|
|
492
477
|
const asyncResolveSsr = createAsyncResolver(resolveSsr);
|
|
493
478
|
return {
|
|
@@ -500,10 +485,14 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
500
485
|
},
|
|
501
486
|
buildEnd() {
|
|
502
487
|
onDone(process.cwd());
|
|
488
|
+
if (config.command === 'build') {
|
|
489
|
+
disposeEvalBrokers();
|
|
490
|
+
}
|
|
503
491
|
},
|
|
504
492
|
configResolved(resolvedConfig) {
|
|
505
493
|
config = resolvedConfig;
|
|
506
494
|
viteResolver = config.createResolver();
|
|
495
|
+
nativeResolverAlias = toNativeResolverAlias(config.resolve?.alias);
|
|
507
496
|
if (preserveCssPaths && config.command === 'build') {
|
|
508
497
|
const outputs = config.build.rollupOptions.output;
|
|
509
498
|
let outputEntries = [];
|
|
@@ -532,7 +521,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
532
521
|
'envDir' in config && typeof config.envDir === 'string'
|
|
533
522
|
? config.envDir
|
|
534
523
|
: config.root;
|
|
535
|
-
const loaded =
|
|
524
|
+
const loaded = loadEnv(config.mode, envDir, envPrefix);
|
|
536
525
|
const base = {
|
|
537
526
|
...loaded,
|
|
538
527
|
BASE_URL: config.base,
|
|
@@ -547,32 +536,33 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
547
536
|
},
|
|
548
537
|
configureServer(_server) {
|
|
549
538
|
devServer = _server;
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
539
|
+
devServer.httpServer?.once('close', disposeEvalBrokers);
|
|
540
|
+
if (ssrDevCssEnabled && config.command === 'serve') {
|
|
541
|
+
devServer.middlewares.use((req, res, next) => {
|
|
542
|
+
const { url } = req;
|
|
543
|
+
if (!url) {
|
|
544
|
+
next();
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
const [pathname] = url.split('?', 1);
|
|
548
|
+
if (pathname !== ssrDevCssRoute) {
|
|
549
|
+
next();
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const etag = `W/"${ssrDevCssVersion}"`;
|
|
553
|
+
const ifNoneMatch = req.headers['if-none-match'];
|
|
554
|
+
if (ifNoneMatch === etag) {
|
|
555
|
+
res.statusCode = 304;
|
|
556
|
+
res.end();
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
res.statusCode = 200;
|
|
560
|
+
res.setHeader('Content-Type', 'text/css; charset=utf-8');
|
|
561
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
562
|
+
res.setHeader('ETag', etag);
|
|
563
|
+
res.end(getSsrDevCssContents());
|
|
564
|
+
});
|
|
565
|
+
}
|
|
576
566
|
},
|
|
577
567
|
transformIndexHtml(html) {
|
|
578
568
|
if (!ssrDevCssEnabled || config.command !== 'serve')
|
|
@@ -666,20 +656,14 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
666
656
|
!filter(url) ||
|
|
667
657
|
id in cssLookup)
|
|
668
658
|
return;
|
|
669
|
-
const log =
|
|
659
|
+
const log = logger.extend('vite').extend(getFileIdx(id));
|
|
670
660
|
log('transform %s', id);
|
|
671
661
|
const isSsr = typeof transformOptions === 'boolean'
|
|
672
662
|
? transformOptions
|
|
673
663
|
: Boolean(transformOptions?.ssr);
|
|
674
|
-
const overrideContext =
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
? { ...context, __wyw_import_meta_env: env }
|
|
678
|
-
: context;
|
|
679
|
-
return rest.overrideContext
|
|
680
|
-
? rest.overrideContext(withEnv, filename)
|
|
681
|
-
: withEnv;
|
|
682
|
-
};
|
|
664
|
+
const overrideContext = isSsr
|
|
665
|
+
? overrideContextSsr
|
|
666
|
+
: overrideContextClient;
|
|
683
667
|
const transformServices = {
|
|
684
668
|
options: {
|
|
685
669
|
filename: id,
|
|
@@ -689,6 +673,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
689
673
|
preprocessor,
|
|
690
674
|
pluginOptions: {
|
|
691
675
|
...rest,
|
|
676
|
+
oxcOptions: mergeOxcResolverAlias(rest.oxcOptions, nativeResolverAlias),
|
|
692
677
|
overrideContext,
|
|
693
678
|
},
|
|
694
679
|
},
|
|
@@ -712,7 +697,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
712
697
|
pluginCode: diagnostic.category,
|
|
713
698
|
});
|
|
714
699
|
});
|
|
715
|
-
const relativeId = normalizeToPosix(
|
|
700
|
+
const relativeId = normalizeToPosix(path.relative(config.root, id));
|
|
716
701
|
const metadataFilename = replaceModuleExtension(id, '.wyw-in-js.json');
|
|
717
702
|
const metadataRelativePath = toBundleRelativePath(metadataFilename);
|
|
718
703
|
delete metadataLookup[metadataRelativePath];
|
|
@@ -745,7 +730,7 @@ function wywInJS({ debug, include, exclude, sourceMap, preserveCssPaths, keepCom
|
|
|
745
730
|
dependencies ??= [];
|
|
746
731
|
const cssFilename = normalizeToPosix(replaceModuleExtension(id, '.wyw-in-js.css'));
|
|
747
732
|
cssFilesByModuleId.set(id, cssFilename);
|
|
748
|
-
const cssRelativePath = normalizeToPosix(
|
|
733
|
+
const cssRelativePath = normalizeToPosix(path.relative(config.root, cssFilename));
|
|
749
734
|
const cssId = `/${cssRelativePath}`;
|
|
750
735
|
if (sourceMap && result.cssSourceMapText) {
|
|
751
736
|
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|