Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(types): publish type declarations #656

Merged
merged 1 commit into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { init } = require("./init");

module.exports.init = init;
6 changes: 2 additions & 4 deletions lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const packagePath = (elem, ...elems) => path.join(...[__dirname, "..", elem, ...

/**
* @param {string} baseDir
* @param {import("ybiq").Logger} logger
* @param {import("../types/ybiq").Logger} logger
*/
// eslint-disable-next-line max-lines-per-function
const initCommand = (baseDir, logger) => {
Expand Down Expand Up @@ -113,9 +113,7 @@ const initCommand = (baseDir, logger) => {
};
};

/**
* @param {import("ybiq").CommandParams} params
*/
/** @type {import("../types/ybiq").InitCommand} */
async function init({ cwd = process.cwd(), logger = defaultLogger } = {}) {
const cmd = initCommand(cwd, logger);

Expand Down
6 changes: 4 additions & 2 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { EOL } = require("os");

/** @type {import("ybiq").Logger} */
module.exports.defaultLogger = (msg) => process.stdout.write(`${msg}${EOL}`);
/** @type {import("../types/ybiq").Logger} */
module.exports.defaultLogger = (msg) => {
process.stdout.write(`${msg}${EOL}`);
};
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
"utility",
"tool"
],
"main": "index.js",
"main": "lib/index.js",
"bin": "bin/cli.js",
"types": "types/ybiq.d.ts",
"files": [
"bin",
"lib",
"types",
".editorconfig",
".remarkignore",
".github/workflows/commitlint.yml",
Expand Down Expand Up @@ -52,9 +54,10 @@
"typescript": "^3.9.7"
},
"scripts": {
"test": "nyc --check-coverage --lines 100 --branches 90 tape \"test/**/*.test.js\"",
"test": "nyc --check-coverage --lines 100 --branches 90 tape \"test/**/*.test.js\" && npm run test:types",
"test:watch": "nodemon --ext js,json --watch . --exec \"tape test/**/*.test.js\"",
"test:coverage": "nyc report --reporter=html",
"test:types": "tsc --project test/tsconfig.test.json --noEmit",
"lint:js": "eslint .",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:md": "remark . --frail",
Expand Down Expand Up @@ -132,15 +135,15 @@
"release",
"remark",
"standard-version",
"travis"
"types"
]
]
}
},
"eslintConfig": {
"root": true,
"ignorePatterns": [
"*.d.ts"
"*.ts"
],
"extends": [
"ybiquitous/node"
Expand Down
6 changes: 6 additions & 0 deletions test/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"strict": true
},
"include": ["./**/*.test.ts"]
}
6 changes: 6 additions & 0 deletions test/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as ybiq from "..";

ybiq.init().then(() => console.log("none"));
ybiq.init({ cwd: "lib" }).then(() => console.log("none"));
ybiq.init({ logger: (msg: string) => {} }).then(() => console.log("none"));
ybiq.init({ cwd: "lib", logger: (msg: string) => {} }).then(() => console.log("none"));
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
},
"include": ["lib", "types"]
"include": ["lib/**/*", "types/**/*"]
}
9 changes: 5 additions & 4 deletions types/ybiq.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
declare module "ybiq" {
type Logger = (msg: string) => any;
type CommandParams = { cwd?: string; logger?: Logger };
}
export type Logger = (msg: string) => void;
export type CommandParams = { cwd?: string; logger?: Logger };

export declare function init(params?: CommandParams): Promise<void>;
type InitCommand = typeof init;