Skip to content

Commit a4de2ba

Browse files
authored
feat: Feature/unplugin 2.x alpha (#36)
* chore: rename pkg name * feat: commit @tailwindcss-mangle/config * feat: commit config pkg * fix: tailwindcss-patch test case * feat: prepare for v2 plugin * feat: commit new eslint config * chore: format codes * feat: commit alpha unplugin * chore: allow test for unplugin-tailwindcss-mangle * fix: miss deps * chore: fix build error
1 parent df59586 commit a4de2ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1849
-1520
lines changed

.eslintrc.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1+
/** @type {import('eslint').Linter.Config} */
12
module.exports = {
23
root: true,
3-
extends: ['@icebreakers/eslint-config-ts', 'plugin:unicorn/recommended'],
4-
rules: {
5-
'unicorn/prefer-module': 0,
6-
'unicorn/prevent-abbreviations': 0,
7-
'unicorn/filename-case': 0,
8-
'unicorn/no-object-as-default-parameter': 0,
9-
'unicorn/no-null': 0
10-
}
4+
extends: ['icebreaker', 'plugin:prettier/recommended']
115
}

.vscode/launch.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
"type": "node-terminal",
1919
"cwd": "${workspaceFolder}/packages/tailwindcss-patch"
2020
},
21+
{
22+
"command": "npm run test:dev",
23+
"name": "[unplugin-tailwindcss-mangle] test:dev",
24+
"request": "launch",
25+
"type": "node-terminal",
26+
"cwd": "${workspaceFolder}/packages/unplugin-tailwindcss-mangle"
27+
},
2128
{
2229
"command": "npm run build",
2330
"name": "Debug nuxt-app",

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# tailwindcss-mangle
22

33
![star](https://badgen.net/github/stars/sonofmagic/tailwindcss-mangle)
4-
![dm0](https://badgen.net/npm/dm/tailwindcss-mangle-core)
5-
![dm1](https://badgen.net/npm/dm/tailwindcss-mangle-shared)
4+
![dm0](https://badgen.net/npm/dm/@tailwindcss-mangle/core)
5+
![dm1](https://badgen.net/npm/dm/@tailwindcss-mangle/shared)
66
![dm2](https://badgen.net/npm/dm/tailwindcss-patch)
77
![dm3](https://badgen.net/npm/dm/unplugin-tailwindcss-mangle)
88
[![test](https://github.com/sonofmagic/tailwindcss-mangle/actions/workflows/test.yml/badge.svg?branch=dev)](https://github.com/sonofmagic/tailwindcss-mangle/actions/workflows/test.yml)
@@ -12,8 +12,8 @@ A util for mangle tailwindcss
1212

1313
- [tailwindcss-mangle](#tailwindcss-mangle)
1414
- [tailwindcss-patch](#tailwindcss-patch)
15-
- [tailwindcss-mangle-core](#tailwindcss-mangle-core)
16-
- [tailwindcss-mangle-shared](#tailwindcss-mangle-shared)
15+
- [@tailwindcss-mangle/core](#@tailwindcss-mangle/core)
16+
- [@tailwindcss-mangle/shared](#@tailwindcss-mangle/shared)
1717
- [unplugin-tailwindcss-mangle](#unplugin-tailwindcss-mangle)
1818
- [How to use](#how-to-use)
1919

@@ -23,17 +23,17 @@ A util for mangle tailwindcss
2323

2424
click [tailwindcss-patch](./packages/tailwindcss-patch) for more details.
2525

26-
## tailwindcss-mangle-core
26+
## @tailwindcss-mangle/core
2727

2828
The core of tailwindcss-mangle
2929

30-
click [tailwindcss-mangle-core](./packages/core) for more details.
30+
click [@tailwindcss-mangle/core](./packages/core) for more details.
3131

32-
## tailwindcss-mangle-shared
32+
## @tailwindcss-mangle/shared
3333

3434
The shared utils of tailwindcss-mangle
3535

36-
click [tailwindcss-mangle-shared](./packages/shared) for more details.
36+
click [@tailwindcss-mangle/shared](./packages/shared) for more details.
3737

3838
## unplugin-tailwindcss-mangle
3939

apps/webpack5-vue3/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"vue-router": "^4.2.4"
1616
},
1717
"devDependencies": {
18-
"@typescript-eslint/eslint-plugin": "^6.2.1",
19-
"@typescript-eslint/parser": "^6.2.1",
18+
"@typescript-eslint/eslint-plugin": "^6.3.0",
19+
"@typescript-eslint/parser": "^6.3.0",
2020
"@vue/cli-plugin-babel": "~5.0.0",
2121
"@vue/cli-plugin-eslint": "~5.0.0",
2222
"@vue/cli-plugin-router": "~5.0.0",

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,37 @@
1515
"lint": "pnpm run -r lint",
1616
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1717
"preinstall": "npx only-allow pnpm",
18-
"sync": "cnpm sync tailwindcss-mangle-shared tailwindcss-patch unplugin-tailwindcss-mangle tailwindcss-mangle-core",
18+
"sync": "cnpm sync @tailwindcss-mangle/shared tailwindcss-patch unplugin-tailwindcss-mangle @tailwindcss-mangle/core",
1919
"publish-packages": "pnpm run build && pnpm run test && changeset version && changeset publish"
2020
},
2121
"devDependencies": {
2222
"@changesets/changelog-github": "^0.4.8",
2323
"@changesets/cli": "^2.26.2",
24-
"@icebreakers/eslint-config-ts": "^1.2.2",
25-
"@icebreakers/rollup": "^0.4.0",
26-
"@icebreakers/tsconfig": "^0.0.7",
24+
"eslint": "^8.46.0",
25+
"eslint-config-icebreaker": "^1.2.2",
26+
"eslint-config-prettier": "^9.0.0",
27+
"eslint-plugin-prettier": "^5.0.0",
28+
"@tailwindcss-mangle/core": "workspace:*",
29+
"@tailwindcss-mangle/shared": "workspace:*",
2730
"@tsconfig/recommended": "^1.0.2",
31+
"@types/lodash-es": "^4.17.8",
2832
"@types/node": "^20.4.8",
2933
"@vitest/coverage-v8": "^0.34.1",
3034
"cross-env": "^7.0.3",
31-
"eslint": "^8.46.0",
32-
"eslint-plugin-unicorn": "^48.0.1",
35+
"dedent": "^1.5.1",
36+
"defu": "^6.1.2",
37+
"del": "^7.0.0",
38+
"lodash-es": "^4.17.21",
3339
"only-allow": "^1.1.1",
3440
"prettier": "^3.0.1",
3541
"rollup": "^3.27.2",
36-
"tailwindcss-mangle-core": "workspace:*",
37-
"tailwindcss-mangle-shared": "workspace:*",
3842
"tailwindcss-patch": "workspace:*",
3943
"ts-node": "^10.9.1",
44+
"tslib": "^2.6.1",
4045
"typescript": "^5.1.6",
4146
"unbuild": "^1.2.1",
4247
"unplugin-tailwindcss-mangle": "workspace:*",
43-
"vitest": "^0.34.1",
44-
"dedent": "^1.5.1",
45-
"defu": "^6.1.2",
46-
"del": "^7.0.0",
47-
"tslib": "^2.6.1"
48+
"vitest": "^0.34.1"
4849
},
4950
"engines": {
5051
"node": ">=16.6.0"

packages/config/build.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
3+
export default defineBuildConfig({})

packages/config/package.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@tailwindcss-mangle/config",
3+
"version": "1.0.0",
4+
"description": "The config and load function of tailwindcss-mangle",
5+
"exports": {
6+
".": {
7+
"types": "./dist/index.d.ts",
8+
"import": "./dist/index.mjs",
9+
"require": "./dist/index.cjs"
10+
}
11+
},
12+
"typesVersions": {
13+
"*": {
14+
"*": [
15+
"./dist/*",
16+
"./dist/index.d.ts"
17+
]
18+
}
19+
},
20+
"main": "./dist/index.cjs",
21+
"module": "./dist/index.mjs",
22+
"types": "./dist/index.d.ts",
23+
"files": [
24+
"dist"
25+
],
26+
"scripts": {
27+
"build": "unbuild",
28+
"test": "vitest run",
29+
"test:dev": "vitest"
30+
},
31+
"keywords": [
32+
"tailwindcss",
33+
"mangle",
34+
"patch",
35+
"core",
36+
"mangle",
37+
"shared",
38+
"utils"
39+
],
40+
"author": "SonOfMagic <qq1324318532@gmail.com>",
41+
"license": "MIT",
42+
"publishConfig": {
43+
"access": "public",
44+
"registry": "https://registry.npmjs.org/"
45+
},
46+
"dependencies": {
47+
"c12": "^1.4.2",
48+
"dedent": "^1.5.1"
49+
},
50+
"homepage": "https://github.com/sonofmagic/tailwindcss-mangle",
51+
"repository": {
52+
"type": "git",
53+
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
54+
}
55+
}

packages/config/src/config.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import path from 'node:path'
2+
import fs from 'node:fs/promises'
3+
import { loadConfig, createDefineConfig } from 'c12'
4+
import dedent from 'dedent'
5+
import type { UserConfig } from './types'
6+
import { getDefaultUserConfig } from './defaults'
7+
import { configName } from './constants'
8+
9+
export function getConfig(cwd?: string) {
10+
return loadConfig<UserConfig>({
11+
name: configName,
12+
defaults: {
13+
...getDefaultUserConfig()
14+
},
15+
cwd
16+
})
17+
}
18+
19+
export const defineConfig = createDefineConfig<UserConfig>()
20+
21+
export function initConfig(cwd: string) {
22+
return fs.writeFile(
23+
path.resolve(cwd, `${configName}.config.ts`),
24+
dedent`
25+
import { defineConfig } from 'tailwindcss-patch'
26+
27+
export default defineConfig({})
28+
`,
29+
'utf8'
30+
)
31+
}

packages/config/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const configName = 'tailwindcss-mangle'

packages/config/src/defaults.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { PatchUserConfig, UserConfig } from './types'
2+
3+
export function getDefaultPatchConfig(): PatchUserConfig {
4+
return {
5+
output: {
6+
filename: '.tw-patch/tw-class-list.json',
7+
removeUniversalSelector: true,
8+
loose: true
9+
},
10+
tailwindcss: {}
11+
}
12+
}
13+
14+
export function getDefaultUserConfig(): UserConfig {
15+
return {
16+
patch: getDefaultPatchConfig()
17+
}
18+
}

packages/config/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './config'
2+
export * from './defaults'
3+
export * from './constants'
4+
export * from './types'

packages/config/src/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface PatchUserConfig {
2+
output?: {
3+
filename?: string
4+
5+
loose?: boolean
6+
/**
7+
* @description remove * in output json
8+
*/
9+
removeUniversalSelector?: boolean
10+
}
11+
tailwindcss?: {
12+
cwd?: string
13+
config?: string
14+
}
15+
}
16+
17+
export interface UserConfig {
18+
patch?: PatchUserConfig
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`defaults > getDefaultPatchConfig 1`] = `
4+
{
5+
"output": {
6+
"filename": ".tw-patch/tw-class-list.json",
7+
"loose": true,
8+
"removeUniversalSelector": true,
9+
},
10+
"tailwindcss": {},
11+
}
12+
`;
13+
14+
exports[`defaults > getDefaultUserConfig 1`] = `
15+
{
16+
"patch": {
17+
"output": {
18+
"filename": ".tw-patch/tw-class-list.json",
19+
"loose": true,
20+
"removeUniversalSelector": true,
21+
},
22+
"tailwindcss": {},
23+
},
24+
}
25+
`;

packages/config/test/defaults.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { omit } from 'lodash-es'
2+
import { getDefaultPatchConfig, getDefaultUserConfig } from '@/defaults'
3+
4+
function omitCwdPath(o: any) {
5+
return omit(o, ['tailwindcss.cwd', 'patch.tailwindcss.cwd'])
6+
}
7+
8+
describe('defaults', () => {
9+
it('getDefaultPatchConfig', () => {
10+
expect(omitCwdPath(getDefaultPatchConfig())).toMatchSnapshot()
11+
})
12+
13+
it('getDefaultUserConfig', () => {
14+
expect(omitCwdPath(getDefaultUserConfig())).toMatchSnapshot()
15+
})
16+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from 'tailwindcss-patch'
2+
3+
export default defineConfig({
4+
patch: {
5+
output: {
6+
filename: 'xxx/yyy/zzz.json',
7+
loose: false,
8+
removeUniversalSelector: false
9+
},
10+
tailwindcss: {
11+
cwd: 'aaa/bbb/cc'
12+
}
13+
}
14+
})

packages/config/test/index.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { resolve } from 'node:path'
2+
import { existsSync } from 'node:fs'
3+
import { deleteAsync } from 'del'
4+
import { fixturesRoot } from './utils'
5+
import { initConfig, getConfig } from '@/index'
6+
import { getDefaultUserConfig } from '@/defaults'
7+
import { configName } from '@/constants'
8+
9+
describe('config', () => {
10+
it('0.default', async () => {
11+
const cwd = resolve(fixturesRoot, './config/0.default')
12+
const configPath = resolve(cwd, `${configName}.config.ts`)
13+
if (existsSync(configPath)) {
14+
await deleteAsync(configPath)
15+
}
16+
17+
await initConfig(cwd)
18+
expect(existsSync(configPath)).toBe(true)
19+
20+
const { config } = await getConfig(cwd)
21+
expect(config).toEqual(getDefaultUserConfig())
22+
})
23+
24+
it('1.change-options', async () => {
25+
const cwd = resolve(fixturesRoot, './config/1.change-options')
26+
const { config } = await getConfig(cwd)
27+
expect(config).toEqual({
28+
patch: {
29+
output: {
30+
filename: 'xxx/yyy/zzz.json',
31+
loose: false,
32+
removeUniversalSelector: false
33+
},
34+
tailwindcss: {
35+
cwd: 'aaa/bbb/cc'
36+
}
37+
}
38+
})
39+
})
40+
})

packages/config/test/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import path from 'node:path'
2+
3+
export const fixturesRoot = path.resolve(__dirname, './fixtures')

packages/config/tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"@/*": [
7+
"src/*"
8+
]
9+
}
10+
},
11+
"include": [
12+
"src",
13+
"test"
14+
]
15+
}

0 commit comments

Comments
 (0)