Skip to content
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

Output ESM instead of CommonJS #225

Merged
merged 22 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install --force
- run: npm test
- uses: codecov/codecov-action@v1
if: matrix.node-version == 14
Expand Down
49 changes: 36 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"main": "dist/index.js",
"engines": {
"node": ">=12"
Expand Down Expand Up @@ -61,15 +62,15 @@
"@types/lodash.isequal": "^4.5.5",
"@types/node": "^16.10.2",
"@types/vali-date": "^1.0.0",
"ava": "^2.4.0",
"ava": "^3.15.0",
"del-cli": "^4.0.0",
"expect-type": "^0.12.0",
"gh-pages": "^3.2.3",
"nyc": "^15.1.0",
"ts-node": "^10.2.1",
"ts-node": "^10.3.0",
"typedoc": "^0.22.5",
"typescript": "^4.4.3",
"xo": "^0.38.2"
"typescript": "^4.5.0-beta",
"xo": "^0.45.0"
},
"browser": {
"./dist/utils/infer-label.js": "./dist/utils/infer-label.browser.js"
Expand All @@ -94,22 +95,44 @@
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-unused-vars": "off",
"import/no-anonymous-default-export": "off"
"import/no-anonymous-default-export": "off",
"@typescript-eslint/comma-dang": "off",
"operator-linebreak": "off",
"@typescript-eslint/object-curly-spacing": "off",
"@typescript-eslint/comma-dangle": "off",
"node/prefer-global/buffer": "off",
"unicorn/prefer-node-protocol": "off",
"no-warning-comments": "off",
"@typescript-eslint/no-unsafe-call": "off",
"import/order": "off",
"unicorn/numeric-separators-style": "off",
"key-spacing": "off",
SimonSiefke marked this conversation as resolved.
Show resolved Hide resolved
"capitalized-comments": "off",
"arrow-body-style": "off",
"@typescript-eslint/no-unsafe-return": "off",
"no-multi-spaces": "off",
"node/prefer-global/process": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/ban-ts-comment": "off"
}
},
"ava": {
"babel": false,
"compileEnhancements": false,
"nonSemVerExperiments": {
"configurableModuleFormat": true
},
"nodeArguments": [
"--loader=ts-node/esm",
"--experimental-specifier-resolution=node"
],
"files": [
"test/**",
"!test/fixtures/**"
],
"extensions": [
"ts"
],
"require": [
"ts-node/register"
]
"extensions": {
"ts": "module"
}
},
"nyc": {
"reporter": [
Expand Down
2 changes: 1 addition & 1 deletion source/argument-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {generateStackTrace} from './utils/generate-stack';
import {generateStackTrace} from './utils/generate-stack.js';

const wrapStackTrace = (error: ArgumentError, stack: string): string => `${error.name}: ${error.message}\n${stack}`;

Expand Down
16 changes: 8 additions & 8 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import callsites from 'callsites';
import {inferLabel} from './utils/infer-label';
import {Predicate} from './predicates/predicate';
import {BasePredicate, isPredicate} from './predicates/base-predicate';
import modifiers, {Modifiers} from './modifiers';
import predicates, {Predicates} from './predicates';
import test from './test';
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';
import test from './test.js';

/**
@hidden
Expand Down Expand Up @@ -149,5 +149,5 @@ const _ow: Ow = predicates(modifiers(ow)) as Ow;
export default _ow;

export {BasePredicate, Predicate};
export * from './predicates';
export {ArgumentError} from './argument-error';
export * from './predicates.js';
export {ArgumentError} from './argument-error.js';
4 changes: 2 additions & 2 deletions source/modifiers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {BasePredicate} from '.';
import predicates, {Predicates} from './predicates';
import {BasePredicate} from './index.js';
import predicates, {Predicates} from './predicates.js';

type Optionalify<P> = P extends BasePredicate<infer X>
? P & BasePredicate<X | undefined>
Expand Down
6 changes: 3 additions & 3 deletions source/operators/not.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import randomId from '../utils/random-id';
import {validatorSymbol} from '../predicates/predicate';
import type {Predicate, Validator} from '../predicates/predicate';
import randomId from '../utils/random-id.js';
import {validatorSymbol} from '../predicates/predicate.js';
import type {Predicate, Validator} from '../predicates/predicate.js';

/**
Operator which inverts the following validation.
Expand Down
36 changes: 18 additions & 18 deletions source/predicates.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {TypedArray} from 'type-fest';
import {StringPredicate} from './predicates/string';
import {NumberPredicate} from './predicates/number';
import {BigIntPredicate} from './predicates/bigint';
import {BooleanPredicate} from './predicates/boolean';
import {Predicate, PredicateOptions} from './predicates/predicate';
import {ArrayPredicate} from './predicates/array';
import {ObjectPredicate, Shape} from './predicates/object';
import {DatePredicate} from './predicates/date';
import {ErrorPredicate} from './predicates/error';
import {MapPredicate} from './predicates/map';
import {WeakMapPredicate} from './predicates/weak-map';
import {SetPredicate} from './predicates/set';
import {WeakSetPredicate} from './predicates/weak-set';
import {TypedArrayPredicate} from './predicates/typed-array';
import {ArrayBufferPredicate} from './predicates/array-buffer';
import {DataViewPredicate} from './predicates/data-view';
import {BasePredicate} from './predicates/base-predicate';
import {AnyPredicate} from './predicates/any';
import {StringPredicate} from './predicates/string.js';
import {NumberPredicate} from './predicates/number.js';
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 {DatePredicate} from './predicates/date.js';
import {ErrorPredicate} from './predicates/error.js';
import {MapPredicate} from './predicates/map.js';
import {WeakMapPredicate} from './predicates/weak-map.js';
import {SetPredicate} from './predicates/set.js';
import {WeakSetPredicate} from './predicates/weak-set.js';
import {TypedArrayPredicate} from './predicates/typed-array.js';
import {ArrayBufferPredicate} from './predicates/array-buffer.js';
import {DataViewPredicate} from './predicates/data-view.js';
import {BasePredicate} from './predicates/base-predicate.js';
import {AnyPredicate} from './predicates/any.js';

export interface Predicates {
/**
Expand Down
10 changes: 5 additions & 5 deletions source/predicates/any.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {ArgumentError} from '../argument-error';
import {BasePredicate, testSymbol} from './base-predicate';
import {PredicateOptions} from './predicate';
import {Main} from '..';
import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message';
import {ArgumentError} from '../argument-error.js';
import {BasePredicate, testSymbol} from './base-predicate.js';
import {PredicateOptions} from './predicate.js';
import {Main} from '../index.js';
import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js';

/**
@hidden
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/array-buffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate} from './predicate';
import {Predicate} from './predicate.js';

export class ArrayBufferPredicate<T extends ArrayBufferLike> extends Predicate<T> {
/**
Expand Down
12 changes: 6 additions & 6 deletions source/predicates/array.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import isEqual = require('lodash.isequal');
import {BasePredicate} from './base-predicate';
import {Predicate, PredicateOptions} from './predicate';
import {Shape} from './object';
import {exact} from '../utils/match-shape';
import ofType from '../utils/of-type';
import isEqual from 'lodash.isequal';
import {BasePredicate} from './base-predicate.js';
import {Predicate, PredicateOptions} from './predicate.js';
import {Shape} from './object.js';
import {exact} from '../utils/match-shape.js';
import ofType from '../utils/of-type.js';

export class ArrayPredicate<T = unknown> extends Predicate<T[]> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/base-predicate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Main} from '..';
import {Main} from '../index.js';

/**
@hidden
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/bigint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class BigIntPredicate extends Predicate<bigint> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class BooleanPredicate extends Predicate<boolean> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/data-view.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class DataViewPredicate extends Predicate<DataView> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/date.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class DatePredicate extends Predicate<Date> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class ErrorPredicate extends Predicate<Error> {
/**
Expand Down
8 changes: 4 additions & 4 deletions source/predicates/map.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isEqual = require('lodash.isequal');
import hasItems from '../utils/has-items';
import ofType from '../utils/of-type';
import {Predicate, PredicateOptions} from './predicate';
import isEqual from 'lodash.isequal';
import hasItems from '../utils/has-items.js';
import ofType from '../utils/of-type.js';
import {Predicate, PredicateOptions} from './predicate.js';

export class MapPredicate<T1 = unknown, T2 = unknown> extends Predicate<Map<T1, T2>> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/number.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import is from '@sindresorhus/is';
import {Predicate, PredicateOptions} from './predicate';
import {Predicate, PredicateOptions} from './predicate.js';

export class NumberPredicate extends Predicate<number> {
/**
Expand Down
16 changes: 8 additions & 8 deletions source/predicates/object.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import is from '@sindresorhus/is';

import dotProp = require('dot-prop');
import isEqual = require('lodash.isequal');
import hasItems from '../utils/has-items';
import ofType from '../utils/of-type';
import ofTypeDeep from '../utils/of-type-deep';
import {partial, exact, Shape, TypeOfShape} from '../utils/match-shape';
import {Predicate, PredicateOptions} from './predicate';
import {BasePredicate} from './base-predicate';
import dotProp from 'dot-prop';
import isEqual from 'lodash.isequal';
import hasItems from '../utils/has-items.js';
import ofType from '../utils/of-type.js';
import ofTypeDeep from '../utils/of-type-deep.js';
import {partial, exact, Shape, TypeOfShape} from '../utils/match-shape.js';
import {Predicate, PredicateOptions} from './predicate.js';
import {BasePredicate} from './base-predicate.js';

export {Shape};

Expand Down
10 changes: 5 additions & 5 deletions source/predicates/predicate.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import is from '@sindresorhus/is';
import {ArgumentError} from '../argument-error';
import {not} from '../operators/not';
import {BasePredicate, testSymbol} from './base-predicate';
import {Main} from '..';
import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message';
import {ArgumentError} from '../argument-error.js';
import {not} from '../operators/not.js';
import {BasePredicate, testSymbol} from './base-predicate.js';
import {Main} from '../index.js';
import {generateArgumentErrorMessage} from '../utils/generate-argument-error-message.js';

/**
Function executed when the provided validation fails.
Expand Down
8 changes: 4 additions & 4 deletions source/predicates/set.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import isEqual = require('lodash.isequal');
import hasItems from '../utils/has-items';
import ofType from '../utils/of-type';
import {Predicate, PredicateOptions} from './predicate';
import isEqual from 'lodash.isequal';
import hasItems from '../utils/has-items.js';
import ofType from '../utils/of-type.js';
import {Predicate, PredicateOptions} from './predicate.js';

export class SetPredicate<T = any> extends Predicate<Set<T>> {
/**
Expand Down
4 changes: 2 additions & 2 deletions source/predicates/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import valiDate = require('vali-date');
import {Predicate, PredicateOptions} from './predicate';
import valiDate from 'vali-date';
import {Predicate, PredicateOptions} from './predicate.js';

export class StringPredicate extends Predicate<string> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/predicates/typed-array.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {TypedArray} from 'type-fest';
import {Predicate} from './predicate';
import {Predicate} from './predicate.js';

export class TypedArrayPredicate<T extends TypedArray> extends Predicate<T> {
/**
Expand Down
4 changes: 2 additions & 2 deletions source/predicates/weak-map.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hasItems from '../utils/has-items';
import {Predicate, PredicateOptions} from './predicate';
import hasItems from '../utils/has-items.js';
import {Predicate, PredicateOptions} from './predicate.js';

export class WeakMapPredicate<KeyType extends object = object> extends Predicate<WeakMap<KeyType, unknown>> {
/**
Expand Down
4 changes: 2 additions & 2 deletions source/predicates/weak-set.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import hasItems from '../utils/has-items';
import {Predicate, PredicateOptions} from './predicate';
import hasItems from '../utils/has-items.js';
import {Predicate, PredicateOptions} from './predicate.js';

export class WeakSetPredicate<T extends object = object> extends Predicate<WeakSet<T>> {
/**
Expand Down
2 changes: 1 addition & 1 deletion source/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {testSymbol, BasePredicate} from './predicates/base-predicate';
import {testSymbol, BasePredicate} from './predicates/base-predicate.js';

/**
Validate the value against the provided predicate.
Expand Down
4 changes: 2 additions & 2 deletions source/utils/infer-label.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import {CallSite} from 'callsites';
import isValidIdentifier from './is-valid-identifier';
import isNode from './node/is-node';
import isValidIdentifier from './is-valid-identifier.js';
import isNode from './node/is-node.js';

// Regex to extract the label out of the `ow` function call
const labelRegex = /^.*?\((?<label>.*?)[,)]/;
Expand Down
6 changes: 3 additions & 3 deletions source/utils/match-shape.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import is from '@sindresorhus/is';
import test from '../test';
import {isPredicate} from '../predicates/base-predicate';
import {BasePredicate} from '..';
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 {
Expand Down
4 changes: 2 additions & 2 deletions source/utils/of-type-deep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import is from '@sindresorhus/is';
import {Predicate} from '../predicates/predicate';
import test from '../test';
import {Predicate} from '../predicates/predicate.js';
import test from '../test.js';

const ofTypeDeep = (object: unknown, predicate: Predicate): boolean => {
if (!is.plainObject(object)) {
Expand Down
4 changes: 2 additions & 2 deletions source/utils/of-type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from '../test';
import {BasePredicate} from '../predicates/base-predicate';
import test from '../test.js';
import {BasePredicate} from '../predicates/base-predicate.js';

/**
Test all the values in the collection against a provided predicate.
Expand Down