Skip to content

Commit

Permalink
fix: use realpath for site dir to resolve symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Oct 10, 2021
1 parent 6636210 commit ce243de
Showing 1 changed file with 28 additions and 34 deletions.
62 changes: 28 additions & 34 deletions packages/docusaurus/bin/docusaurus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

const chalk = require('chalk');
const path = require('path');
const fs = require('fs');
const cli = require('commander');
const {
build,
Expand All @@ -23,6 +23,8 @@ const {

require('./beforeCli');

const resolveDir = (dir = '.') => fs.realpathSync(dir);

cli.version(require('../package.json').version).usage('<command> [options]');

cli
Expand All @@ -48,8 +50,8 @@ cli
'--no-minify',
'build website without minimizing JS bundles (default: false)',
)
.action((siteDir = '.', {bundleAnalyzer, config, outDir, locale, minify}) => {
build(path.resolve(siteDir), {
.action((siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => {
build(resolveDir(siteDir), {
bundleAnalyzer,
outDir,
config,
Expand All @@ -66,14 +68,8 @@ cli
'copy TypeScript theme files when possible (default: false)',
)
.option('--danger', 'enable swizzle for internal component of themes')
.action((themeName, componentName, siteDir = '.', {typescript, danger}) => {
swizzle(
path.resolve(siteDir),
themeName,
componentName,
typescript,
danger,
);
.action((themeName, componentName, siteDir, {typescript, danger}) => {
swizzle(resolveDir(siteDir), themeName, componentName, typescript, danger);
});

cli
Expand All @@ -95,8 +91,8 @@ cli
'--skip-build',
'skip building website before deploy it (default: false)',
)
.action((siteDir = '.', {outDir, skipBuild, config}) => {
deploy(path.resolve(siteDir), {
.action((siteDir, {outDir, skipBuild, config}) => {
deploy(resolveDir(siteDir), {
outDir,
config,
skipBuild,
Expand All @@ -122,19 +118,17 @@ cli
'--poll [interval]',
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
)
.action(
(siteDir = '.', {port, host, locale, config, hotOnly, open, poll}) => {
start(path.resolve(siteDir), {
port,
host,
locale,
config,
hotOnly,
open,
poll,
});
},
);
.action((siteDir, {port, host, locale, config, hotOnly, open, poll}) => {
start(resolveDir(siteDir), {
port,
host,
locale,
config,
hotOnly,
open,
poll,
});
});

cli
.command('serve [siteDir]')
Expand All @@ -152,7 +146,7 @@ cli
.option('-h, --host <host>', 'use specified host (default: localhost)')
.action(
(
siteDir = '.',
siteDir,
{
dir = 'build',
port = 3000,
Expand All @@ -161,7 +155,7 @@ cli
config,
},
) => {
serve(path.resolve(siteDir), {
serve(resolveDir(siteDir), {
dir,
port,
build: buildSite,
Expand All @@ -174,8 +168,8 @@ cli
cli
.command('clear [siteDir]')
.description('Remove build artifacts.')
.action((siteDir = '.') => {
clear(path.resolve(siteDir));
.action((siteDir) => {
clear(resolveDir(siteDir));
});

cli
Expand All @@ -199,10 +193,10 @@ cli
)
.action(
(
siteDir = '.',
siteDir,
{locale = undefined, override = false, messagePrefix = '', config},
) => {
writeTranslations(path.resolve(siteDir), {
writeTranslations(resolveDir(siteDir), {
locale,
override,
config,
Expand All @@ -214,7 +208,7 @@ cli
cli
.command('write-heading-ids [contentDir]')
.description('Generate heading ids in Markdown content.')
.action((siteDir = '.') => {
.action((siteDir) => {
writeHeadingIds(siteDir);
});

Expand All @@ -239,7 +233,7 @@ function isInternalCommand(command) {

async function run() {
if (!isInternalCommand(process.argv.slice(2)[0])) {
await externalCommand(cli, path.resolve('.'));
await externalCommand(cli, resolveDir('.'));
}

cli.parse(process.argv);
Expand Down

0 comments on commit ce243de

Please sign in to comment.