-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
import {Cache, Descriptor, Plugin, Workspace} from '@berry/core'; | ||
import {httpUtils, structUtils} from '@berry/core'; | ||
import {structUtils} from '@berry/core'; | ||
import {Hooks as EssentialsHooks} from '@berry/plugin-essentials'; | ||
import {suggestUtils} from '@berry/plugin-essentials'; | ||
|
||
const getDependencyName = (descriptor: Descriptor) => { | ||
return descriptor.scope | ||
? `@${descriptor.scope}/${descriptor.name}` | ||
: descriptor.name; | ||
}; | ||
|
||
const getTypesName = (descriptor: Descriptor) => { | ||
return descriptor.scope | ||
? `${descriptor.scope}__${descriptor.name}` | ||
: `${descriptor.name}`; | ||
}; | ||
|
||
const afterWorkspaceDependencyAddition = async ( | ||
workspace: Workspace, | ||
dependencyTarget: suggestUtils.Target, | ||
|
@@ -14,12 +26,9 @@ const afterWorkspaceDependencyAddition = async ( | |
const project = workspace.project; | ||
const configuration = project.configuration; | ||
const cache = await Cache.find(configuration); | ||
const typesName = getTypesName(descriptor); | ||
|
||
const typesName = descriptor.scope | ||
? `${descriptor.scope}__${descriptor.name}` | ||
: `${descriptor.name}`; | ||
|
||
const target = suggestUtils.Target.REGULAR; | ||
const target = suggestUtils.Target.DEVELOPMENT; | ||
const modifier = suggestUtils.Modifier.EXACT; | ||
const strategies = [suggestUtils.Strategy.LATEST]; | ||
|
||
|
@@ -40,9 +49,30 @@ const afterWorkspaceDependencyAddition = async ( | |
); | ||
}; | ||
|
||
const afterWorkspaceDependencyRemoval = async ( | ||
workspace: Workspace, | ||
dependencyTarget: suggestUtils.Target, | ||
descriptor: Descriptor, | ||
) => { | ||
if (descriptor.scope === `types`) | ||
return; | ||
|
||
const target = suggestUtils.Target.DEVELOPMENT; | ||
const typesName = getTypesName(descriptor); | ||
|
||
const ident = structUtils.makeIdent(`types`, typesName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use |
||
const current = workspace.manifest[target].get(ident.identHash); | ||
|
||
if (typeof current === `undefined`) | ||
return; | ||
|
||
workspace.manifest[target].delete(ident.identHash); | ||
}; | ||
|
||
const plugin: Plugin = { | ||
hooks: { | ||
afterWorkspaceDependencyAddition, | ||
afterWorkspaceDependencyRemoval, | ||
} as ( | ||
EssentialsHooks | ||
), | ||
|
There was a problem hiding this comment.
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