tailwindcss-patch 9.3.7 → 9.4.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/cli-CBVPia5Z.js +671 -0
- package/dist/cli-CgBdW1U5.mjs +655 -0
- package/dist/cli.js +6 -6
- package/dist/cli.mjs +3 -3
- package/dist/commands/cli-runtime.d.mts +1 -1
- package/dist/commands/cli-runtime.d.ts +1 -1
- package/dist/commands/cli-runtime.js +8 -665
- package/dist/commands/cli-runtime.mjs +2 -654
- package/dist/index.d.mts +37 -3
- package/dist/index.d.ts +37 -3
- package/dist/index.js +339 -35
- package/dist/index.mjs +282 -3
- package/dist/{validate-D7h8SP0T.js → migrate-config-Dn9OTXpO.js} +393 -74
- package/dist/{validate-B7mTl9eT.mjs → migrate-config-DqknZpUe.mjs} +286 -76
- package/dist/{validate-DFiRmBtJ.d.ts → validate-CaJv2g5K.d.ts} +1 -1
- package/dist/{validate-CDegYLlg.d.mts → validate-Dr7IkGU8.d.mts} +1 -1
- package/package.json +1 -1
- package/src/extraction/split-candidate-tokens.ts +101 -0
- package/src/index.bundle.ts +1 -112
- package/src/index.ts +1 -95
- package/src/public-api.ts +104 -0
- package/dist/index.bundle-ByoXMvTR.mjs +0 -221
- package/dist/index.bundle-CuqnqGSX.js +0 -259
- package/src/cli.bundle.ts +0 -20
|
@@ -8,16 +8,17 @@ import { createHash } from "node:crypto";
|
|
|
8
8
|
import { createConsola } from "consola";
|
|
9
9
|
import path$1 from "node:path";
|
|
10
10
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
11
|
-
import { promises } from "node:fs";
|
|
11
|
+
import { promises, realpathSync } from "node:fs";
|
|
12
12
|
import postcss from "postcss";
|
|
13
|
-
import "
|
|
13
|
+
import { stat } from "node:fs/promises";
|
|
14
|
+
import micromatch from "micromatch";
|
|
14
15
|
import * as t from "@babel/types";
|
|
15
16
|
import generate from "@babel/generator";
|
|
16
17
|
import _babelTraverse from "@babel/traverse";
|
|
17
18
|
import { parse, parse as parse$1 } from "@babel/parser";
|
|
18
19
|
import { loadConfig } from "tailwindcss-config";
|
|
19
20
|
//#region package.json
|
|
20
|
-
var version = "9.
|
|
21
|
+
var version = "9.4.1";
|
|
21
22
|
//#endregion
|
|
22
23
|
//#region src/constants.ts
|
|
23
24
|
const pkgName = "tailwindcss-patch";
|
|
@@ -2042,7 +2043,110 @@ async function compileTailwindV4Source(source) {
|
|
|
2042
2043
|
}
|
|
2043
2044
|
//#endregion
|
|
2044
2045
|
//#region src/v4/source-scan.ts
|
|
2046
|
+
const TAILWIND_V4_IGNORED_CONTENT_DIRS = [
|
|
2047
|
+
".git",
|
|
2048
|
+
".hg",
|
|
2049
|
+
".jj",
|
|
2050
|
+
".next",
|
|
2051
|
+
".parcel-cache",
|
|
2052
|
+
".pnpm-store",
|
|
2053
|
+
".svelte-kit",
|
|
2054
|
+
".svn",
|
|
2055
|
+
".turbo",
|
|
2056
|
+
".venv",
|
|
2057
|
+
".vercel",
|
|
2058
|
+
".yarn",
|
|
2059
|
+
"__pycache__",
|
|
2060
|
+
"node_modules",
|
|
2061
|
+
"venv"
|
|
2062
|
+
];
|
|
2063
|
+
const TAILWIND_V4_IGNORED_EXTENSIONS = [
|
|
2064
|
+
"less",
|
|
2065
|
+
"lock",
|
|
2066
|
+
"sass",
|
|
2067
|
+
"scss",
|
|
2068
|
+
"styl",
|
|
2069
|
+
"log"
|
|
2070
|
+
];
|
|
2071
|
+
const TAILWIND_V4_IGNORED_FILES = [
|
|
2072
|
+
"package-lock.json",
|
|
2073
|
+
"pnpm-lock.yaml",
|
|
2074
|
+
"bun.lockb",
|
|
2075
|
+
".gitignore",
|
|
2076
|
+
".env",
|
|
2077
|
+
".env.*"
|
|
2078
|
+
];
|
|
2045
2079
|
const TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN = "**/*";
|
|
2080
|
+
function uniqueResolvedPaths(values) {
|
|
2081
|
+
const result = [];
|
|
2082
|
+
for (const value of values) {
|
|
2083
|
+
if (!value) continue;
|
|
2084
|
+
const resolved = path.resolve(value);
|
|
2085
|
+
if (!result.includes(resolved)) result.push(resolved);
|
|
2086
|
+
}
|
|
2087
|
+
return result;
|
|
2088
|
+
}
|
|
2089
|
+
function toPosixPath(value) {
|
|
2090
|
+
return value.replaceAll(path.sep, "/");
|
|
2091
|
+
}
|
|
2092
|
+
function resolveSourceScanPath(value) {
|
|
2093
|
+
const resolved = path.resolve(value);
|
|
2094
|
+
try {
|
|
2095
|
+
return realpathSync.native(resolved);
|
|
2096
|
+
} catch {
|
|
2097
|
+
return resolved;
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
function normalizeGlobPattern(pattern) {
|
|
2101
|
+
return pattern.startsWith("./") ? pattern.slice(2) : pattern;
|
|
2102
|
+
}
|
|
2103
|
+
function hasGlobMagic(value) {
|
|
2104
|
+
return /[*?[\]{}()!+@]/.test(value);
|
|
2105
|
+
}
|
|
2106
|
+
function splitStaticGlobPrefix(pattern) {
|
|
2107
|
+
const segments = normalizeGlobPattern(pattern).split(/[\\/]+/);
|
|
2108
|
+
const prefix = [];
|
|
2109
|
+
const rest = [];
|
|
2110
|
+
let reachedGlob = false;
|
|
2111
|
+
for (const segment of segments) {
|
|
2112
|
+
if (!reachedGlob && segment && !hasGlobMagic(segment)) {
|
|
2113
|
+
prefix.push(segment);
|
|
2114
|
+
continue;
|
|
2115
|
+
}
|
|
2116
|
+
reachedGlob = true;
|
|
2117
|
+
rest.push(segment);
|
|
2118
|
+
}
|
|
2119
|
+
return {
|
|
2120
|
+
prefix,
|
|
2121
|
+
rest
|
|
2122
|
+
};
|
|
2123
|
+
}
|
|
2124
|
+
async function pathExistsAsDirectory(file) {
|
|
2125
|
+
try {
|
|
2126
|
+
return (await stat(file)).isDirectory();
|
|
2127
|
+
} catch {
|
|
2128
|
+
return false;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
function createTailwindV4DefaultIgnoreSources(base) {
|
|
2132
|
+
return [
|
|
2133
|
+
...TAILWIND_V4_IGNORED_CONTENT_DIRS.map((pattern) => ({
|
|
2134
|
+
base,
|
|
2135
|
+
pattern: `**/${pattern}/**`,
|
|
2136
|
+
negated: true
|
|
2137
|
+
})),
|
|
2138
|
+
...TAILWIND_V4_IGNORED_EXTENSIONS.map((extension) => ({
|
|
2139
|
+
base,
|
|
2140
|
+
pattern: `**/*.${extension}`,
|
|
2141
|
+
negated: true
|
|
2142
|
+
})),
|
|
2143
|
+
...TAILWIND_V4_IGNORED_FILES.map((pattern) => ({
|
|
2144
|
+
base,
|
|
2145
|
+
pattern: `**/${pattern}`,
|
|
2146
|
+
negated: true
|
|
2147
|
+
}))
|
|
2148
|
+
];
|
|
2149
|
+
}
|
|
2046
2150
|
function createTailwindV4RootSources(root, fallbackBase) {
|
|
2047
2151
|
if (root === "none") return [];
|
|
2048
2152
|
if (root === null) return [{
|
|
@@ -2058,6 +2162,34 @@ function createTailwindV4RootSources(root, fallbackBase) {
|
|
|
2058
2162
|
function createTailwindV4CompiledSourceEntries(root, sources, fallbackBase) {
|
|
2059
2163
|
return [...createTailwindV4RootSources(root, fallbackBase), ...sources];
|
|
2060
2164
|
}
|
|
2165
|
+
async function resolveTailwindV4SourceEntry(sourcePath, base, negated, defaultPattern = TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN) {
|
|
2166
|
+
const absoluteSource = path.isAbsolute(sourcePath) ? path.resolve(sourcePath) : path.resolve(base, sourcePath);
|
|
2167
|
+
if (await pathExistsAsDirectory(absoluteSource)) return {
|
|
2168
|
+
base: absoluteSource,
|
|
2169
|
+
negated,
|
|
2170
|
+
pattern: normalizeGlobPattern(defaultPattern)
|
|
2171
|
+
};
|
|
2172
|
+
if (path.isAbsolute(sourcePath)) return {
|
|
2173
|
+
base: path.dirname(absoluteSource),
|
|
2174
|
+
negated,
|
|
2175
|
+
pattern: normalizeGlobPattern(path.basename(absoluteSource))
|
|
2176
|
+
};
|
|
2177
|
+
const { prefix, rest } = splitStaticGlobPrefix(sourcePath);
|
|
2178
|
+
if (prefix.length > 0 && rest.length > 0) return {
|
|
2179
|
+
base: path.resolve(base, ...prefix),
|
|
2180
|
+
negated,
|
|
2181
|
+
pattern: normalizeGlobPattern(rest.join("/"))
|
|
2182
|
+
};
|
|
2183
|
+
return {
|
|
2184
|
+
base,
|
|
2185
|
+
negated,
|
|
2186
|
+
pattern: normalizeGlobPattern(sourcePath)
|
|
2187
|
+
};
|
|
2188
|
+
}
|
|
2189
|
+
async function normalizeTailwindV4SourceEntries(sources, options = {}) {
|
|
2190
|
+
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
2191
|
+
return Promise.all(sources.map((source) => resolveTailwindV4SourceEntry(source.pattern, source.base ? path.resolve(source.base) : cwd, source.negated, options.defaultPattern)));
|
|
2192
|
+
}
|
|
2061
2193
|
function expandBracePattern(pattern) {
|
|
2062
2194
|
const index = pattern.indexOf("{");
|
|
2063
2195
|
if (index === -1) return [pattern];
|
|
@@ -2128,6 +2260,84 @@ function normalizeTailwindV4ScannerSources(sources, cwd, ignoredSources = []) {
|
|
|
2128
2260
|
negated: false
|
|
2129
2261
|
}], ...ignoredSources]);
|
|
2130
2262
|
}
|
|
2263
|
+
function normalizeEntryPattern(entry) {
|
|
2264
|
+
return path.isAbsolute(entry.pattern) ? toPosixPath(path.relative(resolveSourceScanPath(entry.base), entry.pattern)) : normalizeGlobPattern(entry.pattern);
|
|
2265
|
+
}
|
|
2266
|
+
function isFileMatchedByTailwindV4SourceEntry(file, entry) {
|
|
2267
|
+
const relative = toPosixPath(path.relative(resolveSourceScanPath(entry.base), file));
|
|
2268
|
+
return Boolean(relative) && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizeEntryPattern(entry));
|
|
2269
|
+
}
|
|
2270
|
+
function isFileExcludedByTailwindV4SourceEntries(file, entries) {
|
|
2271
|
+
if (!entries?.length) return false;
|
|
2272
|
+
const resolvedFile = resolveSourceScanPath(file);
|
|
2273
|
+
return entries.some((entry) => entry.negated && isFileMatchedByTailwindV4SourceEntry(resolvedFile, entry));
|
|
2274
|
+
}
|
|
2275
|
+
function isFileMatchedByTailwindV4SourceEntries(file, entries) {
|
|
2276
|
+
if (!entries?.length) return true;
|
|
2277
|
+
const positiveEntries = entries.filter((entry) => !entry.negated);
|
|
2278
|
+
const negativeEntries = entries.filter((entry) => entry.negated);
|
|
2279
|
+
if (positiveEntries.length === 0) return false;
|
|
2280
|
+
const resolvedFile = resolveSourceScanPath(file);
|
|
2281
|
+
if (!positiveEntries.some((entry) => isFileMatchedByTailwindV4SourceEntry(resolvedFile, entry))) return false;
|
|
2282
|
+
return !negativeEntries.some((entry) => isFileMatchedByTailwindV4SourceEntry(resolvedFile, entry));
|
|
2283
|
+
}
|
|
2284
|
+
function createTailwindV4SourceEntryMatcher(entries) {
|
|
2285
|
+
if (!entries?.length) return;
|
|
2286
|
+
return (file) => isFileMatchedByTailwindV4SourceEntries(file, entries);
|
|
2287
|
+
}
|
|
2288
|
+
function createTailwindV4SourceExclusionMatcher(entries) {
|
|
2289
|
+
if (!entries?.length) return;
|
|
2290
|
+
return (file) => isFileExcludedByTailwindV4SourceEntries(file, entries);
|
|
2291
|
+
}
|
|
2292
|
+
function groupTailwindV4SourceEntriesByBase(entries) {
|
|
2293
|
+
const entriesByBase = /* @__PURE__ */ new Map();
|
|
2294
|
+
for (const entry of entries) {
|
|
2295
|
+
const base = path.resolve(entry.base);
|
|
2296
|
+
const group = entriesByBase.get(base) ?? [];
|
|
2297
|
+
group.push({
|
|
2298
|
+
...entry,
|
|
2299
|
+
base,
|
|
2300
|
+
pattern: normalizeGlobPattern(entry.pattern)
|
|
2301
|
+
});
|
|
2302
|
+
entriesByBase.set(base, group);
|
|
2303
|
+
}
|
|
2304
|
+
return entriesByBase;
|
|
2305
|
+
}
|
|
2306
|
+
async function expandTailwindV4SourceEntries(entries, resolveFiles) {
|
|
2307
|
+
if (entries.length === 0) return [];
|
|
2308
|
+
const files = /* @__PURE__ */ new Set();
|
|
2309
|
+
await Promise.all([...groupTailwindV4SourceEntriesByBase(entries).entries()].map(async ([base, group]) => {
|
|
2310
|
+
const matched = await resolveFiles({
|
|
2311
|
+
cwd: base,
|
|
2312
|
+
sources: group
|
|
2313
|
+
});
|
|
2314
|
+
for (const file of matched) files.add(path.resolve(file));
|
|
2315
|
+
}));
|
|
2316
|
+
return [...files].filter((file) => !isFileExcludedByTailwindV4SourceEntries(file, entries));
|
|
2317
|
+
}
|
|
2318
|
+
function mergeTailwindV4SourceEntries(...entries) {
|
|
2319
|
+
const result = [];
|
|
2320
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2321
|
+
for (const group of entries) for (const entry of group ?? []) {
|
|
2322
|
+
const normalized = {
|
|
2323
|
+
base: path.resolve(entry.base),
|
|
2324
|
+
pattern: normalizeGlobPattern(entry.pattern),
|
|
2325
|
+
negated: entry.negated
|
|
2326
|
+
};
|
|
2327
|
+
const key = JSON.stringify(normalized);
|
|
2328
|
+
if (seen.has(key)) continue;
|
|
2329
|
+
seen.add(key);
|
|
2330
|
+
result.push(normalized);
|
|
2331
|
+
}
|
|
2332
|
+
return result;
|
|
2333
|
+
}
|
|
2334
|
+
function resolveTailwindV4SourceBaseCandidates(projectRoot, base, baseFallbacks) {
|
|
2335
|
+
return uniqueResolvedPaths([
|
|
2336
|
+
base,
|
|
2337
|
+
projectRoot,
|
|
2338
|
+
...baseFallbacks
|
|
2339
|
+
]);
|
|
2340
|
+
}
|
|
2131
2341
|
//#endregion
|
|
2132
2342
|
//#region src/extraction/candidate-extractor.ts
|
|
2133
2343
|
let oxideImportPromise;
|
|
@@ -3600,6 +3810,78 @@ var TailwindcssPatcher = class {
|
|
|
3600
3810
|
}
|
|
3601
3811
|
};
|
|
3602
3812
|
//#endregion
|
|
3813
|
+
//#region src/commands/types.ts
|
|
3814
|
+
const tailwindcssPatchCommands = [
|
|
3815
|
+
"install",
|
|
3816
|
+
"extract",
|
|
3817
|
+
"tokens",
|
|
3818
|
+
"init",
|
|
3819
|
+
"migrate",
|
|
3820
|
+
"restore",
|
|
3821
|
+
"validate",
|
|
3822
|
+
"status"
|
|
3823
|
+
];
|
|
3824
|
+
//#endregion
|
|
3825
|
+
//#region src/commands/validate.ts
|
|
3826
|
+
const VALIDATE_EXIT_CODES = {
|
|
3827
|
+
OK: 0,
|
|
3828
|
+
REPORT_INCOMPATIBLE: 21,
|
|
3829
|
+
MISSING_BACKUPS: 22,
|
|
3830
|
+
IO_ERROR: 23,
|
|
3831
|
+
UNKNOWN_ERROR: 24
|
|
3832
|
+
};
|
|
3833
|
+
const VALIDATE_FAILURE_REASONS = [
|
|
3834
|
+
"report-incompatible",
|
|
3835
|
+
"missing-backups",
|
|
3836
|
+
"io-error",
|
|
3837
|
+
"unknown-error"
|
|
3838
|
+
];
|
|
3839
|
+
const IO_ERROR_CODES = new Set([
|
|
3840
|
+
"ENOENT",
|
|
3841
|
+
"EACCES",
|
|
3842
|
+
"EPERM",
|
|
3843
|
+
"EISDIR",
|
|
3844
|
+
"ENOTDIR",
|
|
3845
|
+
"EMFILE",
|
|
3846
|
+
"ENFILE"
|
|
3847
|
+
]);
|
|
3848
|
+
function isNodeError(error) {
|
|
3849
|
+
return !!error && typeof error === "object" && ("code" in error || "message" in error);
|
|
3850
|
+
}
|
|
3851
|
+
function classifyValidateError(error) {
|
|
3852
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3853
|
+
if (message.startsWith("Unsupported report kind") || message.startsWith("Unsupported report schema version")) return {
|
|
3854
|
+
reason: "report-incompatible",
|
|
3855
|
+
exitCode: VALIDATE_EXIT_CODES.REPORT_INCOMPATIBLE,
|
|
3856
|
+
message
|
|
3857
|
+
};
|
|
3858
|
+
if (message.startsWith("Restore failed:")) return {
|
|
3859
|
+
reason: "missing-backups",
|
|
3860
|
+
exitCode: VALIDATE_EXIT_CODES.MISSING_BACKUPS,
|
|
3861
|
+
message
|
|
3862
|
+
};
|
|
3863
|
+
if (isNodeError(error) && typeof error.code === "string" && IO_ERROR_CODES.has(error.code)) return {
|
|
3864
|
+
reason: "io-error",
|
|
3865
|
+
exitCode: VALIDATE_EXIT_CODES.IO_ERROR,
|
|
3866
|
+
message
|
|
3867
|
+
};
|
|
3868
|
+
return {
|
|
3869
|
+
reason: "unknown-error",
|
|
3870
|
+
exitCode: VALIDATE_EXIT_CODES.UNKNOWN_ERROR,
|
|
3871
|
+
message
|
|
3872
|
+
};
|
|
3873
|
+
}
|
|
3874
|
+
var ValidateCommandError = class extends Error {
|
|
3875
|
+
reason;
|
|
3876
|
+
exitCode;
|
|
3877
|
+
constructor(summary, options) {
|
|
3878
|
+
super(summary.message, options);
|
|
3879
|
+
this.name = "ValidateCommandError";
|
|
3880
|
+
this.reason = summary.reason;
|
|
3881
|
+
this.exitCode = summary.exitCode;
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3884
|
+
//#endregion
|
|
3603
3885
|
//#region src/commands/migration-report.ts
|
|
3604
3886
|
const MIGRATION_REPORT_KIND = "tw-patch-migrate-report";
|
|
3605
3887
|
const MIGRATION_REPORT_SCHEMA_VERSION = 1;
|
|
@@ -4146,76 +4428,4 @@ async function restoreConfigFiles(options) {
|
|
|
4146
4428
|
};
|
|
4147
4429
|
}
|
|
4148
4430
|
//#endregion
|
|
4149
|
-
|
|
4150
|
-
const tailwindcssPatchCommands = [
|
|
4151
|
-
"install",
|
|
4152
|
-
"extract",
|
|
4153
|
-
"tokens",
|
|
4154
|
-
"init",
|
|
4155
|
-
"migrate",
|
|
4156
|
-
"restore",
|
|
4157
|
-
"validate",
|
|
4158
|
-
"status"
|
|
4159
|
-
];
|
|
4160
|
-
//#endregion
|
|
4161
|
-
//#region src/commands/validate.ts
|
|
4162
|
-
const VALIDATE_EXIT_CODES = {
|
|
4163
|
-
OK: 0,
|
|
4164
|
-
REPORT_INCOMPATIBLE: 21,
|
|
4165
|
-
MISSING_BACKUPS: 22,
|
|
4166
|
-
IO_ERROR: 23,
|
|
4167
|
-
UNKNOWN_ERROR: 24
|
|
4168
|
-
};
|
|
4169
|
-
const VALIDATE_FAILURE_REASONS = [
|
|
4170
|
-
"report-incompatible",
|
|
4171
|
-
"missing-backups",
|
|
4172
|
-
"io-error",
|
|
4173
|
-
"unknown-error"
|
|
4174
|
-
];
|
|
4175
|
-
const IO_ERROR_CODES = new Set([
|
|
4176
|
-
"ENOENT",
|
|
4177
|
-
"EACCES",
|
|
4178
|
-
"EPERM",
|
|
4179
|
-
"EISDIR",
|
|
4180
|
-
"ENOTDIR",
|
|
4181
|
-
"EMFILE",
|
|
4182
|
-
"ENFILE"
|
|
4183
|
-
]);
|
|
4184
|
-
function isNodeError(error) {
|
|
4185
|
-
return !!error && typeof error === "object" && ("code" in error || "message" in error);
|
|
4186
|
-
}
|
|
4187
|
-
function classifyValidateError(error) {
|
|
4188
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
4189
|
-
if (message.startsWith("Unsupported report kind") || message.startsWith("Unsupported report schema version")) return {
|
|
4190
|
-
reason: "report-incompatible",
|
|
4191
|
-
exitCode: VALIDATE_EXIT_CODES.REPORT_INCOMPATIBLE,
|
|
4192
|
-
message
|
|
4193
|
-
};
|
|
4194
|
-
if (message.startsWith("Restore failed:")) return {
|
|
4195
|
-
reason: "missing-backups",
|
|
4196
|
-
exitCode: VALIDATE_EXIT_CODES.MISSING_BACKUPS,
|
|
4197
|
-
message
|
|
4198
|
-
};
|
|
4199
|
-
if (isNodeError(error) && typeof error.code === "string" && IO_ERROR_CODES.has(error.code)) return {
|
|
4200
|
-
reason: "io-error",
|
|
4201
|
-
exitCode: VALIDATE_EXIT_CODES.IO_ERROR,
|
|
4202
|
-
message
|
|
4203
|
-
};
|
|
4204
|
-
return {
|
|
4205
|
-
reason: "unknown-error",
|
|
4206
|
-
exitCode: VALIDATE_EXIT_CODES.UNKNOWN_ERROR,
|
|
4207
|
-
message
|
|
4208
|
-
};
|
|
4209
|
-
}
|
|
4210
|
-
var ValidateCommandError = class extends Error {
|
|
4211
|
-
reason;
|
|
4212
|
-
exitCode;
|
|
4213
|
-
constructor(summary, options) {
|
|
4214
|
-
super(summary.message, options);
|
|
4215
|
-
this.name = "ValidateCommandError";
|
|
4216
|
-
this.reason = summary.reason;
|
|
4217
|
-
this.exitCode = summary.exitCode;
|
|
4218
|
-
}
|
|
4219
|
-
};
|
|
4220
|
-
//#endregion
|
|
4221
|
-
export { resolveValidTailwindV4Candidates as A, resolveProjectSourceFiles as C, canonicalizeBareArbitraryValueCandidates as D, loadTailwindV4DesignSystem as E, logger as F, loadWorkspaceConfigModule as M, normalizeOptions as N, extractTailwindV4InlineSourceCandidates as O, CacheStore as P, groupTokensByFile as S, compileTailwindV4Source as T, extractRawCandidates as _, tailwindcssPatchCommands as a, extractSourceCandidatesWithPositions as b, MIGRATION_REPORT_KIND as c, getPatchStatusReport as d, runTailwindBuild as f, extractProjectCandidatesWithPositions as g, collectClassesFromTailwindV4 as h, classifyValidateError as i, loadPatchOptionsForWorkspace as j, replaceBareArbitraryValueSelectors as k, MIGRATION_REPORT_SCHEMA_VERSION as l, collectClassesFromContexts as m, VALIDATE_FAILURE_REASONS as n, migrateConfigFiles as o, loadRuntimeContexts as p, ValidateCommandError as r, restoreConfigFiles as s, VALIDATE_EXIT_CODES as t, TailwindcssPatcher as u, extractRawCandidatesWithPositions as v, createTailwindV4CompiledSourceEntries as w, extractValidCandidates as x, extractSourceCandidates as y };
|
|
4431
|
+
export { logger as $, createTailwindV4RootSources as A, resolveSourceScanPath as B, resolveProjectSourceFiles as C, TAILWIND_V4_IGNORED_FILES as D, TAILWIND_V4_IGNORED_EXTENSIONS as E, isFileExcludedByTailwindV4SourceEntries as F, canonicalizeBareArbitraryValueCandidates as G, resolveTailwindV4SourceEntry as H, isFileMatchedByTailwindV4SourceEntries as I, resolveValidTailwindV4Candidates as J, extractTailwindV4InlineSourceCandidates as K, mergeTailwindV4SourceEntries as L, createTailwindV4SourceExclusionMatcher as M, expandTailwindV4SourceEntries as N, createTailwindV4CompiledSourceEntries as O, expandTailwindV4SourceEntryBraces as P, CacheStore as Q, normalizeTailwindV4ScannerSources as R, groupTokensByFile as S, TAILWIND_V4_IGNORED_CONTENT_DIRS as T, compileTailwindV4Source as U, resolveTailwindV4SourceBaseCandidates as V, loadTailwindV4DesignSystem as W, loadWorkspaceConfigModule as X, loadPatchOptionsForWorkspace as Y, normalizeOptions as Z, extractRawCandidates as _, VALIDATE_EXIT_CODES as a, extractSourceCandidatesWithPositions as b, classifyValidateError as c, getPatchStatusReport as d, runTailwindBuild as f, extractProjectCandidatesWithPositions as g, collectClassesFromTailwindV4 as h, MIGRATION_REPORT_SCHEMA_VERSION as i, createTailwindV4SourceEntryMatcher as j, createTailwindV4DefaultIgnoreSources as k, tailwindcssPatchCommands as l, collectClassesFromContexts as m, restoreConfigFiles as n, VALIDATE_FAILURE_REASONS as o, loadRuntimeContexts as p, replaceBareArbitraryValueSelectors as q, MIGRATION_REPORT_KIND as r, ValidateCommandError as s, migrateConfigFiles as t, TailwindcssPatcher as u, extractRawCandidatesWithPositions as v, TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN as w, extractValidCandidates as x, extractSourceCandidates as y, normalizeTailwindV4SourceEntries as z };
|
|
@@ -791,4 +791,4 @@ declare class ValidateCommandError extends Error {
|
|
|
791
791
|
constructor(summary: ValidateFailureSummary, options?: ErrorOptions);
|
|
792
792
|
}
|
|
793
793
|
//#endregion
|
|
794
|
-
export {
|
|
794
|
+
export { TailwindV4DesignSystem as $, extractSourceCandidates as A, ExposeContextOptions as B, MIGRATION_REPORT_SCHEMA_VERSION as C, CacheContextMetadata as Ct, extractProjectCandidatesWithPositions as D, ExtractSourceCandidate as E, CacheReadResult as Et, BareArbitraryValueOptions as F, TailwindCssOptions as G, ExtractOptions as H, normalizeOptions as I, TailwindV3Options as J, TailwindCssPatchOptions as K, ApplyOptions as L, extractValidCandidates as M, groupTokensByFile as N, extractRawCandidates as O, resolveProjectSourceFiles as P, TailwindV4CssSource as Q, CacheOptions as R, MIGRATION_REPORT_KIND as S, CacheContextDescriptor as St, TailwindcssPatcher as T, CacheReadMeta as Tt, NormalizedCacheOptions as U, ExtendLengthUnitsOptions as V, NormalizedTailwindCssPatchOptions as W, TailwindV4CandidateSource as X, TailwindV4Options as Y, TailwindV4CompiledSourceRoot as Z, ConfigFileMigrationEntry as _, TailwindcssClassCache as _t, ValidateFailureSummary as a, TailwindV4SourcePattern as at, RestoreConfigFilesOptions as b, CacheClearResult as bt, TailwindcssPatchCliMountOptions as c, PatchCheckStatus as ct, TailwindcssPatchCommandContext as d, PatchStatusReport as dt, TailwindV4Engine as et, TailwindcssPatchCommandHandler as f, TailwindPatchRuntime as ft, tailwindcssPatchCommands as g, TailwindTokenReport as gt, TailwindcssPatchCommandOptions as h, TailwindTokenLocation as ht, ValidateFailureReason as i, TailwindV4SourceOptions as it, extractSourceCandidatesWithPositions as j, extractRawCandidatesWithPositions as k, TailwindcssPatchCliOptions as l, PatchName as lt, TailwindcssPatchCommandOptionDefinition as m, TailwindTokenFileKey as mt, VALIDATE_FAILURE_REASONS as n, TailwindV4GenerateResult as nt, ValidateJsonFailurePayload as o, ExtractResult as ot, TailwindcssPatchCommandHandlerMap as p, TailwindTokenByFileMap as pt, TailwindV2Options as q, ValidateCommandError as r, TailwindV4ResolvedSource as rt, ValidateJsonSuccessPayload as s, ILengthUnitsPatchOptions as st, VALIDATE_EXIT_CODES as t, TailwindV4GenerateOptions as tt, TailwindcssPatchCommand as u, PatchStatusEntry as ut, ConfigFileMigrationReport as v, TailwindcssRuntimeContext as vt, logger as w, CacheIndexFileV2 as wt, RestoreConfigFilesResult as x, CacheClearScope as xt, MigrateConfigFilesOptions as y, CacheClearOptions as yt, CacheStrategy as z };
|
|
@@ -790,4 +790,4 @@ declare class ValidateCommandError extends Error {
|
|
|
790
790
|
constructor(summary: ValidateFailureSummary, options?: ErrorOptions);
|
|
791
791
|
}
|
|
792
792
|
//#endregion
|
|
793
|
-
export {
|
|
793
|
+
export { TailwindV4DesignSystem as $, extractSourceCandidates as A, ExposeContextOptions as B, MIGRATION_REPORT_SCHEMA_VERSION as C, CacheContextMetadata as Ct, extractProjectCandidatesWithPositions as D, ExtractSourceCandidate as E, CacheReadResult as Et, BareArbitraryValueOptions as F, TailwindCssOptions as G, ExtractOptions as H, normalizeOptions as I, TailwindV3Options as J, TailwindCssPatchOptions as K, ApplyOptions as L, extractValidCandidates as M, groupTokensByFile as N, extractRawCandidates as O, resolveProjectSourceFiles as P, TailwindV4CssSource as Q, CacheOptions as R, MIGRATION_REPORT_KIND as S, CacheContextDescriptor as St, TailwindcssPatcher as T, CacheReadMeta as Tt, NormalizedCacheOptions as U, ExtendLengthUnitsOptions as V, NormalizedTailwindCssPatchOptions as W, TailwindV4CandidateSource as X, TailwindV4Options as Y, TailwindV4CompiledSourceRoot as Z, ConfigFileMigrationEntry as _, TailwindcssClassCache as _t, ValidateFailureSummary as a, TailwindV4SourcePattern as at, RestoreConfigFilesOptions as b, CacheClearResult as bt, TailwindcssPatchCliMountOptions as c, PatchCheckStatus as ct, TailwindcssPatchCommandContext as d, PatchStatusReport as dt, TailwindV4Engine as et, TailwindcssPatchCommandHandler as f, TailwindPatchRuntime as ft, tailwindcssPatchCommands as g, TailwindTokenReport as gt, TailwindcssPatchCommandOptions as h, TailwindTokenLocation as ht, ValidateFailureReason as i, TailwindV4SourceOptions as it, extractSourceCandidatesWithPositions as j, extractRawCandidatesWithPositions as k, TailwindcssPatchCliOptions as l, PatchName as lt, TailwindcssPatchCommandOptionDefinition as m, TailwindTokenFileKey as mt, VALIDATE_FAILURE_REASONS as n, TailwindV4GenerateResult as nt, ValidateJsonFailurePayload as o, ExtractResult as ot, TailwindcssPatchCommandHandlerMap as p, TailwindTokenByFileMap as pt, TailwindV2Options as q, ValidateCommandError as r, TailwindV4ResolvedSource as rt, ValidateJsonSuccessPayload as s, ILengthUnitsPatchOptions as st, VALIDATE_EXIT_CODES as t, TailwindV4GenerateOptions as tt, TailwindcssPatchCommand as u, PatchStatusEntry as ut, ConfigFileMigrationReport as v, TailwindcssRuntimeContext as vt, logger as w, CacheIndexFileV2 as wt, RestoreConfigFilesResult as x, CacheClearScope as xt, MigrateConfigFilesOptions as y, CacheClearOptions as yt, CacheStrategy as z };
|
package/package.json
CHANGED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// 参考链接:https://github.com/tailwindlabs/tailwindcss/blob/master/src/lib/regex.js
|
|
2
|
+
// eslint-disable-next-line regexp/no-obscure-range
|
|
3
|
+
export const validateCandidateTokenRE = /[\w\u00A0-\uFFFF%-?]/
|
|
4
|
+
|
|
5
|
+
export function isValidCandidateToken(token = ''): token is string {
|
|
6
|
+
return validateCandidateTokenRE.test(token)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const SPLIT_CACHE_LIMIT = 8192
|
|
10
|
+
const ESCAPED_WHITESPACE_RE = /\\[nrt]/g
|
|
11
|
+
const splitCache = new Map<string, string[]>()
|
|
12
|
+
|
|
13
|
+
function isSplitter(char: string, bracketDepth: number) {
|
|
14
|
+
return bracketDepth === 0 && (char === '"' || /\s/.test(char))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function hasClosingQuotedArbitraryValue(code: string, start: number, quote: string) {
|
|
18
|
+
for (let index = start; index < code.length; index++) {
|
|
19
|
+
if (code[index] === '\\') {
|
|
20
|
+
index++
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
if (code[index] === quote) {
|
|
24
|
+
return code.includes(']', index + 1)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function splitBracketAware(code: string) {
|
|
32
|
+
const result: string[] = []
|
|
33
|
+
let bracketDepth = 0
|
|
34
|
+
let bracketQuote: string | undefined
|
|
35
|
+
let start = 0
|
|
36
|
+
|
|
37
|
+
for (let index = 0; index < code.length; index++) {
|
|
38
|
+
const char = code[index]
|
|
39
|
+
if (char === undefined) {
|
|
40
|
+
continue
|
|
41
|
+
}
|
|
42
|
+
if (bracketDepth > 0 && char === '\\') {
|
|
43
|
+
index++
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (bracketDepth > 0 && (char === '"' || char === '\'')) {
|
|
48
|
+
if (bracketQuote === char) {
|
|
49
|
+
bracketQuote = undefined
|
|
50
|
+
}
|
|
51
|
+
else if (bracketQuote === undefined && hasClosingQuotedArbitraryValue(code, index + 1, char)) {
|
|
52
|
+
bracketQuote = char
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (bracketQuote === undefined) {
|
|
57
|
+
if (char === '[' && code.includes(']', index + 1)) {
|
|
58
|
+
bracketDepth++
|
|
59
|
+
}
|
|
60
|
+
else if (char === ']' && bracketDepth > 0) {
|
|
61
|
+
bracketDepth--
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (!isSplitter(char, bracketDepth)) {
|
|
66
|
+
continue
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const candidate = code.slice(start, index)
|
|
70
|
+
if (isValidCandidateToken(candidate)) {
|
|
71
|
+
result.push(candidate)
|
|
72
|
+
}
|
|
73
|
+
start = index + 1
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const candidate = code.slice(start)
|
|
77
|
+
if (isValidCandidateToken(candidate)) {
|
|
78
|
+
result.push(candidate)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function splitCandidateTokens(code: string) {
|
|
85
|
+
const cached = splitCache.get(code)
|
|
86
|
+
if (cached) {
|
|
87
|
+
return cached
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 把压缩产物中的转义空白字符(\n \r \t)先还原成空格,避免被粘连到类名上。
|
|
91
|
+
const normalized = code.includes('\\') ? code.replace(ESCAPED_WHITESPACE_RE, ' ') : code
|
|
92
|
+
const result = splitBracketAware(normalized)
|
|
93
|
+
|
|
94
|
+
// 防止缓存无限增长。
|
|
95
|
+
if (splitCache.size >= SPLIT_CACHE_LIMIT) {
|
|
96
|
+
splitCache.clear()
|
|
97
|
+
}
|
|
98
|
+
splitCache.set(code, result)
|
|
99
|
+
|
|
100
|
+
return result
|
|
101
|
+
}
|
package/src/index.bundle.ts
CHANGED
|
@@ -1,48 +1,7 @@
|
|
|
1
|
-
import type { TailwindcssMangleConfig } from '@tailwindcss-mangle/config'
|
|
2
1
|
import type { CAC } from 'cac'
|
|
3
2
|
import type { TailwindcssPatchCliMountOptions, TailwindcssPatchCliOptions } from './commands/types'
|
|
4
3
|
|
|
5
4
|
import { createRequire } from 'node:module'
|
|
6
|
-
import { TailwindcssPatcher } from './api/tailwindcss-patcher'
|
|
7
|
-
import { CacheStore } from './cache/store'
|
|
8
|
-
import {
|
|
9
|
-
migrateConfigFiles,
|
|
10
|
-
MIGRATION_REPORT_KIND,
|
|
11
|
-
MIGRATION_REPORT_SCHEMA_VERSION,
|
|
12
|
-
restoreConfigFiles,
|
|
13
|
-
} from './commands/migrate-config'
|
|
14
|
-
import { tailwindcssPatchCommands } from './commands/types'
|
|
15
|
-
import {
|
|
16
|
-
VALIDATE_EXIT_CODES,
|
|
17
|
-
VALIDATE_FAILURE_REASONS,
|
|
18
|
-
ValidateCommandError,
|
|
19
|
-
} from './commands/validate'
|
|
20
|
-
import { normalizeOptions } from './config'
|
|
21
|
-
import {
|
|
22
|
-
extractProjectCandidatesWithPositions,
|
|
23
|
-
extractRawCandidates,
|
|
24
|
-
extractRawCandidatesWithPositions,
|
|
25
|
-
extractSourceCandidates,
|
|
26
|
-
extractSourceCandidatesWithPositions,
|
|
27
|
-
extractValidCandidates,
|
|
28
|
-
groupTokensByFile,
|
|
29
|
-
resolveProjectSourceFiles,
|
|
30
|
-
} from './extraction/candidate-extractor'
|
|
31
|
-
import {
|
|
32
|
-
collectClassesFromContexts,
|
|
33
|
-
collectClassesFromTailwindV4,
|
|
34
|
-
getPatchStatusReport,
|
|
35
|
-
loadRuntimeContexts,
|
|
36
|
-
runTailwindBuild,
|
|
37
|
-
} from './install'
|
|
38
|
-
import logger from './logger'
|
|
39
|
-
import {
|
|
40
|
-
createTailwindV4Engine,
|
|
41
|
-
loadTailwindV4DesignSystem,
|
|
42
|
-
resolveTailwindV4Source,
|
|
43
|
-
resolveTailwindV4SourceFromPatchOptions,
|
|
44
|
-
resolveValidTailwindV4Candidates,
|
|
45
|
-
} from './v4'
|
|
46
5
|
|
|
47
6
|
const require = createRequire(import.meta.url)
|
|
48
7
|
|
|
@@ -52,73 +11,7 @@ function loadCliModule(): CliModule {
|
|
|
52
11
|
return require('./commands/cli-runtime.js') as CliModule
|
|
53
12
|
}
|
|
54
13
|
|
|
55
|
-
export
|
|
56
|
-
CacheStore,
|
|
57
|
-
collectClassesFromContexts,
|
|
58
|
-
collectClassesFromTailwindV4,
|
|
59
|
-
createTailwindV4Engine,
|
|
60
|
-
extractProjectCandidatesWithPositions,
|
|
61
|
-
extractRawCandidates,
|
|
62
|
-
extractRawCandidatesWithPositions,
|
|
63
|
-
extractSourceCandidates,
|
|
64
|
-
extractSourceCandidatesWithPositions,
|
|
65
|
-
extractValidCandidates,
|
|
66
|
-
getPatchStatusReport,
|
|
67
|
-
groupTokensByFile,
|
|
68
|
-
loadRuntimeContexts,
|
|
69
|
-
loadTailwindV4DesignSystem,
|
|
70
|
-
logger,
|
|
71
|
-
migrateConfigFiles,
|
|
72
|
-
MIGRATION_REPORT_KIND,
|
|
73
|
-
MIGRATION_REPORT_SCHEMA_VERSION,
|
|
74
|
-
normalizeOptions,
|
|
75
|
-
resolveTailwindV4Source,
|
|
76
|
-
resolveTailwindV4SourceFromPatchOptions,
|
|
77
|
-
resolveProjectSourceFiles,
|
|
78
|
-
resolveValidTailwindV4Candidates,
|
|
79
|
-
restoreConfigFiles,
|
|
80
|
-
runTailwindBuild,
|
|
81
|
-
tailwindcssPatchCommands,
|
|
82
|
-
TailwindcssPatcher,
|
|
83
|
-
VALIDATE_EXIT_CODES,
|
|
84
|
-
VALIDATE_FAILURE_REASONS,
|
|
85
|
-
ValidateCommandError,
|
|
86
|
-
}
|
|
87
|
-
export type {
|
|
88
|
-
ConfigFileMigrationEntry,
|
|
89
|
-
ConfigFileMigrationReport,
|
|
90
|
-
MigrateConfigFilesOptions,
|
|
91
|
-
RestoreConfigFilesOptions,
|
|
92
|
-
RestoreConfigFilesResult,
|
|
93
|
-
} from './commands/migrate-config'
|
|
94
|
-
export type {
|
|
95
|
-
TailwindcssPatchCliMountOptions,
|
|
96
|
-
TailwindcssPatchCliOptions,
|
|
97
|
-
TailwindcssPatchCommand,
|
|
98
|
-
TailwindcssPatchCommandContext,
|
|
99
|
-
TailwindcssPatchCommandHandler,
|
|
100
|
-
TailwindcssPatchCommandHandlerMap,
|
|
101
|
-
TailwindcssPatchCommandOptionDefinition,
|
|
102
|
-
TailwindcssPatchCommandOptions,
|
|
103
|
-
} from './commands/types'
|
|
104
|
-
export type {
|
|
105
|
-
ValidateFailureReason,
|
|
106
|
-
ValidateFailureSummary,
|
|
107
|
-
ValidateJsonFailurePayload,
|
|
108
|
-
ValidateJsonSuccessPayload,
|
|
109
|
-
} from './commands/validate'
|
|
110
|
-
export type { TailwindCssPatchOptions } from './config'
|
|
111
|
-
export * from './types'
|
|
112
|
-
export type {
|
|
113
|
-
TailwindV4CandidateSource,
|
|
114
|
-
TailwindV4CssSource,
|
|
115
|
-
TailwindV4DesignSystem,
|
|
116
|
-
TailwindV4Engine,
|
|
117
|
-
TailwindV4GenerateOptions,
|
|
118
|
-
TailwindV4GenerateResult,
|
|
119
|
-
TailwindV4ResolvedSource,
|
|
120
|
-
TailwindV4SourceOptions,
|
|
121
|
-
} from './v4'
|
|
14
|
+
export * from './public-api'
|
|
122
15
|
|
|
123
16
|
export function mountTailwindcssPatchCommands(cli: CAC, options: TailwindcssPatchCliMountOptions = {}) {
|
|
124
17
|
return loadCliModule().mountTailwindcssPatchCommands(cli, options)
|
|
@@ -127,7 +20,3 @@ export function mountTailwindcssPatchCommands(cli: CAC, options: TailwindcssPatc
|
|
|
127
20
|
export function createTailwindcssPatchCli(options: TailwindcssPatchCliOptions = {}) {
|
|
128
21
|
return loadCliModule().createTailwindcssPatchCli(options)
|
|
129
22
|
}
|
|
130
|
-
|
|
131
|
-
export function defineConfig<T extends TailwindcssMangleConfig>(config: T): T {
|
|
132
|
-
return config
|
|
133
|
-
}
|