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(deps): drop a few unnecessary dependencies (#643) #654

Merged
merged 10 commits into from
Aug 14, 2020
Merged

Conversation

Anber
Copy link
Collaborator

@Anber Anber commented Aug 11, 2020

Motivation

We have some dependencies which we don't really use or can avoid using: webpack, @babel/core, etc.
Another problem here, that Linaria babel plugin uses an external version of babel instead of a version which launches the plugin, that can probably cause some tricky errors.

Summary

Despite the fact that PR touches a lot of files, the most changes are just type annotations for imports and linted files (update of eslint was required for supporting type). The real change here is passing babel through call stacks in the plugin, but it doesn't affect the logic.
There are also three minor fixes:

  • src/babel/extract.ts — better typings for expressionsToEvaluate and originalLazyExpressions;
  • src/babel/visitors/CollectDependencies.ts — fix for a bug with hoisting in different versions of babel;
  • src/babel/visitors/GenerateClassNames.ts — small typings improve.

Results:

  • webpack has gone;
  • @babel/traverse and @babel/register have gone;
  • @babel/core has been moved to peerDependecies.

Test plan

Since the logic wasn't affected, all existed tests are still working.

return (
literal: TemplateStringsArray,
...placeholders: string[]
): [string, Map<string, string[]>] => {
const code = dedent(literal, ...placeholders);
const [shaken, deps] = shake(
babel,
Copy link
Member

Choose a reason for hiding this comment

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

what's the benefit of injecting Babel here? I don't think we'll inject various versions of Babel and it stays as dependency, but peer. I think we should be fine by leaving these functions as they were – dependent on @babel/core. This would shrink the diff quite a bit :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hm… We don't touch the original AST in evaluators, so it's probably safe to use imported babel here. I'll take a close look.

package.json Show resolved Hide resolved
@@ -174,6 +174,7 @@ Sometimes it can be useful to implement your own strategy (it can be just a mock

```typescript
type Evaluator = (
babel: BabelCore,
Copy link
Member

Choose a reason for hiding this comment

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

no need for this change imho, as stated somewhere earlier

Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the last thing to revert now :)

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Cool move! Don't forget about mentioning @babel/core as peer dependency in the readme

@Anber Anber changed the title Drop a few unnecessary dependencies (#643) fix(deps:) drop a few unnecessary dependencies (#643) Aug 11, 2020
@Anber Anber changed the title fix(deps:) drop a few unnecessary dependencies (#643) fix(deps): drop a few unnecessary dependencies (#643) Aug 11, 2020
@callstack-bot
Copy link

callstack-bot commented Aug 11, 2020

Hey @Anber, thank you for your pull request 🤗.
The coverage report for this branch can be viewed here.

@wereHamster
Copy link
Contributor

Why do we need type-only imports?

https://twitter.com/drosenwasser/status/1218253612746301440

@Anber
Copy link
Collaborator Author

Anber commented Aug 12, 2020

@wereHamster mostly because of linter: eslint doesn't complain about type-only imports if dependencies aren't specified in package.json. Another reason is improved readability, that helps to manage dependencies.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -174,6 +174,7 @@ Sometimes it can be useful to implement your own strategy (it can be just a mock

```typescript
type Evaluator = (
babel: BabelCore,
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this is the last thing to revert now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants