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

refactor: port load to typescript #786

Merged
merged 19 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[{.*rc,*.yml,*.md,package.json,lerna.json,*.svg}]
[{.*rc,*.yml,*.md,package.json,lerna.json,tsconfig.json,tsconfig.*.json,*.svg}]
indent_style = space

[*.md]
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import

const load = require('@commitlint/load');
import load from '@commitlint/load';
const lint = require('@commitlint/lint');
const read = require('@commitlint/read');
const meow = require('meow');
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/ensure/src/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as _ from 'lodash';

export default ensureCase;

type TargetCaseType =
export type TargetCaseType =
| 'camel-case'
| 'kebab-case'
| 'snake-case'
Expand Down
3 changes: 2 additions & 1 deletion @commitlint/ensure/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import ensureCase from './case';
import ensureCase, {TargetCaseType} from './case';
import ensureEnum from './enum';
import maxLength from './max-length';
import maxLineLength from './max-line-length';
import minLength from './min-length';
import notEmpty from './not-empty';

export {ensureCase as case};
export {TargetCaseType};
export {ensureEnum as enum};
export {maxLength, maxLineLength, minLength, notEmpty};
2 changes: 1 addition & 1 deletion @commitlint/execute-rule/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type ExecutedRule<T> = readonly [string, T];
export default execute;

export async function execute<T = unknown>(
rule: Rule<T>
rule?: Rule<T>
): Promise<ExecutedRule<T> | null> {
if (!Array.isArray(rule)) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion @commitlint/load/fixtures/basic/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
rules: {
basic: true
'body-case': [1, 'never', 'camel-case']
}
};
43 changes: 8 additions & 35 deletions @commitlint/load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,13 @@
"version": "8.2.0",
"description": "Load shared commitlint configuration",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib/"
],
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"deps": "dep-check",
"pkg": "pkg-check --skip-import",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose && ava \"src/*.serial-test.js\" --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
"pkg": "pkg-check --skip-import"
},
"engines": {
"node": ">=4"
Expand All @@ -56,21 +34,16 @@
},
"license": "MIT",
"devDependencies": {
"@commitlint/test": "^8.2.0",
"@commitlint/utils": "^8.2.0",
"ava": "0.22.0",
"babel-cli": "6.26.0",
"babel-preset-commitlint": "^8.2.0",
"babel-register": "6.26.0",
"concurrently": "3.6.1",
"cross-env": "5.1.1",
"execa": "0.11.0",
"globby": "10.0.1"
"@commitlint/test": "8.0.0",
"@commitlint/utils": "^8.1.0",
"@types/cosmiconfig": "5.0.3",
"@types/lodash": "4.14.136",
"@types/resolve-from": "^5.0.1",
"typescript": "3.5.3"
},
"dependencies": {
"@commitlint/execute-rule": "^8.2.0",
"@commitlint/resolve-extends": "^8.2.0",
"babel-runtime": "^6.23.0",
"chalk": "2.4.2",
"cosmiconfig": "^5.2.0",
"lodash": "4.17.15",
Expand Down
19 changes: 0 additions & 19 deletions @commitlint/load/src/index.serial-test.js

This file was deleted.

21 changes: 21 additions & 0 deletions @commitlint/load/src/index.serial.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as path from 'path';
import load from '.';

const {fix} = require('@commitlint/test');

const fixture = (name: string) => path.resolve(__dirname, '../fixtures', name);

test('default cwd option to process.cwd()', async () => {
const cwd = await fix.bootstrap(fixture('basic'));
const before = process.cwd();
process.chdir(cwd);

try {
const actual = await load();
expect(actual.rules['body-case']).toBeTruthy();
} catch (err) {
throw err;
} finally {
process.chdir(before);
}
});
Loading