Skip to content

Commit

Permalink
feat: add types (#2)
Browse files Browse the repository at this point in the history
Add types and typecheck in ci
  • Loading branch information
achingbrain authored Feb 3, 2021
1 parent 5ec37fe commit 20454bf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir lint
- uses: gozala/[email protected]
- run: npx aegir build
- run: npx aegir dep-check
test-node:
needs: check
runs-on: ${{ matrix.os }}
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "1.0.0",
"description": "Returns native AbortController/AbortSignal if available or the abort-controller module if not",
"main": "src/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "aegir test -t node -t browser -t webworker -t electron-main -t electron-renderer",
"lint": "aegir lint",
"prepare": "aegir build --no-bundle",
"release": "aegir release --docs false",
"release-minor": "aegir release --type minor --docs false",
"release-major": "aegir release --type major --docs false"
Expand All @@ -16,9 +18,6 @@
"type": "git",
"url": "git+https://github.com/achingbrain/native-abort-controller.git"
},
"dependencies": {
"globalthis": "^1.0.1"
},
"peerDependencies": {
"abort-controller": "*"
},
Expand Down
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const globalThis = require('globalthis')()
let impl

if (globalThis.AbortController && globalThis.AbortSignal) {
Expand Down
25 changes: 12 additions & 13 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
const { expect } = require('aegir/utils/chai')
const { AbortController: NativeAbortController } = require('../src')
const { AbortController: AbortControllerPollyfill } = require('abort-controller')
const globalthis = require('globalthis')()

let nodeVersion

if (globalthis.process && globalthis.process.version) {
nodeVersion = parseInt(globalthis.process.version.match(/v(\d+)\./)[1], 10)
if (globalThis.process && globalThis.process.version) {
nodeVersion = parseInt(globalThis.process.version.match(/v(\d+)\./)[1], 10)
}

describe('env', function () {
Expand All @@ -18,34 +17,34 @@ describe('env', function () {
case 'electron-main':
expect(NativeAbortController).to.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(AbortControllerPollyfill)
expect(globalthis.AbortController).to.be.undefined()
expect(globalThis.AbortController).to.be.undefined()
break
case 'electron-renderer':
expect(NativeAbortController).to.not.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(globalthis.AbortController)
expect(globalthis.AbortController).to.be.ok()
expect(new NativeAbortController()).to.be.instanceOf(globalThis.AbortController)
expect(globalThis.AbortController).to.be.ok()
break
case 'node':
if (nodeVersion < 15) {
expect(NativeAbortController).to.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(AbortControllerPollyfill)
expect(globalthis.AbortController).to.be.undefined()
expect(globalThis.AbortController).to.be.undefined()
} else {
// node 15+ gets native AbortController
expect(NativeAbortController).to.not.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(globalthis.AbortController)
expect(globalthis.AbortController).to.be.ok()
expect(new NativeAbortController()).to.be.instanceOf(globalThis.AbortController)
expect(globalThis.AbortController).to.be.ok()
}
break
case 'browser':
expect(NativeAbortController).to.not.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(globalthis.AbortController)
expect(globalthis.AbortController).to.be.ok()
expect(new NativeAbortController()).to.be.instanceOf(globalThis.AbortController)
expect(globalThis.AbortController).to.be.ok()
break
case 'webworker':
expect(NativeAbortController).to.not.equal(AbortControllerPollyfill)
expect(new NativeAbortController()).to.be.instanceOf(globalthis.AbortController)
expect(globalthis.AbortController).to.be.ok()
expect(new NativeAbortController()).to.be.instanceOf(globalThis.AbortController)
expect(globalThis.AbortController).to.be.ok()
break
default:
expect.fail(`Could not detect env. Current env is ${process.env.AEGIR_RUNNER}`)
Expand Down
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
},
"include": [
"src"
]
}

0 comments on commit 20454bf

Please sign in to comment.