diff --git a/jest/snapshotPathNormalizer.js b/jest/snapshotPathNormalizer.js index e97e0342312a..1db7669d01f3 100644 --- a/jest/snapshotPathNormalizer.js +++ b/jest/snapshotPathNormalizer.js @@ -11,6 +11,7 @@ const _ = require('lodash'); const {escapePath} = require('@docusaurus/utils'); +const {version} = require('@docusaurus/core/package.json'); const os = require('os'); const path = require('path'); const fs = require('fs'); @@ -131,6 +132,9 @@ function normalizePaths(value) { .split(`${path.sep + homeRealRelativeToTemp}`) .join(''), // untested + // Replace the Docusaurus version with a stub + (val) => val.split(version).join(''), + // In case the CWD is escaped (val) => val.split(escapePath(cwd)).join(''), diff --git a/packages/docusaurus-migrate/src/__tests__/__snapshots__/migration.test.ts.snap b/packages/docusaurus-migrate/src/__tests__/__snapshots__/migration.test.ts.snap index 13249f6d7869..b217085727a5 100644 --- a/packages/docusaurus-migrate/src/__tests__/__snapshots__/migration.test.ts.snap +++ b/packages/docusaurus-migrate/src/__tests__/__snapshots__/migration.test.ts.snap @@ -158,8 +158,8 @@ Array [ \\"docusaurus\\": \\"docusaurus\\" }, \\"dependencies\\": { - \\"@docusaurus/core\\": \\"2.0.0-beta.15\\", - \\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\", + \\"@docusaurus/core\\": \\"\\", + \\"@docusaurus/preset-classic\\": \\"\\", \\"clsx\\": \\"^1.1.1\\", \\"react\\": \\"^17.0.2\\", \\"react-dom\\": \\"^17.0.2\\" @@ -350,8 +350,8 @@ Array [ \\"docusaurus\\": \\"docusaurus\\" }, \\"dependencies\\": { - \\"@docusaurus/core\\": \\"2.0.0-beta.15\\", - \\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\", + \\"@docusaurus/core\\": \\"\\", + \\"@docusaurus/preset-classic\\": \\"\\", \\"clsx\\": \\"^1.1.1\\", \\"react\\": \\"^17.0.2\\", \\"react-dom\\": \\"^17.0.2\\" @@ -539,8 +539,8 @@ Array [ \\"docusaurus\\": \\"docusaurus\\" }, \\"dependencies\\": { - \\"@docusaurus/core\\": \\"2.0.0-beta.15\\", - \\"@docusaurus/preset-classic\\": \\"2.0.0-beta.15\\", + \\"@docusaurus/core\\": \\"\\", + \\"@docusaurus/preset-classic\\": \\"\\", \\"clsx\\": \\"^1.1.1\\", \\"react\\": \\"^17.0.2\\", \\"react-dom\\": \\"^17.0.2\\" diff --git a/website/package.json b/website/package.json index f1bc203b4ed2..8a27180bdf78 100644 --- a/website/package.json +++ b/website/package.json @@ -49,7 +49,6 @@ "@docusaurus/utils": "2.0.0-beta.16", "@docusaurus/utils-common": "2.0.0-beta.16", "@popperjs/core": "^2.11.2", - "axios": "^0.26.0", "clsx": "^1.1.1", "color": "^4.2.1", "esbuild-loader": "2.18.0", diff --git a/website/src/plugins/changelog/index.js b/website/src/plugins/changelog/index.js index 54194eed00c3..58a7bb2f6522 100644 --- a/website/src/plugins/changelog/index.js +++ b/website/src/plugins/changelog/index.js @@ -10,7 +10,6 @@ const path = require('path'); const fs = require('fs-extra'); const pluginContentBlog = require('@docusaurus/plugin-content-blog'); const {aliasedSitePath, docuHash, normalizeUrl} = require('@docusaurus/utils'); -const syncAvatars = require('./syncAvatars'); /** * Multiple versions may be published on the same day, causing the order to be @@ -51,7 +50,7 @@ function processSection(section) { .map((author) => ({ ...author, name: author.name ?? author.alias, - imageURL: `./img/${author.alias}.png`, + imageURL: `https://github.com/${author.alias}.png`, })) .sort((a, b) => a.url.localeCompare(b.url)); @@ -117,7 +116,8 @@ async function ChangelogPlugin(context, options) { ), ), ); - await syncAvatars(authorsMap, generateDir); + const authorsPath = path.join(generateDir, 'authors.json'); + await fs.outputFile(authorsPath, JSON.stringify(authorsMap, null, 2)); const content = await blogPlugin.loadContent(); content.blogPosts.forEach((post, index) => { const pageIndex = Math.floor(index / options.postsPerPage); diff --git a/website/src/plugins/changelog/syncAvatars.js b/website/src/plugins/changelog/syncAvatars.js deleted file mode 100644 index a29330e4aef4..000000000000 --- a/website/src/plugins/changelog/syncAvatars.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// @ts-check - -const path = require('path'); -const fs = require('fs-extra'); -// const axios = require('axios').default; - -// TODO not sure how the syncing should be done at all... for now it always -// pretends the limit is reached. We should only fetch a portion of the avatars -// at a time. But seems avatars.githubusercontent.com API doesn't like HTTP -// requests? -/** - * @param {string} username - * @param {Record} lastUpdateCache - * @param {Record} authorsMap - * @returns true if saved successfully (including not found); false if limit - * reached - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -async function fetchImage(username, lastUpdateCache, authorsMap) { - return false; -} - -/** - * We need to keep track of all committers that are in the changelog, and fetch - * their avatars beforehand. This prevents sending too many requests to GitHub - * every time one visits a page. Avatar refreshing is done incrementally across - * each build. - * - * This method mutates the authorsMap. If the avatar fails to be fetched, the - * imageURL is re-written with the github remote URL. The authors map is then - * written to FS. - * - * @param {Record} authorsMap - * @param {string} generateDir - */ -async function syncAvatars(authorsMap, generateDir) { - const imagePath = path.join(generateDir, 'img'); - const lastUpdateCachePath = path.join(imagePath, 'lastUpdate.json'); - const authorsPath = path.join(generateDir, 'authors.json'); - if (!(await fs.pathExists(lastUpdateCachePath))) { - await fs.outputFile(lastUpdateCachePath, '{}'); - } - /** - * Records the last time an avatar was successfully updated. - * If an entry doesn't exist, the file won't exist either. - * @type {Record} - */ - const lastUpdateCache = await fs.readJSON(lastUpdateCachePath); - let limitReached = false; - for (const username of Object.keys(authorsMap)) { - if (!limitReached && !lastUpdateCache[username]) { - if (!(await fetchImage(username, lastUpdateCache, authorsMap))) { - limitReached = true; - } - } - if (limitReached) { - authorsMap[username].imageURL = `https://github.com/${username}.png`; - } - } - const usersByLastUpdate = Object.entries(lastUpdateCache) - .sort((a, b) => a[1] - b[1]) - .map((a) => a[0]); - for (const username of usersByLastUpdate) { - if ( - !limitReached && - lastUpdateCache[username] < Date.now() - 24 * 3600 * 1000 - ) { - if (!(await fetchImage(username, lastUpdateCache, authorsMap))) { - break; - } - } - } - await fs.outputFile( - lastUpdateCachePath, - JSON.stringify(lastUpdateCache, null, 2), - ); - await fs.outputFile(authorsPath, JSON.stringify(authorsMap, null, 2)); -} - -module.exports = syncAvatars; diff --git a/yarn.lock b/yarn.lock index 315d3b4e7b11..ba0b094e5cdb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5326,13 +5326,6 @@ axios@^0.25.0: dependencies: follow-redirects "^1.14.7" -axios@^0.26.0: - version "0.26.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.0.tgz#9a318f1c69ec108f8cd5f3c3d390366635e13928" - integrity sha512-lKoGLMYtHvFrPVt3r+RBMp9nh34N0M8zEfCWqdWZx6phynIEhQqAdydpyBAAG211zlhX9Rgu08cOamy6XjE5Og== - dependencies: - follow-redirects "^1.14.8" - axobject-query@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/axobject-query/-/axobject-query-2.2.0.tgz#943d47e10c0b704aa42275e20edf3722648989be" @@ -9351,7 +9344,7 @@ folder-walker@^3.2.0: dependencies: from2 "^2.1.0" -follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7, follow-redirects@^1.14.8: +follow-redirects@^1.0.0, follow-redirects@^1.14.0, follow-redirects@^1.14.7: version "1.14.9" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7" integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==