postcss-discard-comments 5.0.0-rc.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -12
- package/{dist → src}/index.js +49 -37
- package/{dist → src}/lib/commentParser.js +4 -11
- package/{dist → src}/lib/commentRemover.js +2 -10
- package/CHANGELOG.md +0 -56
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-discard-comments",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Discard comments in your CSS files with PostCSS.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
7
|
+
"src",
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"css",
|
|
17
12
|
"comments",
|
|
@@ -33,10 +28,10 @@
|
|
|
33
28
|
"node": "^10 || ^12 || >=14.0"
|
|
34
29
|
},
|
|
35
30
|
"devDependencies": {
|
|
36
|
-
"postcss": "^8.2.
|
|
31
|
+
"postcss": "^8.2.15"
|
|
37
32
|
},
|
|
38
33
|
"peerDependencies": {
|
|
39
|
-
"postcss": "^8.2.
|
|
34
|
+
"postcss": "^8.2.15"
|
|
40
35
|
},
|
|
41
|
-
"
|
|
42
|
-
}
|
|
36
|
+
"readme": "# [postcss][postcss]-discard-comments\n\n> Discard comments in your CSS files with PostCSS.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-discard-comments) do:\n\n```\nnpm install postcss-discard-comments --save\n```\n\n\n## Example\n\n### Input\n\n```css\nh1/* heading */{\n margin: 0 auto\n}\n```\n\n### Output\n\n```css\nh1 {\n margin: 0 auto\n}\n```\n\nThis module discards comments from your CSS files; by default, it will remove\nall regular comments (`/* comment */`) and preserve comments marked as important\n(`/*! important */`).\n\nNote that this module does not handle source map comments because they are not\navailable to it; PostCSS handles this internally, so if they are removed then\nyou will have to [configure source maps in PostCSS][maps].\n\n[maps]: https://github.com/postcss/postcss/blob/master/docs/source-maps.md\n\n\n## API\n\n### comments([options])\n\n#### options\n\n##### remove(function)\n\nType: `function`\nReturn: `boolean`\nVariable: `comment` contains a comment without `/**/`\n\nFor each comment, return true to remove, or false to keep the comment.\n\n```js\nfunction(comment) {}\n```\n\n```js\nvar css = '/* headings *//*@ h1 */h1{margin:0 auto}/*@ h2 */h2{color:red}';\nconsole.log(postcss(comments({\n remove: function(comment) { return comment[0] == \"@\"; }\n})).process(css).css);\n//=> /* headings */h1{margin:0 auto}h2{color:red}\n```\n**NOTE:** If you use the `remove` function other options will not be available.\n\n##### removeAll\n\nType: `boolean`\nDefault: `false`\n\nRemove all comments marked as important.\n\n```js\nvar css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';\nconsole.log(postcss(comments({removeAll: true})).process(css).css);\n//=> h1{margin:0 auto}h2{color:red}\n```\n\n##### removeAllButFirst\n\nType: `boolean`\nDefault: `false`\n\nRemove all comments marked as important, but the first one.\n\n```js\nvar css = '/*! heading */h1{margin:0 auto}/*! heading 2 */h2{color:red}';\nconsole.log(postcss(comments({removeAllButFirst: true})).process(css).css);\n//=> /*! heading */h1{margin:0 auto}h2{color:red}\n```\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
37
|
+
}
|
package/{dist → src}/index.js
RENAMED
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _commentRemover = _interopRequireDefault(require("./lib/commentRemover"));
|
|
9
|
-
|
|
10
|
-
var _commentParser = _interopRequireDefault(require("./lib/commentParser"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
'use strict';
|
|
2
|
+
const CommentRemover = require('./lib/commentRemover');
|
|
3
|
+
const commentParser = require('./lib/commentParser');
|
|
13
4
|
|
|
14
5
|
function pluginCreator(opts = {}) {
|
|
15
|
-
const remover = new
|
|
16
|
-
const matcherCache =
|
|
17
|
-
const replacerCache =
|
|
6
|
+
const remover = new CommentRemover(opts);
|
|
7
|
+
const matcherCache = new Map();
|
|
8
|
+
const replacerCache = new Map();
|
|
18
9
|
|
|
19
10
|
function matchesComments(source) {
|
|
20
|
-
if (matcherCache
|
|
21
|
-
return matcherCache
|
|
11
|
+
if (matcherCache.has(source)) {
|
|
12
|
+
return matcherCache.get(source);
|
|
22
13
|
}
|
|
23
14
|
|
|
24
|
-
const result = (
|
|
25
|
-
|
|
15
|
+
const result = commentParser(source).filter(([type]) => type);
|
|
16
|
+
|
|
17
|
+
matcherCache.set(source, result);
|
|
18
|
+
|
|
26
19
|
return result;
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
function replaceComments(source, space, separator = ' ') {
|
|
30
23
|
const key = source + '@|@' + separator;
|
|
31
24
|
|
|
32
|
-
if (replacerCache
|
|
33
|
-
return replacerCache
|
|
25
|
+
if (replacerCache.has(key)) {
|
|
26
|
+
return replacerCache.get(key);
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
const parsed = (
|
|
29
|
+
const parsed = commentParser(source).reduce((value, [type, start, end]) => {
|
|
37
30
|
const contents = source.slice(start, end);
|
|
38
31
|
|
|
39
32
|
if (!type) {
|
|
@@ -46,20 +39,22 @@ function pluginCreator(opts = {}) {
|
|
|
46
39
|
|
|
47
40
|
return `${value}/*${contents}*/`;
|
|
48
41
|
}, '');
|
|
42
|
+
|
|
49
43
|
const result = space(parsed).join(' ');
|
|
50
|
-
|
|
44
|
+
|
|
45
|
+
replacerCache.set(key, result);
|
|
46
|
+
|
|
51
47
|
return result;
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
return {
|
|
55
51
|
postcssPlugin: 'postcss-discard-comments',
|
|
56
52
|
|
|
57
|
-
OnceExit(css, {
|
|
58
|
-
|
|
59
|
-
}) {
|
|
60
|
-
css.walk(node => {
|
|
53
|
+
OnceExit(css, { list }) {
|
|
54
|
+
css.walk((node) => {
|
|
61
55
|
if (node.type === 'comment' && remover.canRemove(node.text)) {
|
|
62
56
|
node.remove();
|
|
57
|
+
|
|
63
58
|
return;
|
|
64
59
|
}
|
|
65
60
|
|
|
@@ -79,22 +74,39 @@ function pluginCreator(opts = {}) {
|
|
|
79
74
|
}
|
|
80
75
|
|
|
81
76
|
if (node.raws.important) {
|
|
82
|
-
node.raws.important = replaceComments(
|
|
77
|
+
node.raws.important = replaceComments(
|
|
78
|
+
node.raws.important,
|
|
79
|
+
list.space
|
|
80
|
+
);
|
|
81
|
+
|
|
83
82
|
const b = matchesComments(node.raws.important);
|
|
83
|
+
|
|
84
84
|
node.raws.important = b.length ? node.raws.important : '!important';
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
if (
|
|
91
|
-
node.
|
|
90
|
+
if (
|
|
91
|
+
node.type === 'rule' &&
|
|
92
|
+
node.raws.selector &&
|
|
93
|
+
node.raws.selector.raw
|
|
94
|
+
) {
|
|
95
|
+
node.raws.selector.raw = replaceComments(
|
|
96
|
+
node.raws.selector.raw,
|
|
97
|
+
list.space,
|
|
98
|
+
''
|
|
99
|
+
);
|
|
100
|
+
|
|
92
101
|
return;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
if (node.type === 'atrule') {
|
|
96
105
|
if (node.raws.afterName) {
|
|
97
|
-
const commentsReplaced = replaceComments(
|
|
106
|
+
const commentsReplaced = replaceComments(
|
|
107
|
+
node.raws.afterName,
|
|
108
|
+
list.space
|
|
109
|
+
);
|
|
98
110
|
|
|
99
111
|
if (!commentsReplaced.length) {
|
|
100
112
|
node.raws.afterName = commentsReplaced + ' ';
|
|
@@ -104,16 +116,16 @@ function pluginCreator(opts = {}) {
|
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
if (node.raws.params && node.raws.params.raw) {
|
|
107
|
-
node.raws.params.raw = replaceComments(
|
|
119
|
+
node.raws.params.raw = replaceComments(
|
|
120
|
+
node.raws.params.raw,
|
|
121
|
+
list.space
|
|
122
|
+
);
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
});
|
|
111
|
-
}
|
|
112
|
-
|
|
126
|
+
},
|
|
113
127
|
};
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
pluginCreator.postcss = true;
|
|
117
|
-
|
|
118
|
-
exports.default = _default;
|
|
119
|
-
module.exports = exports.default;
|
|
131
|
+
module.exports = pluginCreator;
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = commentParser;
|
|
7
|
-
|
|
8
|
-
function commentParser(input) {
|
|
1
|
+
'use strict';
|
|
2
|
+
module.exports = function commentParser(input) {
|
|
9
3
|
const tokens = [];
|
|
10
4
|
const length = input.length;
|
|
11
5
|
let pos = 0;
|
|
@@ -17,6 +11,7 @@ function commentParser(input) {
|
|
|
17
11
|
if (~next) {
|
|
18
12
|
tokens.push([0, pos, next]);
|
|
19
13
|
pos = next;
|
|
14
|
+
|
|
20
15
|
next = input.indexOf('*/', pos + 2);
|
|
21
16
|
tokens.push([1, pos + 2, next]);
|
|
22
17
|
pos = next + 2;
|
|
@@ -27,6 +22,4 @@ function commentParser(input) {
|
|
|
27
22
|
}
|
|
28
23
|
|
|
29
24
|
return tokens;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = exports.default;
|
|
25
|
+
};
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
1
|
+
'use strict';
|
|
8
2
|
function CommentRemover(options) {
|
|
9
3
|
this.options = options;
|
|
10
4
|
}
|
|
@@ -30,6 +24,4 @@ CommentRemover.prototype.canRemove = function (comment) {
|
|
|
30
24
|
}
|
|
31
25
|
};
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
exports.default = _default;
|
|
35
|
-
module.exports = exports.default;
|
|
27
|
+
module.exports = CommentRemover;
|
package/CHANGELOG.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-discard-comments@5.0.0-rc.1...postcss-discard-comments@5.0.0-rc.2) (2021-03-15)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-discard-comments
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-discard-comments@5.0.0-rc.0...postcss-discard-comments@5.0.0-rc.1) (2021-03-04)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-discard-comments
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### chore
|
|
26
|
-
|
|
27
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
### Features
|
|
31
|
-
|
|
32
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
### BREAKING CHANGES
|
|
36
|
-
|
|
37
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
38
|
-
* minimum require version of node is 10.13
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## 4.1.9 (2019-02-12)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
### Performance Improvements
|
|
46
|
-
|
|
47
|
-
* **postcss-discard-comments:** increase perf ([#700](https://github.com/cssnano/cssnano/issues/700)) ([84294e9](https://github.com/cssnano/cssnano/commit/84294e97da82bd2fb5cf9299f0a9dc4441c8d70c))
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
## 4.1.1 (2018-09-24)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
### Bug Fixes
|
|
55
|
-
|
|
56
|
-
* **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
|