Skip to content

Commit

Permalink
refactor(core): improve dev perf, fine-grained site reloads - part1 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored Mar 8, 2024
1 parent eb6424c commit d02b96f
Show file tree
Hide file tree
Showing 45 changed files with 2,100 additions and 1,332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import {jest} from '@jest/globals';
import path from 'path';
import {loadContext} from '@docusaurus/core/src/server/index';
import {loadContext} from '@docusaurus/core/src/server/site';
import {createSlugger, posixPath, DEFAULT_PLUGIN_ID} from '@docusaurus/utils';
import {createSidebarsUtils} from '../sidebars/utils';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import _ from 'lodash';
import {isMatch} from 'picomatch';
import commander from 'commander';
import webpack from 'webpack';
import {loadContext} from '@docusaurus/core/src/server/index';
import {loadContext} from '@docusaurus/core/src/server/site';
import {applyConfigureWebpack} from '@docusaurus/core/src/webpack/utils';
import {sortConfig} from '@docusaurus/core/src/server/plugins/routeConfig';
import {sortRoutes} from '@docusaurus/core/src/server/plugins/routeConfig';
import {posixPath} from '@docusaurus/utils';
import {normalizePluginOptions} from '@docusaurus/utils-validation';

Expand Down Expand Up @@ -109,7 +109,7 @@ Entries created:
expectSnapshot: () => {
// Sort the route config like in src/server/plugins/index.ts for
// consistent snapshot ordering
sortConfig(routeConfigs);
sortRoutes(routeConfigs);
expect(routeConfigs).not.toEqual([]);
expect(routeConfigs).toMatchSnapshot('route config');
expect(dataContainer).toMatchSnapshot('data');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import path from 'path';
import {loadContext} from '@docusaurus/core/lib/server';
import {loadContext} from '@docusaurus/core/src/server/site';
import {normalizePluginOptions} from '@docusaurus/utils-validation';

import pluginContentPages from '../index';
Expand Down
9 changes: 9 additions & 0 deletions packages/docusaurus-types/src/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ export type Plugin<Content = unknown> = {
}) => ThemeConfig;
};

/**
* Data required to uniquely identify a plugin
* The name or instance id alone is not enough
*/
export type PluginIdentifier = {
readonly name: string;
readonly id: string;
};

export type InitializedPlugin = Plugin & {
readonly options: Required<PluginOptions>;
readonly version: PluginVersionInformation;
Expand Down
8 changes: 4 additions & 4 deletions packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path from 'path';
import _ from 'lodash';
import logger from '@docusaurus/logger';
import {DOCUSAURUS_VERSION, mapAsyncSequential} from '@docusaurus/utils';
import {load, loadContext, type LoadContextOptions} from '../server';
import {loadSite, loadContext, type LoadContextParams} from '../server/site';
import {handleBrokenLinks} from '../server/brokenLinks';

import {createBuildClientConfig} from '../webpack/client';
Expand All @@ -32,7 +32,7 @@ import type {LoadedPlugin, Props} from '@docusaurus/types';
import type {SiteCollectedData} from '../common';

export type BuildCLIOptions = Pick<
LoadContextOptions,
LoadContextParams,
'config' | 'locale' | 'outDir'
> & {
bundleAnalyzer?: boolean;
Expand Down Expand Up @@ -161,7 +161,7 @@ async function buildLocale({
logger.info`name=${`[${locale}]`} Creating an optimized production build...`;

PerfLogger.start('Loading site');
const props: Props = await load({
const site = await loadSite({
siteDir,
outDir: cliOptions.outDir,
config: cliOptions.config,
Expand All @@ -170,7 +170,7 @@ async function buildLocale({
});
PerfLogger.end('Loading site');

// Apply user webpack config.
const {props} = site;
const {outDir, plugins} = props;

// We can build the 2 configs in parallel
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import os from 'os';
import logger from '@docusaurus/logger';
import shell from 'shelljs';
import {hasSSHProtocol, buildSshUrl, buildHttpsUrl} from '@docusaurus/utils';
import {loadContext, type LoadContextOptions} from '../server';
import {loadContext, type LoadContextParams} from '../server/site';
import {build} from './build';

export type DeployCLIOptions = Pick<
LoadContextOptions,
LoadContextParams,
'config' | 'locale' | 'outDir'
> & {
skipBuild?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/src/commands/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import fs from 'fs-extra';
import {loadContext} from '../server';
import {loadContext} from '../server/site';
import {initPlugins} from '../server/plugins/init';
import type {CommanderStatic} from 'commander';

Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import openBrowser from 'react-dev-utils/openBrowser';
import {loadSiteConfig} from '../server/config';
import {build} from './build';
import {getHostPort, type HostPortOptions} from '../server/getHostPort';
import type {LoadContextOptions} from '../server';
import type {LoadContextParams} from '../server/site';

export type ServeCLIOptions = HostPortOptions &
Pick<LoadContextOptions, 'config'> & {
Pick<LoadContextParams, 'config'> & {
dir?: string;
build?: boolean;
open?: boolean;
Expand Down
Loading

0 comments on commit d02b96f

Please sign in to comment.