Skip to content

Commit fb833e7

Browse files
authored
build: update to latest postcss and resolve issues (#21437)
Updates us to the latest versions of PostCSS and Stylelint. The bot tried to do it in #21279, but it caused some compilation errors. These changes resolve the errors which are due to the fact that the Stylelint typing are stuck on an older version of the PostCSS types.
1 parent 545e898 commit fb833e7

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"moment": "^2.18.1",
150150
"node-fetch": "^2.6.0",
151151
"parse5": "^6.0.1",
152-
"postcss": "^7.0.27",
152+
"postcss": "^8.2.1",
153153
"protractor": "^7.0.0",
154154
"requirejs": "^2.3.6",
155155
"rollup": "~1.25.0",
@@ -164,7 +164,7 @@
164164
"semver": "^6.3.0",
165165
"send": "^0.17.1",
166166
"shelljs": "^0.8.3",
167-
"stylelint": "^13.7.2",
167+
"stylelint": "^13.8.0",
168168
"terser": "^4.8.0",
169169
"ts-api-guardian": "^0.5.0",
170170
"ts-node": "^9.0.0",

tools/postcss/compare-nodes.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import * as postcss from 'postcss';
9+
import {Node, Declaration, Rule} from 'postcss';
1010

1111
/**
1212
* Compares two Postcss AST nodes and returns whether a boolean indicating
1313
* whether they represent the same styles or not. The function does not handle
1414
* `AtRule` nodes or nested rules as it is only concerned with CSS stylesheets
1515
* and the comparison of declarations and rule selectors.
1616
*/
17-
export function compareNodes(a: postcss.Node, b: postcss.Node): boolean {
17+
export function compareNodes(a: Node, b: Node): boolean {
1818
if (a.type !== b.type) {
1919
return false;
2020
}
2121

2222
// Types of A and B are always equal, but for type inferring we
2323
// check both nodes again.
24-
if (a.type === 'decl' && b.type === 'decl') {
24+
if (isDeclaration(a) && isDeclaration(b)) {
2525
return a.prop === b.prop && a.value === b.value;
2626
}
2727

2828
// We only check either rules or declarations. Since we check CSS,
2929
// there cannot be any nested `atrule` or `rule` nodes.
30-
if (a.type !== 'rule' || b.type !== 'rule') {
30+
if (!isRule(a) || !isRule(b)) {
3131
return false;
3232
}
3333

@@ -44,3 +44,13 @@ export function compareNodes(a: postcss.Node, b: postcss.Node): boolean {
4444
}
4545
return equal;
4646
}
47+
48+
/** Asserts that a node is a `Declaration`. */
49+
function isDeclaration(node: Node): node is Declaration {
50+
return node.type === 'decl';
51+
}
52+
53+
/** Asserts that a node is a `Rule`. */
54+
function isRule(node: Node): node is Rule {
55+
return node.type === 'rule';
56+
}

tools/stylelint/no-ampersand-beyond-selector-start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {createPlugin, utils} from 'stylelint';
22
import {basename} from 'path';
3-
import {Node} from 'postcss';
3+
import {Node} from './stylelint-postcss-types';
44

55
const isStandardSyntaxRule = require('stylelint/lib/utils/isStandardSyntaxRule');
66
const isStandardSyntaxSelector = require('stylelint/lib/utils/isStandardSyntaxSelector');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// `@types/postcss` is locked into an older version of `postcss` whose types no longer align with
2+
// the latest ones on npm. This file re-exports the versions that are compatible with Stylelint so
3+
// that we can use them in our custom rules.
4+
// This file can be removed when `@types/postcss` has been updated or when `stylelint` starts to
5+
// publish their type declarations. See https://github.com/stylelint/stylelint/issues/4399.
6+
export {
7+
AtRule,
8+
atRule,
9+
decl,
10+
Declaration,
11+
Node,
12+
Result,
13+
Root
14+
} from 'stylelint/node_modules/postcss';

tools/stylelint/theme-mixin-api.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import {AtRule, atRule, decl, Declaration, Node, Result, Root} from 'postcss';
21
import {createPlugin, Plugin, utils} from 'stylelint';
2+
import {
3+
AtRule,
4+
atRule,
5+
decl,
6+
Declaration,
7+
Node,
8+
Result,
9+
Root
10+
} from './stylelint-postcss-types';
311

412
/** Name of this stylelint rule. */
513
const ruleName = 'material/theme-mixin-api';

yarn.lock

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,16 +7714,11 @@ join-path@^1.1.1:
77147714
url-join "0.0.1"
77157715
valid-url "^1"
77167716

7717-
js-base64@^2.1.8:
7717+
js-base64@^2.1.8, js-base64@^2.1.9:
77187718
version "2.6.4"
77197719
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.6.4.tgz#f4e686c5de1ea1f867dbcad3d46d969428df98c4"
77207720
integrity sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ==
77217721

7722-
js-base64@^2.1.9:
7723-
version "2.4.9"
7724-
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.4.9.tgz#748911fb04f48a60c4771b375cac45a80df11c03"
7725-
integrity sha512-xcinL3AuDJk7VSzsHgb9DvvIXayBbadtMZ4HFPx8rUszbW1MuNMlwYVC4zzCZ6e1sqZpnNS5ZFYOhXqA39T7LQ==
7726-
77277722
js-tokens@^4.0.0:
77287723
version "4.0.0"
77297724
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -9309,6 +9304,11 @@ nan@^2.14.2:
93099304
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
93109305
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
93119306

9307+
nanoid@^3.1.20:
9308+
version "3.1.20"
9309+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.20.tgz#badc263c6b1dcf14b71efaa85f6ab4c1d6cfc788"
9310+
integrity sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw==
9311+
93129312
nanomatch@^1.2.9:
93139313
version "1.2.13"
93149314
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
@@ -10387,7 +10387,7 @@ postcss-values-parser@^1.5.0:
1038710387
indexes-of "^1.0.1"
1038810388
uniq "^1.0.1"
1038910389

10390-
[email protected], postcss@^7.0.14, postcss@^7.0.2, postcss@^7.0.21, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.32, postcss@^7.0.35, postcss@^7.0.6:
10390+
[email protected], postcss@^7.0.14, postcss@^7.0.2, postcss@^7.0.21, postcss@^7.0.26, postcss@^7.0.32, postcss@^7.0.35, postcss@^7.0.6:
1039110391
version "7.0.35"
1039210392
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.35.tgz#d2be00b998f7f211d8a276974079f2e92b970e24"
1039310393
integrity sha512-3QT8bBJeX/S5zKTTjTCIjRF3If4avAT6kqxcASlTWEtAFCb9NH0OUxNDfgZSWdP5fJnBYCMEWkIFfWeugjzYMg==
@@ -10406,6 +10406,15 @@ postcss@^5.2.16:
1040610406
source-map "^0.5.6"
1040710407
supports-color "^3.2.3"
1040810408

10409+
postcss@^8.2.1:
10410+
version "8.2.1"
10411+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.2.1.tgz#eabc5557c4558059b9d9e5b15bce7ffa9089c2a8"
10412+
integrity sha512-RhsqOOAQzTgh1UB/IZdca7F9WDb7SUCR2Vnv1x7DbvuuggQIpoDwjK+q0rzoPffhYvWNKX5JSwS4so4K3UC6vA==
10413+
dependencies:
10414+
colorette "^1.2.1"
10415+
nanoid "^3.1.20"
10416+
source-map "^0.6.1"
10417+
1040910418
postinstall-build@^5.0.1:
1041010419
version "5.0.3"
1041110420
resolved "https://registry.yarnpkg.com/postinstall-build/-/postinstall-build-5.0.3.tgz#238692f712a481d8f5bc8960e94786036241efc7"
@@ -12314,7 +12323,7 @@ style-search@^0.1.0:
1231412323
resolved "https://registry.yarnpkg.com/style-search/-/style-search-0.1.0.tgz#7958c793e47e32e07d2b5cafe5c0bf8e12e77902"
1231512324
integrity sha1-eVjHk+R+MuB9K1yv5cC/jhLneQI=
1231612325

12317-
stylelint@^13.7.2:
12326+
stylelint@^13.8.0:
1231812327
version "13.8.0"
1231912328
resolved "https://registry.yarnpkg.com/stylelint/-/stylelint-13.8.0.tgz#446765dbe25e3617f819a0165956faf2563ddc23"
1232012329
integrity sha512-iHH3dv3UI23SLDrH4zMQDjLT9/dDIz/IpoFeuNxZmEx86KtfpjDOscxLTFioQyv+2vQjPlRZnK0UoJtfxLICXQ==

0 commit comments

Comments
 (0)