Skip to content

Commit

Permalink
Merge pull request #12106 from rak-phillip/chore/12105-tough-cookie
Browse files Browse the repository at this point in the history
Remove unused `browser-env` and `jsdom-global` dependencies
  • Loading branch information
rak-phillip authored Oct 7, 2024
2 parents adef9c3 + f45c6ae commit 9bbaa16
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 1,223 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"axios": "0.21.4",
"axios-retry": "3.1.9",
"babel-plugin-module-resolver": "4.0.0",
"browser-env": "3.3.0",
"cache-loader": "4.1.0",
"clipboard-polyfill": "4.0.1",
"codemirror": "5.65.17",
Expand Down Expand Up @@ -104,7 +103,6 @@
"js-yaml": "4.1.0",
"js-yaml-loader": "1.2.2",
"jsdiff": "1.1.1",
"jsdom-global": "3.0.2",
"jsonpath-plus": "6.0.1",
"jsrsasign": "10.5.25",
"jszip": "3.8.0",
Expand All @@ -122,10 +120,10 @@
"ufo": "0.7.11",
"unfetch": "4.2.0",
"url-parse": "1.5.10",
"vue3-resize": "0.2.0",
"vue-router": "4.4.3",
"vue-select": "4.0.0-beta.6",
"vue-server-renderer": "2.6.14",
"vue3-resize": "0.2.0",
"vue3-virtual-scroll-list": "0.2.1",
"vuedraggable": "2.24.3",
"vuex": "4.0.2",
Expand Down
68 changes: 35 additions & 33 deletions scripts/check-i18n-links
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
/**
* This script reads and parses all of the source code files, reads the US English
* translation files, extracts all http/s links and checks for broken links.
*
*
* This script is used in the PR gate to check for broken links.
*
*/

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const request = require('request-promise-native');
const axios = require('axios');

const base = path.resolve(__dirname, '..');
const srcFolder = path.resolve(base, 'shell');
const pkgFolder = path.resolve(base, 'pkg');

// Simple shell colors
const reset = "\x1b[0m";
const reset = '\x1b[0m';
const cyan = `\x1b[96m`;
const yellow = `\x1b[33m`;
const bold = `\x1b[1m`;
Expand All @@ -27,15 +27,15 @@ const DOCS_BASE_REGEX = /export const DOCS_BASE = '([^']*)';/;

const CATEGORIES = [
{
name: 'Rancher Manager Documentation',
name: 'Rancher Manager Documentation',
regex: /^https:\/\/.*rancher\.com\/.*/
},
{
name: 'RKE2 Documentation',
name: 'RKE2 Documentation',
regex: /^https:\/\/.*rke2\.io\/.*/
},
{
name: 'K3S Documentation',
name: 'K3S Documentation',
regex: /^https:\/\/.*k3s\.io\/.*/
}
];
Expand Down Expand Up @@ -73,25 +73,26 @@ function readAndParseTranslations(filePath) {

return parseTranslations(i18n);
} catch (e) {
console.log('Can not read i18n file'); // eslint-disable-line no-console
console.log(e); // eslint-disable-line no-console
console.log('Can not read i18n file'); // eslint-disable-line no-console
console.log(e); // eslint-disable-line no-console
process.exit(1);
}
}

function parseTranslations(obj, parent) {
let res = {};

Object.keys(obj).forEach((key) => {
const v = obj[key];
const pKey = parent ? `${parent}.${key}` : key;
const pKey = parent ? `${ parent }.${ key }` : key;

if (v === null) {
// ignore
} else if (typeof v === 'object') {
res = {
...res,
...parseTranslations(v, pKey)
}
};
} else {
// Ensure empty strings work
res[pKey] = v.length === 0 ? '[empty]' : v;
Expand Down Expand Up @@ -133,7 +134,7 @@ function loadI18nFiles(folder) {

// Find all of the test files
fs.readdirSync(folder).forEach((file) => {
const filePath = path.resolve(folder, file)
const filePath = path.resolve(folder, file);
const isFolder = fs.lstatSync(filePath).isDirectory();

if (isFolder) {
Expand All @@ -157,7 +158,7 @@ function loadI18nFiles(folder) {
}

console.log('======================================'); // eslint-disable-line no-console
console.log(`${cyan}Checking source files for i18n strings${reset}`); // eslint-disable-line no-console
console.log(`${ cyan }Checking source files for i18n strings${ reset }`); // eslint-disable-line no-console
console.log('======================================'); // eslint-disable-line no-console

console.log(''); // eslint-disable-line no-console
Expand All @@ -167,21 +168,21 @@ let i18n = loadI18nFiles(srcFolder);

i18n = { ...i18n, ...loadI18nFiles(pkgFolder) };

console.log(`Read ${cyan}${ Object.keys(i18n).length }${reset} translations`); // eslint-disable-line no-console
console.log(`Read ${ cyan }${ Object.keys(i18n).length }${ reset } translations`); // eslint-disable-line no-console

const links = [];

// Parse all of the links from each translation file
Object.keys(i18n).forEach((str) => {
const link = parseLinks(i18n[str]);

links.push(...link);
links.push(...link);
});

console.log(`Discovered ${cyan}${links.length}${reset} links`); // eslint-disable-line no-console
console.log(`Discovered ${ cyan }${ links.length }${ reset } links`); // eslint-disable-line no-console

console.log(`${cyan}Links:${reset}`); // eslint-disable-line no-console
console.log(`${cyan}======${reset}`); // eslint-disable-line no-console
console.log(`${ cyan }Links:${ reset }`); // eslint-disable-line no-console
console.log(`${ cyan }======${ reset }`); // eslint-disable-line no-console

showByCategory(links, 'Links in', 'Other Links', cyan);

Expand All @@ -193,6 +194,7 @@ function showByCategory(linksToShow, prefixLabel, otherLabel, color) {

linksToShow.forEach((link) => {
let found = false;

CATEGORIES.forEach((category) => {
byCategory[category.name] = byCategory[category.name] || [];

Expand All @@ -209,56 +211,56 @@ function showByCategory(linksToShow, prefixLabel, otherLabel, color) {

CATEGORIES.forEach((category) => {
if (byCategory[category.name]?.length) {
console.log(`${color}${prefixLabel} ${category.name}${reset}`); // eslint-disable-line no-console
byCategory[category.name].forEach((link) => console.log(` ${link}`)); // eslint-disable-line no-console
console.log(`${ color }${ prefixLabel } ${ category.name }${ reset }`); // eslint-disable-line no-console
byCategory[category.name].forEach((link) => console.log(` ${ link }`)); // eslint-disable-line no-console
}
});

if (others.length) {
console.log(`${color}${otherLabel}${reset}`); // eslint-disable-line no-console
others.forEach((link) => console.log(` ${link}`));
console.log(`${ color }${ otherLabel }${ reset }`); // eslint-disable-line no-console
others.forEach((link) => console.log(` ${ link }`));
}
}

async function check(links) {
const brokenLinks = [];

for(let i =0; i<links.length; i++) {
for (let i = 0; i < links.length; i++) {
const link = links[i];
let statusCode;
let statusMessage;

try {
const headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36',
'Accept': 'text/html',
Accept: 'text/html',
'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8',
};

const r = await request(link, { resolveWithFullResponse: true, headers });
const r = await axios.get(link, { headers });

statusCode = r.statusCode;
statusMessage = r.statusMessage;
statusCode = r.status;
statusMessage = r.statusText;
} catch (e) {
statusCode = e.statusCode;
statusMessage = e.statusMessage;
statusCode = e.status;
statusMessage = e.statusText;
}

if (statusCode !== 200) {
const sc = `${ statusCode }`.padEnd(5);

console.log(` ${ link } : ${ sc } ${ statusMessage ? statusMessage : '' }`); // eslint-disable-line no-console
console.log(` ${ link } : ${ sc } ${ statusMessage || '' }`); // eslint-disable-line no-console

brokenLinks.push(link);
}
};
}

console.log(''); // eslint-disable-line no-console

if (brokenLinks.length === 0) {
console.log(`${cyan}${bold}Links Checked - all links could be fetched okay${reset}`); // eslint-disable-line no-console
console.log(`${ cyan }${ bold }Links Checked - all links could be fetched okay${ reset }`); // eslint-disable-line no-console
} else {
console.log(`${yellow}${bold}Found ${brokenLinks.length} link(s) that could not be fetched${reset}`); // eslint-disable-line no-console
console.log(`${ yellow }${ bold }Found ${ brokenLinks.length } link(s) that could not be fetched${ reset }`); // eslint-disable-line no-console
}

console.log(''); // eslint-disable-line no-console
Expand All @@ -273,6 +275,6 @@ async function check(links) {
}
}

console.log(`${cyan}Checking doc links ...${reset}`); // eslint-disable-line no-console
console.log(`${ cyan }Checking doc links ...${ reset }`); // eslint-disable-line no-console

check(links);
2 changes: 0 additions & 2 deletions shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"babel-eslint": "10.1.0",
"babel-plugin-module-resolver": "4.0.0",
"babel-preset-vue": "2.0.2",
"browser-env": "3.3.0",
"clipboard-polyfill": "4.0.1",
"codemirror": ">=5.64.0 <6",
"codemirror-editor-vue3": "2.7.1",
Expand Down Expand Up @@ -99,7 +98,6 @@
"js-yaml": "4.1.0",
"js-yaml-loader": "1.2.2",
"jsdiff": "1.1.1",
"jsdom-global": "3.0.2",
"jsonpath-plus": "6.0.1",
"jsrsasign": "10.5.25",
"jszip": "3.8.0",
Expand Down
Loading

0 comments on commit 9bbaa16

Please sign in to comment.