diff --git a/.eslintignore b/.eslintignore
deleted file mode 100644
index 77741f15..00000000
--- a/.eslintignore
+++ /dev/null
@@ -1,4 +0,0 @@
-packages/unplugin-tailwindcss-mangle/test/fixtures/**/*
-packages/tailwindcss-patch/test/fixtures/**/*
-packages/*/dist
-packages/**/fixtures
\ No newline at end of file
diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index 61eb8409..00000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,8 +0,0 @@
-/** @type {import('eslint').Linter.Config} */
-module.exports = {
- root: true,
- extends: ['icebreaker', 'plugin:prettier/recommended'],
- rules: {
- 'unicorn/prefer-at': 0
- }
-}
diff --git a/.prettierrc b/.prettierrc
deleted file mode 100644
index bd874ae1..00000000
--- a/.prettierrc
+++ /dev/null
@@ -1,9 +0,0 @@
-{
- "tabWidth": 2,
- "useTabs": false,
- "semi": false,
- "singleQuote": true,
- "endOfLine": "lf",
- "trailingComma": "none",
- "printWidth": 180
-}
\ No newline at end of file
diff --git a/eslint.config.mjs b/eslint.config.mjs
new file mode 100644
index 00000000..6f39e845
--- /dev/null
+++ b/eslint.config.mjs
@@ -0,0 +1,11 @@
+import { icebreaker } from '@icebreakers/eslint-config'
+
+export default icebreaker({}, {
+ ignores: [
+ '**/fixtures/**',
+ ],
+}, {
+ rules: {
+ 'no-console': 'off',
+ },
+})
diff --git a/package.json b/package.json
index d6a48e86..a6d4eb3c 100644
--- a/package.json
+++ b/package.json
@@ -11,8 +11,8 @@
"dev": "pnpm -r run dev",
"test": "vitest run --coverage.enabled",
"test:dev": "vitest --coverage.enabled",
- "lint": "pnpm run -r lint",
- "format": "prettier --write \"**/*.{ts,tsx,md}\"",
+ "lint": "eslint packages",
+ "lint:fix": "eslint packages --fix",
"preinstall": "npx only-allow pnpm",
"sync": "cnpm sync @tailwindcss-mangle/shared @tailwindcss-mangle/config tailwindcss-patch unplugin-tailwindcss-mangle @tailwindcss-mangle/core",
"publish-packages": "pnpm run test && changeset version && changeset publish",
@@ -21,6 +21,7 @@
"devDependencies": {
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.2",
+ "@icebreakers/eslint-config": "^0.2.0",
"@tailwindcss-mangle/core": "workspace:*",
"@tailwindcss-mangle/shared": "workspace:*",
"@tsconfig/recommended": "^1.0.6",
@@ -33,12 +34,8 @@
"defu": "^6.1.4",
"del": "^7.1.0",
"eslint": "^9.3.0",
- "eslint-config-icebreaker": "^1.2.3",
- "eslint-config-prettier": "^9.1.0",
- "eslint-plugin-prettier": "^5.1.3",
"lodash-es": "^4.17.21",
"only-allow": "^1.2.1",
- "prettier": "^3.2.5",
"rollup": "^4.17.2",
"tailwindcss-patch": "workspace:*",
"ts-node": "^10.9.2",
@@ -52,5 +49,5 @@
"engines": {
"node": ">=18.0.0"
},
- "packageManager": "pnpm@9.1.0"
-}
+ "packageManager": "pnpm@9.1.1"
+}
\ No newline at end of file
diff --git a/packages/config/build.config.ts b/packages/config/build.config.ts
index 45c5d795..1e185024 100644
--- a/packages/config/build.config.ts
+++ b/packages/config/build.config.ts
@@ -9,11 +9,11 @@ export default defineBuildConfig({
cjsBridge: true,
dts: {
// https://github.com/unjs/unbuild/issues/135
- respectExternal: false
- }
+ respectExternal: false,
+ },
},
alias: {
- '@': path.resolve(__dirname, './src')
+ '@': path.resolve(__dirname, './src'),
},
- declaration: true
+ declaration: true,
})
diff --git a/packages/config/package.json b/packages/config/package.json
index 030d6e38..86819952 100644
--- a/packages/config/package.json
+++ b/packages/config/package.json
@@ -2,6 +2,22 @@
"name": "@tailwindcss-mangle/config",
"version": "2.2.2",
"description": "The config and load function of tailwindcss-mangle",
+ "author": "SonOfMagic ",
+ "license": "MIT",
+ "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
+ },
+ "keywords": [
+ "tailwindcss",
+ "mangle",
+ "patch",
+ "core",
+ "mangle",
+ "shared",
+ "utils"
+ ],
"exports": {
".": {
"types": "./dist/index.d.ts",
@@ -9,6 +25,9 @@
"require": "./dist/index.cjs"
}
},
+ "main": "./dist/index.cjs",
+ "module": "./dist/index.mjs",
+ "types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
@@ -17,9 +36,6 @@
]
}
},
- "main": "./dist/index.cjs",
- "module": "./dist/index.mjs",
- "types": "./dist/index.d.ts",
"files": [
"dist"
],
@@ -29,17 +45,6 @@
"test": "vitest run --coverage.enabled",
"test:dev": "vitest"
},
- "keywords": [
- "tailwindcss",
- "mangle",
- "patch",
- "core",
- "mangle",
- "shared",
- "utils"
- ],
- "author": "SonOfMagic ",
- "license": "MIT",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
@@ -48,10 +53,5 @@
"@tailwindcss-mangle/shared": "workspace:^",
"c12": "^1.10.0",
"dedent": "^1.5.3"
- },
- "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
}
}
diff --git a/packages/config/src/config.ts b/packages/config/src/config.ts
index 2a546712..bfcfe0e9 100644
--- a/packages/config/src/config.ts
+++ b/packages/config/src/config.ts
@@ -1,6 +1,6 @@
import path from 'node:path'
import fs from 'node:fs/promises'
-import { loadConfig, createDefineConfig } from 'c12'
+import { createDefineConfig, loadConfig } from 'c12'
import dedent from 'dedent'
import type { UserConfig } from './types'
import { getDefaultUserConfig } from './defaults'
@@ -10,9 +10,9 @@ export function getConfig(cwd?: string) {
return loadConfig({
name: configName,
defaults: {
- ...getDefaultUserConfig()
+ ...getDefaultUserConfig(),
},
- cwd
+ cwd,
})
}
@@ -26,6 +26,6 @@ export function initConfig(cwd: string) {
export default defineConfig({})
`,
- 'utf8'
+ 'utf8',
)
}
diff --git a/packages/config/src/defaults.ts b/packages/config/src/defaults.ts
index ad575111..4c574e8a 100644
--- a/packages/config/src/defaults.ts
+++ b/packages/config/src/defaults.ts
@@ -1,14 +1,15 @@
+import process from 'node:process'
import { defaultMangleClassFilter } from '@tailwindcss-mangle/shared'
-import type { PatchUserConfig, UserConfig, MangleUserConfig } from './types'
+import type { MangleUserConfig, PatchUserConfig, UserConfig } from './types'
export function getDefaultPatchConfig(): PatchUserConfig {
return {
output: {
filename: '.tw-patch/tw-class-list.json',
removeUniversalSelector: true,
- loose: true
+ loose: true,
},
- tailwindcss: {}
+ tailwindcss: {},
}
}
@@ -22,15 +23,15 @@ export function getDefaultMangleUserConfig(): MangleUserConfig {
classMapOutput: {
enable: false,
filename: '.tw-patch/tw-map-list.json',
- loose: true
+ loose: true,
},
- preserveFunction: []
+ preserveFunction: [],
}
}
export function getDefaultUserConfig(): UserConfig {
return {
patch: getDefaultPatchConfig(),
- mangle: getDefaultMangleUserConfig()
+ mangle: getDefaultMangleUserConfig(),
}
}
diff --git a/packages/config/test/index.test.ts b/packages/config/test/index.test.ts
index f07db23f..c5fe511c 100644
--- a/packages/config/test/index.test.ts
+++ b/packages/config/test/index.test.ts
@@ -2,8 +2,8 @@ import { resolve } from 'node:path'
import { existsSync } from 'node:fs'
import { deleteAsync } from 'del'
import { fixturesRoot } from './utils'
-import { initConfig, getConfig } from '@/index'
-import { getDefaultUserConfig, getDefaultMangleUserConfig } from '@/defaults'
+import { getConfig, initConfig } from '@/index'
+import { getDefaultMangleUserConfig, getDefaultUserConfig } from '@/defaults'
import { configName } from '@/constants'
describe('config', () => {
@@ -29,13 +29,13 @@ describe('config', () => {
output: {
filename: 'xxx/yyy/zzz.json',
loose: false,
- removeUniversalSelector: false
+ removeUniversalSelector: false,
},
tailwindcss: {
- cwd: 'aaa/bbb/cc'
- }
+ cwd: 'aaa/bbb/cc',
+ },
},
- mangle: getDefaultMangleUserConfig()
+ mangle: getDefaultMangleUserConfig(),
})
})
diff --git a/packages/config/tsconfig.json b/packages/config/tsconfig.json
index d6c27bee..65483f39 100644
--- a/packages/config/tsconfig.json
+++ b/packages/config/tsconfig.json
@@ -12,4 +12,4 @@
"src",
"test"
]
-}
\ No newline at end of file
+}
diff --git a/packages/config/vitest.config.ts b/packages/config/vitest.config.ts
index a688df69..925b0dbf 100644
--- a/packages/config/vitest.config.ts
+++ b/packages/config/vitest.config.ts
@@ -6,10 +6,10 @@ export default defineProject({
alias: [
{
find: '@',
- replacement: path.resolve(__dirname, './src')
- }
+ replacement: path.resolve(__dirname, './src'),
+ },
],
globals: true,
- testTimeout: 60_000
- }
+ testTimeout: 60_000,
+ },
})
diff --git a/packages/core/build.config.ts b/packages/core/build.config.ts
index 45c5d795..1e185024 100644
--- a/packages/core/build.config.ts
+++ b/packages/core/build.config.ts
@@ -9,11 +9,11 @@ export default defineBuildConfig({
cjsBridge: true,
dts: {
// https://github.com/unjs/unbuild/issues/135
- respectExternal: false
- }
+ respectExternal: false,
+ },
},
alias: {
- '@': path.resolve(__dirname, './src')
+ '@': path.resolve(__dirname, './src'),
},
- declaration: true
+ declaration: true,
})
diff --git a/packages/core/package.json b/packages/core/package.json
index ca3ac925..618e6957 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -2,6 +2,22 @@
"name": "@tailwindcss-mangle/core",
"version": "2.2.2",
"description": "The core of tailwindcss-mangle",
+ "author": "SonOfMagic ",
+ "license": "MIT",
+ "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
+ },
+ "bugs": {
+ "url": "https://github.com/sonofmagic/tailwindcss-mangle/issues"
+ },
+ "keywords": [
+ "tailwindcss",
+ "patch",
+ "core",
+ "mangle"
+ ],
"exports": {
".": {
"types": "./dist/index.d.ts",
@@ -9,6 +25,9 @@
"require": "./dist/index.cjs"
}
},
+ "main": "./dist/index.cjs",
+ "module": "./dist/index.mjs",
+ "types": "./dist/index.d.ts",
"typesVersions": {
"*": {
"*": [
@@ -17,9 +36,6 @@
]
}
},
- "main": "./dist/index.cjs",
- "module": "./dist/index.mjs",
- "types": "./dist/index.d.ts",
"files": [
"dist"
],
@@ -30,14 +46,6 @@
"test:dev": "vitest",
"coverage": "vitest run --coverage"
},
- "keywords": [
- "tailwindcss",
- "patch",
- "core",
- "mangle"
- ],
- "author": "SonOfMagic ",
- "license": "MIT",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
@@ -64,14 +72,6 @@
"@vue/compiler-core": "^3.4.27",
"@vue/compiler-sfc": "^3.4.27"
},
- "homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
- "repository": {
- "type": "git",
- "url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
- },
- "bugs": {
- "url": "https://github.com/sonofmagic/tailwindcss-mangle/issues"
- },
"directories": {
"test": "test"
}
diff --git a/packages/core/src/css/index.ts b/packages/core/src/css/index.ts
index 6093f96a..c4c3158e 100644
--- a/packages/core/src/css/index.ts
+++ b/packages/core/src/css/index.ts
@@ -1,5 +1,5 @@
import postcss from 'postcss'
-import { ICssHandlerOptions } from '../types'
+import type { ICssHandlerOptions } from '../types'
import { transformSelectorPostcssPlugin } from './plugins'
export function cssHandler(rawSource: string, options: ICssHandlerOptions) {
@@ -7,6 +7,6 @@ export function cssHandler(rawSource: string, options: ICssHandlerOptions) {
const { file } = options
return postcss(acceptedPlugins).process(rawSource, {
from: file,
- to: file
+ to: file,
})
}
diff --git a/packages/core/src/css/plugins.ts b/packages/core/src/css/plugins.ts
index d823a2db..6c9e86ac 100644
--- a/packages/core/src/css/plugins.ts
+++ b/packages/core/src/css/plugins.ts
@@ -1,7 +1,8 @@
import type { PluginCreator } from 'postcss'
import defu from 'defu'
import parser from 'postcss-selector-parser'
-import { ICssHandlerOptions } from '@/types'
+import type { ICssHandlerOptions } from '@/types'
+
export type PostcssMangleTailwindcssPlugin = PluginCreator
const postcssPlugin = 'postcss-mangle-tailwindcss-plugin'
@@ -23,7 +24,7 @@ export function isVueScoped(s: parser.ClassName): boolean {
export const transformSelectorPostcssPlugin: PluginCreator = function (options) {
const { ignoreVueScoped, replaceMap, ctx } = defu(options, {
- ignoreVueScoped: true
+ ignoreVueScoped: true,
})
return {
@@ -52,9 +53,9 @@ export const transformSelectorPostcssPlugin: PluginCreator =
})
}).transform(rule, {
lossless: false,
- updateSelector: true
+ updateSelector: true,
})
- }
+ },
}
}
transformSelectorPostcssPlugin.postcss = true
diff --git a/packages/core/src/ctx/index.ts b/packages/core/src/ctx/index.ts
index 0ab21333..1c0de915 100644
--- a/packages/core/src/ctx/index.ts
+++ b/packages/core/src/ctx/index.ts
@@ -1,5 +1,6 @@
import fs from 'node:fs'
-import { resolve, isAbsolute } from 'node:path'
+import { isAbsolute, resolve } from 'node:path'
+import process from 'node:process'
import { ClassGenerator } from '@tailwindcss-mangle/shared'
import { getConfig } from '@tailwindcss-mangle/config'
import type { MangleUserConfig } from '@tailwindcss-mangle/config'
@@ -60,7 +61,7 @@ export class Context {
this.classGenerator = new ClassGenerator(this.options.classGenerator)
this.preserveFunctionSet = new Set(this.options?.preserveFunction ?? [])
this.preserveFunctionRegexs = [...this.preserveFunctionSet.values()].map((x) => {
- return new RegExp(escapeStringRegexp(x) + '\\(([^)]*)\\)', 'g')
+ return new RegExp(`${escapeStringRegexp(x)}\\(([^)]*)\\)`, 'g')
})
}
@@ -94,7 +95,7 @@ export class Context {
}
loadClassSet(classList: string[]) {
- const list = sort(classList).desc((c) => c.length)
+ const list = sort(classList).desc(c => c.length)
for (const className of list) {
if (this.currentMangleClassFilter(className)) {
this.classSet.add(className)
@@ -109,7 +110,8 @@ export class Context {
this.mergeOptions(mangleOptions, config?.mangle)
if (_classList) {
this.loadClassSet(_classList)
- } else {
+ }
+ else {
let jsonPath = this.options.classListPath ?? resolve(process.cwd(), config?.patch?.output?.filename as string)
if (!isAbsolute(jsonPath)) {
jsonPath = resolve(configCwd ?? process.cwd(), jsonPath)
diff --git a/packages/core/src/env.ts b/packages/core/src/env.ts
index 5c12fbda..b6180436 100644
--- a/packages/core/src/env.ts
+++ b/packages/core/src/env.ts
@@ -1,2 +1,4 @@
+import process from 'node:process'
+
export const isProd = () => process.env.NODE_ENV === 'production'
export const isDev = () => process.env.NODE_ENV === 'development'
diff --git a/packages/core/src/html/index.ts b/packages/core/src/html/index.ts
index e9489de1..e768e4c3 100644
--- a/packages/core/src/html/index.ts
+++ b/packages/core/src/html/index.ts
@@ -1,6 +1,6 @@
import { parse, serialize } from 'parse5'
import { traverse } from '@parse5/tools'
-import { IHtmlHandlerOptions } from '../types'
+import type { IHtmlHandlerOptions } from '../types'
import { makeRegex, splitCode } from '../shared'
// const { traverse } = await import('@parse5/tools')
export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) {
@@ -8,10 +8,10 @@ export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) {
const fragment = parse(rawSource)
traverse(fragment, {
element(node) {
- const attribute = node.attrs.find((x) => x.name === 'class')
+ const attribute = node.attrs.find(x => x.name === 'class')
if (attribute) {
const array = splitCode(attribute.value, {
- splitQuote: false
+ splitQuote: false,
})
for (const v of array) {
if (replaceMap.has(v)) {
@@ -19,7 +19,7 @@ export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) {
}
}
}
- }
+ },
})
return serialize(fragment)
}
diff --git a/packages/core/src/js/index.ts b/packages/core/src/js/index.ts
index c22c3bc7..58dd77b0 100644
--- a/packages/core/src/js/index.ts
+++ b/packages/core/src/js/index.ts
@@ -1,22 +1,23 @@
-import type { StringLiteral, TemplateElement, CallExpression } from '@babel/types'
-import { transformSync, type BabelFileResult, type NodePath } from '@babel/core'
+import type { CallExpression, StringLiteral, TemplateElement } from '@babel/types'
+import { type BabelFileResult, type NodePath, transformSync } from '@babel/core'
import type { IJsHandlerOptions } from '../types'
import { makeRegex, splitCode } from '../shared'
import { isProd as isProduction } from '../env'
+
export { preProcessJs, preProcessRawCode } from './pre'
export function handleValue(raw: string, node: StringLiteral | TemplateElement, options: IJsHandlerOptions) {
const { replaceMap, ctx, splitQuote = true } = options
const clsGen = ctx.classGenerator
const array = splitCode(raw, {
- splitQuote
+ splitQuote,
})
let rawString = raw
for (const v of array) {
if (replaceMap.has(v)) {
let ignoreFlag = false
if (Array.isArray(node.leadingComments)) {
- ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes('tw-mangle') && x.value.includes('ignore')) > -1
+ ignoreFlag = node.leadingComments.findIndex(x => x.value.includes('tw-mangle') && x.value.includes('ignore')) > -1
}
if (!ignoreFlag) {
@@ -39,13 +40,13 @@ export function jsHandler(rawSource: string, options: IJsHandlerOptions) {
enter(p: NodePath) {
const n = p.node
n.value = handleValue(n.value, n, options)
- }
+ },
},
TemplateElement: {
enter(p: NodePath) {
const n = p.node
n.value.raw = handleValue(n.value.raw, n, options)
- }
+ },
},
CallExpression: {
enter(p: NodePath) {
@@ -59,20 +60,20 @@ export function jsHandler(rawSource: string, options: IJsHandlerOptions) {
if (res.code) {
s.node.value = res.code
}
- }
- }
+ },
+ },
})
}
- }
- }
+ },
+ },
// noScope: true
- }
+ },
}
- }
+ },
],
minified: options.minified ?? isProduction(),
sourceMaps: false,
- configFile: false
+ configFile: false,
})
return result as BabelFileResult
diff --git a/packages/core/src/js/pre.ts b/packages/core/src/js/pre.ts
index f9310b25..b51811a2 100644
--- a/packages/core/src/js/pre.ts
+++ b/packages/core/src/js/pre.ts
@@ -35,7 +35,7 @@ export function handleValue(options: HandleValueOptions) {
}
}
- const arr = sort(splitCode(value)).desc((x) => x.length)
+ const arr = sort(splitCode(value)).desc(x => x.length)
for (const str of arr) {
if (replaceMap.has(str)) {
@@ -74,11 +74,11 @@ export const JsPlugin = declare((api, options: Options) => {
replaceMap,
offset: 1,
escape: true,
- markedArray
+ markedArray,
}
handleValue(opts)
- }
+ },
},
TemplateElement: {
exit(p) {
@@ -91,13 +91,13 @@ export const JsPlugin = declare((api, options: Options) => {
replaceMap,
offset: 0,
escape: false,
- markedArray
+ markedArray,
}
handleValue(opts)
- }
- }
- }
+ },
+ },
+ },
}
})
@@ -112,7 +112,7 @@ function transformSync(ast: babel.types.Node, code: string, plugins: babel.Plugi
babel.transformFromAstSync(ast, code, {
presets: loadPresets(),
plugins,
- filename
+ filename,
})
}
@@ -122,9 +122,9 @@ export function loadPresets() {
require('@babel/preset-typescript'),
{
allExtensions: true,
- isTSX: true
- }
- ]
+ isTSX: true,
+ },
+ ],
]
}
@@ -135,14 +135,16 @@ export function preProcessJs(options: IPreProcessJsOptions): string {
try {
const file = babel.parseSync(magicString.original, {
sourceType: 'unambiguous',
- presets: loadPresets()
+ presets: loadPresets(),
})
if (file) {
ast = file
- } else {
+ }
+ else {
return code.toString()
}
- } catch {
+ }
+ catch {
return code.toString()
}
const markedArray: [number, number][] = []
@@ -160,32 +162,32 @@ export function preProcessJs(options: IPreProcessJsOptions): string {
enter(path) {
const node = path.node
const value = node.value
- const arr = sort(splitCode(value)).desc((x) => x.length)
+ const arr = sort(splitCode(value)).desc(x => x.length)
for (const str of arr) {
if (replaceMap.has(str)) {
ctx.addPreserveClass(str)
}
}
- }
+ },
},
TemplateElement: {
enter(path) {
const node = path.node
const value = node.value.raw
- const arr = sort(splitCode(value)).desc((x) => x.length)
+ const arr = sort(splitCode(value)).desc(x => x.length)
for (const str of arr) {
if (replaceMap.has(str)) {
ctx.addPreserveClass(str)
}
}
- }
- }
+ },
+ },
})
}
- }
- }
+ },
+ },
})
transformSync(
@@ -199,11 +201,11 @@ export function preProcessJs(options: IPreProcessJsOptions): string {
replaceMap,
id,
ctx,
- markedArray
- }
- ]
+ markedArray,
+ },
+ ],
],
- id
+ id,
)
return magicString.toString()
@@ -232,34 +234,35 @@ export function preProcessRawCode(options: IPreProcessRawCodeOptions): string {
let ast: ParseResult | null
try {
ast = babel.parseSync(regExpMatch[0], {
- sourceType: 'unambiguous'
+ sourceType: 'unambiguous',
})
- ast &&
- babel.traverse(ast, {
- StringLiteral: {
- enter(p) {
- const arr = sort(splitCode(p.node.value)).desc((x) => x.length)
+ ast
+ && babel.traverse(ast, {
+ StringLiteral: {
+ enter(p) {
+ const arr = sort(splitCode(p.node.value)).desc(x => x.length)
- for (const v of arr) {
- if (replaceMap.has(v)) {
- ctx.addPreserveClass(v)
- }
+ for (const v of arr) {
+ if (replaceMap.has(v)) {
+ ctx.addPreserveClass(v)
}
}
},
- TemplateElement: {
- enter(p) {
- const arr = sort(splitCode(p.node.value.raw)).desc((x) => x.length)
- for (const v of arr) {
- if (replaceMap.has(v)) {
- ctx.addPreserveClass(v)
- }
+ },
+ TemplateElement: {
+ enter(p) {
+ const arr = sort(splitCode(p.node.value.raw)).desc(x => x.length)
+ for (const v of arr) {
+ if (replaceMap.has(v)) {
+ ctx.addPreserveClass(v)
}
}
- }
- })
- } catch {
+ },
+ },
+ })
+ }
+ catch {
continue
}
}
diff --git a/packages/core/src/js/utils.ts b/packages/core/src/js/utils.ts
index 9c2870f8..e2347756 100644
--- a/packages/core/src/js/utils.ts
+++ b/packages/core/src/js/utils.ts
@@ -1,4 +1,4 @@
-import babel from '@babel/core'
+import type babel from '@babel/core'
// const t = babel.types
export function getStringLiteralCalleeName(path: babel.NodePath) {
if (path.parentPath.isCallExpression()) {
diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts
index 4ec4ccbe..624a51a9 100644
--- a/packages/core/src/types.ts
+++ b/packages/core/src/types.ts
@@ -1,4 +1,5 @@
import type { Context } from './ctx'
+
export interface IClassGeneratorContextItem {
name: string
usedBy: string[]
diff --git a/packages/core/test/css.test.ts b/packages/core/test/css.test.ts
index 62774c3e..a28b0bb8 100644
--- a/packages/core/test/css.test.ts
+++ b/packages/core/test/css.test.ts
@@ -1,6 +1,7 @@
import { getTestCase } from './utils'
import { cssHandler } from '@/css'
import { Context } from '@/ctx'
+
describe('css', () => {
let ctx: Context
beforeEach(() => {
@@ -16,20 +17,20 @@ describe('css', () => {
ctx.addPreserveClass('gap-y-4')
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
})
expect(css).toMatchSnapshot()
})
it('preserveClassNamesSet case 1', async () => {
await ctx.initConfig({
- classList: ['gap-y-4']
+ classList: ['gap-y-4'],
})
const testCase = `.gap-y-4 {color:red;}`
ctx.addPreserveClass('gap-y-4')
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap: ctx.getReplaceMap()
+ replaceMap: ctx.getReplaceMap(),
})
expect(css).toMatchSnapshot()
})
@@ -45,7 +46,7 @@ describe('css', () => {
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
})
expect(css).toMatchSnapshot()
})
@@ -61,7 +62,7 @@ describe('css', () => {
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
})
expect(css).toMatchSnapshot()
})
@@ -78,7 +79,7 @@ describe('css', () => {
const { css } = await cssHandler(testCase, {
ctx,
replaceMap,
- ignoreVueScoped: false
+ ignoreVueScoped: false,
})
expect(css).toMatchSnapshot()
})
@@ -95,7 +96,7 @@ describe('css', () => {
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
})
expect(css).toMatchSnapshot()
})
@@ -109,7 +110,7 @@ describe('css', () => {
const testCase = getTestCase('vue.scoped.css')
const { css } = await cssHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
})
expect(css).toMatchSnapshot()
})
diff --git a/packages/core/test/html.test.ts b/packages/core/test/html.test.ts
index ee47e05e..8972597f 100644
--- a/packages/core/test/html.test.ts
+++ b/packages/core/test/html.test.ts
@@ -18,7 +18,7 @@ describe('html handler', () => {
}
const res = htmlHandler(getTestCase('hello-world.html'), {
ctx,
- replaceMap
+ replaceMap,
})
expect(res).toMatchSnapshot()
})
@@ -31,7 +31,7 @@ describe('html handler', () => {
}
const res = htmlHandler(getTestCase('trailing-slash.html'), {
ctx,
- replaceMap
+ replaceMap,
})
expect(res).toMatchSnapshot()
})
@@ -44,7 +44,7 @@ describe('html handler', () => {
}
const res = htmlHandler(getTestCase('trailing-slash-0.html'), {
ctx,
- replaceMap
+ replaceMap,
})
expect(res).toMatchSnapshot()
})
diff --git a/packages/core/test/js.test.ts b/packages/core/test/js.test.ts
index 7bd2c370..f963265e 100644
--- a/packages/core/test/js.test.ts
+++ b/packages/core/test/js.test.ts
@@ -21,11 +21,11 @@ describe('js handler', async () => {
const replaceMap = new Map()
replaceMap.set('dark:bg-zinc-800/30', true)
replaceMap.set('lg:dark:bg-zinc-800/30', true)
- // eslint-disable-next-line no-template-curly-in-string
+
const testCase = 'element.innerHTML = \'count is counter
\''
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -34,12 +34,12 @@ describe('js handler', async () => {
const replaceMap = new Map()
replaceMap.set('dark:bg-zinc-800/30', true)
replaceMap.set('lg:dark:bg-zinc-800/30', true)
- // eslint-disable-next-line no-template-curly-in-string
+
const testCase = 'element.innerHTML = \'count is counter
\''
const code = jsHandler(testCase, {
ctx,
replaceMap,
- splitQuote: false
+ splitQuote: false,
}).code
expect(code).toMatchSnapshot()
})
@@ -48,11 +48,11 @@ describe('js handler', async () => {
const replaceMap = new Map()
replaceMap.set('dark:bg-zinc-800/30', true)
replaceMap.set('lg:dark:bg-zinc-800/30', true)
- // eslint-disable-next-line no-template-curly-in-string
+
const testCase = 'const counter = 0;element.innerHTML = `count is ${counter}
`'
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -81,7 +81,7 @@ describe('js handler', async () => {
const testCase = `{ className: "z-10 w-full max-w-5xl items-center justify-between font-mono text-sm lg:flex" }`
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -96,7 +96,7 @@ describe('js handler', async () => {
const code = jsHandler(testCase, {
ctx,
replaceMap,
- splitQuote: false
+ splitQuote: false,
}).code
expect(code).toMatchSnapshot()
})
@@ -113,7 +113,7 @@ describe('js handler', async () => {
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -127,7 +127,7 @@ describe('js handler', async () => {
}
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -138,7 +138,7 @@ describe('js handler', async () => {
replaceMap.set('ease-out', true)
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -150,7 +150,7 @@ describe('js handler', async () => {
const code = jsHandler(testCase, {
ctx,
replaceMap,
- minified: true
+ minified: true,
}).code
expect(code).toMatchSnapshot()
})
@@ -162,7 +162,7 @@ describe('js handler', async () => {
replaceMap.set('ease-out', true)
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -174,7 +174,7 @@ describe('js handler', async () => {
replaceMap.set('bg-red-500/50', true)
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -187,7 +187,7 @@ describe('js handler', async () => {
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
@@ -200,19 +200,19 @@ describe('js handler', async () => {
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toMatchSnapshot()
})
- it('LINEFEED case', () => {
+ it('lINEFEED case', () => {
const testCase = 'const LINEFEED = "\\n";'
const replaceMap = new Map()
// replaceMap.set('bg-red-500/50', true)
// replaceMap.set('bg-red-500', true)
const code = jsHandler(testCase, {
ctx,
- replaceMap
+ replaceMap,
}).code
expect(code).toBe('const LINEFEED="\\n";')
})
@@ -226,10 +226,10 @@ describe('js handler', async () => {
code: testCase,
// @ts-ignore
ctx: {
- addToUsedBy: () => {}
+ addToUsedBy: () => {},
},
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toBe(testCase)
})
@@ -243,10 +243,10 @@ describe('js handler', async () => {
code: testCase,
// @ts-ignore
ctx: {
- addToUsedBy: () => {}
+ addToUsedBy: () => {},
},
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toBe('const LINEFEED = `a${n}a`;')
})
@@ -260,10 +260,10 @@ describe('js handler', async () => {
code: testCase,
// @ts-ignore
ctx: {
- addToUsedBy: () => {}
+ addToUsedBy: () => {},
},
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toBe('const LINEFEED = `a${n}a`;')
})
@@ -279,7 +279,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toMatchSnapshot()
})
@@ -290,8 +290,8 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: 'bg-red-500/50 bg-red-500 w-2 h-2 w-1 h-1 bg-red-400 bg-red-400/50'.split(' '),
mangleOptions: {
- preserveFunction: ['cn']
- }
+ preserveFunction: ['cn'],
+ },
})
// cn('w-10 h-10 bg-red-500 and bg-red-500/50')
@@ -304,7 +304,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(4)
@@ -323,8 +323,8 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: 'bg-red-500/50 bg-red-500 w-2 h-2 w-1 h-1 bg-red-400 bg-red-400/50'.split(' '),
mangleOptions: {
- preserveFunction: ['twMerge']
- }
+ preserveFunction: ['twMerge'],
+ },
})
const replaceMap = ctx.getReplaceMap()
@@ -333,7 +333,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(4)
@@ -346,8 +346,8 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: 'bg-red-500/50 bg-red-500 w-2 h-2 w-1 h-1 bg-red-400 bg-red-400/50'.split(' '),
mangleOptions: {
- preserveFunction: ['twMerge', 'cn']
- }
+ preserveFunction: ['twMerge', 'cn'],
+ },
})
const replaceMap = ctx.getReplaceMap()
@@ -361,7 +361,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
id: 'xxx',
- replaceMap
+ replaceMap,
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(8)
@@ -373,8 +373,8 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: 'px-2 py-1 bg-red hover:bg-dark-red p-3 bg-[#B91C1C] flex min-h-screen flex-col items-center justify-between p-24'.split(' '),
mangleOptions: {
- preserveFunction: ['twMerge']
- }
+ preserveFunction: ['twMerge'],
+ },
})
const replaceMap = ctx.getReplaceMap()
@@ -383,7 +383,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
replaceMap,
- id: 'xxx'
+ id: 'xxx',
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(6)
@@ -396,15 +396,15 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: require('./fixtures/preserve-fn-case1.json') as string[],
mangleOptions: {
- preserveFunction: ['twMerge']
- }
+ preserveFunction: ['twMerge'],
+ },
})
const replaceMap = ctx.getReplaceMap()
const code = preProcessRawCode({
code: testCase,
ctx,
replaceMap,
- id: 'xxx'
+ id: 'xxx',
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(6)
@@ -417,8 +417,8 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: require('./fixtures/preserve-fn-case2.json') as string[],
mangleOptions: {
- preserveFunction: ['twMerge']
- }
+ preserveFunction: ['twMerge'],
+ },
})
const replaceMap = ctx.getReplaceMap()
@@ -426,7 +426,7 @@ describe('js handler', async () => {
code: testCase,
ctx,
replaceMap,
- id: 'xxx'
+ id: 'xxx',
})
expect(code).toMatchSnapshot()
expect(ctx.preserveClassNamesSet.size).toBe(8)
@@ -435,7 +435,7 @@ describe('js handler', async () => {
it('tsx app0', async () => {
await ctx.initConfig({
- classList: require('./fixtures/app0.json') as string[]
+ classList: require('./fixtures/app0.json') as string[],
})
const replaceMap = ctx.getReplaceMap()
const code = getTestCase('app0.tsx')
@@ -444,14 +444,14 @@ describe('js handler', async () => {
code,
replaceMap,
ctx,
- id: 'xxx'
+ id: 'xxx',
})
expect(res).toMatchSnapshot()
})
it('ts vanilla-0', async () => {
await ctx.initConfig({
- classList: require('./fixtures/vanilla-0.json') as string[]
+ classList: require('./fixtures/vanilla-0.json') as string[],
})
const replaceMap = ctx.getReplaceMap()
const code = getTestCase('vanilla-0.ts')
@@ -460,7 +460,7 @@ describe('js handler', async () => {
code,
replaceMap,
ctx,
- id: 'xxx'
+ id: 'xxx',
})
expect(res).toMatchSnapshot()
})
@@ -476,15 +476,15 @@ describe('js handler', async () => {
await ctx.initConfig({
classList: 'p-1 p-2 p-3 p-4'.split(' '),
mangleOptions: {
- preserveFunction: ['cn']
- }
+ preserveFunction: ['cn'],
+ },
})
const replaceMap = ctx.getReplaceMap()
const res = preProcessJs({
code,
replaceMap,
ctx,
- id: 'xxx'
+ id: 'xxx',
})
expect(res).toMatchSnapshot()
})
diff --git a/packages/core/test/utils/index.ts b/packages/core/test/utils/index.ts
index f002ec45..386372ce 100644
--- a/packages/core/test/utils/index.ts
+++ b/packages/core/test/utils/index.ts
@@ -16,10 +16,10 @@ export async function getCss(raw: string | string[]) {
tailwindcss({
content: raw.map((x) => {
return {
- raw: x
+ raw: x,
}
- })
- })
+ }),
+ }),
]).process('@tailwind utilities;')
return res.css
}
diff --git a/packages/core/test/utils/svelte-to-tsx.ts b/packages/core/test/utils/svelte-to-tsx.ts
index 612e386b..27afe485 100644
--- a/packages/core/test/utils/svelte-to-tsx.ts
+++ b/packages/core/test/utils/svelte-to-tsx.ts
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
-/* eslint-disable camelcase */
+
import MagicString from 'magic-string'
/** @see https://github.com/sveltejs/svelte/blob/d3297e2a2595db08c85356d65fd5f953b04a681f/packages/svelte/src/compiler/preprocess/index.js#L255C1-L255C85 */
-const regex_style_tags = /|