Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ website/bundler-cpu-profile.json
website/profile.json.gz


.claude
.codex

2 changes: 1 addition & 1 deletion admin/scripts/test-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -xeuo pipefail
rm -rf ../test-website

CUSTOM_REGISTRY_URL="http://localhost:4873"
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version")-NEW"
NEW_VERSION="$(node -p "require('./packages/docusaurus/package.json').version")-NEW-$RANDOM"
CONTAINER_NAME="verdaccio"
EXTRA_OPTS=""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@docusaurus/core": "3.9.2",
"@docusaurus/faster": "3.9.2",
"@docusaurus/preset-classic": "3.9.2",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/create-docusaurus/templates/classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@docusaurus/core": "3.9.2",
"@docusaurus/faster": "3.9.2",
"@docusaurus/preset-classic": "3.9.2",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
Expand Down
7 changes: 2 additions & 5 deletions packages/docusaurus-bundler/src/currentBundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ import type {CurrentBundler, DocusaurusConfig} from '@docusaurus/types';
// We inject a site config slice because the Rspack flag might change place
type SiteConfigSlice = {
future: {
experimental_faster: Pick<
DocusaurusConfig['future']['experimental_faster'],
'rspackBundler'
>;
faster: Pick<DocusaurusConfig['future']['faster'], 'rspackBundler'>;
};
};

function isRspack(siteConfig: SiteConfigSlice): boolean {
return siteConfig.future.experimental_faster.rspackBundler;
return siteConfig.future.faster.rspackBundler;
}

export async function getCurrentBundler({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ describe('createJsLoaderFactory', () => {
webpack: siteConfig?.webpack,
future: fromPartial({
...siteConfig?.future,
experimental_faster: fromPartial({
...siteConfig?.future?.experimental_faster,
faster: fromPartial({
...siteConfig?.future?.faster,
}),
}),
},
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('createJsLoaderFactory', () => {
await expect(() =>
testJsLoaderFactory({
future: {
experimental_faster: {
faster: {
swcJsLoader: true,
},
},
Expand All @@ -82,10 +82,10 @@ describe('createJsLoaderFactory', () => {
},
}),
).rejects.toThrowErrorMatchingInlineSnapshot(`
"You can't use siteConfig.webpack.jsLoader and siteConfig.future.experimental_faster.swcJsLoader at the same time.
"You can't use siteConfig.webpack.jsLoader and siteConfig.future.faster.swcJsLoader at the same time.
To avoid any configuration ambiguity, you must make an explicit choice:
- If you want to use Docusaurus Faster and SWC (recommended), remove siteConfig.webpack.jsLoader
- If you want to use a custom JS loader, use siteConfig.future.experimental_faster.swcJsLoader: false"
- If you want to use a custom JS loader, use siteConfig.future.faster.swcJsLoader: false"
`);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus-bundler/src/loaders/jsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ export async function createJsLoaderFactory({
siteConfig: {
webpack?: DocusaurusConfig['webpack'];
future: {
experimental_faster: DocusaurusConfig['future']['experimental_faster'];
faster: DocusaurusConfig['future']['faster'];
};
};
}): Promise<ConfigureWebpackUtils['getJSLoader']> {
const currentBundler = await getCurrentBundler({siteConfig});
const isSWCLoader = siteConfig.future.experimental_faster.swcJsLoader;
const isSWCLoader = siteConfig.future.faster.swcJsLoader;
if (isSWCLoader) {
if (siteConfig.webpack?.jsLoader) {
throw new Error(
`You can't use siteConfig.webpack.jsLoader and siteConfig.future.experimental_faster.swcJsLoader at the same time.
`You can't use siteConfig.webpack.jsLoader and siteConfig.future.faster.swcJsLoader at the same time.
To avoid any configuration ambiguity, you must make an explicit choice:
- If you want to use Docusaurus Faster and SWC (recommended), remove siteConfig.webpack.jsLoader
- If you want to use a custom JS loader, use siteConfig.future.experimental_faster.swcJsLoader: false`,
- If you want to use a custom JS loader, use siteConfig.future.faster.swcJsLoader: false`,
);
}
return currentBundler.name === 'rspack'
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export default async function pluginContentBlog(
const contentDirs = getContentPathList(contentPaths);

const mdxLoaderItem = await createMDXLoaderItem({
useCrossCompilerCache:
siteConfig.future.experimental_faster.mdxCrossCompilerCache,
useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
admonitions,
remarkPlugins,
rehypePlugins,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('simple website', () => {
configureWebpackUtils: await createConfigureWebpackUtils({
siteConfig: {
webpack: {jsLoader: 'babel'},
future: {experimental_faster: fromPartial({})},
future: {faster: fromPartial({})},
},
}),
content,
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ export default async function pluginContentDocs(
}),
].filter((d): d is string => typeof d === 'string'),

useCrossCompilerCache:
siteConfig.future.experimental_faster.mdxCrossCompilerCache,
useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
admonitions: options.admonitions,
remarkPlugins,
rehypePlugins,
Expand Down
3 changes: 1 addition & 2 deletions packages/docusaurus-plugin-content-pages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ export default async function pluginContentPages(
// Trailing slash is important, see https://github.com/facebook/docusaurus/pull/3970
.map(addTrailingPathSeparator),
options: {
useCrossCompilerCache:
siteConfig.future.experimental_faster.mdxCrossCompilerCache,
useCrossCompilerCache: siteConfig.future.faster.mdxCrossCompilerCache,
admonitions,
remarkPlugins,
rehypePlugins,
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-pwa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default function pluginPWA(
minimizer: debug
? []
: await getMinimizers({
faster: props.siteConfig.future.experimental_faster,
faster: props.siteConfig.future.faster,
currentBundler: props.currentBundler,
}),
},
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-types/src/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type FutureV4Config = {
removeLegacyPostBuildHeadAttribute: boolean;
useCssCascadeLayers: boolean;
siteStorageNamespacing: boolean;
fasterByDefault: boolean;
};

// VCS (Version Control System) info about a given change, e.g., a git commit.
Expand Down Expand Up @@ -95,7 +96,7 @@ export type FutureConfig = {
*/
v4: FutureV4Config;

experimental_faster: FasterConfig;
faster: FasterConfig;

experimental_vcs: VcsConfig;

Expand Down Expand Up @@ -421,7 +422,7 @@ export type Config = Overwrite<
DeepPartial<FutureConfig>,
{
v4?: boolean | Partial<FutureV4Config>;
experimental_faster?: boolean | Partial<FasterConfig>;
faster?: boolean | Partial<FasterConfig>;
experimental_vcs?: VcsPreset | VcsConfig | boolean;
}
>;
Expand Down
93 changes: 91 additions & 2 deletions packages/docusaurus-utils/src/vcs/__tests__/gitUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
getGitAllRepoRoots,
getGitRepositoryFilesInfo,
} from '../gitUtils';
import {createVcsGitEagerConfig} from '../vcsGitEager';

class Git {
private constructor(private dir: string) {
Expand Down Expand Up @@ -156,7 +157,7 @@ class Git {
}
}

async function createTempRepoDir() {
async function createTempDir(): Promise<string> {
let repoDir = await fs.mkdtemp(
// Note, the <MKDTEMP_DIR> is useful for stabilizing Jest snapshots paths
// This way, snapshot paths don't contain random temp dir names.
Expand All @@ -168,7 +169,7 @@ async function createTempRepoDir() {
}

async function createGitRepoEmpty(): Promise<{repoDir: string; git: Git}> {
const repoDir = await createTempRepoDir();
const repoDir = await createTempDir();
const git = await Git.initializeRepo(repoDir);
return {repoDir, git};
}
Expand Down Expand Up @@ -733,3 +734,91 @@ describe('submodules APIs', () => {
});
});
});

describe('VSC strategies', () => {
async function initTestRepo() {
const superproject = await createGitRepoEmpty();
await superproject.git.commitFile('rootFile.md');

const submodule = await createGitRepoEmpty();
await submodule.git.commitFile('submoduleFile.md');
await submodule.git.commitFile('submoduleFile.md', {
commitDate: '2020-06-20',
fileContent: 'updated',
});

await superproject.git.defineSubmodules({
'submodules/submodule': submodule.repoDir,
});

return {superproject, submodule};
}

// Create the repo only once for all tests => faster tests
const repoPromise = initTestRepo();

async function initVsc() {
const repo = await repoPromise;
const repoDir = repo.superproject.repoDir;
const vcs = createVcsGitEagerConfig();
// TODO awkward siteDir -> repoDir although it works
vcs.initialize({siteDir: repoDir});
return {vcs, repoDir};
}

describe('VSC Git Eager Strategy', () => {
it('can read repo file info', async () => {
const {vcs, repoDir} = await initVsc();

const filepath = path.join(repoDir, 'rootFile.md');

await expect(vcs.getFileLastUpdateInfo(filepath)).resolves.toEqual({
author: 'Seb',
timestamp: new Date('2020-06-19').getTime(),
});
await expect(vcs.getFileCreationInfo(filepath)).resolves.toEqual({
author: 'Seb',
timestamp: new Date('2020-06-19').getTime(),
});
});

it('can read submodule file', async () => {
const {vcs, repoDir} = await initVsc();

const filepath = path.join(
repoDir,
'submodules/submodule/submoduleFile.md',
);

await expect(vcs.getFileLastUpdateInfo(filepath)).resolves.toEqual({
author: 'Seb',
timestamp: new Date('2020-06-20').getTime(),
});
await expect(vcs.getFileCreationInfo(filepath)).resolves.toEqual({
author: 'Seb',
timestamp: new Date('2020-06-19').getTime(),
});
});

describe('when site is not using git', () => {
async function initNonGitVsc() {
const repoDir = await createTempDir();
const vcs = createVcsGitEagerConfig();
vcs.initialize({siteDir: repoDir});
return {vcs, repoDir};
}

it('throws on read attempts', async () => {
const {vcs, repoDir} = await initNonGitVsc();

const filepath = path.join(repoDir, 'any.md');

await expect(vcs.getFileLastUpdateInfo(filepath)).rejects
.toThrowErrorMatchingInlineSnapshot(`
"This Docusaurus site is outside any Git worktree.
Unable to read Git info for file "<TEMP_DIR>/git-test-repo<MKDTEMP_DIR_STABLE>/any.md" "
`);
});
});
});
});
15 changes: 15 additions & 0 deletions packages/docusaurus-utils/src/vcs/gitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ export async function getGitCreation(
return getGitCommitInfo(filePath, 'oldest');
}

export async function isGitInsideWorktree(cwd: string): Promise<boolean> {
try {
const result = await execa('git', ['rev-parse', '--is-inside-work-tree'], {
cwd,
reject: false,
});
return result.exitCode === 0;
} catch (error) {
throw new Error(
`Couldn't check if this directory is within a Git worktree: ${cwd}`,
{cause: error},
);
}
}

export async function getGitRepoRoot(cwd: string): Promise<string> {
const createErrorMessageBase = () => {
return `Couldn't find the git repository root directory
Expand Down
Loading
Loading