Comparing version 4.1.0-rc.3 to 4.1.0
@@ -1,1 +0,1 @@ | ||
export default function(command: string, args: string[], stdin: string, cwd?: string): Promise<string> | ||
export default function(command: string, args: string[], stdin: string, cwd?: string, detached?: boolean): Promise<string> |
@@ -14,3 +14,3 @@ "use strict"; | ||
var TEN_MEBIBYTE = 1024 * 1024 * 10; | ||
var exec = function(command, args, stdin, cwd) { | ||
var exec = function(command, args, stdin, cwd, detached) { | ||
return new Promise(function(resolve, reject) { | ||
@@ -22,2 +22,3 @@ var stdout = ""; | ||
cwd: cwd, | ||
detached: detached, | ||
env: {} | ||
@@ -24,0 +25,0 @@ }; |
import { PartialOptions } from "./options" | ||
export function run(filter: string, json: any, options?: PartialOptions, jqPath?: string, cwd?: string): Promise<object | string> | ||
export function run(filter: string, json: any, options?: PartialOptions, jqPath?: string, cwd?: string, detached?: boolean): Promise<object | string> |
@@ -14,6 +14,6 @@ "use strict"; | ||
var run = function(filter, json) { | ||
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, jqPath = arguments.length > 3 ? arguments[3] : void 0, cwd = arguments.length > 4 ? arguments[4] : void 0; | ||
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, jqPath = arguments.length > 3 ? arguments[3] : void 0, cwd = arguments.length > 4 ? arguments[4] : void 0, detached = arguments.length > 5 ? arguments[5] : void 0; | ||
return new Promise(function(resolve, reject) { | ||
var ref = (0, _command).commandFactory(filter, json, options, jqPath), command = ref.command, args = ref.args, stdin = ref.stdin; | ||
(0, _exec).default(command, args, stdin, cwd).then(function(stdout) { | ||
(0, _exec).default(command, args, stdin, cwd, detached).then(function(stdout) { | ||
if (options.output === "json") { | ||
@@ -20,0 +20,0 @@ var result; |
{ | ||
"name": "node-jq", | ||
"version": "4.1.0-rc.3", | ||
"version": "4.1.0", | ||
"description": "Run jq in node", | ||
@@ -5,0 +5,0 @@ "main": "lib/jq.js", |
@@ -9,3 +9,3 @@ <br/> | ||
[node-jq](https://github.com/sanack/node-jq) is a Node.js wrapper for [jq](https://stedolan.github.io/jq/) - a lightweight and flexible command-line JSON processor | ||
[node-jq](https://github.com/sanack/node-jq) is a Node.js wrapper for [jq](https://jqlang.github.io/jq/) - a lightweight and flexible command-line JSON processor | ||
@@ -22,5 +22,13 @@ --- | ||
## Fast | ||
You can use `jq` directly after installing it: | ||
```bash | ||
npx node-jq '.foo' package.json | ||
``` | ||
## Advanced installation | ||
By default, `node-jq` downloads `jq` during the installation process with a post-install script. Depending on your SO downloads from [https://github.com/stedolan/jq/releases] into `./node_modules/node-jq/bin/jq` to avoid colisions with any global installation. Check #161 #167 #171 for more information. You can safely rely on this location for your installed `jq`, we won't change this path without a major version upgrade. | ||
By default, `node-jq` downloads `jq` during the installation process with a post-install script. Depending on your SO downloads from [https://github.com/jqlang/jq/releases] into `./node_modules/node-jq/bin/jq` to avoid colisions with any global installation. Check #161 #167 #171 for more information. You can safely rely on this location for your installed `jq`, we won't change this path without a major version upgrade. | ||
@@ -234,2 +242,37 @@ If you want to skip the installation step of `jq`, you can set `NODE_JQ_SKIP_INSTALL_BINARY` to `true` or ignore the post-install script from the installation `npm install node-jq --ignore-scripts`. | ||
### cwd | ||
| Description | Values | Default | | ||
|:--------------------------------:|:----------:|:-------------:| | ||
| Set working dir for `jq` process | valid path | process.cwd() | | ||
```javascript | ||
jq.run('.', ['file.json'], { output: 'json', sort: true }, '/path/to').then(console.log) | ||
// { | ||
// "a": 2, | ||
// "b": 1 | ||
// }, | ||
``` | ||
### detached | ||
| Description | Values | Default | | ||
|:------------------------------------:|:---------------:|:--------:| | ||
| Run `jq` process as detached process | `true`, `false` | `false` | | ||
By default `jq` process will run 'attached' to the main process. That means that any interrupt signal main process receives will be propagated to `jq` process. For example, if main process receives `SIGTERM`, `jq` will also receive it and exit immediately. | ||
However, in some cases you might **not** want `jq` to exit immediately and let it exit normally. For example, if you want to implement a graceful shutdown - main process receives `SIGTERM`, it finishes processing current json file and exits after processing is completed. | ||
To achieve that run `jq` detached and NodeJS will not propagate `SIGTERM` to `jq` process allowing it to run until it completes. | ||
```javascript | ||
jq.run('.', ['file.json'], { output: 'json', sort: true }, undefined, true).then(console.log) | ||
// { | ||
// "a": 2, | ||
// "b": 1 | ||
// }, | ||
``` | ||
## Projects using **node-jq** | ||
@@ -268,3 +311,3 @@ | ||
You can check out the [official manual](https://stedolan.github.io/jq/manual) and fiddle around in the online playground [jqplay.org](https://jqplay.org). | ||
You can check out the [official manual](https://jqlang.github.io/jq/manual) and fiddle around in the online playground [jqplay.org](https://jqplay.org). | ||
@@ -271,0 +314,0 @@ ## License |
@@ -34,4 +34,4 @@ #!/usr/bin/env node | ||
name: 'jq', | ||
url: 'https://github.com/stedolan/jq/releases/download/', | ||
version: 'jq-1.6' | ||
url: 'https://github.com/jqlang/jq/releases/download/', | ||
version: 'jq-1.7' | ||
} | ||
@@ -71,26 +71,23 @@ | ||
// if platform is missing, download source instead of executable | ||
// if platform or arch is missing, download source instead of executable | ||
const DOWNLOAD_MAP = { | ||
win32: { | ||
def: 'jq-win32.exe', | ||
x64: 'jq-win64.exe' | ||
x64: 'jq-windows-amd64.exe', | ||
ia32: 'jq-windows-i386.exe' | ||
}, | ||
darwin: { | ||
def: 'jq-osx-amd64', | ||
x64: 'jq-osx-amd64' | ||
x64: 'jq-macos-amd64', | ||
arm64: 'jq-macos-arm64' | ||
}, | ||
linux: { | ||
def: 'jq-linux32', | ||
x64: 'jq-linux64' | ||
x64: 'jq-linux-amd64', | ||
ia32: 'jq-linux-i386', | ||
arm64: 'jq-linux-arm64' | ||
} | ||
} | ||
if (platform in DOWNLOAD_MAP) { | ||
if (platform in DOWNLOAD_MAP && arch in DOWNLOAD_MAP[platform]) { | ||
// download the executable | ||
const filename = | ||
arch in DOWNLOAD_MAP[platform] | ||
? DOWNLOAD_MAP[platform][arch] | ||
: DOWNLOAD_MAP[platform].def | ||
const filename = DOWNLOAD_MAP[platform][arch] | ||
const url = `${JQ_INFO.url}${JQ_INFO.version}/${filename}` | ||
@@ -123,4 +120,3 @@ | ||
.url(url, [ | ||
'autoreconf -fi', | ||
`./configure --disable-maintainer-mode --with-oniguruma=builtin --prefix=${tempfile()} --bindir=${OUTPUT_DIR}`, | ||
`./configure --with-oniguruma=builtin --prefix=${tempfile()} --bindir=${OUTPUT_DIR}`, | ||
'make -j8', | ||
@@ -127,0 +123,0 @@ 'make install' |
@@ -1,1 +0,1 @@ | ||
export default function(command: string, args: string[], stdin: string, cwd?: string): Promise<string> | ||
export default function(command: string, args: string[], stdin: string, cwd?: string, detached?: boolean): Promise<string> |
@@ -6,3 +6,3 @@ import childProcess from 'child_process' | ||
const exec = (command, args, stdin, cwd) => { | ||
const exec = (command, args, stdin, cwd, detached) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -12,3 +12,3 @@ let stdout = '' | ||
const spawnOptions = { maxBuffer: TEN_MEBIBYTE, cwd, env: {} } | ||
const spawnOptions = { maxBuffer: TEN_MEBIBYTE, cwd, detached, env: {} } | ||
@@ -15,0 +15,0 @@ const process = childProcess.spawn(command, args, spawnOptions) |
import { PartialOptions } from "./options" | ||
export function run(filter: string, json: any, options?: PartialOptions, jqPath?: string, cwd?: string): Promise<object | string> | ||
export function run(filter: string, json: any, options?: PartialOptions, jqPath?: string, cwd?: string, detached?: boolean): Promise<object | string> |
import exec from './exec' | ||
import { commandFactory } from './command' | ||
export const run = (filter, json, options = {}, jqPath, cwd) => { | ||
export const run = (filter, json, options = {}, jqPath, cwd, detached) => { | ||
return new Promise((resolve, reject) => { | ||
@@ -13,3 +13,3 @@ const { command, args, stdin } = commandFactory( | ||
exec(command, args, stdin, cwd) | ||
exec(command, args, stdin, cwd, detached) | ||
.then((stdout) => { | ||
@@ -16,0 +16,0 @@ if (options.output === 'json') { |
@@ -19,5 +19,2 @@ import { expect } from 'chai' | ||
const FIXTURE_JSON = require('./__test__/fixtures/1.json') | ||
const FIXTURE_JSON_STRING = JSON.stringify(FIXTURE_JSON, null, 2) | ||
const FILTER_VALID = '.repository.type' | ||
@@ -44,14 +41,2 @@ const FILTER_INVALID = 'invalid' | ||
it('should pass on an empty filter', done => { | ||
run('', PATH_JSON_FIXTURE) | ||
.then(output => { | ||
const normalizedOutput = output.replace(/\r\n/g, '\n') | ||
expect(normalizedOutput).to.equal(FIXTURE_JSON_STRING) | ||
done() | ||
}) | ||
.catch(error => { | ||
done(error) | ||
}) | ||
}) | ||
it('should pass on a null filter', done => { | ||
@@ -201,2 +186,13 @@ run(null, PATH_JSON_FIXTURE) | ||
}) | ||
it('should run as detached', done => { | ||
run(FILTER_VALID, PATH_JSON_FIXTURE, undefined, undefined, undefined, true) | ||
.then(output => { | ||
expect(output).to.equal('"git"') | ||
done() | ||
}) | ||
.catch(error => { | ||
done(error) | ||
}) | ||
}) | ||
}) |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2025583
39
1
313
3517
3