Skip to content

Commit c9062bf

Browse files
committed
chore(types): add type check [skip ci]
1 parent 54ff3d0 commit c9062bf

File tree

10 files changed

+83
-23
lines changed

10 files changed

+83
-23
lines changed

.huskyrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"hooks": {
3-
"pre-commit": "lint-staged",
3+
"pre-commit": "npm run ts-compile-check && lint-staged",
44
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
55
}
66
}

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "src/index.js",
66
"scripts": {
77
"lint": "prettier-standard --lint '{src,test}/**/*.js'",
8+
"ts-compile-check": "tsc -p tsconfig.json --noEmit",
89
"test": "nyc mocha test"
910
},
1011
"engines": {
@@ -37,6 +38,7 @@
3738
"@types/chai": "4.2.12",
3839
"@types/mocha": "8.0.3",
3940
"@types/node": "12.12.55",
41+
"@types/semantic-release": "17.1.0",
4042
"chai": "4.2.0",
4143
"eslint": "7.8.1",
4244
"eslint-plugin-array-func": "3.1.7",
@@ -57,7 +59,8 @@
5759
"semantic-release": "17.1.1",
5860
"sinon": "9.0.3",
5961
"stream-buffers": "3.0.2",
60-
"tempy": "0.6.0"
62+
"tempy": "0.6.0",
63+
"typescript": "4.0.2"
6164
},
6265
"peerDependencies": {
6366
"semantic-release": ">=11.0.0 <18.0.0"

src/errors.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
/**
2-
* @typedef {import('semantic-release').Context} Context
2+
* @typedef {import('./types').Context} Context
3+
* @typedef {import('./types').SemanticReleaseError} SemanticReleaseError
34
*/
5+
6+
const pkg = require('../package.json')
7+
8+
const [homepage] = pkg.homepage.split('#')
9+
/* eslint-disable no-unused-vars */
410
/**
5-
* @typedef {Object} SemanticReleaseError
6-
* @property {string} message -
7-
* @property {string} details -
11+
* @param {string} file -
12+
* @returns {string} -
13+
* @example
14+
* const link = linkify(href)
815
*/
16+
const linkify = file => `${homepage}/blob/master/${file}`
17+
/* eslint-enable no-unused-vars */
918

1019
module.exports = new Map([
1120
[
@@ -14,7 +23,7 @@ module.exports = new Map([
1423
* @param {Context} ctx -
1524
* @returns {SemanticReleaseError} -
1625
*/
17-
(ctx) => ({
26+
ctx => ({
1827
message: 'A custom message.',
1928
details: 'A custom description.'
2029
})

src/get-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
const SemanticReleaseError = require('@semantic-release/error')
22
const ERROR_DEFINITIONS = require('./errors')
33

4-
/** @typedef {import('semantic-release').Context} Context */
4+
/** @typedef {import('./types').Context} Context */
55
/**
66
* @param {string} code -
77
* @param {Context} ctx -
88
* @returns {Error} -
99
* @example
1010
* const throw getError('CUSTOMERROR')
1111
*/
12-
module.exports = (code, ctx = {}) => {
12+
module.exports = (code, ctx) => {
1313
const { message, details } = ERROR_DEFINITIONS.get(code)(ctx)
1414
return new SemanticReleaseError(message, code, details)
1515
}

src/publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('semantic-release').Context} Context
3-
* @typedef {import('semantic-release').Config} Config
2+
* @typedef {import('./types').Context} Context
3+
* @typedef {import('./types').Config} Config
44
*/
55
/**
66
* @param {Config} pluginConfig -

src/types.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {
2+
Config as SemanticReleaseConfig,
3+
Context as SemanticReleaseContext,
4+
Result as SemanticReleaseResult
5+
} from 'semantic-release'
6+
7+
export interface Context
8+
extends SemanticReleaseContext,
9+
SemanticReleaseConfig,
10+
SemanticReleaseResult {}
11+
12+
export interface Config {}
13+
14+
export interface SemanticReleaseError {
15+
message: string
16+
details: string
17+
}

src/verify.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const getError = require('./get-error')
22

33
/**
4-
* @typedef {import('semantic-release').Context} Context
5-
* @typedef {import('semantic-release').Config} Config
4+
* @typedef {import('./types').Context} Context
5+
* @typedef {import('./types').Config} Config
66
*/
77
/**
88
* @param {Config} pluginConfig -
@@ -13,6 +13,6 @@ const getError = require('./get-error')
1313
*/
1414
module.exports = (pluginConfig, ctx) => {
1515
if (!ctx.env.CUSTOM_ENV) {
16-
throw getError('CUSTOMERROR')
16+
throw getError('CUSTOMERROR', ctx)
1717
}
1818
}

test/verify.test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
const { describe, it, before } = require('mocha')
1+
const { describe, it } = require('mocha')
22
const { expect } = require('chai')
33
const tempy = require('tempy')
44
const verify = require('../src/verify')
55

66
describe('Verify', () => {
7-
let cwd
8-
9-
before(() => {
10-
cwd = tempy.directory()
11-
})
7+
/** @type {import('../src/types').Context} */
8+
const ctx = {
9+
cwd: tempy.directory(),
10+
env: {},
11+
logger: { log: () => ({}), error: () => ({}) }
12+
}
1213

1314
it('Return SemanticReleaseError if a custom environment variable is not defined', async () => {
1415
try {
15-
await verify({}, { cwd, env: {} })
16+
await verify({}, ctx)
1617
} catch (err) {
1718
expect(err.name).to.equal('SemanticReleaseError')
1819
expect(err.code).to.equal('CUSTOMERROR')
1920
}
2021
})
2122

2223
it('Verify alias from a custom environmen variable', async () => {
23-
const env = { CUSTOM_ENV: 'custom' }
24-
expect(await verify({}, { cwd, env })).to.be.a('undefined')
24+
ctx.env = { CUSTOM_ENV: 'custom' }
25+
expect(await verify({}, ctx)).to.be.a('undefined')
2526
})
2627
})

tsconfig.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"lib": [ "es2017", "es7" ],
4+
"allowJs": true,
5+
"checkJs": true,
6+
"downlevelIteration": true,
7+
"outDir": "build",
8+
"skipLibCheck": true,
9+
"resolveJsonModule": true
10+
},
11+
"exclude": [
12+
"node_modules",
13+
"coverage"
14+
]
15+
}

0 commit comments

Comments
 (0)