postcss 8.4.1 → 8.4.4
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/map-generator.js +62 -68
- package/lib/no-work-result.js +3 -2
- package/lib/processor.js +2 -2
- package/package.json +1 -1
package/lib/map-generator.js
CHANGED
@@ -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
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
this.previousMaps.
|
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 (
|
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 if (this.css) {
|
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
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
already[from]
|
92
|
-
|
93
|
-
this.
|
94
|
-
|
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 if (this.css) {
|
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,40 @@ 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.
|
174
|
-
|
175
|
-
if (this.previous().length
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
-
|
192
|
+
this.map = new SourceMapGenerator({ file: this.outputFile() })
|
193
|
+
this.map.addMapping({
|
194
|
+
source: this.opts.from
|
195
|
+
? this.toUrl(this.path(this.opts.from))
|
196
|
+
: '<no source>',
|
197
|
+
generated: { line: 1, column: 0 },
|
198
|
+
original: { line: 1, column: 0 }
|
199
|
+
})
|
193
200
|
}
|
194
201
|
|
195
|
-
this.
|
196
|
-
|
197
|
-
generated: { line: 1, column: 0 },
|
198
|
-
original: { line: 1, column: 0 }
|
199
|
-
})
|
200
|
-
|
202
|
+
if (this.isSourcesContent()) this.setSourcesContent()
|
203
|
+
if (this.root && this.previous().length > 0) this.applyPrevMaps()
|
201
204
|
if (this.isAnnotation()) this.addAnnotation()
|
202
205
|
|
203
206
|
if (this.isInline()) {
|
204
207
|
return [this.css]
|
208
|
+
} else {
|
209
|
+
return [this.css, this.map]
|
205
210
|
}
|
206
|
-
|
207
|
-
return [this.cssString, this.map]
|
208
211
|
}
|
209
212
|
|
210
213
|
path(file) {
|
@@ -224,7 +227,6 @@ class MapGenerator {
|
|
224
227
|
|
225
228
|
toUrl(path) {
|
226
229
|
if (sep === '\\') {
|
227
|
-
/* c8 ignore next 2 */
|
228
230
|
path = path.replace(/\\/g, '/')
|
229
231
|
}
|
230
232
|
return encodeURI(path).replace(/[#?]/g, encodeURIComponent)
|
@@ -237,7 +239,6 @@ class MapGenerator {
|
|
237
239
|
if (pathToFileURL) {
|
238
240
|
return pathToFileURL(node.source.input.from).toString()
|
239
241
|
} else {
|
240
|
-
/* c8 ignore next 4 */
|
241
242
|
throw new Error(
|
242
243
|
'`map.absolute` option is not available in this PostCSS build'
|
243
244
|
)
|
@@ -267,7 +268,6 @@ class MapGenerator {
|
|
267
268
|
|
268
269
|
if (node && type !== 'end') {
|
269
270
|
mapping.generated.line = line
|
270
|
-
/* c8 ignore next */
|
271
271
|
mapping.generated.column = column - 1
|
272
272
|
if (node.source && node.source.start) {
|
273
273
|
mapping.source = this.sourcePath(node)
|
@@ -275,7 +275,6 @@ class MapGenerator {
|
|
275
275
|
mapping.original.column = node.source.start.column - 1
|
276
276
|
this.map.addMapping(mapping)
|
277
277
|
} else {
|
278
|
-
/* c8 ignore next 8 */
|
279
278
|
mapping.source = noSource
|
280
279
|
mapping.original.line = 1
|
281
280
|
mapping.original.column = 0
|
@@ -317,20 +316,15 @@ class MapGenerator {
|
|
317
316
|
|
318
317
|
generate() {
|
319
318
|
this.clearAnnotation()
|
320
|
-
|
321
|
-
if (pathAvailable && sourceMapAvailable && this.isMap() && !this.root) {
|
322
|
-
return this.generateSimpleMap()
|
323
|
-
}
|
324
|
-
|
325
319
|
if (pathAvailable && sourceMapAvailable && this.isMap()) {
|
326
320
|
return this.generateMap()
|
321
|
+
} else {
|
322
|
+
let result = ''
|
323
|
+
this.stringify(this.root, i => {
|
324
|
+
result += i
|
325
|
+
})
|
326
|
+
return [result]
|
327
327
|
}
|
328
|
-
|
329
|
-
let result = ''
|
330
|
-
this.stringify(this.root, i => {
|
331
|
-
result += i
|
332
|
-
})
|
333
|
-
return [result]
|
334
328
|
}
|
335
329
|
}
|
336
330
|
|
package/lib/no-work-result.js
CHANGED
@@ -8,6 +8,7 @@ const Result = require('./result')
|
|
8
8
|
|
9
9
|
class NoWorkResult {
|
10
10
|
constructor(processor, css, opts) {
|
11
|
+
css = css.toString()
|
11
12
|
this.stringified = false
|
12
13
|
|
13
14
|
this._processor = processor
|
@@ -27,8 +28,8 @@ class NoWorkResult {
|
|
27
28
|
}
|
28
29
|
})
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
let map = new MapGenerator(str, root, this._opts, css)
|
32
|
+
if (map.isMap()) {
|
32
33
|
let [generatedCSS, generatedMap] = map.generate()
|
33
34
|
if (generatedCSS) {
|
34
35
|
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.
|
10
|
+
this.version = '8.4.4'
|
11
11
|
this.plugins = this.normalize(plugins)
|
12
12
|
}
|
13
13
|
|