From 81bbd91ced3c58a1f36ccbcda8221dc5d377934c Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 24 Feb 2024 17:30:34 -0500 Subject: [PATCH 1/5] chore: use direct path to assetgraph-builder > buildProduction in nps --- package-scripts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-scripts.js b/package-scripts.js index 6fb0594980..728ddb206a 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -277,7 +277,7 @@ module.exports = { }, postbuild: { script: - 'buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js docs/_dist >> docs/_dist/_headers', + 'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js docs/_dist >> docs/_dist/_headers', description: 'Post-process docs after build', hiddenFromHelp: true }, From e6999aec1c449f97bd201fc55c04cee4b92c7a34 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 24 Feb 2024 17:45:37 -0500 Subject: [PATCH 2/5] chore: switch NODE_VERSION to 20 --- netlify.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netlify.toml b/netlify.toml index 36fe1e9a47..901bdb7b54 100644 --- a/netlify.toml +++ b/netlify.toml @@ -14,8 +14,7 @@ [build.environment] DEBUG = "mocha:docs*" - NODE_VERSION = "16" - RUBY_VERSION = "2.7.2" + NODE_VERSION = "20" [context.deploy-preview] command = "npm start docs" From a7496680fd6d60a739964019b591b85652774765 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 24 Feb 2024 18:07:07 -0500 Subject: [PATCH 3/5] chore: remove scripts/netlify-headers.js --- package-scripts.js | 4 +- scripts/netlify-headers.js | 126 ------------------------------------- 2 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 scripts/netlify-headers.js diff --git a/package-scripts.js b/package-scripts.js index 728ddb206a..1e4c072973 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -259,7 +259,7 @@ module.exports = { docs: { default: { script: - 'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck && node scripts/netlify-headers.js docs/_site >> docs/_site/_headers', + 'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck', description: 'Build documentation' }, production: { @@ -277,7 +277,7 @@ module.exports = { }, postbuild: { script: - 'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js docs/_dist >> docs/_dist/_headers', + 'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers', description: 'Post-process docs after build', hiddenFromHelp: true }, diff --git a/scripts/netlify-headers.js b/scripts/netlify-headers.js deleted file mode 100644 index e881423d20..0000000000 --- a/scripts/netlify-headers.js +++ /dev/null @@ -1,126 +0,0 @@ -'use strict'; - -const AssetGraph = require('assetgraph'); - -const dest = process.argv[2]; - -if (!dest) { - console.error('usage: node netlify-headers.js '); - console.error('example: node netlify-headers.js docs/_dist'); - process.exit(1); -} - -const headers = ['Content-Security-Policy']; - -const resourceHintTypeMap = { - HtmlPreloadLink: 'preload', - HtmlPrefetchLink: 'prefetch', - HtmlPreconnectLink: 'preconnect', - HtmlDnsPrefetchLink: 'dns-prefetch' -}; - -function getHeaderForRelation(rel) { - let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${ - rel.as - }; type=${rel.to.contentType}`; - - if (rel.as === 'font') { - header = `${header}; crossorigin=anonymous`; - } - - return header; -} - -console.error('Generating optimal netlify headers...'); - -new AssetGraph({root: dest}) - .loadAssets('*.html') - .populate({ - followRelations: {type: 'HtmlAnchor', crossorigin: false} - }) - .queue(function (assetGraph) { - const assets = assetGraph.findAssets({ - type: 'Html', - isInline: false, - isLoaded: true - }); - - const headerMap = {}; - - assets.forEach(function (asset) { - const url = - '/' + - asset.url - .replace(assetGraph.root, '') - .replace(/#.*/, '') - .replace('index.html', ''); - if (!headerMap[url]) { - headerMap[url] = []; - } - - headers.forEach(function (header) { - const node = asset.parseTree.querySelector( - 'meta[http-equiv=' + header + ']' - ); - - if (node) { - headerMap[url].push(`${header}: ${node.getAttribute('content')}`); - - node.parentNode.removeChild(node); - asset.markDirty(); - } - }); - - const firstCssRel = asset.outgoingRelations.filter(r => { - return ( - r.type === 'HtmlStyle' && - r.crossorigin === false && - r.href !== undefined - ); - })[0]; - - if (firstCssRel) { - const header = `Link: <${firstCssRel.href}>; rel=preload; as=style`; - - headerMap[url].push(header); - } - - const resourceHintRelations = asset.outgoingRelations.filter(r => - ['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type) - ); - - resourceHintRelations.forEach(rel => { - headerMap[url].push(getHeaderForRelation(rel)); - - rel.detach(); - }); - - const preconnectRelations = asset.outgoingRelations.filter(r => - ['HtmlPreconnectLink'].includes(r.type) - ); - - preconnectRelations.forEach(rel => { - const header = `Link: <${rel.href}>; rel=preconnect`; - - headerMap[url].push(header); - - rel.detach(); - }); - }); - - console.log('\n## Autogenerated headers:\n'); - - Object.keys(headerMap).forEach(function (url) { - console.log(url); - - const httpHeaders = headerMap[url]; - - httpHeaders.forEach(function (header) { - console.log(` ${header}`); - }); - - console.log(''); - }); - console.error('netlify headers done!'); - }) - .run(); From 4533aae6a62f8df464317e92700c4d0289e174a0 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 24 Feb 2024 18:07:07 -0500 Subject: [PATCH 4/5] chore: remove scripts/netlify-headers.js --- package-scripts.js | 4 +- scripts/netlify-headers.js | 126 ------------------------------------- 2 files changed, 2 insertions(+), 128 deletions(-) delete mode 100644 scripts/netlify-headers.js diff --git a/package-scripts.js b/package-scripts.js index 728ddb206a..1e4c072973 100644 --- a/package-scripts.js +++ b/package-scripts.js @@ -259,7 +259,7 @@ module.exports = { docs: { default: { script: - 'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck && node scripts/netlify-headers.js docs/_site >> docs/_site/_headers', + 'nps docs.clean && nps docs.api && eleventy && nps docs.linkcheck', description: 'Build documentation' }, production: { @@ -277,7 +277,7 @@ module.exports = { }, postbuild: { script: - 'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers && node scripts/netlify-headers.js docs/_dist >> docs/_dist/_headers', + 'node node_modules/assetgraph-builder/bin/buildProduction docs/_site/index.html --outroot docs/_dist --canonicalroot https://mochajs.org/ --optimizeimages --svgo --inlinehtmlimage 9400 --inlinehtmlscript 0 --asyncscripts && cp docs/_headers docs/_dist/_headers', description: 'Post-process docs after build', hiddenFromHelp: true }, diff --git a/scripts/netlify-headers.js b/scripts/netlify-headers.js deleted file mode 100644 index e881423d20..0000000000 --- a/scripts/netlify-headers.js +++ /dev/null @@ -1,126 +0,0 @@ -'use strict'; - -const AssetGraph = require('assetgraph'); - -const dest = process.argv[2]; - -if (!dest) { - console.error('usage: node netlify-headers.js '); - console.error('example: node netlify-headers.js docs/_dist'); - process.exit(1); -} - -const headers = ['Content-Security-Policy']; - -const resourceHintTypeMap = { - HtmlPreloadLink: 'preload', - HtmlPrefetchLink: 'prefetch', - HtmlPreconnectLink: 'preconnect', - HtmlDnsPrefetchLink: 'dns-prefetch' -}; - -function getHeaderForRelation(rel) { - let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${ - rel.as - }; type=${rel.to.contentType}`; - - if (rel.as === 'font') { - header = `${header}; crossorigin=anonymous`; - } - - return header; -} - -console.error('Generating optimal netlify headers...'); - -new AssetGraph({root: dest}) - .loadAssets('*.html') - .populate({ - followRelations: {type: 'HtmlAnchor', crossorigin: false} - }) - .queue(function (assetGraph) { - const assets = assetGraph.findAssets({ - type: 'Html', - isInline: false, - isLoaded: true - }); - - const headerMap = {}; - - assets.forEach(function (asset) { - const url = - '/' + - asset.url - .replace(assetGraph.root, '') - .replace(/#.*/, '') - .replace('index.html', ''); - if (!headerMap[url]) { - headerMap[url] = []; - } - - headers.forEach(function (header) { - const node = asset.parseTree.querySelector( - 'meta[http-equiv=' + header + ']' - ); - - if (node) { - headerMap[url].push(`${header}: ${node.getAttribute('content')}`); - - node.parentNode.removeChild(node); - asset.markDirty(); - } - }); - - const firstCssRel = asset.outgoingRelations.filter(r => { - return ( - r.type === 'HtmlStyle' && - r.crossorigin === false && - r.href !== undefined - ); - })[0]; - - if (firstCssRel) { - const header = `Link: <${firstCssRel.href}>; rel=preload; as=style`; - - headerMap[url].push(header); - } - - const resourceHintRelations = asset.outgoingRelations.filter(r => - ['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type) - ); - - resourceHintRelations.forEach(rel => { - headerMap[url].push(getHeaderForRelation(rel)); - - rel.detach(); - }); - - const preconnectRelations = asset.outgoingRelations.filter(r => - ['HtmlPreconnectLink'].includes(r.type) - ); - - preconnectRelations.forEach(rel => { - const header = `Link: <${rel.href}>; rel=preconnect`; - - headerMap[url].push(header); - - rel.detach(); - }); - }); - - console.log('\n## Autogenerated headers:\n'); - - Object.keys(headerMap).forEach(function (url) { - console.log(url); - - const httpHeaders = headerMap[url]; - - httpHeaders.forEach(function (header) { - console.log(` ${header}`); - }); - - console.log(''); - }); - console.error('netlify headers done!'); - }) - .run(); From 638da23d7fb56633e590b1bd106e6c50a3d8f6f7 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 24 Feb 2024 18:16:08 -0500 Subject: [PATCH 5/5] git checkout master -- netlify.toml --- netlify.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netlify.toml b/netlify.toml index 901bdb7b54..36fe1e9a47 100644 --- a/netlify.toml +++ b/netlify.toml @@ -14,7 +14,8 @@ [build.environment] DEBUG = "mocha:docs*" - NODE_VERSION = "20" + NODE_VERSION = "16" + RUBY_VERSION = "2.7.2" [context.deploy-preview] command = "npm start docs"