Skip to content

Commit eacedd0

Browse files
committed
Fix schema-utils module not found error
1 parent 66dc73a commit eacedd0

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 4.3.0
4+
5+
- Fix [`schema-utils`](https://github.com/retyui/group-css-media-queries-loader/issues/11#issuecomment-926810847) not found error
6+
- Apply a PostCSS plugin guidelines [rule](https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#14-keep-postcss-to-peerdependencies)
7+
38
## 4.2.0
49

510
- Auto-configure `sourceMap` option, based on [`.devtool`](https://webpack.js.org/configuration/devtool/#devtool)

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"name": "group-css-media-queries-loader",
3-
"version": "4.2.0",
3+
"version": "4.3.0",
44
"main": "lib/index.js",
55
"types": "lib/index.d.ts",
66
"files": [
77
"lib"
88
],
9+
"dependencies": {
10+
"schema-utils": "^2.0.0 || ^3.0.0"
11+
},
912
"peerDependencies": {
1013
"loader-utils": "^2.0.0 || ^1.0.0",
1114
"postcss": ">=8.1.0",
@@ -22,6 +25,9 @@
2225
"optional": true
2326
}
2427
},
28+
"optionalDependencies": {
29+
"postcss-loader": "^6.0.0"
30+
},
2531
"scripts": {
2632
"prebuild": "rimraf ./lib",
2733
"build": "tsc",
@@ -30,9 +36,6 @@
3036
"test": "node ./test/test.js && cd example/webpack5 && yarn --ignore-engines && yarn build && cd ../..",
3137
"prepublishOnly": "npm run test"
3238
},
33-
"optionalDependencies": {
34-
"postcss-loader": "^6.0.0"
35-
},
3639
"devDependencies": {
3740
"@tsconfig/node10": "^1.0.1",
3841
"@types/loader-utils": "^2.0.3",

src/group-css-media-queries.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
AtRule,
3-
atRule as postcssAtRule,
4-
Plugin,
5-
PluginCreator,
6-
} from "postcss";
1+
import type { AtRule, Plugin, PluginCreator } from "postcss";
72

83
const EM_TO_PX_RATIO = 16;
9-
104
const MIN_WIDTH = "minWidth" as const;
115
const MAX_WIDTH = "maxWidth" as const;
126
const UNIT = "init" as const;
@@ -100,15 +94,11 @@ const sortMedia =
10094
function GroupCssMediaQueriesPostCssPlugin() {
10195
return {
10296
postcssPlugin: "group-css-media-queries",
103-
Once(root) {
97+
Once(root, { atRule: postcssAtRule }) {
10498
const medias: MediaQueries = {};
10599

106100
root.walkAtRules("media", (atRule) => {
107-
if (!(atRule.parent && atRule.parent.type === "root")) {
108-
return;
109-
}
110-
111-
if (atRule.name !== "media") {
101+
if (atRule.parent?.type !== "root" || atRule.name !== "media") {
112102
return;
113103
}
114104

src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getRemainingRequest,
55
getCurrentRequest,
66
} from "loader-utils";
7-
import { validate } from "schema-utils";
7+
import schemaUtils from "schema-utils";
88
import type { JSONSchema7 } from "schema-utils/declarations/validate";
99
import type { LoaderContext } from "webpack";
1010
import type { LoaderOptions, SourceMap, AdditionalData } from "./types";
@@ -23,7 +23,10 @@ function GroupCssMediaQueriesLoader(
2323
// 2.x.x return empty `object` if empty query
2424
const loaderOptions = getOptions(this) || {};
2525

26-
validate(schema as JSONSchema7, loaderOptions, {
26+
// 2.x.x schemaUtils(schema)
27+
// 3.x.x schemaUtils.validate(schema)
28+
// @ts-ignore
29+
(schemaUtils.validate || schemaUtils)(schema as JSONSchema7, loaderOptions, {
2730
name: "group-css-media-queries-loader",
2831
});
2932

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ safe-buffer@^5.1.0:
741741
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
742742
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==
743743

744-
schema-utils@*, schema-utils@^3.1.0, schema-utils@^3.1.1:
744+
schema-utils@*, "schema-utils@^2.0.0 || ^3.0.0", schema-utils@^3.1.0, schema-utils@^3.1.1:
745745
version "3.1.1"
746746
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.1.1.tgz#bc74c4b6b6995c1d88f76a8b77bea7219e0c8281"
747747
integrity sha512-Y5PQxS4ITlC+EahLuXaY86TXfR7Dc5lw294alXOq86JAHCihAIZfqv8nNCWvaEJvaC51uN9hbLGeV0cFBdH+Fw==

0 commit comments

Comments
 (0)