diff --git a/public/js/components/settings.js b/public/js/components/settings.js index d95501fc..3d63c33c 100644 --- a/public/js/components/settings.js +++ b/public/js/components/settings.js @@ -76,6 +76,8 @@ export class Settings { }); this.config = newConfig; this.saveButton.classList.add("disabled"); + + window.dispatchEvent(new CustomEvent("settings-saved", { detail: this.config })); } updateSettings() { diff --git a/public/js/master.js b/public/js/master.js index 57bfa839..d93d7930 100644 --- a/public/js/master.js +++ b/public/js/master.js @@ -15,6 +15,7 @@ document.addEventListener("DOMContentLoaded", async () => { window.settings = await new Settings().fetchUserConfig(); window.navigation = new ViewNavigation(); window.wiki = new Wiki(); + let currentNodeParams = null; const secureDataSet = new NodeSecureDataSet({ flagsToIgnore: window.settings.config.ignore.flags, @@ -30,6 +31,21 @@ document.addEventListener("DOMContentLoaded", async () => { const nsn = new NodeSecureNetwork(secureDataSet); nsn.network.on("click", updateShowInfoMenu); + window.addEventListener("settings-saved", async(event) => { + secureDataSet.warningsToIgnore = new Set(event.detail.ignore.warnings); + secureDataSet.flagsToIgnore = new Set(event.detail.ignore.flags); + + await secureDataSet.init(secureDataSet.data); + const { nodes } = secureDataSet.build(); + nsn.nodes.update(nodes.get()); + + if (currentNodeParams) { + window.navigation.setNavByName("network--view"); + nsn.neighbourHighlight(currentNodeParams); + updateShowInfoMenu(currentNodeParams); + } + }); + // Initialize searchbar { const dataListElement = document.getElementById("package-list"); @@ -42,12 +58,15 @@ document.addEventListener("DOMContentLoaded", async () => { async function updateShowInfoMenu(params) { if (params.nodes.length === 0) { + currentNodeParams = null; + return PackageInfo.close(); } - const currentNode = params.nodes[0]; + currentNodeParams = params; + const currentNode = currentNodeParams.nodes[0]; const selectedNode = secureDataSet.linker.get( - Number(params.nodes[0]) + Number(currentNode) ); new PackageInfo(selectedNode, currentNode, secureDataSet.data.dependencies[selectedNode.name], nsn); } diff --git a/test/httpServer.test.js b/test/httpServer.test.js index 390a4318..d0c296bb 100644 --- a/test/httpServer.test.js +++ b/test/httpServer.test.js @@ -8,7 +8,7 @@ import assert from "node:assert"; import { once } from "node:events"; // Import Third-party Dependencies -import { get } from "@myunisoft/httpie"; +import { get, MockAgent, getGlobalDispatcher, setGlobalDispatcher } from "@myunisoft/httpie"; import zup from "zup"; import * as i18n from "@nodesecure/i18n"; import * as flags from "@nodesecure/flags"; @@ -18,8 +18,6 @@ import cacache from "cacache"; // Require Internal Dependencies import { buildServer } from "../src/http-server/index.js"; -import * as root from "../src/http-server/endpoints/root.js"; -import * as config from "../src/http-server/endpoints/config.js"; // CONSTANTS const HTTP_PORT = 17049; @@ -31,11 +29,16 @@ const INDEX_HTML = readFileSync(path.join(__dirname, "..", "views", "index.html" const kCachePath = path.join(os.tmpdir(), "nsecure-cli"); const kConfigKey = "cli-config"; +const kGlobalDispatcher = getGlobalDispatcher(); +const kMockAgent = new MockAgent(); +const kBundlephobiaPool = kMockAgent.get("https://bundlephobia.com"); describe("httpServer", () => { let httpServer; before(async() => { + setGlobalDispatcher(kMockAgent); + httpServer = buildServer(JSON_PATH, { port: HTTP_PORT, openLink: false @@ -47,6 +50,8 @@ describe("httpServer", () => { after(() => { httpServer.server.destroy(); + kBundlephobiaPool.close(); + setGlobalDispatcher(kGlobalDispatcher); }); test("'/' should return index.html content", async() => { @@ -154,6 +159,15 @@ describe("httpServer", () => { }); test("'/bundle/:name/:version' should return the bundle size", async() => { + kBundlephobiaPool.intercept({ + path: () => true + }).reply(200, { + gzip: 1, + size: 1, + dependencySizes: { + foo: 1 + } + }, { headers: { "content-type": "application/json" } }); const result = await get(new URL("/bundle/flatstr/1.0.12", HTTP_URL)); assert.equal(result.statusCode, 200); @@ -162,6 +176,9 @@ describe("httpServer", () => { }); test("'/bundle/:name/:version' should return an error if it fails", async() => { + kBundlephobiaPool.intercept({ + path: () => true + }).reply(404); const wrongVersion = undefined; await assert.rejects(async() => { @@ -175,6 +192,15 @@ describe("httpServer", () => { }); test("'/bundle/:name' should return the bundle size of the last version", async() => { + kBundlephobiaPool.intercept({ + path: () => true + }).reply(200, { + gzip: 1, + size: 1, + dependencySizes: { + foo: 1 + } + }, { headers: { "content-type": "application/json" } }); const result = await get(new URL("/bundle/flatstr", HTTP_URL)); assert.equal(result.statusCode, 200); @@ -183,6 +209,9 @@ describe("httpServer", () => { }); test("'/bundle/:name' should return an error if it fails", async() => { + kBundlephobiaPool.intercept({ + path: () => true + }).reply(404); const wrongPackageName = "br-br-br-brah"; await assert.rejects(async() => { diff --git a/workspaces/vis-network/src/dataset.js b/workspaces/vis-network/src/dataset.js index 54308186..aa1c1754 100644 --- a/workspaces/vis-network/src/dataset.js +++ b/workspaces/vis-network/src/dataset.js @@ -59,6 +59,9 @@ export default class NodeSecureDataSet extends EventTarget { const dataEntries = Object.entries(data.dependencies); this.dependenciesCount = dataEntries.length; + this.rawEdgesData = []; + this.rawNodesData = []; + for (const [packageName, descriptor] of dataEntries) { for (const [currVersion, opt] of Object.entries(descriptor.versions)) { const { id, usedBy, flags, size, license, author, composition, warnings } = opt; diff --git a/workspaces/vis-network/src/network.js b/workspaces/vis-network/src/network.js index 7851652d..fbb25234 100644 --- a/workspaces/vis-network/src/network.js +++ b/workspaces/vis-network/src/network.js @@ -93,6 +93,7 @@ export default class NodeSecureNetwork { this.isLoaded = true; this.network.stopSimulation(); this.network.on("click", this.neighbourHighlight.bind(this)); + this.network.setOptions({ physics: false }); }); this.network.stabilize(500);