Skip to content

Commit 0f5ab74

Browse files
authored
Feature/add more test case (#40)
* chore: commit js case * refact: type and plugin * feat: use config to control plugin * chore: allow test for tailwindcss patch * chore: add ci codecov
1 parent b735483 commit 0f5ab74

File tree

28 files changed

+261
-240
lines changed

28 files changed

+261
-240
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,11 @@ jobs:
4242
- name: Build
4343
run: pnpm build
4444

45+
- name: Patch
46+
working-directory: packages/tailwindcss-patch
47+
run: pnpm run patch
48+
4549
- name: Test
4650
run: pnpm test
51+
52+
- uses: codecov/codecov-action@v3

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,5 @@ jobs:
3939
# NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
4040
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4141
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
43+
- uses: codecov/codecov-action@v3

packages/config/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tailwindcss-mangle/config",
3-
"version": "1.0.1",
3+
"version": "2.0.4",
44
"description": "The config and load function of tailwindcss-mangle",
55
"exports": {
66
".": {
@@ -25,7 +25,7 @@
2525
],
2626
"scripts": {
2727
"build": "unbuild",
28-
"test": "vitest run",
28+
"test": "vitest run --coverage.enabled",
2929
"test:dev": "vitest"
3030
},
3131
"keywords": [
@@ -44,6 +44,7 @@
4444
"registry": "https://registry.npmjs.org/"
4545
},
4646
"dependencies": {
47+
"@tailwindcss-mangle/shared": "workspace:^",
4748
"c12": "^1.4.2",
4849
"dedent": "^1.5.1"
4950
},

packages/config/src/defaults.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { PatchUserConfig, UserConfig } from './types'
1+
import { defaultMangleClassFilter } from '@tailwindcss-mangle/shared'
2+
import type { PatchUserConfig, UserConfig, MangleUserConfig } from './types'
23

34
export function getDefaultPatchConfig(): PatchUserConfig {
45
return {
@@ -11,8 +12,24 @@ export function getDefaultPatchConfig(): PatchUserConfig {
1112
}
1213
}
1314

15+
export function getDefaultMangleUserConfig(): MangleUserConfig {
16+
return {
17+
mangleClassFilter: defaultMangleClassFilter,
18+
include: ['**/*.{js,jsx,ts,tsx,svelte,vue}'],
19+
exclude: ['node_modules/**/*', '**/*.{css,scss,less,sass,postcss,html,htm}'],
20+
disabled: process.env.NODE_ENV === 'development',
21+
classListPath: '.tw-patch/tw-class-list.json',
22+
classMapOutput: {
23+
enable: false,
24+
filename: '.tw-patch/tw-map-list.json',
25+
loose: true
26+
}
27+
}
28+
}
29+
1430
export function getDefaultUserConfig(): UserConfig {
1531
return {
16-
patch: getDefaultPatchConfig()
32+
patch: getDefaultPatchConfig(),
33+
mangle: getDefaultMangleUserConfig()
1734
}
1835
}

packages/config/src/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
import type { IClassGeneratorOptions } from '@tailwindcss-mangle/shared'
2+
3+
export interface ClassMapOutputOptions {
4+
enable?: boolean
5+
filename?: string
6+
loose?: boolean
7+
}
8+
9+
export interface MangleUserConfig {
10+
mangleClassFilter?: (className: string) => boolean
11+
classGenerator?: IClassGeneratorOptions
12+
exclude?: string[]
13+
include?: string[]
14+
classListPath?: string
15+
classMapOutput?: ClassMapOutputOptions
16+
disabled?: boolean
17+
}
18+
119
export interface PatchUserConfig {
220
output?: {
321
filename?: string
@@ -16,4 +34,5 @@ export interface PatchUserConfig {
1634

1735
export interface UserConfig {
1836
patch?: PatchUserConfig
37+
mangle?: MangleUserConfig
1938
}

packages/config/test/__snapshots__/defaults.test.ts.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ exports[`defaults > getDefaultPatchConfig 1`] = `
1313

1414
exports[`defaults > getDefaultUserConfig 1`] = `
1515
{
16+
"mangle": {
17+
"classListPath": ".tw-patch/tw-class-list.json",
18+
"classMapOutput": {
19+
"enable": false,
20+
"filename": ".tw-patch/tw-map-list.json",
21+
"loose": true,
22+
},
23+
"disabled": false,
24+
"exclude": [
25+
"node_modules/**/*",
26+
"**/*.{css,scss,less,sass,postcss,html,htm}",
27+
],
28+
"include": [
29+
"**/*.{js,jsx,ts,tsx,svelte,vue}",
30+
],
31+
"mangleClassFilter": [Function],
32+
},
1633
"patch": {
1734
"output": {
1835
"filename": ".tw-patch/tw-class-list.json",

packages/config/test/index.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { existsSync } from 'node:fs'
33
import { deleteAsync } from 'del'
44
import { fixturesRoot } from './utils'
55
import { initConfig, getConfig } from '@/index'
6-
import { getDefaultUserConfig } from '@/defaults'
6+
import { getDefaultUserConfig, getDefaultMangleUserConfig } from '@/defaults'
77
import { configName } from '@/constants'
88

99
describe('config', () => {
@@ -34,7 +34,8 @@ describe('config', () => {
3434
tailwindcss: {
3535
cwd: 'aaa/bbb/cc'
3636
}
37-
}
37+
},
38+
mangle: getDefaultMangleUserConfig()
3839
})
3940
})
4041
})

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tailwindcss-mangle/core",
3-
"version": "2.0.2",
3+
"version": "2.0.4",
44
"description": "The core of tailwindcss-mangle",
55
"exports": {
66
".": {

packages/core/src/types.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ClassGenerator } from './shared'
1+
import type { ClassGenerator } from './shared'
22

33
export interface IClassGeneratorContextItem {
44
name: string
@@ -32,21 +32,3 @@ export interface ICssHandlerOptions extends IHandlerOptions {
3232
ignoreVueScoped?: boolean
3333
file?: string
3434
}
35-
36-
export interface ClassSetOutputOptions {
37-
filename: string
38-
dir?: string
39-
type: 'all' | 'partial'
40-
}
41-
42-
export interface ClassMapOutputOptions {
43-
filename: string
44-
dir?: string
45-
}
46-
export interface Options {
47-
classGenerator?: IClassGeneratorOptions
48-
exclude?: string[]
49-
include?: string[]
50-
classSetOutput?: boolean | ClassSetOutputOptions
51-
classMapOutput?: boolean | ClassMapOutputOptions
52-
}

packages/core/test/fixtures/prod/0.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Unterminated string constant
2+
if (isSvg) {
3+
let source = serializeString(svgNode);
4+
// add xml declaration
5+
source = '<?xml version="1.0" standalone="no"?>\r\n' + source;
6+
// convert svg source to URI data scheme.
7+
url = "data:image/svg+xml;charset=utf-8," + encodeURIComponent(source);
8+
saveAs(url, "graph.svg");
9+
onAlreadySerialized();
10+
return;
11+
}

0 commit comments

Comments
 (0)