weapp-tailwindcss 5.0.0-next.2 → 5.0.0-next.21
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 +6 -7
- package/bin/weapp-tailwindcss.js +1 -21
- package/dist/bundle-state-BnV8o2Yn.js +530 -0
- package/dist/bundle-state-CLnuf2CW.mjs +414 -0
- package/dist/bundlers/shared/cache.d.ts +6 -6
- package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -4
- package/dist/bundlers/shared/css-imports.d.ts +3 -3
- package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
- package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
- package/dist/bundlers/shared/generator-css.d.ts +16 -22
- package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
- package/dist/bundlers/shared/style-requests.d.ts +2 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
- package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
- package/dist/bundlers/vite/index.d.ts +1 -1
- package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
- package/dist/bundlers/vite/postcss-config.d.ts +6 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
- package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
- package/dist/bundlers/vite/source-candidates.d.ts +16 -1
- package/dist/bundlers/vite/source-scan.d.ts +26 -0
- package/dist/bundlers/vite/static-config-content.d.ts +5 -0
- package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
- package/dist/cache/index.d.ts +6 -6
- package/dist/cli/context.d.ts +1 -14
- package/dist/cli/doctor/types.d.ts +11 -11
- package/dist/cli/helpers.d.ts +1 -2
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/types.d.ts +0 -2
- package/dist/cli/vscode-entry.d.ts +3 -3
- package/dist/cli.js +605 -611
- package/dist/cli.mjs +614 -620
- package/dist/constants.d.ts +1 -2
- package/dist/core.js +13 -20
- package/dist/core.mjs +8 -14
- package/dist/css-macro/postcss.js +3 -2
- package/dist/css-macro/postcss.mjs +3 -2
- package/dist/css-macro.d.ts +1 -0
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults-B1igPF_e.mjs +150 -0
- package/dist/defaults-IHhYxNeU.js +193 -0
- package/dist/defaults.d.ts +15 -1
- package/dist/defaults.js +6 -131
- package/dist/defaults.mjs +2 -129
- package/dist/escape.js +10 -2
- package/dist/escape.mjs +10 -2
- package/dist/generator/index.d.ts +1 -1
- package/dist/generator/options.d.ts +9 -8
- package/dist/generator/types.d.ts +3 -3
- package/dist/generator-B4RNgMLx.js +55 -0
- package/dist/generator-DvyhmC76.mjs +32 -0
- package/dist/generator.js +12 -11
- package/dist/generator.mjs +2 -1
- package/dist/gulp.js +185 -47
- package/dist/gulp.mjs +179 -41
- package/dist/incremental-runtime-class-set-C7Q7fC5u.mjs +1863 -0
- package/dist/incremental-runtime-class-set-DZsbM0-a.js +1926 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/js/babel/cache-options.d.ts +3 -0
- package/dist/js/babel/parse.d.ts +7 -4
- package/dist/js/index.d.ts +1 -0
- package/dist/js/literal-transform.d.ts +2 -0
- package/dist/js/precheck.d.ts +2 -2
- package/dist/logger-CZUxvJJD.mjs +2 -0
- package/dist/logger-EVNB9z7i.js +1 -0
- package/dist/postcss/config-directive.d.ts +1 -0
- package/dist/postcss/context.d.ts +9 -0
- package/dist/postcss/source-files.d.ts +8 -0
- package/dist/postcss/tailwind-version.d.ts +3 -0
- package/dist/postcss-CFa6-qO9.js +237 -0
- package/dist/postcss-Drpy7j-g.mjs +228 -0
- package/dist/postcss.d.ts +2 -2
- package/dist/postcss.js +3 -276
- package/dist/postcss.mjs +1 -269
- package/dist/{recorder-gYSNLfOP.js → precheck-8pQbjqpq.js} +218 -314
- package/dist/{recorder-zsgatmkB.mjs → precheck-D1O5AWzy.mjs} +186 -281
- package/dist/presets.js +13 -11
- package/dist/presets.mjs +11 -9
- package/dist/reset.d.ts +1 -0
- package/dist/runtime-registry-CdCV3Opt.js +5496 -0
- package/dist/shared/mpx.d.ts +1 -0
- package/dist/source-candidates-CUTNdsiz.js +222 -0
- package/dist/source-candidates-CnD4vyic.mjs +209 -0
- package/dist/tailwindcss/miniprogram.d.ts +1 -1
- package/dist/tailwindcss/patcher-options.d.ts +3 -51
- package/dist/tailwindcss/patcher.d.ts +1 -2
- package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
- package/dist/tailwindcss/runtime/cache.d.ts +4 -3
- package/dist/tailwindcss/runtime-patch.d.ts +5 -0
- package/dist/tailwindcss/runtime.d.ts +11 -12
- package/dist/tailwindcss/source-scan.d.ts +35 -0
- package/dist/tailwindcss/targets.d.ts +1 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
- package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
- package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
- package/dist/tailwindcss/v4/patcher.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
- package/dist/tailwindcss/version.d.ts +4 -0
- package/dist/tailwindcss-B_JAdOQf.mjs +600 -0
- package/dist/tailwindcss-whZE3HpL.js +651 -0
- package/dist/typedoc.export.d.ts +0 -2
- package/dist/types/index.d.ts +51 -48
- package/dist/types/shared.d.ts +3 -0
- package/dist/types/user-defined-options/general.d.ts +23 -23
- package/dist/types/user-defined-options/important.d.ts +31 -28
- package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
- package/dist/types/user-defined-options/matcher.d.ts +6 -6
- package/dist/uni-app-x/vite.d.ts +1 -1
- package/dist/utils/disabled.d.ts +2 -3
- package/dist/utils/object.d.ts +9 -0
- package/dist/{utils-DmC9_In3.js → utils-4ODFyoqD.js} +1 -1
- package/dist/{utils-7DUGTFED.mjs → utils-CGBVVNm6.mjs} +1 -1
- package/dist/v3-engine-CCwvhRrQ.js +3473 -0
- package/dist/v3-engine-DyIcbpZm.mjs +3190 -0
- package/dist/{vite-CrlzCNqz.mjs → vite-B8IiXgVD.mjs} +1256 -1088
- package/dist/vite-BcnwgJMt.js +2368 -0
- 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 +4533 -16
- package/dist/weapp-tw-runtime-classset-loader.js +33 -7
- package/dist/webpack-C4zI624R.js +846 -0
- package/dist/webpack-DTkshAtp.mjs +836 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +27 -37
- package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
- 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/bundlers/webpack/shared/css-imports.d.ts +0 -6
- package/dist/cli/config.d.ts +0 -5
- package/dist/cli/helpers/patch-cwd.d.ts +0 -1
- package/dist/cli/mount-options/patch-status.d.ts +0 -2
- package/dist/cli/patch-options.d.ts +0 -6
- package/dist/cli/tokens.d.ts +0 -4
- package/dist/cli/workspace/package-dirs.d.ts +0 -3
- package/dist/cli/workspace/patch-package.d.ts +0 -3
- package/dist/cli/workspace/patch-utils.d.ts +0 -3
- package/dist/cli/workspace/types.d.ts +0 -11
- package/dist/cli/workspace/workspace-globs.d.ts +0 -2
- package/dist/cli/workspace/workspace-io.d.ts +0 -1
- package/dist/cli/workspace/workspace-lock.d.ts +0 -1
- package/dist/cli/workspace.d.ts +0 -2
- package/dist/css-imports-BbrbluP9.js +0 -177
- package/dist/css-imports-CSdPq_Sc.mjs +0 -128
- 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/generator-Y-Ikv4Fu.mjs +0 -1177
- package/dist/generator-css-B5ejWUMv.mjs +0 -1098
- package/dist/generator-css-D3OdPRiS.js +0 -1125
- package/dist/generator-mmhXzZnv.js +0 -1276
- package/dist/js/syntax.d.ts +0 -10
- package/dist/lightningcss/index.d.ts +0 -8
- package/dist/lightningcss/style-handler/options.d.ts +0 -3
- package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
- package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
- package/dist/lightningcss/style-handler.d.ts +0 -17
- package/dist/loader-anchors-CNkWT8hx.js +0 -273
- package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
- package/dist/logger-BZ45DZJT.js +0 -1003
- package/dist/logger-BoVx1Dbt.mjs +0 -935
- package/dist/patcher-options-6gJN2EXy.js +0 -115
- package/dist/patcher-options-DQfR5xxT.mjs +0 -92
- package/dist/tailwindcss/recorder.d.ts +0 -13
- package/dist/tailwindcss/targets/paths.d.ts +0 -13
- package/dist/tailwindcss/targets/record-io.d.ts +0 -5
- package/dist/tailwindcss/targets/recorder.d.ts +0 -3
- package/dist/tailwindcss/targets/types.d.ts +0 -35
- package/dist/types/disabled-options.d.ts +0 -4
- package/dist/vite-BC9U7ahn.js +0 -2199
- package/dist/webpack-Bu6M-Hbw.mjs +0 -441
- package/dist/webpack-DD7A6V0u.js +0 -456
- 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
- /package/dist/{constants-B-_T5UnW.mjs → constants-BG12WAKw.mjs} +0 -0
- /package/dist/{constants-p1dyh1x1.js → constants-BeeyfJ9k.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { createPlugins } from './gulp';
|
|
|
4
4
|
export { weappTailwindcssPostcssPlugin } from './postcss';
|
|
5
5
|
export type { WeappTailwindcssPostcssPluginOptions } from './postcss';
|
|
6
6
|
export type * from './types';
|
|
7
|
-
export {
|
|
7
|
+
export { WeappTailwindcss } from './vite';
|
|
8
8
|
export { UnifiedWebpackPluginV5, weappTailwindcssPackageDir } from './webpack';
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generator = require("./generator-
|
|
2
|
+
const require_generator = require("./generator-B4RNgMLx.js");
|
|
3
3
|
const require_gulp = require("./gulp.js");
|
|
4
|
-
const require_postcss = require("./postcss.js");
|
|
5
|
-
const require_vite = require("./vite-
|
|
6
|
-
const require_webpack = require("./webpack-
|
|
7
|
-
exports.UnifiedViteWeappTailwindcssPlugin = require_vite.UnifiedViteWeappTailwindcssPlugin;
|
|
4
|
+
const require_postcss = require("./postcss-CFa6-qO9.js");
|
|
5
|
+
const require_vite = require("./vite-BcnwgJMt.js");
|
|
6
|
+
const require_webpack = require("./webpack-C4zI624R.js");
|
|
8
7
|
exports.UnifiedWebpackPluginV5 = require_webpack.UnifiedWebpackPluginV5;
|
|
8
|
+
exports.WeappTailwindcss = require_vite.WeappTailwindcss;
|
|
9
9
|
exports.createPlugins = require_gulp.createPlugins;
|
|
10
10
|
exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
|
|
11
11
|
exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
|
|
12
|
-
exports.weappTailwindcssPostcssPlugin = require_postcss;
|
|
12
|
+
exports.weappTailwindcssPostcssPlugin = require_postcss.weappTailwindcssPostcssPlugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createWeappTailwindcssGenerator } from "./generator-
|
|
1
|
+
import { t as createWeappTailwindcssGenerator } from "./generator-DvyhmC76.mjs";
|
|
2
2
|
import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
|
|
3
|
-
import weappTailwindcssPostcssPlugin from "./postcss.mjs";
|
|
4
|
-
import { t as
|
|
5
|
-
import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-
|
|
6
|
-
export {
|
|
3
|
+
import { t as weappTailwindcssPostcssPlugin } from "./postcss-Drpy7j-g.mjs";
|
|
4
|
+
import { t as WeappTailwindcss } from "./vite-B8IiXgVD.mjs";
|
|
5
|
+
import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-DTkshAtp.mjs";
|
|
6
|
+
export { UnifiedWebpackPluginV5, WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
|
package/dist/js/babel/parse.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { ParseResult, ParserOptions } from '@babel/parser';
|
|
2
2
|
import type { File } from '@babel/types';
|
|
3
3
|
import { LRUCache } from 'lru-cache';
|
|
4
|
+
export type BabelParseOptions = ParserOptions & {
|
|
5
|
+
cache?: boolean | undefined;
|
|
6
|
+
cacheKey?: string | undefined;
|
|
7
|
+
cacheMaxEntries?: number | undefined;
|
|
8
|
+
cacheMaxSourceLength?: number | undefined;
|
|
9
|
+
};
|
|
4
10
|
export declare const parseCache: LRUCache<string, ParseResult<File>>;
|
|
5
11
|
export declare function genCacheKey(source: string, options: any): string;
|
|
6
|
-
export declare function babelParse(code: string, opts?:
|
|
7
|
-
cache?: boolean;
|
|
8
|
-
cacheKey?: string;
|
|
9
|
-
})): ParseResult<File>;
|
|
12
|
+
export declare function babelParse(code: string, opts?: BabelParseOptions): ParseResult<File>;
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CreateJsHandlerOptions, JsHandler } from '../types';
|
|
2
2
|
import { jsHandler } from './babel';
|
|
3
3
|
export { jsHandler, };
|
|
4
|
+
export { transformLiteralText } from './literal-transform';
|
|
4
5
|
export declare function createJsHandler(options: CreateJsHandlerOptions): JsHandler;
|
package/dist/js/precheck.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function shouldSkipJsTransform(rawSource: string, options?:
|
|
1
|
+
import type { IJsHandlerOptions } from '../types';
|
|
2
|
+
export declare function shouldSkipJsTransform(rawSource: string, options?: IJsHandlerOptions): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require("@weapp-tailwindcss/logger");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prependConfigDirective(css: string, config: string | undefined): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Result, Root } from 'postcss';
|
|
2
|
+
import type { WeappTailwindcssGenerateResult } from '../generator';
|
|
3
|
+
import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
|
|
4
|
+
export declare function resolveInputFile(result: Result): string | undefined;
|
|
5
|
+
export declare function resolvePostcssBase(result: Result, options: WeappTailwindcssPostcssPluginOptions): string;
|
|
6
|
+
export declare function resolvePostcssProjectRoot(result: Result, options: WeappTailwindcssPostcssPluginOptions): string;
|
|
7
|
+
export declare function replaceRootCss(root: Root, css: string, result: Result): void;
|
|
8
|
+
export declare function addDependencyMessages(result: Result, generated: WeappTailwindcssGenerateResult): void;
|
|
9
|
+
export declare function addSourceDependencyMessages(result: Result, files: string[]): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Result, Root } from 'postcss';
|
|
2
|
+
import type { TailwindV4CandidateSource } from '../generator';
|
|
3
|
+
import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
|
|
4
|
+
export declare function collectAutoTailwindCandidates(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): Promise<Set<string>>;
|
|
5
|
+
export declare function collectPostcssLocalSources(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): Promise<{
|
|
6
|
+
files: string[];
|
|
7
|
+
sources: TailwindV4CandidateSource[];
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Result, Root } from 'postcss';
|
|
2
|
+
import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
|
|
3
|
+
export declare function resolvePostcssTailwindVersion(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): import("../tailwindcss/version").SupportedTailwindcssMajorVersion;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
+
const require_v3_engine = require("./v3-engine-CCwvhRrQ.js");
|
|
3
|
+
const require_generator = require("./generator-B4RNgMLx.js");
|
|
4
|
+
let postcss = require("postcss");
|
|
5
|
+
postcss = require_chunk.__toESM(postcss);
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_chunk.__toESM(node_path);
|
|
8
|
+
let node_process = require("node:process");
|
|
9
|
+
node_process = require_chunk.__toESM(node_process);
|
|
10
|
+
let tailwindcss_patch = require("tailwindcss-patch");
|
|
11
|
+
let node_fs_promises = require("node:fs/promises");
|
|
12
|
+
let tailwindcss_config = require("tailwindcss-config");
|
|
13
|
+
//#region src/postcss/config-directive.ts
|
|
14
|
+
function quoteCssString(value) {
|
|
15
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
16
|
+
}
|
|
17
|
+
function toCssPath(value) {
|
|
18
|
+
return value.replaceAll("\\", "/");
|
|
19
|
+
}
|
|
20
|
+
function prependConfigDirective(css, config) {
|
|
21
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
22
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/postcss/context.ts
|
|
26
|
+
const PLUGIN_NAME$1 = "weapp-tailwindcss";
|
|
27
|
+
function resolveInputFile(result) {
|
|
28
|
+
const from = result.opts.from;
|
|
29
|
+
if (typeof from !== "string" || from.length === 0) return;
|
|
30
|
+
return node_path.default.isAbsolute(from) ? from : node_path.default.resolve(node_process.default.cwd(), from);
|
|
31
|
+
}
|
|
32
|
+
function resolvePostcssBase(result, options) {
|
|
33
|
+
if (options.base) return options.base;
|
|
34
|
+
const inputFile = resolveInputFile(result);
|
|
35
|
+
return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
|
|
36
|
+
}
|
|
37
|
+
function resolvePostcssProjectRoot(result, options) {
|
|
38
|
+
if (options.projectRoot) return options.projectRoot;
|
|
39
|
+
const inputFile = resolveInputFile(result);
|
|
40
|
+
return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
|
|
41
|
+
}
|
|
42
|
+
function replaceRootCss(root, css, result) {
|
|
43
|
+
root.removeAll();
|
|
44
|
+
try {
|
|
45
|
+
const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
|
|
46
|
+
root.append(nextRoot.nodes);
|
|
47
|
+
} catch {
|
|
48
|
+
root.raws = { after: css };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function addDependencyMessages(result, generated) {
|
|
52
|
+
for (const file of generated.dependencies) result.messages.push({
|
|
53
|
+
type: "dependency",
|
|
54
|
+
plugin: PLUGIN_NAME$1,
|
|
55
|
+
file
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function addSourceDependencyMessages(result, files) {
|
|
59
|
+
for (const file of files) result.messages.push({
|
|
60
|
+
type: "dependency",
|
|
61
|
+
plugin: PLUGIN_NAME$1,
|
|
62
|
+
file
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/postcss/source-files.ts
|
|
67
|
+
const POSTCSS_SOURCE_PATTERN = require_v3_engine.createSourceScanPattern(require_v3_engine.DEFAULT_SOURCE_SCAN_EXTENSIONS);
|
|
68
|
+
function getSourceExtension(file) {
|
|
69
|
+
return node_path.default.extname(file).slice(1) || void 0;
|
|
70
|
+
}
|
|
71
|
+
function collectConfigPaths(root, base) {
|
|
72
|
+
const configPaths = [];
|
|
73
|
+
root.walkAtRules("config", (rule) => {
|
|
74
|
+
const configPath = require_v3_engine.parseConfigParam(rule.params);
|
|
75
|
+
if (configPath) configPaths.push(node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath));
|
|
76
|
+
});
|
|
77
|
+
return [...new Set(configPaths)];
|
|
78
|
+
}
|
|
79
|
+
function resolveOptionConfigPath(config, base) {
|
|
80
|
+
if (!config) return;
|
|
81
|
+
return node_path.default.isAbsolute(config) ? config : node_path.default.resolve(base, config);
|
|
82
|
+
}
|
|
83
|
+
async function collectConfigContentFiles(root, base, options) {
|
|
84
|
+
const configPaths = [...new Set([...resolveOptionConfigPath(options.config, base) ? [resolveOptionConfigPath(options.config, base)] : [], ...collectConfigPaths(root, base)])];
|
|
85
|
+
const files = [];
|
|
86
|
+
for (const configPath of configPaths) {
|
|
87
|
+
const contentEntries = require_v3_engine.normalizeLegacyContentEntries((await (0, tailwindcss_config.loadConfig)({
|
|
88
|
+
config: configPath,
|
|
89
|
+
cwd: node_path.default.dirname(configPath)
|
|
90
|
+
}))?.config.content, node_path.default.dirname(configPath));
|
|
91
|
+
files.push(...await require_v3_engine.expandTailwindSourceEntries(contentEntries));
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
configPaths,
|
|
95
|
+
files: [...new Set(files)]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function collectConfiguredContentEntries(root, base, options) {
|
|
99
|
+
const configPath = resolveOptionConfigPath(options.generator?.config ?? options.config, base) ?? collectConfigPaths(root, base)[0];
|
|
100
|
+
if (!configPath) return [];
|
|
101
|
+
const resolvedConfigPath = node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath);
|
|
102
|
+
return require_v3_engine.normalizeLegacyContentEntries((await (0, tailwindcss_config.loadConfig)({
|
|
103
|
+
config: resolvedConfigPath,
|
|
104
|
+
cwd: node_path.default.dirname(resolvedConfigPath)
|
|
105
|
+
}))?.config.content, node_path.default.dirname(resolvedConfigPath));
|
|
106
|
+
}
|
|
107
|
+
async function collectRawCandidatesFromSourceEntries(sourceEntries) {
|
|
108
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
109
|
+
const files = await require_v3_engine.expandTailwindSourceEntries(sourceEntries);
|
|
110
|
+
await Promise.all(files.map(async (file) => {
|
|
111
|
+
const matches = await (0, tailwindcss_patch.extractRawCandidatesWithPositions)(await (0, node_fs_promises.readFile)(file, "utf8"), getSourceExtension(file));
|
|
112
|
+
for (const match of matches) {
|
|
113
|
+
const candidate = match?.rawCandidate;
|
|
114
|
+
if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
return candidates;
|
|
118
|
+
}
|
|
119
|
+
async function collectAutoTailwindCandidates(root, result, options) {
|
|
120
|
+
if (options.scanSources === false) return /* @__PURE__ */ new Set();
|
|
121
|
+
const base = resolvePostcssBase(result, options);
|
|
122
|
+
const projectRoot = resolvePostcssProjectRoot(result, options);
|
|
123
|
+
const sourceEntries = [];
|
|
124
|
+
const hasSourceNone = root.toString().includes("source(none)");
|
|
125
|
+
const inlineCandidates = require_v3_engine.collectCssInlineSourceCandidates(root);
|
|
126
|
+
const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
|
|
127
|
+
if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
|
|
128
|
+
else if (!hasSourceNone) sourceEntries.push({
|
|
129
|
+
base,
|
|
130
|
+
negated: false,
|
|
131
|
+
pattern: POSTCSS_SOURCE_PATTERN
|
|
132
|
+
});
|
|
133
|
+
sourceEntries.push(...await require_v3_engine.resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN));
|
|
134
|
+
const candidates = sourceEntries.length === 0 ? [] : options.version === 3 ? await collectRawCandidatesFromSourceEntries(sourceEntries) : await (0, tailwindcss_patch.extractValidCandidates)({
|
|
135
|
+
base,
|
|
136
|
+
css: root.toString(),
|
|
137
|
+
cwd: projectRoot,
|
|
138
|
+
sources: sourceEntries
|
|
139
|
+
});
|
|
140
|
+
return new Set([...[...candidates].filter((candidate) => !inlineCandidates.excluded.has(candidate)), ...inlineCandidates.included]);
|
|
141
|
+
}
|
|
142
|
+
async function collectPostcssLocalSources(root, result, options) {
|
|
143
|
+
const base = resolvePostcssBase(result, options);
|
|
144
|
+
const sourceEntries = await require_v3_engine.resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
|
|
145
|
+
const configContentFiles = await collectConfigContentFiles(root, base, options);
|
|
146
|
+
const files = [...new Set([...await require_v3_engine.expandTailwindSourceEntries(sourceEntries), ...configContentFiles.files])];
|
|
147
|
+
const sources = await Promise.all(files.map(async (file) => {
|
|
148
|
+
const extension = getSourceExtension(file);
|
|
149
|
+
return {
|
|
150
|
+
content: await (0, node_fs_promises.readFile)(file, "utf8"),
|
|
151
|
+
...extension === void 0 ? {} : { extension }
|
|
152
|
+
};
|
|
153
|
+
}));
|
|
154
|
+
return {
|
|
155
|
+
files: [...files, ...configContentFiles.configPaths],
|
|
156
|
+
sources
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/postcss/tailwind-version.ts
|
|
161
|
+
function hasTailwindV4CssSyntax(root) {
|
|
162
|
+
let hasV4Syntax = false;
|
|
163
|
+
root.walkAtRules((rule) => {
|
|
164
|
+
if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
|
|
165
|
+
if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
|
|
166
|
+
});
|
|
167
|
+
return hasV4Syntax;
|
|
168
|
+
}
|
|
169
|
+
function resolvePostcssTailwindVersion(root, result, options) {
|
|
170
|
+
const packageName = options.packageName ?? "tailwindcss";
|
|
171
|
+
const installedVersion = require_v3_engine.readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
|
|
172
|
+
if (installedVersion) return installedVersion;
|
|
173
|
+
if (options.version) return options.version;
|
|
174
|
+
if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
|
|
175
|
+
if (packageName.includes("tailwindcss3")) return 3;
|
|
176
|
+
if (hasTailwindV4CssSyntax(root)) return 4;
|
|
177
|
+
return 4;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/postcss.ts
|
|
181
|
+
const PLUGIN_NAME = "weapp-tailwindcss";
|
|
182
|
+
const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
183
|
+
return {
|
|
184
|
+
postcssPlugin: PLUGIN_NAME,
|
|
185
|
+
async Once(root, { result }) {
|
|
186
|
+
const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
|
|
187
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
|
|
188
|
+
const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
|
|
189
|
+
const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
|
|
190
|
+
const generatorConfig = generatorOptions.config ?? options.config;
|
|
191
|
+
const generator = require_generator.createWeappTailwindcssGenerator(tailwindVersion === 3 ? await require_v3_engine.resolveTailwindV3Source({
|
|
192
|
+
config: generatorConfig,
|
|
193
|
+
css: sourceOptions.css ?? root.toString(),
|
|
194
|
+
base: resolvePostcssBase(result, options),
|
|
195
|
+
cwd: resolvePostcssProjectRoot(result, options),
|
|
196
|
+
projectRoot: resolvePostcssProjectRoot(result, options),
|
|
197
|
+
packageName: options.packageName,
|
|
198
|
+
postcssPlugin: options.postcssPlugin
|
|
199
|
+
}) : await require_v3_engine.resolveTailwindV4Source({
|
|
200
|
+
...sourceOptions,
|
|
201
|
+
css: prependConfigDirective(sourceOptions.css ?? root.toString(), generatorConfig),
|
|
202
|
+
base: resolvePostcssBase(result, options),
|
|
203
|
+
projectRoot: resolvePostcssProjectRoot(result, options)
|
|
204
|
+
}));
|
|
205
|
+
const generateOptions = {
|
|
206
|
+
candidates: new Set([...autoCandidates, ...candidates ?? []]),
|
|
207
|
+
scanSources: scanSources ?? false,
|
|
208
|
+
sources: [...collectedSources.sources, ...sources ?? []],
|
|
209
|
+
styleOptions: {
|
|
210
|
+
...generatorOptions.styleOptions,
|
|
211
|
+
...styleOptions
|
|
212
|
+
},
|
|
213
|
+
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
214
|
+
target: generatorOptions.target
|
|
215
|
+
};
|
|
216
|
+
const generated = await generator.generate(generateOptions);
|
|
217
|
+
replaceRootCss(root, generated.css, result);
|
|
218
|
+
addDependencyMessages(result, generated);
|
|
219
|
+
addSourceDependencyMessages(result, collectedSources.files);
|
|
220
|
+
result.messages.push({
|
|
221
|
+
type: "weapp-tailwindcss:generated",
|
|
222
|
+
plugin: PLUGIN_NAME,
|
|
223
|
+
target: generated.target,
|
|
224
|
+
classSet: generated.classSet,
|
|
225
|
+
rawCss: generated.rawCss
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
weappTailwindcssPostcssPlugin.postcss = true;
|
|
231
|
+
//#endregion
|
|
232
|
+
Object.defineProperty(exports, "weappTailwindcssPostcssPlugin", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get: function() {
|
|
235
|
+
return weappTailwindcssPostcssPlugin;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { A as collectCssInlineSourceCandidates, F as parseConfigParam, H as readInstalledPackageMajorVersion, I as resolveCssSourceEntries, M as expandTailwindSourceEntries, O as DEFAULT_SOURCE_SCAN_EXTENSIONS, P as normalizeLegacyContentEntries, j as createSourceScanPattern, t as resolveTailwindV3Source, y as resolveTailwindV4Source$1 } from "./v3-engine-DyIcbpZm.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator } from "./generator-DvyhmC76.mjs";
|
|
3
|
+
import postcss from "postcss";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { extractRawCandidatesWithPositions, extractValidCandidates } from "tailwindcss-patch";
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
import { loadConfig } from "tailwindcss-config";
|
|
9
|
+
//#region src/postcss/config-directive.ts
|
|
10
|
+
function quoteCssString(value) {
|
|
11
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
12
|
+
}
|
|
13
|
+
function toCssPath(value) {
|
|
14
|
+
return value.replaceAll("\\", "/");
|
|
15
|
+
}
|
|
16
|
+
function prependConfigDirective(css, config) {
|
|
17
|
+
if (!config || /@config\s+/.test(css)) return css;
|
|
18
|
+
return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/postcss/context.ts
|
|
22
|
+
const PLUGIN_NAME$1 = "weapp-tailwindcss";
|
|
23
|
+
function resolveInputFile(result) {
|
|
24
|
+
const from = result.opts.from;
|
|
25
|
+
if (typeof from !== "string" || from.length === 0) return;
|
|
26
|
+
return path.isAbsolute(from) ? from : path.resolve(process.cwd(), from);
|
|
27
|
+
}
|
|
28
|
+
function resolvePostcssBase(result, options) {
|
|
29
|
+
if (options.base) return options.base;
|
|
30
|
+
const inputFile = resolveInputFile(result);
|
|
31
|
+
return inputFile ? path.dirname(inputFile) : process.cwd();
|
|
32
|
+
}
|
|
33
|
+
function resolvePostcssProjectRoot(result, options) {
|
|
34
|
+
if (options.projectRoot) return options.projectRoot;
|
|
35
|
+
const inputFile = resolveInputFile(result);
|
|
36
|
+
return inputFile ? path.dirname(inputFile) : process.cwd();
|
|
37
|
+
}
|
|
38
|
+
function replaceRootCss(root, css, result) {
|
|
39
|
+
root.removeAll();
|
|
40
|
+
try {
|
|
41
|
+
const nextRoot = postcss.parse(css, { from: resolveInputFile(result) });
|
|
42
|
+
root.append(nextRoot.nodes);
|
|
43
|
+
} catch {
|
|
44
|
+
root.raws = { after: css };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function addDependencyMessages(result, generated) {
|
|
48
|
+
for (const file of generated.dependencies) result.messages.push({
|
|
49
|
+
type: "dependency",
|
|
50
|
+
plugin: PLUGIN_NAME$1,
|
|
51
|
+
file
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function addSourceDependencyMessages(result, files) {
|
|
55
|
+
for (const file of files) result.messages.push({
|
|
56
|
+
type: "dependency",
|
|
57
|
+
plugin: PLUGIN_NAME$1,
|
|
58
|
+
file
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/postcss/source-files.ts
|
|
63
|
+
const POSTCSS_SOURCE_PATTERN = createSourceScanPattern(DEFAULT_SOURCE_SCAN_EXTENSIONS);
|
|
64
|
+
function getSourceExtension(file) {
|
|
65
|
+
return path.extname(file).slice(1) || void 0;
|
|
66
|
+
}
|
|
67
|
+
function collectConfigPaths(root, base) {
|
|
68
|
+
const configPaths = [];
|
|
69
|
+
root.walkAtRules("config", (rule) => {
|
|
70
|
+
const configPath = parseConfigParam(rule.params);
|
|
71
|
+
if (configPath) configPaths.push(path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath));
|
|
72
|
+
});
|
|
73
|
+
return [...new Set(configPaths)];
|
|
74
|
+
}
|
|
75
|
+
function resolveOptionConfigPath(config, base) {
|
|
76
|
+
if (!config) return;
|
|
77
|
+
return path.isAbsolute(config) ? config : path.resolve(base, config);
|
|
78
|
+
}
|
|
79
|
+
async function collectConfigContentFiles(root, base, options) {
|
|
80
|
+
const configPaths = [...new Set([...resolveOptionConfigPath(options.config, base) ? [resolveOptionConfigPath(options.config, base)] : [], ...collectConfigPaths(root, base)])];
|
|
81
|
+
const files = [];
|
|
82
|
+
for (const configPath of configPaths) {
|
|
83
|
+
const contentEntries = normalizeLegacyContentEntries((await loadConfig({
|
|
84
|
+
config: configPath,
|
|
85
|
+
cwd: path.dirname(configPath)
|
|
86
|
+
}))?.config.content, path.dirname(configPath));
|
|
87
|
+
files.push(...await expandTailwindSourceEntries(contentEntries));
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
configPaths,
|
|
91
|
+
files: [...new Set(files)]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function collectConfiguredContentEntries(root, base, options) {
|
|
95
|
+
const configPath = resolveOptionConfigPath(options.generator?.config ?? options.config, base) ?? collectConfigPaths(root, base)[0];
|
|
96
|
+
if (!configPath) return [];
|
|
97
|
+
const resolvedConfigPath = path.isAbsolute(configPath) ? configPath : path.resolve(base, configPath);
|
|
98
|
+
return normalizeLegacyContentEntries((await loadConfig({
|
|
99
|
+
config: resolvedConfigPath,
|
|
100
|
+
cwd: path.dirname(resolvedConfigPath)
|
|
101
|
+
}))?.config.content, path.dirname(resolvedConfigPath));
|
|
102
|
+
}
|
|
103
|
+
async function collectRawCandidatesFromSourceEntries(sourceEntries) {
|
|
104
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
105
|
+
const files = await expandTailwindSourceEntries(sourceEntries);
|
|
106
|
+
await Promise.all(files.map(async (file) => {
|
|
107
|
+
const matches = await extractRawCandidatesWithPositions(await readFile(file, "utf8"), getSourceExtension(file));
|
|
108
|
+
for (const match of matches) {
|
|
109
|
+
const candidate = match?.rawCandidate;
|
|
110
|
+
if (typeof candidate === "string" && candidate.length > 0) candidates.add(candidate);
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
return candidates;
|
|
114
|
+
}
|
|
115
|
+
async function collectAutoTailwindCandidates(root, result, options) {
|
|
116
|
+
if (options.scanSources === false) return /* @__PURE__ */ new Set();
|
|
117
|
+
const base = resolvePostcssBase(result, options);
|
|
118
|
+
const projectRoot = resolvePostcssProjectRoot(result, options);
|
|
119
|
+
const sourceEntries = [];
|
|
120
|
+
const hasSourceNone = root.toString().includes("source(none)");
|
|
121
|
+
const inlineCandidates = collectCssInlineSourceCandidates(root);
|
|
122
|
+
const configuredContentEntries = options.version === 3 ? await collectConfiguredContentEntries(root, base, options) : [];
|
|
123
|
+
if (configuredContentEntries.length > 0) sourceEntries.push(...configuredContentEntries);
|
|
124
|
+
else if (!hasSourceNone) sourceEntries.push({
|
|
125
|
+
base,
|
|
126
|
+
negated: false,
|
|
127
|
+
pattern: POSTCSS_SOURCE_PATTERN
|
|
128
|
+
});
|
|
129
|
+
sourceEntries.push(...await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN));
|
|
130
|
+
const candidates = sourceEntries.length === 0 ? [] : options.version === 3 ? await collectRawCandidatesFromSourceEntries(sourceEntries) : await extractValidCandidates({
|
|
131
|
+
base,
|
|
132
|
+
css: root.toString(),
|
|
133
|
+
cwd: projectRoot,
|
|
134
|
+
sources: sourceEntries
|
|
135
|
+
});
|
|
136
|
+
return new Set([...[...candidates].filter((candidate) => !inlineCandidates.excluded.has(candidate)), ...inlineCandidates.included]);
|
|
137
|
+
}
|
|
138
|
+
async function collectPostcssLocalSources(root, result, options) {
|
|
139
|
+
const base = resolvePostcssBase(result, options);
|
|
140
|
+
const sourceEntries = await resolveCssSourceEntries(root, base, POSTCSS_SOURCE_PATTERN);
|
|
141
|
+
const configContentFiles = await collectConfigContentFiles(root, base, options);
|
|
142
|
+
const files = [...new Set([...await expandTailwindSourceEntries(sourceEntries), ...configContentFiles.files])];
|
|
143
|
+
const sources = await Promise.all(files.map(async (file) => {
|
|
144
|
+
const extension = getSourceExtension(file);
|
|
145
|
+
return {
|
|
146
|
+
content: await readFile(file, "utf8"),
|
|
147
|
+
...extension === void 0 ? {} : { extension }
|
|
148
|
+
};
|
|
149
|
+
}));
|
|
150
|
+
return {
|
|
151
|
+
files: [...files, ...configContentFiles.configPaths],
|
|
152
|
+
sources
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/postcss/tailwind-version.ts
|
|
157
|
+
function hasTailwindV4CssSyntax(root) {
|
|
158
|
+
let hasV4Syntax = false;
|
|
159
|
+
root.walkAtRules((rule) => {
|
|
160
|
+
if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
|
|
161
|
+
if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
|
|
162
|
+
});
|
|
163
|
+
return hasV4Syntax;
|
|
164
|
+
}
|
|
165
|
+
function resolvePostcssTailwindVersion(root, result, options) {
|
|
166
|
+
const packageName = options.packageName ?? "tailwindcss";
|
|
167
|
+
const installedVersion = readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
|
|
168
|
+
if (installedVersion) return installedVersion;
|
|
169
|
+
if (options.version) return options.version;
|
|
170
|
+
if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
|
|
171
|
+
if (packageName.includes("tailwindcss3")) return 3;
|
|
172
|
+
if (hasTailwindV4CssSyntax(root)) return 4;
|
|
173
|
+
return 4;
|
|
174
|
+
}
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/postcss.ts
|
|
177
|
+
const PLUGIN_NAME = "weapp-tailwindcss";
|
|
178
|
+
const weappTailwindcssPostcssPlugin = (options = {}) => {
|
|
179
|
+
return {
|
|
180
|
+
postcssPlugin: PLUGIN_NAME,
|
|
181
|
+
async Once(root, { result }) {
|
|
182
|
+
const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
|
|
183
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
|
|
184
|
+
const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
|
|
185
|
+
const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
|
|
186
|
+
const generatorConfig = generatorOptions.config ?? options.config;
|
|
187
|
+
const generator = createWeappTailwindcssGenerator(tailwindVersion === 3 ? await resolveTailwindV3Source({
|
|
188
|
+
config: generatorConfig,
|
|
189
|
+
css: sourceOptions.css ?? root.toString(),
|
|
190
|
+
base: resolvePostcssBase(result, options),
|
|
191
|
+
cwd: resolvePostcssProjectRoot(result, options),
|
|
192
|
+
projectRoot: resolvePostcssProjectRoot(result, options),
|
|
193
|
+
packageName: options.packageName,
|
|
194
|
+
postcssPlugin: options.postcssPlugin
|
|
195
|
+
}) : await resolveTailwindV4Source$1({
|
|
196
|
+
...sourceOptions,
|
|
197
|
+
css: prependConfigDirective(sourceOptions.css ?? root.toString(), generatorConfig),
|
|
198
|
+
base: resolvePostcssBase(result, options),
|
|
199
|
+
projectRoot: resolvePostcssProjectRoot(result, options)
|
|
200
|
+
}));
|
|
201
|
+
const generateOptions = {
|
|
202
|
+
candidates: new Set([...autoCandidates, ...candidates ?? []]),
|
|
203
|
+
scanSources: scanSources ?? false,
|
|
204
|
+
sources: [...collectedSources.sources, ...sources ?? []],
|
|
205
|
+
styleOptions: {
|
|
206
|
+
...generatorOptions.styleOptions,
|
|
207
|
+
...styleOptions
|
|
208
|
+
},
|
|
209
|
+
tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
|
|
210
|
+
target: generatorOptions.target
|
|
211
|
+
};
|
|
212
|
+
const generated = await generator.generate(generateOptions);
|
|
213
|
+
replaceRootCss(root, generated.css, result);
|
|
214
|
+
addDependencyMessages(result, generated);
|
|
215
|
+
addSourceDependencyMessages(result, collectedSources.files);
|
|
216
|
+
result.messages.push({
|
|
217
|
+
type: "weapp-tailwindcss:generated",
|
|
218
|
+
plugin: PLUGIN_NAME,
|
|
219
|
+
target: generated.target,
|
|
220
|
+
classSet: generated.classSet,
|
|
221
|
+
rawCss: generated.rawCss
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
weappTailwindcssPostcssPlugin.postcss = true;
|
|
227
|
+
//#endregion
|
|
228
|
+
export { weappTailwindcssPostcssPlugin as t };
|
package/dist/postcss.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { IStyleHandlerOptions } from '@weapp-tailwindcss/postcss/types';
|
|
2
2
|
import type { PluginCreator } from 'postcss';
|
|
3
|
-
import type { TailwindV4CandidateSource, TailwindV4SourceOptions,
|
|
3
|
+
import type { TailwindV4CandidateSource, TailwindV4SourceOptions, WeappTailwindcssGenerateOptions, WeappTailwindcssGeneratorUserOptions } from './generator';
|
|
4
4
|
export interface WeappTailwindcssPostcssPluginOptions extends TailwindV4SourceOptions {
|
|
5
5
|
generator?: WeappTailwindcssGeneratorUserOptions;
|
|
6
|
-
target?: WeappTailwindcssGeneratorTarget;
|
|
7
6
|
version?: 3 | 4;
|
|
8
7
|
config?: string;
|
|
9
8
|
postcssPlugin?: string;
|
|
10
9
|
candidates?: Iterable<string>;
|
|
10
|
+
scanSources?: WeappTailwindcssGenerateOptions['scanSources'];
|
|
11
11
|
sources?: TailwindV4CandidateSource[];
|
|
12
12
|
styleOptions?: Partial<IStyleHandlerOptions>;
|
|
13
13
|
}
|