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

Refactor: executable script consistency #5890

Merged
merged 23 commits into from
May 17, 2022

Conversation

queengooborg
Copy link
Collaborator

@queengooborg queengooborg commented Mar 27, 2020

This PR is a subset of #5654 and #5655 (and partially from #5626 (comment)). Throughout our scripts, we have a mix of scripts designed to be executable on their own or to be imported into other scripts. Unfortunately, we haven't been consistent about using require.main === module to state execution intent. This PR performs the following:

  1. Remove executability from files not intended to be run on their own
  2. Add a require.main === module if-clause to make all executable scripts importable

@ghost ghost added bulk_update 📦 An update to a mass amount of data, or scripts/linters related to such changes linter 🏡 Issues or pull requests regarding the tests / linter of the JSON files. scripts 📜 Issues or pull requests regarding the scripts in scripts/. labels Mar 27, 2020
@queengooborg queengooborg changed the title Refactor: only include env on executable scripts and use strict on all Refactor: executable script consistency + use strict Mar 27, 2020
@queengooborg queengooborg mentioned this pull request Mar 27, 2020
23 tasks
@ddbeck ddbeck removed their request for review September 8, 2020 14:12
@ddbeck ddbeck removed their request for review December 17, 2020 16:23
@queengooborg queengooborg removed the request for review from Elchi3 February 13, 2021 01:47
Base automatically changed from master to main March 24, 2021 12:54
@foolip
Copy link
Collaborator

foolip commented Apr 19, 2022

I think we can simplify further and remove the shebangs everywhere. Shebangs are needed when a file is executed directly, like ./index.js, but that's only possible (on UNIX) when the executable bit is set. None of the files in BCD have the executable bit set, so nobody can be depending on being able to execute any files directly.

When doing something like node index.js the shebang seems to be parsed and ignored, something like #!/use/bin/env python "works" just fine.

index.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@foolip foolip left a comment

Choose a reason for hiding this comment

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

Hmm, so going deeper into review I see there are a bunch of things being changed here. How about breaking out the simple "make file headers consistent" bits separately, and doing the other things as separate PRs that explain in more what's being changed and why?

@@ -53,52 +53,4 @@ const fixBrowserOrder = filename => {
}
};

if (require.main === module) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's going on with this removal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file isn't really intended to be run on its own, so that's why I've removed this clause.

@queengooborg queengooborg marked this pull request as draft April 20, 2022 17:47
@queengooborg
Copy link
Collaborator Author

Sounds good -- I've marked this PR as a draft to use as a breakdown PR. I'll make individual changes in other PRs!

@github-actions
Copy link

github-actions bot commented May 3, 2022

This pull request has merge conflicts that must be resolved before we can merge this.

@github-actions
Copy link

This pull request has merge conflicts that must be resolved before we can merge this.

@queengooborg queengooborg marked this pull request as ready for review May 14, 2022 03:13
@queengooborg queengooborg changed the title Refactor: executable script consistency + use strict Refactor: executable script consistency May 14, 2022
@queengooborg
Copy link
Collaborator Author

This PR now has a small enough scope that it can be reviewed and merged on its own, so I've updated the description and title to match the scope of this PR!

Copy link
Contributor

@caugner caugner left a comment

Choose a reason for hiding this comment

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

LGTM, can be merged as is, I just have one question:

tests.forEach(({ features, matches, misses }) => {
features.forEach((feature) => testToken(lookup(feature), matches, misses));
});
module.exports = testRegexes;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this script not have an if (require.main === module) { block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This script isn't supposed to be run on its own, but rather as a Mocha unittest. It was never actually hooked up though, and I'm not too worried about hooking it up now since it's going to be removed in #15781!

@queengooborg queengooborg merged commit c04cd95 into mdn:main May 17, 2022
@queengooborg queengooborg deleted the refactor/shbang-and-use-strict branch May 17, 2022 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bulk_update 📦 An update to a mass amount of data, or scripts/linters related to such changes linter 🏡 Issues or pull requests regarding the tests / linter of the JSON files. scripts 📜 Issues or pull requests regarding the scripts in scripts/.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants