Skip to content

Commit c6fa683

Browse files
committed
Use PostCSS 8 API
1 parent 409c864 commit c6fa683

File tree

11 files changed

+2529
-3868
lines changed

11 files changed

+2529
-3868
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
.DS_Store
2-
*~
3-
41
node_modules/
5-
npm-debug.log
62
yarn-error.log
73

8-
build/
9-
lib/*.js
4+
coverage/

.npmignore

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
1-
.gitignore
2-
.npmignore
3-
.editorconfig
4-
5-
node_modules/
6-
npm-debug.log
71
yarn-error.log
82
yarn.lock
93

10-
build/
11-
124
test/
13-
.travis.yml
14-
15-
gulpfile.js
5+
coverage/

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,3 @@ node_js:
44
- node
55
- "12"
66
- "10"
7-
- "8"
8-
install:
9-
- yarn install --ignore-engines

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# PostCSS Safe Parser [![Build Status][ci-img]][ci]
1+
# PostCSS Safe Parser
22

3-
<img align="right" width="95" height="95"
3+
<img align="right" width="135" height="95"
44
title="Philosopher’s stone, logo of PostCSS"
5-
src="http://postcss.github.io/postcss/logo.svg">
5+
src="https://postcss.org/logo-leftp.svg">
66

77
A fault-tolerant CSS parser for [PostCSS], which will find & fix syntax errors,
88
capable of parsing any input. It is useful for:
@@ -14,20 +14,20 @@ capable of parsing any input. It is useful for:
1414
[Autoprefixer demo]: http://simevidas.jsbin.com/gufoko/quiet
1515
[Browserhacks]: http://browserhacks.com/
1616
[PostCSS]: https://github.com/postcss/postcss
17-
[ci-img]: https://img.shields.io/travis/postcss/postcss-safe-parser.svg
18-
[ci]: https://travis-ci.org/postcss/postcss-safe-parser
1917

2018
<a href="https://evilmartians.com/?utm_source=postcss">
21-
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
19+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
2220
</a>
2321

22+
2423
## Usage
2524

2625
```js
27-
var safe = require('postcss-safe-parser');
28-
var badCss = 'a {';
26+
const safe = require('postcss-safe-parser')
27+
28+
const badCss = 'a {'
2929

30-
postcss(plugins).process(badCss, { parser: safe }).then(function (result) {
31-
result.css //= 'a {}'
32-
});
30+
postcss(plugins).process(badCss, { parser: safe }).then(result => {
31+
result.css //= 'a {}'
32+
})
3333
```

gulpfile.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
let Input = require('postcss/lib/input')
1+
let { Input } = require('postcss')
22

33
let SafeParser = require('./safe-parser')
44

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SafeParser extends Parser {
3333
}
3434
}
3535

36-
unclosedBracket () { }
36+
unclosedBracket () {}
3737

3838
unknownWord (tokens) {
3939
this.spaces += tokens.map(i => i[1]).join('')
@@ -43,7 +43,7 @@ class SafeParser extends Parser {
4343
this.current.raws.after += '}'
4444
}
4545

46-
doubleColon () { }
46+
doubleColon () {}
4747

4848
unnamedAtrule (node) {
4949
node.name = ''
@@ -67,7 +67,7 @@ class SafeParser extends Parser {
6767
this.decl(other)
6868
}
6969

70-
checkMissedSemicolon () { }
70+
checkMissedSemicolon () {}
7171

7272
endFile () {
7373
if (this.current.nodes && this.current.nodes.length) {

package.json

Lines changed: 42 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,94 +9,66 @@
99
"parser",
1010
"fault tolerant"
1111
],
12-
"scripts": {
13-
"clean": "del-cli build/ lib/*.js",
14-
"build": "yarn clean && gulp build",
15-
"test": "gulp build && eslint-ci . && jest && ./test/integration.js"
16-
},
1712
"author": "Andrey Sitnik <[email protected]>",
1813
"license": "MIT",
1914
"repository": "postcss/postcss-safe-parser",
15+
"scripts": {
16+
"test": "jest-ci --coverage && eslint-ci . && ./test/integration.js"
17+
},
2018
"engines": {
21-
"node": ">=6.0.0"
19+
"node": ">=10.0"
2220
},
21+
"main": "lib/safe-parse",
2322
"dependencies": {
24-
"postcss": "^7.0.26"
23+
"postcss": "postcss/postcss#ose"
2524
},
2625
"devDependencies": {
27-
"@babel/core": "^7.8.4",
28-
"@babel/preset-env": "^7.8.4",
29-
"@logux/eslint-config": "^35.0.4",
30-
"babel-plugin-add-module-exports": "^1.0.2",
31-
"ci-job-number": "^0.3.1",
32-
"del-cli": "^3.0.0",
33-
"eslint": "^6.8.0",
26+
"@logux/eslint-config": "^40.0.3",
27+
"ci-job-number": "^1.2.2",
28+
"clean-publish": "^1.1.8",
29+
"eslint": "^7.7.0",
3430
"eslint-ci": "^1.0.0",
35-
"eslint-config-standard": "^14.1.0",
36-
"eslint-plugin-es5": "^1.5.0",
37-
"eslint-plugin-import": "^2.20.1",
38-
"eslint-plugin-jest": "^23.6.0",
39-
"eslint-plugin-node": "^11.0.0",
40-
"eslint-plugin-prefer-let": "^1.0.1",
31+
"eslint-config-standard": "^14.1.1",
32+
"eslint-plugin-import": "^2.22.0",
33+
"eslint-plugin-jest": "^23.20.0",
34+
"eslint-plugin-node": "^11.1.0",
35+
"eslint-plugin-prefer-let": "^1.0.2",
36+
"eslint-plugin-prettierx": "^0.14.0",
4137
"eslint-plugin-promise": "^4.2.1",
4238
"eslint-plugin-security": "^1.4.0",
4339
"eslint-plugin-standard": "^4.0.1",
44-
"eslint-plugin-unicorn": "^16.0.0",
45-
"gulp": "^4.0.2",
46-
"gulp-babel": "^8.0.0",
47-
"gulp-sourcemaps": "^2.6.5",
48-
"husky": "^4.2.1",
49-
"jest": "^25.1.0",
50-
"lint-staged": "^10.0.7",
51-
"postcss-parser-tests": "^6.5.0",
52-
"pre-commit": "^1.1.3"
53-
},
54-
"eslintConfig": {
55-
"extends": "@logux/eslint-config/node",
56-
"overrides": [
57-
{
58-
"files": [
59-
"gulpfile.js"
60-
],
61-
"rules": {
62-
"node/no-unpublished-require": "off",
63-
"global-require": "off"
64-
}
65-
}
66-
]
67-
},
68-
"eslintIgnore": [
69-
"build/",
70-
"lib/*.js"
71-
],
72-
"jest": {
73-
"testEnvironment": "node",
74-
"modulePathIgnorePatterns": [
75-
"<rootDir>/build"
76-
]
40+
"eslint-plugin-unicorn": "^21.0.0",
41+
"husky": "^4.2.5",
42+
"jest": "^26.4.2",
43+
"jest-ci": "^0.1.1",
44+
"lint-staged": "^10.2.13",
45+
"postcss-parser-tests": "postcss/postcss-parser-tests",
46+
"postcss-sharec-config": "^0.1.3"
7747
},
78-
"babel": {
79-
"presets": [
80-
[
81-
"@babel/env",
82-
{
83-
"loose": true
84-
}
85-
]
86-
],
87-
"plugins": [
88-
"add-module-exports"
89-
]
90-
},
91-
"main": "lib/safe-parse",
9248
"husky": {
9349
"hooks": {
9450
"pre-commit": "lint-staged"
9551
}
9652
},
9753
"lint-staged": {
98-
"gulpfile.js": "eslint",
99-
"test/*.js": "eslint",
100-
"lib/*.es6": "eslint"
54+
"*.js": "eslint --fix"
55+
},
56+
"eslintConfig": {
57+
"extends": "@logux/eslint-config",
58+
"rules": {
59+
"security/detect-unsafe-regex": "off"
60+
}
61+
},
62+
"jest": {
63+
"testEnvironment": "node",
64+
"coverageThreshold": {
65+
"global": {
66+
"statements": 100
67+
}
68+
}
69+
},
70+
"sharec": {
71+
"config": "postcss-sharec-config",
72+
"version": "0.1.3"
10173
}
10274
}

test/integration.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
#!/usr/bin/env node
22

3+
let { testOnReal } = require('postcss-parser-tests')
34
let ciJobNumber = require('ci-job-number')
4-
let real = require('postcss-parser-tests/real')
55

6-
let safe = require('../build')
7-
8-
const BROWSERHACKS =
9-
'https://raw.githubusercontent.com/maste/browserhacks/gh-pages/' +
10-
'assets/css/tests.css'
6+
let safe = require('../lib/safe-parse')
117

128
if (ciJobNumber() === 1) {
13-
real(() => true, [['Browserhacks', BROWSERHACKS]], css => {
14-
return safe(css).toResult({ map: { annotation: false } })
15-
})
9+
testOnReal(css => safe(css).toResult({ map: { annotation: false } }), [
10+
'https://raw.githubusercontent.com/' +
11+
'4ae9b8/browserhacks/gh-pages/assets/css/tests.css'
12+
])
1613
}

test/parse.test.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
let cases = require('postcss-parser-tests')
1+
let { eachTest, jsonify } = require('postcss-parser-tests')
22

33
let parse = require('../lib/safe-parse')
44

5-
cases.each((name, css, json) => {
5+
eachTest((name, css, json) => {
66
if (name !== 'apply.css' && name !== 'custom-properties.css') {
77
it('parses ' + name, () => {
8-
let parsed = cases.jsonify(parse(css, { from: name }))
8+
let parsed = jsonify(parse(css, { from: name }))
99
expect(parsed).toEqual(json)
1010
})
1111
}
1212
})
1313

1414
it('fixes unclosed blocks in safe mode', () => {
15-
expect(parse('@media (screen) { a {\n').toString())
16-
.toEqual('@media (screen) { a {\n}}')
15+
expect(parse('@media (screen) { a {\n').toString()).toEqual(
16+
'@media (screen) { a {\n}}'
17+
)
1718
expect(parse('a { color').toString()).toEqual('a { color}')
1819
expect(parse('a { color: black').first.first.prop).toEqual('color')
1920
})
@@ -70,7 +71,7 @@ it('fixes property without semicolon in safe mode', () => {
7071

7172
it('does not fall on missed semicolon in IE filter', () => {
7273
expect(() => {
73-
parse('a { one: two: progid:DX(a=\'1\', b=\'2\'); }')
74+
parse("a { one: two: progid:DX(a='1', b='2'); }")
7475
}).not.toThrow()
7576
})
7677

0 commit comments

Comments
 (0)