diff --git a/src/install.js b/src/install.js index fba1e18..bf84f5b 100644 --- a/src/install.js +++ b/src/install.js @@ -4,6 +4,24 @@ const fs = require("fs"); const { installOnePackage } = require('./install-utils'); const { create_mount_folder_init_webr } = require('./config-utils.js'); +const append_package_json = function (package_to_add){ + const package_json_path = process.cwd() + "/package.json"; + // append package.json with package_to_install + if (fs.existsSync(package_json_path)) { + const package_json = JSON.parse(fs.readFileSync(package_json_path)); + + if (!package_json.rdependencies) { + package_json.rdependencies = []; + } + + package_json.rdependencies.push(package_to_add); + package_json.rdependencies = [...new Set(package_json.rdependencies)] + fs.writeFileSync(package_json_path, JSON.stringify(package_json, null, 2)); + } else { + console.log("❗️ No package.json file found"); + } +} + const installIt = async function ( package_to_install, destination_folder @@ -44,6 +62,8 @@ const installIt = async function ( ) } + append_package_json(package_to_install) + await webR.close(); return true @@ -53,7 +73,7 @@ const installFromDesc = async function ( description_file, destination_folder, with_exit = true -){ +) { const webR = new WebR();