weapp-tailwindcss 4.12.0 → 5.0.0-next.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/babel/index.d.ts +3 -0
- package/dist/bundlers/gulp/index.d.ts +7 -0
- package/dist/bundlers/shared/cache.d.ts +16 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/css-imports.d.ts +8 -0
- package/dist/bundlers/shared/generator-candidates.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +43 -0
- package/dist/bundlers/shared/module-graph.d.ts +5 -0
- package/dist/bundlers/shared/run-tasks.d.ts +2 -0
- package/dist/bundlers/vite/bundle-entries.d.ts +14 -0
- package/dist/bundlers/vite/bundle-state.d.ts +43 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +22 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +33 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +21 -0
- package/dist/bundlers/vite/index.d.ts +3 -0
- package/dist/bundlers/vite/js-precheck.d.ts +1 -0
- package/dist/bundlers/vite/query.d.ts +15 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +2 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +11 -0
- package/dist/bundlers/vite/runtime-affecting-signature.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates.d.ts +15 -0
- package/dist/bundlers/vite/utils.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +20 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +14 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +15 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +17 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +19 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
- package/dist/bundlers/webpack/index.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +12 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +11 -0
- package/dist/bundlers/webpack/shared/css-imports.d.ts +6 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +8 -0
- package/dist/cache/index.d.ts +38 -0
- package/dist/cache/md5.d.ts +1 -0
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/cli/config.d.ts +5 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/doctor/constants.d.ts +7 -0
- package/dist/cli/doctor/types.d.ts +31 -0
- package/dist/cli/doctor.d.ts +4 -0
- package/dist/cli/helpers/options/format.d.ts +2 -0
- package/dist/cli/helpers/options/parse.d.ts +3 -0
- package/dist/cli/helpers/options/resolve.d.ts +1 -0
- package/dist/cli/helpers/options.d.ts +3 -0
- package/dist/cli/helpers/patch-cwd.d.ts +1 -0
- package/dist/cli/helpers.d.ts +5 -0
- package/dist/cli/mount-options/patch-status.d.ts +2 -0
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/patch-options.d.ts +6 -0
- package/dist/cli/tokens.d.ts +4 -0
- package/dist/cli/types.d.ts +17 -0
- package/dist/cli/vscode-entry.d.ts +14 -0
- package/dist/cli/workspace/package-dirs.d.ts +3 -0
- package/dist/cli/workspace/patch-package.d.ts +3 -0
- package/dist/cli/workspace/patch-utils.d.ts +3 -0
- package/dist/cli/workspace/types.d.ts +11 -0
- package/dist/cli/workspace/workspace-globs.d.ts +2 -0
- package/dist/cli/workspace/workspace-io.d.ts +1 -0
- package/dist/cli/workspace/workspace-lock.d.ts +1 -0
- package/dist/cli/workspace.d.ts +2 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +2425 -3524
- package/dist/cli.mjs +2402 -3505
- package/dist/constants-B-_T5UnW.mjs +44 -0
- package/dist/constants-p1dyh1x1.js +73 -0
- package/dist/constants.d.ts +13 -0
- package/dist/context/compiler-context-cache.d.ts +3 -0
- package/dist/context/custom-attributes.d.ts +2 -0
- package/dist/context/handlers.d.ts +6 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/logger.d.ts +4 -0
- package/dist/context/tailwindcss/basedir.d.ts +1 -0
- package/dist/context/tailwindcss/rax.d.ts +2 -0
- package/dist/context/tailwindcss.d.ts +4 -0
- package/dist/context/workspace.d.ts +3 -0
- package/dist/core.d.ts +5 -21
- package/dist/core.js +138 -180
- package/dist/core.mjs +135 -180
- package/dist/css-imports-BbrbluP9.js +177 -0
- package/dist/css-imports-CSdPq_Sc.mjs +128 -0
- package/dist/css-macro/constants.d.ts +14 -0
- package/dist/css-macro/index.d.ts +15 -0
- package/dist/css-macro/postcss.d.ts +3 -7
- package/dist/css-macro/postcss.js +44 -58
- package/dist/css-macro/postcss.mjs +44 -56
- package/dist/css-macro.d.ts +1 -20
- package/dist/css-macro.js +37 -50
- package/dist/css-macro.mjs +33 -47
- package/dist/debug/index.d.ts +5 -0
- package/dist/defaults.d.ts +2 -11
- package/dist/defaults.js +132 -8
- package/dist/defaults.mjs +128 -7
- package/dist/escape.js +31 -54
- package/dist/escape.mjs +18 -25
- package/dist/experimental/index.d.ts +2 -0
- package/dist/experimental/oxc/ast-utils.d.ts +30 -0
- package/dist/experimental/oxc/index.d.ts +2 -0
- package/dist/experimental/oxc/module-specifiers.d.ts +2 -0
- package/dist/experimental/shared/cache.d.ts +3 -0
- package/dist/experimental/shared/transform.d.ts +3 -0
- package/dist/experimental/shared.d.ts +8 -0
- package/dist/experimental/swc/ast-utils.d.ts +30 -0
- package/dist/experimental/swc/index.d.ts +2 -0
- package/dist/experimental/swc/module-specifiers.d.ts +2 -0
- package/dist/generator/index.d.ts +11 -0
- package/dist/generator/options.d.ts +17 -0
- package/dist/generator/types.d.ts +20 -0
- package/dist/generator-Y-Ikv4Fu.mjs +1177 -0
- package/dist/generator-css-B5ejWUMv.mjs +1098 -0
- package/dist/generator-css-D3OdPRiS.js +1125 -0
- package/dist/generator-mmhXzZnv.js +1276 -0
- package/dist/generator.d.ts +1 -0
- package/dist/generator.js +19 -0
- package/dist/generator.mjs +2 -0
- package/dist/gulp.d.ts +4 -24
- package/dist/gulp.js +271 -13
- package/dist/gulp.mjs +263 -13
- package/dist/index.d.ts +8 -15
- package/dist/index.js +12 -24
- package/dist/index.mjs +6 -24
- package/dist/js/JsTokenUpdater.d.ts +14 -0
- package/dist/js/ModuleGraph.d.ts +18 -0
- package/dist/js/NodePathWalker.d.ts +33 -0
- package/dist/js/babel/parse.d.ts +9 -0
- package/dist/js/babel/process.d.ts +4 -0
- package/dist/js/babel.d.ts +13 -0
- package/dist/js/class-context.d.ts +3 -0
- package/dist/js/evalTransforms.d.ts +7 -0
- package/dist/js/handlers.d.ts +5 -0
- package/dist/js/index.d.ts +4 -0
- package/dist/js/module-graph/ignored-exports.d.ts +18 -0
- package/dist/js/module-graph/types.d.ts +17 -0
- package/dist/js/node-path-walker/export-handlers.d.ts +12 -0
- package/dist/js/node-path-walker/import-tokens.d.ts +24 -0
- package/dist/js/precheck.d.ts +2 -0
- package/dist/js/sourceAnalysis.d.ts +17 -0
- package/dist/js/syntax.d.ts +10 -0
- package/dist/js/taggedTemplateIgnore.d.ts +13 -0
- package/dist/js/types.d.ts +11 -0
- package/dist/lightningcss/index.d.ts +8 -0
- package/dist/lightningcss/style-handler/options.d.ts +3 -0
- package/dist/lightningcss/style-handler/selector-transform.d.ts +10 -0
- package/dist/lightningcss/style-handler/selector-utils.d.ts +10 -0
- package/dist/lightningcss/style-handler.d.ts +17 -0
- package/dist/loader-anchors-CNkWT8hx.js +273 -0
- package/dist/loader-anchors-TrU7EUr7.mjs +205 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger-BZ45DZJT.js +1003 -0
- package/dist/logger-BoVx1Dbt.mjs +935 -0
- package/dist/patcher-options-6gJN2EXy.js +115 -0
- package/dist/patcher-options-DQfR5xxT.mjs +92 -0
- package/dist/postcss-html-transform.d.ts +3 -3
- package/dist/postcss-html-transform.js +7 -10
- package/dist/postcss-html-transform.mjs +3 -6
- package/dist/postcss.d.ts +15 -0
- package/dist/postcss.js +280 -0
- package/dist/postcss.mjs +270 -0
- package/dist/presets/hbuilderx.d.ts +4 -0
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/shared.d.ts +10 -0
- package/dist/presets/taro.d.ts +4 -0
- package/dist/presets/uni-app-x.d.ts +16 -0
- package/dist/presets/uni-app.d.ts +4 -0
- package/dist/presets.d.ts +1 -76
- package/dist/presets.js +115 -163
- package/dist/presets.mjs +107 -163
- package/dist/recorder-gYSNLfOP.js +2878 -0
- package/dist/recorder-zsgatmkB.mjs +2763 -0
- package/dist/reset/index.d.ts +2 -0
- package/dist/reset.d.ts +1 -4
- package/dist/reset.js +19 -8
- package/dist/reset.mjs +2 -8
- package/dist/shared/classname-transform.d.ts +14 -0
- package/dist/shared/mpx.d.ts +7 -0
- package/dist/shared/tailwindcss-css-redirect.d.ts +1 -0
- package/dist/tailwindcss/index.d.ts +11 -0
- package/dist/tailwindcss/miniprogram.d.ts +1 -0
- package/dist/tailwindcss/patcher-options.d.ts +56 -0
- package/dist/tailwindcss/patcher-resolve.d.ts +4 -0
- package/dist/tailwindcss/patcher.d.ts +13 -0
- package/dist/tailwindcss/recorder.d.ts +13 -0
- package/dist/tailwindcss/remove-unsupported-css.d.ts +2 -0
- package/dist/tailwindcss/runtime/cache.d.ts +11 -0
- package/dist/tailwindcss/runtime-logs.d.ts +3 -0
- package/dist/tailwindcss/runtime.d.ts +29 -0
- package/dist/tailwindcss/targets/paths.d.ts +13 -0
- package/dist/tailwindcss/targets/record-io.d.ts +5 -0
- package/dist/tailwindcss/targets/recorder.d.ts +3 -0
- package/dist/tailwindcss/targets/types.d.ts +35 -0
- package/dist/tailwindcss/targets.d.ts +6 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/source.d.ts +5 -0
- package/dist/tailwindcss/v3-engine/types.d.ts +55 -0
- package/dist/tailwindcss/v4/config.d.ts +5 -0
- package/dist/tailwindcss/v4/css-entries.d.ts +7 -0
- package/dist/tailwindcss/v4/index.d.ts +2 -0
- package/dist/tailwindcss/v4/multi-patcher.d.ts +2 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +24 -0
- package/dist/tailwindcss/v4/patcher.d.ts +14 -0
- package/dist/tailwindcss/v4-engine/candidates.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +7 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/tailwind-v4-default-colors.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +19 -0
- package/dist/typedoc.export.d.ts +5 -0
- package/dist/types/base.d.ts +1 -0
- package/dist/types/disabled-options.d.ts +4 -0
- package/dist/types/index.d.ts +104 -0
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/user-defined-options/general.d.ts +31 -0
- package/dist/types/user-defined-options/important.d.ts +37 -0
- package/dist/types/user-defined-options/index.d.ts +11 -0
- package/dist/types/user-defined-options/lifecycle.d.ts +6 -0
- package/dist/types/user-defined-options/matcher.d.ts +9 -0
- package/dist/types.d.ts +1 -150
- package/dist/types.js +0 -1
- package/dist/types.mjs +1 -1
- package/dist/uni-app-x/component-local-style.d.ts +19 -0
- package/dist/uni-app-x/index.d.ts +2 -0
- package/dist/uni-app-x/options.d.ts +12 -0
- package/dist/uni-app-x/style-isolation.d.ts +2 -0
- package/dist/uni-app-x/transform.d.ts +9 -0
- package/dist/uni-app-x/vite.d.ts +36 -0
- package/dist/utils/decode.d.ts +2 -0
- package/dist/utils/disabled.d.ts +6 -0
- package/dist/utils/hbuilderx.d.ts +5 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/nameMatcher.d.ts +4 -0
- package/dist/utils/resolve-package.d.ts +1 -0
- package/dist/utils/uni-platform.d.ts +11 -0
- package/dist/utils-7DUGTFED.mjs +48 -0
- package/dist/utils-DmC9_In3.js +61 -0
- package/dist/vite-BC9U7ahn.js +2199 -0
- package/dist/vite-CrlzCNqz.mjs +2186 -0
- package/dist/vite.d.ts +4 -17
- package/dist/vite.js +5 -14
- package/dist/vite.mjs +2 -14
- package/dist/weapp-tw-css-import-rewrite-loader.js +59 -92
- package/dist/weapp-tw-runtime-classset-loader.js +31 -50
- package/dist/webpack-Bu6M-Hbw.mjs +441 -0
- package/dist/webpack-DD7A6V0u.js +456 -0
- package/dist/webpack.d.ts +4 -25
- package/dist/webpack.js +6 -17
- package/dist/webpack.mjs +2 -17
- package/dist/webpack4.d.ts +4 -26
- package/dist/webpack4.js +375 -481
- package/dist/webpack4.mjs +366 -482
- package/dist/wxml/Tokenizer.d.ts +15 -0
- package/dist/wxml/custom-attributes.d.ts +4 -0
- package/dist/wxml/index.d.ts +2 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/tokenizer/types.d.ts +18 -0
- package/dist/wxml/utils/codegen/legacy-rewriter.d.ts +2 -0
- package/dist/wxml/utils/codegen/legacy-visitor.d.ts +8 -0
- package/dist/wxml/utils/codegen.d.ts +2 -0
- package/dist/wxml/utils/custom-template.d.ts +3 -0
- package/dist/wxml/utils/fragment-helpers.d.ts +6 -0
- package/dist/wxml/utils/fragment-updater.d.ts +4 -0
- package/dist/wxml/utils/template-fragments.d.ts +3 -0
- package/dist/wxml/utils.d.ts +8 -0
- package/dist/wxml/whitespace.d.ts +2 -0
- package/generator-placeholder.css +1 -0
- package/package.json +19 -8
- package/dist/chunk-24AGZQVR.js +0 -183
- package/dist/chunk-3VQKDHGP.mjs +0 -179
- package/dist/chunk-4AFQP74Z.js +0 -24
- package/dist/chunk-57SOQCAU.mjs +0 -582
- package/dist/chunk-5ZYHNDEK.mjs +0 -2439
- package/dist/chunk-76S2EME4.mjs +0 -34
- package/dist/chunk-A5PB4KZT.js +0 -138
- package/dist/chunk-DUHYLR2R.js +0 -276
- package/dist/chunk-DYLQ6UOI.js +0 -71
- package/dist/chunk-E7I5TW5K.js +0 -52
- package/dist/chunk-FS2NOOEB.js +0 -292
- package/dist/chunk-HVNGIKLS.js +0 -3930
- package/dist/chunk-JZQBZHN5.js +0 -579
- package/dist/chunk-KGTVD4EP.mjs +0 -3930
- package/dist/chunk-NNOQDMUP.mjs +0 -10
- package/dist/chunk-OF6MFURR.js +0 -34
- package/dist/chunk-OFB2KBRP.js +0 -2442
- package/dist/chunk-OOHJLO5M.mjs +0 -71
- package/dist/chunk-PCDYXXSK.mjs +0 -1515
- package/dist/chunk-RKISS72P.js +0 -7
- package/dist/chunk-RRQZL7FQ.mjs +0 -292
- package/dist/chunk-XAKAD2CR.mjs +0 -138
- package/dist/chunk-XZP3MREK.mjs +0 -276
- package/dist/chunk-ZAA5ZG3D.js +0 -1518
- package/dist/chunk-ZCH4YINE.mjs +0 -52
- package/dist/cli.d.mts +0 -2
- package/dist/core.d.mts +0 -26
- package/dist/css-macro/postcss.d.mts +0 -7
- package/dist/css-macro.d.mts +0 -18
- package/dist/defaults.d.mts +0 -11
- package/dist/gulp.d.mts +0 -24
- package/dist/index-BXrmQelt.d.mts +0 -672
- package/dist/index-BXrmQelt.d.ts +0 -672
- package/dist/index.d.mts +0 -15
- package/dist/postcss-html-transform.d.mts +0 -2
- package/dist/presets.d.mts +0 -76
- package/dist/reset.d.mts +0 -1
- package/dist/types.d.mts +0 -150
- package/dist/vite.d.mts +0 -17
- package/dist/webpack.d.mts +0 -25
- package/dist/webpack4.d.mts +0 -26
package/dist/postcss.mjs
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { a as resolveTailwindV4Source$1, i as normalizeWeappTailwindcssGeneratorOptions, p as resolveTailwindV3Source, t as createWeappTailwindcssGenerator } from "./generator-Y-Ikv4Fu.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import postcss from "postcss";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { loadConfig } from "tailwindcss-config";
|
|
7
|
+
import { extractValidCandidates } from "tailwindcss-patch";
|
|
8
|
+
import { readFile, stat } from "node:fs/promises";
|
|
9
|
+
import fg from "fast-glob";
|
|
10
|
+
//#region src/postcss.ts
|
|
11
|
+
const PLUGIN_NAME = "weapp-tailwindcss";
|
|
12
|
+
const POSTCSS_SOURCE_EXTENSIONS = [
|
|
13
|
+
"html",
|
|
14
|
+
"wxml",
|
|
15
|
+
"axml",
|
|
16
|
+
"jxml",
|
|
17
|
+
"ksml",
|
|
18
|
+
"ttml",
|
|
19
|
+
"qml",
|
|
20
|
+
"tyml",
|
|
21
|
+
"xhsml",
|
|
22
|
+
"swan",
|
|
23
|
+
"vue",
|
|
24
|
+
"mpx",
|
|
25
|
+
"js",
|
|
26
|
+
"jsx",
|
|
27
|
+
"ts",
|
|
28
|
+
"tsx"
|
|
29
|
+
];
|
|
30
|
+
function resolveInputFile(result) {
|
|
31
|
+
const from = result.opts.from;
|
|
32
|
+
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
33
|
+
}
|
|
34
|
+
function resolvePostcssBase(result, options) {
|
|
35
|
+
if (options.base) return options.base;
|
|
36
|
+
const inputFile = resolveInputFile(result);
|
|
37
|
+
return inputFile ? path.dirname(inputFile) : process.cwd();
|
|
38
|
+
}
|
|
39
|
+
function resolvePostcssProjectRoot(result, options) {
|
|
40
|
+
if (options.projectRoot) return options.projectRoot;
|
|
41
|
+
const inputFile = resolveInputFile(result);
|
|
42
|
+
return inputFile ? path.dirname(inputFile) : process.cwd();
|
|
43
|
+
}
|
|
44
|
+
function replaceRootCss(root, css, result) {
|
|
45
|
+
const nextRoot = postcss.parse(css, { from: resolveInputFile(result) });
|
|
46
|
+
root.removeAll();
|
|
47
|
+
root.append(nextRoot.nodes);
|
|
48
|
+
}
|
|
49
|
+
function addDependencyMessages(result, generated) {
|
|
50
|
+
for (const file of generated.dependencies) result.messages.push({
|
|
51
|
+
type: "dependency",
|
|
52
|
+
plugin: PLUGIN_NAME,
|
|
53
|
+
file
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function parseLocalSourceParam(params) {
|
|
57
|
+
const value = params.trim();
|
|
58
|
+
if (!value || value === "none" || value.startsWith("not ") || value.startsWith("inline(")) return;
|
|
59
|
+
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
60
|
+
}
|
|
61
|
+
function parseConfigParam(params) {
|
|
62
|
+
const value = params.trim();
|
|
63
|
+
return /^(['"])(.+)\1$/.exec(value)?.[2];
|
|
64
|
+
}
|
|
65
|
+
function parseSourceFileParam(params) {
|
|
66
|
+
const value = params.trim();
|
|
67
|
+
if (!value || value === "none" || value.startsWith("inline(")) return;
|
|
68
|
+
const negated = value.startsWith("not ");
|
|
69
|
+
const sourceValue = negated ? value.slice(4).trim() : value;
|
|
70
|
+
const match = /^(['"])(.+)\1$/.exec(sourceValue);
|
|
71
|
+
return match?.[2] ? {
|
|
72
|
+
negated,
|
|
73
|
+
sourcePath: match[2]
|
|
74
|
+
} : void 0;
|
|
75
|
+
}
|
|
76
|
+
function hasTailwindV4CssSyntax(root) {
|
|
77
|
+
let hasV4Syntax = false;
|
|
78
|
+
root.walkAtRules((rule) => {
|
|
79
|
+
if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
|
|
80
|
+
if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
|
|
81
|
+
});
|
|
82
|
+
return hasV4Syntax;
|
|
83
|
+
}
|
|
84
|
+
function readPackageMajorVersion(packageName, base) {
|
|
85
|
+
try {
|
|
86
|
+
const pkg = createRequire(`${base}/package.json`)(`${packageName}/package.json`);
|
|
87
|
+
const major = Number(pkg.version?.split(".")[0]);
|
|
88
|
+
return major === 3 || major === 4 ? major : void 0;
|
|
89
|
+
} catch {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function resolvePostcssTailwindVersion(root, result, options) {
|
|
94
|
+
if (options.version) return options.version;
|
|
95
|
+
if (hasTailwindV4CssSyntax(root)) return 4;
|
|
96
|
+
const packageName = options.packageName ?? "tailwindcss";
|
|
97
|
+
if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
|
|
98
|
+
if (packageName.includes("tailwindcss3")) return 3;
|
|
99
|
+
return readPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options)) ?? 4;
|
|
100
|
+
}
|
|
101
|
+
function getSourceExtension(file) {
|
|
102
|
+
return path.extname(file).slice(1) || void 0;
|
|
103
|
+
}
|
|
104
|
+
async function pathExistsAsDirectory(file) {
|
|
105
|
+
try {
|
|
106
|
+
return (await stat(file)).isDirectory();
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function expandLocalSourceFiles(sourcePath, base) {
|
|
112
|
+
const absoluteSource = path.isAbsolute(sourcePath) ? sourcePath : path.resolve(base, sourcePath);
|
|
113
|
+
if (await pathExistsAsDirectory(absoluteSource)) return fg(`**/*.{${POSTCSS_SOURCE_EXTENSIONS.join(",")}}`, {
|
|
114
|
+
absolute: true,
|
|
115
|
+
cwd: absoluteSource,
|
|
116
|
+
onlyFiles: true
|
|
117
|
+
});
|
|
118
|
+
return fg(sourcePath, {
|
|
119
|
+
absolute: true,
|
|
120
|
+
cwd: base,
|
|
121
|
+
onlyFiles: true
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function resolveTailwindSourceEntry(sourcePath, base, negated) {
|
|
125
|
+
const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
|
|
126
|
+
if (await pathExistsAsDirectory(absoluteSource)) return {
|
|
127
|
+
base: absoluteSource,
|
|
128
|
+
negated,
|
|
129
|
+
pattern: "**/*"
|
|
130
|
+
};
|
|
131
|
+
if (path.isAbsolute(sourcePath)) return {
|
|
132
|
+
base: path.dirname(absoluteSource),
|
|
133
|
+
negated,
|
|
134
|
+
pattern: path.basename(absoluteSource)
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
base,
|
|
138
|
+
negated,
|
|
139
|
+
pattern: sourcePath
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function collectConfigPaths(root, base) {
|
|
143
|
+
const configPaths = [];
|
|
144
|
+
root.walkAtRules("config", (rule) => {
|
|
145
|
+
const configPath = parseConfigParam(rule.params);
|
|
146
|
+
if (configPath) configPaths.push(path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath));
|
|
147
|
+
});
|
|
148
|
+
return [...new Set(configPaths)];
|
|
149
|
+
}
|
|
150
|
+
function normalizeContentFiles(content) {
|
|
151
|
+
if (typeof content === "string") return [content];
|
|
152
|
+
if (Array.isArray(content)) return content.flatMap((item) => normalizeContentFiles(item));
|
|
153
|
+
if (typeof content === "object" && content !== null && "files" in content) return normalizeContentFiles(content.files);
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
async function collectConfigContentFiles(root, base) {
|
|
157
|
+
const configPaths = collectConfigPaths(root, base);
|
|
158
|
+
const files = [];
|
|
159
|
+
for (const configPath of configPaths) {
|
|
160
|
+
const contentFiles = normalizeContentFiles((await loadConfig({
|
|
161
|
+
config: configPath,
|
|
162
|
+
cwd: path.dirname(configPath)
|
|
163
|
+
}))?.config.content);
|
|
164
|
+
for (const contentFile of contentFiles) files.push(...await expandLocalSourceFiles(contentFile, path.dirname(configPath)));
|
|
165
|
+
}
|
|
166
|
+
return {
|
|
167
|
+
configPaths,
|
|
168
|
+
files: [...new Set(files)]
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
async function collectAutoTailwindCandidates(root, result, options) {
|
|
172
|
+
const base = resolvePostcssBase(result, options);
|
|
173
|
+
const projectRoot = resolvePostcssProjectRoot(result, options);
|
|
174
|
+
const sourceEntryTasks = [];
|
|
175
|
+
if (!root.toString().includes("source(none)")) sourceEntryTasks.push(Promise.resolve({
|
|
176
|
+
base,
|
|
177
|
+
negated: false,
|
|
178
|
+
pattern: "**/*"
|
|
179
|
+
}));
|
|
180
|
+
root.walkAtRules("source", (rule) => {
|
|
181
|
+
const parsed = parseSourceFileParam(rule.params);
|
|
182
|
+
if (!parsed) return;
|
|
183
|
+
sourceEntryTasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated));
|
|
184
|
+
});
|
|
185
|
+
const sourceEntries = await Promise.all(sourceEntryTasks);
|
|
186
|
+
if (sourceEntries.length === 0) return /* @__PURE__ */ new Set();
|
|
187
|
+
const candidates = await extractValidCandidates({
|
|
188
|
+
base,
|
|
189
|
+
css: root.toString(),
|
|
190
|
+
cwd: projectRoot,
|
|
191
|
+
sources: sourceEntries
|
|
192
|
+
});
|
|
193
|
+
return new Set(candidates);
|
|
194
|
+
}
|
|
195
|
+
async function collectPostcssLocalSources(root, result, options) {
|
|
196
|
+
const base = resolvePostcssBase(result, options);
|
|
197
|
+
const sourcePaths = [];
|
|
198
|
+
root.walkAtRules("source", (rule) => {
|
|
199
|
+
const sourcePath = parseLocalSourceParam(rule.params);
|
|
200
|
+
if (sourcePath) sourcePaths.push(sourcePath);
|
|
201
|
+
});
|
|
202
|
+
const configContentFiles = await collectConfigContentFiles(root, base);
|
|
203
|
+
const files = [...new Set((await Promise.all(sourcePaths.map((sourcePath) => expandLocalSourceFiles(sourcePath, base)))).flat().concat(configContentFiles.files))];
|
|
204
|
+
const sources = await Promise.all(files.map(async (file) => ({
|
|
205
|
+
content: await readFile(file, "utf8"),
|
|
206
|
+
extension: getSourceExtension(file)
|
|
207
|
+
})));
|
|
208
|
+
return {
|
|
209
|
+
files: [...files, ...configContentFiles.configPaths],
|
|
210
|
+
sources
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function addSourceDependencyMessages(result, files) {
|
|
214
|
+
for (const file of files) result.messages.push({
|
|
215
|
+
type: "dependency",
|
|
216
|
+
plugin: PLUGIN_NAME,
|
|
217
|
+
file
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
221
|
+
return {
|
|
222
|
+
postcssPlugin: PLUGIN_NAME,
|
|
223
|
+
async Once(root, { result }) {
|
|
224
|
+
const { candidates, generator: userGeneratorOptions, sources, styleOptions, target: legacyTarget, ...sourceOptions } = options;
|
|
225
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
|
|
226
|
+
if (generatorOptions.mode === "off") return;
|
|
227
|
+
const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
|
|
228
|
+
const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
|
|
229
|
+
const generator = createWeappTailwindcssGenerator(tailwindVersion === 3 ? await resolveTailwindV3Source({
|
|
230
|
+
config: options.config,
|
|
231
|
+
css: sourceOptions.css ?? root.toString(),
|
|
232
|
+
base: resolvePostcssBase(result, options),
|
|
233
|
+
cwd: resolvePostcssProjectRoot(result, options),
|
|
234
|
+
projectRoot: resolvePostcssProjectRoot(result, options),
|
|
235
|
+
packageName: options.packageName,
|
|
236
|
+
postcssPlugin: options.postcssPlugin
|
|
237
|
+
}) : await resolveTailwindV4Source$1({
|
|
238
|
+
...sourceOptions,
|
|
239
|
+
css: sourceOptions.css ?? root.toString(),
|
|
240
|
+
base: resolvePostcssBase(result, options),
|
|
241
|
+
projectRoot: resolvePostcssProjectRoot(result, options)
|
|
242
|
+
}));
|
|
243
|
+
const generateOptions = {
|
|
244
|
+
candidates: new Set([...autoCandidates, ...candidates ?? []]),
|
|
245
|
+
scanSources: false,
|
|
246
|
+
sources: [...collectedSources.sources, ...sources ?? []],
|
|
247
|
+
styleOptions: {
|
|
248
|
+
...generatorOptions.styleOptions,
|
|
249
|
+
...styleOptions
|
|
250
|
+
},
|
|
251
|
+
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
252
|
+
target: legacyTarget ?? generatorOptions.target
|
|
253
|
+
};
|
|
254
|
+
const generated = await generator.generate(generateOptions);
|
|
255
|
+
replaceRootCss(root, generated.css, result);
|
|
256
|
+
addDependencyMessages(result, generated);
|
|
257
|
+
addSourceDependencyMessages(result, collectedSources.files);
|
|
258
|
+
result.messages.push({
|
|
259
|
+
type: "weapp-tailwindcss:generated",
|
|
260
|
+
plugin: PLUGIN_NAME,
|
|
261
|
+
target: generated.target,
|
|
262
|
+
classSet: generated.classSet,
|
|
263
|
+
rawCss: generated.rawCss
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
weappTailwindcssPostcssPlugin.postcss = true;
|
|
269
|
+
//#endregion
|
|
270
|
+
export { weappTailwindcssPostcssPlugin as default, weappTailwindcssPostcssPlugin };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PackageResolvingOptions } from 'local-pkg';
|
|
2
|
+
import type { UserDefinedOptions } from '../types';
|
|
3
|
+
export interface BasePresetOptions extends Omit<Partial<UserDefinedOptions>, 'cssEntries'> {
|
|
4
|
+
base?: string;
|
|
5
|
+
cssEntries?: string | string[];
|
|
6
|
+
resolve?: PackageResolvingOptions;
|
|
7
|
+
rawOptions?: UserDefinedOptions;
|
|
8
|
+
}
|
|
9
|
+
export declare function normalizeCssEntries(entries?: string | string[]): string[] | undefined;
|
|
10
|
+
export declare function createBasePreset(options?: BasePresetOptions): Partial<UserDefinedOptions>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PackageResolvingOptions } from 'local-pkg';
|
|
2
|
+
import type { UniAppXComponentLocalStylesOptions, UserDefinedOptions } from '../types';
|
|
3
|
+
export interface UniAppXOptions {
|
|
4
|
+
base: string;
|
|
5
|
+
cssEntries?: string[];
|
|
6
|
+
rem2rpx?: UserDefinedOptions['rem2rpx'];
|
|
7
|
+
generator?: UserDefinedOptions['generator'];
|
|
8
|
+
unitsToPx?: UserDefinedOptions['unitsToPx'];
|
|
9
|
+
rawOptions?: UserDefinedOptions;
|
|
10
|
+
resolve?: PackageResolvingOptions;
|
|
11
|
+
customAttributes?: UserDefinedOptions['customAttributes'];
|
|
12
|
+
uniAppX?: UserDefinedOptions['uniAppX'];
|
|
13
|
+
componentLocalStyles?: boolean | UniAppXComponentLocalStylesOptions;
|
|
14
|
+
uvueUnsupported?: 'error' | 'warn' | 'silent';
|
|
15
|
+
}
|
|
16
|
+
export declare function uniAppX(options: UniAppXOptions): Partial<UserDefinedOptions>;
|
package/dist/presets.d.ts
CHANGED
|
@@ -1,76 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { e as UserDefinedOptions, U as UniAppXComponentLocalStylesOptions } from './index-BXrmQelt.js';
|
|
3
|
-
import '@babel/parser';
|
|
4
|
-
import '@weapp-tailwindcss/postcss/types';
|
|
5
|
-
import 'tailwindcss-patch';
|
|
6
|
-
import 'node:buffer';
|
|
7
|
-
import 'webpack';
|
|
8
|
-
import 'lru-cache';
|
|
9
|
-
|
|
10
|
-
interface BasePresetOptions extends Omit<Partial<UserDefinedOptions>, 'cssEntries'> {
|
|
11
|
-
base?: string;
|
|
12
|
-
cssEntries?: string | string[];
|
|
13
|
-
resolve?: PackageResolvingOptions;
|
|
14
|
-
rawOptions?: UserDefinedOptions;
|
|
15
|
-
}
|
|
16
|
-
declare function normalizeCssEntries(entries?: string | string[]): string[] | undefined;
|
|
17
|
-
declare function createBasePreset(options?: BasePresetOptions): Partial<UserDefinedOptions>;
|
|
18
|
-
|
|
19
|
-
interface UniAppPresetOptions extends BasePresetOptions {
|
|
20
|
-
}
|
|
21
|
-
declare function uniApp(options?: UniAppPresetOptions): Partial<UserDefinedOptions>;
|
|
22
|
-
|
|
23
|
-
interface UniAppXOptions {
|
|
24
|
-
/**
|
|
25
|
-
* uni-app x 工程根目录。
|
|
26
|
-
*/
|
|
27
|
-
base: string;
|
|
28
|
-
/**
|
|
29
|
-
* 指定 Tailwind CSS v4 的入口 CSS。
|
|
30
|
-
*/
|
|
31
|
-
cssEntries?: string[];
|
|
32
|
-
/**
|
|
33
|
-
* rem 转 rpx 配置。
|
|
34
|
-
*/
|
|
35
|
-
rem2rpx?: UserDefinedOptions['rem2rpx'];
|
|
36
|
-
/**
|
|
37
|
-
* 长度单位转 px 配置。
|
|
38
|
-
*/
|
|
39
|
-
unitsToPx?: UserDefinedOptions['unitsToPx'];
|
|
40
|
-
/**
|
|
41
|
-
* 透传原始插件配置。
|
|
42
|
-
*/
|
|
43
|
-
rawOptions?: UserDefinedOptions;
|
|
44
|
-
/**
|
|
45
|
-
* 自定义包解析路径。
|
|
46
|
-
*/
|
|
47
|
-
resolve?: PackageResolvingOptions;
|
|
48
|
-
/**
|
|
49
|
-
* 自定义模板属性转换规则。
|
|
50
|
-
*/
|
|
51
|
-
customAttributes?: UserDefinedOptions['customAttributes'];
|
|
52
|
-
/**
|
|
53
|
-
* 直接控制 `uniAppX.componentLocalStyles` 的快捷入口。
|
|
54
|
-
*
|
|
55
|
-
* @remarks
|
|
56
|
-
* 默认开启;默认仅在 `manifest.json` 的 `styleIsolationVersion=2` 时启用。
|
|
57
|
-
*/
|
|
58
|
-
uniAppX?: UserDefinedOptions['uniAppX'];
|
|
59
|
-
/**
|
|
60
|
-
* issue #822 组件局部样式能力的快捷开关。
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* 等价于设置 `uniAppX.componentLocalStyles`。
|
|
64
|
-
*/
|
|
65
|
-
componentLocalStyles?: boolean | UniAppXComponentLocalStylesOptions;
|
|
66
|
-
/**
|
|
67
|
-
* uvue 不兼容 utility 的处理策略。
|
|
68
|
-
*
|
|
69
|
-
* @remarks
|
|
70
|
-
* 等价于设置 `uniAppX.uvueUnsupported`。
|
|
71
|
-
*/
|
|
72
|
-
uvueUnsupported?: 'error' | 'warn' | 'silent';
|
|
73
|
-
}
|
|
74
|
-
declare function uniAppX(options: UniAppXOptions): Partial<UserDefinedOptions>;
|
|
75
|
-
|
|
76
|
-
export { type BasePresetOptions, type UniAppPresetOptions, type UniAppXOptions, createBasePreset, normalizeCssEntries, uniApp, uniAppX };
|
|
1
|
+
export * from './presets/index';
|