From 1d3e26cafb8b7db03eba49d6142f6c56147ab394 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Thu, 27 Jul 2023 18:57:41 +0200 Subject: [PATCH] Add native ESM support --- package.json | 16 +++++++++++----- src/every.spec.ts | 4 ++-- src/every.ts | 2 +- src/every_strict.spec.ts | 4 ++-- src/every_strict.ts | 2 +- src/filter.spec.ts | 4 ++-- src/filter.ts | 2 +- src/filter_strict.spec.ts | 4 ++-- src/filter_strict.ts | 2 +- src/find.spec.ts | 4 ++-- src/find.ts | 2 +- src/findIndex.spec.ts | 4 ++-- src/findIndex.ts | 2 +- src/forEach.spec.ts | 4 ++-- src/forEach.ts | 2 +- src/forEach_strict.spec.ts | 4 ++-- src/forEach_strict.ts | 2 +- src/index.spec.ts | 2 +- src/index.ts | 26 +++++++++++++------------- src/map.spec.ts | 4 ++-- src/map_strict.spec.ts | 4 ++-- src/reduce.spec.ts | 4 ++-- src/reduce.ts | 2 +- src/some.spec.ts | 4 ++-- src/some.ts | 2 +- src/some_strict.spec.ts | 4 ++-- src/some_strict.ts | 2 +- 27 files changed, 62 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index 14c48c8..1b777db 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,21 @@ "name": "@wojtekmaj/async-array-utils", "version": "1.7.0", "description": "A collection of array-related async utilities.", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "source": "src/index.ts", - "types": "dist/cjs/index.d.ts", + "type": "module", "sideEffects": false, + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "source": "./src/index.ts", + "types": "./dist/cjs/index.d.ts", + "exports": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, "scripts": { - "build": "yarn build-esm && yarn build-cjs", + "build": "yarn build-esm && yarn build-cjs && yarn build-cjs-package", "build-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext", "build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs", + "build-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json", "clean": "rimraf dist", "lint": "eslint .", "postinstall": "husky install", diff --git a/src/every.spec.ts b/src/every.spec.ts index 295cc99..45a0537 100644 --- a/src/every.spec.ts +++ b/src/every.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncEvery from './every'; +import asyncEvery from './every.js'; import { getTimer, @@ -8,7 +8,7 @@ import { largerThanOneHundredInRandomTime, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; function largerOrEqualThanZero(x: number) { return x >= 0; diff --git a/src/every.ts b/src/every.ts index e2b8383..24985f1 100644 --- a/src/every.ts +++ b/src/every.ts @@ -1,4 +1,4 @@ -import asyncForEach from './forEach'; +import asyncForEach from './forEach.js'; function asyncEvery( arr: T[], diff --git a/src/every_strict.spec.ts b/src/every_strict.spec.ts index 7f7cec8..694b877 100644 --- a/src/every_strict.spec.ts +++ b/src/every_strict.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncEveryStrict from './every_strict'; +import asyncEveryStrict from './every_strict.js'; import { doubleInputArr, @@ -11,7 +11,7 @@ import { makePushDuplicate, makePushDuplicateInRandomTime, throws, -} from '../test-utils'; +} from '../test-utils.js'; function largerOrEqualThanZero(x: number) { return x >= 0; diff --git a/src/every_strict.ts b/src/every_strict.ts index c8aed67..cbfa737 100644 --- a/src/every_strict.ts +++ b/src/every_strict.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncEveryStrict( arr: T[], diff --git a/src/filter.spec.ts b/src/filter.spec.ts index 93a3ab0..c565f1d 100644 --- a/src/filter.spec.ts +++ b/src/filter.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncFilter from './filter'; +import asyncFilter from './filter.js'; import { getTimer, @@ -8,7 +8,7 @@ import { largerThanTwoInRandomTime, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncFilter()', () => { it('example from README works as described', async () => { diff --git a/src/filter.ts b/src/filter.ts index b7fcbe8..3022b64 100644 --- a/src/filter.ts +++ b/src/filter.ts @@ -1,4 +1,4 @@ -import asyncForEach from './forEach'; +import asyncForEach from './forEach.js'; function asyncFilter( arr: T[], diff --git a/src/filter_strict.spec.ts b/src/filter_strict.spec.ts index 2733da8..20fc38f 100644 --- a/src/filter_strict.spec.ts +++ b/src/filter_strict.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncFilterStrict from './filter_strict'; +import asyncFilterStrict from './filter_strict.js'; import { doubleInputArr, @@ -11,7 +11,7 @@ import { makePushDuplicate, makePushDuplicateInRandomTime, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncFilterStrict()', () => { it('example from README works as described', async () => { diff --git a/src/filter_strict.ts b/src/filter_strict.ts index d18b7e5..18853d0 100644 --- a/src/filter_strict.ts +++ b/src/filter_strict.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncFilterStrict( arr: T[], diff --git a/src/find.spec.ts b/src/find.spec.ts index 45b90e8..b77bbda 100644 --- a/src/find.spec.ts +++ b/src/find.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncFind from './find'; +import asyncFind from './find.js'; import { getTimer, @@ -10,7 +10,7 @@ import { largerThanTwoInRandomTime, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo); diff --git a/src/find.ts b/src/find.ts index 1b145bf..cf995d9 100644 --- a/src/find.ts +++ b/src/find.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncFind( arr: T[], diff --git a/src/findIndex.spec.ts b/src/findIndex.spec.ts index 2bfd368..dfa4789 100644 --- a/src/findIndex.spec.ts +++ b/src/findIndex.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncFindIndex from './findIndex'; +import asyncFindIndex from './findIndex.js'; import { getTimer, @@ -10,7 +10,7 @@ import { largerThanTwoInRandomTime, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo); diff --git a/src/findIndex.ts b/src/findIndex.ts index 61f233a..4ccec48 100644 --- a/src/findIndex.ts +++ b/src/findIndex.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncFindIndex( arr: T[], diff --git a/src/forEach.spec.ts b/src/forEach.spec.ts index db7786f..1a696af 100644 --- a/src/forEach.spec.ts +++ b/src/forEach.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncForEach from './forEach'; +import asyncForEach from './forEach.js'; import { getTimer, @@ -8,7 +8,7 @@ import { makePushDuplicate, makePushDuplicateInRandomTime, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncForEach()', () => { it('example from README works as described', async () => { diff --git a/src/forEach.ts b/src/forEach.ts index 2f103ae..06fe726 100644 --- a/src/forEach.ts +++ b/src/forEach.ts @@ -1,4 +1,4 @@ -import asyncMap from './map'; +import asyncMap from './map.js'; export default function asyncForEach( arr: T[], diff --git a/src/forEach_strict.spec.ts b/src/forEach_strict.spec.ts index 7c37fa3..b728484 100644 --- a/src/forEach_strict.spec.ts +++ b/src/forEach_strict.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; import { doubleInputArr, getTimer, @@ -8,7 +8,7 @@ import { makePushDuplicate, makePushDuplicateInRandomTime, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncForEachStrict()', () => { it('example from README works as described', async () => { diff --git a/src/forEach_strict.ts b/src/forEach_strict.ts index f0e2924..0880d24 100644 --- a/src/forEach_strict.ts +++ b/src/forEach_strict.ts @@ -1,4 +1,4 @@ -import asyncMapStrict from './map_strict'; +import asyncMapStrict from './map_strict.js'; export default function asyncForEachStrict( arr: T[], diff --git a/src/index.spec.ts b/src/index.spec.ts index e1114a9..9fadd53 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -13,7 +13,7 @@ import { asyncReduce, asyncSome, asyncSomeStrict, -} from './index'; +} from './index.js'; describe('index', () => { it('has asyncFilter exported properly', () => { diff --git a/src/index.ts b/src/index.ts index 89561a3..b2c25f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,16 @@ -import asyncFilter from './filter'; -import asyncFilterStrict from './filter_strict'; -import asyncFind from './find'; -import asyncFindIndex from './findIndex'; -import asyncForEach from './forEach'; -import asyncForEachStrict from './forEach_strict'; -import asyncEvery from './every'; -import asyncEveryStrict from './every_strict'; -import asyncMap from './map'; -import asyncMapStrict from './map_strict'; -import asyncReduce from './reduce'; -import asyncSome from './some'; -import asyncSomeStrict from './some_strict'; +import asyncFilter from './filter.js'; +import asyncFilterStrict from './filter_strict.js'; +import asyncFind from './find.js'; +import asyncFindIndex from './findIndex.js'; +import asyncForEach from './forEach.js'; +import asyncForEachStrict from './forEach_strict.js'; +import asyncEvery from './every.js'; +import asyncEveryStrict from './every_strict.js'; +import asyncMap from './map.js'; +import asyncMapStrict from './map_strict.js'; +import asyncReduce from './reduce.js'; +import asyncSome from './some.js'; +import asyncSomeStrict from './some_strict.js'; export { asyncFilter, diff --git a/src/map.spec.ts b/src/map.spec.ts index 2f090f8..3280bf4 100644 --- a/src/map.spec.ts +++ b/src/map.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncMap from './map'; +import asyncMap from './map.js'; import { doubleInputArr, @@ -9,7 +9,7 @@ import { inputArr, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncMap()', () => { it('example from README works as described', async () => { diff --git a/src/map_strict.spec.ts b/src/map_strict.spec.ts index cf77d88..3a52ae3 100644 --- a/src/map_strict.spec.ts +++ b/src/map_strict.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncMapStrict from './map_strict'; +import asyncMapStrict from './map_strict.js'; import { doubleInputArr, @@ -11,7 +11,7 @@ import { makePushDuplicate, makePushDuplicateInRandomTime, throws, -} from '../test-utils'; +} from '../test-utils.js'; describe('asyncMapStrict()', () => { it('example from README works as described', async () => { diff --git a/src/reduce.spec.ts b/src/reduce.spec.ts index 7792403..9b6c174 100644 --- a/src/reduce.spec.ts +++ b/src/reduce.spec.ts @@ -1,7 +1,7 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncReduce from './reduce'; +import asyncReduce from './reduce.js'; -import { getTimer, makeDelayed, throws } from '../test-utils'; +import { getTimer, makeDelayed, throws } from '../test-utils.js'; describe('asyncReduce()', () => { it('example from README works as described', async () => { diff --git a/src/reduce.ts b/src/reduce.ts index 55d6c8a..9300247 100644 --- a/src/reduce.ts +++ b/src/reduce.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncReduce( arr: T[], diff --git a/src/some.spec.ts b/src/some.spec.ts index 9444fac..8f3b662 100644 --- a/src/some.spec.ts +++ b/src/some.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncSome from './some'; +import asyncSome from './some.js'; import { inputArr, @@ -10,7 +10,7 @@ import { getTimer, makeDelayed, throws, -} from '../test-utils'; +} from '../test-utils.js'; const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo); diff --git a/src/some.ts b/src/some.ts index 8735972..7867aa7 100644 --- a/src/some.ts +++ b/src/some.ts @@ -1,4 +1,4 @@ -import asyncForEach from './forEach'; +import asyncForEach from './forEach.js'; function asyncSome( arr: T[], diff --git a/src/some_strict.spec.ts b/src/some_strict.spec.ts index 837603d..d4686c7 100644 --- a/src/some_strict.spec.ts +++ b/src/some_strict.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest'; -import asyncSomeStrict from './some_strict'; +import asyncSomeStrict from './some_strict.js'; import { doubleInputArr, @@ -13,7 +13,7 @@ import { makeDelayed, getTimer, throws, -} from '../test-utils'; +} from '../test-utils.js'; const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo); diff --git a/src/some_strict.ts b/src/some_strict.ts index a0043ba..4ad26f9 100644 --- a/src/some_strict.ts +++ b/src/some_strict.ts @@ -1,4 +1,4 @@ -import asyncForEachStrict from './forEach_strict'; +import asyncForEachStrict from './forEach_strict.js'; function asyncSomeStrict( arr: T[],