Skip to content

Commit 5f7f9a1

Browse files
Fix: Update plugin import using require() (#95)
Co-authored-by: Jeff <rustyangel@gmail.com>
1 parent e374e3e commit 5f7f9a1

File tree

4 files changed

+73
-59
lines changed

4 files changed

+73
-59
lines changed

.changeset/wild-sheep-tan.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'tailwindcss-capsize': patch
3+
---
4+
5+
Fix usage when `require`ing plugin
6+
7+
```diff
8+
- require('tailwindcss-capsize').default
9+
+ require('tailwindcss-capsize')
10+
```

__tests__/plugin.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import postcss from 'postcss'
33
import { format } from 'prettier'
44
import tailwindcss from 'tailwindcss'
55

6-
import capsizePlugin from '../dist'
6+
// Need to test this how consumers will use it, using `require()`.
7+
// eslint-disable-next-line @typescript-eslint/no-var-requires
8+
const capsizePlugin = require('../dist')
79

810
const THEME_CONFIG = {
911
fontFamily: {

src/index.ts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,3 @@
1-
import { createStyleObject } from '@capsizecss/core'
2-
import type { FontMetrics } from '@capsizecss/core'
3-
import type { NestedObject } from '@navith/tailwindcss-plugin-author-types'
4-
import plugin from 'tailwindcss/plugin'
1+
import plugin from './plugin'
52

6-
import { makeCssSelectors, normalizeValue } from './utils'
7-
8-
export interface PluginOptions {
9-
/** The root font-size, in pixels */
10-
rootSize: number
11-
}
12-
13-
export default plugin.withOptions<Partial<PluginOptions>>(
14-
({ rootSize = 16 } = {}) => {
15-
return function ({ addUtilities, theme }) {
16-
/** @todo Improve these types maybe? */
17-
let fontMetrics = theme('fontMetrics', {}) as Record<
18-
string,
19-
FontMetrics
20-
>
21-
let lineHeight = theme('lineHeight', {}) as Record<string, string>
22-
let fontSize = theme('fontSize', {}) as Record<string, string>
23-
let utilities: NestedObject = {}
24-
25-
Object.keys(fontMetrics).forEach((fontFamily) => {
26-
let fontConfig = fontMetrics[fontFamily]
27-
28-
Object.keys(fontSize).forEach((sizeName) => {
29-
Object.keys(lineHeight).forEach((leading) => {
30-
let fs = normalizeValue(fontSize[sizeName], rootSize)
31-
let lh = normalizeValue(
32-
lineHeight[leading],
33-
rootSize,
34-
fs,
35-
)
36-
37-
let {
38-
'::after': after,
39-
'::before': before,
40-
} = createStyleObject({
41-
fontMetrics: fontConfig,
42-
fontSize: fs,
43-
leading: lh,
44-
})
45-
46-
utilities[
47-
makeCssSelectors(fontFamily, sizeName, leading)
48-
] = {
49-
'&::before': before,
50-
'&::after': after,
51-
}
52-
})
53-
})
54-
})
55-
56-
addUtilities(utilities, {})
57-
}
58-
},
59-
)
3+
module.exports = plugin

src/plugin.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { createStyleObject } from '@capsizecss/core'
2+
import type { FontMetrics } from '@capsizecss/core'
3+
import type { NestedObject } from '@navith/tailwindcss-plugin-author-types'
4+
import plugin from 'tailwindcss/plugin'
5+
6+
import { makeCssSelectors, normalizeValue } from './utils'
7+
8+
export interface PluginOptions {
9+
/** The root font-size, in pixels */
10+
rootSize: number
11+
}
12+
13+
export default plugin.withOptions<Partial<PluginOptions>>(
14+
({ rootSize = 16 } = {}) => {
15+
return function ({ addUtilities, theme }) {
16+
let fontMetrics = theme('fontMetrics', {}) as Record<
17+
string,
18+
FontMetrics
19+
>
20+
let lineHeight = theme('lineHeight', {}) as Record<string, string>
21+
let fontSize = theme('fontSize', {}) as Record<string, string>
22+
let utilities: NestedObject = {}
23+
24+
Object.keys(fontMetrics).forEach((fontFamily) => {
25+
let fontConfig = fontMetrics[fontFamily]
26+
27+
Object.keys(fontSize).forEach((sizeName) => {
28+
Object.keys(lineHeight).forEach((leading) => {
29+
let fs = normalizeValue(fontSize[sizeName], rootSize)
30+
let lh = normalizeValue(
31+
lineHeight[leading],
32+
rootSize,
33+
fs,
34+
)
35+
36+
let {
37+
'::after': after,
38+
'::before': before,
39+
} = createStyleObject({
40+
fontMetrics: fontConfig,
41+
fontSize: fs,
42+
leading: lh,
43+
})
44+
45+
utilities[
46+
makeCssSelectors(fontFamily, sizeName, leading)
47+
] = {
48+
'&::before': before,
49+
'&::after': after,
50+
}
51+
})
52+
})
53+
})
54+
55+
addUtilities(utilities, {})
56+
}
57+
},
58+
)

0 commit comments

Comments
 (0)