weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/bundlers/shared/generator-css.d.ts +5 -2
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -0
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
- package/dist/cli/context.d.ts +0 -3
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli.js +8 -2
- package/dist/cli.mjs +8 -2
- package/dist/constants.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro.d.ts +1 -0
- package/dist/defaults.js +5 -7
- package/dist/defaults.mjs +5 -7
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +3 -4
- package/dist/{generator-mmhXzZnv.js → generator-9UEp8OoQ.js} +259 -21
- package/dist/{generator-Y-Ikv4Fu.mjs → generator-Dpp-5s8z.mjs} +260 -22
- package/dist/{generator-css-CRLrHW4F.js → generator-css-CGueCYbX.js} +173 -32
- package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-MyjZhF0z.mjs} +173 -32
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/gulp.js +15 -11
- package/dist/gulp.mjs +15 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/{logger-BoVx1Dbt.mjs → logger-1gx9UllH.mjs} +21 -51
- package/dist/{logger-BZ45DZJT.js → logger-D9clu_3f.js} +21 -51
- package/dist/patcher-options-DnqazL9E.js +34 -0
- package/dist/patcher-options-GuOwX0-k.mjs +17 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +37 -28
- package/dist/postcss.mjs +37 -28
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/{recorder-XdFvVASS.mjs → recorder-BIW3Kuke.mjs} +5 -12
- package/dist/{recorder-GdTJ3QqX.js → recorder-D4BKt75Q.js} +5 -12
- package/dist/reset.d.ts +1 -0
- package/dist/{css-imports-BbrbluP9.js → run-tasks-Cq5A5nVD.js} +6 -55
- package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DUVrDJGl.mjs} +5 -42
- package/dist/tailwindcss/miniprogram.d.ts +5 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +1 -3
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +0 -2
- package/dist/types/user-defined-options/important.d.ts +3 -3
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/version-CWBxRFPB.js +56 -0
- package/dist/version-WNz3MwRv.mjs +49 -0
- package/dist/{vite-DgRh_GXn.js → vite-BkMGwDeH.js} +106 -39
- package/dist/{vite-BDywuCjn.mjs → vite-fDM-UQpR.mjs} +89 -22
- package/dist/vite.d.ts +1 -2
- package/dist/vite.js +3 -4
- package/dist/vite.mjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/{webpack-CAJR4hhP.js → webpack-CICGEKT9.js} +225 -43
- package/dist/{webpack-CiHqVZTg.mjs → webpack-D2Wdk28V.mjs} +214 -27
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +21 -30
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
- package/dist/experimental/index.d.ts +0 -2
- package/dist/experimental/oxc/ast-utils.d.ts +0 -30
- package/dist/experimental/oxc/index.d.ts +0 -2
- package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
- package/dist/experimental/shared/cache.d.ts +0 -3
- package/dist/experimental/shared/transform.d.ts +0 -3
- package/dist/experimental/shared.d.ts +0 -8
- package/dist/experimental/swc/ast-utils.d.ts +0 -30
- package/dist/experimental/swc/index.d.ts +0 -2
- package/dist/experimental/swc/module-specifiers.d.ts +0 -2
- package/dist/loader-anchors-1MumTAtA.mjs +0 -205
- package/dist/loader-anchors-TrFvT6g1.js +0 -273
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/webpack4.d.ts +0 -4
- package/dist/webpack4.js +0 -387
- package/dist/webpack4.mjs +0 -379
- package/scripts/postinstall.mjs +0 -59
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const require_generator = require("./generator-
|
|
3
|
-
const require_recorder = require("./recorder-
|
|
2
|
+
const require_generator = require("./generator-9UEp8OoQ.js");
|
|
3
|
+
const require_recorder = require("./recorder-D4BKt75Q.js");
|
|
4
4
|
let postcss = require("postcss");
|
|
5
5
|
postcss = require_chunk.__toESM(postcss);
|
|
6
6
|
let node_path = require("node:path");
|
|
@@ -166,7 +166,7 @@ function removeUnsupportedMiniProgramAtRules(css) {
|
|
|
166
166
|
if (MINI_PROGRAM_UNSUPPORTED_AT_RULES.has(atRule.name)) atRule.remove();
|
|
167
167
|
});
|
|
168
168
|
root.walkAtRules((atRule) => {
|
|
169
|
-
if (
|
|
169
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
170
170
|
});
|
|
171
171
|
return root.toString();
|
|
172
172
|
} catch {
|
|
@@ -567,6 +567,10 @@ function inheritLegacyUnitConvertedDeclarations(css, legacyCss) {
|
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOptions) {
|
|
570
|
+
const tailwindV3StyleOptions = cssHandlerOptions.majorVersion === 3 ? {
|
|
571
|
+
cssPreflight: opts.cssPreflight,
|
|
572
|
+
cssPreflightRange: opts.cssPreflightRange
|
|
573
|
+
} : {};
|
|
570
574
|
return {
|
|
571
575
|
cssChildCombinatorReplaceValue: opts.cssChildCombinatorReplaceValue,
|
|
572
576
|
cssSelectorReplacement: opts.cssSelectorReplacement,
|
|
@@ -583,6 +587,7 @@ function resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorStyleOpt
|
|
|
583
587
|
uniAppXCssTarget: opts.uniAppXCssTarget,
|
|
584
588
|
uniAppXUnsupported: opts.uniAppXUnsupported,
|
|
585
589
|
...cssHandlerOptions,
|
|
590
|
+
...tailwindV3StyleOptions,
|
|
586
591
|
...generatorStyleOptions
|
|
587
592
|
};
|
|
588
593
|
}
|
|
@@ -592,6 +597,9 @@ function parseImportRequest(params) {
|
|
|
592
597
|
function parseConfigRequest(params) {
|
|
593
598
|
return /^(["'])(.+)\1\s*;?$/.exec(params.trim())?.[2];
|
|
594
599
|
}
|
|
600
|
+
function isPackageJsonImportRequest(request) {
|
|
601
|
+
return typeof request === "string" && request.startsWith("#");
|
|
602
|
+
}
|
|
595
603
|
function resolvePostcssFromOption(cssHandlerOptions) {
|
|
596
604
|
const from = cssHandlerOptions.postcssOptions?.options?.from;
|
|
597
605
|
return typeof from === "string" && from.length > 0 ? from : void 0;
|
|
@@ -609,11 +617,13 @@ function isTailwindImportAtRule(node) {
|
|
|
609
617
|
function isTailwindSourceDirective(node) {
|
|
610
618
|
if (node.type !== "atrule") return false;
|
|
611
619
|
if (isTailwindImportAtRule(node)) return true;
|
|
620
|
+
if (node.name === "import" && isPackageJsonImportRequest(parseImportRequest(node.params))) return true;
|
|
612
621
|
return TAILWIND_REMOVABLE_SOURCE_DIRECTIVE_NAMES.has(node.name);
|
|
613
622
|
}
|
|
614
623
|
function isTailwindGenerationDirective(node) {
|
|
615
624
|
if (node.type !== "atrule") return false;
|
|
616
|
-
|
|
625
|
+
const request = node.name === "import" ? parseImportRequest(node.params) : node.name === "config" || node.name === "plugin" || node.name === "reference" ? parseConfigRequest(node.params) : void 0;
|
|
626
|
+
return isTailwindImportAtRule(node) || isPackageJsonImportRequest(request) || node.name === "apply" || node.name === "layer" || node.name === "config" || node.name === "source";
|
|
617
627
|
}
|
|
618
628
|
function removeTailwindSourceDirectives(rawSource) {
|
|
619
629
|
try {
|
|
@@ -661,7 +671,7 @@ function resolveCssEntrySource(rawSource, base, options = {}) {
|
|
|
661
671
|
const configPath = parseConfigRequest(node.params);
|
|
662
672
|
if (configPath && !config) {
|
|
663
673
|
configRequest = configPath;
|
|
664
|
-
config = node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
674
|
+
config = isPackageJsonImportRequest(configPath) ? void 0 : node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
665
675
|
}
|
|
666
676
|
if (removeConfig) {
|
|
667
677
|
node.remove();
|
|
@@ -700,6 +710,20 @@ function resolveExistingConfigPath(config, configRequest, file, sourceOptions) {
|
|
|
700
710
|
}
|
|
701
711
|
return sourceOptions.config;
|
|
702
712
|
}
|
|
713
|
+
function quoteCssString(value) {
|
|
714
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
715
|
+
}
|
|
716
|
+
function toCssPath(value) {
|
|
717
|
+
return value.replaceAll("\\", "/");
|
|
718
|
+
}
|
|
719
|
+
function prependConfigDirective(css, config) {
|
|
720
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
721
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
722
|
+
}
|
|
723
|
+
function normalizeConfigDirective(css, config) {
|
|
724
|
+
if (!config || !/@config\s+/.test(css)) return css;
|
|
725
|
+
return css.replace(/@config\s+(["'])(.+?)\1\s*;?/, `@config "${quoteCssString(toCssPath(config))}";`);
|
|
726
|
+
}
|
|
703
727
|
function stripStyleExtension(file) {
|
|
704
728
|
return file.replace(/[?#].*$/, "").replace(/\.(?:wx|ac|jx|tt|q|c|ty)?ss$/i, "");
|
|
705
729
|
}
|
|
@@ -741,6 +765,11 @@ function createSourceStylePathCandidates(file, sourceOptions) {
|
|
|
741
765
|
}
|
|
742
766
|
return [...candidates];
|
|
743
767
|
}
|
|
768
|
+
function canResolveSourceSideCssEntry(file, cssHandlerOptions) {
|
|
769
|
+
const from = resolvePostcssFromOption(cssHandlerOptions);
|
|
770
|
+
if (!from || !node_path.default.isAbsolute(from)) return node_path.default.isAbsolute(file);
|
|
771
|
+
return true;
|
|
772
|
+
}
|
|
744
773
|
function extractStyleDirectiveSources(source) {
|
|
745
774
|
const styleSources = [];
|
|
746
775
|
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
@@ -770,6 +799,34 @@ function resolveSourceSideCssEntrySource(file, sourceOptions, resolveOptions = {
|
|
|
770
799
|
}
|
|
771
800
|
}
|
|
772
801
|
}
|
|
802
|
+
function normalizeCssSourceForCompare(css) {
|
|
803
|
+
return stripGeneratorPlaceholderMarkers(stripTailwindBanners(css)).trim();
|
|
804
|
+
}
|
|
805
|
+
function getOutputFileStem(file) {
|
|
806
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
807
|
+
return node_path.default.basename(normalized, node_path.default.extname(normalized));
|
|
808
|
+
}
|
|
809
|
+
function resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) {
|
|
810
|
+
const cssEntries = sourceOptions.cssEntries;
|
|
811
|
+
if (!cssEntries?.length) return;
|
|
812
|
+
const normalizedRawSource = normalizeCssSourceForCompare(rawSource);
|
|
813
|
+
const outputStem = getOutputFileStem(file);
|
|
814
|
+
const matchingEntry = cssEntries.find((cssEntry) => {
|
|
815
|
+
if (!(0, node_fs.existsSync)(cssEntry)) return false;
|
|
816
|
+
try {
|
|
817
|
+
if (normalizeCssSourceForCompare((0, node_fs.readFileSync)(cssEntry, "utf8")) === normalizedRawSource) return true;
|
|
818
|
+
return outputStem.length > 0 && getOutputFileStem(cssEntry) === outputStem;
|
|
819
|
+
} catch {
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
if (!matchingEntry) return;
|
|
824
|
+
return require_generator.resolveTailwindV4Source({
|
|
825
|
+
...sourceOptions,
|
|
826
|
+
css: void 0,
|
|
827
|
+
cssEntries: [matchingEntry]
|
|
828
|
+
});
|
|
829
|
+
}
|
|
773
830
|
function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
774
831
|
try {
|
|
775
832
|
return require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
@@ -777,16 +834,20 @@ function tryResolveTailwindV4SourceOptions(runtimeState) {
|
|
|
777
834
|
return;
|
|
778
835
|
}
|
|
779
836
|
}
|
|
780
|
-
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
837
|
+
async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
|
|
781
838
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
782
839
|
if (majorVersion === 3) {
|
|
783
840
|
const sourceOptions = require_generator.resolveTailwindV3SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
784
|
-
const
|
|
841
|
+
const mergedSourceOptions = {
|
|
842
|
+
...sourceOptions,
|
|
843
|
+
config: generatorOptions?.config ?? sourceOptions.config
|
|
844
|
+
};
|
|
845
|
+
const sourceSideEntrySource = canResolveSourceSideCssEntry(file, cssHandlerOptions) ? resolveSourceSideCssEntrySource(file, mergedSourceOptions, { removeConfig: true }) : void 0;
|
|
785
846
|
const resolvedEntrySource = cssEntrySource ?? sourceSideEntrySource;
|
|
786
|
-
if (!resolvedEntrySource) return require_generator.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
787
|
-
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file,
|
|
847
|
+
if (!resolvedEntrySource) return generatorOptions?.config ? require_generator.resolveTailwindV3Source(mergedSourceOptions) : require_generator.resolveTailwindV3SourceFromPatcher(runtimeState.twPatcher);
|
|
848
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, mergedSourceOptions);
|
|
788
849
|
return require_generator.resolveTailwindV3Source({
|
|
789
|
-
...
|
|
850
|
+
...mergedSourceOptions,
|
|
790
851
|
base: resolvedEntrySource.base,
|
|
791
852
|
css: resolvedEntrySource.css,
|
|
792
853
|
...config ? { config } : {}
|
|
@@ -794,29 +855,46 @@ async function resolveGeneratorSource(majorVersion, runtimeState, rawSource, fil
|
|
|
794
855
|
}
|
|
795
856
|
const sourceOptions = tryResolveTailwindV4SourceOptions(runtimeState);
|
|
796
857
|
const shouldPreferSourceSideEntry = shouldResolveSourceSideCssEntry(rawSource) || Boolean(cssEntrySource?.css.includes("weapp-tailwindcss generator-placeholder"));
|
|
797
|
-
const
|
|
798
|
-
|
|
858
|
+
const sourceSideEntrySource = sourceOptions && shouldPreferSourceSideEntry ? resolveSourceSideCssEntrySource(file, sourceOptions, { removeConfig: false }) : void 0;
|
|
859
|
+
const matchedCssEntrySource = sourceOptions && cssEntrySource ? await resolveMatchingTailwindV4CssEntry(rawSource, file, sourceOptions) : void 0;
|
|
860
|
+
if (matchedCssEntrySource) return generatorOptions?.config ? {
|
|
861
|
+
...matchedCssEntrySource,
|
|
862
|
+
css: prependConfigDirective(matchedCssEntrySource.css, generatorOptions.config)
|
|
863
|
+
} : matchedCssEntrySource;
|
|
864
|
+
const resolvedEntrySource = sourceSideEntrySource ?? cssEntrySource;
|
|
865
|
+
if (!resolvedEntrySource) {
|
|
866
|
+
const source = await require_generator.resolveTailwindV4SourceFromPatcher(runtimeState.twPatcher);
|
|
867
|
+
return generatorOptions?.config ? {
|
|
868
|
+
...source,
|
|
869
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
870
|
+
} : source;
|
|
871
|
+
}
|
|
872
|
+
const resolvedSourceOptions = sourceOptions ?? {};
|
|
873
|
+
const config = resolveExistingConfigPath(resolvedEntrySource.config, resolvedEntrySource.configRequest, file, resolvedSourceOptions);
|
|
799
874
|
return require_generator.resolveTailwindV4Source({
|
|
800
|
-
...
|
|
875
|
+
...resolvedSourceOptions,
|
|
801
876
|
base: resolvedEntrySource.base,
|
|
802
|
-
css: resolvedEntrySource.css
|
|
877
|
+
css: normalizeConfigDirective(prependConfigDirective(resolvedEntrySource.css, generatorOptions?.config), config)
|
|
803
878
|
});
|
|
804
879
|
}
|
|
805
|
-
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions) {
|
|
880
|
+
async function resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions) {
|
|
806
881
|
const cssEntrySource = resolveCssEntrySource(rawSource, resolveCssSourceBase(file, cssHandlerOptions), { removeConfig: majorVersion === 3 });
|
|
807
|
-
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
882
|
+
if (majorVersion !== 4 || cssEntrySource && !cssHandlerOptions.isMainChunk) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
808
883
|
let sourceOptions;
|
|
809
884
|
try {
|
|
810
885
|
sourceOptions = require_generator.resolveTailwindV4SourceOptionsFromPatcher(runtimeState.twPatcher);
|
|
811
886
|
} catch {
|
|
812
|
-
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
887
|
+
return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
813
888
|
}
|
|
814
|
-
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions)];
|
|
889
|
+
if (!sourceOptions.cssEntries || sourceOptions.cssEntries.length <= 1) return [await resolveGeneratorSource(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions)];
|
|
815
890
|
return await Promise.all(sourceOptions.cssEntries.map((cssEntry) => require_generator.resolveTailwindV4Source({
|
|
816
891
|
...sourceOptions,
|
|
817
892
|
css: void 0,
|
|
818
893
|
cssEntries: [cssEntry]
|
|
819
|
-
}))
|
|
894
|
+
}).then((source) => generatorOptions?.config ? {
|
|
895
|
+
...source,
|
|
896
|
+
css: prependConfigDirective(source.css, generatorOptions.config)
|
|
897
|
+
} : source)));
|
|
820
898
|
}
|
|
821
899
|
function isLocalImportRequest(request) {
|
|
822
900
|
return request.length > 0 && !request.startsWith("tailwindcss") && !request.startsWith("weapp-tailwindcss") && !request.startsWith("data:") && !REMOTE_IMPORT_RE.test(request);
|
|
@@ -837,8 +915,62 @@ function isPureLocalCssImportWrapper(css) {
|
|
|
837
915
|
}
|
|
838
916
|
return hasImport;
|
|
839
917
|
}
|
|
918
|
+
function cleanLocalCssImportWrapperTailwindDirectives(css) {
|
|
919
|
+
let hasLocalImport = false;
|
|
920
|
+
let hasTailwindDirective = false;
|
|
921
|
+
try {
|
|
922
|
+
const root = postcss.default.parse(css);
|
|
923
|
+
for (const node of root.nodes) {
|
|
924
|
+
if (node.type === "comment") continue;
|
|
925
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
926
|
+
const request = parseImportRequest(node.params);
|
|
927
|
+
if (!request || !isLocalImportRequest(request)) return;
|
|
928
|
+
hasLocalImport = true;
|
|
929
|
+
continue;
|
|
930
|
+
}
|
|
931
|
+
if (node.type === "atrule" && node.name === "source") {
|
|
932
|
+
hasTailwindDirective = true;
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
} catch {
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
return hasLocalImport && hasTailwindDirective ? prefixLocalCssImportsWithWebpackIgnore(removeTailwindSourceDirectives(css)) : void 0;
|
|
941
|
+
}
|
|
942
|
+
function prefixLocalCssImportsWithWebpackIgnore(css) {
|
|
943
|
+
try {
|
|
944
|
+
const root = postcss.default.parse(css);
|
|
945
|
+
root.walkAtRules("import", (atRule) => {
|
|
946
|
+
const request = parseImportRequest(atRule.params);
|
|
947
|
+
if (request && isLocalImportRequest(request)) atRule.raws.before = `${atRule.raws.before ?? ""}/* webpackIgnore: true */\n`;
|
|
948
|
+
});
|
|
949
|
+
return root.toString();
|
|
950
|
+
} catch {
|
|
951
|
+
return css;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
840
954
|
function resolveLegacyCompatCssSource(rawSource) {
|
|
841
|
-
return removeUnsupportedMiniProgramAtRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource)));
|
|
955
|
+
return removeUnsupportedMiniProgramAtRules(removeTailwindApplyRules(removeTailwindSourceDirectives(stripTailwindBanners(rawSource))));
|
|
956
|
+
}
|
|
957
|
+
function removeTailwindApplyRules(rawSource) {
|
|
958
|
+
try {
|
|
959
|
+
const root = postcss.default.parse(rawSource);
|
|
960
|
+
let removed = false;
|
|
961
|
+
root.walkAtRules("apply", (rule) => {
|
|
962
|
+
const parent = rule.parent;
|
|
963
|
+
if (parent?.type === "rule") parent.remove();
|
|
964
|
+
else rule.remove();
|
|
965
|
+
removed = true;
|
|
966
|
+
});
|
|
967
|
+
root.walkAtRules((rule) => {
|
|
968
|
+
if (rule.nodes && rule.nodes.length === 0) rule.remove();
|
|
969
|
+
});
|
|
970
|
+
return removed ? root.toString() : rawSource;
|
|
971
|
+
} catch {
|
|
972
|
+
return rawSource;
|
|
973
|
+
}
|
|
842
974
|
}
|
|
843
975
|
function hasContainerConfigToken(rawSource) {
|
|
844
976
|
return rawSource.includes("@config") && /\bcontainer\b/.test(rawSource);
|
|
@@ -945,7 +1077,7 @@ function removeGeneratedSelectorCompatCss(css, generatedCss) {
|
|
|
945
1077
|
}
|
|
946
1078
|
});
|
|
947
1079
|
root.walkAtRules((atRule) => {
|
|
948
|
-
if (
|
|
1080
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
949
1081
|
});
|
|
950
1082
|
return removed ? root.toString() : css;
|
|
951
1083
|
} catch {
|
|
@@ -1018,22 +1150,28 @@ async function generateCssByGenerator(options) {
|
|
|
1018
1150
|
const { opts, runtimeState, runtime, rawSource, file, cssHandlerOptions, cssUserHandlerOptions, styleHandler, debug } = options;
|
|
1019
1151
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1020
1152
|
const majorVersion = runtimeState.twPatcher.majorVersion;
|
|
1153
|
+
const cleanedLocalImportWrapper = cleanLocalCssImportWrapperTailwindDirectives(rawSource);
|
|
1154
|
+
if (cleanedLocalImportWrapper !== void 0) return {
|
|
1155
|
+
css: generatorOptions.target === "weapp" ? removeUnsupportedMiniProgramAtRules(cleanedLocalImportWrapper) : cleanedLocalImportWrapper,
|
|
1156
|
+
target: generatorOptions.target,
|
|
1157
|
+
source: "generator",
|
|
1158
|
+
dependencies: []
|
|
1159
|
+
};
|
|
1021
1160
|
if (isPureLocalCssImportWrapper(rawSource)) return;
|
|
1022
1161
|
const hasGeneratedCss = hasTailwindGeneratedCss(rawSource);
|
|
1023
1162
|
const hasSourceDirectives = hasTailwindSourceDirectives(rawSource);
|
|
1024
1163
|
const hasGeneratedMarkers = hasTailwindGeneratedCssMarkers(rawSource);
|
|
1025
|
-
const
|
|
1026
|
-
|
|
1027
|
-
if (generatorOptions.mode === "off" || !SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || (generatorOptions.mode === "force" ? !shouldForceGenerateCurrentCss : !shouldAutoGenerateCurrentCss) || generatorOptions.mode === "force" && majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers || generatorOptions.mode !== "force" && majorVersion === 3) return;
|
|
1164
|
+
const shouldGenerateCurrentCss = hasGeneratedCss || hasGeneratedMarkers || hasSourceDirectives || cssHandlerOptions.isMainChunk;
|
|
1165
|
+
if (!SUPPORTED_GENERATOR_MAJOR_VERSIONS.has(majorVersion ?? 0) || !shouldGenerateCurrentCss || majorVersion === 3 && !hasSourceDirectives && !hasGeneratedCss && !hasGeneratedMarkers) return;
|
|
1028
1166
|
try {
|
|
1029
1167
|
await runtimeState.patchPromise;
|
|
1030
|
-
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions);
|
|
1168
|
+
const sources = await resolveGeneratorSources(majorVersion, runtimeState, rawSource, file, cssHandlerOptions, generatorOptions);
|
|
1031
1169
|
const generatorStyleOptions = resolveGeneratorStyleOptions(opts, cssHandlerOptions, generatorOptions.styleOptions);
|
|
1032
1170
|
const configuredContainerCompat = hasConfiguredContainerCompatSources(sources);
|
|
1033
1171
|
const generatedResults = await Promise.all(sources.map(async (source) => {
|
|
1034
1172
|
return require_generator.createWeappTailwindcssGenerator(source).generate({
|
|
1035
1173
|
candidates: runtime,
|
|
1036
|
-
scanSources:
|
|
1174
|
+
scanSources: majorVersion === 4,
|
|
1037
1175
|
styleOptions: generatorStyleOptions,
|
|
1038
1176
|
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
1039
1177
|
target: generatorOptions.target
|
|
@@ -1061,7 +1199,8 @@ async function generateCssByGenerator(options) {
|
|
|
1061
1199
|
if (extraSource.trim().length === 0) return {
|
|
1062
1200
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1063
1201
|
target: generated.target,
|
|
1064
|
-
source: "generator"
|
|
1202
|
+
source: "generator",
|
|
1203
|
+
dependencies: generated.dependencies
|
|
1065
1204
|
};
|
|
1066
1205
|
if (generated.target === "weapp") {
|
|
1067
1206
|
const { css: userCss } = await styleHandler(extraSource, {
|
|
@@ -1072,14 +1211,15 @@ async function generateCssByGenerator(options) {
|
|
|
1072
1211
|
} else css = createCssAppend(css, extraSource);
|
|
1073
1212
|
}
|
|
1074
1213
|
}
|
|
1075
|
-
if (generated.target === "weapp"
|
|
1214
|
+
if (generated.target === "weapp") {
|
|
1076
1215
|
css = await appendLegacyCompatCss(css, rawSource, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1077
1216
|
css = await appendLegacyContainerCompatCss(css, rawSource, file, runtime, configuredContainerCompat, generated.target, styleHandler, cssHandlerOptions, generatorStyleOptions);
|
|
1078
1217
|
}
|
|
1079
1218
|
return {
|
|
1080
1219
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1081
1220
|
target: generated.target,
|
|
1082
|
-
source: "generator"
|
|
1221
|
+
source: "generator",
|
|
1222
|
+
dependencies: generated.dependencies
|
|
1083
1223
|
};
|
|
1084
1224
|
}
|
|
1085
1225
|
debug("tailwind direct css generation prefix mismatch, append transformed bundle css %s", file);
|
|
@@ -1090,11 +1230,12 @@ async function generateCssByGenerator(options) {
|
|
|
1090
1230
|
return {
|
|
1091
1231
|
css: finalizeMiniProgramGeneratorCss(css, generated.target),
|
|
1092
1232
|
target: generated.target,
|
|
1093
|
-
source:
|
|
1233
|
+
source: "generator",
|
|
1234
|
+
dependencies: generated.dependencies
|
|
1094
1235
|
};
|
|
1095
1236
|
} catch (error) {
|
|
1096
|
-
|
|
1097
|
-
|
|
1237
|
+
debug("tailwind direct css generation failed: %s %O", file, error);
|
|
1238
|
+
throw error;
|
|
1098
1239
|
}
|
|
1099
1240
|
}
|
|
1100
1241
|
//#endregion
|