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.

@@ -1,7 +1,7 @@
1
1
  'use strict'
2
2
 
3
3
  let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
- let { dirname, resolve, relative, sep } = require('path')
4
+ let { dirname, relative, resolve, sep } = require('path')
5
5
  let { pathToFileURL } = require('url')
6
6
 
7
7
  let Input = require('./input')
@@ -19,98 +19,23 @@ class MapGenerator {
19
19
  this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
20
20
  }
21
21
 
22
- isMap() {
23
- if (typeof this.opts.map !== 'undefined') {
24
- return !!this.opts.map
25
- }
26
- return this.previous().length > 0
27
- }
28
-
29
- previous() {
30
- if (!this.previousMaps) {
31
- this.previousMaps = []
32
- if (this.root) {
33
- this.root.walk(node => {
34
- if (node.source && node.source.input.map) {
35
- let map = node.source.input.map
36
- if (!this.previousMaps.includes(map)) {
37
- this.previousMaps.push(map)
38
- }
39
- }
40
- })
41
- } else {
42
- let input = new Input(this.css, this.opts)
43
- if (input.map) this.previousMaps.push(input.map)
44
- }
45
- }
46
-
47
- return this.previousMaps
48
- }
49
-
50
- isInline() {
51
- if (typeof this.mapOpts.inline !== 'undefined') {
52
- return this.mapOpts.inline
53
- }
54
-
55
- let annotation = this.mapOpts.annotation
56
- if (typeof annotation !== 'undefined' && annotation !== true) {
57
- return false
58
- }
59
-
60
- if (this.previous().length) {
61
- return this.previous().some(i => i.inline)
62
- }
63
- return true
64
- }
65
-
66
- isSourcesContent() {
67
- if (typeof this.mapOpts.sourcesContent !== 'undefined') {
68
- return this.mapOpts.sourcesContent
69
- }
70
- if (this.previous().length) {
71
- return this.previous().some(i => i.withContent())
72
- }
73
- return true
74
- }
75
-
76
- clearAnnotation() {
77
- if (this.mapOpts.annotation === false) return
22
+ addAnnotation() {
23
+ let content
78
24
 
79
- if (this.root) {
80
- let node
81
- for (let i = this.root.nodes.length - 1; i >= 0; i--) {
82
- node = this.root.nodes[i]
83
- if (node.type !== 'comment') continue
84
- if (node.text.indexOf('# sourceMappingURL=') === 0) {
85
- this.root.removeChild(i)
86
- }
87
- }
88
- } else if (this.css) {
89
- this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
25
+ if (this.isInline()) {
26
+ content =
27
+ 'data:application/json;base64,' + this.toBase64(this.map.toString())
28
+ } else if (typeof this.mapOpts.annotation === 'string') {
29
+ content = this.mapOpts.annotation
30
+ } else if (typeof this.mapOpts.annotation === 'function') {
31
+ content = this.mapOpts.annotation(this.opts.to, this.root)
32
+ } else {
33
+ content = this.outputFile() + '.map'
90
34
  }
91
- }
35
+ let eol = '\n'
36
+ if (this.css.includes('\r\n')) eol = '\r\n'
92
37
 
93
- setSourcesContent() {
94
- let already = {}
95
- if (this.root) {
96
- this.root.walk(node => {
97
- if (node.source) {
98
- let from = node.source.input.from
99
- if (from && !already[from]) {
100
- already[from] = true
101
- let fromUrl = this.usesFileUrls
102
- ? this.toFileUrl(from)
103
- : this.toUrl(this.path(from))
104
- this.map.setSourceContent(fromUrl, node.source.input.css)
105
- }
106
- }
107
- })
108
- } else if (this.css) {
109
- let from = this.opts.from
110
- ? this.toUrl(this.path(this.opts.from))
111
- : '<no source>'
112
- this.map.setSourceContent(from, this.css)
113
- }
38
+ this.css += eol + '/*# sourceMappingURL=' + content + ' */'
114
39
  }
115
40
 
116
41
  applyPrevMaps() {
@@ -132,53 +57,33 @@ class MapGenerator {
132
57
  }
133
58
  }
134
59
 
135
- isAnnotation() {
136
- if (this.isInline()) {
137
- return true
138
- }
139
- if (typeof this.mapOpts.annotation !== 'undefined') {
140
- return this.mapOpts.annotation
141
- }
142
- if (this.previous().length) {
143
- return this.previous().some(i => i.annotation)
144
- }
145
- return true
146
- }
147
-
148
- toBase64(str) {
149
- if (Buffer) {
150
- return Buffer.from(str).toString('base64')
151
- } else {
152
- return window.btoa(unescape(encodeURIComponent(str)))
153
- }
154
- }
155
-
156
- addAnnotation() {
157
- let content
60
+ clearAnnotation() {
61
+ if (this.mapOpts.annotation === false) return
158
62
 
159
- if (this.isInline()) {
160
- content =
161
- 'data:application/json;base64,' + this.toBase64(this.map.toString())
162
- } else if (typeof this.mapOpts.annotation === 'string') {
163
- content = this.mapOpts.annotation
164
- } else if (typeof this.mapOpts.annotation === 'function') {
165
- content = this.mapOpts.annotation(this.opts.to, this.root)
166
- } else {
167
- content = this.outputFile() + '.map'
63
+ if (this.root) {
64
+ let node
65
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
66
+ node = this.root.nodes[i]
67
+ if (node.type !== 'comment') continue
68
+ if (node.text.indexOf('# sourceMappingURL=') === 0) {
69
+ this.root.removeChild(i)
70
+ }
71
+ }
72
+ } else if (this.css) {
73
+ this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
168
74
  }
169
- let eol = '\n'
170
- if (this.css.includes('\r\n')) eol = '\r\n'
171
-
172
- this.css += eol + '/*# sourceMappingURL=' + content + ' */'
173
75
  }
174
76
 
175
- outputFile() {
176
- if (this.opts.to) {
177
- return this.path(this.opts.to)
178
- } else if (this.opts.from) {
179
- return this.path(this.opts.from)
77
+ generate() {
78
+ this.clearAnnotation()
79
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
80
+ return this.generateMap()
180
81
  } else {
181
- return 'to.css'
82
+ let result = ''
83
+ this.stringify(this.root, i => {
84
+ result += i
85
+ })
86
+ return [result]
182
87
  }
183
88
  }
184
89
 
@@ -192,11 +97,11 @@ class MapGenerator {
192
97
  } else {
193
98
  this.map = new SourceMapGenerator({ file: this.outputFile() })
194
99
  this.map.addMapping({
100
+ generated: { column: 0, line: 1 },
101
+ original: { column: 0, line: 1 },
195
102
  source: this.opts.from
196
103
  ? this.toUrl(this.path(this.opts.from))
197
- : '<no source>',
198
- generated: { line: 1, column: 0 },
199
- original: { line: 1, column: 0 }
104
+ : '<no source>'
200
105
  })
201
106
  }
202
107
 
@@ -211,48 +116,6 @@ class MapGenerator {
211
116
  }
212
117
  }
213
118
 
214
- path(file) {
215
- if (file.indexOf('<') === 0) return file
216
- if (/^\w+:\/\//.test(file)) return file
217
- if (this.mapOpts.absolute) return file
218
-
219
- let from = this.opts.to ? dirname(this.opts.to) : '.'
220
-
221
- if (typeof this.mapOpts.annotation === 'string') {
222
- from = dirname(resolve(from, this.mapOpts.annotation))
223
- }
224
-
225
- file = relative(from, file)
226
- return file
227
- }
228
-
229
- toUrl(path) {
230
- if (sep === '\\') {
231
- path = path.replace(/\\/g, '/')
232
- }
233
- return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
234
- }
235
-
236
- toFileUrl(path) {
237
- if (pathToFileURL) {
238
- return pathToFileURL(path).toString()
239
- } else {
240
- throw new Error(
241
- '`map.absolute` option is not available in this PostCSS build'
242
- )
243
- }
244
- }
245
-
246
- sourcePath(node) {
247
- if (this.mapOpts.from) {
248
- return this.toUrl(this.mapOpts.from)
249
- } else if (this.usesFileUrls) {
250
- return this.toFileUrl(node.source.input.from)
251
- } else {
252
- return this.toUrl(this.path(node.source.input.from))
253
- }
254
- }
255
-
256
119
  generateString() {
257
120
  this.css = ''
258
121
  this.map = new SourceMapGenerator({ file: this.outputFile() })
@@ -262,9 +125,9 @@ class MapGenerator {
262
125
 
263
126
  let noSource = '<no source>'
264
127
  let mapping = {
265
- source: '',
266
- generated: { line: 0, column: 0 },
267
- original: { line: 0, column: 0 }
128
+ generated: { column: 0, line: 0 },
129
+ original: { column: 0, line: 0 },
130
+ source: ''
268
131
  }
269
132
 
270
133
  let lines, last
@@ -321,18 +184,155 @@ class MapGenerator {
321
184
  })
322
185
  }
323
186
 
324
- generate() {
325
- this.clearAnnotation()
326
- if (pathAvailable && sourceMapAvailable && this.isMap()) {
327
- return this.generateMap()
187
+ isAnnotation() {
188
+ if (this.isInline()) {
189
+ return true
190
+ }
191
+ if (typeof this.mapOpts.annotation !== 'undefined') {
192
+ return this.mapOpts.annotation
193
+ }
194
+ if (this.previous().length) {
195
+ return this.previous().some(i => i.annotation)
196
+ }
197
+ return true
198
+ }
199
+
200
+ isInline() {
201
+ if (typeof this.mapOpts.inline !== 'undefined') {
202
+ return this.mapOpts.inline
203
+ }
204
+
205
+ let annotation = this.mapOpts.annotation
206
+ if (typeof annotation !== 'undefined' && annotation !== true) {
207
+ return false
208
+ }
209
+
210
+ if (this.previous().length) {
211
+ return this.previous().some(i => i.inline)
212
+ }
213
+ return true
214
+ }
215
+
216
+ isMap() {
217
+ if (typeof this.opts.map !== 'undefined') {
218
+ return !!this.opts.map
219
+ }
220
+ return this.previous().length > 0
221
+ }
222
+
223
+ isSourcesContent() {
224
+ if (typeof this.mapOpts.sourcesContent !== 'undefined') {
225
+ return this.mapOpts.sourcesContent
226
+ }
227
+ if (this.previous().length) {
228
+ return this.previous().some(i => i.withContent())
229
+ }
230
+ return true
231
+ }
232
+
233
+ outputFile() {
234
+ if (this.opts.to) {
235
+ return this.path(this.opts.to)
236
+ } else if (this.opts.from) {
237
+ return this.path(this.opts.from)
328
238
  } else {
329
- let result = ''
330
- this.stringify(this.root, i => {
331
- result += i
239
+ return 'to.css'
240
+ }
241
+ }
242
+
243
+ path(file) {
244
+ if (file.indexOf('<') === 0) return file
245
+ if (/^\w+:\/\//.test(file)) return file
246
+ if (this.mapOpts.absolute) return file
247
+
248
+ let from = this.opts.to ? dirname(this.opts.to) : '.'
249
+
250
+ if (typeof this.mapOpts.annotation === 'string') {
251
+ from = dirname(resolve(from, this.mapOpts.annotation))
252
+ }
253
+
254
+ file = relative(from, file)
255
+ return file
256
+ }
257
+
258
+ previous() {
259
+ if (!this.previousMaps) {
260
+ this.previousMaps = []
261
+ if (this.root) {
262
+ this.root.walk(node => {
263
+ if (node.source && node.source.input.map) {
264
+ let map = node.source.input.map
265
+ if (!this.previousMaps.includes(map)) {
266
+ this.previousMaps.push(map)
267
+ }
268
+ }
269
+ })
270
+ } else {
271
+ let input = new Input(this.css, this.opts)
272
+ if (input.map) this.previousMaps.push(input.map)
273
+ }
274
+ }
275
+
276
+ return this.previousMaps
277
+ }
278
+
279
+ setSourcesContent() {
280
+ let already = {}
281
+ if (this.root) {
282
+ this.root.walk(node => {
283
+ if (node.source) {
284
+ let from = node.source.input.from
285
+ if (from && !already[from]) {
286
+ already[from] = true
287
+ let fromUrl = this.usesFileUrls
288
+ ? this.toFileUrl(from)
289
+ : this.toUrl(this.path(from))
290
+ this.map.setSourceContent(fromUrl, node.source.input.css)
291
+ }
292
+ }
332
293
  })
333
- return [result]
294
+ } else if (this.css) {
295
+ let from = this.opts.from
296
+ ? this.toUrl(this.path(this.opts.from))
297
+ : '<no source>'
298
+ this.map.setSourceContent(from, this.css)
334
299
  }
335
300
  }
301
+
302
+ sourcePath(node) {
303
+ if (this.mapOpts.from) {
304
+ return this.toUrl(this.mapOpts.from)
305
+ } else if (this.usesFileUrls) {
306
+ return this.toFileUrl(node.source.input.from)
307
+ } else {
308
+ return this.toUrl(this.path(node.source.input.from))
309
+ }
310
+ }
311
+
312
+ toBase64(str) {
313
+ if (Buffer) {
314
+ return Buffer.from(str).toString('base64')
315
+ } else {
316
+ return window.btoa(unescape(encodeURIComponent(str)))
317
+ }
318
+ }
319
+
320
+ toFileUrl(path) {
321
+ if (pathToFileURL) {
322
+ return pathToFileURL(path).toString()
323
+ } else {
324
+ throw new Error(
325
+ '`map.absolute` option is not available in this PostCSS build'
326
+ )
327
+ }
328
+ }
329
+
330
+ toUrl(path) {
331
+ if (sep === '\\') {
332
+ path = path.replace(/\\/g, '/')
333
+ }
334
+ return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
335
+ }
336
336
  }
337
337
 
338
338
  module.exports = MapGenerator
@@ -1,9 +1,9 @@
1
- import Result, { Message, ResultOptions } from './result.js'
1
+ import LazyResult from './lazy-result.js'
2
2
  import { SourceMap } from './postcss.js'
3
3
  import Processor from './processor.js'
4
- import Warning from './warning.js'
4
+ import Result, { Message, ResultOptions } from './result.js'
5
5
  import Root from './root.js'
6
- import LazyResult from './lazy-result.js'
6
+ import Warning from './warning.js'
7
7
 
8
8
  declare namespace NoWorkResult {
9
9
  // eslint-disable-next-line @typescript-eslint/no-use-before-define
@@ -23,22 +23,22 @@ declare namespace NoWorkResult {
23
23
  * ```
24
24
  */
25
25
  declare class NoWorkResult_ implements LazyResult {
26
- then: Promise<Result>['then']
27
26
  catch: Promise<Result>['catch']
28
27
  finally: Promise<Result>['finally']
28
+ then: Promise<Result>['then']
29
29
  constructor(processor: Processor, css: string, opts: ResultOptions)
30
- get [Symbol.toStringTag](): string
31
- get processor(): Processor
32
- get opts(): ResultOptions
33
- get css(): string
30
+ async(): Promise<Result>
34
31
  get content(): string
32
+ get css(): string
35
33
  get map(): SourceMap
36
- get root(): Root
37
34
  get messages(): Message[]
38
- warnings(): Warning[]
39
- toString(): string
35
+ get opts(): ResultOptions
36
+ get processor(): Processor
37
+ get root(): Root
38
+ get [Symbol.toStringTag](): string
40
39
  sync(): Result
41
- async(): Promise<Result>
40
+ toString(): string
41
+ warnings(): Warning[]
42
42
  }
43
43
 
44
44
  declare class NoWorkResult extends NoWorkResult_ {}
@@ -40,30 +40,43 @@ class NoWorkResult {
40
40
  }
41
41
  }
42
42
 
43
- get [Symbol.toStringTag]() {
44
- return 'NoWorkResult'
43
+ async() {
44
+ if (this.error) return Promise.reject(this.error)
45
+ return Promise.resolve(this.result)
45
46
  }
46
47
 
47
- get processor() {
48
- return this.result.processor
48
+ catch(onRejected) {
49
+ return this.async().catch(onRejected)
49
50
  }
50
51
 
51
- get opts() {
52
- return this.result.opts
52
+ get content() {
53
+ return this.result.css
53
54
  }
54
55
 
55
56
  get css() {
56
57
  return this.result.css
57
58
  }
58
59
 
59
- get content() {
60
- return this.result.css
60
+ finally(onFinally) {
61
+ return this.async().then(onFinally, onFinally)
61
62
  }
62
63
 
63
64
  get map() {
64
65
  return this.result.map
65
66
  }
66
67
 
68
+ get messages() {
69
+ return []
70
+ }
71
+
72
+ get opts() {
73
+ return this.result.opts
74
+ }
75
+
76
+ get processor() {
77
+ return this.result.processor
78
+ }
79
+
67
80
  get root() {
68
81
  if (this._root) {
69
82
  return this._root
@@ -86,16 +99,13 @@ class NoWorkResult {
86
99
  }
87
100
  }
88
101
 
89
- get messages() {
90
- return []
91
- }
92
-
93
- warnings() {
94
- return []
102
+ get [Symbol.toStringTag]() {
103
+ return 'NoWorkResult'
95
104
  }
96
105
 
97
- toString() {
98
- return this._css
106
+ sync() {
107
+ if (this.error) throw this.error
108
+ return this.result
99
109
  }
100
110
 
101
111
  then(onFulfilled, onRejected) {
@@ -112,22 +122,12 @@ class NoWorkResult {
112
122
  return this.async().then(onFulfilled, onRejected)
113
123
  }
114
124
 
115
- catch(onRejected) {
116
- return this.async().catch(onRejected)
117
- }
118
-
119
- finally(onFinally) {
120
- return this.async().then(onFinally, onFinally)
121
- }
122
-
123
- async() {
124
- if (this.error) return Promise.reject(this.error)
125
- return Promise.resolve(this.result)
125
+ toString() {
126
+ return this._css
126
127
  }
127
128
 
128
- sync() {
129
- if (this.error) throw this.error
130
- return this.result
129
+ warnings() {
130
+ return []
131
131
  }
132
132
  }
133
133