Skip to content

Commit

Permalink
Merge pull request #1553 from barak007/patch-2
Browse files Browse the repository at this point in the history
Fix browser bundling with webpack 5
  • Loading branch information
ai committed Apr 11, 2021
2 parents 8682b1e + 7c2e97a commit 4bcd727
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
11 changes: 9 additions & 2 deletions lib/input.js
Expand Up @@ -130,7 +130,9 @@ class Input {

result.input = { line, column, source: this.css }
if (this.file) {
result.input.url = pathToFileURL(this.file).toString()
if (pathToFileURL) {
result.input.url = pathToFileURL(this.file).toString()
}
result.input.file = this.file
}

Expand Down Expand Up @@ -162,7 +164,12 @@ class Input {
}

if (fromUrl.protocol === 'file:') {
result.file = fileURLToPath(fromUrl)
if (fileURLToPath) {
result.file = fileURLToPath(fromUrl)
} else {
// istanbul ignore next
throw new Error(`file: protocol is not available in this PostCSS build`);
}
}

let source = consumer.sourceContentFor(from.source)
Expand Down
9 changes: 7 additions & 2 deletions lib/map-generator.js
Expand Up @@ -4,7 +4,7 @@ let { dirname, resolve, relative, sep } = require('path')
let { pathToFileURL } = require('url')
let mozilla = require('source-map')

let pathAvailable = Boolean(dirname, resolve, relative, sep)
let pathAvailable = Boolean(dirname && resolve && relative && sep)

class MapGenerator {
constructor(stringify, root, opts) {
Expand Down Expand Up @@ -202,7 +202,12 @@ class MapGenerator {
if (this.mapOpts.from) {
return this.toUrl(this.mapOpts.from)
} else if (this.mapOpts.absolute) {
return pathToFileURL(node.source.input.from).toString()
if (pathToFileURL) {
return pathToFileURL(node.source.input.from).toString()
} else {
// istanbul ignore next
throw new Error('`map.absolute` option is not available in this PostCSS build')
}
} else {
return this.toUrl(this.path(node.source.input.from))
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -103,7 +103,8 @@
"./lib/terminal-highlight": false,
"colorette": false,
"fs": false,
"path": false
"path": false,
"url": false
},
"size-limit": [
{
Expand Down

0 comments on commit 4bcd727

Please sign in to comment.