diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 37d078b..0088737 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,16 +10,17 @@ jobs: fail-fast: false matrix: node-version: + - 18 - 16 - 14 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm install --force - run: npm test - - uses: codecov/codecov-action@v2 + - uses: codecov/codecov-action@v3 if: matrix.node-version == 16 with: fail_ci_if_error: true diff --git a/dev-only.js b/dev-only.js index a6ddab3..a38a781 100644 --- a/dev-only.js +++ b/dev-only.js @@ -1,12 +1,13 @@ -'use strict'; - +let ow; if (process.env.NODE_ENV === 'production') { const shim = new Proxy((() => {}), { get: () => shim, - apply: () => shim + apply: () => shim, }); - module.exports = shim; + ow = shim; } else { - module.exports = require('./dist'); + ow = await import('./dist/index.js'); } + +export default ow; diff --git a/package.json b/package.json index cc3c9e8..feb8e3b 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,25 @@ "description": "Function argument validation for humans", "license": "MIT", "repository": "sindresorhus/ow", - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - }, + "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", - "main": "dist/index.js", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "node": "./dist/index.js" + }, + "./dev-only": { + "types": "./dist/index.d.ts", + "node": "./dev-only.js" + } + }, "engines": { - "node": ">=12" + "node": ">=14.16" }, "scripts": { "test": "xo && c8 ava", @@ -50,37 +57,33 @@ "object" ], "dependencies": { - "@sindresorhus/is": "^4.2.0", - "callsites": "^3.1.0", - "dot-prop": "^6.0.1", + "@sindresorhus/is": "^5.1.0", + "callsites": "^4.0.0", + "dot-prop": "^7.2.0", "lodash.isequal": "^4.5.0", - "type-fest": "^2.3.4", + "type-fest": "^2.13.0", "vali-date": "^1.0.0" }, "devDependencies": { - "@sindresorhus/tsconfig": "^0.8.0", - "@types/lodash.isequal": "^4.5.5", - "@types/node": "^16.10.2", + "@sindresorhus/tsconfig": "^3.0.1", + "@types/lodash.isequal": "^4.5.6", + "@types/node": "^17.0.42", "@types/vali-date": "^1.0.0", - "ava": "^3.15.0", - "c8": "^7.10.0", - "del-cli": "^4.0.0", - "expect-type": "^0.12.0", - "gh-pages": "^3.2.3", - "ts-node": "^10.4.0", - "typedoc": "^0.22.5", - "typescript": "^4.5.0-beta", - "xo": "^0.46.4" + "ava": "^4.3.0", + "c8": "^7.11.3", + "del-cli": "^4.0.1", + "expect-type": "^0.13.0", + "gh-pages": "^4.0.0", + "ts-node": "^10.8.1", + "typedoc": "^0.22.17", + "typescript": "^4.7.3", + "xo": "^0.50.0" }, "browser": { "./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js" }, - "types": "dist", "sideEffects": false, "xo": { - "parserOptions": { - "project": "./tsconfig.xo.json" - }, "ignores": [ "example.js", "dev-only.js", @@ -98,20 +101,16 @@ } }, "ava": { - "nonSemVerExperiments": { - "configurableModuleFormat": true - }, - "nodeArguments": [ - "--loader=ts-node/esm", - "--experimental-specifier-resolution=node" - ], "files": [ "test/**", "!test/fixtures/**" ], "extensions": { "ts": "module" - } + }, + "nodeArguments": [ + "--loader=ts-node/esm" + ] }, "c8": { "reporter": [ diff --git a/readme.md b/readme.md index 118eb77..9a4170e 100644 --- a/readme.md +++ b/readme.md @@ -20,14 +20,12 @@ ## Install -``` -$ npm install ow +```sh +npm install ow ``` ## Usage -*If you use CommonJS, you need to import is as `const {default: ow} = require('ow')`.* - ```ts import ow from 'ow'; @@ -65,7 +63,7 @@ ow(unicorn, ow.object.exactShape({ //=> ArgumentError: Expected property `stars.value` to be of type `number` but received type `string` in object `unicorn` ``` -***Note:*** If you intend on using `ow` for development purposes only, use `require('ow/dev-only')` instead of the usual `import 'ow'`, and run the bundler with `NODE_ENV` set to `production` (e.g. `$ NODE_ENV="production" parcel build index.js`). This will make `ow` automatically export a shim when running in production, which should result in a significantly lower bundle size. +***Note:*** If you intend on using `ow` for development purposes only, use `import ow from 'ow/dev-only'` instead of the usual `import ow from 'ow'`, and run the bundler with `NODE_ENV` set to `production` (e.g. `$ NODE_ENV="production" parcel build index.js`). This will make `ow` automatically export a shim when running in production, which should result in a significantly lower bundle size. ## API @@ -291,6 +289,8 @@ This can be useful for creating your own reusable validators which can be extrac ### TypeScript +**Requires TypeScript 4.7 or later.** + Ow includes a type utility that lets you to extract a TypeScript type from the given predicate. ```ts @@ -306,6 +306,9 @@ type User = Infer; ## Maintainers - [Sindre Sorhus](https://github.com/sindresorhus) + +**Former:** + - [Sam Verschueren](https://github.com/SamVerschueren) ## Related diff --git a/source/index.ts b/source/index.ts index 9441357..82a1ad6 100644 --- a/source/index.ts +++ b/source/index.ts @@ -1,6 +1,5 @@ import callsites from 'callsites'; import {inferLabel} from './utils/infer-label.js'; -import {Predicate} from './predicates/predicate.js'; import {BasePredicate, isPredicate} from './predicates/base-predicate.js'; import modifiers, {Modifiers} from './modifiers.js'; import predicates, {Predicates} from './predicates.js'; @@ -72,7 +71,7 @@ export interface ReusableValidator { @param value - Value to test. @param label - Override the label which should be used in error messages. */ - // eslint-disable-next-line @typescript-eslint/prefer-function-type + // eslint-disable-next-line @typescript-eslint/prefer-function-type, @typescript-eslint/no-redundant-type-constituents (value: unknown | T, label?: string): void; } @@ -117,7 +116,7 @@ const ow = (value: unknown, labelOrPredicate: unknown, predicate?: BasePredic Object.defineProperties(ow, { isValid: { - value: (value: unknown, predicate: BasePredicate): boolean => { + value(value: unknown, predicate: BasePredicate): boolean { try { test(value, '', predicate); return true; @@ -148,6 +147,8 @@ const _ow: Ow = predicates(modifiers(ow)) as Ow; export default _ow; -export {BasePredicate, Predicate}; export * from './predicates.js'; export {ArgumentError} from './argument-error.js'; + +export {Predicate} from './predicates/predicate.js'; +export type {BasePredicate} from './predicates/base-predicate.js'; diff --git a/source/predicates.ts b/source/predicates.ts index 1140ae0..6922c16 100644 --- a/source/predicates.ts +++ b/source/predicates.ts @@ -6,7 +6,7 @@ import {BigIntPredicate} from './predicates/bigint.js'; import {BooleanPredicate} from './predicates/boolean.js'; import {Predicate, PredicateOptions} from './predicates/predicate.js'; import {ArrayPredicate} from './predicates/array.js'; -import {ObjectPredicate, Shape} from './predicates/object.js'; +import {ObjectPredicate} from './predicates/object.js'; import {DatePredicate} from './predicates/date.js'; import {ErrorPredicate} from './predicates/error.js'; import {MapPredicate} from './predicates/map.js'; @@ -328,22 +328,20 @@ const predicates = (object: T, options?: PredicateOptions): T & Predicates => export default predicates; -export { - StringPredicate, - NumberPredicate, - BigIntPredicate, - BooleanPredicate, - ArrayPredicate, - ObjectPredicate, - DatePredicate, - ErrorPredicate, - MapPredicate, - WeakMapPredicate, - SetPredicate, - WeakSetPredicate, - TypedArrayPredicate, - ArrayBufferPredicate, - DataViewPredicate, - AnyPredicate, - Shape, -}; +export {ObjectPredicate} from './predicates/object.js'; +export type {Shape} from './predicates/object.js'; +export {StringPredicate} from './predicates/string.js'; +export {NumberPredicate} from './predicates/number.js'; +export {BigIntPredicate} from './predicates/bigint.js'; +export {BooleanPredicate} from './predicates/boolean.js'; +export {ArrayPredicate} from './predicates/array.js'; +export {DatePredicate} from './predicates/date.js'; +export {ErrorPredicate} from './predicates/error.js'; +export {MapPredicate} from './predicates/map.js'; +export {WeakMapPredicate} from './predicates/weak-map.js'; +export {SetPredicate} from './predicates/set.js'; +export {WeakSetPredicate} from './predicates/weak-set.js'; +export {TypedArrayPredicate} from './predicates/typed-array.js'; +export {ArrayBufferPredicate} from './predicates/array-buffer.js'; +export {DataViewPredicate} from './predicates/data-view.js'; +export {AnyPredicate} from './predicates/any.js'; diff --git a/source/predicates/error.ts b/source/predicates/error.ts index db5e3f0..f802009 100644 --- a/source/predicates/error.ts +++ b/source/predicates/error.ts @@ -25,7 +25,7 @@ export class ErrorPredicate extends Predicate { @param expected - Expected message of the Error. */ - message(expected: string): this { + override message(expected: string): this { return this.addValidator({ message: (error, label) => `Expected ${label} message to be \`${expected}\`, got \`${error.message}\``, validator: error => error.message === expected, diff --git a/source/predicates/map.ts b/source/predicates/map.ts index 043b9ad..96b502c 100644 --- a/source/predicates/map.ts +++ b/source/predicates/map.ts @@ -93,7 +93,7 @@ export class MapPredicate extends Predicate `Expected ${label} to have any value of \`${JSON.stringify(values)}\``, - validator: map => { + validator(map) { const valueSet = new Set(map.values()); return values.some(key => valueSet.has(key)); }, diff --git a/source/predicates/number.ts b/source/predicates/number.ts index ae42ffc..008b3b2 100644 --- a/source/predicates/number.ts +++ b/source/predicates/number.ts @@ -89,7 +89,7 @@ export class NumberPredicate extends Predicate { */ oneOf(list: readonly number[]): this { return this.addValidator({ - message: (value, label) => { + message(value, label) { let printedList = JSON.stringify(list); if (list.length > 10) { diff --git a/source/predicates/object.ts b/source/predicates/object.ts index 0246f9a..f34d25d 100644 --- a/source/predicates/object.ts +++ b/source/predicates/object.ts @@ -1,6 +1,5 @@ import is from '@sindresorhus/is'; - -import dotProp from 'dot-prop'; +import {hasProperty} from 'dot-prop'; import isEqual from 'lodash.isequal'; import hasItems from '../utils/has-items.js'; import ofType from '../utils/of-type.js'; @@ -9,8 +8,6 @@ import {partial, exact, Shape, TypeOfShape} from '../utils/match-shape.js'; import {Predicate, PredicateOptions} from './predicate.js'; import {BasePredicate} from './base-predicate.js'; -export {Shape}; - export class ObjectPredicate extends Predicate { /** @hidden @@ -92,7 +89,7 @@ export class ObjectPredicate extends Predicate { */ instanceOf(instance: Function): this { return this.addValidator({ - message: (object: object, label: string) => { + message(object: object, label: string) { let {name} = object?.constructor ?? {}; if (!name || name === 'Object') { @@ -115,7 +112,7 @@ export class ObjectPredicate extends Predicate { message: (_, label, missingKeys) => `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``, validator: object => hasItems( { - has: item => dotProp.has(object, item), + has: item => hasProperty(object, item), }, keys, ), @@ -130,7 +127,7 @@ export class ObjectPredicate extends Predicate { hasAnyKeys(...keys: readonly string[]): this { return this.addValidator({ message: (_, label) => `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``, - validator: object => keys.some(key => dotProp.has(object, key)), + validator: object => keys.some(key => hasProperty(object, key)), }); } @@ -191,3 +188,5 @@ export class ObjectPredicate extends Predicate { }) as ObjectPredicate; } } + +export type {Shape} from '../utils/match-shape.js'; diff --git a/source/predicates/predicate.ts b/source/predicates/predicate.ts index b862b8a..6bebdab 100644 --- a/source/predicates/predicate.ts +++ b/source/predicates/predicate.ts @@ -179,7 +179,7 @@ export class Predicate implements BasePredicate { ? `(${label}) ${error}` // eslint-disable-next-line @typescript-eslint/no-unsafe-call : error(label), - validator: value => { + validator(value) { const {message, validator} = customValidator(value); if (validator) { diff --git a/source/predicates/string.ts b/source/predicates/string.ts index a36c988..b6c8f5a 100644 --- a/source/predicates/string.ts +++ b/source/predicates/string.ts @@ -103,7 +103,7 @@ export class StringPredicate extends Predicate { */ oneOf(list: readonly string[]): this { return this.addValidator({ - message: (value, label) => { + message(value, label) { let printedList = JSON.stringify(list); if (list.length > 10) { @@ -132,7 +132,7 @@ export class StringPredicate extends Predicate { */ get nonBlank(): this { return this.addValidator({ - message: (value, label) => { + message(value, label) { // Unicode's formal substitute characters can be barely legible and may not be easily recognized. // Hence this alternative substitution scheme. const madeVisible = value diff --git a/source/utils/infer-label.ts b/source/utils/infer-label.ts index ccc37ed..f1fc6b3 100644 --- a/source/utils/infer-label.ts +++ b/source/utils/infer-label.ts @@ -51,14 +51,13 @@ export const inferLabel = (callsites: readonly CallSite[]): void | string => { line = line.slice(columnNumber - 1); const match = labelRegex.exec(line); + const token = match?.groups?.['label']; - if (!match?.groups?.label) { + if (!token) { // Exit if we didn't find a label return; } - const token = match.groups.label; - if (isValidIdentifier(token) || isValidIdentifier(token.split('.').pop())) { return token; } diff --git a/source/utils/match-shape.ts b/source/utils/match-shape.ts index be2e00b..bf81657 100644 --- a/source/utils/match-shape.ts +++ b/source/utils/match-shape.ts @@ -3,7 +3,6 @@ import test from '../test.js'; import {isPredicate} from '../predicates/base-predicate.js'; import {BasePredicate} from '../index.js'; -// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style export interface Shape { [key: string]: BasePredicate | Shape; } diff --git a/source/utils/node/is-node.ts b/source/utils/node/is-node.ts index 7bc54a9..5c50d17 100644 --- a/source/utils/node/is-node.ts +++ b/source/utils/node/is-node.ts @@ -1,2 +1,2 @@ -// eslint-disable-next-line node/prefer-global/process +// eslint-disable-next-line n/prefer-global/process export default Boolean(process?.versions?.node); diff --git a/test/any-multiple-errors.ts b/test/any-multiple-errors.ts index c0f2def..840ac21 100644 --- a/test/any-multiple-errors.ts +++ b/test/any-multiple-errors.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ import test from 'ava'; -import ow, {ArgumentError, BasePredicate, Main} from '../source'; -import {testSymbol} from '../source/predicates/base-predicate'; -import {createAnyError, createAnyPredicateError} from './fixtures/create-error'; +import ow, {ArgumentError, BasePredicate, Main} from '../source/index.js'; +import {testSymbol} from '../source/predicates/base-predicate.js'; +import {createAnyError, createAnyPredicateError} from './fixtures/create-error.js'; test('any predicate', t => { // #region Tests line 49 of predicates/any.ts and lines 16-21 of utils/generate-argument-error-message.ts diff --git a/test/any.ts b/test/any.ts index ec08715..1c4d23d 100644 --- a/test/any.ts +++ b/test/any.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import ow from '../source'; -import {createAnyError} from './fixtures/create-error'; +import ow from '../source/index.js'; +import {createAnyError} from './fixtures/create-error.js'; test('any', t => { t.notThrows(() => { diff --git a/test/array-buffer.ts b/test/array-buffer.ts index 8c48fd6..b20632c 100644 --- a/test/array-buffer.ts +++ b/test/array-buffer.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('arrayBuffer', t => { t.notThrows(() => { diff --git a/test/array.ts b/test/array.ts index 3c5c7d9..3d06798 100644 --- a/test/array.ts +++ b/test/array.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('array', t => { t.notThrows(() => { diff --git a/test/bigint.ts b/test/bigint.ts index 2dfaf4c..a5853b0 100644 --- a/test/bigint.ts +++ b/test/bigint.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('bigint', t => { t.notThrows(() => { diff --git a/test/boolean.ts b/test/boolean.ts index fe7670e..f22d522 100644 --- a/test/boolean.ts +++ b/test/boolean.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('boolean', t => { t.notThrows(() => { diff --git a/test/buffer.ts b/test/buffer.ts index dad29be..3909112 100644 --- a/test/buffer.ts +++ b/test/buffer.ts @@ -1,6 +1,6 @@ import {Buffer} from 'node:buffer'; import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('buffer', t => { t.notThrows(() => { diff --git a/test/custom-message.ts b/test/custom-message.ts index 5f3127a..73f6e10 100644 --- a/test/custom-message.ts +++ b/test/custom-message.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow, {ArgumentError, Predicate} from '../source'; +import ow, {ArgumentError, Predicate} from '../source/index.js'; class CustomPredicate extends Predicate { constructor() { diff --git a/test/custom-predicate.ts b/test/custom-predicate.ts index 2794c81..6066637 100644 --- a/test/custom-predicate.ts +++ b/test/custom-predicate.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow, {Predicate} from '../source'; +import ow, {Predicate} from '../source/index.js'; class CustomPredicate extends Predicate { constructor() { diff --git a/test/data-view.ts b/test/data-view.ts index eed40f6..30fc4b6 100644 --- a/test/data-view.ts +++ b/test/data-view.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('dataView', t => { t.notThrows(() => { diff --git a/test/date.ts b/test/date.ts index 0ad88b5..441f518 100644 --- a/test/date.ts +++ b/test/date.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('date', t => { t.notThrows(() => { diff --git a/test/error.ts b/test/error.ts index 4904516..a9ca4f1 100644 --- a/test/error.ts +++ b/test/error.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; class CustomError extends Error { constructor(message: string) { diff --git a/test/function.ts b/test/function.ts index d4e72c9..c278e40 100644 --- a/test/function.ts +++ b/test/function.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('function', t => { t.notThrows(() => { diff --git a/test/iterable.ts b/test/iterable.ts index e9c498a..cded2f3 100644 --- a/test/iterable.ts +++ b/test/iterable.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('iterable', t => { t.notThrows(() => { diff --git a/test/map.ts b/test/map.ts index e444a3d..27c8879 100644 --- a/test/map.ts +++ b/test/map.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('map', t => { t.notThrows(() => { diff --git a/test/nan.ts b/test/nan.ts index f857394..0b42d56 100644 --- a/test/nan.ts +++ b/test/nan.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('nan', t => { t.notThrows(() => { diff --git a/test/null-or-undefined.ts b/test/null-or-undefined.ts index 83ed7ed..db0f299 100644 --- a/test/null-or-undefined.ts +++ b/test/null-or-undefined.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('nullOrUndefined', t => { const x = null; diff --git a/test/null.ts b/test/null.ts index 7707f83..33fb956 100644 --- a/test/null.ts +++ b/test/null.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('null', t => { const x = null; diff --git a/test/number.ts b/test/number.ts index 5660351..7c8c81c 100644 --- a/test/number.ts +++ b/test/number.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('number', t => { t.notThrows(() => { diff --git a/test/object.ts b/test/object.ts index 29eaacb..2d0e429 100644 --- a/test/object.ts +++ b/test/object.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; class Unicorn {} // eslint-disable-line @typescript-eslint/no-extraneous-class diff --git a/test/optional.ts b/test/optional.ts index 0182757..185d1c6 100644 --- a/test/optional.ts +++ b/test/optional.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('optional', t => { t.notThrows(() => { diff --git a/test/promise.ts b/test/promise.ts index e6c34a2..fe33151 100644 --- a/test/promise.ts +++ b/test/promise.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('promise', t => { t.notThrows(() => { diff --git a/test/regexp.ts b/test/regexp.ts index 6e20dc8..8f77f91 100644 --- a/test/regexp.ts +++ b/test/regexp.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('regExp', t => { t.notThrows(() => { diff --git a/test/set.ts b/test/set.ts index 34a5874..a618eb5 100644 --- a/test/set.ts +++ b/test/set.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('set', t => { t.notThrows(() => { diff --git a/test/string.ts b/test/string.ts index ba2ff2a..1207872 100644 --- a/test/string.ts +++ b/test/string.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('string', t => { const bar: any = 12; diff --git a/test/symbol.ts b/test/symbol.ts index 9aa59f0..31cce02 100644 --- a/test/symbol.ts +++ b/test/symbol.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('symbol', t => { t.notThrows(() => { diff --git a/test/test.ts b/test/test.ts index 8754e37..72594e8 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,6 +1,6 @@ import test from 'ava'; -import ow, {ArgumentError, AssertingValidator} from '../source'; -import {createAnyError} from './fixtures/create-error'; +import ow, {ArgumentError, AssertingValidator} from '../source/index.js'; +import {createAnyError} from './fixtures/create-error.js'; test('not', t => { const foo = ''; diff --git a/test/typed-array.ts b/test/typed-array.ts index fc92a44..d2151ac 100644 --- a/test/typed-array.ts +++ b/test/typed-array.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('typedArray', t => { t.notThrows(() => { diff --git a/test/types.ts b/test/types.ts index 3289b3f..c47b334 100644 --- a/test/types.ts +++ b/test/types.ts @@ -2,7 +2,7 @@ import type {Buffer} from 'node:buffer'; import test from 'ava'; import {ExpectTypeOf, expectTypeOf} from 'expect-type'; import {TypedArray} from 'type-fest'; -import ow, {BasePredicate, Infer} from '../source'; +import ow, {BasePredicate, Infer} from '../source/index.js'; test('type-level tests', t => { t.is(typeof typeTests, 'function'); diff --git a/test/undefined.ts b/test/undefined.ts index 1dfe1d9..b51d6ef 100644 --- a/test/undefined.ts +++ b/test/undefined.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('undefined', t => { const x = undefined; diff --git a/test/weak-map.ts b/test/weak-map.ts index df6d51f..9d75cd3 100644 --- a/test/weak-map.ts +++ b/test/weak-map.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; test('weakMap', t => { t.notThrows(() => { diff --git a/test/weak-set.ts b/test/weak-set.ts index 7e4c0f7..e909b74 100644 --- a/test/weak-set.ts +++ b/test/weak-set.ts @@ -1,5 +1,5 @@ import test from 'ava'; -import ow from '../source'; +import ow from '../source/index.js'; const unicorn = {unicorn: '🦄'}; const rainbow = {rainbow: '🌈'}; diff --git a/tsconfig.json b/tsconfig.json index c709604..261b545 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,16 @@ { "extends": "@sindresorhus/tsconfig", "compilerOptions": { - "outDir": "dist", - "target": "ES2019", - "module": "ESNext", - "allowSyntheticDefaultImports": true, - "lib": ["ES2020"] + "outDir": "dist" + }, + "include": [ + "source" + ], + "ts-node": { + "transpileOnly": true, + "files": true, + "experimentalResolver": true }, - "include": ["source"], "typedocOptions": { "out": "docs", "excludePrivate": true, diff --git a/tsconfig.xo.json b/tsconfig.xo.json deleted file mode 100644 index b01049f..0000000 --- a/tsconfig.xo.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": [ - "test" - ] -}