weapp-tailwindcss 4.11.0 → 4.11.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-2PXISDSY.js → chunk-3QHYEMEW.js} +28 -28
- package/dist/{chunk-LL3QUKJI.js → chunk-A5PB4KZT.js} +2 -0
- package/dist/{chunk-KWSWZP5H.mjs → chunk-AB2RGZQO.mjs} +92 -46
- package/dist/{chunk-ZQAWDXIW.js → chunk-AV3XB6EQ.js} +3 -3
- package/dist/{chunk-MAIS4SDW.mjs → chunk-JIERVBTX.mjs} +1 -1
- package/dist/{chunk-C4CWDYUP.js → chunk-SUKOZ6OG.js} +6 -6
- package/dist/{chunk-Z6RS5OPN.js → chunk-TT5WHNGS.js} +61 -15
- package/dist/{chunk-Y75XZ6KA.mjs → chunk-VGPAKLMZ.mjs} +2 -2
- package/dist/{chunk-UO725AHQ.mjs → chunk-W3DXDWYC.mjs} +154 -38
- package/dist/{chunk-GVYD6TY7.js → chunk-WJIRXC26.js} +172 -56
- package/dist/{chunk-23K4XDKF.mjs → chunk-XAKAD2CR.mjs} +2 -0
- package/dist/{chunk-FTFADUJ4.mjs → chunk-ZZ36BKM5.mjs} +1 -1
- package/dist/cli.js +115 -82
- package/dist/cli.mjs +115 -82
- package/dist/core.d.mts +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +7 -7
- package/dist/core.mjs +2 -2
- package/dist/defaults.d.mts +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +2 -2
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.d.mts +1 -1
- package/dist/gulp.d.ts +1 -1
- package/dist/gulp.js +4 -4
- package/dist/gulp.mjs +3 -3
- package/dist/{index-D8E0GGqB.d.mts → index-CoXntW_P.d.mts} +1 -1
- package/dist/{index-D8E0GGqB.d.ts → index-CoXntW_P.d.ts} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -7
- package/dist/index.mjs +6 -6
- package/dist/presets.d.mts +1 -1
- package/dist/presets.d.ts +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +4 -4
- package/dist/vite.mjs +3 -3
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +5 -5
- package/dist/webpack.mjs +4 -4
- package/dist/webpack4.d.mts +1 -1
- package/dist/webpack4.d.ts +1 -1
- package/dist/webpack4.js +25 -25
- package/dist/webpack4.mjs +3 -3
- package/package.json +3 -3
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
var _chunkQK6VNNNLjs = require('./chunk-QK6VNNNL.js');
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _chunkA5PB4KZTjs = require('./chunk-A5PB4KZT.js');
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -361,9 +361,51 @@ function initializeCache(cacheConfig) {
|
|
|
361
361
|
return cacheConfig;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
-
// src/tailwindcss/
|
|
364
|
+
// src/tailwindcss/runtime-logs.ts
|
|
365
365
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
366
366
|
|
|
367
|
+
var runtimeLogDedupeHolder = globalThis;
|
|
368
|
+
var runtimeLogDedupe = _nullishCoalesce(runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__, () => ( (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set())));
|
|
369
|
+
function createRuntimeLogKey(category, baseDir, rootPath, version) {
|
|
370
|
+
return JSON.stringify([
|
|
371
|
+
category,
|
|
372
|
+
_nullishCoalesce(baseDir, () => ( _process2.default.cwd())),
|
|
373
|
+
_nullishCoalesce(rootPath, () => ( "")),
|
|
374
|
+
_nullishCoalesce(version, () => ( ""))
|
|
375
|
+
]);
|
|
376
|
+
}
|
|
377
|
+
function markRuntimeLog(category, baseDir, rootPath, version) {
|
|
378
|
+
const key = createRuntimeLogKey(category, baseDir, rootPath, version);
|
|
379
|
+
if (runtimeLogDedupe.has(key)) {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
runtimeLogDedupe.add(key);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
function logRuntimeTailwindcssTarget(baseDir, rootPath, version) {
|
|
386
|
+
if (!markRuntimeLog("target", baseDir, rootPath, version)) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const versionText = version ? ` (v${version})` : "";
|
|
390
|
+
_logger.logger.info("%s \u4F7F\u7528 Tailwind CSS%s", "Weapp-tailwindcss", versionText);
|
|
391
|
+
}
|
|
392
|
+
function logRuntimeTailwindcssVersion(baseDir, rootPath, version) {
|
|
393
|
+
if (version) {
|
|
394
|
+
if (!markRuntimeLog("version", baseDir, rootPath, version)) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
_logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(version)))}`);
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
400
|
+
if (!markRuntimeLog("missing", baseDir, rootPath, version)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
_logger.logger.warn(`${_logger.pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/tailwindcss/targets.ts
|
|
407
|
+
|
|
408
|
+
|
|
367
409
|
|
|
368
410
|
// src/tailwindcss/targets/paths.ts
|
|
369
411
|
var _fs = require('fs');
|
|
@@ -423,7 +465,7 @@ function getRecordFileCandidates(baseDir) {
|
|
|
423
465
|
// package.json
|
|
424
466
|
var package_default = {
|
|
425
467
|
name: "weapp-tailwindcss",
|
|
426
|
-
version: "4.11.
|
|
468
|
+
version: "4.11.2",
|
|
427
469
|
description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
|
|
428
470
|
author: "ice breaker <1324318532@qq.com>",
|
|
429
471
|
license: "MIT",
|
|
@@ -618,7 +660,7 @@ var package_default = {
|
|
|
618
660
|
"@babel/parser": "~7.29.2",
|
|
619
661
|
"@babel/traverse": "~7.29.0",
|
|
620
662
|
"@babel/types": "~7.29.0",
|
|
621
|
-
"@tailwindcss-mangle/config": "^
|
|
663
|
+
"@tailwindcss-mangle/config": "^7.0.0",
|
|
622
664
|
"@vue/compiler-dom": "catalog:vue3",
|
|
623
665
|
"@vue/compiler-sfc": "catalog:vue3",
|
|
624
666
|
"@weapp-core/escape": "~7.0.0",
|
|
@@ -814,7 +856,7 @@ function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
|
814
856
|
// src/tailwindcss/targets.ts
|
|
815
857
|
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
816
858
|
const packageInfo = _optionalChain([patcher, 'optionalAccess', _20 => _20.packageInfo]);
|
|
817
|
-
const label = kind === "cli" ? "weapp-tw patch" : "tailwindcss
|
|
859
|
+
const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
|
|
818
860
|
if (!_optionalChain([packageInfo, 'optionalAccess', _21 => _21.rootPath])) {
|
|
819
861
|
_logger.logger.warn(
|
|
820
862
|
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
@@ -825,6 +867,10 @@ function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
|
825
867
|
}
|
|
826
868
|
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
827
869
|
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
870
|
+
if (kind === "runtime") {
|
|
871
|
+
logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
828
874
|
_logger.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
829
875
|
}
|
|
830
876
|
|
|
@@ -3713,18 +3759,18 @@ async function clearTailwindcssPatcherCache(patcher, options) {
|
|
|
3713
3759
|
function createInternalCompilerContext(opts) {
|
|
3714
3760
|
const ctx = _chunkDYLQ6UOIjs.defuOverrideArray.call(void 0,
|
|
3715
3761
|
opts,
|
|
3716
|
-
|
|
3762
|
+
_chunkA5PB4KZTjs.getDefaultOptions.call(void 0, ),
|
|
3717
3763
|
{}
|
|
3718
3764
|
);
|
|
3719
3765
|
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
3720
3766
|
applyLoggerLevel(ctx.logLevel);
|
|
3721
3767
|
const twPatcher = _chunkQK6VNNNLjs.createTailwindcssPatcherFromContext.call(void 0, ctx);
|
|
3722
3768
|
logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3769
|
+
logRuntimeTailwindcssVersion(
|
|
3770
|
+
ctx.tailwindcssBasedir,
|
|
3771
|
+
_optionalChain([twPatcher, 'access', _119 => _119.packageInfo, 'optionalAccess', _120 => _120.rootPath]),
|
|
3772
|
+
_optionalChain([twPatcher, 'access', _121 => _121.packageInfo, 'optionalAccess', _122 => _122.version])
|
|
3773
|
+
);
|
|
3728
3774
|
_chunkQK6VNNNLjs.warnMissingCssEntries.call(void 0, ctx, twPatcher);
|
|
3729
3775
|
const cssCalcOptions = _chunkQK6VNNNLjs.applyV4CssCalcDefaults.call(void 0, ctx.cssCalc, twPatcher);
|
|
3730
3776
|
ctx.cssCalc = cssCalcOptions;
|
|
@@ -3742,7 +3788,7 @@ function createInternalCompilerContext(opts) {
|
|
|
3742
3788
|
ctx.twPatcher = twPatcher;
|
|
3743
3789
|
const refreshTailwindcssPatcher = async (options) => {
|
|
3744
3790
|
const previousPatcher = ctx.twPatcher;
|
|
3745
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
3791
|
+
if (_optionalChain([options, 'optionalAccess', _123 => _123.clearCache]) !== false) {
|
|
3746
3792
|
await clearTailwindcssPatcherCache(previousPatcher);
|
|
3747
3793
|
}
|
|
3748
3794
|
_chunkQK6VNNNLjs.invalidateRuntimeClassSet.call(void 0, previousPatcher);
|
|
@@ -3765,11 +3811,11 @@ function getCompilerContext(opts) {
|
|
|
3765
3811
|
// src/tailwindcss/recorder.ts
|
|
3766
3812
|
function setupPatchRecorder(patcher, baseDir, options) {
|
|
3767
3813
|
const recorder = createPatchTargetRecorder(baseDir, patcher, options);
|
|
3768
|
-
if (_optionalChain([recorder, 'optionalAccess',
|
|
3769
|
-
const prefix = _optionalChain([options, 'optionalAccess',
|
|
3814
|
+
if (_optionalChain([recorder, 'optionalAccess', _124 => _124.message]) && _optionalChain([options, 'optionalAccess', _125 => _125.logMessage]) !== false) {
|
|
3815
|
+
const prefix = _optionalChain([options, 'optionalAccess', _126 => _126.messagePrefix]) ? `${options.messagePrefix} ` : "";
|
|
3770
3816
|
_chunkQK6VNNNLjs.logger.info("%s%s", prefix, recorder.message);
|
|
3771
3817
|
}
|
|
3772
|
-
const onPatchCompleted = _optionalChain([recorder, 'optionalAccess',
|
|
3818
|
+
const onPatchCompleted = _optionalChain([recorder, 'optionalAccess', _127 => _127.onPatched]) ? async () => {
|
|
3773
3819
|
await recorder.onPatched();
|
|
3774
3820
|
} : void 0;
|
|
3775
3821
|
const patchPromise = patcher ? createTailwindPatchPromise(patcher, onPatchCompleted) : Promise.resolve();
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
isMpx,
|
|
12
12
|
patchMpxLoaderResolve,
|
|
13
13
|
setupMpxTailwindcssRedirect
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-JIERVBTX.mjs";
|
|
15
15
|
import {
|
|
16
16
|
pushConcurrentTaskFactories,
|
|
17
17
|
resolveDisabledOptions,
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
getCompilerContext,
|
|
29
29
|
pluginName,
|
|
30
30
|
setupPatchRecorder
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-AB2RGZQO.mjs";
|
|
32
32
|
import {
|
|
33
33
|
getRuntimeClassSetSignature,
|
|
34
34
|
resolveTailwindcssOptions
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
toCustomAttributesEntities,
|
|
27
27
|
traverse,
|
|
28
28
|
vitePluginName
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-AB2RGZQO.mjs";
|
|
30
30
|
import {
|
|
31
31
|
findNearestPackageRoot,
|
|
32
32
|
findTailwindConfig,
|
|
@@ -40,9 +40,10 @@ import {
|
|
|
40
40
|
} from "./chunk-OOHJLO5M.mjs";
|
|
41
41
|
|
|
42
42
|
// src/bundlers/vite/index.ts
|
|
43
|
-
import { existsSync } from "fs";
|
|
44
|
-
import
|
|
43
|
+
import { existsSync as existsSync2 } from "fs";
|
|
44
|
+
import path6 from "path";
|
|
45
45
|
import process4 from "process";
|
|
46
|
+
import { logger as logger2 } from "@weapp-tailwindcss/logger";
|
|
46
47
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
47
48
|
|
|
48
49
|
// src/uni-app-x/transform.ts
|
|
@@ -64,18 +65,18 @@ function createStableHash(input) {
|
|
|
64
65
|
}
|
|
65
66
|
return (hash >>> 0).toString(36);
|
|
66
67
|
}
|
|
67
|
-
function extractLiteralValue(
|
|
68
|
-
const allowDoubleQuotes =
|
|
69
|
-
if (
|
|
68
|
+
function extractLiteralValue(path7) {
|
|
69
|
+
const allowDoubleQuotes = path7.isTemplateElement();
|
|
70
|
+
if (path7.isStringLiteral()) {
|
|
70
71
|
return {
|
|
71
72
|
allowDoubleQuotes,
|
|
72
|
-
literal:
|
|
73
|
+
literal: path7.node.value,
|
|
73
74
|
offset: 1
|
|
74
75
|
};
|
|
75
76
|
}
|
|
76
77
|
return {
|
|
77
78
|
allowDoubleQuotes,
|
|
78
|
-
literal:
|
|
79
|
+
literal: path7.node.value.raw,
|
|
79
80
|
offset: 0
|
|
80
81
|
};
|
|
81
82
|
}
|
|
@@ -134,10 +135,10 @@ var UniAppXComponentLocalStyleCollector = class {
|
|
|
134
135
|
sourceType: options.wrapExpression ? "module" : "unambiguous"
|
|
135
136
|
});
|
|
136
137
|
const analysis = analyzeSource(ast, {}, void 0, false);
|
|
137
|
-
for (const
|
|
138
|
-
const { literal, allowDoubleQuotes } = extractLiteralValue(
|
|
138
|
+
for (const path7 of analysis.targetPaths) {
|
|
139
|
+
const { literal, allowDoubleQuotes } = extractLiteralValue(path7);
|
|
139
140
|
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
140
|
-
const classContext = options.wrapExpression || isClassContextLiteralPath(
|
|
141
|
+
const classContext = options.wrapExpression || isClassContextLiteralPath(path7);
|
|
141
142
|
for (const candidate of candidates) {
|
|
142
143
|
if (!candidate || !classContext && !isRuntimeCandidate(candidate, this.runtimeSet)) {
|
|
143
144
|
continue;
|
|
@@ -165,8 +166,8 @@ var UniAppXComponentLocalStyleCollector = class {
|
|
|
165
166
|
return rawSource;
|
|
166
167
|
}
|
|
167
168
|
const updater = new JsTokenUpdater();
|
|
168
|
-
for (const
|
|
169
|
-
const { literal, allowDoubleQuotes, offset } = extractLiteralValue(
|
|
169
|
+
for (const path7 of analysis.targetPaths) {
|
|
170
|
+
const { literal, allowDoubleQuotes, offset } = extractLiteralValue(path7);
|
|
170
171
|
const candidates = splitCode(literal, allowDoubleQuotes);
|
|
171
172
|
if (candidates.length === 0) {
|
|
172
173
|
continue;
|
|
@@ -184,14 +185,14 @@ var UniAppXComponentLocalStyleCollector = class {
|
|
|
184
185
|
mutated = true;
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
if (!mutated || typeof
|
|
188
|
+
if (!mutated || typeof path7.node.start !== "number" || typeof path7.node.end !== "number") {
|
|
188
189
|
continue;
|
|
189
190
|
}
|
|
190
191
|
updater.addToken({
|
|
191
|
-
start:
|
|
192
|
-
end:
|
|
192
|
+
start: path7.node.start + offset,
|
|
193
|
+
end: path7.node.end - offset,
|
|
193
194
|
value: rewritten,
|
|
194
|
-
path:
|
|
195
|
+
path: path7
|
|
195
196
|
});
|
|
196
197
|
}
|
|
197
198
|
if (updater.length === 0) {
|
|
@@ -824,14 +825,14 @@ function createJsRuntimeAffectingSignature(source) {
|
|
|
824
825
|
const parts = [];
|
|
825
826
|
traverse(ast, {
|
|
826
827
|
noScope: true,
|
|
827
|
-
StringLiteral(
|
|
828
|
-
parts.push(`s:${
|
|
828
|
+
StringLiteral(path7) {
|
|
829
|
+
parts.push(`s:${path7.node.value}`);
|
|
829
830
|
},
|
|
830
|
-
TemplateElement(
|
|
831
|
-
parts.push(`t:${
|
|
831
|
+
TemplateElement(path7) {
|
|
832
|
+
parts.push(`t:${path7.node.value.raw}`);
|
|
832
833
|
},
|
|
833
|
-
JSXText(
|
|
834
|
-
const value =
|
|
834
|
+
JSXText(path7) {
|
|
835
|
+
const value = path7.node.value.trim();
|
|
835
836
|
if (value.length > 0) {
|
|
836
837
|
parts.push(`x:${value}`);
|
|
837
838
|
}
|
|
@@ -1954,6 +1955,102 @@ function createBundleRuntimeClassSetManager(options = {}) {
|
|
|
1954
1955
|
};
|
|
1955
1956
|
}
|
|
1956
1957
|
|
|
1958
|
+
// src/bundlers/vite/resolve-app-type.ts
|
|
1959
|
+
import { existsSync, readFileSync } from "fs";
|
|
1960
|
+
import path5 from "path";
|
|
1961
|
+
var PACKAGE_JSON_FILE = "package.json";
|
|
1962
|
+
var MPX_SCRIPT_RE = /\bmpx(?:-cli-service)?\b/u;
|
|
1963
|
+
var TARO_SCRIPT_RE = /\btaro\b/u;
|
|
1964
|
+
var TAILWINDCSS_VITE_MARKERS = [
|
|
1965
|
+
["src/app.mpx", "mpx"],
|
|
1966
|
+
["app.mpx", "mpx"]
|
|
1967
|
+
];
|
|
1968
|
+
function resolveDependencyNames(pkg) {
|
|
1969
|
+
return /* @__PURE__ */ new Set([
|
|
1970
|
+
...Object.keys(pkg.dependencies ?? {}),
|
|
1971
|
+
...Object.keys(pkg.devDependencies ?? {}),
|
|
1972
|
+
...Object.keys(pkg.peerDependencies ?? {}),
|
|
1973
|
+
...Object.keys(pkg.optionalDependencies ?? {})
|
|
1974
|
+
]);
|
|
1975
|
+
}
|
|
1976
|
+
function hasScriptMatch(pkg, pattern) {
|
|
1977
|
+
return Object.values(pkg.scripts ?? {}).some((script) => pattern.test(script));
|
|
1978
|
+
}
|
|
1979
|
+
function resolveAppTypeFromPackageJson(pkg) {
|
|
1980
|
+
const dependencyNames = resolveDependencyNames(pkg);
|
|
1981
|
+
if (dependencyNames.has("weapp-vite") || [...dependencyNames].some((name) => name.startsWith("@weapp-vite/"))) {
|
|
1982
|
+
return "weapp-vite";
|
|
1983
|
+
}
|
|
1984
|
+
if ([...dependencyNames].some((name) => name.startsWith("@mpxjs/")) || hasScriptMatch(pkg, MPX_SCRIPT_RE)) {
|
|
1985
|
+
return "mpx";
|
|
1986
|
+
}
|
|
1987
|
+
if ([...dependencyNames].some((name) => name.startsWith("@tarojs/")) || hasScriptMatch(pkg, TARO_SCRIPT_RE)) {
|
|
1988
|
+
return "taro";
|
|
1989
|
+
}
|
|
1990
|
+
if (dependencyNames.has("@dcloudio/vite-plugin-uni")) {
|
|
1991
|
+
return "uni-app-vite";
|
|
1992
|
+
}
|
|
1993
|
+
if (dependencyNames.has("@dcloudio/vue-cli-plugin-uni") || dependencyNames.has("@dcloudio/uni-app") || Object.hasOwn(pkg, "uni-app")) {
|
|
1994
|
+
return "uni-app";
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
function tryReadUniAppManifest(root) {
|
|
1998
|
+
const manifestPath = path5.join(root, "manifest.json");
|
|
1999
|
+
if (!existsSync(manifestPath)) {
|
|
2000
|
+
return;
|
|
2001
|
+
}
|
|
2002
|
+
try {
|
|
2003
|
+
return JSON.parse(readFileSync(manifestPath, "utf8"));
|
|
2004
|
+
} catch {
|
|
2005
|
+
}
|
|
2006
|
+
}
|
|
2007
|
+
function tryReadPackageJson(root) {
|
|
2008
|
+
const packageJsonPath = path5.join(root, PACKAGE_JSON_FILE);
|
|
2009
|
+
if (!existsSync(packageJsonPath)) {
|
|
2010
|
+
return;
|
|
2011
|
+
}
|
|
2012
|
+
try {
|
|
2013
|
+
return JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
2014
|
+
} catch {
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
function resolveAppTypeFromMarkers(root) {
|
|
2018
|
+
for (const [relativePath, appType] of TAILWINDCSS_VITE_MARKERS) {
|
|
2019
|
+
if (existsSync(path5.join(root, relativePath))) {
|
|
2020
|
+
return appType;
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
function resolveImplicitAppTypeFromViteRoot(root) {
|
|
2025
|
+
const resolvedRoot = path5.resolve(root);
|
|
2026
|
+
if (!existsSync(resolvedRoot)) {
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
const markerDetected = resolveAppTypeFromMarkers(resolvedRoot);
|
|
2030
|
+
if (markerDetected) {
|
|
2031
|
+
return markerDetected;
|
|
2032
|
+
}
|
|
2033
|
+
let current = resolvedRoot;
|
|
2034
|
+
while (true) {
|
|
2035
|
+
const manifest = tryReadUniAppManifest(current);
|
|
2036
|
+
if (manifest && Object.hasOwn(manifest, "uni-app-x")) {
|
|
2037
|
+
return "uni-app-x";
|
|
2038
|
+
}
|
|
2039
|
+
const pkg = tryReadPackageJson(current);
|
|
2040
|
+
if (pkg) {
|
|
2041
|
+
const detected = resolveAppTypeFromPackageJson(pkg);
|
|
2042
|
+
if (detected) {
|
|
2043
|
+
return detected;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
const parent = path5.dirname(current);
|
|
2047
|
+
if (parent === current) {
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
current = parent;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
|
|
1957
2054
|
// src/bundlers/vite/rewrite-css-imports.ts
|
|
1958
2055
|
function joinPosixPath(base, subpath) {
|
|
1959
2056
|
if (base.endsWith("/")) {
|
|
@@ -1972,7 +2069,8 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1972
2069
|
if (!options.shouldRewrite) {
|
|
1973
2070
|
return [];
|
|
1974
2071
|
}
|
|
1975
|
-
const { appType, weappTailwindcssDirPosix: weappTailwindcssDirPosix2 } = options;
|
|
2072
|
+
const { appType, getAppType, weappTailwindcssDirPosix: weappTailwindcssDirPosix2 } = options;
|
|
2073
|
+
const resolveAppType = () => getAppType?.() ?? appType;
|
|
1976
2074
|
return [
|
|
1977
2075
|
{
|
|
1978
2076
|
name: `${vitePluginName}:rewrite-css-imports`,
|
|
@@ -1982,7 +2080,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
1982
2080
|
handler(id, importer) {
|
|
1983
2081
|
const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix2, {
|
|
1984
2082
|
join: joinPosixPath,
|
|
1985
|
-
appType
|
|
2083
|
+
appType: resolveAppType()
|
|
1986
2084
|
});
|
|
1987
2085
|
if (!replacement) {
|
|
1988
2086
|
return null;
|
|
@@ -2001,7 +2099,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
2001
2099
|
}
|
|
2002
2100
|
const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix2, {
|
|
2003
2101
|
join: joinPosixPath,
|
|
2004
|
-
appType
|
|
2102
|
+
appType: resolveAppType()
|
|
2005
2103
|
});
|
|
2006
2104
|
if (!rewritten) {
|
|
2007
2105
|
return null;
|
|
@@ -2020,17 +2118,17 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
2020
2118
|
var debug2 = createDebug();
|
|
2021
2119
|
var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
2022
2120
|
var weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
2023
|
-
var
|
|
2121
|
+
var PACKAGE_JSON_FILE2 = "package.json";
|
|
2024
2122
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
2025
|
-
const resolvedRoot =
|
|
2026
|
-
if (!
|
|
2123
|
+
const resolvedRoot = path6.resolve(root);
|
|
2124
|
+
if (!existsSync2(resolvedRoot)) {
|
|
2027
2125
|
return resolvedRoot;
|
|
2028
2126
|
}
|
|
2029
2127
|
const searchRoots = [];
|
|
2030
2128
|
let current = resolvedRoot;
|
|
2031
2129
|
while (true) {
|
|
2032
2130
|
searchRoots.push(current);
|
|
2033
|
-
const parent =
|
|
2131
|
+
const parent = path6.dirname(current);
|
|
2034
2132
|
if (parent === current) {
|
|
2035
2133
|
break;
|
|
2036
2134
|
}
|
|
@@ -2038,15 +2136,16 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
2038
2136
|
}
|
|
2039
2137
|
const tailwindConfigPath = findTailwindConfig(searchRoots);
|
|
2040
2138
|
if (tailwindConfigPath) {
|
|
2041
|
-
return
|
|
2139
|
+
return path6.dirname(tailwindConfigPath);
|
|
2042
2140
|
}
|
|
2043
2141
|
const packageRoot = findNearestPackageRoot(resolvedRoot);
|
|
2044
|
-
if (packageRoot &&
|
|
2142
|
+
if (packageRoot && existsSync2(path6.join(packageRoot, PACKAGE_JSON_FILE2))) {
|
|
2045
2143
|
return packageRoot;
|
|
2046
2144
|
}
|
|
2047
2145
|
return resolvedRoot;
|
|
2048
2146
|
}
|
|
2049
2147
|
function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
2148
|
+
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
2050
2149
|
const rewriteCssImportsSpecified = Object.hasOwn(options, "rewriteCssImports");
|
|
2051
2150
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
2052
2151
|
const opts = getCompilerContext(options);
|
|
@@ -2055,7 +2154,6 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2055
2154
|
customAttributes,
|
|
2056
2155
|
onLoad,
|
|
2057
2156
|
mainCssChunkMatcher,
|
|
2058
|
-
appType,
|
|
2059
2157
|
styleHandler,
|
|
2060
2158
|
jsHandler,
|
|
2061
2159
|
twPatcher: initialTwPatcher,
|
|
@@ -2068,7 +2166,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2068
2166
|
const tailwindcssMajorVersion = initialTwPatcher.majorVersion ?? 0;
|
|
2069
2167
|
const shouldRewriteCssImports = opts.rewriteCssImports !== false && !disabledOptions.rewriteCssImports && (rewriteCssImportsSpecified || tailwindcssMajorVersion >= 4);
|
|
2070
2168
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
2071
|
-
appType,
|
|
2169
|
+
getAppType: () => opts.appType,
|
|
2072
2170
|
shouldRewrite: shouldRewriteCssImports,
|
|
2073
2171
|
weappTailwindcssDirPosix
|
|
2074
2172
|
});
|
|
@@ -2096,7 +2194,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2096
2194
|
const configPath = resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
|
|
2097
2195
|
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
2098
2196
|
const optionsKey = JSON.stringify({
|
|
2099
|
-
appType,
|
|
2197
|
+
appType: opts.appType,
|
|
2100
2198
|
uniAppX: uniAppXEnabled,
|
|
2101
2199
|
customAttributesEntities,
|
|
2102
2200
|
disabledDefaultTemplateHandler,
|
|
@@ -2198,7 +2296,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2198
2296
|
const utsPlatform = resolveUniUtsPlatform();
|
|
2199
2297
|
const isIosPlatform = utsPlatform.isAppIos;
|
|
2200
2298
|
const uniAppXPlugins = uniAppXEnabled ? createUniAppXPlugins({
|
|
2201
|
-
appType,
|
|
2299
|
+
appType: opts.appType ?? "uni-app-x",
|
|
2202
2300
|
customAttributesEntities,
|
|
2203
2301
|
disabledDefaultTemplateHandler,
|
|
2204
2302
|
isIosPlatform,
|
|
@@ -2217,7 +2315,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2217
2315
|
enforce: "post",
|
|
2218
2316
|
async configResolved(config) {
|
|
2219
2317
|
resolvedConfig = config;
|
|
2220
|
-
const resolvedRoot = config.root ?
|
|
2318
|
+
const resolvedRoot = config.root ? path6.resolve(config.root) : void 0;
|
|
2319
|
+
let shouldRefreshRuntime = false;
|
|
2221
2320
|
if (!hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
2222
2321
|
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
2223
2322
|
if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|
|
@@ -2228,9 +2327,26 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
2228
2327
|
previousBasedir ?? "undefined",
|
|
2229
2328
|
nextTailwindcssBasedir
|
|
2230
2329
|
);
|
|
2231
|
-
|
|
2330
|
+
shouldRefreshRuntime = true;
|
|
2232
2331
|
}
|
|
2233
2332
|
}
|
|
2333
|
+
if (!hasExplicitAppType && resolvedRoot) {
|
|
2334
|
+
const nextAppType = resolveImplicitAppTypeFromViteRoot(resolvedRoot);
|
|
2335
|
+
if (nextAppType && opts.appType !== nextAppType) {
|
|
2336
|
+
const previousAppType = opts.appType;
|
|
2337
|
+
opts.appType = nextAppType;
|
|
2338
|
+
logger2.info("\u6839\u636E Vite \u9879\u76EE\u6839\u76EE\u5F55\u81EA\u52A8\u63A8\u65AD appType -> %s", nextAppType);
|
|
2339
|
+
debug2(
|
|
2340
|
+
"align appType with vite root: %s -> %s",
|
|
2341
|
+
previousAppType ?? "undefined",
|
|
2342
|
+
nextAppType
|
|
2343
|
+
);
|
|
2344
|
+
shouldRefreshRuntime = true;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
if (shouldRefreshRuntime) {
|
|
2348
|
+
await refreshRuntimeState(true);
|
|
2349
|
+
}
|
|
2234
2350
|
if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
|
|
2235
2351
|
const postcssPlugins = config.css.postcss.plugins;
|
|
2236
2352
|
const idx = postcssPlugins.findIndex((x) => (
|