From bf1720e5bbcfdb570a61ea4c723c2453b04cbee0 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 30 May 2025 13:42:30 +0200 Subject: [PATCH] test ... --- packages/docusaurus-utils/src/gitUtils.ts | 19 ++++--- website/package.json | 2 +- website/test.js | 67 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 website/test.js diff --git a/packages/docusaurus-utils/src/gitUtils.ts b/packages/docusaurus-utils/src/gitUtils.ts index fa55f3451b..254105e2d8 100644 --- a/packages/docusaurus-utils/src/gitUtils.ts +++ b/packages/docusaurus-utils/src/gitUtils.ts @@ -142,31 +142,32 @@ export async function getFileCommitDate( // See why: https://github.com/facebook/docusaurus/pull/10022 const resultFormat = includeAuthor ? 'RESULT:%ct,%an' : 'RESULT:%ct'; - const args = [ + const argsArray = [ `--format=${resultFormat}`, '--max-count=1', age === 'oldest' ? '--follow --diff-filter=A' : undefined, - ] - .filter(Boolean) - .join(' '); + ].filter((a) => typeof a !== 'undefined'); + + const args = argsArray.join(' '); const command = `git log ${args} -- "${file}"`; const result = (await GitCommandQueue.add(() => { return PerfLogger.async(command, () => { - return execa(command, { - // shell: true, + return execa('git', ['log', ...argsArray, '--', `"${file}"`], { + shell: false, }); }); }))!; + /* console.log('result', { file, - exitCode: result.exitCode, - stdout: result.stdout, - stderr: result.stderr, + result, }); + */ + if (result.exitCode !== 0) { throw new Error( `Failed to retrieve the git history for file "${file}" with exit code ${result.exitCode}: ${result.stderr}`, diff --git a/website/package.json b/website/package.json index 6d61086ce5..944608d006 100644 --- a/website/package.json +++ b/website/package.json @@ -27,7 +27,7 @@ "profile:bundle:samply": "./profileSamply.sh", "netlify:build:production": "yarn docusaurus write-translations && yarn netlify:crowdin:delay && yarn netlify:crowdin:uploadSources && yarn netlify:crowdin:downloadTranslations && yarn build", "netlify:build:branchDeploy": "yarn build", - "netlify:build:deployPreview": "yarn build", + "netlify:build:deployPreview": "node test", "netlify:crowdin:delay": "node delayCrowdin.mjs", "netlify:crowdin:wait": "node waitForCrowdin.mjs", "netlify:crowdin:downloadTranslations": "yarn netlify:crowdin:wait && yarn --cwd .. crowdin:download:website", diff --git a/website/test.js b/website/test.js new file mode 100644 index 0000000000..1364b86dd6 --- /dev/null +++ b/website/test.js @@ -0,0 +1,67 @@ +/** + * 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. + */ + +const execa = require('execa'); +const {PerfLogger} = require('@docusaurus/logger'); + +async function runTest(name, file, options) { + for (let i = 0; i < 100; i++) { + const before = performance.now(); + const result = await PerfLogger.async(`${name} ${i}`, async () => { + const out = execa.sync( + 'git', + // ['--version'], + ['log', '--format=RESULT:%ct,%an', '--max-count=1', '--', `"${file}"`], + { + // stdout: 'inherit', + ...options, + }, + ); + + return out; + }); + + const time = performance.now() - before; + + // console.log(`${name} ${i} => Time = ${time}`, options, result.exitCode); + } +} + +async function runAllTests() { + await runTest('Shell false', 'website/docs/advanced/architecture.mdx', { + shell: false, + }); + + await runTest('Shell true', 'website/docs/advanced/architecture.mdx', { + shell: true, + }); + + await runTest( + 'Shell false', + 'website/i18n/zh-CN/docusaurus-plugin-content-docs/current/advanced/architecture.mdx', + { + shell: false, + }, + ); + + await runTest( + 'Shell true', + 'website/i18n/zh-CN/docusaurus-plugin-content-docs/current/advanced/architecture.mdx', + { + shell: true, + }, + ); +} + +runAllTests().then( + () => { + console.log('success'); + }, + (e) => { + console.log('failure', e); + }, +);