tailwindcss-patch 3.0.2 → 3.1.0-alpha.0
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.cjs +7 -7
- package/dist/cli.mjs +7 -7
- package/dist/index.cjs +5 -6
- package/dist/index.d.cts +20 -16
- package/dist/index.d.mts +20 -16
- package/dist/index.d.ts +20 -16
- package/dist/index.mjs +3 -3
- package/dist/shared/{tailwindcss-patch.1e524aba.cjs → tailwindcss-patch.27719efb.cjs} +158 -85
- package/dist/shared/{tailwindcss-patch.9adeca36.mjs → tailwindcss-patch.ec6deb5e.mjs} +157 -82
- package/package.json +11 -9
package/dist/cli.cjs
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
const process = require('node:process');
|
|
4
4
|
const cac = require('cac');
|
|
5
5
|
const config = require('@tailwindcss-mangle/config');
|
|
6
|
-
const index = require('./shared/tailwindcss-patch.
|
|
7
|
-
require('@babel/types');
|
|
6
|
+
const index = require('./shared/tailwindcss-patch.27719efb.cjs');
|
|
8
7
|
require('node:path');
|
|
9
|
-
require('
|
|
10
|
-
require('
|
|
11
|
-
require('node:fs/promises');
|
|
8
|
+
require('fs-extra');
|
|
9
|
+
require('@babel/types');
|
|
12
10
|
require('resolve');
|
|
11
|
+
require('semver');
|
|
12
|
+
require('consola');
|
|
13
13
|
require('@babel/generator');
|
|
14
14
|
require('@babel/traverse');
|
|
15
15
|
require('@babel/parser');
|
|
@@ -35,14 +35,14 @@ cli.command("install", "patch install").action(() => {
|
|
|
35
35
|
});
|
|
36
36
|
cli.command("init").action(async () => {
|
|
37
37
|
await init();
|
|
38
|
-
|
|
38
|
+
index.logger.success(`\u2728 ${config.configName}.config.ts initialized!`);
|
|
39
39
|
});
|
|
40
40
|
cli.command("extract").action(async () => {
|
|
41
41
|
const { config: config$1 } = await config.getConfig();
|
|
42
42
|
if (config$1) {
|
|
43
43
|
const twPatcher = new index.TailwindcssPatcher();
|
|
44
44
|
const p = await twPatcher.extract(config$1.patch);
|
|
45
|
-
|
|
45
|
+
index.logger.success(`\u2728 tailwindcss-patch extract success! file path: ${p}`);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
cli.help();
|
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
2
|
import cac from 'cac';
|
|
3
3
|
import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
|
|
4
|
-
import { T as TailwindcssPatcher, g as getPatchOptions } from './shared/tailwindcss-patch.
|
|
5
|
-
import '@babel/types';
|
|
4
|
+
import { T as TailwindcssPatcher, g as getPatchOptions, l as logger } from './shared/tailwindcss-patch.ec6deb5e.mjs';
|
|
6
5
|
import 'node:path';
|
|
7
|
-
import '
|
|
8
|
-
import '
|
|
9
|
-
import 'node:fs/promises';
|
|
6
|
+
import 'fs-extra';
|
|
7
|
+
import '@babel/types';
|
|
10
8
|
import 'resolve';
|
|
9
|
+
import 'semver';
|
|
10
|
+
import 'consola';
|
|
11
11
|
import '@babel/generator';
|
|
12
12
|
import '@babel/traverse';
|
|
13
13
|
import '@babel/parser';
|
|
@@ -28,14 +28,14 @@ cli.command("install", "patch install").action(() => {
|
|
|
28
28
|
});
|
|
29
29
|
cli.command("init").action(async () => {
|
|
30
30
|
await init();
|
|
31
|
-
|
|
31
|
+
logger.success(`\u2728 ${configName}.config.ts initialized!`);
|
|
32
32
|
});
|
|
33
33
|
cli.command("extract").action(async () => {
|
|
34
34
|
const { config } = await getConfig();
|
|
35
35
|
if (config) {
|
|
36
36
|
const twPatcher = new TailwindcssPatcher();
|
|
37
37
|
const p = await twPatcher.extract(config.patch);
|
|
38
|
-
|
|
38
|
+
logger.success(`\u2728 tailwindcss-patch extract success! file path: ${p}`);
|
|
39
39
|
}
|
|
40
40
|
});
|
|
41
41
|
cli.help();
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const index = require('./shared/tailwindcss-patch.
|
|
3
|
+
const index = require('./shared/tailwindcss-patch.27719efb.cjs');
|
|
4
4
|
const config = require('@tailwindcss-mangle/config');
|
|
5
5
|
require('node:path');
|
|
6
|
-
require('
|
|
6
|
+
require('fs-extra');
|
|
7
7
|
require('node:process');
|
|
8
|
+
require('consola');
|
|
8
9
|
require('semver');
|
|
9
10
|
require('@babel/types');
|
|
10
11
|
require('@babel/generator');
|
|
11
12
|
require('@babel/traverse');
|
|
12
13
|
require('@babel/parser');
|
|
13
|
-
require('node:fs/promises');
|
|
14
14
|
require('resolve');
|
|
15
15
|
require('postcss');
|
|
16
16
|
require('lilconfig');
|
|
@@ -20,15 +20,14 @@ require('jiti');
|
|
|
20
20
|
|
|
21
21
|
exports.CacheManager = index.CacheManager;
|
|
22
22
|
exports.TailwindcssPatcher = index.TailwindcssPatcher;
|
|
23
|
-
exports.ensureDir = index.ensureDir;
|
|
24
23
|
exports.ensureFileContent = index.ensureFileContent;
|
|
25
24
|
exports.getCacheOptions = index.getCacheOptions;
|
|
26
25
|
exports.getPackageInfoSync = index.getPackageInfoSync;
|
|
27
|
-
exports.inspectPostcssPlugin = index.inspectPostcssPlugin;
|
|
28
|
-
exports.inspectProcessTailwindFeaturesReturnContext = index.inspectProcessTailwindFeaturesReturnContext;
|
|
29
26
|
exports.internalPatch = index.internalPatch;
|
|
30
27
|
exports.isObject = index.isObject;
|
|
28
|
+
exports.logger = index.logger;
|
|
31
29
|
exports.monkeyPatchForExposingContextV2 = index.monkeyPatchForExposingContextV2;
|
|
32
30
|
exports.monkeyPatchForExposingContextV3 = index.monkeyPatchForExposingContextV3;
|
|
31
|
+
exports.monkeyPatchForSupportingCustomUnit = index.monkeyPatchForSupportingCustomUnit;
|
|
33
32
|
exports.requireResolve = index.requireResolve;
|
|
34
33
|
exports.defineConfig = config.defineConfig;
|
package/dist/index.d.cts
CHANGED
|
@@ -4,6 +4,7 @@ import { UserConfig } from '@tailwindcss-mangle/config';
|
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
5
|
import { SyncOpts } from 'resolve';
|
|
6
6
|
import { PackageJson } from 'pkg-types';
|
|
7
|
+
import * as consola from 'consola';
|
|
7
8
|
|
|
8
9
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
9
10
|
interface PackageInfo {
|
|
@@ -26,12 +27,12 @@ interface PatchOptions {
|
|
|
26
27
|
paths?: string[];
|
|
27
28
|
basedir?: string;
|
|
28
29
|
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
|
+
applyPatches?: {
|
|
31
|
+
exportContext?: boolean;
|
|
32
|
+
extendLengthUnits?: boolean;
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
|
-
interface InternalPatchOptions {
|
|
31
|
-
overwrite: boolean;
|
|
32
|
-
paths?: string[];
|
|
33
|
-
basedir?: string;
|
|
34
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
35
|
+
interface InternalPatchOptions extends PatchOptions {
|
|
35
36
|
version?: string;
|
|
36
37
|
}
|
|
37
38
|
interface TailwindcssPatcherOptions {
|
|
@@ -125,15 +126,6 @@ declare class TailwindcssPatcher {
|
|
|
125
126
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
declare function inspectProcessTailwindFeaturesReturnContext(content: string): {
|
|
129
|
-
code: string;
|
|
130
|
-
hasPatched: boolean;
|
|
131
|
-
};
|
|
132
|
-
declare function inspectPostcssPlugin(content: string): {
|
|
133
|
-
code: string;
|
|
134
|
-
hasPatched: boolean;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
129
|
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): {
|
|
138
130
|
processTailwindFeatures?: string;
|
|
139
131
|
plugin?: string;
|
|
@@ -142,11 +134,21 @@ declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPat
|
|
|
142
134
|
processTailwindFeatures?: string;
|
|
143
135
|
plugin?: string;
|
|
144
136
|
} & Record<string, any>;
|
|
137
|
+
|
|
138
|
+
interface ILengthUnitsPatchOptions {
|
|
139
|
+
units: string[];
|
|
140
|
+
lengthUnitsFilePath?: string;
|
|
141
|
+
variableName?: string;
|
|
142
|
+
overwrite?: boolean;
|
|
143
|
+
destPath?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
147
|
+
|
|
145
148
|
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|
|
146
149
|
|
|
147
150
|
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
148
151
|
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
149
|
-
declare function ensureDir(p: string): Promise<void>;
|
|
150
152
|
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
151
153
|
name: string;
|
|
152
154
|
version: string | undefined;
|
|
@@ -156,4 +158,6 @@ declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
|
156
158
|
} | undefined;
|
|
157
159
|
declare function isObject(val: any): boolean;
|
|
158
160
|
|
|
159
|
-
|
|
161
|
+
declare const logger: consola.ConsolaInstance;
|
|
162
|
+
|
|
163
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, ensureFileContent, getCacheOptions, getPackageInfoSync, internalPatch, isObject, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit, requireResolve };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,6 +4,7 @@ import { UserConfig } from '@tailwindcss-mangle/config';
|
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
5
|
import { SyncOpts } from 'resolve';
|
|
6
6
|
import { PackageJson } from 'pkg-types';
|
|
7
|
+
import * as consola from 'consola';
|
|
7
8
|
|
|
8
9
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
9
10
|
interface PackageInfo {
|
|
@@ -26,12 +27,12 @@ interface PatchOptions {
|
|
|
26
27
|
paths?: string[];
|
|
27
28
|
basedir?: string;
|
|
28
29
|
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
|
+
applyPatches?: {
|
|
31
|
+
exportContext?: boolean;
|
|
32
|
+
extendLengthUnits?: boolean;
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
|
-
interface InternalPatchOptions {
|
|
31
|
-
overwrite: boolean;
|
|
32
|
-
paths?: string[];
|
|
33
|
-
basedir?: string;
|
|
34
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
35
|
+
interface InternalPatchOptions extends PatchOptions {
|
|
35
36
|
version?: string;
|
|
36
37
|
}
|
|
37
38
|
interface TailwindcssPatcherOptions {
|
|
@@ -125,15 +126,6 @@ declare class TailwindcssPatcher {
|
|
|
125
126
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
declare function inspectProcessTailwindFeaturesReturnContext(content: string): {
|
|
129
|
-
code: string;
|
|
130
|
-
hasPatched: boolean;
|
|
131
|
-
};
|
|
132
|
-
declare function inspectPostcssPlugin(content: string): {
|
|
133
|
-
code: string;
|
|
134
|
-
hasPatched: boolean;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
129
|
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): {
|
|
138
130
|
processTailwindFeatures?: string;
|
|
139
131
|
plugin?: string;
|
|
@@ -142,11 +134,21 @@ declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPat
|
|
|
142
134
|
processTailwindFeatures?: string;
|
|
143
135
|
plugin?: string;
|
|
144
136
|
} & Record<string, any>;
|
|
137
|
+
|
|
138
|
+
interface ILengthUnitsPatchOptions {
|
|
139
|
+
units: string[];
|
|
140
|
+
lengthUnitsFilePath?: string;
|
|
141
|
+
variableName?: string;
|
|
142
|
+
overwrite?: boolean;
|
|
143
|
+
destPath?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
147
|
+
|
|
145
148
|
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|
|
146
149
|
|
|
147
150
|
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
148
151
|
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
149
|
-
declare function ensureDir(p: string): Promise<void>;
|
|
150
152
|
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
151
153
|
name: string;
|
|
152
154
|
version: string | undefined;
|
|
@@ -156,4 +158,6 @@ declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
|
156
158
|
} | undefined;
|
|
157
159
|
declare function isObject(val: any): boolean;
|
|
158
160
|
|
|
159
|
-
|
|
161
|
+
declare const logger: consola.ConsolaInstance;
|
|
162
|
+
|
|
163
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, ensureFileContent, getCacheOptions, getPackageInfoSync, internalPatch, isObject, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit, requireResolve };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { UserConfig } from '@tailwindcss-mangle/config';
|
|
|
4
4
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
5
5
|
import { SyncOpts } from 'resolve';
|
|
6
6
|
import { PackageJson } from 'pkg-types';
|
|
7
|
+
import * as consola from 'consola';
|
|
7
8
|
|
|
8
9
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
9
10
|
interface PackageInfo {
|
|
@@ -26,12 +27,12 @@ interface PatchOptions {
|
|
|
26
27
|
paths?: string[];
|
|
27
28
|
basedir?: string;
|
|
28
29
|
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
30
|
+
applyPatches?: {
|
|
31
|
+
exportContext?: boolean;
|
|
32
|
+
extendLengthUnits?: boolean;
|
|
33
|
+
};
|
|
29
34
|
}
|
|
30
|
-
interface InternalPatchOptions {
|
|
31
|
-
overwrite: boolean;
|
|
32
|
-
paths?: string[];
|
|
33
|
-
basedir?: string;
|
|
34
|
-
custom?: (dir: string, ctx: Record<string, any>) => void;
|
|
35
|
+
interface InternalPatchOptions extends PatchOptions {
|
|
35
36
|
version?: string;
|
|
36
37
|
}
|
|
37
38
|
interface TailwindcssPatcherOptions {
|
|
@@ -125,15 +126,6 @@ declare class TailwindcssPatcher {
|
|
|
125
126
|
extract(options?: UserConfig['patch']): Promise<string | undefined>;
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
declare function inspectProcessTailwindFeaturesReturnContext(content: string): {
|
|
129
|
-
code: string;
|
|
130
|
-
hasPatched: boolean;
|
|
131
|
-
};
|
|
132
|
-
declare function inspectPostcssPlugin(content: string): {
|
|
133
|
-
code: string;
|
|
134
|
-
hasPatched: boolean;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
129
|
declare function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions): {
|
|
138
130
|
processTailwindFeatures?: string;
|
|
139
131
|
plugin?: string;
|
|
@@ -142,11 +134,21 @@ declare function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPat
|
|
|
142
134
|
processTailwindFeatures?: string;
|
|
143
135
|
plugin?: string;
|
|
144
136
|
} & Record<string, any>;
|
|
137
|
+
|
|
138
|
+
interface ILengthUnitsPatchOptions {
|
|
139
|
+
units: string[];
|
|
140
|
+
lengthUnitsFilePath?: string;
|
|
141
|
+
variableName?: string;
|
|
142
|
+
overwrite?: boolean;
|
|
143
|
+
destPath?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options?: Partial<ILengthUnitsPatchOptions>): string | undefined;
|
|
147
|
+
|
|
145
148
|
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|
|
146
149
|
|
|
147
150
|
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
148
151
|
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
149
|
-
declare function ensureDir(p: string): Promise<void>;
|
|
150
152
|
declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
151
153
|
name: string;
|
|
152
154
|
version: string | undefined;
|
|
@@ -156,4 +158,6 @@ declare function getPackageInfoSync(name: string, options?: SyncOpts): {
|
|
|
156
158
|
} | undefined;
|
|
157
159
|
declare function isObject(val: any): boolean;
|
|
158
160
|
|
|
159
|
-
|
|
161
|
+
declare const logger: consola.ConsolaInstance;
|
|
162
|
+
|
|
163
|
+
export { CacheManager, type CacheOptions, type CacheStrategy, type DeepRequired, type InternalCacheOptions, type InternalPatchOptions, type PackageInfo, type PatchOptions, type TailwindcssClassCache, TailwindcssPatcher, type TailwindcssPatcherOptions, type TailwindcssRuntimeContext, ensureFileContent, getCacheOptions, getPackageInfoSync, internalPatch, isObject, logger, monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3, monkeyPatchForSupportingCustomUnit, requireResolve };
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export { C as CacheManager, T as TailwindcssPatcher,
|
|
1
|
+
export { C as CacheManager, T as TailwindcssPatcher, e as ensureFileContent, c as getCacheOptions, d as getPackageInfoSync, i as internalPatch, f as isObject, l as logger, a as monkeyPatchForExposingContextV2, m as monkeyPatchForExposingContextV3, b as monkeyPatchForSupportingCustomUnit, r as requireResolve } from './shared/tailwindcss-patch.ec6deb5e.mjs';
|
|
2
2
|
export { defineConfig } from '@tailwindcss-mangle/config';
|
|
3
3
|
import 'node:path';
|
|
4
|
-
import '
|
|
4
|
+
import 'fs-extra';
|
|
5
5
|
import 'node:process';
|
|
6
|
+
import 'consola';
|
|
6
7
|
import 'semver';
|
|
7
8
|
import '@babel/types';
|
|
8
9
|
import '@babel/generator';
|
|
9
10
|
import '@babel/traverse';
|
|
10
11
|
import '@babel/parser';
|
|
11
|
-
import 'node:fs/promises';
|
|
12
12
|
import 'resolve';
|
|
13
13
|
import 'postcss';
|
|
14
14
|
import 'lilconfig';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const path = require('node:path');
|
|
4
|
-
const fs = require('
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
5
|
const process = require('node:process');
|
|
6
|
+
const consola = require('consola');
|
|
6
7
|
const semver = require('semver');
|
|
7
8
|
const t = require('@babel/types');
|
|
8
9
|
const _babelGenerate = require('@babel/generator');
|
|
9
10
|
const _babelTraverse = require('@babel/traverse');
|
|
10
11
|
const parser = require('@babel/parser');
|
|
11
|
-
const fs$1 = require('node:fs/promises');
|
|
12
12
|
const pkg = require('resolve');
|
|
13
13
|
const postcss = require('postcss');
|
|
14
14
|
const lilconfig = require('lilconfig');
|
|
@@ -35,16 +35,13 @@ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
|
35
35
|
const t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
36
36
|
const _babelGenerate__default = /*#__PURE__*/_interopDefaultCompat(_babelGenerate);
|
|
37
37
|
const _babelTraverse__default = /*#__PURE__*/_interopDefaultCompat(_babelTraverse);
|
|
38
|
-
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
39
38
|
const pkg__default = /*#__PURE__*/_interopDefaultCompat(pkg);
|
|
40
39
|
const postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
|
|
41
40
|
const createJiti__default = /*#__PURE__*/_interopDefaultCompat(createJiti);
|
|
42
41
|
|
|
43
42
|
const pkgName = "tailwindcss-patch";
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
return console.log(`[${pkgName}]:${message}`, ...optionalParams);
|
|
47
|
-
}
|
|
44
|
+
const logger = consola.createConsola();
|
|
48
45
|
|
|
49
46
|
var __defProp$1 = Object.defineProperty;
|
|
50
47
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -108,7 +105,7 @@ class CacheManager {
|
|
|
108
105
|
fs__default.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
109
106
|
return filename;
|
|
110
107
|
} catch {
|
|
111
|
-
|
|
108
|
+
logger.error("write cache file fail!");
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
111
|
read() {
|
|
@@ -119,11 +116,11 @@ class CacheManager {
|
|
|
119
116
|
return new Set(JSON.parse(data));
|
|
120
117
|
}
|
|
121
118
|
} catch {
|
|
122
|
-
|
|
119
|
+
logger.error(`parse cache content fail! path:${filename}`);
|
|
123
120
|
try {
|
|
124
121
|
fs__default.unlinkSync(filename);
|
|
125
122
|
} catch {
|
|
126
|
-
|
|
123
|
+
logger.error(`delete cache file fail! path:${filename}`);
|
|
127
124
|
}
|
|
128
125
|
}
|
|
129
126
|
}
|
|
@@ -424,15 +421,6 @@ function ensureFileContent(filepaths) {
|
|
|
424
421
|
function requireResolve(id, opts) {
|
|
425
422
|
return sync(id, opts);
|
|
426
423
|
}
|
|
427
|
-
async function ensureDir(p) {
|
|
428
|
-
try {
|
|
429
|
-
await fs__default$1.access(p);
|
|
430
|
-
} catch {
|
|
431
|
-
await fs__default$1.mkdir(p, {
|
|
432
|
-
recursive: true
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
424
|
function searchPackageJSON(dir) {
|
|
437
425
|
let packageJsonPath;
|
|
438
426
|
while (true) {
|
|
@@ -489,7 +477,7 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
489
477
|
fs__default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
490
478
|
encoding: "utf8"
|
|
491
479
|
});
|
|
492
|
-
|
|
480
|
+
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
493
481
|
}
|
|
494
482
|
result.processTailwindFeatures = code;
|
|
495
483
|
}
|
|
@@ -502,7 +490,7 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
502
490
|
fs__default.writeFileSync(pluginFilePath, code, {
|
|
503
491
|
encoding: "utf8"
|
|
504
492
|
});
|
|
505
|
-
|
|
493
|
+
logger.success("patch tailwindcss for expose runtime context successfully!");
|
|
506
494
|
}
|
|
507
495
|
result.plugin = code;
|
|
508
496
|
}
|
|
@@ -519,7 +507,7 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
519
507
|
fs__default.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
520
508
|
encoding: "utf8"
|
|
521
509
|
});
|
|
522
|
-
|
|
510
|
+
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
523
511
|
}
|
|
524
512
|
result.processTailwindFeatures = code;
|
|
525
513
|
}
|
|
@@ -531,71 +519,13 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
531
519
|
fs__default.writeFileSync(indexFilePath, code, {
|
|
532
520
|
encoding: "utf8"
|
|
533
521
|
});
|
|
534
|
-
|
|
522
|
+
logger.success("patch tailwindcss for expose runtime content successfully!");
|
|
535
523
|
}
|
|
536
524
|
result.plugin = code;
|
|
537
525
|
}
|
|
538
526
|
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
539
527
|
return result;
|
|
540
528
|
}
|
|
541
|
-
function internalPatch(pkgJsonPath, options) {
|
|
542
|
-
if (pkgJsonPath) {
|
|
543
|
-
const pkgJson = require(pkgJsonPath);
|
|
544
|
-
const twDir = path__default.dirname(pkgJsonPath);
|
|
545
|
-
if (semver.gte(pkgJson.version, "3.0.0")) {
|
|
546
|
-
options.version = pkgJson.version;
|
|
547
|
-
const result = monkeyPatchForExposingContextV3(twDir, options);
|
|
548
|
-
return result;
|
|
549
|
-
} else if (semver.gte(pkgJson.version, "2.0.0")) {
|
|
550
|
-
options.version = pkgJson.version;
|
|
551
|
-
const result = monkeyPatchForExposingContextV2(twDir, options);
|
|
552
|
-
return result;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
const jiti = createJiti__default(__filename);
|
|
558
|
-
async function processTailwindcss(options) {
|
|
559
|
-
options.cwd = options.cwd ?? process__default.cwd();
|
|
560
|
-
let config = options.config;
|
|
561
|
-
if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
|
|
562
|
-
const moduleName = "tailwind";
|
|
563
|
-
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
564
|
-
searchPlaces: [
|
|
565
|
-
`${moduleName}.config.js`,
|
|
566
|
-
`${moduleName}.config.cjs`,
|
|
567
|
-
`${moduleName}.config.mjs`,
|
|
568
|
-
`${moduleName}.config.ts`,
|
|
569
|
-
`${moduleName}.config.cts`,
|
|
570
|
-
`${moduleName}.config.mts`
|
|
571
|
-
],
|
|
572
|
-
loaders: {
|
|
573
|
-
// 默认支持 js 和 cjs 2种格式
|
|
574
|
-
".js": jiti,
|
|
575
|
-
".cjs": jiti,
|
|
576
|
-
".mjs": jiti,
|
|
577
|
-
".ts": jiti,
|
|
578
|
-
".cts": jiti,
|
|
579
|
-
".mts": jiti
|
|
580
|
-
}
|
|
581
|
-
}).search(options.cwd);
|
|
582
|
-
if (!result) {
|
|
583
|
-
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
584
|
-
}
|
|
585
|
-
config = result.filepath;
|
|
586
|
-
}
|
|
587
|
-
const id = requireResolve("tailwindcss", {
|
|
588
|
-
basedir: options.cwd
|
|
589
|
-
});
|
|
590
|
-
return await postcss__default([
|
|
591
|
-
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
592
|
-
require(id)({
|
|
593
|
-
config
|
|
594
|
-
})
|
|
595
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
596
|
-
from: void 0
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
529
|
|
|
600
530
|
function isPlainObject(value) {
|
|
601
531
|
if (value === null || typeof value !== "object") {
|
|
@@ -653,8 +583,152 @@ function createDefu(merger) {
|
|
|
653
583
|
}
|
|
654
584
|
const defu = createDefu();
|
|
655
585
|
|
|
586
|
+
function findAstNode(content, options) {
|
|
587
|
+
const { variableName, units } = options;
|
|
588
|
+
const ast = parser.parse(content);
|
|
589
|
+
let arrayRef;
|
|
590
|
+
let changed = false;
|
|
591
|
+
traverse(ast, {
|
|
592
|
+
Identifier(path2) {
|
|
593
|
+
if (path2.node.name === variableName && t__namespace.isVariableDeclarator(path2.parent) && t__namespace.isArrayExpression(path2.parent.init)) {
|
|
594
|
+
arrayRef = path2.parent.init;
|
|
595
|
+
const set = new Set(path2.parent.init.elements.map((x) => x.value));
|
|
596
|
+
for (let i = 0; i < units.length; i++) {
|
|
597
|
+
const unit = units[i];
|
|
598
|
+
if (!set.has(unit)) {
|
|
599
|
+
path2.parent.init.elements = path2.parent.init.elements.map((x) => {
|
|
600
|
+
if (t__namespace.isStringLiteral(x)) {
|
|
601
|
+
return {
|
|
602
|
+
type: x?.type,
|
|
603
|
+
value: x?.value
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
return x;
|
|
607
|
+
});
|
|
608
|
+
path2.parent.init.elements.push({
|
|
609
|
+
type: "StringLiteral",
|
|
610
|
+
value: unit
|
|
611
|
+
});
|
|
612
|
+
changed = true;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
return {
|
|
619
|
+
arrayRef,
|
|
620
|
+
changed
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
624
|
+
const opts = defu(options, {
|
|
625
|
+
units: ["rpx"],
|
|
626
|
+
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
627
|
+
variableName: "lengthUnits",
|
|
628
|
+
overwrite: true
|
|
629
|
+
});
|
|
630
|
+
const { lengthUnitsFilePath, overwrite, destPath } = opts;
|
|
631
|
+
const dataTypesFilePath = path__default.resolve(rootDir, lengthUnitsFilePath);
|
|
632
|
+
const dataTypesFileContent = fs__default.readFileSync(dataTypesFilePath, {
|
|
633
|
+
encoding: "utf8"
|
|
634
|
+
});
|
|
635
|
+
const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
|
|
636
|
+
if (arrayRef && changed) {
|
|
637
|
+
const { code } = generate(arrayRef, {
|
|
638
|
+
jsescOption: {
|
|
639
|
+
quotes: "single"
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
if (arrayRef.start && arrayRef.end) {
|
|
643
|
+
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
644
|
+
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
645
|
+
const newCode = prev + code + next;
|
|
646
|
+
if (overwrite) {
|
|
647
|
+
fs__default.writeFileSync(destPath ?? dataTypesFilePath, newCode, {
|
|
648
|
+
encoding: "utf8"
|
|
649
|
+
});
|
|
650
|
+
logger.success("patch tailwindcss for custom length unit successfully!");
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return code;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
function internalPatch(pkgJsonPath, options) {
|
|
658
|
+
if (pkgJsonPath) {
|
|
659
|
+
const pkgJson = require(pkgJsonPath);
|
|
660
|
+
const twDir = path__default.dirname(pkgJsonPath);
|
|
661
|
+
if (semver.gte(pkgJson.version, "3.0.0")) {
|
|
662
|
+
options.version = pkgJson.version;
|
|
663
|
+
if (options.applyPatches?.extendLengthUnits) {
|
|
664
|
+
try {
|
|
665
|
+
monkeyPatchForSupportingCustomUnit(twDir, {
|
|
666
|
+
overwrite: options.overwrite
|
|
667
|
+
});
|
|
668
|
+
} catch {
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
if (options.applyPatches?.exportContext) {
|
|
672
|
+
return monkeyPatchForExposingContextV3(twDir, options);
|
|
673
|
+
}
|
|
674
|
+
} else if (semver.gte(pkgJson.version, "2.0.0")) {
|
|
675
|
+
options.version = pkgJson.version;
|
|
676
|
+
if (options.applyPatches?.exportContext) {
|
|
677
|
+
return monkeyPatchForExposingContextV2(twDir, options);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const jiti = createJiti__default(__filename);
|
|
684
|
+
async function processTailwindcss(options) {
|
|
685
|
+
options.cwd = options.cwd ?? process__default.cwd();
|
|
686
|
+
let config = options.config;
|
|
687
|
+
if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
|
|
688
|
+
const moduleName = "tailwind";
|
|
689
|
+
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
690
|
+
searchPlaces: [
|
|
691
|
+
`${moduleName}.config.js`,
|
|
692
|
+
`${moduleName}.config.cjs`,
|
|
693
|
+
`${moduleName}.config.mjs`,
|
|
694
|
+
`${moduleName}.config.ts`,
|
|
695
|
+
`${moduleName}.config.cts`,
|
|
696
|
+
`${moduleName}.config.mts`
|
|
697
|
+
],
|
|
698
|
+
loaders: {
|
|
699
|
+
// 默认支持 js 和 cjs 2种格式
|
|
700
|
+
".js": jiti,
|
|
701
|
+
".cjs": jiti,
|
|
702
|
+
".mjs": jiti,
|
|
703
|
+
".ts": jiti,
|
|
704
|
+
".cts": jiti,
|
|
705
|
+
".mts": jiti
|
|
706
|
+
}
|
|
707
|
+
}).search(options.cwd);
|
|
708
|
+
if (!result) {
|
|
709
|
+
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
710
|
+
}
|
|
711
|
+
config = result.filepath;
|
|
712
|
+
}
|
|
713
|
+
const id = requireResolve("tailwindcss", {
|
|
714
|
+
basedir: options.cwd
|
|
715
|
+
});
|
|
716
|
+
return await postcss__default([
|
|
717
|
+
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
718
|
+
require(id)({
|
|
719
|
+
config
|
|
720
|
+
})
|
|
721
|
+
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
722
|
+
from: void 0
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
|
|
656
726
|
function getDefaultPatchOptions() {
|
|
657
727
|
return {
|
|
728
|
+
applyPatches: {
|
|
729
|
+
exportContext: true,
|
|
730
|
+
extendLengthUnits: false
|
|
731
|
+
},
|
|
658
732
|
overwrite: true
|
|
659
733
|
};
|
|
660
734
|
}
|
|
@@ -695,7 +769,7 @@ class TailwindcssPatcher {
|
|
|
695
769
|
try {
|
|
696
770
|
return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
|
|
697
771
|
} catch (error) {
|
|
698
|
-
console.
|
|
772
|
+
console.error(`patch tailwindcss failed: ${error.message}`);
|
|
699
773
|
}
|
|
700
774
|
};
|
|
701
775
|
}
|
|
@@ -777,7 +851,7 @@ class TailwindcssPatcher {
|
|
|
777
851
|
removeUniversalSelector
|
|
778
852
|
});
|
|
779
853
|
if (filename) {
|
|
780
|
-
await ensureDir(path__default.dirname(filename));
|
|
854
|
+
await fs__default.ensureDir(path__default.dirname(filename));
|
|
781
855
|
const classList = [...set];
|
|
782
856
|
fs__default.writeFileSync(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
|
|
783
857
|
return filename;
|
|
@@ -788,15 +862,14 @@ class TailwindcssPatcher {
|
|
|
788
862
|
|
|
789
863
|
exports.CacheManager = CacheManager;
|
|
790
864
|
exports.TailwindcssPatcher = TailwindcssPatcher;
|
|
791
|
-
exports.ensureDir = ensureDir;
|
|
792
865
|
exports.ensureFileContent = ensureFileContent;
|
|
793
866
|
exports.getCacheOptions = getCacheOptions;
|
|
794
867
|
exports.getPackageInfoSync = getPackageInfoSync;
|
|
795
868
|
exports.getPatchOptions = getPatchOptions;
|
|
796
|
-
exports.inspectPostcssPlugin = inspectPostcssPlugin$1;
|
|
797
|
-
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext$1;
|
|
798
869
|
exports.internalPatch = internalPatch;
|
|
799
870
|
exports.isObject = isObject;
|
|
871
|
+
exports.logger = logger;
|
|
800
872
|
exports.monkeyPatchForExposingContextV2 = monkeyPatchForExposingContextV2;
|
|
801
873
|
exports.monkeyPatchForExposingContextV3 = monkeyPatchForExposingContextV3;
|
|
874
|
+
exports.monkeyPatchForSupportingCustomUnit = monkeyPatchForSupportingCustomUnit;
|
|
802
875
|
exports.requireResolve = requireResolve;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import fs from '
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
+
import { createConsola } from 'consola';
|
|
4
5
|
import { gte } from 'semver';
|
|
5
6
|
import * as t from '@babel/types';
|
|
6
7
|
import _babelGenerate from '@babel/generator';
|
|
7
8
|
import _babelTraverse from '@babel/traverse';
|
|
8
9
|
import { parse } from '@babel/parser';
|
|
9
|
-
import fs$1 from 'node:fs/promises';
|
|
10
10
|
import pkg from 'resolve';
|
|
11
11
|
import postcss from 'postcss';
|
|
12
12
|
import { lilconfig } from 'lilconfig';
|
|
@@ -24,9 +24,7 @@ const __dirname = __cjs_path__.dirname(__filename);
|
|
|
24
24
|
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
25
25
|
const pkgName = "tailwindcss-patch";
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
return console.log(`[${pkgName}]:${message}`, ...optionalParams);
|
|
29
|
-
}
|
|
27
|
+
const logger = createConsola();
|
|
30
28
|
|
|
31
29
|
var __defProp$1 = Object.defineProperty;
|
|
32
30
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -90,7 +88,7 @@ class CacheManager {
|
|
|
90
88
|
fs.writeFileSync(filename, JSON.stringify([...data], void 0, 2), "utf8");
|
|
91
89
|
return filename;
|
|
92
90
|
} catch {
|
|
93
|
-
|
|
91
|
+
logger.error("write cache file fail!");
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
94
|
read() {
|
|
@@ -101,11 +99,11 @@ class CacheManager {
|
|
|
101
99
|
return new Set(JSON.parse(data));
|
|
102
100
|
}
|
|
103
101
|
} catch {
|
|
104
|
-
|
|
102
|
+
logger.error(`parse cache content fail! path:${filename}`);
|
|
105
103
|
try {
|
|
106
104
|
fs.unlinkSync(filename);
|
|
107
105
|
} catch {
|
|
108
|
-
|
|
106
|
+
logger.error(`delete cache file fail! path:${filename}`);
|
|
109
107
|
}
|
|
110
108
|
}
|
|
111
109
|
}
|
|
@@ -406,15 +404,6 @@ function ensureFileContent(filepaths) {
|
|
|
406
404
|
function requireResolve(id, opts) {
|
|
407
405
|
return sync(id, opts);
|
|
408
406
|
}
|
|
409
|
-
async function ensureDir(p) {
|
|
410
|
-
try {
|
|
411
|
-
await fs$1.access(p);
|
|
412
|
-
} catch {
|
|
413
|
-
await fs$1.mkdir(p, {
|
|
414
|
-
recursive: true
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
407
|
function searchPackageJSON(dir) {
|
|
419
408
|
let packageJsonPath;
|
|
420
409
|
while (true) {
|
|
@@ -471,7 +460,7 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
471
460
|
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
472
461
|
encoding: "utf8"
|
|
473
462
|
});
|
|
474
|
-
|
|
463
|
+
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
475
464
|
}
|
|
476
465
|
result.processTailwindFeatures = code;
|
|
477
466
|
}
|
|
@@ -484,7 +473,7 @@ function monkeyPatchForExposingContextV3(twDir, opt) {
|
|
|
484
473
|
fs.writeFileSync(pluginFilePath, code, {
|
|
485
474
|
encoding: "utf8"
|
|
486
475
|
});
|
|
487
|
-
|
|
476
|
+
logger.success("patch tailwindcss for expose runtime context successfully!");
|
|
488
477
|
}
|
|
489
478
|
result.plugin = code;
|
|
490
479
|
}
|
|
@@ -501,7 +490,7 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
501
490
|
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
|
|
502
491
|
encoding: "utf8"
|
|
503
492
|
});
|
|
504
|
-
|
|
493
|
+
logger.success("patch tailwindcss processTailwindFeatures for return content successfully!");
|
|
505
494
|
}
|
|
506
495
|
result.processTailwindFeatures = code;
|
|
507
496
|
}
|
|
@@ -513,71 +502,13 @@ function monkeyPatchForExposingContextV2(twDir, opt) {
|
|
|
513
502
|
fs.writeFileSync(indexFilePath, code, {
|
|
514
503
|
encoding: "utf8"
|
|
515
504
|
});
|
|
516
|
-
|
|
505
|
+
logger.success("patch tailwindcss for expose runtime content successfully!");
|
|
517
506
|
}
|
|
518
507
|
result.plugin = code;
|
|
519
508
|
}
|
|
520
509
|
opt.custom && typeof opt.custom === "function" && opt.custom(twDir, result);
|
|
521
510
|
return result;
|
|
522
511
|
}
|
|
523
|
-
function internalPatch(pkgJsonPath, options) {
|
|
524
|
-
if (pkgJsonPath) {
|
|
525
|
-
const pkgJson = require(pkgJsonPath);
|
|
526
|
-
const twDir = path.dirname(pkgJsonPath);
|
|
527
|
-
if (gte(pkgJson.version, "3.0.0")) {
|
|
528
|
-
options.version = pkgJson.version;
|
|
529
|
-
const result = monkeyPatchForExposingContextV3(twDir, options);
|
|
530
|
-
return result;
|
|
531
|
-
} else if (gte(pkgJson.version, "2.0.0")) {
|
|
532
|
-
options.version = pkgJson.version;
|
|
533
|
-
const result = monkeyPatchForExposingContextV2(twDir, options);
|
|
534
|
-
return result;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const jiti = createJiti(__filename);
|
|
540
|
-
async function processTailwindcss(options) {
|
|
541
|
-
options.cwd = options.cwd ?? process.cwd();
|
|
542
|
-
let config = options.config;
|
|
543
|
-
if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
|
|
544
|
-
const moduleName = "tailwind";
|
|
545
|
-
const result = await lilconfig("tailwindcss", {
|
|
546
|
-
searchPlaces: [
|
|
547
|
-
`${moduleName}.config.js`,
|
|
548
|
-
`${moduleName}.config.cjs`,
|
|
549
|
-
`${moduleName}.config.mjs`,
|
|
550
|
-
`${moduleName}.config.ts`,
|
|
551
|
-
`${moduleName}.config.cts`,
|
|
552
|
-
`${moduleName}.config.mts`
|
|
553
|
-
],
|
|
554
|
-
loaders: {
|
|
555
|
-
// 默认支持 js 和 cjs 2种格式
|
|
556
|
-
".js": jiti,
|
|
557
|
-
".cjs": jiti,
|
|
558
|
-
".mjs": jiti,
|
|
559
|
-
".ts": jiti,
|
|
560
|
-
".cts": jiti,
|
|
561
|
-
".mts": jiti
|
|
562
|
-
}
|
|
563
|
-
}).search(options.cwd);
|
|
564
|
-
if (!result) {
|
|
565
|
-
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
566
|
-
}
|
|
567
|
-
config = result.filepath;
|
|
568
|
-
}
|
|
569
|
-
const id = requireResolve("tailwindcss", {
|
|
570
|
-
basedir: options.cwd
|
|
571
|
-
});
|
|
572
|
-
return await postcss([
|
|
573
|
-
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
574
|
-
require(id)({
|
|
575
|
-
config
|
|
576
|
-
})
|
|
577
|
-
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
578
|
-
from: void 0
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
512
|
|
|
582
513
|
function isPlainObject(value) {
|
|
583
514
|
if (value === null || typeof value !== "object") {
|
|
@@ -635,8 +566,152 @@ function createDefu(merger) {
|
|
|
635
566
|
}
|
|
636
567
|
const defu = createDefu();
|
|
637
568
|
|
|
569
|
+
function findAstNode(content, options) {
|
|
570
|
+
const { variableName, units } = options;
|
|
571
|
+
const ast = parse(content);
|
|
572
|
+
let arrayRef;
|
|
573
|
+
let changed = false;
|
|
574
|
+
traverse(ast, {
|
|
575
|
+
Identifier(path2) {
|
|
576
|
+
if (path2.node.name === variableName && t.isVariableDeclarator(path2.parent) && t.isArrayExpression(path2.parent.init)) {
|
|
577
|
+
arrayRef = path2.parent.init;
|
|
578
|
+
const set = new Set(path2.parent.init.elements.map((x) => x.value));
|
|
579
|
+
for (let i = 0; i < units.length; i++) {
|
|
580
|
+
const unit = units[i];
|
|
581
|
+
if (!set.has(unit)) {
|
|
582
|
+
path2.parent.init.elements = path2.parent.init.elements.map((x) => {
|
|
583
|
+
if (t.isStringLiteral(x)) {
|
|
584
|
+
return {
|
|
585
|
+
type: x?.type,
|
|
586
|
+
value: x?.value
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
return x;
|
|
590
|
+
});
|
|
591
|
+
path2.parent.init.elements.push({
|
|
592
|
+
type: "StringLiteral",
|
|
593
|
+
value: unit
|
|
594
|
+
});
|
|
595
|
+
changed = true;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
return {
|
|
602
|
+
arrayRef,
|
|
603
|
+
changed
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function monkeyPatchForSupportingCustomUnit(rootDir, options) {
|
|
607
|
+
const opts = defu(options, {
|
|
608
|
+
units: ["rpx"],
|
|
609
|
+
lengthUnitsFilePath: "lib/util/dataTypes.js",
|
|
610
|
+
variableName: "lengthUnits",
|
|
611
|
+
overwrite: true
|
|
612
|
+
});
|
|
613
|
+
const { lengthUnitsFilePath, overwrite, destPath } = opts;
|
|
614
|
+
const dataTypesFilePath = path.resolve(rootDir, lengthUnitsFilePath);
|
|
615
|
+
const dataTypesFileContent = fs.readFileSync(dataTypesFilePath, {
|
|
616
|
+
encoding: "utf8"
|
|
617
|
+
});
|
|
618
|
+
const { arrayRef, changed } = findAstNode(dataTypesFileContent, opts);
|
|
619
|
+
if (arrayRef && changed) {
|
|
620
|
+
const { code } = generate(arrayRef, {
|
|
621
|
+
jsescOption: {
|
|
622
|
+
quotes: "single"
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
if (arrayRef.start && arrayRef.end) {
|
|
626
|
+
const prev = dataTypesFileContent.slice(0, arrayRef.start);
|
|
627
|
+
const next = dataTypesFileContent.slice(arrayRef.end);
|
|
628
|
+
const newCode = prev + code + next;
|
|
629
|
+
if (overwrite) {
|
|
630
|
+
fs.writeFileSync(destPath ?? dataTypesFilePath, newCode, {
|
|
631
|
+
encoding: "utf8"
|
|
632
|
+
});
|
|
633
|
+
logger.success("patch tailwindcss for custom length unit successfully!");
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
return code;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function internalPatch(pkgJsonPath, options) {
|
|
641
|
+
if (pkgJsonPath) {
|
|
642
|
+
const pkgJson = require(pkgJsonPath);
|
|
643
|
+
const twDir = path.dirname(pkgJsonPath);
|
|
644
|
+
if (gte(pkgJson.version, "3.0.0")) {
|
|
645
|
+
options.version = pkgJson.version;
|
|
646
|
+
if (options.applyPatches?.extendLengthUnits) {
|
|
647
|
+
try {
|
|
648
|
+
monkeyPatchForSupportingCustomUnit(twDir, {
|
|
649
|
+
overwrite: options.overwrite
|
|
650
|
+
});
|
|
651
|
+
} catch {
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (options.applyPatches?.exportContext) {
|
|
655
|
+
return monkeyPatchForExposingContextV3(twDir, options);
|
|
656
|
+
}
|
|
657
|
+
} else if (gte(pkgJson.version, "2.0.0")) {
|
|
658
|
+
options.version = pkgJson.version;
|
|
659
|
+
if (options.applyPatches?.exportContext) {
|
|
660
|
+
return monkeyPatchForExposingContextV2(twDir, options);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
const jiti = createJiti(__filename);
|
|
667
|
+
async function processTailwindcss(options) {
|
|
668
|
+
options.cwd = options.cwd ?? process.cwd();
|
|
669
|
+
let config = options.config;
|
|
670
|
+
if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
|
|
671
|
+
const moduleName = "tailwind";
|
|
672
|
+
const result = await lilconfig("tailwindcss", {
|
|
673
|
+
searchPlaces: [
|
|
674
|
+
`${moduleName}.config.js`,
|
|
675
|
+
`${moduleName}.config.cjs`,
|
|
676
|
+
`${moduleName}.config.mjs`,
|
|
677
|
+
`${moduleName}.config.ts`,
|
|
678
|
+
`${moduleName}.config.cts`,
|
|
679
|
+
`${moduleName}.config.mts`
|
|
680
|
+
],
|
|
681
|
+
loaders: {
|
|
682
|
+
// 默认支持 js 和 cjs 2种格式
|
|
683
|
+
".js": jiti,
|
|
684
|
+
".cjs": jiti,
|
|
685
|
+
".mjs": jiti,
|
|
686
|
+
".ts": jiti,
|
|
687
|
+
".cts": jiti,
|
|
688
|
+
".mts": jiti
|
|
689
|
+
}
|
|
690
|
+
}).search(options.cwd);
|
|
691
|
+
if (!result) {
|
|
692
|
+
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
693
|
+
}
|
|
694
|
+
config = result.filepath;
|
|
695
|
+
}
|
|
696
|
+
const id = requireResolve("tailwindcss", {
|
|
697
|
+
basedir: options.cwd
|
|
698
|
+
});
|
|
699
|
+
return await postcss([
|
|
700
|
+
// eslint-disable-next-line ts/no-var-requires, ts/no-require-imports
|
|
701
|
+
require(id)({
|
|
702
|
+
config
|
|
703
|
+
})
|
|
704
|
+
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
705
|
+
from: void 0
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
|
|
638
709
|
function getDefaultPatchOptions() {
|
|
639
710
|
return {
|
|
711
|
+
applyPatches: {
|
|
712
|
+
exportContext: true,
|
|
713
|
+
extendLengthUnits: false
|
|
714
|
+
},
|
|
640
715
|
overwrite: true
|
|
641
716
|
};
|
|
642
717
|
}
|
|
@@ -677,7 +752,7 @@ class TailwindcssPatcher {
|
|
|
677
752
|
try {
|
|
678
753
|
return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions);
|
|
679
754
|
} catch (error) {
|
|
680
|
-
console.
|
|
755
|
+
console.error(`patch tailwindcss failed: ${error.message}`);
|
|
681
756
|
}
|
|
682
757
|
};
|
|
683
758
|
}
|
|
@@ -759,7 +834,7 @@ class TailwindcssPatcher {
|
|
|
759
834
|
removeUniversalSelector
|
|
760
835
|
});
|
|
761
836
|
if (filename) {
|
|
762
|
-
await ensureDir(path.dirname(filename));
|
|
837
|
+
await fs.ensureDir(path.dirname(filename));
|
|
763
838
|
const classList = [...set];
|
|
764
839
|
fs.writeFileSync(filename, JSON.stringify(classList, null, loose ? 2 : void 0), "utf8");
|
|
765
840
|
return filename;
|
|
@@ -768,4 +843,4 @@ class TailwindcssPatcher {
|
|
|
768
843
|
}
|
|
769
844
|
}
|
|
770
845
|
|
|
771
|
-
export { CacheManager as C, TailwindcssPatcher as T,
|
|
846
|
+
export { CacheManager as C, TailwindcssPatcher as T, monkeyPatchForExposingContextV2 as a, monkeyPatchForSupportingCustomUnit as b, getCacheOptions as c, getPackageInfoSync as d, ensureFileContent as e, isObject as f, getPatchOptions as g, internalPatch as i, logger as l, monkeyPatchForExposingContextV3 as m, requireResolve as r };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-alpha.0",
|
|
4
4
|
"description": "patch tailwindcss for exposing context and extract classes",
|
|
5
5
|
"author": "SonOfMagic <qq1324318532@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,16 +42,18 @@
|
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@babel/generator": "^7.24.
|
|
46
|
-
"@babel/parser": "^7.24.
|
|
47
|
-
"@babel/traverse": "^7.24.
|
|
48
|
-
"@babel/types": "^7.24.
|
|
45
|
+
"@babel/generator": "^7.24.10",
|
|
46
|
+
"@babel/parser": "^7.24.8",
|
|
47
|
+
"@babel/traverse": "^7.24.8",
|
|
48
|
+
"@babel/types": "^7.24.9",
|
|
49
49
|
"cac": "^6.7.14",
|
|
50
|
+
"consola": "^3.2.3",
|
|
51
|
+
"fs-extra": "^11.2.0",
|
|
50
52
|
"jiti": "^1.21.6",
|
|
51
53
|
"lilconfig": "^3.1.2",
|
|
52
|
-
"postcss": "^8.4.
|
|
54
|
+
"postcss": "^8.4.39",
|
|
53
55
|
"resolve": "^1.22.8",
|
|
54
|
-
"semver": "^7.6.
|
|
56
|
+
"semver": "^7.6.3",
|
|
55
57
|
"@tailwindcss-mangle/config": "^3.0.0"
|
|
56
58
|
},
|
|
57
59
|
"devDependencies": {
|
|
@@ -59,9 +61,9 @@
|
|
|
59
61
|
"@types/babel__traverse": "^7.20.6",
|
|
60
62
|
"@types/resolve": "^1.20.6",
|
|
61
63
|
"@types/semver": "^7.5.8",
|
|
62
|
-
"pkg-types": "^1.1.
|
|
64
|
+
"pkg-types": "^1.1.3",
|
|
63
65
|
"postcss7": "npm:postcss@7",
|
|
64
|
-
"tailwindcss": "^3.4.
|
|
66
|
+
"tailwindcss": "^3.4.6",
|
|
65
67
|
"tailwindcss2": "npm:@tailwindcss/postcss7-compat@^2.2.17"
|
|
66
68
|
},
|
|
67
69
|
"directories": {
|