diff --git a/package-lock.json b/package-lock.json index 65331afb..498b63a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1586,13 +1586,13 @@ } }, "@jest/core": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/core/-/core-26.3.0.tgz", - "integrity": "sha512-WAAqGMpc+U+GS0oSr/ikI1JdRyPQyTZSVOr1xjnVcfvfUTZCK+wGoN0Cb7dm7HVdpbMQr/NvtM6vBVChctmzHA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/core/-/core-26.4.0.tgz", + "integrity": "sha512-mpXm4OjWQbz7qbzGIiSqvfNZ1FxX6ywWgLtdSD2luPORt5zKPtqcdDnX7L8RdfMaj1znDBgN2+gB094ZIr7vnA==", "dev": true, "requires": { "@jest/console": "^26.3.0", - "@jest/reporters": "^26.3.0", + "@jest/reporters": "^26.4.0", "@jest/test-result": "^26.3.0", "@jest/transform": "^26.3.0", "@jest/types": "^26.3.0", @@ -1602,17 +1602,17 @@ "exit": "^0.1.2", "graceful-fs": "^4.2.4", "jest-changed-files": "^26.3.0", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-haste-map": "^26.3.0", "jest-message-util": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", - "jest-resolve-dependencies": "^26.3.0", - "jest-runner": "^26.3.0", - "jest-runtime": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-resolve-dependencies": "^26.4.0", + "jest-runner": "^26.4.0", + "jest-runtime": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "jest-watcher": "^26.3.0", "micromatch": "^4.0.2", "p-each-series": "^2.1.0", @@ -1749,20 +1749,20 @@ } }, "@jest/globals": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-26.3.0.tgz", - "integrity": "sha512-oPe30VG9zor2U3Ev7khCM2LkjO3D+mgAv6s5D3Ed0sxfELxoRZwR8d1VgYWVQljcpumMwe9tDrKNuzgVjbEt7g==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-26.4.0.tgz", + "integrity": "sha512-QKwoVAeL9d0xaEM9ebPvfc+bolN04F+o3zM2jswGDBiiNjCogZ3LvOaqumRdDyz6kLmbx+UhgMBAVuLunbXZ2A==", "dev": true, "requires": { "@jest/environment": "^26.3.0", "@jest/types": "^26.3.0", - "expect": "^26.3.0" + "expect": "^26.4.0" } }, "@jest/reporters": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-26.3.0.tgz", - "integrity": "sha512-MfLJOUPxhGb3sRT/wFjHXd6gyVQ1Fb1XxbEwY+gqdDBpg3pq5qAB5eiBUvcTheFRHmhu3gOv3UZ/gtxmqGBA+Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/reporters/-/reporters-26.4.0.tgz", + "integrity": "sha512-14OPAAuYhgRBSNxAocVluX6ksdMdK/EuP9NmtBXU9g1uKaVBrPnohn/CVm6iMot1a9iU8BCxa5715YRf8FEg/A==", "dev": true, "requires": { "@bcoe/v8-coverage": "^0.2.3", @@ -1781,7 +1781,7 @@ "istanbul-lib-source-maps": "^4.0.0", "istanbul-reports": "^3.0.2", "jest-haste-map": "^26.3.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "jest-util": "^26.3.0", "jest-worker": "^26.3.0", "node-notifier": "^7.0.0", @@ -1874,16 +1874,16 @@ } }, "@jest/test-sequencer": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-26.3.0.tgz", - "integrity": "sha512-G7TA0Z85uj5l1m9UKZ/nXbArn0y+MeLKbojNLDHgjb1PpNNFDAOO6FJhk9We34m/hadcciMcJFnxV94dV2TX+w==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/@jest/test-sequencer/-/test-sequencer-26.4.0.tgz", + "integrity": "sha512-9Z7lCShS7vERp+DRwIVNH/6sHMWwJK1DPnGCpGeVLGJJWJ4Y08sQI3vIKdmKHu2KmwlUBpRM+BFf7NlVUkl5XA==", "dev": true, "requires": { "@jest/test-result": "^26.3.0", "graceful-fs": "^4.2.4", "jest-haste-map": "^26.3.0", - "jest-runner": "^26.3.0", - "jest-runtime": "^26.3.0" + "jest-runner": "^26.4.0", + "jest-runtime": "^26.4.0" } }, "@jest/transform": { @@ -2875,9 +2875,9 @@ "dev": true }, "aws4": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.0.tgz", - "integrity": "sha512-3YDiu347mtVtjpyV3u5kVqQLP242c06zwDOgpeRnybmXlYYsLbtTrUBUm8i8srONt+FWobl5aibnU1030PeeuA==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz", + "integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==", "dev": true }, "babel-code-frame": { @@ -4156,19 +4156,19 @@ } }, "conventional-changelog-core": { - "version": "4.1.7", - "resolved": "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-4.1.7.tgz", - "integrity": "sha512-UBvSrQR2RdKbSQKh7RhueiiY4ZAIOW3+CSWdtKOwRv+KxIMNFKm1rOcGBFx0eA8AKhGkkmmacoTWJTqyz7Q0VA==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-4.2.0.tgz", + "integrity": "sha512-8+xMvN6JvdDtPbGBqA7oRNyZD4od1h/SIzrWqHcKZjitbVXrFpozEeyn4iI4af1UwdrabQpiZMaV07fPUTGd4w==", "dev": true, "requires": { "add-stream": "^1.0.0", - "conventional-changelog-writer": "^4.0.16", + "conventional-changelog-writer": "^4.0.17", "conventional-commits-parser": "^3.1.0", "dateformat": "^3.0.0", "get-pkg-repo": "^1.0.0", "git-raw-commits": "2.0.0", "git-remote-origin-url": "^2.0.0", - "git-semver-tags": "^4.0.0", + "git-semver-tags": "^4.1.0", "lodash": "^4.17.15", "normalize-package-data": "^2.3.5", "q": "^1.5.1", @@ -5856,9 +5856,9 @@ } }, "electron-to-chromium": { - "version": "1.3.529", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.529.tgz", - "integrity": "sha512-n3sriLldqNyjBlosbnPftjCY+m1dVOY307I1Y0HaHAqDGe3hRvK7ksJwWd+qs599ybR4jobCo1+7zXM9GyNMSA==", + "version": "1.3.533", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.533.tgz", + "integrity": "sha512-YqAL+NXOzjBnpY+dcOKDlZybJDCOzgsq4koW3fvyty/ldTmsb4QazZpOWmVvZ2m0t5jbBf7L0lIGU3BUipwG+A==", "dev": true }, "elliptic": { @@ -6699,15 +6699,15 @@ } }, "expect": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-26.3.0.tgz", - "integrity": "sha512-3tC0dpPgkTGkycM9H+mMjzIhm8I3ZAOV+y1Cj3xmF9iKxDeHBCAB64hf1OY//bMzQ/AftfodNy2pQWMKpTIV8Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-26.4.0.tgz", + "integrity": "sha512-dbYDJhFcqQsamlos6nEwAMe+ahdckJBk5fmw1DYGLQGabGSlUuT+Fm2jHYw5119zG3uIhP+lCQbjJhFEdZMJtg==", "dev": true, "requires": { "@jest/types": "^26.3.0", "ansi-styles": "^4.0.0", "jest-get-type": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", "jest-regex-util": "^26.0.0" }, @@ -7599,9 +7599,9 @@ } }, "git-semver-tags": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/git-semver-tags/-/git-semver-tags-4.0.0.tgz", - "integrity": "sha512-LajaAWLYVBff+1NVircURJFL8TQ3EMIcLAfHisWYX/nPoMwnTYfWAznQDmMujlLqoD12VtLmoSrF1sQ5MhimEQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/git-semver-tags/-/git-semver-tags-4.1.0.tgz", + "integrity": "sha512-TcxAGeo03HdErzKzi4fDD+xEL7gi8r2Y5YSxH6N2XYdVSV5UkBwfrt7Gqo1b+uSHCjy/sa9Y6BBBxxFLxfbhTg==", "dev": true, "requires": { "meow": "^7.0.0", @@ -8092,14 +8092,6 @@ "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", "dev": true }, - "import-cwd": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-3.0.0.tgz", - "integrity": "sha512-4pnzH16plW+hgvRECbDWpQl3cqtvSofHWh44met7ESfZ8UZOWWddm8hEyDTqREJ9RbYHY8gi8DqmaelApoOGMg==", - "requires": { - "import-from": "^3.0.0" - } - }, "import-fresh": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", @@ -8109,21 +8101,6 @@ "resolve-from": "^4.0.0" } }, - "import-from": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/import-from/-/import-from-3.0.0.tgz", - "integrity": "sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ==", - "requires": { - "resolve-from": "^5.0.0" - }, - "dependencies": { - "resolve-from": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", - "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==" - } - } - }, "import-local": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/import-local/-/import-local-3.0.2.tgz", @@ -8760,14 +8737,14 @@ } }, "jest": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest/-/jest-26.3.0.tgz", - "integrity": "sha512-LFCry7NS6bTa4BUGUHC+NvZ3B9WG7Jv8F+Lb96dAJFM23LMwSsL5RiJcw9S+nejsh8lS1VxHq+RSH4Xa9tujpA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest/-/jest-26.4.0.tgz", + "integrity": "sha512-lNCOS+ckRHE1wFyVtQClBmbsOVuH2GWUTJMDL3vunp9DXcah+V8vfvVVApngClcdoc3rgZpqOfCNKLjxjj2l4g==", "dev": true, "requires": { - "@jest/core": "^26.3.0", + "@jest/core": "^26.4.0", "import-local": "^3.0.2", - "jest-cli": "^26.3.0" + "jest-cli": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -8812,12 +8789,12 @@ "dev": true }, "jest-cli": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-26.3.0.tgz", - "integrity": "sha512-vrlDluEjnNTJNpmw+lJ1Dvjhc+2o7QG0dG8n+iDu3NaoQ9OzqNeZsZZ0a9KP7SdtD5BXgvGSpCWTlLH5SqtxcA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-cli/-/jest-cli-26.4.0.tgz", + "integrity": "sha512-kw2Pr3V2x9/WzSDGsbz/MJBNlCoPMxMudrIavft4bqRlv5tASjU51tyO+1Os1LdW2dAnLQZYsxFUZ8oWPyssGQ==", "dev": true, "requires": { - "@jest/core": "^26.3.0", + "@jest/core": "^26.4.0", "@jest/test-result": "^26.3.0", "@jest/types": "^26.3.0", "chalk": "^4.0.0", @@ -8825,9 +8802,9 @@ "graceful-fs": "^4.2.4", "import-local": "^3.0.2", "is-ci": "^2.0.0", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "prompts": "^2.0.1", "yargs": "^15.3.1" } @@ -8939,13 +8916,13 @@ } }, "jest-config": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-26.3.0.tgz", - "integrity": "sha512-xzvmhKYOXOc/JjGabUUXoi7Nxu6QpY5zJxND85wdqFrdP7raJT5wqlrVJbp6Bv4Sj1e83Z8bkxjsZCpwPASaPw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-config/-/jest-config-26.4.0.tgz", + "integrity": "sha512-MxsvrBug8YY+C4QcUBtmgnHyFeW7w3Ouk/w9eplCDN8VJGVyBEZFe8Lxzfp2pSqh0Dqurqv8Oik2YkbekGUlxg==", "dev": true, "requires": { "@babel/core": "^7.1.0", - "@jest/test-sequencer": "^26.3.0", + "@jest/test-sequencer": "^26.4.0", "@jest/types": "^26.3.0", "babel-jest": "^26.3.0", "chalk": "^4.0.0", @@ -8955,13 +8932,13 @@ "jest-environment-jsdom": "^26.3.0", "jest-environment-node": "^26.3.0", "jest-get-type": "^26.3.0", - "jest-jasmine2": "^26.3.0", + "jest-jasmine2": "^26.4.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "micromatch": "^4.0.2", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -9060,15 +9037,15 @@ } }, "jest-diff": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.3.0.tgz", - "integrity": "sha512-q5OZAtnr5CbHzrhjANzc3wvROk7+rcjCUI5uqM4cjOjtscNKfbJKBs3YhsWWhsdsIZzI3gc6wOpm49r6S61beg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-26.4.0.tgz", + "integrity": "sha512-wwC38HlOW+iTq6j5tkj/ZamHn6/nrdcEOc/fKaVILNtN2NLWGdkfRaHWwfNYr5ehaLvuoG2LfCZIcWByVj0gjg==", "dev": true, "requires": { "chalk": "^4.0.0", "diff-sequences": "^26.3.0", "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -9133,16 +9110,16 @@ } }, "jest-each": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-26.3.0.tgz", - "integrity": "sha512-OSAnLv0Eo/sDVhV0ifT2u6Q4aYUBoZ97R4k9cQshUFLTco0iRDbViJiW3Y6ySZjW95Tb83/xMYCppBih/7sW/A==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-each/-/jest-each-26.4.0.tgz", + "integrity": "sha512-+cyBh1ehs6thVT/bsZVG+WwmRn2ix4Q4noS9yLZgM10yGWPW12/TDvwuOV2VZXn1gi09/ZwJKJWql6YW1C9zNw==", "dev": true, "requires": { "@jest/types": "^26.3.0", "chalk": "^4.0.0", "jest-get-type": "^26.3.0", "jest-util": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -9317,9 +9294,9 @@ } }, "jest-jasmine2": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.3.0.tgz", - "integrity": "sha512-ZPkkA2XfH/fcLOp0SjeR4uDrMoNFilcwxLHORpjfMrcU0BFHNNRaF3DnslCdmewzqaERqtmHpYo8jj34RT+m2g==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-jasmine2/-/jest-jasmine2-26.4.0.tgz", + "integrity": "sha512-cGBxwzDDKB09EPJ4pE69BMDv+2lO442IB1xQd+vL3cua2OKdeXQK6iDlQKoRX/iP0RgU5T8sn9yahLcx/+ox8Q==", "dev": true, "requires": { "@babel/traverse": "^7.1.0", @@ -9330,15 +9307,15 @@ "@types/node": "*", "chalk": "^4.0.0", "co": "^4.6.0", - "expect": "^26.3.0", + "expect": "^26.4.0", "is-generator-fn": "^2.0.0", - "jest-each": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-each": "^26.4.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-runtime": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-runtime": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "pretty-format": "^26.3.0", + "pretty-format": "^26.4.0", "throat": "^5.0.0" }, "dependencies": { @@ -9436,25 +9413,25 @@ } }, "jest-leak-detector": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.3.0.tgz", - "integrity": "sha512-8C2Bur0S6n2xgW5kx22bDbe+Jjz9sM7/abr7DRQ48ww6q4w7vVzEpDEZiY7KatjTHtUloLTAqwTXEXg+tuETTg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-leak-detector/-/jest-leak-detector-26.4.0.tgz", + "integrity": "sha512-7EXKKEKnAWUPyiVtGZzJflbPOtYUdlNoevNVOkAcPpdR8xWiYKPGNGA6sz25S+8YhZq3rmkQJYAh3/P0VnoRwA==", "dev": true, "requires": { "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" } }, "jest-matcher-utils": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-26.3.0.tgz", - "integrity": "sha512-M5ZRSp6qpyzZyrLwXD2Sop7xaxm6qu/mKvqWU+BOSPTa4Y0ZEoKUYBzus/emg6kaVt7Ov9xMDLLZR1SrC8FxCw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-26.4.0.tgz", + "integrity": "sha512-u+xdCdq+F262DH+PutJKXLGr2H5P3DImdJCir51PGSfi3TtbLQ5tbzKaN8BkXbiTIU6ayuAYBWTlU1nyckVdzA==", "dev": true, "requires": { "chalk": "^4.0.0", - "jest-diff": "^26.3.0", + "jest-diff": "^26.4.0", "jest-get-type": "^26.3.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -9649,9 +9626,9 @@ "dev": true }, "jest-resolve": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-26.3.0.tgz", - "integrity": "sha512-+oKVWDkXjdZ4Xciuxv+M5e5v/Z3RLjrKIzen9tq3IO6HpzsLf9Mk3rET5du1uU8iVUCvz4/1PmjzNF50Uc7l2A==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-resolve/-/jest-resolve-26.4.0.tgz", + "integrity": "sha512-bn/JoZTEXRSlEx3+SfgZcJAVuTMOksYq9xe9O6s4Ekg84aKBObEaVXKOEilULRqviSLAYJldnoWV9c07kwtiCg==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -9723,20 +9700,20 @@ } }, "jest-resolve-dependencies": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-26.3.0.tgz", - "integrity": "sha512-j5rZ2BUh8vVjJZ7bpgCre0t6mbFLm5BWfVhYb1H35A3nbPN3kepzMqkMnKXPhwyLIVwn25uYkv6LHc2/Xa1sGw==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-resolve-dependencies/-/jest-resolve-dependencies-26.4.0.tgz", + "integrity": "sha512-hznK/hlrlhu8hwdbieRdHFKmcV83GW8t30libt/v6j1L3IEzb8iN21SaWzV8KRAAK4ijiU0kuge0wnHn+0rytQ==", "dev": true, "requires": { "@jest/types": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-snapshot": "^26.3.0" + "jest-snapshot": "^26.4.0" } }, "jest-runner": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-26.3.0.tgz", - "integrity": "sha512-eiPKgbhTM4q6A7RBh4qzKf6hwFDJMfqoFJubFvWSrHdZUsvSiBWYDqQI+FUXDFxDAOn/AfZjKURACAH3fUDjwA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-runner/-/jest-runner-26.4.0.tgz", + "integrity": "sha512-XF+tnUGolnPriu6Gg+HHWftspMjD5NkTV2mQppQnpZe39GcUangJ0al7aBGtA3GbVAcRd048DQiJPmsQRdugjw==", "dev": true, "requires": { "@jest/console": "^26.3.0", @@ -9748,13 +9725,13 @@ "emittery": "^0.7.1", "exit": "^0.1.2", "graceful-fs": "^4.2.4", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-docblock": "^26.0.0", "jest-haste-map": "^26.3.0", - "jest-leak-detector": "^26.3.0", + "jest-leak-detector": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-resolve": "^26.3.0", - "jest-runtime": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-runtime": "^26.4.0", "jest-util": "^26.3.0", "jest-worker": "^26.3.0", "source-map-support": "^0.5.6", @@ -9814,15 +9791,15 @@ } }, "jest-runtime": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-26.3.0.tgz", - "integrity": "sha512-cqCz+S76qwZcPnddkLCjuNw9O8/lB+i1odjz2hpvpDogXLp0qSMs+Slh1gBjB5V4feUyBHav/550Mr3FeTdmnA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-26.4.0.tgz", + "integrity": "sha512-1fjZgGpkyQBUTo59Vi19I4IcsBwzY6uwVFNjUmR06iIi3XRErkY28yimi4IUDRrofQErqcDEw2n3DF9WmQ6vEg==", "dev": true, "requires": { "@jest/console": "^26.3.0", "@jest/environment": "^26.3.0", "@jest/fake-timers": "^26.3.0", - "@jest/globals": "^26.3.0", + "@jest/globals": "^26.4.0", "@jest/source-map": "^26.3.0", "@jest/test-result": "^26.3.0", "@jest/transform": "^26.3.0", @@ -9833,15 +9810,15 @@ "exit": "^0.1.2", "glob": "^7.1.3", "graceful-fs": "^4.2.4", - "jest-config": "^26.3.0", + "jest-config": "^26.4.0", "jest-haste-map": "^26.3.0", "jest-message-util": "^26.3.0", "jest-mock": "^26.3.0", "jest-regex-util": "^26.0.0", - "jest-resolve": "^26.3.0", - "jest-snapshot": "^26.3.0", + "jest-resolve": "^26.4.0", + "jest-snapshot": "^26.4.0", "jest-util": "^26.3.0", - "jest-validate": "^26.3.0", + "jest-validate": "^26.4.0", "slash": "^3.0.0", "strip-bom": "^4.0.0", "yargs": "^15.3.1" @@ -9922,25 +9899,25 @@ } }, "jest-snapshot": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-26.3.0.tgz", - "integrity": "sha512-tHVUIeOTN/0SZN2ZjBZHzPG5txs/6uEQx2mwjxIT7QRE7pddPLd8jktXthyIz6bV+3GKetWXSV4YAoPUQwrfMA==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-26.4.0.tgz", + "integrity": "sha512-vFGmNGWHMBomrlOpheTMoqihymovuH3GqfmaEIWoPpsxUXyxT3IlbxI5I4m2vg0uv3HUJYg5JoGrkgMzVsAwCg==", "dev": true, "requires": { "@babel/types": "^7.0.0", "@jest/types": "^26.3.0", "@types/prettier": "^2.0.0", "chalk": "^4.0.0", - "expect": "^26.3.0", + "expect": "^26.4.0", "graceful-fs": "^4.2.4", - "jest-diff": "^26.3.0", + "jest-diff": "^26.4.0", "jest-get-type": "^26.3.0", "jest-haste-map": "^26.3.0", - "jest-matcher-utils": "^26.3.0", + "jest-matcher-utils": "^26.4.0", "jest-message-util": "^26.3.0", - "jest-resolve": "^26.3.0", + "jest-resolve": "^26.4.0", "natural-compare": "^1.4.0", - "pretty-format": "^26.3.0", + "pretty-format": "^26.4.0", "semver": "^7.3.2" }, "dependencies": { @@ -10112,9 +10089,9 @@ } }, "jest-validate": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-26.3.0.tgz", - "integrity": "sha512-oIJWqkIdgh1Q1O7ku4kDGkQoFKUOtZyDMbfYs4DsBi6r+FDY37xKTyZ30nM8F6yGZfB72qc7XB+3qKRgokwoXg==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-26.4.0.tgz", + "integrity": "sha512-t56Z/FRMrLP6mpmje7/YgHy0wOzcuc6i3LBXz6kjmsUWYN62OuMdC86Vg9/dX59SvyitSqqegOrx+h7BkNXeaQ==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -10122,7 +10099,7 @@ "chalk": "^4.0.0", "jest-get-type": "^26.3.0", "leven": "^3.1.0", - "pretty-format": "^26.3.0" + "pretty-format": "^26.4.0" }, "dependencies": { "ansi-styles": { @@ -12747,6 +12724,15 @@ "postcss": "^7.0.0" } }, + "postcss-font-weights": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/postcss-font-weights/-/postcss-font-weights-5.0.0.tgz", + "integrity": "sha512-n/1sLibDcRcFS4HcGVzB81eUdxjG8p3XZFvM3Q+0Szz+e8f64dV3bJyUMs7Nw8ZV4qmO293SUVmOMmmhNMkzjw==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, "postcss-import": { "version": "12.0.1", "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-12.0.1.tgz", @@ -13144,6 +13130,96 @@ "uniq": "^1.0.1" } }, + "postcss-short": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/postcss-short/-/postcss-short-5.0.0.tgz", + "integrity": "sha512-7VvAeY8Bm01cK+honNsQIisaJsUdhdNTPlYuo7iQq80Fbjl844pVNBXhjXjVeXi/+dKK5aRtCNKod7U0hSeTug==", + "dev": true, + "requires": { + "postcss": "^7.0.5", + "postcss-font-weights": "^5.0.0", + "postcss-short-border": "^4.0.0", + "postcss-short-border-radius": "^3.0.0", + "postcss-short-color": "^4.0.0", + "postcss-short-font-size": "^5.0.0", + "postcss-short-overflow": "^1.0.0", + "postcss-short-position": "^4.0.1", + "postcss-short-size": "^4.0.0", + "postcss-short-spacing": "^4.0.0" + } + }, + "postcss-short-border": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-border/-/postcss-short-border-4.0.0.tgz", + "integrity": "sha512-o9lZZ7yavQAs2Tj1BazltLBTDH4XdNtUuY15NhV6Nr1R+1sG4e9k2QZRhaOazPbntrw7pDHFqRwDYQND9DB8jw==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-border-radius": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-border-radius/-/postcss-short-border-radius-3.0.0.tgz", + "integrity": "sha512-s4g/NSUFA71+s4fJMUFo/IqcJL1ZdmWSz90GctW/f3msdhetgaU2OuORYQtUB2HGX5BdsvBFai8FBv/D3/lrVQ==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-color": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-color/-/postcss-short-color-4.0.0.tgz", + "integrity": "sha512-2cIbOysfLRXweXDqVpt+csXNaAF46S150lN8SgItvKN3naWXfKSanYLefzF9xZ2eVl7qgkv7Fkd8NgNI0PZFHQ==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-font-size": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-font-size/-/postcss-short-font-size-5.0.0.tgz", + "integrity": "sha512-CaEzUc/YSOq2PDblqZuSxdecmCqN5HbxLLLu5h53GoKJpXPNxrk6R9cfBvB/cO1LQyXNFtzZuQwL/JglkuBy4A==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-overflow": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-overflow/-/postcss-short-overflow-1.0.0.tgz", + "integrity": "sha512-nYFZGCt4+/x3kyQjgX3unxx7942sU/7ZI3JE8jHdgJZ/c/sAOrwWyjrNdrdckJzUj1xrCYcrp+vcrj2wspsCJA==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-position": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/postcss-short-position/-/postcss-short-position-4.0.1.tgz", + "integrity": "sha512-/k2v8v+Wwrb+nIcXqOuD32y6Yss1lci1fq7FMzsJsu7nfWHf48mpgPR/afliGdZvrXRRB9IW2aJbwugoOCgDsw==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-size": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-size/-/postcss-short-size-4.0.0.tgz", + "integrity": "sha512-/RRw2JFj+7xmX+GO5HIp9+sVNZTm+bXWKwHlxxXcxEJDPng/dNeWGXIdExbuknqgDeDX/lv5YfgjD2g5TUtUtA==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, + "postcss-short-spacing": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/postcss-short-spacing/-/postcss-short-spacing-4.0.0.tgz", + "integrity": "sha512-ThWP8vse9jtT26+l8fqfCriPVR7QGYUX7gEXYNPJ2+smD4XHpMJAmbhqa8aKuYsCMhvzeC9ZxCsR/B+nXA7iEw==", + "dev": true, + "requires": { + "postcss": "^7.0.5" + } + }, "postcss-svgo": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/postcss-svgo/-/postcss-svgo-4.0.2.tgz", @@ -13194,9 +13270,9 @@ "dev": true }, "pretty-format": { - "version": "26.3.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.3.0.tgz", - "integrity": "sha512-24kRw4C2Ok8+SHquydTZZCZPF2fvANI7rChGs8sNu784+1Jkq5jVFMvNAJSLuLy6XUcP3Fnw+SscLIQag/CG8Q==", + "version": "26.4.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.4.0.tgz", + "integrity": "sha512-mEEwwpCseqrUtuMbrJG4b824877pM5xald3AkilJ47Po2YLr97/siejYQHqj2oDQBeJNbu+Q0qUuekJ8F0NAPg==", "dev": true, "requires": { "@jest/types": "^26.3.0", @@ -14063,9 +14139,9 @@ "dev": true }, "serialize-javascript": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-3.1.0.tgz", - "integrity": "sha512-JIJT1DGiWmIKhzRsG91aS6Ze4sFUrYbltlkg2onR5OrnNM02Kl/hnY/T4FN2omvyeBbQmMJv+K4cPOpGzOTFBg==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", + "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", "dev": true, "requires": { "randombytes": "^2.1.0" @@ -15350,16 +15426,16 @@ } }, "terser-webpack-plugin": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.4.tgz", - "integrity": "sha512-U4mACBHIegmfoEe5fdongHESNJWqsGU+W0S/9+BmYGVQDw1+c2Ow05TpMhxjPK1sRb7cuYq1BPl1e5YHJMTCqA==", + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-1.4.5.tgz", + "integrity": "sha512-04Rfe496lN8EYruwi6oPQkG0vo8C+HT49X687FZnpPF0qMAIHONI6HEXYPKDOE8e5HjXTyKfqRd/agHtH0kOtw==", "dev": true, "requires": { "cacache": "^12.0.2", "find-cache-dir": "^2.1.0", "is-wsl": "^1.1.0", "schema-utils": "^1.0.0", - "serialize-javascript": "^3.1.0", + "serialize-javascript": "^4.0.0", "source-map": "^0.6.1", "terser": "^4.1.2", "webpack-sources": "^1.4.0", diff --git a/package.json b/package.json index 7226c866..3a14ba90 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ }, "dependencies": { "cosmiconfig": "^7.0.0", - "import-cwd": "^3.0.0", "loader-utils": "^2.0.0", "postcss": "^7.0.0", "schema-utils": "^2.7.0" @@ -74,6 +73,7 @@ "postcss-import": "^12.0.1", "postcss-js": "^2.0.0", "postcss-nested": "^4.2.3", + "postcss-short": "^5.0.0", "prettier": "^2.0.5", "standard": "^14.3.4", "standard-version": "^8.0.2", diff --git a/src/index.js b/src/index.js index 2d6c8651..d694eb01 100644 --- a/src/index.js +++ b/src/index.js @@ -7,9 +7,8 @@ import postcss from 'postcss'; import Warning from './Warning'; import SyntaxError from './Error'; -import parseOptions from './options'; import schema from './options.json'; -import { exec, loadConfig } from './utils'; +import { exec, loadConfig, getArrayPlugins } from './utils'; /** * **PostCSS Loader** @@ -34,30 +33,13 @@ export default async function loader(content, sourceMap, meta = {}) { const callback = this.async(); const file = this.resourcePath; - let config; - - const { length } = Object.keys(options).filter((option) => { - switch (option) { - // case 'exec': - case 'ident': - case 'config': - case 'sourceMap': - return false; - default: - return option; - } - }); + let loadedConfig = {}; - if (length) { - try { - config = await parseOptions.call(this, options); - } catch (error) { - callback(error); + const configOptions = + typeof options.config === 'undefined' ? true : options.config; - return; - } - } else { - const rc = { + if (configOptions) { + const dataForLoadConfig = { path: path.dirname(file), ctx: { file: { @@ -69,20 +51,23 @@ export default async function loader(content, sourceMap, meta = {}) { }, }; - if (options.config) { - if (options.config.path) { - rc.path = path.resolve(options.config.path); - } + if (typeof configOptions.path !== 'undefined') { + dataForLoadConfig.path = path.resolve(configOptions.path); + } - if (options.config.ctx) { - rc.ctx.options = options.config.ctx; - } + if (typeof configOptions.ctx !== 'undefined') { + dataForLoadConfig.ctx.options = configOptions.ctx; } - rc.ctx.webpack = this; + dataForLoadConfig.ctx.webpack = this; try { - config = await loadConfig(options.config, rc.ctx, rc.path, this.fs); + loadedConfig = await loadConfig( + configOptions, + dataForLoadConfig.ctx, + dataForLoadConfig.path, + this + ); } catch (error) { callback(error); @@ -90,37 +75,38 @@ export default async function loader(content, sourceMap, meta = {}) { } } - if (typeof config === 'undefined') { - config = {}; - } + let plugins; - if (config.file) { - this.addDependency(config.file); + try { + plugins = [ + ...getArrayPlugins(loadedConfig.plugins, file), + ...getArrayPlugins(options.plugins, file), + ]; + } catch (error) { + this.emitError(error); } - if (typeof config.options !== 'undefined') { - if (typeof config.options.to !== 'undefined') { - delete config.options.to; - } + const mergedOptions = { + ...loadedConfig, + ...options, + plugins, + }; - if (typeof config.options.from !== 'undefined') { - delete config.options.from; - } - } + const resultPlugins = mergedOptions.plugins; - const plugins = config.plugins || []; + const { parser, syntax, stringifier } = mergedOptions; - const postcssOptions = Object.assign( - { - from: file, - map: options.sourceMap - ? options.sourceMap === 'inline' - ? { inline: true, annotation: false } - : { inline: false, annotation: false } - : false, - }, - config.options - ); + const postcssOptions = { + from: file, + map: options.sourceMap + ? options.sourceMap === 'inline' + ? { inline: true, annotation: false } + : { inline: false, annotation: false } + : false, + parser, + syntax, + stringifier, + }; // Loader Exec (Deprecated) // https://webpack.js.org/api/loaders/#deprecated-context-properties @@ -130,23 +116,41 @@ export default async function loader(content, sourceMap, meta = {}) { } if (typeof postcssOptions.parser === 'string') { - // eslint-disable-next-line import/no-dynamic-require,global-require - postcssOptions.parser = require(postcssOptions.parser); + try { + // eslint-disable-next-line import/no-dynamic-require,global-require + postcssOptions.parser = require(postcssOptions.parser); + } catch (error) { + this.emitError( + `Loading PostCSS Parser failed: ${error.message}\n\n(@${file})` + ); + } } if (typeof postcssOptions.syntax === 'string') { - // eslint-disable-next-line import/no-dynamic-require,global-require - postcssOptions.syntax = require(postcssOptions.syntax); + try { + // eslint-disable-next-line import/no-dynamic-require,global-require + postcssOptions.syntax = require(postcssOptions.syntax); + } catch (error) { + this.emitError( + `Loading PostCSS Syntax failed: ${error.message}\n\n(@${file})` + ); + } } if (typeof postcssOptions.stringifier === 'string') { - // eslint-disable-next-line import/no-dynamic-require,global-require - postcssOptions.stringifier = require(postcssOptions.stringifier); + try { + // eslint-disable-next-line import/no-dynamic-require,global-require + postcssOptions.stringifier = require(postcssOptions.stringifier); + } catch (error) { + this.emitError( + `Loading PostCSS Stringifier failed: ${error.message}\n\n(@${file})` + ); + } } // Loader API Exec (Deprecated) // https://webpack.js.org/api/loaders/#deprecated-context-properties - if (config.exec) { + if (mergedOptions.exec) { // eslint-disable-next-line no-param-reassign content = exec(content, this); } @@ -163,7 +167,7 @@ export default async function loader(content, sourceMap, meta = {}) { let result; try { - result = await postcss(plugins).process(content, postcssOptions); + result = await postcss(resultPlugins).process(content, postcssOptions); } catch (error) { if (error.file) { this.addDependency(error.file); @@ -231,9 +235,7 @@ export default async function loader(content, sourceMap, meta = {}) { * @requires schema-utils * * @requires postcss - * @requires postcss-load-config * - * @requires ./options.js * @requires ./Warning.js * @requires ./SyntaxError.js */ diff --git a/src/options.js b/src/options.js deleted file mode 100644 index c227b4b1..00000000 --- a/src/options.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * **PostCSS Options Parser** - * - * Transforms the loader options into a valid postcss config `{Object}` - * - * @method parseOptions - * - * @param {Boolean} exec Execute CSS-in-JS - * @param {String|Object} parser PostCSS Parser - * @param {String|Object} syntax PostCSS Syntax - * @param {String|Object} stringifier PostCSS Stringifier - * @param {Array|Object|Function} plugins PostCSS Plugins - * - * @return {Promise} PostCSS Config - */ -function parseOptions({ exec, parser, syntax, stringifier, plugins }) { - if (typeof plugins === 'function') { - // eslint-disable-next-line no-param-reassign - plugins = plugins.call(this, this); - } - - if (typeof plugins === 'undefined') { - // eslint-disable-next-line no-param-reassign - plugins = []; - } else if (!Array.isArray(plugins)) { - // eslint-disable-next-line no-param-reassign - plugins = [plugins]; - } - - const options = {}; - - options.parser = parser; - options.syntax = syntax; - options.stringifier = stringifier; - - return Promise.resolve({ options, plugins, exec }); -} - -module.exports = parseOptions; diff --git a/src/utils.js b/src/utils.js index 7280ea3e..1ec7d0ec 100644 --- a/src/utils.js +++ b/src/utils.js @@ -2,8 +2,8 @@ import path from 'path'; import Module from 'module'; +import postcssPkg from 'postcss/package.json'; import { cosmiconfig } from 'cosmiconfig'; -import importCwd from 'import-cwd'; const parentModule = module; const moduleName = 'postcss'; @@ -32,47 +32,6 @@ const createContext = (context) => { return result; }; -const loadOptions = (config, file) => { - const result = {}; - - if (config.parser && typeof config.parser === 'string') { - try { - result.parser = importCwd(config.parser); - } catch (err) { - throw new Error( - `Loading PostCSS Parser failed: ${err.message}\n\n(@${file})` - ); - } - } - - if (config.syntax && typeof config.syntax === 'string') { - try { - result.syntax = importCwd(config.syntax); - } catch (err) { - throw new Error( - `Loading PostCSS Syntax failed: ${err.message}\n\n(@${file})` - ); - } - } - - if (config.stringifier && typeof config.stringifier === 'string') { - try { - result.stringifier = importCwd(config.stringifier); - } catch (err) { - throw new Error( - `Loading PostCSS Stringifier failed: ${err.message}\n\n(@${file})` - ); - } - } - - if (config.plugins) { - // eslint-disable-next-line no-param-reassign - delete config.plugins; - } - - return { ...config, ...result }; -}; - const load = (plugin, options, file) => { try { if ( @@ -80,39 +39,34 @@ const load = (plugin, options, file) => { typeof options === 'undefined' || Object.keys(options).length === 0 ) { - return importCwd(plugin); + // eslint-disable-next-line global-require,import/no-dynamic-require + return require(plugin); } - return importCwd(plugin)(options); - } catch (err) { + // eslint-disable-next-line global-require,import/no-dynamic-require + return require(plugin)(options); + } catch (error) { throw new Error( - `Loading PostCSS Plugin failed: ${err.message}\n\n(@${file})` + `Loading PostCSS Plugin failed: ${error.message}\n\n(@${file})` ); } }; -const loadPlugins = (config, file) => { - let plugins = []; +function loadPlugins(pluginEntry, file) { + const plugins = Object.entries(pluginEntry).filter((i) => { + const [, options] = i; - if (Array.isArray(config.plugins)) { - plugins = config.plugins.filter(Boolean); - } else { - plugins = Object.keys(config.plugins) - .filter((plugin) => { - return config.plugins[plugin] !== false ? plugin : ''; - }) - .map((plugin) => { - return load(plugin, config.plugins[plugin], file); - }); - } + return options !== false ? pluginEntry : ''; + }); - if (plugins.length && plugins.length > 0) { - plugins.forEach((plugin, i) => { - if (plugin.postcss) { - // eslint-disable-next-line no-param-reassign - plugin = plugin.postcss; - } + const loadedPlugins = plugins.map((plugin) => { + const [pluginName, pluginOptions] = plugin; + return load(pluginName, pluginOptions, file); + }); + + if (loadedPlugins.length && loadedPlugins.length > 0) { + loadedPlugins.forEach((plugin, i) => { if (plugin.default) { // eslint-disable-next-line no-param-reassign plugin = plugin.default; @@ -132,29 +86,8 @@ const loadPlugins = (config, file) => { }); } - return plugins; -}; - -const processResult = (context, result) => { - const file = result.filepath || ''; - let config = result.config || {}; - - if (typeof config === 'function') { - config = config(context); - } else { - config = Object.assign({}, config, context); - } - - if (!config.plugins) { - config.plugins = []; - } - - return { - plugins: loadPlugins(config, file), - options: loadOptions(config, file), - file, - }; -}; + return loadedPlugins; +} function exec(code, loaderContext) { const { resource, context } = loaderContext; @@ -171,11 +104,7 @@ function exec(code, loaderContext) { return module.exports; } -async function loadConfig(config, context, configPath, inputFileSystem) { - if (config === false) { - return {}; - } - +async function loadConfig(config, context, configPath, loaderContext) { let searchPath = configPath ? path.resolve(configPath) : process.cwd(); if (typeof config === 'string') { @@ -185,7 +114,7 @@ async function loadConfig(config, context, configPath, inputFileSystem) { let stats; try { - stats = await stat(inputFileSystem, searchPath); + stats = await stat(loaderContext.fs, searchPath); } catch (errorIgnore) { throw new Error(`No PostCSS Config found in: ${searchPath}`); } @@ -204,7 +133,57 @@ async function loadConfig(config, context, configPath, inputFileSystem) { throw new Error(`No PostCSS Config found in: ${searchPath}`); } - return processResult(createContext(context), result); + const patchedContext = createContext(context); + + let resultConfig = result.config || {}; + + if (typeof resultConfig === 'function') { + resultConfig = resultConfig(patchedContext); + } else { + resultConfig = { ...resultConfig, ...patchedContext }; + } + + if (result.filepath) { + resultConfig.file = result.filepath; + loaderContext.addDependency(result.filepath); + } + + return resultConfig; +} + +function getPlugin(pluginEntry) { + if (!pluginEntry) { + return []; + } + + if (pluginEntry.postcssVersion === postcssPkg.version) { + return [pluginEntry]; + } + + const result = pluginEntry.call(this, this); + + return Array.isArray(result) ? result : [result]; +} + +function getArrayPlugins(plugins, file) { + if (Array.isArray(plugins)) { + return plugins.reduce((accumulator, plugin) => { + // eslint-disable-next-line no-param-reassign + accumulator = accumulator.concat(getArrayPlugins(plugin)); + + return accumulator; + }, []); + } + + if (typeof plugins === 'object' && typeof plugins !== 'function') { + if (Object.keys(plugins).length === 0) { + return []; + } + + return getArrayPlugins(loadPlugins(plugins, file), file); + } + + return getPlugin(plugins); } -export { exec, loadConfig }; +export { exec, loadConfig, getArrayPlugins }; diff --git a/test/__snapshots__/validate-options.test.js.snap b/test/__snapshots__/validate-options.test.js.snap index 85b98925..ca7a2491 100644 --- a/test/__snapshots__/validate-options.test.js.snap +++ b/test/__snapshots__/validate-options.test.js.snap @@ -100,8 +100,6 @@ exports[`validate options should throw an error on the "parser" option with "tru object { … }" `; -exports[`validate options should throw an error on the "plugins" option with "/test/" value 1`] = `"/test/ is not a PostCSS plugin"`; - exports[`validate options should throw an error on the "plugins" option with "1" value 1`] = ` "Invalid options object. PostCSS Loader has been initialized using an options object that does not match the API schema. - options.plugins should be one of these: diff --git a/test/config-autoload.test.js b/test/config-autoload.test.js index 2bd1762b..9c9c795b 100644 --- a/test/config-autoload.test.js +++ b/test/config-autoload.test.js @@ -7,6 +7,11 @@ import { loadConfig } from '../src/utils'; const testDirectory = path.resolve(__dirname, 'fixtures', 'config-autoload'); +const loaderContext = { + fs, + addDependency: () => true, +}; + describe('config-autoload', () => { const ctx = { parser: true, @@ -15,15 +20,11 @@ describe('config-autoload', () => { it('.postcssrc - {Object} - Load Config', async () => { const expected = (config) => { - expect(config.options.parser).toEqual(require('sugarss')); - expect(config.options.syntax).toEqual(require('sugarss')); - expect(config.options.map).toEqual(false); - expect(config.options.from).toEqual('./test/rc/fixtures/index.css'); - expect(config.options.to).toEqual('./test/rc/expect/index.css'); + expect(config.map).toEqual(false); + expect(config.from).toEqual('./test/rc/fixtures/index.css'); + expect(config.to).toEqual('./test/rc/expect/index.css'); - expect(config.plugins.length).toEqual(2); - expect(typeof config.plugins[0]).toBe('function'); - expect(typeof config.plugins[1]).toBe('function'); + expect(Object.keys(config.plugins).length).toEqual(3); expect(config.file).toEqual( path.resolve(testDirectory, 'rc', '.postcssrc') @@ -31,10 +32,10 @@ describe('config-autoload', () => { }; const config = await loadConfig( - null, + true, {}, path.resolve(testDirectory, 'rc'), - fs + loaderContext ); expected(config); @@ -42,17 +43,11 @@ describe('config-autoload', () => { it('postcss.config.js - {Object} - Load Config', async () => { const expected = (config) => { - expect(config.options.parser).toEqual(require('sugarss')); - expect(config.options.syntax).toEqual(require('sugarss')); - expect(config.options.map).toEqual(false); - expect(config.options.from).toEqual( - './test/js/object/fixtures/index.css' - ); - expect(config.options.to).toEqual('./test/js/object/expect/index.css'); + expect(config.map).toEqual(false); + expect(config.from).toEqual('./test/js/object/fixtures/index.css'); + expect(config.to).toEqual('./test/js/object/expect/index.css'); - expect(config.plugins.length).toEqual(2); - expect(typeof config.plugins[0]).toBe('function'); - expect(typeof config.plugins[1]).toBe('function'); + expect(Object.keys(config.plugins).length).toEqual(3); expect(config.file).toEqual( path.resolve(testDirectory, 'js/object', 'postcss.config.js') @@ -60,10 +55,10 @@ describe('config-autoload', () => { }; const config = await loadConfig( - null, + true, ctx, path.resolve(testDirectory, 'js/object'), - fs + loaderContext ); expected(config); @@ -71,15 +66,11 @@ describe('config-autoload', () => { it('postcss.config.js - {Array} - Load Config', async () => { const expected = (config) => { - expect(config.options.parser).toEqual(require('sugarss')); - expect(config.options.syntax).toEqual(require('sugarss')); - expect(config.options.map).toEqual(false); - expect(config.options.from).toEqual('./test/js/array/fixtures/index.css'); - expect(config.options.to).toEqual('./test/js/array/expect/index.css'); + expect(config.map).toEqual(false); + expect(config.from).toEqual('./test/js/array/fixtures/index.css'); + expect(config.to).toEqual('./test/js/array/expect/index.css'); - expect(config.plugins.length).toEqual(2); - expect(typeof config.plugins[0]).toBe('function'); - expect(typeof config.plugins[1]).toBe('function'); + expect(Object.keys(config.plugins).length).toEqual(3); expect(config.file).toEqual( path.resolve(testDirectory, 'js/array', 'postcss.config.js') @@ -87,10 +78,10 @@ describe('config-autoload', () => { }; const config = await loadConfig( - null, + true, ctx, path.resolve(testDirectory, 'js/array'), - fs + loaderContext ); expected(config); @@ -98,15 +89,12 @@ describe('config-autoload', () => { it('package.json - {Object} - Load Config', async () => { const expected = (config) => { - expect(config.options.parser).toEqual(false); - expect(config.options.syntax).toEqual(false); - expect(config.options.map).toEqual(false); - expect(config.options.from).toEqual('./test/pkg/fixtures/index.css'); - expect(config.options.to).toEqual('./test/pkg/expect/index.css'); - - expect(config.plugins.length).toEqual(2); - expect(typeof config.plugins[0]).toBe('function'); - expect(typeof config.plugins[1]).toBe('function'); + expect(config.parser).toEqual(false); + expect(config.syntax).toEqual(false); + expect(config.map).toEqual(false); + expect(config.from).toEqual('./test/pkg/fixtures/index.css'); + expect(config.to).toEqual('./test/pkg/expect/index.css'); + expect(Object.keys(config.plugins).length).toEqual(3); expect(config.file).toEqual( path.resolve(testDirectory, 'pkg', 'package.json') @@ -114,10 +102,10 @@ describe('config-autoload', () => { }; const config = await loadConfig( - null, + true, {}, path.resolve(testDirectory, 'pkg'), - fs + loaderContext ); expected(config); @@ -125,119 +113,9 @@ describe('config-autoload', () => { it('Loading Config - {Error}', async () => { try { - await loadConfig(null, {}, path.resolve('unresolved'), fs); + await loadConfig(true, {}, path.resolve('unresolved'), fs); } catch (error) { expect(error.message).toMatch(/^No PostCSS Config found in: (.*)$/); } }); - - it('Plugin - {Type} - Invalid', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/plugins'), - fs - ); - } catch (error) { - expect(error.message).toMatch( - /^Invalid PostCSS Plugin found at: (.*)\n\n\(@.*\)$/ - ); - } - }); - - it('Loading Plugin - {Object} - {Error}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/plugins/object'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Loading PostCSS Plugin failed: .*$/m); - } - }); - - it('Loading Plugin - {Object} - Options - {Error}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/plugins/object/options'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Loading PostCSS Plugin failed: .*$/m); - } - }); - - it('Loading Plugin - {Array} - {Error}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/plugins/array'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Cannot find (.*)$/); - } - }); - - it('Loading Plugin - {Array} - Options - {Error}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/plugins/array/options'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Cannot find (.*)$/); - } - }); -}); - -describe('Loading Options - {Error}', () => { - it('Parser - {String}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/options/parser'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Loading PostCSS Parser failed: .*$/m); - } - }); - - it('Syntax - {String}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/options/syntax'), - fs - ); - } catch (error) { - expect(error.message).toMatch(/^Loading PostCSS Syntax failed: .*$/m); - } - }); - - it('Stringifier - {String}', async () => { - try { - await loadConfig( - null, - {}, - path.resolve(testDirectory, 'err/options/stringifier'), - fs - ); - } catch (error) { - expect(error.message).toMatch( - /^Loading PostCSS Stringifier failed: .*$/m - ); - } - }); }); diff --git a/test/fixtures/css/index2.js b/test/fixtures/css/index2.js new file mode 100644 index 00000000..9415e9b0 --- /dev/null +++ b/test/fixtures/css/index2.js @@ -0,0 +1,3 @@ +import style from './style2.css' + +export default style diff --git a/test/fixtures/css/invalid.config.js b/test/fixtures/css/invalid.config.js new file mode 100644 index 00000000..7dd96ea6 --- /dev/null +++ b/test/fixtures/css/invalid.config.js @@ -0,0 +1 @@ +throw new Error('invalid postcss config'); diff --git a/test/fixtures/css/style2.css b/test/fixtures/css/style2.css new file mode 100644 index 00000000..3bab8470 --- /dev/null +++ b/test/fixtures/css/style2.css @@ -0,0 +1,4 @@ +a { + -x-border-color: blue blue *; + -x-color: * #fafafa; +} diff --git a/test/loader.test.js b/test/loader.test.js index 8f0c194c..54c67984 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -1,3 +1,5 @@ +import postcss from 'postcss'; + import { compile, getCompiler, @@ -8,7 +10,10 @@ import { describe('loader', () => { it('should work', async () => { - const compiler = getCompiler('./css/index.js', { plugins: [] }); + const compiler = getCompiler('./css/index.js', { + plugins: [], + config: false, + }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle('style.css', stats); @@ -25,7 +30,12 @@ describe('loader', () => { }); }; - const compiler = getCompiler('./css/index.js', { plugins: [plugin()] }); + const postcssPlugin = postcss.plugin('postcss-plugin', plugin); + + const compiler = getCompiler('./css/index.js', { + plugins: [postcssPlugin()], + config: false, + }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle('style.css', stats); @@ -36,7 +46,10 @@ describe('loader', () => { }); it('should emit Syntax Error', async () => { - const compiler = getCompiler('./css/index.js', { parser: 'sugarss' }); + const compiler = getCompiler('./css/index.js', { + parser: 'sugarss', + config: false, + }); const stats = await compile(compiler); expect(getWarnings(stats)).toMatchSnapshot('warnings'); diff --git a/test/options/__snapshots__/config.test.js.snap b/test/options/__snapshots__/config.test.js.snap index 7cd81570..6883a980 100644 --- a/test/options/__snapshots__/config.test.js.snap +++ b/test/options/__snapshots__/config.test.js.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Config Options should emit error when invalid config : errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +Error: No PostCSS Config found in: /test/fixtures/css/invalid.config.js", +] +`; + +exports[`Config Options should emit error when invalid config : warnings 1`] = `Array []`; + +exports[`Config Options should emit error when unresolved config : errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +Error: No PostCSS Config found in: /test/fixtures/css/unresolve.js", +] +`; + +exports[`Config Options should emit error when unresolved config : warnings 1`] = `Array []`; + exports[`Config Options should work Config - "string" with path directory: css 1`] = ` "a { color: rgba(255, 0, 0, 1.0) } " diff --git a/test/options/__snapshots__/exec.test.js.snap b/test/options/__snapshots__/exec.test.js.snap index 61611464..edc3fde8 100644 --- a/test/options/__snapshots__/exec.test.js.snap +++ b/test/options/__snapshots__/exec.test.js.snap @@ -11,8 +11,9 @@ exports[`Options Exec should work Exec - {Boolean}: errors 1`] = `Array []`; exports[`Options Exec should work Exec - {Boolean}: warnings 1`] = `Array []`; exports[`Options Exec should work JSS - {String}: css 1`] = ` -"{ a: { color: 'yellow' } } -" +"a { + color: yellow +}" `; exports[`Options Exec should work JSS - {String}: errors 1`] = `Array []`; diff --git a/test/options/__snapshots__/parser.test.js.snap b/test/options/__snapshots__/parser.test.js.snap index e0e4b314..86684afc 100644 --- a/test/options/__snapshots__/parser.test.js.snap +++ b/test/options/__snapshots__/parser.test.js.snap @@ -1,5 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Parser should emit error Parser: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: parser is not a function", + "ModuleError: Module Error (from \`replaced original path\`): +(Emitted value instead of an instance of Error) Loading PostCSS Parser failed: Cannot find module 'unresolve' from 'src/index.js'", +] +`; + +exports[`Options Parser should emit error Parser: warnings 1`] = `Array []`; + exports[`Options Parser should work Parser - {Object}: css 1`] = ` "a { color: black diff --git a/test/options/__snapshots__/plugins.test.js.snap b/test/options/__snapshots__/plugins.test.js.snap index eea69ea2..d2b9cffe 100644 --- a/test/options/__snapshots__/plugins.test.js.snap +++ b/test/options/__snapshots__/plugins.test.js.snap @@ -1,5 +1,30 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Plugins should emit error on load plugin: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: Cannot read property 'postcss' of undefined", + "ModuleError: Module Error (from \`replaced original path\`): +Loading PostCSS Plugin failed: Cannot find module 'postcss-unresolved' from 'src/utils.js'", +] +`; + +exports[`Options Plugins should emit error on load plugin: warnings 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Array} + options: css 1`] = ` +"a { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} +" +`; + +exports[`Options Plugins should work Plugins - {Array} + options: errors 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Array} + options: warnings 1`] = `Array []`; + exports[`Options Plugins should work Plugins - {Array}: css 1`] = ` "a { color: rgba(255, 0, 0, 1.0) } " @@ -27,6 +52,43 @@ exports[`Options Plugins should work Plugins - {Function} - {Object}: errors 1`] exports[`Options Plugins should work Plugins - {Function} - {Object}: warnings 1`] = `Array []`; +exports[`Options Plugins should work Plugins - {Object without require} + options: css 1`] = ` +"a { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} +" +`; + +exports[`Options Plugins should work Plugins - {Object without require} + options: errors 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Object without require} + options: warnings 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Object without require}: css 1`] = ` +"a { color: rgba(255, 0, 0, 1.0) } +" +`; + +exports[`Options Plugins should work Plugins - {Object without require}: errors 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Object without require}: warnings 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Object} + options: css 1`] = ` +"a { + border-top-color: blue; + border-right-color: blue; + border-left-color: blue; + background-color: #fafafa; +} +" +`; + +exports[`Options Plugins should work Plugins - {Object} + options: errors 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {Object} + options: warnings 1`] = `Array []`; + exports[`Options Plugins should work Plugins - {Object}: css 1`] = ` "a { color: rgba(255, 0, 0, 1.0) } " @@ -35,3 +97,12 @@ exports[`Options Plugins should work Plugins - {Object}: css 1`] = ` exports[`Options Plugins should work Plugins - {Object}: errors 1`] = `Array []`; exports[`Options Plugins should work Plugins - {Object}: warnings 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {empty Object}: css 1`] = ` +"a { color: rgba(255, 0, 0, 1.0) } +" +`; + +exports[`Options Plugins should work Plugins - {empty Object}: errors 1`] = `Array []`; + +exports[`Options Plugins should work Plugins - {empty Object}: warnings 1`] = `Array []`; diff --git a/test/options/__snapshots__/stringifier.test.js.snap b/test/options/__snapshots__/stringifier.test.js.snap index 53afa6a2..2d229b46 100644 --- a/test/options/__snapshots__/stringifier.test.js.snap +++ b/test/options/__snapshots__/stringifier.test.js.snap @@ -1,5 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Stringifier should emit error Stringifier: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: this.stringify is not a function", + "ModuleError: Module Error (from \`replaced original path\`): +(Emitted value instead of an instance of Error) Loading PostCSS Stringifier failed: Cannot find module 'unresolved' from 'src/index.js'", +] +`; + +exports[`Options Stringifier should emit error Stringifier: warnings 1`] = `Array []`; + exports[`Options Stringifier should work Stringifier - {Object}: css 1`] = ` "a color: black " diff --git a/test/options/__snapshots__/syntax.test.js.snap b/test/options/__snapshots__/syntax.test.js.snap index 0a56f772..80bcdaff 100644 --- a/test/options/__snapshots__/syntax.test.js.snap +++ b/test/options/__snapshots__/syntax.test.js.snap @@ -1,5 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Options Syntax should emit error Syntax: errors 1`] = ` +Array [ + "ModuleBuildError: Module build failed (from \`replaced original path\`): +TypeError: Cannot read property 'parse' of undefined", + "ModuleError: Module Error (from \`replaced original path\`): +(Emitted value instead of an instance of Error) Loading PostCSS Syntax failed: Cannot find module 'unresolve' from 'src/index.js'", +] +`; + +exports[`Options Syntax should emit error Syntax: warnings 1`] = `Array []`; + exports[`Options Syntax should work Syntax - {Object}: css 1`] = ` "a color: black diff --git a/test/options/config.test.js b/test/options/config.test.js index 7ba9f46a..033cd7a8 100644 --- a/test/options/config.test.js +++ b/test/options/config.test.js @@ -212,4 +212,24 @@ describe('Config Options', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should emit error when unresolved config ', async () => { + const compiler = getCompiler('./css/index.js', { + config: path.resolve(__dirname, '../fixtures/css/unresolve.js'), + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); + + it('should emit error when invalid config ', async () => { + const compiler = getCompiler('./css/index.js', { + config: path.resolve(__dirname, '../fixtures/css/invalid.config.js'), + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); }); diff --git a/test/options/exec.test.js b/test/options/exec.test.js index 179a8761..39be2ecf 100644 --- a/test/options/exec.test.js +++ b/test/options/exec.test.js @@ -50,7 +50,7 @@ describe('Options Exec', () => { module: { rules: [ { - test: /style.\.js$/i, + test: /style\.js$/i, use: [ { loader: require.resolve('../helpers/testLoader'), diff --git a/test/options/parser.test.js b/test/options/parser.test.js index c3d8034c..21a94572 100644 --- a/test/options/parser.test.js +++ b/test/options/parser.test.js @@ -25,7 +25,7 @@ describe('Options Parser', () => { }, { loader: path.resolve(__dirname, '../../src'), - options: { parser: 'sugarss' }, + options: { parser: 'sugarss', config: false }, }, ], }, @@ -59,7 +59,12 @@ describe('Options Parser', () => { { loader: path.resolve(__dirname, '../../src'), // eslint-disable-next-line global-require - options: { ident: 'postcss', parser: require('sugarss') }, + options: { + ident: 'postcss', + // eslint-disable-next-line global-require,import/no-dynamic-require + parser: require('sugarss'), + config: false, + }, }, ], }, @@ -75,4 +80,35 @@ describe('Options Parser', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should emit error Parser', async () => { + const compiler = getCompiler( + './sss/index.js', + {}, + { + module: { + rules: [ + { + test: /\.sss$/i, + use: [ + { + loader: require.resolve('../helpers/testLoader'), + options: {}, + }, + { + loader: path.resolve(__dirname, '../../src'), + options: { parser: 'unresolve', config: false }, + }, + ], + }, + ], + }, + } + ); + + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); }); diff --git a/test/options/plugins.test.js b/test/options/plugins.test.js index a53a3d14..9a8516c6 100644 --- a/test/options/plugins.test.js +++ b/test/options/plugins.test.js @@ -66,4 +66,91 @@ describe('Options Plugins', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should work Plugins - {Object without require}', async () => { + const compiler = getCompiler('./css/index.js', { + plugins: { + 'postcss-import': {}, + 'postcss-nested': {}, + }, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work Plugins - {empty Object}', async () => { + const compiler = getCompiler('./css/index.js', { + plugins: {}, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work Plugins - {Object without require} + options', async () => { + const compiler = getCompiler('./css/index2.js', { + plugins: { + 'postcss-short': { prefix: 'x' }, + }, + config: false, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style2.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work Plugins - {Object} + options', async () => { + const compiler = getCompiler('./css/index2.js', { + // eslint-disable-next-line global-require + plugins: require('postcss-short')({ prefix: 'x' }), + config: false, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style2.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work Plugins - {Array} + options', async () => { + const compiler = getCompiler('./css/index2.js', { + // eslint-disable-next-line global-require + plugins: [require('postcss-short')({ prefix: 'x' })], + config: false, + }); + const stats = await compile(compiler); + + const codeFromBundle = getCodeFromBundle('style2.css', stats); + + expect(codeFromBundle.css).toMatchSnapshot('css'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should emit error on load plugin', async () => { + const compiler = getCompiler('./css/index2.js', { + plugins: { + 'postcss-unresolved': {}, + }, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); }); diff --git a/test/options/stringifier.test.js b/test/options/stringifier.test.js index 667aa517..efb1b6db 100644 --- a/test/options/stringifier.test.js +++ b/test/options/stringifier.test.js @@ -8,7 +8,10 @@ import { describe('Options Stringifier', () => { it('should work Stringifier - {String}', async () => { - const compiler = getCompiler('./css/index.js', { stringifier: 'sugarss' }); + const compiler = getCompiler('./css/index.js', { + stringifier: 'sugarss', + config: false, + }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle('style.css', stats); @@ -23,6 +26,7 @@ describe('Options Stringifier', () => { ident: 'postcss', // eslint-disable-next-line global-require stringifier: require('sugarss'), + config: false, }); const stats = await compile(compiler); @@ -32,4 +36,17 @@ describe('Options Stringifier', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should emit error Stringifier', async () => { + const compiler = getCompiler('./css/index.js', { + ident: 'postcss', + // eslint-disable-next-line global-require + stringifier: 'unresolved', + config: false, + }); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); }); diff --git a/test/options/syntax.test.js b/test/options/syntax.test.js index 083ed933..d3c6a9b8 100644 --- a/test/options/syntax.test.js +++ b/test/options/syntax.test.js @@ -25,7 +25,7 @@ describe('Options Syntax', () => { }, { loader: path.resolve(__dirname, '../../src'), - options: { syntax: 'sugarss' }, + options: { syntax: 'sugarss', config: false }, }, ], }, @@ -62,6 +62,7 @@ describe('Options Syntax', () => { ident: 'postcss', // eslint-disable-next-line global-require syntax: require('sugarss'), + config: false, }, }, ], @@ -79,4 +80,34 @@ describe('Options Syntax', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should emit error Syntax', async () => { + const compiler = getCompiler( + './sss/index.js', + {}, + { + module: { + rules: [ + { + test: /\.sss$/i, + use: [ + { + loader: require.resolve('../helpers/testLoader'), + options: {}, + }, + { + loader: path.resolve(__dirname, '../../src'), + options: { syntax: 'unresolve', config: false }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats, true)).toMatchSnapshot('errors'); + }); }); diff --git a/test/validate-options.test.js b/test/validate-options.test.js index a0757af4..d39cf972 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -44,7 +44,7 @@ describe('validate options', () => { require('./fixtures/config/plugin'), () => [require('./fixtures/config/plugin')()], ], - failure: [1, true, false, /test/], + failure: [1, true, false], }, };