Skip to content

Commit

Permalink
chore: Use named capture groups polyfill on Node.js < v10
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Feb 10, 2019
1 parent 8f5cb7f commit b0a7d77
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
8 changes: 7 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@ jobs:
key: v1-dependencies-{{ checksum "package.json" }}

- run:
name: Run tests and coverage
name: Run Node.js v10 tests and coverage
command: |
set -e
npm run test-coverage
- run:
name: Run Node.js v8 tests
command: |
nvm use 8
npm run test
- run:
name: Send coverage to Code Climate
command: ./cc-test-reporter after-build --coverage-input-type lcov --exit-code $?
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"cross-spawn": "^6.0.4",
"debug": "^4.1.1",
"lodash": "^4.17.11",
"normalize-path": "^3.0.0"
"normalize-path": "^3.0.0",
"regexp-polyfill": "^1.0.1"
},
"optionalDependencies": {},
"devDependencies": {
Expand Down
27 changes: 19 additions & 8 deletions src/regexp.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
const LINE_SPLIT = /\n|\r\n|\x08+|\r +\r/
const BODY_PROGRESS = /^ *(?<percent>\d+)% ?(?<fileCount>\d+)? ?(?<file>.*)$/
const BODY_SYMBOL_FILE = /^(?<symbol>[=TU+R.-]) (?<file>.+)$/
const BODY_HASH = /^(?<hash>\S+)? +(?<size>\d*) +(?<file>.+)$/
const END_OF_STAGE_HYPHEN = /^(-+ +)+-+$/
const INFOS = /^(?<property>.+?)(?<separator>( = )|(: +))(?<value>.+)$/
const INFOS_SPLIT = /, +# /
const ERROR = /(?<level>WARNING|ERROR): (?<message>.*)(\r\n)?(\n)?/i
// @COMPAT Named capture groups aren't available before Node.js 10. This
// compatibility checks the running Node.js version and apply a polyfill
// if needed.
// Support until Jan 2020 (https://github.com/nodejs/Release)
const semver = /v(\d+)\.(\d+)\.(\d+)/
const nodeVersionResults = process.version.match(semver)
const nodeVersionMajor = parseInt(nodeVersionResults[1])
if (nodeVersionMajor < 10) {
require('regexp-polyfill')
}

const LINE_SPLIT = new RegExp('\n|\r\n|\x08+|\r +\r')
const BODY_PROGRESS = new RegExp('^ *(?<percent>\\d+)% ?(?<fileCount>\\d+)? ?(?<file>.*)$')
const BODY_SYMBOL_FILE = new RegExp('^(?<symbol>[=TU+R.-]) (?<file>.+)$')
const BODY_HASH = new RegExp('^(?<hash>\\S+)? +(?<size>\\d*) +(?<file>.+)$')
const END_OF_STAGE_HYPHEN = new RegExp('^(-+ +)+-+$')
const INFOS = new RegExp('^(?<property>.+?)(?<separator>( = )|(: +))(?<value>.+)$')
const INFOS_SPLIT = new RegExp(', +# ')
const ERROR = new RegExp('(?<level>WARNING|ERROR): (?<message>.*)(\r\n)?(\n)?', 'i')

module.exports = {
LINE_SPLIT,
Expand Down

0 comments on commit b0a7d77

Please sign in to comment.