Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade deps and convert to TypeScript #15

Merged
merged 14 commits into from
Feb 15, 2022
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
src/parser.js
package.json
src/parser.ts
dist
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
# set:ft=yaml:

env:
browser: true
Expand All @@ -7,17 +8,24 @@ env:
node: true

plugins:
- "@typescript-eslint"
- jest
- prettier

extends:
- eslint:recommended
- plugin:jest/recommended
- plugin:prettier/recommended
- plugin:@typescript-eslint/recommended

parser: "@typescript-eslint/parser"

parserOptions:
ecmaVersion: 2018

ignorePatterns:
- "src/parser.ts"

rules:
indent:
- error
Expand Down Expand Up @@ -47,3 +55,5 @@ rules:

prettier/prettier:
- error

"@typescript-eslint/ban-ts-comment": 'off'
12 changes: 4 additions & 8 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x, 15.x]
node-version: [16.x, 17.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- uses: borales/actions-yarn@v2.0.0
with:
cmd: install
- uses: borales/actions-yarn@v2.0.0
with:
cmd: test
- run: yarn
- run: yarn test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules
src/parser.ts
dist
.eslintcache
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a user.

## How does it work?

It uses a [PegJS](https://pegjs.org/) grammar to transform JQ expressions
It uses a [parsed expression grammar][peg] (via [Peggy][peggy]) to transform JQ expressions
into a series of "op codes", with each one representing a JQ filter
operation. Each op code is executed with a context, which is initialised
with the input object. As each op code executes, the context is updated.
Expand All @@ -26,3 +26,6 @@ with the input object. As each op code executes, the context is updated.

* Complete implementation of JQ (but the level of completeness may
increase over time).

[peg]: https://en.wikipedia.org/wiki/Parsing_expression_grammar
[peggy]: https://peggyjs.org/
38 changes: 28 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,39 @@
"name": "@elastic/micro-jq",
"version": "1.4.3",
"description": "Small implementation of jq",
"main": "./src/index.js",
"main": "./dist/index.js",
"license": "Apache-2.0",
"bin": "./src/cli.js",
"bin": "./dist/cli.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "pegjs -o ./src/parser.js ./src/parser.pegjs",
"lint": "eslint .",
"build": "peggy --plugin ./node_modules/ts-pegjs --cache -o ./src/parser.ts ./src/parser.pegjs && tsc --declaration --outdir dist src/*.ts",
"lint": "eslint --cache src",
"test": "yarn lint && yarn build && jest"
},
"devDependencies": {
"eslint": "^7.31.0",
"@types/jest": "^27.4.0",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-jest": "^24.4.0",
"eslint-plugin-prettier": "^3.4.0",
"jest": "^27.0.6",
"pegjs": "^0.10.0",
"prettier": "^2.3.2"
"eslint-plugin-jest": "^26.1.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.5.1",
"peggy": "^1.2.0",
"prettier": "^2.5.1",
"ts-jest": "^27.1.3",
"ts-pegjs": "^1.2.1",
"typescript": "^4.5.5"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"globals": {
"ts-jest": {
"tsconfig": {
"noImplicitAny": false
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/cli.js → src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable no-console */

const fs = require('fs')
const executeScript = require('./execute')
import { readFileSync } from 'fs'
import executeScript from './execute'

const script = process.argv[2] || '.'

const input = JSON.parse(fs.readFileSync(0, 'utf8'))
const input = JSON.parse(readFileSync(0, 'utf8'))

const result = executeScript(input, script)

Expand Down
247 changes: 0 additions & 247 deletions src/execute.js

This file was deleted.

Loading