From ade7af36dce86396e34773d843d443570f22ccbb Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Fri, 4 Oct 2019 17:57:42 +0900 Subject: [PATCH 1/5] refactor: port read to typescript --- @commitlint/cli/src/cli.js | 3 +- @commitlint/read/package.json | 26 +----- .../read/src/{index.test.js => index.test.ts} | 30 +++---- @commitlint/read/src/{index.js => index.ts} | 50 +++++++---- @commitlint/read/tsconfig.json | 15 ++++ @commitlint/top-level/src/index.ts | 2 +- tsconfig.json | 1 + yarn.lock | 83 ++++++++++++++++--- 8 files changed, 143 insertions(+), 67 deletions(-) rename @commitlint/read/src/{index.test.js => index.test.ts} (65%) rename @commitlint/read/src/{index.js => index.ts} (55%) create mode 100644 @commitlint/read/tsconfig.json diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index cad49f191f..f3b7a7eb26 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -1,9 +1,10 @@ #!/usr/bin/env node require('babel-polyfill'); // eslint-disable-line import/no-unassigned-import +import read from '@commitlint/read'; + const load = require('@commitlint/load'); const lint = require('@commitlint/lint'); -const read = require('@commitlint/read'); const meow = require('meow'); const {merge, pick, isFunction} = require('lodash'); const stdin = require('get-stdin'); diff --git a/@commitlint/read/package.json b/@commitlint/read/package.json index 946a6b0dd6..f0855c919d 100644 --- a/@commitlint/read/package.json +++ b/@commitlint/read/package.json @@ -3,30 +3,13 @@ "version": "8.1.0", "description": "Read commit messages from a specified range or last edit", "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", - "watch": "babel src --out-dir lib --watch --source-maps" - }, - "ava": { - "files": [ - "src/**/*.test.js", - "!lib/**/*" - ], - "source": [ - "src/**/*.js", - "!lib/**/*" - ], - "babel": "inherit", - "require": [ - "babel-register" - ] + "pkg": "pkg-check --skip-import" }, "babel": { "presets": [ @@ -58,13 +41,10 @@ "devDependencies": { "@commitlint/test": "8.0.0", "@commitlint/utils": "^8.1.0", - "ava": "0.22.0", "babel-cli": "6.26.0", "babel-preset-commitlint": "^8.0.0", "babel-register": "6.26.0", - "concurrently": "3.6.1", - "cross-env": "5.1.1", - "execa": "0.11.0" + "execa": "2.0.4" }, "dependencies": { "@commitlint/top-level": "^8.1.0", diff --git a/@commitlint/read/src/index.test.js b/@commitlint/read/src/index.test.ts similarity index 65% rename from @commitlint/read/src/index.test.js rename to @commitlint/read/src/index.test.ts index 4c4b93c4a7..1954b07d14 100644 --- a/@commitlint/read/src/index.test.js +++ b/@commitlint/read/src/index.test.ts @@ -1,33 +1,33 @@ -import {git} from '@commitlint/test'; -import test from 'ava'; import execa from 'execa'; -import * as sander from '@marionebl/sander'; + +const {git} = require('@commitlint/test'); +const sander = require('@marionebl/sander'); import read from '.'; -test('get edit commit message specified by the `edit` flag', async t => { - const cwd = await git.bootstrap(); +test('get edit commit message specified by the `edit` flag', async () => { + const cwd: string = await git.bootstrap(); await sander.writeFile(cwd, 'commit-msg-file', 'foo'); const expected = ['foo\n']; const actual = await read({edit: 'commit-msg-file', cwd}); - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); -test('get edit commit message from git root', async t => { - const cwd = await git.bootstrap(); +test('get edit commit message from git root', async () => { + const cwd: string = await git.bootstrap(); await sander.writeFile(cwd, 'alpha.txt', 'alpha'); await execa('git', ['add', '.'], {cwd}); await execa('git', ['commit', '-m', 'alpha'], {cwd}); const expected = ['alpha\n\n']; const actual = await read({edit: true, cwd}); - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); -test('get history commit messages', async t => { - const cwd = await git.bootstrap(); +test('get history commit messages', async () => { + const cwd: string = await git.bootstrap(); await sander.writeFile(cwd, 'alpha.txt', 'alpha'); await execa('git', ['add', 'alpha.txt'], {cwd}); await execa('git', ['commit', '-m', 'alpha'], {cwd}); @@ -36,11 +36,11 @@ test('get history commit messages', async t => { const expected = ['remove alpha\n\n', 'alpha\n\n']; const actual = await read({cwd}); - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); -test('get edit commit message from git subdirectory', async t => { - const cwd = await git.bootstrap(); +test('get edit commit message from git subdirectory', async () => { + const cwd: string = await git.bootstrap(); await sander.mkdir(cwd, 'beta'); await sander.writeFile(cwd, 'beta/beta.txt', 'beta'); @@ -49,5 +49,5 @@ test('get edit commit message from git subdirectory', async t => { const expected = ['beta\n\n']; const actual = await read({edit: true, cwd}); - t.deepEqual(actual, expected); + expect(actual).toEqual(expected); }); diff --git a/@commitlint/read/src/index.js b/@commitlint/read/src/index.ts similarity index 55% rename from @commitlint/read/src/index.js rename to @commitlint/read/src/index.ts index b9ae72e0b4..4dc44396b5 100644 --- a/@commitlint/read/src/index.js +++ b/@commitlint/read/src/index.ts @@ -1,14 +1,24 @@ import path from 'path'; -import gitRawCommits from 'git-raw-commits'; -import * as sander from '@marionebl/sander'; +import {Stats} from 'fs'; +import Buffer from 'buffer'; +import {Readable} from 'stream'; import toplevel from '@commitlint/top-level'; +const gitRawCommits = require('git-raw-commits'); +const sander = require('@marionebl/sander'); + +interface Settings { + cwd?: string; + from?: string; + to?: string; + edit?: boolean | string; +} + export default getCommitMessages; // Get commit messages -// Object => Promise> -async function getCommitMessages(settings) { +async function getCommitMessages(settings: Settings): Promise { const {cwd, from, to, edit} = settings; if (edit) { @@ -19,11 +29,13 @@ async function getCommitMessages(settings) { } // Get commit messages from history -// Object => Promise -function getHistoryCommits(options, opts = {}) { +function getHistoryCommits( + options: {from?: string; to?: string}, + opts: {cwd?: string} = {} +): Promise { return new Promise((resolve, reject) => { - const data = []; - gitRawCommits(options, {cwd: opts.cwd}) + const data: string[] = []; + (gitRawCommits(options, {cwd: opts.cwd}) as Readable) .on('data', chunk => data.push(chunk.toString('utf-8'))) .on('error', reject) .on('end', () => { @@ -33,8 +45,10 @@ function getHistoryCommits(options, opts = {}) { } // Get recently edited commit message -// (cwd: string, edit: any) => Promise> -async function getEditCommit(cwd, edit) { +async function getEditCommit( + cwd?: string, + edit?: boolean | string +): Promise { const top = await toplevel(cwd); if (typeof top !== 'string') { @@ -43,23 +57,27 @@ async function getEditCommit(cwd, edit) { const editFilePath = await getEditFilePath(top, edit); - const editFile = await sander.readFile(editFilePath); + const editFile: Buffer = await sander.readFile(editFilePath); return [`${editFile.toString('utf-8')}\n`]; } // Get path to recently edited commit message file -// (top: string, edit: any) => Promise -async function getEditFilePath(top, edit) { - let editFilePath; +async function getEditFilePath( + top: string, + edit?: boolean | string +): Promise { + let editFilePath: string; if (typeof edit === 'string') { editFilePath = path.resolve(top, edit); } else { const dotgitPath = path.join(top, '.git'); - const dotgitStats = sander.lstatSync(dotgitPath); + const dotgitStats: Stats = sander.lstatSync(dotgitPath); if (dotgitStats.isDirectory()) { editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); } else { - const gitFile = await sander.readFile(dotgitPath, {encoding: 'utf-8'}); + const gitFile: string = await sander.readFile(dotgitPath, { + encoding: 'utf-8' + }); const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); } diff --git a/@commitlint/read/tsconfig.json b/@commitlint/read/tsconfig.json new file mode 100644 index 0000000000..f4a57643f0 --- /dev/null +++ b/@commitlint/read/tsconfig.json @@ -0,0 +1,15 @@ +{ + "extends": "../../tsconfig.shared.json", + "compilerOptions": { + "composite": true, + "rootDir": "./src", + "outDir": "./lib" + }, + "include": [ + "./src" + ], + "exclude": [ + "./src/**/*.test.ts", + "./lib/**/*" + ] +} diff --git a/@commitlint/top-level/src/index.ts b/@commitlint/top-level/src/index.ts index 6984e899a7..dde9b29249 100644 --- a/@commitlint/top-level/src/index.ts +++ b/@commitlint/top-level/src/index.ts @@ -13,7 +13,7 @@ export default toplevel; /** * Find the next git root */ -async function toplevel(cwd: string) { +async function toplevel(cwd?: string) { const found = await up('.git', {cwd, type: 'directory'}); if (typeof found !== 'string') { diff --git a/tsconfig.json b/tsconfig.json index 02b03b0b40..04c654ea91 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,6 @@ { "path": "@commitlint/resolve-extends" }, { "path": "@commitlint/to-lines" }, { "path": "@commitlint/top-level" }, + { "path": "@commitlint/read" } ] } diff --git a/yarn.lock b/yarn.lock index f829f9b116..e252cad36d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2856,7 +2856,7 @@ brace-expansion@^1.1.7: braces@2.3.1, braces@^1.8.2, braces@^2.3.0: version "2.3.1" - resolved "https://registry.yarnpkg.com/braces/-/braces-2.3.1.tgz#7086c913b4e5a08dbe37ac0ee6a2500c4ba691bb" + resolved "https://registry.npmjs.org/braces/-/braces-2.3.1.tgz#7086c913b4e5a08dbe37ac0ee6a2500c4ba691bb" integrity sha512-SO5lYHA3vO6gz66erVvedSCkp7AKWdv6VcQ2N4ysXfPxdAlxAMMAdwegGGcv1Bqwm7naF1hNdk5d6AAIEHV2nQ== dependencies: arr-flatten "^1.1.0" @@ -3877,7 +3877,7 @@ cross-spawn@^5.0.1, cross-spawn@^5.1.0: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^6.0.0: +cross-spawn@^6.0.0, cross-spawn@^6.0.5: version "6.0.5" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== @@ -4050,7 +4050,7 @@ deep-equal@^1.0.0: deep-extend@0.5.1, deep-extend@^0.6.0, deep-extend@~0.4.0: version "0.5.1" - resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.5.1.tgz#b894a9dd90d3023fbf1c55a394fb858eb2066f1f" + resolved "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz#b894a9dd90d3023fbf1c55a394fb858eb2066f1f" integrity sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w== deep-is@~0.1.3: @@ -4514,6 +4514,21 @@ execa@0.9.0: signal-exit "^3.0.0" strip-eof "^1.0.0" +execa@2.0.4: + version "2.0.4" + resolved "https://registry.npmjs.org/execa/-/execa-2.0.4.tgz#2f5cc589c81db316628627004ea4e37b93391d8e" + integrity sha512-VcQfhuGD51vQUQtKIq2fjGDLDbL6N1DTQVpYzxZ7LPIXw3HqTuIz6uxRmpV1qf8i31LHf2kjiaGI+GdHwRgbnQ== + dependencies: + cross-spawn "^6.0.5" + get-stream "^5.0.0" + is-stream "^2.0.0" + merge-stream "^2.0.0" + npm-run-path "^3.0.0" + onetime "^5.1.0" + p-finally "^2.0.0" + signal-exit "^3.0.2" + strip-final-newline "^2.0.0" + execa@^0.10.0: version "0.10.0" resolved "https://registry.npmjs.org/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50" @@ -5133,6 +5148,13 @@ get-stream@^4.0.0, get-stream@^4.1.0: dependencies: pump "^3.0.0" +get-stream@^5.0.0: + version "5.1.0" + resolved "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9" + integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw== + dependencies: + pump "^3.0.0" + get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -5546,7 +5568,7 @@ hawk@3.1.3, hawk@~3.1.3: hoek@2.x.x, hoek@5.0.3: version "5.0.3" - resolved "https://registry.yarnpkg.com/hoek/-/hoek-5.0.3.tgz#b71d40d943d0a95da01956b547f83c4a5b4a34ac" + resolved "https://registry.npmjs.org/hoek/-/hoek-5.0.3.tgz#b71d40d943d0a95da01956b547f83c4a5b4a34ac" integrity sha512-Bmr56pxML1c9kU+NS51SMFkiVQAb+9uFfXwyqR2tn4w2FPvmPt65eZ9aCcEfRXd9G74HkZnILC6p967pED4aiw== home-or-tmp@^2.0.0: @@ -6275,6 +6297,11 @@ is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0: resolved "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= +is-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" + integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== + is-subset@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz#8a59117d932de1de00f245fcdd39ce43f1e939a6" @@ -6817,7 +6844,7 @@ js-tokens@^4.0.0: 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: version "3.13.1" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" + resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847" integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw== dependencies: argparse "^1.0.7" @@ -7451,7 +7478,7 @@ map-visit@^1.0.0: marked@0.3.9, marked@^0.3.6, marked@^0.5.1: version "0.3.9" - resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.9.tgz#54ce6a57e720c3ac6098374ec625fcbcc97ff290" + resolved "https://registry.npmjs.org/marked/-/marked-0.3.9.tgz#54ce6a57e720c3ac6098374ec625fcbcc97ff290" integrity sha512-nW5u0dxpXxHfkHzzrveY45gCbi+R4PaO4WRZYqZNl+vB0hVGeqlFn0aOg1c8AKL63TrNFn9Bm2UP4AdiZ9TPLw== matcher@^0.1.1: @@ -7596,6 +7623,11 @@ merge-stream@^1.0.1: dependencies: readable-stream "^2.0.1" +merge-stream@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" + integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== + merge2@1.2.1: version "1.2.1" resolved "https://registry.npmjs.org/merge2/-/merge2-1.2.1.tgz#271d2516ff52d4af7f7b710b8bf3e16e183fef66" @@ -7710,7 +7742,7 @@ mimic-fn@^1.0.0: resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" integrity sha1-5md4PZLonb00KBi1IwudYqZyrRg= -mimic-fn@^2.0.0: +mimic-fn@^2.0.0, mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== @@ -7811,7 +7843,7 @@ module-not-found-error@^1.0.1: moment@2.19.3, moment@^2.18.1: version "2.19.3" - resolved "https://registry.yarnpkg.com/moment/-/moment-2.19.3.tgz#bdb99d270d6d7fda78cc0fbace855e27fe7da69f" + resolved "https://registry.npmjs.org/moment/-/moment-2.19.3.tgz#bdb99d270d6d7fda78cc0fbace855e27fe7da69f" integrity sha1-vbmdJw1tf9p4zA+6zoVeJ/59pp8= move-concurrently@^1.0.1: @@ -8192,6 +8224,13 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" +npm-run-path@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-3.1.0.tgz#7f91be317f6a466efed3c9f2980ad8a4ee8b0fa5" + integrity sha512-Dbl4A/VfiVGLgQv29URL9xshU8XDY1GeLy+fsaZ1AA8JDSfjvr5P5+pzRbWqRSBxk6/DW7MIh8lTM/PaGnP2kg== + dependencies: + path-key "^3.0.0" + npm-which@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/npm-which/-/npm-which-3.0.1.tgz#9225f26ec3a285c209cae67c3b11a6b4ab7140aa" @@ -8327,6 +8366,13 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" +onetime@^5.1.0: + version "5.1.0" + resolved "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz#fff0f3c91617fe62bb50189636e99ac8a6df7be5" + integrity sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q== + dependencies: + mimic-fn "^2.1.0" + opencollective@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/opencollective/-/opencollective-1.0.3.tgz#aee6372bc28144583690c3ca8daecfc120dd0ef1" @@ -8481,6 +8527,11 @@ p-finally@^1.0.0: resolved "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= +p-finally@^2.0.0: + version "2.0.1" + resolved "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz#bd6fcaa9c559a096b680806f4d657b3f0f240561" + integrity sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw== + p-is-promise@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" @@ -8740,6 +8791,11 @@ path-key@^2.0.0, path-key@^2.0.1: resolved "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= +path-key@^3.0.0: + version "3.1.0" + resolved "https://registry.npmjs.org/path-key/-/path-key-3.1.0.tgz#99a10d870a803bdd5ee6f0470e58dfcd2f9a54d3" + integrity sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg== + path-parse@^1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" @@ -9114,7 +9170,7 @@ quick-lru@^1.0.0: randomatic@3: version "3.1.1" - resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" + resolved "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" integrity sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw== dependencies: is-number "^4.0.0" @@ -10242,7 +10298,7 @@ sprintf-js@~1.0.2: sshpk@1.14.1: version "1.14.1" - resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.14.1.tgz#130f5975eddad963f1d56f92b9ac6c51fa9f83eb" + resolved "https://registry.npmjs.org/sshpk/-/sshpk-1.14.1.tgz#130f5975eddad963f1d56f92b9ac6c51fa9f83eb" integrity sha1-Ew9Zde3a2WPx1W+SuaxsUfqfg+s= dependencies: asn1 "~0.2.3" @@ -10403,7 +10459,7 @@ stringify-object@^3.2.2: stringstream@0.0.6, stringstream@~0.0.4: version "0.0.6" - resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" + resolved "https://registry.npmjs.org/stringstream/-/stringstream-0.0.6.tgz#7880225b0d4ad10e30927d167a1d6f2fd3b33a72" integrity sha512-87GEBAkegbBcweToUrdzf3eLhWNg06FJTebl4BVJz/JgWy8CvEr9dRtX5qWphiynMSQlxxi+QqN0z5T32SLlhA== strip-ansi@^0.3.0: @@ -10463,6 +10519,11 @@ strip-eof@^1.0.0: resolved "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= +strip-final-newline@^2.0.0: + version "2.0.0" + resolved "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" + integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== + strip-indent@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2" From 11ac6aa6a8bd40dc525ac48826c8ed971eeae7c4 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 3 Feb 2020 19:41:35 +1100 Subject: [PATCH 2/5] fix: use @types/git-raw-commits --- @commitlint/read/package.json | 10 +- @commitlint/read/src/get-edit-commit.ts | 18 ++ @commitlint/read/src/get-edit-file-path.ts | 29 +++ @commitlint/read/src/get-history-commits.ts | 10 + @commitlint/read/src/index.ts | 87 --------- .../read/src/{index.test.ts => read.test.ts} | 2 +- @commitlint/read/src/read.ts | 20 ++ @commitlint/read/src/stream-to-promise.ts | 11 ++ @commitlint/read/tsconfig.json | 3 + yarn.lock | 182 +++++++++--------- 10 files changed, 181 insertions(+), 191 deletions(-) create mode 100644 @commitlint/read/src/get-edit-commit.ts create mode 100644 @commitlint/read/src/get-edit-file-path.ts create mode 100644 @commitlint/read/src/get-history-commits.ts delete mode 100644 @commitlint/read/src/index.ts rename @commitlint/read/src/{index.test.ts => read.test.ts} (98%) create mode 100644 @commitlint/read/src/read.ts create mode 100644 @commitlint/read/src/stream-to-promise.ts diff --git a/@commitlint/read/package.json b/@commitlint/read/package.json index f0855c919d..049530aeba 100644 --- a/@commitlint/read/package.json +++ b/@commitlint/read/package.json @@ -2,8 +2,8 @@ "name": "@commitlint/read", "version": "8.1.0", "description": "Read commit messages from a specified range or last edit", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "lib/read.js", + "types": "lib/read.d.ts", "files": [ "lib/" ], @@ -41,15 +41,11 @@ "devDependencies": { "@commitlint/test": "8.0.0", "@commitlint/utils": "^8.1.0", - "babel-cli": "6.26.0", - "babel-preset-commitlint": "^8.0.0", - "babel-register": "6.26.0", - "execa": "2.0.4" + "@types/git-raw-commits": "^2.0.0" }, "dependencies": { "@commitlint/top-level": "^8.1.0", "@marionebl/sander": "^0.6.0", - "babel-runtime": "^6.23.0", "git-raw-commits": "^1.3.0" } } diff --git a/@commitlint/read/src/get-edit-commit.ts b/@commitlint/read/src/get-edit-commit.ts new file mode 100644 index 0000000000..860cc04790 --- /dev/null +++ b/@commitlint/read/src/get-edit-commit.ts @@ -0,0 +1,18 @@ +import toplevel from '@commitlint/top-level'; + +// Get recently edited commit message +export async function getEditCommit( + cwd?: string, + edit?: boolean | string +): Promise { + const top = await toplevel(cwd); + + if (typeof top !== 'string') { + throw new TypeError(`Could not find git root from ${cwd}`); + } + + const editFilePath = await getEditFilePath(top, edit); + + const editFile: Buffer = await sander.readFile(editFilePath); + return [`${editFile.toString('utf-8')}\n`]; +} diff --git a/@commitlint/read/src/get-edit-file-path.ts b/@commitlint/read/src/get-edit-file-path.ts new file mode 100644 index 0000000000..1f8bbe588d --- /dev/null +++ b/@commitlint/read/src/get-edit-file-path.ts @@ -0,0 +1,29 @@ +import path from 'path'; +import {Stats} from 'fs'; + +const sander = require('@marionebl/sander'); + +// Get path to recently edited commit message file +export async function getEditFilePath( + top: string, + edit?: boolean | string +): Promise { + let editFilePath: string; + if (typeof edit === 'string') { + editFilePath = path.resolve(top, edit); + } else { + const dotgitPath = path.join(top, '.git'); + const dotgitStats: Stats = sander.lstatSync(dotgitPath); + if (dotgitStats.isDirectory()) { + editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); + } else { + const gitFile: string = await sander.readFile(dotgitPath, { + encoding: 'utf-8' + }); + const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); + editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); + } + } + + return editFilePath; +} diff --git a/@commitlint/read/src/get-history-commits.ts b/@commitlint/read/src/get-history-commits.ts new file mode 100644 index 0000000000..caf2fae197 --- /dev/null +++ b/@commitlint/read/src/get-history-commits.ts @@ -0,0 +1,10 @@ +import gitRawCommits from 'git-raw-commits'; +import {streamToPromise} from './stream-to-promise'; + +// Get commit messages from history +export async function getHistoryCommits( + options: {from?: string; to?: string}, + opts: {cwd?: string} = {} +): Promise { + return streamToPromise(gitRawCommits(options, {cwd: opts.cwd})); +} diff --git a/@commitlint/read/src/index.ts b/@commitlint/read/src/index.ts deleted file mode 100644 index 4dc44396b5..0000000000 --- a/@commitlint/read/src/index.ts +++ /dev/null @@ -1,87 +0,0 @@ -import path from 'path'; -import {Stats} from 'fs'; -import Buffer from 'buffer'; -import {Readable} from 'stream'; - -import toplevel from '@commitlint/top-level'; - -const gitRawCommits = require('git-raw-commits'); -const sander = require('@marionebl/sander'); - -interface Settings { - cwd?: string; - from?: string; - to?: string; - edit?: boolean | string; -} - -export default getCommitMessages; - -// Get commit messages -async function getCommitMessages(settings: Settings): Promise { - const {cwd, from, to, edit} = settings; - - if (edit) { - return getEditCommit(cwd, edit); - } - - return getHistoryCommits({from, to}, {cwd}); -} - -// Get commit messages from history -function getHistoryCommits( - options: {from?: string; to?: string}, - opts: {cwd?: string} = {} -): Promise { - return new Promise((resolve, reject) => { - const data: string[] = []; - (gitRawCommits(options, {cwd: opts.cwd}) as Readable) - .on('data', chunk => data.push(chunk.toString('utf-8'))) - .on('error', reject) - .on('end', () => { - resolve(data); - }); - }); -} - -// Get recently edited commit message -async function getEditCommit( - cwd?: string, - edit?: boolean | string -): Promise { - const top = await toplevel(cwd); - - if (typeof top !== 'string') { - throw new TypeError(`Could not find git root from ${cwd}`); - } - - const editFilePath = await getEditFilePath(top, edit); - - const editFile: Buffer = await sander.readFile(editFilePath); - return [`${editFile.toString('utf-8')}\n`]; -} - -// Get path to recently edited commit message file -async function getEditFilePath( - top: string, - edit?: boolean | string -): Promise { - let editFilePath: string; - if (typeof edit === 'string') { - editFilePath = path.resolve(top, edit); - } else { - const dotgitPath = path.join(top, '.git'); - const dotgitStats: Stats = sander.lstatSync(dotgitPath); - if (dotgitStats.isDirectory()) { - editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); - } else { - const gitFile: string = await sander.readFile(dotgitPath, { - encoding: 'utf-8' - }); - const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); - editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); - } - } - - return editFilePath; -} diff --git a/@commitlint/read/src/index.test.ts b/@commitlint/read/src/read.test.ts similarity index 98% rename from @commitlint/read/src/index.test.ts rename to @commitlint/read/src/read.test.ts index 1954b07d14..ded6904b12 100644 --- a/@commitlint/read/src/index.test.ts +++ b/@commitlint/read/src/read.test.ts @@ -3,7 +3,7 @@ import execa from 'execa'; const {git} = require('@commitlint/test'); const sander = require('@marionebl/sander'); -import read from '.'; +import read from './read'; test('get edit commit message specified by the `edit` flag', async () => { const cwd: string = await git.bootstrap(); diff --git a/@commitlint/read/src/read.ts b/@commitlint/read/src/read.ts new file mode 100644 index 0000000000..b3ba6eaeac --- /dev/null +++ b/@commitlint/read/src/read.ts @@ -0,0 +1,20 @@ +import { getHistoryCommits } from './get-history-commits'; +import { getEditCommit } from './get-edit-commit'; + +interface GetCommitMessageOptions { + cwd?: string; + from?: string; + to?: string; + edit?: boolean | string; +} + +// Get commit messages +export default async function getCommitMessages(settings: GetCommitMessageOptions): Promise { + const {cwd, from, to, edit} = settings; + + if (edit) { + return getEditCommit(cwd, edit); + } + + return getHistoryCommits({from, to}, {cwd}); +} diff --git a/@commitlint/read/src/stream-to-promise.ts b/@commitlint/read/src/stream-to-promise.ts new file mode 100644 index 0000000000..9d2518b9b5 --- /dev/null +++ b/@commitlint/read/src/stream-to-promise.ts @@ -0,0 +1,11 @@ +import { Readable } from 'stream'; + +export function streamToPromise(stream: Readable): Promise { + const data: string[] = []; + return new Promise((resolve, reject) => ( + stream + .on('data', chunk => data.push(chunk.toString('utf-8'))) + .on('error', reject) + .on('end', () => resolve(data)) + )); +} diff --git a/@commitlint/read/tsconfig.json b/@commitlint/read/tsconfig.json index f4a57643f0..5eb707a721 100644 --- a/@commitlint/read/tsconfig.json +++ b/@commitlint/read/tsconfig.json @@ -11,5 +11,8 @@ "exclude": [ "./src/**/*.test.ts", "./lib/**/*" + ], + "references": [ + { "path": "../top-level" } ] } diff --git a/yarn.lock b/yarn.lock index e252cad36d..231fd99928 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1244,6 +1244,13 @@ resolved "https://registry.npmjs.org/@types/find-up/-/find-up-2.1.1.tgz#1cd2d240f1ad1f48d32346074724dc3107248a11" integrity sha512-60LC501bQRN9/3yfVaEEMd7IndaufffL56PBRAejPpUrY304Ps1jfnjNqPw5jmM5R8JHWiKBAe5IHzNcPV41AA== +"@types/git-raw-commits@^2.0.0": + version "2.0.0" + resolved "https://packages.atlassian.com/api/npm/npm-remote/@types/git-raw-commits/-/git-raw-commits-2.0.0.tgz#157e9e4709db0748fb1aa623f8927ddd4864bac6" + integrity sha1-FX6eRwnbB0j7GqYj+JJ93UhkusY= + dependencies: + "@types/node" "*" + "@types/glob@^7.1.1": version "7.1.1" resolved "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" @@ -2854,7 +2861,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://packages.atlassian.com/api/npm/npm-remote/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== @@ -3877,7 +3893,7 @@ cross-spawn@^5.0.1, cross-spawn@^5.1.0: shebang-command "^1.2.0" which "^1.2.9" -cross-spawn@^6.0.0, cross-spawn@^6.0.5: +cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" integrity sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ== @@ -4048,10 +4064,15 @@ deep-equal@^1.0.0: resolved "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5" integrity sha1-9dJgKStmDghO/0zbyfCK0yR0SLU= -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://packages.atlassian.com/api/npm/npm-remote/deep-extend/-/deep-extend-0.6.0.tgz#c4fa7c95404a17a9c3e8ca7e1537312b736330ac" + integrity sha1-xPp8lUBKF6nD6Mp+FTcxK3NjMKw= + +deep-extend@~0.4.0: + version "0.4.2" + resolved "https://packages.atlassian.com/api/npm/npm-remote/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f" + integrity sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8= deep-is@~0.1.3: version "0.1.3" @@ -4514,21 +4535,6 @@ execa@0.9.0: signal-exit "^3.0.0" strip-eof "^1.0.0" -execa@2.0.4: - version "2.0.4" - resolved "https://registry.npmjs.org/execa/-/execa-2.0.4.tgz#2f5cc589c81db316628627004ea4e37b93391d8e" - integrity sha512-VcQfhuGD51vQUQtKIq2fjGDLDbL6N1DTQVpYzxZ7LPIXw3HqTuIz6uxRmpV1qf8i31LHf2kjiaGI+GdHwRgbnQ== - dependencies: - cross-spawn "^6.0.5" - get-stream "^5.0.0" - is-stream "^2.0.0" - merge-stream "^2.0.0" - npm-run-path "^3.0.0" - onetime "^5.1.0" - p-finally "^2.0.0" - signal-exit "^3.0.2" - strip-final-newline "^2.0.0" - execa@^0.10.0: version "0.10.0" resolved "https://registry.npmjs.org/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50" @@ -4598,6 +4604,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://packages.atlassian.com/api/npm/npm-remote/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" @@ -4793,6 +4806,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://packages.atlassian.com/api/npm/npm-remote/fill-range/-/fill-range-2.2.4.tgz#eb1e773abb056dcd8df2bfdf6af59b8b3a936565" + integrity sha1-6x53OrsFbc2N8r/favWbizqTZWU= + 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" @@ -5148,13 +5172,6 @@ get-stream@^4.0.0, get-stream@^4.1.0: dependencies: pump "^3.0.0" -get-stream@^5.0.0: - version "5.1.0" - resolved "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz#01203cdc92597f9b909067c3e656cc1f4d3c4dc9" - integrity sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw== - dependencies: - pump "^3.0.0" - get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" resolved "https://registry.npmjs.org/get-value/-/get-value-2.0.6.tgz#dc15ca1c672387ca76bd37ac0a395ba2042a2c28" @@ -5566,10 +5583,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://packages.atlassian.com/api/npm/npm-remote/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" + integrity sha1-ILt0A9POo5jpHcRxCo/xuCdKJe0= home-or-tmp@^2.0.0: version "2.0.0" @@ -6169,6 +6186,13 @@ is-npm@^1.0.0: resolved "https://registry.npmjs.org/is-npm/-/is-npm-1.0.0.tgz#f2fb63a65e4905b406c86072765a1a4dc793b9f4" integrity sha1-8vtjpl5JBbQGyGBydloaTceTufQ= +is-number@^2.1.0: + version "2.1.0" + resolved "https://packages.atlassian.com/api/npm/npm-remote/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" @@ -6297,11 +6321,6 @@ is-stream@^1.0.0, is-stream@^1.0.1, is-stream@^1.1.0: resolved "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" integrity sha1-EtSj3U5o4Lec6428hBc66A2RykQ= -is-stream@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/is-stream/-/is-stream-2.0.0.tgz#bde9c32680d6fae04129d6ac9d921ce7815f78e3" - integrity sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== - is-subset@^0.1.1: version "0.1.1" resolved "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz#8a59117d932de1de00f245fcdd39ce43f1e939a6" @@ -6842,7 +6861,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== @@ -7314,11 +7333,21 @@ lodash.uniq@^4.5.0: resolved "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@4.17.11, lodash@4.17.14, 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: + version "4.17.11" + resolved "https://packages.atlassian.com/api/npm/npm-remote/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d" + integrity sha1-s56mIp72B+zYniyN8SU2iRysm40= + +lodash@4.17.14, 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.14" resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.14.tgz#9ce487ae66c96254fe20b599f21b6816028078ba" integrity sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw== +lodash@^3.3.1: + version "3.10.1" + resolved "https://packages.atlassian.com/api/npm/npm-remote/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" @@ -7476,11 +7505,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://packages.atlassian.com/api/npm/npm-remote/marked/-/marked-0.5.2.tgz#3efdb27b1fd0ecec4f5aba362bddcd18120e5ba9" + integrity sha1-Pv2yex/Q7OxPWro2K93NGBIOW6k= + matcher@^0.1.1: version "0.1.2" resolved "https://registry.npmjs.org/matcher/-/matcher-0.1.2.tgz#ef20cbde64c24c50cc61af5b83ee0b1b8ff00101" @@ -7623,11 +7657,6 @@ merge-stream@^1.0.1: dependencies: readable-stream "^2.0.1" -merge-stream@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" - integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== - merge2@1.2.1: version "1.2.1" resolved "https://registry.npmjs.org/merge2/-/merge2-1.2.1.tgz#271d2516ff52d4af7f7b710b8bf3e16e183fef66" @@ -7742,7 +7771,7 @@ mimic-fn@^1.0.0: resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" integrity sha1-5md4PZLonb00KBi1IwudYqZyrRg= -mimic-fn@^2.0.0, mimic-fn@^2.1.0: +mimic-fn@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== @@ -7841,7 +7870,7 @@ module-not-found-error@^1.0.1: 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= @@ -8224,13 +8253,6 @@ npm-run-path@^2.0.0: dependencies: path-key "^2.0.0" -npm-run-path@^3.0.0: - version "3.1.0" - resolved "https://registry.npmjs.org/npm-run-path/-/npm-run-path-3.1.0.tgz#7f91be317f6a466efed3c9f2980ad8a4ee8b0fa5" - integrity sha512-Dbl4A/VfiVGLgQv29URL9xshU8XDY1GeLy+fsaZ1AA8JDSfjvr5P5+pzRbWqRSBxk6/DW7MIh8lTM/PaGnP2kg== - dependencies: - path-key "^3.0.0" - npm-which@^3.0.1: version "3.0.1" resolved "https://registry.npmjs.org/npm-which/-/npm-which-3.0.1.tgz#9225f26ec3a285c209cae67c3b11a6b4ab7140aa" @@ -8366,13 +8388,6 @@ onetime@^2.0.0: dependencies: mimic-fn "^1.0.0" -onetime@^5.1.0: - version "5.1.0" - resolved "https://registry.npmjs.org/onetime/-/onetime-5.1.0.tgz#fff0f3c91617fe62bb50189636e99ac8a6df7be5" - integrity sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q== - dependencies: - mimic-fn "^2.1.0" - opencollective@^1.0.3: version "1.0.3" resolved "https://registry.npmjs.org/opencollective/-/opencollective-1.0.3.tgz#aee6372bc28144583690c3ca8daecfc120dd0ef1" @@ -8527,11 +8542,6 @@ p-finally@^1.0.0: resolved "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4= -p-finally@^2.0.0: - version "2.0.1" - resolved "https://registry.npmjs.org/p-finally/-/p-finally-2.0.1.tgz#bd6fcaa9c559a096b680806f4d657b3f0f240561" - integrity sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw== - p-is-promise@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" @@ -8791,11 +8801,6 @@ path-key@^2.0.0, path-key@^2.0.1: resolved "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A= -path-key@^3.0.0: - version "3.1.0" - resolved "https://registry.npmjs.org/path-key/-/path-key-3.1.0.tgz#99a10d870a803bdd5ee6f0470e58dfcd2f9a54d3" - integrity sha512-8cChqz0RP6SHJkMt48FW0A7+qUOn+OsnOsVtzI59tZ8m+5bCSk7hzwET0pulwOM2YMn9J1efb07KB9l9f30SGg== - path-parse@^1.0.5: version "1.0.5" resolved "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" @@ -8970,6 +8975,11 @@ prepend-http@^1.0.1: resolved "https://registry.npmjs.org/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= +preserve@^0.2.0: + version "0.2.0" + resolved "https://packages.atlassian.com/api/npm/npm-remote/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" @@ -9168,10 +9178,10 @@ quick-lru@^1.0.0: resolved "https://registry.npmjs.org/quick-lru/-/quick-lru-1.1.0.tgz#4360b17c61136ad38078397ff11416e186dcfbb8" integrity sha1-Q2CxfGETatOAeDl/8RQW4Ybc+7g= -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== + resolved "https://packages.atlassian.com/api/npm/npm-remote/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed" + integrity sha1-t3bvxZN1mE42xTey9RofCv8Noe0= dependencies: is-number "^4.0.0" kind-of "^6.0.0" @@ -9533,7 +9543,7 @@ repeat-element@^1.1.2: resolved "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" integrity sha1-7wiaF40Ug7quTZPrmLT55OEdmQo= -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" integrity sha1-jcrkcOHIirwtYA//Sndihtp15jc= @@ -10296,21 +10306,6 @@ sprintf-js@~1.0.2: resolved "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -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" @@ -10457,7 +10452,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== @@ -10519,11 +10514,6 @@ strip-eof@^1.0.0: resolved "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" integrity sha1-u0P/VZim6wXYm1n80SnJgzE2Br8= -strip-final-newline@^2.0.0: - version "2.0.0" - resolved "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad" - integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== - strip-indent@^1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/strip-indent/-/strip-indent-1.0.1.tgz#0c7962a6adefa7bbd4ac366460a638552ae1a0a2" From 3d4f50685903454530e7b52a16dd92fd04081735 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 3 Feb 2020 19:55:06 +1100 Subject: [PATCH 3/5] fix: adapt to latest master --- @commitlint/read/src/get-edit-commit.ts | 3 +++ @commitlint/top-level/src/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/@commitlint/read/src/get-edit-commit.ts b/@commitlint/read/src/get-edit-commit.ts index 860cc04790..a36a7ba0ea 100644 --- a/@commitlint/read/src/get-edit-commit.ts +++ b/@commitlint/read/src/get-edit-commit.ts @@ -1,4 +1,7 @@ import toplevel from '@commitlint/top-level'; +import {getEditFilePath} from './get-edit-file-path'; + +const sander = require('@marionebl/sander'); // Get recently edited commit message export async function getEditCommit( diff --git a/@commitlint/top-level/src/index.ts b/@commitlint/top-level/src/index.ts index 1ea308ea39..4fb04043e4 100644 --- a/@commitlint/top-level/src/index.ts +++ b/@commitlint/top-level/src/index.ts @@ -13,7 +13,7 @@ export default toplevel; /** * Find the next git root */ -async function toplevel(cwd: string) { +async function toplevel(cwd?: string) { const found = await searchDotGit(cwd); if (typeof found !== 'string') { @@ -26,7 +26,7 @@ async function toplevel(cwd: string) { /** * Search .git, the '.git' can be a file(submodule), also can be a directory(normal) */ -async function searchDotGit(cwd: string) { +async function searchDotGit(cwd?: string) { const foundFile = await up('.git', {cwd, type: 'file'}); const foundDir = await up('.git', {cwd, type: 'directory'}); From 4a8a4c97c7209207aaf59134706018caf9afcccc Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 3 Feb 2020 19:56:52 +1100 Subject: [PATCH 4/5] refactor: unnest getEditFilePath --- @commitlint/read/src/get-edit-file-path.ts | 28 ++++++++++------------ 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/@commitlint/read/src/get-edit-file-path.ts b/@commitlint/read/src/get-edit-file-path.ts index 1f8bbe588d..3b8ecf37aa 100644 --- a/@commitlint/read/src/get-edit-file-path.ts +++ b/@commitlint/read/src/get-edit-file-path.ts @@ -8,22 +8,20 @@ export async function getEditFilePath( top: string, edit?: boolean | string ): Promise { - let editFilePath: string; if (typeof edit === 'string') { - editFilePath = path.resolve(top, edit); - } else { - const dotgitPath = path.join(top, '.git'); - const dotgitStats: Stats = sander.lstatSync(dotgitPath); - if (dotgitStats.isDirectory()) { - editFilePath = path.join(top, '.git/COMMIT_EDITMSG'); - } else { - const gitFile: string = await sander.readFile(dotgitPath, { - encoding: 'utf-8' - }); - const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); - editFilePath = path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); - } + return path.resolve(top, edit); } - return editFilePath; + const dotgitPath = path.join(top, '.git'); + const dotgitStats: Stats = sander.lstatSync(dotgitPath); + + if (dotgitStats.isDirectory()) { + return path.join(top, '.git/COMMIT_EDITMSG'); + } + + const gitFile: string = await sander.readFile(dotgitPath, { + encoding: 'utf-8' + }); + const relativeGitPath = gitFile.replace('gitdir: ', '').replace('\n', ''); + return path.resolve(top, relativeGitPath, 'COMMIT_EDITMSG'); } From 147d0278f9cc28314f4910038dadadae90759cbc Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Mon, 3 Feb 2020 19:57:41 +1100 Subject: [PATCH 5/5] style: apply autoformatting --- @commitlint/read/src/read.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/@commitlint/read/src/read.ts b/@commitlint/read/src/read.ts index b3ba6eaeac..6074d9d9b4 100644 --- a/@commitlint/read/src/read.ts +++ b/@commitlint/read/src/read.ts @@ -1,5 +1,5 @@ -import { getHistoryCommits } from './get-history-commits'; -import { getEditCommit } from './get-edit-commit'; +import {getHistoryCommits} from './get-history-commits'; +import {getEditCommit} from './get-edit-commit'; interface GetCommitMessageOptions { cwd?: string; @@ -9,7 +9,9 @@ interface GetCommitMessageOptions { } // Get commit messages -export default async function getCommitMessages(settings: GetCommitMessageOptions): Promise { +export default async function getCommitMessages( + settings: GetCommitMessageOptions +): Promise { const {cwd, from, to, edit} = settings; if (edit) {