tailwindcss-patch 2.0.1 → 2.0.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.
- package/dist/cli.cjs +8 -7
- package/dist/cli.mjs +6 -5
- package/dist/index.cjs +67 -146
- package/dist/index.d.ts +7 -24
- package/dist/index.mjs +73 -152
- package/package.json +8 -7
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const cac = require('cac');
|
|
3
4
|
const index = require('./index.cjs');
|
|
4
5
|
require('node:path');
|
|
5
6
|
require('node:fs');
|
|
@@ -9,10 +10,10 @@ require('@babel/types');
|
|
|
9
10
|
require('@babel/generator');
|
|
10
11
|
require('@babel/traverse');
|
|
11
12
|
require('@babel/parser');
|
|
12
|
-
const
|
|
13
|
+
const config = require('@tailwindcss-mangle/config');
|
|
13
14
|
require('semver');
|
|
14
15
|
require('postcss');
|
|
15
|
-
require('
|
|
16
|
+
require('lilconfig');
|
|
16
17
|
|
|
17
18
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
19
|
|
|
@@ -20,7 +21,7 @@ const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
|
20
21
|
|
|
21
22
|
function init() {
|
|
22
23
|
const cwd = process.cwd();
|
|
23
|
-
return
|
|
24
|
+
return config.initConfig(cwd);
|
|
24
25
|
}
|
|
25
26
|
const cli = cac__default();
|
|
26
27
|
cli.command("install", "patch install").action(() => {
|
|
@@ -30,13 +31,13 @@ cli.command("install", "patch install").action(() => {
|
|
|
30
31
|
});
|
|
31
32
|
cli.command("init").action(async () => {
|
|
32
33
|
await init();
|
|
33
|
-
console.log(
|
|
34
|
+
console.log(`\u2728 ${config.configName}.config.ts initialized!`);
|
|
34
35
|
});
|
|
35
36
|
cli.command("extract").action(async () => {
|
|
36
|
-
const { config } = await
|
|
37
|
-
if (config) {
|
|
37
|
+
const { config: config$1 } = await config.getConfig();
|
|
38
|
+
if (config$1) {
|
|
38
39
|
const twPatcher = new index.TailwindcssPatcher();
|
|
39
|
-
const p = await twPatcher.extract(config);
|
|
40
|
+
const p = await twPatcher.extract(config$1.patch);
|
|
40
41
|
console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
|
|
41
42
|
}
|
|
42
43
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cac from 'cac';
|
|
2
|
+
import { getPatchOptions, TailwindcssPatcher, createPatch } from './index.mjs';
|
|
2
3
|
import 'node:path';
|
|
3
4
|
import 'node:fs';
|
|
4
5
|
import 'node:fs/promises';
|
|
@@ -7,10 +8,10 @@ import '@babel/types';
|
|
|
7
8
|
import '@babel/generator';
|
|
8
9
|
import '@babel/traverse';
|
|
9
10
|
import '@babel/parser';
|
|
10
|
-
import
|
|
11
|
+
import { configName, getConfig, initConfig } from '@tailwindcss-mangle/config';
|
|
11
12
|
import 'semver';
|
|
12
13
|
import 'postcss';
|
|
13
|
-
import '
|
|
14
|
+
import 'lilconfig';
|
|
14
15
|
|
|
15
16
|
function init() {
|
|
16
17
|
const cwd = process.cwd();
|
|
@@ -24,13 +25,13 @@ cli.command("install", "patch install").action(() => {
|
|
|
24
25
|
});
|
|
25
26
|
cli.command("init").action(async () => {
|
|
26
27
|
await init();
|
|
27
|
-
console.log(
|
|
28
|
+
console.log(`\u2728 ${configName}.config.ts initialized!`);
|
|
28
29
|
});
|
|
29
30
|
cli.command("extract").action(async () => {
|
|
30
31
|
const { config } = await getConfig();
|
|
31
32
|
if (config) {
|
|
32
33
|
const twPatcher = new TailwindcssPatcher();
|
|
33
|
-
const p = await twPatcher.extract(config);
|
|
34
|
+
const p = await twPatcher.extract(config.patch);
|
|
34
35
|
console.log("\u2728 tailwindcss-patch extract success! file path:\n" + p);
|
|
35
36
|
}
|
|
36
37
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const fs$1 = require('node:fs/promises');
|
|
3
4
|
const path = require('node:path');
|
|
4
5
|
const fs = require('node:fs');
|
|
5
|
-
const fs$1 = require('node:fs/promises');
|
|
6
6
|
const pkg = require('resolve');
|
|
7
7
|
const semver = require('semver');
|
|
8
8
|
const t = require('@babel/types');
|
|
@@ -10,7 +10,8 @@ const generate = require('@babel/generator');
|
|
|
10
10
|
const traverse = require('@babel/traverse');
|
|
11
11
|
const parser = require('@babel/parser');
|
|
12
12
|
const postcss = require('postcss');
|
|
13
|
-
const
|
|
13
|
+
const lilconfig = require('lilconfig');
|
|
14
|
+
const config = require('@tailwindcss-mangle/config');
|
|
14
15
|
|
|
15
16
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
16
17
|
|
|
@@ -26,9 +27,9 @@ function _interopNamespaceCompat(e) {
|
|
|
26
27
|
return n;
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
29
31
|
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
30
32
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
31
|
-
const fs__default$1 = /*#__PURE__*/_interopDefaultCompat(fs$1);
|
|
32
33
|
const pkg__default = /*#__PURE__*/_interopDefaultCompat(pkg);
|
|
33
34
|
const t__namespace = /*#__PURE__*/_interopNamespaceCompat(t);
|
|
34
35
|
const generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
|
|
@@ -182,6 +183,48 @@ class CacheManager {
|
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
|
|
186
|
+
function isObject(value) {
|
|
187
|
+
return value !== null && typeof value === "object";
|
|
188
|
+
}
|
|
189
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
190
|
+
if (!isObject(defaults)) {
|
|
191
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
192
|
+
}
|
|
193
|
+
const object = Object.assign({}, defaults);
|
|
194
|
+
for (const key in baseObject) {
|
|
195
|
+
if (key === "__proto__" || key === "constructor") {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const value = baseObject[key];
|
|
199
|
+
if (value === null || value === void 0) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
206
|
+
object[key] = [...value, ...object[key]];
|
|
207
|
+
} else if (isObject(value) && isObject(object[key])) {
|
|
208
|
+
object[key] = _defu(
|
|
209
|
+
value,
|
|
210
|
+
object[key],
|
|
211
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
212
|
+
merger
|
|
213
|
+
);
|
|
214
|
+
} else {
|
|
215
|
+
object[key] = value;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return object;
|
|
219
|
+
}
|
|
220
|
+
function createDefu(merger) {
|
|
221
|
+
return (...arguments_) => (
|
|
222
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
223
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
const defu = createDefu();
|
|
227
|
+
|
|
185
228
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
186
229
|
const ast = parser.parse(content);
|
|
187
230
|
let hasPatched = false;
|
|
@@ -319,65 +362,11 @@ function inspectPostcssPlugin(content) {
|
|
|
319
362
|
};
|
|
320
363
|
}
|
|
321
364
|
|
|
322
|
-
function isObject(value) {
|
|
323
|
-
return value !== null && typeof value === "object";
|
|
324
|
-
}
|
|
325
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
326
|
-
if (!isObject(defaults)) {
|
|
327
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
328
|
-
}
|
|
329
|
-
const object = Object.assign({}, defaults);
|
|
330
|
-
for (const key in baseObject) {
|
|
331
|
-
if (key === "__proto__" || key === "constructor") {
|
|
332
|
-
continue;
|
|
333
|
-
}
|
|
334
|
-
const value = baseObject[key];
|
|
335
|
-
if (value === null || value === void 0) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
342
|
-
object[key] = [...value, ...object[key]];
|
|
343
|
-
} else if (isObject(value) && isObject(object[key])) {
|
|
344
|
-
object[key] = _defu(
|
|
345
|
-
value,
|
|
346
|
-
object[key],
|
|
347
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
348
|
-
merger
|
|
349
|
-
);
|
|
350
|
-
} else {
|
|
351
|
-
object[key] = value;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return object;
|
|
355
|
-
}
|
|
356
|
-
function createDefu(merger) {
|
|
357
|
-
return (...arguments_) => (
|
|
358
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
359
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
const defu = createDefu();
|
|
363
|
-
|
|
364
365
|
function getDefaultPatchOptions() {
|
|
365
366
|
return {
|
|
366
367
|
overwrite: true
|
|
367
368
|
};
|
|
368
369
|
}
|
|
369
|
-
function getDefaultUserConfig() {
|
|
370
|
-
return {
|
|
371
|
-
output: {
|
|
372
|
-
filename: ".tw-patch/tw-class-list.json",
|
|
373
|
-
removeUniversalSelector: true,
|
|
374
|
-
loose: true
|
|
375
|
-
},
|
|
376
|
-
tailwindcss: {
|
|
377
|
-
cwd: process.cwd()
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
370
|
|
|
382
371
|
function getInstalledPkgJsonPath(options = {}) {
|
|
383
372
|
try {
|
|
@@ -454,15 +443,29 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
454
443
|
|
|
455
444
|
async function processTailwindcss(options) {
|
|
456
445
|
options.cwd = options.cwd ?? process.cwd();
|
|
457
|
-
|
|
458
|
-
|
|
446
|
+
let config = options.config;
|
|
447
|
+
if (!(typeof options.config === "string" && path__default.isAbsolute(options.config))) {
|
|
448
|
+
const moduleName = "tailwind";
|
|
449
|
+
const result = await lilconfig.lilconfig("tailwindcss", {
|
|
450
|
+
searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
|
|
451
|
+
loaders: {
|
|
452
|
+
// 默认支持 js 和 cjs 2种格式
|
|
453
|
+
".js": require,
|
|
454
|
+
".cjs": require
|
|
455
|
+
}
|
|
456
|
+
}).search(options.cwd);
|
|
457
|
+
if (!result) {
|
|
458
|
+
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
459
|
+
}
|
|
460
|
+
config = result.filepath;
|
|
461
|
+
}
|
|
462
|
+
return await postcss__default([
|
|
459
463
|
require("tailwindcss")({
|
|
460
464
|
config
|
|
461
465
|
})
|
|
462
466
|
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
463
467
|
from: void 0
|
|
464
468
|
});
|
|
465
|
-
return res;
|
|
466
469
|
}
|
|
467
470
|
|
|
468
471
|
class TailwindcssPatcher {
|
|
@@ -512,7 +515,7 @@ class TailwindcssPatcher {
|
|
|
512
515
|
return getContexts(basedir);
|
|
513
516
|
}
|
|
514
517
|
async extract(options) {
|
|
515
|
-
const { output, tailwindcss } = options;
|
|
518
|
+
const { output, tailwindcss } = options ?? {};
|
|
516
519
|
if (output && tailwindcss) {
|
|
517
520
|
const { removeUniversalSelector, filename, loose } = output;
|
|
518
521
|
await processTailwindcss(tailwindcss);
|
|
@@ -529,105 +532,23 @@ class TailwindcssPatcher {
|
|
|
529
532
|
}
|
|
530
533
|
}
|
|
531
534
|
|
|
532
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
533
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
534
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
535
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
536
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
537
|
-
const dedent = createDedent({});
|
|
538
|
-
function createDedent(options) {
|
|
539
|
-
dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
540
|
-
return dedent;
|
|
541
|
-
function dedent(strings, ...values) {
|
|
542
|
-
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
543
|
-
const {
|
|
544
|
-
escapeSpecialCharacters = Array.isArray(strings)
|
|
545
|
-
} = options;
|
|
546
|
-
|
|
547
|
-
// first, perform interpolation
|
|
548
|
-
let result = "";
|
|
549
|
-
for (let i = 0; i < raw.length; i++) {
|
|
550
|
-
let next = raw[i];
|
|
551
|
-
if (escapeSpecialCharacters) {
|
|
552
|
-
// handle escaped newlines, backticks, and interpolation characters
|
|
553
|
-
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
|
|
554
|
-
}
|
|
555
|
-
result += next;
|
|
556
|
-
if (i < values.length) {
|
|
557
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
558
|
-
result += values[i];
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
// now strip indentation
|
|
563
|
-
const lines = result.split("\n");
|
|
564
|
-
let mindent = null;
|
|
565
|
-
for (const l of lines) {
|
|
566
|
-
const m = l.match(/^(\s+)\S+/);
|
|
567
|
-
if (m) {
|
|
568
|
-
const indent = m[1].length;
|
|
569
|
-
if (!mindent) {
|
|
570
|
-
// this is the first indented line
|
|
571
|
-
mindent = indent;
|
|
572
|
-
} else {
|
|
573
|
-
mindent = Math.min(mindent, indent);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
if (mindent !== null) {
|
|
578
|
-
const m = mindent; // appease TypeScript
|
|
579
|
-
result = lines
|
|
580
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/7140
|
|
581
|
-
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
582
|
-
.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
|
|
583
|
-
}
|
|
584
|
-
return result
|
|
585
|
-
// dedent eats leading and trailing whitespace too
|
|
586
|
-
.trim()
|
|
587
|
-
// handle escaped newlines at the end to ensure they don't get stripped too
|
|
588
|
-
.replace(/\\n/g, "\n");
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
function getConfig(cwd) {
|
|
593
|
-
return c12.loadConfig({
|
|
594
|
-
name: "tailwindcss-patch",
|
|
595
|
-
defaults: {
|
|
596
|
-
...getDefaultUserConfig()
|
|
597
|
-
},
|
|
598
|
-
cwd
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
const defineConfig = c12.createDefineConfig();
|
|
602
|
-
function initConfig(cwd) {
|
|
603
|
-
return fs__default$1.writeFile(
|
|
604
|
-
path__default.resolve(cwd, "tailwindcss-patch.config.ts"),
|
|
605
|
-
dedent`
|
|
606
|
-
import { defineConfig } from 'tailwindcss-patch'
|
|
607
|
-
|
|
608
|
-
export default defineConfig({})
|
|
609
|
-
`,
|
|
610
|
-
"utf8"
|
|
611
|
-
);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
535
|
exports.CacheManager = CacheManager;
|
|
615
536
|
exports.TailwindcssPatcher = TailwindcssPatcher;
|
|
616
537
|
exports.createPatch = createPatch;
|
|
617
|
-
exports.defineConfig = defineConfig;
|
|
618
538
|
exports.ensureDir = ensureDir;
|
|
619
539
|
exports.ensureFileContent = ensureFileContent;
|
|
620
540
|
exports.getCacheOptions = getCacheOptions;
|
|
621
541
|
exports.getClassCacheSet = getClassCacheSet;
|
|
622
542
|
exports.getClassCaches = getClassCaches;
|
|
623
|
-
exports.getConfig = getConfig;
|
|
624
543
|
exports.getContexts = getContexts;
|
|
625
544
|
exports.getInstalledPkgJsonPath = getInstalledPkgJsonPath;
|
|
626
545
|
exports.getPatchOptions = getPatchOptions;
|
|
627
546
|
exports.getTailwindcssEntry = getTailwindcssEntry;
|
|
628
|
-
exports.initConfig = initConfig;
|
|
629
547
|
exports.inspectPostcssPlugin = inspectPostcssPlugin;
|
|
630
548
|
exports.inspectProcessTailwindFeaturesReturnContext = inspectProcessTailwindFeaturesReturnContext;
|
|
631
549
|
exports.internalPatch = internalPatch;
|
|
632
550
|
exports.monkeyPatchForExposingContext = monkeyPatchForExposingContext;
|
|
633
551
|
exports.requireResolve = requireResolve;
|
|
552
|
+
Object.keys(config).forEach(function (k) {
|
|
553
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = config[k];
|
|
554
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Rule, Node } from 'postcss';
|
|
2
2
|
import { Config } from 'tailwindcss';
|
|
3
|
-
import
|
|
3
|
+
import { UserConfig } from '@tailwindcss-mangle/config';
|
|
4
|
+
export * from '@tailwindcss-mangle/config';
|
|
4
5
|
import { SyncOpts } from 'resolve';
|
|
5
6
|
|
|
6
7
|
type CacheStrategy = 'merge' | 'overwrite';
|
|
@@ -37,7 +38,7 @@ type TailwindcssClassCache = Map<string, ({
|
|
|
37
38
|
} | Rule)[]>;
|
|
38
39
|
type TailwindcssRuntimeContext = {
|
|
39
40
|
applyClassCache: Map<any, any>;
|
|
40
|
-
candidateRuleCache: Map<string |
|
|
41
|
+
candidateRuleCache: Map<string | string, Set<[
|
|
41
42
|
{
|
|
42
43
|
arbitrary: any;
|
|
43
44
|
index: any;
|
|
@@ -49,7 +50,7 @@ type TailwindcssRuntimeContext = {
|
|
|
49
50
|
},
|
|
50
51
|
Node
|
|
51
52
|
]>>;
|
|
52
|
-
candidateRuleMap: Map<string |
|
|
53
|
+
candidateRuleMap: Map<string | string, [object, Node][]>;
|
|
53
54
|
changedContent: any[];
|
|
54
55
|
classCache: TailwindcssClassCache;
|
|
55
56
|
disposables: any[];
|
|
@@ -58,7 +59,7 @@ type TailwindcssRuntimeContext = {
|
|
|
58
59
|
getVariants: Function;
|
|
59
60
|
markInvalidUtilityCandidate: Function;
|
|
60
61
|
markInvalidUtilityNode: Function;
|
|
61
|
-
notClassCache: Set<
|
|
62
|
+
notClassCache: Set<string>;
|
|
62
63
|
offsets: {
|
|
63
64
|
layerPositions: object;
|
|
64
65
|
offsets: object;
|
|
@@ -73,20 +74,6 @@ type TailwindcssRuntimeContext = {
|
|
|
73
74
|
variantMap: Map<string, [[object, Function]]>;
|
|
74
75
|
variantOptions: Map<string, object>;
|
|
75
76
|
};
|
|
76
|
-
interface UserConfig {
|
|
77
|
-
output?: {
|
|
78
|
-
filename?: string;
|
|
79
|
-
loose?: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* @description remove * in output json
|
|
82
|
-
*/
|
|
83
|
-
removeUniversalSelector?: boolean;
|
|
84
|
-
};
|
|
85
|
-
tailwindcss?: {
|
|
86
|
-
cwd?: string;
|
|
87
|
-
config?: string;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
77
|
type DeepRequired<T> = {
|
|
91
78
|
[K in keyof T]: Required<DeepRequired<T[K]>>;
|
|
92
79
|
};
|
|
@@ -127,7 +114,7 @@ declare class TailwindcssPatcher {
|
|
|
127
114
|
removeUniversalSelector?: boolean;
|
|
128
115
|
}): Set<string>;
|
|
129
116
|
getContexts(basedir?: string): TailwindcssRuntimeContext[];
|
|
130
|
-
extract(options: UserConfig): Promise<string | undefined>;
|
|
117
|
+
extract(options: UserConfig['patch']): Promise<string | undefined>;
|
|
131
118
|
}
|
|
132
119
|
|
|
133
120
|
declare function getTailwindcssEntry(basedir?: string): string;
|
|
@@ -155,12 +142,8 @@ declare function monkeyPatchForExposingContext(twDir: string, opt: InternalPatch
|
|
|
155
142
|
} & Record<string, any>;
|
|
156
143
|
declare function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined;
|
|
157
144
|
|
|
158
|
-
declare function getConfig(cwd?: string): Promise<c12.ResolvedConfig<UserConfig, c12.ConfigLayerMeta>>;
|
|
159
|
-
declare const defineConfig: c12.DefineConfig<UserConfig, c12.ConfigLayerMeta>;
|
|
160
|
-
declare function initConfig(cwd: string): Promise<void>;
|
|
161
|
-
|
|
162
145
|
declare function ensureFileContent(filepaths: string | string[]): string | undefined;
|
|
163
146
|
declare function requireResolve(id: string, opts?: SyncOpts): string;
|
|
164
147
|
declare function ensureDir(p: string): Promise<void>;
|
|
165
148
|
|
|
166
|
-
export { CacheManager, CacheOptions, CacheStrategy, DeepRequired, InternalCacheOptions, InternalPatchOptions, PatchOptions, TailwindcssClassCache, TailwindcssPatcher, TailwindcssPatcherOptions, TailwindcssRuntimeContext,
|
|
149
|
+
export { CacheManager, CacheOptions, CacheStrategy, DeepRequired, InternalCacheOptions, InternalPatchOptions, PatchOptions, TailwindcssClassCache, TailwindcssPatcher, TailwindcssPatcherOptions, TailwindcssRuntimeContext, createPatch, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import fs$1 from 'node:fs/promises';
|
|
1
2
|
import path, { dirname } from 'node:path';
|
|
2
3
|
import fs from 'node:fs';
|
|
3
|
-
import fs$1 from 'node:fs/promises';
|
|
4
4
|
import pkg from 'resolve';
|
|
5
5
|
import { gte } from 'semver';
|
|
6
6
|
import * as t from '@babel/types';
|
|
@@ -8,7 +8,17 @@ import generate from '@babel/generator';
|
|
|
8
8
|
import traverse from '@babel/traverse';
|
|
9
9
|
import { parse } from '@babel/parser';
|
|
10
10
|
import postcss from 'postcss';
|
|
11
|
-
import {
|
|
11
|
+
import { lilconfig } from 'lilconfig';
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
// -- Unbuild CommonJS Shims --
|
|
15
|
+
import __cjs_url__ from 'url';
|
|
16
|
+
import __cjs_path__ from 'path';
|
|
17
|
+
import __cjs_mod__ from 'module';
|
|
18
|
+
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = __cjs_path__.dirname(__filename);
|
|
20
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
21
|
+
export * from '@tailwindcss-mangle/config';
|
|
12
22
|
|
|
13
23
|
const { sync } = pkg;
|
|
14
24
|
function ensureFileContent(filepaths) {
|
|
@@ -157,6 +167,48 @@ class CacheManager {
|
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
169
|
|
|
170
|
+
function isObject(value) {
|
|
171
|
+
return value !== null && typeof value === "object";
|
|
172
|
+
}
|
|
173
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
174
|
+
if (!isObject(defaults)) {
|
|
175
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
176
|
+
}
|
|
177
|
+
const object = Object.assign({}, defaults);
|
|
178
|
+
for (const key in baseObject) {
|
|
179
|
+
if (key === "__proto__" || key === "constructor") {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const value = baseObject[key];
|
|
183
|
+
if (value === null || value === void 0) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
190
|
+
object[key] = [...value, ...object[key]];
|
|
191
|
+
} else if (isObject(value) && isObject(object[key])) {
|
|
192
|
+
object[key] = _defu(
|
|
193
|
+
value,
|
|
194
|
+
object[key],
|
|
195
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
196
|
+
merger
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
object[key] = value;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return object;
|
|
203
|
+
}
|
|
204
|
+
function createDefu(merger) {
|
|
205
|
+
return (...arguments_) => (
|
|
206
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
207
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const defu = createDefu();
|
|
211
|
+
|
|
160
212
|
function inspectProcessTailwindFeaturesReturnContext(content) {
|
|
161
213
|
const ast = parse(content);
|
|
162
214
|
let hasPatched = false;
|
|
@@ -294,65 +346,11 @@ function inspectPostcssPlugin(content) {
|
|
|
294
346
|
};
|
|
295
347
|
}
|
|
296
348
|
|
|
297
|
-
function isObject(value) {
|
|
298
|
-
return value !== null && typeof value === "object";
|
|
299
|
-
}
|
|
300
|
-
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
301
|
-
if (!isObject(defaults)) {
|
|
302
|
-
return _defu(baseObject, {}, namespace, merger);
|
|
303
|
-
}
|
|
304
|
-
const object = Object.assign({}, defaults);
|
|
305
|
-
for (const key in baseObject) {
|
|
306
|
-
if (key === "__proto__" || key === "constructor") {
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
const value = baseObject[key];
|
|
310
|
-
if (value === null || value === void 0) {
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
if (merger && merger(object, key, value, namespace)) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
317
|
-
object[key] = [...value, ...object[key]];
|
|
318
|
-
} else if (isObject(value) && isObject(object[key])) {
|
|
319
|
-
object[key] = _defu(
|
|
320
|
-
value,
|
|
321
|
-
object[key],
|
|
322
|
-
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
323
|
-
merger
|
|
324
|
-
);
|
|
325
|
-
} else {
|
|
326
|
-
object[key] = value;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return object;
|
|
330
|
-
}
|
|
331
|
-
function createDefu(merger) {
|
|
332
|
-
return (...arguments_) => (
|
|
333
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
334
|
-
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
const defu = createDefu();
|
|
338
|
-
|
|
339
349
|
function getDefaultPatchOptions() {
|
|
340
350
|
return {
|
|
341
351
|
overwrite: true
|
|
342
352
|
};
|
|
343
353
|
}
|
|
344
|
-
function getDefaultUserConfig() {
|
|
345
|
-
return {
|
|
346
|
-
output: {
|
|
347
|
-
filename: ".tw-patch/tw-class-list.json",
|
|
348
|
-
removeUniversalSelector: true,
|
|
349
|
-
loose: true
|
|
350
|
-
},
|
|
351
|
-
tailwindcss: {
|
|
352
|
-
cwd: process.cwd()
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
354
|
|
|
357
355
|
function getInstalledPkgJsonPath(options = {}) {
|
|
358
356
|
try {
|
|
@@ -429,15 +427,29 @@ function internalPatch(pkgJsonPath, options) {
|
|
|
429
427
|
|
|
430
428
|
async function processTailwindcss(options) {
|
|
431
429
|
options.cwd = options.cwd ?? process.cwd();
|
|
432
|
-
|
|
433
|
-
|
|
430
|
+
let config = options.config;
|
|
431
|
+
if (!(typeof options.config === "string" && path.isAbsolute(options.config))) {
|
|
432
|
+
const moduleName = "tailwind";
|
|
433
|
+
const result = await lilconfig("tailwindcss", {
|
|
434
|
+
searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.cjs`],
|
|
435
|
+
loaders: {
|
|
436
|
+
// 默认支持 js 和 cjs 2种格式
|
|
437
|
+
".js": require,
|
|
438
|
+
".cjs": require
|
|
439
|
+
}
|
|
440
|
+
}).search(options.cwd);
|
|
441
|
+
if (!result) {
|
|
442
|
+
throw new Error(`No TailwindCSS Config found in: ${options.cwd}`);
|
|
443
|
+
}
|
|
444
|
+
config = result.filepath;
|
|
445
|
+
}
|
|
446
|
+
return await postcss([
|
|
434
447
|
require("tailwindcss")({
|
|
435
448
|
config
|
|
436
449
|
})
|
|
437
450
|
]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
|
|
438
451
|
from: void 0
|
|
439
452
|
});
|
|
440
|
-
return res;
|
|
441
453
|
}
|
|
442
454
|
|
|
443
455
|
class TailwindcssPatcher {
|
|
@@ -487,7 +499,7 @@ class TailwindcssPatcher {
|
|
|
487
499
|
return getContexts(basedir);
|
|
488
500
|
}
|
|
489
501
|
async extract(options) {
|
|
490
|
-
const { output, tailwindcss } = options;
|
|
502
|
+
const { output, tailwindcss } = options ?? {};
|
|
491
503
|
if (output && tailwindcss) {
|
|
492
504
|
const { removeUniversalSelector, filename, loose } = output;
|
|
493
505
|
await processTailwindcss(tailwindcss);
|
|
@@ -504,95 +516,4 @@ class TailwindcssPatcher {
|
|
|
504
516
|
}
|
|
505
517
|
}
|
|
506
518
|
|
|
507
|
-
|
|
508
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
509
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
510
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
511
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
512
|
-
const dedent = createDedent({});
|
|
513
|
-
function createDedent(options) {
|
|
514
|
-
dedent.withOptions = newOptions => createDedent(_objectSpread(_objectSpread({}, options), newOptions));
|
|
515
|
-
return dedent;
|
|
516
|
-
function dedent(strings, ...values) {
|
|
517
|
-
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
518
|
-
const {
|
|
519
|
-
escapeSpecialCharacters = Array.isArray(strings)
|
|
520
|
-
} = options;
|
|
521
|
-
|
|
522
|
-
// first, perform interpolation
|
|
523
|
-
let result = "";
|
|
524
|
-
for (let i = 0; i < raw.length; i++) {
|
|
525
|
-
let next = raw[i];
|
|
526
|
-
if (escapeSpecialCharacters) {
|
|
527
|
-
// handle escaped newlines, backticks, and interpolation characters
|
|
528
|
-
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\{/g, "{");
|
|
529
|
-
}
|
|
530
|
-
result += next;
|
|
531
|
-
if (i < values.length) {
|
|
532
|
-
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
533
|
-
result += values[i];
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
// now strip indentation
|
|
538
|
-
const lines = result.split("\n");
|
|
539
|
-
let mindent = null;
|
|
540
|
-
for (const l of lines) {
|
|
541
|
-
const m = l.match(/^(\s+)\S+/);
|
|
542
|
-
if (m) {
|
|
543
|
-
const indent = m[1].length;
|
|
544
|
-
if (!mindent) {
|
|
545
|
-
// this is the first indented line
|
|
546
|
-
mindent = indent;
|
|
547
|
-
} else {
|
|
548
|
-
mindent = Math.min(mindent, indent);
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
if (mindent !== null) {
|
|
553
|
-
const m = mindent; // appease TypeScript
|
|
554
|
-
result = lines
|
|
555
|
-
// https://github.com/typescript-eslint/typescript-eslint/issues/7140
|
|
556
|
-
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
|
|
557
|
-
.map(l => l[0] === " " || l[0] === "\t" ? l.slice(m) : l).join("\n");
|
|
558
|
-
}
|
|
559
|
-
return result
|
|
560
|
-
// dedent eats leading and trailing whitespace too
|
|
561
|
-
.trim()
|
|
562
|
-
// handle escaped newlines at the end to ensure they don't get stripped too
|
|
563
|
-
.replace(/\\n/g, "\n");
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
function getConfig(cwd) {
|
|
568
|
-
return loadConfig({
|
|
569
|
-
name: "tailwindcss-patch",
|
|
570
|
-
defaults: {
|
|
571
|
-
...getDefaultUserConfig()
|
|
572
|
-
},
|
|
573
|
-
cwd
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
const defineConfig = createDefineConfig();
|
|
577
|
-
function initConfig(cwd) {
|
|
578
|
-
return fs$1.writeFile(
|
|
579
|
-
path.resolve(cwd, "tailwindcss-patch.config.ts"),
|
|
580
|
-
dedent`
|
|
581
|
-
import { defineConfig } from 'tailwindcss-patch'
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
// -- Unbuild CommonJS Shims --
|
|
586
|
-
import __cjs_url__ from 'url';
|
|
587
|
-
import __cjs_path__ from 'path';
|
|
588
|
-
import __cjs_mod__ from 'module';
|
|
589
|
-
const __filename = __cjs_url__.fileURLToPath(import.meta.url);
|
|
590
|
-
const __dirname = __cjs_path__.dirname(__filename);
|
|
591
|
-
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
592
|
-
export default defineConfig({})
|
|
593
|
-
`,
|
|
594
|
-
"utf8"
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
export { CacheManager, TailwindcssPatcher, createPatch, defineConfig, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getConfig, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, initConfig, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
|
|
519
|
+
export { CacheManager, TailwindcssPatcher, createPatch, ensureDir, ensureFileContent, getCacheOptions, getClassCacheSet, getClassCaches, getContexts, getInstalledPkgJsonPath, getPatchOptions, getTailwindcssEntry, inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext, internalPatch, monkeyPatchForExposingContext, requireResolve };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss-patch",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "patch tailwindcss for exposing context and extract classes",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -57,15 +57,16 @@
|
|
|
57
57
|
"tailwindcss": "^3.3.3"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@babel/generator": "^7.22.
|
|
61
|
-
"@babel/parser": "^7.22.
|
|
62
|
-
"@babel/traverse": "^7.22.
|
|
63
|
-
"@babel/types": "^7.22.
|
|
64
|
-
"c12": "^1.4.2",
|
|
60
|
+
"@babel/generator": "^7.22.10",
|
|
61
|
+
"@babel/parser": "^7.22.10",
|
|
62
|
+
"@babel/traverse": "^7.22.10",
|
|
63
|
+
"@babel/types": "^7.22.10",
|
|
65
64
|
"cac": "^6.7.14",
|
|
65
|
+
"lilconfig": "^2.1.0",
|
|
66
66
|
"postcss": "^8.4.27",
|
|
67
67
|
"resolve": "^1.22.4",
|
|
68
|
-
"semver": "^7.5.4"
|
|
68
|
+
"semver": "^7.5.4",
|
|
69
|
+
"@tailwindcss-mangle/config": "^1.0.0"
|
|
69
70
|
},
|
|
70
71
|
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
|
|
71
72
|
"repository": {
|