From ddc0f46b733173dcbea0e58b4553bbd6505d8699 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 22 Jul 2021 15:13:57 +0100 Subject: [PATCH] fix: cli upgrade helper fail when no `package.dependencies` (#5204) * Fix handling of empty `dependencies` section. In Flipper, https://github.com/facebook/flipper/blob/master/website/package.json, all our dependencies live in `devDependecies` of our `package.json`. As a result `dependencies` is not set, causing a crash when running `yarn start`: ``` /Users/mweststrate/fbsource/xplat/sonar/website/node_modules/@docusaurus/core/bin/docusaurus.js:50 const siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies) ^ TypeError: Cannot convert undefined or null to object at Function.keys () at Object. (/Users/mweststrate/fbsource/xplat/sonar/website/node_modules/@docusaurus/core/bin/docusaurus.js:50:50) at Module._compile (internal/modules/cjs/loader.js:955:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:991:10) at Module.load (internal/modules/cjs/loader.js:811:32) at Function.Module._load (internal/modules/cjs/loader.js:723:14) at Function.Module.runMain (internal/modules/cjs/loader.js:1043:10) at internal/main/run_main_module.js:17:11 error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. ``` Setting `"dependencies": {}`, works as work around, but this patch fixes the crash, and makes sure the deps are upgraded as well if they live in `devDependencies` instead of `dependencies`. * formatting fix --- packages/docusaurus/bin/beforeCli.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/bin/beforeCli.js b/packages/docusaurus/bin/beforeCli.js index 1684ddfa4d..8992e27c9d 100644 --- a/packages/docusaurus/bin/beforeCli.js +++ b/packages/docusaurus/bin/beforeCli.js @@ -57,7 +57,10 @@ if (notifier.update && notifier.update.current !== notifier.update.latest) { // eslint-disable-next-line import/no-dynamic-require, global-require const sitePkg = require(path.resolve(process.cwd(), 'package.json')); - const siteDocusaurusPackagesForUpdate = Object.keys(sitePkg.dependencies) + const siteDocusaurusPackagesForUpdate = Object.keys({ + ...sitePkg.dependencies, + ...sitePkg.devDependencies, + }) .filter((p) => p.startsWith('@docusaurus')) .map((p) => p.concat('@latest')) .join(' ');