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

misc: convert all internal scripts to ESM #6286

Merged
merged 11 commits into from
Jan 8, 2022
Merged

misc: convert all internal scripts to ESM #6286

merged 11 commits into from
Jan 8, 2022

Conversation

Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Jan 7, 2022

Motivation

ESM looks nicer. Also allows top-level await. Also a POC that the docusaurus.config.js file now supports dynamically importing ES module dependencies.

Seems Jest can't ergonomically import ESM yet, so the theme-translations/update.js was not converted.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Ran the scripts locally.

@Josh-Cena Josh-Cena added the pr: maintenance This PR does not produce any behavior differences to end users when upgrading. label Jan 7, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 7, 2022
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

Size Change: 0 B

Total Size: 676 kB

ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 41.6 kB
website/build/assets/css/styles.********.css 102 kB
website/build/assets/js/main.********.js 502 kB
website/build/index.html 29.6 kB

compressed-size-action

Comment on lines -64 to -73
run().then(
() => {
process.exit(0);
},
(e) => {
console.error(e.message);
console.error(e.stack);
process.exit(1);
},
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: review with hide whitespace

@netlify
Copy link

netlify bot commented Jan 7, 2022

✔️ [V2]

🔨 Explore the source changes: 25825cc

🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/61d912fe7dbb360007183460

😎 Browse the preview: https://deploy-preview-6286--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jan 7, 2022

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 83
🟢 Accessibility 98
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-6286--docusaurus-2.netlify.app/

@Josh-Cena Josh-Cena merged commit 4fad1ce into main Jan 8, 2022
@Josh-Cena Josh-Cena deleted the jc/mjs-script branch January 8, 2022 04:59
await new Promise((resolve) => {
setTimeout(resolve, 0);
});
const FeatureRequestsPlugin = (await import('./src/featureRequests/FeatureRequestsPlugin.mjs')).default;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤪 IMHO this looks weird, we should just use createConfig now and put everything inside the function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, but that creates too much indentation changes... I'd rather use this with the return of less indentation for our massive config object

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use this with the return of less indentation for our massive config object

I don't understand what you mean here

Do you see this as a temporary step?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I view this as a long term solution.

const config = {
  foo: bar, // two spaces of indentation
};
async function createConfig() {
  return {
    foo: bar, // four spaces of indentation
  };
}

I'd like to avoid that extra level of indentation at all costs

Copy link
Collaborator

@slorber slorber Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd 1000% prefer to have an extra indentation than to have this in the long term (which we currently have):

const config = {
  foo: bar, // two spaces of indentation
};

async function createConfig() 
  config.xyz = await abc();
  return config;
}

module.exports = createConfig;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, I'm not sure if we are to add more async items in the future. We'll see...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep it for now, I'll figure out a way to clean this up later

@Josh-Cena Josh-Cena mentioned this pull request Jan 31, 2022
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: maintenance This PR does not produce any behavior differences to end users when upgrading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants