tailwindcss-patch 9.0.0 → 9.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/cli.d.mts +1 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +18 -22
- package/dist/cli.mjs +17 -22
- package/dist/commands/cli-runtime.d.mts +5 -10
- package/dist/commands/cli-runtime.d.ts +5 -10
- package/dist/commands/cli-runtime.js +582 -1217
- package/dist/commands/cli-runtime.mjs +570 -1216
- package/dist/dist-B1VBpHtd.js +21 -0
- package/dist/dist-BjUV1yEM.mjs +19 -0
- package/dist/index.bundle-BGBMTX9A.js +35 -0
- package/dist/index.bundle-ByrTqrr3.mjs +18 -0
- package/dist/index.d.mts +68 -67
- package/dist/index.d.ts +68 -67
- package/dist/index.js +28 -57
- package/dist/index.mjs +3 -57
- package/dist/validate-B8H-8rWO.js +3487 -0
- package/dist/validate-BI8356RT.mjs +3336 -0
- package/dist/validate-Bu_rkfQF.d.ts +686 -0
- package/dist/validate-CIMnzW8O.d.mts +685 -0
- package/package.json +11 -11
- package/src/api/tailwindcss-patcher.ts +33 -6
- package/src/commands/basic-handlers.ts +0 -1
- package/src/config/index.ts +1 -1
- package/src/config/workspace.ts +1 -1
- package/src/options/legacy.ts +2 -2
- package/src/options/normalize.ts +10 -5
- package/src/runtime/collector.ts +7 -7
- package/src/runtime/process-tailwindcss.ts +33 -17
- package/dist/chunk-4RRHMRLJ.js +0 -4378
- package/dist/chunk-AOSPLINO.mjs +0 -4378
- package/dist/chunk-OSH52QWA.mjs +0 -10
- package/dist/chunk-QQXAOMUH.js +0 -25
- package/dist/chunk-YYBY7EM5.mjs +0 -21
- package/dist/chunk-ZPLR2UEW.js +0 -7
- package/dist/dist-22YCNIJW.js +0 -269
- package/dist/dist-7W73GIRD.mjs +0 -269
- package/dist/validate-nbmOI2w8.d.mts +0 -677
- package/dist/validate-nbmOI2w8.d.ts +0 -677
package/dist/chunk-4RRHMRLJ.js
DELETED
|
@@ -1,4378 +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;
|
|
2
|
-
|
|
3
|
-
var _chunkZPLR2UEWjs = require('./chunk-ZPLR2UEW.js');
|
|
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
|
-
|
|
14
|
-
// src/cache/context.ts
|
|
15
|
-
var _crypto = require('crypto');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
|
|
19
|
-
|
|
20
|
-
// package.json
|
|
21
|
-
var package_default = {
|
|
22
|
-
name: "tailwindcss-patch",
|
|
23
|
-
version: "9.0.0",
|
|
24
|
-
description: "patch tailwindcss for exposing context and extract classes",
|
|
25
|
-
author: "ice breaker <1324318532@qq.com>",
|
|
26
|
-
license: "MIT",
|
|
27
|
-
engines: {
|
|
28
|
-
node: ">=18.0.0"
|
|
29
|
-
},
|
|
30
|
-
homepage: "https://mangle.icebreaker.top/",
|
|
31
|
-
repository: {
|
|
32
|
-
type: "git",
|
|
33
|
-
url: "git+https://github.com/sonofmagic/tailwindcss-mangle.git",
|
|
34
|
-
directory: "packages/tailwindcss-patch"
|
|
35
|
-
},
|
|
36
|
-
bugs: {
|
|
37
|
-
url: "https://github.com/sonofmagic/tailwindcss-mangle/issues"
|
|
38
|
-
},
|
|
39
|
-
keywords: [
|
|
40
|
-
"tailwindcss",
|
|
41
|
-
"patch",
|
|
42
|
-
"extract",
|
|
43
|
-
"class"
|
|
44
|
-
],
|
|
45
|
-
exports: {
|
|
46
|
-
".": {
|
|
47
|
-
types: "./src/index.ts",
|
|
48
|
-
import: "./src/index.ts",
|
|
49
|
-
require: "./src/index.ts"
|
|
50
|
-
},
|
|
51
|
-
"./migration-report.schema.json": "./schema/migration-report.schema.json",
|
|
52
|
-
"./restore-result.schema.json": "./schema/restore-result.schema.json",
|
|
53
|
-
"./validate-result.schema.json": "./schema/validate-result.schema.json"
|
|
54
|
-
},
|
|
55
|
-
main: "./src/index.ts",
|
|
56
|
-
module: "./src/index.ts",
|
|
57
|
-
types: "./src/index.ts",
|
|
58
|
-
bin: {
|
|
59
|
-
"tw-patch": "dev/bin.ts",
|
|
60
|
-
"tailwindcss-patch": "dev/bin.ts"
|
|
61
|
-
},
|
|
62
|
-
files: [
|
|
63
|
-
"bin",
|
|
64
|
-
"dist",
|
|
65
|
-
"schema",
|
|
66
|
-
"src"
|
|
67
|
-
],
|
|
68
|
-
scripts: {
|
|
69
|
-
dev: "tsup --watch --sourcemap",
|
|
70
|
-
build: "tsup",
|
|
71
|
-
test: "vitest run",
|
|
72
|
-
"test:types": "pnpm build && tsd --typings dist/index.d.mts --files test-d/**/*.test-d.ts",
|
|
73
|
-
"test:dev": "vitest",
|
|
74
|
-
"bench:cold-start": "node --import tsx bench/cold-start.ts",
|
|
75
|
-
patch: "tsx dev/bin.ts install",
|
|
76
|
-
r0: "tsx dev/bin.ts extract",
|
|
77
|
-
r1: "tsx dev/bin.ts extract --css index.css"
|
|
78
|
-
},
|
|
79
|
-
tsd: {
|
|
80
|
-
directory: "test-d"
|
|
81
|
-
},
|
|
82
|
-
publishConfig: {
|
|
83
|
-
access: "public",
|
|
84
|
-
registry: "https://registry.npmjs.org/",
|
|
85
|
-
bin: {
|
|
86
|
-
"tw-patch": "bin/tw-patch.js",
|
|
87
|
-
"tailwindcss-patch": "bin/tw-patch.js"
|
|
88
|
-
},
|
|
89
|
-
exports: {
|
|
90
|
-
".": {
|
|
91
|
-
types: "./dist/index.d.ts",
|
|
92
|
-
import: "./dist/index.mjs",
|
|
93
|
-
require: "./dist/index.js"
|
|
94
|
-
},
|
|
95
|
-
"./migration-report.schema.json": "./schema/migration-report.schema.json",
|
|
96
|
-
"./restore-result.schema.json": "./schema/restore-result.schema.json",
|
|
97
|
-
"./validate-result.schema.json": "./schema/validate-result.schema.json"
|
|
98
|
-
},
|
|
99
|
-
main: "./dist/index.js",
|
|
100
|
-
module: "./dist/index.mjs",
|
|
101
|
-
types: "./dist/index.d.ts"
|
|
102
|
-
},
|
|
103
|
-
peerDependencies: {
|
|
104
|
-
tailwindcss: ">=2.0.0"
|
|
105
|
-
},
|
|
106
|
-
peerDependenciesMeta: {
|
|
107
|
-
tailwindcss: {
|
|
108
|
-
optional: true
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
dependencies: {
|
|
112
|
-
"@babel/generator": "^7.29.1",
|
|
113
|
-
"@babel/parser": "^7.29.2",
|
|
114
|
-
"@babel/traverse": "^7.29.0",
|
|
115
|
-
"@babel/types": "^7.29.0",
|
|
116
|
-
"@tailwindcss-mangle/config": "workspace:*",
|
|
117
|
-
"@tailwindcss/node": "^4.2.2",
|
|
118
|
-
cac: "6.7.14",
|
|
119
|
-
consola: "^3.4.2",
|
|
120
|
-
"fs-extra": "^11.3.4",
|
|
121
|
-
"local-pkg": "^1.1.2",
|
|
122
|
-
pathe: "^2.0.3",
|
|
123
|
-
postcss: "^8.5.8",
|
|
124
|
-
semver: "^7.7.4",
|
|
125
|
-
"tailwindcss-config": "^1.1.4"
|
|
126
|
-
},
|
|
127
|
-
devDependencies: {
|
|
128
|
-
"@tailwindcss/oxide": "^4.2.2",
|
|
129
|
-
"@tailwindcss/postcss": "^4.2.2",
|
|
130
|
-
"@tailwindcss/vite": "^4.2.2",
|
|
131
|
-
tailwindcss: "catalog:tailwindcss4",
|
|
132
|
-
"tailwindcss-3": "catalog:tailwindcss3",
|
|
133
|
-
"tailwindcss-4": "catalog:tailwindcss4"
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// src/constants.ts
|
|
138
|
-
var pkgName = "tailwindcss-patch";
|
|
139
|
-
var pkgVersion = package_default.version;
|
|
140
|
-
|
|
141
|
-
// src/cache/types.ts
|
|
142
|
-
var CACHE_SCHEMA_VERSION = 2;
|
|
143
|
-
var CACHE_FINGERPRINT_VERSION = 1;
|
|
144
|
-
|
|
145
|
-
// src/cache/context.ts
|
|
146
|
-
var DEFAULT_TAILWIND_CONFIG_FILES = [
|
|
147
|
-
"tailwind.config.js",
|
|
148
|
-
"tailwind.config.cjs",
|
|
149
|
-
"tailwind.config.mjs",
|
|
150
|
-
"tailwind.config.ts",
|
|
151
|
-
"tailwind.config.cts",
|
|
152
|
-
"tailwind.config.mts"
|
|
153
|
-
];
|
|
154
|
-
function normalizePathname(value) {
|
|
155
|
-
return _pathe2.default.normalize(value).replaceAll("\\", "/");
|
|
156
|
-
}
|
|
157
|
-
function resolveRealpathSyncSafe(value) {
|
|
158
|
-
const resolved = _pathe2.default.resolve(value);
|
|
159
|
-
try {
|
|
160
|
-
return normalizePathname(_fsextra2.default.realpathSync(resolved));
|
|
161
|
-
} catch (e2) {
|
|
162
|
-
return normalizePathname(resolved);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function resolveFileMtimeMsSync(value) {
|
|
166
|
-
if (!value) {
|
|
167
|
-
return void 0;
|
|
168
|
-
}
|
|
169
|
-
try {
|
|
170
|
-
const stat = _fsextra2.default.statSync(value);
|
|
171
|
-
if (!stat.isFile()) {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
return stat.mtimeMs;
|
|
175
|
-
} catch (e3) {
|
|
176
|
-
return void 0;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
function resolveTailwindConfigPath(options, majorVersion) {
|
|
180
|
-
const tailwind = options.tailwind;
|
|
181
|
-
const baseDir = _nullishCoalesce(tailwind.cwd, () => ( options.projectRoot));
|
|
182
|
-
const configured = (() => {
|
|
183
|
-
if (majorVersion === 2 && _optionalChain([tailwind, 'access', _ => _.v2, 'optionalAccess', _2 => _2.config])) {
|
|
184
|
-
return tailwind.v2.config;
|
|
185
|
-
}
|
|
186
|
-
if (majorVersion === 3 && _optionalChain([tailwind, 'access', _3 => _3.v3, 'optionalAccess', _4 => _4.config])) {
|
|
187
|
-
return tailwind.v3.config;
|
|
188
|
-
}
|
|
189
|
-
return tailwind.config;
|
|
190
|
-
})();
|
|
191
|
-
if (configured) {
|
|
192
|
-
const absolute = _pathe2.default.isAbsolute(configured) ? configured : _pathe2.default.resolve(baseDir, configured);
|
|
193
|
-
if (_fsextra2.default.pathExistsSync(absolute)) {
|
|
194
|
-
return resolveRealpathSyncSafe(absolute);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
for (const candidate of DEFAULT_TAILWIND_CONFIG_FILES) {
|
|
198
|
-
const absolute = _pathe2.default.resolve(baseDir, candidate);
|
|
199
|
-
if (_fsextra2.default.pathExistsSync(absolute)) {
|
|
200
|
-
return resolveRealpathSyncSafe(absolute);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return void 0;
|
|
204
|
-
}
|
|
205
|
-
function stableSerialize(input) {
|
|
206
|
-
if (input === null) {
|
|
207
|
-
return "null";
|
|
208
|
-
}
|
|
209
|
-
if (typeof input === "string") {
|
|
210
|
-
return JSON.stringify(input);
|
|
211
|
-
}
|
|
212
|
-
if (typeof input === "number" || typeof input === "boolean") {
|
|
213
|
-
return JSON.stringify(input);
|
|
214
|
-
}
|
|
215
|
-
if (Array.isArray(input)) {
|
|
216
|
-
return `[${input.map((item) => stableSerialize(item)).join(",")}]`;
|
|
217
|
-
}
|
|
218
|
-
if (typeof input === "object") {
|
|
219
|
-
const entries = Object.entries(input).filter(([, value]) => value !== void 0).sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => `${JSON.stringify(key)}:${stableSerialize(value)}`);
|
|
220
|
-
return `{${entries.join(",")}}`;
|
|
221
|
-
}
|
|
222
|
-
return JSON.stringify(String(input));
|
|
223
|
-
}
|
|
224
|
-
function hash(input) {
|
|
225
|
-
return _crypto.createHash.call(void 0, "sha256").update(input).digest("hex");
|
|
226
|
-
}
|
|
227
|
-
function toFingerprintOptions(normalized) {
|
|
228
|
-
return {
|
|
229
|
-
overwrite: normalized.overwrite,
|
|
230
|
-
output: {
|
|
231
|
-
removeUniversalSelector: normalized.output.removeUniversalSelector,
|
|
232
|
-
format: normalized.output.format
|
|
233
|
-
},
|
|
234
|
-
features: normalized.features,
|
|
235
|
-
tailwind: {
|
|
236
|
-
packageName: normalized.tailwind.packageName,
|
|
237
|
-
cwd: normalized.tailwind.cwd,
|
|
238
|
-
config: normalized.tailwind.config,
|
|
239
|
-
postcssPlugin: normalized.tailwind.postcssPlugin,
|
|
240
|
-
versionHint: normalized.tailwind.versionHint,
|
|
241
|
-
v2: normalized.tailwind.v2,
|
|
242
|
-
v3: normalized.tailwind.v3,
|
|
243
|
-
v4: normalized.tailwind.v4
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function createCacheContextDescriptor(options, packageInfo, majorVersion) {
|
|
248
|
-
const projectRootRealpath = resolveRealpathSyncSafe(options.projectRoot);
|
|
249
|
-
const processCwdRealpath = resolveRealpathSyncSafe(_process2.default.cwd());
|
|
250
|
-
const cacheCwdRealpath = resolveRealpathSyncSafe(options.cache.cwd);
|
|
251
|
-
const tailwindPackageRootRealpath = resolveRealpathSyncSafe(packageInfo.rootPath);
|
|
252
|
-
const tailwindConfigPath = resolveTailwindConfigPath(options, majorVersion);
|
|
253
|
-
const tailwindConfigMtimeMs = resolveFileMtimeMsSync(tailwindConfigPath);
|
|
254
|
-
const optionsHash = hash(stableSerialize(toFingerprintOptions(options)));
|
|
255
|
-
const metadata = {
|
|
256
|
-
fingerprintVersion: CACHE_FINGERPRINT_VERSION,
|
|
257
|
-
projectRootRealpath,
|
|
258
|
-
processCwdRealpath,
|
|
259
|
-
cacheCwdRealpath,
|
|
260
|
-
...tailwindConfigPath === void 0 ? {} : { tailwindConfigPath },
|
|
261
|
-
...tailwindConfigMtimeMs === void 0 ? {} : { tailwindConfigMtimeMs },
|
|
262
|
-
tailwindPackageRootRealpath,
|
|
263
|
-
tailwindPackageVersion: _nullishCoalesce(packageInfo.version, () => ( "unknown")),
|
|
264
|
-
patcherVersion: pkgVersion,
|
|
265
|
-
majorVersion,
|
|
266
|
-
optionsHash
|
|
267
|
-
};
|
|
268
|
-
const fingerprint = hash(stableSerialize(metadata));
|
|
269
|
-
return {
|
|
270
|
-
fingerprint,
|
|
271
|
-
metadata
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function explainContextMismatch(current, cached) {
|
|
275
|
-
const reasons = [];
|
|
276
|
-
if (current.projectRootRealpath !== cached.projectRootRealpath) {
|
|
277
|
-
reasons.push(`project-root changed: ${cached.projectRootRealpath} -> ${current.projectRootRealpath}`);
|
|
278
|
-
}
|
|
279
|
-
if (current.processCwdRealpath !== cached.processCwdRealpath) {
|
|
280
|
-
reasons.push(`process-cwd changed: ${cached.processCwdRealpath} -> ${current.processCwdRealpath}`);
|
|
281
|
-
}
|
|
282
|
-
if (current.cacheCwdRealpath !== cached.cacheCwdRealpath) {
|
|
283
|
-
reasons.push(`cache-cwd changed: ${cached.cacheCwdRealpath} -> ${current.cacheCwdRealpath}`);
|
|
284
|
-
}
|
|
285
|
-
if ((_nullishCoalesce(current.tailwindConfigPath, () => ( ""))) !== (_nullishCoalesce(cached.tailwindConfigPath, () => ( "")))) {
|
|
286
|
-
reasons.push(`tailwind-config path changed: ${_nullishCoalesce(cached.tailwindConfigPath, () => ( "<none>"))} -> ${_nullishCoalesce(current.tailwindConfigPath, () => ( "<none>"))}`);
|
|
287
|
-
}
|
|
288
|
-
if ((_nullishCoalesce(current.tailwindConfigMtimeMs, () => ( -1))) !== (_nullishCoalesce(cached.tailwindConfigMtimeMs, () => ( -1)))) {
|
|
289
|
-
reasons.push("tailwind-config mtime changed");
|
|
290
|
-
}
|
|
291
|
-
if (current.tailwindPackageRootRealpath !== cached.tailwindPackageRootRealpath) {
|
|
292
|
-
reasons.push(`tailwind-package root changed: ${cached.tailwindPackageRootRealpath} -> ${current.tailwindPackageRootRealpath}`);
|
|
293
|
-
}
|
|
294
|
-
if (current.tailwindPackageVersion !== cached.tailwindPackageVersion) {
|
|
295
|
-
reasons.push(`tailwind-package version changed: ${cached.tailwindPackageVersion} -> ${current.tailwindPackageVersion}`);
|
|
296
|
-
}
|
|
297
|
-
if (current.patcherVersion !== cached.patcherVersion) {
|
|
298
|
-
reasons.push(`patcher version changed: ${cached.patcherVersion} -> ${current.patcherVersion}`);
|
|
299
|
-
}
|
|
300
|
-
if (current.majorVersion !== cached.majorVersion) {
|
|
301
|
-
reasons.push(`major version changed: ${cached.majorVersion} -> ${current.majorVersion}`);
|
|
302
|
-
}
|
|
303
|
-
if (current.optionsHash !== cached.optionsHash) {
|
|
304
|
-
reasons.push(`patch options hash changed: ${cached.optionsHash.slice(0, 12)} -> ${current.optionsHash.slice(0, 12)}`);
|
|
305
|
-
}
|
|
306
|
-
return reasons;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// src/cache/store.ts
|
|
310
|
-
function isErrnoException(error) {
|
|
311
|
-
return error instanceof Error && typeof error.code === "string";
|
|
312
|
-
}
|
|
313
|
-
function isAccessDenied(error) {
|
|
314
|
-
return isErrnoException(error) && Boolean(error.code && ["EPERM", "EBUSY", "EACCES"].includes(error.code));
|
|
315
|
-
}
|
|
316
|
-
function toStringArray(value) {
|
|
317
|
-
if (!Array.isArray(value)) {
|
|
318
|
-
return [];
|
|
319
|
-
}
|
|
320
|
-
return value.filter((item) => typeof item === "string");
|
|
321
|
-
}
|
|
322
|
-
function asObject(value) {
|
|
323
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
324
|
-
return void 0;
|
|
325
|
-
}
|
|
326
|
-
return value;
|
|
327
|
-
}
|
|
328
|
-
function toReadMeta(meta) {
|
|
329
|
-
return {
|
|
330
|
-
...meta,
|
|
331
|
-
details: [...meta.details]
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
function cloneEntry(entry) {
|
|
335
|
-
return {
|
|
336
|
-
context: {
|
|
337
|
-
...entry.context
|
|
338
|
-
},
|
|
339
|
-
values: [...entry.values],
|
|
340
|
-
updatedAt: entry.updatedAt
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
var CacheStore = (_class = class {
|
|
344
|
-
constructor(options, context) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);
|
|
345
|
-
this.options = options;
|
|
346
|
-
this.context = context;
|
|
347
|
-
this.driver = _nullishCoalesce(options.driver, () => ( "file"));
|
|
348
|
-
this.lockPath = `${this.options.path}.lock`;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
__init() {this.memoryCache = null}
|
|
353
|
-
__init2() {this.memoryIndex = null}
|
|
354
|
-
__init3() {this.lastReadMeta = {
|
|
355
|
-
hit: false,
|
|
356
|
-
reason: "context-not-found",
|
|
357
|
-
details: []
|
|
358
|
-
}}
|
|
359
|
-
isContextAware() {
|
|
360
|
-
return this.context !== void 0;
|
|
361
|
-
}
|
|
362
|
-
createEmptyIndex() {
|
|
363
|
-
return {
|
|
364
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
365
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
366
|
-
contexts: {}
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
async ensureDir() {
|
|
370
|
-
await _fsextra2.default.ensureDir(this.options.dir);
|
|
371
|
-
}
|
|
372
|
-
ensureDirSync() {
|
|
373
|
-
_fsextra2.default.ensureDirSync(this.options.dir);
|
|
374
|
-
}
|
|
375
|
-
createTempPath() {
|
|
376
|
-
const uniqueSuffix = `${_process2.default.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
377
|
-
return `${this.options.path}.${uniqueSuffix}.tmp`;
|
|
378
|
-
}
|
|
379
|
-
async replaceCacheFile(tempPath) {
|
|
380
|
-
try {
|
|
381
|
-
await _fsextra2.default.rename(tempPath, this.options.path);
|
|
382
|
-
return true;
|
|
383
|
-
} catch (error) {
|
|
384
|
-
if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
|
|
385
|
-
try {
|
|
386
|
-
await _fsextra2.default.remove(this.options.path);
|
|
387
|
-
} catch (removeError) {
|
|
388
|
-
if (isAccessDenied(removeError)) {
|
|
389
|
-
logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
|
|
393
|
-
throw removeError;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
await _fsextra2.default.rename(tempPath, this.options.path);
|
|
397
|
-
return true;
|
|
398
|
-
}
|
|
399
|
-
throw error;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
replaceCacheFileSync(tempPath) {
|
|
403
|
-
try {
|
|
404
|
-
_fsextra2.default.renameSync(tempPath, this.options.path);
|
|
405
|
-
return true;
|
|
406
|
-
} catch (error) {
|
|
407
|
-
if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
|
|
408
|
-
try {
|
|
409
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
410
|
-
} catch (removeError) {
|
|
411
|
-
if (isAccessDenied(removeError)) {
|
|
412
|
-
logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
|
|
413
|
-
return false;
|
|
414
|
-
}
|
|
415
|
-
if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
|
|
416
|
-
throw removeError;
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
_fsextra2.default.renameSync(tempPath, this.options.path);
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
throw error;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
async cleanupTempFile(tempPath) {
|
|
426
|
-
try {
|
|
427
|
-
await _fsextra2.default.remove(tempPath);
|
|
428
|
-
} catch (e4) {
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
cleanupTempFileSync(tempPath) {
|
|
432
|
-
try {
|
|
433
|
-
_fsextra2.default.removeSync(tempPath);
|
|
434
|
-
} catch (e5) {
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
async delay(ms) {
|
|
438
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
439
|
-
}
|
|
440
|
-
async acquireLock() {
|
|
441
|
-
await _fsextra2.default.ensureDir(this.options.dir);
|
|
442
|
-
const maxAttempts = 40;
|
|
443
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
444
|
-
try {
|
|
445
|
-
await _fsextra2.default.writeFile(this.lockPath, `${_process2.default.pid}
|
|
446
|
-
${Date.now()}`, { flag: "wx" });
|
|
447
|
-
return true;
|
|
448
|
-
} catch (error) {
|
|
449
|
-
if (!isErrnoException(error) || error.code !== "EEXIST") {
|
|
450
|
-
logger_default.debug("Unable to acquire cache lock.", error);
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
try {
|
|
454
|
-
const stat = await _fsextra2.default.stat(this.lockPath);
|
|
455
|
-
if (Date.now() - stat.mtimeMs > 3e4) {
|
|
456
|
-
await _fsextra2.default.remove(this.lockPath);
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
} catch (e6) {
|
|
460
|
-
}
|
|
461
|
-
await this.delay(25);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
logger_default.debug("Timed out while waiting for cache lock; skipping cache mutation.");
|
|
465
|
-
return false;
|
|
466
|
-
}
|
|
467
|
-
releaseLockSyncOrAsync(sync) {
|
|
468
|
-
if (sync) {
|
|
469
|
-
try {
|
|
470
|
-
_fsextra2.default.removeSync(this.lockPath);
|
|
471
|
-
} catch (e7) {
|
|
472
|
-
}
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
return _fsextra2.default.remove(this.lockPath).catch(() => void 0);
|
|
476
|
-
}
|
|
477
|
-
acquireLockSync() {
|
|
478
|
-
_fsextra2.default.ensureDirSync(this.options.dir);
|
|
479
|
-
const maxAttempts = 40;
|
|
480
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
481
|
-
try {
|
|
482
|
-
_fsextra2.default.writeFileSync(this.lockPath, `${_process2.default.pid}
|
|
483
|
-
${Date.now()}`, { flag: "wx" });
|
|
484
|
-
return true;
|
|
485
|
-
} catch (error) {
|
|
486
|
-
if (!isErrnoException(error) || error.code !== "EEXIST") {
|
|
487
|
-
logger_default.debug("Unable to acquire cache lock.", error);
|
|
488
|
-
return false;
|
|
489
|
-
}
|
|
490
|
-
try {
|
|
491
|
-
const stat = _fsextra2.default.statSync(this.lockPath);
|
|
492
|
-
if (Date.now() - stat.mtimeMs > 3e4) {
|
|
493
|
-
_fsextra2.default.removeSync(this.lockPath);
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
} catch (e8) {
|
|
497
|
-
}
|
|
498
|
-
const start = Date.now();
|
|
499
|
-
while (Date.now() - start < 25) {
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
logger_default.debug("Timed out while waiting for cache lock; skipping cache mutation.");
|
|
504
|
-
return false;
|
|
505
|
-
}
|
|
506
|
-
async withFileLock(fn) {
|
|
507
|
-
const locked = await this.acquireLock();
|
|
508
|
-
if (!locked) {
|
|
509
|
-
return void 0;
|
|
510
|
-
}
|
|
511
|
-
try {
|
|
512
|
-
return await fn();
|
|
513
|
-
} finally {
|
|
514
|
-
await this.releaseLockSyncOrAsync(false);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
withFileLockSync(fn) {
|
|
518
|
-
const locked = this.acquireLockSync();
|
|
519
|
-
if (!locked) {
|
|
520
|
-
return void 0;
|
|
521
|
-
}
|
|
522
|
-
try {
|
|
523
|
-
return fn();
|
|
524
|
-
} finally {
|
|
525
|
-
this.releaseLockSyncOrAsync(true);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
normalizeContextEntry(value) {
|
|
529
|
-
const record = asObject(value);
|
|
530
|
-
if (!record) {
|
|
531
|
-
return void 0;
|
|
532
|
-
}
|
|
533
|
-
const values = toStringArray(record["values"]);
|
|
534
|
-
if (values.length === 0) {
|
|
535
|
-
return void 0;
|
|
536
|
-
}
|
|
537
|
-
const contextRecord = asObject(record["context"]);
|
|
538
|
-
if (!contextRecord) {
|
|
539
|
-
return void 0;
|
|
540
|
-
}
|
|
541
|
-
const {
|
|
542
|
-
fingerprintVersion,
|
|
543
|
-
projectRootRealpath,
|
|
544
|
-
processCwdRealpath,
|
|
545
|
-
cacheCwdRealpath,
|
|
546
|
-
tailwindConfigPath,
|
|
547
|
-
tailwindConfigMtimeMs,
|
|
548
|
-
tailwindPackageRootRealpath,
|
|
549
|
-
tailwindPackageVersion,
|
|
550
|
-
patcherVersion,
|
|
551
|
-
majorVersion,
|
|
552
|
-
optionsHash
|
|
553
|
-
} = contextRecord;
|
|
554
|
-
if (fingerprintVersion !== 1 || typeof projectRootRealpath !== "string" || typeof processCwdRealpath !== "string" || typeof cacheCwdRealpath !== "string" || typeof tailwindPackageRootRealpath !== "string" || typeof tailwindPackageVersion !== "string" || typeof patcherVersion !== "string" || majorVersion !== 2 && majorVersion !== 3 && majorVersion !== 4 || typeof optionsHash !== "string") {
|
|
555
|
-
return void 0;
|
|
556
|
-
}
|
|
557
|
-
const normalized = {
|
|
558
|
-
context: {
|
|
559
|
-
fingerprintVersion,
|
|
560
|
-
projectRootRealpath,
|
|
561
|
-
processCwdRealpath,
|
|
562
|
-
cacheCwdRealpath,
|
|
563
|
-
...typeof tailwindConfigPath === "string" ? { tailwindConfigPath } : {},
|
|
564
|
-
...typeof tailwindConfigMtimeMs === "number" ? { tailwindConfigMtimeMs } : {},
|
|
565
|
-
tailwindPackageRootRealpath,
|
|
566
|
-
tailwindPackageVersion,
|
|
567
|
-
patcherVersion,
|
|
568
|
-
majorVersion,
|
|
569
|
-
optionsHash
|
|
570
|
-
},
|
|
571
|
-
values,
|
|
572
|
-
updatedAt: typeof record["updatedAt"] === "string" ? record["updatedAt"] : (/* @__PURE__ */ new Date(0)).toISOString()
|
|
573
|
-
};
|
|
574
|
-
return normalized;
|
|
575
|
-
}
|
|
576
|
-
normalizeIndexFile(payload) {
|
|
577
|
-
if (Array.isArray(payload)) {
|
|
578
|
-
return {
|
|
579
|
-
kind: "legacy",
|
|
580
|
-
data: toStringArray(payload)
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
const record = asObject(payload);
|
|
584
|
-
if (!record) {
|
|
585
|
-
return { kind: "invalid" };
|
|
586
|
-
}
|
|
587
|
-
if (record["schemaVersion"] !== CACHE_SCHEMA_VERSION) {
|
|
588
|
-
return { kind: "invalid" };
|
|
589
|
-
}
|
|
590
|
-
const contextsRecord = asObject(record["contexts"]);
|
|
591
|
-
if (!contextsRecord) {
|
|
592
|
-
return { kind: "invalid" };
|
|
593
|
-
}
|
|
594
|
-
const contexts = {};
|
|
595
|
-
for (const [fingerprint, value] of Object.entries(contextsRecord)) {
|
|
596
|
-
if (typeof fingerprint !== "string" || !fingerprint) {
|
|
597
|
-
continue;
|
|
598
|
-
}
|
|
599
|
-
const entry = this.normalizeContextEntry(value);
|
|
600
|
-
if (!entry) {
|
|
601
|
-
continue;
|
|
602
|
-
}
|
|
603
|
-
contexts[fingerprint] = entry;
|
|
604
|
-
}
|
|
605
|
-
return {
|
|
606
|
-
kind: "v2",
|
|
607
|
-
data: {
|
|
608
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
609
|
-
updatedAt: typeof record["updatedAt"] === "string" ? record["updatedAt"] : (/* @__PURE__ */ new Date(0)).toISOString(),
|
|
610
|
-
contexts
|
|
611
|
-
}
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
async readParsedCacheFile(cleanupInvalid) {
|
|
615
|
-
try {
|
|
616
|
-
if (!await _fsextra2.default.pathExists(this.options.path)) {
|
|
617
|
-
return { kind: "empty" };
|
|
618
|
-
}
|
|
619
|
-
const payload = await _fsextra2.default.readJSON(this.options.path);
|
|
620
|
-
const normalized = this.normalizeIndexFile(payload);
|
|
621
|
-
if (normalized.kind !== "invalid") {
|
|
622
|
-
return normalized;
|
|
623
|
-
}
|
|
624
|
-
if (cleanupInvalid) {
|
|
625
|
-
logger_default.warn("Unable to read Tailwind class cache index, removing invalid file.");
|
|
626
|
-
await _fsextra2.default.remove(this.options.path);
|
|
627
|
-
}
|
|
628
|
-
return { kind: "invalid" };
|
|
629
|
-
} catch (error) {
|
|
630
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
631
|
-
return { kind: "empty" };
|
|
632
|
-
}
|
|
633
|
-
logger_default.warn("Unable to read Tailwind class cache index, removing invalid file.", error);
|
|
634
|
-
if (cleanupInvalid) {
|
|
635
|
-
try {
|
|
636
|
-
await _fsextra2.default.remove(this.options.path);
|
|
637
|
-
} catch (cleanupError) {
|
|
638
|
-
logger_default.error("Failed to clean up invalid cache file", cleanupError);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
return { kind: "invalid" };
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
readParsedCacheFileSync(cleanupInvalid) {
|
|
645
|
-
try {
|
|
646
|
-
if (!_fsextra2.default.pathExistsSync(this.options.path)) {
|
|
647
|
-
return { kind: "empty" };
|
|
648
|
-
}
|
|
649
|
-
const payload = _fsextra2.default.readJSONSync(this.options.path);
|
|
650
|
-
const normalized = this.normalizeIndexFile(payload);
|
|
651
|
-
if (normalized.kind !== "invalid") {
|
|
652
|
-
return normalized;
|
|
653
|
-
}
|
|
654
|
-
if (cleanupInvalid) {
|
|
655
|
-
logger_default.warn("Unable to read Tailwind class cache index, removing invalid file.");
|
|
656
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
657
|
-
}
|
|
658
|
-
return { kind: "invalid" };
|
|
659
|
-
} catch (error) {
|
|
660
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
661
|
-
return { kind: "empty" };
|
|
662
|
-
}
|
|
663
|
-
logger_default.warn("Unable to read Tailwind class cache index, removing invalid file.", error);
|
|
664
|
-
if (cleanupInvalid) {
|
|
665
|
-
try {
|
|
666
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
667
|
-
} catch (cleanupError) {
|
|
668
|
-
logger_default.error("Failed to clean up invalid cache file", cleanupError);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
return { kind: "invalid" };
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
findProjectMatch(index) {
|
|
675
|
-
if (!this.context) {
|
|
676
|
-
return void 0;
|
|
677
|
-
}
|
|
678
|
-
const current = this.context.metadata.projectRootRealpath;
|
|
679
|
-
return Object.entries(index.contexts).find(([, entry]) => entry.context.projectRootRealpath === current);
|
|
680
|
-
}
|
|
681
|
-
async writeIndexFile(index) {
|
|
682
|
-
const tempPath = this.createTempPath();
|
|
683
|
-
try {
|
|
684
|
-
await this.ensureDir();
|
|
685
|
-
await _fsextra2.default.writeJSON(tempPath, index);
|
|
686
|
-
const replaced = await this.replaceCacheFile(tempPath);
|
|
687
|
-
if (replaced) {
|
|
688
|
-
return this.options.path;
|
|
689
|
-
}
|
|
690
|
-
await this.cleanupTempFile(tempPath);
|
|
691
|
-
return void 0;
|
|
692
|
-
} catch (error) {
|
|
693
|
-
await this.cleanupTempFile(tempPath);
|
|
694
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
695
|
-
return void 0;
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
writeIndexFileSync(index) {
|
|
699
|
-
const tempPath = this.createTempPath();
|
|
700
|
-
try {
|
|
701
|
-
this.ensureDirSync();
|
|
702
|
-
_fsextra2.default.writeJSONSync(tempPath, index);
|
|
703
|
-
const replaced = this.replaceCacheFileSync(tempPath);
|
|
704
|
-
if (replaced) {
|
|
705
|
-
return this.options.path;
|
|
706
|
-
}
|
|
707
|
-
this.cleanupTempFileSync(tempPath);
|
|
708
|
-
return void 0;
|
|
709
|
-
} catch (error) {
|
|
710
|
-
this.cleanupTempFileSync(tempPath);
|
|
711
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
712
|
-
return void 0;
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
async write(data) {
|
|
716
|
-
if (!this.options.enabled) {
|
|
717
|
-
return void 0;
|
|
718
|
-
}
|
|
719
|
-
if (this.driver === "noop") {
|
|
720
|
-
return void 0;
|
|
721
|
-
}
|
|
722
|
-
if (this.driver === "memory") {
|
|
723
|
-
if (!this.isContextAware()) {
|
|
724
|
-
this.memoryCache = new Set(data);
|
|
725
|
-
return "memory";
|
|
726
|
-
}
|
|
727
|
-
const index = _nullishCoalesce(this.memoryIndex, () => ( this.createEmptyIndex()));
|
|
728
|
-
if (!this.context) {
|
|
729
|
-
return "memory";
|
|
730
|
-
}
|
|
731
|
-
index.contexts[this.context.fingerprint] = {
|
|
732
|
-
context: {
|
|
733
|
-
...this.context.metadata
|
|
734
|
-
},
|
|
735
|
-
values: Array.from(data),
|
|
736
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
737
|
-
};
|
|
738
|
-
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
739
|
-
this.memoryIndex = index;
|
|
740
|
-
return "memory";
|
|
741
|
-
}
|
|
742
|
-
if (!this.isContextAware()) {
|
|
743
|
-
const tempPath = this.createTempPath();
|
|
744
|
-
try {
|
|
745
|
-
await this.ensureDir();
|
|
746
|
-
await _fsextra2.default.writeJSON(tempPath, Array.from(data));
|
|
747
|
-
const replaced = await this.replaceCacheFile(tempPath);
|
|
748
|
-
if (replaced) {
|
|
749
|
-
return this.options.path;
|
|
750
|
-
}
|
|
751
|
-
await this.cleanupTempFile(tempPath);
|
|
752
|
-
return void 0;
|
|
753
|
-
} catch (error) {
|
|
754
|
-
await this.cleanupTempFile(tempPath);
|
|
755
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
756
|
-
return void 0;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
const result = await this.withFileLock(async () => {
|
|
760
|
-
const parsed = await this.readParsedCacheFile(false);
|
|
761
|
-
const index = parsed.kind === "v2" ? parsed.data : this.createEmptyIndex();
|
|
762
|
-
if (this.context) {
|
|
763
|
-
index.contexts[this.context.fingerprint] = {
|
|
764
|
-
context: {
|
|
765
|
-
...this.context.metadata
|
|
766
|
-
},
|
|
767
|
-
values: Array.from(data),
|
|
768
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
769
|
-
};
|
|
770
|
-
}
|
|
771
|
-
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
772
|
-
return this.writeIndexFile(index);
|
|
773
|
-
});
|
|
774
|
-
return result;
|
|
775
|
-
}
|
|
776
|
-
writeSync(data) {
|
|
777
|
-
if (!this.options.enabled) {
|
|
778
|
-
return void 0;
|
|
779
|
-
}
|
|
780
|
-
if (this.driver === "noop") {
|
|
781
|
-
return void 0;
|
|
782
|
-
}
|
|
783
|
-
if (this.driver === "memory") {
|
|
784
|
-
if (!this.isContextAware()) {
|
|
785
|
-
this.memoryCache = new Set(data);
|
|
786
|
-
return "memory";
|
|
787
|
-
}
|
|
788
|
-
const index = _nullishCoalesce(this.memoryIndex, () => ( this.createEmptyIndex()));
|
|
789
|
-
if (!this.context) {
|
|
790
|
-
return "memory";
|
|
791
|
-
}
|
|
792
|
-
index.contexts[this.context.fingerprint] = {
|
|
793
|
-
context: {
|
|
794
|
-
...this.context.metadata
|
|
795
|
-
},
|
|
796
|
-
values: Array.from(data),
|
|
797
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
798
|
-
};
|
|
799
|
-
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
800
|
-
this.memoryIndex = index;
|
|
801
|
-
return "memory";
|
|
802
|
-
}
|
|
803
|
-
if (!this.isContextAware()) {
|
|
804
|
-
const tempPath = this.createTempPath();
|
|
805
|
-
try {
|
|
806
|
-
this.ensureDirSync();
|
|
807
|
-
_fsextra2.default.writeJSONSync(tempPath, Array.from(data));
|
|
808
|
-
const replaced = this.replaceCacheFileSync(tempPath);
|
|
809
|
-
if (replaced) {
|
|
810
|
-
return this.options.path;
|
|
811
|
-
}
|
|
812
|
-
this.cleanupTempFileSync(tempPath);
|
|
813
|
-
return void 0;
|
|
814
|
-
} catch (error) {
|
|
815
|
-
this.cleanupTempFileSync(tempPath);
|
|
816
|
-
logger_default.error("Unable to persist Tailwind class cache", error);
|
|
817
|
-
return void 0;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
const result = this.withFileLockSync(() => {
|
|
821
|
-
const parsed = this.readParsedCacheFileSync(false);
|
|
822
|
-
const index = parsed.kind === "v2" ? parsed.data : this.createEmptyIndex();
|
|
823
|
-
if (this.context) {
|
|
824
|
-
index.contexts[this.context.fingerprint] = {
|
|
825
|
-
context: {
|
|
826
|
-
...this.context.metadata
|
|
827
|
-
},
|
|
828
|
-
values: Array.from(data),
|
|
829
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
830
|
-
};
|
|
831
|
-
}
|
|
832
|
-
index.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
833
|
-
return this.writeIndexFileSync(index);
|
|
834
|
-
});
|
|
835
|
-
return result;
|
|
836
|
-
}
|
|
837
|
-
async readWithMeta() {
|
|
838
|
-
if (!this.options.enabled) {
|
|
839
|
-
return {
|
|
840
|
-
data: /* @__PURE__ */ new Set(),
|
|
841
|
-
meta: {
|
|
842
|
-
hit: false,
|
|
843
|
-
reason: "cache-disabled",
|
|
844
|
-
details: ["cache disabled"]
|
|
845
|
-
}
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
|
-
if (this.driver === "noop") {
|
|
849
|
-
return {
|
|
850
|
-
data: /* @__PURE__ */ new Set(),
|
|
851
|
-
meta: {
|
|
852
|
-
hit: false,
|
|
853
|
-
reason: "noop-driver",
|
|
854
|
-
details: ["cache driver is noop"]
|
|
855
|
-
}
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
if (this.driver === "memory") {
|
|
859
|
-
if (!this.isContextAware()) {
|
|
860
|
-
const cache = new Set(_nullishCoalesce(this.memoryCache, () => ( [])));
|
|
861
|
-
return {
|
|
862
|
-
data: cache,
|
|
863
|
-
meta: {
|
|
864
|
-
hit: cache.size > 0,
|
|
865
|
-
reason: cache.size > 0 ? "hit" : "context-not-found",
|
|
866
|
-
details: cache.size > 0 ? ["memory cache hit"] : ["memory cache miss"]
|
|
867
|
-
}
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
const index = this.memoryIndex;
|
|
871
|
-
if (!index || !this.context) {
|
|
872
|
-
return {
|
|
873
|
-
data: /* @__PURE__ */ new Set(),
|
|
874
|
-
meta: {
|
|
875
|
-
hit: false,
|
|
876
|
-
reason: "context-not-found",
|
|
877
|
-
..._optionalChain([this, 'access', _5 => _5.context, 'optionalAccess', _6 => _6.fingerprint]) === void 0 ? {} : { fingerprint: this.context.fingerprint },
|
|
878
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
879
|
-
details: ["no in-memory cache index for current context"]
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
}
|
|
883
|
-
const entry2 = index.contexts[this.context.fingerprint];
|
|
884
|
-
if (entry2) {
|
|
885
|
-
return {
|
|
886
|
-
data: new Set(entry2.values),
|
|
887
|
-
meta: {
|
|
888
|
-
hit: true,
|
|
889
|
-
reason: "hit",
|
|
890
|
-
fingerprint: this.context.fingerprint,
|
|
891
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
892
|
-
details: ["memory cache hit"]
|
|
893
|
-
}
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
const projectMatch2 = this.findProjectMatch(index);
|
|
897
|
-
if (projectMatch2 && this.context) {
|
|
898
|
-
const [, matchedEntry] = projectMatch2;
|
|
899
|
-
return {
|
|
900
|
-
data: /* @__PURE__ */ new Set(),
|
|
901
|
-
meta: {
|
|
902
|
-
hit: false,
|
|
903
|
-
reason: "context-mismatch",
|
|
904
|
-
fingerprint: this.context.fingerprint,
|
|
905
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
906
|
-
details: explainContextMismatch(this.context.metadata, matchedEntry.context)
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
return {
|
|
911
|
-
data: /* @__PURE__ */ new Set(),
|
|
912
|
-
meta: {
|
|
913
|
-
hit: false,
|
|
914
|
-
reason: "context-not-found",
|
|
915
|
-
fingerprint: this.context.fingerprint,
|
|
916
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
917
|
-
details: ["context fingerprint not found in memory cache index"]
|
|
918
|
-
}
|
|
919
|
-
};
|
|
920
|
-
}
|
|
921
|
-
const parsed = await this.readParsedCacheFile(true);
|
|
922
|
-
if (parsed.kind === "empty") {
|
|
923
|
-
return {
|
|
924
|
-
data: /* @__PURE__ */ new Set(),
|
|
925
|
-
meta: {
|
|
926
|
-
hit: false,
|
|
927
|
-
reason: "file-missing",
|
|
928
|
-
details: ["cache file not found"]
|
|
929
|
-
}
|
|
930
|
-
};
|
|
931
|
-
}
|
|
932
|
-
if (parsed.kind === "invalid") {
|
|
933
|
-
return {
|
|
934
|
-
data: /* @__PURE__ */ new Set(),
|
|
935
|
-
meta: {
|
|
936
|
-
hit: false,
|
|
937
|
-
reason: "invalid-schema",
|
|
938
|
-
details: ["cache schema invalid and has been reset"]
|
|
939
|
-
}
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
if (!this.isContextAware()) {
|
|
943
|
-
if (parsed.kind === "legacy") {
|
|
944
|
-
return {
|
|
945
|
-
data: new Set(parsed.data),
|
|
946
|
-
meta: {
|
|
947
|
-
hit: parsed.data.length > 0,
|
|
948
|
-
reason: parsed.data.length > 0 ? "hit" : "context-not-found",
|
|
949
|
-
details: ["legacy cache format"]
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
}
|
|
953
|
-
const union = Object.values(parsed.data.contexts).flatMap((entry2) => entry2.values);
|
|
954
|
-
return {
|
|
955
|
-
data: new Set(union),
|
|
956
|
-
meta: {
|
|
957
|
-
hit: union.length > 0,
|
|
958
|
-
reason: union.length > 0 ? "hit" : "context-not-found",
|
|
959
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
960
|
-
details: ["context-less read merged all cache entries"]
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
if (parsed.kind === "legacy") {
|
|
965
|
-
return {
|
|
966
|
-
data: /* @__PURE__ */ new Set(),
|
|
967
|
-
meta: {
|
|
968
|
-
hit: false,
|
|
969
|
-
reason: "legacy-schema",
|
|
970
|
-
..._optionalChain([this, 'access', _7 => _7.context, 'optionalAccess', _8 => _8.fingerprint]) === void 0 ? {} : { fingerprint: this.context.fingerprint },
|
|
971
|
-
details: ["legacy cache schema detected; rebuilding cache with context fingerprint"]
|
|
972
|
-
}
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
if (!this.context) {
|
|
976
|
-
return {
|
|
977
|
-
data: /* @__PURE__ */ new Set(),
|
|
978
|
-
meta: {
|
|
979
|
-
hit: false,
|
|
980
|
-
reason: "context-not-found",
|
|
981
|
-
details: ["cache context missing"]
|
|
982
|
-
}
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
const entry = parsed.data.contexts[this.context.fingerprint];
|
|
986
|
-
if (entry) {
|
|
987
|
-
const mismatchReasons = explainContextMismatch(this.context.metadata, entry.context);
|
|
988
|
-
if (mismatchReasons.length === 0) {
|
|
989
|
-
return {
|
|
990
|
-
data: new Set(entry.values),
|
|
991
|
-
meta: {
|
|
992
|
-
hit: true,
|
|
993
|
-
reason: "hit",
|
|
994
|
-
fingerprint: this.context.fingerprint,
|
|
995
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
996
|
-
details: [`context fingerprint ${this.context.fingerprint.slice(0, 12)} matched`]
|
|
997
|
-
}
|
|
998
|
-
};
|
|
999
|
-
}
|
|
1000
|
-
return {
|
|
1001
|
-
data: /* @__PURE__ */ new Set(),
|
|
1002
|
-
meta: {
|
|
1003
|
-
hit: false,
|
|
1004
|
-
reason: "context-mismatch",
|
|
1005
|
-
fingerprint: this.context.fingerprint,
|
|
1006
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1007
|
-
details: mismatchReasons
|
|
1008
|
-
}
|
|
1009
|
-
};
|
|
1010
|
-
}
|
|
1011
|
-
const projectMatch = this.findProjectMatch(parsed.data);
|
|
1012
|
-
if (projectMatch) {
|
|
1013
|
-
const [matchedFingerprint, matchedEntry] = projectMatch;
|
|
1014
|
-
return {
|
|
1015
|
-
data: /* @__PURE__ */ new Set(),
|
|
1016
|
-
meta: {
|
|
1017
|
-
hit: false,
|
|
1018
|
-
reason: "context-mismatch",
|
|
1019
|
-
fingerprint: this.context.fingerprint,
|
|
1020
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1021
|
-
details: [
|
|
1022
|
-
`nearest context fingerprint: ${matchedFingerprint.slice(0, 12)}`,
|
|
1023
|
-
...explainContextMismatch(this.context.metadata, matchedEntry.context)
|
|
1024
|
-
]
|
|
1025
|
-
}
|
|
1026
|
-
};
|
|
1027
|
-
}
|
|
1028
|
-
return {
|
|
1029
|
-
data: /* @__PURE__ */ new Set(),
|
|
1030
|
-
meta: {
|
|
1031
|
-
hit: false,
|
|
1032
|
-
reason: "context-not-found",
|
|
1033
|
-
fingerprint: this.context.fingerprint,
|
|
1034
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1035
|
-
details: ["context fingerprint not found in cache index"]
|
|
1036
|
-
}
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
readWithMetaSync() {
|
|
1040
|
-
if (!this.options.enabled) {
|
|
1041
|
-
return {
|
|
1042
|
-
data: /* @__PURE__ */ new Set(),
|
|
1043
|
-
meta: {
|
|
1044
|
-
hit: false,
|
|
1045
|
-
reason: "cache-disabled",
|
|
1046
|
-
details: ["cache disabled"]
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
|
-
}
|
|
1050
|
-
if (this.driver === "noop") {
|
|
1051
|
-
return {
|
|
1052
|
-
data: /* @__PURE__ */ new Set(),
|
|
1053
|
-
meta: {
|
|
1054
|
-
hit: false,
|
|
1055
|
-
reason: "noop-driver",
|
|
1056
|
-
details: ["cache driver is noop"]
|
|
1057
|
-
}
|
|
1058
|
-
};
|
|
1059
|
-
}
|
|
1060
|
-
if (this.driver === "memory") {
|
|
1061
|
-
if (!this.isContextAware()) {
|
|
1062
|
-
const cache = new Set(_nullishCoalesce(this.memoryCache, () => ( [])));
|
|
1063
|
-
return {
|
|
1064
|
-
data: cache,
|
|
1065
|
-
meta: {
|
|
1066
|
-
hit: cache.size > 0,
|
|
1067
|
-
reason: cache.size > 0 ? "hit" : "context-not-found",
|
|
1068
|
-
details: cache.size > 0 ? ["memory cache hit"] : ["memory cache miss"]
|
|
1069
|
-
}
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
const index = this.memoryIndex;
|
|
1073
|
-
if (!index || !this.context) {
|
|
1074
|
-
return {
|
|
1075
|
-
data: /* @__PURE__ */ new Set(),
|
|
1076
|
-
meta: {
|
|
1077
|
-
hit: false,
|
|
1078
|
-
reason: "context-not-found",
|
|
1079
|
-
..._optionalChain([this, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.fingerprint]) === void 0 ? {} : { fingerprint: this.context.fingerprint },
|
|
1080
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
1081
|
-
details: ["no in-memory cache index for current context"]
|
|
1082
|
-
}
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
const entry2 = index.contexts[this.context.fingerprint];
|
|
1086
|
-
if (entry2) {
|
|
1087
|
-
return {
|
|
1088
|
-
data: new Set(entry2.values),
|
|
1089
|
-
meta: {
|
|
1090
|
-
hit: true,
|
|
1091
|
-
reason: "hit",
|
|
1092
|
-
fingerprint: this.context.fingerprint,
|
|
1093
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
1094
|
-
details: ["memory cache hit"]
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
}
|
|
1098
|
-
const projectMatch2 = this.findProjectMatch(index);
|
|
1099
|
-
if (projectMatch2 && this.context) {
|
|
1100
|
-
const [, matchedEntry] = projectMatch2;
|
|
1101
|
-
return {
|
|
1102
|
-
data: /* @__PURE__ */ new Set(),
|
|
1103
|
-
meta: {
|
|
1104
|
-
hit: false,
|
|
1105
|
-
reason: "context-mismatch",
|
|
1106
|
-
fingerprint: this.context.fingerprint,
|
|
1107
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
1108
|
-
details: explainContextMismatch(this.context.metadata, matchedEntry.context)
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
data: /* @__PURE__ */ new Set(),
|
|
1114
|
-
meta: {
|
|
1115
|
-
hit: false,
|
|
1116
|
-
reason: "context-not-found",
|
|
1117
|
-
fingerprint: this.context.fingerprint,
|
|
1118
|
-
schemaVersion: CACHE_SCHEMA_VERSION,
|
|
1119
|
-
details: ["context fingerprint not found in memory cache index"]
|
|
1120
|
-
}
|
|
1121
|
-
};
|
|
1122
|
-
}
|
|
1123
|
-
const parsed = this.readParsedCacheFileSync(true);
|
|
1124
|
-
if (parsed.kind === "empty") {
|
|
1125
|
-
return {
|
|
1126
|
-
data: /* @__PURE__ */ new Set(),
|
|
1127
|
-
meta: {
|
|
1128
|
-
hit: false,
|
|
1129
|
-
reason: "file-missing",
|
|
1130
|
-
details: ["cache file not found"]
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1134
|
-
if (parsed.kind === "invalid") {
|
|
1135
|
-
return {
|
|
1136
|
-
data: /* @__PURE__ */ new Set(),
|
|
1137
|
-
meta: {
|
|
1138
|
-
hit: false,
|
|
1139
|
-
reason: "invalid-schema",
|
|
1140
|
-
details: ["cache schema invalid and has been reset"]
|
|
1141
|
-
}
|
|
1142
|
-
};
|
|
1143
|
-
}
|
|
1144
|
-
if (!this.isContextAware()) {
|
|
1145
|
-
if (parsed.kind === "legacy") {
|
|
1146
|
-
return {
|
|
1147
|
-
data: new Set(parsed.data),
|
|
1148
|
-
meta: {
|
|
1149
|
-
hit: parsed.data.length > 0,
|
|
1150
|
-
reason: parsed.data.length > 0 ? "hit" : "context-not-found",
|
|
1151
|
-
details: ["legacy cache format"]
|
|
1152
|
-
}
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
const union = Object.values(parsed.data.contexts).flatMap((entry2) => entry2.values);
|
|
1156
|
-
return {
|
|
1157
|
-
data: new Set(union),
|
|
1158
|
-
meta: {
|
|
1159
|
-
hit: union.length > 0,
|
|
1160
|
-
reason: union.length > 0 ? "hit" : "context-not-found",
|
|
1161
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1162
|
-
details: ["context-less read merged all cache entries"]
|
|
1163
|
-
}
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
if (parsed.kind === "legacy") {
|
|
1167
|
-
return {
|
|
1168
|
-
data: /* @__PURE__ */ new Set(),
|
|
1169
|
-
meta: {
|
|
1170
|
-
hit: false,
|
|
1171
|
-
reason: "legacy-schema",
|
|
1172
|
-
..._optionalChain([this, 'access', _11 => _11.context, 'optionalAccess', _12 => _12.fingerprint]) === void 0 ? {} : { fingerprint: this.context.fingerprint },
|
|
1173
|
-
details: ["legacy cache schema detected; rebuilding cache with context fingerprint"]
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
if (!this.context) {
|
|
1178
|
-
return {
|
|
1179
|
-
data: /* @__PURE__ */ new Set(),
|
|
1180
|
-
meta: {
|
|
1181
|
-
hit: false,
|
|
1182
|
-
reason: "context-not-found",
|
|
1183
|
-
details: ["cache context missing"]
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
}
|
|
1187
|
-
const entry = parsed.data.contexts[this.context.fingerprint];
|
|
1188
|
-
if (entry) {
|
|
1189
|
-
const mismatchReasons = explainContextMismatch(this.context.metadata, entry.context);
|
|
1190
|
-
if (mismatchReasons.length === 0) {
|
|
1191
|
-
return {
|
|
1192
|
-
data: new Set(entry.values),
|
|
1193
|
-
meta: {
|
|
1194
|
-
hit: true,
|
|
1195
|
-
reason: "hit",
|
|
1196
|
-
fingerprint: this.context.fingerprint,
|
|
1197
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1198
|
-
details: [`context fingerprint ${this.context.fingerprint.slice(0, 12)} matched`]
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
|
-
}
|
|
1202
|
-
return {
|
|
1203
|
-
data: /* @__PURE__ */ new Set(),
|
|
1204
|
-
meta: {
|
|
1205
|
-
hit: false,
|
|
1206
|
-
reason: "context-mismatch",
|
|
1207
|
-
fingerprint: this.context.fingerprint,
|
|
1208
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1209
|
-
details: mismatchReasons
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
}
|
|
1213
|
-
const projectMatch = this.findProjectMatch(parsed.data);
|
|
1214
|
-
if (projectMatch) {
|
|
1215
|
-
const [matchedFingerprint, matchedEntry] = projectMatch;
|
|
1216
|
-
return {
|
|
1217
|
-
data: /* @__PURE__ */ new Set(),
|
|
1218
|
-
meta: {
|
|
1219
|
-
hit: false,
|
|
1220
|
-
reason: "context-mismatch",
|
|
1221
|
-
fingerprint: this.context.fingerprint,
|
|
1222
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1223
|
-
details: [
|
|
1224
|
-
`nearest context fingerprint: ${matchedFingerprint.slice(0, 12)}`,
|
|
1225
|
-
...explainContextMismatch(this.context.metadata, matchedEntry.context)
|
|
1226
|
-
]
|
|
1227
|
-
}
|
|
1228
|
-
};
|
|
1229
|
-
}
|
|
1230
|
-
return {
|
|
1231
|
-
data: /* @__PURE__ */ new Set(),
|
|
1232
|
-
meta: {
|
|
1233
|
-
hit: false,
|
|
1234
|
-
reason: "context-not-found",
|
|
1235
|
-
fingerprint: this.context.fingerprint,
|
|
1236
|
-
schemaVersion: parsed.data.schemaVersion,
|
|
1237
|
-
details: ["context fingerprint not found in cache index"]
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
async read() {
|
|
1242
|
-
const result = await this.readWithMeta();
|
|
1243
|
-
this.lastReadMeta = toReadMeta(result.meta);
|
|
1244
|
-
return new Set(result.data);
|
|
1245
|
-
}
|
|
1246
|
-
readSync() {
|
|
1247
|
-
const result = this.readWithMetaSync();
|
|
1248
|
-
this.lastReadMeta = toReadMeta(result.meta);
|
|
1249
|
-
return new Set(result.data);
|
|
1250
|
-
}
|
|
1251
|
-
getLastReadMeta() {
|
|
1252
|
-
return toReadMeta(this.lastReadMeta);
|
|
1253
|
-
}
|
|
1254
|
-
countEntriesFromParsed(parsed) {
|
|
1255
|
-
if (parsed.kind === "legacy") {
|
|
1256
|
-
return {
|
|
1257
|
-
contexts: parsed.data.length ? 1 : 0,
|
|
1258
|
-
entries: parsed.data.length
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
if (parsed.kind === "v2") {
|
|
1262
|
-
const values = Object.values(parsed.data.contexts);
|
|
1263
|
-
return {
|
|
1264
|
-
contexts: values.length,
|
|
1265
|
-
entries: values.reduce((acc, item) => acc + item.values.length, 0)
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
return {
|
|
1269
|
-
contexts: 0,
|
|
1270
|
-
entries: 0
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
async clear(options) {
|
|
1274
|
-
const scope = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _13 => _13.scope]), () => ( "current"));
|
|
1275
|
-
if (!this.options.enabled || this.driver === "noop") {
|
|
1276
|
-
return {
|
|
1277
|
-
scope,
|
|
1278
|
-
filesRemoved: 0,
|
|
1279
|
-
entriesRemoved: 0,
|
|
1280
|
-
contextsRemoved: 0
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
|
-
if (this.driver === "memory") {
|
|
1284
|
-
if (!this.isContextAware() || scope === "all") {
|
|
1285
|
-
const entriesRemoved2 = _nullishCoalesce(_optionalChain([this, 'access', _14 => _14.memoryCache, 'optionalAccess', _15 => _15.size]), () => ( (this.memoryIndex ? this.countEntriesFromParsed({ kind: "v2", data: this.memoryIndex }).entries : 0)));
|
|
1286
|
-
const contextsRemoved = this.memoryIndex ? Object.keys(this.memoryIndex.contexts).length : _optionalChain([this, 'access', _16 => _16.memoryCache, 'optionalAccess', _17 => _17.size]) ? 1 : 0;
|
|
1287
|
-
this.memoryCache = null;
|
|
1288
|
-
this.memoryIndex = null;
|
|
1289
|
-
return {
|
|
1290
|
-
scope,
|
|
1291
|
-
filesRemoved: 0,
|
|
1292
|
-
entriesRemoved: entriesRemoved2,
|
|
1293
|
-
contextsRemoved
|
|
1294
|
-
};
|
|
1295
|
-
}
|
|
1296
|
-
if (!this.context || !this.memoryIndex) {
|
|
1297
|
-
return {
|
|
1298
|
-
scope,
|
|
1299
|
-
filesRemoved: 0,
|
|
1300
|
-
entriesRemoved: 0,
|
|
1301
|
-
contextsRemoved: 0
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
|
-
const entry = this.memoryIndex.contexts[this.context.fingerprint];
|
|
1305
|
-
if (!entry) {
|
|
1306
|
-
return {
|
|
1307
|
-
scope,
|
|
1308
|
-
filesRemoved: 0,
|
|
1309
|
-
entriesRemoved: 0,
|
|
1310
|
-
contextsRemoved: 0
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
const entriesRemoved = entry.values.length;
|
|
1314
|
-
delete this.memoryIndex.contexts[this.context.fingerprint];
|
|
1315
|
-
return {
|
|
1316
|
-
scope,
|
|
1317
|
-
filesRemoved: 0,
|
|
1318
|
-
entriesRemoved,
|
|
1319
|
-
contextsRemoved: 1
|
|
1320
|
-
};
|
|
1321
|
-
}
|
|
1322
|
-
const result = await this.withFileLock(async () => {
|
|
1323
|
-
const parsed = await this.readParsedCacheFile(false);
|
|
1324
|
-
if (parsed.kind === "empty") {
|
|
1325
|
-
return {
|
|
1326
|
-
scope,
|
|
1327
|
-
filesRemoved: 0,
|
|
1328
|
-
entriesRemoved: 0,
|
|
1329
|
-
contextsRemoved: 0
|
|
1330
|
-
};
|
|
1331
|
-
}
|
|
1332
|
-
if (!this.isContextAware() || scope === "all") {
|
|
1333
|
-
const counts = this.countEntriesFromParsed(parsed);
|
|
1334
|
-
await _fsextra2.default.remove(this.options.path);
|
|
1335
|
-
return {
|
|
1336
|
-
scope,
|
|
1337
|
-
filesRemoved: 1,
|
|
1338
|
-
entriesRemoved: counts.entries,
|
|
1339
|
-
contextsRemoved: counts.contexts
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
if (parsed.kind !== "v2" || !this.context) {
|
|
1343
|
-
const counts = this.countEntriesFromParsed(parsed);
|
|
1344
|
-
await _fsextra2.default.remove(this.options.path);
|
|
1345
|
-
return {
|
|
1346
|
-
scope,
|
|
1347
|
-
filesRemoved: 1,
|
|
1348
|
-
entriesRemoved: counts.entries,
|
|
1349
|
-
contextsRemoved: counts.contexts
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
const entry = parsed.data.contexts[this.context.fingerprint];
|
|
1353
|
-
if (!entry) {
|
|
1354
|
-
return {
|
|
1355
|
-
scope,
|
|
1356
|
-
filesRemoved: 0,
|
|
1357
|
-
entriesRemoved: 0,
|
|
1358
|
-
contextsRemoved: 0
|
|
1359
|
-
};
|
|
1360
|
-
}
|
|
1361
|
-
const entriesRemoved = entry.values.length;
|
|
1362
|
-
delete parsed.data.contexts[this.context.fingerprint];
|
|
1363
|
-
const remain = Object.keys(parsed.data.contexts).length;
|
|
1364
|
-
if (remain === 0) {
|
|
1365
|
-
await _fsextra2.default.remove(this.options.path);
|
|
1366
|
-
return {
|
|
1367
|
-
scope,
|
|
1368
|
-
filesRemoved: 1,
|
|
1369
|
-
entriesRemoved,
|
|
1370
|
-
contextsRemoved: 1
|
|
1371
|
-
};
|
|
1372
|
-
}
|
|
1373
|
-
parsed.data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1374
|
-
await this.writeIndexFile(parsed.data);
|
|
1375
|
-
return {
|
|
1376
|
-
scope,
|
|
1377
|
-
filesRemoved: 0,
|
|
1378
|
-
entriesRemoved,
|
|
1379
|
-
contextsRemoved: 1
|
|
1380
|
-
};
|
|
1381
|
-
});
|
|
1382
|
-
return _nullishCoalesce(result, () => ( {
|
|
1383
|
-
scope,
|
|
1384
|
-
filesRemoved: 0,
|
|
1385
|
-
entriesRemoved: 0,
|
|
1386
|
-
contextsRemoved: 0
|
|
1387
|
-
}));
|
|
1388
|
-
}
|
|
1389
|
-
clearSync(options) {
|
|
1390
|
-
const scope = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.scope]), () => ( "current"));
|
|
1391
|
-
if (!this.options.enabled || this.driver === "noop") {
|
|
1392
|
-
return {
|
|
1393
|
-
scope,
|
|
1394
|
-
filesRemoved: 0,
|
|
1395
|
-
entriesRemoved: 0,
|
|
1396
|
-
contextsRemoved: 0
|
|
1397
|
-
};
|
|
1398
|
-
}
|
|
1399
|
-
if (this.driver === "memory") {
|
|
1400
|
-
if (!this.isContextAware() || scope === "all") {
|
|
1401
|
-
const entriesRemoved2 = _nullishCoalesce(_optionalChain([this, 'access', _19 => _19.memoryCache, 'optionalAccess', _20 => _20.size]), () => ( (this.memoryIndex ? this.countEntriesFromParsed({ kind: "v2", data: this.memoryIndex }).entries : 0)));
|
|
1402
|
-
const contextsRemoved = this.memoryIndex ? Object.keys(this.memoryIndex.contexts).length : _optionalChain([this, 'access', _21 => _21.memoryCache, 'optionalAccess', _22 => _22.size]) ? 1 : 0;
|
|
1403
|
-
this.memoryCache = null;
|
|
1404
|
-
this.memoryIndex = null;
|
|
1405
|
-
return {
|
|
1406
|
-
scope,
|
|
1407
|
-
filesRemoved: 0,
|
|
1408
|
-
entriesRemoved: entriesRemoved2,
|
|
1409
|
-
contextsRemoved
|
|
1410
|
-
};
|
|
1411
|
-
}
|
|
1412
|
-
if (!this.context || !this.memoryIndex) {
|
|
1413
|
-
return {
|
|
1414
|
-
scope,
|
|
1415
|
-
filesRemoved: 0,
|
|
1416
|
-
entriesRemoved: 0,
|
|
1417
|
-
contextsRemoved: 0
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1420
|
-
const entry = this.memoryIndex.contexts[this.context.fingerprint];
|
|
1421
|
-
if (!entry) {
|
|
1422
|
-
return {
|
|
1423
|
-
scope,
|
|
1424
|
-
filesRemoved: 0,
|
|
1425
|
-
entriesRemoved: 0,
|
|
1426
|
-
contextsRemoved: 0
|
|
1427
|
-
};
|
|
1428
|
-
}
|
|
1429
|
-
const entriesRemoved = entry.values.length;
|
|
1430
|
-
delete this.memoryIndex.contexts[this.context.fingerprint];
|
|
1431
|
-
return {
|
|
1432
|
-
scope,
|
|
1433
|
-
filesRemoved: 0,
|
|
1434
|
-
entriesRemoved,
|
|
1435
|
-
contextsRemoved: 1
|
|
1436
|
-
};
|
|
1437
|
-
}
|
|
1438
|
-
const result = this.withFileLockSync(() => {
|
|
1439
|
-
const parsed = this.readParsedCacheFileSync(false);
|
|
1440
|
-
if (parsed.kind === "empty") {
|
|
1441
|
-
return {
|
|
1442
|
-
scope,
|
|
1443
|
-
filesRemoved: 0,
|
|
1444
|
-
entriesRemoved: 0,
|
|
1445
|
-
contextsRemoved: 0
|
|
1446
|
-
};
|
|
1447
|
-
}
|
|
1448
|
-
if (!this.isContextAware() || scope === "all") {
|
|
1449
|
-
const counts = this.countEntriesFromParsed(parsed);
|
|
1450
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
1451
|
-
return {
|
|
1452
|
-
scope,
|
|
1453
|
-
filesRemoved: 1,
|
|
1454
|
-
entriesRemoved: counts.entries,
|
|
1455
|
-
contextsRemoved: counts.contexts
|
|
1456
|
-
};
|
|
1457
|
-
}
|
|
1458
|
-
if (parsed.kind !== "v2" || !this.context) {
|
|
1459
|
-
const counts = this.countEntriesFromParsed(parsed);
|
|
1460
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
1461
|
-
return {
|
|
1462
|
-
scope,
|
|
1463
|
-
filesRemoved: 1,
|
|
1464
|
-
entriesRemoved: counts.entries,
|
|
1465
|
-
contextsRemoved: counts.contexts
|
|
1466
|
-
};
|
|
1467
|
-
}
|
|
1468
|
-
const entry = parsed.data.contexts[this.context.fingerprint];
|
|
1469
|
-
if (!entry) {
|
|
1470
|
-
return {
|
|
1471
|
-
scope,
|
|
1472
|
-
filesRemoved: 0,
|
|
1473
|
-
entriesRemoved: 0,
|
|
1474
|
-
contextsRemoved: 0
|
|
1475
|
-
};
|
|
1476
|
-
}
|
|
1477
|
-
const entriesRemoved = entry.values.length;
|
|
1478
|
-
delete parsed.data.contexts[this.context.fingerprint];
|
|
1479
|
-
const remain = Object.keys(parsed.data.contexts).length;
|
|
1480
|
-
if (remain === 0) {
|
|
1481
|
-
_fsextra2.default.removeSync(this.options.path);
|
|
1482
|
-
return {
|
|
1483
|
-
scope,
|
|
1484
|
-
filesRemoved: 1,
|
|
1485
|
-
entriesRemoved,
|
|
1486
|
-
contextsRemoved: 1
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
parsed.data.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1490
|
-
this.writeIndexFileSync(parsed.data);
|
|
1491
|
-
return {
|
|
1492
|
-
scope,
|
|
1493
|
-
filesRemoved: 0,
|
|
1494
|
-
entriesRemoved,
|
|
1495
|
-
contextsRemoved: 1
|
|
1496
|
-
};
|
|
1497
|
-
});
|
|
1498
|
-
return _nullishCoalesce(result, () => ( {
|
|
1499
|
-
scope,
|
|
1500
|
-
filesRemoved: 0,
|
|
1501
|
-
entriesRemoved: 0,
|
|
1502
|
-
contextsRemoved: 0
|
|
1503
|
-
}));
|
|
1504
|
-
}
|
|
1505
|
-
readIndexSnapshot() {
|
|
1506
|
-
if (this.driver === "memory") {
|
|
1507
|
-
return this.memoryIndex ? {
|
|
1508
|
-
...this.memoryIndex,
|
|
1509
|
-
contexts: Object.fromEntries(Object.entries(this.memoryIndex.contexts).map(([key, value]) => [key, cloneEntry(value)]))
|
|
1510
|
-
} : void 0;
|
|
1511
|
-
}
|
|
1512
|
-
const parsed = this.readParsedCacheFileSync(false);
|
|
1513
|
-
if (parsed.kind !== "v2") {
|
|
1514
|
-
return void 0;
|
|
1515
|
-
}
|
|
1516
|
-
return {
|
|
1517
|
-
...parsed.data,
|
|
1518
|
-
contexts: Object.fromEntries(Object.entries(parsed.data.contexts).map(([key, value]) => [key, cloneEntry(value)]))
|
|
1519
|
-
};
|
|
1520
|
-
}
|
|
1521
|
-
}, _class);
|
|
1522
|
-
|
|
1523
|
-
// src/options/normalize.ts
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
function resolveRealpathSafe(value) {
|
|
1528
|
-
const resolved = _pathe2.default.resolve(value);
|
|
1529
|
-
try {
|
|
1530
|
-
return _pathe2.default.normalize(_fsextra2.default.realpathSync(resolved));
|
|
1531
|
-
} catch (e9) {
|
|
1532
|
-
return _pathe2.default.normalize(resolved);
|
|
1533
|
-
}
|
|
1534
|
-
}
|
|
1535
|
-
function toPrettyValue(value) {
|
|
1536
|
-
if (typeof value === "number") {
|
|
1537
|
-
return value > 0 ? value : false;
|
|
1538
|
-
}
|
|
1539
|
-
if (value === true) {
|
|
1540
|
-
return 2;
|
|
1541
|
-
}
|
|
1542
|
-
return false;
|
|
1543
|
-
}
|
|
1544
|
-
function normalizeCacheDriver(driver) {
|
|
1545
|
-
if (driver === "memory" || driver === "noop") {
|
|
1546
|
-
return driver;
|
|
1547
|
-
}
|
|
1548
|
-
return "file";
|
|
1549
|
-
}
|
|
1550
|
-
function normalizeCacheOptions(cache, projectRoot) {
|
|
1551
|
-
let enabled = false;
|
|
1552
|
-
let cwd = resolveRealpathSafe(projectRoot);
|
|
1553
|
-
let dir = _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
1554
|
-
let file = "class-cache.json";
|
|
1555
|
-
let strategy = "merge";
|
|
1556
|
-
let driver = "file";
|
|
1557
|
-
if (typeof cache === "boolean") {
|
|
1558
|
-
enabled = cache;
|
|
1559
|
-
} else if (typeof cache === "object" && cache) {
|
|
1560
|
-
enabled = _nullishCoalesce(cache.enabled, () => ( true));
|
|
1561
|
-
cwd = cache.cwd ? resolveRealpathSafe(cache.cwd) : cwd;
|
|
1562
|
-
dir = cache.dir ? _pathe2.default.resolve(cache.dir) : _pathe2.default.resolve(cwd, "node_modules/.cache", pkgName);
|
|
1563
|
-
file = _nullishCoalesce(cache.file, () => ( file));
|
|
1564
|
-
strategy = _nullishCoalesce(cache.strategy, () => ( strategy));
|
|
1565
|
-
driver = normalizeCacheDriver(cache.driver);
|
|
1566
|
-
}
|
|
1567
|
-
const filename = _pathe2.default.resolve(dir, file);
|
|
1568
|
-
return {
|
|
1569
|
-
enabled,
|
|
1570
|
-
cwd,
|
|
1571
|
-
dir,
|
|
1572
|
-
file,
|
|
1573
|
-
path: filename,
|
|
1574
|
-
strategy,
|
|
1575
|
-
driver
|
|
1576
|
-
};
|
|
1577
|
-
}
|
|
1578
|
-
function normalizeOutputOptions(output) {
|
|
1579
|
-
const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _23 => _23.write]), () => ( true));
|
|
1580
|
-
const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _24 => _24.file]), () => ( ".tw-patch/tw-class-list.json"));
|
|
1581
|
-
const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _25 => _25.format]), () => ( "json"));
|
|
1582
|
-
const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _26 => _26.pretty]), () => ( true)));
|
|
1583
|
-
const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _27 => _27.removeUniversalSelector]), () => ( true));
|
|
1584
|
-
return {
|
|
1585
|
-
enabled,
|
|
1586
|
-
file,
|
|
1587
|
-
format,
|
|
1588
|
-
pretty,
|
|
1589
|
-
removeUniversalSelector
|
|
1590
|
-
};
|
|
1591
|
-
}
|
|
1592
|
-
function normalizeExposeContextOptions(exposeContext) {
|
|
1593
|
-
if (exposeContext === false) {
|
|
1594
|
-
return {
|
|
1595
|
-
enabled: false,
|
|
1596
|
-
refProperty: "contextRef"
|
|
1597
|
-
};
|
|
1598
|
-
}
|
|
1599
|
-
if (typeof exposeContext === "object" && exposeContext) {
|
|
1600
|
-
return {
|
|
1601
|
-
enabled: true,
|
|
1602
|
-
refProperty: _nullishCoalesce(exposeContext.refProperty, () => ( "contextRef"))
|
|
1603
|
-
};
|
|
1604
|
-
}
|
|
1605
|
-
return {
|
|
1606
|
-
enabled: true,
|
|
1607
|
-
refProperty: "contextRef"
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
function normalizeExtendLengthUnitsOptions(extend) {
|
|
1611
|
-
if (extend === false || extend === void 0) {
|
|
1612
|
-
return null;
|
|
1613
|
-
}
|
|
1614
|
-
if (extend.enabled === false) {
|
|
1615
|
-
return null;
|
|
1616
|
-
}
|
|
1617
|
-
const base = {
|
|
1618
|
-
units: ["rpx"],
|
|
1619
|
-
overwrite: true
|
|
1620
|
-
};
|
|
1621
|
-
return {
|
|
1622
|
-
...base,
|
|
1623
|
-
...extend,
|
|
1624
|
-
enabled: _nullishCoalesce(extend.enabled, () => ( true)),
|
|
1625
|
-
units: _nullishCoalesce(extend.units, () => ( base.units)),
|
|
1626
|
-
overwrite: _nullishCoalesce(extend.overwrite, () => ( base.overwrite))
|
|
1627
|
-
};
|
|
1628
|
-
}
|
|
1629
|
-
function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
1630
|
-
const configuredBase = _optionalChain([v4, 'optionalAccess', _28 => _28.base]) ? _pathe2.default.resolve(v4.base) : void 0;
|
|
1631
|
-
const base = _nullishCoalesce(configuredBase, () => ( fallbackBase));
|
|
1632
|
-
const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _29 => _29.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
|
|
1633
|
-
const userSources = _optionalChain([v4, 'optionalAccess', _30 => _30.sources]);
|
|
1634
|
-
const hasUserDefinedSources = Boolean(_optionalChain([userSources, 'optionalAccess', _31 => _31.length]));
|
|
1635
|
-
const sources = hasUserDefinedSources ? userSources : [
|
|
1636
|
-
{
|
|
1637
|
-
base: fallbackBase,
|
|
1638
|
-
pattern: "**/*",
|
|
1639
|
-
negated: false
|
|
1640
|
-
}
|
|
1641
|
-
];
|
|
1642
|
-
return {
|
|
1643
|
-
base,
|
|
1644
|
-
...configuredBase === void 0 ? {} : { configuredBase },
|
|
1645
|
-
..._optionalChain([v4, 'optionalAccess', _32 => _32.css]) === void 0 ? {} : { css: v4.css },
|
|
1646
|
-
cssEntries,
|
|
1647
|
-
sources,
|
|
1648
|
-
hasUserDefinedSources
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
1652
|
-
const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _33 => _33.packageName]), () => ( "tailwindcss"));
|
|
1653
|
-
const versionHint = _optionalChain([tailwind, 'optionalAccess', _34 => _34.version]);
|
|
1654
|
-
const resolve = _optionalChain([tailwind, 'optionalAccess', _35 => _35.resolve]);
|
|
1655
|
-
const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _36 => _36.cwd]), () => ( projectRoot));
|
|
1656
|
-
const config = _optionalChain([tailwind, 'optionalAccess', _37 => _37.config]);
|
|
1657
|
-
const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _38 => _38.postcssPlugin]);
|
|
1658
|
-
const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _39 => _39.v4]), cwd);
|
|
1659
|
-
return {
|
|
1660
|
-
packageName,
|
|
1661
|
-
cwd,
|
|
1662
|
-
...versionHint === void 0 ? {} : { versionHint },
|
|
1663
|
-
...resolve === void 0 ? {} : { resolve },
|
|
1664
|
-
...config === void 0 ? {} : { config },
|
|
1665
|
-
...postcssPlugin === void 0 ? {} : { postcssPlugin },
|
|
1666
|
-
..._optionalChain([tailwind, 'optionalAccess', _40 => _40.v2]) === void 0 ? {} : { v2: tailwind.v2 },
|
|
1667
|
-
..._optionalChain([tailwind, 'optionalAccess', _41 => _41.v3]) === void 0 ? {} : { v3: tailwind.v3 },
|
|
1668
|
-
v4
|
|
1669
|
-
};
|
|
1670
|
-
}
|
|
1671
|
-
var deprecatedOptionMapping = {
|
|
1672
|
-
cwd: "projectRoot",
|
|
1673
|
-
overwrite: "apply.overwrite",
|
|
1674
|
-
tailwind: "tailwindcss",
|
|
1675
|
-
features: "apply",
|
|
1676
|
-
output: "extract"
|
|
1677
|
-
};
|
|
1678
|
-
function assertNoDeprecatedOptions(options) {
|
|
1679
|
-
const used = Object.keys(deprecatedOptionMapping).filter((key) => Object.prototype.hasOwnProperty.call(options, key));
|
|
1680
|
-
if (used.length === 0) {
|
|
1681
|
-
return;
|
|
1682
|
-
}
|
|
1683
|
-
const mapping = used.map((key) => `${key} -> ${deprecatedOptionMapping[key]}`).join(", ");
|
|
1684
|
-
throw new Error(
|
|
1685
|
-
`Legacy TailwindcssPatcher options are no longer supported: ${used.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1686
|
-
);
|
|
1687
|
-
}
|
|
1688
|
-
function normalizeOptions(options = {}) {
|
|
1689
|
-
assertNoDeprecatedOptions(options);
|
|
1690
|
-
const projectRoot = resolveRealpathSafe(options.projectRoot ? _pathe2.default.resolve(options.projectRoot) : _process2.default.cwd());
|
|
1691
|
-
const overwrite = _nullishCoalesce(_optionalChain([options, 'access', _42 => _42.apply, 'optionalAccess', _43 => _43.overwrite]), () => ( true));
|
|
1692
|
-
const output = normalizeOutputOptions(options.extract);
|
|
1693
|
-
const cache = normalizeCacheOptions(options.cache, projectRoot);
|
|
1694
|
-
const tailwind = normalizeTailwindOptions(options.tailwindcss, projectRoot);
|
|
1695
|
-
const exposeContext = normalizeExposeContextOptions(_optionalChain([options, 'access', _44 => _44.apply, 'optionalAccess', _45 => _45.exposeContext]));
|
|
1696
|
-
const extendLengthUnits = normalizeExtendLengthUnitsOptions(_optionalChain([options, 'access', _46 => _46.apply, 'optionalAccess', _47 => _47.extendLengthUnits]));
|
|
1697
|
-
const filter = (className) => {
|
|
1698
|
-
if (output.removeUniversalSelector && className === "*") {
|
|
1699
|
-
return false;
|
|
1700
|
-
}
|
|
1701
|
-
if (typeof options.filter === "function") {
|
|
1702
|
-
return options.filter(className) !== false;
|
|
1703
|
-
}
|
|
1704
|
-
return true;
|
|
1705
|
-
};
|
|
1706
|
-
return {
|
|
1707
|
-
projectRoot,
|
|
1708
|
-
overwrite,
|
|
1709
|
-
tailwind,
|
|
1710
|
-
features: {
|
|
1711
|
-
exposeContext,
|
|
1712
|
-
extendLengthUnits
|
|
1713
|
-
},
|
|
1714
|
-
output,
|
|
1715
|
-
cache,
|
|
1716
|
-
filter
|
|
1717
|
-
};
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
// src/options/legacy.ts
|
|
1721
|
-
var deprecatedRegistryMapping = {
|
|
1722
|
-
output: "extract",
|
|
1723
|
-
tailwind: "tailwindcss"
|
|
1724
|
-
};
|
|
1725
|
-
var deprecatedTailwindMapping = {
|
|
1726
|
-
package: "packageName",
|
|
1727
|
-
legacy: "v2",
|
|
1728
|
-
classic: "v3",
|
|
1729
|
-
next: "v4"
|
|
1730
|
-
};
|
|
1731
|
-
function assertNoDeprecatedRegistryOptions(registry) {
|
|
1732
|
-
const usedRegistryKeys = Object.keys(deprecatedRegistryMapping).filter((key) => Object.prototype.hasOwnProperty.call(registry, key));
|
|
1733
|
-
if (usedRegistryKeys.length > 0) {
|
|
1734
|
-
const mapping = usedRegistryKeys.map((key) => `${key} -> ${deprecatedRegistryMapping[key]}`).join(", ");
|
|
1735
|
-
throw new Error(
|
|
1736
|
-
`Legacy registry fields are no longer supported: ${usedRegistryKeys.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1737
|
-
);
|
|
1738
|
-
}
|
|
1739
|
-
const tailwind = registry.tailwindcss;
|
|
1740
|
-
if (!tailwind) {
|
|
1741
|
-
return;
|
|
1742
|
-
}
|
|
1743
|
-
const usedTailwindKeys = Object.keys(deprecatedTailwindMapping).filter((key) => Object.prototype.hasOwnProperty.call(tailwind, key));
|
|
1744
|
-
if (usedTailwindKeys.length > 0) {
|
|
1745
|
-
const mapping = usedTailwindKeys.map((key) => `${key} -> tailwindcss.${deprecatedTailwindMapping[key]}`).join(", ");
|
|
1746
|
-
throw new Error(
|
|
1747
|
-
`Legacy "registry.tailwindcss" fields are no longer supported: ${usedTailwindKeys.join(", ")}. Use the modern fields instead: ${mapping}.`
|
|
1748
|
-
);
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
function fromUnifiedConfig(registry) {
|
|
1752
|
-
if (!registry) {
|
|
1753
|
-
return {};
|
|
1754
|
-
}
|
|
1755
|
-
assertNoDeprecatedRegistryOptions(registry);
|
|
1756
|
-
const extract = registry.extract ? {
|
|
1757
|
-
...registry.extract.write === void 0 ? {} : { write: registry.extract.write },
|
|
1758
|
-
...registry.extract.file === void 0 ? {} : { file: registry.extract.file },
|
|
1759
|
-
...registry.extract.format === void 0 ? {} : { format: registry.extract.format },
|
|
1760
|
-
...registry.extract.pretty === void 0 ? {} : { pretty: registry.extract.pretty },
|
|
1761
|
-
...registry.extract.removeUniversalSelector === void 0 ? {} : { removeUniversalSelector: registry.extract.removeUniversalSelector }
|
|
1762
|
-
} : void 0;
|
|
1763
|
-
const tailwindcss = registry.tailwindcss ? {
|
|
1764
|
-
...registry.tailwindcss.version === void 0 ? {} : { version: registry.tailwindcss.version },
|
|
1765
|
-
...registry.tailwindcss.packageName === void 0 ? {} : { packageName: registry.tailwindcss.packageName },
|
|
1766
|
-
...registry.tailwindcss.resolve === void 0 ? {} : { resolve: registry.tailwindcss.resolve },
|
|
1767
|
-
...registry.tailwindcss.config === void 0 ? {} : { config: registry.tailwindcss.config },
|
|
1768
|
-
...registry.tailwindcss.cwd === void 0 ? {} : { cwd: registry.tailwindcss.cwd },
|
|
1769
|
-
...registry.tailwindcss.v2 === void 0 ? {} : { v2: registry.tailwindcss.v2 },
|
|
1770
|
-
...registry.tailwindcss.v3 === void 0 ? {} : { v3: registry.tailwindcss.v3 },
|
|
1771
|
-
...registry.tailwindcss.v4 === void 0 ? {} : { v4: registry.tailwindcss.v4 }
|
|
1772
|
-
} : void 0;
|
|
1773
|
-
const apply = registry.apply ? {
|
|
1774
|
-
...registry.apply.overwrite === void 0 ? {} : { overwrite: registry.apply.overwrite },
|
|
1775
|
-
...registry.apply.exposeContext === void 0 ? {} : { exposeContext: registry.apply.exposeContext },
|
|
1776
|
-
...registry.apply.extendLengthUnits === void 0 ? {} : { extendLengthUnits: registry.apply.extendLengthUnits }
|
|
1777
|
-
} : void 0;
|
|
1778
|
-
return {
|
|
1779
|
-
...registry.projectRoot === void 0 ? {} : { projectRoot: registry.projectRoot },
|
|
1780
|
-
...apply === void 0 ? {} : { apply },
|
|
1781
|
-
...registry.cache === void 0 ? {} : { cache: registry.cache },
|
|
1782
|
-
...registry.filter === void 0 ? {} : { filter: registry.filter },
|
|
1783
|
-
...extract === void 0 ? {} : { extract },
|
|
1784
|
-
...tailwindcss === void 0 ? {} : { tailwindcss }
|
|
1785
|
-
};
|
|
1786
|
-
}
|
|
1787
|
-
|
|
1788
|
-
// src/config/workspace.ts
|
|
1789
|
-
var _url = require('url');
|
|
1790
|
-
|
|
1791
|
-
var configModulePromise;
|
|
1792
|
-
var defuPromise;
|
|
1793
|
-
function isNodeError(error) {
|
|
1794
|
-
return !!error && typeof error === "object" && ("code" in error || "message" in error);
|
|
1795
|
-
}
|
|
1796
|
-
function isMissingModuleError(error, pkgName2) {
|
|
1797
|
-
if (!isNodeError(error)) {
|
|
1798
|
-
return false;
|
|
1799
|
-
}
|
|
1800
|
-
const code = error.code;
|
|
1801
|
-
if (code !== "MODULE_NOT_FOUND" && code !== "ERR_MODULE_NOT_FOUND") {
|
|
1802
|
-
return false;
|
|
1803
|
-
}
|
|
1804
|
-
const message = _nullishCoalesce(error.message, () => ( ""));
|
|
1805
|
-
return message.includes(pkgName2) || message.includes(`${pkgName2}/dist/`);
|
|
1806
|
-
}
|
|
1807
|
-
function isMissingConfigModuleError(error) {
|
|
1808
|
-
return isMissingModuleError(error, "@tailwindcss-mangle/config");
|
|
1809
|
-
}
|
|
1810
|
-
function isMissingSharedModuleError(error) {
|
|
1811
|
-
return isMissingModuleError(error, "@tailwindcss-mangle/shared");
|
|
1812
|
-
}
|
|
1813
|
-
async function loadWorkspaceConfigModule() {
|
|
1814
|
-
if (!configModulePromise) {
|
|
1815
|
-
configModulePromise = Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss-mangle/config"))).catch(async (error) => {
|
|
1816
|
-
if (!isMissingConfigModuleError(error)) {
|
|
1817
|
-
throw error;
|
|
1818
|
-
}
|
|
1819
|
-
const fallback = _pathe2.default.resolve(__dirname, "../../../config/src/index.ts");
|
|
1820
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require(_url.pathToFileURL.call(void 0, fallback).href)));
|
|
1821
|
-
});
|
|
1822
|
-
}
|
|
1823
|
-
return configModulePromise;
|
|
1824
|
-
}
|
|
1825
|
-
async function loadWorkspaceDefu() {
|
|
1826
|
-
if (!defuPromise) {
|
|
1827
|
-
defuPromise = Promise.resolve().then(() => _interopRequireWildcard(require("./dist-22YCNIJW.js"))).then((mod) => mod.defu).catch(async (error) => {
|
|
1828
|
-
if (!isMissingSharedModuleError(error)) {
|
|
1829
|
-
throw error;
|
|
1830
|
-
}
|
|
1831
|
-
const fallback = _pathe2.default.resolve(__dirname, "../../../shared/src/utils.ts");
|
|
1832
|
-
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require(_url.pathToFileURL.call(void 0, fallback).href)));
|
|
1833
|
-
return mod.defu;
|
|
1834
|
-
});
|
|
1835
|
-
}
|
|
1836
|
-
return defuPromise;
|
|
1837
|
-
}
|
|
1838
|
-
async function loadPatchOptionsForWorkspace(cwd, overrides) {
|
|
1839
|
-
const merge = await loadWorkspaceDefu();
|
|
1840
|
-
const configModule = await loadWorkspaceConfigModule();
|
|
1841
|
-
const { config } = await configModule.getConfig(cwd);
|
|
1842
|
-
if (config && typeof config === "object" && "patch" in config && config.patch !== void 0) {
|
|
1843
|
-
throw new Error('Legacy workspace config field "patch" is no longer supported. Move patcher options under "registry".');
|
|
1844
|
-
}
|
|
1845
|
-
const base = _optionalChain([config, 'optionalAccess', _48 => _48.registry]) ? fromUnifiedConfig(config.registry) : {};
|
|
1846
|
-
const merged = merge(_nullishCoalesce(overrides, () => ( {})), base);
|
|
1847
|
-
return merged;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
// src/extraction/candidate-extractor.ts
|
|
1851
|
-
var _fs = require('fs');
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
var nodeImportPromise;
|
|
1855
|
-
var oxideImportPromise;
|
|
1856
|
-
var designSystemPromiseCache = /* @__PURE__ */ new Map();
|
|
1857
|
-
var designSystemCandidateCache = /* @__PURE__ */ new Map();
|
|
1858
|
-
async function importNode() {
|
|
1859
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
|
|
1860
|
-
}
|
|
1861
|
-
async function importOxide() {
|
|
1862
|
-
return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
|
|
1863
|
-
}
|
|
1864
|
-
function getNodeModule() {
|
|
1865
|
-
nodeImportPromise ??= importNode();
|
|
1866
|
-
return nodeImportPromise;
|
|
1867
|
-
}
|
|
1868
|
-
function getOxideModule() {
|
|
1869
|
-
oxideImportPromise ??= importOxide();
|
|
1870
|
-
return oxideImportPromise;
|
|
1871
|
-
}
|
|
1872
|
-
function createDesignSystemCacheKey(css, bases) {
|
|
1873
|
-
return JSON.stringify({
|
|
1874
|
-
css,
|
|
1875
|
-
bases: Array.from(new Set(bases.filter(Boolean)))
|
|
1876
|
-
});
|
|
1877
|
-
}
|
|
1878
|
-
async function loadDesignSystem(css, bases) {
|
|
1879
|
-
const uniqueBases = Array.from(new Set(bases.filter(Boolean)));
|
|
1880
|
-
if (uniqueBases.length === 0) {
|
|
1881
|
-
throw new Error("No base directories provided for Tailwind CSS design system.");
|
|
1882
|
-
}
|
|
1883
|
-
const cacheKey = createDesignSystemCacheKey(css, uniqueBases);
|
|
1884
|
-
const cached = designSystemPromiseCache.get(cacheKey);
|
|
1885
|
-
if (cached) {
|
|
1886
|
-
return cached;
|
|
1887
|
-
}
|
|
1888
|
-
const promise = (async () => {
|
|
1889
|
-
const { __unstable__loadDesignSystem } = await getNodeModule();
|
|
1890
|
-
let lastError;
|
|
1891
|
-
for (const base of uniqueBases) {
|
|
1892
|
-
try {
|
|
1893
|
-
return await __unstable__loadDesignSystem(css, { base });
|
|
1894
|
-
} catch (error) {
|
|
1895
|
-
lastError = error;
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
if (lastError instanceof Error) {
|
|
1899
|
-
throw lastError;
|
|
1900
|
-
}
|
|
1901
|
-
throw new Error("Failed to load Tailwind CSS design system.");
|
|
1902
|
-
})();
|
|
1903
|
-
designSystemPromiseCache.set(cacheKey, promise);
|
|
1904
|
-
promise.catch(() => {
|
|
1905
|
-
if (designSystemPromiseCache.get(cacheKey) === promise) {
|
|
1906
|
-
designSystemPromiseCache.delete(cacheKey);
|
|
1907
|
-
designSystemCandidateCache.delete(cacheKey);
|
|
1908
|
-
}
|
|
1909
|
-
});
|
|
1910
|
-
return promise;
|
|
1911
|
-
}
|
|
1912
|
-
async function extractRawCandidatesWithPositions(content, extension = "html") {
|
|
1913
|
-
const { Scanner } = await getOxideModule();
|
|
1914
|
-
const scanner = new Scanner({});
|
|
1915
|
-
const result = scanner.getCandidatesWithPositions({ content, extension });
|
|
1916
|
-
return result.map(({ candidate, position }) => ({
|
|
1917
|
-
rawCandidate: candidate,
|
|
1918
|
-
start: position,
|
|
1919
|
-
end: position + candidate.length
|
|
1920
|
-
}));
|
|
1921
|
-
}
|
|
1922
|
-
async function extractRawCandidates(sources) {
|
|
1923
|
-
const { Scanner } = await getOxideModule();
|
|
1924
|
-
const scanner = new Scanner(sources === void 0 ? {} : { sources });
|
|
1925
|
-
return scanner.scan();
|
|
1926
|
-
}
|
|
1927
|
-
async function extractValidCandidates(options) {
|
|
1928
|
-
const providedOptions = _nullishCoalesce(options, () => ( {}));
|
|
1929
|
-
const defaultCwd = _nullishCoalesce(providedOptions.cwd, () => ( _process2.default.cwd()));
|
|
1930
|
-
const base = _nullishCoalesce(providedOptions.base, () => ( defaultCwd));
|
|
1931
|
-
const baseFallbacks = _nullishCoalesce(providedOptions.baseFallbacks, () => ( []));
|
|
1932
|
-
const css = _nullishCoalesce(providedOptions.css, () => ( '@import "tailwindcss";'));
|
|
1933
|
-
const sources = (_nullishCoalesce(providedOptions.sources, () => ( [
|
|
1934
|
-
{
|
|
1935
|
-
base: defaultCwd,
|
|
1936
|
-
pattern: "**/*",
|
|
1937
|
-
negated: false
|
|
1938
|
-
}
|
|
1939
|
-
]))).map((source) => ({
|
|
1940
|
-
base: _nullishCoalesce(source.base, () => ( defaultCwd)),
|
|
1941
|
-
pattern: source.pattern,
|
|
1942
|
-
negated: source.negated
|
|
1943
|
-
}));
|
|
1944
|
-
const designSystemKey = createDesignSystemCacheKey(css, [base, ...baseFallbacks]);
|
|
1945
|
-
const designSystem = await loadDesignSystem(css, [base, ...baseFallbacks]);
|
|
1946
|
-
const candidateCache = _nullishCoalesce(designSystemCandidateCache.get(designSystemKey), () => ( /* @__PURE__ */ new Map()));
|
|
1947
|
-
designSystemCandidateCache.set(designSystemKey, candidateCache);
|
|
1948
|
-
const candidates = await extractRawCandidates(sources);
|
|
1949
|
-
const validCandidates = [];
|
|
1950
|
-
const uncachedCandidates = [];
|
|
1951
|
-
for (const rawCandidate of candidates) {
|
|
1952
|
-
const cached = candidateCache.get(rawCandidate);
|
|
1953
|
-
if (cached === true) {
|
|
1954
|
-
validCandidates.push(rawCandidate);
|
|
1955
|
-
continue;
|
|
1956
|
-
}
|
|
1957
|
-
if (cached === false) {
|
|
1958
|
-
continue;
|
|
1959
|
-
}
|
|
1960
|
-
if (designSystem.parseCandidate(rawCandidate).length > 0) {
|
|
1961
|
-
uncachedCandidates.push(rawCandidate);
|
|
1962
|
-
continue;
|
|
1963
|
-
}
|
|
1964
|
-
candidateCache.set(rawCandidate, false);
|
|
1965
|
-
}
|
|
1966
|
-
if (uncachedCandidates.length === 0) {
|
|
1967
|
-
return validCandidates;
|
|
1968
|
-
}
|
|
1969
|
-
const cssByCandidate = designSystem.candidatesToCss(uncachedCandidates);
|
|
1970
|
-
for (let index = 0; index < uncachedCandidates.length; index++) {
|
|
1971
|
-
const candidate = uncachedCandidates[index];
|
|
1972
|
-
if (candidate === void 0) {
|
|
1973
|
-
continue;
|
|
1974
|
-
}
|
|
1975
|
-
const candidateCss = cssByCandidate[index];
|
|
1976
|
-
const isValid = typeof candidateCss === "string" && candidateCss.trim().length > 0;
|
|
1977
|
-
candidateCache.set(candidate, isValid);
|
|
1978
|
-
if (!isValid) {
|
|
1979
|
-
continue;
|
|
1980
|
-
}
|
|
1981
|
-
validCandidates.push(candidate);
|
|
1982
|
-
}
|
|
1983
|
-
return validCandidates;
|
|
1984
|
-
}
|
|
1985
|
-
function normalizeSources(sources, cwd) {
|
|
1986
|
-
const baseSources = _optionalChain([sources, 'optionalAccess', _49 => _49.length]) ? sources : [
|
|
1987
|
-
{
|
|
1988
|
-
base: cwd,
|
|
1989
|
-
pattern: "**/*",
|
|
1990
|
-
negated: false
|
|
1991
|
-
}
|
|
1992
|
-
];
|
|
1993
|
-
return baseSources.map((source) => ({
|
|
1994
|
-
base: _nullishCoalesce(source.base, () => ( cwd)),
|
|
1995
|
-
pattern: source.pattern,
|
|
1996
|
-
negated: source.negated
|
|
1997
|
-
}));
|
|
1998
|
-
}
|
|
1999
|
-
function buildLineOffsets(content) {
|
|
2000
|
-
const offsets = [0];
|
|
2001
|
-
for (let i = 0; i < content.length; i++) {
|
|
2002
|
-
if (content[i] === "\n") {
|
|
2003
|
-
offsets.push(i + 1);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
if (offsets[offsets.length - 1] !== content.length) {
|
|
2007
|
-
offsets.push(content.length);
|
|
2008
|
-
}
|
|
2009
|
-
return offsets;
|
|
2010
|
-
}
|
|
2011
|
-
function resolveLineMeta(content, offsets, index) {
|
|
2012
|
-
let low = 0;
|
|
2013
|
-
let high = offsets.length - 1;
|
|
2014
|
-
while (low <= high) {
|
|
2015
|
-
const mid = Math.floor((low + high) / 2);
|
|
2016
|
-
const start = offsets[mid];
|
|
2017
|
-
if (start === void 0) {
|
|
2018
|
-
break;
|
|
2019
|
-
}
|
|
2020
|
-
const nextStart = _nullishCoalesce(offsets[mid + 1], () => ( content.length));
|
|
2021
|
-
if (index < start) {
|
|
2022
|
-
high = mid - 1;
|
|
2023
|
-
continue;
|
|
2024
|
-
}
|
|
2025
|
-
if (index >= nextStart) {
|
|
2026
|
-
low = mid + 1;
|
|
2027
|
-
continue;
|
|
2028
|
-
}
|
|
2029
|
-
const line = mid + 1;
|
|
2030
|
-
const column = index - start + 1;
|
|
2031
|
-
const lineEnd = content.indexOf("\n", start);
|
|
2032
|
-
const lineText = content.slice(start, lineEnd === -1 ? content.length : lineEnd);
|
|
2033
|
-
return { line, column, lineText };
|
|
2034
|
-
}
|
|
2035
|
-
const lastStart = _nullishCoalesce(offsets[offsets.length - 2], () => ( 0));
|
|
2036
|
-
return {
|
|
2037
|
-
line: offsets.length - 1,
|
|
2038
|
-
column: index - lastStart + 1,
|
|
2039
|
-
lineText: content.slice(lastStart)
|
|
2040
|
-
};
|
|
2041
|
-
}
|
|
2042
|
-
function toExtension(filename) {
|
|
2043
|
-
const ext = _pathe2.default.extname(filename).replace(/^\./, "");
|
|
2044
|
-
return ext || "txt";
|
|
2045
|
-
}
|
|
2046
|
-
function toRelativeFile(cwd, filename) {
|
|
2047
|
-
const relative = _pathe2.default.relative(cwd, filename);
|
|
2048
|
-
return relative === "" ? _pathe2.default.basename(filename) : relative;
|
|
2049
|
-
}
|
|
2050
|
-
async function extractProjectCandidatesWithPositions(options) {
|
|
2051
|
-
const cwd = _optionalChain([options, 'optionalAccess', _50 => _50.cwd]) ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
|
|
2052
|
-
const normalizedSources = normalizeSources(_optionalChain([options, 'optionalAccess', _51 => _51.sources]), cwd);
|
|
2053
|
-
const { Scanner } = await getOxideModule();
|
|
2054
|
-
const scanner = new Scanner({
|
|
2055
|
-
sources: normalizedSources
|
|
2056
|
-
});
|
|
2057
|
-
const files = _nullishCoalesce(scanner.files, () => ( []));
|
|
2058
|
-
const entries = [];
|
|
2059
|
-
const skipped = [];
|
|
2060
|
-
for (const file of files) {
|
|
2061
|
-
let content;
|
|
2062
|
-
try {
|
|
2063
|
-
content = await _fs.promises.readFile(file, "utf8");
|
|
2064
|
-
} catch (error) {
|
|
2065
|
-
skipped.push({
|
|
2066
|
-
file,
|
|
2067
|
-
reason: error instanceof Error ? error.message : "Unknown error"
|
|
2068
|
-
});
|
|
2069
|
-
continue;
|
|
2070
|
-
}
|
|
2071
|
-
const extension = toExtension(file);
|
|
2072
|
-
const matches = scanner.getCandidatesWithPositions({
|
|
2073
|
-
file,
|
|
2074
|
-
content,
|
|
2075
|
-
extension
|
|
2076
|
-
});
|
|
2077
|
-
if (!matches.length) {
|
|
2078
|
-
continue;
|
|
2079
|
-
}
|
|
2080
|
-
const offsets = buildLineOffsets(content);
|
|
2081
|
-
const relativeFile = toRelativeFile(cwd, file);
|
|
2082
|
-
for (const match of matches) {
|
|
2083
|
-
const info = resolveLineMeta(content, offsets, match.position);
|
|
2084
|
-
entries.push({
|
|
2085
|
-
rawCandidate: match.candidate,
|
|
2086
|
-
file,
|
|
2087
|
-
relativeFile,
|
|
2088
|
-
extension,
|
|
2089
|
-
start: match.position,
|
|
2090
|
-
end: match.position + match.candidate.length,
|
|
2091
|
-
length: match.candidate.length,
|
|
2092
|
-
line: info.line,
|
|
2093
|
-
column: info.column,
|
|
2094
|
-
lineText: info.lineText
|
|
2095
|
-
});
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
return {
|
|
2099
|
-
entries,
|
|
2100
|
-
filesScanned: files.length,
|
|
2101
|
-
skippedFiles: skipped,
|
|
2102
|
-
sources: normalizedSources
|
|
2103
|
-
};
|
|
2104
|
-
}
|
|
2105
|
-
function groupTokensByFile(report, options) {
|
|
2106
|
-
const key = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _52 => _52.key]), () => ( "relative"));
|
|
2107
|
-
const stripAbsolute = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _53 => _53.stripAbsolutePaths]), () => ( key !== "absolute"));
|
|
2108
|
-
return report.entries.reduce((acc, entry) => {
|
|
2109
|
-
const bucketKey = key === "absolute" ? entry.file : entry.relativeFile;
|
|
2110
|
-
const bucket = _nullishCoalesce(acc[bucketKey], () => ( (acc[bucketKey] = [])));
|
|
2111
|
-
const value = stripAbsolute ? {
|
|
2112
|
-
...entry,
|
|
2113
|
-
file: entry.relativeFile
|
|
2114
|
-
} : entry;
|
|
2115
|
-
bucket.push(value);
|
|
2116
|
-
return acc;
|
|
2117
|
-
}, {});
|
|
2118
|
-
}
|
|
2119
|
-
|
|
2120
|
-
// src/runtime/class-collector.ts
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
// src/utils.ts
|
|
2126
|
-
function isObject(val) {
|
|
2127
|
-
return val !== null && typeof val === "object" && Array.isArray(val) === false;
|
|
2128
|
-
}
|
|
2129
|
-
function spliceChangesIntoString(str, changes) {
|
|
2130
|
-
const firstChange = changes[0];
|
|
2131
|
-
if (!firstChange) {
|
|
2132
|
-
return str;
|
|
2133
|
-
}
|
|
2134
|
-
changes.sort((a, b) => {
|
|
2135
|
-
return a.end - b.end || a.start - b.start;
|
|
2136
|
-
});
|
|
2137
|
-
let result = "";
|
|
2138
|
-
let previous = firstChange;
|
|
2139
|
-
result += str.slice(0, previous.start);
|
|
2140
|
-
result += previous.replacement;
|
|
2141
|
-
for (let i = 1; i < changes.length; ++i) {
|
|
2142
|
-
const change = changes[i];
|
|
2143
|
-
if (!change) {
|
|
2144
|
-
continue;
|
|
2145
|
-
}
|
|
2146
|
-
result += str.slice(previous.end, change.start);
|
|
2147
|
-
result += change.replacement;
|
|
2148
|
-
previous = change;
|
|
2149
|
-
}
|
|
2150
|
-
result += str.slice(previous.end);
|
|
2151
|
-
return result;
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
// src/runtime/class-collector.ts
|
|
2155
|
-
function collectRuntimeCandidateKeys(context) {
|
|
2156
|
-
const candidateRuleCache = context.candidateRuleCache;
|
|
2157
|
-
if (candidateRuleCache instanceof Map && candidateRuleCache.size > 0) {
|
|
2158
|
-
return candidateRuleCache.keys();
|
|
2159
|
-
}
|
|
2160
|
-
return context.classCache.keys();
|
|
2161
|
-
}
|
|
2162
|
-
function collectClassesFromContexts(contexts, filter) {
|
|
2163
|
-
const set = /* @__PURE__ */ new Set();
|
|
2164
|
-
for (const context of contexts) {
|
|
2165
|
-
if (!isObject(context) || !context.classCache) {
|
|
2166
|
-
continue;
|
|
2167
|
-
}
|
|
2168
|
-
for (const key of collectRuntimeCandidateKeys(context)) {
|
|
2169
|
-
const className = key.toString();
|
|
2170
|
-
if (filter(className)) {
|
|
2171
|
-
set.add(className);
|
|
2172
|
-
}
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
return set;
|
|
2176
|
-
}
|
|
2177
|
-
async function collectClassesFromTailwindV4(options) {
|
|
2178
|
-
const set = /* @__PURE__ */ new Set();
|
|
2179
|
-
const v4Options = options.tailwind.v4;
|
|
2180
|
-
if (!v4Options) {
|
|
2181
|
-
return set;
|
|
2182
|
-
}
|
|
2183
|
-
const toAbsolute = (value) => {
|
|
2184
|
-
if (!value) {
|
|
2185
|
-
return void 0;
|
|
2186
|
-
}
|
|
2187
|
-
return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
|
|
2188
|
-
};
|
|
2189
|
-
const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
|
|
2190
|
-
const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
|
|
2191
|
-
const resolveSources = (base) => {
|
|
2192
|
-
if (!_optionalChain([v4Options, 'access', _54 => _54.sources, 'optionalAccess', _55 => _55.length])) {
|
|
2193
|
-
return void 0;
|
|
2194
|
-
}
|
|
2195
|
-
return v4Options.sources.map((source) => ({
|
|
2196
|
-
base: _nullishCoalesce(source.base, () => ( base)),
|
|
2197
|
-
pattern: source.pattern,
|
|
2198
|
-
negated: source.negated
|
|
2199
|
-
}));
|
|
2200
|
-
};
|
|
2201
|
-
if (v4Options.cssEntries.length > 0) {
|
|
2202
|
-
for (const entry of v4Options.cssEntries) {
|
|
2203
|
-
const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
|
|
2204
|
-
if (!await _fsextra2.default.pathExists(filePath)) {
|
|
2205
|
-
continue;
|
|
2206
|
-
}
|
|
2207
|
-
const css = await _fsextra2.default.readFile(filePath, "utf8");
|
|
2208
|
-
const entryDir = _pathe2.default.dirname(filePath);
|
|
2209
|
-
const designSystemBases = resolvedConfiguredBase && resolvedConfiguredBase !== entryDir ? [entryDir, resolvedConfiguredBase] : [entryDir];
|
|
2210
|
-
const sourcesBase = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
|
|
2211
|
-
const sources = resolveSources(sourcesBase);
|
|
2212
|
-
const firstBase = _nullishCoalesce(designSystemBases[0], () => ( entryDir));
|
|
2213
|
-
const extractOptions = {
|
|
2214
|
-
cwd: options.projectRoot,
|
|
2215
|
-
base: firstBase,
|
|
2216
|
-
baseFallbacks: designSystemBases.slice(1),
|
|
2217
|
-
css,
|
|
2218
|
-
...sources === void 0 ? {} : { sources }
|
|
2219
|
-
};
|
|
2220
|
-
const candidates = await extractValidCandidates(extractOptions);
|
|
2221
|
-
for (const candidate of candidates) {
|
|
2222
|
-
if (options.filter(candidate)) {
|
|
2223
|
-
set.add(candidate);
|
|
2224
|
-
}
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
} else {
|
|
2228
|
-
const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
|
|
2229
|
-
const sources = resolveSources(baseForCss);
|
|
2230
|
-
const extractOptions = {
|
|
2231
|
-
cwd: options.projectRoot,
|
|
2232
|
-
base: baseForCss,
|
|
2233
|
-
...v4Options.css === void 0 ? {} : { css: v4Options.css },
|
|
2234
|
-
...sources === void 0 ? {} : { sources }
|
|
2235
|
-
};
|
|
2236
|
-
const candidates = await extractValidCandidates(extractOptions);
|
|
2237
|
-
for (const candidate of candidates) {
|
|
2238
|
-
if (options.filter(candidate)) {
|
|
2239
|
-
set.add(candidate);
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
}
|
|
2243
|
-
return set;
|
|
2244
|
-
}
|
|
2245
|
-
|
|
2246
|
-
// src/runtime/context-registry.ts
|
|
2247
|
-
var _module = require('module');
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
var require2 = _module.createRequire.call(void 0, _chunkZPLR2UEWjs.importMetaUrl);
|
|
2251
|
-
function resolveRuntimeEntry(packageInfo, majorVersion) {
|
|
2252
|
-
const root = packageInfo.rootPath;
|
|
2253
|
-
if (majorVersion === 2) {
|
|
2254
|
-
const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
|
|
2255
|
-
if (_fsextra2.default.existsSync(jitIndex)) {
|
|
2256
|
-
return jitIndex;
|
|
2257
|
-
}
|
|
2258
|
-
} else if (majorVersion === 3) {
|
|
2259
|
-
const plugin = _pathe2.default.join(root, "lib/plugin.js");
|
|
2260
|
-
const index = _pathe2.default.join(root, "lib/index.js");
|
|
2261
|
-
if (_fsextra2.default.existsSync(plugin)) {
|
|
2262
|
-
return plugin;
|
|
2263
|
-
}
|
|
2264
|
-
if (_fsextra2.default.existsSync(index)) {
|
|
2265
|
-
return index;
|
|
2266
|
-
}
|
|
2267
|
-
}
|
|
2268
|
-
return void 0;
|
|
2269
|
-
}
|
|
2270
|
-
function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
|
|
2271
|
-
if (majorVersion === 4) {
|
|
2272
|
-
return [];
|
|
2273
|
-
}
|
|
2274
|
-
const entry = resolveRuntimeEntry(packageInfo, majorVersion);
|
|
2275
|
-
if (!entry) {
|
|
2276
|
-
return [];
|
|
2277
|
-
}
|
|
2278
|
-
const moduleExports = require2(entry);
|
|
2279
|
-
if (!moduleExports) {
|
|
2280
|
-
return [];
|
|
2281
|
-
}
|
|
2282
|
-
const ref = moduleExports[refProperty];
|
|
2283
|
-
if (!ref) {
|
|
2284
|
-
return [];
|
|
2285
|
-
}
|
|
2286
|
-
if (Array.isArray(ref)) {
|
|
2287
|
-
return ref;
|
|
2288
|
-
}
|
|
2289
|
-
if (typeof ref === "object" && Array.isArray(ref.value)) {
|
|
2290
|
-
return ref.value;
|
|
2291
|
-
}
|
|
2292
|
-
return [];
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
// src/runtime/process-tailwindcss.ts
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
|
|
2300
|
-
var _tailwindcssconfig = require('tailwindcss-config');
|
|
2301
|
-
var require3 = _module.createRequire.call(void 0, _chunkZPLR2UEWjs.importMetaUrl);
|
|
2302
|
-
function resolveModuleEntry(id) {
|
|
2303
|
-
return _pathe2.default.isAbsolute(id) ? id : require3.resolve(id);
|
|
2304
|
-
}
|
|
2305
|
-
function resolvePackageRootFromEntry(entry) {
|
|
2306
|
-
let current = _pathe2.default.dirname(entry);
|
|
2307
|
-
while (current && current !== _pathe2.default.dirname(current)) {
|
|
2308
|
-
const packageJsonPath = _pathe2.default.join(current, "package.json");
|
|
2309
|
-
if (_fsextra2.default.pathExistsSync(packageJsonPath)) {
|
|
2310
|
-
return current;
|
|
2311
|
-
}
|
|
2312
|
-
current = _pathe2.default.dirname(current);
|
|
2313
|
-
}
|
|
2314
|
-
return void 0;
|
|
2315
|
-
}
|
|
2316
|
-
function clearTailwindV3RuntimeState(pluginName) {
|
|
2317
|
-
try {
|
|
2318
|
-
const entry = resolveModuleEntry(pluginName);
|
|
2319
|
-
const root = resolvePackageRootFromEntry(entry);
|
|
2320
|
-
if (!root) {
|
|
2321
|
-
return;
|
|
2322
|
-
}
|
|
2323
|
-
const sharedStatePath = _pathe2.default.join(root, "lib/lib/sharedState.js");
|
|
2324
|
-
if (!_fsextra2.default.pathExistsSync(sharedStatePath)) {
|
|
2325
|
-
return;
|
|
2326
|
-
}
|
|
2327
|
-
const sharedState = _optionalChain([require3, 'access', _56 => _56.cache, 'access', _57 => _57[sharedStatePath], 'optionalAccess', _58 => _58.exports]);
|
|
2328
|
-
_optionalChain([sharedState, 'optionalAccess', _59 => _59.contextMap, 'optionalAccess', _60 => _60.clear, 'call', _61 => _61()]);
|
|
2329
|
-
_optionalChain([sharedState, 'optionalAccess', _62 => _62.configContextMap, 'optionalAccess', _63 => _63.clear, 'call', _64 => _64()]);
|
|
2330
|
-
_optionalChain([sharedState, 'optionalAccess', _65 => _65.contextSourcesMap, 'optionalAccess', _66 => _66.clear, 'call', _67 => _67()]);
|
|
2331
|
-
_optionalChain([sharedState, 'optionalAccess', _68 => _68.sourceHashMap, 'optionalAccess', _69 => _69.clear, 'call', _70 => _70()]);
|
|
2332
|
-
for (const candidate of ["lib/plugin.js", "lib/index.js"]) {
|
|
2333
|
-
const runtimeEntry = _pathe2.default.join(root, candidate);
|
|
2334
|
-
if (!_fsextra2.default.pathExistsSync(runtimeEntry)) {
|
|
2335
|
-
continue;
|
|
2336
|
-
}
|
|
2337
|
-
const runtimeModule = _optionalChain([require3, 'access', _71 => _71.cache, 'access', _72 => _72[runtimeEntry], 'optionalAccess', _73 => _73.exports]);
|
|
2338
|
-
_optionalChain([runtimeModule, 'optionalAccess', _74 => _74.contextRef, 'optionalAccess', _75 => _75.value, 'optionalAccess', _76 => _76.splice, 'call', _77 => _77(0, runtimeModule.contextRef.value.length)]);
|
|
2339
|
-
break;
|
|
2340
|
-
}
|
|
2341
|
-
} catch (e10) {
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
async function resolveConfigPath(options) {
|
|
2345
|
-
if (options.config && _pathe2.default.isAbsolute(options.config)) {
|
|
2346
|
-
return options.config;
|
|
2347
|
-
}
|
|
2348
|
-
const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
|
|
2349
|
-
if (!result) {
|
|
2350
|
-
throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
|
|
2351
|
-
}
|
|
2352
|
-
return result.filepath;
|
|
2353
|
-
}
|
|
2354
|
-
async function runTailwindBuild(options) {
|
|
2355
|
-
const configPath = await resolveConfigPath(options);
|
|
2356
|
-
const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
|
|
2357
|
-
if (options.majorVersion === 3) {
|
|
2358
|
-
clearTailwindV3RuntimeState(pluginName);
|
|
2359
|
-
}
|
|
2360
|
-
if (options.majorVersion === 4) {
|
|
2361
|
-
return _postcss2.default.call(void 0, [
|
|
2362
|
-
require3(pluginName)({
|
|
2363
|
-
config: configPath
|
|
2364
|
-
})
|
|
2365
|
-
]).process("@import 'tailwindcss';", {
|
|
2366
|
-
from: void 0
|
|
2367
|
-
});
|
|
2368
|
-
}
|
|
2369
|
-
return _postcss2.default.call(void 0, [
|
|
2370
|
-
require3(pluginName)({
|
|
2371
|
-
config: configPath
|
|
2372
|
-
})
|
|
2373
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
2374
|
-
from: void 0
|
|
2375
|
-
});
|
|
2376
|
-
}
|
|
2377
|
-
|
|
2378
|
-
// src/patching/status.ts
|
|
2379
|
-
var _types = require('@babel/types'); var t4 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types); var t5 = _interopRequireWildcard(_types);
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
// src/babel/index.ts
|
|
2384
|
-
var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
|
|
2385
|
-
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
2386
|
-
var _parser = require('@babel/parser');
|
|
2387
|
-
function _interopDefaultCompat(e) {
|
|
2388
|
-
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
2389
|
-
}
|
|
2390
|
-
var generate = _interopDefaultCompat(_generator2.default);
|
|
2391
|
-
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
2392
|
-
|
|
2393
|
-
// src/patching/operations/export-context/postcss-v2.ts
|
|
2394
|
-
|
|
2395
|
-
var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
|
|
2396
|
-
function toIdentifierName(property) {
|
|
2397
|
-
if (!property) {
|
|
2398
|
-
return "contextRef";
|
|
2399
|
-
}
|
|
2400
|
-
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
2401
|
-
if (/^\d/.test(sanitized)) {
|
|
2402
|
-
return `_${sanitized}`;
|
|
2403
|
-
}
|
|
2404
|
-
return sanitized || "contextRef";
|
|
2405
|
-
}
|
|
2406
|
-
function createExportsMember(property) {
|
|
2407
|
-
if (IDENTIFIER_RE.test(property)) {
|
|
2408
|
-
return t.memberExpression(t.identifier("exports"), t.identifier(property));
|
|
2409
|
-
}
|
|
2410
|
-
return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
|
|
2411
|
-
}
|
|
2412
|
-
function transformProcessTailwindFeaturesReturnContextV2(content) {
|
|
2413
|
-
const ast = _parser.parse.call(void 0, content, {
|
|
2414
|
-
sourceType: "unambiguous"
|
|
2415
|
-
});
|
|
2416
|
-
let hasPatched = false;
|
|
2417
|
-
traverse(ast, {
|
|
2418
|
-
FunctionDeclaration(path15) {
|
|
2419
|
-
const node = path15.node;
|
|
2420
|
-
if (_optionalChain([node, 'access', _78 => _78.id, 'optionalAccess', _79 => _79.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
|
|
2421
|
-
return;
|
|
2422
|
-
}
|
|
2423
|
-
const returnStatement3 = node.body.body[0];
|
|
2424
|
-
if (!t.isFunctionExpression(returnStatement3.argument)) {
|
|
2425
|
-
return;
|
|
2426
|
-
}
|
|
2427
|
-
const body = returnStatement3.argument.body.body;
|
|
2428
|
-
const lastStatement = body[body.length - 1];
|
|
2429
|
-
const alreadyReturnsContext = Boolean(
|
|
2430
|
-
t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
2431
|
-
);
|
|
2432
|
-
hasPatched = alreadyReturnsContext;
|
|
2433
|
-
if (!alreadyReturnsContext) {
|
|
2434
|
-
body.push(t.returnStatement(t.identifier("context")));
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
});
|
|
2438
|
-
return {
|
|
2439
|
-
code: hasPatched ? content : generate(ast).code,
|
|
2440
|
-
hasPatched
|
|
2441
|
-
};
|
|
2442
|
-
}
|
|
2443
|
-
function transformPostcssPluginV2(content, options) {
|
|
2444
|
-
const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
|
|
2445
|
-
const exportMember = createExportsMember(options.refProperty);
|
|
2446
|
-
const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
|
|
2447
|
-
const ast = _parser.parse.call(void 0, content);
|
|
2448
|
-
let hasPatched = false;
|
|
2449
|
-
traverse(ast, {
|
|
2450
|
-
Program(path15) {
|
|
2451
|
-
const program = path15.node;
|
|
2452
|
-
const index = program.body.findIndex((statement) => {
|
|
2453
|
-
return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _80 => _80.id, 'optionalAccess', _81 => _81.name]) === "_default";
|
|
2454
|
-
});
|
|
2455
|
-
if (index === -1) {
|
|
2456
|
-
return;
|
|
2457
|
-
}
|
|
2458
|
-
const previous = program.body[index - 1];
|
|
2459
|
-
const beforePrevious = program.body[index - 2];
|
|
2460
|
-
const alreadyHasVariable = Boolean(
|
|
2461
|
-
previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && (() => {
|
|
2462
|
-
const declaration = previous.declarations[0];
|
|
2463
|
-
return Boolean(
|
|
2464
|
-
declaration && t.isIdentifier(declaration.id) && declaration.id.name === refIdentifier.name
|
|
2465
|
-
);
|
|
2466
|
-
})()
|
|
2467
|
-
);
|
|
2468
|
-
const alreadyAssignsExports = Boolean(
|
|
2469
|
-
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
|
|
2470
|
-
);
|
|
2471
|
-
hasPatched = alreadyHasVariable && alreadyAssignsExports;
|
|
2472
|
-
if (!alreadyHasVariable) {
|
|
2473
|
-
program.body.splice(
|
|
2474
|
-
index,
|
|
2475
|
-
0,
|
|
2476
|
-
t.variableDeclaration("var", [
|
|
2477
|
-
t.variableDeclarator(
|
|
2478
|
-
refIdentifier,
|
|
2479
|
-
t.objectExpression([
|
|
2480
|
-
t.objectProperty(t.identifier("value"), t.arrayExpression())
|
|
2481
|
-
])
|
|
2482
|
-
)
|
|
2483
|
-
]),
|
|
2484
|
-
t.expressionStatement(
|
|
2485
|
-
t.assignmentExpression("=", exportMember, refIdentifier)
|
|
2486
|
-
)
|
|
2487
|
-
);
|
|
2488
|
-
}
|
|
2489
|
-
},
|
|
2490
|
-
FunctionDeclaration(path15) {
|
|
2491
|
-
if (hasPatched) {
|
|
2492
|
-
return;
|
|
2493
|
-
}
|
|
2494
|
-
const fn = path15.node;
|
|
2495
|
-
if (_optionalChain([fn, 'access', _82 => _82.id, 'optionalAccess', _83 => _83.name]) !== "_default") {
|
|
2496
|
-
return;
|
|
2497
|
-
}
|
|
2498
|
-
if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
|
|
2499
|
-
return;
|
|
2500
|
-
}
|
|
2501
|
-
const returnStatement3 = fn.body.body[0];
|
|
2502
|
-
if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
|
|
2503
|
-
return;
|
|
2504
|
-
}
|
|
2505
|
-
const fnExpression = returnStatement3.argument.callee.object.elements[1];
|
|
2506
|
-
if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
|
|
2507
|
-
return;
|
|
2508
|
-
}
|
|
2509
|
-
const block = fnExpression.body;
|
|
2510
|
-
const statements = block.body;
|
|
2511
|
-
if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
|
|
2512
|
-
hasPatched = true;
|
|
2513
|
-
return;
|
|
2514
|
-
}
|
|
2515
|
-
const lastStatement = statements[statements.length - 1];
|
|
2516
|
-
if (lastStatement && t.isExpressionStatement(lastStatement)) {
|
|
2517
|
-
statements[statements.length - 1] = t.expressionStatement(
|
|
2518
|
-
t.callExpression(
|
|
2519
|
-
t.memberExpression(valueMember, t.identifier("push")),
|
|
2520
|
-
[lastStatement.expression]
|
|
2521
|
-
)
|
|
2522
|
-
);
|
|
2523
|
-
}
|
|
2524
|
-
const index = statements.findIndex((statement) => t.isIfStatement(statement));
|
|
2525
|
-
if (index > -1) {
|
|
2526
|
-
const ifStatement = statements[index];
|
|
2527
|
-
if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
|
|
2528
|
-
const forOf = ifStatement.consequent.body[1];
|
|
2529
|
-
if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
|
|
2530
|
-
const nestedIf = forOf.body.body[0];
|
|
2531
|
-
if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
|
|
2532
|
-
nestedIf.consequent.body[0] = t.expressionStatement(
|
|
2533
|
-
t.callExpression(
|
|
2534
|
-
t.memberExpression(valueMember, t.identifier("push")),
|
|
2535
|
-
[nestedIf.consequent.body[0].expression]
|
|
2536
|
-
)
|
|
2537
|
-
);
|
|
2538
|
-
}
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
|
-
statements.unshift(
|
|
2543
|
-
t.expressionStatement(
|
|
2544
|
-
t.assignmentExpression(
|
|
2545
|
-
"=",
|
|
2546
|
-
t.memberExpression(valueMember, t.identifier("length")),
|
|
2547
|
-
t.numericLiteral(0)
|
|
2548
|
-
)
|
|
2549
|
-
)
|
|
2550
|
-
);
|
|
2551
|
-
}
|
|
2552
|
-
});
|
|
2553
|
-
return {
|
|
2554
|
-
code: hasPatched ? content : generate(ast).code,
|
|
2555
|
-
hasPatched
|
|
2556
|
-
};
|
|
2557
|
-
}
|
|
2558
|
-
|
|
2559
|
-
// src/patching/operations/export-context/postcss-v3.ts
|
|
2560
|
-
|
|
2561
|
-
var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
|
|
2562
|
-
function toIdentifierName2(property) {
|
|
2563
|
-
if (!property) {
|
|
2564
|
-
return "contextRef";
|
|
2565
|
-
}
|
|
2566
|
-
const sanitized = property.replace(/[^\w$]/gu, "_");
|
|
2567
|
-
if (/^\d/.test(sanitized)) {
|
|
2568
|
-
return `_${sanitized}`;
|
|
2569
|
-
}
|
|
2570
|
-
return sanitized || "contextRef";
|
|
2571
|
-
}
|
|
2572
|
-
function createModuleExportsMember(property) {
|
|
2573
|
-
const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
|
|
2574
|
-
if (IDENTIFIER_RE2.test(property)) {
|
|
2575
|
-
return t2.memberExpression(object, t2.identifier(property));
|
|
2576
|
-
}
|
|
2577
|
-
return t2.memberExpression(object, t2.stringLiteral(property), true);
|
|
2578
|
-
}
|
|
2579
|
-
function transformProcessTailwindFeaturesReturnContext(content) {
|
|
2580
|
-
const ast = _parser.parse.call(void 0, content);
|
|
2581
|
-
let hasPatched = false;
|
|
2582
|
-
traverse(ast, {
|
|
2583
|
-
FunctionDeclaration(path15) {
|
|
2584
|
-
const node = path15.node;
|
|
2585
|
-
if (_optionalChain([node, 'access', _84 => _84.id, 'optionalAccess', _85 => _85.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
|
|
2586
|
-
return;
|
|
2587
|
-
}
|
|
2588
|
-
const [returnStatement3] = node.body.body;
|
|
2589
|
-
if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
|
|
2590
|
-
return;
|
|
2591
|
-
}
|
|
2592
|
-
const expression = returnStatement3.argument;
|
|
2593
|
-
const body = expression.body.body;
|
|
2594
|
-
const lastStatement = body[body.length - 1];
|
|
2595
|
-
const alreadyReturnsContext = Boolean(
|
|
2596
|
-
t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
|
|
2597
|
-
);
|
|
2598
|
-
hasPatched = alreadyReturnsContext;
|
|
2599
|
-
if (!alreadyReturnsContext) {
|
|
2600
|
-
body.push(t2.returnStatement(t2.identifier("context")));
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
});
|
|
2604
|
-
return {
|
|
2605
|
-
code: hasPatched ? content : generate(ast).code,
|
|
2606
|
-
hasPatched
|
|
2607
|
-
};
|
|
2608
|
-
}
|
|
2609
|
-
function transformPostcssPlugin(content, { refProperty }) {
|
|
2610
|
-
const ast = _parser.parse.call(void 0, content);
|
|
2611
|
-
const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
|
|
2612
|
-
const moduleExportsMember = createModuleExportsMember(refProperty);
|
|
2613
|
-
const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
|
|
2614
|
-
let hasPatched = false;
|
|
2615
|
-
traverse(ast, {
|
|
2616
|
-
Program(path15) {
|
|
2617
|
-
const program = path15.node;
|
|
2618
|
-
const index = program.body.findIndex((statement) => {
|
|
2619
|
-
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _86 => _86.expression, 'access', _87 => _87.right, 'access', _88 => _88.id, 'optionalAccess', _89 => _89.name]) === "tailwindcss";
|
|
2620
|
-
});
|
|
2621
|
-
if (index === -1) {
|
|
2622
|
-
return;
|
|
2623
|
-
}
|
|
2624
|
-
const previousStatement = program.body[index - 1];
|
|
2625
|
-
const lastStatement = program.body[program.body.length - 1];
|
|
2626
|
-
const alreadyHasVariable = Boolean(
|
|
2627
|
-
previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && (() => {
|
|
2628
|
-
const declaration = previousStatement.declarations[0];
|
|
2629
|
-
return Boolean(
|
|
2630
|
-
declaration && t2.isIdentifier(declaration.id) && declaration.id.name === refIdentifier.name
|
|
2631
|
-
);
|
|
2632
|
-
})()
|
|
2633
|
-
);
|
|
2634
|
-
const alreadyAssignsModuleExports = Boolean(
|
|
2635
|
-
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
|
|
2636
|
-
);
|
|
2637
|
-
hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
|
|
2638
|
-
if (!alreadyHasVariable) {
|
|
2639
|
-
program.body.splice(
|
|
2640
|
-
index,
|
|
2641
|
-
0,
|
|
2642
|
-
t2.variableDeclaration("const", [
|
|
2643
|
-
t2.variableDeclarator(
|
|
2644
|
-
refIdentifier,
|
|
2645
|
-
t2.objectExpression([
|
|
2646
|
-
t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
|
|
2647
|
-
])
|
|
2648
|
-
)
|
|
2649
|
-
])
|
|
2650
|
-
);
|
|
2651
|
-
}
|
|
2652
|
-
if (!alreadyAssignsModuleExports) {
|
|
2653
|
-
program.body.push(
|
|
2654
|
-
t2.expressionStatement(
|
|
2655
|
-
t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
|
|
2656
|
-
)
|
|
2657
|
-
);
|
|
2658
|
-
}
|
|
2659
|
-
},
|
|
2660
|
-
FunctionExpression(path15) {
|
|
2661
|
-
if (hasPatched) {
|
|
2662
|
-
return;
|
|
2663
|
-
}
|
|
2664
|
-
const fn = path15.node;
|
|
2665
|
-
if (_optionalChain([fn, 'access', _90 => _90.id, 'optionalAccess', _91 => _91.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
|
|
2666
|
-
return;
|
|
2667
|
-
}
|
|
2668
|
-
const [returnStatement3] = fn.body.body;
|
|
2669
|
-
if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
|
|
2670
|
-
return;
|
|
2671
|
-
}
|
|
2672
|
-
const properties = returnStatement3.argument.properties;
|
|
2673
|
-
if (properties.length !== 2) {
|
|
2674
|
-
return;
|
|
2675
|
-
}
|
|
2676
|
-
const pluginsProperty = properties.find(
|
|
2677
|
-
(prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
|
|
2678
|
-
);
|
|
2679
|
-
if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
|
|
2680
|
-
return;
|
|
2681
|
-
}
|
|
2682
|
-
const pluginsArray = pluginsProperty.value.callee.object.elements;
|
|
2683
|
-
const targetPlugin = pluginsArray[1];
|
|
2684
|
-
if (!targetPlugin || !t2.isFunctionExpression(targetPlugin)) {
|
|
2685
|
-
return;
|
|
2686
|
-
}
|
|
2687
|
-
const block = targetPlugin.body;
|
|
2688
|
-
const statements = block.body;
|
|
2689
|
-
const last = statements[statements.length - 1];
|
|
2690
|
-
if (last && t2.isExpressionStatement(last)) {
|
|
2691
|
-
statements[statements.length - 1] = t2.expressionStatement(
|
|
2692
|
-
t2.callExpression(
|
|
2693
|
-
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
2694
|
-
[last.expression]
|
|
2695
|
-
)
|
|
2696
|
-
);
|
|
2697
|
-
}
|
|
2698
|
-
const index = statements.findIndex((s) => t2.isIfStatement(s));
|
|
2699
|
-
if (index > -1) {
|
|
2700
|
-
const ifStatement = statements[index];
|
|
2701
|
-
if (t2.isBlockStatement(ifStatement.consequent)) {
|
|
2702
|
-
const [, second] = ifStatement.consequent.body;
|
|
2703
|
-
if (second && t2.isForOfStatement(second) && t2.isBlockStatement(second.body)) {
|
|
2704
|
-
const bodyStatement = second.body.body[0];
|
|
2705
|
-
if (bodyStatement && t2.isIfStatement(bodyStatement) && t2.isBlockStatement(bodyStatement.consequent) && bodyStatement.consequent.body.length === 1 && t2.isExpressionStatement(bodyStatement.consequent.body[0])) {
|
|
2706
|
-
bodyStatement.consequent.body[0] = t2.expressionStatement(
|
|
2707
|
-
t2.callExpression(
|
|
2708
|
-
t2.memberExpression(valueMember, t2.identifier("push")),
|
|
2709
|
-
[bodyStatement.consequent.body[0].expression]
|
|
2710
|
-
)
|
|
2711
|
-
);
|
|
2712
|
-
}
|
|
2713
|
-
}
|
|
2714
|
-
}
|
|
2715
|
-
}
|
|
2716
|
-
statements.unshift(
|
|
2717
|
-
t2.expressionStatement(
|
|
2718
|
-
t2.assignmentExpression(
|
|
2719
|
-
"=",
|
|
2720
|
-
t2.memberExpression(valueMember, t2.identifier("length")),
|
|
2721
|
-
t2.numericLiteral(0)
|
|
2722
|
-
)
|
|
2723
|
-
)
|
|
2724
|
-
);
|
|
2725
|
-
}
|
|
2726
|
-
});
|
|
2727
|
-
return {
|
|
2728
|
-
code: hasPatched ? content : generate(ast).code,
|
|
2729
|
-
hasPatched
|
|
2730
|
-
};
|
|
2731
|
-
}
|
|
2732
|
-
|
|
2733
|
-
// src/patching/operations/extend-length-units.ts
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
function updateLengthUnitsArray(content, options) {
|
|
2738
|
-
const { variableName = "lengthUnits", units } = options;
|
|
2739
|
-
const ast = _parser.parse.call(void 0, content);
|
|
2740
|
-
let arrayRef;
|
|
2741
|
-
let changed = false;
|
|
2742
|
-
traverse(ast, {
|
|
2743
|
-
Identifier(path15) {
|
|
2744
|
-
if (path15.node.name === variableName && t3.isVariableDeclarator(path15.parent) && t3.isArrayExpression(path15.parent.init)) {
|
|
2745
|
-
arrayRef = path15.parent.init;
|
|
2746
|
-
const existing = new Set(
|
|
2747
|
-
path15.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
2748
|
-
);
|
|
2749
|
-
for (const unit of units) {
|
|
2750
|
-
if (!existing.has(unit)) {
|
|
2751
|
-
path15.parent.init.elements = path15.parent.init.elements.map((element) => {
|
|
2752
|
-
if (t3.isStringLiteral(element)) {
|
|
2753
|
-
return t3.stringLiteral(element.value);
|
|
2754
|
-
}
|
|
2755
|
-
return element;
|
|
2756
|
-
});
|
|
2757
|
-
path15.parent.init.elements.push(t3.stringLiteral(unit));
|
|
2758
|
-
changed = true;
|
|
2759
|
-
}
|
|
2760
|
-
}
|
|
2761
|
-
}
|
|
2762
|
-
}
|
|
2763
|
-
});
|
|
2764
|
-
return {
|
|
2765
|
-
...arrayRef === void 0 ? {} : { arrayRef },
|
|
2766
|
-
changed
|
|
2767
|
-
};
|
|
2768
|
-
}
|
|
2769
|
-
function applyExtendLengthUnitsPatchV3(rootDir, options) {
|
|
2770
|
-
if (!options.enabled) {
|
|
2771
|
-
return { changed: false, code: void 0 };
|
|
2772
|
-
}
|
|
2773
|
-
const opts = {
|
|
2774
|
-
...options,
|
|
2775
|
-
lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
|
|
2776
|
-
variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
|
|
2777
|
-
};
|
|
2778
|
-
const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
|
|
2779
|
-
const exists = _fsextra2.default.existsSync(dataTypesFilePath);
|
|
2780
|
-
if (!exists) {
|
|
2781
|
-
return { changed: false, code: void 0 };
|
|
2782
|
-
}
|
|
2783
|
-
const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
|
|
2784
|
-
const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
|
|
2785
|
-
if (!arrayRef || !changed) {
|
|
2786
|
-
return { changed: false, code: void 0 };
|
|
2787
|
-
}
|
|
2788
|
-
const { code } = generate(arrayRef, {
|
|
2789
|
-
jsescOption: { quotes: "single" }
|
|
2790
|
-
});
|
|
2791
|
-
if (arrayRef.start != null && arrayRef.end != null) {
|
|
2792
|
-
const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
|
|
2793
|
-
if (opts.overwrite) {
|
|
2794
|
-
const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
|
|
2795
|
-
_fsextra2.default.writeFileSync(target, nextCode, "utf8");
|
|
2796
|
-
logger_default.success("Patched Tailwind CSS length unit list (v3).");
|
|
2797
|
-
}
|
|
2798
|
-
return {
|
|
2799
|
-
changed: true,
|
|
2800
|
-
code: nextCode
|
|
2801
|
-
};
|
|
2802
|
-
}
|
|
2803
|
-
return {
|
|
2804
|
-
changed: false,
|
|
2805
|
-
code: void 0
|
|
2806
|
-
};
|
|
2807
|
-
}
|
|
2808
|
-
function applyExtendLengthUnitsPatchV4(rootDir, options) {
|
|
2809
|
-
if (!options.enabled) {
|
|
2810
|
-
return { files: [], changed: false };
|
|
2811
|
-
}
|
|
2812
|
-
const opts = { ...options };
|
|
2813
|
-
const distDir = _pathe2.default.resolve(rootDir, "dist");
|
|
2814
|
-
if (!_fsextra2.default.existsSync(distDir)) {
|
|
2815
|
-
return { files: [], changed: false };
|
|
2816
|
-
}
|
|
2817
|
-
const entries = _fsextra2.default.readdirSync(distDir);
|
|
2818
|
-
const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
|
|
2819
|
-
const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
|
|
2820
|
-
const candidates = chunkNames.map((chunkName) => {
|
|
2821
|
-
const file = _pathe2.default.join(distDir, chunkName);
|
|
2822
|
-
const code = _fsextra2.default.readFileSync(file, "utf8");
|
|
2823
|
-
const match = pattern.exec(code);
|
|
2824
|
-
if (!match) {
|
|
2825
|
-
return null;
|
|
2826
|
-
}
|
|
2827
|
-
return {
|
|
2828
|
-
file,
|
|
2829
|
-
code,
|
|
2830
|
-
match,
|
|
2831
|
-
hasPatched: false
|
|
2832
|
-
};
|
|
2833
|
-
}).filter((candidate) => candidate !== null);
|
|
2834
|
-
for (const item of candidates) {
|
|
2835
|
-
const { code, file, match } = item;
|
|
2836
|
-
const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
|
|
2837
|
-
traverse(ast, {
|
|
2838
|
-
ArrayExpression(path15) {
|
|
2839
|
-
for (const unit of opts.units) {
|
|
2840
|
-
if (path15.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
|
|
2841
|
-
item.hasPatched = true;
|
|
2842
|
-
return;
|
|
2843
|
-
}
|
|
2844
|
-
path15.node.elements.push(t3.stringLiteral(unit));
|
|
2845
|
-
}
|
|
2846
|
-
}
|
|
2847
|
-
});
|
|
2848
|
-
if (item.hasPatched) {
|
|
2849
|
-
continue;
|
|
2850
|
-
}
|
|
2851
|
-
const { code: replacement } = generate(ast, { minified: true });
|
|
2852
|
-
const start = _nullishCoalesce(match.index, () => ( 0));
|
|
2853
|
-
const end = start + match[0].length;
|
|
2854
|
-
item.code = spliceChangesIntoString(code, [
|
|
2855
|
-
{
|
|
2856
|
-
start,
|
|
2857
|
-
end,
|
|
2858
|
-
replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
|
|
2859
|
-
}
|
|
2860
|
-
]);
|
|
2861
|
-
if (opts.overwrite) {
|
|
2862
|
-
_fsextra2.default.writeFileSync(file, item.code, "utf8");
|
|
2863
|
-
}
|
|
2864
|
-
}
|
|
2865
|
-
if (candidates.some((file) => !file.hasPatched)) {
|
|
2866
|
-
logger_default.success("Patched Tailwind CSS length unit list (v4).");
|
|
2867
|
-
}
|
|
2868
|
-
return {
|
|
2869
|
-
changed: candidates.some((file) => !file.hasPatched),
|
|
2870
|
-
files: candidates
|
|
2871
|
-
};
|
|
2872
|
-
}
|
|
2873
|
-
|
|
2874
|
-
// src/patching/status.ts
|
|
2875
|
-
function inspectLengthUnitsArray(content, variableName, units) {
|
|
2876
|
-
const ast = _parser.parse.call(void 0, content);
|
|
2877
|
-
let found = false;
|
|
2878
|
-
let missingUnits = [];
|
|
2879
|
-
traverse(ast, {
|
|
2880
|
-
Identifier(path15) {
|
|
2881
|
-
if (path15.node.name === variableName && t4.isVariableDeclarator(path15.parent) && t4.isArrayExpression(path15.parent.init)) {
|
|
2882
|
-
found = true;
|
|
2883
|
-
const existing = new Set(
|
|
2884
|
-
path15.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
2885
|
-
);
|
|
2886
|
-
missingUnits = units.filter((unit) => !existing.has(unit));
|
|
2887
|
-
path15.stop();
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
|
-
});
|
|
2891
|
-
return {
|
|
2892
|
-
found,
|
|
2893
|
-
missingUnits
|
|
2894
|
-
};
|
|
2895
|
-
}
|
|
2896
|
-
function checkExposeContextPatch(context) {
|
|
2897
|
-
const { packageInfo, options, majorVersion } = context;
|
|
2898
|
-
const refProperty = options.features.exposeContext.refProperty;
|
|
2899
|
-
if (!options.features.exposeContext.enabled) {
|
|
2900
|
-
return {
|
|
2901
|
-
name: "exposeContext",
|
|
2902
|
-
status: "skipped",
|
|
2903
|
-
reason: "exposeContext feature disabled",
|
|
2904
|
-
files: []
|
|
2905
|
-
};
|
|
2906
|
-
}
|
|
2907
|
-
if (majorVersion === 4) {
|
|
2908
|
-
return {
|
|
2909
|
-
name: "exposeContext",
|
|
2910
|
-
status: "unsupported",
|
|
2911
|
-
reason: "Context export patch is only required for Tailwind v2/v3",
|
|
2912
|
-
files: []
|
|
2913
|
-
};
|
|
2914
|
-
}
|
|
2915
|
-
const checks = [];
|
|
2916
|
-
function inspectFile(relative, transform) {
|
|
2917
|
-
const filePath = _pathe2.default.resolve(packageInfo.rootPath, relative);
|
|
2918
|
-
if (!_fsextra2.default.existsSync(filePath)) {
|
|
2919
|
-
checks.push({ relative, exists: false, patched: false });
|
|
2920
|
-
return;
|
|
2921
|
-
}
|
|
2922
|
-
const content = _fsextra2.default.readFileSync(filePath, "utf8");
|
|
2923
|
-
const { hasPatched } = transform(content);
|
|
2924
|
-
checks.push({
|
|
2925
|
-
relative,
|
|
2926
|
-
exists: true,
|
|
2927
|
-
patched: hasPatched
|
|
2928
|
-
});
|
|
2929
|
-
}
|
|
2930
|
-
if (majorVersion === 3) {
|
|
2931
|
-
inspectFile("lib/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContext);
|
|
2932
|
-
const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
|
|
2933
|
-
const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(packageInfo.rootPath, candidate)));
|
|
2934
|
-
if (pluginRelative) {
|
|
2935
|
-
inspectFile(pluginRelative, (content) => transformPostcssPlugin(content, { refProperty }));
|
|
2936
|
-
} else {
|
|
2937
|
-
checks.push({ relative: "lib/plugin.js", exists: false, patched: false });
|
|
2938
|
-
}
|
|
2939
|
-
} else {
|
|
2940
|
-
inspectFile("lib/jit/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContextV2);
|
|
2941
|
-
inspectFile("lib/jit/index.js", (content) => transformPostcssPluginV2(content, { refProperty }));
|
|
2942
|
-
}
|
|
2943
|
-
const files = checks.filter((check) => check.exists).map((check) => check.relative);
|
|
2944
|
-
const missingFiles = checks.filter((check) => !check.exists);
|
|
2945
|
-
const unpatchedFiles = checks.filter((check) => check.exists && !check.patched);
|
|
2946
|
-
const reasons = [];
|
|
2947
|
-
if (missingFiles.length) {
|
|
2948
|
-
reasons.push(`missing files: ${missingFiles.map((item) => item.relative).join(", ")}`);
|
|
2949
|
-
}
|
|
2950
|
-
if (unpatchedFiles.length) {
|
|
2951
|
-
reasons.push(`unpatched files: ${unpatchedFiles.map((item) => item.relative).join(", ")}`);
|
|
2952
|
-
}
|
|
2953
|
-
return {
|
|
2954
|
-
name: "exposeContext",
|
|
2955
|
-
status: reasons.length ? "not-applied" : "applied",
|
|
2956
|
-
...reasons.length ? { reason: reasons.join("; ") } : {},
|
|
2957
|
-
files
|
|
2958
|
-
};
|
|
2959
|
-
}
|
|
2960
|
-
function checkExtendLengthUnitsV3(rootDir, options) {
|
|
2961
|
-
const lengthUnitsFilePath = _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
|
|
2962
|
-
const variableName = _nullishCoalesce(options.variableName, () => ( "lengthUnits"));
|
|
2963
|
-
const target = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
|
|
2964
|
-
const files = _fsextra2.default.existsSync(target) ? [_pathe2.default.relative(rootDir, target)] : [];
|
|
2965
|
-
if (!_fsextra2.default.existsSync(target)) {
|
|
2966
|
-
return {
|
|
2967
|
-
name: "extendLengthUnits",
|
|
2968
|
-
status: "not-applied",
|
|
2969
|
-
reason: `missing ${lengthUnitsFilePath}`,
|
|
2970
|
-
files
|
|
2971
|
-
};
|
|
2972
|
-
}
|
|
2973
|
-
const content = _fsextra2.default.readFileSync(target, "utf8");
|
|
2974
|
-
const { found, missingUnits } = inspectLengthUnitsArray(content, variableName, options.units);
|
|
2975
|
-
if (!found) {
|
|
2976
|
-
return {
|
|
2977
|
-
name: "extendLengthUnits",
|
|
2978
|
-
status: "not-applied",
|
|
2979
|
-
reason: `could not locate ${variableName} array in ${lengthUnitsFilePath}`,
|
|
2980
|
-
files
|
|
2981
|
-
};
|
|
2982
|
-
}
|
|
2983
|
-
if (missingUnits.length) {
|
|
2984
|
-
return {
|
|
2985
|
-
name: "extendLengthUnits",
|
|
2986
|
-
status: "not-applied",
|
|
2987
|
-
reason: `missing units: ${missingUnits.join(", ")}`,
|
|
2988
|
-
files
|
|
2989
|
-
};
|
|
2990
|
-
}
|
|
2991
|
-
return {
|
|
2992
|
-
name: "extendLengthUnits",
|
|
2993
|
-
status: "applied",
|
|
2994
|
-
files
|
|
2995
|
-
};
|
|
2996
|
-
}
|
|
2997
|
-
function checkExtendLengthUnitsV4(rootDir, options) {
|
|
2998
|
-
const distDir = _pathe2.default.resolve(rootDir, "dist");
|
|
2999
|
-
if (!_fsextra2.default.existsSync(distDir)) {
|
|
3000
|
-
return {
|
|
3001
|
-
name: "extendLengthUnits",
|
|
3002
|
-
status: "not-applied",
|
|
3003
|
-
reason: "dist directory not found for Tailwind v4 package",
|
|
3004
|
-
files: []
|
|
3005
|
-
};
|
|
3006
|
-
}
|
|
3007
|
-
const result = applyExtendLengthUnitsPatchV4(rootDir, {
|
|
3008
|
-
...options,
|
|
3009
|
-
enabled: true,
|
|
3010
|
-
overwrite: false
|
|
3011
|
-
});
|
|
3012
|
-
if (result.files.length === 0) {
|
|
3013
|
-
return {
|
|
3014
|
-
name: "extendLengthUnits",
|
|
3015
|
-
status: "not-applied",
|
|
3016
|
-
reason: "no bundle chunks matched the length unit pattern",
|
|
3017
|
-
files: []
|
|
3018
|
-
};
|
|
3019
|
-
}
|
|
3020
|
-
const files = result.files.map((file) => _pathe2.default.relative(rootDir, file.file));
|
|
3021
|
-
const pending = result.files.filter((file) => !file.hasPatched);
|
|
3022
|
-
if (pending.length) {
|
|
3023
|
-
return {
|
|
3024
|
-
name: "extendLengthUnits",
|
|
3025
|
-
status: "not-applied",
|
|
3026
|
-
reason: `missing units in ${pending.length} bundle${pending.length > 1 ? "s" : ""}`,
|
|
3027
|
-
files: pending.map((file) => _pathe2.default.relative(rootDir, file.file))
|
|
3028
|
-
};
|
|
3029
|
-
}
|
|
3030
|
-
return {
|
|
3031
|
-
name: "extendLengthUnits",
|
|
3032
|
-
status: "applied",
|
|
3033
|
-
files
|
|
3034
|
-
};
|
|
3035
|
-
}
|
|
3036
|
-
function checkExtendLengthUnitsPatch(context) {
|
|
3037
|
-
const { packageInfo, options, majorVersion } = context;
|
|
3038
|
-
if (!options.features.extendLengthUnits) {
|
|
3039
|
-
return {
|
|
3040
|
-
name: "extendLengthUnits",
|
|
3041
|
-
status: "skipped",
|
|
3042
|
-
reason: "extendLengthUnits feature disabled",
|
|
3043
|
-
files: []
|
|
3044
|
-
};
|
|
3045
|
-
}
|
|
3046
|
-
if (majorVersion === 2) {
|
|
3047
|
-
return {
|
|
3048
|
-
name: "extendLengthUnits",
|
|
3049
|
-
status: "unsupported",
|
|
3050
|
-
reason: "length unit extension is only applied for Tailwind v3/v4",
|
|
3051
|
-
files: []
|
|
3052
|
-
};
|
|
3053
|
-
}
|
|
3054
|
-
if (majorVersion === 3) {
|
|
3055
|
-
return checkExtendLengthUnitsV3(packageInfo.rootPath, options.features.extendLengthUnits);
|
|
3056
|
-
}
|
|
3057
|
-
return checkExtendLengthUnitsV4(packageInfo.rootPath, options.features.extendLengthUnits);
|
|
3058
|
-
}
|
|
3059
|
-
function getPatchStatusReport(context) {
|
|
3060
|
-
return {
|
|
3061
|
-
package: {
|
|
3062
|
-
name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _92 => _92.packageInfo, 'access', _93 => _93.packageJson, 'optionalAccess', _94 => _94.name]))),
|
|
3063
|
-
version: context.packageInfo.version,
|
|
3064
|
-
root: context.packageInfo.rootPath
|
|
3065
|
-
},
|
|
3066
|
-
majorVersion: context.majorVersion,
|
|
3067
|
-
entries: [
|
|
3068
|
-
checkExposeContextPatch(context),
|
|
3069
|
-
checkExtendLengthUnitsPatch(context)
|
|
3070
|
-
]
|
|
3071
|
-
};
|
|
3072
|
-
}
|
|
3073
|
-
|
|
3074
|
-
// src/api/tailwindcss-patcher.ts
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
var _localpkg = require('local-pkg');
|
|
3078
|
-
|
|
3079
|
-
var _semver = require('semver');
|
|
3080
|
-
|
|
3081
|
-
// src/patching/operations/export-context/index.ts
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
function writeFileIfRequired(filePath, code, overwrite, successMessage) {
|
|
3085
|
-
if (!overwrite) {
|
|
3086
|
-
return;
|
|
3087
|
-
}
|
|
3088
|
-
_fsextra2.default.writeFileSync(filePath, code, {
|
|
3089
|
-
encoding: "utf8"
|
|
3090
|
-
});
|
|
3091
|
-
logger_default.success(successMessage);
|
|
3092
|
-
}
|
|
3093
|
-
function applyExposeContextPatch(params) {
|
|
3094
|
-
const { rootDir, refProperty, overwrite, majorVersion } = params;
|
|
3095
|
-
const result = {
|
|
3096
|
-
applied: false,
|
|
3097
|
-
files: {}
|
|
3098
|
-
};
|
|
3099
|
-
if (majorVersion === 3) {
|
|
3100
|
-
const processFileRelative = "lib/processTailwindFeatures.js";
|
|
3101
|
-
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
3102
|
-
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
3103
|
-
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
3104
|
-
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContext(content);
|
|
3105
|
-
result.files[processFileRelative] = code;
|
|
3106
|
-
if (!hasPatched) {
|
|
3107
|
-
writeFileIfRequired(
|
|
3108
|
-
processFilePath,
|
|
3109
|
-
code,
|
|
3110
|
-
overwrite,
|
|
3111
|
-
"Patched Tailwind CSS processTailwindFeatures to expose runtime context."
|
|
3112
|
-
);
|
|
3113
|
-
result.applied = true;
|
|
3114
|
-
}
|
|
3115
|
-
}
|
|
3116
|
-
const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
|
|
3117
|
-
const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(rootDir, candidate)));
|
|
3118
|
-
if (pluginRelative) {
|
|
3119
|
-
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
3120
|
-
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
3121
|
-
const { code, hasPatched } = transformPostcssPlugin(content, { refProperty });
|
|
3122
|
-
result.files[pluginRelative] = code;
|
|
3123
|
-
if (!hasPatched) {
|
|
3124
|
-
writeFileIfRequired(
|
|
3125
|
-
pluginPath,
|
|
3126
|
-
code,
|
|
3127
|
-
overwrite,
|
|
3128
|
-
"Patched Tailwind CSS plugin entry to collect runtime contexts."
|
|
3129
|
-
);
|
|
3130
|
-
result.applied = true;
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
|
-
} else if (majorVersion === 2) {
|
|
3134
|
-
const processFileRelative = "lib/jit/processTailwindFeatures.js";
|
|
3135
|
-
const processFilePath = _pathe2.default.resolve(rootDir, processFileRelative);
|
|
3136
|
-
if (_fsextra2.default.existsSync(processFilePath)) {
|
|
3137
|
-
const content = _fsextra2.default.readFileSync(processFilePath, "utf8");
|
|
3138
|
-
const { code, hasPatched } = transformProcessTailwindFeaturesReturnContextV2(content);
|
|
3139
|
-
result.files[processFileRelative] = code;
|
|
3140
|
-
if (!hasPatched) {
|
|
3141
|
-
writeFileIfRequired(
|
|
3142
|
-
processFilePath,
|
|
3143
|
-
code,
|
|
3144
|
-
overwrite,
|
|
3145
|
-
"Patched Tailwind CSS JIT processTailwindFeatures to expose runtime context."
|
|
3146
|
-
);
|
|
3147
|
-
result.applied = true;
|
|
3148
|
-
}
|
|
3149
|
-
}
|
|
3150
|
-
const pluginRelative = "lib/jit/index.js";
|
|
3151
|
-
const pluginPath = _pathe2.default.resolve(rootDir, pluginRelative);
|
|
3152
|
-
if (_fsextra2.default.existsSync(pluginPath)) {
|
|
3153
|
-
const content = _fsextra2.default.readFileSync(pluginPath, "utf8");
|
|
3154
|
-
const { code, hasPatched } = transformPostcssPluginV2(content, { refProperty });
|
|
3155
|
-
result.files[pluginRelative] = code;
|
|
3156
|
-
if (!hasPatched) {
|
|
3157
|
-
writeFileIfRequired(
|
|
3158
|
-
pluginPath,
|
|
3159
|
-
code,
|
|
3160
|
-
overwrite,
|
|
3161
|
-
"Patched Tailwind CSS JIT entry to collect runtime contexts."
|
|
3162
|
-
);
|
|
3163
|
-
result.applied = true;
|
|
3164
|
-
}
|
|
3165
|
-
}
|
|
3166
|
-
}
|
|
3167
|
-
return result;
|
|
3168
|
-
}
|
|
3169
|
-
|
|
3170
|
-
// src/patching/patch-runner.ts
|
|
3171
|
-
function applyTailwindPatches(context) {
|
|
3172
|
-
const { packageInfo, options, majorVersion } = context;
|
|
3173
|
-
const results = {};
|
|
3174
|
-
if (options.features.exposeContext.enabled && (majorVersion === 2 || majorVersion === 3)) {
|
|
3175
|
-
results.exposeContext = applyExposeContextPatch({
|
|
3176
|
-
rootDir: packageInfo.rootPath,
|
|
3177
|
-
refProperty: options.features.exposeContext.refProperty,
|
|
3178
|
-
overwrite: options.overwrite,
|
|
3179
|
-
majorVersion
|
|
3180
|
-
});
|
|
3181
|
-
}
|
|
3182
|
-
if (_optionalChain([options, 'access', _95 => _95.features, 'access', _96 => _96.extendLengthUnits, 'optionalAccess', _97 => _97.enabled])) {
|
|
3183
|
-
if (majorVersion === 3) {
|
|
3184
|
-
results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
|
|
3185
|
-
packageInfo.rootPath,
|
|
3186
|
-
options.features.extendLengthUnits
|
|
3187
|
-
);
|
|
3188
|
-
} else if (majorVersion === 4) {
|
|
3189
|
-
results.extendLengthUnits = applyExtendLengthUnitsPatchV4(
|
|
3190
|
-
packageInfo.rootPath,
|
|
3191
|
-
options.features.extendLengthUnits
|
|
3192
|
-
);
|
|
3193
|
-
}
|
|
3194
|
-
}
|
|
3195
|
-
return results;
|
|
3196
|
-
}
|
|
3197
|
-
|
|
3198
|
-
// src/runtime/collector.ts
|
|
3199
|
-
function resolveTailwindExecutionOptions(normalized, majorVersion) {
|
|
3200
|
-
const base = normalized.tailwind;
|
|
3201
|
-
if (majorVersion === 2 && base.v2) {
|
|
3202
|
-
return {
|
|
3203
|
-
cwd: _nullishCoalesce(_nullishCoalesce(base.v2.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
3204
|
-
config: _nullishCoalesce(base.v2.config, () => ( base.config)),
|
|
3205
|
-
postcssPlugin: _nullishCoalesce(base.v2.postcssPlugin, () => ( base.postcssPlugin))
|
|
3206
|
-
};
|
|
3207
|
-
}
|
|
3208
|
-
if (majorVersion === 3 && base.v3) {
|
|
3209
|
-
return {
|
|
3210
|
-
cwd: _nullishCoalesce(_nullishCoalesce(base.v3.cwd, () => ( base.cwd)), () => ( normalized.projectRoot)),
|
|
3211
|
-
config: _nullishCoalesce(base.v3.config, () => ( base.config)),
|
|
3212
|
-
postcssPlugin: _nullishCoalesce(base.v3.postcssPlugin, () => ( base.postcssPlugin))
|
|
3213
|
-
};
|
|
3214
|
-
}
|
|
3215
|
-
return {
|
|
3216
|
-
cwd: _nullishCoalesce(base.cwd, () => ( normalized.projectRoot)),
|
|
3217
|
-
config: base.config,
|
|
3218
|
-
postcssPlugin: base.postcssPlugin
|
|
3219
|
-
};
|
|
3220
|
-
}
|
|
3221
|
-
var BaseCollector = class {
|
|
3222
|
-
constructor(packageInfo, options, majorVersion) {
|
|
3223
|
-
this.packageInfo = packageInfo;
|
|
3224
|
-
this.options = options;
|
|
3225
|
-
this.majorVersion = majorVersion;
|
|
3226
|
-
}
|
|
3227
|
-
async patch() {
|
|
3228
|
-
return applyTailwindPatches({
|
|
3229
|
-
packageInfo: this.packageInfo,
|
|
3230
|
-
options: this.options,
|
|
3231
|
-
majorVersion: this.majorVersion
|
|
3232
|
-
});
|
|
3233
|
-
}
|
|
3234
|
-
async getPatchStatus() {
|
|
3235
|
-
return getPatchStatusReport({
|
|
3236
|
-
packageInfo: this.packageInfo,
|
|
3237
|
-
options: this.options,
|
|
3238
|
-
majorVersion: this.majorVersion
|
|
3239
|
-
});
|
|
3240
|
-
}
|
|
3241
|
-
getContexts() {
|
|
3242
|
-
return loadRuntimeContexts(
|
|
3243
|
-
this.packageInfo,
|
|
3244
|
-
this.majorVersion,
|
|
3245
|
-
this.options.features.exposeContext.refProperty
|
|
3246
|
-
);
|
|
3247
|
-
}
|
|
3248
|
-
};
|
|
3249
|
-
var RuntimeCollector = class extends BaseCollector {
|
|
3250
|
-
constructor(packageInfo, options, majorVersion, snapshotFactory) {
|
|
3251
|
-
super(packageInfo, options, majorVersion);
|
|
3252
|
-
this.snapshotFactory = snapshotFactory;
|
|
3253
|
-
}
|
|
3254
|
-
|
|
3255
|
-
async collectClassSet() {
|
|
3256
|
-
const contexts = this.getContexts();
|
|
3257
|
-
return collectClassesFromContexts(contexts, this.options.filter);
|
|
3258
|
-
}
|
|
3259
|
-
getPatchSnapshot() {
|
|
3260
|
-
return this.snapshotFactory();
|
|
3261
|
-
}
|
|
3262
|
-
async runTailwindBuildIfNeeded() {
|
|
3263
|
-
if (this.inFlightBuild) {
|
|
3264
|
-
return this.inFlightBuild;
|
|
3265
|
-
}
|
|
3266
|
-
const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
|
|
3267
|
-
const buildOptions = {
|
|
3268
|
-
cwd: executionOptions.cwd,
|
|
3269
|
-
majorVersion: this.majorVersion,
|
|
3270
|
-
...executionOptions.config === void 0 ? {} : { config: executionOptions.config },
|
|
3271
|
-
...executionOptions.postcssPlugin === void 0 ? {} : { postcssPlugin: executionOptions.postcssPlugin }
|
|
3272
|
-
};
|
|
3273
|
-
this.inFlightBuild = runTailwindBuild(buildOptions).then(() => void 0);
|
|
3274
|
-
try {
|
|
3275
|
-
await this.inFlightBuild;
|
|
3276
|
-
} finally {
|
|
3277
|
-
this.inFlightBuild = void 0;
|
|
3278
|
-
}
|
|
3279
|
-
}
|
|
3280
|
-
};
|
|
3281
|
-
var TailwindV4Collector = class extends BaseCollector {
|
|
3282
|
-
constructor(packageInfo, options, snapshotFactory) {
|
|
3283
|
-
super(packageInfo, options, 4);
|
|
3284
|
-
this.snapshotFactory = snapshotFactory;
|
|
3285
|
-
}
|
|
3286
|
-
|
|
3287
|
-
async collectClassSet() {
|
|
3288
|
-
return collectClassesFromTailwindV4(this.options);
|
|
3289
|
-
}
|
|
3290
|
-
getPatchSnapshot() {
|
|
3291
|
-
return this.snapshotFactory();
|
|
3292
|
-
}
|
|
3293
|
-
};
|
|
3294
|
-
|
|
3295
|
-
// src/api/tailwindcss-patcher.ts
|
|
3296
|
-
function resolveInstalledMajorVersion(version) {
|
|
3297
|
-
if (!version) {
|
|
3298
|
-
return void 0;
|
|
3299
|
-
}
|
|
3300
|
-
const coerced = _semver.coerce.call(void 0, version);
|
|
3301
|
-
if (!coerced) {
|
|
3302
|
-
return void 0;
|
|
3303
|
-
}
|
|
3304
|
-
const major = coerced.major;
|
|
3305
|
-
if (major === 2 || major === 3 || major === 4) {
|
|
3306
|
-
return major;
|
|
3307
|
-
}
|
|
3308
|
-
if (major >= 4) {
|
|
3309
|
-
return 4;
|
|
3310
|
-
}
|
|
3311
|
-
return void 0;
|
|
3312
|
-
}
|
|
3313
|
-
function validateInstalledVersion(packageVersion, expectedMajor, packageName) {
|
|
3314
|
-
const installedMajor = resolveInstalledMajorVersion(packageVersion);
|
|
3315
|
-
if (installedMajor === void 0) {
|
|
3316
|
-
return;
|
|
3317
|
-
}
|
|
3318
|
-
if (installedMajor !== expectedMajor) {
|
|
3319
|
-
throw new Error(
|
|
3320
|
-
`Configured tailwindcss.version=${expectedMajor}, but resolved package "${packageName}" is version ${packageVersion}. Update the configuration or resolve the correct package.`
|
|
3321
|
-
);
|
|
3322
|
-
}
|
|
3323
|
-
}
|
|
3324
|
-
function resolveMajorVersionOrThrow(configuredMajor, packageVersion, packageName) {
|
|
3325
|
-
if (configuredMajor !== void 0) {
|
|
3326
|
-
validateInstalledVersion(packageVersion, configuredMajor, packageName);
|
|
3327
|
-
return configuredMajor;
|
|
3328
|
-
}
|
|
3329
|
-
const installedMajor = resolveInstalledMajorVersion(packageVersion);
|
|
3330
|
-
if (installedMajor !== void 0) {
|
|
3331
|
-
return installedMajor;
|
|
3332
|
-
}
|
|
3333
|
-
throw new Error(
|
|
3334
|
-
`Unable to infer Tailwind CSS major version from resolved package "${packageName}" (${_nullishCoalesce(packageVersion, () => ( "unknown"))}). Set "tailwindcss.version" to 2, 3, or 4 explicitly.`
|
|
3335
|
-
);
|
|
3336
|
-
}
|
|
3337
|
-
function createCollector(packageInfo, options, majorVersion, snapshotFactory) {
|
|
3338
|
-
if (majorVersion === 4) {
|
|
3339
|
-
return new TailwindV4Collector(packageInfo, options, snapshotFactory);
|
|
3340
|
-
}
|
|
3341
|
-
return new RuntimeCollector(packageInfo, options, majorVersion, snapshotFactory);
|
|
3342
|
-
}
|
|
3343
|
-
var TailwindcssPatcher = (_class2 = class {
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
constructor(options = {}) {;_class2.prototype.__init4.call(this);
|
|
3352
|
-
this.options = normalizeOptions(options);
|
|
3353
|
-
const packageInfo = _localpkg.getPackageInfoSync.call(void 0,
|
|
3354
|
-
this.options.tailwind.packageName,
|
|
3355
|
-
this.options.tailwind.resolve
|
|
3356
|
-
);
|
|
3357
|
-
if (!packageInfo) {
|
|
3358
|
-
throw new Error(`Unable to locate Tailwind CSS package "${this.options.tailwind.packageName}".`);
|
|
3359
|
-
}
|
|
3360
|
-
this.packageInfo = packageInfo;
|
|
3361
|
-
this.majorVersion = resolveMajorVersionOrThrow(
|
|
3362
|
-
this.options.tailwind.versionHint,
|
|
3363
|
-
this.packageInfo.version,
|
|
3364
|
-
this.options.tailwind.packageName
|
|
3365
|
-
);
|
|
3366
|
-
this.cacheContext = createCacheContextDescriptor(
|
|
3367
|
-
this.options,
|
|
3368
|
-
this.packageInfo,
|
|
3369
|
-
this.majorVersion
|
|
3370
|
-
);
|
|
3371
|
-
this.cacheStore = new CacheStore(this.options.cache, this.cacheContext);
|
|
3372
|
-
this.collector = createCollector(
|
|
3373
|
-
this.packageInfo,
|
|
3374
|
-
this.options,
|
|
3375
|
-
this.majorVersion,
|
|
3376
|
-
() => this.createPatchSnapshot()
|
|
3377
|
-
);
|
|
3378
|
-
}
|
|
3379
|
-
async patch() {
|
|
3380
|
-
const snapshot = this.collector.getPatchSnapshot();
|
|
3381
|
-
if (this.patchMemo && this.patchMemo.snapshot === snapshot) {
|
|
3382
|
-
return this.patchMemo.result;
|
|
3383
|
-
}
|
|
3384
|
-
const result = await this.collector.patch();
|
|
3385
|
-
this.patchMemo = {
|
|
3386
|
-
result,
|
|
3387
|
-
snapshot: this.collector.getPatchSnapshot()
|
|
3388
|
-
};
|
|
3389
|
-
return result;
|
|
3390
|
-
}
|
|
3391
|
-
async getPatchStatus() {
|
|
3392
|
-
return this.collector.getPatchStatus();
|
|
3393
|
-
}
|
|
3394
|
-
getContexts() {
|
|
3395
|
-
return this.collector.getContexts();
|
|
3396
|
-
}
|
|
3397
|
-
createPatchSnapshot() {
|
|
3398
|
-
const entries = [];
|
|
3399
|
-
const pushSnapshot = (filePath) => {
|
|
3400
|
-
if (!_fsextra2.default.pathExistsSync(filePath)) {
|
|
3401
|
-
entries.push(`${filePath}:missing`);
|
|
3402
|
-
return;
|
|
3403
|
-
}
|
|
3404
|
-
const stat = _fsextra2.default.statSync(filePath);
|
|
3405
|
-
entries.push(`${filePath}:${stat.size}:${Math.trunc(stat.mtimeMs)}`);
|
|
3406
|
-
};
|
|
3407
|
-
if (this.options.features.exposeContext.enabled && (this.majorVersion === 2 || this.majorVersion === 3)) {
|
|
3408
|
-
if (this.majorVersion === 2) {
|
|
3409
|
-
pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/jit/processTailwindFeatures.js"));
|
|
3410
|
-
pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/jit/index.js"));
|
|
3411
|
-
} else {
|
|
3412
|
-
pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/processTailwindFeatures.js"));
|
|
3413
|
-
const pluginPath = ["lib/plugin.js", "lib/index.js"].map((file) => _pathe2.default.resolve(this.packageInfo.rootPath, file)).find((file) => _fsextra2.default.pathExistsSync(file));
|
|
3414
|
-
if (pluginPath) {
|
|
3415
|
-
pushSnapshot(pluginPath);
|
|
3416
|
-
}
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3419
|
-
if (_optionalChain([this, 'access', _98 => _98.options, 'access', _99 => _99.features, 'access', _100 => _100.extendLengthUnits, 'optionalAccess', _101 => _101.enabled])) {
|
|
3420
|
-
if (this.majorVersion === 3) {
|
|
3421
|
-
const target = _nullishCoalesce(this.options.features.extendLengthUnits.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
|
|
3422
|
-
pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, target));
|
|
3423
|
-
} else if (this.majorVersion === 4) {
|
|
3424
|
-
const distDir = _pathe2.default.resolve(this.packageInfo.rootPath, "dist");
|
|
3425
|
-
if (_fsextra2.default.pathExistsSync(distDir)) {
|
|
3426
|
-
const chunkNames = _fsextra2.default.readdirSync(distDir).filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs")).sort();
|
|
3427
|
-
for (const chunkName of chunkNames) {
|
|
3428
|
-
pushSnapshot(_pathe2.default.join(distDir, chunkName));
|
|
3429
|
-
}
|
|
3430
|
-
} else {
|
|
3431
|
-
entries.push(`${distDir}:missing`);
|
|
3432
|
-
}
|
|
3433
|
-
}
|
|
3434
|
-
}
|
|
3435
|
-
return entries.join("|");
|
|
3436
|
-
}
|
|
3437
|
-
async collectClassSet() {
|
|
3438
|
-
if (this.majorVersion === 4) {
|
|
3439
|
-
return this.collector.collectClassSet();
|
|
3440
|
-
}
|
|
3441
|
-
const contexts = this.getContexts();
|
|
3442
|
-
return collectClassesFromContexts(contexts, this.options.filter);
|
|
3443
|
-
}
|
|
3444
|
-
async runTailwindBuildIfNeeded() {
|
|
3445
|
-
await _optionalChain([this, 'access', _102 => _102.collector, 'access', _103 => _103.runTailwindBuildIfNeeded, 'optionalCall', _104 => _104()]);
|
|
3446
|
-
}
|
|
3447
|
-
debugCacheRead(meta) {
|
|
3448
|
-
if (meta.hit) {
|
|
3449
|
-
logger_default.debug(
|
|
3450
|
-
`[cache] hit fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _105 => _105.fingerprint, 'optionalAccess', _106 => _106.slice, 'call', _107 => _107(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
|
|
3451
|
-
);
|
|
3452
|
-
return;
|
|
3453
|
-
}
|
|
3454
|
-
logger_default.debug(
|
|
3455
|
-
`[cache] miss reason=${meta.reason} fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _108 => _108.fingerprint, 'optionalAccess', _109 => _109.slice, 'call', _110 => _110(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
|
|
3456
|
-
);
|
|
3457
|
-
}
|
|
3458
|
-
async mergeWithCache(set) {
|
|
3459
|
-
if (!this.options.cache.enabled) {
|
|
3460
|
-
return set;
|
|
3461
|
-
}
|
|
3462
|
-
const { data: existing, meta } = await this.cacheStore.readWithMeta();
|
|
3463
|
-
this.debugCacheRead(meta);
|
|
3464
|
-
if (this.options.cache.strategy === "merge") {
|
|
3465
|
-
for (const value of existing) {
|
|
3466
|
-
set.add(value);
|
|
3467
|
-
}
|
|
3468
|
-
const writeTarget = this.areSetsEqual(existing, set) ? void 0 : await this.cacheStore.write(set);
|
|
3469
|
-
if (writeTarget) {
|
|
3470
|
-
logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
|
|
3471
|
-
}
|
|
3472
|
-
} else {
|
|
3473
|
-
if (set.size > 0) {
|
|
3474
|
-
const writeTarget = this.areSetsEqual(existing, set) ? void 0 : await this.cacheStore.write(set);
|
|
3475
|
-
if (writeTarget) {
|
|
3476
|
-
logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
|
|
3477
|
-
}
|
|
3478
|
-
} else {
|
|
3479
|
-
return existing;
|
|
3480
|
-
}
|
|
3481
|
-
}
|
|
3482
|
-
return set;
|
|
3483
|
-
}
|
|
3484
|
-
mergeWithCacheSync(set) {
|
|
3485
|
-
if (!this.options.cache.enabled) {
|
|
3486
|
-
return set;
|
|
3487
|
-
}
|
|
3488
|
-
const { data: existing, meta } = this.cacheStore.readWithMetaSync();
|
|
3489
|
-
this.debugCacheRead(meta);
|
|
3490
|
-
if (this.options.cache.strategy === "merge") {
|
|
3491
|
-
for (const value of existing) {
|
|
3492
|
-
set.add(value);
|
|
3493
|
-
}
|
|
3494
|
-
const writeTarget = this.areSetsEqual(existing, set) ? void 0 : this.cacheStore.writeSync(set);
|
|
3495
|
-
if (writeTarget) {
|
|
3496
|
-
logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
|
|
3497
|
-
}
|
|
3498
|
-
} else {
|
|
3499
|
-
if (set.size > 0) {
|
|
3500
|
-
const writeTarget = this.areSetsEqual(existing, set) ? void 0 : this.cacheStore.writeSync(set);
|
|
3501
|
-
if (writeTarget) {
|
|
3502
|
-
logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
|
|
3503
|
-
}
|
|
3504
|
-
} else {
|
|
3505
|
-
return existing;
|
|
3506
|
-
}
|
|
3507
|
-
}
|
|
3508
|
-
return set;
|
|
3509
|
-
}
|
|
3510
|
-
areSetsEqual(a, b) {
|
|
3511
|
-
if (a.size !== b.size) {
|
|
3512
|
-
return false;
|
|
3513
|
-
}
|
|
3514
|
-
for (const value of a) {
|
|
3515
|
-
if (!b.has(value)) {
|
|
3516
|
-
return false;
|
|
3517
|
-
}
|
|
3518
|
-
}
|
|
3519
|
-
return true;
|
|
3520
|
-
}
|
|
3521
|
-
async getClassSet() {
|
|
3522
|
-
await this.runTailwindBuildIfNeeded();
|
|
3523
|
-
const set = await this.collectClassSet();
|
|
3524
|
-
return this.mergeWithCache(set);
|
|
3525
|
-
}
|
|
3526
|
-
getClassSetSync() {
|
|
3527
|
-
if (this.majorVersion === 4) {
|
|
3528
|
-
throw new Error("getClassSetSync is not supported for Tailwind CSS v4 projects. Use getClassSet instead.");
|
|
3529
|
-
}
|
|
3530
|
-
const contexts = this.getContexts();
|
|
3531
|
-
const set = collectClassesFromContexts(contexts, this.options.filter);
|
|
3532
|
-
const merged = this.mergeWithCacheSync(set);
|
|
3533
|
-
if (contexts.length === 0 && merged.size === 0) {
|
|
3534
|
-
return void 0;
|
|
3535
|
-
}
|
|
3536
|
-
return merged;
|
|
3537
|
-
}
|
|
3538
|
-
async extract(options) {
|
|
3539
|
-
const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _111 => _111.write]), () => ( this.options.output.enabled));
|
|
3540
|
-
const classSet = await this.getClassSet();
|
|
3541
|
-
const classList = Array.from(classSet);
|
|
3542
|
-
const result = {
|
|
3543
|
-
classList,
|
|
3544
|
-
classSet
|
|
3545
|
-
};
|
|
3546
|
-
if (!shouldWrite || !this.options.output.file) {
|
|
3547
|
-
return result;
|
|
3548
|
-
}
|
|
3549
|
-
const target = _pathe2.default.resolve(this.options.output.file);
|
|
3550
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
3551
|
-
if (this.options.output.format === "json") {
|
|
3552
|
-
const spaces = typeof this.options.output.pretty === "number" ? this.options.output.pretty : void 0;
|
|
3553
|
-
await _fsextra2.default.writeJSON(target, classList, { spaces });
|
|
3554
|
-
} else {
|
|
3555
|
-
await _fsextra2.default.writeFile(target, `${classList.join("\n")}
|
|
3556
|
-
`, "utf8");
|
|
3557
|
-
}
|
|
3558
|
-
logger_default.success(`Tailwind CSS class list saved to ${target.replace(_process2.default.cwd(), ".")}`);
|
|
3559
|
-
return {
|
|
3560
|
-
...result,
|
|
3561
|
-
filename: target
|
|
3562
|
-
};
|
|
3563
|
-
}
|
|
3564
|
-
async clearCache(options) {
|
|
3565
|
-
const result = await this.cacheStore.clear(options);
|
|
3566
|
-
logger_default.debug(
|
|
3567
|
-
`[cache] clear scope=${result.scope} contexts=${result.contextsRemoved} entries=${result.entriesRemoved} files=${result.filesRemoved}`
|
|
3568
|
-
);
|
|
3569
|
-
return result;
|
|
3570
|
-
}
|
|
3571
|
-
// Backwards compatibility helper used by tests and API consumers.
|
|
3572
|
-
__init4() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
|
|
3573
|
-
async collectContentTokens(options) {
|
|
3574
|
-
return extractProjectCandidatesWithPositions({
|
|
3575
|
-
cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _112 => _112.cwd]), () => ( this.options.projectRoot)),
|
|
3576
|
-
sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _113 => _113.sources]), () => ( _optionalChain([this, 'access', _114 => _114.options, 'access', _115 => _115.tailwind, 'access', _116 => _116.v4, 'optionalAccess', _117 => _117.sources]))), () => ( []))
|
|
3577
|
-
});
|
|
3578
|
-
}
|
|
3579
|
-
async collectContentTokensByFile(options) {
|
|
3580
|
-
const collectContentOptions = {
|
|
3581
|
-
..._optionalChain([options, 'optionalAccess', _118 => _118.cwd]) === void 0 ? {} : { cwd: options.cwd },
|
|
3582
|
-
..._optionalChain([options, 'optionalAccess', _119 => _119.sources]) === void 0 ? {} : { sources: options.sources }
|
|
3583
|
-
};
|
|
3584
|
-
const report = await this.collectContentTokens(collectContentOptions);
|
|
3585
|
-
const groupOptions = {
|
|
3586
|
-
..._optionalChain([options, 'optionalAccess', _120 => _120.key]) === void 0 ? {} : { key: options.key },
|
|
3587
|
-
..._optionalChain([options, 'optionalAccess', _121 => _121.stripAbsolutePaths]) === void 0 ? {} : { stripAbsolutePaths: options.stripAbsolutePaths }
|
|
3588
|
-
};
|
|
3589
|
-
return groupTokensByFile(report, groupOptions);
|
|
3590
|
-
}
|
|
3591
|
-
}, _class2);
|
|
3592
|
-
|
|
3593
|
-
// src/commands/migration-report.ts
|
|
3594
|
-
var MIGRATION_REPORT_KIND = "tw-patch-migrate-report";
|
|
3595
|
-
var MIGRATION_REPORT_SCHEMA_VERSION = 1;
|
|
3596
|
-
function assertMigrationReportCompatibility(report, reportFile) {
|
|
3597
|
-
if (report.reportKind !== void 0 && report.reportKind !== MIGRATION_REPORT_KIND) {
|
|
3598
|
-
throw new Error(`Unsupported report kind "${report.reportKind}" in ${reportFile}.`);
|
|
3599
|
-
}
|
|
3600
|
-
if (report.schemaVersion !== void 0 && (!Number.isInteger(report.schemaVersion) || report.schemaVersion > MIGRATION_REPORT_SCHEMA_VERSION)) {
|
|
3601
|
-
throw new Error(
|
|
3602
|
-
`Unsupported report schema version "${String(report.schemaVersion)}" in ${reportFile}. Current supported version is ${MIGRATION_REPORT_SCHEMA_VERSION}.`
|
|
3603
|
-
);
|
|
3604
|
-
}
|
|
3605
|
-
}
|
|
3606
|
-
|
|
3607
|
-
// src/commands/migrate-config.ts
|
|
3608
|
-
|
|
3609
|
-
|
|
3610
|
-
// src/commands/migration-aggregation.ts
|
|
3611
|
-
function createMigrationAggregationState() {
|
|
3612
|
-
return {
|
|
3613
|
-
scannedFiles: 0,
|
|
3614
|
-
changedFiles: 0,
|
|
3615
|
-
writtenFiles: 0,
|
|
3616
|
-
backupsWritten: 0,
|
|
3617
|
-
unchangedFiles: 0,
|
|
3618
|
-
missingFiles: 0,
|
|
3619
|
-
entries: []
|
|
3620
|
-
};
|
|
3621
|
-
}
|
|
3622
|
-
function collectMigrationExecutionResult(state, result) {
|
|
3623
|
-
if (result.missing) {
|
|
3624
|
-
state.missingFiles += 1;
|
|
3625
|
-
return;
|
|
3626
|
-
}
|
|
3627
|
-
state.scannedFiles += 1;
|
|
3628
|
-
state.entries.push(result.entry);
|
|
3629
|
-
if (result.changed) {
|
|
3630
|
-
state.changedFiles += 1;
|
|
3631
|
-
if (result.wrote) {
|
|
3632
|
-
state.writtenFiles += 1;
|
|
3633
|
-
}
|
|
3634
|
-
if (result.backupWritten) {
|
|
3635
|
-
state.backupsWritten += 1;
|
|
3636
|
-
}
|
|
3637
|
-
} else {
|
|
3638
|
-
state.unchangedFiles += 1;
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
function buildMigrationReport(state, context) {
|
|
3642
|
-
const {
|
|
3643
|
-
cwd,
|
|
3644
|
-
dryRun,
|
|
3645
|
-
rollbackOnError,
|
|
3646
|
-
backupDirectory,
|
|
3647
|
-
toolName,
|
|
3648
|
-
toolVersion,
|
|
3649
|
-
generatedAt = (/* @__PURE__ */ new Date()).toISOString()
|
|
3650
|
-
} = context;
|
|
3651
|
-
return {
|
|
3652
|
-
reportKind: MIGRATION_REPORT_KIND,
|
|
3653
|
-
schemaVersion: MIGRATION_REPORT_SCHEMA_VERSION,
|
|
3654
|
-
generatedAt,
|
|
3655
|
-
tool: {
|
|
3656
|
-
name: toolName,
|
|
3657
|
-
version: toolVersion
|
|
3658
|
-
},
|
|
3659
|
-
cwd,
|
|
3660
|
-
dryRun,
|
|
3661
|
-
rollbackOnError,
|
|
3662
|
-
...backupDirectory ? { backupDirectory } : {},
|
|
3663
|
-
scannedFiles: state.scannedFiles,
|
|
3664
|
-
changedFiles: state.changedFiles,
|
|
3665
|
-
writtenFiles: state.writtenFiles,
|
|
3666
|
-
backupsWritten: state.backupsWritten,
|
|
3667
|
-
unchangedFiles: state.unchangedFiles,
|
|
3668
|
-
missingFiles: state.missingFiles,
|
|
3669
|
-
entries: state.entries
|
|
3670
|
-
};
|
|
3671
|
-
}
|
|
3672
|
-
|
|
3673
|
-
// src/commands/migration-file-executor.ts
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
// src/commands/migration-source.ts
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
var ROOT_LEGACY_KEYS = ["cwd", "overwrite", "tailwind", "features", "output", "applyPatches"];
|
|
3682
|
-
function getPropertyKeyName(property) {
|
|
3683
|
-
if (!property.computed && t5.isIdentifier(property.key)) {
|
|
3684
|
-
return property.key.name;
|
|
3685
|
-
}
|
|
3686
|
-
if (t5.isStringLiteral(property.key)) {
|
|
3687
|
-
return property.key.value;
|
|
3688
|
-
}
|
|
3689
|
-
return void 0;
|
|
3690
|
-
}
|
|
3691
|
-
function findObjectProperty(objectExpression4, name) {
|
|
3692
|
-
for (const property of objectExpression4.properties) {
|
|
3693
|
-
if (!t5.isObjectProperty(property)) {
|
|
3694
|
-
continue;
|
|
3695
|
-
}
|
|
3696
|
-
if (getPropertyKeyName(property) === name) {
|
|
3697
|
-
return property;
|
|
3698
|
-
}
|
|
3699
|
-
}
|
|
3700
|
-
return void 0;
|
|
3701
|
-
}
|
|
3702
|
-
function findObjectExpressionProperty(objectExpression4, name) {
|
|
3703
|
-
const property = findObjectProperty(objectExpression4, name);
|
|
3704
|
-
if (!property) {
|
|
3705
|
-
return void 0;
|
|
3706
|
-
}
|
|
3707
|
-
if (t5.isObjectExpression(property.value)) {
|
|
3708
|
-
return property.value;
|
|
3709
|
-
}
|
|
3710
|
-
return void 0;
|
|
3711
|
-
}
|
|
3712
|
-
function removeObjectProperty(objectExpression4, property) {
|
|
3713
|
-
const index = objectExpression4.properties.indexOf(property);
|
|
3714
|
-
if (index >= 0) {
|
|
3715
|
-
objectExpression4.properties.splice(index, 1);
|
|
3716
|
-
}
|
|
3717
|
-
}
|
|
3718
|
-
function hasObjectProperty(objectExpression4, name) {
|
|
3719
|
-
return findObjectProperty(objectExpression4, name) !== void 0;
|
|
3720
|
-
}
|
|
3721
|
-
function keyAsIdentifier(name) {
|
|
3722
|
-
return t5.identifier(name);
|
|
3723
|
-
}
|
|
3724
|
-
function mergeObjectProperties(target, source) {
|
|
3725
|
-
let changed = false;
|
|
3726
|
-
for (const sourceProperty of source.properties) {
|
|
3727
|
-
if (t5.isSpreadElement(sourceProperty)) {
|
|
3728
|
-
target.properties.push(sourceProperty);
|
|
3729
|
-
changed = true;
|
|
3730
|
-
continue;
|
|
3731
|
-
}
|
|
3732
|
-
const sourceKey = getPropertyKeyName(sourceProperty);
|
|
3733
|
-
if (!sourceKey) {
|
|
3734
|
-
target.properties.push(sourceProperty);
|
|
3735
|
-
changed = true;
|
|
3736
|
-
continue;
|
|
3737
|
-
}
|
|
3738
|
-
if (hasObjectProperty(target, sourceKey)) {
|
|
3739
|
-
continue;
|
|
3740
|
-
}
|
|
3741
|
-
target.properties.push(sourceProperty);
|
|
3742
|
-
changed = true;
|
|
3743
|
-
}
|
|
3744
|
-
return changed;
|
|
3745
|
-
}
|
|
3746
|
-
function moveProperty(objectExpression4, from, to, changes, scope) {
|
|
3747
|
-
const source = findObjectProperty(objectExpression4, from);
|
|
3748
|
-
if (!source) {
|
|
3749
|
-
return false;
|
|
3750
|
-
}
|
|
3751
|
-
const target = findObjectProperty(objectExpression4, to);
|
|
3752
|
-
if (!target) {
|
|
3753
|
-
source.key = keyAsIdentifier(to);
|
|
3754
|
-
source.computed = false;
|
|
3755
|
-
source.shorthand = false;
|
|
3756
|
-
changes.add(`${scope}.${from} -> ${scope}.${to}`);
|
|
3757
|
-
return true;
|
|
3758
|
-
}
|
|
3759
|
-
if (t5.isObjectExpression(source.value) && t5.isObjectExpression(target.value)) {
|
|
3760
|
-
const merged = mergeObjectProperties(target.value, source.value);
|
|
3761
|
-
if (merged) {
|
|
3762
|
-
changes.add(`${scope}.${from} merged into ${scope}.${to}`);
|
|
3763
|
-
}
|
|
3764
|
-
}
|
|
3765
|
-
removeObjectProperty(objectExpression4, source);
|
|
3766
|
-
changes.add(`${scope}.${from} removed (preferred ${scope}.${to})`);
|
|
3767
|
-
return true;
|
|
3768
|
-
}
|
|
3769
|
-
function migrateExtractOptions(extract, changes, scope) {
|
|
3770
|
-
let changed = false;
|
|
3771
|
-
changed = moveProperty(extract, "enabled", "write", changes, scope) || changed;
|
|
3772
|
-
changed = moveProperty(extract, "stripUniversalSelector", "removeUniversalSelector", changes, scope) || changed;
|
|
3773
|
-
return changed;
|
|
3774
|
-
}
|
|
3775
|
-
function migrateTailwindOptions(tailwindcss, changes, scope) {
|
|
3776
|
-
let changed = false;
|
|
3777
|
-
changed = moveProperty(tailwindcss, "package", "packageName", changes, scope) || changed;
|
|
3778
|
-
changed = moveProperty(tailwindcss, "legacy", "v2", changes, scope) || changed;
|
|
3779
|
-
changed = moveProperty(tailwindcss, "classic", "v3", changes, scope) || changed;
|
|
3780
|
-
changed = moveProperty(tailwindcss, "next", "v4", changes, scope) || changed;
|
|
3781
|
-
return changed;
|
|
3782
|
-
}
|
|
3783
|
-
function migrateApplyOptions(apply, changes, scope) {
|
|
3784
|
-
return moveProperty(apply, "exportContext", "exposeContext", changes, scope);
|
|
3785
|
-
}
|
|
3786
|
-
function ensureObjectExpressionProperty(objectExpression4, name, changes, scope) {
|
|
3787
|
-
const existing = findObjectProperty(objectExpression4, name);
|
|
3788
|
-
if (existing) {
|
|
3789
|
-
return t5.isObjectExpression(existing.value) ? existing.value : void 0;
|
|
3790
|
-
}
|
|
3791
|
-
const value = t5.objectExpression([]);
|
|
3792
|
-
objectExpression4.properties.push(t5.objectProperty(keyAsIdentifier(name), value));
|
|
3793
|
-
changes.add(`${scope}.${name} created`);
|
|
3794
|
-
return value;
|
|
3795
|
-
}
|
|
3796
|
-
function moveOverwriteToApply(objectExpression4, changes, scope) {
|
|
3797
|
-
const overwrite = findObjectProperty(objectExpression4, "overwrite");
|
|
3798
|
-
if (!overwrite) {
|
|
3799
|
-
return false;
|
|
3800
|
-
}
|
|
3801
|
-
const apply = ensureObjectExpressionProperty(objectExpression4, "apply", changes, scope);
|
|
3802
|
-
if (!apply) {
|
|
3803
|
-
return false;
|
|
3804
|
-
}
|
|
3805
|
-
const hasApplyOverwrite = hasObjectProperty(apply, "overwrite");
|
|
3806
|
-
if (!hasApplyOverwrite) {
|
|
3807
|
-
apply.properties.push(
|
|
3808
|
-
t5.objectProperty(keyAsIdentifier("overwrite"), overwrite.value)
|
|
3809
|
-
);
|
|
3810
|
-
changes.add(`${scope}.overwrite -> ${scope}.apply.overwrite`);
|
|
3811
|
-
}
|
|
3812
|
-
removeObjectProperty(objectExpression4, overwrite);
|
|
3813
|
-
return true;
|
|
3814
|
-
}
|
|
3815
|
-
function hasAnyRootLegacyKeys(objectExpression4) {
|
|
3816
|
-
return ROOT_LEGACY_KEYS.some((key) => hasObjectProperty(objectExpression4, key));
|
|
3817
|
-
}
|
|
3818
|
-
function migrateOptionObject(objectExpression4, scope, changes) {
|
|
3819
|
-
let changed = false;
|
|
3820
|
-
changed = moveProperty(objectExpression4, "cwd", "projectRoot", changes, scope) || changed;
|
|
3821
|
-
changed = moveProperty(objectExpression4, "tailwind", "tailwindcss", changes, scope) || changed;
|
|
3822
|
-
changed = moveProperty(objectExpression4, "features", "apply", changes, scope) || changed;
|
|
3823
|
-
changed = moveProperty(objectExpression4, "applyPatches", "apply", changes, scope) || changed;
|
|
3824
|
-
changed = moveProperty(objectExpression4, "output", "extract", changes, scope) || changed;
|
|
3825
|
-
changed = moveOverwriteToApply(objectExpression4, changes, scope) || changed;
|
|
3826
|
-
const extract = findObjectExpressionProperty(objectExpression4, "extract");
|
|
3827
|
-
if (extract) {
|
|
3828
|
-
changed = migrateExtractOptions(extract, changes, scope) || changed;
|
|
3829
|
-
}
|
|
3830
|
-
const tailwindcss = findObjectExpressionProperty(objectExpression4, "tailwindcss");
|
|
3831
|
-
if (tailwindcss) {
|
|
3832
|
-
changed = migrateTailwindOptions(tailwindcss, changes, scope) || changed;
|
|
3833
|
-
}
|
|
3834
|
-
const apply = findObjectExpressionProperty(objectExpression4, "apply");
|
|
3835
|
-
if (apply) {
|
|
3836
|
-
changed = migrateApplyOptions(apply, changes, scope) || changed;
|
|
3837
|
-
}
|
|
3838
|
-
return changed;
|
|
3839
|
-
}
|
|
3840
|
-
function unwrapExpression(node) {
|
|
3841
|
-
let current = node;
|
|
3842
|
-
while (t5.isTSAsExpression(current) || t5.isTSSatisfiesExpression(current) || t5.isTSTypeAssertion(current) || t5.isParenthesizedExpression(current)) {
|
|
3843
|
-
current = current.expression;
|
|
3844
|
-
}
|
|
3845
|
-
return current;
|
|
3846
|
-
}
|
|
3847
|
-
function resolveObjectExpressionFromExpression(expression) {
|
|
3848
|
-
const unwrapped = unwrapExpression(expression);
|
|
3849
|
-
if (t5.isObjectExpression(unwrapped)) {
|
|
3850
|
-
return unwrapped;
|
|
3851
|
-
}
|
|
3852
|
-
if (t5.isCallExpression(unwrapped)) {
|
|
3853
|
-
const [firstArg] = unwrapped.arguments;
|
|
3854
|
-
if (!firstArg || !t5.isExpression(firstArg)) {
|
|
3855
|
-
return void 0;
|
|
3856
|
-
}
|
|
3857
|
-
const firstArgUnwrapped = unwrapExpression(firstArg);
|
|
3858
|
-
if (t5.isObjectExpression(firstArgUnwrapped)) {
|
|
3859
|
-
return firstArgUnwrapped;
|
|
3860
|
-
}
|
|
3861
|
-
}
|
|
3862
|
-
return void 0;
|
|
3863
|
-
}
|
|
3864
|
-
function resolveObjectExpressionFromProgram(program, name) {
|
|
3865
|
-
for (const statement of program.body) {
|
|
3866
|
-
if (!t5.isVariableDeclaration(statement)) {
|
|
3867
|
-
continue;
|
|
3868
|
-
}
|
|
3869
|
-
for (const declaration of statement.declarations) {
|
|
3870
|
-
if (!t5.isIdentifier(declaration.id) || declaration.id.name !== name || !declaration.init) {
|
|
3871
|
-
continue;
|
|
3872
|
-
}
|
|
3873
|
-
const objectExpression4 = resolveObjectExpressionFromExpression(declaration.init);
|
|
3874
|
-
if (objectExpression4) {
|
|
3875
|
-
return objectExpression4;
|
|
3876
|
-
}
|
|
3877
|
-
}
|
|
3878
|
-
}
|
|
3879
|
-
return void 0;
|
|
3880
|
-
}
|
|
3881
|
-
function resolveRootConfigObjectExpression(program) {
|
|
3882
|
-
for (const statement of program.body) {
|
|
3883
|
-
if (!t5.isExportDefaultDeclaration(statement)) {
|
|
3884
|
-
continue;
|
|
3885
|
-
}
|
|
3886
|
-
const declaration = statement.declaration;
|
|
3887
|
-
if (t5.isIdentifier(declaration)) {
|
|
3888
|
-
return resolveObjectExpressionFromProgram(program, declaration.name);
|
|
3889
|
-
}
|
|
3890
|
-
const objectExpression4 = resolveObjectExpressionFromExpression(declaration);
|
|
3891
|
-
if (objectExpression4) {
|
|
3892
|
-
return objectExpression4;
|
|
3893
|
-
}
|
|
3894
|
-
}
|
|
3895
|
-
return void 0;
|
|
3896
|
-
}
|
|
3897
|
-
function migrateConfigSource(source) {
|
|
3898
|
-
const ast = _parser.parse.call(void 0, source, {
|
|
3899
|
-
sourceType: "module",
|
|
3900
|
-
plugins: ["typescript", "jsx"]
|
|
3901
|
-
});
|
|
3902
|
-
const root = resolveRootConfigObjectExpression(ast.program);
|
|
3903
|
-
if (!root) {
|
|
3904
|
-
return {
|
|
3905
|
-
changed: false,
|
|
3906
|
-
code: source,
|
|
3907
|
-
changes: []
|
|
3908
|
-
};
|
|
3909
|
-
}
|
|
3910
|
-
const changes = /* @__PURE__ */ new Set();
|
|
3911
|
-
let changed = false;
|
|
3912
|
-
const registry = findObjectExpressionProperty(root, "registry");
|
|
3913
|
-
if (registry) {
|
|
3914
|
-
changed = migrateOptionObject(registry, "registry", changes) || changed;
|
|
3915
|
-
}
|
|
3916
|
-
const patch = findObjectExpressionProperty(root, "patch");
|
|
3917
|
-
if (patch) {
|
|
3918
|
-
changed = migrateOptionObject(patch, "patch", changes) || changed;
|
|
3919
|
-
}
|
|
3920
|
-
if (hasAnyRootLegacyKeys(root)) {
|
|
3921
|
-
changed = migrateOptionObject(root, "root", changes) || changed;
|
|
3922
|
-
}
|
|
3923
|
-
if (!changed) {
|
|
3924
|
-
return {
|
|
3925
|
-
changed: false,
|
|
3926
|
-
code: source,
|
|
3927
|
-
changes: []
|
|
3928
|
-
};
|
|
3929
|
-
}
|
|
3930
|
-
const generated = _generator2.default.call(void 0, ast, {
|
|
3931
|
-
comments: true
|
|
3932
|
-
}).code;
|
|
3933
|
-
const code = source.endsWith("\n") ? `${generated}
|
|
3934
|
-
` : generated;
|
|
3935
|
-
return {
|
|
3936
|
-
changed: true,
|
|
3937
|
-
code,
|
|
3938
|
-
changes: [...changes]
|
|
3939
|
-
};
|
|
3940
|
-
}
|
|
3941
|
-
|
|
3942
|
-
// src/commands/migration-target-files.ts
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
var DEFAULT_CONFIG_FILENAMES = [
|
|
3946
|
-
"tailwindcss-patch.config.ts",
|
|
3947
|
-
"tailwindcss-patch.config.js",
|
|
3948
|
-
"tailwindcss-patch.config.mjs",
|
|
3949
|
-
"tailwindcss-patch.config.cjs",
|
|
3950
|
-
"tailwindcss-mangle.config.ts",
|
|
3951
|
-
"tailwindcss-mangle.config.js",
|
|
3952
|
-
"tailwindcss-mangle.config.mjs",
|
|
3953
|
-
"tailwindcss-mangle.config.cjs"
|
|
3954
|
-
];
|
|
3955
|
-
var DEFAULT_CONFIG_FILENAME_SET = new Set(DEFAULT_CONFIG_FILENAMES);
|
|
3956
|
-
var DEFAULT_WORKSPACE_IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
3957
|
-
".git",
|
|
3958
|
-
".idea",
|
|
3959
|
-
".turbo",
|
|
3960
|
-
".vscode",
|
|
3961
|
-
".yarn",
|
|
3962
|
-
"coverage",
|
|
3963
|
-
"dist",
|
|
3964
|
-
"node_modules",
|
|
3965
|
-
"tmp"
|
|
3966
|
-
]);
|
|
3967
|
-
var DEFAULT_WORKSPACE_MAX_DEPTH = 6;
|
|
3968
|
-
function resolveTargetFiles(cwd, files) {
|
|
3969
|
-
const candidates = files && files.length > 0 ? files : [...DEFAULT_CONFIG_FILENAMES];
|
|
3970
|
-
const resolved = /* @__PURE__ */ new Set();
|
|
3971
|
-
for (const file of candidates) {
|
|
3972
|
-
resolved.add(_pathe2.default.resolve(cwd, file));
|
|
3973
|
-
}
|
|
3974
|
-
return [...resolved];
|
|
3975
|
-
}
|
|
3976
|
-
async function collectWorkspaceConfigFiles(cwd, maxDepth) {
|
|
3977
|
-
const files = /* @__PURE__ */ new Set();
|
|
3978
|
-
const queue = [{ dir: cwd, depth: 0 }];
|
|
3979
|
-
while (queue.length > 0) {
|
|
3980
|
-
const current = queue.shift();
|
|
3981
|
-
if (!current) {
|
|
3982
|
-
continue;
|
|
3983
|
-
}
|
|
3984
|
-
const { dir, depth } = current;
|
|
3985
|
-
let entries;
|
|
3986
|
-
try {
|
|
3987
|
-
entries = await _fsextra2.default.readdir(dir, { withFileTypes: true });
|
|
3988
|
-
} catch (e11) {
|
|
3989
|
-
continue;
|
|
3990
|
-
}
|
|
3991
|
-
for (const entry of entries) {
|
|
3992
|
-
const absolutePath = _pathe2.default.resolve(dir, entry.name);
|
|
3993
|
-
if (entry.isFile() && DEFAULT_CONFIG_FILENAME_SET.has(entry.name)) {
|
|
3994
|
-
files.add(absolutePath);
|
|
3995
|
-
continue;
|
|
3996
|
-
}
|
|
3997
|
-
if (!entry.isDirectory()) {
|
|
3998
|
-
continue;
|
|
3999
|
-
}
|
|
4000
|
-
if (DEFAULT_WORKSPACE_IGNORED_DIRS.has(entry.name)) {
|
|
4001
|
-
continue;
|
|
4002
|
-
}
|
|
4003
|
-
if (depth >= maxDepth) {
|
|
4004
|
-
continue;
|
|
4005
|
-
}
|
|
4006
|
-
queue.push({ dir: absolutePath, depth: depth + 1 });
|
|
4007
|
-
}
|
|
4008
|
-
}
|
|
4009
|
-
return [...files].sort((a, b) => a.localeCompare(b));
|
|
4010
|
-
}
|
|
4011
|
-
function resolveBackupRelativePath(cwd, file) {
|
|
4012
|
-
const relative = _pathe2.default.relative(cwd, file);
|
|
4013
|
-
const isExternal = relative.startsWith("..") || _pathe2.default.isAbsolute(relative);
|
|
4014
|
-
if (isExternal) {
|
|
4015
|
-
const sanitized = file.replace(/[:/\\]+/g, "_");
|
|
4016
|
-
return _pathe2.default.join("__external__", `${sanitized}.bak`);
|
|
4017
|
-
}
|
|
4018
|
-
return `${relative}.bak`;
|
|
4019
|
-
}
|
|
4020
|
-
function normalizePattern(pattern) {
|
|
4021
|
-
return pattern.replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/^\/+/, "");
|
|
4022
|
-
}
|
|
4023
|
-
function globToRegExp(globPattern) {
|
|
4024
|
-
const normalized = normalizePattern(globPattern);
|
|
4025
|
-
let pattern = "";
|
|
4026
|
-
for (let i = 0; i < normalized.length; i += 1) {
|
|
4027
|
-
const char = normalized[i];
|
|
4028
|
-
if (char === "*") {
|
|
4029
|
-
if (normalized[i + 1] === "*") {
|
|
4030
|
-
pattern += ".*";
|
|
4031
|
-
i += 1;
|
|
4032
|
-
} else {
|
|
4033
|
-
pattern += "[^/]*";
|
|
4034
|
-
}
|
|
4035
|
-
continue;
|
|
4036
|
-
}
|
|
4037
|
-
if (char === "?") {
|
|
4038
|
-
pattern += "[^/]";
|
|
4039
|
-
continue;
|
|
4040
|
-
}
|
|
4041
|
-
if ("\\^$+?.()|{}[]".includes(char)) {
|
|
4042
|
-
pattern += `\\${char}`;
|
|
4043
|
-
continue;
|
|
4044
|
-
}
|
|
4045
|
-
pattern += char;
|
|
4046
|
-
}
|
|
4047
|
-
return new RegExp(`^${pattern}$`);
|
|
4048
|
-
}
|
|
4049
|
-
function toPatternList(patterns) {
|
|
4050
|
-
if (!patterns || patterns.length === 0) {
|
|
4051
|
-
return [];
|
|
4052
|
-
}
|
|
4053
|
-
return patterns.map((pattern) => pattern.trim()).filter(Boolean).map(globToRegExp);
|
|
4054
|
-
}
|
|
4055
|
-
function normalizeFileForPattern(file, cwd) {
|
|
4056
|
-
const relative = _pathe2.default.relative(cwd, file);
|
|
4057
|
-
if (!relative.startsWith("..") && !_pathe2.default.isAbsolute(relative)) {
|
|
4058
|
-
return relative.replace(/\\/g, "/");
|
|
4059
|
-
}
|
|
4060
|
-
return file.replace(/\\/g, "/");
|
|
4061
|
-
}
|
|
4062
|
-
function filterTargetFiles(targetFiles, cwd, include, exclude) {
|
|
4063
|
-
const includePatterns = toPatternList(include);
|
|
4064
|
-
const excludePatterns = toPatternList(exclude);
|
|
4065
|
-
if (includePatterns.length === 0 && excludePatterns.length === 0) {
|
|
4066
|
-
return targetFiles;
|
|
4067
|
-
}
|
|
4068
|
-
return targetFiles.filter((file) => {
|
|
4069
|
-
const normalized = normalizeFileForPattern(file, cwd);
|
|
4070
|
-
const inInclude = includePatterns.length === 0 || includePatterns.some((pattern) => pattern.test(normalized));
|
|
4071
|
-
if (!inInclude) {
|
|
4072
|
-
return false;
|
|
4073
|
-
}
|
|
4074
|
-
const inExclude = excludePatterns.some((pattern) => pattern.test(normalized));
|
|
4075
|
-
return !inExclude;
|
|
4076
|
-
});
|
|
4077
|
-
}
|
|
4078
|
-
|
|
4079
|
-
// src/commands/migration-file-executor.ts
|
|
4080
|
-
async function rollbackWrittenEntries(wroteEntries) {
|
|
4081
|
-
let rollbackCount = 0;
|
|
4082
|
-
for (const written of [...wroteEntries].reverse()) {
|
|
4083
|
-
try {
|
|
4084
|
-
await _fsextra2.default.writeFile(written.file, written.source, "utf8");
|
|
4085
|
-
written.entry.written = false;
|
|
4086
|
-
written.entry.rolledBack = true;
|
|
4087
|
-
rollbackCount += 1;
|
|
4088
|
-
} catch (e12) {
|
|
4089
|
-
}
|
|
4090
|
-
}
|
|
4091
|
-
return rollbackCount;
|
|
4092
|
-
}
|
|
4093
|
-
async function executeMigrationFile(options) {
|
|
4094
|
-
const {
|
|
4095
|
-
cwd,
|
|
4096
|
-
file,
|
|
4097
|
-
dryRun,
|
|
4098
|
-
rollbackOnError,
|
|
4099
|
-
backupDirectory,
|
|
4100
|
-
wroteEntries
|
|
4101
|
-
} = options;
|
|
4102
|
-
const exists = await _fsextra2.default.pathExists(file);
|
|
4103
|
-
if (!exists) {
|
|
4104
|
-
return {
|
|
4105
|
-
missing: true,
|
|
4106
|
-
changed: false,
|
|
4107
|
-
wrote: false,
|
|
4108
|
-
backupWritten: false
|
|
4109
|
-
};
|
|
4110
|
-
}
|
|
4111
|
-
const source = await _fsextra2.default.readFile(file, "utf8");
|
|
4112
|
-
const migrated = migrateConfigSource(source);
|
|
4113
|
-
const entry = {
|
|
4114
|
-
file,
|
|
4115
|
-
changed: migrated.changed,
|
|
4116
|
-
written: false,
|
|
4117
|
-
rolledBack: false,
|
|
4118
|
-
changes: migrated.changes
|
|
4119
|
-
};
|
|
4120
|
-
if (!migrated.changed || dryRun) {
|
|
4121
|
-
return {
|
|
4122
|
-
missing: false,
|
|
4123
|
-
changed: migrated.changed,
|
|
4124
|
-
wrote: false,
|
|
4125
|
-
backupWritten: false,
|
|
4126
|
-
entry
|
|
4127
|
-
};
|
|
4128
|
-
}
|
|
4129
|
-
let backupWritten = false;
|
|
4130
|
-
try {
|
|
4131
|
-
if (backupDirectory) {
|
|
4132
|
-
const backupRelativePath = resolveBackupRelativePath(cwd, file);
|
|
4133
|
-
const backupFile = _pathe2.default.resolve(backupDirectory, backupRelativePath);
|
|
4134
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(backupFile));
|
|
4135
|
-
await _fsextra2.default.writeFile(backupFile, source, "utf8");
|
|
4136
|
-
entry.backupFile = backupFile;
|
|
4137
|
-
backupWritten = true;
|
|
4138
|
-
}
|
|
4139
|
-
await _fsextra2.default.writeFile(file, migrated.code, "utf8");
|
|
4140
|
-
entry.written = true;
|
|
4141
|
-
wroteEntries.push({ file, source, entry });
|
|
4142
|
-
return {
|
|
4143
|
-
missing: false,
|
|
4144
|
-
changed: true,
|
|
4145
|
-
wrote: true,
|
|
4146
|
-
backupWritten,
|
|
4147
|
-
entry
|
|
4148
|
-
};
|
|
4149
|
-
} catch (error) {
|
|
4150
|
-
const rollbackCount = rollbackOnError && wroteEntries.length > 0 ? await rollbackWrittenEntries(wroteEntries) : 0;
|
|
4151
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
4152
|
-
const rollbackHint = rollbackOnError && rollbackCount > 0 ? ` Rolled back ${rollbackCount} previously written file(s).` : "";
|
|
4153
|
-
throw new Error(`Failed to write migrated config "${file}": ${reason}.${rollbackHint}`);
|
|
4154
|
-
}
|
|
4155
|
-
}
|
|
4156
|
-
async function restoreConfigEntries(entries, dryRun) {
|
|
4157
|
-
let scannedEntries = 0;
|
|
4158
|
-
let restorableEntries = 0;
|
|
4159
|
-
let restoredFiles = 0;
|
|
4160
|
-
let missingBackups = 0;
|
|
4161
|
-
let skippedEntries = 0;
|
|
4162
|
-
const restored = [];
|
|
4163
|
-
for (const entry of entries) {
|
|
4164
|
-
scannedEntries += 1;
|
|
4165
|
-
const targetFile = entry.file ? _pathe2.default.resolve(entry.file) : void 0;
|
|
4166
|
-
const backupFile = entry.backupFile ? _pathe2.default.resolve(entry.backupFile) : void 0;
|
|
4167
|
-
if (!targetFile || !backupFile) {
|
|
4168
|
-
skippedEntries += 1;
|
|
4169
|
-
continue;
|
|
4170
|
-
}
|
|
4171
|
-
restorableEntries += 1;
|
|
4172
|
-
const backupExists = await _fsextra2.default.pathExists(backupFile);
|
|
4173
|
-
if (!backupExists) {
|
|
4174
|
-
missingBackups += 1;
|
|
4175
|
-
continue;
|
|
4176
|
-
}
|
|
4177
|
-
if (!dryRun) {
|
|
4178
|
-
const backupContent = await _fsextra2.default.readFile(backupFile, "utf8");
|
|
4179
|
-
await _fsextra2.default.ensureDir(_pathe2.default.dirname(targetFile));
|
|
4180
|
-
await _fsextra2.default.writeFile(targetFile, backupContent, "utf8");
|
|
4181
|
-
}
|
|
4182
|
-
restoredFiles += 1;
|
|
4183
|
-
restored.push(targetFile);
|
|
4184
|
-
}
|
|
4185
|
-
return {
|
|
4186
|
-
scannedEntries,
|
|
4187
|
-
restorableEntries,
|
|
4188
|
-
restoredFiles,
|
|
4189
|
-
missingBackups,
|
|
4190
|
-
skippedEntries,
|
|
4191
|
-
restored
|
|
4192
|
-
};
|
|
4193
|
-
}
|
|
4194
|
-
|
|
4195
|
-
// src/commands/migration-report-loader.ts
|
|
4196
|
-
|
|
4197
|
-
async function loadMigrationReportForRestore(reportFile) {
|
|
4198
|
-
const report = await _fsextra2.default.readJSON(reportFile);
|
|
4199
|
-
assertMigrationReportCompatibility(report, reportFile);
|
|
4200
|
-
return {
|
|
4201
|
-
...report.reportKind === void 0 ? {} : { reportKind: report.reportKind },
|
|
4202
|
-
...report.schemaVersion === void 0 ? {} : { schemaVersion: report.schemaVersion },
|
|
4203
|
-
entries: Array.isArray(report.entries) ? report.entries : []
|
|
4204
|
-
};
|
|
4205
|
-
}
|
|
4206
|
-
|
|
4207
|
-
// src/commands/migration-target-resolver.ts
|
|
4208
|
-
async function resolveMigrationTargetFiles(options) {
|
|
4209
|
-
const {
|
|
4210
|
-
cwd,
|
|
4211
|
-
files,
|
|
4212
|
-
workspace,
|
|
4213
|
-
maxDepth,
|
|
4214
|
-
include,
|
|
4215
|
-
exclude
|
|
4216
|
-
} = options;
|
|
4217
|
-
const resolvedMaxDepth = _nullishCoalesce(maxDepth, () => ( DEFAULT_WORKSPACE_MAX_DEPTH));
|
|
4218
|
-
const discoveredTargetFiles = files && files.length > 0 ? resolveTargetFiles(cwd, files) : workspace ? await collectWorkspaceConfigFiles(cwd, resolvedMaxDepth) : resolveTargetFiles(cwd);
|
|
4219
|
-
return filterTargetFiles(discoveredTargetFiles, cwd, include, exclude);
|
|
4220
|
-
}
|
|
4221
|
-
|
|
4222
|
-
// src/commands/migrate-config.ts
|
|
4223
|
-
async function migrateConfigFiles(options) {
|
|
4224
|
-
const cwd = _pathe2.default.resolve(options.cwd);
|
|
4225
|
-
const dryRun = _nullishCoalesce(options.dryRun, () => ( false));
|
|
4226
|
-
const rollbackOnError = _nullishCoalesce(options.rollbackOnError, () => ( true));
|
|
4227
|
-
const backupDirectory = options.backupDir ? _pathe2.default.resolve(cwd, options.backupDir) : void 0;
|
|
4228
|
-
const targetFiles = await resolveMigrationTargetFiles({
|
|
4229
|
-
cwd,
|
|
4230
|
-
files: options.files,
|
|
4231
|
-
workspace: options.workspace,
|
|
4232
|
-
maxDepth: options.maxDepth,
|
|
4233
|
-
include: options.include,
|
|
4234
|
-
exclude: options.exclude
|
|
4235
|
-
});
|
|
4236
|
-
const aggregation = createMigrationAggregationState();
|
|
4237
|
-
const wroteEntries = [];
|
|
4238
|
-
for (const file of targetFiles) {
|
|
4239
|
-
const result = await executeMigrationFile({
|
|
4240
|
-
cwd,
|
|
4241
|
-
file,
|
|
4242
|
-
dryRun,
|
|
4243
|
-
rollbackOnError,
|
|
4244
|
-
wroteEntries,
|
|
4245
|
-
...backupDirectory ? { backupDirectory } : {}
|
|
4246
|
-
});
|
|
4247
|
-
collectMigrationExecutionResult(aggregation, result);
|
|
4248
|
-
}
|
|
4249
|
-
return buildMigrationReport(aggregation, {
|
|
4250
|
-
cwd,
|
|
4251
|
-
dryRun,
|
|
4252
|
-
rollbackOnError,
|
|
4253
|
-
...backupDirectory ? { backupDirectory } : {},
|
|
4254
|
-
toolName: pkgName,
|
|
4255
|
-
toolVersion: pkgVersion
|
|
4256
|
-
});
|
|
4257
|
-
}
|
|
4258
|
-
async function restoreConfigFiles(options) {
|
|
4259
|
-
const cwd = _pathe2.default.resolve(options.cwd);
|
|
4260
|
-
const dryRun = _nullishCoalesce(options.dryRun, () => ( false));
|
|
4261
|
-
const strict = _nullishCoalesce(options.strict, () => ( false));
|
|
4262
|
-
const reportFile = _pathe2.default.resolve(cwd, options.reportFile);
|
|
4263
|
-
const report = await loadMigrationReportForRestore(reportFile);
|
|
4264
|
-
const {
|
|
4265
|
-
scannedEntries,
|
|
4266
|
-
restorableEntries,
|
|
4267
|
-
restoredFiles,
|
|
4268
|
-
missingBackups,
|
|
4269
|
-
skippedEntries,
|
|
4270
|
-
restored
|
|
4271
|
-
} = await restoreConfigEntries(report.entries, dryRun);
|
|
4272
|
-
if (strict && missingBackups > 0) {
|
|
4273
|
-
throw new Error(`Restore failed: ${missingBackups} backup file(s) missing in report ${reportFile}.`);
|
|
4274
|
-
}
|
|
4275
|
-
return {
|
|
4276
|
-
cwd,
|
|
4277
|
-
reportFile,
|
|
4278
|
-
...report.reportKind === void 0 ? {} : { reportKind: report.reportKind },
|
|
4279
|
-
...report.schemaVersion === void 0 ? {} : { reportSchemaVersion: report.schemaVersion },
|
|
4280
|
-
dryRun,
|
|
4281
|
-
strict,
|
|
4282
|
-
scannedEntries,
|
|
4283
|
-
restorableEntries,
|
|
4284
|
-
restoredFiles,
|
|
4285
|
-
missingBackups,
|
|
4286
|
-
skippedEntries,
|
|
4287
|
-
restored
|
|
4288
|
-
};
|
|
4289
|
-
}
|
|
4290
|
-
|
|
4291
|
-
// src/commands/types.ts
|
|
4292
|
-
var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "migrate", "restore", "validate", "status"];
|
|
4293
|
-
|
|
4294
|
-
// src/commands/validate.ts
|
|
4295
|
-
var VALIDATE_EXIT_CODES = {
|
|
4296
|
-
OK: 0,
|
|
4297
|
-
REPORT_INCOMPATIBLE: 21,
|
|
4298
|
-
MISSING_BACKUPS: 22,
|
|
4299
|
-
IO_ERROR: 23,
|
|
4300
|
-
UNKNOWN_ERROR: 24
|
|
4301
|
-
};
|
|
4302
|
-
var VALIDATE_FAILURE_REASONS = [
|
|
4303
|
-
"report-incompatible",
|
|
4304
|
-
"missing-backups",
|
|
4305
|
-
"io-error",
|
|
4306
|
-
"unknown-error"
|
|
4307
|
-
];
|
|
4308
|
-
var IO_ERROR_CODES = /* @__PURE__ */ new Set(["ENOENT", "EACCES", "EPERM", "EISDIR", "ENOTDIR", "EMFILE", "ENFILE"]);
|
|
4309
|
-
function isNodeError2(error) {
|
|
4310
|
-
return !!error && typeof error === "object" && ("code" in error || "message" in error);
|
|
4311
|
-
}
|
|
4312
|
-
function classifyValidateError(error) {
|
|
4313
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4314
|
-
if (message.startsWith("Unsupported report kind") || message.startsWith("Unsupported report schema version")) {
|
|
4315
|
-
return {
|
|
4316
|
-
reason: "report-incompatible",
|
|
4317
|
-
exitCode: VALIDATE_EXIT_CODES.REPORT_INCOMPATIBLE,
|
|
4318
|
-
message
|
|
4319
|
-
};
|
|
4320
|
-
}
|
|
4321
|
-
if (message.startsWith("Restore failed:")) {
|
|
4322
|
-
return {
|
|
4323
|
-
reason: "missing-backups",
|
|
4324
|
-
exitCode: VALIDATE_EXIT_CODES.MISSING_BACKUPS,
|
|
4325
|
-
message
|
|
4326
|
-
};
|
|
4327
|
-
}
|
|
4328
|
-
if (isNodeError2(error) && typeof error.code === "string" && IO_ERROR_CODES.has(error.code)) {
|
|
4329
|
-
return {
|
|
4330
|
-
reason: "io-error",
|
|
4331
|
-
exitCode: VALIDATE_EXIT_CODES.IO_ERROR,
|
|
4332
|
-
message
|
|
4333
|
-
};
|
|
4334
|
-
}
|
|
4335
|
-
return {
|
|
4336
|
-
reason: "unknown-error",
|
|
4337
|
-
exitCode: VALIDATE_EXIT_CODES.UNKNOWN_ERROR,
|
|
4338
|
-
message
|
|
4339
|
-
};
|
|
4340
|
-
}
|
|
4341
|
-
var ValidateCommandError = class extends Error {
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
constructor(summary, options) {
|
|
4345
|
-
super(summary.message, options);
|
|
4346
|
-
this.name = "ValidateCommandError";
|
|
4347
|
-
this.reason = summary.reason;
|
|
4348
|
-
this.exitCode = summary.exitCode;
|
|
4349
|
-
}
|
|
4350
|
-
};
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.normalizeOptions = normalizeOptions; exports.loadWorkspaceConfigModule = loadWorkspaceConfigModule; exports.loadPatchOptionsForWorkspace = loadPatchOptionsForWorkspace; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.getPatchStatusReport = getPatchStatusReport; exports.TailwindcssPatcher = TailwindcssPatcher; exports.MIGRATION_REPORT_KIND = MIGRATION_REPORT_KIND; exports.MIGRATION_REPORT_SCHEMA_VERSION = MIGRATION_REPORT_SCHEMA_VERSION; exports.migrateConfigFiles = migrateConfigFiles; exports.restoreConfigFiles = restoreConfigFiles; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.VALIDATE_EXIT_CODES = VALIDATE_EXIT_CODES; exports.VALIDATE_FAILURE_REASONS = VALIDATE_FAILURE_REASONS; exports.classifyValidateError = classifyValidateError; exports.ValidateCommandError = ValidateCommandError;
|