Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v2): docusaurus start --poll 500 should work + better config load failure error #3622

Merged
merged 5 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export type HostPortCLIOptions = {
export type StartCLIOptions = HostPortCLIOptions & {
hotOnly: boolean;
open: boolean;
poll: boolean;
poll: boolean | number;
};

export type ServeCLIOptions = HostPortCLIOptions & {
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus/bin/docusaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ cli
)
.option('--no-open', 'Do not open page in the browser (default: false)')
.option(
'--poll',
'Use polling rather than watching for reload (default: false)',
'--poll [interval]',
'Use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds.',
)
.action((siteDir = '.', {port, host, hotOnly, open, poll}) => {
wrapCommand(start)(path.resolve(siteDir), {
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus/src/commands/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,16 @@ export default async function start(
.filter(Boolean),
)
.map(normalizeToSiteDir);

const fsWatcher = chokidar.watch([...pluginPaths, CONFIG_FILE_NAME], {
cwd: siteDir,
ignoreInitial: true,
usePolling: !!cliOptions.poll,
interval: Number.isInteger(cliOptions.poll)
? (cliOptions.poll as number)
: undefined,
});

['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) =>
fsWatcher.on(event, reload),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`loadConfig website with incomplete siteConfig 1`] = `
"
`;

exports[`loadConfig website with no siteConfig 1`] = `"docusaurus.config.js not found"`;
exports[`loadConfig website with no siteConfig 1`] = `"docusaurus.config.js not found at packages/docusaurus/src/server/__tests__/__fixtures__/nonExisting/docusaurus.config.js"`;

exports[`loadConfig website with useless field (wrong field) in siteConfig 1`] = `
"\\"favicon\\" is required
Expand Down
7 changes: 6 additions & 1 deletion packages/docusaurus/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export default function loadConfig(siteDir: string): DocusaurusConfig {
const configPath = path.resolve(siteDir, loadedConfigFileName);

if (!fs.existsSync(configPath)) {
throw new Error(`${CONFIG_FILE_NAME} not found`);
throw new Error(
`${CONFIG_FILE_NAME} not found at ${path.relative(
process.cwd(),
configPath,
)}`,
);
}

const loadedConfig = importFresh(configPath) as Partial<DocusaurusConfig>;
Expand Down