From 8ea45d60a57e53aa18e598a7439db87cb3a7388f Mon Sep 17 00:00:00 2001 From: Rifat Nabi Date: Tue, 9 Nov 2021 00:09:03 +1100 Subject: [PATCH] :package: better-ajv-errors v1 --- .changeset/honest-guests-destroy.md | 30 +++++++++++++++++++++++++++++ README.md | 12 +++++++----- package.json | 20 +++++++++++++------ screenshot.js | 2 +- 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 .changeset/honest-guests-destroy.md diff --git a/.changeset/honest-guests-destroy.md b/.changeset/honest-guests-destroy.md new file mode 100644 index 00000000..5a8023da --- /dev/null +++ b/.changeset/honest-guests-destroy.md @@ -0,0 +1,30 @@ +--- +'better-ajv-errors': major +--- + +:package: better-ajv-errors v1 + +### Breaking Changes + +- Dropped support for Node.js `< 12.13.0` +- Default import in CommonJS format no longer supported + + **:no_entry_sign: Wrong** + + ```js + const betterAjvErrors = require('better-ajv-errors'); + ``` + + **:white_check_mark: Correct** + + ```js + const betterAjvErrors = require('better-ajv-errors').default; + // Or + const { default: betterAjvErrors } = require('better-ajv-errors'); + ``` + +### Other Changes +- Added ESM support +- Moved from `babel` to `esbuild` _(99% faster build: from `2170ms` to `20ms`)_ + - https://github.com/atlassian/better-ajv-errors/pull/101#issuecomment-963129931 +- Bumped all `dependencies` & `devDependencies` diff --git a/README.md b/README.md index e5a87bb7..1ed89e34 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Main goal of this library is to provide relevant error messages like the followi ## Installation ```bash -$ yarn add better-ajv-errors -$ # Or $ npm i better-ajv-errors +$ # Or +$ yarn add better-ajv-errors ``` Also make sure that you installed [ajv](https://www.npmjs.com/package/ajv) package to validate data against JSON schemas. @@ -29,10 +29,12 @@ First, you need to validate your payload with `ajv`. If it's invalid then you ca import Ajv from 'ajv'; import betterAjvErrors from 'better-ajv-errors'; // const Ajv = require('ajv'); -// const betterAjvErrors = require('better-ajv-errors'); +// const betterAjvErrors = require('better-ajv-errors').default; +// Or +// const { default: betterAjvErrors } = require('better-ajv-errors'); -// You need to pass `jsonPointers: true` -const ajv = new Ajv({ jsonPointers: true }); +// You need to pass `{ jsonPointers: true }` for older versions of ajv +const ajv = new Ajv(); // Load schema and data const schema = ...; diff --git a/package.json b/package.json index 423d8be1..86b16276 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,17 @@ "version": "0.8.2", "description": "JSON Schema validation for Human", "repository": "atlassian/better-ajv-errors", - "main": "lib/cjs/index.js", - "module": "lib/esm/index.js", + "main": "./lib/cjs/index.js", + "exports": { + ".": { + "require": "./lib/cjs/index.js", + "default": "./lib/esm/index.js" + } + }, + "module": "./lib/esm/index.js", + "engines": { + "node": ">= 12.13.0" + }, "keywords": [ "json-schema", "ajv", @@ -17,10 +26,9 @@ "Tong Li" ], "license": "Apache-2.0", - "typings": "typings.d.ts", + "types": "./typings.d.ts", "files": [ "lib", - "index.js", "typings.d.ts" ], "scripts": { @@ -30,10 +38,10 @@ "build:esm": "node build.js", "prerelease": "npm run build", "release": "changeset publish", - "format": "prettier --write 'src/**/*.js' '.changeset/*.json'", + "format": "prettier --write './src/**/*.js' './.changeset/*.json'", "test": "jest", "test-ci": "jest --coverage --colors", - "screenshot": "svg-term --command='node screenshot' --out=media/screenshot.svg --padding=5 --width=80 --height=13 --at=1000 --no-cursor --term iterm2 --profile='deep' --window", + "screenshot": "svg-term --command='node screenshot' --out=./media/screenshot.svg --padding=5 --width=80 --height=13 --at=1000 --no-cursor --term iterm2 --profile='deep' --window", "prepare": "husky install" }, "dependencies": { diff --git a/screenshot.js b/screenshot.js index c46c5306..be18c95e 100644 --- a/screenshot.js +++ b/screenshot.js @@ -4,7 +4,7 @@ const Ajv = require('ajv'); const schema = require('./src/__fixtures__/default/schema.json'); const data = require('./src/__fixtures__/default/data.json'); -const betterAjvErrors = require('./lib/cjs').default; +const betterAjvErrors = require('.').default; // options can be passed, e.g. {allErrors: true} // const ajv = new Ajv({ allErrors: true, async: 'es7' });