tailwindcss-patch 8.6.1 → 8.7.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 +193 -11
- package/dist/chunk-2YHCFHVA.mjs +4739 -0
- package/dist/chunk-ATKR3J24.js +4743 -0
- package/dist/cli.js +20 -5
- package/dist/cli.mjs +20 -5
- package/dist/index.d.mts +282 -23
- package/dist/index.d.ts +282 -23
- package/dist/index.js +16 -2
- package/dist/index.mjs +15 -1
- package/package.json +14 -10
- package/schema/migration-report.schema.json +144 -0
- package/schema/restore-result.schema.json +68 -0
- package/schema/validate-result.schema.json +122 -0
- package/dist/chunk-DRPYVUDA.js +0 -2462
- package/dist/chunk-LOJHMBK5.mjs +0 -2458
package/dist/chunk-DRPYVUDA.js
DELETED
|
@@ -1,2462 +0,0 @@
|
|
|
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; var _class2;// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
|
|
2
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? 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 _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
12
|
-
var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
|
|
13
|
-
function isErrnoException(error) {
|
|
14
|
-
return error instanceof Error && typeof error.code === "string";
|
|
15
|
-
}
|
|
16
|
-
function isAccessDenied(error) {
|
|
17
|
-
return isErrnoException(error) && Boolean(error.code && ["EPERM", "EBUSY", "EACCES"].includes(error.code));
|
|
18
|
-
}
|
|
19
|
-
var CacheStore = (_class = class {
|
|
20
|
-
constructor(options) {;_class.prototype.__init.call(this);
|
|
21
|
-
this.options = options;
|
|
22
|
-
this.driver = _nullishCoalesce(options.driver, () => ( "file"));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
__init() {this.memoryCache = null}
|
|
26
|
-
async ensureDir() {
|
|
27
|
-
await _fsextra2.default.ensureDir(this.options.dir);
|
|
28
|
-
}
|
|
29
|
-
ensureDirSync() {
|
|
30
|
-
_fsextra2.default.ensureDirSync(this.options.dir);
|
|
31
|
-
}
|
|
32
|
-
createTempPath() {
|
|
33
|
-
const uniqueSuffix = `${_process2.default.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
34
|
-
return `${this.options.path}.${uniqueSuffix}.tmp`;
|
|
35
|
-
}
|
|
36
|
-
async replaceCacheFile(tempPath) {
|
|
37
|
-
try {
|
|
38
|
-
await _fsextra2.default.rename(tempPath, this.options.path);
|
|
39
|
-
return true;
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
|
|
42
|
-
try {
|
|
43
|
-
await _fsextra2.default.remove(this.options.path);
|
|
44
|
-
} catch (removeError) {
|
|
45
|
-
if (isAccessDenied(removeError)) {
|
|
46
|
-
logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
|
|
50
|
-
throw removeError;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
await _fsextra2.default.rename(tempPath, this.options.path);
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
replaceCacheFileSync(tempPath) {
|
|
60
|
-
try {
|
|
61
|
-
_fsextra2.default.renameSync(tempPath, this.options.path);
|
|
62
|
-
return true;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
|
|
65
|
-
try {
|
|
66
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
67
|
-
} catch (removeError) {
|
|
68
|
-
if (isAccessDenied(removeError)) {
|
|
69
|
-
logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
|
|
73
|
-
throw removeError;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
_fsextra2.default.renameSync(tempPath, this.options.path);
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async cleanupTempFile(tempPath) {
|
|
83
|
-
try {
|
|
84
|
-
await _fsextra2.default.remove(tempPath);
|
|
85
|
-
} catch (e2) {
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
cleanupTempFileSync(tempPath) {
|
|
89
|
-
try {
|
|
90
|
-
_fsextra2.default.removeSync(tempPath);
|
|
91
|
-
} catch (e3) {
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
async write(data) {
|
|
95
|
-
if (!this.options.enabled) {
|
|
96
|
-
return void 0;
|
|
97
|
-
}
|
|
98
|
-
if (this.driver === "noop") {
|
|
99
|
-
return void 0;
|
|
100
|
-
}
|
|
101
|
-
if (this.driver === "memory") {
|
|
102
|
-
this.memoryCache = new Set(data);
|
|
103
|
-
return "memory";
|
|
104
|
-
}
|
|
105
|
-
const tempPath = this.createTempPath();
|
|
106
|
-
try {
|
|
107
|
-
await this.ensureDir();
|
|
108
|
-
await _fsextra2.default.writeJSON(tempPath, Array.from(data));
|
|
109
|
-
const replaced = await this.replaceCacheFile(tempPath);
|
|
110
|
-
if (replaced) {
|
|
111
|
-
return this.options.path;
|
|
112
|
-
}
|
|
113
|
-
await this.cleanupTempFile(tempPath);
|
|
114
|
-
return void 0;
|
|
115
|
-
} catch (error) {
|
|
116
|
-
await this.cleanupTempFile(tempPath);
|
|
117
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
118
|
-
return void 0;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
writeSync(data) {
|
|
122
|
-
if (!this.options.enabled) {
|
|
123
|
-
return void 0;
|
|
124
|
-
}
|
|
125
|
-
if (this.driver === "noop") {
|
|
126
|
-
return void 0;
|
|
127
|
-
}
|
|
128
|
-
if (this.driver === "memory") {
|
|
129
|
-
this.memoryCache = new Set(data);
|
|
130
|
-
return "memory";
|
|
131
|
-
}
|
|
132
|
-
const tempPath = this.createTempPath();
|
|
133
|
-
try {
|
|
134
|
-
this.ensureDirSync();
|
|
135
|
-
_fsextra2.default.writeJSONSync(tempPath, Array.from(data));
|
|
136
|
-
const replaced = this.replaceCacheFileSync(tempPath);
|
|
137
|
-
if (replaced) {
|
|
138
|
-
return this.options.path;
|
|
139
|
-
}
|
|
140
|
-
this.cleanupTempFileSync(tempPath);
|
|
141
|
-
return void 0;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
this.cleanupTempFileSync(tempPath);
|
|
144
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
145
|
-
return void 0;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
async read() {
|
|
149
|
-
if (!this.options.enabled) {
|
|
150
|
-
return /* @__PURE__ */ new Set();
|
|
151
|
-
}
|
|
152
|
-
if (this.driver === "noop") {
|
|
153
|
-
return /* @__PURE__ */ new Set();
|
|
154
|
-
}
|
|
155
|
-
if (this.driver === "memory") {
|
|
156
|
-
return new Set(_nullishCoalesce(this.memoryCache, () => ( [])));
|
|
157
|
-
}
|
|
158
|
-
try {
|
|
159
|
-
const exists = await _fsextra2.default.pathExists(this.options.path);
|
|
160
|
-
if (!exists) {
|
|
161
|
-
return /* @__PURE__ */ new Set();
|
|
162
|
-
}
|
|
163
|
-
const data = await _fsextra2.default.readJSON(this.options.path);
|
|
164
|
-
if (Array.isArray(data)) {
|
|
165
|
-
return new Set(data.filter((item) => typeof item === "string"));
|
|
166
|
-
}
|
|
167
|
-
} catch (error) {
|
|
168
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
169
|
-
return /* @__PURE__ */ new Set();
|
|
170
|
-
}
|
|
171
|
-
logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
|
|
172
|
-
try {
|
|
173
|
-
await _fsextra2.default.remove(this.options.path);
|
|
174
|
-
} catch (cleanupError) {
|
|
175
|
-
logger_default.error("Failed to clean up invalid cache file", cleanupError);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return /* @__PURE__ */ new Set();
|
|
179
|
-
}
|
|
180
|
-
readSync() {
|
|
181
|
-
if (!this.options.enabled) {
|
|
182
|
-
return /* @__PURE__ */ new Set();
|
|
183
|
-
}
|
|
184
|
-
if (this.driver === "noop") {
|
|
185
|
-
return /* @__PURE__ */ new Set();
|
|
186
|
-
}
|
|
187
|
-
if (this.driver === "memory") {
|
|
188
|
-
return new Set(_nullishCoalesce(this.memoryCache, () => ( [])));
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
const exists = _fsextra2.default.pathExistsSync(this.options.path);
|
|
192
|
-
if (!exists) {
|
|
193
|
-
return /* @__PURE__ */ new Set();
|
|
194
|
-
}
|
|
195
|
-
const data = _fsextra2.default.readJSONSync(this.options.path);
|
|
196
|
-
if (Array.isArray(data)) {
|
|
197
|
-
return new Set(data.filter((item) => typeof item === "string"));
|
|
198
|
-
}
|
|
199
|
-
} catch (error) {
|
|
200
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
201
|
-
return /* @__PURE__ */ new Set();
|
|
202
|
-
}
|
|
203
|
-
logger_default.warn("Unable to read Tailwind class cache, removing invalid file.", error);
|
|
204
|
-
try {
|
|
205
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
206
|
-
} catch (cleanupError) {
|
|
207
|
-
logger_default.error("Failed to clean up invalid cache file", cleanupError);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return /* @__PURE__ */ new Set();
|
|
211
|
-
}
|
|
212
|
-
}, _class);
|
|
213
|
-
|
|
214
|
-
// src/extraction/candidate-extractor.ts
|
|
215
|
-
var _fs = require('fs');
|
|
216
|
-
|
|
217
|
-
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
218
|
-
async function importNode() {
|
|
219
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
|
|
220
|
-
}
|
|
221
|
-
async function importOxide() {
|
|
222
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
|
|
223
|
-
}
|
|
224
|
-
async function loadDesignSystem(css, bases) {
|
|
225
|
-
const uniqueBases = Array.from(new Set(bases.filter(Boolean)));
|
|
226
|
-
if (uniqueBases.length === 0) {
|
|
227
|
-
throw new Error("No base directories provided for Tailwind CSS design system.");
|
|
228
|
-
}
|
|
229
|
-
const { __unstable__loadDesignSystem } = await importNode();
|
|
230
|
-
let lastError;
|
|
231
|
-
for (const base of uniqueBases) {
|
|
232
|
-
try {
|
|
233
|
-
return await __unstable__loadDesignSystem(css, { base });
|
|
234
|
-
} catch (error) {
|
|
235
|
-
lastError = error;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
if (lastError instanceof Error) {
|
|
239
|
-
throw lastError;
|
|
240
|
-
}
|
|
241
|
-
throw new Error("Failed to load Tailwind CSS design system.");
|
|
242
|
-
}
|
|
243
|
-
async function extractRawCandidatesWithPositions(content, extension = "html") {
|
|
244
|
-
const { Scanner } = await importOxide();
|
|
245
|
-
const scanner = new Scanner({});
|
|
246
|
-
const result = scanner.getCandidatesWithPositions({ content, extension });
|
|
247
|
-
return result.map(({ candidate, position }) => ({
|
|
248
|
-
rawCandidate: candidate,
|
|
249
|
-
start: position,
|
|
250
|
-
end: position + candidate.length
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
async function extractRawCandidates(sources) {
|
|
254
|
-
const { Scanner } = await importOxide();
|
|
255
|
-
const scanner = new Scanner({
|
|
256
|
-
sources
|
|
257
|
-
});
|
|
258
|
-
return scanner.scan();
|
|
259
|
-
}
|
|
260
|
-
async function extractValidCandidates(options) {
|
|
261
|
-
const providedOptions = _nullishCoalesce(options, () => ( {}));
|
|
262
|
-
const defaultCwd = _nullishCoalesce(providedOptions.cwd, () => ( _process2.default.cwd()));
|
|
263
|
-
const base = _nullishCoalesce(providedOptions.base, () => ( defaultCwd));
|
|
264
|
-
const baseFallbacks = _nullishCoalesce(providedOptions.baseFallbacks, () => ( []));
|
|
265
|
-
const css = _nullishCoalesce(providedOptions.css, () => ( '@import "tailwindcss";'));
|
|
266
|
-
const sources = (_nullishCoalesce(providedOptions.sources, () => ( [
|
|
267
|
-
{
|
|
268
|
-
base: defaultCwd,
|
|
269
|
-
pattern: "**/*",
|
|
270
|
-
negated: false
|
|
271
|
-
}
|
|
272
|
-
]))).map((source) => ({
|
|
273
|
-
base: _nullishCoalesce(source.base, () => ( defaultCwd)),
|
|
274
|
-
pattern: source.pattern,
|
|
275
|
-
negated: source.negated
|
|
276
|
-
}));
|
|
277
|
-
const designSystem = await loadDesignSystem(css, [base, ...baseFallbacks]);
|
|
278
|
-
const candidates = await extractRawCandidates(sources);
|
|
279
|
-
const parsedCandidates = candidates.filter(
|
|
280
|
-
(rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
|
|
281
|
-
);
|
|
282
|
-
if (parsedCandidates.length === 0) {
|
|
283
|
-
return parsedCandidates;
|
|
284
|
-
}
|
|
285
|
-
const cssByCandidate = designSystem.candidatesToCss(parsedCandidates);
|
|
286
|
-
const validCandidates = [];
|
|
287
|
-
for (let index = 0; index < parsedCandidates.length; index++) {
|
|
288
|
-
const css2 = cssByCandidate[index];
|
|
289
|
-
if (typeof css2 === "string" && css2.trim().length > 0) {
|
|
290
|
-
validCandidates.push(parsedCandidates[index]);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
return validCandidates;
|
|
294
|
-
}
|
|
295
|
-
function normalizeSources(sources, cwd) {
|
|
296
|
-
const baseSources = _optionalChain([sources, 'optionalAccess', _ => _.length]) ? sources : [
|
|
297
|
-
{
|
|
298
|
-
base: cwd,
|
|
299
|
-
pattern: "**/*",
|
|
300
|
-
negated: false
|
|
301
|
-
}
|
|
302
|
-
];
|
|
303
|
-
return baseSources.map((source) => ({
|
|
304
|
-
base: _nullishCoalesce(source.base, () => ( cwd)),
|
|
305
|
-
pattern: source.pattern,
|
|
306
|
-
negated: source.negated
|
|
307
|
-
}));
|
|
308
|
-
}
|
|
309
|
-
function buildLineOffsets(content) {
|
|
310
|
-
const offsets = [0];
|
|
311
|
-
for (let i = 0; i < content.length; i++) {
|
|
312
|
-
if (content[i] === "\n") {
|
|
313
|
-
offsets.push(i + 1);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
if (offsets[offsets.length - 1] !== content.length) {
|
|
317
|
-
offsets.push(content.length);
|
|
318
|
-
}
|
|
319
|
-
return offsets;
|
|
320
|
-
}
|
|
321
|
-
function resolveLineMeta(content, offsets, index) {
|
|
322
|
-
let low = 0;
|
|
323
|
-
let high = offsets.length - 1;
|
|
324
|
-
while (low <= high) {
|
|
325
|
-
const mid = Math.floor((low + high) / 2);
|
|
326
|
-
const start = offsets[mid];
|
|
327
|
-
const nextStart = _nullishCoalesce(offsets[mid + 1], () => ( content.length));
|
|
328
|
-
if (index < start) {
|
|
329
|
-
high = mid - 1;
|
|
330
|
-
continue;
|
|
331
|
-
}
|
|
332
|
-
if (index >= nextStart) {
|
|
333
|
-
low = mid + 1;
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
const line = mid + 1;
|
|
337
|
-
const column = index - start + 1;
|
|
338
|
-
const lineEnd = content.indexOf("\n", start);
|
|
339
|
-
const lineText = content.slice(start, lineEnd === -1 ? content.length : lineEnd);
|
|
340
|
-
return { line, column, lineText };
|
|
341
|
-
}
|
|
342
|
-
const lastStart = _nullishCoalesce(offsets[offsets.length - 2], () => ( 0));
|
|
343
|
-
return {
|
|
344
|
-
line: offsets.length - 1,
|
|
345
|
-
column: index - lastStart + 1,
|
|
346
|
-
lineText: content.slice(lastStart)
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
function toExtension(filename) {
|
|
350
|
-
const ext = _pathe2.default.extname(filename).replace(/^\./, "");
|
|
351
|
-
return ext || "txt";
|
|
352
|
-
}
|
|
353
|
-
function toRelativeFile(cwd, filename) {
|
|
354
|
-
const relative = _pathe2.default.relative(cwd, filename);
|
|
355
|
-
return relative === "" ? _pathe2.default.basename(filename) : relative;
|
|
356
|
-
}
|
|
357
|
-
async function extractProjectCandidatesWithPositions(options) {
|
|
358
|
-
const cwd = _optionalChain([options, 'optionalAccess', _2 => _2.cwd]) ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
|
|
359
|
-
const normalizedSources = normalizeSources(_optionalChain([options, 'optionalAccess', _3 => _3.sources]), cwd);
|
|
360
|
-
const { Scanner } = await importOxide();
|
|
361
|
-
const scanner = new Scanner({
|
|
362
|
-
sources: normalizedSources
|
|
363
|
-
});
|
|
364
|
-
const files = _nullishCoalesce(scanner.files, () => ( []));
|
|
365
|
-
const entries = [];
|
|
366
|
-
const skipped = [];
|
|
367
|
-
for (const file of files) {
|
|
368
|
-
let content;
|
|
369
|
-
try {
|
|
370
|
-
content = await _fs.promises.readFile(file, "utf8");
|
|
371
|
-
} catch (error) {
|
|
372
|
-
skipped.push({
|
|
373
|
-
file,
|
|
374
|
-
reason: error instanceof Error ? error.message : "Unknown error"
|
|
375
|
-
});
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
const extension = toExtension(file);
|
|
379
|
-
const matches = scanner.getCandidatesWithPositions({
|
|
380
|
-
file,
|
|
381
|
-
content,
|
|
382
|
-
extension
|
|
383
|
-
});
|
|
384
|
-
if (!matches.length) {
|
|
385
|
-
continue;
|
|
386
|
-
}
|
|
387
|
-
const offsets = buildLineOffsets(content);
|
|
388
|
-
const relativeFile = toRelativeFile(cwd, file);
|
|
389
|
-
for (const match of matches) {
|
|
390
|
-
const info = resolveLineMeta(content, offsets, match.position);
|
|
391
|
-
entries.push({
|
|
392
|
-
rawCandidate: match.candidate,
|
|
393
|
-
file,
|
|
394
|
-
relativeFile,
|
|
395
|
-
extension,
|
|
396
|
-
start: match.position,
|
|
397
|
-
end: match.position + match.candidate.length,
|
|
398
|
-
length: match.candidate.length,
|
|
399
|
-
line: info.line,
|
|
400
|
-
column: info.column,
|
|
401
|
-
lineText: info.lineText
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return {
|
|
406
|
-
entries,
|
|
407
|
-
filesScanned: files.length,
|
|
408
|
-
skippedFiles: skipped,
|
|
409
|
-
sources: normalizedSources
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
function groupTokensByFile(report, options) {
|
|
413
|
-
const key = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.key]), () => ( "relative"));
|
|
414
|
-
const stripAbsolute = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.stripAbsolutePaths]), () => ( key !== "absolute"));
|
|
415
|
-
return report.entries.reduce((acc, entry) => {
|
|
416
|
-
const bucketKey = key === "absolute" ? entry.file : entry.relativeFile;
|
|
417
|
-
if (!acc[bucketKey]) {
|
|
418
|
-
acc[bucketKey] = [];
|
|
419
|
-
}
|
|
420
|
-
const value = stripAbsolute ? {
|
|
421
|
-
...entry,
|
|
422
|
-
file: entry.relativeFile
|
|
423
|
-
} : entry;
|
|
424
|
-
acc[bucketKey].push(value);
|
|
425
|
-
return acc;
|
|
426
|
-
}, {});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// src/options/normalize.ts
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
// src/constants.ts
|
|
434
|
-
var pkgName = "tailwindcss-patch";
|
|
435
|
-
|
|
436
|
-
// src/options/normalize.ts
|
|
437
|
-
function toPrettyValue(value) {
|
|
438
|
-
if (typeof value === "number") {
|
|
439
|
-
return value > 0 ? value : false;
|
|
440
|
-
}
|
|
441
|
-
if (value === true) {
|
|
442
|
-
return 2;
|
|
443
|
-
}
|
|
444
|
-
return false;
|
|
445
|
-
}
|
|
446
|
-
function normalizeCacheDriver(driver) {
|
|
447
|
-
if (driver === "memory" || driver === "noop") {
|
|
448
|
-
return driver;
|
|
449
|
-
}
|
|
450
|
-
return "file";
|
|
451
|
-
}
|
|
452
|
-
function normalizeCacheOptions(cache, projectRoot) {
|
|
453
|
-
let enabled = false;
|
|
454
|
-
let cwd = projectRoot;
|
|
455
|
-
let dir = _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
456
|
-
let file = "class-cache.json";
|
|
457
|
-
let strategy = "merge";
|
|
458
|
-
let driver = "file";
|
|
459
|
-
if (typeof cache === "boolean") {
|
|
460
|
-
enabled = cache;
|
|
461
|
-
} else if (typeof cache === "object" && cache) {
|
|
462
|
-
enabled = _nullishCoalesce(cache.enabled, () => ( true));
|
|
463
|
-
cwd = _nullishCoalesce(cache.cwd, () => ( cwd));
|
|
464
|
-
dir = cache.dir ? _pathe2.default.resolve(cache.dir) : _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
465
|
-
file = _nullishCoalesce(cache.file, () => ( file));
|
|
466
|
-
strategy = _nullishCoalesce(cache.strategy, () => ( strategy));
|
|
467
|
-
driver = normalizeCacheDriver(cache.driver);
|
|
468
|
-
}
|
|
469
|
-
const filename = _pathe2.default.resolve(dir, file);
|
|
470
|
-
return {
|
|
471
|
-
enabled,
|
|
472
|
-
cwd,
|
|
473
|
-
dir,
|
|
474
|
-
file,
|
|
475
|
-
path: filename,
|
|
476
|
-
strategy,
|
|
477
|
-
driver
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
function normalizeOutputOptions(output) {
|
|
481
|
-
const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _6 => _6.enabled]), () => ( true));
|
|
482
|
-
const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _7 => _7.file]), () => ( ".tw-patch/tw-class-list.json"));
|
|
483
|
-
const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _8 => _8.format]), () => ( "json"));
|
|
484
|
-
const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _9 => _9.pretty]), () => ( true)));
|
|
485
|
-
const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _10 => _10.removeUniversalSelector]), () => ( true));
|
|
486
|
-
return {
|
|
487
|
-
enabled,
|
|
488
|
-
file,
|
|
489
|
-
format,
|
|
490
|
-
pretty,
|
|
491
|
-
removeUniversalSelector
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
function normalizeExposeContextOptions(features) {
|
|
495
|
-
if (_optionalChain([features, 'optionalAccess', _11 => _11.exposeContext]) === false) {
|
|
496
|
-
return {
|
|
497
|
-
enabled: false,
|
|
498
|
-
refProperty: "contextRef"
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
if (typeof _optionalChain([features, 'optionalAccess', _12 => _12.exposeContext]) === "object" && features.exposeContext) {
|
|
502
|
-
return {
|
|
503
|
-
enabled: true,
|
|
504
|
-
refProperty: _nullishCoalesce(features.exposeContext.refProperty, () => ( "contextRef"))
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
enabled: true,
|
|
509
|
-
refProperty: "contextRef"
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
function normalizeExtendLengthUnitsOptions(features) {
|
|
513
|
-
const extend = _optionalChain([features, 'optionalAccess', _13 => _13.extendLengthUnits]);
|
|
514
|
-
if (extend === false || extend === void 0) {
|
|
515
|
-
return null;
|
|
516
|
-
}
|
|
517
|
-
if (extend.enabled === false) {
|
|
518
|
-
return null;
|
|
519
|
-
}
|
|
520
|
-
const base = {
|
|
521
|
-
units: ["rpx"],
|
|
522
|
-
overwrite: true
|
|
523
|
-
};
|
|
524
|
-
return {
|
|
525
|
-
...base,
|
|
526
|
-
...extend,
|
|
527
|
-
enabled: _nullishCoalesce(extend.enabled, () => ( true)),
|
|
528
|
-
units: _nullishCoalesce(extend.units, () => ( base.units)),
|
|
529
|
-
overwrite: _nullishCoalesce(extend.overwrite, () => ( base.overwrite))
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
533
|
-
const configuredBase = _optionalChain([v4, 'optionalAccess', _14 => _14.base]) ? _pathe2.default.resolve(v4.base) : void 0;
|
|
534
|
-
const base = _nullishCoalesce(configuredBase, () => ( fallbackBase));
|
|
535
|
-
const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _15 => _15.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
|
|
536
|
-
const userSources = _optionalChain([v4, 'optionalAccess', _16 => _16.sources]);
|
|
537
|
-
const hasUserDefinedSources = Boolean(_optionalChain([userSources, 'optionalAccess', _17 => _17.length]));
|
|
538
|
-
const sources = hasUserDefinedSources ? userSources : [
|
|
539
|
-
{
|
|
540
|
-
base: fallbackBase,
|
|
541
|
-
pattern: "**/*",
|
|
542
|
-
negated: false
|
|
543
|
-
}
|
|
544
|
-
];
|
|
545
|
-
return {
|
|
546
|
-
base,
|
|
547
|
-
configuredBase,
|
|
548
|
-
css: _optionalChain([v4, 'optionalAccess', _18 => _18.css]),
|
|
549
|
-
cssEntries,
|
|
550
|
-
sources,
|
|
551
|
-
hasUserDefinedSources
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
555
|
-
const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _19 => _19.packageName]), () => ( "tailwindcss"));
|
|
556
|
-
const versionHint = _optionalChain([tailwind, 'optionalAccess', _20 => _20.version]);
|
|
557
|
-
const resolve = _optionalChain([tailwind, 'optionalAccess', _21 => _21.resolve]);
|
|
558
|
-
const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _22 => _22.cwd]), () => ( projectRoot));
|
|
559
|
-
const config = _optionalChain([tailwind, 'optionalAccess', _23 => _23.config]);
|
|
560
|
-
const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _24 => _24.postcssPlugin]);
|
|
561
|
-
const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _25 => _25.v4]), cwd);
|
|
562
|
-
return {
|
|
563
|
-
packageName,
|
|
564
|
-
versionHint,
|
|
565
|
-
resolve,
|
|
566
|
-
cwd,
|
|
567
|
-
config,
|
|
568
|
-
postcssPlugin,
|
|
569
|
-
v2: _optionalChain([tailwind, 'optionalAccess', _26 => _26.v2]),
|
|
570
|
-
v3: _optionalChain([tailwind, 'optionalAccess', _27 => _27.v3]),
|
|
571
|
-
v4
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
function normalizeOptions(options = {}) {
|
|
575
|
-
const projectRoot = options.cwd ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
|
|
576
|
-
const overwrite = _nullishCoalesce(options.overwrite, () => ( true));
|
|
577
|
-
const output = normalizeOutputOptions(options.output);
|
|
578
|
-
const cache = normalizeCacheOptions(options.cache, projectRoot);
|
|
579
|
-
const tailwind = normalizeTailwindOptions(options.tailwind, projectRoot);
|
|
580
|
-
const exposeContext = normalizeExposeContextOptions(options.features);
|
|
581
|
-
const extendLengthUnits = normalizeExtendLengthUnitsOptions(options.features);
|
|
582
|
-
const filter = (className) => {
|
|
583
|
-
if (output.removeUniversalSelector && className === "*") {
|
|
584
|
-
return false;
|
|
585
|
-
}
|
|
586
|
-
if (typeof options.filter === "function") {
|
|
587
|
-
return options.filter(className) !== false;
|
|
588
|
-
}
|
|
589
|
-
return true;
|
|
590
|
-
};
|
|
591
|
-
return {
|
|
592
|
-
projectRoot,
|
|
593
|
-
overwrite,
|
|
594
|
-
tailwind,
|
|
595
|
-
features: {
|
|
596
|
-
exposeContext,
|
|
597
|
-
extendLengthUnits
|
|
598
|
-
},
|
|
599
|
-
output,
|
|
600
|
-
cache,
|
|
601
|
-
filter
|
|
602
|
-
};
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
// src/patching/status.ts
|
|
606
|
-
var _types = require('@babel/types'); var t4 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
// src/babel/index.ts
|
|
611
|
-
var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
|
|
612
|
-
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
613
|
-
var _parser = require('@babel/parser');
|
|
614
|
-
function _interopDefaultCompat(e) {
|
|
615
|
-
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
616
|
-
}
|
|
617
|
-
var generate = _interopDefaultCompat(_generator2.default);
|
|
618
|
-
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
619
|
-
|
|
620
|
-
// src/patching/operations/export-context/postcss-v2.ts
|
|
621
|
-
|
|
622
|
-
var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
623
|
-
function toIdentifierName(property) {
|
|
624
|
-
if (!property) {
|
|
625
|
-
return "contextRef";
|
|
626
|
-
}
|
|
627
|
-
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
628
|
-
if (/^\d/.test(sanitized)) {
|
|
629
|
-
return `_${sanitized}`;
|
|
630
|
-
}
|
|
631
|
-
return sanitized || "contextRef";
|
|
632
|
-
}
|
|
633
|
-
function createExportsMember(property) {
|
|
634
|
-
if (IDENTIFIER_RE.test(property)) {
|
|
635
|
-
return t.memberExpression(t.identifier("exports"), t.identifier(property));
|
|
636
|
-
}
|
|
637
|
-
return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
|
|
638
|
-
}
|
|
639
|
-
function transformProcessTailwindFeaturesReturnContextV2(content) {
|
|
640
|
-
const ast = _parser.parse.call(void 0, content, {
|
|
641
|
-
sourceType: "unambiguous"
|
|
642
|
-
});
|
|
643
|
-
let hasPatched = false;
|
|
644
|
-
traverse(ast, {
|
|
645
|
-
FunctionDeclaration(path11) {
|
|
646
|
-
const node = path11.node;
|
|
647
|
-
if (_optionalChain([node, 'access', _28 => _28.id, 'optionalAccess', _29 => _29.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
const returnStatement3 = node.body.body[0];
|
|
651
|
-
if (!t.isFunctionExpression(returnStatement3.argument)) {
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
const body = returnStatement3.argument.body.body;
|
|
655
|
-
const lastStatement = body[body.length - 1];
|
|
656
|
-
const alreadyReturnsContext = Boolean(
|
|
657
|
-
t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
658
|
-
);
|
|
659
|
-
hasPatched = alreadyReturnsContext;
|
|
660
|
-
if (!alreadyReturnsContext) {
|
|
661
|
-
body.push(t.returnStatement(t.identifier("context")));
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
return {
|
|
666
|
-
code: hasPatched ? content : generate(ast).code,
|
|
667
|
-
hasPatched
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
function transformPostcssPluginV2(content, options) {
|
|
671
|
-
const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
|
|
672
|
-
const exportMember = createExportsMember(options.refProperty);
|
|
673
|
-
const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
|
|
674
|
-
const ast = _parser.parse.call(void 0, content);
|
|
675
|
-
let hasPatched = false;
|
|
676
|
-
traverse(ast, {
|
|
677
|
-
Program(path11) {
|
|
678
|
-
const program = path11.node;
|
|
679
|
-
const index = program.body.findIndex((statement) => {
|
|
680
|
-
return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _30 => _30.id, 'optionalAccess', _31 => _31.name]) === "_default";
|
|
681
|
-
});
|
|
682
|
-
if (index === -1) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
const previous = program.body[index - 1];
|
|
686
|
-
const beforePrevious = program.body[index - 2];
|
|
687
|
-
const alreadyHasVariable = Boolean(
|
|
688
|
-
previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
|
|
689
|
-
);
|
|
690
|
-
const alreadyAssignsExports = Boolean(
|
|
691
|
-
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
|
|
692
|
-
);
|
|
693
|
-
hasPatched = alreadyHasVariable && alreadyAssignsExports;
|
|
694
|
-
if (!alreadyHasVariable) {
|
|
695
|
-
program.body.splice(
|
|
696
|
-
index,
|
|
697
|
-
0,
|
|
698
|
-
t.variableDeclaration("var", [
|
|
699
|
-
t.variableDeclarator(
|
|
700
|
-
refIdentifier,
|
|
701
|
-
t.objectExpression([
|
|
702
|
-
t.objectProperty(t.identifier("value"), t.arrayExpression())
|
|
703
|
-
])
|
|
704
|
-
)
|
|
705
|
-
]),
|
|
706
|
-
t.expressionStatement(
|
|
707
|
-
t.assignmentExpression("=", exportMember, refIdentifier)
|
|
708
|
-
)
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
},
|
|
712
|
-
FunctionDeclaration(path11) {
|
|
713
|
-
if (hasPatched) {
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
716
|
-
const fn = path11.node;
|
|
717
|
-
if (_optionalChain([fn, 'access', _32 => _32.id, 'optionalAccess', _33 => _33.name]) !== "_default") {
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
const returnStatement3 = fn.body.body[0];
|
|
724
|
-
if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
const fnExpression = returnStatement3.argument.callee.object.elements[1];
|
|
728
|
-
if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
const block = fnExpression.body;
|
|
732
|
-
const statements = block.body;
|
|
733
|
-
if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
|
|
734
|
-
hasPatched = true;
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
const lastStatement = statements[statements.length - 1];
|
|
738
|
-
if (lastStatement && t.isExpressionStatement(lastStatement)) {
|
|
739
|
-
statements[statements.length - 1] = t.expressionStatement(
|
|
740
|
-
t.callExpression(
|
|
741
|
-
t.memberExpression(valueMember, t.identifier("push")),
|
|
742
|
-
[lastStatement.expression]
|
|
743
|
-
)
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
const index = statements.findIndex((statement) => t.isIfStatement(statement));
|
|
747
|
-
if (index > -1) {
|
|
748
|
-
const ifStatement = statements[index];
|
|
749
|
-
if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
|
|
750
|
-
const forOf = ifStatement.consequent.body[1];
|
|
751
|
-
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
|
|
752
|
-
const nestedIf = forOf.body.body[0];
|
|
753
|
-
if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
|
|
754
|
-
nestedIf.consequent.body[0] = t.expressionStatement(
|
|
755
|
-
t.callExpression(
|
|
756
|
-
t.memberExpression(valueMember, t.identifier("push")),
|
|
757
|
-
[nestedIf.consequent.body[0].expression]
|
|
758
|
-
)
|
|
759
|
-
);
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
statements.unshift(
|
|
765
|
-
t.expressionStatement(
|
|
766
|
-
t.assignmentExpression(
|
|
767
|
-
"=",
|
|
768
|
-
t.memberExpression(valueMember, t.identifier("length")),
|
|
769
|
-
t.numericLiteral(0)
|
|
770
|
-
)
|
|
771
|
-
)
|
|
772
|
-
);
|
|
773
|
-
}
|
|
774
|
-
});
|
|
775
|
-
return {
|
|
776
|
-
code: hasPatched ? content : generate(ast).code,
|
|
777
|
-
hasPatched
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// src/patching/operations/export-context/postcss-v3.ts
|
|
782
|
-
|
|
783
|
-
var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
|
|
784
|
-
function toIdentifierName2(property) {
|
|
785
|
-
if (!property) {
|
|
786
|
-
return "contextRef";
|
|
787
|
-
}
|
|
788
|
-
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
789
|
-
if (/^\d/.test(sanitized)) {
|
|
790
|
-
return `_${sanitized}`;
|
|
791
|
-
}
|
|
792
|
-
return sanitized || "contextRef";
|
|
793
|
-
}
|
|
794
|
-
function createModuleExportsMember(property) {
|
|
795
|
-
const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
|
|
796
|
-
if (IDENTIFIER_RE2.test(property)) {
|
|
797
|
-
return t2.memberExpression(object, t2.identifier(property));
|
|
798
|
-
}
|
|
799
|
-
return t2.memberExpression(object, t2.stringLiteral(property), true);
|
|
800
|
-
}
|
|
801
|
-
function transformProcessTailwindFeaturesReturnContext(content) {
|
|
802
|
-
const ast = _parser.parse.call(void 0, content);
|
|
803
|
-
let hasPatched = false;
|
|
804
|
-
traverse(ast, {
|
|
805
|
-
FunctionDeclaration(path11) {
|
|
806
|
-
const node = path11.node;
|
|
807
|
-
if (_optionalChain([node, 'access', _34 => _34.id, 'optionalAccess', _35 => _35.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
const [returnStatement3] = node.body.body;
|
|
811
|
-
if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
const expression = returnStatement3.argument;
|
|
815
|
-
const body = expression.body.body;
|
|
816
|
-
const lastStatement = body[body.length - 1];
|
|
817
|
-
const alreadyReturnsContext = Boolean(
|
|
818
|
-
t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
819
|
-
);
|
|
820
|
-
hasPatched = alreadyReturnsContext;
|
|
821
|
-
if (!alreadyReturnsContext) {
|
|
822
|
-
body.push(t2.returnStatement(t2.identifier("context")));
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
});
|
|
826
|
-
return {
|
|
827
|
-
code: hasPatched ? content : generate(ast).code,
|
|
828
|
-
hasPatched
|
|
829
|
-
};
|
|
830
|
-
}
|
|
831
|
-
function transformPostcssPlugin(content, { refProperty }) {
|
|
832
|
-
const ast = _parser.parse.call(void 0, content);
|
|
833
|
-
const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
|
|
834
|
-
const moduleExportsMember = createModuleExportsMember(refProperty);
|
|
835
|
-
const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
|
|
836
|
-
let hasPatched = false;
|
|
837
|
-
traverse(ast, {
|
|
838
|
-
Program(path11) {
|
|
839
|
-
const program = path11.node;
|
|
840
|
-
const index = program.body.findIndex((statement) => {
|
|
841
|
-
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _36 => _36.expression, 'access', _37 => _37.right, 'access', _38 => _38.id, 'optionalAccess', _39 => _39.name]) === "tailwindcss";
|
|
842
|
-
});
|
|
843
|
-
if (index === -1) {
|
|
844
|
-
return;
|
|
845
|
-
}
|
|
846
|
-
const previousStatement = program.body[index - 1];
|
|
847
|
-
const lastStatement = program.body[program.body.length - 1];
|
|
848
|
-
const alreadyHasVariable = Boolean(
|
|
849
|
-
previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
|
|
850
|
-
);
|
|
851
|
-
const alreadyAssignsModuleExports = Boolean(
|
|
852
|
-
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
|
|
853
|
-
);
|
|
854
|
-
hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
|
|
855
|
-
if (!alreadyHasVariable) {
|
|
856
|
-
program.body.splice(
|
|
857
|
-
index,
|
|
858
|
-
0,
|
|
859
|
-
t2.variableDeclaration("const", [
|
|
860
|
-
t2.variableDeclarator(
|
|
861
|
-
refIdentifier,
|
|
862
|
-
t2.objectExpression([
|
|
863
|
-
t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
|
|
864
|
-
])
|
|
865
|
-
)
|
|
866
|
-
])
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
if (!alreadyAssignsModuleExports) {
|
|
870
|
-
program.body.push(
|
|
871
|
-
t2.expressionStatement(
|
|
872
|
-
t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
|
|
873
|
-
)
|
|
874
|
-
);
|
|
875
|
-
}
|
|
876
|
-
},
|
|
877
|
-
FunctionExpression(path11) {
|
|
878
|
-
if (hasPatched) {
|
|
879
|
-
return;
|
|
880
|
-
}
|
|
881
|
-
const fn = path11.node;
|
|
882
|
-
if (_optionalChain([fn, 'access', _40 => _40.id, 'optionalAccess', _41 => _41.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
|
|
883
|
-
return;
|
|
884
|
-
}
|
|
885
|
-
const [returnStatement3] = fn.body.body;
|
|
886
|
-
if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
const properties = returnStatement3.argument.properties;
|
|
890
|
-
if (properties.length !== 2) {
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
const pluginsProperty = properties.find(
|
|
894
|
-
(prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
|
|
895
|
-
);
|
|
896
|
-
if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
|
|
897
|
-
return;
|
|
898
|
-
}
|
|
899
|
-
const pluginsArray = pluginsProperty.value.callee.object.elements;
|
|
900
|
-
const targetPlugin = pluginsArray[1];
|
|
901
|
-
if (!targetPlugin || !t2.isFunctionExpression(targetPlugin)) {
|
|
902
|
-
return;
|
|
903
|
-
}
|
|
904
|
-
const block = targetPlugin.body;
|
|
905
|
-
const statements = block.body;
|
|
906
|
-
const last = statements[statements.length - 1];
|
|
907
|
-
if (last && t2.isExpressionStatement(last)) {
|
|
908
|
-
statements[statements.length - 1] = t2.expressionStatement(
|
|
909
|
-
t2.callExpression(
|
|
910
|
-
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
911
|
-
[last.expression]
|
|
912
|
-
)
|
|
913
|
-
);
|
|
914
|
-
}
|
|
915
|
-
const index = statements.findIndex((s) => t2.isIfStatement(s));
|
|
916
|
-
if (index > -1) {
|
|
917
|
-
const ifStatement = statements[index];
|
|
918
|
-
if (t2.isBlockStatement(ifStatement.consequent)) {
|
|
919
|
-
const [, second] = ifStatement.consequent.body;
|
|
920
|
-
if (second && t2.isForOfStatement(second) && t2.isBlockStatement(second.body)) {
|
|
921
|
-
const bodyStatement = second.body.body[0];
|
|
922
|
-
if (bodyStatement && t2.isIfStatement(bodyStatement) && t2.isBlockStatement(bodyStatement.consequent) && bodyStatement.consequent.body.length === 1 && t2.isExpressionStatement(bodyStatement.consequent.body[0])) {
|
|
923
|
-
bodyStatement.consequent.body[0] = t2.expressionStatement(
|
|
924
|
-
t2.callExpression(
|
|
925
|
-
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
926
|
-
[bodyStatement.consequent.body[0].expression]
|
|
927
|
-
)
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
statements.unshift(
|
|
934
|
-
t2.expressionStatement(
|
|
935
|
-
t2.assignmentExpression(
|
|
936
|
-
"=",
|
|
937
|
-
t2.memberExpression(valueMember, t2.identifier("length")),
|
|
938
|
-
t2.numericLiteral(0)
|
|
939
|
-
)
|
|
940
|
-
)
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
return {
|
|
945
|
-
code: hasPatched ? content : generate(ast).code,
|
|
946
|
-
hasPatched
|
|
947
|
-
};
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
// src/patching/operations/extend-length-units.ts
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
// src/utils.ts
|
|
956
|
-
function isObject(val) {
|
|
957
|
-
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
958
|
-
}
|
|
959
|
-
function spliceChangesIntoString(str, changes) {
|
|
960
|
-
if (!changes[0]) {
|
|
961
|
-
return str;
|
|
962
|
-
}
|
|
963
|
-
changes.sort((a, b) => {
|
|
964
|
-
return a.end - b.end || a.start - b.start;
|
|
965
|
-
});
|
|
966
|
-
let result = "";
|
|
967
|
-
let previous = changes[0];
|
|
968
|
-
result += str.slice(0, previous.start);
|
|
969
|
-
result += previous.replacement;
|
|
970
|
-
for (let i = 1; i < changes.length; ++i) {
|
|
971
|
-
const change = changes[i];
|
|
972
|
-
result += str.slice(previous.end, change.start);
|
|
973
|
-
result += change.replacement;
|
|
974
|
-
previous = change;
|
|
975
|
-
}
|
|
976
|
-
result += str.slice(previous.end);
|
|
977
|
-
return result;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
// src/patching/operations/extend-length-units.ts
|
|
981
|
-
function updateLengthUnitsArray(content, options) {
|
|
982
|
-
const { variableName = "lengthUnits", units } = options;
|
|
983
|
-
const ast = _parser.parse.call(void 0, content);
|
|
984
|
-
let arrayRef;
|
|
985
|
-
let changed = false;
|
|
986
|
-
traverse(ast, {
|
|
987
|
-
Identifier(path11) {
|
|
988
|
-
if (path11.node.name === variableName && t3.isVariableDeclarator(path11.parent) && t3.isArrayExpression(path11.parent.init)) {
|
|
989
|
-
arrayRef = path11.parent.init;
|
|
990
|
-
const existing = new Set(
|
|
991
|
-
path11.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
992
|
-
);
|
|
993
|
-
for (const unit of units) {
|
|
994
|
-
if (!existing.has(unit)) {
|
|
995
|
-
path11.parent.init.elements = path11.parent.init.elements.map((element) => {
|
|
996
|
-
if (t3.isStringLiteral(element)) {
|
|
997
|
-
return t3.stringLiteral(element.value);
|
|
998
|
-
}
|
|
999
|
-
return element;
|
|
1000
|
-
});
|
|
1001
|
-
path11.parent.init.elements.push(t3.stringLiteral(unit));
|
|
1002
|
-
changed = true;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
return {
|
|
1009
|
-
arrayRef,
|
|
1010
|
-
changed
|
|
1011
|
-
};
|
|
1012
|
-
}
|
|
1013
|
-
function applyExtendLengthUnitsPatchV3(rootDir, options) {
|
|
1014
|
-
if (!options.enabled) {
|
|
1015
|
-
return { changed: false, code: void 0 };
|
|
1016
|
-
}
|
|
1017
|
-
const opts = {
|
|
1018
|
-
...options,
|
|
1019
|
-
lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
|
|
1020
|
-
variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
|
|
1021
|
-
};
|
|
1022
|
-
const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
|
|
1023
|
-
const exists = _fsextra2.default.existsSync(dataTypesFilePath);
|
|
1024
|
-
if (!exists) {
|
|
1025
|
-
return { changed: false, code: void 0 };
|
|
1026
|
-
}
|
|
1027
|
-
const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
|
|
1028
|
-
const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
|
|
1029
|
-
if (!arrayRef || !changed) {
|
|
1030
|
-
return { changed: false, code: void 0 };
|
|
1031
|
-
}
|
|
1032
|
-
const { code } = generate(arrayRef, {
|
|
1033
|
-
jsescOption: { quotes: "single" }
|
|
1034
|
-
});
|
|
1035
|
-
if (arrayRef.start != null && arrayRef.end != null) {
|
|
1036
|
-
const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
|
|
1037
|
-
if (opts.overwrite) {
|
|
1038
|
-
const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
|
|
1039
|
-
_fsextra2.default.writeFileSync(target, nextCode, "utf8");
|
|
1040
|
-
logger_default.success("Patched Tailwind CSS length unit list (v3).");
|
|
1041
|
-
}
|
|
1042
|
-
return {
|
|
1043
|
-
changed: true,
|
|
1044
|
-
code: nextCode
|
|
1045
|
-
};
|
|
1046
|
-
}
|
|
1047
|
-
return {
|
|
1048
|
-
changed: false,
|
|
1049
|
-
code: void 0
|
|
1050
|
-
};
|
|
1051
|
-
}
|
|
1052
|
-
function applyExtendLengthUnitsPatchV4(rootDir, options) {
|
|
1053
|
-
if (!options.enabled) {
|
|
1054
|
-
return { files: [], changed: false };
|
|
1055
|
-
}
|
|
1056
|
-
const opts = { ...options };
|
|
1057
|
-
const distDir = _pathe2.default.resolve(rootDir, "dist");
|
|
1058
|
-
if (!_fsextra2.default.existsSync(distDir)) {
|
|
1059
|
-
return { files: [], changed: false };
|
|
1060
|
-
}
|
|
1061
|
-
const entries = _fsextra2.default.readdirSync(distDir);
|
|
1062
|
-
const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
|
|
1063
|
-
const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
|
|
1064
|
-
const candidates = chunkNames.map((chunkName) => {
|
|
1065
|
-
const file = _pathe2.default.join(distDir, chunkName);
|
|
1066
|
-
const code = _fsextra2.default.readFileSync(file, "utf8");
|
|
1067
|
-
const match = pattern.exec(code);
|
|
1068
|
-
if (!match) {
|
|
1069
|
-
return null;
|
|
1070
|
-
}
|
|
1071
|
-
return {
|
|
1072
|
-
file,
|
|
1073
|
-
code,
|
|
1074
|
-
match,
|
|
1075
|
-
hasPatched: false
|
|
1076
|
-
};
|
|
1077
|
-
}).filter((candidate) => candidate !== null);
|
|
1078
|
-
for (const item of candidates) {
|
|
1079
|
-
const { code, file, match } = item;
|
|
1080
|
-
const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
|
|
1081
|
-
traverse(ast, {
|
|
1082
|
-
ArrayExpression(path11) {
|
|
1083
|
-
for (const unit of opts.units) {
|
|
1084
|
-
if (path11.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
|
|
1085
|
-
item.hasPatched = true;
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
|
-
path11.node.elements.push(t3.stringLiteral(unit));
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
});
|
|
1092
|
-
if (item.hasPatched) {
|
|
1093
|
-
continue;
|
|
1094
|
-
}
|
|
1095
|
-
const { code: replacement } = generate(ast, { minified: true });
|
|
1096
|
-
const start = _nullishCoalesce(match.index, () => ( 0));
|
|
1097
|
-
const end = start + match[0].length;
|
|
1098
|
-
item.code = spliceChangesIntoString(code, [
|
|
1099
|
-
{
|
|
1100
|
-
start,
|
|
1101
|
-
end,
|
|
1102
|
-
replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
|
|
1103
|
-
}
|
|
1104
|
-
]);
|
|
1105
|
-
if (opts.overwrite) {
|
|
1106
|
-
_fsextra2.default.writeFileSync(file, item.code, "utf8");
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
if (candidates.some((file) => !file.hasPatched)) {
|
|
1110
|
-
logger_default.success("Patched Tailwind CSS length unit list (v4).");
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
changed: candidates.some((file) => !file.hasPatched),
|
|
1114
|
-
files: candidates
|
|
1115
|
-
};
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
// src/patching/status.ts
|
|
1119
|
-
function inspectLengthUnitsArray(content, variableName, units) {
|
|
1120
|
-
const ast = _parser.parse.call(void 0, content);
|
|
1121
|
-
let found = false;
|
|
1122
|
-
let missingUnits = [];
|
|
1123
|
-
traverse(ast, {
|
|
1124
|
-
Identifier(path11) {
|
|
1125
|
-
if (path11.node.name === variableName && t4.isVariableDeclarator(path11.parent) && t4.isArrayExpression(path11.parent.init)) {
|
|
1126
|
-
found = true;
|
|
1127
|
-
const existing = new Set(
|
|
1128
|
-
path11.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
1129
|
-
);
|
|
1130
|
-
missingUnits = units.filter((unit) => !existing.has(unit));
|
|
1131
|
-
path11.stop();
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
});
|
|
1135
|
-
return {
|
|
1136
|
-
found,
|
|
1137
|
-
missingUnits
|
|
1138
|
-
};
|
|
1139
|
-
}
|
|
1140
|
-
function checkExposeContextPatch(context) {
|
|
1141
|
-
const { packageInfo, options, majorVersion } = context;
|
|
1142
|
-
const refProperty = options.features.exposeContext.refProperty;
|
|
1143
|
-
if (!options.features.exposeContext.enabled) {
|
|
1144
|
-
return {
|
|
1145
|
-
name: "exposeContext",
|
|
1146
|
-
status: "skipped",
|
|
1147
|
-
reason: "exposeContext feature disabled",
|
|
1148
|
-
files: []
|
|
1149
|
-
};
|
|
1150
|
-
}
|
|
1151
|
-
if (majorVersion === 4) {
|
|
1152
|
-
return {
|
|
1153
|
-
name: "exposeContext",
|
|
1154
|
-
status: "unsupported",
|
|
1155
|
-
reason: "Context export patch is only required for Tailwind v2/v3",
|
|
1156
|
-
files: []
|
|
1157
|
-
};
|
|
1158
|
-
}
|
|
1159
|
-
const checks = [];
|
|
1160
|
-
function inspectFile(relative, transform) {
|
|
1161
|
-
const filePath = _pathe2.default.resolve(packageInfo.rootPath, relative);
|
|
1162
|
-
if (!_fsextra2.default.existsSync(filePath)) {
|
|
1163
|
-
checks.push({ relative, exists: false, patched: false });
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
const content = _fsextra2.default.readFileSync(filePath, "utf8");
|
|
1167
|
-
const { hasPatched } = transform(content);
|
|
1168
|
-
checks.push({
|
|
1169
|
-
relative,
|
|
1170
|
-
exists: true,
|
|
1171
|
-
patched: hasPatched
|
|
1172
|
-
});
|
|
1173
|
-
}
|
|
1174
|
-
if (majorVersion === 3) {
|
|
1175
|
-
inspectFile("lib/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContext);
|
|
1176
|
-
const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
|
|
1177
|
-
const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(packageInfo.rootPath, candidate)));
|
|
1178
|
-
if (pluginRelative) {
|
|
1179
|
-
inspectFile(pluginRelative, (content) => transformPostcssPlugin(content, { refProperty }));
|
|
1180
|
-
} else {
|
|
1181
|
-
checks.push({ relative: "lib/plugin.js", exists: false, patched: false });
|
|
1182
|
-
}
|
|
1183
|
-
} else {
|
|
1184
|
-
inspectFile("lib/jit/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContextV2);
|
|
1185
|
-
inspectFile("lib/jit/index.js", (content) => transformPostcssPluginV2(content, { refProperty }));
|
|
1186
|
-
}
|
|
1187
|
-
const files = checks.filter((check) => check.exists).map((check) => check.relative);
|
|
1188
|
-
const missingFiles = checks.filter((check) => !check.exists);
|
|
1189
|
-
const unpatchedFiles = checks.filter((check) => check.exists && !check.patched);
|
|
1190
|
-
const reasons = [];
|
|
1191
|
-
if (missingFiles.length) {
|
|
1192
|
-
reasons.push(`missing files: ${missingFiles.map((item) => item.relative).join(", ")}`);
|
|
1193
|
-
}
|
|
1194
|
-
if (unpatchedFiles.length) {
|
|
1195
|
-
reasons.push(`unpatched files: ${unpatchedFiles.map((item) => item.relative).join(", ")}`);
|
|
1196
|
-
}
|
|
1197
|
-
return {
|
|
1198
|
-
name: "exposeContext",
|
|
1199
|
-
status: reasons.length ? "not-applied" : "applied",
|
|
1200
|
-
reason: reasons.length ? reasons.join("; ") : void 0,
|
|
1201
|
-
files
|
|
1202
|
-
};
|
|
1203
|
-
}
|
|
1204
|
-
function checkExtendLengthUnitsV3(rootDir, options) {
|
|
1205
|
-
const lengthUnitsFilePath = _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
|
|
1206
|
-
const variableName = _nullishCoalesce(options.variableName, () => ( "lengthUnits"));
|
|
1207
|
-
const target = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
|
|
1208
|
-
const files = _fsextra2.default.existsSync(target) ? [_pathe2.default.relative(rootDir, target)] : [];
|
|
1209
|
-
if (!_fsextra2.default.existsSync(target)) {
|
|
1210
|
-
return {
|
|
1211
|
-
name: "extendLengthUnits",
|
|
1212
|
-
status: "not-applied",
|
|
1213
|
-
reason: `missing ${lengthUnitsFilePath}`,
|
|
1214
|
-
files
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
const content = _fsextra2.default.readFileSync(target, "utf8");
|
|
1218
|
-
const { found, missingUnits } = inspectLengthUnitsArray(content, variableName, options.units);
|
|
1219
|
-
if (!found) {
|
|
1220
|
-
return {
|
|
1221
|
-
name: "extendLengthUnits",
|
|
1222
|
-
status: "not-applied",
|
|
1223
|
-
reason: `could not locate ${variableName} array in ${lengthUnitsFilePath}`,
|
|
1224
|
-
files
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
|
-
if (missingUnits.length) {
|
|
1228
|
-
return {
|
|
1229
|
-
name: "extendLengthUnits",
|
|
1230
|
-
status: "not-applied",
|
|
1231
|
-
reason: `missing units: ${missingUnits.join(", ")}`,
|
|
1232
|
-
files
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
return {
|
|
1236
|
-
name: "extendLengthUnits",
|
|
1237
|
-
status: "applied",
|
|
1238
|
-
files
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
function checkExtendLengthUnitsV4(rootDir, options) {
|
|
1242
|
-
const distDir = _pathe2.default.resolve(rootDir, "dist");
|
|
1243
|
-
if (!_fsextra2.default.existsSync(distDir)) {
|
|
1244
|
-
return {
|
|
1245
|
-
name: "extendLengthUnits",
|
|
1246
|
-
status: "not-applied",
|
|
1247
|
-
reason: "dist directory not found for Tailwind v4 package",
|
|
1248
|
-
files: []
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
const result = applyExtendLengthUnitsPatchV4(rootDir, {
|
|
1252
|
-
...options,
|
|
1253
|
-
enabled: true,
|
|
1254
|
-
overwrite: false
|
|
1255
|
-
});
|
|
1256
|
-
if (result.files.length === 0) {
|
|
1257
|
-
return {
|
|
1258
|
-
name: "extendLengthUnits",
|
|
1259
|
-
status: "not-applied",
|
|
1260
|
-
reason: "no bundle chunks matched the length unit pattern",
|
|
1261
|
-
files: []
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
const files = result.files.map((file) => _pathe2.default.relative(rootDir, file.file));
|
|
1265
|
-
const pending = result.files.filter((file) => !file.hasPatched);
|
|
1266
|
-
if (pending.length) {
|
|
1267
|
-
return {
|
|
1268
|
-
name: "extendLengthUnits",
|
|
1269
|
-
status: "not-applied",
|
|
1270
|
-
reason: `missing units in ${pending.length} bundle${pending.length > 1 ? "s" : ""}`,
|
|
1271
|
-
files: pending.map((file) => _pathe2.default.relative(rootDir, file.file))
|
|
1272
|
-
};
|
|
1273
|
-
}
|
|
1274
|
-
return {
|
|
1275
|
-
name: "extendLengthUnits",
|
|
1276
|
-
status: "applied",
|
|
1277
|
-
files
|
|
1278
|
-
};
|
|
1279
|
-
}
|
|
1280
|
-
function checkExtendLengthUnitsPatch(context) {
|
|
1281
|
-
const { packageInfo, options, majorVersion } = context;
|
|
1282
|
-
if (!options.features.extendLengthUnits) {
|
|
1283
|
-
return {
|
|
1284
|
-
name: "extendLengthUnits",
|
|
1285
|
-
status: "skipped",
|
|
1286
|
-
reason: "extendLengthUnits feature disabled",
|
|
1287
|
-
files: []
|
|
1288
|
-
};
|
|
1289
|
-
}
|
|
1290
|
-
if (majorVersion === 2) {
|
|
1291
|
-
return {
|
|
1292
|
-
name: "extendLengthUnits",
|
|
1293
|
-
status: "unsupported",
|
|
1294
|
-
reason: "length unit extension is only applied for Tailwind v3/v4",
|
|
1295
|
-
files: []
|
|
1296
|
-
};
|
|
1297
|
-
}
|
|
1298
|
-
if (majorVersion === 3) {
|
|
1299
|
-
return checkExtendLengthUnitsV3(packageInfo.rootPath, options.features.extendLengthUnits);
|
|
1300
|
-
}
|
|
1301
|
-
return checkExtendLengthUnitsV4(packageInfo.rootPath, options.features.extendLengthUnits);
|
|
1302
|
-
}
|
|
1303
|
-
function getPatchStatusReport(context) {
|
|
1304
|
-
return {
|
|
1305
|
-
package: {
|
|
1306
|
-
name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _42 => _42.packageInfo, 'access', _43 => _43.packageJson, 'optionalAccess', _44 => _44.name]))),
|
|
1307
|
-
version: context.packageInfo.version,
|
|
1308
|
-
root: context.packageInfo.rootPath
|
|
1309
|
-
},
|
|
1310
|
-
majorVersion: context.majorVersion,
|
|
1311
|
-
entries: [
|
|
1312
|
-
checkExposeContextPatch(context),
|
|
1313
|
-
checkExtendLengthUnitsPatch(context)
|
|
1314
|
-
]
|
|
1315
|
-
};
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
// src/runtime/class-collector.ts
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
function collectClassesFromContexts(contexts, filter) {
|
|
1323
|
-
const set = /* @__PURE__ */ new Set();
|
|
1324
|
-
for (const context of contexts) {
|
|
1325
|
-
if (!isObject(context) || !context.classCache) {
|
|
1326
|
-
continue;
|
|
1327
|
-
}
|
|
1328
|
-
for (const key of context.classCache.keys()) {
|
|
1329
|
-
const className = key.toString();
|
|
1330
|
-
if (filter(className)) {
|
|
1331
|
-
set.add(className);
|
|
1332
|
-
}
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
return set;
|
|
1336
|
-
}
|
|
1337
|
-
async function collectClassesFromTailwindV4(options) {
|
|
1338
|
-
const set = /* @__PURE__ */ new Set();
|
|
1339
|
-
const v4Options = options.tailwind.v4;
|
|
1340
|
-
if (!v4Options) {
|
|
1341
|
-
return set;
|
|
1342
|
-
}
|
|
1343
|
-
const toAbsolute = (value) => {
|
|
1344
|
-
if (!value) {
|
|
1345
|
-
return void 0;
|
|
1346
|
-
}
|
|
1347
|
-
return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
|
|
1348
|
-
};
|
|
1349
|
-
const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
|
|
1350
|
-
const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
|
|
1351
|
-
const resolveSources = (base) => {
|
|
1352
|
-
if (!_optionalChain([v4Options, 'access', _45 => _45.sources, 'optionalAccess', _46 => _46.length])) {
|
|
1353
|
-
return void 0;
|
|
1354
|
-
}
|
|
1355
|
-
return v4Options.sources.map((source) => ({
|
|
1356
|
-
base: _nullishCoalesce(source.base, () => ( base)),
|
|
1357
|
-
pattern: source.pattern,
|
|
1358
|
-
negated: source.negated
|
|
1359
|
-
}));
|
|
1360
|
-
};
|
|
1361
|
-
if (v4Options.cssEntries.length > 0) {
|
|
1362
|
-
for (const entry of v4Options.cssEntries) {
|
|
1363
|
-
const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
|
|
1364
|
-
if (!await _fsextra2.default.pathExists(filePath)) {
|
|
1365
|
-
continue;
|
|
1366
|
-
}
|
|
1367
|
-
const css = await _fsextra2.default.readFile(filePath, "utf8");
|
|
1368
|
-
const entryDir = _pathe2.default.dirname(filePath);
|
|
1369
|
-
const designSystemBases = resolvedConfiguredBase && resolvedConfiguredBase !== entryDir ? [entryDir, resolvedConfiguredBase] : [entryDir];
|
|
1370
|
-
const sourcesBase = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
|
|
1371
|
-
const sources = resolveSources(sourcesBase);
|
|
1372
|
-
const candidates = await extractValidCandidates({
|
|
1373
|
-
cwd: options.projectRoot,
|
|
1374
|
-
base: designSystemBases[0],
|
|
1375
|
-
baseFallbacks: designSystemBases.slice(1),
|
|
1376
|
-
css,
|
|
1377
|
-
sources
|
|
1378
|
-
});
|
|
1379
|
-
for (const candidate of candidates) {
|
|
1380
|
-
if (options.filter(candidate)) {
|
|
1381
|
-
set.add(candidate);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
} else {
|
|
1386
|
-
const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
|
|
1387
|
-
const sources = resolveSources(baseForCss);
|
|
1388
|
-
const candidates = await extractValidCandidates({
|
|
1389
|
-
cwd: options.projectRoot,
|
|
1390
|
-
base: baseForCss,
|
|
1391
|
-
css: v4Options.css,
|
|
1392
|
-
sources
|
|
1393
|
-
});
|
|
1394
|
-
for (const candidate of candidates) {
|
|
1395
|
-
if (options.filter(candidate)) {
|
|
1396
|
-
set.add(candidate);
|
|
1397
|
-
}
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
return set;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
// src/runtime/context-registry.ts
|
|
1404
|
-
var _module = require('module');
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
var require2 = _module.createRequire.call(void 0, importMetaUrl);
|
|
1408
|
-
function resolveRuntimeEntry(packageInfo, majorVersion) {
|
|
1409
|
-
const root = packageInfo.rootPath;
|
|
1410
|
-
if (majorVersion === 2) {
|
|
1411
|
-
const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
|
|
1412
|
-
if (_fsextra2.default.existsSync(jitIndex)) {
|
|
1413
|
-
return jitIndex;
|
|
1414
|
-
}
|
|
1415
|
-
} else if (majorVersion === 3) {
|
|
1416
|
-
const plugin = _pathe2.default.join(root, "lib/plugin.js");
|
|
1417
|
-
const index = _pathe2.default.join(root, "lib/index.js");
|
|
1418
|
-
if (_fsextra2.default.existsSync(plugin)) {
|
|
1419
|
-
return plugin;
|
|
1420
|
-
}
|
|
1421
|
-
if (_fsextra2.default.existsSync(index)) {
|
|
1422
|
-
return index;
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
return void 0;
|
|
1426
|
-
}
|
|
1427
|
-
function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
|
|
1428
|
-
if (majorVersion === 4) {
|
|
1429
|
-
return [];
|
|
1430
|
-
}
|
|
1431
|
-
const entry = resolveRuntimeEntry(packageInfo, majorVersion);
|
|
1432
|
-
if (!entry) {
|
|
1433
|
-
return [];
|
|
1434
|
-
}
|
|
1435
|
-
const moduleExports = require2(entry);
|
|
1436
|
-
if (!moduleExports) {
|
|
1437
|
-
return [];
|
|
1438
|
-
}
|
|
1439
|
-
const ref = moduleExports[refProperty];
|
|
1440
|
-
if (!ref) {
|
|
1441
|
-
return [];
|
|
1442
|
-
}
|
|
1443
|
-
if (Array.isArray(ref)) {
|
|
1444
|
-
return ref;
|
|
1445
|
-
}
|
|
1446
|
-
if (typeof ref === "object" && Array.isArray(ref.value)) {
|
|
1447
|
-
return ref.value;
|
|
1448
|
-
}
|
|
1449
|
-
return [];
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
// src/runtime/process-tailwindcss.ts
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
1456
|
-
var _tailwindcssconfig = require('tailwindcss-config');
|
|
1457
|
-
var require3 = _module.createRequire.call(void 0, importMetaUrl);
|
|
1458
|
-
async function resolveConfigPath(options) {
|
|
1459
|
-
if (options.config && _pathe2.default.isAbsolute(options.config)) {
|
|
1460
|
-
return options.config;
|
|
1461
|
-
}
|
|
1462
|
-
const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
|
|
1463
|
-
if (!result) {
|
|
1464
|
-
throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
|
|
1465
|
-
}
|
|
1466
|
-
return result.filepath;
|
|
1467
|
-
}
|
|
1468
|
-
async function runTailwindBuild(options) {
|
|
1469
|
-
const configPath = await resolveConfigPath(options);
|
|
1470
|
-
const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
|
|
1471
|
-
if (options.majorVersion === 4) {
|
|
1472
|
-
return _postcss2.default.call(void 0, [
|
|
1473
|
-
require3(pluginName)({
|
|
1474
|
-
config: configPath
|
|
1475
|
-
})
|
|
1476
|
-
]).process("@import 'tailwindcss';", {
|
|
1477
|
-
from: void 0
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
return _postcss2.default.call(void 0, [
|
|
1481
|
-
require3(pluginName)({
|
|
1482
|
-
config: configPath
|
|
1483
|
-
})
|
|
1484
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
1485
|
-
from: void 0
|
|
1486
|
-
});
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
// src/api/tailwindcss-patcher.ts
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
var _localpkg = require('local-pkg');
|
|
1493
|
-
|
|
1494
|
-
var _semver = require('semver');
|
|
1495
|
-
|
|
1496
|
-
// src/options/legacy.ts
|
|
1497
|
-
function normalizeLegacyFeatures(patch) {
|
|
1498
|
-
const apply = _optionalChain([patch, 'optionalAccess', _47 => _47.applyPatches]);
|
|
1499
|
-
const extend = _optionalChain([apply, 'optionalAccess', _48 => _48.extendLengthUnits]);
|
|
1500
|
-
let extendOption = false;
|
|
1501
|
-
if (extend && typeof extend === "object") {
|
|
1502
|
-
extendOption = {
|
|
1503
|
-
...extend,
|
|
1504
|
-
enabled: true
|
|
1505
|
-
};
|
|
1506
|
-
} else if (extend === true) {
|
|
1507
|
-
extendOption = {
|
|
1508
|
-
enabled: true,
|
|
1509
|
-
units: ["rpx"],
|
|
1510
|
-
overwrite: _optionalChain([patch, 'optionalAccess', _49 => _49.overwrite])
|
|
1511
|
-
};
|
|
1512
|
-
}
|
|
1513
|
-
return {
|
|
1514
|
-
exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _50 => _50.exportContext]), () => ( true)),
|
|
1515
|
-
extendLengthUnits: extendOption
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
function fromLegacyOptions(options) {
|
|
1519
|
-
if (!options) {
|
|
1520
|
-
return {};
|
|
1521
|
-
}
|
|
1522
|
-
const patch = options.patch;
|
|
1523
|
-
const features = normalizeLegacyFeatures(patch);
|
|
1524
|
-
const output = _optionalChain([patch, 'optionalAccess', _51 => _51.output]);
|
|
1525
|
-
const tailwindConfig = _optionalChain([patch, 'optionalAccess', _52 => _52.tailwindcss]);
|
|
1526
|
-
const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _53 => _53.version]);
|
|
1527
|
-
const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _54 => _54.v2]);
|
|
1528
|
-
const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _55 => _55.v3]);
|
|
1529
|
-
const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _56 => _56.v4]);
|
|
1530
|
-
const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _57 => _57.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _58 => _58.config])));
|
|
1531
|
-
const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _59 => _59.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _60 => _60.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _61 => _61.cwd])));
|
|
1532
|
-
return {
|
|
1533
|
-
cwd: _optionalChain([patch, 'optionalAccess', _62 => _62.cwd]),
|
|
1534
|
-
overwrite: _optionalChain([patch, 'optionalAccess', _63 => _63.overwrite]),
|
|
1535
|
-
filter: _optionalChain([patch, 'optionalAccess', _64 => _64.filter]),
|
|
1536
|
-
cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
|
|
1537
|
-
...options.cache,
|
|
1538
|
-
enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
|
|
1539
|
-
} : void 0,
|
|
1540
|
-
output: output ? {
|
|
1541
|
-
file: output.filename,
|
|
1542
|
-
pretty: output.loose ? 2 : false,
|
|
1543
|
-
removeUniversalSelector: output.removeUniversalSelector
|
|
1544
|
-
} : void 0,
|
|
1545
|
-
tailwind: {
|
|
1546
|
-
packageName: _optionalChain([patch, 'optionalAccess', _65 => _65.packageName]),
|
|
1547
|
-
version: tailwindVersion,
|
|
1548
|
-
resolve: _optionalChain([patch, 'optionalAccess', _66 => _66.resolve]),
|
|
1549
|
-
config: tailwindConfigPath,
|
|
1550
|
-
cwd: tailwindCwd,
|
|
1551
|
-
v2: tailwindV2,
|
|
1552
|
-
v3: tailwindV3,
|
|
1553
|
-
v4: tailwindV4
|
|
1554
|
-
},
|
|
1555
|
-
features: {
|
|
1556
|
-
exposeContext: features.exposeContext,
|
|
1557
|
-
extendLengthUnits: features.extendLengthUnits
|
|
1558
|
-
}
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
function fromUnifiedConfig(registry) {
|
|
1562
|
-
if (!registry) {
|
|
1563
|
-
return {};
|
|
1564
|
-
}
|
|
1565
|
-
const tailwind = registry.tailwind;
|
|
1566
|
-
const output = registry.output;
|
|
1567
|
-
const pretty = (() => {
|
|
1568
|
-
if (_optionalChain([output, 'optionalAccess', _67 => _67.pretty]) === void 0) {
|
|
1569
|
-
return void 0;
|
|
1570
|
-
}
|
|
1571
|
-
if (typeof output.pretty === "boolean") {
|
|
1572
|
-
return output.pretty ? 2 : false;
|
|
1573
|
-
}
|
|
1574
|
-
return output.pretty;
|
|
1575
|
-
})();
|
|
1576
|
-
return {
|
|
1577
|
-
output: output ? {
|
|
1578
|
-
file: output.file,
|
|
1579
|
-
pretty,
|
|
1580
|
-
removeUniversalSelector: output.stripUniversalSelector
|
|
1581
|
-
} : void 0,
|
|
1582
|
-
tailwind: tailwind ? {
|
|
1583
|
-
version: tailwind.version,
|
|
1584
|
-
packageName: tailwind.package,
|
|
1585
|
-
resolve: tailwind.resolve,
|
|
1586
|
-
config: tailwind.config,
|
|
1587
|
-
cwd: tailwind.cwd,
|
|
1588
|
-
v2: tailwind.legacy,
|
|
1589
|
-
v3: tailwind.classic,
|
|
1590
|
-
v4: tailwind.next
|
|
1591
|
-
} : void 0
|
|
1592
|
-
};
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
// src/patching/operations/export-context/index.ts
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
function writeFileIfRequired(filePath, code, overwrite, successMessage) {
|
|
1599
|
-
if (!overwrite) {
|
|
1600
|
-
return;
|
|
1601
|
-
}
|
|
1602
|
-
_fsextra2.default.writeFileSync(filePath, code, {
|
|
1603
|
-
encoding: "utf8"
|
|
1604
|
-
});
|
|
1605
|
-
logger_default.success(successMessage);
|
|
1606
|
-
}
|
|
1607
|
-
function applyExposeContextPatch(params) {
|
|
1608
|
-
const { rootDir, refProperty, overwrite, majorVersion } = params;
|
|
1609
|
-
const result = {
|
|
1610
|
-
applied: false,
|
|
1611
|
-
files: {}
|
|
1612
|
-
};
|
|
1613
|
-
if (majorVersion === 3) {
|
|
1614
|
-
const processFileRelative = "lib/processTailwindFeatures.js";
|
|
1615
|
-
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
1616
|
-
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
1617
|
-
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
1618
|
-
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContext(content);
|
|
1619
|
-
result.files[processFileRelative] = code;
|
|
1620
|
-
if (!hasPatched) {
|
|
1621
|
-
writeFileIfRequired(
|
|
1622
|
-
processFilePath,
|
|
1623
|
-
code,
|
|
1624
|
-
overwrite,
|
|
1625
|
-
"Patched Tailwind CSS processTailwindFeatures to expose runtime context."
|
|
1626
|
-
);
|
|
1627
|
-
result.applied = true;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
|
|
1631
|
-
const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(rootDir, candidate)));
|
|
1632
|
-
if (pluginRelative) {
|
|
1633
|
-
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
1634
|
-
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
1635
|
-
const { code, hasPatched } = transformPostcssPlugin(content, { refProperty });
|
|
1636
|
-
result.files[pluginRelative] = code;
|
|
1637
|
-
if (!hasPatched) {
|
|
1638
|
-
writeFileIfRequired(
|
|
1639
|
-
pluginPath,
|
|
1640
|
-
code,
|
|
1641
|
-
overwrite,
|
|
1642
|
-
"Patched Tailwind CSS plugin entry to collect runtime contexts."
|
|
1643
|
-
);
|
|
1644
|
-
result.applied = true;
|
|
1645
|
-
}
|
|
1646
|
-
}
|
|
1647
|
-
} else if (majorVersion === 2) {
|
|
1648
|
-
const processFileRelative = "lib/jit/processTailwindFeatures.js";
|
|
1649
|
-
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
1650
|
-
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
1651
|
-
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
1652
|
-
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContextV2(content);
|
|
1653
|
-
result.files[processFileRelative] = code;
|
|
1654
|
-
if (!hasPatched) {
|
|
1655
|
-
writeFileIfRequired(
|
|
1656
|
-
processFilePath,
|
|
1657
|
-
code,
|
|
1658
|
-
overwrite,
|
|
1659
|
-
"Patched Tailwind CSS JIT processTailwindFeatures to expose runtime context."
|
|
1660
|
-
);
|
|
1661
|
-
result.applied = true;
|
|
1662
|
-
}
|
|
1663
|
-
}
|
|
1664
|
-
const pluginRelative = "lib/jit/index.js";
|
|
1665
|
-
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
1666
|
-
if (_fsextra2.default.existsSync(pluginPath)) {
|
|
1667
|
-
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
1668
|
-
const { code, hasPatched } = transformPostcssPluginV2(content, { refProperty });
|
|
1669
|
-
result.files[pluginRelative] = code;
|
|
1670
|
-
if (!hasPatched) {
|
|
1671
|
-
writeFileIfRequired(
|
|
1672
|
-
pluginPath,
|
|
1673
|
-
code,
|
|
1674
|
-
overwrite,
|
|
1675
|
-
"Patched Tailwind CSS JIT entry to collect runtime contexts."
|
|
1676
|
-
);
|
|
1677
|
-
result.applied = true;
|
|
1678
|
-
}
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
return result;
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
// src/patching/patch-runner.ts
|
|
1685
|
-
function applyTailwindPatches(context) {
|
|
1686
|
-
const { packageInfo, options, majorVersion } = context;
|
|
1687
|
-
const results = {};
|
|
1688
|
-
if (options.features.exposeContext.enabled && (majorVersion === 2 || majorVersion === 3)) {
|
|
1689
|
-
results.exposeContext = applyExposeContextPatch({
|
|
1690
|
-
rootDir: packageInfo.rootPath,
|
|
1691
|
-
refProperty: options.features.exposeContext.refProperty,
|
|
1692
|
-
overwrite: options.overwrite,
|
|
1693
|
-
majorVersion
|
|
1694
|
-
});
|
|
1695
|
-
}
|
|
1696
|
-
if (_optionalChain([options, 'access', _68 => _68.features, 'access', _69 => _69.extendLengthUnits, 'optionalAccess', _70 => _70.enabled])) {
|
|
1697
|
-
if (majorVersion === 3) {
|
|
1698
|
-
results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
|
|
1699
|
-
packageInfo.rootPath,
|
|
1700
|
-
options.features.extendLengthUnits
|
|
1701
|
-
);
|
|
1702
|
-
} else if (majorVersion === 4) {
|
|
1703
|
-
results.extendLengthUnits = applyExtendLengthUnitsPatchV4(
|
|
1704
|
-
packageInfo.rootPath,
|
|
1705
|
-
options.features.extendLengthUnits
|
|
1706
|
-
);
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
return results;
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
// src/api/tailwindcss-patcher.ts
|
|
1713
|
-
function resolveMajorVersion(version, hint) {
|
|
1714
|
-
if (hint && [2, 3, 4].includes(hint)) {
|
|
1715
|
-
return hint;
|
|
1716
|
-
}
|
|
1717
|
-
if (version) {
|
|
1718
|
-
const coerced = _semver.coerce.call(void 0, version);
|
|
1719
|
-
if (coerced) {
|
|
1720
|
-
const major = coerced.major;
|
|
1721
|
-
if (major === 2 || major === 3 || major === 4) {
|
|
1722
|
-
return major;
|
|
1723
|
-
}
|
|
1724
|
-
if (major >= 4) {
|
|
1725
|
-
return 4;
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
}
|
|
1729
|
-
return 3;
|
|
1730
|
-
}
|
|
1731
|
-
function resolveTailwindExecutionOptions(normalized, majorVersion) {
|
|
1732
|
-
const base = normalized.tailwind;
|
|
1733
|
-
if (majorVersion === 2 && base.v2) {
|
|
1734
|
-
return {
|
|
1735
|
-
cwd: _nullishCoalesce(_nullishCoalesce(base.v2.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
1736
|
-
config: _nullishCoalesce(base.v2.config, () => ( base.config)),
|
|
1737
|
-
postcssPlugin: _nullishCoalesce(base.v2.postcssPlugin, () => ( base.postcssPlugin))
|
|
1738
|
-
};
|
|
1739
|
-
}
|
|
1740
|
-
if (majorVersion === 3 && base.v3) {
|
|
1741
|
-
return {
|
|
1742
|
-
cwd: _nullishCoalesce(_nullishCoalesce(base.v3.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
1743
|
-
config: _nullishCoalesce(base.v3.config, () => ( base.config)),
|
|
1744
|
-
postcssPlugin: _nullishCoalesce(base.v3.postcssPlugin, () => ( base.postcssPlugin))
|
|
1745
|
-
};
|
|
1746
|
-
}
|
|
1747
|
-
return {
|
|
1748
|
-
cwd: _nullishCoalesce(base.cwd, () => ( normalized.projectRoot)),
|
|
1749
|
-
config: base.config,
|
|
1750
|
-
postcssPlugin: base.postcssPlugin
|
|
1751
|
-
};
|
|
1752
|
-
}
|
|
1753
|
-
var TailwindcssPatcher = (_class2 = class {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
constructor(options = {}) {;_class2.prototype.__init2.call(this);
|
|
1759
|
-
const resolvedOptions = options && typeof options === "object" && "patch" in options ? fromLegacyOptions(options) : options;
|
|
1760
|
-
this.options = normalizeOptions(resolvedOptions);
|
|
1761
|
-
const packageInfo = _localpkg.getPackageInfoSync.call(void 0,
|
|
1762
|
-
this.options.tailwind.packageName,
|
|
1763
|
-
this.options.tailwind.resolve
|
|
1764
|
-
);
|
|
1765
|
-
if (!packageInfo) {
|
|
1766
|
-
throw new Error(`Unable to locate Tailwind CSS package "${this.options.tailwind.packageName}".`);
|
|
1767
|
-
}
|
|
1768
|
-
this.packageInfo = packageInfo;
|
|
1769
|
-
this.majorVersion = resolveMajorVersion(
|
|
1770
|
-
this.packageInfo.version,
|
|
1771
|
-
this.options.tailwind.versionHint
|
|
1772
|
-
);
|
|
1773
|
-
this.cacheStore = new CacheStore(this.options.cache);
|
|
1774
|
-
}
|
|
1775
|
-
async patch() {
|
|
1776
|
-
return applyTailwindPatches({
|
|
1777
|
-
packageInfo: this.packageInfo,
|
|
1778
|
-
options: this.options,
|
|
1779
|
-
majorVersion: this.majorVersion
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
async getPatchStatus() {
|
|
1783
|
-
return getPatchStatusReport({
|
|
1784
|
-
packageInfo: this.packageInfo,
|
|
1785
|
-
options: this.options,
|
|
1786
|
-
majorVersion: this.majorVersion
|
|
1787
|
-
});
|
|
1788
|
-
}
|
|
1789
|
-
getContexts() {
|
|
1790
|
-
return loadRuntimeContexts(
|
|
1791
|
-
this.packageInfo,
|
|
1792
|
-
this.majorVersion,
|
|
1793
|
-
this.options.features.exposeContext.refProperty
|
|
1794
|
-
);
|
|
1795
|
-
}
|
|
1796
|
-
async runTailwindBuildIfNeeded() {
|
|
1797
|
-
if (this.majorVersion === 2 || this.majorVersion === 3) {
|
|
1798
|
-
const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
|
|
1799
|
-
await runTailwindBuild({
|
|
1800
|
-
cwd: executionOptions.cwd,
|
|
1801
|
-
config: executionOptions.config,
|
|
1802
|
-
majorVersion: this.majorVersion,
|
|
1803
|
-
postcssPlugin: executionOptions.postcssPlugin
|
|
1804
|
-
});
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
async collectClassSet() {
|
|
1808
|
-
if (this.majorVersion === 4) {
|
|
1809
|
-
return collectClassesFromTailwindV4(this.options);
|
|
1810
|
-
}
|
|
1811
|
-
const contexts = this.getContexts();
|
|
1812
|
-
return collectClassesFromContexts(contexts, this.options.filter);
|
|
1813
|
-
}
|
|
1814
|
-
async mergeWithCache(set) {
|
|
1815
|
-
if (!this.options.cache.enabled) {
|
|
1816
|
-
return set;
|
|
1817
|
-
}
|
|
1818
|
-
const existing = await this.cacheStore.read();
|
|
1819
|
-
if (this.options.cache.strategy === "merge") {
|
|
1820
|
-
for (const value of existing) {
|
|
1821
|
-
set.add(value);
|
|
1822
|
-
}
|
|
1823
|
-
await this.cacheStore.write(set);
|
|
1824
|
-
} else {
|
|
1825
|
-
if (set.size > 0) {
|
|
1826
|
-
await this.cacheStore.write(set);
|
|
1827
|
-
} else {
|
|
1828
|
-
return existing;
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1831
|
-
return set;
|
|
1832
|
-
}
|
|
1833
|
-
mergeWithCacheSync(set) {
|
|
1834
|
-
if (!this.options.cache.enabled) {
|
|
1835
|
-
return set;
|
|
1836
|
-
}
|
|
1837
|
-
const existing = this.cacheStore.readSync();
|
|
1838
|
-
if (this.options.cache.strategy === "merge") {
|
|
1839
|
-
for (const value of existing) {
|
|
1840
|
-
set.add(value);
|
|
1841
|
-
}
|
|
1842
|
-
this.cacheStore.writeSync(set);
|
|
1843
|
-
} else {
|
|
1844
|
-
if (set.size > 0) {
|
|
1845
|
-
this.cacheStore.writeSync(set);
|
|
1846
|
-
} else {
|
|
1847
|
-
return existing;
|
|
1848
|
-
}
|
|
1849
|
-
}
|
|
1850
|
-
return set;
|
|
1851
|
-
}
|
|
1852
|
-
async getClassSet() {
|
|
1853
|
-
await this.runTailwindBuildIfNeeded();
|
|
1854
|
-
const set = await this.collectClassSet();
|
|
1855
|
-
return this.mergeWithCache(set);
|
|
1856
|
-
}
|
|
1857
|
-
getClassSetSync() {
|
|
1858
|
-
if (this.majorVersion === 4) {
|
|
1859
|
-
throw new Error("getClassSetSync is not supported for Tailwind CSS v4 projects. Use getClassSet instead.");
|
|
1860
|
-
}
|
|
1861
|
-
const contexts = this.getContexts();
|
|
1862
|
-
const set = collectClassesFromContexts(contexts, this.options.filter);
|
|
1863
|
-
const merged = this.mergeWithCacheSync(set);
|
|
1864
|
-
if (contexts.length === 0 && merged.size === 0) {
|
|
1865
|
-
return void 0;
|
|
1866
|
-
}
|
|
1867
|
-
return merged;
|
|
1868
|
-
}
|
|
1869
|
-
async extract(options) {
|
|
1870
|
-
const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.write]), () => ( this.options.output.enabled));
|
|
1871
|
-
const classSet = await this.getClassSet();
|
|
1872
|
-
const classList = Array.from(classSet);
|
|
1873
|
-
const result = {
|
|
1874
|
-
classList,
|
|
1875
|
-
classSet
|
|
1876
|
-
};
|
|
1877
|
-
if (!shouldWrite || !this.options.output.file) {
|
|
1878
|
-
return result;
|
|
1879
|
-
}
|
|
1880
|
-
const target = _pathe2.default.resolve(this.options.output.file);
|
|
1881
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
1882
|
-
if (this.options.output.format === "json") {
|
|
1883
|
-
const spaces = typeof this.options.output.pretty === "number" ? this.options.output.pretty : void 0;
|
|
1884
|
-
await _fsextra2.default.writeJSON(target, classList, { spaces });
|
|
1885
|
-
} else {
|
|
1886
|
-
await _fsextra2.default.writeFile(target, `${classList.join("\n")}
|
|
1887
|
-
`, "utf8");
|
|
1888
|
-
}
|
|
1889
|
-
logger_default.success(`Tailwind CSS class list saved to ${target.replace(_process2.default.cwd(), ".")}`);
|
|
1890
|
-
return {
|
|
1891
|
-
...result,
|
|
1892
|
-
filename: target
|
|
1893
|
-
};
|
|
1894
|
-
}
|
|
1895
|
-
// Backwards compatibility helper used by tests and API consumers.
|
|
1896
|
-
__init2() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
|
|
1897
|
-
async collectContentTokens(options) {
|
|
1898
|
-
return extractProjectCandidatesWithPositions({
|
|
1899
|
-
cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.cwd]), () => ( this.options.projectRoot)),
|
|
1900
|
-
sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.sources]), () => ( _optionalChain([this, 'access', _74 => _74.options, 'access', _75 => _75.tailwind, 'access', _76 => _76.v4, 'optionalAccess', _77 => _77.sources]))), () => ( []))
|
|
1901
|
-
});
|
|
1902
|
-
}
|
|
1903
|
-
async collectContentTokensByFile(options) {
|
|
1904
|
-
const report = await this.collectContentTokens({
|
|
1905
|
-
cwd: _optionalChain([options, 'optionalAccess', _78 => _78.cwd]),
|
|
1906
|
-
sources: _optionalChain([options, 'optionalAccess', _79 => _79.sources])
|
|
1907
|
-
});
|
|
1908
|
-
return groupTokensByFile(report, {
|
|
1909
|
-
key: _optionalChain([options, 'optionalAccess', _80 => _80.key]),
|
|
1910
|
-
stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _81 => _81.stripAbsolutePaths])
|
|
1911
|
-
});
|
|
1912
|
-
}
|
|
1913
|
-
}, _class2);
|
|
1914
|
-
|
|
1915
|
-
// src/cli/commands.ts
|
|
1916
|
-
|
|
1917
|
-
var _config = require('@tailwindcss-mangle/config');
|
|
1918
|
-
|
|
1919
|
-
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
1920
|
-
function isPlainObject(value) {
|
|
1921
|
-
if (value === null || typeof value !== "object") {
|
|
1922
|
-
return false;
|
|
1923
|
-
}
|
|
1924
|
-
const prototype = Object.getPrototypeOf(value);
|
|
1925
|
-
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
1926
|
-
return false;
|
|
1927
|
-
}
|
|
1928
|
-
if (Symbol.iterator in value) {
|
|
1929
|
-
return false;
|
|
1930
|
-
}
|
|
1931
|
-
if (Symbol.toStringTag in value) {
|
|
1932
|
-
return Object.prototype.toString.call(value) === "[object Module]";
|
|
1933
|
-
}
|
|
1934
|
-
return true;
|
|
1935
|
-
}
|
|
1936
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
1937
|
-
if (!isPlainObject(defaults)) {
|
|
1938
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
1939
|
-
}
|
|
1940
|
-
const object = Object.assign({}, defaults);
|
|
1941
|
-
for (const key in baseObject) {
|
|
1942
|
-
if (key === "__proto__" || key === "constructor") {
|
|
1943
|
-
continue;
|
|
1944
|
-
}
|
|
1945
|
-
const value = baseObject[key];
|
|
1946
|
-
if (value === null || value === void 0) {
|
|
1947
|
-
continue;
|
|
1948
|
-
}
|
|
1949
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
1950
|
-
continue;
|
|
1951
|
-
}
|
|
1952
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
1953
|
-
object[key] = [...value, ...object[key]];
|
|
1954
|
-
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
1955
|
-
object[key] = _defu(
|
|
1956
|
-
value,
|
|
1957
|
-
object[key],
|
|
1958
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
1959
|
-
merger
|
|
1960
|
-
);
|
|
1961
|
-
} else {
|
|
1962
|
-
object[key] = value;
|
|
1963
|
-
}
|
|
1964
|
-
}
|
|
1965
|
-
return object;
|
|
1966
|
-
}
|
|
1967
|
-
function createDefu(merger) {
|
|
1968
|
-
return (...arguments_) => (
|
|
1969
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
1970
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
1971
|
-
);
|
|
1972
|
-
}
|
|
1973
|
-
var defu = createDefu();
|
|
1974
|
-
var defuFn = createDefu((object, key, currentValue) => {
|
|
1975
|
-
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
1976
|
-
object[key] = currentValue(object[key]);
|
|
1977
|
-
return true;
|
|
1978
|
-
}
|
|
1979
|
-
});
|
|
1980
|
-
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
1981
|
-
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
1982
|
-
object[key] = currentValue(object[key]);
|
|
1983
|
-
return true;
|
|
1984
|
-
}
|
|
1985
|
-
});
|
|
1986
|
-
|
|
1987
|
-
// ../shared/src/utils.ts
|
|
1988
|
-
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
1989
|
-
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
1990
|
-
obj[key] = value;
|
|
1991
|
-
return true;
|
|
1992
|
-
}
|
|
1993
|
-
});
|
|
1994
|
-
var preserveClassNames = [
|
|
1995
|
-
// https://tailwindcss.com/docs/transition-timing-function start
|
|
1996
|
-
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
1997
|
-
"ease-out",
|
|
1998
|
-
"ease-linear",
|
|
1999
|
-
"ease-in",
|
|
2000
|
-
"ease-in-out"
|
|
2001
|
-
// https://tailwindcss.com/docs/transition-timing-function end
|
|
2002
|
-
];
|
|
2003
|
-
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
2004
|
-
acc[cur] = true;
|
|
2005
|
-
return acc;
|
|
2006
|
-
}, {});
|
|
2007
|
-
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
2008
|
-
|
|
2009
|
-
// src/cli/commands.ts
|
|
2010
|
-
var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "status"];
|
|
2014
|
-
var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
2015
|
-
var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
|
|
2016
|
-
function formatTokenLine(entry) {
|
|
2017
|
-
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
2018
|
-
}
|
|
2019
|
-
function formatGroupedPreview(map, limit = 3) {
|
|
2020
|
-
const files = Object.keys(map);
|
|
2021
|
-
if (!files.length) {
|
|
2022
|
-
return { preview: "", moreFiles: 0 };
|
|
2023
|
-
}
|
|
2024
|
-
const lines = files.slice(0, limit).map((file) => {
|
|
2025
|
-
const tokens = map[file];
|
|
2026
|
-
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
2027
|
-
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
2028
|
-
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
2029
|
-
});
|
|
2030
|
-
return {
|
|
2031
|
-
preview: lines.join("\n"),
|
|
2032
|
-
moreFiles: Math.max(0, files.length - limit)
|
|
2033
|
-
};
|
|
2034
|
-
}
|
|
2035
|
-
function resolveCwd(rawCwd) {
|
|
2036
|
-
if (!rawCwd) {
|
|
2037
|
-
return _process2.default.cwd();
|
|
2038
|
-
}
|
|
2039
|
-
return _pathe2.default.resolve(rawCwd);
|
|
2040
|
-
}
|
|
2041
|
-
function createDefaultRunner(factory) {
|
|
2042
|
-
let promise;
|
|
2043
|
-
return () => {
|
|
2044
|
-
if (!promise) {
|
|
2045
|
-
promise = factory();
|
|
2046
|
-
}
|
|
2047
|
-
return promise;
|
|
2048
|
-
};
|
|
2049
|
-
}
|
|
2050
|
-
async function loadPatchOptionsForCwd(cwd, overrides) {
|
|
2051
|
-
const { config } = await _config.getConfig.call(void 0, cwd);
|
|
2052
|
-
const legacyConfig = config;
|
|
2053
|
-
const base = _optionalChain([config, 'optionalAccess', _82 => _82.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _83 => _83.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
|
|
2054
|
-
const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
|
|
2055
|
-
return merged;
|
|
2056
|
-
}
|
|
2057
|
-
function createCommandContext(cli, command, commandName, args, cwd) {
|
|
2058
|
-
let cachedOptions;
|
|
2059
|
-
let cachedPatcher;
|
|
2060
|
-
let cachedConfig;
|
|
2061
|
-
const loadPatchOptionsForContext = (overrides) => {
|
|
2062
|
-
if (overrides) {
|
|
2063
|
-
return loadPatchOptionsForCwd(cwd, overrides);
|
|
2064
|
-
}
|
|
2065
|
-
if (!cachedOptions) {
|
|
2066
|
-
cachedOptions = loadPatchOptionsForCwd(cwd);
|
|
2067
|
-
}
|
|
2068
|
-
return cachedOptions;
|
|
2069
|
-
};
|
|
2070
|
-
const createPatcherForContext = async (overrides) => {
|
|
2071
|
-
if (overrides) {
|
|
2072
|
-
const patchOptions = await loadPatchOptionsForCwd(cwd, overrides);
|
|
2073
|
-
return new TailwindcssPatcher(patchOptions);
|
|
2074
|
-
}
|
|
2075
|
-
if (!cachedPatcher) {
|
|
2076
|
-
cachedPatcher = loadPatchOptionsForContext().then((options) => new TailwindcssPatcher(options));
|
|
2077
|
-
}
|
|
2078
|
-
return cachedPatcher;
|
|
2079
|
-
};
|
|
2080
|
-
return {
|
|
2081
|
-
cli,
|
|
2082
|
-
command,
|
|
2083
|
-
commandName,
|
|
2084
|
-
args,
|
|
2085
|
-
cwd,
|
|
2086
|
-
logger: logger_default,
|
|
2087
|
-
loadConfig: () => {
|
|
2088
|
-
if (!cachedConfig) {
|
|
2089
|
-
cachedConfig = _config.getConfig.call(void 0, cwd);
|
|
2090
|
-
}
|
|
2091
|
-
return cachedConfig;
|
|
2092
|
-
},
|
|
2093
|
-
loadPatchOptions: loadPatchOptionsForContext,
|
|
2094
|
-
createPatcher: createPatcherForContext
|
|
2095
|
-
};
|
|
2096
|
-
}
|
|
2097
|
-
function createCwdOptionDefinition(description = "Working directory") {
|
|
2098
|
-
return {
|
|
2099
|
-
flags: "--cwd <dir>",
|
|
2100
|
-
description,
|
|
2101
|
-
config: { default: _process2.default.cwd() }
|
|
2102
|
-
};
|
|
2103
|
-
}
|
|
2104
|
-
function buildDefaultCommandDefinitions() {
|
|
2105
|
-
return {
|
|
2106
|
-
install: {
|
|
2107
|
-
description: "Apply Tailwind CSS runtime patches",
|
|
2108
|
-
optionDefs: [createCwdOptionDefinition()]
|
|
2109
|
-
},
|
|
2110
|
-
extract: {
|
|
2111
|
-
description: "Collect generated class names into a cache file",
|
|
2112
|
-
optionDefs: [
|
|
2113
|
-
createCwdOptionDefinition(),
|
|
2114
|
-
{ flags: "--output <file>", description: "Override output file path" },
|
|
2115
|
-
{ flags: "--format <format>", description: "Output format (json|lines)" },
|
|
2116
|
-
{ flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
|
|
2117
|
-
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
2118
|
-
]
|
|
2119
|
-
},
|
|
2120
|
-
tokens: {
|
|
2121
|
-
description: "Extract Tailwind tokens with file/position metadata",
|
|
2122
|
-
optionDefs: [
|
|
2123
|
-
createCwdOptionDefinition(),
|
|
2124
|
-
{ flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
|
|
2125
|
-
{
|
|
2126
|
-
flags: "--format <format>",
|
|
2127
|
-
description: "Output format (json|lines|grouped-json)",
|
|
2128
|
-
config: { default: "json" }
|
|
2129
|
-
},
|
|
2130
|
-
{
|
|
2131
|
-
flags: "--group-key <key>",
|
|
2132
|
-
description: "Grouping key for grouped-json output (relative|absolute)",
|
|
2133
|
-
config: { default: "relative" }
|
|
2134
|
-
},
|
|
2135
|
-
{ flags: "--no-write", description: "Skip writing to disk" }
|
|
2136
|
-
]
|
|
2137
|
-
},
|
|
2138
|
-
init: {
|
|
2139
|
-
description: "Generate a tailwindcss-patch config file",
|
|
2140
|
-
optionDefs: [createCwdOptionDefinition()]
|
|
2141
|
-
},
|
|
2142
|
-
status: {
|
|
2143
|
-
description: "Check which Tailwind patches are applied",
|
|
2144
|
-
optionDefs: [
|
|
2145
|
-
createCwdOptionDefinition(),
|
|
2146
|
-
{ flags: "--json", description: "Print a JSON report of patch status" }
|
|
2147
|
-
]
|
|
2148
|
-
}
|
|
2149
|
-
};
|
|
2150
|
-
}
|
|
2151
|
-
function addPrefixIfMissing(value, prefix) {
|
|
2152
|
-
if (!prefix || value.startsWith(prefix)) {
|
|
2153
|
-
return value;
|
|
2154
|
-
}
|
|
2155
|
-
return `${prefix}${value}`;
|
|
2156
|
-
}
|
|
2157
|
-
function resolveCommandNames(command, mountOptions, prefix) {
|
|
2158
|
-
const override = _optionalChain([mountOptions, 'access', _84 => _84.commandOptions, 'optionalAccess', _85 => _85[command]]);
|
|
2159
|
-
const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _86 => _86.name]), () => ( command));
|
|
2160
|
-
const name = addPrefixIfMissing(baseName, prefix);
|
|
2161
|
-
const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
2162
|
-
return { name, aliases };
|
|
2163
|
-
}
|
|
2164
|
-
function resolveOptionDefinitions(defaults, override) {
|
|
2165
|
-
if (!override) {
|
|
2166
|
-
return defaults;
|
|
2167
|
-
}
|
|
2168
|
-
const appendDefaults = _nullishCoalesce(override.appendDefaultOptions, () => ( true));
|
|
2169
|
-
const customDefs = _nullishCoalesce(override.optionDefs, () => ( []));
|
|
2170
|
-
if (!appendDefaults) {
|
|
2171
|
-
return customDefs;
|
|
2172
|
-
}
|
|
2173
|
-
if (customDefs.length === 0) {
|
|
2174
|
-
return defaults;
|
|
2175
|
-
}
|
|
2176
|
-
return [...defaults, ...customDefs];
|
|
2177
|
-
}
|
|
2178
|
-
function applyCommandOptions(command, optionDefs) {
|
|
2179
|
-
for (const option of optionDefs) {
|
|
2180
|
-
command.option(option.flags, _nullishCoalesce(option.description, () => ( "")), option.config);
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
|
|
2184
|
-
const cwd = resolveCwd(args.cwd);
|
|
2185
|
-
const context = createCommandContext(cli, command, commandName, args, cwd);
|
|
2186
|
-
const runDefault = createDefaultRunner(() => defaultHandler(context));
|
|
2187
|
-
if (!handler) {
|
|
2188
|
-
return runDefault();
|
|
2189
|
-
}
|
|
2190
|
-
return handler(context, runDefault);
|
|
2191
|
-
}
|
|
2192
|
-
function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
|
|
2193
|
-
const names = resolveCommandNames(command, mountOptions, prefix);
|
|
2194
|
-
const definition = defaults[command];
|
|
2195
|
-
const override = _optionalChain([mountOptions, 'access', _88 => _88.commandOptions, 'optionalAccess', _89 => _89[command]]);
|
|
2196
|
-
const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _90 => _90.description]), () => ( definition.description));
|
|
2197
|
-
const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
|
|
2198
|
-
return { ...names, description, optionDefs };
|
|
2199
|
-
}
|
|
2200
|
-
async function installCommandDefaultHandler(ctx) {
|
|
2201
|
-
const patcher = await ctx.createPatcher();
|
|
2202
|
-
await patcher.patch();
|
|
2203
|
-
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
2204
|
-
}
|
|
2205
|
-
async function extractCommandDefaultHandler(ctx) {
|
|
2206
|
-
const { args } = ctx;
|
|
2207
|
-
const overrides = {};
|
|
2208
|
-
let hasOverrides = false;
|
|
2209
|
-
if (args.output || args.format) {
|
|
2210
|
-
overrides.output = {
|
|
2211
|
-
file: args.output,
|
|
2212
|
-
format: args.format
|
|
2213
|
-
};
|
|
2214
|
-
hasOverrides = true;
|
|
2215
|
-
}
|
|
2216
|
-
if (args.css) {
|
|
2217
|
-
overrides.tailwind = {
|
|
2218
|
-
v4: {
|
|
2219
|
-
cssEntries: [args.css]
|
|
2220
|
-
}
|
|
2221
|
-
};
|
|
2222
|
-
hasOverrides = true;
|
|
2223
|
-
}
|
|
2224
|
-
const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
|
|
2225
|
-
const result = await patcher.extract({ write: args.write });
|
|
2226
|
-
if (result.filename) {
|
|
2227
|
-
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
2228
|
-
} else {
|
|
2229
|
-
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
2230
|
-
}
|
|
2231
|
-
return result;
|
|
2232
|
-
}
|
|
2233
|
-
async function tokensCommandDefaultHandler(ctx) {
|
|
2234
|
-
const { args } = ctx;
|
|
2235
|
-
const patcher = await ctx.createPatcher();
|
|
2236
|
-
const report = await patcher.collectContentTokens();
|
|
2237
|
-
const shouldWrite = _nullishCoalesce(args.write, () => ( true));
|
|
2238
|
-
let format = _nullishCoalesce(args.format, () => ( "json"));
|
|
2239
|
-
if (!TOKEN_FORMATS.includes(format)) {
|
|
2240
|
-
format = "json";
|
|
2241
|
-
}
|
|
2242
|
-
const targetFile = _nullishCoalesce(args.output, () => ( DEFAULT_TOKEN_REPORT));
|
|
2243
|
-
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
2244
|
-
const buildGrouped = () => groupTokensByFile(report, {
|
|
2245
|
-
key: groupKey,
|
|
2246
|
-
stripAbsolutePaths: groupKey !== "absolute"
|
|
2247
|
-
});
|
|
2248
|
-
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
2249
|
-
const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
|
|
2250
|
-
if (shouldWrite) {
|
|
2251
|
-
const target = _pathe2.default.resolve(targetFile);
|
|
2252
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
2253
|
-
if (format === "json") {
|
|
2254
|
-
await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
|
|
2255
|
-
} else if (format === "grouped-json") {
|
|
2256
|
-
await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
2257
|
-
} else {
|
|
2258
|
-
const lines = report.entries.map(formatTokenLine);
|
|
2259
|
-
await _fsextra2.default.writeFile(target, `${lines.join("\n")}
|
|
2260
|
-
`, "utf8");
|
|
2261
|
-
}
|
|
2262
|
-
logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`);
|
|
2263
|
-
} else {
|
|
2264
|
-
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
2265
|
-
if (format === "lines") {
|
|
2266
|
-
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
2267
|
-
if (preview) {
|
|
2268
|
-
logger_default.log("");
|
|
2269
|
-
logger_default.info(preview);
|
|
2270
|
-
if (report.entries.length > 5) {
|
|
2271
|
-
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
} else if (format === "grouped-json") {
|
|
2275
|
-
const map = resolveGrouped();
|
|
2276
|
-
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
2277
|
-
if (preview) {
|
|
2278
|
-
logger_default.log("");
|
|
2279
|
-
logger_default.info(preview);
|
|
2280
|
-
if (moreFiles > 0) {
|
|
2281
|
-
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
2282
|
-
}
|
|
2283
|
-
}
|
|
2284
|
-
} else {
|
|
2285
|
-
const previewEntries = report.entries.slice(0, 3);
|
|
2286
|
-
if (previewEntries.length) {
|
|
2287
|
-
logger_default.log("");
|
|
2288
|
-
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
}
|
|
2292
|
-
if (report.skippedFiles.length) {
|
|
2293
|
-
logger_default.warn("Skipped files:");
|
|
2294
|
-
for (const skipped of report.skippedFiles) {
|
|
2295
|
-
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
2296
|
-
}
|
|
2297
|
-
}
|
|
2298
|
-
return report;
|
|
2299
|
-
}
|
|
2300
|
-
async function initCommandDefaultHandler(ctx) {
|
|
2301
|
-
await _config.initConfig.call(void 0, ctx.cwd);
|
|
2302
|
-
logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
|
|
2303
|
-
}
|
|
2304
|
-
function formatFilesHint(entry) {
|
|
2305
|
-
if (!entry.files.length) {
|
|
2306
|
-
return "";
|
|
2307
|
-
}
|
|
2308
|
-
return ` (${entry.files.join(", ")})`;
|
|
2309
|
-
}
|
|
2310
|
-
async function statusCommandDefaultHandler(ctx) {
|
|
2311
|
-
const patcher = await ctx.createPatcher();
|
|
2312
|
-
const report = await patcher.getPatchStatus();
|
|
2313
|
-
if (ctx.args.json) {
|
|
2314
|
-
logger_default.log(JSON.stringify(report, null, 2));
|
|
2315
|
-
return report;
|
|
2316
|
-
}
|
|
2317
|
-
const applied = report.entries.filter((entry) => entry.status === "applied");
|
|
2318
|
-
const pending = report.entries.filter((entry) => entry.status === "not-applied");
|
|
2319
|
-
const skipped = report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported");
|
|
2320
|
-
const packageLabel = `${_nullishCoalesce(report.package.name, () => ( "tailwindcss"))}@${_nullishCoalesce(report.package.version, () => ( "unknown"))}`;
|
|
2321
|
-
logger_default.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
|
|
2322
|
-
if (applied.length) {
|
|
2323
|
-
logger_default.success("Applied:");
|
|
2324
|
-
applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
|
|
2325
|
-
}
|
|
2326
|
-
if (pending.length) {
|
|
2327
|
-
logger_default.warn("Needs attention:");
|
|
2328
|
-
pending.forEach((entry) => {
|
|
2329
|
-
const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
|
|
2330
|
-
logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
|
|
2331
|
-
});
|
|
2332
|
-
} else {
|
|
2333
|
-
logger_default.success("All applicable patches are applied.");
|
|
2334
|
-
}
|
|
2335
|
-
if (skipped.length) {
|
|
2336
|
-
logger_default.info("Skipped:");
|
|
2337
|
-
skipped.forEach((entry) => {
|
|
2338
|
-
const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
|
|
2339
|
-
logger_default.info(` \u2022 ${entry.name}${details}`);
|
|
2340
|
-
});
|
|
2341
|
-
}
|
|
2342
|
-
return report;
|
|
2343
|
-
}
|
|
2344
|
-
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
2345
|
-
const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
|
|
2346
|
-
const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
|
|
2347
|
-
const defaultDefinitions = buildDefaultCommandDefinitions();
|
|
2348
|
-
const registrars = {
|
|
2349
|
-
install: () => {
|
|
2350
|
-
const metadata = resolveCommandMetadata("install", options, prefix, defaultDefinitions);
|
|
2351
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
2352
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
2353
|
-
command.action(async (args) => {
|
|
2354
|
-
return runWithCommandHandler(
|
|
2355
|
-
cli,
|
|
2356
|
-
command,
|
|
2357
|
-
"install",
|
|
2358
|
-
args,
|
|
2359
|
-
_optionalChain([options, 'access', _91 => _91.commandHandlers, 'optionalAccess', _92 => _92.install]),
|
|
2360
|
-
installCommandDefaultHandler
|
|
2361
|
-
);
|
|
2362
|
-
});
|
|
2363
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2364
|
-
},
|
|
2365
|
-
extract: () => {
|
|
2366
|
-
const metadata = resolveCommandMetadata("extract", options, prefix, defaultDefinitions);
|
|
2367
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
2368
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
2369
|
-
command.action(async (args) => {
|
|
2370
|
-
return runWithCommandHandler(
|
|
2371
|
-
cli,
|
|
2372
|
-
command,
|
|
2373
|
-
"extract",
|
|
2374
|
-
args,
|
|
2375
|
-
_optionalChain([options, 'access', _93 => _93.commandHandlers, 'optionalAccess', _94 => _94.extract]),
|
|
2376
|
-
extractCommandDefaultHandler
|
|
2377
|
-
);
|
|
2378
|
-
});
|
|
2379
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2380
|
-
},
|
|
2381
|
-
tokens: () => {
|
|
2382
|
-
const metadata = resolveCommandMetadata("tokens", options, prefix, defaultDefinitions);
|
|
2383
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
2384
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
2385
|
-
command.action(async (args) => {
|
|
2386
|
-
return runWithCommandHandler(
|
|
2387
|
-
cli,
|
|
2388
|
-
command,
|
|
2389
|
-
"tokens",
|
|
2390
|
-
args,
|
|
2391
|
-
_optionalChain([options, 'access', _95 => _95.commandHandlers, 'optionalAccess', _96 => _96.tokens]),
|
|
2392
|
-
tokensCommandDefaultHandler
|
|
2393
|
-
);
|
|
2394
|
-
});
|
|
2395
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2396
|
-
},
|
|
2397
|
-
init: () => {
|
|
2398
|
-
const metadata = resolveCommandMetadata("init", options, prefix, defaultDefinitions);
|
|
2399
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
2400
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
2401
|
-
command.action(async (args) => {
|
|
2402
|
-
return runWithCommandHandler(
|
|
2403
|
-
cli,
|
|
2404
|
-
command,
|
|
2405
|
-
"init",
|
|
2406
|
-
args,
|
|
2407
|
-
_optionalChain([options, 'access', _97 => _97.commandHandlers, 'optionalAccess', _98 => _98.init]),
|
|
2408
|
-
initCommandDefaultHandler
|
|
2409
|
-
);
|
|
2410
|
-
});
|
|
2411
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2412
|
-
},
|
|
2413
|
-
status: () => {
|
|
2414
|
-
const metadata = resolveCommandMetadata("status", options, prefix, defaultDefinitions);
|
|
2415
|
-
const command = cli.command(metadata.name, metadata.description);
|
|
2416
|
-
applyCommandOptions(command, metadata.optionDefs);
|
|
2417
|
-
command.action(async (args) => {
|
|
2418
|
-
return runWithCommandHandler(
|
|
2419
|
-
cli,
|
|
2420
|
-
command,
|
|
2421
|
-
"status",
|
|
2422
|
-
args,
|
|
2423
|
-
_optionalChain([options, 'access', _99 => _99.commandHandlers, 'optionalAccess', _100 => _100.status]),
|
|
2424
|
-
statusCommandDefaultHandler
|
|
2425
|
-
);
|
|
2426
|
-
});
|
|
2427
|
-
metadata.aliases.forEach((alias) => command.alias(alias));
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
for (const name of selectedCommands) {
|
|
2431
|
-
const register = registrars[name];
|
|
2432
|
-
if (register) {
|
|
2433
|
-
register();
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
return cli;
|
|
2437
|
-
}
|
|
2438
|
-
function createTailwindcssPatchCli(options = {}) {
|
|
2439
|
-
const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
|
|
2440
|
-
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
2441
|
-
return cli;
|
|
2442
|
-
}
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.normalizeOptions = normalizeOptions; exports.getPatchStatusReport = getPatchStatusReport; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli;
|