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

Adds auto-remove types to plugin-typescript #99

Merged
merged 4 commits into from
May 1, 2019

Conversation

deini
Copy link
Member

@deini deini commented Apr 29, 2019

@arcanis I'm trying to implement a prompt for plugin-typescript but I have a ton of questions 😂

Questions:

  1. Is there a way to have access to preferInteractive inside afterWorkspaceDependencyAddition hook? I've read in the plugin's README that ideally it should be using preferInteractive to either prompt or not (if I'm understanding it correctly).
  2. If we use preferInteractive would we expect to only add @types when prompted or would we also add them by default?
  3. Right now we always use EXACT for @types, is there a reason for that or should it be changed to CARET?
  4. The target is always REGULAR, would it make more sense to add it to DEVELOPMENT? Or match the dependencyTarget?
  5. What do you think of also hooking into afterWorkspaceDependencyRemoval and remove types?
  6. Since this is not a plugin that adds a command not sure how to go about testing it 🤔. Could I potentially setup something similar to the add tests?
  7. Will leave a few questions as PR comments.

@@ -5,7 +5,9 @@
"dependencies": {
"@berry/builder": "workspace:*",
"@berry/core": "workspace:*",
"@berry/plugin-essentials": "workspace:*"
"@berry/plugin-essentials": "workspace:*",
"@types/inquirer": "6.0.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

Should the types be here? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Types probably should be declared at the place the typeRoots configuration is set. At the moment it's at the root of the repository.

@Vlasenko's work will likely remove the need for typesRoot in the medium term, which would make it possible to store the types in each individual package.

@arcanis
Copy link
Member

arcanis commented Apr 29, 2019

  1. Is there a way to have access to preferInteractive inside afterWorkspaceDependencyAddition hook? I've read in the plugin's README that ideally it should be using preferInteractive to either prompt or not (if I'm understanding it correctly).

Yep! The Workspace class has a reference to its parent Project, which has a configuration to its parent Configuration. So it would be workspace.project.configuration.get(`preferInteractive`).

  1. If we use preferInteractive would we expect to only add @types when prompted or would we also add them by default?

I'd tend to say that we would always want to add it - it doesn't cost much to have too many @types packages, and the case of "I have a dependency in a TS project but don't want the types" must be relatively rare 🤔

  1. Right now we always use EXACT for @types, is there a reason for that or should it be changed to CARET?

iirc the @types packages don't follow semver. More details on this discussion:

yarnpkg/yarn#6695 (comment)

  1. The target is always REGULAR, would it make more sense to add it to DEVELOPMENT? Or match the dependencyTarget?

Adding them to the devDependencies makes sense! It's probably a bit overkill to match the exact target - I guess it's something that we'll have to see at usage.

  1. What do you think of also hooking into afterWorkspaceDependencyRemoval and remove types?

Sounds good to me 👍

  1. Since this is not a plugin that adds a command not sure how to go about testing it 🤔. Could I potentially setup something similar to the add tests?

Plugin tests are currently a bit weird.

  • In theory it would be nice if the tests for each individual plugin could live inside their own folders.
  • But for now it's not really possible (there isn't that much work since pkg-tests-core is a workspace, but the plumbing for the Jest config isn't trivial), so you can just create a file in acceptance-tests/pkg-tests-specs/sources/plugins (this folder doesn't exist yet), for example plugin-typescript.ts.

const target = suggestUtils.Target.DEVELOPMENT;
const typesName = getTypesName(descriptor);

const ident = structUtils.makeIdent(`types`, typesName);
Copy link
Member Author

@deini deini Apr 30, 2019

Choose a reason for hiding this comment

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

Not sure if I should use makeIdent or something like structUtils.parseIdent(typesName).

Copy link
Member

Choose a reason for hiding this comment

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

Better to use makeIdent for names you generate; parseIdent is mostly meant to be used with user input (like CLI parameters, for example).

@deini
Copy link
Member Author

deini commented Apr 30, 2019

I'm now checking preferInteractive, however, I'm not sure how to check if yarn add is running with --interactive. 🤔

@arcanis
Copy link
Member

arcanis commented Apr 30, 2019

One question I have regarding the goal of the PR - in my mind the @types packages were automatically added / removed so that the user didn't have to care about them. Doesn't adding a prompt go against this principle? In which situation will it benefit the user to say "no, I don't want to add the types for X" or "no, I don't want to remove the types for Y"?

@deini
Copy link
Member Author

deini commented Apr 30, 2019

I have the same question. I am basing the work on this comment:

This is a crude implementation so far (an ideal implementation should use preferInteractive in order to ask the user for confirmation), but it gives an idea of how hooks work. Help appreciated!

🤔 Maybe when you add something like prettier or eslint and plan to use only their cli?

@arcanis
Copy link
Member

arcanis commented Apr 30, 2019

I have the same question. I am basing the work on this comment

Well that's awkward since I wrote this line myself 😅 I probably didn't completely thought it through when I wrote it ...

However the "auto-remove" part is useful, can you update your PR to only keep this part for now? Plus we sidestep the problem with --interactive! 😄

@deini deini changed the title WIP: Adds prompt to plugin-typescript Adds auto-remove types to plugin-typescript Apr 30, 2019
Copy link
Member

@arcanis arcanis left a comment

Choose a reason for hiding this comment

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

Sounds good! I'll merge it as it is, feel free to followup on the stringifyIdent thing whenever you like (if you can add a test or two it would also be awesome 😃).

import {Hooks as EssentialsHooks} from '@berry/plugin-essentials';
import {suggestUtils} from '@berry/plugin-essentials';

const getDependencyName = (descriptor: Descriptor) => {
Copy link
Member

Choose a reason for hiding this comment

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

Technically this probably should be structUtils.stringifyIdent

@arcanis arcanis merged commit 6632a03 into yarnpkg:master May 1, 2019
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.

2 participants