weapp-tailwindcss 4.7.0 → 4.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-Q5TPAJI4.js → chunk-2SI3KT2H.js} +7 -6
- package/dist/{chunk-IY2OKZE6.mjs → chunk-3ARXMTWC.mjs} +21 -8
- package/dist/{chunk-D7SF52F6.mjs → chunk-5BW6X6AJ.mjs} +42 -36
- package/dist/chunk-667CYXAH.mjs +133 -0
- package/dist/chunk-BUMQQPAO.js +133 -0
- package/dist/{chunk-W3JU6K3T.js → chunk-FPDJ3BCM.js} +260 -108
- package/dist/{chunk-BAXZHBSU.js → chunk-GNWJEIZZ.js} +92 -77
- package/dist/{chunk-7TKAJ3P6.mjs → chunk-JYCQWWYU.mjs} +257 -105
- package/dist/{chunk-NRG7N2Q7.mjs → chunk-KZJLIZIK.mjs} +0 -1
- package/dist/{chunk-34T2BFTJ.mjs → chunk-KZUIVLPP.mjs} +42 -1
- package/dist/{chunk-C3CG4UUY.js → chunk-OPTIAB5G.js} +21 -8
- package/dist/{chunk-BTOCLUJ4.mjs → chunk-Q6PLZCM6.mjs} +6 -5
- package/dist/{chunk-CCMDCC3N.js → chunk-QZRXYCOQ.js} +49 -43
- package/dist/{chunk-WVKK6TBL.js → chunk-W7BVY5S5.js} +42 -1
- package/dist/{chunk-LZ6L3UQO.js → chunk-WXBFAARR.js} +0 -1
- package/dist/{chunk-KSXOBEXQ.mjs → chunk-Z2H7M33Z.mjs} +83 -68
- package/dist/cli.js +6 -6
- package/dist/cli.mjs +3 -3
- package/dist/core.js +10 -9
- package/dist/core.mjs +10 -9
- package/dist/defaults.js +2 -2
- package/dist/defaults.mjs +1 -1
- package/dist/gulp.js +6 -6
- package/dist/gulp.mjs +5 -5
- package/dist/index.js +9 -9
- package/dist/index.mjs +8 -8
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +1 -1
- package/dist/types.d.mts +2 -21
- package/dist/types.d.ts +2 -21
- package/dist/vite.js +7 -7
- package/dist/vite.mjs +6 -6
- package/dist/webpack.js +7 -7
- package/dist/webpack.mjs +6 -6
- package/dist/webpack4.js +51 -45
- package/dist/webpack4.mjs +44 -38
- package/package.json +4 -4
- package/dist/chunk-FB5P4TRH.js +0 -70
- package/dist/chunk-YPBRGP6K.mjs +0 -70
|
@@ -4,10 +4,11 @@ var _chunkLTJQUORKjs = require('./chunk-LTJQUORK.js');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var _chunkFB5P4TRHjs = require('./chunk-FB5P4TRH.js');
|
|
8
7
|
|
|
8
|
+
var _chunkBUMQQPAOjs = require('./chunk-BUMQQPAO.js');
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
var _chunkFPDJ3BCMjs = require('./chunk-FPDJ3BCM.js');
|
|
11
12
|
|
|
12
13
|
// src/bundlers/gulp/index.ts
|
|
13
14
|
var _buffer = require('buffer');
|
|
@@ -15,13 +16,13 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
|
15
16
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
16
17
|
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
17
18
|
var _stream = require('stream'); var _stream2 = _interopRequireDefault(_stream);
|
|
18
|
-
var debug =
|
|
19
|
+
var debug = _chunkBUMQQPAOjs.createDebug.call(void 0, );
|
|
19
20
|
var Transform = _stream2.default.Transform;
|
|
20
21
|
function createPlugins(options = {}) {
|
|
21
|
-
const opts =
|
|
22
|
+
const opts = _chunkFPDJ3BCMjs.getCompilerContext.call(void 0, options);
|
|
22
23
|
const { templateHandler, styleHandler, jsHandler, cache, twPatcher } = opts;
|
|
23
24
|
let runtimeSet = /* @__PURE__ */ new Set();
|
|
24
|
-
const patchPromise =
|
|
25
|
+
const patchPromise = _chunkBUMQQPAOjs.createTailwindPatchPromise.call(void 0, twPatcher);
|
|
25
26
|
const MODULE_EXTENSIONS = [".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx"];
|
|
26
27
|
let runtimeSetInitialized = false;
|
|
27
28
|
async function refreshRuntimeSet(force = false) {
|
|
@@ -29,7 +30,7 @@ function createPlugins(options = {}) {
|
|
|
29
30
|
if (!force && runtimeSetInitialized && runtimeSet.size > 0) {
|
|
30
31
|
return runtimeSet;
|
|
31
32
|
}
|
|
32
|
-
runtimeSet = await
|
|
33
|
+
runtimeSet = await _chunkBUMQQPAOjs.collectRuntimeClassSet.call(void 0, twPatcher, { force });
|
|
33
34
|
runtimeSetInitialized = true;
|
|
34
35
|
return runtimeSet;
|
|
35
36
|
}
|
|
@@ -243,25 +243,29 @@ function normalizeTailwindcssPatcherOptions(options) {
|
|
|
243
243
|
function createTailwindcssPatcher(options) {
|
|
244
244
|
const { basedir, cacheDir, supportCustomLengthUnitsPatch, tailwindcss, tailwindcssPatcherOptions } = options || {};
|
|
245
245
|
const cache = {};
|
|
246
|
+
const normalizedBasedir = basedir ? path.resolve(basedir) : void 0;
|
|
247
|
+
const cacheRoot = findNearestPackageRoot(normalizedBasedir) ?? normalizedBasedir ?? process.cwd();
|
|
246
248
|
if (cacheDir) {
|
|
247
249
|
if (path.isAbsolute(cacheDir)) {
|
|
248
250
|
cache.dir = cacheDir;
|
|
249
|
-
} else if (
|
|
250
|
-
cache.dir = path.resolve(
|
|
251
|
+
} else if (normalizedBasedir) {
|
|
252
|
+
cache.dir = path.resolve(normalizedBasedir, cacheDir);
|
|
251
253
|
} else {
|
|
252
254
|
cache.dir = path.resolve(process.cwd(), cacheDir);
|
|
253
255
|
}
|
|
256
|
+
} else {
|
|
257
|
+
cache.dir = path.join(cacheRoot, "node_modules", ".cache", "tailwindcss-patch");
|
|
254
258
|
}
|
|
255
|
-
if (
|
|
256
|
-
cache.cwd =
|
|
259
|
+
if (normalizedBasedir) {
|
|
260
|
+
cache.cwd = normalizedBasedir;
|
|
257
261
|
}
|
|
258
|
-
const resolvePaths = createDefaultResolvePaths(cache.cwd ??
|
|
262
|
+
const resolvePaths = createDefaultResolvePaths(cache.cwd ?? normalizedBasedir ?? process.cwd());
|
|
259
263
|
const normalizedUserOptions = normalizeTailwindcssPatcherOptions(tailwindcssPatcherOptions);
|
|
260
264
|
const extendLengthUnits = normalizeExtendLengthUnits(supportCustomLengthUnitsPatch);
|
|
261
265
|
const baseTailwindOptions = defuOverrideArray2(
|
|
262
266
|
tailwindcss ?? {},
|
|
263
267
|
{
|
|
264
|
-
cwd:
|
|
268
|
+
cwd: normalizedBasedir,
|
|
265
269
|
resolve: {
|
|
266
270
|
paths: resolvePaths
|
|
267
271
|
}
|
|
@@ -287,7 +291,7 @@ function createTailwindcssPatcher(options) {
|
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
293
|
const baseOptions = {
|
|
290
|
-
cwd:
|
|
294
|
+
cwd: normalizedBasedir,
|
|
291
295
|
cache,
|
|
292
296
|
tailwind: baseTailwindOptions,
|
|
293
297
|
features: {
|
|
@@ -380,6 +384,12 @@ var ENV_BASEDIR_KEYS = [
|
|
|
380
384
|
"PWD"
|
|
381
385
|
];
|
|
382
386
|
var GENERIC_ENV_BASEDIR_KEYS = /* @__PURE__ */ new Set(["INIT_CWD", "PWD"]);
|
|
387
|
+
function isLegacyTailwindcssPatcherOptions(options) {
|
|
388
|
+
return typeof options === "object" && options !== null && "patch" in options;
|
|
389
|
+
}
|
|
390
|
+
function isModernTailwindcssPatchOptions(options) {
|
|
391
|
+
return typeof options === "object" && options !== null && !("patch" in options);
|
|
392
|
+
}
|
|
383
393
|
function pickEnvBasedir() {
|
|
384
394
|
for (const key of ENV_BASEDIR_KEYS) {
|
|
385
395
|
const value = process2.env[key];
|
|
@@ -538,7 +548,7 @@ function overrideTailwindcssPatcherOptionsForBase(options, baseDir, cssEntries)
|
|
|
538
548
|
if (!options) {
|
|
539
549
|
return options;
|
|
540
550
|
}
|
|
541
|
-
if (
|
|
551
|
+
if (isLegacyTailwindcssPatcherOptions(options)) {
|
|
542
552
|
const patchOptions = options.patch;
|
|
543
553
|
if (!patchOptions) {
|
|
544
554
|
return options;
|
|
@@ -563,6 +573,9 @@ function overrideTailwindcssPatcherOptionsForBase(options, baseDir, cssEntries)
|
|
|
563
573
|
patch: nextPatch
|
|
564
574
|
};
|
|
565
575
|
}
|
|
576
|
+
if (!isModernTailwindcssPatchOptions(options)) {
|
|
577
|
+
return options;
|
|
578
|
+
}
|
|
566
579
|
if (!options.tailwind) {
|
|
567
580
|
return options;
|
|
568
581
|
}
|
|
@@ -2,20 +2,22 @@ import {
|
|
|
2
2
|
getCacheKey
|
|
3
3
|
} from "./chunk-2F7HOQQY.mjs";
|
|
4
4
|
import {
|
|
5
|
+
pushConcurrentTaskFactories,
|
|
5
6
|
resolveOutputSpecifier,
|
|
6
7
|
toAbsoluteOutputPath
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-KZUIVLPP.mjs";
|
|
8
9
|
import {
|
|
9
10
|
processCachedTask
|
|
10
11
|
} from "./chunk-RRHPTTCP.mjs";
|
|
11
12
|
import {
|
|
12
13
|
collectRuntimeClassSet,
|
|
13
|
-
createDebug
|
|
14
|
-
|
|
14
|
+
createDebug,
|
|
15
|
+
createTailwindPatchPromise
|
|
16
|
+
} from "./chunk-667CYXAH.mjs";
|
|
15
17
|
import {
|
|
16
18
|
getCompilerContext,
|
|
17
19
|
pluginName
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-JYCQWWYU.mjs";
|
|
19
21
|
import {
|
|
20
22
|
getGroupedEntries
|
|
21
23
|
} from "./chunk-ZNKIYZRQ.mjs";
|
|
@@ -51,12 +53,12 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
51
53
|
if (disabled) {
|
|
52
54
|
return;
|
|
53
55
|
}
|
|
54
|
-
const patchPromise =
|
|
56
|
+
const patchPromise = createTailwindPatchPromise(twPatcher);
|
|
55
57
|
const { Compilation, sources, NormalModule } = compiler.webpack;
|
|
56
58
|
const { ConcatSource } = sources;
|
|
57
59
|
async function getClassSetInLoader() {
|
|
58
60
|
await patchPromise;
|
|
59
|
-
await collectRuntimeClassSet(twPatcher);
|
|
61
|
+
await collectRuntimeClassSet(twPatcher, { force: true });
|
|
60
62
|
}
|
|
61
63
|
onLoad();
|
|
62
64
|
const loader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-loader.js");
|
|
@@ -147,7 +149,7 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
147
149
|
}
|
|
148
150
|
};
|
|
149
151
|
const groupedEntries = getGroupedEntries(entries, this.options);
|
|
150
|
-
const runtimeSet = await collectRuntimeClassSet(twPatcher);
|
|
152
|
+
const runtimeSet = await collectRuntimeClassSet(twPatcher, { force: true });
|
|
151
153
|
debug("get runtimeSet, class count: %d", runtimeSet.size);
|
|
152
154
|
const tasks = [];
|
|
153
155
|
if (Array.isArray(groupedEntries.html)) {
|
|
@@ -181,6 +183,7 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
181
183
|
);
|
|
182
184
|
}
|
|
183
185
|
}
|
|
186
|
+
const jsTaskFactories = [];
|
|
184
187
|
if (Array.isArray(groupedEntries.js)) {
|
|
185
188
|
for (const [file] of groupedEntries.js) {
|
|
186
189
|
const cacheKey = getCacheKey(file);
|
|
@@ -191,35 +194,37 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
191
194
|
const absoluteFile = toAbsoluteOutputPath(file, outputDir);
|
|
192
195
|
const initialSource = asset.source.source();
|
|
193
196
|
const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
197
|
+
jsTaskFactories.push(async () => {
|
|
198
|
+
await processCachedTask({
|
|
199
|
+
cache,
|
|
200
|
+
cacheKey,
|
|
201
|
+
rawSource: initialRawSource,
|
|
202
|
+
applyResult(source) {
|
|
203
|
+
compilation.updateAsset(file, source);
|
|
204
|
+
},
|
|
205
|
+
onCacheHit() {
|
|
206
|
+
debug("js cache hit: %s", file);
|
|
207
|
+
},
|
|
208
|
+
transform: async () => {
|
|
209
|
+
const currentAsset = compilation.getAsset(file);
|
|
210
|
+
const currentSourceValue = currentAsset?.source.source();
|
|
211
|
+
const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
|
|
212
|
+
const { code, linked } = await jsHandler(currentSource, runtimeSet, {
|
|
213
|
+
filename: absoluteFile,
|
|
214
|
+
moduleGraph: moduleGraphOptions,
|
|
215
|
+
babelParserOptions: {
|
|
216
|
+
sourceFilename: absoluteFile
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
const source = new ConcatSource(code);
|
|
220
|
+
onUpdate(file, currentSource, code);
|
|
221
|
+
debug("js handle: %s", file);
|
|
222
|
+
applyLinkedResults(linked);
|
|
223
|
+
return {
|
|
224
|
+
result: source
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
});
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
230
|
}
|
|
@@ -261,6 +266,7 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
261
266
|
);
|
|
262
267
|
}
|
|
263
268
|
}
|
|
269
|
+
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
264
270
|
await Promise.all(tasks);
|
|
265
271
|
debug("end");
|
|
266
272
|
onEnd();
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// src/tailwindcss/runtime.ts
|
|
2
|
+
import { statSync } from "fs";
|
|
3
|
+
|
|
4
|
+
// src/debug/index.ts
|
|
5
|
+
import _createDebug from "debug";
|
|
6
|
+
var _debug = _createDebug("weapp-tw");
|
|
7
|
+
function createDebug(prefix) {
|
|
8
|
+
function debug2(formatter, ...args) {
|
|
9
|
+
return _debug((prefix ?? "") + formatter, ...args);
|
|
10
|
+
}
|
|
11
|
+
return debug2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/tailwindcss/runtime.ts
|
|
15
|
+
var debug = createDebug("[tailwindcss:runtime] ");
|
|
16
|
+
var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
function getCacheEntry(twPatcher) {
|
|
18
|
+
let entry = runtimeClassSetCache.get(twPatcher);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
entry = {};
|
|
21
|
+
runtimeClassSetCache.set(twPatcher, entry);
|
|
22
|
+
}
|
|
23
|
+
return entry;
|
|
24
|
+
}
|
|
25
|
+
function getTailwindConfigSignature(twPatcher) {
|
|
26
|
+
const configPath = twPatcher.options?.tailwind?.config;
|
|
27
|
+
if (typeof configPath !== "string" || configPath.length === 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const stats = statSync(configPath);
|
|
32
|
+
return `${configPath}:${stats.size}:${stats.mtimeMs}`;
|
|
33
|
+
} catch {
|
|
34
|
+
return `${configPath}:missing`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function invalidateRuntimeClassSet(twPatcher) {
|
|
38
|
+
if (!twPatcher) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
runtimeClassSetCache.delete(twPatcher);
|
|
42
|
+
}
|
|
43
|
+
function createTailwindPatchPromise(twPatcher) {
|
|
44
|
+
return Promise.resolve(twPatcher.patch()).then((result) => {
|
|
45
|
+
invalidateRuntimeClassSet(twPatcher);
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function shouldPreferSync(majorVersion) {
|
|
50
|
+
if (majorVersion == null) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (majorVersion === 3) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (majorVersion === 4) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
62
|
+
if (typeof twPatcher.getClassSetSync !== "function") {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
if (!shouldPreferSync(twPatcher.majorVersion)) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
return twPatcher.getClassSetSync();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (twPatcher.majorVersion === 4) {
|
|
72
|
+
debug("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
73
|
+
} else {
|
|
74
|
+
debug("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
80
|
+
const entry = getCacheEntry(twPatcher);
|
|
81
|
+
const signature = getTailwindConfigSignature(twPatcher);
|
|
82
|
+
if (!options.force) {
|
|
83
|
+
if (entry.value && entry.signature === signature) {
|
|
84
|
+
return entry.value;
|
|
85
|
+
}
|
|
86
|
+
if (entry.promise) {
|
|
87
|
+
return entry.promise;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
entry.value = void 0;
|
|
91
|
+
}
|
|
92
|
+
const task = (async () => {
|
|
93
|
+
const syncSet = tryGetRuntimeClassSetSync(twPatcher);
|
|
94
|
+
if (syncSet) {
|
|
95
|
+
return syncSet;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const result = await twPatcher.extract({ write: false });
|
|
99
|
+
if (result?.classSet) {
|
|
100
|
+
return result.classSet;
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
debug("extract() failed, fallback to getClassSet(): %O", error);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const fallbackSet = await Promise.resolve(twPatcher.getClassSet());
|
|
107
|
+
if (fallbackSet) {
|
|
108
|
+
return fallbackSet;
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
debug("getClassSet() failed, returning empty set: %O", error);
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ new Set();
|
|
114
|
+
})();
|
|
115
|
+
entry.promise = task;
|
|
116
|
+
entry.signature = signature;
|
|
117
|
+
try {
|
|
118
|
+
const resolved = await task;
|
|
119
|
+
entry.value = resolved;
|
|
120
|
+
entry.promise = void 0;
|
|
121
|
+
entry.signature = signature;
|
|
122
|
+
return resolved;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
entry.promise = void 0;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export {
|
|
130
|
+
createDebug,
|
|
131
|
+
createTailwindPatchPromise,
|
|
132
|
+
collectRuntimeClassSet
|
|
133
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/tailwindcss/runtime.ts
|
|
2
|
+
var _fs = require('fs');
|
|
3
|
+
|
|
4
|
+
// src/debug/index.ts
|
|
5
|
+
var _debug2 = require('debug'); var _debug3 = _interopRequireDefault(_debug2);
|
|
6
|
+
var _debug = _debug3.default.call(void 0, "weapp-tw");
|
|
7
|
+
function createDebug(prefix) {
|
|
8
|
+
function debug2(formatter, ...args) {
|
|
9
|
+
return _debug((_nullishCoalesce(prefix, () => ( ""))) + formatter, ...args);
|
|
10
|
+
}
|
|
11
|
+
return debug2;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/tailwindcss/runtime.ts
|
|
15
|
+
var debug = createDebug("[tailwindcss:runtime] ");
|
|
16
|
+
var runtimeClassSetCache = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
function getCacheEntry(twPatcher) {
|
|
18
|
+
let entry = runtimeClassSetCache.get(twPatcher);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
entry = {};
|
|
21
|
+
runtimeClassSetCache.set(twPatcher, entry);
|
|
22
|
+
}
|
|
23
|
+
return entry;
|
|
24
|
+
}
|
|
25
|
+
function getTailwindConfigSignature(twPatcher) {
|
|
26
|
+
const configPath = _optionalChain([twPatcher, 'access', _ => _.options, 'optionalAccess', _2 => _2.tailwind, 'optionalAccess', _3 => _3.config]);
|
|
27
|
+
if (typeof configPath !== "string" || configPath.length === 0) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const stats = _fs.statSync.call(void 0, configPath);
|
|
32
|
+
return `${configPath}:${stats.size}:${stats.mtimeMs}`;
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return `${configPath}:missing`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function invalidateRuntimeClassSet(twPatcher) {
|
|
38
|
+
if (!twPatcher) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
runtimeClassSetCache.delete(twPatcher);
|
|
42
|
+
}
|
|
43
|
+
function createTailwindPatchPromise(twPatcher) {
|
|
44
|
+
return Promise.resolve(twPatcher.patch()).then((result) => {
|
|
45
|
+
invalidateRuntimeClassSet(twPatcher);
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function shouldPreferSync(majorVersion) {
|
|
50
|
+
if (majorVersion == null) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (majorVersion === 3) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (majorVersion === 4) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
62
|
+
if (typeof twPatcher.getClassSetSync !== "function") {
|
|
63
|
+
return void 0;
|
|
64
|
+
}
|
|
65
|
+
if (!shouldPreferSync(twPatcher.majorVersion)) {
|
|
66
|
+
return void 0;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
return twPatcher.getClassSetSync();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
if (twPatcher.majorVersion === 4) {
|
|
72
|
+
debug("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
73
|
+
} else {
|
|
74
|
+
debug("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
75
|
+
}
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
80
|
+
const entry = getCacheEntry(twPatcher);
|
|
81
|
+
const signature = getTailwindConfigSignature(twPatcher);
|
|
82
|
+
if (!options.force) {
|
|
83
|
+
if (entry.value && entry.signature === signature) {
|
|
84
|
+
return entry.value;
|
|
85
|
+
}
|
|
86
|
+
if (entry.promise) {
|
|
87
|
+
return entry.promise;
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
entry.value = void 0;
|
|
91
|
+
}
|
|
92
|
+
const task = (async () => {
|
|
93
|
+
const syncSet = tryGetRuntimeClassSetSync(twPatcher);
|
|
94
|
+
if (syncSet) {
|
|
95
|
+
return syncSet;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const result = await twPatcher.extract({ write: false });
|
|
99
|
+
if (_optionalChain([result, 'optionalAccess', _4 => _4.classSet])) {
|
|
100
|
+
return result.classSet;
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
debug("extract() failed, fallback to getClassSet(): %O", error);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const fallbackSet = await Promise.resolve(twPatcher.getClassSet());
|
|
107
|
+
if (fallbackSet) {
|
|
108
|
+
return fallbackSet;
|
|
109
|
+
}
|
|
110
|
+
} catch (error) {
|
|
111
|
+
debug("getClassSet() failed, returning empty set: %O", error);
|
|
112
|
+
}
|
|
113
|
+
return /* @__PURE__ */ new Set();
|
|
114
|
+
})();
|
|
115
|
+
entry.promise = task;
|
|
116
|
+
entry.signature = signature;
|
|
117
|
+
try {
|
|
118
|
+
const resolved = await task;
|
|
119
|
+
entry.value = resolved;
|
|
120
|
+
entry.promise = void 0;
|
|
121
|
+
entry.signature = signature;
|
|
122
|
+
return resolved;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
entry.promise = void 0;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
exports.createDebug = createDebug; exports.createTailwindPatchPromise = createTailwindPatchPromise; exports.collectRuntimeClassSet = collectRuntimeClassSet;
|