From 8ca15451c92c46e1ffaf7fabf167ed7ee036158d Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Sun, 5 May 2019 18:39:25 +0200 Subject: [PATCH 1/2] build: simplify repo cleaning --- @commitlint/cli/package.json | 2 -- @commitlint/ensure/package.json | 4 +-- @commitlint/execute-rule/package.json | 4 +-- @commitlint/format/package.json | 4 +-- @commitlint/is-ignored/package.json | 4 +-- @commitlint/lint/package.json | 2 -- @commitlint/load/package.json | 4 +-- @commitlint/message/package.json | 4 +-- @commitlint/parse/package.json | 4 +-- @commitlint/prompt-cli/package.json | 1 - @commitlint/prompt/package.json | 1 - @commitlint/read/package.json | 4 +-- @commitlint/resolve-extends/package.json | 4 +-- @commitlint/rules/package.json | 4 +-- @commitlint/to-lines/package.json | 4 +-- @commitlint/top-level/package.json | 4 +-- @commitlint/travis-cli/package.json | 1 - .../babel-preset-commitlint/index.test.js | 27 ------------------- .../babel-preset-commitlint/package.json | 7 ----- @packages/test/package.json | 9 +------ README.md | 16 +++++------ package.json | 2 +- yarn.lock | 8 +----- 23 files changed, 24 insertions(+), 100 deletions(-) delete mode 100644 @packages/babel-preset-commitlint/index.test.js diff --git a/@commitlint/cli/package.json b/@commitlint/cli/package.json index e20bba9c7c..395f82d5b2 100644 --- a/@commitlint/cli/package.json +++ b/@commitlint/cli/package.json @@ -12,7 +12,6 @@ }, "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -66,7 +65,6 @@ "mkdirp": "0.5.1", "pkg-dir": "2.0.0", "resolve-bin": "0.4.0", - "rimraf": "2.6.2", "sander": "0.6.0", "string-to-stream": "1.1.0", "tmp": "0.1.0" diff --git a/@commitlint/ensure/package.json b/@commitlint/ensure/package.json index 0f2b680b6e..586dc5e7c2 100644 --- a/@commitlint/ensure/package.json +++ b/@commitlint/ensure/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,8 +64,7 @@ "babel-register": "6.26.0", "concurrently": "3.5.1", "cross-env": "5.1.1", - "globby": "8.0.1", - "rimraf": "2.6.1" + "globby": "8.0.1" }, "dependencies": { "lodash": "4.17.11" diff --git a/@commitlint/execute-rule/package.json b/@commitlint/execute-rule/package.json index 6a043c2510..0d908aa35c 100644 --- a/@commitlint/execute-rule/package.json +++ b/@commitlint/execute-rule/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,8 +64,7 @@ "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" }, "dependencies": { "babel-runtime": "6.26.0" diff --git a/@commitlint/format/package.json b/@commitlint/format/package.json index 36864fa428..a2efe6f0ae 100644 --- a/@commitlint/format/package.json +++ b/@commitlint/format/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "tsc", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"yarn test --watchAll\" \"yarn run watch\"", @@ -47,7 +46,8 @@ "jest": "24.8.0", "rimraf": "2.6.1", "ts-jest": "24.0.2", - "typescript": "3.4.5" + "typescript": "3.4.5", + "lodash": "4.17.11" }, "dependencies": { "chalk": "^2.0.1" diff --git a/@commitlint/is-ignored/package.json b/@commitlint/is-ignored/package.json index 7fa01f9f12..26a78194af 100644 --- a/@commitlint/is-ignored/package.json +++ b/@commitlint/is-ignored/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,8 +64,7 @@ "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" }, "dependencies": { "semver": "6.0.0" diff --git a/@commitlint/lint/package.json b/@commitlint/lint/package.json index b48a2ddd64..5300b47d1a 100644 --- a/@commitlint/lint/package.json +++ b/@commitlint/lint/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -67,7 +66,6 @@ "cross-env": "5.1.1", "execa": "0.9.0", "globby": "8.0.1", - "rimraf": "2.6.1", "proxyquire": "2.1.0" }, "dependencies": { diff --git a/@commitlint/load/package.json b/@commitlint/load/package.json index 0ee7803fd6..30b3e122ed 100644 --- a/@commitlint/load/package.json +++ b/@commitlint/load/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -66,8 +65,7 @@ "concurrently": "3.5.1", "cross-env": "5.1.1", "execa": "0.9.0", - "globby": "8.0.1", - "rimraf": "2.6.1" + "globby": "8.0.1" }, "dependencies": { "@commitlint/execute-rule": "^7.5.0", diff --git a/@commitlint/message/package.json b/@commitlint/message/package.json index 65206917d0..bda3ee88de 100644 --- a/@commitlint/message/package.json +++ b/@commitlint/message/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -64,7 +63,6 @@ "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" } } diff --git a/@commitlint/parse/package.json b/@commitlint/parse/package.json index 3b3ece9337..48c5b5c034 100644 --- a/@commitlint/parse/package.json +++ b/@commitlint/parse/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,8 +64,7 @@ "babel-register": "6.26.0", "concurrently": "3.5.1", "cross-env": "5.1.1", - "import-from": "3.0.0", - "rimraf": "2.6.1" + "import-from": "3.0.0" }, "dependencies": { "conventional-changelog-angular": "^1.3.3", diff --git a/@commitlint/prompt-cli/package.json b/@commitlint/prompt-cli/package.json index 3a25bfd754..108c2884bc 100644 --- a/@commitlint/prompt-cli/package.json +++ b/@commitlint/prompt-cli/package.json @@ -9,7 +9,6 @@ "commit": "./cli.js" }, "scripts": { - "clean": "npx rimraf lib", "commit": "$npm_package_bin_commit", "deps": "dep-check", "pkg": "pkg-check --skip-main", diff --git a/@commitlint/prompt/package.json b/@commitlint/prompt/package.json index f1fe3dedf0..61f60f2106 100644 --- a/@commitlint/prompt/package.json +++ b/@commitlint/prompt/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "commit": "git-cz", "deps": "dep-check", "pkg": "pkg-check --skip-import", diff --git a/@commitlint/read/package.json b/@commitlint/read/package.json index ae0104752d..10b887050e 100644 --- a/@commitlint/read/package.json +++ b/@commitlint/read/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,8 +64,7 @@ "babel-register": "6.26.0", "concurrently": "3.5.1", "cross-env": "5.1.1", - "execa": "0.9.0", - "rimraf": "2.6.1" + "execa": "0.9.0" }, "dependencies": { "@commitlint/top-level": "^7.5.0", diff --git a/@commitlint/resolve-extends/package.json b/@commitlint/resolve-extends/package.json index 7888a582d2..82c72c91ce 100644 --- a/@commitlint/resolve-extends/package.json +++ b/@commitlint/resolve-extends/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -67,8 +66,7 @@ "babel-register": "6.26.0", "concurrently": "3.5.1", "cross-env": "5.1.1", - "execa": "0.9.0", - "rimraf": "2.6.1" + "execa": "0.9.0" }, "dependencies": { "babel-runtime": "6.26.0", diff --git a/@commitlint/rules/package.json b/@commitlint/rules/package.json index 0c208a437b..a40f1f4994 100644 --- a/@commitlint/rules/package.json +++ b/@commitlint/rules/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-import", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -68,8 +67,7 @@ "conventional-changelog-angular": "1.6.6", "cross-env": "5.1.1", "globby": "8.0.1", - "lodash": "4.17.11", - "rimraf": "2.6.1" + "lodash": "4.17.11" }, "dependencies": { "@commitlint/ensure": "^7.5.2", diff --git a/@commitlint/to-lines/package.json b/@commitlint/to-lines/package.json index 314d6dd556..8e75c5874a 100644 --- a/@commitlint/to-lines/package.json +++ b/@commitlint/to-lines/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", @@ -65,7 +64,6 @@ "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" } } diff --git a/@commitlint/top-level/package.json b/@commitlint/top-level/package.json index bf2dc5035c..7df06695bb 100644 --- a/@commitlint/top-level/package.json +++ b/@commitlint/top-level/package.json @@ -8,7 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check", "start": "yarn watch", @@ -46,8 +45,7 @@ "babel-cli": "6.26.0", "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" }, "dependencies": { "find-up": "^2.1.0" diff --git a/@commitlint/travis-cli/package.json b/@commitlint/travis-cli/package.json index 292a9b28a8..1c8a23be46 100644 --- a/@commitlint/travis-cli/package.json +++ b/@commitlint/travis-cli/package.json @@ -10,7 +10,6 @@ }, "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", "deps": "dep-check", "pkg": "pkg-check --skip-main", "start": "ava -c 4 --verbose --watch", diff --git a/@packages/babel-preset-commitlint/index.test.js b/@packages/babel-preset-commitlint/index.test.js deleted file mode 100644 index b125c38b85..0000000000 --- a/@packages/babel-preset-commitlint/index.test.js +++ /dev/null @@ -1,27 +0,0 @@ -import test from 'ava'; -import * as babel from 'babel-core'; -import preset from '.'; - -test('does not throw', t => { - t.notThrows(() => preset()); -}); - -test('returns an object', t => { - t.is(typeof preset(), 'object'); -}); - -test('succeeds for a simple babel transformation', t => { - t.notThrows(() => babel.transform('code();', preset)); -}); - -test('produces valid values in plugins', t => { - const config = preset(); - t.true( - config.plugins.every(plugin => { - if (Array.isArray(plugin)) { - return typeof plugin[0] === 'function'; - } - return typeof plugin === 'function'; - }) - ); -}); diff --git a/@packages/babel-preset-commitlint/package.json b/@packages/babel-preset-commitlint/package.json index b5a70d9dc3..190b94a965 100644 --- a/@packages/babel-preset-commitlint/package.json +++ b/@packages/babel-preset-commitlint/package.json @@ -6,12 +6,6 @@ "files": [ "index.js" ], - "scripts": { - "deps": "dep-check", - "pkg": "pkg-check", - "start": "ava --watch --verbose", - "test": "ava --verbose" - }, "ava": { "files": [ "test.js", @@ -49,7 +43,6 @@ }, "license": "MIT", "devDependencies": { - "@commitlint/utils": "^7.5.0", "ava": "0.22.0", "babel-core": "6.26.0" }, diff --git a/@packages/test/package.json b/@packages/test/package.json index e26fcb1659..3171933398 100644 --- a/@packages/test/package.json +++ b/@packages/test/package.json @@ -8,9 +8,6 @@ ], "scripts": { "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", - "clean": "npx rimraf lib", - "deps": "dep-check", - "pkg": "pkg-check --skip-import", "start": "concurrently \"ava --watch --verbose\" \"yarn run watch\"", "test": "ava --verbose", "watch": "babel src --out-dir lib --watch --source-maps" @@ -56,19 +53,15 @@ }, "license": "MIT", "dependencies": { - "@commitlint/utils": "^7.5.0", "@marionebl/sander": "0.6.1", "execa": "0.9.0", "pkg-dir": "2.0.0" }, "devDependencies": { - "@commitlint/utils": "^7.5.0", - "ava": "0.22.0", "babel-cli": "6.26.0", "babel-preset-commitlint": "^7.5.0", "babel-register": "6.26.0", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "rimraf": "2.6.1" + "cross-env": "5.1.1" } } diff --git a/README.md b/README.md index 872f939634..6fed89e877 100644 --- a/README.md +++ b/README.md @@ -187,9 +187,9 @@ Copyright by @marionebl. All `commitlint` packages are released under the MIT li ```sh git clone git@github.com:conventional-changelog/commitlint.git cd commitlint -npx yarn install -npx yarn run build # run build tasks -npx yarn start # run tests, again on change +yarn +yarn run build # run build tasks +yarn start # run tests, again on change ``` For more information on how to contribute please take a look at our [contribution guide](./.github/CONTRIBUTING.md). @@ -197,11 +197,11 @@ For more information on how to contribute please take a look at our [contributio ### Publishing a release ```sh -npx yarn run clean -npx yarn install -npx yarn run build -npx yarn test -npx yarn run publish +yarn clean +yarn install +yarn run build +yarn test +yarn run publish ``` diff --git a/package.json b/package.json index 4a0d744a16..d200179699 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "build": "lerna run build --stream --parallel --include-filtered-dependencies", "watch": "lerna run watch --stream --parallel --include-filtered-dependencies", - "clean": "npx lerna clean --yes && npx lerna run clean --stream --parallel --include-filtered-dependencies", + "clean": "lerna clean --yes && lerna exec 'git clean -xdf lib' && git clean -xdf node_modules", "commit": "node @commitlint/prompt-cli/cli.js", "deps": "lerna run deps", "pkg": "lerna run pkg", diff --git a/yarn.lock b/yarn.lock index 47a2adc0f4..4395bef859 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8511,18 +8511,12 @@ right-pad@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0" -rimraf@2, rimraf@2.6.2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: +rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2.6.1, rimraf@^2.6.2: version "2.6.2" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" dependencies: glob "^7.0.5" -rimraf@2.6.1: - version "2.6.1" - resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d" - dependencies: - glob "^7.0.5" - rimraf@^2.6.3: version "2.6.3" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab" From 1ed6503e8c27d594a83dc9bff1c2d7f21422f8ea Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 20 May 2019 17:51:43 +0000 Subject: [PATCH 2/2] build: port execute-rule to ts --- .vscode/settings.json | 3 ++ @commitlint/execute-rule/index.d.ts | 1 + @commitlint/execute-rule/index.js | 1 + @commitlint/execute-rule/jest.config.js | 4 ++ @commitlint/execute-rule/package.json | 43 +++++----------------- @commitlint/execute-rule/src/index.js | 9 ----- @commitlint/execute-rule/src/index.test.js | 27 -------------- @commitlint/execute-rule/src/index.test.ts | 26 +++++++++++++ @commitlint/execute-rule/src/index.ts | 25 +++++++++++++ @commitlint/execute-rule/tsconfig.json | 22 +++++++++++ @commitlint/format/package.json | 2 - yarn.lock | 7 ++++ 12 files changed, 99 insertions(+), 71 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 @commitlint/execute-rule/index.d.ts create mode 100644 @commitlint/execute-rule/index.js create mode 100644 @commitlint/execute-rule/jest.config.js delete mode 100644 @commitlint/execute-rule/src/index.js delete mode 100644 @commitlint/execute-rule/src/index.test.js create mode 100644 @commitlint/execute-rule/src/index.test.ts create mode 100644 @commitlint/execute-rule/src/index.ts create mode 100644 @commitlint/execute-rule/tsconfig.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..55712c19f1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/@commitlint/execute-rule/index.d.ts b/@commitlint/execute-rule/index.d.ts new file mode 100644 index 0000000000..8cd5167d1c --- /dev/null +++ b/@commitlint/execute-rule/index.d.ts @@ -0,0 +1 @@ +export * from "./lib"; diff --git a/@commitlint/execute-rule/index.js b/@commitlint/execute-rule/index.js new file mode 100644 index 0000000000..bb0a047c4f --- /dev/null +++ b/@commitlint/execute-rule/index.js @@ -0,0 +1 @@ +module.exports = require('./lib'); diff --git a/@commitlint/execute-rule/jest.config.js b/@commitlint/execute-rule/jest.config.js new file mode 100644 index 0000000000..20d2ea60f5 --- /dev/null +++ b/@commitlint/execute-rule/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +}; diff --git a/@commitlint/execute-rule/package.json b/@commitlint/execute-rule/package.json index 0d908aa35c..46147c8e48 100644 --- a/@commitlint/execute-rule/package.json +++ b/@commitlint/execute-rule/package.json @@ -7,31 +7,12 @@ "lib/" ], "scripts": { - "build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps", + "build": "tsc", "deps": "dep-check", "pkg": "pkg-check", - "start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"", - "test": "ava -c 4 --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" - ] + "start": "concurrently \"yarn test --watchAll\" \"yarn run watch\"", + "test": "jest", + "watch": "tsc -w" }, "engines": { "node": ">=4" @@ -57,16 +38,12 @@ "license": "MIT", "devDependencies": { "@commitlint/parse": "^7.5.0", - "@commitlint/test": "7.6.0", "@commitlint/utils": "^7.5.0", - "ava": "0.22.0", - "babel-cli": "6.26.0", - "babel-preset-commitlint": "^7.5.0", - "babel-register": "6.26.0", + "@types/jest": "24.0.13", + "@types/lodash": "4.14.130", "concurrently": "3.5.1", - "cross-env": "5.1.1" - }, - "dependencies": { - "babel-runtime": "6.26.0" + "jest": "24.8.0", + "ts-jest": "24.0.2", + "typescript": "3.4.5" } -} +} \ No newline at end of file diff --git a/@commitlint/execute-rule/src/index.js b/@commitlint/execute-rule/src/index.js deleted file mode 100644 index 5deda83237..0000000000 --- a/@commitlint/execute-rule/src/index.js +++ /dev/null @@ -1,9 +0,0 @@ -export default async entry => { - if (!Array.isArray(entry)) { - return null; - } - const [name, config] = entry; - return typeof config === 'function' - ? [name, await config()] - : [name, await config]; -}; diff --git a/@commitlint/execute-rule/src/index.test.js b/@commitlint/execute-rule/src/index.test.js deleted file mode 100644 index 836265740c..0000000000 --- a/@commitlint/execute-rule/src/index.test.js +++ /dev/null @@ -1,27 +0,0 @@ -import test from 'ava'; -import execute from '.'; - -test('does nothing without params', async t => { - const actual = await execute(); - t.is(actual, null); -}); - -test('returns plain config', async t => { - const actual = await execute(['name', 'config']); - t.deepEqual(actual, ['name', 'config']); -}); - -test('unwraps promised config', async t => { - const actual = await execute(['name', Promise.resolve('config')]); - t.deepEqual(actual, ['name', 'config']); -}); - -test('executes config functions', async t => { - const actual = await execute(['name', () => 'config']); - t.deepEqual(actual, ['name', 'config']); -}); - -test('executes async config functions', async t => { - const actual = await execute(['name', async () => 'config']); - t.deepEqual(actual, ['name', 'config']); -}); diff --git a/@commitlint/execute-rule/src/index.test.ts b/@commitlint/execute-rule/src/index.test.ts new file mode 100644 index 0000000000..2c9698de18 --- /dev/null +++ b/@commitlint/execute-rule/src/index.test.ts @@ -0,0 +1,26 @@ +import execute from '.'; + +test('does nothing without params', async () => { + const exec = execute as any; + expect(await exec()).toBeNull(); +}); + +test('returns plain config', async () => { + const actual = await execute(['name', 'config']); + expect(actual).toEqual(['name', 'config']); +}); + +test('unwraps promised config', async () => { + const actual = await execute(['name', Promise.resolve('config')]); + expect(actual).toEqual(['name', 'config']); +}); + +test('executes config functions', async () => { + const actual = await execute(['name', () => 'config']); + expect(actual).toEqual(['name', 'config']); +}); + +test('executes async config functions', async () => { + const actual = await execute(['name', async () => 'config']); + expect(actual).toEqual(['name', 'config']); +}); diff --git a/@commitlint/execute-rule/src/index.ts b/@commitlint/execute-rule/src/index.ts new file mode 100644 index 0000000000..4eb0fa7f88 --- /dev/null +++ b/@commitlint/execute-rule/src/index.ts @@ -0,0 +1,25 @@ +type Rule = readonly [string, Config]; +type Config = T | Promise | ExectableConfig; +type ExectableConfig = (() => T) | (() => Promise); + +type ExecutedRule = readonly [string, T]; + +export default execute; + +export async function execute(rule: Rule): Promise | null> { + if (!Array.isArray(rule)) { + return null; + } + + const [name, config] = rule; + + const fn = executable(config) + ? config + : async () => config; + + return [name, await fn()]; +}; + +function executable(config: Config): config is ExectableConfig { + return typeof config === 'function'; +} \ No newline at end of file diff --git a/@commitlint/execute-rule/tsconfig.json b/@commitlint/execute-rule/tsconfig.json new file mode 100644 index 0000000000..7ed644a5a1 --- /dev/null +++ b/@commitlint/execute-rule/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "lib": [ + "dom", + "es2015" + ], + "rootDir": "src", + "outDir": "lib", + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/**/*.test.ts" + ] +} \ No newline at end of file diff --git a/@commitlint/format/package.json b/@commitlint/format/package.json index a2efe6f0ae..fb5e3e345c 100644 --- a/@commitlint/format/package.json +++ b/@commitlint/format/package.json @@ -37,12 +37,10 @@ }, "license": "MIT", "devDependencies": { - "@commitlint/test": "7.6.0", "@commitlint/utils": "^7.5.0", "@types/jest": "24.0.13", "@types/lodash": "4.14.130", "concurrently": "3.5.1", - "cross-env": "5.1.1", "jest": "24.8.0", "rimraf": "2.6.1", "ts-jest": "24.0.2", diff --git a/yarn.lock b/yarn.lock index 4395bef859..ae7ec7b2dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8517,6 +8517,13 @@ rimraf@2, rimraf@^2.2.8, rimraf@^2.5.1, rimraf@^2.5.2, rimraf@^2.5.4, rimraf@^2. dependencies: glob "^7.0.5" +rimraf@2.6.1: + version "2.6.1" + resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d" + integrity sha1-wjOOxkPfeht/5cVPqG9XQopV8z0= + dependencies: + glob "^7.0.5" + rimraf@^2.6.3: version "2.6.3" resolved "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz#b2d104fe0d8fb27cf9e0a1cda8262dd3833c6cab"