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

Testing: Add lint for Babel runtime dependency in transpiled packages #14373

Open
aduth opened this issue Mar 11, 2019 · 1 comment
Open

Testing: Add lint for Babel runtime dependency in transpiled packages #14373

aduth opened this issue Mar 11, 2019 · 1 comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@aduth
Copy link
Member

aduth commented Mar 11, 2019

Each package transpiled using Babel is configured to apply the Babel runtime transform (source). Thus, the built output for any package is expected to contain references to the @babel/runtime module. For this reason, the package must explicitly define @babel/runtime as a dependency.

For any package which is transpiled using Babel, we should lint to ensure it also includes an explicit dependency on @babel/runtime.

Implementation:

  • A package can be determined as being subject to transpilation if its package.json includes a main reference to a build/ relative path.
    • Technically speaking, any package will be transpiled with Babel if it includes a src/ directory (source), but the main reference is a better indication that it's actually used (related)
  • I expect the best option for linting would be a rule from npm-package-json-lint requiring a specific dependency to be present, and for each exception package (the minority of cases), a package-specific .npmpackagejsonlintrc.json configuration override should disable the lint rule.
    • The lint rule should be applied only in the Gutenberg-specific configuration, not in @wordpress/npm-package-json-lint-config
    • As best I can tell, however, there is no rule present which covers this case. require-dependencies only requires that the dependencies block be present, and no-restricted-dependencies is the inverse of what we need. We may need to consider contributing an upstream enhancement.

cc @greatislander in case it's of interest to you, as you'd done similarly in the past for #13947 with an upstream enhancement at tclindner/npm-package-json-lint#106 .

@aduth aduth added [Type] Task Issues or PRs that have been broken down into an individual action to take [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Mar 11, 2019
@gziolo
Copy link
Member

gziolo commented Mar 11, 2019

Technically speaking, any package will be transpiled with Babel if it includes a src/ directory (source), but the main reference is a better indication that it's actually used (related)

We also add module field in package.json file for every transpiled package which webpack uses to take advantage for optimization techniques based on import/export syntax.

We could take advantage of it and change the script which performs transpilation based on the presence of this field rather than to depend on src folder which as it turns out might be added without the goal of having code transpiled.

@gziolo gziolo added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Apr 2, 2019
@gziolo gziolo added the Needs Dev Ready for, and needs developer efforts label Apr 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue An issue that's suitable for someone looking to contribute for the first time Needs Dev Ready for, and needs developer efforts [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

2 participants