Skip to content

Commit

Permalink
fix: do not crash if pkg.(d|devD)ependencies unset (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Dec 11, 2023
1 parent 84f16be commit 8ef0c7e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ export default async function loader(content, sourceMap, meta) {
}

if (pkg) {
if (!pkg.dependencies.postcss && !pkg.devDependencies.postcss) {
const { dependencies = {}, devDependencies = {} } = pkg;

if (!dependencies.postcss && !devDependencies.postcss) {
this.emitWarning(
new Error(
"Add postcss as project dependency. postcss is not a peer dependency for postcss-loader. " +
Expand Down
5 changes: 1 addition & 4 deletions test/fixtures/package-json-files/no-postcss/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
{
"dependencies": {},
"devDependencies": {}
}
{}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"postcss": "^8.0.0"
},
"devDependencies": {}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {},
"devDependencies": {
"postcss": "^8.0.0"
}
}
}

0 comments on commit 8ef0c7e

Please sign in to comment.