diff --git a/.gitignore b/.gitignore index c964f38..62de83e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules lib -es yarn-error.log .idea diff --git a/package.json b/package.json index 9a9ed4e..e66658c 100644 --- a/package.json +++ b/package.json @@ -14,20 +14,17 @@ ], "repository": "deeplay-io/abort-controller-x", "sideEffects": false, - "main": "lib/index.js", - "module": "es/index.js", - "typings": "lib/index.d.ts", + "type": "module", + "exports": "./lib/index.js", + "typings": "./lib/index.d.ts", "files": [ "src", - "lib", - "es" + "lib" ], "scripts": { - "clean": "rimraf lib es", + "clean": "rimraf lib", "test": "jest", - "build:lib": "tsc -P tsconfig.build.json", - "build:es": "tsc -P tsconfig.es.json", - "build": "npm run build:lib && npm run build:es", + "build": "tsc -P tsconfig.build.json", "prepublishOnly": "npm test && npm run clean && npm run build" }, "author": "Daniel Lytkin ", diff --git a/src/AbortError.test.ts b/src/AbortError.test.ts index 951f507..f5d8e3c 100644 --- a/src/AbortError.test.ts +++ b/src/AbortError.test.ts @@ -4,7 +4,7 @@ import { isAbortError, rethrowAbortError, throwIfAborted, -} from './AbortError'; +} from './AbortError.js'; test('isAbortError', () => { expect(isAbortError({})).toBe(false); diff --git a/src/abortable.test.ts b/src/abortable.test.ts index b38871d..47c3de4 100644 --- a/src/abortable.test.ts +++ b/src/abortable.test.ts @@ -1,5 +1,5 @@ -import {abortable} from './abortable'; -import {nextTick} from './utils/nextTick'; +import {abortable} from './abortable.js'; +import {nextTick} from './utils/nextTick.js'; test('abortable endless promise', async () => { const abortController = new AbortController(); diff --git a/src/abortable.ts b/src/abortable.ts index 82c9b67..f3349f8 100644 --- a/src/abortable.ts +++ b/src/abortable.ts @@ -1,4 +1,4 @@ -import {execute} from './execute'; +import {execute} from './execute.js'; /** * Wrap a promise to reject with `AbortError` once `signal` is aborted. diff --git a/src/all.test.ts b/src/all.test.ts index 3479c86..f8f6c42 100644 --- a/src/all.test.ts +++ b/src/all.test.ts @@ -1,7 +1,7 @@ import defer = require('defer-promise'); -import {AbortError} from './AbortError'; -import {all} from './all'; -import {nextTick} from './utils/nextTick'; +import {AbortError} from './AbortError.js'; +import {all} from './all.js'; +import {nextTick} from './utils/nextTick.js'; test('external abort', async () => { const abortController = new AbortController(); diff --git a/src/all.ts b/src/all.ts index a93779d..a8c2874 100644 --- a/src/all.ts +++ b/src/all.ts @@ -1,4 +1,4 @@ -import {AbortError, isAbortError} from './AbortError'; +import {AbortError, isAbortError} from './AbortError.js'; /** * Abortable version of `Promise.all`. diff --git a/src/delay.ts b/src/delay.ts index cab9052..16e2e33 100644 --- a/src/delay.ts +++ b/src/delay.ts @@ -1,4 +1,4 @@ -import {execute} from './execute'; +import {execute} from './execute.js'; /** * Returns a promise that fulfills after delay and rejects with diff --git a/src/execute.test.ts b/src/execute.test.ts index 531b56a..2e4a7ca 100644 --- a/src/execute.test.ts +++ b/src/execute.test.ts @@ -1,6 +1,6 @@ import defer = require('defer-promise'); -import {execute} from './execute'; -import {nextTick} from './utils/nextTick'; +import {execute} from './execute.js'; +import {nextTick} from './utils/nextTick.js'; test('resolve immediately', async () => { const abortController = new AbortController(); diff --git a/src/execute.ts b/src/execute.ts index 2f6c488..f69fc27 100644 --- a/src/execute.ts +++ b/src/execute.ts @@ -1,4 +1,4 @@ -import {AbortError} from './AbortError'; +import {AbortError} from './AbortError.js'; /** * Similar to `new Promise(executor)`, but allows executor to return abort diff --git a/src/forever.test.ts b/src/forever.test.ts index c4d5f25..c9ea1e9 100644 --- a/src/forever.test.ts +++ b/src/forever.test.ts @@ -1,5 +1,5 @@ -import {forever} from './forever'; -import {nextTick} from './utils/nextTick'; +import {forever} from './forever.js'; +import {nextTick} from './utils/nextTick.js'; test('forever', async () => { const abortController = new AbortController(); diff --git a/src/forever.ts b/src/forever.ts index bca7965..5cbf3a9 100644 --- a/src/forever.ts +++ b/src/forever.ts @@ -1,4 +1,4 @@ -import {execute} from './execute'; +import {execute} from './execute.js'; /** * Return a promise that never fulfills and only rejects with `AbortError` once diff --git a/src/index.ts b/src/index.ts index 2b88563..3990e6a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ -export * from './abortable'; -export * from './AbortError'; -export * from './delay'; -export * from './execute'; -export * from './forever'; -export * from './waitForEvent'; -export * from './all'; -export * from './race'; -export * from './retry'; -export * from './spawn'; -export * from './run'; +export * from './abortable.js'; +export * from './AbortError.js'; +export * from './delay.js'; +export * from './execute.js'; +export * from './forever.js'; +export * from './waitForEvent.js'; +export * from './all.js'; +export * from './race.js'; +export * from './retry.js'; +export * from './spawn.js'; +export * from './run.js'; diff --git a/src/race.test.ts b/src/race.test.ts index 43e1ca5..5ec42a2 100644 --- a/src/race.test.ts +++ b/src/race.test.ts @@ -1,7 +1,7 @@ import defer = require('defer-promise'); -import {AbortError} from './AbortError'; -import {race} from './race'; -import {nextTick} from './utils/nextTick'; +import {AbortError} from './AbortError.js'; +import {race} from './race.js'; +import {nextTick} from './utils/nextTick.js'; test('external abort', async () => { const abortController = new AbortController(); diff --git a/src/race.ts b/src/race.ts index 741dced..2e8405f 100644 --- a/src/race.ts +++ b/src/race.ts @@ -1,4 +1,4 @@ -import {AbortError, isAbortError} from './AbortError'; +import {AbortError, isAbortError} from './AbortError.js'; /** * Abortable version of `Promise.race`. diff --git a/src/retry.ts b/src/retry.ts index 5630cc6..5d7ab55 100644 --- a/src/retry.ts +++ b/src/retry.ts @@ -1,5 +1,5 @@ -import {delay} from './delay'; -import {rethrowAbortError} from './AbortError'; +import {delay} from './delay.js'; +import {rethrowAbortError} from './AbortError.js'; export type RetryOptions = { /** diff --git a/src/run.ts b/src/run.ts index 3e9eab1..b53d8eb 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,4 +1,4 @@ -import {catchAbortError} from './AbortError'; +import {catchAbortError} from './AbortError.js'; /** * Invokes an abortable function with implicitly created `AbortSignal`. diff --git a/src/spawn.test.ts b/src/spawn.test.ts index acfcf46..c11ac2a 100644 --- a/src/spawn.test.ts +++ b/src/spawn.test.ts @@ -1,6 +1,6 @@ -import {spawn} from './spawn'; -import {forever} from './forever'; -import {delay} from './delay'; +import {spawn} from './spawn.js'; +import {forever} from './forever.js'; +import {delay} from './delay.js'; test('fork manual abort', async () => { const abortController = new AbortController(); diff --git a/src/spawn.ts b/src/spawn.ts index cca1fe8..bc5d7b0 100644 --- a/src/spawn.ts +++ b/src/spawn.ts @@ -1,4 +1,4 @@ -import {AbortError, catchAbortError, isAbortError} from './AbortError'; +import {AbortError, catchAbortError, isAbortError} from './AbortError.js'; export type SpawnEffects = { /** diff --git a/src/waitForEvent.test.ts b/src/waitForEvent.test.ts index e7c4205..e0f6724 100644 --- a/src/waitForEvent.test.ts +++ b/src/waitForEvent.test.ts @@ -1,5 +1,5 @@ -import {nextTick} from './utils/nextTick'; -import {waitForEvent} from './waitForEvent'; +import {nextTick} from './utils/nextTick.js'; +import {waitForEvent} from './waitForEvent.js'; test('external abort', async () => { const abortController = new AbortController(); diff --git a/src/waitForEvent.ts b/src/waitForEvent.ts index 9fba66b..4001eb7 100644 --- a/src/waitForEvent.ts +++ b/src/waitForEvent.ts @@ -1,4 +1,4 @@ -import {execute} from './execute'; +import {execute} from './execute.js'; export type EventTargetLike = | EventTargetLike.HasEventTargetAddRemove diff --git a/tsconfig.es.json b/tsconfig.es.json deleted file mode 100644 index 8423c0a..0000000 --- a/tsconfig.es.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "module": "es6", - "outDir": "es" - }, - "exclude": [ - "src/**/*.test.ts" - ] -} diff --git a/tsconfig.json b/tsconfig.json index 371940e..363cd79 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,8 @@ "compilerOptions": { "target": "es2020", "lib": ["es2020", "dom"], - "module": "commonjs", - "moduleResolution": "node", + "module": "Node16", + "moduleResolution": "Node16", "outDir": "lib", "sourceMap": true, "declaration": true, @@ -11,6 +11,5 @@ "noImplicitReturns": true, "noUnusedLocals": true }, - "files": ["src/index.ts"], - "include": ["src/**/*.test.ts"] + "include": ["src"] }