Skip to content

Fix schema-utils module not found error #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Code Quality

on:
push:
branches:
- master
paths:
- '.github/**'
- 'yarn.lock'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 4.3.0

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

## 4.2.0

- Auto-configure `sourceMap` option, based on [`.devtool`](https://webpack.js.org/configuration/devtool/#devtool)
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
"name": "group-css-media-queries-loader",
"version": "4.2.0",
"version": "4.3.0",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"dependencies": {
"schema-utils": "^2.0.0 || ^3.0.0"
},
"peerDependencies": {
"loader-utils": "^2.0.0 || ^1.0.0",
"postcss": ">=8.1.0",
Expand All @@ -22,6 +25,9 @@
"optional": true
}
},
"optionalDependencies": {
"postcss-loader": "^6.0.0"
},
"scripts": {
"prebuild": "rimraf ./lib",
"build": "tsc",
Expand All @@ -30,9 +36,6 @@
"test": "node ./test/test.js && cd example/webpack5 && yarn --ignore-engines && yarn build && cd ../..",
"prepublishOnly": "npm run test"
},
"optionalDependencies": {
"postcss-loader": "^6.0.0"
},
"devDependencies": {
"@tsconfig/node10": "^1.0.1",
"@types/loader-utils": "^2.0.3",
Expand Down
16 changes: 3 additions & 13 deletions src/group-css-media-queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import {
AtRule,
atRule as postcssAtRule,
Plugin,
PluginCreator,
} from "postcss";
import type { AtRule, Plugin, PluginCreator } from "postcss";

const EM_TO_PX_RATIO = 16;

const MIN_WIDTH = "minWidth" as const;
const MAX_WIDTH = "maxWidth" as const;
const UNIT = "init" as const;
Expand Down Expand Up @@ -100,15 +94,11 @@ const sortMedia =
function GroupCssMediaQueriesPostCssPlugin() {
return {
postcssPlugin: "group-css-media-queries",
Once(root) {
Once(root, { atRule: postcssAtRule }) {
const medias: MediaQueries = {};

root.walkAtRules("media", (atRule) => {
if (!(atRule.parent && atRule.parent.type === "root")) {
return;
}

if (atRule.name !== "media") {
if (atRule.parent?.type !== "root" || atRule.name !== "media") {
return;
}

Expand Down
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
getRemainingRequest,
getCurrentRequest,
} from "loader-utils";
import { validate } from "schema-utils";
import schemaUtils from "schema-utils";
import type { JSONSchema7 } from "schema-utils/declarations/validate";
import type { LoaderContext } from "webpack";
import type { LoaderOptions, SourceMap, AdditionalData } from "./types";
Expand All @@ -23,7 +23,10 @@ function GroupCssMediaQueriesLoader(
// 2.x.x return empty `object` if empty query
const loaderOptions = getOptions(this) || {};

validate(schema as JSONSchema7, loaderOptions, {
// 2.x.x schemaUtils(schema)
// 3.x.x schemaUtils.validate(schema)
// @ts-ignore
(schemaUtils.validate || schemaUtils)(schema as JSONSchema7, loaderOptions, {
name: "group-css-media-queries-loader",
});

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ safe-buffer@^5.1.0:
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6"
integrity sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==

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