Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(v1): fresh install failing due to <> syntax #3213

Merged
merged 1 commit into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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