Skip to content

Convert built-in utility modules to private plugins #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 60 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
146b984
Accept plugins as separate processPlugins arg
adamwathan Jan 9, 2019
6352843
Port zIndex module to default plugin
adamwathan Jan 9, 2019
027b69c
Port width and whitespace modules to plugins
adamwathan Jan 9, 2019
239234b
Port visibility module to plugin
adamwathan Jan 9, 2019
718389c
Port verticalAlign module to plugin
adamwathan Jan 9, 2019
86d8127
Port tracking module to plugin
adamwathan Jan 9, 2019
3ac73fb
Port text sizes and text style modules to plugins
adamwathan Jan 9, 2019
7e2e278
Port textColors module to plugin
adamwathan Jan 9, 2019
fbeadb7
Port textAlign module to plugin
adamwathan Jan 9, 2019
ff3e6be
Port tableLayout module to plugin
adamwathan Jan 9, 2019
efb9e69
Port svgStroke module to plugin
adamwathan Jan 9, 2019
e6c0da0
Port svgFill module to plugin
adamwathan Jan 9, 2019
6a3ed59
Port shadows module to plugin
adamwathan Jan 9, 2019
e7bf2bc
Port resize module to plugin
adamwathan Jan 9, 2019
6125121
Port position module to plugin
adamwathan Jan 9, 2019
c5abdc9
Port pointerEvents module to plugin
adamwathan Jan 9, 2019
d6611dd
Port padding module to plugin
adamwathan Jan 9, 2019
0ba183a
Port overflow module to plugin
adamwathan Jan 9, 2019
a3ea578
Port outline module to plugin
adamwathan Jan 9, 2019
3f08918
Port opacity module to plugin
adamwathan Jan 9, 2019
5b3d6d8
Port objectPosition module to plugin, conditionally load plugins base…
adamwathan Jan 9, 2019
bfbb179
Port objectFit module to plugin
adamwathan Jan 9, 2019
1ff0143
Port negativeMargin module to plugin
adamwathan Jan 9, 2019
b140bf6
Port minWidth module to plugin
adamwathan Jan 10, 2019
645de65
Port minHeight module to plugin
adamwathan Jan 10, 2019
3c99be0
Port maxWidth module to plugin
adamwathan Jan 10, 2019
b5a51e8
Port maxHeight module to plugin
adamwathan Jan 10, 2019
97da5c4
Port margin module to plugin
adamwathan Jan 10, 2019
c8802df
Port leading module to plugin
adamwathan Jan 10, 2019
964bf81
Port height module to plugin
adamwathan Jan 10, 2019
07193bb
Port fontWeights module to plugin
adamwathan Jan 10, 2019
499fae2
Port fonts module to plugins
adamwathan Jan 10, 2019
dce3b5f
Port float module to plugin
adamwathan Jan 10, 2019
fd1729e
Port flexbox module to plugin
adamwathan Jan 10, 2019
a493ee4
Port display module to plugin
adamwathan Jan 10, 2019
e16c6e6
Port cursor module to plugin
adamwathan Jan 10, 2019
36075fa
Port borderWidths module to plugin
adamwathan Jan 10, 2019
d969096
Port borderStyle module to plugin
adamwathan Jan 10, 2019
2a0b64f
Port borderRadius module to plugin
adamwathan Jan 10, 2019
4715bda
Port borderColors module to plugin
adamwathan Jan 10, 2019
96439a3
Port borderCollapse module to plugin
adamwathan Jan 10, 2019
5a37287
Port backgroundSize module to plugin
adamwathan Jan 10, 2019
6112b3e
Port backgroundRepeat module to plugin
adamwathan Jan 10, 2019
0cd679b
Port backgroundPosition module to plugin
adamwathan Jan 10, 2019
c39ed44
Port backgroundColors module to plugin
adamwathan Jan 10, 2019
a6e96c8
Port backgroundAttachment module to plugin
adamwathan Jan 10, 2019
a0de7e0
Port appearance module to plugin
adamwathan Jan 10, 2019
0d333f2
Port lists module to plugin
adamwathan Jan 10, 2019
eeb42cd
Provide our own rawCache to avoid performance issues
adamwathan Jan 11, 2019
5ade923
Fix tests and lint warnings
adamwathan Jan 11, 2019
f01d79f
Add a comment to explain performance optimization
adamwathan Jan 11, 2019
060d234
Remove code obsoleted by upgrading PostCSS
adamwathan Jan 14, 2019
20588c9
Remove unused code
adamwathan Jan 14, 2019
ca524ef
Remove more dead code
adamwathan Jan 14, 2019
fe1b30b
Remove prefixTree, update relevant tests
adamwathan Jan 14, 2019
d255978
Delete even more dead code
adamwathan Jan 14, 2019
b948c25
Delete possibly last remnants of dead code
adamwathan Jan 14, 2019
adc5d25
Remove unnecessary parameter
adamwathan Jan 14, 2019
057b4ea
More dead code discovered and deleted
adamwathan Jan 14, 2019
e120f59
Simplify defaultPlugins module
adamwathan Jan 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions __tests__/applyAtRule.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import postcss from 'postcss'
import plugin from '../src/lib/substituteClassApplyAtRules'
import generateUtilities from '../src/util/generateUtilities'
import substituteClassApplyAtRules from '../src/lib/substituteClassApplyAtRules'
import processPlugins from '../src/util/processPlugins'
import defaultPlugins from '../src/defaultPlugins'
import defaultConfig from '../defaultConfig.stub.js'

const defaultUtilities = generateUtilities(defaultConfig, [])
const { utilities: defaultUtilities } = processPlugins(defaultPlugins(defaultConfig), defaultConfig)

function run(input, config = defaultConfig, utilities = defaultUtilities) {
return postcss([plugin(config, utilities)]).process(input, { from: undefined })
return postcss([substituteClassApplyAtRules(config, utilities)]).process(input, {
from: undefined,
})
}

test("it copies a class's declarations into itself", () => {
Expand Down Expand Up @@ -206,10 +209,12 @@ test('you can apply utility classes without using the given prefix', () => {
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})

test('you can apply utility classes without using the given prefix when using a function for the prefix', () => {
Expand All @@ -232,8 +237,10 @@ test('you can apply utility classes without using the given prefix when using a
experiments: { shadowLookup: true },
}

return run(input, config, generateUtilities(config, [])).then(result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
})
return run(input, config, processPlugins(defaultPlugins(defaultConfig), config).utilities).then(
result => {
expect(result.css).toEqual(expected)
expect(result.warnings().length).toBe(0)
}
)
})
81 changes: 41 additions & 40 deletions __tests__/containerPlugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@ function css(nodes) {
return postcss.root({ nodes }).toString()
}

function processPluginsWithValidConfig(config) {
return processPlugins(
_.defaultsDeep(config, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
},
})
)
function config(overrides) {
return _.defaultsDeep(overrides, {
screens: {
sm: '576px',
md: '768px',
lg: '992px',
xl: '1200px',
},
options: {
prefix: '',
important: false,
separator: ':',
},
})
}

test('options are not required', () => {
const { components } = processPluginsWithValidConfig({
plugins: [container()],
})
test.only('options are not required', () => {
const { components } = processPlugins([container()], config())

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -47,17 +43,18 @@ test('options are not required', () => {
`)
})

test('screens can be specified explicitly', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('screens can be specified explicitly', () => {
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
lg: '500px',
},
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -70,14 +67,15 @@ test('screens can be specified explicitly', () => {
`)
})

test('screens can be an array', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('screens can be an array', () => {
const { components } = processPlugins(
[
container({
screens: ['400px', '500px'],
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container { width: 100% }
Expand All @@ -90,14 +88,15 @@ test('screens can be an array', () => {
`)
})

test('the container can be centered by default', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('the container can be centered by default', () => {
const { components } = processPlugins(
[
container({
center: true,
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -120,14 +119,15 @@ test('the container can be centered by default', () => {
`)
})

test('horizontal padding can be included by default', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('horizontal padding can be included by default', () => {
const { components } = processPlugins(
[
container({
padding: '2rem',
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand All @@ -150,9 +150,9 @@ test('horizontal padding can be included by default', () => {
`)
})

test('setting all options at once', () => {
const { components } = processPluginsWithValidConfig({
plugins: [
test.only('setting all options at once', () => {
const { components } = processPlugins(
[
container({
screens: {
sm: '400px',
Expand All @@ -162,7 +162,8 @@ test('setting all options at once', () => {
padding: '2rem',
}),
],
})
config()
)

expect(css(components)).toMatchCss(`
.container {
Expand Down
27 changes: 0 additions & 27 deletions __tests__/defineClass.test.js

This file was deleted.

19 changes: 0 additions & 19 deletions __tests__/defineClasses.test.js

This file was deleted.

133 changes: 0 additions & 133 deletions __tests__/generateModules.test.js

This file was deleted.

Loading