MCPcopy
hub / github.com/angular/angular-cli / removeDependency

Function removeDependency

packages/schematics/angular/utility/dependency.ts:237–284  ·  view source on GitHub ↗
(
  name: string,
  options: {
    /**
     * The path of the package manifest file (`package.json`) that will be modified.
     * Defaults to `/package.json`.
     */
    packageJsonPath?: string;

    /**
     * The dependency installation behavior to use to determine whether a
     * {@link NodePackageInstallTask} should be scheduled after removing the dependency.
     * Defaults to {@link InstallBehavior.Auto}.
     */
    install?: InstallBehavior;
  } = {},
)

Source from the content-addressed store, hash-verified

235 * @returns A Schematics {@link Rule}
236 */
237export function removeDependency(
238 name: string,
239 options: {
240 /**
241 * The path of the package manifest file (`package.json`) that will be modified.
242 * Defaults to `/package.json`.
243 */
244 packageJsonPath?: string;
245
246 /**
247 * The dependency installation behavior to use to determine whether a
248 * {@link NodePackageInstallTask} should be scheduled after removing the dependency.
249 * Defaults to {@link InstallBehavior.Auto}.
250 */
251 install?: InstallBehavior;
252 } = {},
253): Rule {
254 const { packageJsonPath = '/package.json', install = InstallBehavior.Auto } = options;
255
256 return (tree, context) => {
257 const manifest = tree.readJson(packageJsonPath) as MinimalPackageManifest;
258 let wasRemoved = false;
259
260 for (const type of [DependencyType.Default, DependencyType.Dev, DependencyType.Peer]) {
261 const dependencySection = manifest[type];
262 if (dependencySection?.[name]) {
263 delete dependencySection[name];
264 wasRemoved = true;
265 }
266 }
267
268 if (wasRemoved) {
269 tree.overwrite(packageJsonPath, JSON.stringify(manifest, null, 2));
270
271 const installPaths = installTasks.get(context) ?? new Set<string>();
272 if (
273 install === InstallBehavior.Always ||
274 (install === InstallBehavior.Auto && !installPaths.has(packageJsonPath))
275 ) {
276 context.addTask(
277 new NodePackageInstallTask({ workingDirectory: path.dirname(packageJsonPath) }),
278 );
279 installPaths.add(packageJsonPath);
280 installTasks.set(context, installPaths);
281 }
282 }
283 };
284}

Callers 2

dependency_spec.tsFile · 0.90
updateProjectsFunction · 0.90

Calls 7

readJsonMethod · 0.65
overwriteMethod · 0.65
getMethod · 0.65
hasMethod · 0.65
addTaskMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected