diff --git a/.gitignore b/.gitignore index b82a40d..838aabd 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ typings/ .node_repl_history *.tgz .yarn-integrity +.yarn/* .env .env.test .cache diff --git a/package.json b/package.json index d9f7f07..f228063 100644 --- a/package.json +++ b/package.json @@ -64,5 +64,6 @@ "lint-staged": { "**/*": "prettier --write --ignore-unknown", "{src,tests}/**/*.js": "eslint --fix" - } + }, + "packageManager": "yarn@1.22.19" } diff --git a/src/background/cache.js b/src/background/cache.js index b5f76cc..cd38f79 100644 --- a/src/background/cache.js +++ b/src/background/cache.js @@ -1,7 +1,5 @@ import LRUCache from 'lru-cache'; - -const SECOND = 1000; -const MINUTE = 60 * SECOND; +import { MINUTE } from '../globals'; const _cache = new LRUCache({ max: 500, diff --git a/src/content/content.npmjs.js b/src/content/content.npmjs.js index 08869a0..9b62af4 100644 --- a/src/content/content.npmjs.js +++ b/src/content/content.npmjs.js @@ -4,6 +4,8 @@ import { mountContentScript, reloadWhenURLChanged } from './content'; import { fetchPackageInfo } from './content-events'; import { urlParsers } from './registry/npm'; +const CSS_SELECTOR_COLLABORATORS = '#collaborators'; + const addPackageReport = async (packageID) => { // remove an old package report (if exists) const currPackageReport = document.getElementsByTagName(packageReportTagName); @@ -11,11 +13,14 @@ const addPackageReport = async (packageID) => { currPackageReport.item(0).remove(); } - const repository = await waitForElement('#repository', document.querySelector('#main')); + const collaborators = await waitForElement(CSS_SELECTOR_COLLABORATORS, document.querySelector('#main')); const packageReport = document.createElement(packageReportTagName); packageReport.setAttribute('package-type', packageID.type); packageReport.setAttribute('package-name', packageID.name); - repository.parentElement.insertBefore(packageReport, repository); + + const properties = collaborators.parentElement.parentElement; + const install = properties.querySelector('p'); + install.after(packageReport); }; const loadPackageInfo = async () => { diff --git a/src/globals.js b/src/globals.js index 8944ae0..ece7f45 100644 --- a/src/globals.js +++ b/src/globals.js @@ -1,10 +1,13 @@ +export const SECOND = 1000; +export const MINUTE = 60 * SECOND; + export const advisories = { snyk: 'Snyk Advisor', depsDev: 'OpenSSF Scorecard', socket: 'Socket', debricked: 'Debricked', }; -export const advisoriesNames = Object.keys(advisories); +export const advisoriesNames = Object.keys(advisories); export const indicatorTagName = 'overlay-indicator'; export const packageReportTagName = 'overlay-package-report'; diff --git a/src/utils/utils.js b/src/utils/utils.js index c22ba25..ea4a993 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -4,8 +4,16 @@ * @param {Node} target A DOM Node (which may be an Element) within the DOM tree to watch for changes, or to be the root of a subtree of nodes to be watched. * */ +import { SECOND } from '../globals'; + +const waitElementTimeOot = 10 * SECOND; + const waitForElement = (selector, target) => { - return new Promise((resolve) => { + return new Promise((resolve, reject) => { + setTimeout(() => { + reject(new Error('Time out to wait for the element ' + selector)); + }, waitElementTimeOot); + if (document.querySelector(selector)) { return resolve(document.querySelector(selector)); }