weapp-tailwindcss 4.9.2-alpha.2 → 4.9.3

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 (54) hide show
  1. package/dist/{chunk-W4XFWZB5.js → chunk-3UOPODB3.js} +44 -44
  2. package/dist/{chunk-JOLM54PI.mjs → chunk-4HESZS5A.mjs} +2 -2
  3. package/dist/{chunk-5O6237HX.js → chunk-4RUFPPI6.js} +400 -377
  4. package/dist/{chunk-ZE7JKKFT.mjs → chunk-7D27E7TU.mjs} +438 -415
  5. package/dist/{chunk-KA2JONAP.js → chunk-A2BRI46M.js} +5 -5
  6. package/dist/{chunk-3SKEY32E.mjs → chunk-F2CKKG6Q.mjs} +67 -67
  7. package/dist/{chunk-YBTRKOE2.js → chunk-I3IRT5VH.js} +7 -7
  8. package/dist/chunk-IMOEZLDR.js +441 -0
  9. package/dist/{chunk-OU2OBBPZ.mjs → chunk-IW3B6ZJD.mjs} +646 -565
  10. package/dist/{chunk-NGRAUBWU.js → chunk-KXZ4MP4L.js} +277 -236
  11. package/dist/chunk-PU5CC4ZI.mjs +444 -0
  12. package/dist/{chunk-FFGR5V3H.mjs → chunk-SPH6SCTM.mjs} +1 -1
  13. package/dist/{chunk-J7KULRTR.js → chunk-VOD2WUH6.js} +635 -554
  14. package/dist/{chunk-2WPTDMN3.js → chunk-VPHA77FH.js} +61 -61
  15. package/dist/{chunk-QA5NZSGN.mjs → chunk-WH65CIYG.mjs} +41 -41
  16. package/dist/{chunk-UAEME5HT.js → chunk-Y6F6NBA7.js} +1 -1
  17. package/dist/{chunk-6HBFEXOW.mjs → chunk-Z2D5NSG5.mjs} +265 -224
  18. package/dist/{chunk-XWGIWOHV.mjs → chunk-ZL22KEHH.mjs} +2 -2
  19. package/dist/cli.js +182 -136
  20. package/dist/cli.mjs +194 -148
  21. package/dist/core.js +10 -10
  22. package/dist/core.mjs +4 -4
  23. package/dist/css-macro/postcss.js +1 -1
  24. package/dist/css-macro/postcss.mjs +1 -1
  25. package/dist/css-macro.js +1 -1
  26. package/dist/css-macro.mjs +1 -1
  27. package/dist/defaults.js +1 -1
  28. package/dist/defaults.mjs +1 -1
  29. package/dist/gulp.js +6 -6
  30. package/dist/gulp.mjs +5 -5
  31. package/dist/index.js +10 -10
  32. package/dist/index.mjs +9 -9
  33. package/dist/postcss-html-transform.js +1 -1
  34. package/dist/postcss-html-transform.mjs +1 -1
  35. package/dist/presets.js +5 -5
  36. package/dist/presets.mjs +2 -2
  37. package/dist/reset.d.mts +2 -1
  38. package/dist/reset.d.ts +2 -1
  39. package/dist/reset.js +25 -21
  40. package/dist/reset.mjs +25 -21
  41. package/dist/types.d.mts +503 -474
  42. package/dist/types.d.ts +503 -474
  43. package/dist/types.js +1 -1
  44. package/dist/types.mjs +1 -1
  45. package/dist/vite.js +7 -7
  46. package/dist/vite.mjs +6 -6
  47. package/dist/weapp-tw-css-import-rewrite-loader.js +2 -4
  48. package/dist/webpack.js +8 -8
  49. package/dist/webpack.mjs +7 -7
  50. package/dist/webpack4.js +351 -307
  51. package/dist/webpack4.mjs +341 -297
  52. package/package.json +11 -11
  53. package/dist/chunk-CF7VDUIE.mjs +0 -397
  54. package/dist/chunk-OGG7WXHZ.js +0 -394
@@ -0,0 +1,444 @@
1
+ import {
2
+ applyTailwindcssCssImportRewrite,
3
+ createLoaderAnchorFinders,
4
+ ensureMpxTailwindcssAliases,
5
+ getCacheKey,
6
+ hasLoaderEntry,
7
+ injectMpxCssRewritePreRules,
8
+ isCssLikeModuleResource,
9
+ isMpx,
10
+ patchMpxLoaderResolve,
11
+ setupMpxTailwindcssRedirect
12
+ } from "./chunk-WH65CIYG.mjs";
13
+ import {
14
+ pushConcurrentTaskFactories,
15
+ resolveDisabledOptions,
16
+ resolveOutputSpecifier,
17
+ resolvePackageDir,
18
+ toAbsoluteOutputPath
19
+ } from "./chunk-F2CKKG6Q.mjs";
20
+ import {
21
+ processCachedTask
22
+ } from "./chunk-RRHPTTCP.mjs";
23
+ import {
24
+ setupPatchRecorder
25
+ } from "./chunk-ZL22KEHH.mjs";
26
+ import {
27
+ collectRuntimeClassSet,
28
+ createDebug,
29
+ getCompilerContext,
30
+ pluginName,
31
+ refreshTailwindRuntimeState
32
+ } from "./chunk-IW3B6ZJD.mjs";
33
+ import {
34
+ getGroupedEntries
35
+ } from "./chunk-OOHJLO5M.mjs";
36
+ import {
37
+ __dirname
38
+ } from "./chunk-SPH6SCTM.mjs";
39
+
40
+ // src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
41
+ import process3 from "process";
42
+
43
+ // src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
44
+ import path from "path";
45
+ import process from "process";
46
+ function setupWebpackV5ProcessAssetsHook(options) {
47
+ const {
48
+ compiler,
49
+ options: compilerOptions,
50
+ appType,
51
+ runtimeState,
52
+ refreshRuntimeState,
53
+ debug: debug2
54
+ } = options;
55
+ const { Compilation, sources } = compiler.webpack;
56
+ const { ConcatSource } = sources;
57
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
58
+ compilation.hooks.processAssets.tapPromise(
59
+ {
60
+ name: pluginName,
61
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
62
+ },
63
+ async (assets) => {
64
+ compilerOptions.onStart();
65
+ debug2("start");
66
+ await runtimeState.patchPromise;
67
+ for (const chunk of compilation.chunks) {
68
+ if (chunk.id && chunk.hash) {
69
+ compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
70
+ }
71
+ }
72
+ const entries = Object.entries(assets);
73
+ const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
74
+ const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
75
+ const jsAssets = /* @__PURE__ */ new Map();
76
+ for (const [file] of entries) {
77
+ if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
78
+ const absolute = toAbsoluteOutputPath(file, outputDir);
79
+ jsAssets.set(absolute, file);
80
+ }
81
+ }
82
+ const moduleGraphOptions = {
83
+ resolve(specifier, importer) {
84
+ return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
85
+ },
86
+ load: (id) => {
87
+ const assetName = jsAssets.get(id);
88
+ if (!assetName) {
89
+ return void 0;
90
+ }
91
+ const asset = compilation.getAsset(assetName);
92
+ if (!asset) {
93
+ return void 0;
94
+ }
95
+ const source = asset.source.source();
96
+ return typeof source === "string" ? source : source.toString();
97
+ },
98
+ filter(id) {
99
+ return jsAssets.has(id);
100
+ }
101
+ };
102
+ const applyLinkedResults = (linked) => {
103
+ if (!linked) {
104
+ return;
105
+ }
106
+ for (const [id, { code }] of Object.entries(linked)) {
107
+ const assetName = jsAssets.get(id);
108
+ if (!assetName) {
109
+ continue;
110
+ }
111
+ const asset = compilation.getAsset(assetName);
112
+ if (!asset) {
113
+ continue;
114
+ }
115
+ const previousSource = asset.source.source();
116
+ const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
117
+ if (previous === code) {
118
+ continue;
119
+ }
120
+ const source = new ConcatSource(code);
121
+ compilation.updateAsset(assetName, source);
122
+ compilerOptions.onUpdate(assetName, previous, code);
123
+ debug2("js linked handle: %s", assetName);
124
+ }
125
+ };
126
+ const groupedEntries = getGroupedEntries(entries, compilerOptions);
127
+ await refreshRuntimeState(true);
128
+ await runtimeState.patchPromise;
129
+ const runtimeSet = await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
130
+ debug2("get runtimeSet, class count: %d", runtimeSet.size);
131
+ const tasks = [];
132
+ if (Array.isArray(groupedEntries.html)) {
133
+ for (const element of groupedEntries.html) {
134
+ const [file, originalSource] = element;
135
+ const rawSource = originalSource.source().toString();
136
+ const cacheKey = file;
137
+ tasks.push(
138
+ processCachedTask({
139
+ cache: compilerOptions.cache,
140
+ cacheKey,
141
+ rawSource,
142
+ applyResult(source) {
143
+ compilation.updateAsset(file, source);
144
+ },
145
+ onCacheHit() {
146
+ debug2("html cache hit: %s", file);
147
+ },
148
+ transform: async () => {
149
+ const wxml = await compilerOptions.templateHandler(rawSource, {
150
+ runtimeSet
151
+ });
152
+ const source = new ConcatSource(wxml);
153
+ compilerOptions.onUpdate(file, rawSource, wxml);
154
+ debug2("html handle: %s", file);
155
+ return {
156
+ result: source
157
+ };
158
+ }
159
+ })
160
+ );
161
+ }
162
+ }
163
+ const jsTaskFactories = [];
164
+ if (Array.isArray(groupedEntries.js)) {
165
+ for (const [file] of groupedEntries.js) {
166
+ const cacheKey = getCacheKey(file);
167
+ const asset = compilation.getAsset(file);
168
+ if (!asset) {
169
+ continue;
170
+ }
171
+ const absoluteFile = toAbsoluteOutputPath(file, outputDir);
172
+ const initialSource = asset.source.source();
173
+ const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
174
+ jsTaskFactories.push(async () => {
175
+ await processCachedTask({
176
+ cache: compilerOptions.cache,
177
+ cacheKey,
178
+ rawSource: initialRawSource,
179
+ applyResult(source) {
180
+ compilation.updateAsset(file, source);
181
+ },
182
+ onCacheHit() {
183
+ debug2("js cache hit: %s", file);
184
+ },
185
+ transform: async () => {
186
+ const currentAsset = compilation.getAsset(file);
187
+ const currentSourceValue = currentAsset?.source.source();
188
+ const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
189
+ const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, {
190
+ filename: absoluteFile,
191
+ moduleGraph: moduleGraphOptions,
192
+ babelParserOptions: {
193
+ sourceFilename: absoluteFile
194
+ }
195
+ });
196
+ const source = new ConcatSource(code);
197
+ compilerOptions.onUpdate(file, currentSource, code);
198
+ debug2("js handle: %s", file);
199
+ applyLinkedResults(linked);
200
+ return {
201
+ result: source
202
+ };
203
+ }
204
+ });
205
+ });
206
+ }
207
+ }
208
+ if (Array.isArray(groupedEntries.css)) {
209
+ for (const element of groupedEntries.css) {
210
+ const [file, originalSource] = element;
211
+ const rawSource = originalSource.source().toString();
212
+ const cacheKey = file;
213
+ tasks.push(
214
+ processCachedTask({
215
+ cache: compilerOptions.cache,
216
+ cacheKey,
217
+ rawSource,
218
+ applyResult(source) {
219
+ compilation.updateAsset(file, source);
220
+ },
221
+ onCacheHit() {
222
+ debug2("css cache hit: %s", file);
223
+ },
224
+ transform: async () => {
225
+ await runtimeState.patchPromise;
226
+ const { css } = await compilerOptions.styleHandler(rawSource, {
227
+ isMainChunk: compilerOptions.mainCssChunkMatcher(file, appType),
228
+ postcssOptions: {
229
+ options: {
230
+ from: file
231
+ }
232
+ },
233
+ majorVersion: runtimeState.twPatcher.majorVersion
234
+ });
235
+ const source = new ConcatSource(css);
236
+ compilerOptions.onUpdate(file, rawSource, css);
237
+ debug2("css handle: %s", file);
238
+ return {
239
+ result: source
240
+ };
241
+ }
242
+ })
243
+ );
244
+ }
245
+ }
246
+ pushConcurrentTaskFactories(tasks, jsTaskFactories);
247
+ await Promise.all(tasks);
248
+ debug2("end");
249
+ compilerOptions.onEnd();
250
+ }
251
+ );
252
+ });
253
+ }
254
+
255
+ // src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
256
+ import fs from "fs";
257
+ import path2 from "path";
258
+ import process2 from "process";
259
+ function setupWebpackV5Loaders(options) {
260
+ const {
261
+ compiler,
262
+ options: compilerOptions,
263
+ appType,
264
+ weappTailwindcssPackageDir: weappTailwindcssPackageDir2,
265
+ shouldRewriteCssImports,
266
+ runtimeLoaderPath,
267
+ runtimeCssImportRewriteLoaderPath,
268
+ getClassSetInLoader,
269
+ debug: debug2
270
+ } = options;
271
+ const isMpxApp = isMpx(appType);
272
+ if (shouldRewriteCssImports && isMpxApp) {
273
+ ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir2);
274
+ }
275
+ const runtimeClassSetLoader = runtimeLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
276
+ const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
277
+ const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
278
+ const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
279
+ const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
280
+ pkgDir: weappTailwindcssPackageDir2,
281
+ appType
282
+ } : void 0;
283
+ const classSetLoaderOptions = {
284
+ getClassSet: getClassSetInLoader
285
+ };
286
+ const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
287
+ const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
288
+ rewriteCssImports: runtimeLoaderRewriteOptions
289
+ } : void 0;
290
+ if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) {
291
+ injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
292
+ }
293
+ const createRuntimeClassSetLoaderEntry = () => ({
294
+ loader: runtimeClassSetLoader,
295
+ options: classSetLoaderOptions,
296
+ ident: null,
297
+ type: null
298
+ });
299
+ const createCssImportRewriteLoaderEntry = () => {
300
+ if (!runtimeCssImportRewriteLoader) {
301
+ return null;
302
+ }
303
+ return {
304
+ loader: runtimeCssImportRewriteLoader,
305
+ options: cssImportRewriteLoaderOptions,
306
+ ident: null,
307
+ type: null
308
+ };
309
+ };
310
+ const { NormalModule } = compiler.webpack;
311
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
312
+ NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
313
+ const hasRuntimeLoader = runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists;
314
+ if (!hasRuntimeLoader) {
315
+ return;
316
+ }
317
+ patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir2, shouldRewriteCssImports && isMpxApp);
318
+ const loaderEntries = module.loaders || [];
319
+ let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
320
+ const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
321
+ const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
322
+ if (process2.env.WEAPP_TW_LOADER_DEBUG && isCssModule) {
323
+ debug2("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
324
+ }
325
+ if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.includes("app.css")) {
326
+ debug2("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
327
+ } else if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.endsWith(".css")) {
328
+ debug2("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
329
+ }
330
+ if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) {
331
+ return;
332
+ }
333
+ const anchorlessInsert = (entry, position) => {
334
+ if (position === "after") {
335
+ loaderEntries.push(entry);
336
+ } else {
337
+ loaderEntries.unshift(entry);
338
+ }
339
+ };
340
+ if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
341
+ const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
342
+ const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
343
+ if (rewriteLoaderEntry) {
344
+ const anchorIndex = findRewriteAnchor(loaderEntries);
345
+ if (anchorIndex === -1) {
346
+ anchorlessInsert(rewriteLoaderEntry, "after");
347
+ } else {
348
+ loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
349
+ }
350
+ rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
351
+ }
352
+ }
353
+ if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
354
+ const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
355
+ const anchorIndex = findClassSetAnchor(loaderEntries);
356
+ if (anchorIndex === -1) {
357
+ anchorlessInsert(classSetLoaderEntry, "before");
358
+ } else {
359
+ const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
360
+ loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
361
+ }
362
+ }
363
+ });
364
+ });
365
+ }
366
+
367
+ // src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
368
+ var debug = createDebug();
369
+ var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
370
+ var UnifiedWebpackPluginV5 = class {
371
+ constructor(options = {}) {
372
+ this.options = getCompilerContext(options);
373
+ this.appType = this.options.appType;
374
+ }
375
+ apply(compiler) {
376
+ compiler.options = compiler.options || {};
377
+ const {
378
+ disabled,
379
+ onLoad,
380
+ runtimeLoaderPath,
381
+ runtimeCssImportRewriteLoaderPath,
382
+ twPatcher: initialTwPatcher,
383
+ refreshTailwindcssPatcher
384
+ } = this.options;
385
+ const disabledOptions = resolveDisabledOptions(disabled);
386
+ const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
387
+ const shouldRewriteCssImports = isTailwindcssV4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
388
+ const isMpxApp = isMpx(this.appType);
389
+ if (shouldRewriteCssImports) {
390
+ applyTailwindcssCssImportRewrite(compiler, {
391
+ pkgDir: weappTailwindcssPackageDir,
392
+ enabled: true,
393
+ appType: this.appType
394
+ });
395
+ setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
396
+ }
397
+ if (disabledOptions.plugin) {
398
+ return;
399
+ }
400
+ const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
401
+ source: "runtime",
402
+ cwd: this.options.tailwindcssBasedir ?? process3.cwd()
403
+ });
404
+ const runtimeState = {
405
+ twPatcher: initialTwPatcher,
406
+ patchPromise: patchRecorderState.patchPromise,
407
+ refreshTailwindcssPatcher,
408
+ onPatchCompleted: patchRecorderState.onPatchCompleted
409
+ };
410
+ const refreshRuntimeState = async (force) => {
411
+ await refreshTailwindRuntimeState(runtimeState, force);
412
+ };
413
+ async function getClassSetInLoader() {
414
+ await refreshRuntimeState(true);
415
+ await runtimeState.patchPromise;
416
+ await collectRuntimeClassSet(runtimeState.twPatcher, { force: true, skipRefresh: true });
417
+ }
418
+ onLoad();
419
+ setupWebpackV5Loaders({
420
+ compiler,
421
+ options: this.options,
422
+ appType: this.appType,
423
+ weappTailwindcssPackageDir,
424
+ shouldRewriteCssImports,
425
+ runtimeLoaderPath,
426
+ runtimeCssImportRewriteLoaderPath,
427
+ getClassSetInLoader,
428
+ debug
429
+ });
430
+ setupWebpackV5ProcessAssetsHook({
431
+ compiler,
432
+ options: this.options,
433
+ appType: this.appType,
434
+ runtimeState,
435
+ refreshRuntimeState,
436
+ debug
437
+ });
438
+ }
439
+ };
440
+
441
+ export {
442
+ weappTailwindcssPackageDir,
443
+ UnifiedWebpackPluginV5
444
+ };
@@ -1,4 +1,4 @@
1
- // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.55.2_@types+node@24.10.4__@swc+core@1.15.7_@swc+h_4d5dc336679991eff78ae0f04625a6b1/node_modules/tsup/assets/esm_shims.js
1
+ // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.55.2_@types+node@24.10.9__@swc+core@1.15.10_@swc+_ff0c9e72feaa13fcd6be33c9c3d4ff4d/node_modules/tsup/assets/esm_shims.js
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  var getFilename = () => fileURLToPath(import.meta.url);