Skip to content

Commit

Permalink
fix(core): normalize input for poll option
Browse files Browse the repository at this point in the history
This change normalizes input for the poll option to either a boolean or number to meet the specs required by Webpack config

fixes facebook#8306
  • Loading branch information
mhnaeem committed Nov 15, 2022
1 parent d8c72fb commit 89471c3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/docusaurus/bin/docusaurus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
writeTranslations,
writeHeadingIds,
} from '../lib/index.js';
import {normalizePollValue} from './utils.mjs';
import beforeCli from './beforeCli.mjs';

await beforeCli();
Expand Down Expand Up @@ -122,6 +123,7 @@ cli
.option(
'--poll [interval]',
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
normalizePollValue,
)
.option(
'--no-minify',
Expand Down
24 changes: 24 additions & 0 deletions packages/docusaurus/bin/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.
*/

/**
*
* @param {string} value
* @returns {boolean|number}
*/
export function normalizePollValue(value) {
if (value === undefined || value === '') {
return false;
}

const parsedIntValue = Number.parseInt(value, 10);
if (!Number.isNaN(parsedIntValue)) {
return parsedIntValue;
}

return value === 'true';
}

0 comments on commit 89471c3

Please sign in to comment.