postcss 8.4.1 → 8.4.2

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.

@@ -4,6 +4,8 @@ let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
4
  let { dirname, resolve, relative, sep } = require('path')
5
5
  let { pathToFileURL } = require('url')
6
6
 
7
+ let Input = require('./input')
8
+
7
9
  let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
8
10
  let pathAvailable = Boolean(dirname && resolve && relative && sep)
9
11
 
@@ -26,14 +28,19 @@ class MapGenerator {
26
28
  previous() {
27
29
  if (!this.previousMaps) {
28
30
  this.previousMaps = []
29
- this.root.walk(node => {
30
- if (node.source && node.source.input.map) {
31
- let map = node.source.input.map
32
- if (!this.previousMaps.includes(map)) {
33
- this.previousMaps.push(map)
31
+ if (this.root) {
32
+ this.root.walk(node => {
33
+ if (node.source && node.source.input.map) {
34
+ let map = node.source.input.map
35
+ if (!this.previousMaps.includes(map)) {
36
+ this.previousMaps.push(map)
37
+ }
34
38
  }
35
- }
36
- })
39
+ })
40
+ } else {
41
+ let input = new Input(this.css, this.opts)
42
+ if (input.map) this.previousMaps.push(input.map)
43
+ }
37
44
  }
38
45
 
39
46
  return this.previousMaps
@@ -68,9 +75,7 @@ class MapGenerator {
68
75
  clearAnnotation() {
69
76
  if (this.mapOpts.annotation === false) return
70
77
 
71
- if (!this.root && typeof this.css === 'string') {
72
- this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
73
- } else {
78
+ if (this.root) {
74
79
  let node
75
80
  for (let i = this.root.nodes.length - 1; i >= 0; i--) {
76
81
  node = this.root.nodes[i]
@@ -79,23 +84,32 @@ class MapGenerator {
79
84
  this.root.removeChild(i)
80
85
  }
81
86
  }
87
+ } else {
88
+ this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
82
89
  }
83
90
  }
84
91
 
85
92
  setSourcesContent() {
86
93
  let already = {}
87
- this.root.walk(node => {
88
- if (node.source) {
89
- let from = node.source.input.from
90
- if (from && !already[from]) {
91
- already[from] = true
92
- this.map.setSourceContent(
93
- this.toUrl(this.path(from)),
94
- node.source.input.css
95
- )
94
+ if (this.root) {
95
+ this.root.walk(node => {
96
+ if (node.source) {
97
+ let from = node.source.input.from
98
+ if (from && !already[from]) {
99
+ already[from] = true
100
+ this.map.setSourceContent(
101
+ this.toUrl(this.path(from)),
102
+ node.source.input.css
103
+ )
104
+ }
96
105
  }
97
- }
98
- })
106
+ })
107
+ } else {
108
+ let from = this.opts.from
109
+ ? this.toUrl(this.path(this.opts.from))
110
+ : '<no source>'
111
+ this.map.setSourceContent(from, this.css)
112
+ }
99
113
  }
100
114
 
101
115
  applyPrevMaps() {
@@ -134,7 +148,6 @@ class MapGenerator {
134
148
  if (Buffer) {
135
149
  return Buffer.from(str).toString('base64')
136
150
  } else {
137
- /* c8 ignore next 2 */
138
151
  return window.btoa(unescape(encodeURIComponent(str)))
139
152
  }
140
153
  }
@@ -152,7 +165,6 @@ class MapGenerator {
152
165
  } else {
153
166
  content = this.outputFile() + '.map'
154
167
  }
155
- /* c8 ignore next 6 */
156
168
  let eol = '\n'
157
169
  if (this.css.includes('\r\n')) eol = '\r\n'
158
170
 
@@ -162,49 +174,38 @@ class MapGenerator {
162
174
  outputFile() {
163
175
  if (this.opts.to) {
164
176
  return this.path(this.opts.to)
165
- }
166
- if (this.opts.from) {
177
+ } else if (this.opts.from) {
167
178
  return this.path(this.opts.from)
179
+ } else {
180
+ return 'to.css'
168
181
  }
169
- return 'to.css'
170
182
  }
171
183
 
172
184
  generateMap() {
173
- this.generateString()
174
- if (this.isSourcesContent()) this.setSourcesContent()
175
- if (this.previous().length > 0) this.applyPrevMaps()
176
- if (this.isAnnotation()) this.addAnnotation()
177
-
178
- if (this.isInline()) {
179
- return [this.css]
180
- }
181
- return [this.css, this.map]
182
- }
183
-
184
- generateSimpleMap() {
185
- this.map = new SourceMapGenerator({ file: this.outputFile() })
186
- this.previousMaps = []
187
-
188
- let source
189
- if (this.opts.from) {
190
- source = this.toUrl(this.opts.from)
185
+ if (this.root) {
186
+ this.generateString()
187
+ } else if (this.previous().length === 1) {
188
+ let prev = this.previous()[0].consumer()
189
+ prev.file = this.outputFile()
190
+ this.map = SourceMapGenerator.fromSourceMap(prev)
191
191
  } else {
192
- source = '<no source>'
192
+ this.map = new SourceMapGenerator({ file: this.outputFile() })
193
+ this.map.addMapping({
194
+ source: this.opts.from ? this.toUrl(this.opts.from) : '<no source>',
195
+ generated: { line: 1, column: 0 },
196
+ original: { line: 1, column: 0 }
197
+ })
193
198
  }
194
199
 
195
- this.map.addMapping({
196
- source,
197
- generated: { line: 1, column: 0 },
198
- original: { line: 1, column: 0 }
199
- })
200
-
200
+ if (this.isSourcesContent()) this.setSourcesContent()
201
+ if (this.root && this.previous().length > 0) this.applyPrevMaps()
201
202
  if (this.isAnnotation()) this.addAnnotation()
202
203
 
203
204
  if (this.isInline()) {
204
205
  return [this.css]
206
+ } else {
207
+ return [this.css, this.map]
205
208
  }
206
-
207
- return [this.cssString, this.map]
208
209
  }
209
210
 
210
211
  path(file) {
@@ -224,7 +225,6 @@ class MapGenerator {
224
225
 
225
226
  toUrl(path) {
226
227
  if (sep === '\\') {
227
- /* c8 ignore next 2 */
228
228
  path = path.replace(/\\/g, '/')
229
229
  }
230
230
  return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
@@ -237,7 +237,6 @@ class MapGenerator {
237
237
  if (pathToFileURL) {
238
238
  return pathToFileURL(node.source.input.from).toString()
239
239
  } else {
240
- /* c8 ignore next 4 */
241
240
  throw new Error(
242
241
  '`map.absolute` option is not available in this PostCSS build'
243
242
  )
@@ -267,7 +266,6 @@ class MapGenerator {
267
266
 
268
267
  if (node && type !== 'end') {
269
268
  mapping.generated.line = line
270
- /* c8 ignore next */
271
269
  mapping.generated.column = column - 1
272
270
  if (node.source && node.source.start) {
273
271
  mapping.source = this.sourcePath(node)
@@ -275,7 +273,6 @@ class MapGenerator {
275
273
  mapping.original.column = node.source.start.column - 1
276
274
  this.map.addMapping(mapping)
277
275
  } else {
278
- /* c8 ignore next 8 */
279
276
  mapping.source = noSource
280
277
  mapping.original.line = 1
281
278
  mapping.original.column = 0
@@ -317,20 +314,15 @@ class MapGenerator {
317
314
 
318
315
  generate() {
319
316
  this.clearAnnotation()
320
-
321
- if (pathAvailable && sourceMapAvailable && this.isMap() && !this.root) {
322
- return this.generateSimpleMap()
323
- }
324
-
325
317
  if (pathAvailable && sourceMapAvailable && this.isMap()) {
326
318
  return this.generateMap()
319
+ } else {
320
+ let result = ''
321
+ this.stringify(this.root, i => {
322
+ result += i
323
+ })
324
+ return [result]
327
325
  }
328
-
329
- let result = ''
330
- this.stringify(this.root, i => {
331
- result += i
332
- })
333
- return [result]
334
326
  }
335
327
  }
336
328
 
@@ -27,8 +27,8 @@ class NoWorkResult {
27
27
  }
28
28
  })
29
29
 
30
- if (this._opts.map) {
31
- let map = new MapGenerator(str, root, this._opts, css)
30
+ let map = new MapGenerator(str, root, this._opts, css)
31
+ if (map.isMap()) {
32
32
  let [generatedCSS, generatedMap] = map.generate()
33
33
  if (generatedCSS) {
34
34
  this.result.css = generatedCSS
package/lib/processor.js CHANGED
@@ -1,13 +1,13 @@
1
1
  'use strict'
2
2
 
3
+ let NoWorkResult = require('./no-work-result')
3
4
  let LazyResult = require('./lazy-result')
4
5
  let Document = require('./document')
5
6
  let Root = require('./root')
6
- let NoWorkResult = require('./no-work-result')
7
7
 
8
8
  class Processor {
9
9
  constructor(plugins = []) {
10
- this.version = '8.4.1'
10
+ this.version = '8.4.2'
11
11
  this.plugins = this.normalize(plugins)
12
12
  }
13
13
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss",
3
- "version": "8.4.1",
3
+ "version": "8.4.2",
4
4
  "description": "Tool for transforming styles with JS plugins",
5
5
  "engines": {
6
6
  "node": "^10 || ^12 || >=14"