Skip to content

Commit

Permalink
fix(v1): fresh install failing due to <> syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 5, 2020
1 parent 8f0c00f commit 83d160f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-1.x/.eslintrc.js
Expand Up @@ -28,6 +28,7 @@ module.exports = {
'no-plusplus': OFF,
'prefer-template': OFF,
'import/no-extraneous-dependencies': OFF,
'react/jsx-fragments': OFF, // Babylon v6 does not support <> fragments
'react/jsx-closing-bracket-location': OFF, // Formatting is left to Prettier.
'react/jsx-filename-extension': OFF, // Enable in future when migrating.
'react/jsx-one-expression-per-line': OFF, // Formatting is left to Prettier.
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-1.x/examples/basics/pages/en/users.js
Expand Up @@ -34,14 +34,14 @@ class Users extends React.Component {
</div>
<div className="logos">{showcase}</div>
{siteConfig.repoUrl && (
<>
<React.Fragment>
<p>Are you using this project?</p>
<a
href={`${siteConfig.repoUrl}/edit/master/website/siteConfig.js`}
className="button">
Add your company
</a>
</>
</React.Fragment>
)}
</div>
</Container>
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-1.x/lib/start-server.js
Expand Up @@ -49,6 +49,6 @@ program
.parse(process.argv);

startDocusaurus().catch((ex) => {
console.error(chalk.red(`Failed to start Docusaurus server: ${ex}`));
console.error(chalk.red(ex && ex.stack ? ex.stack : ex));
process.exit(1);
});
15 changes: 12 additions & 3 deletions packages/docusaurus-1.x/lib/write-translations.js
Expand Up @@ -55,6 +55,17 @@ if (fs.existsSync(`${CWD}/data/custom-translation-strings.json`)) {
);
}

function parseJSXFile(file) {
try {
return babylon.parse(fs.readFileSync(file, 'utf8'), {
plugins: ['jsx'],
});
} catch (e) {
throw new Error(`Babylon parsing failure for file=${file}: ${e.message}
\nNote: Docusaurus v1 currently uses Babylon v6, and <> fragment syntax is not supported`);
}
}

function writeFileAndCreateFolder(file, content) {
mkdirp.sync(file.replace(new RegExp('/[^/]*$'), ''));
fs.writeFileSync(file, content);
Expand Down Expand Up @@ -151,9 +162,7 @@ function execute() {
glob.sync(`${CWD}/pages/en/**`).forEach((file) => {
const extension = nodePath.extname(file);
if (extension === '.js') {
const ast = babylon.parse(fs.readFileSync(file, 'utf8'), {
plugins: ['jsx'],
});
const ast = parseJSXFile(file);
traverse(ast, {
enter(path) {
if (
Expand Down

0 comments on commit 83d160f

Please sign in to comment.