From fdc0e6e07d2f3e9113bfc32e3b24958c730028ab Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Tue, 2 Apr 2024 15:23:32 +0100 Subject: [PATCH 1/2] Fix template generation for WWW + Community --- src/build/fetchTemplate.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/build/fetchTemplate.js b/src/build/fetchTemplate.js index 6df106d2..5f02278d 100644 --- a/src/build/fetchTemplate.js +++ b/src/build/fetchTemplate.js @@ -21,6 +21,12 @@ const ensureDir = require('./ensureDir'); const fetch = import('node-fetch'); +const wwwSelectors = { + content: '[class^="Layout"] > *, [class*=" Layout"] > *', + header: 'nav, [class^="Header"], [class*=" Header"]', + footer: 'footer, [class^="Footer"], [class*=" Footer"], #footer', +}; + const baseHtml = async mode => { // Support a blank template for completely local dev if (mode === 'blank') { @@ -105,17 +111,22 @@ module.exports = async () => { document.head.insertBefore(charset, document.head.firstChild); } + let contentAnchor; if (mode === 'www' || mode === 'community') { // Remove nav log in + sign up buttons - document.querySelectorAll('nav li').forEach(node => { + document.querySelectorAll('header li').forEach(node => { if (node.textContent.toLowerCase().includes('log in')) node.remove(); if (node.textContent.toLowerCase().includes('sign up')) node.remove(); }); // Remove www + community content - document.querySelectorAll('div[class^="Layout"] > *').forEach(node => { - if (node.querySelector('nav, [class^="Header"], [class*=" Header"]')) return; - if (node.querySelector('footer, [class^="Footer"], [class*=" Footer"]')) return; + document.querySelectorAll(wwwSelectors.content).forEach(node => { + if (node.querySelector(wwwSelectors.header)) return; + if (node.querySelector(wwwSelectors.footer)) return; + + // If this is the first content node on the page, + // we'll inject the content block where it is + if (!contentAnchor) contentAnchor = node.previousElementSibling; node.remove(); }); } @@ -127,7 +138,7 @@ module.exports = async () => { document.querySelector('body > .app').appendChild(content); } if (mode === 'www' || mode === 'community') { - document.querySelector('nav').parentElement.insertAdjacentElement('afterend', content); + contentAnchor.insertAdjacentElement('afterend', content); } // Inject the title block From e08fa3546ba1c6069b2d7fdd2a941d07f8baba5e Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Tue, 2 Apr 2024 15:24:53 +0100 Subject: [PATCH 2/2] Remove node-fetch usage --- package-lock.json | 127 ------------------------------- package.json | 1 - src/build/createGitHubComment.js | 8 +- src/build/fetchTemplate.js | 6 +- 4 files changed, 5 insertions(+), 137 deletions(-) diff --git a/package-lock.json b/package-lock.json index a449b451..55b3224e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,6 @@ "html-webpack-plugin": "^5.6.0", "jsdom": "^23.2.0", "mini-css-extract-plugin": "^2.7.7", - "node-fetch": "^3.3.2", "path-browserify": "^1.0.1", "posthtml": "^0.16.6", "posthtml-expressions": "^1.11.3", @@ -4339,14 +4338,6 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, - "node_modules/data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==", - "engines": { - "node": ">= 12" - } - }, "node_modules/data-urls": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", @@ -5268,28 +5259,6 @@ "resolved": "https://registry.npmjs.org/fclone/-/fclone-1.0.11.tgz", "integrity": "sha1-EOhdo4v+p/xZk0HClu4ddyZu5kA=" }, - "node_modules/fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "paypal", - "url": "https://paypal.me/jimmywarting" - } - ], - "dependencies": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - }, - "engines": { - "node": "^12.20 || >= 14.13" - } - }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -5459,17 +5428,6 @@ "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" }, - "node_modules/formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "dependencies": { - "fetch-blob": "^3.1.2" - }, - "engines": { - "node": ">=12.20.0" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -7256,41 +7214,6 @@ "tslib": "^2.0.3" } }, - "node_modules/node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/jimmywarting" - }, - { - "type": "github", - "url": "https://paypal.me/jimmywarting" - } - ], - "engines": { - "node": ">=10.5.0" - } - }, - "node_modules/node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "dependencies": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - }, - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/node-fetch" - } - }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -10386,14 +10309,6 @@ "minimalistic-assert": "^1.0.0" } }, - "node_modules/web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", - "engines": { - "node": ">= 8" - } - }, "node_modules/webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", @@ -13959,11 +13874,6 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, - "data-uri-to-buffer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.0.tgz", - "integrity": "sha512-Vr3mLBA8qWmcuschSLAOogKgQ/Jwxulv3RNE4FXnYWRGujzrRWQI4m12fQqRkwX06C0KanhLr4hK+GydchZsaA==" - }, "data-urls": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", @@ -14650,15 +14560,6 @@ "resolved": "https://registry.npmjs.org/fclone/-/fclone-1.0.11.tgz", "integrity": "sha1-EOhdo4v+p/xZk0HClu4ddyZu5kA=" }, - "fetch-blob": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", - "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", - "requires": { - "node-domexception": "^1.0.0", - "web-streams-polyfill": "^3.0.3" - } - }, "file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -14778,14 +14679,6 @@ "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", "integrity": "sha1-C+4AUBiusmDQo6865ljdATbsG5k=" }, - "formdata-polyfill": { - "version": "4.0.10", - "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", - "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", - "requires": { - "fetch-blob": "^3.1.2" - } - }, "forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -16081,21 +15974,6 @@ "tslib": "^2.0.3" } }, - "node-domexception": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", - "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" - }, - "node-fetch": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", - "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", - "requires": { - "data-uri-to-buffer": "^4.0.0", - "fetch-blob": "^3.1.4", - "formdata-polyfill": "^4.0.10" - } - }, "node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -18211,11 +18089,6 @@ "minimalistic-assert": "^1.0.0" } }, - "web-streams-polyfill": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", - "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==" - }, "webidl-conversions": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", diff --git a/package.json b/package.json index b4de64ba..9e8e85fc 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "html-webpack-plugin": "^5.6.0", "jsdom": "^23.2.0", "mini-css-extract-plugin": "^2.7.7", - "node-fetch": "^3.3.2", "path-browserify": "^1.0.1", "posthtml": "^0.16.6", "posthtml-expressions": "^1.11.3", diff --git a/src/build/createGitHubComment.js b/src/build/createGitHubComment.js index 1e6ce2fd..8d7634bd 100644 --- a/src/build/createGitHubComment.js +++ b/src/build/createGitHubComment.js @@ -1,5 +1,5 @@ /* -Copyright 2022 DigitalOcean +Copyright 2024 DigitalOcean Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,8 +14,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -const fetch = import('node-fetch'); - module.exports = async args => { const baseURL = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com`; const tools = args.map(data => { @@ -28,7 +26,7 @@ module.exports = async args => { | ${tools.join(' | ')} | |${(new Array(tools.length).fill('---')).join('|')}|`; - const res = await fetch.then(({ default: run }) => run( + const res = await fetch( `https://api.github.com/repos/${process.env.REPO_NAME}/commits/${process.env.COMMIT_SHA}/comments`, { method: 'POST', @@ -41,7 +39,7 @@ module.exports = async args => { Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString('base64')}`, }, }, - )).catch(async e => { + ).catch(async e => { console.log(await e.json()); process.exit(1); }); diff --git a/src/build/fetchTemplate.js b/src/build/fetchTemplate.js index 5f02278d..6856a232 100644 --- a/src/build/fetchTemplate.js +++ b/src/build/fetchTemplate.js @@ -19,8 +19,6 @@ const { JSDOM } = jsdom; const fs = require('fs'); const ensureDir = require('./ensureDir'); -const fetch = import('node-fetch'); - const wwwSelectors = { content: '[class^="Layout"] > *, [class*=" Layout"] > *', header: 'nav, [class^="Header"], [class*=" Header"]', @@ -44,13 +42,13 @@ const baseHtml = async mode => { // Support developing a tool for WWW if (mode === 'www') { - const res = await fetch.then(({ default: run }) => run('https://www.digitalocean.com')); + const res = await fetch('https://www.digitalocean.com'); return await res.text(); } // Default to a tool for Community tooling if (mode === 'community') { - const res = await fetch.then(({ default: run }) => run('https://www.digitalocean.com/community')); + const res = await fetch('https://www.digitalocean.com/community'); return await res.text(); }