Skip to content

Commit 4efaaf3

Browse files
authored
Merge pull request #16 from sonofmagic/dev
feat(utils): use new shared utils
2 parents 39288a9 + 1e98448 commit 4efaaf3

34 files changed

+253
-198
lines changed

.github/workflows/release.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
release:
13+
permissions:
14+
id-token: write
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install pnpm
22+
uses: pnpm/action-setup@v2
23+
24+
- name: Set node
25+
uses: actions/setup-node@v3
26+
with:
27+
node-version: 18
28+
cache: pnpm
29+
registry-url: 'https://registry.npmjs.org'
30+
31+
- run: npx changelogithub
32+
continue-on-error: true
33+
env:
34+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
35+
36+
- name: Install Dependencies
37+
run: pnpm i
38+
39+
- name: PNPM build
40+
run: pnpm run build:pkg
41+
42+
- name: Publish to NPM
43+
run: pnpm -r publish --access public --no-git-checks
44+
env:
45+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
46+
NPM_CONFIG_PROVENANCE: true

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
{
22
"name": "tailwindcss-mangle",
3-
"version": "0.0.0",
3+
"version": "1.2.0",
44
"private": true,
55
"workspaces": [
66
"apps/*",
77
"packages/*"
88
],
99
"scripts": {
1010
"build": "pnpm run -r build",
11-
"build:pkg": "pnpm run -r --filter ./packages/* build",
12-
"build:app": "pnpm run -r --filter ./apps/* build ",
13-
"dev": "pnpm run -r --parallel dev",
14-
"dev:pkg": "pnpm run -r --parallel --filter ./packages/* dev ",
15-
"test": "pnpm run -r --filter ./packages/* test ",
11+
"build:pkg": "pnpm run -r --filter=./packages/* build",
12+
"build:app": "pnpm run -r --filter=./apps/* build ",
13+
"dev": "pnpm -r --parallel run dev",
14+
"dev:pkg": "pnpm -r --filter=./packages/* --parallel run dev",
15+
"test": "pnpm run -r --filter=./packages/* test ",
1616
"lint": "pnpm run -r lint",
1717
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
1818
"preinstall": "npx only-allow pnpm",
19+
"release": "bumpp -r",
1920
"sync": "cnpm sync tailwindcss-patch unplugin-tailwindcss-mangle tailwindcss-mangle-core"
2021
},
2122
"devDependencies": {
@@ -25,6 +26,7 @@
2526
"@tsconfig/recommended": "^1.0.2",
2627
"@types/jest": "^29.5.1",
2728
"@types/node": "^20.1.3",
29+
"bumpp": "^9.1.0",
2830
"cross-env": "^7.0.3",
2931
"eslint": "^8.40.0",
3032
"jest": "^29.5.0",
@@ -39,4 +41,4 @@
3941
"node": ">=14.0.0"
4042
},
4143
"packageManager": "[email protected]"
42-
}
44+
}

packages/core/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tailwindcss-mangle-core",
3-
"version": "1.0.1",
3+
"version": "1.2.0",
44
"description": "The core of tailwindcss-mangle",
55
"main": "dist/index.js",
66
"module": "./dist/index.mjs",
@@ -32,7 +32,8 @@
3232
"@babel/types": "^7.21.5",
3333
"parse5": "^7.1.2",
3434
"postcss": "^8.4.23",
35-
"postcss-selector-parser": "^6.0.12"
35+
"postcss-selector-parser": "^6.0.12",
36+
"tailwindcss-mangle-shared": "workspace:^"
3637
},
3738
"devDependencies": {
3839
"@parse5/tools": "^0.1.0",
@@ -44,4 +45,4 @@
4445
"type": "git",
4546
"url": "git+https://github.com/sonofmagic/tailwindcss-mangle.git"
4647
}
47-
}
48+
}

packages/core/src/html/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { parse, serialize } from 'parse5'
22
import { traverse } from '@parse5/tools'
33
import { IHtmlHandlerOptions } from '../types'
4+
import { makeRegex, splitCode } from '../shared'
45

56
export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) {
67
const { runtimeSet, classGenerator } = options
@@ -9,15 +10,15 @@ export function htmlHandler(rawSource: string, options: IHtmlHandlerOptions) {
910
element(node, parent) {
1011
const attr = node.attrs.find((x) => x.name === 'class')
1112
if (attr) {
12-
const arr = attr.value.split(/\s/).filter((x) => x)
13-
attr.value = arr
14-
.map((x) => {
15-
if (runtimeSet.has(x)) {
16-
return classGenerator.generateClassName(x).name
17-
}
18-
return x
19-
})
20-
.join(' ')
13+
const arr = splitCode(attr.value, {
14+
splitQuote: false
15+
})
16+
for (let i = 0; i < arr.length; i++) {
17+
const v = arr[i]
18+
if (runtimeSet.has(v)) {
19+
attr.value = attr.value.replace(makeRegex(v), classGenerator.generateClassName(v).name)
20+
}
21+
}
2122
}
2223
}
2324
})

packages/core/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './css'
22
export * from './html'
33
export * from './js'
4-
export { default as ClassGenerator } from './classGenerator'
4+
export { ClassGenerator } from './shared'
5+
export * from './types'

packages/core/src/js/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import type { StringLiteral, TemplateElement, CallExpression } from '@babel/type
22
import * as t from '@babel/types'
33
import { transformSync, type BabelFileResult, type NodePath } from '@babel/core'
44
import type { IJsHandlerOptions } from '../types'
5-
import { escapeStringRegexp } from '../utils'
6-
import { splitCode } from './split'
7-
8-
export function makeRegex(str: string) {
9-
return new RegExp('(?<=^|[\\s"])' + escapeStringRegexp(str), 'g')
10-
}
5+
import { makeRegex, splitCode } from '../shared'
116

127
export function handleValue(str: string, node: StringLiteral | TemplateElement, options: IJsHandlerOptions) {
138
const { runtimeSet: set, classGenerator: clsGen, splitQuote = true } = options

packages/core/src/shared.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from 'tailwindcss-mangle-shared'

packages/core/src/types.ts

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

33
export interface IClassGeneratorContextItem {
44
name: string
@@ -15,12 +15,6 @@ export interface IClassGeneratorOptions {
1515
classPrefix?: string
1616
}
1717

18-
export interface IClassGenerator {
19-
newClassMap: Record<string, IClassGeneratorContextItem>
20-
newClassSize: number
21-
context: Record<string, any>
22-
}
23-
2418
export interface IHandlerOptions {
2519
runtimeSet: Set<string>
2620
classGenerator: ClassGenerator

packages/core/test/css.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cssHandler } from '../src/css'
2-
import ClassGenerator from '../src/classGenerator'
2+
import { ClassGenerator } from '../src/shared'
33
import { getTestCase } from './utils'
44
describe('css', () => {
55
let classGenerator: ClassGenerator

packages/core/test/exports.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ClassGenerator, cssHandler, handleValue, htmlHandler, jsHandler, makeRegex } from '../'
1+
import { ClassGenerator, cssHandler, handleValue, htmlHandler, jsHandler } from '../'
22

33
describe('exports', () => {
44
it('exports should be defined', () => {
5-
;[ClassGenerator, cssHandler, handleValue, htmlHandler, jsHandler, makeRegex].forEach((x) => {
5+
;[ClassGenerator, cssHandler, handleValue, htmlHandler, jsHandler].forEach((x) => {
66
expect(x).toBeDefined()
77
})
88
})

0 commit comments

Comments
 (0)