From bf188f949af6e3e9e805c9e72ca231963273da47 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 22 Aug 2024 17:59:05 -0400 Subject: [PATCH 01/11] Drop source maps for prebuilt msa -- no point since it's pre-minified and all mangled. --- config/plugins/visualizations/msa/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/plugins/visualizations/msa/package.json b/config/plugins/visualizations/msa/package.json index 1a011c6ef6b1..eb1fdd25361e 100644 --- a/config/plugins/visualizations/msa/package.json +++ b/config/plugins/visualizations/msa/package.json @@ -11,7 +11,7 @@ "babel-preset-env": "^1.6.1" }, "scripts": { - "build": "parcel build src/script.js --dist-dir static" + "build": "parcel build src/script.js --dist-dir static --no-source-maps" }, "devDependencies": { "parcel": "^2.12.0" From 9d1292140e707cffe6b667f4453994ba338ce004 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 22 Aug 2024 17:59:30 -0400 Subject: [PATCH 02/11] Version bump of msa, rename to @galaxyproject/msa, define files to publish. --- config/plugins/visualizations/msa/package.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/config/plugins/visualizations/msa/package.json b/config/plugins/visualizations/msa/package.json index eb1fdd25361e..b9fab172d249 100644 --- a/config/plugins/visualizations/msa/package.json +++ b/config/plugins/visualizations/msa/package.json @@ -1,6 +1,6 @@ { - "name": "visualization", - "version": "0.1.0", + "name": "@galaxyproject/msa", + "version": "0.2.0", "keywords": [ "galaxy", "visualization" @@ -10,6 +10,9 @@ "babel-plugin-transform-export-extensions": "^6.22.0", "babel-preset-env": "^1.6.1" }, + "files": [ + "static" + ], "scripts": { "build": "parcel build src/script.js --dist-dir static --no-source-maps" }, From 50c97a933e563c11cbdc536b76888da752eda929 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 11:36:38 -0400 Subject: [PATCH 03/11] Specify npm dependency msa@0.2.0 for msa in configfile --- config/plugins/visualizations/msa/config/msa.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/plugins/visualizations/msa/config/msa.xml b/config/plugins/visualizations/msa/config/msa.xml index 566a036ebe9b..575ea47a85d4 100644 --- a/config/plugins/visualizations/msa/config/msa.xml +++ b/config/plugins/visualizations/msa/config/msa.xml @@ -11,6 +11,9 @@ dataset_id + + + dataset_id From a9a99e62e254460c358a8872d205b283734d1c61 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 11:37:38 -0400 Subject: [PATCH 04/11] Add xml2js to client dev dependencies for parsing xml files (viz config) --- client/package.json | 1 + client/yarn.lock | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/client/package.json b/client/package.json index 28104a656ff5..7b5fd2366f2e 100644 --- a/client/package.json +++ b/client/package.json @@ -204,6 +204,7 @@ "webpack-dev-server": "^4.15.1", "webpack-merge": "^5.10.0", "xml-js": "^1.6.11", + "xml2js": "^0.6.2", "yaml-jest": "^1.2.0", "yaml-loader": "^0.8.0" }, diff --git a/client/yarn.lock b/client/yarn.lock index 83b454203c5f..9200eed2e90e 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -10364,6 +10364,11 @@ sass@^1.69.4: immutable "^4.0.0" source-map-js ">=0.6.2 <2.0.0" +sax@>=0.6.0: + version "1.4.1" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.4.1.tgz#44cc8988377f126304d3b3fc1010c733b929ef0f" + integrity sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg== + sax@^1.2.4: version "1.2.4" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" @@ -12245,6 +12250,19 @@ xml-name-validator@^4.0.0: resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-4.0.0.tgz" integrity sha512-ICP2e+jsHvAj2E2lIHxa5tjXRlKDJo4IdvPvCXbXQGdzSfmSpNVyIKMvoZHjDY9DP0zV17iI85o90vRFXNccRw== +xml2js@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499" + integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA== + dependencies: + sax ">=0.6.0" + xmlbuilder "~11.0.0" + +xmlbuilder@~11.0.0: + version "11.0.1" + resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3" + integrity sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA== + xmlchars@^2.2.0: version "2.2.0" resolved "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz" From 7aab2739745f2a05182734e48bf3783b88082efe Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 12:53:32 -0400 Subject: [PATCH 05/11] Shift some dependencies to dev from runtime for bundled msa -- clears up installation. --- config/plugins/visualizations/msa/package.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/config/plugins/visualizations/msa/package.json b/config/plugins/visualizations/msa/package.json index b9fab172d249..6d96f0a712b1 100644 --- a/config/plugins/visualizations/msa/package.json +++ b/config/plugins/visualizations/msa/package.json @@ -1,15 +1,11 @@ { "name": "@galaxyproject/msa", - "version": "0.2.0", + "version": "0.2.1", "keywords": [ "galaxy", "visualization" ], "license": "AFL-3.0", - "dependencies": { - "babel-plugin-transform-export-extensions": "^6.22.0", - "babel-preset-env": "^1.6.1" - }, "files": [ "static" ], @@ -17,6 +13,8 @@ "build": "parcel build src/script.js --dist-dir static --no-source-maps" }, "devDependencies": { + "babel-plugin-transform-export-extensions": "^6.22.0", + "babel-preset-env": "^1.6.1", "parcel": "^2.12.0" } } From 725f59b14aa9f268ca12e1c5ea9f6f542352e064 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 12:54:11 -0400 Subject: [PATCH 06/11] Update msa to newly published patch rev --- config/plugins/visualizations/msa/config/msa.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/plugins/visualizations/msa/config/msa.xml b/config/plugins/visualizations/msa/config/msa.xml index 575ea47a85d4..51ef1ea64f23 100644 --- a/config/plugins/visualizations/msa/config/msa.xml +++ b/config/plugins/visualizations/msa/config/msa.xml @@ -12,7 +12,7 @@ - + dataset_id From 90ea64429a99e9a78468dd9af28321ede5f45fbe Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 13:52:35 -0400 Subject: [PATCH 07/11] Add fs-extra for use by gulp staging -- not super gulpy, but the next step is to get this all out of js anyway --- client/package.json | 1 + client/yarn.lock | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/client/package.json b/client/package.json index 7b5fd2366f2e..a4f2c4b695d2 100644 --- a/client/package.json +++ b/client/package.json @@ -172,6 +172,7 @@ "eslint-plugin-vuejs-accessibility": "^2.2.0", "expose-loader": "^4.1.0", "fake-indexeddb": "^6.0.0", + "fs-extra": "^11.2.0", "gulp": "^4.0.2", "ignore-loader": "^0.1.2", "imports-loader": "^4.0.1", diff --git a/client/yarn.lock b/client/yarn.lock index 9200eed2e90e..1b464017f3bb 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -6295,6 +6295,15 @@ fresh@0.5.2: resolved "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz" integrity sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q== +fs-extra@^11.2.0: + version "11.2.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.2.0.tgz#e70e17dfad64232287d01929399e0ea7c86b0e5b" + integrity sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs-mkdirp-stream@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz" @@ -6561,7 +6570,12 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" -graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.10, graceful-fs@^4.2.11, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9: +graceful-fs@^4.0.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.4, graceful-fs@^4.2.6, graceful-fs@^4.2.9: + version "4.2.10" + resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz" + integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== + +graceful-fs@^4.2.0, graceful-fs@^4.2.10, graceful-fs@^4.2.11: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -8077,6 +8091,15 @@ json5@^2.2.2, json5@^2.2.3: resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.3.tgz#78cd6f1a19bdc12b73db5ad0c61efd66c1e29283" integrity sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg== +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jspdf@^2.5.1: version "2.5.1" resolved "https://registry.npmjs.org/jspdf/-/jspdf-2.5.1.tgz" @@ -11602,6 +11625,11 @@ universalify@^0.2.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0" integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg== +universalify@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.1.tgz#168efc2180964e6386d061e094df61afe239b18d" + integrity sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw== + unpipe@1.0.0, unpipe@~1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz" From 9b9f0607c5632c4b4e40dc3d6be90e7fa9d239e6 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 14:14:14 -0400 Subject: [PATCH 08/11] Feature for installing prebuilt packages directly from viz build framework --- client/gulpfile.js | 87 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/client/gulpfile.js b/client/gulpfile.js index 873bae0c0bd8..db819580a72d 100644 --- a/client/gulpfile.js +++ b/client/gulpfile.js @@ -1,10 +1,11 @@ const path = require("path"); -const fs = require("fs"); +const fs = require("fs-extra"); const del = require("del"); const { src, dest, series, parallel, watch } = require("gulp"); const child_process = require("child_process"); const { globSync } = require("glob"); const buildIcons = require("./icons/build_icons"); +const xml2js = require("xml2js"); /* * We'll want a flexible glob down the road, but for now there are no @@ -24,7 +25,6 @@ const STATIC_PLUGIN_BUILD_IDS = [ "hyphyvision", "jqplot/jqplot_bar", "media_player", - "msa", "mvpapp", "ngl", "nora", @@ -39,9 +39,15 @@ const STATIC_PLUGIN_BUILD_IDS = [ "ts_visjs", "venn", ]; +const INSTALL_PLUGIN_BUILD_IDS = ["msa"]; // todo: derive from XML const DIST_PLUGIN_BUILD_IDS = ["new_user"]; const PLUGIN_BUILD_IDS = Array.prototype.concat(DIST_PLUGIN_BUILD_IDS, STATIC_PLUGIN_BUILD_IDS); +const failOnError = + process.env.GALAXY_PLUGIN_BUILD_FAIL_ON_ERROR && process.env.GALAXY_PLUGIN_BUILD_FAIL_ON_ERROR !== "0" + ? true + : false; + const PATHS = { nodeModules: "./node_modules", stagedLibraries: { @@ -57,11 +63,6 @@ const PATHS = { }, }; -const failOnError = - process.env.GALAXY_PLUGIN_BUILD_FAIL_ON_ERROR && process.env.GALAXY_PLUGIN_BUILD_FAIL_ON_ERROR !== "0" - ? true - : false; - PATHS.pluginBaseDir = (process.env.GALAXY_PLUGIN_PATH && process.env.GALAXY_PLUGIN_PATH !== "None" ? process.env.GALAXY_PLUGIN_PATH @@ -162,6 +163,8 @@ function buildPlugins(callback, forceRebuild) { console.log(`No changes detected for ${pluginName}`); } else { console.log(`Installing Dependencies for ${pluginName}`); + + // Else we call yarn install and yarn build child_process.spawnSync( "yarn", ["install", "--production=false", "--network-timeout=300000", "--check-files"], @@ -205,6 +208,71 @@ function buildPlugins(callback, forceRebuild) { return callback(); } +function installPlugins(callback) { + // iterate through install_plugin_build_ids, identify xml files and install dependencies + for (const plugin_name of INSTALL_PLUGIN_BUILD_IDS) { + const pluginDir = path.join(PATHS.pluginBaseDir, `visualizations/${plugin_name}`); + const xmlPath = path.join(pluginDir, `config/${plugin_name}.xml`); + // Check if the file exists + if (fs.existsSync(xmlPath)) { + installDependenciesFromXML(xmlPath, pluginDir); + } else { + console.error(`XML file not found: ${xmlPath}`); + } + } + + return callback(); +} + +// Function to parse the XML and install dependencies +function installDependenciesFromXML(xmlPath, pluginDir) { + const parser = new xml2js.Parser(); + fs.readFile(xmlPath, (err, data) => { + if (err) { + console.error("Error reading XML file:", err); + return; + } + parser.parseString(data, async (err, result) => { + if (err) { + console.error("Error parsing XML:", err); + return; + } + // Navigate to the dependencies + const requirements = result.visualization.requirements[0].requirement; + // Extract the details + requirements.forEach((dep) => { + const reqType = dep.$.type; + const pkgName = dep.$.package; + const version = dep.$.version; + + if (reqType == "package" && pkgName && version) { + // install the package. + if ( + child_process.spawnSync("npm", ["install", "--silent", "--no-save", `${pkgName}@${version}`], { + cwd: pluginDir, + stdio: "inherit", + shell: true, + }).status === 0 + ) { + // Copy static from the installed package to the + // plugin's static directory. + // This keeps separation from standard staging. + fs.copy(path.join(pluginDir, "node_modules", pkgName, "static"), path.join(pluginDir, "static")) + .then(() => { + console.log(`Successfully staged package for ${pkgName}@${version} in ${pluginDir}`); + }) + .catch((err) => { + console.error(`Error staging package ${pkgName}@${version} in ${pluginDir}`); + }); + } else { + console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); + } + } + }); + }); + }); +} + function forceBuildPlugins(callback) { return buildPlugins(callback, true); } @@ -214,8 +282,8 @@ function cleanPlugins() { } const client = parallel(fonts, stageLibs, icons); -const plugins = series(buildPlugins, cleanPlugins, stagePlugins); -const pluginsRebuild = series(forceBuildPlugins, cleanPlugins, stagePlugins); +const plugins = series(buildPlugins, installPlugins, cleanPlugins, stagePlugins); +const pluginsRebuild = series(forceBuildPlugins, installPlugins, cleanPlugins, stagePlugins); function watchPlugins() { const BUILD_PLUGIN_WATCH_GLOB = [ @@ -229,3 +297,4 @@ module.exports.plugins = plugins; module.exports.pluginsRebuild = pluginsRebuild; module.exports.watchPlugins = watchPlugins; module.exports.default = parallel(client, plugins); +module.exports.installPlugins = installPlugins; \ No newline at end of file From d0ba3a0b4347489a645b62492c8165af759d7b3b Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 20:40:14 -0400 Subject: [PATCH 09/11] Wrap xml handling in promise to ensure order of operations in gulp --- client/gulpfile.js | 95 +++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 43 deletions(-) diff --git a/client/gulpfile.js b/client/gulpfile.js index db819580a72d..3dc198121fb5 100644 --- a/client/gulpfile.js +++ b/client/gulpfile.js @@ -77,6 +77,8 @@ PATHS.pluginBuildModules = [ path.join(PATHS.pluginBaseDir, `{visualizations,welcome_page}/{${PLUGIN_BUILD_IDS.join(",")}}/package.json`), ]; +const parser = new xml2js.Parser(); + function stageLibs(callback) { Object.keys(PATHS.stagedLibraries).forEach((lib) => { var p1 = path.resolve(path.join(PATHS.nodeModules, lib, PATHS.stagedLibraries[lib][0])); @@ -208,66 +210,73 @@ function buildPlugins(callback, forceRebuild) { return callback(); } -function installPlugins(callback) { +async function installPlugins(callback) { // iterate through install_plugin_build_ids, identify xml files and install dependencies for (const plugin_name of INSTALL_PLUGIN_BUILD_IDS) { const pluginDir = path.join(PATHS.pluginBaseDir, `visualizations/${plugin_name}`); const xmlPath = path.join(pluginDir, `config/${plugin_name}.xml`); // Check if the file exists if (fs.existsSync(xmlPath)) { - installDependenciesFromXML(xmlPath, pluginDir); + await installDependenciesFromXML(xmlPath, pluginDir); } else { console.error(`XML file not found: ${xmlPath}`); } } - return callback(); } // Function to parse the XML and install dependencies -function installDependenciesFromXML(xmlPath, pluginDir) { - const parser = new xml2js.Parser(); - fs.readFile(xmlPath, (err, data) => { - if (err) { - console.error("Error reading XML file:", err); - return; - } - parser.parseString(data, async (err, result) => { +async function installDependenciesFromXML(xmlPath, pluginDir) { + return new Promise((resolve, reject) => { + fs.readFile(xmlPath, (err, data) => { if (err) { - console.error("Error parsing XML:", err); - return; + console.error("Error reading XML file:", err); + reject(err); } - // Navigate to the dependencies - const requirements = result.visualization.requirements[0].requirement; - // Extract the details - requirements.forEach((dep) => { - const reqType = dep.$.type; - const pkgName = dep.$.package; - const version = dep.$.version; + parser.parseString(data, async (err, result) => { + if (err) { + console.error("Error parsing XML:", err); + reject(err); + } + // Navigate to the dependencies + const requirements = result.visualization.requirements[0].requirement; + // Extract the details + requirements.forEach(async (dep) => { + const reqType = dep.$.type; + const pkgName = dep.$.package; + const version = dep.$.version; - if (reqType == "package" && pkgName && version) { - // install the package. - if ( - child_process.spawnSync("npm", ["install", "--silent", "--no-save", `${pkgName}@${version}`], { - cwd: pluginDir, - stdio: "inherit", - shell: true, - }).status === 0 - ) { - // Copy static from the installed package to the - // plugin's static directory. - // This keeps separation from standard staging. - fs.copy(path.join(pluginDir, "node_modules", pkgName, "static"), path.join(pluginDir, "static")) - .then(() => { - console.log(`Successfully staged package for ${pkgName}@${version} in ${pluginDir}`); - }) - .catch((err) => { - console.error(`Error staging package ${pkgName}@${version} in ${pluginDir}`); - }); - } else { - console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); + if (reqType == "package" && pkgName && version) { + // install the package. + if ( + child_process.spawnSync( + "npm", + ["install", "--silent", "--no-save", `${pkgName}@${version}`], + { + cwd: pluginDir, + stdio: "inherit", + shell: true, + } + ).status === 0 + ) { + // Copy static from the installed package to the + // plugin's static directory. + // This keeps separation from standard staging. + try { + await fs.copy( + path.join(pluginDir, "node_modules", pkgName, "static"), + path.join(pluginDir, "static") + ); + console.log(`Installed package ${pkgName}@${version} in ${pluginDir}`); + } catch (err) { + console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); + } + } else { + console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); + } } - } + }); + resolve(); }); }); }); @@ -297,4 +306,4 @@ module.exports.plugins = plugins; module.exports.pluginsRebuild = pluginsRebuild; module.exports.watchPlugins = watchPlugins; module.exports.default = parallel(client, plugins); -module.exports.installPlugins = installPlugins; \ No newline at end of file +module.exports.installPlugins = installPlugins; From c9c775f0ec0cdf4ea5640361bed9c18e35c4c4f5 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Fri, 23 Aug 2024 21:40:30 -0400 Subject: [PATCH 10/11] Refactor async npm package installation --- client/gulpfile.js | 86 +++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 51 deletions(-) diff --git a/client/gulpfile.js b/client/gulpfile.js index 3dc198121fb5..abf037453efd 100644 --- a/client/gulpfile.js +++ b/client/gulpfile.js @@ -77,8 +77,6 @@ PATHS.pluginBuildModules = [ path.join(PATHS.pluginBaseDir, `{visualizations,welcome_page}/{${PLUGIN_BUILD_IDS.join(",")}}/package.json`), ]; -const parser = new xml2js.Parser(); - function stageLibs(callback) { Object.keys(PATHS.stagedLibraries).forEach((lib) => { var p1 = path.resolve(path.join(PATHS.nodeModules, lib, PATHS.stagedLibraries[lib][0])); @@ -227,59 +225,45 @@ async function installPlugins(callback) { // Function to parse the XML and install dependencies async function installDependenciesFromXML(xmlPath, pluginDir) { - return new Promise((resolve, reject) => { - fs.readFile(xmlPath, (err, data) => { - if (err) { - console.error("Error reading XML file:", err); - reject(err); - } - parser.parseString(data, async (err, result) => { - if (err) { - console.error("Error parsing XML:", err); - reject(err); - } - // Navigate to the dependencies - const requirements = result.visualization.requirements[0].requirement; - // Extract the details - requirements.forEach(async (dep) => { - const reqType = dep.$.type; - const pkgName = dep.$.package; - const version = dep.$.version; + try { + const pluginXML = fs.readFileSync(xmlPath); + const parsedXML = await xml2js.parseStringPromise(pluginXML); + const requirements = parsedXML.visualization.requirements[0].requirement; + + const installPromises = requirements.map(async (dep) => { + const { type: reqType, package: pkgName, version } = dep.$; - if (reqType == "package" && pkgName && version) { - // install the package. - if ( - child_process.spawnSync( - "npm", - ["install", "--silent", "--no-save", `${pkgName}@${version}`], - { - cwd: pluginDir, - stdio: "inherit", - shell: true, - } - ).status === 0 - ) { - // Copy static from the installed package to the - // plugin's static directory. - // This keeps separation from standard staging. - try { - await fs.copy( - path.join(pluginDir, "node_modules", pkgName, "static"), - path.join(pluginDir, "static") - ); - console.log(`Installed package ${pkgName}@${version} in ${pluginDir}`); - } catch (err) { - console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); - } - } else { - console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); + if (reqType === "package" && pkgName && version) { + try { + const installResult = child_process.spawnSync( + "npm", + ["install", "--silent", "--no-save", `${pkgName}@${version}`], + { + cwd: pluginDir, + stdio: "inherit", + shell: true, } + ); + + if (installResult.status === 0) { + await fs.copy( + path.join(pluginDir, "node_modules", pkgName, "static"), + path.join(pluginDir, "static") + ); + console.log(`Installed package ${pkgName}@${version} in ${pluginDir}`); + } else { + console.error(`Error installing package ${pkgName}@${version} in ${pluginDir}`); } - }); - resolve(); - }); + } catch (err) { + console.error(`Error handling package ${pkgName}@${version} in ${pluginDir}:`, err); + } + } }); - }); + + await Promise.all(installPromises); + } catch (err) { + console.error(`Error processing XML file ${xmlPath}:`, err); + } } function forceBuildPlugins(callback) { From 114f973361f253e9f284474212a53e90d03cf2d6 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Wed, 4 Sep 2024 11:13:43 -0400 Subject: [PATCH 11/11] Swap 'package' requirement type to more clearly state that it's an 'npm' package. --- client/gulpfile.js | 2 +- config/plugins/visualizations/msa/config/msa.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/gulpfile.js b/client/gulpfile.js index abf037453efd..feb386952329 100644 --- a/client/gulpfile.js +++ b/client/gulpfile.js @@ -233,7 +233,7 @@ async function installDependenciesFromXML(xmlPath, pluginDir) { const installPromises = requirements.map(async (dep) => { const { type: reqType, package: pkgName, version } = dep.$; - if (reqType === "package" && pkgName && version) { + if (reqType === "npm" && pkgName && version) { try { const installResult = child_process.spawnSync( "npm", diff --git a/config/plugins/visualizations/msa/config/msa.xml b/config/plugins/visualizations/msa/config/msa.xml index 51ef1ea64f23..2fd3761c4847 100644 --- a/config/plugins/visualizations/msa/config/msa.xml +++ b/config/plugins/visualizations/msa/config/msa.xml @@ -12,7 +12,7 @@ - + dataset_id