From 061fa0ddb7d51f3b96d3a0f6a6bebb196f105a7b Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sat, 6 Apr 2019 07:09:09 +0000 Subject: [PATCH 1/2] Refactor TypeScript definition to CommonJS compatible export (#3) --- index.d.ts | 173 ++++++++++++++++++++++++++---------------------- index.js | 1 + index.test-d.ts | 24 ++++--- package.json | 8 +-- 4 files changed, 112 insertions(+), 94 deletions(-) diff --git a/index.d.ts b/index.d.ts index 27fd1de..7a9c892 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,93 +1,106 @@ -interface CommonOptions { - /** - * The issue body. - */ - readonly body?: string; +declare namespace newGithubIssueUrl { + interface CommonOptions { + /** + The issue body. + */ + readonly body?: string; - /** - * The issue title. - */ - readonly title?: string; + /** + The issue title. + */ + readonly title?: string; - /** - * Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository/). - * - * @example - * - * 'unicorn.md' // If you want to use a template at `ISSUE_TEMPLATE/unicorn.md`. - */ - readonly template?: string; + /** + Use an [issue template](https://help.github.com/articles/manually-creating-a-single-issue-template-for-your-repository/). - /** - * The labels for the issue. - * - * *Requires the user to have the permission to add labels.* - */ - readonly labels?: string[]; + @example + ``` + 'unicorn.md' // If you want to use a template at `ISSUE_TEMPLATE/unicorn.md`. + ``` + */ + readonly template?: string; - /** - * The milestone for the issue. - * - * *Requires the user to have the permission to add milestone.* - */ - readonly milestone?: string; + /** + The labels for the issue. - /** - * The user to assign to the issue. - * - * *Requires the user to have the permission to add assignee.* - */ - readonly assignee?: string; + _Requires the user to have the permission to add labels._ + */ + readonly labels?: string[]; - /** - * The projects to add the issue to. - * The project reference format is `user/`, for example, if the URL to the project is `https://github.com/sindresorhus/some-repo/projects/3`, the project reference would be `some-repo/3`. - * - * *Requires the user to have the permission to add projects.* - */ - readonly projects?: string[]; -} + /** + The milestone for the issue. + + _Requires the user to have the permission to add milestone._ + */ + readonly milestone?: string; + + /** + The user to assign to the issue. + + _Requires the user to have the permission to add assignee._ + */ + readonly assignee?: string; + + /** + The projects to add the issue to. + The project reference format is `user/`, for example, if the URL to the project is `https://github.com/sindresorhus/some-repo/projects/3`, the project reference would be `some-repo/3`. + + _Requires the user to have the permission to add projects._ + */ + readonly projects?: string[]; + } + + interface RepoUrlOptions extends CommonOptions { + /** + The full URL to the repo. + */ + readonly repoUrl: string; + } + + interface UserAndRepoOptions extends CommonOptions { + /** + GitHub username or organization. + */ + readonly user: string; + + /** + GitHub repo. + */ + readonly repo: string; + } -interface RepoUrlOptions extends CommonOptions { /** - * The full URL to the repo. - */ - readonly repoUrl: string; + You are required to either specify the `repoUrl` option or both the `user` and `repo` options. + */ + type Options = RepoUrlOptions | UserAndRepoOptions; } -interface UserAndRepoOptions extends CommonOptions { +declare const newGithubIssueUrl: { /** - * GitHub username or organization. - */ - readonly user: string; + Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields. - /** - * GitHub repo. - */ - readonly repo: string; -} + @example + ``` + import newGithubIssueUrl = require('new-github-issue-url'); + import opn = require('opn'); + + const url = newGithubIssueUrl({ + user: 'sindresorhus', + repo: 'new-github-issue-url', + body: '\n\n\n---\nI\'m a human. Please be nice.' + }); + //=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.' + + // Then open it + opn(url); + ``` + */ + (options: newGithubIssueUrl.Options): string; + + // TODO: Remove this for the next major release, refactor the whole definition to: + // declare function newGithubIssueUrl(options: newGithubIssueUrl.Options): string; + // export = newGithubIssueUrl; + default: typeof newGithubIssueUrl; +}; -/** - * You are required to either specify the `repoUrl` option or both the `user` and `repo` options. - */ -export type Options = RepoUrlOptions | UserAndRepoOptions - -/** - * Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields. - * - * @example - * - * import newGithubIssueUrl from 'new-github-issue-url'; - * import opn from 'opn'; - * - * const url = newGithubIssueUrl({ - * user: 'sindresorhus', - * repo: 'new-github-issue-url', - * body: '\n\n\n---\nI\'m a human. Please be nice.' - * }); - * //=> 'https://github.com/sindresorhus/new-github-issue-url/issues/new?body=%0A%0A%0A---%0AI%27m+a+human.+Please+be+nice.' - * - * // Then open it - * opn(url); - */ -export default function newGithubIssueUrl(options: Options): string; +export = newGithubIssueUrl; diff --git a/index.js b/index.js index 4b93114..dde2d3c 100644 --- a/index.js +++ b/index.js @@ -42,4 +42,5 @@ module.exports = (options = {}) => { return url.toString(); }; +// TODO: Remove this for the next major release module.exports.default = module.exports; diff --git a/index.test-d.ts b/index.test-d.ts index 226b487..c885b65 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,12 +1,16 @@ -import {expectType} from 'tsd-check'; -import newGithubIssueUrl from '.'; +import {expectType} from 'tsd'; +import newGithubIssueUrl = require('.'); -expectType(newGithubIssueUrl({ - repoUrl: 'https://github.com/sindresorhus/new-github-issue-url', - body: 'test' -})); +expectType( + newGithubIssueUrl({ + repoUrl: 'https://github.com/sindresorhus/new-github-issue-url', + body: 'test' + }) +); -expectType(newGithubIssueUrl({ - user: 'sindresorhus', - repo: 'new-github-issue-url' -})); +expectType( + newGithubIssueUrl({ + user: 'sindresorhus', + repo: 'new-github-issue-url' + }) +); diff --git a/package.json b/package.json index 4932381..546d140 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "node": ">=10" }, "scripts": { - "test": "xo && ava && tsd-check" + "test": "xo && ava && tsd" }, "files": [ "index.js", @@ -32,8 +32,8 @@ "params" ], "devDependencies": { - "ava": "^0.25.0", - "tsd-check": "^0.3.0", - "xo": "^0.23.0" + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" } } From 9f4856f8beb580e7ae9a90422765dc70676ff952 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 6 Apr 2019 14:13:01 +0700 Subject: [PATCH 2/2] 0.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 546d140..0e7f7d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "new-github-issue-url", - "version": "0.2.0", + "version": "0.2.1", "description": "Generate a URL for opening a new GitHub issue with prefilled title, body, and other fields", "license": "MIT", "repository": "sindresorhus/new-github-issue-url",