From 8ca15451c92c46e1ffaf7fabf167ed7ee036158d Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Sun, 5 May 2019 18:39:25 +0200 Subject: [PATCH 1/5] 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/5] 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" From 9a02cdd99bd0b19e890a93c5ad5bf8482a32a239 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Tue, 21 May 2019 08:03:59 +0000 Subject: [PATCH 3/5] fixup\!: port to ts --- @commitlint/resolve-extends/jest.config.js | 4 + @commitlint/resolve-extends/package.json | 41 ++---- .../src/{index.test.js => index.test.ts} | 57 ++++---- .../src/{index.js => index.ts} | 68 +++++----- @commitlint/resolve-extends/tsconfig.json | 15 +++ yarn.lock | 124 +++++++++++++----- 6 files changed, 182 insertions(+), 127 deletions(-) create mode 100644 @commitlint/resolve-extends/jest.config.js rename @commitlint/resolve-extends/src/{index.test.js => index.test.ts} (82%) rename @commitlint/resolve-extends/src/{index.js => index.ts} (63%) create mode 100644 @commitlint/resolve-extends/tsconfig.json diff --git a/@commitlint/resolve-extends/jest.config.js b/@commitlint/resolve-extends/jest.config.js new file mode 100644 index 0000000000..20d2ea60f5 --- /dev/null +++ b/@commitlint/resolve-extends/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node' +}; diff --git a/@commitlint/resolve-extends/package.json b/@commitlint/resolve-extends/package.json index 82c72c91ce..85c61b006c 100644 --- a/@commitlint/resolve-extends/package.json +++ b/@commitlint/resolve-extends/package.json @@ -7,31 +7,11 @@ "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 \"jest --watchAll\" \"tsc -w\"", + "test": "jest" }, "engines": { "node": ">=4" @@ -60,16 +40,17 @@ "@commitlint/test": "7.6.0", "@commitlint/utils": "^7.5.0", "@marionebl/sander": "0.6.1", - "ava": "0.22.0", - "babel-cli": "6.26.0", - "babel-preset-commitlint": "^7.5.0", - "babel-register": "6.26.0", + "@types/execa": "^0.9.0", + "@types/jest": "24.0.13", + "@types/lodash": "^4.14.130", + "@types/resolve-from": "^5.0.1", "concurrently": "3.5.1", - "cross-env": "5.1.1", - "execa": "0.9.0" + "execa": "0.9.0", + "jest": "24.8.0", + "ts-jest": "24.0.2", + "typescript": "3.4.5" }, "dependencies": { - "babel-runtime": "6.26.0", "import-fresh": "^3.0.0", "lodash": "4.17.11", "resolve-from": "^5.0.0", diff --git a/@commitlint/resolve-extends/src/index.test.js b/@commitlint/resolve-extends/src/index.test.ts similarity index 82% rename from @commitlint/resolve-extends/src/index.test.js rename to @commitlint/resolve-extends/src/index.test.ts index 504e7a1082..46743b927a 100644 --- a/@commitlint/resolve-extends/src/index.test.js +++ b/@commitlint/resolve-extends/src/index.test.ts @@ -1,23 +1,23 @@ -import test from 'ava'; import execa from 'execa'; -import {fix} from '@commitlint/test'; -import * as sander from '@marionebl/sander'; import resolveExtends from '.'; -const id = id => id; +const {fix} = require('@commitlint/test'); +const sander = require('@marionebl/sander'); -test('returns empty object when called without params', t => { +const id = (id: unknown) => id; + +test('returns empty object when called without params', () => { const actual = resolveExtends(); - t.deepEqual(actual, {}); + expect(actual).toEqual({}); }); -test('returns an equivalent object as passed in', t => { +test('returns an equivalent object as passed in', () => { const expected = {foo: 'bar'}; const actual = resolveExtends(expected); - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); -test.serial('falls back to global install', async t => { +test('falls back to global install', async () => { const prev = process.env.PREFIX; const cwd = await fix.bootstrap('fixtures/global-install'); @@ -38,12 +38,12 @@ test.serial('falls back to global install', async t => { ]); const expected = {extends: ['@commitlint/config-angular']}; - t.notThrows(() => resolveExtends(expected)); + expect(() => resolveExtends(expected)).not.toThrow(); process.env.PREFIX = prev; }); -test.serial('fails for missing extends', async t => { +test('fails for missing extends', async () => { const prev = process.env.PREFIX; const cwd = await fix.bootstrap('fixtures/missing-install'); @@ -53,21 +53,18 @@ test.serial('fails for missing extends', async t => { const input = {extends: ['@commitlint/foo-bar']}; - t.throws( - () => resolveExtends(input, {cwd}), - /Cannot find module "@commitlint\/foo-bar" from/ - ); + expect(() => resolveExtends(input, {cwd})).toThrow(/Cannot find module "@commitlint\/foo-bar" from/); process.env.PREFIX = prev; }); -test('uses empty prefix by default', t => { +test('uses empty prefix by default', () => { const input = {extends: ['extender-name']}; resolveExtends(input, { resolve: id, require(id) { - t.is(id, 'extender-name'); + expect(id).toBe('extender-name') } }); }); @@ -79,7 +76,7 @@ test('uses prefix as configured', t => { prefix: 'prefix', resolve: id, require(id) { - t.is(id, 'prefix-extender-name'); + expect(id).toBe('prefix-extender-name') } }); }); @@ -91,7 +88,7 @@ test('ignores prefix for scoped extends', t => { prefix: 'prefix', resolve: id, require(id) { - t.is(id, '@scope/extender-name'); + expect(id).toBe('@scope/extender-name'); } }); }); @@ -103,7 +100,7 @@ test('adds prefix as suffix for scopes only', t => { prefix: 'prefix', resolve: id, require(id) { - t.is(id, '@scope/prefix'); + expect(id).toBe('@scope/prefix'); } }); }); @@ -115,7 +112,7 @@ test('ignores prefix for relative extends', t => { prefix: 'prefix', resolve: id, require(id) { - t.is(id, './extender'); + expect(id).toBe('./extender'); } }); }); @@ -131,12 +128,12 @@ test('propagates return value of require function', t => { } }); - t.is(actual.foo, 'bar'); + expect(actual.foo).toBe('bar'); }); test('resolves extends recursively', t => { const input = {extends: ['extender-name']}; - const actual = []; + const actual: string[] = []; resolveExtends(input, { resolve: id, @@ -151,12 +148,12 @@ test('resolves extends recursively', t => { } }); - t.deepEqual(actual, ['extender-name', 'recursive-extender-name']); + expect(actual).toBe(['extender-name', 'recursive-extender-name']); }); test('uses prefix key recursively', t => { const input = {extends: ['extender-name']}; - const actual = []; + const actual: string[] = []; resolveExtends(input, { prefix: 'prefix', @@ -172,7 +169,7 @@ test('uses prefix key recursively', t => { } }); - t.deepEqual(actual, [ + expect(actual).toEqual([ 'prefix-extender-name', 'prefix-recursive-extender-name' ]); @@ -199,7 +196,7 @@ test('propagates contents recursively', t => { baz: 'bar' }; - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); test('propagates contents recursively with overlap', t => { @@ -227,7 +224,7 @@ test('propagates contents recursively with overlap', t => { } }; - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); test('extending contents should take precedence', t => { @@ -261,7 +258,7 @@ test('extending contents should take precedence', t => { three: 'second-recursive-extender-name' }; - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); test('should fall back to conventional-changelog-lint-config prefix', t => { @@ -286,7 +283,7 @@ test('should fall back to conventional-changelog-lint-config prefix', t => { } }); - t.deepEqual(actual, { + expect(actual).toEqual({ extends: ['extender-name'], rules: { fallback: true diff --git a/@commitlint/resolve-extends/src/index.js b/@commitlint/resolve-extends/src/index.ts similarity index 63% rename from @commitlint/resolve-extends/src/index.js rename to @commitlint/resolve-extends/src/index.ts index a202512001..c6f2032896 100644 --- a/@commitlint/resolve-extends/src/index.js +++ b/@commitlint/resolve-extends/src/index.ts @@ -1,13 +1,29 @@ import path from 'path'; -import 'resolve-global'; // eslint-disable-line import/no-unassigned-import -import importFresh from 'import-fresh'; +import 'resolve-global'; import resolveFrom from 'resolve-from'; -import {isArray, merge, mergeWith, omit} from 'lodash'; +import { isArray, merge, mergeWith, omit } from 'lodash'; -// Resolve extend configs -export default function resolveExtends(config = {}, context = {}) { - const {extends: e} = config; +const importFresh = require('import-fresh'); + +export interface ResolvedConfig { + +} + +export interface ResolveExtendsConfig { + parserPreset?: unknown; + extends?: string[]; +} + +export interface ResolveExtendsContext { + parserPreset?: unknown; + prefix?: string; + resolve?(id: string, ctx?: { prefix?: string, cwd?: string }): string; + require?(id: string): T; +} + +export default function resolveExtends(config: ResolveExtendsConfig = {}, context: ResolveExtendsContext = {}) { + const { extends: e } = config; const extended = loadExtends(config, context).reduceRight( (r, c) => mergeWith(r, omit(c, 'extends'), (objValue, srcValue) => { @@ -15,35 +31,19 @@ export default function resolveExtends(config = {}, context = {}) { return srcValue; } }), - e ? {extends: e} : {} + e ? { extends: e } : {} ); - // Remove deprecation warning in version 3 - if (typeof config === 'object' && 'wildcards' in config) { - console.warn( - `'wildcards' found in top-level configuration ignored. Remove them from your config to silence this warning.` - ); - } - return merge({}, extended, config); } -// (any, string, string, Function) => any[]; -function loadExtends(config = {}, context = {}) { - return (config.extends || []).reduce((configs, raw) => { +function loadExtends(config: ResolveExtendsConfig = {}, context: ResolveExtendsContext = {}): ResolvedConfig[] { + return (config.extends || []).reduce((configs, raw) => { const load = context.require || require; const resolved = resolveConfig(raw, context); const c = load(resolved); const cwd = path.dirname(resolved); - - // Remove deprecation warning in version 3 - if (typeof c === 'object' && 'wildcards' in c) { - console.warn( - `'wildcards' found in '${raw}' ignored. To silence this warning raise an issue at 'npm repo ${raw}' to remove the wildcards.` - ); - } - - const ctx = merge({}, context, {cwd}); + const ctx = merge({}, context, { cwd }); // Resolve parser preset if none was present before if ( @@ -68,7 +68,7 @@ function loadExtends(config = {}, context = {}) { }, []); } -function getId(raw = '', prefix = '') { +function getId(raw: string = '', prefix: string = ''): string { const first = raw.charAt(0); const scoped = first === '@'; const relative = first === '.'; @@ -80,7 +80,7 @@ function getId(raw = '', prefix = '') { return relative ? raw : [prefix, raw].filter(String).join('-'); } -function resolveConfig(raw, context = {}) { +function resolveConfig(raw: string, context: ResolveExtendsContext = {}): string { const resolve = context.resolve || resolveId; const id = getId(raw, context.prefix); @@ -96,7 +96,7 @@ function resolveConfig(raw, context = {}) { } } -function resolveId(id, context = {}) { +function resolveId(id: string, context: { cwd?: string } = {}): string { const cwd = context.cwd || process.cwd(); const localPath = resolveFromSilent(cwd, id); @@ -111,19 +111,19 @@ function resolveId(id, context = {}) { } const err = new Error(`Cannot find module "${id}" from "${cwd}"`); - err.code = 'MODULE_NOT_FOUND'; + (err as any).code = 'MODULE_NOT_FOUND'; throw err; } -function resolveFromSilent(cwd, id) { +function resolveFromSilent(cwd: string, id: string): string | void { try { return resolveFrom(cwd, id); - } catch (err) {} + } catch (err) { } } -function resolveGlobalSilent(id) { +function resolveGlobalSilent(id: string): string | void { try { const resolveGlobal = importFresh('resolve-global'); return resolveGlobal(id); - } catch (err) {} + } catch (err) { } } diff --git a/@commitlint/resolve-extends/tsconfig.json b/@commitlint/resolve-extends/tsconfig.json new file mode 100644 index 0000000000..b0b634a3fe --- /dev/null +++ b/@commitlint/resolve-extends/tsconfig.json @@ -0,0 +1,15 @@ +{ + "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"] +} diff --git a/yarn.lock b/yarn.lock index ae7ec7b2dd..0c6ad30544 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1109,6 +1109,13 @@ dependencies: "@babel/types" "^7.3.0" +"@types/execa@^0.9.0": + version "0.9.0" + resolved "https://registry.npmjs.org/@types/execa/-/execa-0.9.0.tgz#9b025d2755f17e80beaf9368c3f4f319d8b0fb93" + integrity sha512-mgfd93RhzjYBUHHV532turHC2j4l/qxsF/PbfDmprHDEUHmNZGlDn1CEsulGK3AfsPdhkWzZQT/S/k0UGhLGsA== + dependencies: + "@types/node" "*" + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.1" resolved "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -1141,16 +1148,28 @@ dependencies: "@types/jest-diff" "*" -"@types/lodash@4.14.130": +"@types/lodash@4.14.130", "@types/lodash@^4.14.130": version "4.14.130" resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.130.tgz#04b3a690d5f4fc34579963c99adae067b8c8eb5a" integrity sha512-H++wk0tbneBsRVfLkgAAd0IIpmpVr2Bj4T0HncoOsQf3/xrJexRYQK2Tqo0Ej3pFslM8GkMgdis9bu6xIb1ycw== +"@types/node@*": + version "12.0.2" + resolved "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40" + integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA== + "@types/normalize-package-data@^2.4.0": version "2.4.0" resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA== +"@types/resolve-from@^5.0.1": + version "5.0.1" + resolved "https://registry.npmjs.org/@types/resolve-from/-/resolve-from-5.0.1.tgz#2714eaa840c0472dcfa96ec3fb9d170dbf0b677d" + integrity sha512-1G7n5Jtr5inoS1Ez2Y9Efedk9/wH6uGQslbfhGTOw9J42PCAwuyaDgQHW7fIq02+shwB02kM/w31W8gMxI8ORg== + dependencies: + resolve-from "*" + "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" @@ -2506,7 +2525,16 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" -braces@2.3.1, braces@^1.8.2, braces@^2.3.0: +braces@^1.8.2: + version "1.8.5" + resolved "https://registry.npmjs.org/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7" + integrity sha1-uneWLhLf+WnWt2cR6RS3N4V79qc= + dependencies: + expand-range "^1.8.1" + preserve "^0.2.0" + repeat-element "^1.1.2" + +braces@^2.3.0: version "2.3.1" resolved "https://registry.npmjs.org/braces/-/braces-2.3.1.tgz#7086c913b4e5a08dbe37ac0ee6a2500c4ba691bb" integrity sha512-SO5lYHA3vO6gz66erVvedSCkp7AKWdv6VcQ2N4ysXfPxdAlxAMMAdwegGGcv1Bqwm7naF1hNdk5d6AAIEHV2nQ== @@ -3530,10 +3558,15 @@ deep-equal@^1.0.0: version "1.0.1" resolved "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" -deep-extend@0.5.1, deep-extend@^0.6.0, deep-extend@~0.4.0: - version "0.5.1" - resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz#b894a9dd90d3023fbf1c55a394fb858eb2066f1f" - integrity sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w== +deep-extend@^0.6.0: + version "0.6.0" + resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA== + +deep-extend@~0.4.0: + version "0.4.2" + resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f" + integrity sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8= deep-is@~0.1.3: version "0.1.3" @@ -3987,6 +4020,13 @@ expand-brackets@^2.1.4: snapdragon "^0.8.1" to-regex "^3.0.1" +expand-range@^1.8.1: + version "1.8.2" + resolved "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz#a299effd335fe2721ebae8e257ec79644fc85337" + integrity sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc= + dependencies: + fill-range "^2.1.0" + expand-tilde@^2.0.0, expand-tilde@^2.0.2: version "2.0.2" resolved "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502" @@ -4143,6 +4183,17 @@ fill-keys@^1.0.2: is-object "~1.0.1" merge-descriptors "~1.0.0" +fill-range@^2.1.0: + version "2.2.4" + resolved "https://registry.npmjs.org/fill-range/-/fill-range-2.2.4.tgz#eb1e773abb056dcd8df2bfdf6af59b8b3a936565" + integrity sha512-cnrcCbj01+j2gTG921VZPnHbjmdAf8oQV/iGeV2kZxGSyfYjjTyY79ErsK1WJWMpw6DaApEX72binqJE+/d+5Q== + dependencies: + is-number "^2.1.0" + isobject "^2.0.0" + randomatic "^3.0.0" + repeat-element "^1.1.2" + repeat-string "^1.5.2" + fill-range@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7" @@ -4791,10 +4842,10 @@ hawk@3.1.3, hawk@~3.1.3: hoek "2.x.x" sntp "1.x.x" -hoek@2.x.x, hoek@5.0.3: - version "5.0.3" - resolved "https://registry.npmjs.org/hoek/-/hoek-5.0.3.tgz#b71d40d943d0a95da01956b547f83c4a5b4a34ac" - integrity sha512-Bmr56pxML1c9kU+NS51SMFkiVQAb+9uFfXwyqR2tn4w2FPvmPt65eZ9aCcEfRXd9G74HkZnILC6p967pED4aiw== +hoek@2.x.x: + version "2.16.3" + resolved "https://registry.npmjs.org/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" + integrity sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0= home-or-tmp@^2.0.0: version "2.0.0" @@ -5314,6 +5365,13 @@ is-npm@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/is-npm/-/is-npm-1.0.0.tgz#f2fb63a65e4905b406c86072765a1a4dc793b9f4" +is-number@^2.1.0: + version "2.1.0" + resolved "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" + integrity sha1-Afy7s5NGOlSPL0ZszhbezknbkI8= + dependencies: + kind-of "^3.0.2" + is-number@^3.0.0: version "3.0.0" resolved "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" @@ -5937,7 +5995,7 @@ js-tokens@^4.0.0: resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ== -js-yaml@>=3.13.0, js-yaml@^3.10.0, js-yaml@^3.13.0, js-yaml@^3.8.2, js-yaml@^3.9.0: +js-yaml@^3.10.0, js-yaml@^3.13.0, js-yaml@^3.8.2, js-yaml@^3.9.0: version "3.13.1" resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== @@ -6375,10 +6433,15 @@ lodash.uniq@^4.5.0: version "4.5.0" resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" -lodash@4.17.11, lodash@^3.3.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: +lodash@4.17.11, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, lodash@^4.3.0, lodash@^4.5.1: version "4.17.11" resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" +lodash@^3.3.1: + version "3.10.1" + resolved "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6" + integrity sha1-W/Rejkm6QYnhfUgnid/RW9FAt7Y= + log-symbols@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18" @@ -6518,11 +6581,16 @@ map-visit@^1.0.0: dependencies: object-visit "^1.0.0" -marked@0.3.9, marked@^0.3.6, marked@^0.5.1: +marked@^0.3.6: version "0.3.9" resolved "https://registry.npmjs.org/marked/-/marked-0.3.9.tgz#54ce6a57e720c3ac6098374ec625fcbcc97ff290" integrity sha512-nW5u0dxpXxHfkHzzrveY45gCbi+R4PaO4WRZYqZNl+vB0hVGeqlFn0aOg1c8AKL63TrNFn9Bm2UP4AdiZ9TPLw== +marked@^0.5.1: + version "0.5.2" + resolved "https://registry.npmjs.org/marked/-/marked-0.5.2.tgz#3efdb27b1fd0ecec4f5aba362bddcd18120e5ba9" + integrity sha512-fdZvBa7/vSQIZCi4uuwo2N3q+7jJURpMVCcbaX0S1Mg65WZ5ilXvC67MviJAsdjqqgD+CEq4RKo5AYGgINkVAA== + matcher@^0.1.1: version "0.1.2" resolved "https://registry.npmjs.org/matcher/-/matcher-0.1.2.tgz#ef20cbde64c24c50cc61af5b83ee0b1b8ff00101" @@ -6815,7 +6883,7 @@ module-not-found-error@^1.0.0: resolved "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz#cf8b4ff4f29640674d6cdd02b0e3bc523c2bbdc0" integrity sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA= -moment@2.19.3, moment@^2.18.1: +moment@^2.18.1: version "2.19.3" resolved "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz#bdb99d270d6d7fda78cc0fbace855e27fe7da69f" integrity sha1-vbmdJw1tf9p4zA+6zoVeJ/59pp8= @@ -7805,6 +7873,11 @@ prepend-http@^1.0.1: version "1.0.4" resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" +preserve@^0.2.0: + version "0.2.0" + resolved "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" + integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= + prettier@1.17.1: version "1.17.1" resolved "https://registry.npmjs.org/prettier/-/prettier-1.17.1.tgz#ed64b4e93e370cb8a25b9ef7fef3e4fd1c0995db" @@ -7977,7 +8050,7 @@ quick-lru@^1.0.0: version "1.1.0" resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8" -randomatic@3: +randomatic@^3.0.0: version "3.1.1" resolved "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" integrity sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw== @@ -8296,7 +8369,7 @@ repeat-element@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" -repeat-string@^1.6.1: +repeat-string@^1.5.2, repeat-string@^1.6.1: version "1.6.1" resolved "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" @@ -8421,7 +8494,7 @@ resolve-dir@^1.0.0, resolve-dir@^1.0.1: expand-tilde "^2.0.0" global-modules "^1.0.0" -resolve-from@5.0.0, resolve-from@^5.0.0: +resolve-from@*, resolve-from@5.0.0, resolve-from@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== @@ -8962,21 +9035,6 @@ sprintf-js@~1.0.2: version "1.0.3" resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" -sshpk@1.14.1: - version "1.14.1" - resolved "https://registry.npmjs.org/sshpk/-/sshpk-1.14.1.tgz#130f5975eddad963f1d56f92b9ac6c51fa9f83eb" - integrity sha1-Ew9Zde3a2WPx1W+SuaxsUfqfg+s= - dependencies: - asn1 "~0.2.3" - assert-plus "^1.0.0" - dashdash "^1.12.0" - getpass "^0.1.1" - optionalDependencies: - bcrypt-pbkdf "^1.0.0" - ecc-jsbn "~0.1.1" - jsbn "~0.1.0" - tweetnacl "~0.14.0" - sshpk@^1.7.0: version "1.16.1" resolved "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" @@ -9112,7 +9170,7 @@ stringify-object@^3.2.2: is-obj "^1.0.1" is-regexp "^1.0.0" -stringstream@0.0.6, stringstream@~0.0.4: +stringstream@~0.0.4: version "0.0.6" resolved "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" integrity sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA== From 8cf3361f238c7106be4ea242a1cd0d106184d683 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Wed, 22 May 2019 20:36:25 +0000 Subject: [PATCH 4/5] test: bring test cases up to speed --- @commitlint/resolve-extends/package.json | 4 - @commitlint/resolve-extends/src/index.test.ts | 327 ++++++++---------- @commitlint/resolve-extends/src/index.ts | 11 +- 3 files changed, 160 insertions(+), 182 deletions(-) diff --git a/@commitlint/resolve-extends/package.json b/@commitlint/resolve-extends/package.json index 85c61b006c..2a51fe678c 100644 --- a/@commitlint/resolve-extends/package.json +++ b/@commitlint/resolve-extends/package.json @@ -37,15 +37,11 @@ "license": "MIT", "devDependencies": { "@commitlint/parse": "^7.5.0", - "@commitlint/test": "7.6.0", "@commitlint/utils": "^7.5.0", - "@marionebl/sander": "0.6.1", - "@types/execa": "^0.9.0", "@types/jest": "24.0.13", "@types/lodash": "^4.14.130", "@types/resolve-from": "^5.0.1", "concurrently": "3.5.1", - "execa": "0.9.0", "jest": "24.8.0", "ts-jest": "24.0.2", "typescript": "3.4.5" diff --git a/@commitlint/resolve-extends/src/index.test.ts b/@commitlint/resolve-extends/src/index.test.ts index 46743b927a..3ee70d9846 100644 --- a/@commitlint/resolve-extends/src/index.test.ts +++ b/@commitlint/resolve-extends/src/index.test.ts @@ -1,8 +1,5 @@ -import execa from 'execa'; -import resolveExtends from '.'; - -const {fix} = require('@commitlint/test'); -const sander = require('@marionebl/sander'); +import resolveExtends, { ResolveExtendsContext } from '.'; +import resolveGlobal from 'resolve-global'; const id = (id: unknown) => id; @@ -12,183 +9,153 @@ test('returns empty object when called without params', () => { }); test('returns an equivalent object as passed in', () => { - const expected = {foo: 'bar'}; + const expected = { foo: 'bar' }; const actual = resolveExtends(expected); expect(actual).toEqual(expected); }); test('falls back to global install', async () => { - const prev = process.env.PREFIX; - - const cwd = await fix.bootstrap('fixtures/global-install'); - const prefix = `${cwd}/commitlint-npm-packages`; - - const npm = args => execa('npm', args, {cwd}); - - await sander.mkdir(cwd, 'commitlint-npm-packages'); + const resolveGlobal = jest.fn(() => '@commitlint/foo-bar'); + const require = jest.fn(() => ({})); - process.env.PREFIX = prefix; + const ctx = {resolveGlobal, require} as ResolveExtendsContext; - await npm([ - 'install', - '--global', - '@commitlint/config-angular', - '--prefix', - prefix - ]); - - const expected = {extends: ['@commitlint/config-angular']}; - - expect(() => resolveExtends(expected)).not.toThrow(); - process.env.PREFIX = prev; + resolveExtends({ extends: ['@commitlint/foo-bar'] }, ctx); + expect(ctx.resolveGlobal).toBeCalledWith('@commitlint/foo-bar'); }); test('fails for missing extends', async () => { - const prev = process.env.PREFIX; - - const cwd = await fix.bootstrap('fixtures/missing-install'); - const prefix = `${cwd}/commitlint-npm-packages`; - - process.env.PREFIX = prefix; - - const input = {extends: ['@commitlint/foo-bar']}; - - expect(() => resolveExtends(input, {cwd})).toThrow(/Cannot find module "@commitlint\/foo-bar" from/); - - process.env.PREFIX = prev; + expect(() => resolveExtends({ extends: ['@commitlint/foo-bar'] })).toThrow(/Cannot find module "@commitlint\/foo-bar" from/); }); test('uses empty prefix by default', () => { - const input = {extends: ['extender-name']}; + const input = { extends: ['extender-name'] }; + const ctx = { resolve: id, require: jest.fn(() => ({})) } as ResolveExtendsContext; + resolveExtends(input, ctx); - resolveExtends(input, { - resolve: id, - require(id) { - expect(id).toBe('extender-name') - } - }); + expect(ctx.require).toHaveBeenCalledWith('extender-name'); }); -test('uses prefix as configured', t => { - const input = {extends: ['extender-name']}; +test('uses prefix as configured', () => { + const input = { extends: ['extender-name'] }; + const ctx = { resolve: id, require: jest.fn(() => ({})) } as ResolveExtendsContext; resolveExtends(input, { - prefix: 'prefix', - resolve: id, - require(id) { - expect(id).toBe('prefix-extender-name') - } + ...ctx, + prefix: 'prefix' }); + + expect(ctx.require).toHaveBeenCalledWith('prefix-extender-name'); }); -test('ignores prefix for scoped extends', t => { - const input = {extends: ['@scope/extender-name']}; +test('ignores prefix for scoped extends', () => { + const input = { extends: ['@scope/extender-name'] }; + const ctx = { resolve: id, require: jest.fn(() => ({})) } as ResolveExtendsContext; resolveExtends(input, { - prefix: 'prefix', - resolve: id, - require(id) { - expect(id).toBe('@scope/extender-name'); - } + ...ctx, + prefix: 'prefix' }); + + expect(ctx.require).toHaveBeenCalledWith('@scope/extender-name'); }); -test('adds prefix as suffix for scopes only', t => { - const input = {extends: ['@scope']}; +test('adds prefix as suffix for scopes only', () => { + const input = { extends: ['@scope'] }; + const ctx = { resolve: id, require: jest.fn(() => ({})) } as ResolveExtendsContext; resolveExtends(input, { - prefix: 'prefix', - resolve: id, - require(id) { - expect(id).toBe('@scope/prefix'); - } + ...ctx, + prefix: 'prefix' }); + + expect(ctx.require).toHaveBeenCalledWith('@scope/prefix'); }); -test('ignores prefix for relative extends', t => { - const input = {extends: ['./extender']}; +test('ignores prefix for relative extends', () => { + const input = { extends: ['./extender'] }; + const ctx = { resolve: id, require: jest.fn(() => ({})) } as ResolveExtendsContext; resolveExtends(input, { - prefix: 'prefix', - resolve: id, - require(id) { - expect(id).toBe('./extender'); - } + ...ctx, + prefix: 'prefix' }); + + expect(ctx.require).toHaveBeenCalledWith('./extender'); }); -test('propagates return value of require function', t => { - const input = {extends: ['extender-name']}; - const propagated = {foo: 'bar'}; +test('propagates return value of require function', () => { + const input = { extends: ['extender-name'] }; + const propagated = { foo: 'bar' }; + const ctx = { resolve: id, require: jest.fn(() => propagated) } as ResolveExtendsContext; - const actual = resolveExtends(input, { - resolve: id, - require() { - return propagated; - } - }); - - expect(actual.foo).toBe('bar'); + const actual = resolveExtends(input, ctx); + expect(actual).toEqual(expect.objectContaining(propagated)); }); -test('resolves extends recursively', t => { - const input = {extends: ['extender-name']}; - const actual: string[] = []; - - resolveExtends(input, { - resolve: id, - require(id) { - actual.push(id); - if (id === 'extender-name') { - return {extends: ['recursive-extender-name']}; - } - if (id === 'recursive-extender-name') { - return {foo: 'bar'}; - } +test('resolves extends recursively', () => { + const input = { extends: ['extender-name'] }; + + const require = (id: string) => { + switch (id) { + case 'extender-name': + return { extends: ['recursive-extender-name'] }; + case 'recursive-extender-name': + return { foo: 'bar' }; + default: + return {}; } - }); + }; + + const ctx = { resolve: id, require: jest.fn(require) } as ResolveExtendsContext; + resolveExtends(input, ctx); - expect(actual).toBe(['extender-name', 'recursive-extender-name']); + expect(ctx.require).toHaveBeenCalledWith('extender-name'); + expect(ctx.require).toHaveBeenCalledWith('recursive-extender-name'); }); -test('uses prefix key recursively', t => { - const input = {extends: ['extender-name']}; - const actual: string[] = []; +test('uses prefix key recursively', () => { + const input = { extends: ['extender-name'] }; + + const require = (id: string) => { + switch (id) { + case 'prefix-extender-name': + return { extends: ['recursive-extender-name'] }; + case 'prefix-recursive-extender-name': + return { foo: 'bar' }; + default: + return {}; + } + }; + + const ctx = { resolve: id, require: jest.fn(require) } as ResolveExtendsContext; resolveExtends(input, { - prefix: 'prefix', - resolve: id, - require(id) { - actual.push(id); - if (id === 'prefix-extender-name') { - return {extends: ['recursive-extender-name']}; - } - if (id === 'prefix-recursive-extender-name') { - return {foo: 'bar'}; - } - } + ...ctx, + prefix: 'prefix' }); - expect(actual).toEqual([ - 'prefix-extender-name', - 'prefix-recursive-extender-name' - ]); + expect(ctx.require).toHaveBeenCalledWith('prefix-extender-name'); + expect(ctx.require).toHaveBeenCalledWith('prefix-recursive-extender-name'); }); -test('propagates contents recursively', t => { - const input = {extends: ['extender-name']}; - - const actual = resolveExtends(input, { - resolve: id, - require(id) { - if (id === 'extender-name') { - return {extends: ['recursive-extender-name'], foo: 'bar'}; - } - if (id === 'recursive-extender-name') { - return {baz: 'bar'}; - } +test('propagates contents recursively', () => { + const input = { extends: ['extender-name'] }; + + const require = (id: string) => { + switch (id) { + case 'extender-name': + return { extends: ['recursive-extender-name'], foo: 'bar' }; + case 'recursive-extender-name': + return { baz: 'bar' }; + default: + return {}; } - }); + }; + + const ctx = { resolve: id, require: jest.fn(require) } as ResolveExtendsContext; + + const actual = resolveExtends(input, ctx); const expected = { extends: ['extender-name'], @@ -199,23 +166,23 @@ test('propagates contents recursively', t => { expect(actual).toEqual(expected); }); -test('propagates contents recursively with overlap', t => { - const input = {extends: ['extender-name']}; - - const actual = resolveExtends(input, { - resolve: id, - require(id) { - if (id === 'extender-name') { - return { - extends: ['recursive-extender-name'], - rules: {rule: ['zero', 'one']} - }; - } - if (id === 'recursive-extender-name') { - return {rules: {rule: ['two', 'three', 'four']}}; - } +test('propagates contents recursively with overlap', () => { + const input = { extends: ['extender-name'] }; + + const require = (id: string) => { + switch (id) { + case 'extender-name': + return { extends: ['recursive-extender-name'], rules: { rule: ['zero', 'one'] } }; + case 'recursive-extender-name': + return { rules: { rule: ['two', 'three', 'four'] } }; + default: + return {}; } - }); + }; + + const ctx = { resolve: id, require: jest.fn(require) } as ResolveExtendsContext; + + const actual = resolveExtends(input, ctx); const expected = { extends: ['extender-name'], @@ -227,28 +194,30 @@ test('propagates contents recursively with overlap', t => { expect(actual).toEqual(expected); }); -test('extending contents should take precedence', t => { - const input = {extends: ['extender-name'], zero: 'root'}; +test('extending contents should take precedence', () => { + const input = { extends: ['extender-name'], zero: 'root' }; - const actual = resolveExtends(input, { - resolve: id, - require(id) { - if (id === 'extender-name') { - return {extends: ['recursive-extender-name'], zero: id, one: id}; - } - if (id === 'recursive-extender-name') { + const require = (id: string) => { + switch (id) { + case 'extender-name': + return { extends: ['recursive-extender-name'], zero: id, one: id }; + case 'recursive-extender-name': return { extends: ['second-recursive-extender-name'], zero: id, one: id, two: id }; - } - if (id === 'second-recursive-extender-name') { - return {zero: id, one: id, two: id, three: id}; - } + case 'second-recursive-extender-name': + return { zero: id, one: id, two: id, three: id }; + default: + return {}; } - }); + }; + + const ctx = { resolve: id, require: jest.fn(require) } as ResolveExtendsContext; + + const actual = resolveExtends(input, ctx); const expected = { extends: ['extender-name'], @@ -261,26 +230,34 @@ test('extending contents should take precedence', t => { expect(actual).toEqual(expected); }); -test('should fall back to conventional-changelog-lint-config prefix', t => { - const input = {extends: ['extender-name']}; +test('should fall back to conventional-changelog-lint-config prefix', () => { + const input = { extends: ['extender-name'] }; - const actual = resolveExtends(input, { - prefix: 'prefix', - resolve(id) { - if (id === 'conventional-changelog-lint-config-extender-name') { - return 'conventional-changelog-lint-config-extender-name'; - } - throw new Error(`Could not find module "*${id}"`); - }, - require(id) { - if (id === 'conventional-changelog-lint-config-extender-name') { + const resolve = (id: string) => { + if (id === 'conventional-changelog-lint-config-extender-name') { + return 'conventional-changelog-lint-config-extender-name'; + } + throw new Error(`Could not find module "*${id}"`); + }; + + const require = (id: string) => { + switch (id) { + case 'conventional-changelog-lint-config-extender-name': return { rules: { fallback: true } }; - } + default: + return {}; } + }; + + const ctx = { resolve: jest.fn(resolve), require: jest.fn(require) } as ResolveExtendsContext; + + const actual = resolveExtends(input, { + ...ctx, + prefix: 'prefix' }); expect(actual).toEqual({ diff --git a/@commitlint/resolve-extends/src/index.ts b/@commitlint/resolve-extends/src/index.ts index c6f2032896..e54875de89 100644 --- a/@commitlint/resolve-extends/src/index.ts +++ b/@commitlint/resolve-extends/src/index.ts @@ -7,18 +7,22 @@ import { isArray, merge, mergeWith, omit } from 'lodash'; const importFresh = require('import-fresh'); export interface ResolvedConfig { - + parserPreset?: unknown; + [key: string]: unknown; } export interface ResolveExtendsConfig { parserPreset?: unknown; extends?: string[]; + [key: string]: unknown; } export interface ResolveExtendsContext { + cwd?: string; parserPreset?: unknown; prefix?: string; resolve?(id: string, ctx?: { prefix?: string, cwd?: string }): string; + resolveGlobal?: (id: string) => string; require?(id: string): T; } @@ -96,7 +100,7 @@ function resolveConfig(raw: string, context: ResolveExtendsContext = {}): str } } -function resolveId(id: string, context: { cwd?: string } = {}): string { +function resolveId(id: string, context: { cwd?: string, resolveGlobal?: (id: string) => string | void } = {}): string { const cwd = context.cwd || process.cwd(); const localPath = resolveFromSilent(cwd, id); @@ -104,7 +108,8 @@ function resolveId(id: string, context: { cwd?: string } = {}): string { return localPath; } - const globalPath = resolveGlobalSilent(id); + const resolveGlobal = context.resolveGlobal || resolveGlobalSilent; + const globalPath = resolveGlobal(id); if (typeof globalPath === 'string') { return globalPath; From c6b973c0fe74175d11a28cab94829fe97967ad5a Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Thu, 23 May 2019 10:58:26 +0000 Subject: [PATCH 5/5] fix: add missing node typings --- @commitlint/resolve-extends/package.json | 1 + yarn.lock | 9 +-------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/@commitlint/resolve-extends/package.json b/@commitlint/resolve-extends/package.json index 2a51fe678c..40bef11ad4 100644 --- a/@commitlint/resolve-extends/package.json +++ b/@commitlint/resolve-extends/package.json @@ -47,6 +47,7 @@ "typescript": "3.4.5" }, "dependencies": { + "@types/node": "^12.0.2", "import-fresh": "^3.0.0", "lodash": "4.17.11", "resolve-from": "^5.0.0", diff --git a/yarn.lock b/yarn.lock index 0c6ad30544..578cf20eb4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1109,13 +1109,6 @@ dependencies: "@babel/types" "^7.3.0" -"@types/execa@^0.9.0": - version "0.9.0" - resolved "https://registry.npmjs.org/@types/execa/-/execa-0.9.0.tgz#9b025d2755f17e80beaf9368c3f4f319d8b0fb93" - integrity sha512-mgfd93RhzjYBUHHV532turHC2j4l/qxsF/PbfDmprHDEUHmNZGlDn1CEsulGK3AfsPdhkWzZQT/S/k0UGhLGsA== - dependencies: - "@types/node" "*" - "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.1" resolved "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -1153,7 +1146,7 @@ resolved "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.130.tgz#04b3a690d5f4fc34579963c99adae067b8c8eb5a" integrity sha512-H++wk0tbneBsRVfLkgAAd0IIpmpVr2Bj4T0HncoOsQf3/xrJexRYQK2Tqo0Ej3pFslM8GkMgdis9bu6xIb1ycw== -"@types/node@*": +"@types/node@^12.0.2": version "12.0.2" resolved "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz#3452a24edf9fea138b48fad4a0a028a683da1e40" integrity sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==