tailwindcss-patch 9.4.0 → 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/src/index.ts CHANGED
@@ -1,104 +1,5 @@
1
- import type { TailwindcssMangleConfig } from '@tailwindcss-mangle/config'
2
-
3
- export { TailwindcssPatcher } from './api/tailwindcss-patcher'
4
- export { CacheStore } from './cache/store'
5
1
  export {
6
2
  createTailwindcssPatchCli,
7
3
  mountTailwindcssPatchCommands,
8
- type TailwindcssPatchCliMountOptions,
9
- type TailwindcssPatchCliOptions,
10
- type TailwindcssPatchCommand,
11
- type TailwindcssPatchCommandContext,
12
- type TailwindcssPatchCommandHandler,
13
- type TailwindcssPatchCommandHandlerMap,
14
- type TailwindcssPatchCommandOptionDefinition,
15
- type TailwindcssPatchCommandOptions,
16
- tailwindcssPatchCommands,
17
- VALIDATE_EXIT_CODES,
18
- VALIDATE_FAILURE_REASONS,
19
- ValidateCommandError,
20
- type ValidateFailureReason,
21
- type ValidateFailureSummary,
22
- type ValidateJsonFailurePayload,
23
- type ValidateJsonSuccessPayload,
24
4
  } from './commands/cli'
25
- export {
26
- type ConfigFileMigrationEntry,
27
- type ConfigFileMigrationReport,
28
- migrateConfigFiles,
29
- type MigrateConfigFilesOptions,
30
- MIGRATION_REPORT_KIND,
31
- MIGRATION_REPORT_SCHEMA_VERSION,
32
- restoreConfigFiles,
33
- type RestoreConfigFilesOptions,
34
- type RestoreConfigFilesResult,
35
- } from './commands/migrate-config'
36
- export { normalizeOptions } from './config'
37
- export type { TailwindCssPatchOptions } from './config'
38
- export {
39
- extractProjectCandidatesWithPositions,
40
- extractRawCandidates,
41
- extractRawCandidatesWithPositions,
42
- extractSourceCandidates,
43
- extractSourceCandidatesWithPositions,
44
- extractValidCandidates,
45
- groupTokensByFile,
46
- resolveProjectSourceFiles,
47
- type ExtractSourceCandidate,
48
- } from './extraction/candidate-extractor'
49
- export {
50
- isValidCandidateToken,
51
- splitCandidateTokens,
52
- validateCandidateTokenRE,
53
- } from './extraction/split-candidate-tokens'
54
- export {
55
- collectClassesFromContexts,
56
- collectClassesFromTailwindV4,
57
- getPatchStatusReport,
58
- loadRuntimeContexts,
59
- runTailwindBuild,
60
- } from './install'
61
- export { default as logger } from './logger'
62
- export * from './types'
63
- export {
64
- createTailwindV4CompiledSourceEntries,
65
- createTailwindV4Engine,
66
- createTailwindV4DefaultIgnoreSources,
67
- createTailwindV4RootSources,
68
- createTailwindV4SourceEntryMatcher,
69
- createTailwindV4SourceExclusionMatcher,
70
- expandTailwindV4SourceEntries,
71
- expandTailwindV4SourceEntryBraces,
72
- isFileExcludedByTailwindV4SourceEntries,
73
- isFileMatchedByTailwindV4SourceEntries,
74
- loadTailwindV4DesignSystem,
75
- mergeTailwindV4SourceEntries,
76
- normalizeTailwindV4ScannerSources,
77
- normalizeTailwindV4SourceEntries,
78
- resolveSourceScanPath,
79
- resolveTailwindV4Source,
80
- resolveTailwindV4SourceBaseCandidates,
81
- resolveTailwindV4SourceEntry,
82
- resolveTailwindV4SourceFromPatchOptions,
83
- resolveValidTailwindV4Candidates,
84
- TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN,
85
- TAILWIND_V4_IGNORED_CONTENT_DIRS,
86
- TAILWIND_V4_IGNORED_EXTENSIONS,
87
- TAILWIND_V4_IGNORED_FILES,
88
- } from './v4'
89
- export type {
90
- TailwindV4CandidateSource,
91
- TailwindV4CompiledSourceRoot,
92
- TailwindV4CssSource,
93
- TailwindV4DesignSystem,
94
- TailwindV4Engine,
95
- TailwindV4GenerateOptions,
96
- TailwindV4GenerateResult,
97
- TailwindV4ResolvedSource,
98
- TailwindV4SourceOptions,
99
- TailwindV4SourcePattern,
100
- } from './v4'
101
-
102
- export function defineConfig<T extends TailwindcssMangleConfig>(config: T): T {
103
- return config
104
- }
5
+ export * from './public-api'
@@ -0,0 +1,104 @@
1
+ import type { TailwindcssMangleConfig } from '@tailwindcss-mangle/config'
2
+
3
+ export { TailwindcssPatcher } from './api/tailwindcss-patcher'
4
+ export { CacheStore } from './cache/store'
5
+ export {
6
+ type TailwindcssPatchCliMountOptions,
7
+ type TailwindcssPatchCliOptions,
8
+ type TailwindcssPatchCommand,
9
+ type TailwindcssPatchCommandContext,
10
+ type TailwindcssPatchCommandHandler,
11
+ type TailwindcssPatchCommandHandlerMap,
12
+ type TailwindcssPatchCommandOptionDefinition,
13
+ type TailwindcssPatchCommandOptions,
14
+ tailwindcssPatchCommands,
15
+ } from './commands/types'
16
+ export {
17
+ VALIDATE_EXIT_CODES,
18
+ VALIDATE_FAILURE_REASONS,
19
+ ValidateCommandError,
20
+ type ValidateFailureReason,
21
+ type ValidateFailureSummary,
22
+ type ValidateJsonFailurePayload,
23
+ type ValidateJsonSuccessPayload,
24
+ } from './commands/validate'
25
+ export {
26
+ type ConfigFileMigrationEntry,
27
+ type ConfigFileMigrationReport,
28
+ migrateConfigFiles,
29
+ type MigrateConfigFilesOptions,
30
+ MIGRATION_REPORT_KIND,
31
+ MIGRATION_REPORT_SCHEMA_VERSION,
32
+ restoreConfigFiles,
33
+ type RestoreConfigFilesOptions,
34
+ type RestoreConfigFilesResult,
35
+ } from './commands/migrate-config'
36
+ export { normalizeOptions } from './config'
37
+ export type { TailwindCssPatchOptions } from './config'
38
+ export {
39
+ extractProjectCandidatesWithPositions,
40
+ extractRawCandidates,
41
+ extractRawCandidatesWithPositions,
42
+ extractSourceCandidates,
43
+ extractSourceCandidatesWithPositions,
44
+ extractValidCandidates,
45
+ groupTokensByFile,
46
+ resolveProjectSourceFiles,
47
+ type ExtractSourceCandidate,
48
+ } from './extraction/candidate-extractor'
49
+ export {
50
+ isValidCandidateToken,
51
+ splitCandidateTokens,
52
+ validateCandidateTokenRE,
53
+ } from './extraction/split-candidate-tokens'
54
+ export {
55
+ collectClassesFromContexts,
56
+ collectClassesFromTailwindV4,
57
+ getPatchStatusReport,
58
+ loadRuntimeContexts,
59
+ runTailwindBuild,
60
+ } from './install'
61
+ export { default as logger } from './logger'
62
+ export * from './types'
63
+ export {
64
+ createTailwindV4CompiledSourceEntries,
65
+ createTailwindV4Engine,
66
+ createTailwindV4DefaultIgnoreSources,
67
+ createTailwindV4RootSources,
68
+ createTailwindV4SourceEntryMatcher,
69
+ createTailwindV4SourceExclusionMatcher,
70
+ expandTailwindV4SourceEntries,
71
+ expandTailwindV4SourceEntryBraces,
72
+ isFileExcludedByTailwindV4SourceEntries,
73
+ isFileMatchedByTailwindV4SourceEntries,
74
+ loadTailwindV4DesignSystem,
75
+ mergeTailwindV4SourceEntries,
76
+ normalizeTailwindV4ScannerSources,
77
+ normalizeTailwindV4SourceEntries,
78
+ resolveSourceScanPath,
79
+ resolveTailwindV4Source,
80
+ resolveTailwindV4SourceBaseCandidates,
81
+ resolveTailwindV4SourceEntry,
82
+ resolveTailwindV4SourceFromPatchOptions,
83
+ resolveValidTailwindV4Candidates,
84
+ TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN,
85
+ TAILWIND_V4_IGNORED_CONTENT_DIRS,
86
+ TAILWIND_V4_IGNORED_EXTENSIONS,
87
+ TAILWIND_V4_IGNORED_FILES,
88
+ } from './v4'
89
+ export type {
90
+ TailwindV4CandidateSource,
91
+ TailwindV4CompiledSourceRoot,
92
+ TailwindV4CssSource,
93
+ TailwindV4DesignSystem,
94
+ TailwindV4Engine,
95
+ TailwindV4GenerateOptions,
96
+ TailwindV4GenerateResult,
97
+ TailwindV4ResolvedSource,
98
+ TailwindV4SourceOptions,
99
+ TailwindV4SourcePattern,
100
+ } from './v4'
101
+
102
+ export function defineConfig<T extends TailwindcssMangleConfig>(config: T): T {
103
+ return config
104
+ }
@@ -1,259 +0,0 @@
1
- const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_validate = require("./validate-D9fDrE9I.js");
3
- let node_module = require("node:module");
4
- let node_process = require("node:process");
5
- node_process = require_chunk.__toESM(node_process);
6
- let pathe = require("pathe");
7
- pathe = require_chunk.__toESM(pathe);
8
- let node_fs = require("node:fs");
9
- //#region src/v4/engine.ts
10
- function resolveScanSources(options, source, compiledRoot, compiledSources) {
11
- if (Array.isArray(options?.scanSources)) return options.scanSources;
12
- if (options?.scanSources === true) return require_validate.createTailwindV4CompiledSourceEntries(compiledRoot, compiledSources, source.base);
13
- return [];
14
- }
15
- async function collectRawCandidates(source, options, compiledRoot, compiledSources = []) {
16
- const rawCandidates = /* @__PURE__ */ new Set();
17
- for (const candidate of options?.candidates ?? []) rawCandidates.add(candidate);
18
- for (const candidateSource of options?.sources ?? []) {
19
- const candidates = await require_validate.extractRawCandidatesWithPositions(candidateSource.content, candidateSource.extension);
20
- for (const candidate of candidates) rawCandidates.add(candidate.rawCandidate);
21
- }
22
- const filesystemSources = resolveScanSources(options, source, compiledRoot, compiledSources);
23
- if (filesystemSources.length > 0) for (const candidate of await require_validate.extractRawCandidates(filesystemSources)) rawCandidates.add(candidate);
24
- const inlineSources = require_validate.extractTailwindV4InlineSourceCandidates(source.css);
25
- for (const candidate of inlineSources.included) rawCandidates.add(candidate);
26
- for (const candidate of inlineSources.excluded) rawCandidates.delete(candidate);
27
- return rawCandidates;
28
- }
29
- function createTailwindV4Engine(source) {
30
- return {
31
- source,
32
- loadDesignSystem() {
33
- return require_validate.loadTailwindV4DesignSystem(source);
34
- },
35
- async validateCandidates(candidates) {
36
- return require_validate.resolveValidTailwindV4Candidates(await require_validate.loadTailwindV4DesignSystem(source), candidates);
37
- },
38
- async generate(options) {
39
- const { compiled, dependencies } = await require_validate.compileTailwindV4Source(source);
40
- const rawCandidates = await collectRawCandidates(source, options, compiled.root, compiled.sources);
41
- const classSet = require_validate.resolveValidTailwindV4Candidates(await require_validate.loadTailwindV4DesignSystem(source), rawCandidates, { ...options?.bareArbitraryValues === void 0 ? {} : { bareArbitraryValues: options.bareArbitraryValues } });
42
- const inlineSources = require_validate.extractTailwindV4InlineSourceCandidates(source.css);
43
- for (const candidate of inlineSources.excluded) classSet.delete(candidate);
44
- const buildCandidates = require_validate.canonicalizeBareArbitraryValueCandidates(classSet, options?.bareArbitraryValues);
45
- return {
46
- css: require_validate.replaceBareArbitraryValueSelectors(compiled.build(buildCandidates), classSet, options?.bareArbitraryValues),
47
- classSet,
48
- rawCandidates,
49
- dependencies: Array.from(dependencies),
50
- sources: compiled.sources,
51
- root: compiled.root
52
- };
53
- }
54
- };
55
- }
56
- //#endregion
57
- //#region src/v4/source.ts
58
- function resolveBase(value, fallback) {
59
- return value === void 0 ? fallback : pathe.default.isAbsolute(value) ? pathe.default.resolve(value) : pathe.default.resolve(fallback, value);
60
- }
61
- function uniquePaths(values) {
62
- const result = [];
63
- for (const value of values) {
64
- if (!value) continue;
65
- const resolved = pathe.default.resolve(value);
66
- if (!result.includes(resolved)) result.push(resolved);
67
- }
68
- return result;
69
- }
70
- function toCssImportPath(value) {
71
- return value.replaceAll("\\", "/");
72
- }
73
- function quoteCssImport(value) {
74
- return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
75
- }
76
- function isPostcssPluginSpecifier(packageName) {
77
- return packageName === "@tailwindcss/postcss" || /(?:^|[/\\])@tailwindcss[/\\]postcss(?:[/\\]|$)/.test(packageName) || /(?:^|[/\\])postcss(?:[/\\]|$)/i.test(packageName) || /postcss\.config\.[cm]?[jt]s$/i.test(packageName);
78
- }
79
- function createDefaultCss(packageName) {
80
- return `@import "${quoteCssImport(toCssImportPath(packageName && !isPostcssPluginSpecifier(packageName) ? packageName : "tailwindcss"))}";`;
81
- }
82
- async function pathExists(filePath) {
83
- try {
84
- await node_fs.promises.access(filePath);
85
- return true;
86
- } catch {
87
- return false;
88
- }
89
- }
90
- async function resolveCssEntries(entries, projectRoot, base) {
91
- const resolvedEntries = entries.map((entry) => ({
92
- original: entry,
93
- absolute: pathe.default.isAbsolute(entry) ? pathe.default.resolve(entry) : pathe.default.resolve(projectRoot, entry)
94
- }));
95
- const resolvedBase = base ?? pathe.default.dirname(resolvedEntries[0]?.absolute ?? projectRoot);
96
- const dependencies = resolvedEntries.map((entry) => entry.absolute);
97
- const cssParts = [];
98
- for (const entry of resolvedEntries) {
99
- if (await pathExists(entry.absolute)) {
100
- cssParts.push(await node_fs.promises.readFile(entry.absolute, "utf8"));
101
- continue;
102
- }
103
- const importPath = pathe.default.isAbsolute(entry.original) ? entry.absolute : pathe.default.relative(resolvedBase, entry.absolute);
104
- cssParts.push(`@import "${quoteCssImport(toCssImportPath(importPath))}";`);
105
- }
106
- return {
107
- base: resolvedBase,
108
- css: cssParts.join("\n"),
109
- dependencies
110
- };
111
- }
112
- function resolveCssSources(sources, projectRoot, base) {
113
- const resolvedSources = sources.map((source) => ({
114
- ...source,
115
- base: source.base === void 0 ? void 0 : resolveBase(source.base, projectRoot),
116
- file: source.file === void 0 ? void 0 : pathe.default.isAbsolute(source.file) ? pathe.default.resolve(source.file) : pathe.default.resolve(projectRoot, source.file),
117
- dependencies: source.dependencies?.map((dependency) => pathe.default.isAbsolute(dependency) ? pathe.default.resolve(dependency) : pathe.default.resolve(projectRoot, dependency)) ?? []
118
- }));
119
- const firstSource = resolvedSources[0];
120
- const resolvedBase = base ?? firstSource?.base ?? (firstSource?.file ? pathe.default.dirname(firstSource.file) : projectRoot);
121
- const dependencies = resolvedSources.flatMap((source) => [source.file, ...source.dependencies]).filter((dependency) => Boolean(dependency));
122
- return {
123
- base: resolvedBase,
124
- css: resolvedSources.map((source) => source.css).join("\n"),
125
- dependencies
126
- };
127
- }
128
- function normalizeResolvedSource(source) {
129
- const baseFallbacks = uniquePaths([
130
- ...source.baseFallbacks,
131
- source.projectRoot,
132
- source.cwd
133
- ]).filter((base) => base !== source.base);
134
- return {
135
- projectRoot: source.projectRoot,
136
- base: source.base,
137
- baseFallbacks,
138
- css: source.css,
139
- dependencies: Array.from(new Set(source.dependencies.map((dependency) => pathe.default.resolve(dependency))))
140
- };
141
- }
142
- async function resolveTailwindV4Source(options = {}) {
143
- const projectRoot = resolveBase(options.projectRoot, node_process.default.cwd());
144
- const cwd = resolveBase(options.cwd, projectRoot);
145
- const configuredBase = options.base === void 0 ? void 0 : resolveBase(options.base, projectRoot);
146
- const baseFallbacks = uniquePaths(options.baseFallbacks?.map((base) => resolveBase(base, projectRoot)) ?? []);
147
- if (options.css !== void 0) return normalizeResolvedSource({
148
- projectRoot,
149
- cwd,
150
- base: configuredBase ?? cwd,
151
- baseFallbacks,
152
- css: options.css,
153
- dependencies: []
154
- });
155
- if (options.cssEntries?.length || options.cssSources?.length) {
156
- const entries = options.cssEntries?.length ? await resolveCssEntries(options.cssEntries, projectRoot, configuredBase) : void 0;
157
- const sources = options.cssSources?.length ? resolveCssSources(options.cssSources, projectRoot, configuredBase) : void 0;
158
- const css = [entries?.css, sources?.css].filter(Boolean).join("\n");
159
- return normalizeResolvedSource({
160
- projectRoot,
161
- cwd,
162
- base: configuredBase ?? entries?.base ?? sources?.base ?? cwd,
163
- baseFallbacks,
164
- css,
165
- dependencies: [...entries?.dependencies ?? [], ...sources?.dependencies ?? []]
166
- });
167
- }
168
- return normalizeResolvedSource({
169
- projectRoot,
170
- cwd,
171
- base: configuredBase ?? cwd,
172
- baseFallbacks,
173
- css: createDefaultCss(options.packageName),
174
- dependencies: []
175
- });
176
- }
177
- function resolveConfigDir(config, projectRoot) {
178
- if (!config) return;
179
- const configPath = pathe.default.isAbsolute(config) ? config : pathe.default.resolve(projectRoot, config);
180
- return pathe.default.dirname(configPath);
181
- }
182
- function createSourceOptionsFromNormalizedPatchOptions(options) {
183
- const v4 = options.tailwind.v4;
184
- const configDir = resolveConfigDir(options.tailwind.config, options.projectRoot);
185
- const baseFallbacks = uniquePaths([
186
- v4?.configuredBase,
187
- options.tailwind.cwd,
188
- options.projectRoot,
189
- configDir
190
- ]);
191
- return {
192
- projectRoot: options.projectRoot,
193
- ...options.tailwind.cwd === void 0 ? {} : { cwd: options.tailwind.cwd },
194
- ...v4?.configuredBase === void 0 ? {} : { base: v4.configuredBase },
195
- baseFallbacks,
196
- ...v4?.css === void 0 ? {} : { css: v4.css },
197
- ...v4?.cssSources === void 0 ? {} : { cssSources: v4.cssSources },
198
- ...v4?.cssEntries === void 0 ? {} : { cssEntries: v4.cssEntries },
199
- packageName: options.tailwind.packageName
200
- };
201
- }
202
- function tailwindV4SourceOptionsFromPatchOptions(options) {
203
- return createSourceOptionsFromNormalizedPatchOptions(require_validate.normalizeOptions(options));
204
- }
205
- async function resolveTailwindV4SourceFromPatchOptions(options) {
206
- return resolveTailwindV4Source(tailwindV4SourceOptionsFromPatchOptions(options));
207
- }
208
- //#endregion
209
- //#region src/index.bundle.ts
210
- const require$1 = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
211
- function loadCliModule() {
212
- return require$1("./commands/cli-runtime.js");
213
- }
214
- function mountTailwindcssPatchCommands(cli, options = {}) {
215
- return loadCliModule().mountTailwindcssPatchCommands(cli, options);
216
- }
217
- function createTailwindcssPatchCli(options = {}) {
218
- return loadCliModule().createTailwindcssPatchCli(options);
219
- }
220
- function defineConfig(config) {
221
- return config;
222
- }
223
- //#endregion
224
- Object.defineProperty(exports, "createTailwindV4Engine", {
225
- enumerable: true,
226
- get: function() {
227
- return createTailwindV4Engine;
228
- }
229
- });
230
- Object.defineProperty(exports, "createTailwindcssPatchCli", {
231
- enumerable: true,
232
- get: function() {
233
- return createTailwindcssPatchCli;
234
- }
235
- });
236
- Object.defineProperty(exports, "defineConfig", {
237
- enumerable: true,
238
- get: function() {
239
- return defineConfig;
240
- }
241
- });
242
- Object.defineProperty(exports, "mountTailwindcssPatchCommands", {
243
- enumerable: true,
244
- get: function() {
245
- return mountTailwindcssPatchCommands;
246
- }
247
- });
248
- Object.defineProperty(exports, "resolveTailwindV4Source", {
249
- enumerable: true,
250
- get: function() {
251
- return resolveTailwindV4Source;
252
- }
253
- });
254
- Object.defineProperty(exports, "resolveTailwindV4SourceFromPatchOptions", {
255
- enumerable: true,
256
- get: function() {
257
- return resolveTailwindV4SourceFromPatchOptions;
258
- }
259
- });
@@ -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 };