@tailwindcss-mangle/core 5.1.0 → 5.1.2-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/index.cjs +49 -45
- package/dist/index.js +49 -45
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -264,7 +264,7 @@ var Context = class {
|
|
|
264
264
|
const { cwd, classList: _classList, transformerOptions } = opts;
|
|
265
265
|
const { config, cwd: configCwd } = await (0, import_config.getConfig)(cwd);
|
|
266
266
|
this.configRoot = configCwd ?? cwd ?? import_node_process.default.cwd();
|
|
267
|
-
|
|
267
|
+
const normalizedTransformer = transformerOptions ? { ...transformerOptions, registry: { ...transformerOptions.registry } } : void 0;
|
|
268
268
|
if (normalizedTransformer?.registry?.mapping === true) {
|
|
269
269
|
const fallback = config?.transformer?.registry?.mapping;
|
|
270
270
|
if (typeof fallback === "function") {
|
|
@@ -323,7 +323,8 @@ var Context = class {
|
|
|
323
323
|
import_fs_extra.default.writeFileSync(outputFile, JSON.stringify(arr, null, 2));
|
|
324
324
|
}
|
|
325
325
|
} catch (error) {
|
|
326
|
-
|
|
326
|
+
import_node_process.default.stderr.write(`[tailwindcss-mangle]: ${String(error)}
|
|
327
|
+
`);
|
|
327
328
|
}
|
|
328
329
|
}
|
|
329
330
|
};
|
|
@@ -499,31 +500,15 @@ function jsHandler(rawSource, options) {
|
|
|
499
500
|
}
|
|
500
501
|
|
|
501
502
|
// src/svelte/index.ts
|
|
502
|
-
var import_compiler = require("svelte/compiler");
|
|
503
503
|
var import_magic_string3 = __toESM(require("magic-string"), 1);
|
|
504
|
-
|
|
505
|
-
const { ctx, id } = options;
|
|
506
|
-
const ms = new import_magic_string3.default(rawSource);
|
|
507
|
-
try {
|
|
508
|
-
const ast = (0, import_compiler.parse)(rawSource, {
|
|
509
|
-
filename: id || "unknown.svelte"
|
|
510
|
-
});
|
|
511
|
-
await processSvelteAst(ast, ms, ctx, id);
|
|
512
|
-
return {
|
|
513
|
-
code: ms.toString(),
|
|
514
|
-
get map() {
|
|
515
|
-
return ms.generateMap();
|
|
516
|
-
}
|
|
517
|
-
};
|
|
518
|
-
} catch (error) {
|
|
519
|
-
return jsHandler(rawSource, options);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
504
|
+
var import_compiler = require("svelte/compiler");
|
|
522
505
|
async function processSvelteAst(ast, ms, ctx, id) {
|
|
523
506
|
const { replaceMap, classGenerator } = ctx;
|
|
524
507
|
const stylePromises = [];
|
|
525
508
|
async function walk(node) {
|
|
526
|
-
if (!node)
|
|
509
|
+
if (!node) {
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
527
512
|
if (node.type === "Attribute" && node.name === "class") {
|
|
528
513
|
for (const attrValue of node.value) {
|
|
529
514
|
if (attrValue.type === "Text") {
|
|
@@ -590,56 +575,47 @@ async function processSvelteAst(ast, ms, ctx, id) {
|
|
|
590
575
|
await walk(ast);
|
|
591
576
|
await Promise.all(stylePromises);
|
|
592
577
|
}
|
|
593
|
-
|
|
594
|
-
// src/vue/index.ts
|
|
595
|
-
var import_compiler_sfc = require("@vue/compiler-sfc");
|
|
596
|
-
var import_magic_string4 = __toESM(require("magic-string"), 1);
|
|
597
|
-
async function vueHandler(rawSource, options) {
|
|
578
|
+
async function svelteHandler(rawSource, options) {
|
|
598
579
|
const { ctx, id } = options;
|
|
599
|
-
const ms = new
|
|
580
|
+
const ms = new import_magic_string3.default(rawSource);
|
|
600
581
|
try {
|
|
601
|
-
const
|
|
602
|
-
filename: id || "unknown.
|
|
582
|
+
const ast = (0, import_compiler.parse)(rawSource, {
|
|
583
|
+
filename: id || "unknown.svelte"
|
|
603
584
|
});
|
|
604
|
-
|
|
605
|
-
await processTemplate(descriptor.template, ms, ctx, id);
|
|
606
|
-
}
|
|
607
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
608
|
-
await processScript(descriptor, ms, ctx, id);
|
|
609
|
-
}
|
|
610
|
-
if (descriptor.styles && descriptor.styles.length > 0) {
|
|
611
|
-
await processStyles(descriptor.styles, ms, ctx, id);
|
|
612
|
-
}
|
|
585
|
+
await processSvelteAst(ast, ms, ctx, id);
|
|
613
586
|
return {
|
|
614
587
|
code: ms.toString(),
|
|
615
588
|
get map() {
|
|
616
589
|
return ms.generateMap();
|
|
617
590
|
}
|
|
618
591
|
};
|
|
619
|
-
} catch
|
|
592
|
+
} catch {
|
|
620
593
|
return jsHandler(rawSource, options);
|
|
621
594
|
}
|
|
622
595
|
}
|
|
596
|
+
|
|
597
|
+
// src/vue/index.ts
|
|
598
|
+
var import_compiler_sfc = require("@vue/compiler-sfc");
|
|
599
|
+
var import_magic_string4 = __toESM(require("magic-string"), 1);
|
|
623
600
|
async function processTemplate(template, ms, ctx, id) {
|
|
624
601
|
const { replaceMap, classGenerator } = ctx;
|
|
625
602
|
if (!template.ast) {
|
|
626
603
|
try {
|
|
627
|
-
|
|
604
|
+
(0, import_compiler_sfc.compileTemplate)({
|
|
628
605
|
source: template.content,
|
|
629
606
|
filename: id || "unknown.vue",
|
|
630
|
-
id:
|
|
607
|
+
id: `${id || "unknown"}?template`
|
|
631
608
|
});
|
|
632
609
|
} catch {
|
|
633
610
|
return;
|
|
634
611
|
}
|
|
635
612
|
}
|
|
636
613
|
const classAttrRegex = /\sclass\s*=\s*["']([^"']+)["']/g;
|
|
637
|
-
let match;
|
|
638
614
|
const templateStart = template.loc.start.offset;
|
|
639
615
|
const templateEnd = template.loc.end.offset;
|
|
640
616
|
const templateContent = ms.original.slice(templateStart, templateEnd);
|
|
641
617
|
const replacements = [];
|
|
642
|
-
|
|
618
|
+
for (const match of templateContent.matchAll(classAttrRegex)) {
|
|
643
619
|
const fullMatch = match[0];
|
|
644
620
|
const classValue = match[1];
|
|
645
621
|
if (classValue === void 0) {
|
|
@@ -674,7 +650,9 @@ async function processTemplate(template, ms, ctx, id) {
|
|
|
674
650
|
}
|
|
675
651
|
async function processScript(descriptor, ms, ctx, id) {
|
|
676
652
|
const script = descriptor.scriptSetup || descriptor.script;
|
|
677
|
-
if (!script)
|
|
653
|
+
if (!script) {
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
678
656
|
const scriptContent = ms.original.slice(
|
|
679
657
|
script.loc.start.offset,
|
|
680
658
|
script.loc.end.offset
|
|
@@ -706,6 +684,32 @@ async function processStyles(styles, ms, ctx, id) {
|
|
|
706
684
|
}
|
|
707
685
|
}
|
|
708
686
|
}
|
|
687
|
+
async function vueHandler(rawSource, options) {
|
|
688
|
+
const { ctx, id } = options;
|
|
689
|
+
const ms = new import_magic_string4.default(rawSource);
|
|
690
|
+
try {
|
|
691
|
+
const { descriptor } = (0, import_compiler_sfc.parse)(rawSource, {
|
|
692
|
+
filename: id || "unknown.vue"
|
|
693
|
+
});
|
|
694
|
+
if (descriptor.template) {
|
|
695
|
+
await processTemplate(descriptor.template, ms, ctx, id);
|
|
696
|
+
}
|
|
697
|
+
if (descriptor.script || descriptor.scriptSetup) {
|
|
698
|
+
await processScript(descriptor, ms, ctx, id);
|
|
699
|
+
}
|
|
700
|
+
if (descriptor.styles && descriptor.styles.length > 0) {
|
|
701
|
+
await processStyles(descriptor.styles, ms, ctx, id);
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
code: ms.toString(),
|
|
705
|
+
get map() {
|
|
706
|
+
return ms.generateMap();
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
} catch {
|
|
710
|
+
return jsHandler(rawSource, options);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
709
713
|
// Annotate the CommonJS export names for ESM import in node:
|
|
710
714
|
0 && (module.exports = {
|
|
711
715
|
ClassGenerator,
|
package/dist/index.js
CHANGED
|
@@ -235,7 +235,7 @@ var Context = class {
|
|
|
235
235
|
const { cwd, classList: _classList, transformerOptions } = opts;
|
|
236
236
|
const { config, cwd: configCwd } = await getConfig(cwd);
|
|
237
237
|
this.configRoot = configCwd ?? cwd ?? process.cwd();
|
|
238
|
-
|
|
238
|
+
const normalizedTransformer = transformerOptions ? { ...transformerOptions, registry: { ...transformerOptions.registry } } : void 0;
|
|
239
239
|
if (normalizedTransformer?.registry?.mapping === true) {
|
|
240
240
|
const fallback = config?.transformer?.registry?.mapping;
|
|
241
241
|
if (typeof fallback === "function") {
|
|
@@ -294,7 +294,8 @@ var Context = class {
|
|
|
294
294
|
fs.writeFileSync(outputFile, JSON.stringify(arr, null, 2));
|
|
295
295
|
}
|
|
296
296
|
} catch (error) {
|
|
297
|
-
|
|
297
|
+
process.stderr.write(`[tailwindcss-mangle]: ${String(error)}
|
|
298
|
+
`);
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
};
|
|
@@ -470,31 +471,15 @@ function jsHandler(rawSource, options) {
|
|
|
470
471
|
}
|
|
471
472
|
|
|
472
473
|
// src/svelte/index.ts
|
|
473
|
-
import { parse as parse2 } from "svelte/compiler";
|
|
474
474
|
import MagicString3 from "magic-string";
|
|
475
|
-
|
|
476
|
-
const { ctx, id } = options;
|
|
477
|
-
const ms = new MagicString3(rawSource);
|
|
478
|
-
try {
|
|
479
|
-
const ast = parse2(rawSource, {
|
|
480
|
-
filename: id || "unknown.svelte"
|
|
481
|
-
});
|
|
482
|
-
await processSvelteAst(ast, ms, ctx, id);
|
|
483
|
-
return {
|
|
484
|
-
code: ms.toString(),
|
|
485
|
-
get map() {
|
|
486
|
-
return ms.generateMap();
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
} catch (error) {
|
|
490
|
-
return jsHandler(rawSource, options);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
475
|
+
import { parse as parse2 } from "svelte/compiler";
|
|
493
476
|
async function processSvelteAst(ast, ms, ctx, id) {
|
|
494
477
|
const { replaceMap, classGenerator } = ctx;
|
|
495
478
|
const stylePromises = [];
|
|
496
479
|
async function walk(node) {
|
|
497
|
-
if (!node)
|
|
480
|
+
if (!node) {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
498
483
|
if (node.type === "Attribute" && node.name === "class") {
|
|
499
484
|
for (const attrValue of node.value) {
|
|
500
485
|
if (attrValue.type === "Text") {
|
|
@@ -561,56 +546,47 @@ async function processSvelteAst(ast, ms, ctx, id) {
|
|
|
561
546
|
await walk(ast);
|
|
562
547
|
await Promise.all(stylePromises);
|
|
563
548
|
}
|
|
564
|
-
|
|
565
|
-
// src/vue/index.ts
|
|
566
|
-
import { compileTemplate, parse as parse3 } from "@vue/compiler-sfc";
|
|
567
|
-
import MagicString4 from "magic-string";
|
|
568
|
-
async function vueHandler(rawSource, options) {
|
|
549
|
+
async function svelteHandler(rawSource, options) {
|
|
569
550
|
const { ctx, id } = options;
|
|
570
|
-
const ms = new
|
|
551
|
+
const ms = new MagicString3(rawSource);
|
|
571
552
|
try {
|
|
572
|
-
const
|
|
573
|
-
filename: id || "unknown.
|
|
553
|
+
const ast = parse2(rawSource, {
|
|
554
|
+
filename: id || "unknown.svelte"
|
|
574
555
|
});
|
|
575
|
-
|
|
576
|
-
await processTemplate(descriptor.template, ms, ctx, id);
|
|
577
|
-
}
|
|
578
|
-
if (descriptor.script || descriptor.scriptSetup) {
|
|
579
|
-
await processScript(descriptor, ms, ctx, id);
|
|
580
|
-
}
|
|
581
|
-
if (descriptor.styles && descriptor.styles.length > 0) {
|
|
582
|
-
await processStyles(descriptor.styles, ms, ctx, id);
|
|
583
|
-
}
|
|
556
|
+
await processSvelteAst(ast, ms, ctx, id);
|
|
584
557
|
return {
|
|
585
558
|
code: ms.toString(),
|
|
586
559
|
get map() {
|
|
587
560
|
return ms.generateMap();
|
|
588
561
|
}
|
|
589
562
|
};
|
|
590
|
-
} catch
|
|
563
|
+
} catch {
|
|
591
564
|
return jsHandler(rawSource, options);
|
|
592
565
|
}
|
|
593
566
|
}
|
|
567
|
+
|
|
568
|
+
// src/vue/index.ts
|
|
569
|
+
import { compileTemplate, parse as parse3 } from "@vue/compiler-sfc";
|
|
570
|
+
import MagicString4 from "magic-string";
|
|
594
571
|
async function processTemplate(template, ms, ctx, id) {
|
|
595
572
|
const { replaceMap, classGenerator } = ctx;
|
|
596
573
|
if (!template.ast) {
|
|
597
574
|
try {
|
|
598
|
-
|
|
575
|
+
compileTemplate({
|
|
599
576
|
source: template.content,
|
|
600
577
|
filename: id || "unknown.vue",
|
|
601
|
-
id:
|
|
578
|
+
id: `${id || "unknown"}?template`
|
|
602
579
|
});
|
|
603
580
|
} catch {
|
|
604
581
|
return;
|
|
605
582
|
}
|
|
606
583
|
}
|
|
607
584
|
const classAttrRegex = /\sclass\s*=\s*["']([^"']+)["']/g;
|
|
608
|
-
let match;
|
|
609
585
|
const templateStart = template.loc.start.offset;
|
|
610
586
|
const templateEnd = template.loc.end.offset;
|
|
611
587
|
const templateContent = ms.original.slice(templateStart, templateEnd);
|
|
612
588
|
const replacements = [];
|
|
613
|
-
|
|
589
|
+
for (const match of templateContent.matchAll(classAttrRegex)) {
|
|
614
590
|
const fullMatch = match[0];
|
|
615
591
|
const classValue = match[1];
|
|
616
592
|
if (classValue === void 0) {
|
|
@@ -645,7 +621,9 @@ async function processTemplate(template, ms, ctx, id) {
|
|
|
645
621
|
}
|
|
646
622
|
async function processScript(descriptor, ms, ctx, id) {
|
|
647
623
|
const script = descriptor.scriptSetup || descriptor.script;
|
|
648
|
-
if (!script)
|
|
624
|
+
if (!script) {
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
649
627
|
const scriptContent = ms.original.slice(
|
|
650
628
|
script.loc.start.offset,
|
|
651
629
|
script.loc.end.offset
|
|
@@ -677,6 +655,32 @@ async function processStyles(styles, ms, ctx, id) {
|
|
|
677
655
|
}
|
|
678
656
|
}
|
|
679
657
|
}
|
|
658
|
+
async function vueHandler(rawSource, options) {
|
|
659
|
+
const { ctx, id } = options;
|
|
660
|
+
const ms = new MagicString4(rawSource);
|
|
661
|
+
try {
|
|
662
|
+
const { descriptor } = parse3(rawSource, {
|
|
663
|
+
filename: id || "unknown.vue"
|
|
664
|
+
});
|
|
665
|
+
if (descriptor.template) {
|
|
666
|
+
await processTemplate(descriptor.template, ms, ctx, id);
|
|
667
|
+
}
|
|
668
|
+
if (descriptor.script || descriptor.scriptSetup) {
|
|
669
|
+
await processScript(descriptor, ms, ctx, id);
|
|
670
|
+
}
|
|
671
|
+
if (descriptor.styles && descriptor.styles.length > 0) {
|
|
672
|
+
await processStyles(descriptor.styles, ms, ctx, id);
|
|
673
|
+
}
|
|
674
|
+
return {
|
|
675
|
+
code: ms.toString(),
|
|
676
|
+
get map() {
|
|
677
|
+
return ms.generateMap();
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
} catch {
|
|
681
|
+
return jsHandler(rawSource, options);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
680
684
|
var export_ClassGenerator = shared_exports.ClassGenerator;
|
|
681
685
|
export {
|
|
682
686
|
export_ClassGenerator as ClassGenerator,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailwindcss-mangle/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.1.0",
|
|
4
|
+
"version": "5.1.2-alpha.0",
|
|
5
5
|
"description": "The core of tailwindcss-mangle",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -50,18 +50,18 @@
|
|
|
50
50
|
"@babel/parser": "^7.29.0",
|
|
51
51
|
"@babel/traverse": "^7.29.0",
|
|
52
52
|
"@babel/types": "^7.29.0",
|
|
53
|
-
"@vue/compiler-sfc": "^3.5.
|
|
53
|
+
"@vue/compiler-sfc": "^3.5.30",
|
|
54
54
|
"fast-sort": "^3.4.1",
|
|
55
|
-
"fs-extra": "^11.3.
|
|
55
|
+
"fs-extra": "^11.3.4",
|
|
56
56
|
"htmlparser2": "10.1.0",
|
|
57
57
|
"magic-string": "^0.30.21",
|
|
58
58
|
"parse5": "^8.0.0",
|
|
59
59
|
"pathe": "^2.0.3",
|
|
60
|
-
"postcss": "^8.5.
|
|
60
|
+
"postcss": "^8.5.8",
|
|
61
61
|
"postcss-selector-parser": "^7.1.1",
|
|
62
|
-
"svelte": "^5.
|
|
63
|
-
"@tailwindcss-mangle/config": "^6.1.
|
|
64
|
-
"@tailwindcss-mangle/shared": "^4.1.
|
|
62
|
+
"svelte": "^5.53.11",
|
|
63
|
+
"@tailwindcss-mangle/config": "^6.1.4-alpha.0",
|
|
64
|
+
"@tailwindcss-mangle/shared": "^4.1.3"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/parse5": "^7.0.0"
|