From e8c88858fd7482a66a0b07652f8f488f4568cece Mon Sep 17 00:00:00 2001 From: SonOfMagic Date: Mon, 15 May 2023 17:40:24 +0800 Subject: [PATCH 01/17] feat: init mangle store --- package.json | 1 + pnpm-lock.yaml | 276 +++++++++++++++++++++++++++++--------------- src/mangle/store.ts | 50 ++++++++ src/types.ts | 11 +- 4 files changed, 242 insertions(+), 96 deletions(-) create mode 100644 src/mangle/store.ts diff --git a/package.json b/package.json index ac2fa5ce6..d6257b578 100644 --- a/package.json +++ b/package.json @@ -215,6 +215,7 @@ "postcss": "8.4.23", "postcss-selector-parser": "^6.0.12", "semver": "^7.5.0", + "tailwindcss-mangle-core": "^1.0.1", "tailwindcss-patch": "^1.1.1", "webpack-sources": "^3.2.3" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b8dbb9092..0c9b27309 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -83,6 +83,7 @@ specifiers: style-loader2: npm:style-loader@2.0.0 tailwind-children: ^0.5.0 tailwindcss: ^3.3.2 + tailwindcss-mangle-core: ^1.0.1 tailwindcss-patch: ^1.1.1 ts-jest: ^29.1.0 ts-node: ^10.9.1 @@ -110,6 +111,7 @@ dependencies: postcss: 8.4.23 postcss-selector-parser: 6.0.12 semver: 7.5.0 + tailwindcss-mangle-core: 1.0.1 tailwindcss-patch: 1.1.1 webpack-sources: 3.2.3 @@ -213,7 +215,6 @@ packages: dependencies: '@jridgewell/gen-mapping': 0.1.1 '@jridgewell/trace-mapping': 0.3.18 - dev: true /@babel/code-frame/7.21.4: resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==} @@ -226,6 +227,10 @@ packages: engines: {node: '>=6.9.0'} dev: true + /@babel/compat-data/7.21.7: + resolution: {integrity: sha512-KYMqFYTaenzMK4yUtf4EW9wc4N9ef80FsbMtkwool5zpwl4YrT1SdWYSTRcT94KO4hannogdS+LxY7L+arP3gA==} + engines: {node: '>=6.9.0'} + /@babel/core/7.21.4: resolution: {integrity: sha512-qt/YV149Jman/6AfmlxJ04LMIu8bMoyl3RB91yTFrxQmgbrSvQMy7cI8Q62FHx1t8wJ8B5fu0UDoLwHAhUo1QA==} engines: {node: '>=6.9.0'} @@ -249,6 +254,28 @@ packages: - supports-color dev: true + /@babel/core/7.21.8: + resolution: {integrity: sha512-YeM22Sondbo523Sz0+CirSPnbj9bG3P0CdHcBZdqUuaeOaYEFbOLoGU7lebvGP6P5J/WE9wOn7u7C4J9HvS1xQ==} + engines: {node: '>=6.9.0'} + dependencies: + '@ampproject/remapping': 2.2.0 + '@babel/code-frame': 7.21.4 + '@babel/generator': 7.21.5 + '@babel/helper-compilation-targets': 7.21.5_@babel+core@7.21.8 + '@babel/helper-module-transforms': 7.21.5 + '@babel/helpers': 7.21.5 + '@babel/parser': 7.21.8 + '@babel/template': 7.20.7 + '@babel/traverse': 7.21.5 + '@babel/types': 7.21.5 + convert-source-map: 1.9.0 + debug: 4.3.4 + gensync: 1.0.0-beta.2 + json5: 2.2.3 + semver: 6.3.0 + transitivePeerDependencies: + - supports-color + /@babel/generator/7.21.4: resolution: {integrity: sha512-NieM3pVIYW2SwGzKoqfPrQsf4xGs9M9AIG3ThppsSRmO+m7eQhmI6amajKMUeIO37wFfsvnvcxQFx6x6iqxDnA==} engines: {node: '>=6.9.0'} @@ -266,13 +293,12 @@ packages: '@jridgewell/gen-mapping': 0.3.3 '@jridgewell/trace-mapping': 0.3.18 jsesc: 2.5.2 - dev: false /@babel/helper-annotate-as-pure/7.18.6: resolution: {integrity: sha512-duORpUiYrEpzKIop6iNbjnwKLAKnJ47csTyRACyEmWj0QdUrm5aqNJGHSSEQSUAvNW0ojX0dOmK9dZduvkfeXA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 dev: true /@babel/helper-compilation-targets/7.21.4_@babel+core@7.21.4: @@ -289,6 +315,19 @@ packages: semver: 6.3.0 dev: true + /@babel/helper-compilation-targets/7.21.5_@babel+core@7.21.8: + resolution: {integrity: sha512-1RkbFGUKex4lvsB9yhIfWltJM5cZKUftB2eNajaDv3dCMEp49iBG0K14uH8NnX9IPux2+mK7JGEOB0jn48/J6w==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0 + dependencies: + '@babel/compat-data': 7.21.7 + '@babel/core': 7.21.8 + '@babel/helper-validator-option': 7.21.0 + browserslist: 4.21.5 + lru-cache: 5.1.1 + semver: 6.3.0 + /@babel/helper-environment-visitor/7.18.9: resolution: {integrity: sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==} engines: {node: '>=6.9.0'} @@ -302,27 +341,26 @@ packages: engines: {node: '>=6.9.0'} dependencies: '@babel/template': 7.20.7 - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 /@babel/helper-hoist-variables/7.18.6: resolution: {integrity: sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 /@babel/helper-module-imports/7.18.6: resolution: {integrity: sha512-0NFvs3VkuSYbFi1x2Vd6tKrywq+z/cLeYC/RJNFrIX/30Bf5aiGYbtvGXolEktzJH8o5E5KJ3tT+nkxuuZFVlA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 dev: true /@babel/helper-module-imports/7.21.4: resolution: {integrity: sha512-orajc5T2PsRYUN3ZryCEFeMDYwyw09c/pZeaQEZPH0MpKzSvn3e0uXsDBu3k03VI+9DBiRo+l22BfKTpKwa/Wg==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 - dev: true + '@babel/types': 7.21.5 /@babel/helper-module-transforms/7.21.2: resolution: {integrity: sha512-79yj2AR4U/Oqq/WOV7Lx6hUjau1Zfo4cI+JLAVYeMV5XIlbOhmjEk5ulbTc9fMpmlojzZHkUUxAiK+UKn+hNQQ==} @@ -340,6 +378,21 @@ packages: - supports-color dev: true + /@babel/helper-module-transforms/7.21.5: + resolution: {integrity: sha512-bI2Z9zBGY2q5yMHoBvJ2a9iX3ZOAzJPm7Q8Yz6YeoUjU/Cvhmi2G4QyTNyPBqqXSgTjUxRg3L0xV45HvkNWWBw==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/helper-environment-visitor': 7.21.5 + '@babel/helper-module-imports': 7.21.4 + '@babel/helper-simple-access': 7.21.5 + '@babel/helper-split-export-declaration': 7.18.6 + '@babel/helper-validator-identifier': 7.19.1 + '@babel/template': 7.20.7 + '@babel/traverse': 7.21.5 + '@babel/types': 7.21.5 + transitivePeerDependencies: + - supports-color + /@babel/helper-plugin-utils/7.19.0: resolution: {integrity: sha512-40Ryx7I8mT+0gaNxm8JGTZFUITNqdLAgdg0hXzeVZxVD6nFsdhQvip6v8dqkRHzsz1VFpFAaOCHNn0vKBL7Czw==} engines: {node: '>=6.9.0'} @@ -354,14 +407,20 @@ packages: resolution: {integrity: sha512-+0woI/WPq59IrqDYbVGfshjT5Dmk/nnbdpcF8SnMhhXObpTq2KNBdLFRFrkVdbDOyUmHBCxzm5FHV1rACIkIbA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 dev: true + /@babel/helper-simple-access/7.21.5: + resolution: {integrity: sha512-ENPDAMC1wAjR0uaCUwliBdiSl1KBJAVnMTzXqi64c2MG8MPR6ii4qf7bSXDqSFbr4W6W028/rf5ivoHop5/mkg==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/types': 7.21.5 + /@babel/helper-split-export-declaration/7.18.6: resolution: {integrity: sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==} engines: {node: '>=6.9.0'} dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 /@babel/helper-string-parser/7.19.4: resolution: {integrity: sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==} @@ -370,7 +429,6 @@ packages: /@babel/helper-string-parser/7.21.5: resolution: {integrity: sha512-5pTUx3hAJaZIdW99sJ6ZUUgWq/Y+Hja7TowEnLNMm1VivRgZQL3vpBY3qUACVsvw+yQU6+YgfBVmcbLaZtrA1w==} engines: {node: '>=6.9.0'} - dev: false /@babel/helper-validator-identifier/7.19.1: resolution: {integrity: sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==} @@ -384,7 +442,6 @@ packages: /@babel/helper-validator-option/7.21.0: resolution: {integrity: sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==} engines: {node: '>=6.9.0'} - dev: true /@babel/helpers/7.21.0: resolution: {integrity: sha512-XXve0CBtOW0pd7MRzzmoyuSj0e3SEzj8pgyFxnTT1NJZL38BD1MK7yYrm8yefRPIDvNNe14xR4FdbHwpInD4rA==} @@ -397,6 +454,16 @@ packages: - supports-color dev: true + /@babel/helpers/7.21.5: + resolution: {integrity: sha512-BSY+JSlHxOmGsPTydUkPf1MdMQ3M81x5xGCOVgWM3G8XH77sJ292Y2oqcp0CbbgxhqBuI46iUz1tT7hqP7EfgA==} + engines: {node: '>=6.9.0'} + dependencies: + '@babel/template': 7.20.7 + '@babel/traverse': 7.21.5 + '@babel/types': 7.21.5 + transitivePeerDependencies: + - supports-color + /@babel/highlight/7.18.6: resolution: {integrity: sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==} engines: {node: '>=6.9.0'} @@ -417,51 +484,58 @@ packages: engines: {node: '>=6.0.0'} hasBin: true dependencies: - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 dev: false - /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.21.4: + /@babel/parser/7.21.8: + resolution: {integrity: sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==} + engines: {node: '>=6.0.0'} + hasBin: true + dependencies: + '@babel/types': 7.21.5 + + /@babel/plugin-syntax-async-generators/7.8.4_@babel+core@7.21.8: resolution: {integrity: sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-bigint/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-bigint/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.21.4: + /@babel/plugin-syntax-class-properties/7.12.13_@babel+core@7.21.8: resolution: {integrity: sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.21.4: + /@babel/plugin-syntax-import-meta/7.10.4_@babel+core@7.21.8: resolution: {integrity: sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-json-strings/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true @@ -475,77 +549,87 @@ packages: '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.21.4: + /@babel/plugin-syntax-jsx/7.18.6_@babel+core@7.21.8: + resolution: {integrity: sha512-6mmljtAedFGTWu2p/8WIORGwy+61PLgOMPOdazc7YoJ9ZCWUyFy3A6CpPkRKLKD1ToAesxX8KGEViAiLo9N+7Q==} + engines: {node: '>=6.9.0'} + peerDependencies: + '@babel/core': ^7.0.0-0 + dependencies: + '@babel/core': 7.21.8 + '@babel/helper-plugin-utils': 7.20.2 + dev: true + + /@babel/plugin-syntax-logical-assignment-operators/7.10.4_@babel+core@7.21.8: resolution: {integrity: sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-nullish-coalescing-operator/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.21.4: + /@babel/plugin-syntax-numeric-separator/7.10.4_@babel+core@7.21.8: resolution: {integrity: sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-object-rest-spread/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-optional-catch-binding/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.21.4: + /@babel/plugin-syntax-optional-chaining/7.8.3_@babel+core@7.21.8: resolution: {integrity: sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-top-level-await/7.14.5_@babel+core@7.21.4: + /@babel/plugin-syntax-top-level-await/7.14.5_@babel+core@7.21.8: resolution: {integrity: sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true - /@babel/plugin-syntax-typescript/7.20.0_@babel+core@7.21.4: + /@babel/plugin-syntax-typescript/7.20.0_@babel+core@7.21.8: resolution: {integrity: sha512-rd9TkG+u1CExzS4SM1BlMEhMXwFLKVjOAFFCDx9PbX5ycJWDoWMcwdJH9RhkPu1dOgn5TrxLot/Gx6lWFuAUNQ==} engines: {node: '>=6.9.0'} peerDependencies: '@babel/core': ^7.0.0-0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@babel/helper-plugin-utils': 7.20.2 dev: true @@ -644,13 +728,12 @@ packages: '@babel/helper-function-name': 7.21.0 '@babel/helper-hoist-variables': 7.18.6 '@babel/helper-split-export-declaration': 7.18.6 - '@babel/parser': 7.21.5 + '@babel/parser': 7.21.8 '@babel/types': 7.21.5 debug: 4.3.4 globals: 11.12.0 transitivePeerDependencies: - supports-color - dev: false /@babel/types/7.21.4: resolution: {integrity: sha512-rU2oY501qDxE8Pyo7i/Orqma4ziCOrby0/9mvbDUGEfvZjb279Nk9k19e2fiCxHbRRpY2ZyrgW1eq22mvmOIzA==} @@ -667,7 +750,6 @@ packages: '@babel/helper-string-parser': 7.21.5 '@babel/helper-validator-identifier': 7.19.1 to-fast-properties: 2.0.0 - dev: false /@bcoe/v8-coverage/0.2.3: resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} @@ -1200,7 +1282,7 @@ packages: resolution: {integrity: sha512-8vbeZWqLJOvHaDfeMuoHITGKSz5qWc9u04lnWrQE3VyuSw604PzQM824ZeX9XSjUCeDiE3GuxZe5UKa8J61NQw==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@jest/types': 29.5.0 '@jridgewell/trace-mapping': 0.3.18 babel-plugin-istanbul: 6.1.1 @@ -1558,7 +1640,6 @@ packages: dependencies: '@jridgewell/set-array': 1.1.2 '@jridgewell/sourcemap-codec': 1.4.15 - dev: true /@jridgewell/gen-mapping/0.3.2: resolution: {integrity: sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==} @@ -1801,8 +1882,8 @@ packages: /@types/babel__core/7.20.0: resolution: {integrity: sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==} dependencies: - '@babel/parser': 7.21.4 - '@babel/types': 7.21.4 + '@babel/parser': 7.21.8 + '@babel/types': 7.21.5 '@types/babel__generator': 7.6.4 '@types/babel__template': 7.4.1 '@types/babel__traverse': 7.18.5 @@ -1817,8 +1898,8 @@ packages: /@types/babel__template/7.4.1: resolution: {integrity: sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==} dependencies: - '@babel/parser': 7.21.4 - '@babel/types': 7.21.4 + '@babel/parser': 7.21.8 + '@babel/types': 7.21.5 dev: true /@types/babel__traverse/7.18.5: @@ -2567,17 +2648,17 @@ packages: engines: {node: '>= 0.4'} dev: true - /babel-jest/29.5.0_@babel+core@7.21.4: + /babel-jest/29.5.0_@babel+core@7.21.8: resolution: {integrity: sha512-mA4eCDh5mSo2EcA9xQjVTpmbbNk32Zb3Q3QFQsNhaK56Q+yoXowzFodLux30HRgyOho5rsQ6B0P9QpMkvvnJ0Q==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: '@babel/core': ^7.8.0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@jest/transform': 29.5.0 '@types/babel__core': 7.20.0 babel-plugin-istanbul: 6.1.1 - babel-preset-jest: 29.5.0_@babel+core@7.21.4 + babel-preset-jest: 29.5.0_@babel+core@7.21.8 chalk: 4.1.2 graceful-fs: 4.2.11 slash: 3.0.0 @@ -2618,40 +2699,40 @@ packages: engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: '@babel/template': 7.20.7 - '@babel/types': 7.21.4 + '@babel/types': 7.21.5 '@types/babel__core': 7.20.0 '@types/babel__traverse': 7.18.5 dev: true - /babel-preset-current-node-syntax/1.0.1_@babel+core@7.21.4: + /babel-preset-current-node-syntax/1.0.1_@babel+core@7.21.8: resolution: {integrity: sha512-M7LQ0bxarkxQoN+vz5aJPsLBn77n8QgTFmo8WK0/44auK2xlCXrYcUxHFxgU7qW5Yzw/CjmLRK2uJzaCd7LvqQ==} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.21.4 - '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.21.4 - '@babel/plugin-syntax-bigint': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-class-properties': 7.12.13_@babel+core@7.21.4 - '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.21.4 - '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-logical-assignment-operators': 7.10.4_@babel+core@7.21.4 - '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-numeric-separator': 7.10.4_@babel+core@7.21.4 - '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.21.4 - '@babel/plugin-syntax-top-level-await': 7.14.5_@babel+core@7.21.4 - dev: true - - /babel-preset-jest/29.5.0_@babel+core@7.21.4: + '@babel/core': 7.21.8 + '@babel/plugin-syntax-async-generators': 7.8.4_@babel+core@7.21.8 + '@babel/plugin-syntax-bigint': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-class-properties': 7.12.13_@babel+core@7.21.8 + '@babel/plugin-syntax-import-meta': 7.10.4_@babel+core@7.21.8 + '@babel/plugin-syntax-json-strings': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-logical-assignment-operators': 7.10.4_@babel+core@7.21.8 + '@babel/plugin-syntax-nullish-coalescing-operator': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-numeric-separator': 7.10.4_@babel+core@7.21.8 + '@babel/plugin-syntax-object-rest-spread': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-optional-catch-binding': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-optional-chaining': 7.8.3_@babel+core@7.21.8 + '@babel/plugin-syntax-top-level-await': 7.14.5_@babel+core@7.21.8 + dev: true + + /babel-preset-jest/29.5.0_@babel+core@7.21.8: resolution: {integrity: sha512-JOMloxOqdiBSxMAzjRaH023/vvcaSaec49zvg+2LmNsktC7ei39LTJGw02J+9uUtTZUq6xbLyJ4dxe9sSmIuAg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} peerDependencies: '@babel/core': ^7.0.0 dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 babel-plugin-jest-hoist: 29.5.0 - babel-preset-current-node-syntax: 1.0.1_@babel+core@7.21.4 + babel-preset-current-node-syntax: 1.0.1_@babel+core@7.21.8 dev: true /balanced-match/1.0.2: @@ -2724,7 +2805,6 @@ packages: electron-to-chromium: 1.4.365 node-releases: 2.0.10 update-browserslist-db: 1.0.11_browserslist@4.21.5 - dev: true /bs-logger/0.2.6: resolution: {integrity: sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==} @@ -2861,7 +2941,6 @@ packages: /caniuse-lite/1.0.30001479: resolution: {integrity: sha512-6nuRFim5dx8Eu2tO+KJ9PiBdPHs7WB5Hdf+klDcyefyEuOAcfhihIv7pS+JFknJLUiNQbm1AJYKm0c9QOlQS/Q==} - dev: true /chai/4.3.7: resolution: {integrity: sha512-HLnAzZ2iupm25PlN0xFreAlBA5zaBSv3og0DdeGA4Ar6h6rJ3A0rolRUKJhSF2V10GZKDgWF/VmAEsNWjCRB+A==} @@ -3041,7 +3120,6 @@ packages: /convert-source-map/1.9.0: resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==} - dev: true /convert-source-map/2.0.0: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} @@ -3382,7 +3460,6 @@ packages: /electron-to-chromium/1.4.365: resolution: {integrity: sha512-FRHZO+1tUNO4TOPXmlxetkoaIY8uwHzd1kKopK/Gx2SKn1L47wJXWD44wxP5CGRyyP98z/c8e1eBzJrgPeiBOg==} - dev: true /emittery/0.13.1: resolution: {integrity: sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==} @@ -3412,7 +3489,6 @@ packages: /entities/4.5.0: resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} - dev: true /errno/0.1.8: resolution: {integrity: sha512-dJ6oBr5SQ1VSd9qkk7ByRgb/1SH4JZjCHSW/mr63/QcXO9zLVxvJ6Oy13nio03rxpSnVDDjFor75SjVeZWPW/A==} @@ -3527,7 +3603,6 @@ packages: /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} engines: {node: '>=6'} - dev: true /escape-string-regexp/1.0.5: resolution: {integrity: sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==} @@ -4123,7 +4198,6 @@ packages: /gensync/1.0.0-beta.2: resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==} engines: {node: '>=6.9.0'} - dev: true /get-caller-file/2.0.5: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} @@ -4755,8 +4829,8 @@ packages: resolution: {integrity: sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==} engines: {node: '>=8'} dependencies: - '@babel/core': 7.21.4 - '@babel/parser': 7.21.4 + '@babel/core': 7.21.8 + '@babel/parser': 7.21.8 '@istanbuljs/schema': 0.1.3 istanbul-lib-coverage: 3.2.0 semver: 6.3.0 @@ -4868,11 +4942,11 @@ packages: ts-node: optional: true dependencies: - '@babel/core': 7.21.4 + '@babel/core': 7.21.8 '@jest/test-sequencer': 29.5.0 '@jest/types': 29.5.0 '@types/node': 18.16.3 - babel-jest: 29.5.0_@babel+core@7.21.4 + babel-jest: 29.5.0_@babel+core@7.21.8 chalk: 4.1.2 ci-info: 3.8.0 deepmerge: 4.3.1 @@ -5107,18 +5181,18 @@ packages: resolution: {integrity: sha512-x7Wolra5V0tt3wRs3/ts3S6ciSQVypgGQlJpz2rsdQYoUKxMxPNaoHMGJN6qAuPJqS+2iQ1ZUn5kl7HCyls84g==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/core': 7.21.4 - '@babel/generator': 7.21.4 - '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.21.4 - '@babel/plugin-syntax-typescript': 7.20.0_@babel+core@7.21.4 - '@babel/traverse': 7.21.4 - '@babel/types': 7.21.4 + '@babel/core': 7.21.8 + '@babel/generator': 7.21.5 + '@babel/plugin-syntax-jsx': 7.18.6_@babel+core@7.21.8 + '@babel/plugin-syntax-typescript': 7.20.0_@babel+core@7.21.8 + '@babel/traverse': 7.21.5 + '@babel/types': 7.21.5 '@jest/expect-utils': 29.5.0 '@jest/transform': 29.5.0 '@jest/types': 29.5.0 '@types/babel__traverse': 7.18.5 '@types/prettier': 2.7.2 - babel-preset-current-node-syntax: 1.0.1_@babel+core@7.21.4 + babel-preset-current-node-syntax: 1.0.1_@babel+core@7.21.8 chalk: 4.1.2 expect: 29.5.0 graceful-fs: 4.2.11 @@ -5294,7 +5368,6 @@ packages: resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==} engines: {node: '>=6'} hasBin: true - dev: true /jsonc-parser/3.2.0: resolution: {integrity: sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==} @@ -5462,7 +5535,6 @@ packages: resolution: {integrity: sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==} dependencies: yallist: 3.1.1 - dev: true /lru-cache/6.0.0: resolution: {integrity: sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==} @@ -5770,7 +5842,6 @@ packages: /node-releases/2.0.10: resolution: {integrity: sha512-5GFldHPXVG/YZmFzJvKK2zDSzPKhEp0+ZR5SVaoSag9fsL5YgHbUHDfnG5494ISANDcK4KwPXAx2xqVEydmd7w==} - dev: true /normalize-package-data/2.5.0: resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} @@ -6037,6 +6108,12 @@ packages: entities: 4.5.0 dev: true + /parse5/7.1.2: + resolution: {integrity: sha512-Czj1WaSVpaoj0wbhMzLmWD69anp2WH7FXMB9n1Sy8/ZFF9jolSQVMu1Ij5WIyGmcBmhk7EOndpO4mIpihVqAXw==} + dependencies: + entities: 4.5.0 + dev: false + /pascal-case/3.1.2: resolution: {integrity: sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==} dependencies: @@ -6759,7 +6836,6 @@ packages: /semver/6.3.0: resolution: {integrity: sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==} hasBin: true - dev: true /semver/7.5.0: resolution: {integrity: sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==} @@ -7096,6 +7172,18 @@ packages: - ts-node dev: true + /tailwindcss-mangle-core/1.0.1: + resolution: {integrity: sha512-8aBvG4kH+MINVc4Wjls4PuUp27/Lm+j1QJrN9gxfjQXRnmlXraejtP89kBT15is3vIfx0A+3qnmhqv9sVe47jA==} + dependencies: + '@babel/core': 7.21.8 + '@babel/types': 7.21.5 + parse5: 7.1.2 + postcss: 8.4.23 + postcss-selector-parser: 6.0.12 + transitivePeerDependencies: + - supports-color + dev: false + /tailwindcss-patch/1.1.1: resolution: {integrity: sha512-H4I8HbzHnAxNK0NA+6PFl05F0+pPbKuHIGOBsYa1Of+QQ47UcpgMlBdhsPYtpELmV8qqM8DwRUGRpIENDrv1Fw==} hasBin: true @@ -7567,7 +7655,6 @@ packages: browserslist: 4.21.5 escalade: 3.1.1 picocolors: 1.0.0 - dev: true /uri-js/4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} @@ -7936,7 +8023,6 @@ packages: /yallist/3.1.1: resolution: {integrity: sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==} - dev: true /yallist/4.0.0: resolution: {integrity: sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==} diff --git a/src/mangle/store.ts b/src/mangle/store.ts new file mode 100644 index 000000000..f559379cc --- /dev/null +++ b/src/mangle/store.ts @@ -0,0 +1,50 @@ +import { ClassGenerator, cssHandler, jsHandler } from 'tailwindcss-mangle-core' +import { UserDefinedOptions } from '@/types' +// import type { BabelFileResult } from '@babel/core' +const scope: { + rawOptions: UserDefinedOptions['mangle'] + runtimeSet?: Set + classGenerator: ClassGenerator + cssHandler: (rawSource: string) => string // typeof cssHandler + jsHandler: (rawSource: string) => string // typeof jsHandler +} = { + rawOptions: false, + classGenerator: new ClassGenerator(), + cssHandler: (x) => x, + jsHandler: (x) => x +} + +export function useStore() { + return scope as Required +} + +export function initStore(options: UserDefinedOptions['mangle']) { + scope.rawOptions = options + if (options) { + if (options === true) { + options = { + classGenerator: {} + } + } + scope.classGenerator = new ClassGenerator(options.classGenerator) + scope.jsHandler = (rawSource: string) => { + return jsHandler(rawSource, { + classGenerator: scope.classGenerator, + runtimeSet: scope.runtimeSet!, + splitQuote: false + }).code! + } + scope.cssHandler = (rawSource: string) => { + // process 最后处理, loader 无所谓顺序 + return cssHandler(rawSource, { + classGenerator: scope.classGenerator, + runtimeSet: scope.runtimeSet!, + scene: 'process' + }) + } + } +} + +export function setRuntimeSet(runtimeSet: Set) { + scope.runtimeSet = runtimeSet +} diff --git a/src/types.ts b/src/types.ts index 7519d9439..62e761d3b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,6 @@ import type { InjectPreflight } from './postcss/preflight' import type { Rule } from 'postcss' - +import type { ClassGenerator } from 'tailwindcss-mangle-core' import type { GeneratorResult } from '@babel/generator' export type ItemOrItemArray = T | T[] @@ -171,6 +171,15 @@ export interface UserDefinedOptions { * @default process.env.NODE_ENV === 'production' */ minifiedJs?: boolean + + /** + * @description tailwindcss-mangle-core 带来的能力 + */ + mangle?: + | boolean + | { + classGenerator: ConstructorParameters[0] + } } export interface ICommonReplaceOptions { From 6dc22aefe731c47a61b591587c27bbf04ca17d66 Mon Sep 17 00:00:00 2001 From: SonOfMagic Date: Mon, 15 May 2023 18:02:59 +0800 Subject: [PATCH 02/17] chore: prepare for wxmlHandler --- src/mangle/store.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/mangle/store.ts b/src/mangle/store.ts index f559379cc..36fd36a85 100644 --- a/src/mangle/store.ts +++ b/src/mangle/store.ts @@ -1,22 +1,32 @@ import { ClassGenerator, cssHandler, jsHandler } from 'tailwindcss-mangle-core' import { UserDefinedOptions } from '@/types' +import { splitCode } from '@/extractors/split' + +function getSelf(x: string) { + return x +} // import type { BabelFileResult } from '@babel/core' -const scope: { +// 为什么要用这种方式,因为一层一层往下传递参数,太烦了 +// 所以说还是搞个 IOC 容器比较爽,要什么注入什么 +export const scope: { rawOptions: UserDefinedOptions['mangle'] - runtimeSet?: Set + runtimeSet: Set classGenerator: ClassGenerator cssHandler: (rawSource: string) => string // typeof cssHandler jsHandler: (rawSource: string) => string // typeof jsHandler + wxmlHandler: (rawSource: string) => string } = { rawOptions: false, + runtimeSet: new Set(), classGenerator: new ClassGenerator(), - cssHandler: (x) => x, - jsHandler: (x) => x -} + cssHandler: getSelf, + jsHandler: getSelf, + wxmlHandler: getSelf +} // as default -export function useStore() { - return scope as Required -} +// export function useStore() { +// return scope as Required +// } export function initStore(options: UserDefinedOptions['mangle']) { scope.rawOptions = options @@ -42,6 +52,11 @@ export function initStore(options: UserDefinedOptions['mangle']) { scene: 'process' }) } + + scope.wxmlHandler = (rawSource: string) => { + // splitCode(rawSource) + return rawSource + } } } From ef75fe0608f6d4fad2478f4ccd7c6b6577e07b5a Mon Sep 17 00:00:00 2001 From: sonofmagic <1324318532@qq.com> Date: Mon, 15 May 2023 23:00:37 +0800 Subject: [PATCH 03/17] feat: commit webpack5 test demo --- package.json | 1 + src/js/index.ts | 3 + src/mangle/store.ts | 104 ++++++-- src/postcss/shared.ts | 3 + src/webpack/BaseUnifiedPlugin/v5.ts | 13 +- src/wxml/shared.ts | 4 +- test/__snapshots__/webpack.v5.test.ts.snap | 272 ++++++++++----------- test/webpack.v5.test.ts | 24 +- 8 files changed, 253 insertions(+), 171 deletions(-) diff --git a/package.json b/package.json index d6257b578..c8f432504 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "dts": "tsc --emitDeclarationOnly -p tsconfig.dts.json", "fix-dts": "ts-node scripts/fix-dts.ts", "test": "jest && vitest run", + "jest-u": "jest -u", "vitest:test": "vitest", "vitest:coverage": "vitest run --coverage", "test:all": "cross-env JEST_INVALID_SKIP_CASES=1 jest", diff --git a/src/js/index.ts b/src/js/index.ts index 79614ed8c..95e5749a9 100644 --- a/src/js/index.ts +++ b/src/js/index.ts @@ -6,6 +6,7 @@ import { replaceWxml } from '@/wxml/shared' import { escapeStringRegexp } from '@/reg' import { splitCode } from '@/extractors/split' import { isProd } from '@/env' +import { useStore } from '@/mangle/store' export function handleValue(str: string, node: StringLiteral | TemplateElement, options: IJsHandlerOptions) { const set = options.classNameSet @@ -21,6 +22,8 @@ export function handleValue(str: string, node: StringLiteral | TemplateElement, } if (!ignoreFlag) { + const { jsHandler } = useStore() + rawStr = jsHandler(rawStr) rawStr = rawStr.replace( new RegExp(escapeStringRegexp(v), 'g'), replaceWxml(v, { diff --git a/src/mangle/store.ts b/src/mangle/store.ts index 36fd36a85..525ac1da2 100644 --- a/src/mangle/store.ts +++ b/src/mangle/store.ts @@ -1,32 +1,49 @@ -import { ClassGenerator, cssHandler, jsHandler } from 'tailwindcss-mangle-core' +import { ClassGenerator } from 'tailwindcss-mangle-core' import { UserDefinedOptions } from '@/types' import { splitCode } from '@/extractors/split' +import { escapeStringRegexp } from '@/reg' function getSelf(x: string) { return x } + +const defaultScope = { + rawOptions: false, + runtimeSet: new Set(), + classGenerator: new ClassGenerator(), + cssHandler: getSelf, + jsHandler: getSelf, + wxmlHandler: getSelf, + recorder: { + js: [], + css: [], + wxml: [] + } +} // as default // import type { BabelFileResult } from '@babel/core' // 为什么要用这种方式,因为一层一层往下传递参数,太烦了 // 所以说还是搞个 IOC 容器比较爽,要什么注入什么 -export const scope: { +const scope: { rawOptions: UserDefinedOptions['mangle'] runtimeSet: Set classGenerator: ClassGenerator cssHandler: (rawSource: string) => string // typeof cssHandler jsHandler: (rawSource: string) => string // typeof jsHandler wxmlHandler: (rawSource: string) => string -} = { - rawOptions: false, - runtimeSet: new Set(), - classGenerator: new ClassGenerator(), - cssHandler: getSelf, - jsHandler: getSelf, - wxmlHandler: getSelf -} // as default + recorder: { + js: string[] + css: string[] + wxml: string[] + } +} = Object.assign({}, defaultScope) -// export function useStore() { -// return scope as Required -// } +export function useStore() { + return scope +} + +export function resetStore() { + return Object.assign(scope, defaultScope) +} export function initStore(options: UserDefinedOptions['mangle']) { scope.rawOptions = options @@ -38,28 +55,67 @@ export function initStore(options: UserDefinedOptions['mangle']) { } scope.classGenerator = new ClassGenerator(options.classGenerator) scope.jsHandler = (rawSource: string) => { - return jsHandler(rawSource, { - classGenerator: scope.classGenerator, - runtimeSet: scope.runtimeSet!, - splitQuote: false - }).code! + scope.recorder.js.push(rawSource) + const arr = splitCode(rawSource) + for (let i = 0; i < arr.length; i++) { + const x = arr[i] + if (scope.runtimeSet.has(x)) { + rawSource = rawSource.replace(new RegExp(escapeStringRegexp(x), 'g'), scope.classGenerator.generateClassName(x).name) + } + } + return rawSource + // return jsHandler(rawSource, { + // classGenerator: scope.classGenerator, + // runtimeSet: scope.runtimeSet!, + // splitQuote: false + // }).code! } scope.cssHandler = (rawSource: string) => { // process 最后处理, loader 无所谓顺序 - return cssHandler(rawSource, { - classGenerator: scope.classGenerator, - runtimeSet: scope.runtimeSet!, - scene: 'process' - }) + scope.recorder.css.push(rawSource) + const arr = splitCode(rawSource) + for (let i = 0; i < arr.length; i++) { + const x = arr[i] + if (scope.runtimeSet.has(x)) { + rawSource = rawSource.replace(new RegExp(escapeStringRegexp(x), 'g'), scope.classGenerator.generateClassName(x).name) + } + } + return rawSource + // return cssHandler(rawSource, { + // classGenerator: scope.classGenerator, + // runtimeSet: scope.runtimeSet!, + // scene: 'process' + // }) } scope.wxmlHandler = (rawSource: string) => { // splitCode(rawSource) + scope.recorder.wxml.push(rawSource) + const arr = splitCode(rawSource) + for (let i = 0; i < arr.length; i++) { + const x = arr[i] + if (scope.runtimeSet.has(x)) { + rawSource = rawSource.replace(new RegExp(escapeStringRegexp(x), 'g'), scope.classGenerator.generateClassName(x).name) + } + } return rawSource } } } +export const isMangleClass = (className: string) => { + // ignore className like 'filter','container' + // it may be dangerous to mangle/rename all StringLiteral , so use /-/ test for only those with /-/ like: + // bg-[#123456] w-1 etc... + return /[-:]/.test(className) +} + export function setRuntimeSet(runtimeSet: Set) { - scope.runtimeSet = runtimeSet + const newSet = new Set() + runtimeSet.forEach((c) => { + if (isMangleClass(c)) { + newSet.add(c) + } + }) + scope.runtimeSet = newSet } diff --git a/src/postcss/shared.ts b/src/postcss/shared.ts index be6b2b331..db37a8e18 100644 --- a/src/postcss/shared.ts +++ b/src/postcss/shared.ts @@ -1,5 +1,6 @@ import { escape } from '@/escape' import { SimpleMappingChars2String } from '@/dic' +import { useStore } from '@/mangle/store' // css 中,要多加一个 '\' 来转义 // for raw css selector // export function cssSelectorReplacer(selector: string, escapeEntries = MappingChars2StringEntries) { @@ -7,6 +8,8 @@ import { SimpleMappingChars2String } from '@/dic' // } export function internalCssSelectorReplacer(selectors: string, map: Record = SimpleMappingChars2String) { + const { cssHandler } = useStore() + selectors = cssHandler(selectors) return escape(selectors, { map }) diff --git a/src/webpack/BaseUnifiedPlugin/v5.ts b/src/webpack/BaseUnifiedPlugin/v5.ts index 12ce25b7f..a07995876 100644 --- a/src/webpack/BaseUnifiedPlugin/v5.ts +++ b/src/webpack/BaseUnifiedPlugin/v5.ts @@ -5,6 +5,7 @@ import { getOptions } from '@/options' import { pluginName, NS } from '@/constants' import { createTailwindcssPatcher } from '@/tailwindcss/patcher' import { getGroupedEntries } from '@/utils' +import { initStore, setRuntimeSet } from '@/mangle/store' /** * @name UnifiedWebpackPluginV5 @@ -26,12 +27,12 @@ export class UnifiedWebpackPluginV5 implements IBaseWebpackPlugin { } apply(compiler: Compiler) { - const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templeteHandler, jsHandler } = this.options + const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templeteHandler, jsHandler, mangle } = this.options if (disabled) { return } patch?.() - + initStore(mangle) const Compilation = compiler.webpack.Compilation const { ConcatSource } = compiler.webpack.sources // react @@ -60,7 +61,10 @@ export class UnifiedWebpackPluginV5 implements IBaseWebpackPlugin { onStart() const entries = Object.entries(assets) const groupedEntries = getGroupedEntries(entries, this.options) - + // 再次 build 不转化的原因是此时 set.size 为0 + // 也就是说当开启缓存的时候没有触发 postcss,导致 tailwindcss 并没有触发 + const set = getClassSet() + setRuntimeSet(set) if (Array.isArray(groupedEntries.html)) { for (let i = 0; i < groupedEntries.html.length; i++) { const [file, originalSource] = groupedEntries.html[i] @@ -75,9 +79,6 @@ export class UnifiedWebpackPluginV5 implements IBaseWebpackPlugin { } if (Array.isArray(groupedEntries.js)) { - // 再次 build 不转化的原因是此时 set.size 为0 - // 也就是说当开启缓存的时候没有触发 postcss,导致 tailwindcss 并没有触发 - const set = getClassSet() for (let i = 0; i < groupedEntries.js.length; i++) { const [file, originalSource] = groupedEntries.js[i] diff --git a/src/wxml/shared.ts b/src/wxml/shared.ts index 9542e8893..60e0972c4 100644 --- a/src/wxml/shared.ts +++ b/src/wxml/shared.ts @@ -2,6 +2,7 @@ import { ICommonReplaceOptions } from '@/types' import { escape } from '@/escape' import { SimpleMappingChars2String } from '@/dic' +import { useStore } from '@/mangle/store' export function replaceWxml( original: string, options: ICommonReplaceOptions | boolean = { @@ -21,7 +22,8 @@ export function replaceWxml( // 不能全去掉,头条小程序变量绑定,实现方式依赖空格,你说坑不坑? .replace(/[\r\n]+/g, '') } - + const { wxmlHandler } = useStore() + res = wxmlHandler(res) res = escape(res, { map: options.escapeMap }) diff --git a/test/__snapshots__/webpack.v5.test.ts.snap b/test/__snapshots__/webpack.v5.test.ts.snap index 1542e12a8..0eab6d371 100644 --- a/test/__snapshots__/webpack.v5.test.ts.snap +++ b/test/__snapshots__/webpack.v5.test.ts.snap @@ -871,20 +871,20 @@ view,::before,::after { --tw-backdrop-saturate: ; --tw-backdrop-sepia: } -.-m-_bl_20px_br_ { +.cb { margin: -20px } -.m-_bl_20px_br_ { +.sa { margin: 20px } -.mx-auto { +.qa { margin-left: auto; margin-right: auto } -.-mt-2 { +.b { margin-top: -0.5rem } -.mb-_bl_-20px_br_ { +.c { margin-bottom: -20px } .flex { @@ -893,171 +893,171 @@ view,::before,::after { .grid { display: grid } -.h-10 { +.oa { height: 2.5rem } -.h-_bl_100px_br_ { +.p { height: 100px } -.h-_bl_200_p__br_ { +.a { height: 200% } -.h-_bl_99px_br_ { +.ab { height: 99px } -.max-h-_bl_100px_br_ { +.i { max-height: 100px } -.min-h-_bl_100px_br_ { +.m { min-height: 100px } -.w-10 { +.pa { width: 2.5rem } -.w-32 { +.fa { width: 8rem } -.w-_bl_100px_br_ { +.q { width: 100px } -.w-_bl_20px_br_ { +.ra { width: 20px } -.w-_bl_300rpx_br_ { +.f { width: 300rpx } -.w-_bl_99px_br_ { +.za { width: 99px } -.min-w-_bl_300rpx_br_ { +.j { min-width: 300rpx } -.max-w-_bl_300rpx_br_ { +.n { max-width: 300rpx } -.grid-cols-3 { +.ba { grid-template-columns: repeat(3, minmax(0, 1fr)) } -.items-center { +.r { align-items: center } -.justify-center { +.s { justify-content: center } -.space-y-_bl_1_d_6rem_br_>view + view { +.e>view + view { --tw-space-y-reverse: 0; margin-top: calc(1.6rem * calc(1 - var(--tw-space-y-reverse))); margin-bottom: calc(1.6rem * var(--tw-space-y-reverse)) } -.divide-x-_bl_10px_br_>view + view { +.ca>view + view { --tw-divide-x-reverse: 0; border-right-width: calc(10px * var(--tw-divide-x-reverse)); border-left-width: calc(10px * calc(1 - var(--tw-divide-x-reverse))) } -.divide-solid>view + view { +.da>view + view { border-style: solid } -.divide-_bl__h_010101_br_>view + view { +.ea>view + view { --tw-divide-opacity: 1; border-color: rgb(1 1 1 / var(--tw-divide-opacity)) } -.rounded-_bl_40px_br_ { +.t { border-radius: 40px } -.rounded-md { +.ga { border-radius: 0.375rem } -.border-0 { +.na { border-width: 0px } -.border-_bl_10px_br_ { +.x { border-width: 10px } -.border-solid { +.y { border-style: solid } -.border-_bl__h_098765_br_ { +.z { --tw-border-opacity: 1; border-color: rgb(9 135 101 / var(--tw-border-opacity)) } -.border-opacity-_bl_0_d_44_br_ { +.aa { --tw-border-opacity: 0.44 } -.bg-_bl__h_123456_br_ { +.u { --tw-bg-opacity: 1; background-color: rgb(18 52 86 / var(--tw-bg-opacity)) } -.bg-pink-500 { +.ha { --tw-bg-opacity: 1; background-color: rgb(236 72 153 / var(--tw-bg-opacity)) } -.bg-sky-700 { +.ta { --tw-bg-opacity: 1; background-color: rgb(3 105 161 / var(--tw-bg-opacity)) } -.bg-opacity-_bl_0_d_54_br_ { +.v { --tw-bg-opacity: 0.54 } -.bg-_bl_url_pl__q_https_c__s__s_xxx_d_com_s_xx_d_webp_q__qr__br_ { +.ya { background-image: url('https://xxx.com/xx.webp') } -.bg-_bl_url_pl__q_https_c__s__s_yyy_d_com_s_xx_d_webp_q__qr__br_ { +.bb { background-image: url('https://yyy.com/xx.webp') } -.p-_bl_20px_br_ { +.d { padding: 20px } -.px-4 { +.ua { padding-left: 1rem; padding-right: 1rem } -.py-2 { +.ia { padding-top: 0.5rem; padding-bottom: 0.5rem } -.text-_bl_20px_br_ { +.k { font-size: 20px } -.font-semibold { +.ja { font-weight: 600 } -.leading-_bl_0_d_9_br_ { +.l { line-height: 0.9 } -.text-_bl__h_dddddd_br_ { +.o { --tw-text-opacity: 1; color: rgb(221 221 221 / var(--tw-text-opacity)) } -.text-_bl__h_ffffff_br_ { +.w { --tw-text-opacity: 1; color: rgb(255 255 255 / var(--tw-text-opacity)) } -.text-black { +.g { --tw-text-opacity: 1; color: rgb(0 0 0 / var(--tw-text-opacity)) } -.text-white { +.ka { --tw-text-opacity: 1; color: rgb(255 255 255 / var(--tw-text-opacity)) } -.text-opacity-_bl_0_d_19_br_ { +.h { --tw-text-opacity: 0.19 } -.ring-4 { +.la { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color); box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000) } -.ring-pink-300 { +.ma { --tw-ring-opacity: 1; --tw-ring-color: rgb(249 168 212 / var(--tw-ring-opacity)) } @media (min-width: 640px) { - .sm_c_px-8 { + .wa { padding-left: 2rem; padding-right: 2rem } - .sm_c_py-3 { + .xa { padding-top: 0.75rem; padding-bottom: 0.75rem } @@ -1071,41 +1071,41 @@ view,::before,::after {