diff --git a/CHANGELOG-2.x.md b/CHANGELOG-2.x.md index 5700b740b7..04e843d69e 100644 --- a/CHANGELOG-2.x.md +++ b/CHANGELOG-2.x.md @@ -5,6 +5,7 @@ - Fix `keywords` frontmatter for SEO not working properly. - Fix `swizzle` command not passing context properly to theme packages. - Add `extendCli` api for plugins. This will allow plugin to further extend Docusaurus CLI. +- Fix `swizzle` command not being able to swizzle single js file. ## 2.0.0-alpha.27 diff --git a/packages/docusaurus/src/commands/swizzle.ts b/packages/docusaurus/src/commands/swizzle.ts index 0a08b62d57..556aee920d 100644 --- a/packages/docusaurus/src/commands/swizzle.ts +++ b/packages/docusaurus/src/commands/swizzle.ts @@ -28,12 +28,18 @@ export async function swizzle( if (componentName) { fromPath = path.join(fromPath, componentName); toPath = path.join(toPath, componentName); + + // Handle single js file only. + // E.g: if does not exist, we try to swizzle .js instead + if (!fs.existsSync(fromPath) && fs.existsSync(`${fromPath}.js`)) { + [fromPath, toPath] = [`${fromPath}.js`, `${toPath}.js`]; + } } await fs.copy(fromPath, toPath); const relativeDir = path.relative(process.cwd(), toPath); const fromMsg = chalk.blue( - componentName ? `${themeName}/${componentName}` : themeName, + componentName ? `${themeName} ${chalk.yellow(componentName)}` : themeName, ); const toMsg = chalk.cyan(relativeDir); console.log(