tailwindcss-patch 7.1.5 → 8.0.0
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 +87 -73
- package/dist/chunk-FSTUQMKT.js +1320 -0
- package/dist/chunk-Y45IACSP.mjs +1316 -0
- package/dist/cli.js +131 -38
- package/dist/cli.mjs +132 -38
- package/dist/index.d.mts +237 -87
- package/dist/index.d.ts +237 -87
- package/dist/index.js +6 -2
- package/dist/index.mjs +19 -15
- package/package.json +20 -20
- package/dist/chunk-N2DIY7M3.js +0 -1107
- package/dist/chunk-NS2I2YPX.mjs +0 -1102
|
@@ -0,0 +1,1320 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; } var _class;// ../../node_modules/.pnpm/tsup@8.5.0_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
2
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
3
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
4
|
+
|
|
5
|
+
// src/logger.ts
|
|
6
|
+
var _consola = require('consola');
|
|
7
|
+
var logger = _consola.createConsola.call(void 0, );
|
|
8
|
+
var logger_default = logger;
|
|
9
|
+
|
|
10
|
+
// src/cache/store.ts
|
|
11
|
+
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
12
|
+
var CacheStore = class {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
async ensureDir() {
|
|
17
|
+
await _fsextra2.default.ensureDir(this.options.dir);
|
|
18
|
+
}
|
|
19
|
+
async write(data) {
|
|
20
|
+
if (!this.options.enabled) {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
await this.ensureDir();
|
|
25
|
+
await _fsextra2.default.writeJSON(this.options.path, Array.from(data));
|
|
26
|
+
return this.options.path;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async read() {
|
|
33
|
+
if (!this.options.enabled) {
|
|
34
|
+
return /* @__PURE__ */ new Set();
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const exists = await _fsextra2.default.pathExists(this.options.path);
|
|
38
|
+
if (!exists) {
|
|
39
|
+
return /* @__PURE__ */ new Set();
|
|
40
|
+
}
|
|
41
|
+
const data = await _fsextra2.default.readJSON(this.options.path);
|
|
42
|
+
if (Array.isArray(data)) {
|
|
43
|
+
return new Set(data.filter((item) => typeof item === "string"));
|
|
44
|
+
}
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
|
|
47
|
+
try {
|
|
48
|
+
await _fsextra2.default.remove(this.options.path);
|
|
49
|
+
} catch (cleanupError) {
|
|
50
|
+
logger_default.error("Failed to clean up invalid cache file", cleanupError);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return /* @__PURE__ */ new Set();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/extraction/candidate-extractor.ts
|
|
58
|
+
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
59
|
+
async function importNode() {
|
|
60
|
+
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
|
|
61
|
+
}
|
|
62
|
+
async function importOxide() {
|
|
63
|
+
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
|
|
64
|
+
}
|
|
65
|
+
async function extractRawCandidatesWithPositions(content, extension = "html") {
|
|
66
|
+
const { Scanner } = await importOxide();
|
|
67
|
+
const scanner = new Scanner({});
|
|
68
|
+
const result = scanner.getCandidatesWithPositions({ content, extension });
|
|
69
|
+
return result.map(({ candidate, position }) => ({
|
|
70
|
+
rawCandidate: candidate,
|
|
71
|
+
start: position,
|
|
72
|
+
end: position + candidate.length
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
async function extractRawCandidates(sources) {
|
|
76
|
+
const { Scanner } = await importOxide();
|
|
77
|
+
const scanner = new Scanner({
|
|
78
|
+
sources
|
|
79
|
+
});
|
|
80
|
+
return scanner.scan();
|
|
81
|
+
}
|
|
82
|
+
async function extractValidCandidates(options) {
|
|
83
|
+
const providedOptions = _nullishCoalesce(options, () => ( {}));
|
|
84
|
+
const defaultCwd = _nullishCoalesce(providedOptions.cwd, () => ( _process2.default.cwd()));
|
|
85
|
+
const base = _nullishCoalesce(providedOptions.base, () => ( defaultCwd));
|
|
86
|
+
const css = _nullishCoalesce(providedOptions.css, () => ( '@import "tailwindcss";'));
|
|
87
|
+
const sources = (_nullishCoalesce(providedOptions.sources, () => ( [
|
|
88
|
+
{
|
|
89
|
+
base: defaultCwd,
|
|
90
|
+
pattern: "**/*",
|
|
91
|
+
negated: false
|
|
92
|
+
}
|
|
93
|
+
]))).map((source) => ({
|
|
94
|
+
base: _nullishCoalesce(source.base, () => ( defaultCwd)),
|
|
95
|
+
pattern: source.pattern,
|
|
96
|
+
negated: source.negated
|
|
97
|
+
}));
|
|
98
|
+
const { __unstable__loadDesignSystem } = await importNode();
|
|
99
|
+
const designSystem = await __unstable__loadDesignSystem(css, { base });
|
|
100
|
+
const candidates = await extractRawCandidates(sources);
|
|
101
|
+
const validCandidates = candidates.filter(
|
|
102
|
+
(rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
|
|
103
|
+
);
|
|
104
|
+
return validCandidates;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/options/legacy.ts
|
|
108
|
+
function normalizeLegacyFeatures(patch) {
|
|
109
|
+
const apply = _optionalChain([patch, 'optionalAccess', _ => _.applyPatches]);
|
|
110
|
+
const extend = _optionalChain([apply, 'optionalAccess', _2 => _2.extendLengthUnits]);
|
|
111
|
+
let extendOption = false;
|
|
112
|
+
if (extend && typeof extend === "object") {
|
|
113
|
+
extendOption = {
|
|
114
|
+
...extend,
|
|
115
|
+
enabled: true
|
|
116
|
+
};
|
|
117
|
+
} else if (extend === true) {
|
|
118
|
+
extendOption = {
|
|
119
|
+
enabled: true,
|
|
120
|
+
units: ["rpx"],
|
|
121
|
+
overwrite: _optionalChain([patch, 'optionalAccess', _3 => _3.overwrite])
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _4 => _4.exportContext]), () => ( true)),
|
|
126
|
+
extendLengthUnits: extendOption
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function fromLegacyOptions(options) {
|
|
130
|
+
if (!options) {
|
|
131
|
+
return {};
|
|
132
|
+
}
|
|
133
|
+
const patch = options.patch;
|
|
134
|
+
const features = normalizeLegacyFeatures(patch);
|
|
135
|
+
const output = _optionalChain([patch, 'optionalAccess', _5 => _5.output]);
|
|
136
|
+
const tailwindConfig = _optionalChain([patch, 'optionalAccess', _6 => _6.tailwindcss]);
|
|
137
|
+
const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _7 => _7.version]);
|
|
138
|
+
const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _8 => _8.v2]);
|
|
139
|
+
const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _9 => _9.v3]);
|
|
140
|
+
const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _10 => _10.v4]);
|
|
141
|
+
const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _11 => _11.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _12 => _12.config])));
|
|
142
|
+
const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _13 => _13.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _14 => _14.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _15 => _15.cwd])));
|
|
143
|
+
return {
|
|
144
|
+
cwd: _optionalChain([patch, 'optionalAccess', _16 => _16.cwd]),
|
|
145
|
+
overwrite: _optionalChain([patch, 'optionalAccess', _17 => _17.overwrite]),
|
|
146
|
+
filter: _optionalChain([patch, 'optionalAccess', _18 => _18.filter]),
|
|
147
|
+
cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
|
|
148
|
+
...options.cache,
|
|
149
|
+
enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
|
|
150
|
+
} : void 0,
|
|
151
|
+
output: output ? {
|
|
152
|
+
file: output.filename,
|
|
153
|
+
pretty: output.loose ? 2 : false,
|
|
154
|
+
removeUniversalSelector: output.removeUniversalSelector
|
|
155
|
+
} : void 0,
|
|
156
|
+
tailwind: {
|
|
157
|
+
packageName: _optionalChain([patch, 'optionalAccess', _19 => _19.packageName]),
|
|
158
|
+
version: tailwindVersion,
|
|
159
|
+
resolve: _optionalChain([patch, 'optionalAccess', _20 => _20.resolve]),
|
|
160
|
+
config: tailwindConfigPath,
|
|
161
|
+
cwd: tailwindCwd,
|
|
162
|
+
v2: tailwindV2,
|
|
163
|
+
v3: tailwindV3,
|
|
164
|
+
v4: tailwindV4
|
|
165
|
+
},
|
|
166
|
+
features: {
|
|
167
|
+
exposeContext: features.exposeContext,
|
|
168
|
+
extendLengthUnits: features.extendLengthUnits
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function fromUnifiedConfig(registry) {
|
|
173
|
+
if (!registry) {
|
|
174
|
+
return {};
|
|
175
|
+
}
|
|
176
|
+
const tailwind = registry.tailwind;
|
|
177
|
+
const output = registry.output;
|
|
178
|
+
const pretty = (() => {
|
|
179
|
+
if (_optionalChain([output, 'optionalAccess', _21 => _21.pretty]) === void 0) {
|
|
180
|
+
return void 0;
|
|
181
|
+
}
|
|
182
|
+
if (typeof output.pretty === "boolean") {
|
|
183
|
+
return output.pretty ? 2 : false;
|
|
184
|
+
}
|
|
185
|
+
return output.pretty;
|
|
186
|
+
})();
|
|
187
|
+
return {
|
|
188
|
+
output: output ? {
|
|
189
|
+
file: output.file,
|
|
190
|
+
pretty,
|
|
191
|
+
removeUniversalSelector: output.stripUniversalSelector
|
|
192
|
+
} : void 0,
|
|
193
|
+
tailwind: tailwind ? {
|
|
194
|
+
version: tailwind.version,
|
|
195
|
+
packageName: tailwind.package,
|
|
196
|
+
resolve: tailwind.resolve,
|
|
197
|
+
config: tailwind.config,
|
|
198
|
+
cwd: tailwind.cwd,
|
|
199
|
+
v2: tailwind.legacy,
|
|
200
|
+
v3: tailwind.classic,
|
|
201
|
+
v4: tailwind.next
|
|
202
|
+
} : void 0
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/options/normalize.ts
|
|
207
|
+
|
|
208
|
+
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
209
|
+
|
|
210
|
+
// src/constants.ts
|
|
211
|
+
var pkgName = "tailwindcss-patch";
|
|
212
|
+
|
|
213
|
+
// src/options/normalize.ts
|
|
214
|
+
function toPrettyValue(value) {
|
|
215
|
+
if (typeof value === "number") {
|
|
216
|
+
return value > 0 ? value : false;
|
|
217
|
+
}
|
|
218
|
+
if (value === true) {
|
|
219
|
+
return 2;
|
|
220
|
+
}
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
function normalizeCacheOptions(cache, projectRoot) {
|
|
224
|
+
let enabled = false;
|
|
225
|
+
let cwd = projectRoot;
|
|
226
|
+
let dir = _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
227
|
+
let file = "class-cache.json";
|
|
228
|
+
let strategy = "merge";
|
|
229
|
+
if (typeof cache === "boolean") {
|
|
230
|
+
enabled = cache;
|
|
231
|
+
} else if (typeof cache === "object" && cache) {
|
|
232
|
+
enabled = _nullishCoalesce(cache.enabled, () => ( true));
|
|
233
|
+
cwd = _nullishCoalesce(cache.cwd, () => ( cwd));
|
|
234
|
+
dir = cache.dir ? _pathe2.default.resolve(cache.dir) : _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
235
|
+
file = _nullishCoalesce(cache.file, () => ( file));
|
|
236
|
+
strategy = _nullishCoalesce(cache.strategy, () => ( strategy));
|
|
237
|
+
}
|
|
238
|
+
const filename = _pathe2.default.resolve(dir, file);
|
|
239
|
+
return {
|
|
240
|
+
enabled,
|
|
241
|
+
cwd,
|
|
242
|
+
dir,
|
|
243
|
+
file,
|
|
244
|
+
path: filename,
|
|
245
|
+
strategy
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function normalizeOutputOptions(output) {
|
|
249
|
+
const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _22 => _22.enabled]), () => ( true));
|
|
250
|
+
const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _23 => _23.file]), () => ( ".tw-patch/tw-class-list.json"));
|
|
251
|
+
const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _24 => _24.format]), () => ( "json"));
|
|
252
|
+
const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _25 => _25.pretty]), () => ( true)));
|
|
253
|
+
const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _26 => _26.removeUniversalSelector]), () => ( true));
|
|
254
|
+
return {
|
|
255
|
+
enabled,
|
|
256
|
+
file,
|
|
257
|
+
format,
|
|
258
|
+
pretty,
|
|
259
|
+
removeUniversalSelector
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function normalizeExposeContextOptions(features) {
|
|
263
|
+
if (_optionalChain([features, 'optionalAccess', _27 => _27.exposeContext]) === false) {
|
|
264
|
+
return {
|
|
265
|
+
enabled: false,
|
|
266
|
+
refProperty: "contextRef"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
if (typeof _optionalChain([features, 'optionalAccess', _28 => _28.exposeContext]) === "object" && features.exposeContext) {
|
|
270
|
+
return {
|
|
271
|
+
enabled: true,
|
|
272
|
+
refProperty: _nullishCoalesce(features.exposeContext.refProperty, () => ( "contextRef"))
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
enabled: true,
|
|
277
|
+
refProperty: "contextRef"
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function normalizeExtendLengthUnitsOptions(features) {
|
|
281
|
+
const extend = _optionalChain([features, 'optionalAccess', _29 => _29.extendLengthUnits]);
|
|
282
|
+
if (extend === false || extend === void 0) {
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
if (extend.enabled === false) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
const base = {
|
|
289
|
+
units: ["rpx"],
|
|
290
|
+
overwrite: true
|
|
291
|
+
};
|
|
292
|
+
return {
|
|
293
|
+
...base,
|
|
294
|
+
...extend,
|
|
295
|
+
enabled: _nullishCoalesce(extend.enabled, () => ( true)),
|
|
296
|
+
units: _nullishCoalesce(extend.units, () => ( base.units)),
|
|
297
|
+
overwrite: _nullishCoalesce(extend.overwrite, () => ( base.overwrite))
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
301
|
+
const base = _optionalChain([v4, 'optionalAccess', _30 => _30.base]) ? _pathe2.default.resolve(v4.base) : fallbackBase;
|
|
302
|
+
const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _31 => _31.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
|
|
303
|
+
const sources = _optionalChain([v4, 'optionalAccess', _32 => _32.sources, 'optionalAccess', _33 => _33.length]) ? v4.sources : [
|
|
304
|
+
{
|
|
305
|
+
base,
|
|
306
|
+
pattern: "**/*",
|
|
307
|
+
negated: false
|
|
308
|
+
}
|
|
309
|
+
];
|
|
310
|
+
return {
|
|
311
|
+
base,
|
|
312
|
+
css: _optionalChain([v4, 'optionalAccess', _34 => _34.css]),
|
|
313
|
+
cssEntries,
|
|
314
|
+
sources
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
318
|
+
const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _35 => _35.packageName]), () => ( "tailwindcss"));
|
|
319
|
+
const versionHint = _optionalChain([tailwind, 'optionalAccess', _36 => _36.version]);
|
|
320
|
+
const resolve = _optionalChain([tailwind, 'optionalAccess', _37 => _37.resolve]);
|
|
321
|
+
const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _38 => _38.cwd]), () => ( projectRoot));
|
|
322
|
+
const config = _optionalChain([tailwind, 'optionalAccess', _39 => _39.config]);
|
|
323
|
+
const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _40 => _40.postcssPlugin]);
|
|
324
|
+
const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _41 => _41.v4]), cwd);
|
|
325
|
+
return {
|
|
326
|
+
packageName,
|
|
327
|
+
versionHint,
|
|
328
|
+
resolve,
|
|
329
|
+
cwd,
|
|
330
|
+
config,
|
|
331
|
+
postcssPlugin,
|
|
332
|
+
v2: _optionalChain([tailwind, 'optionalAccess', _42 => _42.v2]),
|
|
333
|
+
v3: _optionalChain([tailwind, 'optionalAccess', _43 => _43.v3]),
|
|
334
|
+
v4
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function normalizeOptions(options = {}) {
|
|
338
|
+
const projectRoot = options.cwd ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
|
|
339
|
+
const overwrite = _nullishCoalesce(options.overwrite, () => ( true));
|
|
340
|
+
const output = normalizeOutputOptions(options.output);
|
|
341
|
+
const cache = normalizeCacheOptions(options.cache, projectRoot);
|
|
342
|
+
const tailwind = normalizeTailwindOptions(options.tailwind, projectRoot);
|
|
343
|
+
const exposeContext = normalizeExposeContextOptions(options.features);
|
|
344
|
+
const extendLengthUnits = normalizeExtendLengthUnitsOptions(options.features);
|
|
345
|
+
const filter = (className) => {
|
|
346
|
+
if (output.removeUniversalSelector && className === "*") {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
if (typeof options.filter === "function") {
|
|
350
|
+
return options.filter(className) !== false;
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
projectRoot,
|
|
356
|
+
overwrite,
|
|
357
|
+
tailwind,
|
|
358
|
+
features: {
|
|
359
|
+
exposeContext,
|
|
360
|
+
extendLengthUnits
|
|
361
|
+
},
|
|
362
|
+
output,
|
|
363
|
+
cache,
|
|
364
|
+
filter
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// src/runtime/class-collector.ts
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
// src/utils.ts
|
|
374
|
+
function isObject(val) {
|
|
375
|
+
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
376
|
+
}
|
|
377
|
+
function spliceChangesIntoString(str, changes) {
|
|
378
|
+
if (!changes[0]) {
|
|
379
|
+
return str;
|
|
380
|
+
}
|
|
381
|
+
changes.sort((a, b) => {
|
|
382
|
+
return a.end - b.end || a.start - b.start;
|
|
383
|
+
});
|
|
384
|
+
let result = "";
|
|
385
|
+
let previous = changes[0];
|
|
386
|
+
result += str.slice(0, previous.start);
|
|
387
|
+
result += previous.replacement;
|
|
388
|
+
for (let i = 1; i < changes.length; ++i) {
|
|
389
|
+
const change = changes[i];
|
|
390
|
+
result += str.slice(previous.end, change.start);
|
|
391
|
+
result += change.replacement;
|
|
392
|
+
previous = change;
|
|
393
|
+
}
|
|
394
|
+
result += str.slice(previous.end);
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/runtime/class-collector.ts
|
|
399
|
+
function collectClassesFromContexts(contexts, filter) {
|
|
400
|
+
const set = /* @__PURE__ */ new Set();
|
|
401
|
+
for (const context of contexts) {
|
|
402
|
+
if (!isObject(context) || !context.classCache) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
for (const key of context.classCache.keys()) {
|
|
406
|
+
const className = key.toString();
|
|
407
|
+
if (filter(className)) {
|
|
408
|
+
set.add(className);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return set;
|
|
413
|
+
}
|
|
414
|
+
async function collectClassesFromTailwindV4(options) {
|
|
415
|
+
const set = /* @__PURE__ */ new Set();
|
|
416
|
+
const v4Options = options.tailwind.v4;
|
|
417
|
+
if (!v4Options) {
|
|
418
|
+
return set;
|
|
419
|
+
}
|
|
420
|
+
const sources = _optionalChain([v4Options, 'access', _44 => _44.sources, 'optionalAccess', _45 => _45.map, 'call', _46 => _46((source) => {
|
|
421
|
+
return {
|
|
422
|
+
base: _nullishCoalesce(_nullishCoalesce(source.base, () => ( v4Options.base)), () => ( _process2.default.cwd())),
|
|
423
|
+
pattern: source.pattern,
|
|
424
|
+
negated: source.negated
|
|
425
|
+
};
|
|
426
|
+
})]);
|
|
427
|
+
if (v4Options.cssEntries.length > 0) {
|
|
428
|
+
for (const entry of v4Options.cssEntries) {
|
|
429
|
+
const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
|
|
430
|
+
if (!await _fsextra2.default.pathExists(filePath)) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
const css = await _fsextra2.default.readFile(filePath, "utf8");
|
|
434
|
+
const candidates = await extractValidCandidates({
|
|
435
|
+
cwd: options.projectRoot,
|
|
436
|
+
base: v4Options.base,
|
|
437
|
+
css,
|
|
438
|
+
sources
|
|
439
|
+
});
|
|
440
|
+
for (const candidate of candidates) {
|
|
441
|
+
if (options.filter(candidate)) {
|
|
442
|
+
set.add(candidate);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
} else {
|
|
447
|
+
const candidates = await extractValidCandidates({
|
|
448
|
+
cwd: options.projectRoot,
|
|
449
|
+
base: v4Options.base,
|
|
450
|
+
css: v4Options.css,
|
|
451
|
+
sources
|
|
452
|
+
});
|
|
453
|
+
for (const candidate of candidates) {
|
|
454
|
+
if (options.filter(candidate)) {
|
|
455
|
+
set.add(candidate);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return set;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/runtime/context-registry.ts
|
|
463
|
+
var _module = require('module');
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
var require2 = _module.createRequire.call(void 0, importMetaUrl);
|
|
467
|
+
function resolveRuntimeEntry(packageInfo, majorVersion) {
|
|
468
|
+
const root = packageInfo.rootPath;
|
|
469
|
+
if (majorVersion === 2) {
|
|
470
|
+
const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
|
|
471
|
+
if (_fsextra2.default.existsSync(jitIndex)) {
|
|
472
|
+
return jitIndex;
|
|
473
|
+
}
|
|
474
|
+
} else if (majorVersion === 3) {
|
|
475
|
+
const plugin = _pathe2.default.join(root, "lib/plugin.js");
|
|
476
|
+
const index = _pathe2.default.join(root, "lib/index.js");
|
|
477
|
+
if (_fsextra2.default.existsSync(plugin)) {
|
|
478
|
+
return plugin;
|
|
479
|
+
}
|
|
480
|
+
if (_fsextra2.default.existsSync(index)) {
|
|
481
|
+
return index;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return void 0;
|
|
485
|
+
}
|
|
486
|
+
function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
|
|
487
|
+
if (majorVersion === 4) {
|
|
488
|
+
return [];
|
|
489
|
+
}
|
|
490
|
+
const entry = resolveRuntimeEntry(packageInfo, majorVersion);
|
|
491
|
+
if (!entry) {
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
const moduleExports = require2(entry);
|
|
495
|
+
if (!moduleExports) {
|
|
496
|
+
return [];
|
|
497
|
+
}
|
|
498
|
+
const ref = moduleExports[refProperty];
|
|
499
|
+
if (!ref) {
|
|
500
|
+
return [];
|
|
501
|
+
}
|
|
502
|
+
if (Array.isArray(ref)) {
|
|
503
|
+
return ref;
|
|
504
|
+
}
|
|
505
|
+
if (typeof ref === "object" && Array.isArray(ref.value)) {
|
|
506
|
+
return ref.value;
|
|
507
|
+
}
|
|
508
|
+
return [];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/runtime/process-tailwindcss.ts
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
515
|
+
var _tailwindcssconfig = require('tailwindcss-config');
|
|
516
|
+
var require3 = _module.createRequire.call(void 0, importMetaUrl);
|
|
517
|
+
async function resolveConfigPath(options) {
|
|
518
|
+
if (options.config && _pathe2.default.isAbsolute(options.config)) {
|
|
519
|
+
return options.config;
|
|
520
|
+
}
|
|
521
|
+
const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
|
|
522
|
+
if (!result) {
|
|
523
|
+
throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
|
|
524
|
+
}
|
|
525
|
+
return result.filepath;
|
|
526
|
+
}
|
|
527
|
+
async function runTailwindBuild(options) {
|
|
528
|
+
const configPath = await resolveConfigPath(options);
|
|
529
|
+
const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
|
|
530
|
+
if (options.majorVersion === 4) {
|
|
531
|
+
return _postcss2.default.call(void 0, [
|
|
532
|
+
require3(pluginName)({
|
|
533
|
+
config: configPath
|
|
534
|
+
})
|
|
535
|
+
]).process("@import 'tailwindcss';", {
|
|
536
|
+
from: void 0
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
return _postcss2.default.call(void 0, [
|
|
540
|
+
require3(pluginName)({
|
|
541
|
+
config: configPath
|
|
542
|
+
})
|
|
543
|
+
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
544
|
+
from: void 0
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// src/api/tailwindcss-patcher.ts
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
var _localpkg = require('local-pkg');
|
|
552
|
+
|
|
553
|
+
var _semver = require('semver');
|
|
554
|
+
|
|
555
|
+
// src/patching/operations/export-context/index.ts
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
// src/patching/operations/export-context/postcss-v2.ts
|
|
560
|
+
var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
|
|
561
|
+
|
|
562
|
+
// src/babel/index.ts
|
|
563
|
+
var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
|
|
564
|
+
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
565
|
+
var _parser = require('@babel/parser');
|
|
566
|
+
function _interopDefaultCompat(e) {
|
|
567
|
+
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
568
|
+
}
|
|
569
|
+
var generate = _interopDefaultCompat(_generator2.default);
|
|
570
|
+
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
571
|
+
|
|
572
|
+
// src/patching/operations/export-context/postcss-v2.ts
|
|
573
|
+
var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
574
|
+
function toIdentifierName(property) {
|
|
575
|
+
if (!property) {
|
|
576
|
+
return "contextRef";
|
|
577
|
+
}
|
|
578
|
+
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
579
|
+
if (/^\d/.test(sanitized)) {
|
|
580
|
+
return `_${sanitized}`;
|
|
581
|
+
}
|
|
582
|
+
return sanitized || "contextRef";
|
|
583
|
+
}
|
|
584
|
+
function createExportsMember(property) {
|
|
585
|
+
if (IDENTIFIER_RE.test(property)) {
|
|
586
|
+
return t.memberExpression(t.identifier("exports"), t.identifier(property));
|
|
587
|
+
}
|
|
588
|
+
return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
|
|
589
|
+
}
|
|
590
|
+
function transformProcessTailwindFeaturesReturnContextV2(content) {
|
|
591
|
+
const ast = _parser.parse.call(void 0, content, {
|
|
592
|
+
sourceType: "unambiguous"
|
|
593
|
+
});
|
|
594
|
+
let hasPatched = false;
|
|
595
|
+
traverse(ast, {
|
|
596
|
+
FunctionDeclaration(path8) {
|
|
597
|
+
const node = path8.node;
|
|
598
|
+
if (_optionalChain([node, 'access', _47 => _47.id, 'optionalAccess', _48 => _48.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const returnStatement3 = node.body.body[0];
|
|
602
|
+
if (!t.isFunctionExpression(returnStatement3.argument)) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
const body = returnStatement3.argument.body.body;
|
|
606
|
+
const lastStatement = body[body.length - 1];
|
|
607
|
+
const alreadyReturnsContext = Boolean(
|
|
608
|
+
t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
609
|
+
);
|
|
610
|
+
hasPatched = alreadyReturnsContext;
|
|
611
|
+
if (!alreadyReturnsContext) {
|
|
612
|
+
body.push(t.returnStatement(t.identifier("context")));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
return {
|
|
617
|
+
code: hasPatched ? content : generate(ast).code,
|
|
618
|
+
hasPatched
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
function transformPostcssPluginV2(content, options) {
|
|
622
|
+
const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
|
|
623
|
+
const exportMember = createExportsMember(options.refProperty);
|
|
624
|
+
const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
|
|
625
|
+
const ast = _parser.parse.call(void 0, content);
|
|
626
|
+
let hasPatched = false;
|
|
627
|
+
traverse(ast, {
|
|
628
|
+
Program(path8) {
|
|
629
|
+
const program = path8.node;
|
|
630
|
+
const index = program.body.findIndex((statement) => {
|
|
631
|
+
return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _49 => _49.id, 'optionalAccess', _50 => _50.name]) === "_default";
|
|
632
|
+
});
|
|
633
|
+
if (index === -1) {
|
|
634
|
+
return;
|
|
635
|
+
}
|
|
636
|
+
const previous = program.body[index - 1];
|
|
637
|
+
const beforePrevious = program.body[index - 2];
|
|
638
|
+
const alreadyHasVariable = Boolean(
|
|
639
|
+
previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
|
|
640
|
+
);
|
|
641
|
+
const alreadyAssignsExports = Boolean(
|
|
642
|
+
beforePrevious && t.isExpressionStatement(beforePrevious) && t.isAssignmentExpression(beforePrevious.expression) && t.isMemberExpression(beforePrevious.expression.left) && t.isIdentifier(beforePrevious.expression.right) && beforePrevious.expression.right.name === refIdentifier.name && generate(beforePrevious.expression.left).code === generate(exportMember).code
|
|
643
|
+
);
|
|
644
|
+
hasPatched = alreadyHasVariable && alreadyAssignsExports;
|
|
645
|
+
if (!alreadyHasVariable) {
|
|
646
|
+
program.body.splice(
|
|
647
|
+
index,
|
|
648
|
+
0,
|
|
649
|
+
t.variableDeclaration("var", [
|
|
650
|
+
t.variableDeclarator(
|
|
651
|
+
refIdentifier,
|
|
652
|
+
t.objectExpression([
|
|
653
|
+
t.objectProperty(t.identifier("value"), t.arrayExpression())
|
|
654
|
+
])
|
|
655
|
+
)
|
|
656
|
+
]),
|
|
657
|
+
t.expressionStatement(
|
|
658
|
+
t.assignmentExpression("=", exportMember, refIdentifier)
|
|
659
|
+
)
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
},
|
|
663
|
+
FunctionDeclaration(path8) {
|
|
664
|
+
if (hasPatched) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const fn = path8.node;
|
|
668
|
+
if (_optionalChain([fn, 'access', _51 => _51.id, 'optionalAccess', _52 => _52.name]) !== "_default") {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
const returnStatement3 = fn.body.body[0];
|
|
675
|
+
if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
const fnExpression = returnStatement3.argument.callee.object.elements[1];
|
|
679
|
+
if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const block = fnExpression.body;
|
|
683
|
+
const statements = block.body;
|
|
684
|
+
if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
|
|
685
|
+
hasPatched = true;
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
const lastStatement = statements[statements.length - 1];
|
|
689
|
+
if (lastStatement && t.isExpressionStatement(lastStatement)) {
|
|
690
|
+
statements[statements.length - 1] = t.expressionStatement(
|
|
691
|
+
t.callExpression(
|
|
692
|
+
t.memberExpression(valueMember, t.identifier("push")),
|
|
693
|
+
[lastStatement.expression]
|
|
694
|
+
)
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
const index = statements.findIndex((statement) => t.isIfStatement(statement));
|
|
698
|
+
if (index > -1) {
|
|
699
|
+
const ifStatement = statements[index];
|
|
700
|
+
if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
|
|
701
|
+
const forOf = ifStatement.consequent.body[1];
|
|
702
|
+
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
|
|
703
|
+
const nestedIf = forOf.body.body[0];
|
|
704
|
+
if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
|
|
705
|
+
nestedIf.consequent.body[0] = t.expressionStatement(
|
|
706
|
+
t.callExpression(
|
|
707
|
+
t.memberExpression(valueMember, t.identifier("push")),
|
|
708
|
+
[nestedIf.consequent.body[0].expression]
|
|
709
|
+
)
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
statements.unshift(
|
|
716
|
+
t.expressionStatement(
|
|
717
|
+
t.assignmentExpression(
|
|
718
|
+
"=",
|
|
719
|
+
t.memberExpression(valueMember, t.identifier("length")),
|
|
720
|
+
t.numericLiteral(0)
|
|
721
|
+
)
|
|
722
|
+
)
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
return {
|
|
727
|
+
code: hasPatched ? content : generate(ast).code,
|
|
728
|
+
hasPatched
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// src/patching/operations/export-context/postcss-v3.ts
|
|
733
|
+
|
|
734
|
+
var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
|
|
735
|
+
function toIdentifierName2(property) {
|
|
736
|
+
if (!property) {
|
|
737
|
+
return "contextRef";
|
|
738
|
+
}
|
|
739
|
+
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
740
|
+
if (/^\d/.test(sanitized)) {
|
|
741
|
+
return `_${sanitized}`;
|
|
742
|
+
}
|
|
743
|
+
return sanitized || "contextRef";
|
|
744
|
+
}
|
|
745
|
+
function createModuleExportsMember(property) {
|
|
746
|
+
const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
|
|
747
|
+
if (IDENTIFIER_RE2.test(property)) {
|
|
748
|
+
return t2.memberExpression(object, t2.identifier(property));
|
|
749
|
+
}
|
|
750
|
+
return t2.memberExpression(object, t2.stringLiteral(property), true);
|
|
751
|
+
}
|
|
752
|
+
function transformProcessTailwindFeaturesReturnContext(content) {
|
|
753
|
+
const ast = _parser.parse.call(void 0, content);
|
|
754
|
+
let hasPatched = false;
|
|
755
|
+
traverse(ast, {
|
|
756
|
+
FunctionDeclaration(path8) {
|
|
757
|
+
const node = path8.node;
|
|
758
|
+
if (_optionalChain([node, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
const [returnStatement3] = node.body.body;
|
|
762
|
+
if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
|
|
763
|
+
return;
|
|
764
|
+
}
|
|
765
|
+
const expression = returnStatement3.argument;
|
|
766
|
+
const body = expression.body.body;
|
|
767
|
+
const lastStatement = body[body.length - 1];
|
|
768
|
+
const alreadyReturnsContext = Boolean(
|
|
769
|
+
t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
770
|
+
);
|
|
771
|
+
hasPatched = alreadyReturnsContext;
|
|
772
|
+
if (!alreadyReturnsContext) {
|
|
773
|
+
body.push(t2.returnStatement(t2.identifier("context")));
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
});
|
|
777
|
+
return {
|
|
778
|
+
code: hasPatched ? content : generate(ast).code,
|
|
779
|
+
hasPatched
|
|
780
|
+
};
|
|
781
|
+
}
|
|
782
|
+
function transformPostcssPlugin(content, { refProperty }) {
|
|
783
|
+
const ast = _parser.parse.call(void 0, content);
|
|
784
|
+
const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
|
|
785
|
+
const moduleExportsMember = createModuleExportsMember(refProperty);
|
|
786
|
+
const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
|
|
787
|
+
let hasPatched = false;
|
|
788
|
+
traverse(ast, {
|
|
789
|
+
Program(path8) {
|
|
790
|
+
const program = path8.node;
|
|
791
|
+
const index = program.body.findIndex((statement) => {
|
|
792
|
+
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _55 => _55.expression, 'access', _56 => _56.right, 'access', _57 => _57.id, 'optionalAccess', _58 => _58.name]) === "tailwindcss";
|
|
793
|
+
});
|
|
794
|
+
if (index === -1) {
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
const previousStatement = program.body[index - 1];
|
|
798
|
+
const lastStatement = program.body[program.body.length - 1];
|
|
799
|
+
const alreadyHasVariable = Boolean(
|
|
800
|
+
previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
|
|
801
|
+
);
|
|
802
|
+
const alreadyAssignsModuleExports = Boolean(
|
|
803
|
+
t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isMemberExpression(lastStatement.expression.left) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === refIdentifier.name && generate(lastStatement.expression.left).code === generate(moduleExportsMember).code
|
|
804
|
+
);
|
|
805
|
+
hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
|
|
806
|
+
if (!alreadyHasVariable) {
|
|
807
|
+
program.body.splice(
|
|
808
|
+
index,
|
|
809
|
+
0,
|
|
810
|
+
t2.variableDeclaration("const", [
|
|
811
|
+
t2.variableDeclarator(
|
|
812
|
+
refIdentifier,
|
|
813
|
+
t2.objectExpression([
|
|
814
|
+
t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
|
|
815
|
+
])
|
|
816
|
+
)
|
|
817
|
+
])
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
if (!alreadyAssignsModuleExports) {
|
|
821
|
+
program.body.push(
|
|
822
|
+
t2.expressionStatement(
|
|
823
|
+
t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
|
|
824
|
+
)
|
|
825
|
+
);
|
|
826
|
+
}
|
|
827
|
+
},
|
|
828
|
+
FunctionExpression(path8) {
|
|
829
|
+
if (hasPatched) {
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const fn = path8.node;
|
|
833
|
+
if (_optionalChain([fn, 'access', _59 => _59.id, 'optionalAccess', _60 => _60.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
const [returnStatement3] = fn.body.body;
|
|
837
|
+
if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const properties = returnStatement3.argument.properties;
|
|
841
|
+
if (properties.length !== 2) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
const pluginsProperty = properties.find(
|
|
845
|
+
(prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
|
|
846
|
+
);
|
|
847
|
+
if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
const pluginsArray = pluginsProperty.value.callee.object.elements;
|
|
851
|
+
const targetPlugin = pluginsArray[1];
|
|
852
|
+
if (!targetPlugin || !t2.isFunctionExpression(targetPlugin)) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
const block = targetPlugin.body;
|
|
856
|
+
const statements = block.body;
|
|
857
|
+
const last = statements[statements.length - 1];
|
|
858
|
+
if (last && t2.isExpressionStatement(last)) {
|
|
859
|
+
statements[statements.length - 1] = t2.expressionStatement(
|
|
860
|
+
t2.callExpression(
|
|
861
|
+
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
862
|
+
[last.expression]
|
|
863
|
+
)
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
const index = statements.findIndex((s) => t2.isIfStatement(s));
|
|
867
|
+
if (index > -1) {
|
|
868
|
+
const ifStatement = statements[index];
|
|
869
|
+
if (t2.isBlockStatement(ifStatement.consequent)) {
|
|
870
|
+
const [, second] = ifStatement.consequent.body;
|
|
871
|
+
if (second && t2.isForOfStatement(second) && t2.isBlockStatement(second.body)) {
|
|
872
|
+
const bodyStatement = second.body.body[0];
|
|
873
|
+
if (bodyStatement && t2.isIfStatement(bodyStatement) && t2.isBlockStatement(bodyStatement.consequent) && bodyStatement.consequent.body.length === 1 && t2.isExpressionStatement(bodyStatement.consequent.body[0])) {
|
|
874
|
+
bodyStatement.consequent.body[0] = t2.expressionStatement(
|
|
875
|
+
t2.callExpression(
|
|
876
|
+
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
877
|
+
[bodyStatement.consequent.body[0].expression]
|
|
878
|
+
)
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
statements.unshift(
|
|
885
|
+
t2.expressionStatement(
|
|
886
|
+
t2.assignmentExpression(
|
|
887
|
+
"=",
|
|
888
|
+
t2.memberExpression(valueMember, t2.identifier("length")),
|
|
889
|
+
t2.numericLiteral(0)
|
|
890
|
+
)
|
|
891
|
+
)
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
});
|
|
895
|
+
return {
|
|
896
|
+
code: hasPatched ? content : generate(ast).code,
|
|
897
|
+
hasPatched
|
|
898
|
+
};
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// src/patching/operations/export-context/index.ts
|
|
902
|
+
function writeFileIfRequired(filePath, code, overwrite, successMessage) {
|
|
903
|
+
if (!overwrite) {
|
|
904
|
+
return;
|
|
905
|
+
}
|
|
906
|
+
_fsextra2.default.writeFileSync(filePath, code, {
|
|
907
|
+
encoding: "utf8"
|
|
908
|
+
});
|
|
909
|
+
logger_default.success(successMessage);
|
|
910
|
+
}
|
|
911
|
+
function applyExposeContextPatch(params) {
|
|
912
|
+
const { rootDir, refProperty, overwrite, majorVersion } = params;
|
|
913
|
+
const result = {
|
|
914
|
+
applied: false,
|
|
915
|
+
files: {}
|
|
916
|
+
};
|
|
917
|
+
if (majorVersion === 3) {
|
|
918
|
+
const processFileRelative = "lib/processTailwindFeatures.js";
|
|
919
|
+
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
920
|
+
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
921
|
+
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
922
|
+
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContext(content);
|
|
923
|
+
result.files[processFileRelative] = code;
|
|
924
|
+
if (!hasPatched) {
|
|
925
|
+
writeFileIfRequired(
|
|
926
|
+
processFilePath,
|
|
927
|
+
code,
|
|
928
|
+
overwrite,
|
|
929
|
+
"Patched Tailwind CSS processTailwindFeatures to expose runtime context."
|
|
930
|
+
);
|
|
931
|
+
result.applied = true;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
|
|
935
|
+
const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(rootDir, candidate)));
|
|
936
|
+
if (pluginRelative) {
|
|
937
|
+
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
938
|
+
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
939
|
+
const { code, hasPatched } = transformPostcssPlugin(content, { refProperty });
|
|
940
|
+
result.files[pluginRelative] = code;
|
|
941
|
+
if (!hasPatched) {
|
|
942
|
+
writeFileIfRequired(
|
|
943
|
+
pluginPath,
|
|
944
|
+
code,
|
|
945
|
+
overwrite,
|
|
946
|
+
"Patched Tailwind CSS plugin entry to collect runtime contexts."
|
|
947
|
+
);
|
|
948
|
+
result.applied = true;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
} else if (majorVersion === 2) {
|
|
952
|
+
const processFileRelative = "lib/jit/processTailwindFeatures.js";
|
|
953
|
+
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
954
|
+
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
955
|
+
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
956
|
+
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContextV2(content);
|
|
957
|
+
result.files[processFileRelative] = code;
|
|
958
|
+
if (!hasPatched) {
|
|
959
|
+
writeFileIfRequired(
|
|
960
|
+
processFilePath,
|
|
961
|
+
code,
|
|
962
|
+
overwrite,
|
|
963
|
+
"Patched Tailwind CSS JIT processTailwindFeatures to expose runtime context."
|
|
964
|
+
);
|
|
965
|
+
result.applied = true;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
const pluginRelative = "lib/jit/index.js";
|
|
969
|
+
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
970
|
+
if (_fsextra2.default.existsSync(pluginPath)) {
|
|
971
|
+
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
972
|
+
const { code, hasPatched } = transformPostcssPluginV2(content, { refProperty });
|
|
973
|
+
result.files[pluginRelative] = code;
|
|
974
|
+
if (!hasPatched) {
|
|
975
|
+
writeFileIfRequired(
|
|
976
|
+
pluginPath,
|
|
977
|
+
code,
|
|
978
|
+
overwrite,
|
|
979
|
+
"Patched Tailwind CSS JIT entry to collect runtime contexts."
|
|
980
|
+
);
|
|
981
|
+
result.applied = true;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
return result;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// src/patching/operations/extend-length-units.ts
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
function updateLengthUnitsArray(content, options) {
|
|
993
|
+
const { variableName = "lengthUnits", units } = options;
|
|
994
|
+
const ast = _parser.parse.call(void 0, content);
|
|
995
|
+
let arrayRef;
|
|
996
|
+
let changed = false;
|
|
997
|
+
traverse(ast, {
|
|
998
|
+
Identifier(path8) {
|
|
999
|
+
if (path8.node.name === variableName && t3.isVariableDeclarator(path8.parent) && t3.isArrayExpression(path8.parent.init)) {
|
|
1000
|
+
arrayRef = path8.parent.init;
|
|
1001
|
+
const existing = new Set(
|
|
1002
|
+
path8.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
1003
|
+
);
|
|
1004
|
+
for (const unit of units) {
|
|
1005
|
+
if (!existing.has(unit)) {
|
|
1006
|
+
path8.parent.init.elements = path8.parent.init.elements.map((element) => {
|
|
1007
|
+
if (t3.isStringLiteral(element)) {
|
|
1008
|
+
return t3.stringLiteral(element.value);
|
|
1009
|
+
}
|
|
1010
|
+
return element;
|
|
1011
|
+
});
|
|
1012
|
+
path8.parent.init.elements.push(t3.stringLiteral(unit));
|
|
1013
|
+
changed = true;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
return {
|
|
1020
|
+
arrayRef,
|
|
1021
|
+
changed
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
function applyExtendLengthUnitsPatchV3(rootDir, options) {
|
|
1025
|
+
if (!options.enabled) {
|
|
1026
|
+
return { changed: false, code: void 0 };
|
|
1027
|
+
}
|
|
1028
|
+
const opts = {
|
|
1029
|
+
...options,
|
|
1030
|
+
lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
|
|
1031
|
+
variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
|
|
1032
|
+
};
|
|
1033
|
+
const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
|
|
1034
|
+
const exists = _fsextra2.default.existsSync(dataTypesFilePath);
|
|
1035
|
+
if (!exists) {
|
|
1036
|
+
return { changed: false, code: void 0 };
|
|
1037
|
+
}
|
|
1038
|
+
const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
|
|
1039
|
+
const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
|
|
1040
|
+
if (!arrayRef || !changed) {
|
|
1041
|
+
return { changed: false, code: void 0 };
|
|
1042
|
+
}
|
|
1043
|
+
const { code } = generate(arrayRef, {
|
|
1044
|
+
jsescOption: { quotes: "single" }
|
|
1045
|
+
});
|
|
1046
|
+
if (arrayRef.start != null && arrayRef.end != null) {
|
|
1047
|
+
const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
|
|
1048
|
+
if (opts.overwrite) {
|
|
1049
|
+
const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
|
|
1050
|
+
_fsextra2.default.writeFileSync(target, nextCode, "utf8");
|
|
1051
|
+
logger_default.success("Patched Tailwind CSS length unit list (v3).");
|
|
1052
|
+
}
|
|
1053
|
+
return {
|
|
1054
|
+
changed: true,
|
|
1055
|
+
code: nextCode
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
return {
|
|
1059
|
+
changed: false,
|
|
1060
|
+
code: void 0
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
function applyExtendLengthUnitsPatchV4(rootDir, options) {
|
|
1064
|
+
if (!options.enabled) {
|
|
1065
|
+
return { files: [], changed: false };
|
|
1066
|
+
}
|
|
1067
|
+
const opts = { ...options };
|
|
1068
|
+
const distDir = _pathe2.default.resolve(rootDir, "dist");
|
|
1069
|
+
if (!_fsextra2.default.existsSync(distDir)) {
|
|
1070
|
+
return { files: [], changed: false };
|
|
1071
|
+
}
|
|
1072
|
+
const entries = _fsextra2.default.readdirSync(distDir);
|
|
1073
|
+
const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
|
|
1074
|
+
const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
|
|
1075
|
+
const candidates = chunkNames.map((chunkName) => {
|
|
1076
|
+
const file = _pathe2.default.join(distDir, chunkName);
|
|
1077
|
+
const code = _fsextra2.default.readFileSync(file, "utf8");
|
|
1078
|
+
const match = pattern.exec(code);
|
|
1079
|
+
if (!match) {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1082
|
+
return {
|
|
1083
|
+
file,
|
|
1084
|
+
code,
|
|
1085
|
+
match,
|
|
1086
|
+
hasPatched: false
|
|
1087
|
+
};
|
|
1088
|
+
}).filter((candidate) => candidate !== null);
|
|
1089
|
+
for (const item of candidates) {
|
|
1090
|
+
const { code, file, match } = item;
|
|
1091
|
+
const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
|
|
1092
|
+
traverse(ast, {
|
|
1093
|
+
ArrayExpression(path8) {
|
|
1094
|
+
for (const unit of opts.units) {
|
|
1095
|
+
if (path8.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
|
|
1096
|
+
item.hasPatched = true;
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1099
|
+
path8.node.elements.push(t3.stringLiteral(unit));
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
});
|
|
1103
|
+
if (item.hasPatched) {
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
const { code: replacement } = generate(ast, { minified: true });
|
|
1107
|
+
const start = _nullishCoalesce(match.index, () => ( 0));
|
|
1108
|
+
const end = start + match[0].length;
|
|
1109
|
+
item.code = spliceChangesIntoString(code, [
|
|
1110
|
+
{
|
|
1111
|
+
start,
|
|
1112
|
+
end,
|
|
1113
|
+
replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
|
|
1114
|
+
}
|
|
1115
|
+
]);
|
|
1116
|
+
if (opts.overwrite) {
|
|
1117
|
+
_fsextra2.default.writeFileSync(file, item.code, "utf8");
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
if (candidates.some((file) => !file.hasPatched)) {
|
|
1121
|
+
logger_default.success("Patched Tailwind CSS length unit list (v4).");
|
|
1122
|
+
}
|
|
1123
|
+
return {
|
|
1124
|
+
changed: candidates.some((file) => !file.hasPatched),
|
|
1125
|
+
files: candidates
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// src/patching/patch-runner.ts
|
|
1130
|
+
function applyTailwindPatches(context) {
|
|
1131
|
+
const { packageInfo, options, majorVersion } = context;
|
|
1132
|
+
const results = {};
|
|
1133
|
+
if (options.features.exposeContext.enabled && (majorVersion === 2 || majorVersion === 3)) {
|
|
1134
|
+
results.exposeContext = applyExposeContextPatch({
|
|
1135
|
+
rootDir: packageInfo.rootPath,
|
|
1136
|
+
refProperty: options.features.exposeContext.refProperty,
|
|
1137
|
+
overwrite: options.overwrite,
|
|
1138
|
+
majorVersion
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
if (_optionalChain([options, 'access', _61 => _61.features, 'access', _62 => _62.extendLengthUnits, 'optionalAccess', _63 => _63.enabled])) {
|
|
1142
|
+
if (majorVersion === 3) {
|
|
1143
|
+
results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
|
|
1144
|
+
packageInfo.rootPath,
|
|
1145
|
+
options.features.extendLengthUnits
|
|
1146
|
+
);
|
|
1147
|
+
} else if (majorVersion === 4) {
|
|
1148
|
+
results.extendLengthUnits = applyExtendLengthUnitsPatchV4(
|
|
1149
|
+
packageInfo.rootPath,
|
|
1150
|
+
options.features.extendLengthUnits
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return results;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// src/api/tailwindcss-patcher.ts
|
|
1158
|
+
function resolveMajorVersion(version, hint) {
|
|
1159
|
+
if (hint && [2, 3, 4].includes(hint)) {
|
|
1160
|
+
return hint;
|
|
1161
|
+
}
|
|
1162
|
+
if (version) {
|
|
1163
|
+
const coerced = _semver.coerce.call(void 0, version);
|
|
1164
|
+
if (coerced) {
|
|
1165
|
+
const major = coerced.major;
|
|
1166
|
+
if (major === 2 || major === 3 || major === 4) {
|
|
1167
|
+
return major;
|
|
1168
|
+
}
|
|
1169
|
+
if (major >= 4) {
|
|
1170
|
+
return 4;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
return 3;
|
|
1175
|
+
}
|
|
1176
|
+
function resolveTailwindExecutionOptions(normalized, majorVersion) {
|
|
1177
|
+
const base = normalized.tailwind;
|
|
1178
|
+
if (majorVersion === 2 && base.v2) {
|
|
1179
|
+
return {
|
|
1180
|
+
cwd: _nullishCoalesce(_nullishCoalesce(base.v2.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
1181
|
+
config: _nullishCoalesce(base.v2.config, () => ( base.config)),
|
|
1182
|
+
postcssPlugin: _nullishCoalesce(base.v2.postcssPlugin, () => ( base.postcssPlugin))
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
if (majorVersion === 3 && base.v3) {
|
|
1186
|
+
return {
|
|
1187
|
+
cwd: _nullishCoalesce(_nullishCoalesce(base.v3.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
1188
|
+
config: _nullishCoalesce(base.v3.config, () => ( base.config)),
|
|
1189
|
+
postcssPlugin: _nullishCoalesce(base.v3.postcssPlugin, () => ( base.postcssPlugin))
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
return {
|
|
1193
|
+
cwd: _nullishCoalesce(base.cwd, () => ( normalized.projectRoot)),
|
|
1194
|
+
config: base.config,
|
|
1195
|
+
postcssPlugin: base.postcssPlugin
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
var TailwindcssPatcher = (_class = class {
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
constructor(options = {}) {;_class.prototype.__init.call(this);
|
|
1204
|
+
const resolvedOptions = options && typeof options === "object" && "patch" in options ? fromLegacyOptions(options) : options;
|
|
1205
|
+
this.options = normalizeOptions(resolvedOptions);
|
|
1206
|
+
const packageInfo = _localpkg.getPackageInfoSync.call(void 0,
|
|
1207
|
+
this.options.tailwind.packageName,
|
|
1208
|
+
this.options.tailwind.resolve
|
|
1209
|
+
);
|
|
1210
|
+
if (!packageInfo) {
|
|
1211
|
+
throw new Error(`Unable to locate Tailwind CSS package "${this.options.tailwind.packageName}".`);
|
|
1212
|
+
}
|
|
1213
|
+
this.packageInfo = packageInfo;
|
|
1214
|
+
this.majorVersion = resolveMajorVersion(
|
|
1215
|
+
this.packageInfo.version,
|
|
1216
|
+
this.options.tailwind.versionHint
|
|
1217
|
+
);
|
|
1218
|
+
this.cacheStore = new CacheStore(this.options.cache);
|
|
1219
|
+
}
|
|
1220
|
+
async patch() {
|
|
1221
|
+
return applyTailwindPatches({
|
|
1222
|
+
packageInfo: this.packageInfo,
|
|
1223
|
+
options: this.options,
|
|
1224
|
+
majorVersion: this.majorVersion
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
getContexts() {
|
|
1228
|
+
return loadRuntimeContexts(
|
|
1229
|
+
this.packageInfo,
|
|
1230
|
+
this.majorVersion,
|
|
1231
|
+
this.options.features.exposeContext.refProperty
|
|
1232
|
+
);
|
|
1233
|
+
}
|
|
1234
|
+
async runTailwindBuildIfNeeded() {
|
|
1235
|
+
if (this.majorVersion === 2 || this.majorVersion === 3) {
|
|
1236
|
+
const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
|
|
1237
|
+
await runTailwindBuild({
|
|
1238
|
+
cwd: executionOptions.cwd,
|
|
1239
|
+
config: executionOptions.config,
|
|
1240
|
+
majorVersion: this.majorVersion,
|
|
1241
|
+
postcssPlugin: executionOptions.postcssPlugin
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
async collectClassSet() {
|
|
1246
|
+
if (this.majorVersion === 4) {
|
|
1247
|
+
return collectClassesFromTailwindV4(this.options);
|
|
1248
|
+
}
|
|
1249
|
+
const contexts = this.getContexts();
|
|
1250
|
+
return collectClassesFromContexts(contexts, this.options.filter);
|
|
1251
|
+
}
|
|
1252
|
+
async mergeWithCache(set) {
|
|
1253
|
+
if (!this.options.cache.enabled) {
|
|
1254
|
+
return set;
|
|
1255
|
+
}
|
|
1256
|
+
const existing = await this.cacheStore.read();
|
|
1257
|
+
if (this.options.cache.strategy === "merge") {
|
|
1258
|
+
for (const value of existing) {
|
|
1259
|
+
set.add(value);
|
|
1260
|
+
}
|
|
1261
|
+
await this.cacheStore.write(set);
|
|
1262
|
+
} else {
|
|
1263
|
+
if (set.size > 0) {
|
|
1264
|
+
await this.cacheStore.write(set);
|
|
1265
|
+
} else {
|
|
1266
|
+
return existing;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
return set;
|
|
1270
|
+
}
|
|
1271
|
+
async getClassSet() {
|
|
1272
|
+
await this.runTailwindBuildIfNeeded();
|
|
1273
|
+
const set = await this.collectClassSet();
|
|
1274
|
+
return this.mergeWithCache(set);
|
|
1275
|
+
}
|
|
1276
|
+
async extract(options) {
|
|
1277
|
+
const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _64 => _64.write]), () => ( this.options.output.enabled));
|
|
1278
|
+
const classSet = await this.getClassSet();
|
|
1279
|
+
const classList = Array.from(classSet);
|
|
1280
|
+
const result = {
|
|
1281
|
+
classList,
|
|
1282
|
+
classSet
|
|
1283
|
+
};
|
|
1284
|
+
if (!shouldWrite || !this.options.output.file) {
|
|
1285
|
+
return result;
|
|
1286
|
+
}
|
|
1287
|
+
const target = _pathe2.default.resolve(this.options.output.file);
|
|
1288
|
+
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
1289
|
+
if (this.options.output.format === "json") {
|
|
1290
|
+
const spaces = typeof this.options.output.pretty === "number" ? this.options.output.pretty : void 0;
|
|
1291
|
+
await _fsextra2.default.writeJSON(target, classList, { spaces });
|
|
1292
|
+
} else {
|
|
1293
|
+
await _fsextra2.default.writeFile(target, `${classList.join("\n")}
|
|
1294
|
+
`, "utf8");
|
|
1295
|
+
}
|
|
1296
|
+
logger_default.success(`Tailwind CSS class list saved to ${target.replace(_process2.default.cwd(), ".")}`);
|
|
1297
|
+
return {
|
|
1298
|
+
...result,
|
|
1299
|
+
filename: target
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
// Backwards compatibility helper used by tests and API consumers.
|
|
1303
|
+
__init() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
|
|
1304
|
+
}, _class);
|
|
1305
|
+
|
|
1306
|
+
|
|
1307
|
+
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
|
|
1311
|
+
|
|
1312
|
+
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.fromLegacyOptions = fromLegacyOptions; exports.fromUnifiedConfig = fromUnifiedConfig; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher;
|