From 5dcfa6a9d971944e585c4cef70a3e897a5ce95c0 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:18:03 +0300 Subject: [PATCH 1/4] docs(build-site): minor TODO fix (#9049) --- bin/build-site.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/build-site.js b/bin/build-site.js index 5e63af52c2..e48d5f6ded 100755 --- a/bin/build-site.js +++ b/bin/build-site.js @@ -47,7 +47,7 @@ function highlightEs6() { // TODO: this is a fragile and hacky way to get // 'async' and 'await' to highlight correctly - // in this blog post. + // in blog posts & documentation. replace({ regex: '(await|async|of)', replacement: '$1', From 9121f6e394187f4a5d96ac0c9072a51c12a090cc Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:03:05 +0300 Subject: [PATCH 2/4] chore: remove dependency child-process-promise (#9054) This dependency is ancient, and can be implement easily with the standard library. --- bin/build-site.js | 4 +++- package-lock.json | 59 ----------------------------------------------- package.json | 1 - 3 files changed, 3 insertions(+), 61 deletions(-) diff --git a/bin/build-site.js b/bin/build-site.js index e48d5f6ded..c2ac0bf2cc 100755 --- a/bin/build-site.js +++ b/bin/build-site.js @@ -2,9 +2,11 @@ 'use strict'; +const { promisify } = require('node:util'); +const exec = promisify(require('node:child_process').exec); + var fs = require('fs'); var replace = require('replace'); -var exec = require('child-process-promise').exec; var mkdirp = require('mkdirp'); var cssmin = require('cssmin'); diff --git a/package-lock.json b/package-lock.json index 3442c835d7..88be4f8acd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,6 @@ "chai": "3.5.0", "chai-as-promised": "5.3.0", "change-case": "4.0.1", - "child-process-promise": "2.2.1", "cssmin": "0.4.3", "denodeify": "1.2.1", "derequire": "2.1.1", @@ -1567,17 +1566,6 @@ "snake-case": "^3.0.1" } }, - "node_modules/child-process-promise": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/child-process-promise/-/child-process-promise-2.2.1.tgz", - "integrity": "sha512-Fi4aNdqBsr0mv+jgWxcZ/7rAIC2mgihrptyVI4foh/rrjY/3BNjfP9+oaiFx/fzim+1ZyCNBae0DlyfQhSugog==", - "dev": true, - "dependencies": { - "cross-spawn": "^4.0.2", - "node-version": "^1.0.0", - "promise-polyfill": "^6.0.1" - } - }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", @@ -2142,16 +2130,6 @@ "sha.js": "^2.4.8" } }, - "node_modules/cross-spawn": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-4.0.2.tgz", - "integrity": "sha512-yAXz/pA1tD8Gtg2S98Ekf/sewp3Lcp3YoFKJ4Hkp5h5yLWnKVTDU0kwjKJ8NDCYcfTLfyGkzTikst+jWypT1iA==", - "dev": true, - "dependencies": { - "lru-cache": "^4.0.1", - "which": "^1.2.9" - } - }, "node_modules/crypto-browserify": { "version": "3.12.0", "resolved": "https://registry.npmjs.org/crypto-browserify/-/crypto-browserify-3.12.0.tgz", @@ -5822,16 +5800,6 @@ "tslib": "^2.0.3" } }, - "node_modules/lru-cache": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", - "integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", - "dev": true, - "dependencies": { - "pseudomap": "^1.0.2", - "yallist": "^2.1.2" - } - }, "node_modules/ltgt": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", @@ -6507,15 +6475,6 @@ "node-gyp-build-test": "build-test.js" } }, - "node_modules/node-version": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/node-version/-/node-version-1.2.0.tgz", - "integrity": "sha512-ma6oU4Sk0qOoKEAymVoTvk8EdXEobdS7m/mAGhDJ8Rouugho48crHBORAmy5BoOcv8wraPM6xumapQp5hl4iIQ==", - "dev": true, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/nodemon": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.2.1.tgz", @@ -7989,12 +7948,6 @@ "integrity": "sha512-j9RWp/40Ttja+wxiEjS5Ud5liHQxAA5K+STc9Vh09mF4zpNEuXTR35U6Uk5qVCsf6qp2v5UnLWa7SNmZ6M1ewQ==", "dev": true }, - "node_modules/promise-polyfill": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-6.1.0.tgz", - "integrity": "sha512-g0LWaH0gFsxovsU7R5LrrhHhWAWiHRnh1GPrhXnPgYsDkIqjRYUYSZEsej/wtleDrz5xVSIDbeKfidztp2XHFQ==", - "dev": true - }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -8022,12 +7975,6 @@ "event-stream": "~0.5" } }, - "node_modules/pseudomap": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", - "integrity": "sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==", - "dev": true - }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", @@ -10435,12 +10382,6 @@ "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", "dev": true }, - "node_modules/yallist": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", - "integrity": "sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==", - "dev": true - }, "node_modules/yargs": { "version": "15.4.1", "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", diff --git a/package.json b/package.json index 60bee79d5e..1000179386 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,6 @@ "chai": "3.5.0", "chai-as-promised": "5.3.0", "change-case": "4.0.1", - "child-process-promise": "2.2.1", "cssmin": "0.4.3", "denodeify": "1.2.1", "derequire": "2.1.1", From 17a3b3b70bd3b17510b7f04c1594b9101b768872 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:04:20 +0300 Subject: [PATCH 3/4] refactor(build-site): standardise path resolution (#9050) --- bin/build-site.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bin/build-site.js b/bin/build-site.js index c2ac0bf2cc..94f2f0a08e 100755 --- a/bin/build-site.js +++ b/bin/build-site.js @@ -6,12 +6,14 @@ const { promisify } = require('node:util'); const exec = promisify(require('node:child_process').exec); var fs = require('fs'); +const Path = require('node:path'); + var replace = require('replace'); var mkdirp = require('mkdirp'); var cssmin = require('cssmin'); -var POUCHDB_CSS = __dirname + '/../docs/static/css/pouchdb.css'; -var POUCHDB_LESS = __dirname + '/../docs/static/less/pouchdb/pouchdb.less'; +const POUCHDB_CSS = resolvePath('docs/static/css/pouchdb.css'); +const POUCHDB_LESS = resolvePath('docs/static/less/pouchdb/pouchdb.less'); process.chdir('docs'); @@ -22,8 +24,8 @@ function checkJekyll() { } function buildCSS() { - mkdirp.sync(__dirname + '/../docs/static/css'); - var cmd = __dirname + '/../node_modules/less/bin/lessc ' + POUCHDB_LESS; + mkdirp.sync(resolvePath('docs/static/css')); + const cmd = [ resolvePath('node_modules/less/bin/lessc'), POUCHDB_LESS ].join(' '); return exec(cmd).then(function (child) { var minifiedCss = cssmin(child.stdout); fs.writeFileSync(POUCHDB_CSS, minifiedCss); @@ -45,7 +47,7 @@ function buildJekyll(path) { } function highlightEs6() { - var path = require('path').resolve(__dirname, '../docs/_site'); + const path = resolvePath('docs/_site'); // TODO: this is a fragile and hacky way to get // 'async' and 'await' to highlight correctly @@ -71,6 +73,10 @@ function buildEverything() { .catch(onError); } +function resolvePath(projectLocalPath) { + return Path.resolve(__dirname, '..', projectLocalPath); +} + if (!process.env.BUILD) { const http_server = require('http-server'); const watchGlob = require('glob-watcher'); From 4711759937e59ed44ae0277f5238c8eb9b527620 Mon Sep 17 00:00:00 2001 From: Alex Anderson <191496+alxndrsn@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:24:54 +0300 Subject: [PATCH 4/4] fix(docs): minify code.js automatically (#9051) Previously minification seemed to happen "offline", and both source and minified file were tracked in git. This also prevents the unused source file `code.js` from being served at https://pouchdb.com/static/js/code.js --- bin/build-site.js | 21 +++++++++++++++++++++ docs/_config.yml | 2 ++ docs/{static/js => src}/code.js | 0 docs/static/js/code.min.js | 1 - 4 files changed, 23 insertions(+), 1 deletion(-) rename docs/{static/js => src}/code.js (100%) delete mode 100644 docs/static/js/code.min.js diff --git a/bin/build-site.js b/bin/build-site.js index 94f2f0a08e..691e006e22 100755 --- a/bin/build-site.js +++ b/bin/build-site.js @@ -11,6 +11,7 @@ const Path = require('node:path'); var replace = require('replace'); var mkdirp = require('mkdirp'); var cssmin = require('cssmin'); +const terser = require('terser'); const POUCHDB_CSS = resolvePath('docs/static/css/pouchdb.css'); const POUCHDB_LESS = resolvePath('docs/static/less/pouchdb/pouchdb.less'); @@ -43,6 +44,26 @@ function buildJekyll(path) { return highlightEs6(); }).then(function () { console.log('=> Highlighted ES6'); + + const srcPath = resolvePath('docs/src/code.js'); + const targetPath = resolvePath('docs/_site/static/js/code.min.js'); + const src = fs.readFileSync(srcPath, { encoding:'utf8' }); + const mangle = { toplevel: true }; + const output = { ascii_only: true }; + const { code, error } = terser.minify(src, { mangle, output }); + if (error) { + if (process.env.BUILD) { + throw error; + } else { + console.log( + `Javascript minification failed on line ${error.line} col ${error.col}:`, + error.message, + ); + } + } else { + fs.writeFileSync(targetPath, code); + console.log('Minified javascript.'); + } }); } diff --git a/docs/_config.yml b/docs/_config.yml index f6d6709aec..4b1b19275a 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -11,3 +11,5 @@ github: collections: guides: output: true +exclude: + - src diff --git a/docs/static/js/code.js b/docs/src/code.js similarity index 100% rename from docs/static/js/code.js rename to docs/src/code.js diff --git a/docs/static/js/code.min.js b/docs/static/js/code.min.js deleted file mode 100644 index 5bf9fd3313..0000000000 --- a/docs/static/js/code.min.js +++ /dev/null @@ -1 +0,0 @@ -function codeWrap(){"use strict";function a(){var a='
{{tapPanes}}
';l.forEach(function(e){var t=$("[data-code-id='"+e+"']"),c=t.get().map(function(a){return a.outerHTML}).join(""),i=a.replace(/{{tapPanes}}/g,c).replace(/{{codeId}}/g,e);t.first().replaceWith(i),t.remove()}),$("[data-code-hide]").addClass("hide")}function e(a){var e=!localStorage.getItem("codeStyle");if(e&&localStorage.setItem("codeStyle",c),a=a||localStorage.getItem("codeStyle"),"undefined"!=typeof a&&null!==a){var t=$('[data-code-tablist] [href="#'+a+'"]').parent();$("[data-code-tablist] li").removeClass("active"),t.addClass("active"),$(".tab-pane").removeClass("active"),$('.tab-pane[id="'+a+'"]').addClass("active"),localStorage.setItem("codeStyle",a)}}function t(){o.length>0||l.forEach(function(a){var e=$("[data-code-id='"+a+"']"),t=0;e.get().forEach(function(a){var e=a.style.display;a.style.display="block";var c=a.clientHeight;a.style.display=e,c>t&&(t=c)}),e.find("pre").css("height",t),o.push(a)})}var c="promise",i=$("[data-code-id]").get(),l=i.map(function(a){return a.attributes["data-code-id"].value}).filter(function(a,e,t){return t.indexOf(a)==e});a(),e(),$("[data-code-tablist] [href]").on("click",function(a){var c=$(this).attr("href");e(c.replace("#","")),t(),a.preventDefault()});var o=[]}codeWrap();