weapp-tailwindcss 4.5.0 → 4.5.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-XYYHPJOQ.js → chunk-A3TJT6B6.js} +77 -189
- package/dist/{chunk-DKUPUV4T.mjs → chunk-CKTI35D3.mjs} +1 -1
- package/dist/{chunk-IO3RB6AQ.js → chunk-FOUWGCIJ.js} +2 -2
- package/dist/{chunk-OHUQYFGP.mjs → chunk-GGIH6WLF.mjs} +1 -1
- package/dist/chunk-KBR4YB6N.js +178 -0
- package/dist/{chunk-Z7Q5UFNU.mjs → chunk-L4AXTSIM.mjs} +79 -188
- package/dist/chunk-S2WEN6NJ.mjs +175 -0
- package/dist/{chunk-MRKRCDIE.js → chunk-TGTFIOJU.js} +2 -2
- package/dist/{chunk-RQGIJKLG.mjs → chunk-WFZ73Q6S.mjs} +1 -1
- package/dist/{chunk-4NWVZ7I2.js → chunk-ZUH5ZA7D.js} +3 -3
- package/dist/cli.js +3 -2
- package/dist/cli.mjs +2 -1
- package/dist/core.js +3 -2
- package/dist/core.mjs +2 -1
- package/dist/gulp.js +4 -3
- package/dist/gulp.mjs +3 -2
- package/dist/index.js +6 -5
- package/dist/index.mjs +5 -4
- package/dist/presets.d.mts +9 -1
- package/dist/presets.d.ts +9 -1
- package/dist/presets.js +62 -2
- package/dist/presets.mjs +60 -0
- package/dist/vite.js +4 -3
- package/dist/vite.mjs +3 -2
- package/dist/webpack.js +4 -3
- package/dist/webpack.mjs +3 -2
- package/dist/webpack4.js +3 -2
- package/dist/webpack4.mjs +2 -1
- package/package.json +3 -3
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
replaceWxml
|
|
3
3
|
} from "./chunk-Q67IXIAH.mjs";
|
|
4
|
+
import {
|
|
5
|
+
createTailwindcssPatcherFromContext
|
|
6
|
+
} from "./chunk-S2WEN6NJ.mjs";
|
|
4
7
|
import {
|
|
5
8
|
getDefaultOptions
|
|
6
9
|
} from "./chunk-IHKVNALD.mjs";
|
|
@@ -10,7 +13,7 @@ import {
|
|
|
10
13
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
11
14
|
|
|
12
15
|
// src/context/index.ts
|
|
13
|
-
import { logger as
|
|
16
|
+
import { logger as logger2, pc } from "@weapp-tailwindcss/logger";
|
|
14
17
|
import { useMangleStore } from "@weapp-tailwindcss/mangle";
|
|
15
18
|
|
|
16
19
|
// src/cache/index.ts
|
|
@@ -277,15 +280,15 @@ function shouldTransformClassName(candidate, {
|
|
|
277
280
|
}
|
|
278
281
|
return !jsPreserveClass?.(candidate);
|
|
279
282
|
}
|
|
280
|
-
function extractLiteralValue(
|
|
283
|
+
function extractLiteralValue(path, { unescapeUnicode, arbitraryValues }) {
|
|
281
284
|
const allowDoubleQuotes = arbitraryValues?.allowDoubleQuotes;
|
|
282
285
|
let offset = 0;
|
|
283
286
|
let original;
|
|
284
|
-
if (
|
|
287
|
+
if (path.isStringLiteral()) {
|
|
285
288
|
offset = 1;
|
|
286
|
-
original =
|
|
287
|
-
} else if (
|
|
288
|
-
original =
|
|
289
|
+
original = path.node.value;
|
|
290
|
+
} else if (path.isTemplateElement()) {
|
|
291
|
+
original = path.node.value.raw;
|
|
289
292
|
} else {
|
|
290
293
|
original = "";
|
|
291
294
|
}
|
|
@@ -300,7 +303,7 @@ function extractLiteralValue(path2, { unescapeUnicode, arbitraryValues }) {
|
|
|
300
303
|
original
|
|
301
304
|
};
|
|
302
305
|
}
|
|
303
|
-
function replaceHandleValue(
|
|
306
|
+
function replaceHandleValue(path, options) {
|
|
304
307
|
const {
|
|
305
308
|
escapeMap,
|
|
306
309
|
mangleContext,
|
|
@@ -310,8 +313,8 @@ function replaceHandleValue(path2, options) {
|
|
|
310
313
|
if (!alwaysEscape && (!classNameSet || classNameSet.size === 0)) {
|
|
311
314
|
return void 0;
|
|
312
315
|
}
|
|
313
|
-
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(
|
|
314
|
-
if (hasIgnoreComment(
|
|
316
|
+
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path, options);
|
|
317
|
+
if (hasIgnoreComment(path.node)) {
|
|
315
318
|
return void 0;
|
|
316
319
|
}
|
|
317
320
|
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
@@ -344,7 +347,7 @@ function replaceHandleValue(path2, options) {
|
|
|
344
347
|
mutated = true;
|
|
345
348
|
}
|
|
346
349
|
}
|
|
347
|
-
const node =
|
|
350
|
+
const node = path.node;
|
|
348
351
|
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
349
352
|
return void 0;
|
|
350
353
|
}
|
|
@@ -358,7 +361,7 @@ function replaceHandleValue(path2, options) {
|
|
|
358
361
|
start,
|
|
359
362
|
end,
|
|
360
363
|
value,
|
|
361
|
-
path
|
|
364
|
+
path
|
|
362
365
|
};
|
|
363
366
|
}
|
|
364
367
|
|
|
@@ -670,35 +673,35 @@ var NodePathWalker = class {
|
|
|
670
673
|
this.visited = /* @__PURE__ */ new WeakSet();
|
|
671
674
|
this.isIgnoredCallIdentifier = createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true });
|
|
672
675
|
}
|
|
673
|
-
walkVariableDeclarator(
|
|
674
|
-
const init =
|
|
676
|
+
walkVariableDeclarator(path) {
|
|
677
|
+
const init = path.get("init");
|
|
675
678
|
this.walkNode(init);
|
|
676
679
|
}
|
|
677
|
-
walkTemplateLiteral(
|
|
678
|
-
for (const exp of
|
|
680
|
+
walkTemplateLiteral(path) {
|
|
681
|
+
for (const exp of path.get("expressions")) {
|
|
679
682
|
this.walkNode(exp);
|
|
680
683
|
}
|
|
681
|
-
for (const quasis of
|
|
684
|
+
for (const quasis of path.get("quasis")) {
|
|
682
685
|
this.callback(quasis);
|
|
683
686
|
}
|
|
684
687
|
}
|
|
685
|
-
walkStringLiteral(
|
|
686
|
-
this.callback(
|
|
688
|
+
walkStringLiteral(path) {
|
|
689
|
+
this.callback(path);
|
|
687
690
|
}
|
|
688
|
-
walkBinaryExpression(
|
|
689
|
-
const left =
|
|
691
|
+
walkBinaryExpression(path) {
|
|
692
|
+
const left = path.get("left");
|
|
690
693
|
this.walkNode(left);
|
|
691
|
-
const right =
|
|
694
|
+
const right = path.get("right");
|
|
692
695
|
this.walkNode(right);
|
|
693
696
|
}
|
|
694
|
-
walkLogicalExpression(
|
|
695
|
-
const left =
|
|
697
|
+
walkLogicalExpression(path) {
|
|
698
|
+
const left = path.get("left");
|
|
696
699
|
this.walkNode(left);
|
|
697
|
-
const right =
|
|
700
|
+
const right = path.get("right");
|
|
698
701
|
this.walkNode(right);
|
|
699
702
|
}
|
|
700
|
-
walkObjectExpression(
|
|
701
|
-
const props =
|
|
703
|
+
walkObjectExpression(path) {
|
|
704
|
+
const props = path.get("properties");
|
|
702
705
|
for (const prop of props) {
|
|
703
706
|
if (prop.isObjectProperty()) {
|
|
704
707
|
const key = prop.get("key");
|
|
@@ -708,8 +711,8 @@ var NodePathWalker = class {
|
|
|
708
711
|
}
|
|
709
712
|
}
|
|
710
713
|
}
|
|
711
|
-
walkArrayExpression(
|
|
712
|
-
const elements =
|
|
714
|
+
walkArrayExpression(path) {
|
|
715
|
+
const elements = path.get("elements");
|
|
713
716
|
for (const element of elements) {
|
|
714
717
|
this.walkNode(element);
|
|
715
718
|
}
|
|
@@ -782,33 +785,33 @@ var NodePathWalker = class {
|
|
|
782
785
|
/**
|
|
783
786
|
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
784
787
|
*/
|
|
785
|
-
walkCallExpression(
|
|
786
|
-
const calleePath =
|
|
788
|
+
walkCallExpression(path) {
|
|
789
|
+
const calleePath = path.get("callee");
|
|
787
790
|
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
788
|
-
for (const arg of
|
|
791
|
+
for (const arg of path.get("arguments")) {
|
|
789
792
|
this.walkNode(arg);
|
|
790
793
|
}
|
|
791
794
|
}
|
|
792
795
|
}
|
|
793
|
-
walkExportDeclaration(
|
|
794
|
-
if (
|
|
795
|
-
if (
|
|
796
|
-
this.walkExportNamedDeclaration(
|
|
797
|
-
} else if (
|
|
798
|
-
this.walkExportDefaultDeclaration(
|
|
799
|
-
} else if (
|
|
800
|
-
this.walkExportAllDeclaration(
|
|
796
|
+
walkExportDeclaration(path) {
|
|
797
|
+
if (path.isExportDeclaration()) {
|
|
798
|
+
if (path.isExportNamedDeclaration()) {
|
|
799
|
+
this.walkExportNamedDeclaration(path);
|
|
800
|
+
} else if (path.isExportDefaultDeclaration()) {
|
|
801
|
+
this.walkExportDefaultDeclaration(path);
|
|
802
|
+
} else if (path.isExportAllDeclaration()) {
|
|
803
|
+
this.walkExportAllDeclaration(path);
|
|
801
804
|
}
|
|
802
805
|
}
|
|
803
806
|
}
|
|
804
|
-
walkExportNamedDeclaration(
|
|
805
|
-
const declaration =
|
|
807
|
+
walkExportNamedDeclaration(path) {
|
|
808
|
+
const declaration = path.get("declaration");
|
|
806
809
|
if (declaration.isVariableDeclaration()) {
|
|
807
810
|
for (const decl of declaration.get("declarations")) {
|
|
808
811
|
this.walkNode(decl);
|
|
809
812
|
}
|
|
810
813
|
}
|
|
811
|
-
const specifiers =
|
|
814
|
+
const specifiers = path.get("specifiers");
|
|
812
815
|
for (const spec of specifiers) {
|
|
813
816
|
if (spec.isExportSpecifier()) {
|
|
814
817
|
const local = spec.get("local");
|
|
@@ -818,20 +821,20 @@ var NodePathWalker = class {
|
|
|
818
821
|
}
|
|
819
822
|
}
|
|
820
823
|
}
|
|
821
|
-
walkExportDefaultDeclaration(
|
|
822
|
-
const decl =
|
|
824
|
+
walkExportDefaultDeclaration(path) {
|
|
825
|
+
const decl = path.get("declaration");
|
|
823
826
|
if (decl.isIdentifier()) {
|
|
824
827
|
this.walkNode(decl);
|
|
825
828
|
} else {
|
|
826
829
|
this.walkNode(decl);
|
|
827
830
|
}
|
|
828
831
|
}
|
|
829
|
-
walkExportAllDeclaration(
|
|
830
|
-
const source =
|
|
832
|
+
walkExportAllDeclaration(path) {
|
|
833
|
+
const source = path.get("source");
|
|
831
834
|
if (source.isStringLiteral()) {
|
|
832
835
|
this.imports.add(
|
|
833
836
|
{
|
|
834
|
-
declaration:
|
|
837
|
+
declaration: path,
|
|
835
838
|
source: source.node.value,
|
|
836
839
|
type: "ExportAllDeclaration"
|
|
837
840
|
}
|
|
@@ -874,15 +877,15 @@ function isEvalPath(p) {
|
|
|
874
877
|
}
|
|
875
878
|
return false;
|
|
876
879
|
}
|
|
877
|
-
function createEvalReplacementToken(
|
|
878
|
-
const node =
|
|
880
|
+
function createEvalReplacementToken(path, updated) {
|
|
881
|
+
const node = path.node;
|
|
879
882
|
let offset = 0;
|
|
880
883
|
let original;
|
|
881
|
-
if (
|
|
884
|
+
if (path.isStringLiteral()) {
|
|
882
885
|
offset = 1;
|
|
883
|
-
original =
|
|
884
|
-
} else if (
|
|
885
|
-
original =
|
|
886
|
+
original = path.node.value;
|
|
887
|
+
} else if (path.isTemplateElement()) {
|
|
888
|
+
original = path.node.value.raw;
|
|
886
889
|
} else {
|
|
887
890
|
original = "";
|
|
888
891
|
}
|
|
@@ -897,16 +900,16 @@ function createEvalReplacementToken(path2, updated) {
|
|
|
897
900
|
if (original === updated) {
|
|
898
901
|
return void 0;
|
|
899
902
|
}
|
|
900
|
-
const value =
|
|
903
|
+
const value = path.isStringLiteral() ? jsStringEscape2(updated) : updated;
|
|
901
904
|
return {
|
|
902
905
|
start,
|
|
903
906
|
end,
|
|
904
907
|
value,
|
|
905
|
-
path
|
|
908
|
+
path
|
|
906
909
|
};
|
|
907
910
|
}
|
|
908
|
-
function handleEvalStringLiteral(
|
|
909
|
-
const { code } = jsHandler(
|
|
911
|
+
function handleEvalStringLiteral(path, options, updater) {
|
|
912
|
+
const { code } = jsHandler(path.node.value, {
|
|
910
913
|
...options,
|
|
911
914
|
needEscaped: false,
|
|
912
915
|
generateMap: false
|
|
@@ -914,26 +917,26 @@ function handleEvalStringLiteral(path2, options, updater) {
|
|
|
914
917
|
if (!code) {
|
|
915
918
|
return;
|
|
916
919
|
}
|
|
917
|
-
const token = createEvalReplacementToken(
|
|
920
|
+
const token = createEvalReplacementToken(path, code);
|
|
918
921
|
if (token) {
|
|
919
922
|
updater.addToken(token);
|
|
920
923
|
}
|
|
921
924
|
}
|
|
922
|
-
function handleEvalTemplateElement(
|
|
923
|
-
const { code } = jsHandler(
|
|
925
|
+
function handleEvalTemplateElement(path, options, updater) {
|
|
926
|
+
const { code } = jsHandler(path.node.value.raw, {
|
|
924
927
|
...options,
|
|
925
928
|
generateMap: false
|
|
926
929
|
});
|
|
927
930
|
if (!code) {
|
|
928
931
|
return;
|
|
929
932
|
}
|
|
930
|
-
const token = createEvalReplacementToken(
|
|
933
|
+
const token = createEvalReplacementToken(path, code);
|
|
931
934
|
if (token) {
|
|
932
935
|
updater.addToken(token);
|
|
933
936
|
}
|
|
934
937
|
}
|
|
935
|
-
function walkEvalExpression(
|
|
936
|
-
|
|
938
|
+
function walkEvalExpression(path, options, updater) {
|
|
939
|
+
path.traverse({
|
|
937
940
|
StringLiteral(innerPath) {
|
|
938
941
|
handleEvalStringLiteral(innerPath, options, updater);
|
|
939
942
|
},
|
|
@@ -948,9 +951,9 @@ function analyzeSource(ast, options) {
|
|
|
948
951
|
const walker = new NodePathWalker(
|
|
949
952
|
{
|
|
950
953
|
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
951
|
-
callback(
|
|
952
|
-
if (
|
|
953
|
-
ignoredPaths.add(
|
|
954
|
+
callback(path) {
|
|
955
|
+
if (path.isStringLiteral() || path.isTemplateElement()) {
|
|
956
|
+
ignoredPaths.add(path);
|
|
954
957
|
}
|
|
955
958
|
}
|
|
956
959
|
}
|
|
@@ -1021,15 +1024,15 @@ function processUpdatedSource(rawSource, options, analysis) {
|
|
|
1021
1024
|
const ms = new MagicString(rawSource);
|
|
1022
1025
|
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
1023
1026
|
const replacementTokens = [];
|
|
1024
|
-
for (const
|
|
1025
|
-
if (ignoredPaths.has(
|
|
1027
|
+
for (const path of targetPaths) {
|
|
1028
|
+
if (ignoredPaths.has(path)) {
|
|
1026
1029
|
continue;
|
|
1027
1030
|
}
|
|
1028
1031
|
const token = replaceHandleValue(
|
|
1029
|
-
|
|
1032
|
+
path,
|
|
1030
1033
|
{
|
|
1031
1034
|
...options,
|
|
1032
|
-
needEscaped:
|
|
1035
|
+
needEscaped: path.isStringLiteral() ? options.needEscaped ?? true : false
|
|
1033
1036
|
}
|
|
1034
1037
|
);
|
|
1035
1038
|
if (token) {
|
|
@@ -1281,16 +1284,16 @@ function generateCode(match, options = {}) {
|
|
|
1281
1284
|
const ast = parseExpression(match);
|
|
1282
1285
|
const jsTokenUpdater = new JsTokenUpdater();
|
|
1283
1286
|
traverse(ast, {
|
|
1284
|
-
StringLiteral(
|
|
1285
|
-
if (t.isMemberExpression(
|
|
1287
|
+
StringLiteral(path) {
|
|
1288
|
+
if (t.isMemberExpression(path.parent)) {
|
|
1286
1289
|
return;
|
|
1287
1290
|
}
|
|
1288
|
-
if (t.isBinaryExpression(
|
|
1291
|
+
if (t.isBinaryExpression(path.parent) && (t.isConditionalExpression(path.parentPath?.parent) || t.isLogicalExpression(path.parentPath?.parent))) {
|
|
1289
1292
|
return;
|
|
1290
1293
|
}
|
|
1291
1294
|
jsTokenUpdater.addToken(
|
|
1292
1295
|
replaceHandleValue(
|
|
1293
|
-
|
|
1296
|
+
path,
|
|
1294
1297
|
{
|
|
1295
1298
|
mangleContext: options.mangleContext,
|
|
1296
1299
|
escapeMap: options.escapeMap,
|
|
@@ -1604,118 +1607,6 @@ function applyLoggerLevel(logLevel) {
|
|
|
1604
1607
|
logger.level = loggerLevelMap[logLevel ?? "info"] ?? loggerLevelMap.info;
|
|
1605
1608
|
}
|
|
1606
1609
|
|
|
1607
|
-
// src/tailwindcss/index.ts
|
|
1608
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
1609
|
-
|
|
1610
|
-
// src/tailwindcss/patcher.ts
|
|
1611
|
-
import path from "path";
|
|
1612
|
-
import process from "process";
|
|
1613
|
-
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
1614
|
-
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
1615
|
-
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
1616
|
-
function createFallbackTailwindcssPatcher() {
|
|
1617
|
-
const packageInfo = {
|
|
1618
|
-
name: "tailwindcss",
|
|
1619
|
-
version: void 0,
|
|
1620
|
-
rootPath: "",
|
|
1621
|
-
packageJsonPath: "",
|
|
1622
|
-
packageJson: {}
|
|
1623
|
-
};
|
|
1624
|
-
return {
|
|
1625
|
-
packageInfo,
|
|
1626
|
-
majorVersion: 0,
|
|
1627
|
-
patch() {
|
|
1628
|
-
},
|
|
1629
|
-
async getClassSet() {
|
|
1630
|
-
return /* @__PURE__ */ new Set();
|
|
1631
|
-
},
|
|
1632
|
-
getClassSetV3() {
|
|
1633
|
-
return /* @__PURE__ */ new Set();
|
|
1634
|
-
},
|
|
1635
|
-
async extract(_options) {
|
|
1636
|
-
const classSet = /* @__PURE__ */ new Set();
|
|
1637
|
-
return {
|
|
1638
|
-
classList: [],
|
|
1639
|
-
classSet
|
|
1640
|
-
};
|
|
1641
|
-
}
|
|
1642
|
-
};
|
|
1643
|
-
}
|
|
1644
|
-
var hasLoggedMissingTailwind = false;
|
|
1645
|
-
function createTailwindcssPatcher(options) {
|
|
1646
|
-
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
1647
|
-
const cache = {};
|
|
1648
|
-
if (cacheDir) {
|
|
1649
|
-
if (path.isAbsolute(cacheDir)) {
|
|
1650
|
-
cache.dir = cacheDir;
|
|
1651
|
-
} else if (basedir) {
|
|
1652
|
-
cache.dir = path.resolve(basedir, cacheDir);
|
|
1653
|
-
} else {
|
|
1654
|
-
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
const resolvedOptions = defuOverrideArray2(
|
|
1658
|
-
tailwindcssPatcherOptions,
|
|
1659
|
-
{
|
|
1660
|
-
cache,
|
|
1661
|
-
patch: {
|
|
1662
|
-
basedir,
|
|
1663
|
-
applyPatches: {
|
|
1664
|
-
exportContext: true,
|
|
1665
|
-
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
1666
|
-
},
|
|
1667
|
-
tailwindcss,
|
|
1668
|
-
resolve: {
|
|
1669
|
-
paths: [
|
|
1670
|
-
import.meta.url
|
|
1671
|
-
]
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
}
|
|
1675
|
-
);
|
|
1676
|
-
try {
|
|
1677
|
-
return new TailwindcssPatcher(resolvedOptions);
|
|
1678
|
-
} catch (error) {
|
|
1679
|
-
if (error instanceof Error && /tailwindcss not found/i.test(error.message)) {
|
|
1680
|
-
if (!hasLoggedMissingTailwind) {
|
|
1681
|
-
logger2.warn("Tailwind CSS \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7 Tailwind \u76F8\u5173\u8865\u4E01\u3002\u82E5\u9700\u4F7F\u7528 Tailwind \u80FD\u529B\uFF0C\u8BF7\u5B89\u88C5 tailwindcss\u3002");
|
|
1682
|
-
hasLoggedMissingTailwind = true;
|
|
1683
|
-
}
|
|
1684
|
-
return createFallbackTailwindcssPatcher();
|
|
1685
|
-
}
|
|
1686
|
-
throw error;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
|
|
1690
|
-
// src/context/tailwindcss.ts
|
|
1691
|
-
function createTailwindcssPatcherFromContext(ctx) {
|
|
1692
|
-
const {
|
|
1693
|
-
tailwindcssBasedir,
|
|
1694
|
-
supportCustomLengthUnitsPatch,
|
|
1695
|
-
tailwindcss,
|
|
1696
|
-
tailwindcssPatcherOptions,
|
|
1697
|
-
cssEntries,
|
|
1698
|
-
appType
|
|
1699
|
-
} = ctx;
|
|
1700
|
-
return createTailwindcssPatcher(
|
|
1701
|
-
{
|
|
1702
|
-
basedir: tailwindcssBasedir,
|
|
1703
|
-
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
1704
|
-
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
1705
|
-
tailwindcss: defuOverrideArray(
|
|
1706
|
-
tailwindcss,
|
|
1707
|
-
{
|
|
1708
|
-
v4: {
|
|
1709
|
-
base: tailwindcssBasedir,
|
|
1710
|
-
cssEntries
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
),
|
|
1714
|
-
tailwindcssPatcherOptions
|
|
1715
|
-
}
|
|
1716
|
-
);
|
|
1717
|
-
}
|
|
1718
|
-
|
|
1719
1610
|
// src/context/index.ts
|
|
1720
1611
|
var DEFAULT_SPACING_VARIABLE = "--spacing";
|
|
1721
1612
|
function matchesSpacingToken(token) {
|
|
@@ -1762,9 +1653,9 @@ function getCompilerContext(opts) {
|
|
|
1762
1653
|
applyLoggerLevel(ctx.logLevel);
|
|
1763
1654
|
const twPatcher = createTailwindcssPatcherFromContext(ctx);
|
|
1764
1655
|
if (twPatcher.packageInfo?.version) {
|
|
1765
|
-
|
|
1656
|
+
logger2.success(`\u5F53\u524D\u4F7F\u7528 ${pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${pc.underline(pc.bold(pc.green(twPatcher.packageInfo.version)))}`);
|
|
1766
1657
|
} else {
|
|
1767
|
-
|
|
1658
|
+
logger2.warn(`${pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
|
|
1768
1659
|
}
|
|
1769
1660
|
let cssCalcOptions = ctx.cssCalc ?? twPatcher.majorVersion === 4;
|
|
1770
1661
|
if (twPatcher.majorVersion === 4 && cssCalcOptions) {
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defuOverrideArray
|
|
3
|
+
} from "./chunk-ZNKIYZRQ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/context/tailwindcss.ts
|
|
6
|
+
import path2 from "path";
|
|
7
|
+
import process2 from "process";
|
|
8
|
+
|
|
9
|
+
// src/tailwindcss/index.ts
|
|
10
|
+
import { getPackageInfoSync } from "local-pkg";
|
|
11
|
+
|
|
12
|
+
// src/tailwindcss/patcher.ts
|
|
13
|
+
import path from "path";
|
|
14
|
+
import process from "process";
|
|
15
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
16
|
+
import { defuOverrideArray as defuOverrideArray2 } from "@weapp-tailwindcss/shared";
|
|
17
|
+
import { TailwindcssPatcher } from "tailwindcss-patch";
|
|
18
|
+
function createFallbackTailwindcssPatcher() {
|
|
19
|
+
const packageInfo = {
|
|
20
|
+
name: "tailwindcss",
|
|
21
|
+
version: void 0,
|
|
22
|
+
rootPath: "",
|
|
23
|
+
packageJsonPath: "",
|
|
24
|
+
packageJson: {}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
packageInfo,
|
|
28
|
+
majorVersion: 0,
|
|
29
|
+
patch() {
|
|
30
|
+
},
|
|
31
|
+
async getClassSet() {
|
|
32
|
+
return /* @__PURE__ */ new Set();
|
|
33
|
+
},
|
|
34
|
+
getClassSetV3() {
|
|
35
|
+
return /* @__PURE__ */ new Set();
|
|
36
|
+
},
|
|
37
|
+
async extract(_options) {
|
|
38
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
39
|
+
return {
|
|
40
|
+
classList: [],
|
|
41
|
+
classSet
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var hasLoggedMissingTailwind = false;
|
|
47
|
+
function createTailwindcssPatcher(options) {
|
|
48
|
+
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
49
|
+
const cache = {};
|
|
50
|
+
if (cacheDir) {
|
|
51
|
+
if (path.isAbsolute(cacheDir)) {
|
|
52
|
+
cache.dir = cacheDir;
|
|
53
|
+
} else if (basedir) {
|
|
54
|
+
cache.dir = path.resolve(basedir, cacheDir);
|
|
55
|
+
} else {
|
|
56
|
+
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (basedir) {
|
|
60
|
+
cache.cwd = basedir;
|
|
61
|
+
}
|
|
62
|
+
const resolvedOptions = defuOverrideArray2(
|
|
63
|
+
tailwindcssPatcherOptions,
|
|
64
|
+
{
|
|
65
|
+
cache,
|
|
66
|
+
patch: {
|
|
67
|
+
basedir,
|
|
68
|
+
cwd: basedir,
|
|
69
|
+
applyPatches: {
|
|
70
|
+
exportContext: true,
|
|
71
|
+
extendLengthUnits: supportCustomLengthUnitsPatch
|
|
72
|
+
},
|
|
73
|
+
tailwindcss,
|
|
74
|
+
resolve: {
|
|
75
|
+
paths: [
|
|
76
|
+
import.meta.url
|
|
77
|
+
]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
try {
|
|
83
|
+
return new TailwindcssPatcher(resolvedOptions);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof Error && /tailwindcss not found/i.test(error.message)) {
|
|
86
|
+
if (!hasLoggedMissingTailwind) {
|
|
87
|
+
logger.warn("Tailwind CSS \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7 Tailwind \u76F8\u5173\u8865\u4E01\u3002\u82E5\u9700\u4F7F\u7528 Tailwind \u80FD\u529B\uFF0C\u8BF7\u5B89\u88C5 tailwindcss\u3002");
|
|
88
|
+
hasLoggedMissingTailwind = true;
|
|
89
|
+
}
|
|
90
|
+
return createFallbackTailwindcssPatcher();
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/context/tailwindcss.ts
|
|
97
|
+
var ENV_BASEDIR_KEYS = [
|
|
98
|
+
"WEAPP_TAILWINDCSS_BASEDIR",
|
|
99
|
+
"WEAPP_TAILWINDCSS_BASE_DIR",
|
|
100
|
+
"TAILWINDCSS_BASEDIR",
|
|
101
|
+
"TAILWINDCSS_BASE_DIR",
|
|
102
|
+
"UNI_INPUT_DIR",
|
|
103
|
+
"UNI_INPUT_ROOT",
|
|
104
|
+
"UNI_CLI_ROOT",
|
|
105
|
+
"UNI_APP_INPUT_DIR",
|
|
106
|
+
"INIT_CWD",
|
|
107
|
+
"PWD"
|
|
108
|
+
];
|
|
109
|
+
function pickEnvBasedir() {
|
|
110
|
+
for (const key of ENV_BASEDIR_KEYS) {
|
|
111
|
+
const value = process2.env[key];
|
|
112
|
+
if (value && path2.isAbsolute(value)) {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
function resolveTailwindcssBasedir(basedir) {
|
|
119
|
+
const envBasedir = pickEnvBasedir();
|
|
120
|
+
const anchor = envBasedir ?? process2.cwd();
|
|
121
|
+
if (basedir && basedir.trim().length > 0) {
|
|
122
|
+
if (path2.isAbsolute(basedir)) {
|
|
123
|
+
return path2.normalize(basedir);
|
|
124
|
+
}
|
|
125
|
+
return path2.resolve(anchor, basedir);
|
|
126
|
+
}
|
|
127
|
+
if (envBasedir) {
|
|
128
|
+
return path2.normalize(envBasedir);
|
|
129
|
+
}
|
|
130
|
+
return path2.normalize(process2.cwd());
|
|
131
|
+
}
|
|
132
|
+
function createTailwindcssPatcherFromContext(ctx) {
|
|
133
|
+
const {
|
|
134
|
+
tailwindcssBasedir,
|
|
135
|
+
supportCustomLengthUnitsPatch,
|
|
136
|
+
tailwindcss,
|
|
137
|
+
tailwindcssPatcherOptions,
|
|
138
|
+
cssEntries,
|
|
139
|
+
appType
|
|
140
|
+
} = ctx;
|
|
141
|
+
const resolvedTailwindcssBasedir = resolveTailwindcssBasedir(tailwindcssBasedir);
|
|
142
|
+
ctx.tailwindcssBasedir = resolvedTailwindcssBasedir;
|
|
143
|
+
const defaultTailwindcssConfig = {
|
|
144
|
+
v2: {
|
|
145
|
+
cwd: resolvedTailwindcssBasedir
|
|
146
|
+
},
|
|
147
|
+
v3: {
|
|
148
|
+
cwd: resolvedTailwindcssBasedir
|
|
149
|
+
},
|
|
150
|
+
v4: {
|
|
151
|
+
base: resolvedTailwindcssBasedir,
|
|
152
|
+
cssEntries
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
if (cssEntries?.length && (tailwindcss == null || tailwindcss.version == null)) {
|
|
156
|
+
defaultTailwindcssConfig.version = 4;
|
|
157
|
+
}
|
|
158
|
+
return createTailwindcssPatcher(
|
|
159
|
+
{
|
|
160
|
+
basedir: resolvedTailwindcssBasedir,
|
|
161
|
+
cacheDir: appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0,
|
|
162
|
+
supportCustomLengthUnitsPatch: supportCustomLengthUnitsPatch ?? true,
|
|
163
|
+
tailwindcss: defuOverrideArray(
|
|
164
|
+
tailwindcss,
|
|
165
|
+
defaultTailwindcssConfig
|
|
166
|
+
),
|
|
167
|
+
tailwindcssPatcherOptions
|
|
168
|
+
}
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export {
|
|
173
|
+
resolveTailwindcssBasedir,
|
|
174
|
+
createTailwindcssPatcherFromContext
|
|
175
|
+
};
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var _chunk2NRTWL47js = require('./chunk-2NRTWL47.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkA3TJT6B6js = require('./chunk-A3TJT6B6.js');
|
|
8
8
|
|
|
9
9
|
// src/bundlers/gulp/index.ts
|
|
10
10
|
var _buffer = require('buffer');
|
|
@@ -15,7 +15,7 @@ var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
|
|
|
15
15
|
var debug = _chunk2NRTWL47js.createDebug.call(void 0, );
|
|
16
16
|
var Transform = _stream2.default.Transform;
|
|
17
17
|
function createPlugins(options = {}) {
|
|
18
|
-
const opts =
|
|
18
|
+
const opts = _chunkA3TJT6B6js.getCompilerContext.call(void 0, options);
|
|
19
19
|
const { templateHandler, styleHandler, jsHandler, setMangleRuntimeSet, cache, twPatcher } = opts;
|
|
20
20
|
let runtimeSet = /* @__PURE__ */ new Set();
|
|
21
21
|
twPatcher.patch();
|