tailwindcss-patch 9.4.0 → 9.4.2

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.
@@ -1,221 +0,0 @@
1
- import { A as resolveValidTailwindV4Candidates, D as canonicalizeBareArbitraryValueCandidates, E as loadTailwindV4DesignSystem, N as normalizeOptions, O as extractTailwindV4InlineSourceCandidates, T as compileTailwindV4Source, _ as extractRawCandidates, k as replaceBareArbitraryValueSelectors, v as extractRawCandidatesWithPositions, w as createTailwindV4CompiledSourceEntries } from "./validate-Ci0W2Fuu.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/v4/engine.ts
7
- function resolveScanSources(options, source, compiledRoot, compiledSources) {
8
- if (Array.isArray(options?.scanSources)) return options.scanSources;
9
- if (options?.scanSources === true) return createTailwindV4CompiledSourceEntries(compiledRoot, compiledSources, source.base);
10
- return [];
11
- }
12
- async function collectRawCandidates(source, options, compiledRoot, compiledSources = []) {
13
- const rawCandidates = /* @__PURE__ */ new Set();
14
- for (const candidate of options?.candidates ?? []) rawCandidates.add(candidate);
15
- for (const candidateSource of options?.sources ?? []) {
16
- const candidates = await extractRawCandidatesWithPositions(candidateSource.content, candidateSource.extension);
17
- for (const candidate of candidates) rawCandidates.add(candidate.rawCandidate);
18
- }
19
- const filesystemSources = resolveScanSources(options, source, compiledRoot, compiledSources);
20
- if (filesystemSources.length > 0) for (const candidate of await extractRawCandidates(filesystemSources)) rawCandidates.add(candidate);
21
- const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
22
- for (const candidate of inlineSources.included) rawCandidates.add(candidate);
23
- for (const candidate of inlineSources.excluded) rawCandidates.delete(candidate);
24
- return rawCandidates;
25
- }
26
- function createTailwindV4Engine(source) {
27
- return {
28
- source,
29
- loadDesignSystem() {
30
- return loadTailwindV4DesignSystem(source);
31
- },
32
- async validateCandidates(candidates) {
33
- return resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), candidates);
34
- },
35
- async generate(options) {
36
- const { compiled, dependencies } = await compileTailwindV4Source(source);
37
- const rawCandidates = await collectRawCandidates(source, options, compiled.root, compiled.sources);
38
- const classSet = resolveValidTailwindV4Candidates(await loadTailwindV4DesignSystem(source), rawCandidates, { ...options?.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
39
- const inlineSources = extractTailwindV4InlineSourceCandidates(source.css);
40
- for (const candidate of inlineSources.excluded) classSet.delete(candidate);
41
- const buildCandidates = canonicalizeBareArbitraryValueCandidates(classSet, options?.bareArbitraryValues);
42
- return {
43
- css: replaceBareArbitraryValueSelectors(compiled.build(buildCandidates), classSet, options?.bareArbitraryValues),
44
- classSet,
45
- rawCandidates,
46
- dependencies: Array.from(dependencies),
47
- sources: compiled.sources,
48
- root: compiled.root
49
- };
50
- }
51
- };
52
- }
53
- //#endregion
54
- //#region src/v4/source.ts
55
- function resolveBase(value, fallback) {
56
- return value === void 0 ? fallback : path.isAbsolute(value) ? path.resolve(value) : path.resolve(fallback, value);
57
- }
58
- function uniquePaths(values) {
59
- const result = [];
60
- for (const value of values) {
61
- if (!value) continue;
62
- const resolved = path.resolve(value);
63
- if (!result.includes(resolved)) result.push(resolved);
64
- }
65
- return result;
66
- }
67
- function toCssImportPath(value) {
68
- return value.replaceAll("\\", "/");
69
- }
70
- function quoteCssImport(value) {
71
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
72
- }
73
- function isPostcssPluginSpecifier(packageName) {
74
- return packageName === "@tailwindcss/postcss" || /(?:^|[/\\])@tailwindcss[/\\]postcss(?:[/\\]|$)/.test(packageName) || /(?:^|[/\\])postcss(?:[/\\]|$)/i.test(packageName) || /postcss\.config\.[cm]?[jt]s$/i.test(packageName);
75
- }
76
- function createDefaultCss(packageName) {
77
- return `@import "${quoteCssImport(toCssImportPath(packageName && !isPostcssPluginSpecifier(packageName) ? packageName : "tailwindcss"))}";`;
78
- }
79
- async function pathExists(filePath) {
80
- try {
81
- await promises.access(filePath);
82
- return true;
83
- } catch {
84
- return false;
85
- }
86
- }
87
- async function resolveCssEntries(entries, projectRoot, base) {
88
- const resolvedEntries = entries.map((entry) => ({
89
- original: entry,
90
- absolute: path.isAbsolute(entry) ? path.resolve(entry) : path.resolve(projectRoot, entry)
91
- }));
92
- const resolvedBase = base ?? path.dirname(resolvedEntries[0]?.absolute ?? projectRoot);
93
- const dependencies = resolvedEntries.map((entry) => entry.absolute);
94
- const cssParts = [];
95
- for (const entry of resolvedEntries) {
96
- if (await pathExists(entry.absolute)) {
97
- cssParts.push(await promises.readFile(entry.absolute, "utf8"));
98
- continue;
99
- }
100
- const importPath = path.isAbsolute(entry.original) ? entry.absolute : path.relative(resolvedBase, entry.absolute);
101
- cssParts.push(`@import "${quoteCssImport(toCssImportPath(importPath))}";`);
102
- }
103
- return {
104
- base: resolvedBase,
105
- css: cssParts.join("\n"),
106
- dependencies
107
- };
108
- }
109
- function resolveCssSources(sources, projectRoot, base) {
110
- const resolvedSources = sources.map((source) => ({
111
- ...source,
112
- base: source.base === void 0 ? void 0 : resolveBase(source.base, projectRoot),
113
- file: source.file === void 0 ? void 0 : path.isAbsolute(source.file) ? path.resolve(source.file) : path.resolve(projectRoot, source.file),
114
- dependencies: source.dependencies?.map((dependency) => path.isAbsolute(dependency) ? path.resolve(dependency) : path.resolve(projectRoot, dependency)) ?? []
115
- }));
116
- const firstSource = resolvedSources[0];
117
- const resolvedBase = base ?? firstSource?.base ?? (firstSource?.file ? path.dirname(firstSource.file) : projectRoot);
118
- const dependencies = resolvedSources.flatMap((source) => [source.file, ...source.dependencies]).filter((dependency) => Boolean(dependency));
119
- return {
120
- base: resolvedBase,
121
- css: resolvedSources.map((source) => source.css).join("\n"),
122
- dependencies
123
- };
124
- }
125
- function normalizeResolvedSource(source) {
126
- const baseFallbacks = uniquePaths([
127
- ...source.baseFallbacks,
128
- source.projectRoot,
129
- source.cwd
130
- ]).filter((base) => base !== source.base);
131
- return {
132
- projectRoot: source.projectRoot,
133
- base: source.base,
134
- baseFallbacks,
135
- css: source.css,
136
- dependencies: Array.from(new Set(source.dependencies.map((dependency) => path.resolve(dependency))))
137
- };
138
- }
139
- async function resolveTailwindV4Source(options = {}) {
140
- const projectRoot = resolveBase(options.projectRoot, process.cwd());
141
- const cwd = resolveBase(options.cwd, projectRoot);
142
- const configuredBase = options.base === void 0 ? void 0 : resolveBase(options.base, projectRoot);
143
- const baseFallbacks = uniquePaths(options.baseFallbacks?.map((base) => resolveBase(base, projectRoot)) ?? []);
144
- if (options.css !== void 0) return normalizeResolvedSource({
145
- projectRoot,
146
- cwd,
147
- base: configuredBase ?? cwd,
148
- baseFallbacks,
149
- css: options.css,
150
- dependencies: []
151
- });
152
- if (options.cssEntries?.length || options.cssSources?.length) {
153
- const entries = options.cssEntries?.length ? await resolveCssEntries(options.cssEntries, projectRoot, configuredBase) : void 0;
154
- const sources = options.cssSources?.length ? resolveCssSources(options.cssSources, projectRoot, configuredBase) : void 0;
155
- const css = [entries?.css, sources?.css].filter(Boolean).join("\n");
156
- return normalizeResolvedSource({
157
- projectRoot,
158
- cwd,
159
- base: configuredBase ?? entries?.base ?? sources?.base ?? cwd,
160
- baseFallbacks,
161
- css,
162
- dependencies: [...entries?.dependencies ?? [], ...sources?.dependencies ?? []]
163
- });
164
- }
165
- return normalizeResolvedSource({
166
- projectRoot,
167
- cwd,
168
- base: configuredBase ?? cwd,
169
- baseFallbacks,
170
- css: createDefaultCss(options.packageName),
171
- dependencies: []
172
- });
173
- }
174
- function resolveConfigDir(config, projectRoot) {
175
- if (!config) return;
176
- const configPath = path.isAbsolute(config) ? config : path.resolve(projectRoot, config);
177
- return path.dirname(configPath);
178
- }
179
- function createSourceOptionsFromNormalizedPatchOptions(options) {
180
- const v4 = options.tailwind.v4;
181
- const configDir = resolveConfigDir(options.tailwind.config, options.projectRoot);
182
- const baseFallbacks = uniquePaths([
183
- v4?.configuredBase,
184
- options.tailwind.cwd,
185
- options.projectRoot,
186
- configDir
187
- ]);
188
- return {
189
- projectRoot: options.projectRoot,
190
- ...options.tailwind.cwd === void 0 ? {} : { cwd: options.tailwind.cwd },
191
- ...v4?.configuredBase === void 0 ? {} : { base: v4.configuredBase },
192
- baseFallbacks,
193
- ...v4?.css === void 0 ? {} : { css: v4.css },
194
- ...v4?.cssSources === void 0 ? {} : { cssSources: v4.cssSources },
195
- ...v4?.cssEntries === void 0 ? {} : { cssEntries: v4.cssEntries },
196
- packageName: options.tailwind.packageName
197
- };
198
- }
199
- function tailwindV4SourceOptionsFromPatchOptions(options) {
200
- return createSourceOptionsFromNormalizedPatchOptions(normalizeOptions(options));
201
- }
202
- async function resolveTailwindV4SourceFromPatchOptions(options) {
203
- return resolveTailwindV4Source(tailwindV4SourceOptionsFromPatchOptions(options));
204
- }
205
- //#endregion
206
- //#region src/index.bundle.ts
207
- const require = createRequire(import.meta.url);
208
- function loadCliModule() {
209
- return require("./commands/cli-runtime.js");
210
- }
211
- function mountTailwindcssPatchCommands(cli, options = {}) {
212
- return loadCliModule().mountTailwindcssPatchCommands(cli, options);
213
- }
214
- function createTailwindcssPatchCli(options = {}) {
215
- return loadCliModule().createTailwindcssPatchCli(options);
216
- }
217
- function defineConfig(config) {
218
- return config;
219
- }
220
- //#endregion
221
- export { resolveTailwindV4SourceFromPatchOptions as a, resolveTailwindV4Source as i, defineConfig as n, createTailwindV4Engine as o, mountTailwindcssPatchCommands as r, createTailwindcssPatchCli as t };
package/src/cli.bundle.ts DELETED
@@ -1,20 +0,0 @@
1
- import process from 'node:process'
2
- import { createTailwindcssPatchCli, ValidateCommandError } from './index.bundle'
3
- import logger from './logger'
4
-
5
- async function main() {
6
- const cli = createTailwindcssPatchCli()
7
- cli.help()
8
- cli.parse(process.argv, { run: false })
9
- await cli.runMatchedCommand()
10
- }
11
-
12
- main().catch((error) => {
13
- if (error instanceof ValidateCommandError) {
14
- process.exitCode = error.exitCode
15
- return
16
- }
17
- const message = error instanceof Error ? error.message : String(error)
18
- logger.error(message)
19
- process.exitCode = 1
20
- })