weapp-tailwindcss 5.0.0-next.2 → 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.
Files changed (95) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundlers/shared/generator-css.d.ts +5 -2
  4. package/dist/bundlers/vite/generate-bundle.d.ts +1 -0
  5. package/dist/bundlers/vite/index.d.ts +1 -1
  6. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  7. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
  8. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
  9. package/dist/cli/context.d.ts +0 -3
  10. package/dist/cli/mount-options.d.ts +2 -0
  11. package/dist/cli.js +8 -2
  12. package/dist/cli.mjs +8 -2
  13. package/dist/constants.d.ts +1 -1
  14. package/dist/core.js +1 -1
  15. package/dist/core.mjs +1 -1
  16. package/dist/css-macro.d.ts +1 -0
  17. package/dist/defaults.js +5 -7
  18. package/dist/defaults.mjs +5 -7
  19. package/dist/generator/index.d.ts +1 -1
  20. package/dist/generator/options.d.ts +3 -4
  21. package/dist/{generator-mmhXzZnv.js → generator-9UEp8OoQ.js} +259 -21
  22. package/dist/{generator-Y-Ikv4Fu.mjs → generator-Dpp-5s8z.mjs} +260 -22
  23. package/dist/{generator-css-D3OdPRiS.js → generator-css-CGueCYbX.js} +182 -42
  24. package/dist/{generator-css-B5ejWUMv.mjs → generator-css-MyjZhF0z.mjs} +182 -42
  25. package/dist/generator.js +1 -1
  26. package/dist/generator.mjs +1 -1
  27. package/dist/gulp.js +17 -14
  28. package/dist/gulp.mjs +17 -14
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +4 -4
  31. package/dist/index.mjs +4 -4
  32. package/dist/js/index.d.ts +1 -0
  33. package/dist/js/literal-transform.d.ts +2 -0
  34. package/dist/{logger-BoVx1Dbt.mjs → logger-1gx9UllH.mjs} +21 -51
  35. package/dist/{logger-BZ45DZJT.js → logger-D9clu_3f.js} +21 -51
  36. package/dist/patcher-options-DnqazL9E.js +34 -0
  37. package/dist/patcher-options-GuOwX0-k.mjs +17 -0
  38. package/dist/postcss.d.ts +2 -2
  39. package/dist/postcss.js +37 -28
  40. package/dist/postcss.mjs +37 -28
  41. package/dist/presets.js +1 -1
  42. package/dist/presets.mjs +1 -1
  43. package/dist/{recorder-zsgatmkB.mjs → recorder-BIW3Kuke.mjs} +5 -12
  44. package/dist/{recorder-gYSNLfOP.js → recorder-D4BKt75Q.js} +5 -12
  45. package/dist/reset.d.ts +1 -0
  46. package/dist/{css-imports-BbrbluP9.js → run-tasks-Cq5A5nVD.js} +6 -55
  47. package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DUVrDJGl.mjs} +5 -42
  48. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  49. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  50. package/dist/tailwindcss/patcher.d.ts +1 -2
  51. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  52. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  53. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  54. package/dist/tailwindcss/version.d.ts +4 -0
  55. package/dist/typedoc.export.d.ts +0 -2
  56. package/dist/types/index.d.ts +1 -3
  57. package/dist/types/shared.d.ts +3 -0
  58. package/dist/types/user-defined-options/general.d.ts +0 -2
  59. package/dist/types/user-defined-options/important.d.ts +3 -3
  60. package/dist/utils/disabled.d.ts +2 -3
  61. package/dist/version-CWBxRFPB.js +56 -0
  62. package/dist/version-WNz3MwRv.mjs +49 -0
  63. package/dist/{vite-BC9U7ahn.js → vite-BkMGwDeH.js} +106 -39
  64. package/dist/{vite-CrlzCNqz.mjs → vite-fDM-UQpR.mjs} +89 -22
  65. package/dist/vite.d.ts +1 -2
  66. package/dist/vite.js +3 -4
  67. package/dist/vite.mjs +2 -2
  68. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  69. package/dist/{webpack-DD7A6V0u.js → webpack-CICGEKT9.js} +225 -43
  70. package/dist/{webpack-Bu6M-Hbw.mjs → webpack-D2Wdk28V.mjs} +214 -27
  71. package/dist/webpack.js +1 -1
  72. package/dist/webpack.mjs +1 -1
  73. package/package.json +21 -30
  74. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  75. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  76. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  77. package/dist/experimental/index.d.ts +0 -2
  78. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  79. package/dist/experimental/oxc/index.d.ts +0 -2
  80. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  81. package/dist/experimental/shared/cache.d.ts +0 -3
  82. package/dist/experimental/shared/transform.d.ts +0 -3
  83. package/dist/experimental/shared.d.ts +0 -8
  84. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  85. package/dist/experimental/swc/index.d.ts +0 -2
  86. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  87. package/dist/loader-anchors-CNkWT8hx.js +0 -273
  88. package/dist/loader-anchors-TrU7EUr7.mjs +0 -205
  89. package/dist/patcher-options-6gJN2EXy.js +0 -115
  90. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  91. package/dist/types/disabled-options.d.ts +0 -4
  92. package/dist/webpack4.d.ts +0 -4
  93. package/dist/webpack4.js +0 -387
  94. package/dist/webpack4.mjs +0 -379
  95. package/scripts/postinstall.mjs +0 -59
package/dist/webpack4.mjs DELETED
@@ -1,379 +0,0 @@
1
- import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, p as pluginName, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-zsgatmkB.mjs";
2
- import { r as getGroupedEntries } from "./utils-7DUGTFED.mjs";
3
- import { d as getRuntimeClassSetSignature } from "./logger-BoVx1Dbt.mjs";
4
- import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-B5ejWUMv.mjs";
5
- import { a as resolveDisabledOptions, c as toAbsoluteOutputPath, i as resolvePackageDir, r as pushConcurrentTaskFactories, s as resolveOutputSpecifier } from "./css-imports-CSdPq_Sc.mjs";
6
- import { a as hasLoaderEntry, c as applyTailwindcssCssImportRewrite, d as isMpx, f as patchMpxLoaderResolve, i as getCacheKey, l as ensureMpxTailwindcssAliases, n as __dirname, p as setupMpxTailwindcssRedirect, r as createAssetHashByChunkMap, s as isCssLikeModuleResource, t as createLoaderAnchorFinders, u as injectMpxCssRewritePreRules } from "./loader-anchors-TrU7EUr7.mjs";
7
- import path from "node:path";
8
- import process from "node:process";
9
- import fs from "node:fs";
10
- import { ConcatSource } from "webpack-sources";
11
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-assets.ts
12
- function resolveWebpackStaleClassNameFallback(option, _compiler) {
13
- if (typeof option === "boolean") return option;
14
- return false;
15
- }
16
- function toWebpackV4AssetCompilation(compilation) {
17
- return compilation;
18
- }
19
- function readWebpackV4AssetSource(asset) {
20
- const source = asset.source();
21
- return typeof source === "string" ? source : source.toString();
22
- }
23
- function setupWebpackV4EmitHook(options) {
24
- const { compiler, options: compilerOptions, appType, runtimeState, debug } = options;
25
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
26
- const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
27
- compiler.hooks.emit.tapPromise(pluginName, async (compilation) => {
28
- await runtimeState.patchPromise;
29
- compilerOptions.onStart();
30
- debug("start");
31
- for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
32
- const assetCompilation = toWebpackV4AssetCompilation(compilation);
33
- const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
34
- const assets = assetCompilation.assets;
35
- const entries = Object.entries(assets);
36
- const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
37
- const jsAssets = /* @__PURE__ */ new Map();
38
- for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
39
- const absolute = toAbsoluteOutputPath(file, outputDir);
40
- jsAssets.set(absolute, file);
41
- }
42
- const moduleGraphOptions = {
43
- resolve(specifier, importer) {
44
- return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
45
- },
46
- load: (id) => {
47
- const assetName = jsAssets.get(id);
48
- if (!assetName) return;
49
- const assetSource = assetCompilation.assets[assetName];
50
- if (!assetSource) return;
51
- return readWebpackV4AssetSource(assetSource);
52
- },
53
- filter(id) {
54
- return jsAssets.has(id);
55
- }
56
- };
57
- const applyLinkedResults = (linked) => {
58
- if (!linked) return;
59
- for (const [id, { code }] of Object.entries(linked)) {
60
- const assetName = jsAssets.get(id);
61
- if (!assetName) continue;
62
- const assetSource = assetCompilation.assets[assetName];
63
- if (!assetSource) continue;
64
- const previous = readWebpackV4AssetSource(assetSource);
65
- if (previous === code) continue;
66
- const source = new ConcatSource(code);
67
- assetCompilation.updateAsset(assetName, source);
68
- compilerOptions.onUpdate(assetName, previous, code);
69
- debug("js linked handle: %s", assetName);
70
- }
71
- };
72
- const groupedEntries = getGroupedEntries(entries, compilerOptions);
73
- const getCssHandlerOptions = (file) => {
74
- const majorVersion = runtimeState.twPatcher.majorVersion;
75
- const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
76
- const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
77
- const cached = cssHandlerOptionsCache.get(cacheKey);
78
- if (cached) return cached;
79
- const created = {
80
- isMainChunk,
81
- postcssOptions: { options: { from: file } },
82
- majorVersion
83
- };
84
- cssHandlerOptionsCache.set(cacheKey, created);
85
- return created;
86
- };
87
- const getCssUserHandlerOptions = (file) => {
88
- const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
89
- const cached = cssUserHandlerOptionsCache.get(cacheKey);
90
- if (cached) return cached;
91
- const created = {
92
- ...getCssHandlerOptions(file),
93
- isMainChunk: false
94
- };
95
- cssUserHandlerOptionsCache.set(cacheKey, created);
96
- return created;
97
- };
98
- const staleClassNameFallback = resolveWebpackStaleClassNameFallback(compilerOptions.staleClassNameFallback, compiler);
99
- const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
100
- forceCollect: true,
101
- allowEmpty: false
102
- });
103
- const defaultTemplateHandlerOptions = { runtimeSet };
104
- debug("get runtimeSet, class count: %d", runtimeSet.size);
105
- const tasks = [];
106
- if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
107
- const [file, originalSource] = element;
108
- const rawSource = readWebpackV4AssetSource(originalSource);
109
- const cacheKey = file;
110
- const chunkHash = assetHashByChunk.get(file);
111
- tasks.push(processCachedTask({
112
- cache: compilerOptions.cache,
113
- cacheKey,
114
- hashKey: `${file}:asset`,
115
- rawSource,
116
- hash: chunkHash,
117
- applyResult(source) {
118
- assetCompilation.updateAsset(file, source);
119
- },
120
- onCacheHit() {
121
- debug("html cache hit: %s", file);
122
- },
123
- transform: async () => {
124
- const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
125
- const source = new ConcatSource(wxml);
126
- compilerOptions.onUpdate(file, rawSource, wxml);
127
- debug("html handle: %s", file);
128
- return { result: source };
129
- }
130
- }));
131
- }
132
- const jsTaskFactories = [];
133
- if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
134
- const cacheKey = getCacheKey(file);
135
- const assetSource = assetCompilation.assets[file];
136
- if (!assetSource) continue;
137
- const initialRawSource = readWebpackV4AssetSource(assetSource);
138
- const absoluteFile = toAbsoluteOutputPath(file, outputDir);
139
- const chunkHash = assetHashByChunk.get(file);
140
- const sourceAwareHash = chunkHash ? `${chunkHash}:${compilerOptions.cache.computeHash(initialRawSource)}` : void 0;
141
- jsTaskFactories.push(async () => {
142
- await processCachedTask({
143
- cache: compilerOptions.cache,
144
- cacheKey,
145
- hashKey: `${file}:asset`,
146
- rawSource: initialRawSource,
147
- hash: sourceAwareHash,
148
- applyResult(source) {
149
- assetCompilation.updateAsset(file, source);
150
- },
151
- onCacheHit() {
152
- debug("js cache hit: %s", file);
153
- },
154
- transform: async () => {
155
- const currentAsset = assetCompilation.assets[file];
156
- const currentSource = currentAsset ? readWebpackV4AssetSource(currentAsset) : "";
157
- const handlerOptions = {
158
- staleClassNameFallback,
159
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
160
- filename: absoluteFile,
161
- moduleGraph: moduleGraphOptions,
162
- babelParserOptions: { sourceFilename: absoluteFile }
163
- };
164
- if (shouldSkipJsTransform(currentSource, handlerOptions)) return { result: new ConcatSource(currentSource) };
165
- const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
166
- const source = new ConcatSource(code);
167
- compilerOptions.onUpdate(file, currentSource, code);
168
- debug("js handle: %s", file);
169
- applyLinkedResults(linked);
170
- return { result: source };
171
- }
172
- });
173
- });
174
- }
175
- if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
176
- const [file, originalSource] = element;
177
- const rawSource = readWebpackV4AssetSource(originalSource);
178
- const cacheKey = file;
179
- const chunkHash = assetHashByChunk.get(file);
180
- tasks.push(processCachedTask({
181
- cache: compilerOptions.cache,
182
- cacheKey,
183
- hashKey: `${file}:asset`,
184
- rawSource,
185
- hash: chunkHash,
186
- applyResult(source) {
187
- assetCompilation.updateAsset(file, source);
188
- },
189
- onCacheHit() {
190
- debug("css cache hit: %s", file);
191
- },
192
- transform: async () => {
193
- await runtimeState.patchPromise;
194
- const cssHandlerOptions = getCssHandlerOptions(file);
195
- const generated = await generateCssByGenerator({
196
- opts: compilerOptions,
197
- runtimeState,
198
- runtime: runtimeSet,
199
- rawSource,
200
- file,
201
- cssHandlerOptions,
202
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
203
- styleHandler: compilerOptions.styleHandler,
204
- debug
205
- });
206
- const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
207
- const source = new ConcatSource(css);
208
- compilerOptions.onUpdate(file, rawSource, css);
209
- if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
210
- else debug("css handle: %s", file);
211
- return { result: source };
212
- }
213
- }));
214
- }
215
- pushConcurrentTaskFactories(tasks, jsTaskFactories);
216
- await Promise.all(tasks);
217
- debug("end");
218
- compilerOptions.onEnd();
219
- });
220
- }
221
- //#endregion
222
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.ts
223
- function setupWebpackV4Loaders(options) {
224
- const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, getClassSetInLoader, debug } = options;
225
- const isMpxApp = isMpx(appType);
226
- if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
227
- const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
228
- const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
229
- const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
230
- const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
231
- const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
232
- pkgDir: weappTailwindcssPackageDir,
233
- appType
234
- } : void 0;
235
- const classSetLoaderOptions = { getClassSet: getClassSetInLoader };
236
- const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
237
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { rewriteCssImports: runtimeLoaderRewriteOptions } : void 0;
238
- if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
239
- const createRuntimeClassSetLoaderEntry = () => ({
240
- loader: runtimeClassSetLoader,
241
- options: classSetLoaderOptions,
242
- ident: null,
243
- type: null
244
- });
245
- const createCssImportRewriteLoaderEntry = () => {
246
- if (!runtimeCssImportRewriteLoader) return null;
247
- return {
248
- loader: runtimeCssImportRewriteLoader,
249
- options: cssImportRewriteLoaderOptions,
250
- ident: null,
251
- type: null
252
- };
253
- };
254
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
255
- compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
256
- if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
257
- if (shouldRewriteCssImports && isMpx(appType) && typeof _loaderContext.resolve === "function") patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, true);
258
- const loaderEntries = module.loaders || [];
259
- let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
260
- const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
261
- const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
262
- if (process.env.WEAPP_TW_LOADER_DEBUG && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
263
- rewriteAnchorIdx,
264
- classSetAnchorIdx
265
- });
266
- if (process.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.includes("app.css")) debug("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), {
267
- rewriteAnchorIdx,
268
- classSetAnchorIdx
269
- });
270
- else if (process.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.endsWith(".css")) debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
271
- rewriteAnchorIdx,
272
- classSetAnchorIdx
273
- });
274
- if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
275
- const anchorlessInsert = (entry, position) => {
276
- if (position === "after") loaderEntries.push(entry);
277
- else loaderEntries.unshift(entry);
278
- };
279
- if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
280
- const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
281
- const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
282
- if (rewriteEntry) {
283
- const anchorIndex = findRewriteAnchor(loaderEntries);
284
- if (anchorIndex === -1) anchorlessInsert(rewriteEntry, "after");
285
- else loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
286
- rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
287
- }
288
- }
289
- if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
290
- const anchorIndex = findClassSetAnchor(loaderEntries);
291
- if (anchorIndex === -1) anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
292
- else {
293
- const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
294
- loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
295
- }
296
- }
297
- });
298
- });
299
- }
300
- //#endregion
301
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
302
- const debug = createDebug();
303
- const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
304
- /**
305
- * @name UnifiedWebpackPluginV4
306
- * @description webpack4 核心转义插件
307
- * @link https://tw.icebreaker.top/docs/intro
308
- */
309
- var UnifiedWebpackPluginV4 = class {
310
- constructor(options = {}) {
311
- this.options = getCompilerContext(options);
312
- this.appType = this.options.appType;
313
- }
314
- apply(compiler) {
315
- compiler.options = compiler.options || {};
316
- const { disabled, onLoad, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
317
- const disabledOptions = resolveDisabledOptions(disabled);
318
- const shouldRewriteCssImports = (initialTwPatcher.majorVersion ?? 0) >= 4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
319
- const isMpxApp = isMpx(this.appType);
320
- if (shouldRewriteCssImports) {
321
- applyTailwindcssCssImportRewrite(compiler, {
322
- pkgDir: weappTailwindcssPackageDir,
323
- enabled: true,
324
- appType: this.appType
325
- });
326
- setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
327
- }
328
- if (disabledOptions.plugin) return;
329
- const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
330
- source: "runtime",
331
- cwd: this.options.tailwindcssBasedir ?? process.cwd()
332
- });
333
- const runtimeState = {
334
- twPatcher: initialTwPatcher,
335
- patchPromise: patchRecorderState.patchPromise,
336
- refreshTailwindcssPatcher,
337
- onPatchCompleted: patchRecorderState.onPatchCompleted
338
- };
339
- let runtimeSetPrepared = false;
340
- let runtimeSetSignature;
341
- compiler.hooks.compilation.tap(pluginName, () => {
342
- runtimeSetPrepared = false;
343
- });
344
- async function getClassSetInLoader() {
345
- if (runtimeSetPrepared) return;
346
- const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
347
- const forceRefresh = signature !== runtimeSetSignature;
348
- runtimeSetPrepared = true;
349
- await ensureRuntimeClassSet(runtimeState, {
350
- forceRefresh,
351
- forceCollect: true,
352
- clearCache: forceRefresh,
353
- allowEmpty: true
354
- });
355
- runtimeSetSignature = signature;
356
- }
357
- onLoad();
358
- setupWebpackV4Loaders({
359
- compiler,
360
- options: this.options,
361
- appType: this.appType,
362
- weappTailwindcssPackageDir,
363
- shouldRewriteCssImports,
364
- runtimeLoaderPath,
365
- runtimeCssImportRewriteLoaderPath,
366
- getClassSetInLoader,
367
- debug
368
- });
369
- setupWebpackV4EmitHook({
370
- compiler,
371
- options: this.options,
372
- appType: this.appType,
373
- runtimeState,
374
- debug
375
- });
376
- }
377
- };
378
- //#endregion
379
- export { UnifiedWebpackPluginV4, UnifiedWebpackPluginV4 as WeappTailwindcss, UnifiedWebpackPluginV4 as weappTailwindcss, weappTailwindcssPackageDir };
@@ -1,59 +0,0 @@
1
- import { spawnSync } from 'node:child_process'
2
- import process from 'node:process'
3
- import { fileURLToPath, pathToFileURL } from 'node:url'
4
-
5
- const cliPath = fileURLToPath(new URL('../bin/weapp-tailwindcss.js', import.meta.url))
6
- const missingRuntimeModuleMessage = `${[
7
- '[weapp-tailwindcss] postinstall patch skipped because a runtime module is missing.',
8
- 'Run `pnpm --filter weapp-tailwindcss build` before strict CLI validation.',
9
- ].join(' ')}\n`
10
-
11
- export function isMissingRuntimeModuleOutput(output) {
12
- return /MODULE_NOT_FOUND|Cannot find module/.test(output)
13
- }
14
-
15
- export function resolvePostinstallPatchExitCode(result) {
16
- if (result.error) {
17
- return {
18
- code: 0,
19
- message: `[weapp-tailwindcss] postinstall patch skipped: ${result.error.message}\n`,
20
- }
21
- }
22
-
23
- if (result.status && isMissingRuntimeModuleOutput(`${result.stderr ?? ''}\n${result.stdout ?? ''}`)) {
24
- return {
25
- code: 0,
26
- message: missingRuntimeModuleMessage,
27
- }
28
- }
29
-
30
- return {
31
- code: result.status ?? 0,
32
- }
33
- }
34
-
35
- export function runPostinstallPatch() {
36
- const result = spawnSync(process.execPath, [cliPath, 'patch'], {
37
- encoding: 'utf8',
38
- })
39
-
40
- if (result.stdout) {
41
- process.stdout.write(result.stdout)
42
- }
43
-
44
- if (result.stderr) {
45
- process.stderr.write(result.stderr)
46
- }
47
-
48
- const resolved = resolvePostinstallPatchExitCode(result)
49
- if (resolved.message) {
50
- process.stderr.write(resolved.message)
51
- }
52
-
53
- process.exitCode = resolved.code
54
- }
55
-
56
- const entryPoint = process.argv[1] ? pathToFileURL(process.argv[1]).href : undefined
57
- if (import.meta.url === entryPoint) {
58
- runPostinstallPatch()
59
- }