Skip to content

Commit 3b750eb

Browse files
committed
Add options to allow duplicates or force imports
1 parent 0c0d7b5 commit 3b750eb

File tree

8 files changed

+110
-39
lines changed

8 files changed

+110
-39
lines changed

.tape.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ module.exports = {
1515
browsers: 'last 1 versions'
1616
}
1717
},
18-
'insertion': {
19-
message: 'supports an insertion point'
20-
},
2118
'insertion-after': {
2219
message: 'support an insertion point (at the end of the file)'
2320
},
2421
'insertion-duplicate': {
2522
message: 'removes duplicate insertion points'
23+
},
24+
'option-force-import': {
25+
message: 'forces an import at the beginning of the file',
26+
options: {
27+
forceImport: true
28+
}
2629
}
2730
}
2831
};

index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ module.exports = postcss.plugin('postcss-normalize', (opts) => {
3737
root.walkAtRules(
3838
'import-normalize',
3939
(atrule) => {
40-
if (appliedRules[0].parent) {
40+
if (opts && opts.allowDuplicates) {
41+
// use any insertion point
42+
atrule.replaceWith(
43+
appliedRules.map(
44+
(rule) => rule.clone()
45+
)
46+
);
47+
} else if (appliedRules[0].parent) {
4148
// remove duplicate insertions
4249
atrule.remove();
4350
} else {
@@ -47,7 +54,7 @@ module.exports = postcss.plugin('postcss-normalize', (opts) => {
4754
}
4855
);
4956

50-
if (!appliedRules[0].parent) {
57+
if (opts && opts.forceImport && !appliedRules[0].parent) {
5158
// prepend required normalize rules
5259
root.prepend(appliedRules);
5360
}

test/basic.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import-normalize;
2+
13
body {
24
font-family: sans-serif;
35
}

test/basic.expect.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,104 @@ html {
33
-ms-text-size-adjust: 100%;
44
-webkit-text-size-adjust: 100%;
55
}
6+
67
h1 {
78
font-size: 2em;
89
margin: 0.67em 0;
910
}
11+
1012
hr {
1113
box-sizing: content-box;
1214
height: 0;
1315
overflow: visible;
1416
}
17+
1518
main {
1619
display: block;
1720
}
21+
1822
pre {
1923
font-family: monospace, monospace;
2024
font-size: 1em;
2125
}
26+
2227
a {
2328
background-color: transparent;
2429
-webkit-text-decoration-skip: objects;
2530
}
31+
2632
abbr[title] {
2733
text-decoration: underline;
2834
text-decoration: underline dotted;
2935
}
36+
3037
b,
3138
strong {
3239
font-weight: bolder;
3340
}
41+
3442
code,
3543
kbd,
3644
samp {
3745
font-family: monospace, monospace;
3846
font-size: 1em;
3947
}
48+
4049
small {
4150
font-size: 80%;
4251
}
52+
4353
img {
4454
border-style: none;
4555
}
56+
4657
svg:not(:root) {
4758
overflow: hidden;
4859
}
60+
4961
button,
5062
input,
5163
optgroup,
5264
select,
5365
textarea {
5466
margin: 0;
5567
}
68+
5669
button {
5770
overflow: visible;
5871
text-transform: none;
5972
}
73+
6074
button,
6175
[type="button"],
6276
[type="reset"],
6377
[type="submit"] {
6478
-webkit-appearance: button;
6579
}
80+
6681
button::-moz-focus-inner,
6782
[type="button"]::-moz-focus-inner,
6883
[type="reset"]::-moz-focus-inner,
6984
[type="submit"]::-moz-focus-inner {
7085
border-style: none;
7186
padding: 0;
7287
}
88+
7389
button:-moz-focusring,
7490
[type="button"]:-moz-focusring,
7591
[type="reset"]:-moz-focusring,
7692
[type="submit"]:-moz-focusring {
7793
outline: 1px dotted ButtonText;
7894
}
95+
7996
fieldset {
8097
padding: 0.35em 0.75em 0.625em;
8198
}
99+
82100
input {
83101
overflow: visible;
84102
}
103+
85104
legend {
86105
box-sizing: border-box;
87106
color: inherit;
@@ -90,49 +109,62 @@ legend {
90109
padding: 0;
91110
white-space: normal;
92111
}
112+
93113
progress {
94114
display: inline-block;
95115
vertical-align: baseline;
96116
}
117+
97118
select {
98119
text-transform: none;
99120
}
121+
100122
textarea {
101123
overflow: auto;
102124
}
125+
103126
[type="checkbox"],
104127
[type="radio"] {
105128
box-sizing: border-box;
106129
padding: 0;
107130
}
131+
108132
[type="number"]::-webkit-inner-spin-button,
109133
[type="number"]::-webkit-outer-spin-button {
110134
height: auto;
111135
}
136+
112137
[type="search"] {
113138
-webkit-appearance: textfield;
114139
outline-offset: -2px;
115140
}
141+
116142
[type="search"]::-webkit-search-cancel-button,
117143
[type="search"]::-webkit-search-decoration {
118144
-webkit-appearance: none;
119145
}
146+
120147
::-webkit-file-upload-button {
121148
-webkit-appearance: button;
122149
font: inherit;
123150
}
151+
124152
details {
125153
display: block;
126154
}
155+
127156
summary {
128157
display: list-item;
129158
}
159+
130160
template {
131161
display: none;
132162
}
163+
133164
[hidden] {
134165
display: none;
135166
}
167+
136168
body {
137169
font-family: sans-serif;
138170
}

test/basic.last-1.expect.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,99 @@ html {
33
-ms-text-size-adjust: 100%;
44
-webkit-text-size-adjust: 100%;
55
}
6+
67
h1 {
78
font-size: 2em;
89
margin: 0.67em 0;
910
}
11+
1012
hr {
1113
box-sizing: content-box;
1214
height: 0;
1315
overflow: visible;
1416
}
17+
1518
main {
1619
display: block;
1720
}
21+
1822
pre {
1923
font-family: monospace, monospace;
2024
font-size: 1em;
2125
}
26+
2227
a {
2328
-webkit-text-decoration-skip: objects;
2429
}
30+
2531
abbr[title] {
2632
text-decoration: underline;
2733
text-decoration: underline dotted;
2834
}
35+
2936
b,
3037
strong {
3138
font-weight: bolder;
3239
}
40+
3341
code,
3442
kbd,
3543
samp {
3644
font-family: monospace, monospace;
3745
font-size: 1em;
3846
}
47+
3948
small {
4049
font-size: 80%;
4150
}
51+
4252
svg:not(:root) {
4353
overflow: hidden;
4454
}
55+
4556
button,
4657
input,
4758
optgroup,
4859
select,
4960
textarea {
5061
margin: 0;
5162
}
63+
5264
button {
5365
overflow: visible;
5466
text-transform: none;
5567
}
68+
5669
button,
5770
[type="button"],
5871
[type="reset"],
5972
[type="submit"] {
6073
-webkit-appearance: button;
6174
}
75+
6276
button::-moz-focus-inner,
6377
[type="button"]::-moz-focus-inner,
6478
[type="reset"]::-moz-focus-inner,
6579
[type="submit"]::-moz-focus-inner {
6680
border-style: none;
6781
padding: 0;
6882
}
83+
6984
button:-moz-focusring,
7085
[type="button"]:-moz-focusring,
7186
[type="reset"]:-moz-focusring,
7287
[type="submit"]:-moz-focusring {
7388
outline: 1px dotted ButtonText;
7489
}
90+
7591
fieldset {
7692
padding: 0.35em 0.75em 0.625em;
7793
}
94+
7895
input {
7996
overflow: visible;
8097
}
98+
8199
legend {
82100
box-sizing: border-box;
83101
color: inherit;
@@ -86,41 +104,52 @@ legend {
86104
padding: 0;
87105
white-space: normal;
88106
}
107+
89108
progress {
90109
display: inline-block;
91110
vertical-align: baseline;
92111
}
112+
93113
select {
94114
text-transform: none;
95115
}
116+
96117
textarea {
97118
overflow: auto;
98119
}
120+
99121
[type="number"]::-webkit-inner-spin-button,
100122
[type="number"]::-webkit-outer-spin-button {
101123
height: auto;
102124
}
125+
103126
[type="search"] {
104127
-webkit-appearance: textfield;
105128
outline-offset: -2px;
106129
}
130+
107131
[type="search"]::-webkit-search-cancel-button,
108132
[type="search"]::-webkit-search-decoration {
109133
-webkit-appearance: none;
110134
}
135+
111136
::-webkit-file-upload-button {
112137
-webkit-appearance: button;
113138
font: inherit;
114139
}
140+
115141
details {
116142
display: block;
117143
}
144+
118145
summary {
119146
display: list-item;
120147
}
148+
121149
template {
122150
display: none;
123151
}
152+
124153
body {
125154
font-family: sans-serif;
126155
}

0 commit comments

Comments
 (0)