postcss 8.4.23 → 8.4.25

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.

Potentially problematic release.


This version of postcss might be problematic. Click here for more details.

package/lib/postcss.d.ts CHANGED
@@ -1,28 +1,28 @@
1
- import { SourceMapGenerator, RawSourceMap } from 'source-map-js'
1
+ import { RawSourceMap, SourceMapGenerator } from 'source-map-js'
2
2
 
3
+ import AtRule, { AtRuleProps } from './at-rule.js'
4
+ import Comment, { CommentProps } from './comment.js'
5
+ import Container, { ContainerProps } from './container.js'
6
+ import CssSyntaxError from './css-syntax-error.js'
7
+ import Declaration, { DeclarationProps } from './declaration.js'
8
+ import Document, { DocumentProps } from './document.js'
9
+ import Input, { FilePosition } from './input.js'
10
+ import LazyResult from './lazy-result.js'
11
+ import list from './list.js'
3
12
  import Node, {
4
- Position,
5
- Source,
13
+ AnyNode,
6
14
  ChildNode,
15
+ ChildProps,
7
16
  NodeErrorOptions,
8
17
  NodeProps,
9
- ChildProps,
10
- AnyNode
18
+ Position,
19
+ Source
11
20
  } from './node.js'
12
- import Declaration, { DeclarationProps } from './declaration.js'
13
- import Container, { ContainerProps } from './container.js'
14
- import Document, { DocumentProps } from './document.js'
15
- import Warning, { WarningOptions } from './warning.js'
16
- import Comment, { CommentProps } from './comment.js'
17
- import AtRule, { AtRuleProps } from './at-rule.js'
18
- import Input, { FilePosition } from './input.js'
21
+ import Processor from './processor.js'
19
22
  import Result, { Message } from './result.js'
20
23
  import Root, { RootProps } from './root.js'
21
24
  import Rule, { RuleProps } from './rule.js'
22
- import CssSyntaxError from './css-syntax-error.js'
23
- import list from './list.js'
24
- import LazyResult from './lazy-result.js'
25
- import Processor from './processor.js'
25
+ import Warning, { WarningOptions } from './warning.js'
26
26
 
27
27
  type DocumentProcessor = (
28
28
  document: Document,
@@ -42,42 +42,33 @@ type CommentProcessor = (
42
42
 
43
43
  interface Processors {
44
44
  /**
45
- * Will be called on `Document` node.
45
+ * Will be called on all`AtRule` nodes.
46
46
  *
47
- * Will be called again on children changes.
47
+ * Will be called again on node or children changes.
48
48
  */
49
- Document?: DocumentProcessor
49
+ AtRule?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
50
50
 
51
51
  /**
52
- * Will be called on `Document` node, when all children will be processed.
52
+ * Will be called on all `AtRule` nodes, when all children will be processed.
53
53
  *
54
- * Will be called again on children changes.
55
- */
56
- DocumentExit?: DocumentProcessor
57
-
58
- /**
59
- * Will be called on `Root` node once.
60
- */
61
- Once?: RootProcessor
62
-
63
- /**
64
- * Will be called on `Root` node once, when all children will be processed.
54
+ * Will be called again on node or children changes.
65
55
  */
66
- OnceExit?: RootProcessor
56
+ AtRuleExit?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
67
57
 
68
58
  /**
69
- * Will be called on `Root` node.
59
+ * Will be called on all `Comment` nodes.
70
60
  *
71
- * Will be called again on children changes.
61
+ * Will be called again on node or children changes.
72
62
  */
73
- Root?: RootProcessor
63
+ Comment?: CommentProcessor
74
64
 
75
65
  /**
76
- * Will be called on `Root` node, when all children will be processed.
66
+ * Will be called on all `Comment` nodes after listeners
67
+ * for `Comment` event.
77
68
  *
78
- * Will be called again on children changes.
69
+ * Will be called again on node or children changes.
79
70
  */
80
- RootExit?: RootProcessor
71
+ CommentExit?: CommentProcessor
81
72
 
82
73
  /**
83
74
  * Will be called on all `Declaration` nodes after listeners
@@ -85,7 +76,7 @@ interface Processors {
85
76
  *
86
77
  * Will be called again on node or children changes.
87
78
  */
88
- Declaration?: DeclarationProcessor | { [prop: string]: DeclarationProcessor }
79
+ Declaration?: { [prop: string]: DeclarationProcessor } | DeclarationProcessor
89
80
 
90
81
  /**
91
82
  * Will be called on all `Declaration` nodes.
@@ -93,101 +84,103 @@ interface Processors {
93
84
  * Will be called again on node or children changes.
94
85
  */
95
86
  DeclarationExit?:
96
- | DeclarationProcessor
97
87
  | { [prop: string]: DeclarationProcessor }
88
+ | DeclarationProcessor
98
89
 
99
90
  /**
100
- * Will be called on all `Rule` nodes.
91
+ * Will be called on `Document` node.
101
92
  *
102
- * Will be called again on node or children changes.
93
+ * Will be called again on children changes.
103
94
  */
104
- Rule?: RuleProcessor
95
+ Document?: DocumentProcessor
105
96
 
106
97
  /**
107
- * Will be called on all `Rule` nodes, when all children will be processed.
98
+ * Will be called on `Document` node, when all children will be processed.
108
99
  *
109
- * Will be called again on node or children changes.
100
+ * Will be called again on children changes.
110
101
  */
111
- RuleExit?: RuleProcessor
102
+ DocumentExit?: DocumentProcessor
112
103
 
113
104
  /**
114
- * Will be called on all`AtRule` nodes.
115
- *
116
- * Will be called again on node or children changes.
105
+ * Will be called on `Root` node once.
117
106
  */
118
- AtRule?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
107
+ Once?: RootProcessor
119
108
 
120
109
  /**
121
- * Will be called on all `AtRule` nodes, when all children will be processed.
110
+ * Will be called on `Root` node once, when all children will be processed.
111
+ */
112
+ OnceExit?: RootProcessor
113
+
114
+ /**
115
+ * Will be called on `Root` node.
122
116
  *
123
- * Will be called again on node or children changes.
117
+ * Will be called again on children changes.
124
118
  */
125
- AtRuleExit?: AtRuleProcessor | { [name: string]: AtRuleProcessor }
119
+ Root?: RootProcessor
126
120
 
127
121
  /**
128
- * Will be called on all `Comment` nodes.
122
+ * Will be called on `Root` node, when all children will be processed.
129
123
  *
130
- * Will be called again on node or children changes.
124
+ * Will be called again on children changes.
131
125
  */
132
- Comment?: CommentProcessor
126
+ RootExit?: RootProcessor
133
127
 
134
128
  /**
135
- * Will be called on all `Comment` nodes after listeners
136
- * for `Comment` event.
129
+ * Will be called on all `Rule` nodes.
137
130
  *
138
131
  * Will be called again on node or children changes.
139
132
  */
140
- CommentExit?: CommentProcessor
133
+ Rule?: RuleProcessor
141
134
 
142
135
  /**
143
- * Will be called when all other listeners processed the document.
136
+ * Will be called on all `Rule` nodes, when all children will be processed.
144
137
  *
145
- * This listener will not be called again.
138
+ * Will be called again on node or children changes.
146
139
  */
147
- Exit?: RootProcessor
140
+ RuleExit?: RuleProcessor
148
141
  }
149
142
 
150
143
  declare namespace postcss {
151
144
  export {
152
- NodeErrorOptions,
153
- DeclarationProps,
154
- CssSyntaxError,
145
+ AnyNode,
146
+ AtRule,
147
+ AtRuleProps,
148
+ ChildNode,
149
+ ChildProps,
150
+ Comment,
151
+ CommentProps,
152
+ Container,
155
153
  ContainerProps,
156
- WarningOptions,
154
+ CssSyntaxError,
155
+ Declaration,
156
+ DeclarationProps,
157
+ Document,
157
158
  DocumentProps,
158
159
  FilePosition,
159
- CommentProps,
160
- AtRuleProps,
161
- Declaration,
162
- ChildProps,
160
+ Input,
163
161
  LazyResult,
164
- ChildNode,
162
+ list,
163
+ Message,
164
+ Node,
165
+ NodeErrorOptions,
165
166
  NodeProps,
166
- Processor,
167
- RuleProps,
168
- RootProps,
169
- Container,
170
167
  Position,
171
- Document,
172
- AnyNode,
173
- Warning,
174
- Message,
175
- Comment,
176
- Source,
177
- AtRule,
168
+ Processor,
178
169
  Result,
179
- Input,
180
- Node,
181
- list,
170
+ Root,
171
+ RootProps,
182
172
  Rule,
183
- Root
173
+ RuleProps,
174
+ Source,
175
+ Warning,
176
+ WarningOptions
184
177
  }
185
178
 
186
179
  export type SourceMap = SourceMapGenerator & {
187
180
  toJSON(): RawSourceMap
188
181
  }
189
182
 
190
- export type Helpers = { result: Result; postcss: Postcss } & Postcss
183
+ export type Helpers = { postcss: Postcss; result: Result } & Postcss
191
184
 
192
185
  export interface Plugin extends Processors {
193
186
  postcssPlugin: string
@@ -214,24 +207,24 @@ declare namespace postcss {
214
207
  }
215
208
 
216
209
  export type AcceptedPlugin =
217
- | Plugin
218
- | PluginCreator<any>
219
- | OldPlugin<any>
220
- | TransformCallback
221
210
  | {
222
- postcss: TransformCallback | Processor
211
+ postcss: Processor | TransformCallback
223
212
  }
213
+ | OldPlugin<any>
214
+ | Plugin
215
+ | PluginCreator<any>
224
216
  | Processor
217
+ | TransformCallback
225
218
 
226
- export interface Parser<RootNode = Root | Document> {
219
+ export interface Parser<RootNode = Document | Root> {
227
220
  (
228
- css: string | { toString(): string },
229
- opts?: Pick<ProcessOptions, 'map' | 'from'>
221
+ css: { toString(): string } | string,
222
+ opts?: Pick<ProcessOptions, 'from' | 'map'>
230
223
  ): RootNode
231
224
  }
232
225
 
233
226
  export interface Builder {
234
- (part: string, node?: AnyNode, type?: 'start' | 'end'): void
227
+ (part: string, node?: AnyNode, type?: 'end' | 'start'): void
235
228
  }
236
229
 
237
230
  export interface Stringifier {
@@ -239,8 +232,8 @@ declare namespace postcss {
239
232
  }
240
233
 
241
234
  export interface JSONHydrator {
242
- (data: object[]): Node[]
243
235
  (data: object): Node
236
+ (data: object[]): Node[]
244
237
  }
245
238
 
246
239
  export interface Syntax {
@@ -256,6 +249,30 @@ declare namespace postcss {
256
249
  }
257
250
 
258
251
  export interface SourceMapOptions {
252
+ /**
253
+ * Use absolute path in generated source map.
254
+ */
255
+ absolute?: boolean
256
+
257
+ /**
258
+ * Indicates that PostCSS should add annotation comments to the CSS.
259
+ * By default, PostCSS will always add a comment with a path
260
+ * to the source map. PostCSS will not add annotations to CSS files
261
+ * that do not contain any comments.
262
+ *
263
+ * By default, PostCSS presumes that you want to save the source map as
264
+ * `opts.to + '.map'` and will use this path in the annotation comment.
265
+ * A different path can be set by providing a string value for annotation.
266
+ *
267
+ * If you have set `inline: true`, annotation cannot be disabled.
268
+ */
269
+ annotation?: ((file: string, root: Root) => string) | boolean | string
270
+
271
+ /**
272
+ * Override `from` in map’s sources.
273
+ */
274
+ from?: string
275
+
259
276
  /**
260
277
  * Indicates that the source map should be embedded in the output CSS
261
278
  * as a Base64-encoded comment. By default, it is `true`.
@@ -276,7 +293,7 @@ declare namespace postcss {
276
293
  *
277
294
  * If desired, you can omit the previous map with prev: `false`.
278
295
  */
279
- prev?: string | boolean | object | ((file: string) => string)
296
+ prev?: ((file: string) => string) | boolean | object | string
280
297
 
281
298
  /**
282
299
  * Indicates that PostCSS should set the origin content (e.g., Sass source)
@@ -285,30 +302,6 @@ declare namespace postcss {
285
302
  * do not set this option.
286
303
  */
287
304
  sourcesContent?: boolean
288
-
289
- /**
290
- * Indicates that PostCSS should add annotation comments to the CSS.
291
- * By default, PostCSS will always add a comment with a path
292
- * to the source map. PostCSS will not add annotations to CSS files
293
- * that do not contain any comments.
294
- *
295
- * By default, PostCSS presumes that you want to save the source map as
296
- * `opts.to + '.map'` and will use this path in the annotation comment.
297
- * A different path can be set by providing a string value for annotation.
298
- *
299
- * If you have set `inline: true`, annotation cannot be disabled.
300
- */
301
- annotation?: string | boolean | ((file: string, root: Root) => string)
302
-
303
- /**
304
- * Override `from` in map’s sources.
305
- */
306
- from?: string
307
-
308
- /**
309
- * Use absolute path in generated source map.
310
- */
311
- absolute?: boolean
312
305
  }
313
306
 
314
307
  export interface ProcessOptions {
@@ -319,20 +312,19 @@ declare namespace postcss {
319
312
  from?: string
320
313
 
321
314
  /**
322
- * The path where you'll put the output CSS file. You should always set `to`
323
- * to generate correct source maps.
315
+ * Source map options
324
316
  */
325
- to?: string
317
+ map?: boolean | SourceMapOptions
326
318
 
327
319
  /**
328
320
  * Function to generate AST by string.
329
321
  */
330
- parser?: Syntax | Parser
322
+ parser?: Parser | Syntax
331
323
 
332
324
  /**
333
325
  * Class to generate string by AST.
334
326
  */
335
- stringifier?: Syntax | Stringifier
327
+ stringifier?: Stringifier | Syntax
336
328
 
337
329
  /**
338
330
  * Object with parse and stringify.
@@ -340,9 +332,10 @@ declare namespace postcss {
340
332
  syntax?: Syntax
341
333
 
342
334
  /**
343
- * Source map options
335
+ * The path where you'll put the output CSS file. You should always set `to`
336
+ * to generate correct source maps.
344
337
  */
345
- map?: SourceMapOptions | boolean
338
+ to?: string
346
339
  }
347
340
 
348
341
  export type Postcss = typeof postcss
@@ -21,35 +21,35 @@ declare namespace PreviousMap {
21
21
  */
22
22
  declare class PreviousMap_ {
23
23
  /**
24
- * Was source map inlined by data-uri to input CSS.
24
+ * `sourceMappingURL` content.
25
25
  */
26
- inline: boolean
26
+ annotation?: string
27
27
 
28
28
  /**
29
- * `sourceMappingURL` content.
29
+ * The CSS source identifier. Contains `Input#file` if the user
30
+ * set the `from` option, or `Input#id` if they did not.
30
31
  */
31
- annotation?: string
32
+ file?: string
32
33
 
33
34
  /**
34
- * Source map file content.
35
+ * Was source map inlined by data-uri to input CSS.
35
36
  */
36
- text?: string
37
+ inline: boolean
37
38
 
38
39
  /**
39
- * The directory with source map file, if source map is in separated file.
40
+ * Path to source map file.
40
41
  */
41
- root?: string
42
+ mapFile?: string
42
43
 
43
44
  /**
44
- * The CSS source identifier. Contains `Input#file` if the user
45
- * set the `from` option, or `Input#id` if they did not.
45
+ * The directory with source map file, if source map is in separated file.
46
46
  */
47
- file?: string
47
+ root?: string
48
48
 
49
49
  /**
50
- * Path to source map file.
50
+ * Source map file content.
51
51
  */
52
- mapFile?: string
52
+ text?: string
53
53
 
54
54
  /**
55
55
  * @param css Input CSS source.
@@ -35,22 +35,37 @@ class PreviousMap {
35
35
  return this.consumerCache
36
36
  }
37
37
 
38
- withContent() {
39
- return !!(
40
- this.consumer().sourcesContent &&
41
- this.consumer().sourcesContent.length > 0
42
- )
43
- }
38
+ decodeInline(text) {
39
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
40
+ let baseUri = /^data:application\/json;base64,/
41
+ let charsetUri = /^data:application\/json;charset=utf-?8,/
42
+ let uri = /^data:application\/json,/
44
43
 
45
- startWith(string, start) {
46
- if (!string) return false
47
- return string.substr(0, start.length) === start
44
+ if (charsetUri.test(text) || uri.test(text)) {
45
+ return decodeURIComponent(text.substr(RegExp.lastMatch.length))
46
+ }
47
+
48
+ if (baseCharsetUri.test(text) || baseUri.test(text)) {
49
+ return fromBase64(text.substr(RegExp.lastMatch.length))
50
+ }
51
+
52
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1]
53
+ throw new Error('Unsupported source map encoding ' + encoding)
48
54
  }
49
55
 
50
56
  getAnnotationURL(sourceMapString) {
51
57
  return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
52
58
  }
53
59
 
60
+ isMap(map) {
61
+ if (typeof map !== 'object') return false
62
+ return (
63
+ typeof map.mappings === 'string' ||
64
+ typeof map._mappings === 'string' ||
65
+ Array.isArray(map.sections)
66
+ )
67
+ }
68
+
54
69
  loadAnnotation(css) {
55
70
  let comments = css.match(/\/\*\s*# sourceMappingURL=/gm)
56
71
  if (!comments) return
@@ -65,24 +80,6 @@ class PreviousMap {
65
80
  }
66
81
  }
67
82
 
68
- decodeInline(text) {
69
- let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
70
- let baseUri = /^data:application\/json;base64,/
71
- let charsetUri = /^data:application\/json;charset=utf-?8,/
72
- let uri = /^data:application\/json,/
73
-
74
- if (charsetUri.test(text) || uri.test(text)) {
75
- return decodeURIComponent(text.substr(RegExp.lastMatch.length))
76
- }
77
-
78
- if (baseCharsetUri.test(text) || baseUri.test(text)) {
79
- return fromBase64(text.substr(RegExp.lastMatch.length))
80
- }
81
-
82
- let encoding = text.match(/data:application\/json;([^,]+),/)[1]
83
- throw new Error('Unsupported source map encoding ' + encoding)
84
- }
85
-
86
83
  loadFile(path) {
87
84
  this.root = dirname(path)
88
85
  if (existsSync(path)) {
@@ -128,12 +125,15 @@ class PreviousMap {
128
125
  }
129
126
  }
130
127
 
131
- isMap(map) {
132
- if (typeof map !== 'object') return false
133
- return (
134
- typeof map.mappings === 'string' ||
135
- typeof map._mappings === 'string' ||
136
- Array.isArray(map.sections)
128
+ startWith(string, start) {
129
+ if (!string) return false
130
+ return string.substr(0, start.length) === start
131
+ }
132
+
133
+ withContent() {
134
+ return !!(
135
+ this.consumer().sourcesContent &&
136
+ this.consumer().sourcesContent.length > 0
137
137
  )
138
138
  }
139
139
  }
@@ -1,14 +1,14 @@
1
+ import LazyResult from './lazy-result.js'
2
+ import NoWorkResult from './no-work-result.js'
1
3
  import {
2
4
  AcceptedPlugin,
3
5
  Plugin,
4
6
  ProcessOptions,
5
- Transformer,
6
- TransformCallback
7
+ TransformCallback,
8
+ Transformer
7
9
  } from './postcss.js'
8
- import LazyResult from './lazy-result.js'
9
10
  import Result from './result.js'
10
11
  import Root from './root.js'
11
- import NoWorkResult from './no-work-result.js'
12
12
 
13
13
  declare namespace Processor {
14
14
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -27,31 +27,55 @@ declare namespace Processor {
27
27
  */
28
28
  declare class Processor_ {
29
29
  /**
30
- * Current PostCSS version.
30
+ * Plugins added to this processor.
31
31
  *
32
32
  * ```js
33
- * if (result.processor.version.split('.')[0] !== '6') {
34
- * throw new Error('This plugin works only with PostCSS 6')
35
- * }
33
+ * const processor = postcss([autoprefixer, postcssNested])
34
+ * processor.plugins.length //=> 2
36
35
  * ```
37
36
  */
38
- version: string
37
+ plugins: (Plugin | TransformCallback | Transformer)[]
39
38
 
40
39
  /**
41
- * Plugins added to this processor.
40
+ * Current PostCSS version.
42
41
  *
43
42
  * ```js
44
- * const processor = postcss([autoprefixer, postcssNested])
45
- * processor.plugins.length //=> 2
43
+ * if (result.processor.version.split('.')[0] !== '6') {
44
+ * throw new Error('This plugin works only with PostCSS 6')
45
+ * }
46
46
  * ```
47
47
  */
48
- plugins: (Plugin | Transformer | TransformCallback)[]
48
+ version: string
49
49
 
50
50
  /**
51
51
  * @param plugins PostCSS plugins
52
52
  */
53
53
  constructor(plugins?: AcceptedPlugin[])
54
54
 
55
+ /**
56
+ * Parses source CSS and returns a `LazyResult` Promise proxy.
57
+ * Because some plugins can be asynchronous it doesn’t make
58
+ * any transformations. Transformations will be applied
59
+ * in the `LazyResult` methods.
60
+ *
61
+ * ```js
62
+ * processor.process(css, { from: 'a.css', to: 'a.out.css' })
63
+ * .then(result => {
64
+ * console.log(result.css)
65
+ * })
66
+ * ```
67
+ *
68
+ * @param css String with input CSS or any object with a `toString()` method,
69
+ * like a Buffer. Optionally, send a `Result` instance
70
+ * and the processor will take the `Root` from it.
71
+ * @param opts Options.
72
+ * @return Promise proxy.
73
+ */
74
+ process(
75
+ css: { toString(): string } | LazyResult | Result | Root | string,
76
+ options?: ProcessOptions
77
+ ): LazyResult | NoWorkResult
78
+
55
79
  /**
56
80
  * Adds a plugin to be used as a CSS processor.
57
81
  *
@@ -80,30 +104,6 @@ declare class Processor_ {
80
104
  * @return Current processor to make methods chain.
81
105
  */
82
106
  use(plugin: AcceptedPlugin): this
83
-
84
- /**
85
- * Parses source CSS and returns a `LazyResult` Promise proxy.
86
- * Because some plugins can be asynchronous it doesn’t make
87
- * any transformations. Transformations will be applied
88
- * in the `LazyResult` methods.
89
- *
90
- * ```js
91
- * processor.process(css, { from: 'a.css', to: 'a.out.css' })
92
- * .then(result => {
93
- * console.log(result.css)
94
- * })
95
- * ```
96
- *
97
- * @param css String with input CSS or any object with a `toString()` method,
98
- * like a Buffer. Optionally, send a `Result` instance
99
- * and the processor will take the `Root` from it.
100
- * @param opts Options.
101
- * @return Promise proxy.
102
- */
103
- process(
104
- css: string | { toString(): string } | Result | LazyResult | Root,
105
- options?: ProcessOptions
106
- ): LazyResult | NoWorkResult
107
107
  }
108
108
 
109
109
  declare class Processor extends Processor_ {}