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
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,282 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { $ as logger, A as createTailwindV4RootSources, B as resolveSourceScanPath, C as resolveProjectSourceFiles, D as TAILWIND_V4_IGNORED_FILES, E as TAILWIND_V4_IGNORED_EXTENSIONS, F as isFileExcludedByTailwindV4SourceEntries, G as canonicalizeBareArbitraryValueCandidates, H as resolveTailwindV4SourceEntry, I as isFileMatchedByTailwindV4SourceEntries, J as resolveValidTailwindV4Candidates, K as extractTailwindV4InlineSourceCandidates, L as mergeTailwindV4SourceEntries, M as createTailwindV4SourceExclusionMatcher, N as expandTailwindV4SourceEntries, O as createTailwindV4CompiledSourceEntries, P as expandTailwindV4SourceEntryBraces, Q as CacheStore, R as normalizeTailwindV4ScannerSources, S as groupTokensByFile, T as TAILWIND_V4_IGNORED_CONTENT_DIRS, U as compileTailwindV4Source, V as resolveTailwindV4SourceBaseCandidates, W as loadTailwindV4DesignSystem, Z as normalizeOptions, _ as extractRawCandidates, a as VALIDATE_EXIT_CODES, b as extractSourceCandidatesWithPositions, d as getPatchStatusReport, f as runTailwindBuild, g as extractProjectCandidatesWithPositions, h as collectClassesFromTailwindV4, i as MIGRATION_REPORT_SCHEMA_VERSION, j as createTailwindV4SourceEntryMatcher, k as createTailwindV4DefaultIgnoreSources, l as tailwindcssPatchCommands, m as collectClassesFromContexts, n as restoreConfigFiles, o as VALIDATE_FAILURE_REASONS, p as loadRuntimeContexts, q as replaceBareArbitraryValueSelectors, r as MIGRATION_REPORT_KIND, s as ValidateCommandError, t as migrateConfigFiles, u as TailwindcssPatcher, v as extractRawCandidatesWithPositions, w as TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, x as extractValidCandidates, y as extractSourceCandidates, z as normalizeTailwindV4SourceEntries } from "./migrate-config-DqknZpUe.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import path from "pathe";
|
|
5
|
+
import { promises } from "node:fs";
|
|
6
|
+
//#region src/extraction/split-candidate-tokens.ts
|
|
7
|
+
const validateCandidateTokenRE = /[\w\u00A0-\uFFFF%-?]/;
|
|
8
|
+
function isValidCandidateToken(token = "") {
|
|
9
|
+
return validateCandidateTokenRE.test(token);
|
|
10
|
+
}
|
|
11
|
+
const SPLIT_CACHE_LIMIT = 8192;
|
|
12
|
+
const ESCAPED_WHITESPACE_RE = /\\[nrt]/g;
|
|
13
|
+
const splitCache = /* @__PURE__ */ new Map();
|
|
14
|
+
function isSplitter(char, bracketDepth) {
|
|
15
|
+
return bracketDepth === 0 && (char === "\"" || /\s/.test(char));
|
|
16
|
+
}
|
|
17
|
+
function hasClosingQuotedArbitraryValue(code, start, quote) {
|
|
18
|
+
for (let index = start; index < code.length; index++) {
|
|
19
|
+
if (code[index] === "\\") {
|
|
20
|
+
index++;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (code[index] === quote) return code.includes("]", index + 1);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
function splitBracketAware(code) {
|
|
28
|
+
const result = [];
|
|
29
|
+
let bracketDepth = 0;
|
|
30
|
+
let bracketQuote;
|
|
31
|
+
let start = 0;
|
|
32
|
+
for (let index = 0; index < code.length; index++) {
|
|
33
|
+
const char = code[index];
|
|
34
|
+
if (char === void 0) continue;
|
|
35
|
+
if (bracketDepth > 0 && char === "\\") {
|
|
36
|
+
index++;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (bracketDepth > 0 && (char === "\"" || char === "'")) {
|
|
40
|
+
if (bracketQuote === char) bracketQuote = void 0;
|
|
41
|
+
else if (bracketQuote === void 0 && hasClosingQuotedArbitraryValue(code, index + 1, char)) bracketQuote = char;
|
|
42
|
+
}
|
|
43
|
+
if (bracketQuote === void 0) {
|
|
44
|
+
if (char === "[" && code.includes("]", index + 1)) bracketDepth++;
|
|
45
|
+
else if (char === "]" && bracketDepth > 0) bracketDepth--;
|
|
46
|
+
}
|
|
47
|
+
if (!isSplitter(char, bracketDepth)) continue;
|
|
48
|
+
const candidate = code.slice(start, index);
|
|
49
|
+
if (isValidCandidateToken(candidate)) result.push(candidate);
|
|
50
|
+
start = index + 1;
|
|
51
|
+
}
|
|
52
|
+
const candidate = code.slice(start);
|
|
53
|
+
if (isValidCandidateToken(candidate)) result.push(candidate);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function splitCandidateTokens(code) {
|
|
57
|
+
const cached = splitCache.get(code);
|
|
58
|
+
if (cached) return cached;
|
|
59
|
+
const result = splitBracketAware(code.includes("\\") ? code.replace(ESCAPED_WHITESPACE_RE, " ") : code);
|
|
60
|
+
if (splitCache.size >= SPLIT_CACHE_LIMIT) splitCache.clear();
|
|
61
|
+
splitCache.set(code, result);
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/v4/engine.ts
|
|
66
|
+
function resolveScanSources(options, source, compiledRoot, compiledSources) {
|
|
67
|
+
if (Array.isArray(options?.scanSources)) return options.scanSources;
|
|
68
|
+
if (options?.scanSources === true) return createTailwindV4CompiledSourceEntries(compiledRoot, compiledSources, source.base);
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
async function collectRawCandidates(source, options, compiledRoot, compiledSources = []) {
|
|
72
|
+
const rawCandidates = /* @__PURE__ */ new Set();
|
|
73
|
+
for (const candidate of options?.candidates ?? []) rawCandidates.add(candidate);
|
|
74
|
+
for (const candidateSource of options?.sources ?? []) {
|
|
75
|
+
const candidates = await extractRawCandidatesWithPositions(candidateSource.content, candidateSource.extension);
|
|
76
|
+
for (const candidate of candidates) rawCandidates.add(candidate.rawCandidate);
|
|
77
|
+
}
|
|
78
|
+
const filesystemSources = resolveScanSources(options, source, compiledRoot, compiledSources);
|
|
79
|
+
if (filesystemSources.length > 0) for (const candidate of await extractRawCandidates(filesystemSources)) rawCandidates.add(candidate);
|
|
80
|
+
const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
|
|
81
|
+
for (const candidate of inlineSources.included) rawCandidates.add(candidate);
|
|
82
|
+
for (const candidate of inlineSources.excluded) rawCandidates.delete(candidate);
|
|
83
|
+
return rawCandidates;
|
|
84
|
+
}
|
|
85
|
+
function createTailwindV4Engine(source) {
|
|
86
|
+
return {
|
|
87
|
+
source,
|
|
88
|
+
loadDesignSystem() {
|
|
89
|
+
return loadTailwindV4DesignSystem(source);
|
|
90
|
+
},
|
|
91
|
+
async validateCandidates(candidates) {
|
|
92
|
+
return resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), candidates);
|
|
93
|
+
},
|
|
94
|
+
async generate(options) {
|
|
95
|
+
const { compiled, dependencies } = await compileTailwindV4Source(source);
|
|
96
|
+
const rawCandidates = await collectRawCandidates(source, options, compiled.root, compiled.sources);
|
|
97
|
+
const classSet = resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), rawCandidates, { ...options?.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
|
|
98
|
+
const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
|
|
99
|
+
for (const candidate of inlineSources.excluded) classSet.delete(candidate);
|
|
100
|
+
const buildCandidates = canonicalizeBareArbitraryValueCandidates(classSet, options?.bareArbitraryValues);
|
|
101
|
+
return {
|
|
102
|
+
css: replaceBareArbitraryValueSelectors(compiled.build(buildCandidates), classSet, options?.bareArbitraryValues),
|
|
103
|
+
classSet,
|
|
104
|
+
rawCandidates,
|
|
105
|
+
dependencies: Array.from(dependencies),
|
|
106
|
+
sources: compiled.sources,
|
|
107
|
+
root: compiled.root
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region src/v4/source.ts
|
|
114
|
+
function resolveBase(value, fallback) {
|
|
115
|
+
return value === void 0 ? fallback : path.isAbsolute(value) ? path.resolve(value) : path.resolve(fallback, value);
|
|
116
|
+
}
|
|
117
|
+
function uniquePaths(values) {
|
|
118
|
+
const result = [];
|
|
119
|
+
for (const value of values) {
|
|
120
|
+
if (!value) continue;
|
|
121
|
+
const resolved = path.resolve(value);
|
|
122
|
+
if (!result.includes(resolved)) result.push(resolved);
|
|
123
|
+
}
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function toCssImportPath(value) {
|
|
127
|
+
return value.replaceAll("\\", "/");
|
|
128
|
+
}
|
|
129
|
+
function quoteCssImport(value) {
|
|
130
|
+
return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
|
|
131
|
+
}
|
|
132
|
+
function isPostcssPluginSpecifier(packageName) {
|
|
133
|
+
return packageName === "@tailwindcss/postcss" || /(?:^|[/\\])@tailwindcss[/\\]postcss(?:[/\\]|$)/.test(packageName) || /(?:^|[/\\])postcss(?:[/\\]|$)/i.test(packageName) || /postcss\.config\.[cm]?[jt]s$/i.test(packageName);
|
|
134
|
+
}
|
|
135
|
+
function createDefaultCss(packageName) {
|
|
136
|
+
return `@import "${quoteCssImport(toCssImportPath(packageName && !isPostcssPluginSpecifier(packageName) ? packageName : "tailwindcss"))}";`;
|
|
137
|
+
}
|
|
138
|
+
async function pathExists(filePath) {
|
|
139
|
+
try {
|
|
140
|
+
await promises.access(filePath);
|
|
141
|
+
return true;
|
|
142
|
+
} catch {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async function resolveCssEntries(entries, projectRoot, base) {
|
|
147
|
+
const resolvedEntries = entries.map((entry) => ({
|
|
148
|
+
original: entry,
|
|
149
|
+
absolute: path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(projectRoot, entry)
|
|
150
|
+
}));
|
|
151
|
+
const resolvedBase = base ?? path.dirname(resolvedEntries[0]?.absolute ?? projectRoot);
|
|
152
|
+
const dependencies = resolvedEntries.map((entry) => entry.absolute);
|
|
153
|
+
const cssParts = [];
|
|
154
|
+
for (const entry of resolvedEntries) {
|
|
155
|
+
if (await pathExists(entry.absolute)) {
|
|
156
|
+
cssParts.push(await promises.readFile(entry.absolute, "utf8"));
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
const importPath = path.isAbsolute(entry.original) ? entry.absolute : path.relative(resolvedBase, entry.absolute);
|
|
160
|
+
cssParts.push(`@import "${quoteCssImport(toCssImportPath(importPath))}";`);
|
|
161
|
+
}
|
|
162
|
+
return {
|
|
163
|
+
base: resolvedBase,
|
|
164
|
+
css: cssParts.join("\n"),
|
|
165
|
+
dependencies
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function resolveCssSources(sources, projectRoot, base) {
|
|
169
|
+
const resolvedSources = sources.map((source) => ({
|
|
170
|
+
...source,
|
|
171
|
+
base: source.base === void 0 ? void 0 : resolveBase(source.base, projectRoot),
|
|
172
|
+
file: source.file === void 0 ? void 0 : path.isAbsolute(source.file) ? path.resolve(source.file) : path.resolve(projectRoot, source.file),
|
|
173
|
+
dependencies: source.dependencies?.map((dependency) => path.isAbsolute(dependency) ? path.resolve(dependency) : path.resolve(projectRoot, dependency)) ?? []
|
|
174
|
+
}));
|
|
175
|
+
const firstSource = resolvedSources[0];
|
|
176
|
+
const resolvedBase = base ?? firstSource?.base ?? (firstSource?.file ? path.dirname(firstSource.file) : projectRoot);
|
|
177
|
+
const dependencies = resolvedSources.flatMap((source) => [source.file, ...source.dependencies]).filter((dependency) => Boolean(dependency));
|
|
178
|
+
return {
|
|
179
|
+
base: resolvedBase,
|
|
180
|
+
css: resolvedSources.map((source) => source.css).join("\n"),
|
|
181
|
+
dependencies
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function normalizeResolvedSource(source) {
|
|
185
|
+
const baseFallbacks = uniquePaths([
|
|
186
|
+
...source.baseFallbacks,
|
|
187
|
+
source.projectRoot,
|
|
188
|
+
source.cwd
|
|
189
|
+
]).filter((base) => base !== source.base);
|
|
190
|
+
return {
|
|
191
|
+
projectRoot: source.projectRoot,
|
|
192
|
+
base: source.base,
|
|
193
|
+
baseFallbacks,
|
|
194
|
+
css: source.css,
|
|
195
|
+
dependencies: Array.from(new Set(source.dependencies.map((dependency) => path.resolve(dependency))))
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
async function resolveTailwindV4Source(options = {}) {
|
|
199
|
+
const projectRoot = resolveBase(options.projectRoot, process.cwd());
|
|
200
|
+
const cwd = resolveBase(options.cwd, projectRoot);
|
|
201
|
+
const configuredBase = options.base === void 0 ? void 0 : resolveBase(options.base, projectRoot);
|
|
202
|
+
const baseFallbacks = uniquePaths(options.baseFallbacks?.map((base) => resolveBase(base, projectRoot)) ?? []);
|
|
203
|
+
if (options.css !== void 0) return normalizeResolvedSource({
|
|
204
|
+
projectRoot,
|
|
205
|
+
cwd,
|
|
206
|
+
base: configuredBase ?? cwd,
|
|
207
|
+
baseFallbacks,
|
|
208
|
+
css: options.css,
|
|
209
|
+
dependencies: []
|
|
210
|
+
});
|
|
211
|
+
if (options.cssEntries?.length || options.cssSources?.length) {
|
|
212
|
+
const entries = options.cssEntries?.length ? await resolveCssEntries(options.cssEntries, projectRoot, configuredBase) : void 0;
|
|
213
|
+
const sources = options.cssSources?.length ? resolveCssSources(options.cssSources, projectRoot, configuredBase) : void 0;
|
|
214
|
+
const css = [entries?.css, sources?.css].filter(Boolean).join("\n");
|
|
215
|
+
return normalizeResolvedSource({
|
|
216
|
+
projectRoot,
|
|
217
|
+
cwd,
|
|
218
|
+
base: configuredBase ?? entries?.base ?? sources?.base ?? cwd,
|
|
219
|
+
baseFallbacks,
|
|
220
|
+
css,
|
|
221
|
+
dependencies: [...entries?.dependencies ?? [], ...sources?.dependencies ?? []]
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
return normalizeResolvedSource({
|
|
225
|
+
projectRoot,
|
|
226
|
+
cwd,
|
|
227
|
+
base: configuredBase ?? cwd,
|
|
228
|
+
baseFallbacks,
|
|
229
|
+
css: createDefaultCss(options.packageName),
|
|
230
|
+
dependencies: []
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function resolveConfigDir(config, projectRoot) {
|
|
234
|
+
if (!config) return;
|
|
235
|
+
const configPath = path.isAbsolute(config) ? config : path.resolve(projectRoot, config);
|
|
236
|
+
return path.dirname(configPath);
|
|
237
|
+
}
|
|
238
|
+
function createSourceOptionsFromNormalizedPatchOptions(options) {
|
|
239
|
+
const v4 = options.tailwind.v4;
|
|
240
|
+
const configDir = resolveConfigDir(options.tailwind.config, options.projectRoot);
|
|
241
|
+
const baseFallbacks = uniquePaths([
|
|
242
|
+
v4?.configuredBase,
|
|
243
|
+
options.tailwind.cwd,
|
|
244
|
+
options.projectRoot,
|
|
245
|
+
configDir
|
|
246
|
+
]);
|
|
247
|
+
return {
|
|
248
|
+
projectRoot: options.projectRoot,
|
|
249
|
+
...options.tailwind.cwd === void 0 ? {} : { cwd: options.tailwind.cwd },
|
|
250
|
+
...v4?.configuredBase === void 0 ? {} : { base: v4.configuredBase },
|
|
251
|
+
baseFallbacks,
|
|
252
|
+
...v4?.css === void 0 ? {} : { css: v4.css },
|
|
253
|
+
...v4?.cssSources === void 0 ? {} : { cssSources: v4.cssSources },
|
|
254
|
+
...v4?.cssEntries === void 0 ? {} : { cssEntries: v4.cssEntries },
|
|
255
|
+
packageName: options.tailwind.packageName
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
function tailwindV4SourceOptionsFromPatchOptions(options) {
|
|
259
|
+
return createSourceOptionsFromNormalizedPatchOptions(normalizeOptions(options));
|
|
260
|
+
}
|
|
261
|
+
async function resolveTailwindV4SourceFromPatchOptions(options) {
|
|
262
|
+
return resolveTailwindV4Source(tailwindV4SourceOptionsFromPatchOptions(options));
|
|
263
|
+
}
|
|
264
|
+
//#endregion
|
|
265
|
+
//#region src/public-api.ts
|
|
266
|
+
function defineConfig(config) {
|
|
267
|
+
return config;
|
|
268
|
+
}
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/index.bundle.ts
|
|
271
|
+
const require = createRequire(import.meta.url);
|
|
272
|
+
function loadCliModule() {
|
|
273
|
+
return require("./commands/cli-runtime.js");
|
|
274
|
+
}
|
|
275
|
+
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
276
|
+
return loadCliModule().mountTailwindcssPatchCommands(cli, options);
|
|
277
|
+
}
|
|
278
|
+
function createTailwindcssPatchCli(options = {}) {
|
|
279
|
+
return loadCliModule().createTailwindcssPatchCli(options);
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
282
|
+
export { CacheStore, MIGRATION_REPORT_KIND, MIGRATION_REPORT_SCHEMA_VERSION, TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, TAILWIND_V4_IGNORED_CONTENT_DIRS, TAILWIND_V4_IGNORED_EXTENSIONS, TAILWIND_V4_IGNORED_FILES, TailwindcssPatcher, VALIDATE_EXIT_CODES, VALIDATE_FAILURE_REASONS, ValidateCommandError, collectClassesFromContexts, collectClassesFromTailwindV4, createTailwindV4CompiledSourceEntries, createTailwindV4DefaultIgnoreSources, createTailwindV4Engine, createTailwindV4RootSources, createTailwindV4SourceEntryMatcher, createTailwindV4SourceExclusionMatcher, createTailwindcssPatchCli, defineConfig, expandTailwindV4SourceEntries, expandTailwindV4SourceEntryBraces, extractProjectCandidatesWithPositions, extractRawCandidates, extractRawCandidatesWithPositions, extractSourceCandidates, extractSourceCandidatesWithPositions, extractValidCandidates, getPatchStatusReport, groupTokensByFile, isFileExcludedByTailwindV4SourceEntries, isFileMatchedByTailwindV4SourceEntries, isValidCandidateToken, loadRuntimeContexts, loadTailwindV4DesignSystem, logger, mergeTailwindV4SourceEntries, migrateConfigFiles, mountTailwindcssPatchCommands, normalizeOptions, normalizeTailwindV4ScannerSources, normalizeTailwindV4SourceEntries, resolveProjectSourceFiles, resolveSourceScanPath, resolveTailwindV4Source, resolveTailwindV4SourceBaseCandidates, resolveTailwindV4SourceEntry, resolveTailwindV4SourceFromPatchOptions, resolveValidTailwindV4Candidates, restoreConfigFiles, runTailwindBuild, splitCandidateTokens, tailwindcssPatchCommands, validateCandidateTokenRE };
|