Skip to content

Commit f6243b0

Browse files
authored
V5: faster, more detailed, browser-compatible (#208)
- Drop support for Node 8 and 10 ([Node.js releases](https://nodejs.org/en/about/releases/)) - Rename all metrics ending on `.share` to `.ratio` - Rename `stylesheets` to `stylesheet` - Remove `stylesheets.browserhacks` - Remove `stylesheets.cohesion` (now `rules.selectors.mean`) - Remove `atrules.documents` - Remove `atrules.mediaqueries.browserhacks` - Add `atrules.keyframes.prefixed` - Drop `atrules.namespace.*` - Drop `atrules.page.*` - Drop `atrules.supports.browserhacks.*` - Remove `stylesheets.simplicity`(now `rules.selectors.mean`) - Add `rules.selectors.mean/median/mode/etc` - Add `rules.declarations.mea/median/mode` - Remove `selectors.js.*` - Add `selectors.specificity.*` - Add `selectors.complexity.*` - Remove `selectors.browserhacks.*` - Remove `values.total` - Remove `values.browserhacks.*` - Remove `values.colors.duplicate.*` Closes #207, #206, #200, #184, #183, #181, #148, #142, #129, #121, #83, #59
1 parent 07a446f commit f6243b0

File tree

160 files changed

+491607
-12831
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+491607
-12831
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
22
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
33

4-
name: Node.js Package
4+
name: Publish
55
on:
66
release:
77
types: [created]
@@ -11,9 +11,9 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v2
1313
# Setup .npmrc file to publish to npm
14-
- uses: actions/setup-node@v1
14+
- uses: actions/setup-node@v2
1515
with:
16-
node-version: '12.x'
16+
node-version: '16.x'
1717
registry-url: https://registry.npmjs.org/
1818
- run: npm ci
1919
- run: npm publish

.github/workflows/test.yml

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,23 @@ on:
1010
branches: [master]
1111

1212
jobs:
13-
build:
13+
test:
14+
name: Unit tests
1415
runs-on: ubuntu-latest
1516

1617
strategy:
1718
matrix:
18-
node-version: [10.x, 12.x, 14.x]
19+
node-version:
20+
- 12.20.0
21+
- 14.13.0
22+
- 16
1923

2024
steps:
2125
- uses: actions/checkout@v2
2226
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v1
27+
uses: actions/setup-node@v2
2428
with:
2529
node-version: ${{ matrix.node-version }}
30+
cache: "npm"
2631
- run: npm ci
2732
- run: npm test
28-
env:
29-
CI: true
30-
- name: Coveralls
31-
uses: coverallsapp/github-action@master
32-
with:
33-
github-token: ${{ secrets.GITHUB_TOKEN }}
34-
parallel: true
35-
- name: Coveralls Finished
36-
uses: coverallsapp/github-action@master
37-
with:
38-
github-token: ${{ secrets.GITHUB_TOKEN }}
39-
parallel-finished: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
.nyc_output
33
coverage
44
.DS_Store
5+
dist

benchmark/benchmark.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import benchmark from 'benchmark'
2+
import byteSize from './format-filesize.js'
3+
import { analyze as analyzeCss } from '../dist/analyzer.js'
4+
import * as fs from 'fs'
5+
const files = [
6+
['bol-com-20190617', 'Bol.com'],
7+
['bootstrap-5.0.0', 'Bootstrap 5.0.0'],
8+
['css-tricks-20190319', 'CSS-Tricks'],
9+
['facebook-20190319', 'Facebook.com'],
10+
['github-20210501', 'GitHub.com'],
11+
['gazelle-20210905', 'Gazelle.nl'],
12+
['lego-20190617', 'Lego.com'],
13+
['smashing-magazine-20190319', 'Smashing Magazine.com'],
14+
['trello-20190617', 'Trello.com']
15+
]
16+
17+
const suite = new benchmark.Suite()
18+
let maxLen = -1
19+
20+
files.forEach(([, name]) => {
21+
if (name.length > maxLen) {
22+
maxLen = name.length
23+
}
24+
})
25+
26+
files.forEach(([filename, name]) => {
27+
const css = fs.readFileSync(`./src/__fixtures__/${filename}.css`, 'utf-8')
28+
const fileSize = byteSize(css.length)
29+
suite.add(`${name.padEnd(maxLen + 2)} (${fileSize.padStart(6)})`, () => analyzeCss(css))
30+
})
31+
32+
console.log('Running benchmark on /dist/analyzer.js:')
33+
suite
34+
.on('cycle', event => {
35+
const name = event.target.name
36+
const ops = event.target.hz.toFixed(2).padStart(6)
37+
console.log(`${name}: ${ops} ops/sec`)
38+
})
39+
.run()

benchmark/format-filesize.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
3+
const BYTE_UNITS = ["B", "kB", "MB"];
4+
5+
export default (number) => {
6+
if (number < 1) {
7+
return String(number) + " " + BYTE_UNITS[0];
8+
}
9+
10+
const exponent = Math.min(
11+
Math.floor(Math.log10(number) / 3),
12+
BYTE_UNITS.length - 1
13+
);
14+
number = Number((number / Math.pow(1000, exponent)).toPrecision(3));
15+
16+
const unit = BYTE_UNITS[exponent];
17+
18+
return String(number) + " " + unit;
19+
};

benchmark/parse-analyze-ratio.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import byteSize from './format-filesize.js'
2+
import { analyze as analyzeCss } from '../dist/analyzer.js'
3+
import * as fs from 'fs'
4+
const files = [
5+
['bol-com-20190617', 'Bol.com'],
6+
['bootstrap-5.0.0', 'Bootstrap 5.0.0'],
7+
['css-tricks-20190319', 'CSS-Tricks'],
8+
['facebook-20190319', 'Facebook.com'],
9+
['github-20210501', 'GitHub.com'],
10+
['gazelle-20210905', 'Gazelle.nl'],
11+
['lego-20190617', 'Lego.com'],
12+
['smashing-magazine-20190319', 'Smashing Magazine.com'],
13+
['trello-20190617', 'Trello.com']
14+
]
15+
16+
let maxLen = -1
17+
18+
files.forEach(([, name]) => {
19+
if (name.length > maxLen) {
20+
maxLen = name.length
21+
}
22+
})
23+
24+
console.log('Running benchmark on /dist/analyzer.js:')
25+
const header = `${'File'.padEnd(maxLen + 2)} | ${'Size'.padEnd(6)} | total | parse | Analyze |`
26+
console.log(''.padEnd(header.length, '='))
27+
console.log(header)
28+
console.log(''.padEnd(header.length, '='))
29+
30+
files.forEach(([filename, name]) => {
31+
const css = fs.readFileSync(`./src/__fixtures__/${filename}.css`, 'utf-8')
32+
const fileSize = byteSize(css.length).padStart(6)
33+
const result = analyzeCss(css)
34+
35+
name = name.padEnd(maxLen + 2)
36+
const parseTime = String(result.__meta__.parseTime).padStart(3)
37+
const analyzeTime = String(result.__meta__.analyzeTime).padStart(4)
38+
const totalTime = String(result.__meta__.total).padStart(4)
39+
const analyzeRatio = (analyzeTime / totalTime * 100).toFixed(1)
40+
41+
console.log(`${name} | ${fileSize} | ${totalTime}ms | ${parseTime}ms | ${analyzeTime}ms (${analyzeRatio}%) |`)
42+
})

benchmark/readme.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Benchmarks
2+
3+
## Analyzing
4+
5+
`node benchmark/benchmark.js`
6+
7+
```
8+
Bol.com (468 kB): 8.88 ops/sec
9+
Bootstrap 5.0.0 (195 kB): 21.81 ops/sec
10+
CSS-Tricks (195 kB): 21.14 ops/sec
11+
Facebook.com (268 kB): 13.28 ops/sec
12+
GitHub.com (514 kB): 10.28 ops/sec
13+
Gazelle.nl (972 kB): 3.14 ops/sec
14+
Lego.com (246 kB): 16.51 ops/sec
15+
Smashing Magazine.com (1.1 MB): 3.01 ops/sec
16+
Trello.com (312 kB): 12.16 ops/sec
17+
```
18+
19+
## Parsing vs. analyzing
20+
21+
`node benchmark/parse-analyze-ratio.js`
22+
23+
```
24+
====================================================================
25+
File | Size | total | parse | Analyze |
26+
====================================================================
27+
Bol.com | 468 kB | 330ms | 201ms | 128ms (38.8%) |
28+
Bootstrap 5.0.0 | 195 kB | 130ms | 88ms | 41ms (31.5%) |
29+
CSS-Tricks | 195 kB | 102ms | 62ms | 40ms (39.2%) |
30+
Facebook.com | 268 kB | 144ms | 69ms | 75ms (52.1%) |
31+
GitHub.com | 514 kB | 195ms | 90ms | 104ms (53.3%) |
32+
Gazelle.nl | 972 kB | 442ms | 209ms | 229ms (51.8%) |
33+
Lego.com | 246 kB | 89ms | 42ms | 46ms (51.7%) |
34+
Smashing Magazine.com | 1.1 MB | 356ms | 166ms | 189ms (53.1%) |
35+
Trello.com | 312 kB | 136ms | 50ms | 86ms (63.2%) |
36+
```

logo.svg

Lines changed: 9 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)