Skip to content

Commit 77e1adc

Browse files
clydinalan-agius4
authored andcommitted
refactor(@schematics/angular): remove manual install task in library schematic
Removes the manual `NodePackageInstallTask` from the library schematic. The responsibility for scheduling the installation is now delegated to the `addDependency` utility by passing the correct `InstallBehavior`. This makes the schematic cleaner and more consistent with the `application` schematic.
1 parent 9723844 commit 77e1adc

File tree

1 file changed

+5
-9
lines changed
  • packages/schematics/angular/library

1 file changed

+5
-9
lines changed

packages/schematics/angular/library/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {
1010
Rule,
11-
SchematicContext,
1211
Tree,
1312
apply,
1413
applyTemplates,
@@ -20,11 +19,11 @@ import {
2019
strings,
2120
url,
2221
} from '@angular-devkit/schematics';
23-
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
2422
import { join } from 'node:path/posix';
2523
import {
2624
DependencyType,
2725
ExistingBehavior,
26+
InstallBehavior,
2827
addDependency,
2928
getDependency,
3029
} from '../utility/dependency';
@@ -70,17 +69,19 @@ function addTsProjectReference(...paths: string[]) {
7069
};
7170
}
7271

73-
function addDependenciesToPackageJson(): Rule {
72+
function addDependenciesToPackageJson(skipInstall: boolean): Rule {
7473
return chain([
7574
...LIBRARY_DEV_DEPENDENCIES.map((dependency) =>
7675
addDependency(dependency.name, dependency.version, {
7776
type: DependencyType.Dev,
7877
existing: ExistingBehavior.Skip,
78+
install: skipInstall ? InstallBehavior.None : InstallBehavior.Auto,
7979
}),
8080
),
8181
addDependency('tslib', latestVersions['tslib'], {
8282
type: DependencyType.Default,
8383
existing: ExistingBehavior.Skip,
84+
install: skipInstall ? InstallBehavior.None : InstallBehavior.Auto,
8485
}),
8586
]);
8687
}
@@ -171,7 +172,7 @@ export default function (options: LibraryOptions): Rule {
171172
return chain([
172173
mergeWith(templateSource),
173174
addLibToWorkspaceFile(options, libDir, packageName, hasZoneDependency),
174-
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
175+
options.skipPackageJson ? noop() : addDependenciesToPackageJson(!!options.skipInstall),
175176
options.skipTsConfig ? noop() : updateTsConfig(packageName, './' + distRoot),
176177
options.skipTsConfig
177178
? noop()
@@ -203,11 +204,6 @@ export default function (options: LibraryOptions): Rule {
203204
// inherits its `type` from the workspace.
204205
type: '',
205206
}),
206-
(_tree: Tree, context: SchematicContext) => {
207-
if (!options.skipPackageJson && !options.skipInstall) {
208-
context.addTask(new NodePackageInstallTask());
209-
}
210-
},
211207
]);
212208
};
213209
}

0 commit comments

Comments
 (0)