Skip to content

Commit b4eed5c

Browse files
authored
Migrate to PostCSS 8.x (#33)
1 parent 23916f5 commit b4eed5c

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"license": "Apache-2.0",
2626
"repository": "https://github.com/google/postcss-rename",
2727
"dependencies": {
28-
"postcss": "^7.0.18",
29-
"postcss-selector-parser": "^6.0.2"
28+
"postcss-selector-parser": "^6.0.4"
3029
},
3130
"devDependencies": {
3231
"@babel/cli": "^7.6.0",
@@ -40,9 +39,13 @@
4039
"gts": "2.0.0",
4140
"jest": "^24.9.0",
4241
"jest-cli": "^24.9.0",
42+
"postcss": "^8.2.6",
4343
"ts-jest": "^24.2.0",
4444
"typescript": "^3.8.0"
4545
},
46+
"peerDependencies": {
47+
"postcss": "^8.2.6"
48+
},
4649
"engines": {
4750
"node": ">=8.3.0"
4851
}

src/index.ts

+24-20
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import * as postcss from 'postcss';
1918
import selectorParser from 'postcss-selector-parser';
2019

2120
import {MinimalRenamer} from './minimal-renamer';
@@ -33,19 +32,19 @@ namespace plugin {
3332
}
3433

3534
// eslint-disable-next-line no-redeclare
36-
const plugin = postcss.plugin(
37-
'postcss-rename',
38-
({
39-
strategy = 'none',
40-
by = 'whole',
41-
prefix = '',
42-
except = [],
43-
ids = false,
44-
outputMapCallback,
45-
}: plugin.Options = {}) => {
46-
const exceptSet = new Set(except);
47-
return (root: postcss.Root): void => {
48-
if (strategy === 'none' && !outputMapCallback && !prefix) return;
35+
const plugin = ({
36+
strategy = 'none',
37+
by = 'whole',
38+
prefix = '',
39+
except = [],
40+
ids = false,
41+
outputMapCallback,
42+
}: plugin.Options = {}) => {
43+
const exceptSet = new Set(except);
44+
return {
45+
postcssPlugin: 'postcss-rename',
46+
prepare() {
47+
if (strategy === 'none' && !outputMapCallback && !prefix) return {};
4948

5049
const outputMap: {[key: string]: string} | null = outputMapCallback
5150
? {}
@@ -97,11 +96,16 @@ const plugin = postcss.plugin(
9796
if (ids) selectors.walkIds(renameNode);
9897
});
9998

100-
root.walkRules(ruleNode => selectorProcessor.process(ruleNode));
101-
102-
if (outputMapCallback) outputMapCallback(outputMap);
103-
};
104-
}
105-
);
99+
return {
100+
Rule(ruleNode) {
101+
selectorProcessor.process(ruleNode);
102+
},
103+
OnceExit() {
104+
if (outputMapCallback) outputMapCallback(outputMap);
105+
},
106+
};
107+
},
108+
};
109+
};
106110

107111
export = plugin;

test/index.test.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
*/
1717

1818
import plugin = require('../src');
19-
import postcss from 'postcss';
19+
import postcss, {Result} from 'postcss';
2020
import {toShortName} from '../src/minimal-renamer';
2121

22-
async function run(
23-
input: string,
24-
options?: plugin.Options
25-
): Promise<postcss.Result> {
22+
async function run(input: string, options?: plugin.Options): Promise<Result> {
2623
return await postcss([plugin(options)]).process(input, {from: undefined});
2724
}
2825

29-
function assertPostcss(result: postcss.Result, output: string): void {
26+
function assertPostcss(result: Result, output: string): void {
3027
expect(result.css).toEqual(output);
3128
expect(result.warnings()).toHaveLength(0);
3229
}

yarn.lock

+22-11
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,11 @@ color-name@~1.1.4:
16861686
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
16871687
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
16881688

1689+
colorette@^1.2.1:
1690+
version "1.2.1"
1691+
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.2.1.tgz#4d0b921325c14faf92633086a536db6e89564b1b"
1692+
integrity sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==
1693+
16891694
combined-stream@^1.0.6, combined-stream@~1.0.6:
16901695
version "1.0.8"
16911696
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
@@ -3810,6 +3815,11 @@ nan@^2.12.1:
38103815
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
38113816
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==
38123817

3818+
nanoid@^3.1.20:
3819+
version "3.1.20"
3820+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
3821+
integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
3822+
38133823
nanomatch@^1.2.9:
38143824
version "1.2.13"
38153825
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -4177,23 +4187,24 @@ posix-character-classes@^0.1.0:
41774187
resolved "https://registry.yarnpkg.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
41784188
integrity sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=
41794189

4180-
postcss-selector-parser@^6.0.2:
4181-
version "6.0.2"
4182-
resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-6.0.2.tgz#934cf799d016c83411859e09dcecade01286ec5c"
4183-
integrity sha512-36P2QR59jDTOAiIkqEprfJDsoNrvwFei3eCqKd1Y0tUsBimsq39BLp7RD+JWny3WgB1zGhJX8XVePwm9k4wdBg==
4190+
postcss-selector-parser@^6.0.4:
4191+
version "6.0.4"
4192+
resolved "https://registry.yarnpkg.com/postcss-selector-parser/-/postcss-selector-parser-6.0.4.tgz#56075a1380a04604c38b063ea7767a129af5c2b3"
4193+
integrity sha512-gjMeXBempyInaBqpp8gODmwZ52WaYsVOsfr4L4lDQ7n3ncD6mEyySiDtgzCT+NYC0mmeOLvtsF8iaEf0YT6dBw==
41844194
dependencies:
41854195
cssesc "^3.0.0"
41864196
indexes-of "^1.0.1"
41874197
uniq "^1.0.1"
4198+
util-deprecate "^1.0.2"
41884199

4189-
postcss@^7.0.18:
4190-
version "7.0.27"
4191-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.27.tgz#cc67cdc6b0daa375105b7c424a85567345fc54d9"
4192-
integrity sha512-WuQETPMcW9Uf1/22HWUWP9lgsIC+KEHg2kozMflKjbeUtw9ujvFX6QmIfozaErDkmLWS9WEnEdEe6Uo9/BNTdQ==
4200+
postcss@^8.2.6:
4201+
version "8.2.6"
4202+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.6.tgz#5d69a974543b45f87e464bc4c3e392a97d6be9fe"
4203+
integrity sha512-xpB8qYxgPuly166AGlpRjUdEYtmOWx2iCwGmrv4vqZL9YPVviDVPZPRXxnXr6xPZOdxQ9lp3ZBFCRgWJ7LE3Sg==
41934204
dependencies:
4194-
chalk "^2.4.2"
4205+
colorette "^1.2.1"
4206+
nanoid "^3.1.20"
41954207
source-map "^0.6.1"
4196-
supports-color "^6.1.0"
41974208

41984209
prelude-ls@~1.1.2:
41994210
version "1.1.2"
@@ -5331,7 +5342,7 @@ use@^3.1.0:
53315342
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
53325343
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==
53335344

5334-
util-deprecate@~1.0.1:
5345+
util-deprecate@^1.0.2, util-deprecate@~1.0.1:
53355346
version "1.0.2"
53365347
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
53375348
integrity sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=

0 commit comments

Comments
 (0)