From 90f47e58777f6bcac90426b7252746a2f977d250 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Thu, 5 Oct 2023 21:15:38 +0530 Subject: [PATCH] feat(#396): decomment support in json and scripts --- package-lock.json | 36 +++++++++++++++---- packages/bruno-cli/package.json | 1 + .../bruno-cli/src/runner/prepare-request.js | 5 +-- .../src/runner/run-single-request.js | 7 ++-- packages/bruno-electron/package.json | 1 + .../bruno-electron/src/ipc/network/index.js | 17 ++++----- .../src/ipc/network/prepare-request.js | 6 ++-- 7 files changed, 52 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index c609f0d8..c2229628 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6678,6 +6678,18 @@ "node": ">=0.10.0" } }, + "node_modules/decomment": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/decomment/-/decomment-0.9.5.tgz", + "integrity": "sha512-h0TZ8t6Dp49duwyDHo3iw67mnh9/UpFiSSiOb5gDK1sqoXzrfX/SQxIUQd2R2QEiSnqib0KF2fnKnGfAhAs6lg==", + "dependencies": { + "esprima": "4.0.1" + }, + "engines": { + "node": ">=6.4", + "npm": ">=2.15" + } + }, "node_modules/decompress-response": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", @@ -7505,7 +7517,6 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true, "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -16765,7 +16776,7 @@ }, "packages/bruno-cli": { "name": "@usebruno/cli", - "version": "0.10.1", + "version": "0.11.0", "license": "MIT", "dependencies": { "@usebruno/js": "0.6.0", @@ -16773,6 +16784,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chalk": "^3.0.0", + "decomment": "^0.9.5", "form-data": "^4.0.0", "fs-extra": "^10.1.0", "handlebars": "^4.7.8", @@ -16810,7 +16822,7 @@ }, "packages/bruno-electron": { "name": "bruno", - "version": "v0.18.0", + "version": "v0.19.0", "dependencies": { "@usebruno/js": "0.6.0", "@usebruno/lang": "0.5.0", @@ -16819,6 +16831,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chokidar": "^3.5.3", + "decomment": "^0.9.5", "dotenv": "^16.0.3", "electron-is-dev": "^2.0.0", "electron-notarize": "^1.2.2", @@ -16848,7 +16861,9 @@ "dmg-license": "^1.0.11" } }, - "packages/bruno-electron/0.5cd ../.0": {}, + "packages/bruno-electron/0.5cd ../.0": { + "extraneous": true + }, "packages/bruno-electron/node_modules/@types/node": { "version": "16.18.11", "dev": true, @@ -20092,6 +20107,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chalk": "^3.0.0", + "decomment": "*", "form-data": "^4.0.0", "fs-extra": "^10.1.0", "handlebars": "^4.7.8", @@ -21201,6 +21217,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chokidar": "^3.5.3", + "decomment": "^0.9.5", "dmg-license": "^1.0.11", "dotenv": "^16.0.3", "electron": "21.1.1", @@ -22309,6 +22326,14 @@ "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", "dev": true }, + "decomment": { + "version": "0.9.5", + "resolved": "https://registry.npmjs.org/decomment/-/decomment-0.9.5.tgz", + "integrity": "sha512-h0TZ8t6Dp49duwyDHo3iw67mnh9/UpFiSSiOb5gDK1sqoXzrfX/SQxIUQd2R2QEiSnqib0KF2fnKnGfAhAs6lg==", + "requires": { + "esprima": "4.0.1" + } + }, "decompress-response": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", @@ -22958,8 +22983,7 @@ "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "dev": true + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, "esrecurse": { "version": "4.3.0", diff --git a/packages/bruno-cli/package.json b/packages/bruno-cli/package.json index abb99627..326ad8fc 100644 --- a/packages/bruno-cli/package.json +++ b/packages/bruno-cli/package.json @@ -29,6 +29,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chalk": "^3.0.0", + "decomment": "^0.9.5", "form-data": "^4.0.0", "fs-extra": "^10.1.0", "handlebars": "^4.7.8", diff --git a/packages/bruno-cli/src/runner/prepare-request.js b/packages/bruno-cli/src/runner/prepare-request.js index e766d08e..e52cb541 100644 --- a/packages/bruno-cli/src/runner/prepare-request.js +++ b/packages/bruno-cli/src/runner/prepare-request.js @@ -1,4 +1,5 @@ const { get, each, filter } = require('lodash'); +const decomment = require('decomment'); const prepareRequest = (request) => { const headers = {}; @@ -39,7 +40,7 @@ const prepareRequest = (request) => { axiosRequest.headers['content-type'] = 'application/json'; } try { - axiosRequest.data = JSON.parse(request.body.json); + axiosRequest.data = JSON.parse(decomment(request.body.json)); } catch (ex) { axiosRequest.data = request.body.json; } @@ -78,7 +79,7 @@ const prepareRequest = (request) => { if (request.body.mode === 'graphql') { const graphqlQuery = { query: get(request, 'body.graphql.query'), - variables: JSON.parse(get(request, 'body.graphql.variables') || '{}') + variables: JSON.parse(decomment(get(request, 'body.graphql.variables') || '{}')) }; if (!contentTypeDefined) { axiosRequest.headers['content-type'] = 'application/json'; diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 69ecb1fa..78985079 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -1,5 +1,6 @@ const qs = require('qs'); const chalk = require('chalk'); +const decomment = require('decomment'); const fs = require('fs'); const { forOwn, each, extend, get } = require('lodash'); const FormData = require('form-data'); @@ -55,7 +56,7 @@ const runSingleRequest = async function ( if (requestScriptFile && requestScriptFile.length) { const scriptRuntime = new ScriptRuntime(); await scriptRuntime.runRequestScript( - requestScriptFile, + decomment(requestScriptFile), request, envVariables, collectionVariables, @@ -180,7 +181,7 @@ const runSingleRequest = async function ( if (responseScriptFile && responseScriptFile.length) { const scriptRuntime = new ScriptRuntime(); await scriptRuntime.runResponseScript( - responseScriptFile, + decomment(responseScriptFile), request, response, envVariables, @@ -221,7 +222,7 @@ const runSingleRequest = async function ( if (typeof testFile === 'string') { const testRuntime = new TestRuntime(); const result = await testRuntime.runTests( - testFile, + decomment(testFile), request, response, envVariables, diff --git a/packages/bruno-electron/package.json b/packages/bruno-electron/package.json index c57c8176..6c81f5dc 100644 --- a/packages/bruno-electron/package.json +++ b/packages/bruno-electron/package.json @@ -21,6 +21,7 @@ "axios": "^1.5.1", "chai": "^4.3.7", "chokidar": "^3.5.3", + "decomment": "^0.9.5", "dotenv": "^16.0.3", "electron-is-dev": "^2.0.0", "electron-notarize": "^1.2.2", diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 89740b8b..2dad7286 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -1,6 +1,7 @@ const qs = require('qs'); const https = require('https'); const axios = require('axios'); +const decomment = require('decomment'); const Mustache = require('mustache'); const FormData = require('form-data'); const { ipcMain } = require('electron'); @@ -151,7 +152,7 @@ const registerNetworkIpc = (mainWindow) => { if (requestScript && requestScript.length) { const scriptRuntime = new ScriptRuntime(); const result = await scriptRuntime.runRequestScript( - requestScript, + decomment(requestScript), request, envVars, collectionVariables, @@ -277,7 +278,7 @@ const registerNetworkIpc = (mainWindow) => { if (responseScript && responseScript.length) { const scriptRuntime = new ScriptRuntime(); const result = await scriptRuntime.runResponseScript( - responseScript, + decomment(responseScript), request, response, envVars, @@ -323,7 +324,7 @@ const registerNetworkIpc = (mainWindow) => { if (typeof testFile === 'string') { const testRuntime = new TestRuntime(); const testResults = await testRuntime.runTests( - testFile, + decomment(testFile), request, response, envVars, @@ -402,7 +403,7 @@ const registerNetworkIpc = (mainWindow) => { if (typeof testFile === 'string') { const testRuntime = new TestRuntime(); const testResults = await testRuntime.runTests( - testFile, + decomment(testFile), request, error.response, envVars, @@ -603,7 +604,7 @@ const registerNetworkIpc = (mainWindow) => { if (requestScript && requestScript.length) { const scriptRuntime = new ScriptRuntime(); const result = await scriptRuntime.runRequestScript( - requestScript, + decomment(requestScript), request, envVars, collectionVariables, @@ -704,7 +705,7 @@ const registerNetworkIpc = (mainWindow) => { if (responseScript && responseScript.length) { const scriptRuntime = new ScriptRuntime(); const result = await scriptRuntime.runResponseScript( - responseScript, + decomment(responseScript), request, response, envVars, @@ -748,7 +749,7 @@ const registerNetworkIpc = (mainWindow) => { if (typeof testFile === 'string') { const testRuntime = new TestRuntime(); const testResults = await testRuntime.runTests( - testFile, + decomment(testFile), request, response, envVars, @@ -828,7 +829,7 @@ const registerNetworkIpc = (mainWindow) => { if (typeof testFile === 'string') { const testRuntime = new TestRuntime(); const testResults = await testRuntime.runTests( - testFile, + decomment(testFile), request, error.response, envVars, diff --git a/packages/bruno-electron/src/ipc/network/prepare-request.js b/packages/bruno-electron/src/ipc/network/prepare-request.js index 5a851291..922c9929 100644 --- a/packages/bruno-electron/src/ipc/network/prepare-request.js +++ b/packages/bruno-electron/src/ipc/network/prepare-request.js @@ -1,4 +1,5 @@ const { get, each, filter } = require('lodash'); +const decomment = require('decomment'); const prepareRequest = (request) => { const headers = {}; @@ -37,7 +38,8 @@ const prepareRequest = (request) => { axiosRequest.headers['content-type'] = 'application/json'; } try { - axiosRequest.data = JSON.parse(request.body.json); + // axiosRequest.data = JSON.parse(request.body.json); + axiosRequest.data = JSON.parse(decomment(request.body.json)); } catch (ex) { axiosRequest.data = request.body.json; } @@ -76,7 +78,7 @@ const prepareRequest = (request) => { if (request.body.mode === 'graphql') { const graphqlQuery = { query: get(request, 'body.graphql.query'), - variables: JSON.parse(get(request, 'body.graphql.variables') || '{}') + variables: JSON.parse(decomment(get(request, 'body.graphql.variables') || '{}')) }; if (!contentTypeDefined) { axiosRequest.headers['content-type'] = 'application/json';