Skip to content

Commit

Permalink
feat: support big integers (#44)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Node >= 10.8

* feat: support big integers

* chore: circle
  • Loading branch information
P0lip authored May 12, 2020
1 parent c88d57e commit 590785a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 17 deletions.
57 changes: 49 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,67 @@
version: 2
version: 2.1

commands:
cached-dependencies:
steps:
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn

install_and_test:
description: >-
Install everything required to run the test suite, then run it.
steps:
- cached-dependencies
- run: yarn test.prod

jobs:
test_node_8:
# https://nodejs.org/en/about/releases/
test_node_lts:
docker:
- image: circleci/node:8
- image: circleci/node:lts
steps:
- checkout
- run:
name: Download cc-test-reporter
command: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
- run: yarn
- run:
name: cc-before
command: |
./cc-test-reporter before-build
- run: yarn test.prod
- install_and_test
- run:
name: cc-after
command: |
./cc-test-reporter after-build --coverage-input-type lcov --exit-code $?
test_node_dubnium:
docker:
- image: circleci/node:dubnium
steps:
- checkout
- install_and_test

test_node_latest:
docker:
- image: circleci/node:latest
steps:
- checkout
- install_and_test

release:
docker:
- image: circleci/node:8
- image: circleci/node:lts
steps:
- checkout
- run: yarn
Expand All @@ -35,10 +72,14 @@ workflows:
version: 2
test_and_release:
jobs:
- test_node_8
- test_node_lts
- test_node_dubnium
- test_node_latest
- release:
filters:
branches:
only: master
requires:
- test_node_8
- test_node_lts
- test_node_dubnium
- test_node_latest
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"**/*"
],
"engines": {
"node": ">=8.3.0"
"node": ">=10.8"
},
"scripts": {
"build": "sl-scripts build",
Expand All @@ -41,7 +41,7 @@
"dependencies": {
"@stoplight/ordered-object-literal": "^1.0.1",
"@stoplight/types": "^11.1.1",
"@stoplight/yaml-ast-parser": "0.0.45",
"@stoplight/yaml-ast-parser": "0.0.46",
"lodash": "^4.17.15"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/parseWithPointers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,4 +812,8 @@ bar: false
});
});
});

test.each(['6917528997577384320', '9223372036854775807'])('big int %s', value => {
expect(parseWithPointers(`${value}`).data).toEqual(BigInt(value));
});
});
6 changes: 3 additions & 3 deletions src/parseWithPointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { DiagnosticSeverity, Dictionary, IDiagnostic, Optional } from '@stopligh
import {
determineScalarType,
load as loadAST,
parseYamlBigInteger,
parseYamlBoolean,
parseYamlFloat,
parseYamlInteger,
YAMLException,
} from '@stoplight/yaml-ast-parser';
import { buildJsonPath } from './buildJsonPath';
Expand Down Expand Up @@ -120,7 +120,7 @@ export const walkAST = (
return node;
};

function getScalarValue(node: YAMLScalar): number | null | boolean | string | void {
function getScalarValue(node: YAMLScalar): number | bigint | null | boolean | string | void {
switch (determineScalarType(node)) {
case ScalarType.null:
return null;
Expand All @@ -129,7 +129,7 @@ function getScalarValue(node: YAMLScalar): number | null | boolean | string | vo
case ScalarType.bool:
return parseYamlBoolean(node.value);
case ScalarType.int:
return parseYamlInteger(node.value);
return parseYamlBigInteger(node.value);
case ScalarType.float:
return parseYamlFloat(node.value);
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": "./node_modules/@stoplight/scripts/tsconfig.json",
"lib": ["es2020", "dom"],

// target all ts files
"include": ["."]
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1587,10 +1587,10 @@
dependencies:
"@types/json-schema" "^7.0.3"

"@stoplight/[email protected].45":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.45.tgz#672c0a1511d581843be5a9c55899ca95a30dcadb"
integrity sha512-0MTEvgp3XMdeMUSTCGiNECuC+YlLbzytDEIOJVDHrrmzVZpIR3gGnHI6mmPI4P7saPxUiHxFF2uuoTuCNlKjrw==
"@stoplight/[email protected].46":
version "0.0.46"
resolved "https://registry.yarnpkg.com/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.46.tgz#ee9c8da3d8b89ae9007bfe015daf34ee68db9bd5"
integrity sha512-eKVeNt6n3U/nA2hjwUsyLOC48DaMiwRx/qrLPzt9Oie+ke4lPA2Jm8ozUMcleVdV5JyZNpG3UhBcSb3PTlt0Kw==

"@storybook/[email protected]":
version "4.0.11"
Expand Down

0 comments on commit 590785a

Please sign in to comment.