weapp-tailwindcss 4.11.0-alpha.0 → 4.11.0-alpha.2
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/dist/{chunk-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
- package/dist/{chunk-FV4ZRTAK.js → chunk-2W24MRCQ.js} +10 -12
- package/dist/chunk-4AFQP74Z.js +24 -0
- package/dist/{chunk-7XQXBJL6.js → chunk-4TTPYMVM.js} +12 -8
- package/dist/{chunk-RXNSOSCT.js → chunk-5KSBT6GU.js} +448 -270
- package/dist/{chunk-QX2A7SBB.mjs → chunk-66E76FQE.mjs} +666 -102
- package/dist/{chunk-WGFNCK5B.js → chunk-6O7HJU2F.js} +123 -42
- package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
- package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
- package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
- package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
- package/dist/{chunk-XGUD52TA.mjs → chunk-EW2K6CO5.mjs} +413 -235
- package/dist/{chunk-FMWKBZWX.mjs → chunk-HADJCWHU.mjs} +291 -265
- package/dist/{chunk-FKUPQQYX.js → chunk-K7CZXT46.js} +692 -125
- package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
- package/dist/{chunk-I4EOMKX2.js → chunk-LYGLQCWI.js} +356 -330
- package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
- package/dist/{chunk-W3JO6LBC.mjs → chunk-RED7Y22U.mjs} +91 -10
- package/dist/{chunk-CLNUBO3Q.mjs → chunk-SJ3SG6DU.mjs} +5 -1
- package/dist/{chunk-OIDFSOER.mjs → chunk-UCUAXK7F.mjs} +4 -6
- package/dist/cli.js +1006 -147
- package/dist/cli.mjs +942 -107
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +9 -11
- package/dist/core.mjs +6 -8
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +4 -4
- package/dist/defaults.d.mts +2 -2
- package/dist/defaults.d.ts +2 -2
- package/dist/defaults.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/gulp.d.mts +2 -2
- package/dist/gulp.d.ts +2 -2
- package/dist/gulp.js +7 -8
- package/dist/gulp.mjs +6 -7
- package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
- package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -12
- package/dist/index.mjs +9 -10
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +5 -5
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +8 -9
- package/dist/vite.mjs +6 -7
- package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
- package/dist/weapp-tw-runtime-classset-loader.js +29 -2
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +9 -10
- package/dist/webpack.mjs +7 -8
- package/dist/webpack4.d.mts +2 -2
- package/dist/webpack4.d.ts +2 -2
- package/dist/webpack4.js +41 -41
- package/dist/webpack4.mjs +12 -12
- package/package.json +9 -9
- package/dist/chunk-EOK3NZVC.mjs +0 -29
- package/dist/chunk-PXZUQ7RR.js +0 -29
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk7LKMJZD2js = require('./chunk-7LKMJZD2.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkOF6MFURRjs = require('./chunk-OF6MFURR.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var _chunkPXZUQ7RRjs = require('./chunk-PXZUQ7RR.js');
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
|
|
@@ -24,14 +23,22 @@ var _chunkPXZUQ7RRjs = require('./chunk-PXZUQ7RR.js');
|
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
|
|
26
|
+
var _chunkLYGLQCWIjs = require('./chunk-LYGLQCWI.js');
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _chunk5KSBT6GUjs = require('./chunk-5KSBT6GU.js');
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
var _chunkDYLQ6UOIjs = require('./chunk-DYLQ6UOI.js');
|
|
33
36
|
|
|
37
|
+
|
|
38
|
+
var _chunkCRDOWYG4js = require('./chunk-CRDOWYG4.js');
|
|
39
|
+
|
|
34
40
|
// src/bundlers/vite/index.ts
|
|
41
|
+
var _fs = require('fs');
|
|
35
42
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
36
43
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
37
44
|
var _htmltransform = require('@weapp-tailwindcss/postcss/html-transform'); var _htmltransform2 = _interopRequireDefault(_htmltransform);
|
|
@@ -57,7 +64,7 @@ function updateStaticAttribute(ms, prop) {
|
|
|
57
64
|
const start = prop.value.loc.start.offset + 1;
|
|
58
65
|
const end = prop.value.loc.end.offset - 1;
|
|
59
66
|
if (start < end) {
|
|
60
|
-
ms.update(start, end,
|
|
67
|
+
ms.update(start, end, _chunkLYGLQCWIjs.replaceWxml.call(void 0, prop.value.content));
|
|
61
68
|
}
|
|
62
69
|
}
|
|
63
70
|
function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
@@ -69,7 +76,7 @@ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
|
|
|
69
76
|
if (start >= end) {
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
72
|
-
const generated =
|
|
79
|
+
const generated = _chunkLYGLQCWIjs.generateCode.call(void 0, prop.exp.content, {
|
|
73
80
|
jsHandler,
|
|
74
81
|
runtimeSet,
|
|
75
82
|
wrapExpression: true
|
|
@@ -99,7 +106,7 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
99
106
|
return;
|
|
100
107
|
}
|
|
101
108
|
const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
|
|
102
|
-
const matchCustomAttribute =
|
|
109
|
+
const matchCustomAttribute = _chunkLYGLQCWIjs.createAttributeMatcher.call(void 0, customAttributesEntities);
|
|
103
110
|
const ms = new (0, _magicstring2.default)(code);
|
|
104
111
|
const { descriptor, errors } = _compilersfc.parse.call(void 0, code);
|
|
105
112
|
if (errors.length === 0) {
|
|
@@ -369,17 +376,17 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
369
376
|
cache,
|
|
370
377
|
hashKey,
|
|
371
378
|
createHandlerOptions,
|
|
372
|
-
debug:
|
|
379
|
+
debug: debug3,
|
|
373
380
|
jsHandler,
|
|
374
381
|
onUpdate,
|
|
375
382
|
runtimeSet,
|
|
376
383
|
applyLinkedResults: applyLinkedResults2
|
|
377
384
|
} = options;
|
|
378
|
-
const absoluteFile =
|
|
385
|
+
const absoluteFile = _chunk7LKMJZD2js.toAbsoluteOutputPath.call(void 0, file, outDir);
|
|
379
386
|
const rawSource = originalSource.source.toString();
|
|
380
387
|
const rawHashSource = options.hashSalt ? `${rawSource}
|
|
381
388
|
/*${options.hashSalt}*/` : rawSource;
|
|
382
|
-
await
|
|
389
|
+
await _chunkOF6MFURRjs.processCachedTask.call(void 0, {
|
|
383
390
|
cache,
|
|
384
391
|
cacheKey: file,
|
|
385
392
|
hashKey,
|
|
@@ -388,7 +395,7 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
388
395
|
originalSource.source = source;
|
|
389
396
|
},
|
|
390
397
|
onCacheHit() {
|
|
391
|
-
|
|
398
|
+
debug3("js cache hit: %s", file);
|
|
392
399
|
},
|
|
393
400
|
async transform() {
|
|
394
401
|
const currentSource = originalSource.source.toString();
|
|
@@ -402,7 +409,7 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
402
409
|
}
|
|
403
410
|
}));
|
|
404
411
|
onUpdate(file, currentSource, code);
|
|
405
|
-
|
|
412
|
+
debug3("js handle: %s", file);
|
|
406
413
|
applyLinkedResults2(linked);
|
|
407
414
|
return {
|
|
408
415
|
result: code
|
|
@@ -415,6 +422,8 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
415
422
|
// src/bundlers/vite/generate-bundle.ts
|
|
416
423
|
|
|
417
424
|
|
|
425
|
+
var _logger = require('@weapp-tailwindcss/logger');
|
|
426
|
+
var _extractors = require('@weapp-tailwindcss/shared/extractors');
|
|
418
427
|
|
|
419
428
|
// src/bundlers/vite/bundle-entries.ts
|
|
420
429
|
var _buffer = require('buffer');
|
|
@@ -447,7 +456,7 @@ function isJavaScriptEntry(entry) {
|
|
|
447
456
|
function createBundleModuleGraphOptions(outputDir, entries) {
|
|
448
457
|
return {
|
|
449
458
|
resolve(specifier, importer) {
|
|
450
|
-
return
|
|
459
|
+
return _chunk7LKMJZD2js.resolveOutputSpecifier.call(void 0, specifier, importer, outputDir, (candidate) => entries.has(candidate));
|
|
451
460
|
},
|
|
452
461
|
load(id) {
|
|
453
462
|
const entry = entries.get(id);
|
|
@@ -486,6 +495,10 @@ function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) {
|
|
|
486
495
|
|
|
487
496
|
// src/bundlers/vite/runtime-affecting-signature.ts
|
|
488
497
|
var _htmlparser2 = require('htmlparser2');
|
|
498
|
+
var CSS_BLOCK_COMMENT_RE = /\/\*[\s\S]*?\*\//g;
|
|
499
|
+
var CSS_AROUND_PUNCTUATION_RE = /\s*([{}:;,>+~()])\s*/g;
|
|
500
|
+
var CSS_TRAILING_DECLARATION_SEMICOLON_RE = /;\}/g;
|
|
501
|
+
var CSS_WHITESPACE_RE = /\s+/g;
|
|
489
502
|
function createHtmlRuntimeAffectingSignature(source) {
|
|
490
503
|
try {
|
|
491
504
|
const parts = [];
|
|
@@ -517,23 +530,23 @@ function createHtmlRuntimeAffectingSignature(source) {
|
|
|
517
530
|
}
|
|
518
531
|
function createJsRuntimeAffectingSignature(source) {
|
|
519
532
|
try {
|
|
520
|
-
const ast =
|
|
533
|
+
const ast = _chunkLYGLQCWIjs.babelParse.call(void 0, source, {
|
|
521
534
|
cache: true,
|
|
522
535
|
cacheKey: "vite-runtime-affecting:unambiguous",
|
|
523
536
|
plugins: ["jsx", "typescript"],
|
|
524
537
|
sourceType: "unambiguous"
|
|
525
538
|
});
|
|
526
539
|
const parts = [];
|
|
527
|
-
|
|
540
|
+
_chunkLYGLQCWIjs.traverse.call(void 0, ast, {
|
|
528
541
|
noScope: true,
|
|
529
|
-
StringLiteral(
|
|
530
|
-
parts.push(`s:${
|
|
542
|
+
StringLiteral(path5) {
|
|
543
|
+
parts.push(`s:${path5.node.value}`);
|
|
531
544
|
},
|
|
532
|
-
TemplateElement(
|
|
533
|
-
parts.push(`t:${
|
|
545
|
+
TemplateElement(path5) {
|
|
546
|
+
parts.push(`t:${path5.node.value.raw}`);
|
|
534
547
|
},
|
|
535
|
-
JSXText(
|
|
536
|
-
const value =
|
|
548
|
+
JSXText(path5) {
|
|
549
|
+
const value = path5.node.value.trim();
|
|
537
550
|
if (value.length > 0) {
|
|
538
551
|
parts.push(`x:${value}`);
|
|
539
552
|
}
|
|
@@ -552,6 +565,9 @@ function createJsRuntimeAffectingSignature(source) {
|
|
|
552
565
|
return source;
|
|
553
566
|
}
|
|
554
567
|
}
|
|
568
|
+
function createCssRuntimeAffectingSignature(source) {
|
|
569
|
+
return source.replace(CSS_BLOCK_COMMENT_RE, "").replace(CSS_AROUND_PUNCTUATION_RE, "$1").replace(CSS_TRAILING_DECLARATION_SEMICOLON_RE, "}").replace(CSS_WHITESPACE_RE, " ").trim();
|
|
570
|
+
}
|
|
555
571
|
function createRuntimeAffectingSourceSignature(source, type) {
|
|
556
572
|
if (type === "html") {
|
|
557
573
|
return createHtmlRuntimeAffectingSignature(source);
|
|
@@ -559,6 +575,9 @@ function createRuntimeAffectingSourceSignature(source, type) {
|
|
|
559
575
|
if (type === "js") {
|
|
560
576
|
return createJsRuntimeAffectingSignature(source);
|
|
561
577
|
}
|
|
578
|
+
if (type === "css") {
|
|
579
|
+
return createCssRuntimeAffectingSignature(source);
|
|
580
|
+
}
|
|
562
581
|
return source;
|
|
563
582
|
}
|
|
564
583
|
|
|
@@ -610,7 +629,7 @@ function collectJsEntries(fileName, output, outDir, store) {
|
|
|
610
629
|
if (!isJavaScriptEntry(entry)) {
|
|
611
630
|
return;
|
|
612
631
|
}
|
|
613
|
-
const absolute =
|
|
632
|
+
const absolute = _chunk7LKMJZD2js.toAbsoluteOutputPath.call(void 0, fileName, outDir);
|
|
614
633
|
store.set(absolute, entry);
|
|
615
634
|
}
|
|
616
635
|
function markProcessFile(type, file, processFiles) {
|
|
@@ -620,6 +639,7 @@ function markProcessFile(type, file, processFiles) {
|
|
|
620
639
|
}
|
|
621
640
|
function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false) {
|
|
622
641
|
const sourceHashByFile = /* @__PURE__ */ new Map();
|
|
642
|
+
const runtimeAffectingSignatureByFile = /* @__PURE__ */ new Map();
|
|
623
643
|
const runtimeAffectingHashByFile = /* @__PURE__ */ new Map();
|
|
624
644
|
const changedByType = createChangedByType();
|
|
625
645
|
const runtimeAffectingChangedByType = createChangedByType();
|
|
@@ -634,6 +654,7 @@ function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false) {
|
|
|
634
654
|
const hash = opts.cache.computeHash(source);
|
|
635
655
|
sourceHashByFile.set(file, hash);
|
|
636
656
|
const runtimeAffectingSignature = createRuntimeAffectingSourceSignature(source, type);
|
|
657
|
+
runtimeAffectingSignatureByFile.set(file, runtimeAffectingSignature);
|
|
637
658
|
const runtimeAffectingHash = opts.cache.computeHash(runtimeAffectingSignature);
|
|
638
659
|
runtimeAffectingHashByFile.set(file, runtimeAffectingHash);
|
|
639
660
|
const previousHash = state.sourceHashByFile.get(file);
|
|
@@ -682,6 +703,7 @@ function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false) {
|
|
|
682
703
|
entries,
|
|
683
704
|
jsEntries,
|
|
684
705
|
sourceHashByFile,
|
|
706
|
+
runtimeAffectingSignatureByFile,
|
|
685
707
|
runtimeAffectingHashByFile,
|
|
686
708
|
changedByType,
|
|
687
709
|
runtimeAffectingChangedByType,
|
|
@@ -703,12 +725,22 @@ function invertLinkedByEntry(linkedByEntry) {
|
|
|
703
725
|
}
|
|
704
726
|
return dependentsByLinkedFile;
|
|
705
727
|
}
|
|
706
|
-
function updateBundleBuildState(state, snapshot, linkedByEntry) {
|
|
728
|
+
function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
|
|
729
|
+
const incremental = options.incremental === true;
|
|
707
730
|
state.iteration += 1;
|
|
708
|
-
state.sourceHashByFile =
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
731
|
+
state.sourceHashByFile = incremental ? new Map([
|
|
732
|
+
...state.sourceHashByFile,
|
|
733
|
+
...snapshot.sourceHashByFile
|
|
734
|
+
]) : snapshot.sourceHashByFile;
|
|
735
|
+
state.runtimeAffectingHashByFile = incremental ? new Map([
|
|
736
|
+
...state.runtimeAffectingHashByFile,
|
|
737
|
+
...snapshot.runtimeAffectingHashByFile
|
|
738
|
+
]) : snapshot.runtimeAffectingHashByFile;
|
|
739
|
+
state.linkedByEntry = incremental ? new Map([
|
|
740
|
+
...state.linkedByEntry,
|
|
741
|
+
...linkedByEntry
|
|
742
|
+
]) : linkedByEntry;
|
|
743
|
+
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
712
744
|
}
|
|
713
745
|
|
|
714
746
|
// src/bundlers/vite/js-precheck.ts
|
|
@@ -813,6 +845,42 @@ function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
|
|
|
813
845
|
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
814
846
|
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
815
847
|
}
|
|
848
|
+
function canShareCssTransformResult(rawSource) {
|
|
849
|
+
return !rawSource.includes("@import") && !rawSource.includes("url(");
|
|
850
|
+
}
|
|
851
|
+
function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
852
|
+
const currentFileSet = new Set(currentBundleFiles);
|
|
853
|
+
for (const file of previousBundleFiles) {
|
|
854
|
+
if (!currentFileSet.has(file)) {
|
|
855
|
+
return true;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
var MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
861
|
+
var QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
862
|
+
function isArbitraryValueCandidate(candidate) {
|
|
863
|
+
return candidate.includes("[") && candidate.includes("]");
|
|
864
|
+
}
|
|
865
|
+
function collectUnescapedDynamicCandidates(source) {
|
|
866
|
+
const matches = /* @__PURE__ */ new Set();
|
|
867
|
+
for (const expression of _nullishCoalesce(source.match(MUSTACHE_EXPRESSION_RE), () => ( []))) {
|
|
868
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
869
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
870
|
+
while (quoted !== null) {
|
|
871
|
+
const literal = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(quoted[1], () => ( quoted[2])), () => ( quoted[3])), () => ( ""));
|
|
872
|
+
for (const candidate of _extractors.splitCode.call(void 0, literal, true)) {
|
|
873
|
+
const normalized = candidate.trim();
|
|
874
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) {
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
matches.add(normalized);
|
|
878
|
+
}
|
|
879
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
return [...matches];
|
|
883
|
+
}
|
|
816
884
|
function createGenerateBundleHook(context) {
|
|
817
885
|
const state = createBundleBuildState();
|
|
818
886
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -820,8 +888,8 @@ function createGenerateBundleHook(context) {
|
|
|
820
888
|
const {
|
|
821
889
|
opts,
|
|
822
890
|
runtimeState,
|
|
823
|
-
|
|
824
|
-
debug:
|
|
891
|
+
ensureBundleRuntimeClassSet,
|
|
892
|
+
debug: debug3,
|
|
825
893
|
getResolvedConfig
|
|
826
894
|
} = context;
|
|
827
895
|
const {
|
|
@@ -857,7 +925,7 @@ function createGenerateBundleHook(context) {
|
|
|
857
925
|
return created;
|
|
858
926
|
};
|
|
859
927
|
await runtimeState.patchPromise;
|
|
860
|
-
|
|
928
|
+
debug3("start");
|
|
861
929
|
onStart();
|
|
862
930
|
const metrics = createEmptyMetrics();
|
|
863
931
|
const forceRuntimeRefreshByEnv = _process2.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
@@ -865,54 +933,69 @@ function createGenerateBundleHook(context) {
|
|
|
865
933
|
const disableJsPrecheck = _process2.default.env.WEAPP_TW_VITE_DISABLE_JS_PRECHECK === "1";
|
|
866
934
|
const debugCssDiff = _process2.default.env.WEAPP_TW_VITE_DEBUG_CSS_DIFF === "1";
|
|
867
935
|
const resolvedConfig = getResolvedConfig();
|
|
868
|
-
const
|
|
869
|
-
const
|
|
870
|
-
const
|
|
871
|
-
const
|
|
872
|
-
const
|
|
936
|
+
const bundleFiles = Object.keys(bundle);
|
|
937
|
+
const buildCommand = _optionalChain([resolvedConfig, 'optionalAccess', _26 => _26.command]) === "build";
|
|
938
|
+
const useIncrementalMode = !buildCommand || hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
939
|
+
const rootDir = _optionalChain([resolvedConfig, 'optionalAccess', _27 => _27.root]) ? _path2.default.resolve(resolvedConfig.root) : _process2.default.cwd();
|
|
940
|
+
const outDir = _optionalChain([resolvedConfig, 'optionalAccess', _28 => _28.build, 'optionalAccess', _29 => _29.outDir]) ? _path2.default.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
941
|
+
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode);
|
|
942
|
+
const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
|
|
943
|
+
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
873
944
|
const processFiles = snapshot.processFiles;
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
945
|
+
if (useIncrementalMode) {
|
|
946
|
+
debug3(
|
|
947
|
+
"dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]",
|
|
948
|
+
state.iteration + 1,
|
|
949
|
+
snapshot.changedByType.html.size,
|
|
950
|
+
formatDebugFileList(snapshot.changedByType.html),
|
|
951
|
+
snapshot.changedByType.js.size,
|
|
952
|
+
formatDebugFileList(snapshot.changedByType.js),
|
|
953
|
+
snapshot.changedByType.css.size,
|
|
954
|
+
formatDebugFileList(snapshot.changedByType.css),
|
|
955
|
+
snapshot.changedByType.other.size,
|
|
956
|
+
formatDebugFileList(snapshot.changedByType.other)
|
|
957
|
+
);
|
|
958
|
+
debug3(
|
|
959
|
+
"process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]",
|
|
960
|
+
state.iteration + 1,
|
|
961
|
+
processFiles.html.size,
|
|
962
|
+
formatDebugFileList(processFiles.html),
|
|
963
|
+
processFiles.js.size,
|
|
964
|
+
formatDebugFileList(processFiles.js),
|
|
965
|
+
processFiles.css.size,
|
|
966
|
+
formatDebugFileList(processFiles.css)
|
|
967
|
+
);
|
|
968
|
+
} else {
|
|
969
|
+
debug3(
|
|
970
|
+
"build mode full process html=%d[%s] js=%d[%s] css=%d[%s]",
|
|
971
|
+
processFiles.html.size,
|
|
972
|
+
formatDebugFileList(processFiles.html),
|
|
973
|
+
processFiles.js.size,
|
|
974
|
+
formatDebugFileList(processFiles.js),
|
|
975
|
+
processFiles.css.size,
|
|
976
|
+
formatDebugFileList(processFiles.css)
|
|
977
|
+
);
|
|
978
|
+
}
|
|
896
979
|
const jsEntries = snapshot.jsEntries;
|
|
897
980
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
898
981
|
const runtimeStart = performance.now();
|
|
899
|
-
const runtime = await ensureRuntimeClassSet(
|
|
982
|
+
const runtime = useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
900
983
|
const defaultTemplateHandlerOptions = {
|
|
901
984
|
runtimeSet: runtime
|
|
902
985
|
};
|
|
903
986
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
904
987
|
if (forceRuntimeRefreshBySource) {
|
|
905
|
-
|
|
988
|
+
debug3(
|
|
906
989
|
"runtimeSet forced refresh due to source changes: html=%d js=%d",
|
|
907
990
|
snapshot.runtimeAffectingChangedByType.html.size,
|
|
908
991
|
snapshot.runtimeAffectingChangedByType.js.size
|
|
909
992
|
);
|
|
910
993
|
}
|
|
911
|
-
|
|
912
|
-
const runtimeSignature = _nullishCoalesce(
|
|
994
|
+
debug3("get runtimeSet, class count: %d", runtime.size);
|
|
995
|
+
const runtimeSignature = _nullishCoalesce(_chunk5KSBT6GUjs.getRuntimeClassSetSignature.call(void 0, runtimeState.twPatcher), () => ( "runtime:missing"));
|
|
913
996
|
const handleLinkedUpdate = (fileName, previous, next) => {
|
|
914
997
|
onUpdate(fileName, previous, next);
|
|
915
|
-
|
|
998
|
+
debug3("js linked handle: %s", fileName);
|
|
916
999
|
};
|
|
917
1000
|
const pendingLinkedUpdates = [];
|
|
918
1001
|
const scheduleLinkedApply = (entry, code) => {
|
|
@@ -933,11 +1016,12 @@ function createGenerateBundleHook(context) {
|
|
|
933
1016
|
tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
|
|
934
1017
|
moduleGraph: moduleGraphOptions,
|
|
935
1018
|
babelParserOptions: {
|
|
936
|
-
..._nullishCoalesce(_optionalChain([extra, 'optionalAccess',
|
|
1019
|
+
..._nullishCoalesce(_optionalChain([extra, 'optionalAccess', _30 => _30.babelParserOptions]), () => ( {})),
|
|
937
1020
|
sourceFilename: absoluteFilename
|
|
938
1021
|
}
|
|
939
1022
|
});
|
|
940
|
-
const linkedByEntry = /* @__PURE__ */ new Map();
|
|
1023
|
+
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
1024
|
+
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
941
1025
|
const tasks = [];
|
|
942
1026
|
const jsTaskFactories = [];
|
|
943
1027
|
for (const entry of snapshot.entries) {
|
|
@@ -949,7 +1033,7 @@ function createGenerateBundleHook(context) {
|
|
|
949
1033
|
}
|
|
950
1034
|
const rawSource = originalEntrySource;
|
|
951
1035
|
tasks.push(
|
|
952
|
-
|
|
1036
|
+
_chunkOF6MFURRjs.processCachedTask.call(void 0, {
|
|
953
1037
|
cache,
|
|
954
1038
|
cacheKey: file,
|
|
955
1039
|
rawSource,
|
|
@@ -959,15 +1043,35 @@ function createGenerateBundleHook(context) {
|
|
|
959
1043
|
},
|
|
960
1044
|
onCacheHit() {
|
|
961
1045
|
metrics.html.cacheHits++;
|
|
962
|
-
|
|
1046
|
+
debug3("html cache hit: %s", file);
|
|
963
1047
|
},
|
|
964
1048
|
async transform() {
|
|
965
1049
|
const start = performance.now();
|
|
966
|
-
|
|
1050
|
+
let transformed = await templateHandler(rawSource, defaultTemplateHandlerOptions);
|
|
1051
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1052
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
1053
|
+
_logger.logger.warn(
|
|
1054
|
+
"\u68C0\u6D4B\u5230 WXML \u52A8\u6001\u7C7B\u540D\u672A\u5B8C\u6210\u8F6C\u8BD1\uFF0C\u5DF2\u56DE\u9000\u5230\u5B8C\u6574 runtimeSet \u91CD\u8BD5: %s -> %O",
|
|
1055
|
+
file,
|
|
1056
|
+
unresolvedDynamicCandidates
|
|
1057
|
+
);
|
|
1058
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
1059
|
+
transformed = await templateHandler(rawSource, {
|
|
1060
|
+
runtimeSet: fullRuntimeSet
|
|
1061
|
+
});
|
|
1062
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1063
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
1064
|
+
_logger.logger.warn(
|
|
1065
|
+
"WXML \u52A8\u6001\u7C7B\u540D\u5728\u5B8C\u6574 runtimeSet \u91CD\u8BD5\u540E\u4ECD\u672A\u5B8C\u6210\u8F6C\u8BD1: %s -> %O",
|
|
1066
|
+
file,
|
|
1067
|
+
unresolvedDynamicCandidates
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
967
1071
|
metrics.html.elapsed += measureElapsed(start);
|
|
968
1072
|
metrics.html.transformed++;
|
|
969
1073
|
onUpdate(file, rawSource, transformed);
|
|
970
|
-
|
|
1074
|
+
debug3("html handle: %s", file);
|
|
971
1075
|
return {
|
|
972
1076
|
result: transformed
|
|
973
1077
|
};
|
|
@@ -979,30 +1083,53 @@ function createGenerateBundleHook(context) {
|
|
|
979
1083
|
if (type === "css" && originalSource.type === "asset") {
|
|
980
1084
|
metrics.css.total++;
|
|
981
1085
|
const rawSource = originalEntrySource;
|
|
1086
|
+
const cssRuntimeAffectingSignature = _nullishCoalesce(snapshot.runtimeAffectingSignatureByFile.get(file), () => ( rawSource));
|
|
1087
|
+
const shareCssResult = canShareCssTransformResult(rawSource);
|
|
1088
|
+
const cssSharedCacheKey = shareCssResult ? `${runtimeSignature}:${_nullishCoalesce(runtimeState.twPatcher.majorVersion, () => ( "unknown"))}:${getCssHandlerOptions(file).isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}` : void 0;
|
|
982
1089
|
tasks.push(
|
|
983
|
-
|
|
1090
|
+
_chunkOF6MFURRjs.processCachedTask.call(void 0, {
|
|
984
1091
|
cache,
|
|
985
1092
|
cacheKey: file,
|
|
986
|
-
rawSource,
|
|
987
1093
|
hashKey: `${file}:css:${runtimeSignature}:${_nullishCoalesce(runtimeState.twPatcher.majorVersion, () => ( "unknown"))}`,
|
|
1094
|
+
rawSource: cssRuntimeAffectingSignature,
|
|
988
1095
|
applyResult(source) {
|
|
989
1096
|
originalSource.source = source;
|
|
990
1097
|
},
|
|
991
1098
|
onCacheHit() {
|
|
992
1099
|
metrics.css.cacheHits++;
|
|
993
|
-
|
|
1100
|
+
debug3("css cache hit: %s", file);
|
|
994
1101
|
},
|
|
995
1102
|
async transform() {
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1103
|
+
if (cssSharedCacheKey) {
|
|
1104
|
+
const sharedCssTask = sharedCssResultCache.get(cssSharedCacheKey);
|
|
1105
|
+
if (sharedCssTask != null) {
|
|
1106
|
+
metrics.css.cacheHits++;
|
|
1107
|
+
debug3("css shared hit: %s", file);
|
|
1108
|
+
const sharedCss = await sharedCssTask;
|
|
1109
|
+
onUpdate(file, rawSource, sharedCss);
|
|
1110
|
+
return {
|
|
1111
|
+
result: sharedCss
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1001
1114
|
}
|
|
1002
|
-
|
|
1003
|
-
|
|
1115
|
+
const runTransform = async () => {
|
|
1116
|
+
const start = performance.now();
|
|
1117
|
+
await runtimeState.patchPromise;
|
|
1118
|
+
const { css: css2 } = await styleHandler(rawSource, getCssHandlerOptions(file));
|
|
1119
|
+
if (debugCssDiff) {
|
|
1120
|
+
debug3("css diff %s: %s", file, summarizeStringDiff(rawSource, css2));
|
|
1121
|
+
}
|
|
1122
|
+
metrics.css.elapsed += measureElapsed(start);
|
|
1123
|
+
metrics.css.transformed++;
|
|
1124
|
+
return css2;
|
|
1125
|
+
};
|
|
1126
|
+
const cssTask = cssSharedCacheKey ? _nullishCoalesce(sharedCssResultCache.get(cssSharedCacheKey), () => ( runTransform())) : runTransform();
|
|
1127
|
+
if (cssSharedCacheKey && !sharedCssResultCache.has(cssSharedCacheKey)) {
|
|
1128
|
+
sharedCssResultCache.set(cssSharedCacheKey, cssTask);
|
|
1129
|
+
}
|
|
1130
|
+
const css = await cssTask;
|
|
1004
1131
|
onUpdate(file, rawSource, css);
|
|
1005
|
-
|
|
1132
|
+
debug3("css handle: %s", file);
|
|
1006
1133
|
return {
|
|
1007
1134
|
result: css
|
|
1008
1135
|
};
|
|
@@ -1015,23 +1142,25 @@ function createGenerateBundleHook(context) {
|
|
|
1015
1142
|
continue;
|
|
1016
1143
|
}
|
|
1017
1144
|
metrics.js.total++;
|
|
1018
|
-
const shouldTransformJs = processFiles.js.has(file);
|
|
1145
|
+
const shouldTransformJs = !useIncrementalMode || processFiles.js.has(file);
|
|
1019
1146
|
if (!shouldTransformJs) {
|
|
1020
|
-
|
|
1147
|
+
debug3("js skip transform (clean), replay cache: %s", file);
|
|
1021
1148
|
}
|
|
1022
1149
|
if (originalSource.type === "chunk") {
|
|
1023
1150
|
const absoluteFile = _path2.default.resolve(outDir, file);
|
|
1024
1151
|
const initialRawSource = originalEntrySource;
|
|
1025
|
-
const linkedSet = /* @__PURE__ */ new Set();
|
|
1026
|
-
linkedByEntry
|
|
1152
|
+
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
1153
|
+
if (linkedByEntry && linkedSet) {
|
|
1154
|
+
linkedByEntry.set(file, linkedSet);
|
|
1155
|
+
}
|
|
1027
1156
|
jsTaskFactories.push(async () => {
|
|
1028
|
-
const linkedImpactSignature = createLinkedImpactSignature(
|
|
1157
|
+
const linkedImpactSignature = useIncrementalMode ? createLinkedImpactSignature(
|
|
1029
1158
|
file,
|
|
1030
1159
|
snapshot.linkedImpactsByEntry,
|
|
1031
1160
|
snapshot.sourceHashByFile
|
|
1032
|
-
);
|
|
1161
|
+
) : void 0;
|
|
1033
1162
|
const hashSalt = createJsHashSalt(runtimeSignature, linkedImpactSignature);
|
|
1034
|
-
await
|
|
1163
|
+
await _chunkOF6MFURRjs.processCachedTask.call(void 0, {
|
|
1035
1164
|
cache,
|
|
1036
1165
|
cacheKey: file,
|
|
1037
1166
|
hashKey: `${file}:js`,
|
|
@@ -1042,13 +1171,13 @@ function createGenerateBundleHook(context) {
|
|
|
1042
1171
|
},
|
|
1043
1172
|
onCacheHit() {
|
|
1044
1173
|
metrics.js.cacheHits++;
|
|
1045
|
-
|
|
1174
|
+
debug3("js cache hit: %s", file);
|
|
1046
1175
|
},
|
|
1047
1176
|
async transform() {
|
|
1048
1177
|
const start = performance.now();
|
|
1049
1178
|
const rawSource = originalSource.code;
|
|
1050
1179
|
if (!shouldTransformJs) {
|
|
1051
|
-
|
|
1180
|
+
debug3("js cache replay miss, fallback transform: %s", file);
|
|
1052
1181
|
}
|
|
1053
1182
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
1054
1183
|
if (!disableJsPrecheck && shouldSkipViteJsTransform(rawSource, handlerOptions)) {
|
|
@@ -1062,11 +1191,11 @@ function createGenerateBundleHook(context) {
|
|
|
1062
1191
|
metrics.js.elapsed += measureElapsed(start);
|
|
1063
1192
|
metrics.js.transformed++;
|
|
1064
1193
|
onUpdate(file, rawSource, code);
|
|
1065
|
-
|
|
1194
|
+
debug3("js handle: %s", file);
|
|
1066
1195
|
if (linked) {
|
|
1067
1196
|
for (const id of Object.keys(linked)) {
|
|
1068
1197
|
const linkedEntry = jsEntries.get(id);
|
|
1069
|
-
if (linkedEntry) {
|
|
1198
|
+
if (linkedEntry && linkedSet) {
|
|
1070
1199
|
linkedSet.add(linkedEntry.fileName);
|
|
1071
1200
|
}
|
|
1072
1201
|
}
|
|
@@ -1079,14 +1208,16 @@ function createGenerateBundleHook(context) {
|
|
|
1079
1208
|
});
|
|
1080
1209
|
});
|
|
1081
1210
|
} else if (uniAppX && originalSource.type === "asset") {
|
|
1082
|
-
const linkedSet = /* @__PURE__ */ new Set();
|
|
1083
|
-
linkedByEntry
|
|
1211
|
+
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
1212
|
+
if (linkedByEntry && linkedSet) {
|
|
1213
|
+
linkedByEntry.set(file, linkedSet);
|
|
1214
|
+
}
|
|
1084
1215
|
const baseApplyLinkedUpdates = applyLinkedUpdates;
|
|
1085
1216
|
const wrappedApplyLinkedUpdates = (linked) => {
|
|
1086
1217
|
if (linked) {
|
|
1087
1218
|
for (const id of Object.keys(linked)) {
|
|
1088
1219
|
const linkedEntry = jsEntries.get(id);
|
|
1089
|
-
if (linkedEntry) {
|
|
1220
|
+
if (linkedEntry && linkedSet) {
|
|
1090
1221
|
linkedSet.add(linkedEntry.fileName);
|
|
1091
1222
|
}
|
|
1092
1223
|
}
|
|
@@ -1102,14 +1233,14 @@ function createGenerateBundleHook(context) {
|
|
|
1102
1233
|
hashKey: `${file}:js`,
|
|
1103
1234
|
hashSalt: createJsHashSalt(
|
|
1104
1235
|
runtimeSignature,
|
|
1105
|
-
createLinkedImpactSignature(
|
|
1236
|
+
useIncrementalMode ? createLinkedImpactSignature(
|
|
1106
1237
|
file,
|
|
1107
1238
|
snapshot.linkedImpactsByEntry,
|
|
1108
1239
|
snapshot.sourceHashByFile
|
|
1109
|
-
)
|
|
1240
|
+
) : void 0
|
|
1110
1241
|
),
|
|
1111
1242
|
createHandlerOptions,
|
|
1112
|
-
debug:
|
|
1243
|
+
debug: debug3,
|
|
1113
1244
|
jsHandler,
|
|
1114
1245
|
onUpdate,
|
|
1115
1246
|
runtimeSet: runtime,
|
|
@@ -1120,7 +1251,7 @@ function createGenerateBundleHook(context) {
|
|
|
1120
1251
|
jsTaskFactories.push(async () => {
|
|
1121
1252
|
const start = performance.now();
|
|
1122
1253
|
if (!shouldTransformJs) {
|
|
1123
|
-
|
|
1254
|
+
debug3("js skip transform (clean, uni-app-x), replay cache: %s", file);
|
|
1124
1255
|
await factory();
|
|
1125
1256
|
metrics.js.elapsed += measureElapsed(start);
|
|
1126
1257
|
metrics.js.transformed++;
|
|
@@ -1146,15 +1277,20 @@ function createGenerateBundleHook(context) {
|
|
|
1146
1277
|
});
|
|
1147
1278
|
}
|
|
1148
1279
|
}
|
|
1149
|
-
|
|
1280
|
+
_chunk7LKMJZD2js.pushConcurrentTaskFactories.call(void 0, tasks, jsTaskFactories);
|
|
1150
1281
|
await Promise.all(tasks);
|
|
1151
1282
|
for (const apply of pendingLinkedUpdates) {
|
|
1152
1283
|
apply();
|
|
1153
1284
|
}
|
|
1154
|
-
updateBundleBuildState(
|
|
1155
|
-
|
|
1285
|
+
updateBundleBuildState(
|
|
1286
|
+
state,
|
|
1287
|
+
snapshot,
|
|
1288
|
+
useIncrementalMode ? _nullishCoalesce(linkedByEntry, () => ( /* @__PURE__ */ new Map())) : /* @__PURE__ */ new Map(),
|
|
1289
|
+
{ incremental: useIncrementalMode }
|
|
1290
|
+
);
|
|
1291
|
+
debug3(
|
|
1156
1292
|
"metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)",
|
|
1157
|
-
state.iteration,
|
|
1293
|
+
useIncrementalMode ? state.iteration : 0,
|
|
1158
1294
|
formatMs(metrics.runtimeSet),
|
|
1159
1295
|
metrics.html.total,
|
|
1160
1296
|
metrics.html.transformed,
|
|
@@ -1173,7 +1309,363 @@ function createGenerateBundleHook(context) {
|
|
|
1173
1309
|
formatMs(metrics.css.elapsed)
|
|
1174
1310
|
);
|
|
1175
1311
|
onEnd();
|
|
1176
|
-
|
|
1312
|
+
debug3("end");
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// src/bundlers/vite/incremental-runtime-class-set.ts
|
|
1317
|
+
var _promises = require('fs/promises');
|
|
1318
|
+
var _module = require('module');
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
var _tailwindcsspatch = require('tailwindcss-patch');
|
|
1322
|
+
var debug = _chunkLYGLQCWIjs.createDebug.call(void 0, "[vite:runtime-set] ");
|
|
1323
|
+
var require2 = _module.createRequire.call(void 0, _chunkCRDOWYG4js.importMetaUrl);
|
|
1324
|
+
var EXTENSION_DOT_PREFIX_RE = /^\./;
|
|
1325
|
+
var VALIDATION_FILE_NAME = "runtime-candidates.html";
|
|
1326
|
+
var tailwindNodeModulePromise;
|
|
1327
|
+
function toPosixPath(value) {
|
|
1328
|
+
return value.replaceAll("\\", "/");
|
|
1329
|
+
}
|
|
1330
|
+
function createCssImportSource(imports) {
|
|
1331
|
+
return imports.map((value) => `@import "${toPosixPath(value)}";`).join("\n");
|
|
1332
|
+
}
|
|
1333
|
+
function isPostcssPluginImportTarget(value) {
|
|
1334
|
+
if (!value) {
|
|
1335
|
+
return false;
|
|
1336
|
+
}
|
|
1337
|
+
return value === "@tailwindcss/postcss" || value === "@tailwindcss/postcss7-compat" || value.includes("/postcss");
|
|
1338
|
+
}
|
|
1339
|
+
function resolveTailwindCssImportTarget(patcher) {
|
|
1340
|
+
const tailwindOptions = _chunk5KSBT6GUjs.resolveTailwindcssOptions.call(void 0, patcher.options);
|
|
1341
|
+
const cssEntries = _optionalChain([tailwindOptions, 'optionalAccess', _31 => _31.v4, 'optionalAccess', _32 => _32.cssEntries, 'optionalAccess', _33 => _33.filter, 'call', _34 => _34((item) => typeof item === "string" && item.length > 0)]);
|
|
1342
|
+
if (cssEntries && cssEntries.length > 0) {
|
|
1343
|
+
return createCssImportSource(cssEntries);
|
|
1344
|
+
}
|
|
1345
|
+
const configuredPackageName = _optionalChain([tailwindOptions, 'optionalAccess', _35 => _35.packageName]);
|
|
1346
|
+
if (typeof configuredPackageName === "string" && configuredPackageName.length > 0 && !isPostcssPluginImportTarget(configuredPackageName)) {
|
|
1347
|
+
return createCssImportSource([configuredPackageName]);
|
|
1348
|
+
}
|
|
1349
|
+
const packageName = _optionalChain([patcher, 'access', _36 => _36.packageInfo, 'optionalAccess', _37 => _37.name]);
|
|
1350
|
+
if (typeof packageName === "string" && packageName.length > 0 && !isPostcssPluginImportTarget(packageName)) {
|
|
1351
|
+
return createCssImportSource([packageName]);
|
|
1352
|
+
}
|
|
1353
|
+
return createCssImportSource(["tailwindcss"]);
|
|
1354
|
+
}
|
|
1355
|
+
function getProjectRoot(patcher) {
|
|
1356
|
+
return _nullishCoalesce(_optionalChain([patcher, 'access', _38 => _38.options, 'optionalAccess', _39 => _39.projectRoot]), () => ( _process2.default.cwd()));
|
|
1357
|
+
}
|
|
1358
|
+
async function importTailwindNodeModule() {
|
|
1359
|
+
if (!tailwindNodeModulePromise) {
|
|
1360
|
+
tailwindNodeModulePromise = (async () => {
|
|
1361
|
+
try {
|
|
1362
|
+
const resolved = require2.resolve("@tailwindcss/node");
|
|
1363
|
+
return await Promise.resolve().then(() => _interopRequireWildcard(require(resolved)));
|
|
1364
|
+
} catch (e3) {
|
|
1365
|
+
const tailwindcssPatchEntry = require2.resolve("tailwindcss-patch");
|
|
1366
|
+
const resolved = require2.resolve("@tailwindcss/node", {
|
|
1367
|
+
paths: [_path2.default.dirname(tailwindcssPatchEntry)]
|
|
1368
|
+
});
|
|
1369
|
+
return await Promise.resolve().then(() => _interopRequireWildcard(require(resolved)));
|
|
1370
|
+
}
|
|
1371
|
+
})();
|
|
1372
|
+
}
|
|
1373
|
+
return tailwindNodeModulePromise;
|
|
1374
|
+
}
|
|
1375
|
+
function resolveMaybeAbsolute(base, value) {
|
|
1376
|
+
if (!value) {
|
|
1377
|
+
return void 0;
|
|
1378
|
+
}
|
|
1379
|
+
return _path2.default.isAbsolute(value) ? value : _path2.default.resolve(base, value);
|
|
1380
|
+
}
|
|
1381
|
+
async function resolveTailwindCssSource(patcher) {
|
|
1382
|
+
const projectRoot = getProjectRoot(patcher);
|
|
1383
|
+
const tailwindOptions = _chunk5KSBT6GUjs.resolveTailwindcssOptions.call(void 0, patcher.options);
|
|
1384
|
+
const configuredBase = resolveMaybeAbsolute(projectRoot, _optionalChain([tailwindOptions, 'optionalAccess', _40 => _40.v4, 'optionalAccess', _41 => _41.base]));
|
|
1385
|
+
const configDir = _optionalChain([tailwindOptions, 'optionalAccess', _42 => _42.config]) ? _path2.default.dirname(tailwindOptions.config) : void 0;
|
|
1386
|
+
const sharedFallbacks = [
|
|
1387
|
+
configuredBase,
|
|
1388
|
+
projectRoot,
|
|
1389
|
+
_optionalChain([tailwindOptions, 'optionalAccess', _43 => _43.cwd]),
|
|
1390
|
+
configDir
|
|
1391
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1392
|
+
if (_optionalChain([tailwindOptions, 'optionalAccess', _44 => _44.v4, 'optionalAccess', _45 => _45.css])) {
|
|
1393
|
+
return {
|
|
1394
|
+
projectRoot,
|
|
1395
|
+
base: _nullishCoalesce(configuredBase, () => ( projectRoot)),
|
|
1396
|
+
baseFallbacks: [...new Set(sharedFallbacks)],
|
|
1397
|
+
css: tailwindOptions.v4.css
|
|
1398
|
+
};
|
|
1399
|
+
}
|
|
1400
|
+
const cssEntries = _nullishCoalesce(_optionalChain([tailwindOptions, 'optionalAccess', _46 => _46.v4, 'optionalAccess', _47 => _47.cssEntries, 'optionalAccess', _48 => _48.filter, 'call', _49 => _49((item) => typeof item === "string" && item.length > 0)]), () => ( []));
|
|
1401
|
+
if (cssEntries.length > 0) {
|
|
1402
|
+
const resolvedEntries = cssEntries.map((entry) => _nullishCoalesce(resolveMaybeAbsolute(projectRoot, entry), () => ( entry)));
|
|
1403
|
+
const cssChunks = [];
|
|
1404
|
+
const entryDirs = [];
|
|
1405
|
+
for (const entry of resolvedEntries) {
|
|
1406
|
+
try {
|
|
1407
|
+
cssChunks.push(await _promises.readFile.call(void 0, entry, "utf8"));
|
|
1408
|
+
entryDirs.push(_path2.default.dirname(entry));
|
|
1409
|
+
} catch (e4) {
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (cssChunks.length > 0) {
|
|
1413
|
+
const base = _nullishCoalesce(_nullishCoalesce(entryDirs[0], () => ( configuredBase)), () => ( projectRoot));
|
|
1414
|
+
const baseFallbacks = [...new Set([
|
|
1415
|
+
...entryDirs.slice(1),
|
|
1416
|
+
...sharedFallbacks
|
|
1417
|
+
].filter((item) => typeof item === "string" && item.length > 0 && item !== base))];
|
|
1418
|
+
return {
|
|
1419
|
+
projectRoot,
|
|
1420
|
+
base,
|
|
1421
|
+
baseFallbacks,
|
|
1422
|
+
css: cssChunks.join("\n")
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
return {
|
|
1427
|
+
projectRoot,
|
|
1428
|
+
base: _nullishCoalesce(configuredBase, () => ( projectRoot)),
|
|
1429
|
+
baseFallbacks: [...new Set(sharedFallbacks)],
|
|
1430
|
+
css: resolveTailwindCssImportTarget(patcher)
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
function createExtractOptions(context, tempRoot, pattern) {
|
|
1434
|
+
return {
|
|
1435
|
+
cwd: context.projectRoot,
|
|
1436
|
+
base: context.base,
|
|
1437
|
+
baseFallbacks: context.baseFallbacks,
|
|
1438
|
+
css: context.css,
|
|
1439
|
+
sources: [{
|
|
1440
|
+
base: tempRoot,
|
|
1441
|
+
pattern,
|
|
1442
|
+
negated: false
|
|
1443
|
+
}]
|
|
1444
|
+
};
|
|
1445
|
+
}
|
|
1446
|
+
function createRuntimeEntries(snapshot) {
|
|
1447
|
+
return snapshot.entries.filter((entry) => entry.type === "html" || entry.type === "js");
|
|
1448
|
+
}
|
|
1449
|
+
function collectChangedRuntimeFiles(snapshot) {
|
|
1450
|
+
return /* @__PURE__ */ new Set([
|
|
1451
|
+
...snapshot.runtimeAffectingChangedByType.html,
|
|
1452
|
+
...snapshot.runtimeAffectingChangedByType.js
|
|
1453
|
+
]);
|
|
1454
|
+
}
|
|
1455
|
+
async function writeTempEntryFile(tempRoot, file, source) {
|
|
1456
|
+
const absoluteFile = _path2.default.join(tempRoot, file);
|
|
1457
|
+
await _promises.mkdir.call(void 0, _path2.default.dirname(absoluteFile), { recursive: true });
|
|
1458
|
+
await _promises.writeFile.call(void 0, absoluteFile, source, "utf8");
|
|
1459
|
+
return file;
|
|
1460
|
+
}
|
|
1461
|
+
function resolveEntryExtension(entry) {
|
|
1462
|
+
const ext = _path2.default.extname(entry.file).replace(EXTENSION_DOT_PREFIX_RE, "");
|
|
1463
|
+
if (ext.length > 0) {
|
|
1464
|
+
return ext;
|
|
1465
|
+
}
|
|
1466
|
+
return entry.type === "html" ? "html" : "js";
|
|
1467
|
+
}
|
|
1468
|
+
function createCandidateValidationSource(candidates) {
|
|
1469
|
+
return [...new Set(candidates)].sort().join("\n");
|
|
1470
|
+
}
|
|
1471
|
+
function removeCandidateSet(candidateCountByClass, runtimeSet, candidates) {
|
|
1472
|
+
for (const className of candidates) {
|
|
1473
|
+
const count = candidateCountByClass.get(className);
|
|
1474
|
+
if (count == null) {
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
if (count <= 1) {
|
|
1478
|
+
candidateCountByClass.delete(className);
|
|
1479
|
+
runtimeSet.delete(className);
|
|
1480
|
+
continue;
|
|
1481
|
+
}
|
|
1482
|
+
candidateCountByClass.set(className, count - 1);
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
function addCandidateSet(candidateCountByClass, runtimeSet, candidates) {
|
|
1486
|
+
for (const className of candidates) {
|
|
1487
|
+
const nextCount = (_nullishCoalesce(candidateCountByClass.get(className), () => ( 0))) + 1;
|
|
1488
|
+
candidateCountByClass.set(className, nextCount);
|
|
1489
|
+
runtimeSet.add(className);
|
|
1490
|
+
}
|
|
1491
|
+
}
|
|
1492
|
+
function createBundleRuntimeClassSetManager(options = {}) {
|
|
1493
|
+
const customExtractCandidates = options.extractCandidates;
|
|
1494
|
+
const extractCandidates = _nullishCoalesce(customExtractCandidates, () => ( _tailwindcsspatch.extractValidCandidates));
|
|
1495
|
+
const extractRawCandidates = _nullishCoalesce(options.extractRawCandidates, () => ( _tailwindcsspatch.extractRawCandidatesWithPositions));
|
|
1496
|
+
const runtimeSet = /* @__PURE__ */ new Set();
|
|
1497
|
+
const candidateCountByClass = /* @__PURE__ */ new Map();
|
|
1498
|
+
const candidatesByFile = /* @__PURE__ */ new Map();
|
|
1499
|
+
const candidateValidityCache = /* @__PURE__ */ new Map();
|
|
1500
|
+
let runtimeSignature;
|
|
1501
|
+
let resolvedTempRoot;
|
|
1502
|
+
let validationContext;
|
|
1503
|
+
let designSystemPromise;
|
|
1504
|
+
async function reset() {
|
|
1505
|
+
runtimeSet.clear();
|
|
1506
|
+
candidateCountByClass.clear();
|
|
1507
|
+
candidatesByFile.clear();
|
|
1508
|
+
candidateValidityCache.clear();
|
|
1509
|
+
runtimeSignature = void 0;
|
|
1510
|
+
validationContext = void 0;
|
|
1511
|
+
designSystemPromise = void 0;
|
|
1512
|
+
if (resolvedTempRoot) {
|
|
1513
|
+
await _promises.rm.call(void 0, resolvedTempRoot, { recursive: true, force: true });
|
|
1514
|
+
resolvedTempRoot = void 0;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
async function resolveValidationContextCached(patcher) {
|
|
1518
|
+
if (!validationContext) {
|
|
1519
|
+
validationContext = await resolveTailwindCssSource(patcher);
|
|
1520
|
+
}
|
|
1521
|
+
return validationContext;
|
|
1522
|
+
}
|
|
1523
|
+
async function loadDesignSystem(context) {
|
|
1524
|
+
if (!designSystemPromise) {
|
|
1525
|
+
designSystemPromise = (async () => {
|
|
1526
|
+
const { __unstable__loadDesignSystem } = await importTailwindNodeModule();
|
|
1527
|
+
let lastError;
|
|
1528
|
+
for (const base of [context.base, ...context.baseFallbacks]) {
|
|
1529
|
+
try {
|
|
1530
|
+
return await __unstable__loadDesignSystem(context.css, { base });
|
|
1531
|
+
} catch (error) {
|
|
1532
|
+
lastError = error;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
throw lastError instanceof Error ? lastError : new Error("Failed to load Tailwind CSS design system for incremental runtime validation.");
|
|
1536
|
+
})();
|
|
1537
|
+
}
|
|
1538
|
+
return designSystemPromise;
|
|
1539
|
+
}
|
|
1540
|
+
function populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates) {
|
|
1541
|
+
const parsedCandidates = [...unknownCandidates].filter((candidate) => designSystem.parseCandidate(candidate).length > 0);
|
|
1542
|
+
const cssByCandidate = parsedCandidates.length > 0 ? designSystem.candidatesToCss(parsedCandidates) : [];
|
|
1543
|
+
const validCandidates = /* @__PURE__ */ new Set();
|
|
1544
|
+
for (let index = 0; index < parsedCandidates.length; index += 1) {
|
|
1545
|
+
const candidate = parsedCandidates[index];
|
|
1546
|
+
const css = cssByCandidate[index];
|
|
1547
|
+
if (candidate && typeof css === "string" && css.trim().length > 0) {
|
|
1548
|
+
validCandidates.add(candidate);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
for (const candidate of unknownCandidates) {
|
|
1552
|
+
candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
async function validateUnknownCandidates(patcher, tempRoot, unknownCandidates) {
|
|
1556
|
+
if (unknownCandidates.size === 0) {
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const context = await resolveValidationContextCached(patcher);
|
|
1560
|
+
if (!customExtractCandidates) {
|
|
1561
|
+
try {
|
|
1562
|
+
const designSystem = await loadDesignSystem(context);
|
|
1563
|
+
populateCandidateValidityCacheFromDesignSystem(designSystem, unknownCandidates);
|
|
1564
|
+
return;
|
|
1565
|
+
} catch (error) {
|
|
1566
|
+
debug("incremental design-system validation failed, fallback to extractValidCandidates: %O", error);
|
|
1567
|
+
designSystemPromise = void 0;
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
const source = createCandidateValidationSource(unknownCandidates);
|
|
1571
|
+
const pattern = await writeTempEntryFile(tempRoot, VALIDATION_FILE_NAME, source);
|
|
1572
|
+
const validCandidates = new Set(await extractCandidates(createExtractOptions(context, tempRoot, pattern)));
|
|
1573
|
+
for (const candidate of unknownCandidates) {
|
|
1574
|
+
candidateValidityCache.set(candidate, validCandidates.has(candidate));
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
async function extractEntryRawCandidates(entry) {
|
|
1578
|
+
const matches = await extractRawCandidates(entry.source, resolveEntryExtension(entry));
|
|
1579
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
1580
|
+
for (const match of matches) {
|
|
1581
|
+
const candidate = _optionalChain([match, 'optionalAccess', _50 => _50.rawCandidate]);
|
|
1582
|
+
if (typeof candidate === "string" && candidate.length > 0) {
|
|
1583
|
+
candidates.add(candidate);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
return candidates;
|
|
1587
|
+
}
|
|
1588
|
+
async function sync(patcher, snapshot) {
|
|
1589
|
+
const nextSignature = _nullishCoalesce(_chunk5KSBT6GUjs.getRuntimeClassSetSignature.call(void 0, patcher), () => ( "runtime:missing"));
|
|
1590
|
+
const runtimeEntries = createRuntimeEntries(snapshot);
|
|
1591
|
+
const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
|
|
1592
|
+
const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
|
|
1593
|
+
const fullRebuild = runtimeSignature !== nextSignature || candidatesByFile.size === 0;
|
|
1594
|
+
if (runtimeSignature !== nextSignature) {
|
|
1595
|
+
debug("runtime signature changed, reset incremental runtime set: %s", nextSignature);
|
|
1596
|
+
await reset();
|
|
1597
|
+
}
|
|
1598
|
+
runtimeSignature = nextSignature;
|
|
1599
|
+
const projectRoot = getProjectRoot(patcher);
|
|
1600
|
+
resolvedTempRoot = _nullishCoalesce(options.tempRoot, () => ( _path2.default.join(
|
|
1601
|
+
projectRoot,
|
|
1602
|
+
"node_modules",
|
|
1603
|
+
".cache",
|
|
1604
|
+
"weapp-tailwindcss",
|
|
1605
|
+
"vite-runtime-set"
|
|
1606
|
+
)));
|
|
1607
|
+
for (const [file, previousCandidates] of candidatesByFile) {
|
|
1608
|
+
if (currentRuntimeFiles.has(file)) {
|
|
1609
|
+
continue;
|
|
1610
|
+
}
|
|
1611
|
+
removeCandidateSet(candidateCountByClass, runtimeSet, previousCandidates);
|
|
1612
|
+
candidatesByFile.delete(file);
|
|
1613
|
+
}
|
|
1614
|
+
const changedRuntimeFiles = fullRebuild ? [...runtimeEntriesByFile.keys()] : [...collectChangedRuntimeFiles(snapshot)];
|
|
1615
|
+
if (changedRuntimeFiles.length === 0) {
|
|
1616
|
+
return new Set(runtimeSet);
|
|
1617
|
+
}
|
|
1618
|
+
const rawCandidatesByFile = /* @__PURE__ */ new Map();
|
|
1619
|
+
const unknownCandidates = /* @__PURE__ */ new Set();
|
|
1620
|
+
await Promise.all(changedRuntimeFiles.map(async (file) => {
|
|
1621
|
+
const entry = runtimeEntriesByFile.get(file);
|
|
1622
|
+
if (!entry) {
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
const candidates = await extractEntryRawCandidates(entry);
|
|
1626
|
+
rawCandidatesByFile.set(file, candidates);
|
|
1627
|
+
for (const candidate of candidates) {
|
|
1628
|
+
if (!candidateValidityCache.has(candidate)) {
|
|
1629
|
+
unknownCandidates.add(candidate);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}));
|
|
1633
|
+
await validateUnknownCandidates(patcher, resolvedTempRoot, unknownCandidates);
|
|
1634
|
+
let rawCandidateCount = 0;
|
|
1635
|
+
for (const file of changedRuntimeFiles) {
|
|
1636
|
+
const nextRawCandidates = rawCandidatesByFile.get(file);
|
|
1637
|
+
const previousCandidates = candidatesByFile.get(file);
|
|
1638
|
+
if (previousCandidates) {
|
|
1639
|
+
removeCandidateSet(candidateCountByClass, runtimeSet, previousCandidates);
|
|
1640
|
+
}
|
|
1641
|
+
if (!nextRawCandidates || nextRawCandidates.size === 0) {
|
|
1642
|
+
candidatesByFile.delete(file);
|
|
1643
|
+
continue;
|
|
1644
|
+
}
|
|
1645
|
+
rawCandidateCount += nextRawCandidates.size;
|
|
1646
|
+
const nextCandidates = new Set(
|
|
1647
|
+
[...nextRawCandidates].filter((candidate) => candidateValidityCache.get(candidate) === true)
|
|
1648
|
+
);
|
|
1649
|
+
if (nextCandidates.size === 0) {
|
|
1650
|
+
candidatesByFile.delete(file);
|
|
1651
|
+
continue;
|
|
1652
|
+
}
|
|
1653
|
+
addCandidateSet(candidateCountByClass, runtimeSet, nextCandidates);
|
|
1654
|
+
candidatesByFile.set(file, nextCandidates);
|
|
1655
|
+
}
|
|
1656
|
+
debug(
|
|
1657
|
+
"incremental runtime set synced, changedFiles=%d rawCandidates=%d validateMisses=%d runtimeSize=%d trackedFiles=%d",
|
|
1658
|
+
changedRuntimeFiles.length,
|
|
1659
|
+
rawCandidateCount,
|
|
1660
|
+
unknownCandidates.size,
|
|
1661
|
+
runtimeSet.size,
|
|
1662
|
+
candidatesByFile.size
|
|
1663
|
+
);
|
|
1664
|
+
return new Set(runtimeSet);
|
|
1665
|
+
}
|
|
1666
|
+
return {
|
|
1667
|
+
sync,
|
|
1668
|
+
reset
|
|
1177
1669
|
};
|
|
1178
1670
|
}
|
|
1179
1671
|
|
|
@@ -1198,12 +1690,12 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1198
1690
|
const { appType, weappTailwindcssDirPosix: weappTailwindcssDirPosix2 } = options;
|
|
1199
1691
|
return [
|
|
1200
1692
|
{
|
|
1201
|
-
name: `${
|
|
1693
|
+
name: `${_chunkLYGLQCWIjs.vitePluginName}:rewrite-css-imports`,
|
|
1202
1694
|
enforce: "pre",
|
|
1203
1695
|
resolveId: {
|
|
1204
1696
|
order: "pre",
|
|
1205
1697
|
handler(id, importer) {
|
|
1206
|
-
const replacement =
|
|
1698
|
+
const replacement = _chunk7LKMJZD2js.resolveTailwindcssImport.call(void 0, id, weappTailwindcssDirPosix2, {
|
|
1207
1699
|
join: joinPosixPath,
|
|
1208
1700
|
appType
|
|
1209
1701
|
});
|
|
@@ -1222,7 +1714,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1222
1714
|
if (!isCSSRequest(id)) {
|
|
1223
1715
|
return null;
|
|
1224
1716
|
}
|
|
1225
|
-
const rewritten =
|
|
1717
|
+
const rewritten = _chunk7LKMJZD2js.rewriteTailwindcssImportsInCode.call(void 0, code, weappTailwindcssDirPosix2, {
|
|
1226
1718
|
join: joinPosixPath,
|
|
1227
1719
|
appType
|
|
1228
1720
|
});
|
|
@@ -1240,13 +1732,39 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1240
1732
|
}
|
|
1241
1733
|
|
|
1242
1734
|
// src/bundlers/vite/index.ts
|
|
1243
|
-
var
|
|
1244
|
-
var weappTailwindcssPackageDir =
|
|
1735
|
+
var debug2 = _chunkLYGLQCWIjs.createDebug.call(void 0, );
|
|
1736
|
+
var weappTailwindcssPackageDir = _chunk7LKMJZD2js.resolvePackageDir.call(void 0, "weapp-tailwindcss");
|
|
1245
1737
|
var weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
1738
|
+
var PACKAGE_JSON_FILE = "package.json";
|
|
1739
|
+
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
1740
|
+
const resolvedRoot = _path2.default.resolve(root);
|
|
1741
|
+
if (!_fs.existsSync.call(void 0, resolvedRoot)) {
|
|
1742
|
+
return resolvedRoot;
|
|
1743
|
+
}
|
|
1744
|
+
const searchRoots = [];
|
|
1745
|
+
let current = resolvedRoot;
|
|
1746
|
+
while (true) {
|
|
1747
|
+
searchRoots.push(current);
|
|
1748
|
+
const parent = _path2.default.dirname(current);
|
|
1749
|
+
if (parent === current) {
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
current = parent;
|
|
1753
|
+
}
|
|
1754
|
+
const tailwindConfigPath = _chunk5KSBT6GUjs.findTailwindConfig.call(void 0, searchRoots);
|
|
1755
|
+
if (tailwindConfigPath) {
|
|
1756
|
+
return _path2.default.dirname(tailwindConfigPath);
|
|
1757
|
+
}
|
|
1758
|
+
const packageRoot = _chunk5KSBT6GUjs.findNearestPackageRoot.call(void 0, resolvedRoot);
|
|
1759
|
+
if (packageRoot && _fs.existsSync.call(void 0, _path2.default.join(packageRoot, PACKAGE_JSON_FILE))) {
|
|
1760
|
+
return packageRoot;
|
|
1761
|
+
}
|
|
1762
|
+
return resolvedRoot;
|
|
1763
|
+
}
|
|
1246
1764
|
function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
1247
1765
|
const rewriteCssImportsSpecified = Object.hasOwn(options, "rewriteCssImports");
|
|
1248
1766
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
1249
|
-
const opts =
|
|
1767
|
+
const opts = _chunkLYGLQCWIjs.getCompilerContext.call(void 0, options);
|
|
1250
1768
|
const {
|
|
1251
1769
|
disabled,
|
|
1252
1770
|
customAttributes,
|
|
@@ -1260,7 +1778,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1260
1778
|
uniAppX,
|
|
1261
1779
|
disabledDefaultTemplateHandler
|
|
1262
1780
|
} = opts;
|
|
1263
|
-
const disabledOptions =
|
|
1781
|
+
const disabledOptions = _chunk7LKMJZD2js.resolveDisabledOptions.call(void 0, disabled);
|
|
1264
1782
|
const tailwindcssMajorVersion = _nullishCoalesce(initialTwPatcher.majorVersion, () => ( 0));
|
|
1265
1783
|
const shouldRewriteCssImports = opts.rewriteCssImports !== false && !disabledOptions.rewriteCssImports && (rewriteCssImportsSpecified || tailwindcssMajorVersion >= 4);
|
|
1266
1784
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
@@ -1271,8 +1789,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1271
1789
|
if (disabledOptions.plugin) {
|
|
1272
1790
|
return rewritePlugins.length ? rewritePlugins : void 0;
|
|
1273
1791
|
}
|
|
1274
|
-
const customAttributesEntities =
|
|
1275
|
-
const patchRecorderState =
|
|
1792
|
+
const customAttributesEntities = _chunkLYGLQCWIjs.toCustomAttributesEntities.call(void 0, customAttributes);
|
|
1793
|
+
const patchRecorderState = _chunkLYGLQCWIjs.setupPatchRecorder.call(void 0, initialTwPatcher, opts.tailwindcssBasedir, {
|
|
1276
1794
|
source: "runtime",
|
|
1277
1795
|
cwd: _nullishCoalesce(opts.tailwindcssBasedir, () => ( _process2.default.cwd()))
|
|
1278
1796
|
});
|
|
@@ -1287,9 +1805,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1287
1805
|
let resolvedConfig;
|
|
1288
1806
|
let runtimeRefreshSignature;
|
|
1289
1807
|
let runtimeRefreshOptionsKey;
|
|
1808
|
+
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
|
|
1290
1809
|
function resolveRuntimeRefreshOptions() {
|
|
1291
|
-
const configPath = _optionalChain([
|
|
1292
|
-
const signature =
|
|
1810
|
+
const configPath = _optionalChain([_chunk5KSBT6GUjs.resolveTailwindcssOptions.call(void 0, runtimeState.twPatcher.options), 'optionalAccess', _51 => _51.config]);
|
|
1811
|
+
const signature = _chunk5KSBT6GUjs.getRuntimeClassSetSignature.call(void 0, runtimeState.twPatcher);
|
|
1293
1812
|
const optionsKey = JSON.stringify({
|
|
1294
1813
|
appType,
|
|
1295
1814
|
uniAppX: Boolean(uniAppX),
|
|
@@ -1310,12 +1829,12 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1310
1829
|
async function refreshRuntimeState(force) {
|
|
1311
1830
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
1312
1831
|
const shouldRefresh = force || invalidation.changed;
|
|
1313
|
-
const refreshed = await
|
|
1832
|
+
const refreshed = await _chunkLYGLQCWIjs.refreshTailwindRuntimeState.call(void 0, runtimeState, {
|
|
1314
1833
|
force: shouldRefresh,
|
|
1315
1834
|
clearCache: force || invalidation.changed
|
|
1316
1835
|
});
|
|
1317
1836
|
if (invalidation.changed) {
|
|
1318
|
-
|
|
1837
|
+
debug2("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
|
|
1319
1838
|
}
|
|
1320
1839
|
if (refreshed) {
|
|
1321
1840
|
runtimeSet = void 0;
|
|
@@ -1331,7 +1850,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1331
1850
|
}
|
|
1332
1851
|
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
1333
1852
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
1334
|
-
const task2 =
|
|
1853
|
+
const task2 = _chunkLYGLQCWIjs.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, {
|
|
1335
1854
|
force: forceRuntimeRefresh || invalidation.changed,
|
|
1336
1855
|
skipRefresh: forceRuntimeRefresh,
|
|
1337
1856
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -1348,6 +1867,46 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1348
1867
|
}
|
|
1349
1868
|
}
|
|
1350
1869
|
}
|
|
1870
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
|
|
1871
|
+
const forceRuntimeRefresh = forceRefresh || _process2.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
|
|
1872
|
+
const invalidation = resolveRuntimeRefreshOptions();
|
|
1873
|
+
const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
|
|
1874
|
+
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
1875
|
+
await refreshRuntimeState(shouldRefreshPatcher);
|
|
1876
|
+
await runtimeState.patchPromise;
|
|
1877
|
+
if (shouldRefreshPatcher) {
|
|
1878
|
+
runtimeSet = void 0;
|
|
1879
|
+
runtimeSetPromise = void 0;
|
|
1880
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1881
|
+
}
|
|
1882
|
+
if (runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
|
|
1883
|
+
try {
|
|
1884
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
1885
|
+
runtimeSet = nextRuntimeSet;
|
|
1886
|
+
return nextRuntimeSet;
|
|
1887
|
+
} catch (error) {
|
|
1888
|
+
debug2("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1889
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) {
|
|
1893
|
+
return runtimeSet;
|
|
1894
|
+
}
|
|
1895
|
+
const task = _chunkLYGLQCWIjs.collectRuntimeClassSet.call(void 0, runtimeState.twPatcher, {
|
|
1896
|
+
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
1897
|
+
skipRefresh: forceRuntimeRefresh,
|
|
1898
|
+
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
1899
|
+
});
|
|
1900
|
+
runtimeSetPromise = task;
|
|
1901
|
+
try {
|
|
1902
|
+
runtimeSet = await task;
|
|
1903
|
+
return runtimeSet;
|
|
1904
|
+
} finally {
|
|
1905
|
+
if (runtimeSetPromise === task) {
|
|
1906
|
+
runtimeSetPromise = void 0;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1351
1910
|
onLoad();
|
|
1352
1911
|
const getResolvedConfig = () => resolvedConfig;
|
|
1353
1912
|
const utsPlatform = _chunkDYLQ6UOIjs.resolveUniUtsPlatform.call(void 0, );
|
|
@@ -1367,16 +1926,23 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1367
1926
|
const plugins = [
|
|
1368
1927
|
...rewritePlugins,
|
|
1369
1928
|
{
|
|
1370
|
-
name: `${
|
|
1929
|
+
name: `${_chunkLYGLQCWIjs.vitePluginName}:post`,
|
|
1371
1930
|
enforce: "post",
|
|
1372
1931
|
async configResolved(config) {
|
|
1373
1932
|
resolvedConfig = config;
|
|
1374
1933
|
const resolvedRoot = config.root ? _path2.default.resolve(config.root) : void 0;
|
|
1375
|
-
if (!hasExplicitTailwindcssBasedir && resolvedRoot
|
|
1376
|
-
const
|
|
1377
|
-
opts.tailwindcssBasedir
|
|
1378
|
-
|
|
1379
|
-
|
|
1934
|
+
if (!hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
1935
|
+
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
1936
|
+
if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|
|
1937
|
+
const previousBasedir = opts.tailwindcssBasedir;
|
|
1938
|
+
opts.tailwindcssBasedir = nextTailwindcssBasedir;
|
|
1939
|
+
debug2(
|
|
1940
|
+
"align tailwindcss basedir with vite root: %s -> %s",
|
|
1941
|
+
_nullishCoalesce(previousBasedir, () => ( "undefined")),
|
|
1942
|
+
nextTailwindcssBasedir
|
|
1943
|
+
);
|
|
1944
|
+
await refreshRuntimeState(true);
|
|
1945
|
+
}
|
|
1380
1946
|
}
|
|
1381
1947
|
if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
|
|
1382
1948
|
const postcssPlugins = config.css.postcss.plugins;
|
|
@@ -1386,7 +1952,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1386
1952
|
));
|
|
1387
1953
|
if (idx > -1) {
|
|
1388
1954
|
postcssPlugins.splice(idx, 1, _htmltransform2.default.call(void 0, ));
|
|
1389
|
-
|
|
1955
|
+
debug2("remove postcss-html-transform plugin from vite config");
|
|
1390
1956
|
}
|
|
1391
1957
|
}
|
|
1392
1958
|
},
|
|
@@ -1394,7 +1960,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1394
1960
|
opts,
|
|
1395
1961
|
runtimeState,
|
|
1396
1962
|
ensureRuntimeClassSet,
|
|
1397
|
-
|
|
1963
|
+
ensureBundleRuntimeClassSet,
|
|
1964
|
+
debug: debug2,
|
|
1398
1965
|
getResolvedConfig
|
|
1399
1966
|
})
|
|
1400
1967
|
}
|