Skip to content

Commit ccd7e71

Browse files
committed
refactor(@schematics/angular): minor cleanup of unneeded @angular-devkit/core imports
Several imported types and values from `@angular-devkit/core` could be removed while still maintaining the same functionality. This further reduces the schematics direct dependence on the `@angular-devkit/core` package.
1 parent 291bbff commit ccd7e71

File tree

3 files changed

+21
-25
lines changed

3 files changed

+21
-25
lines changed

packages/schematics/angular/utility/find-module_spec.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { Path } from '@angular-devkit/core';
109
import { EmptyTree, Tree } from '@angular-devkit/schematics';
1110
import { ModuleOptions, buildRelativePath, findModule, findModuleFromOptions } from './find-module';
1211

@@ -107,51 +106,51 @@ describe('find-module', () => {
107106
tree.create('/projects/my-proj/src/app.module.ts', '');
108107
options.module = 'app.module.ts';
109108
options.path = '/projects/my-proj/src';
110-
const modPath = findModuleFromOptions(tree, options);
111-
expect(modPath).toEqual('/projects/my-proj/src/app.module.ts' as Path);
109+
const modPath = findModuleFromOptions(tree, options) as string;
110+
expect(modPath).toEqual('/projects/my-proj/src/app.module.ts');
112111
});
113112

114113
it('should find a module when name has underscore', () => {
115114
tree.create('/projects/my-proj/src/feature_module/app_test.module.ts', '');
116115
options.path = '/projects/my-proj/src';
117116
options.name = 'feature_module/new_component';
118-
const modPath = findModuleFromOptions(tree, options);
119-
expect(modPath).toEqual('/projects/my-proj/src/feature_module/app_test.module.ts' as Path);
117+
const modPath = findModuleFromOptions(tree, options) as string;
118+
expect(modPath).toEqual('/projects/my-proj/src/feature_module/app_test.module.ts');
120119
});
121120

122121
it('should find a module when name has uppercase', () => {
123122
tree.create('/projects/my-proj/src/featureModule/appTest.module.ts', '');
124123
options.path = '/projects/my-proj/src';
125124
options.name = 'featureModule/newComponent';
126-
const modPath = findModuleFromOptions(tree, options);
127-
expect(modPath).toEqual('/projects/my-proj/src/featureModule/appTest.module.ts' as Path);
125+
const modPath = findModuleFromOptions(tree, options) as string;
126+
expect(modPath).toEqual('/projects/my-proj/src/featureModule/appTest.module.ts');
128127
});
129128

130129
it('should find a module if flat is true', () => {
131130
tree.create('/projects/my-proj/src/module/app_test.module.ts', '');
132131
options.path = '/projects/my-proj/src';
133132
options.flat = true;
134133
options.name = '/module/directive';
135-
const modPath = findModuleFromOptions(tree, options);
136-
expect(modPath).toEqual('/projects/my-proj/src/module/app_test.module.ts' as Path);
134+
const modPath = findModuleFromOptions(tree, options) as string;
135+
expect(modPath).toEqual('/projects/my-proj/src/module/app_test.module.ts');
137136
});
138137

139138
it('should find a module in a sub dir', () => {
140139
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
141140
options.name = 'other/test';
142141
options.module = 'admin/foo';
143142
options.path = '/projects/my-proj/src';
144-
const modPath = findModuleFromOptions(tree, options);
145-
expect(modPath).toEqual('/projects/my-proj/src/admin/foo.module.ts' as Path);
143+
const modPath = findModuleFromOptions(tree, options) as string;
144+
expect(modPath).toEqual('/projects/my-proj/src/admin/foo.module.ts');
146145
});
147146

148147
it('should find a module in a sub dir (2)', () => {
149148
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
150149
options.name = 'admin/hello';
151150
options.module = 'foo';
152151
options.path = '/projects/my-proj/src';
153-
const modPath = findModuleFromOptions(tree, options);
154-
expect(modPath).toEqual('/projects/my-proj/src/admin/foo.module.ts' as Path);
152+
const modPath = findModuleFromOptions(tree, options) as string;
153+
expect(modPath).toEqual('/projects/my-proj/src/admin/foo.module.ts');
155154
});
156155

157156
it('should find a module using custom ext', () => {
@@ -160,16 +159,16 @@ describe('find-module', () => {
160159
options.path = '/projects/my-proj/src';
161160
options.moduleExt = '_module.ts';
162161
// Should find module using custom moduleExt
163-
const modPath = findModuleFromOptions(tree, options);
164-
expect(modPath).toBe('/projects/my-proj/src/app_module.ts' as Path);
162+
const modPath = findModuleFromOptions(tree, options) as string;
163+
expect(modPath).toBe('/projects/my-proj/src/app_module.ts');
165164
// Should not find module if using invalid ext
166165
options.moduleExt = '-module.ts';
167-
expect(() => findModuleFromOptions(tree, options)).toThrowError(
166+
expect(() => findModuleFromOptions(tree, options) as string).toThrowError(
168167
/Specified module 'app' does not exist/,
169168
);
170169
// Should not find module if using default ext
171170
options.moduleExt = undefined; // use default ext
172-
expect(() => findModuleFromOptions(tree, options)).toThrowError(
171+
expect(() => findModuleFromOptions(tree, options) as string).toThrowError(
173172
/Specified module 'app' does not exist/,
174173
);
175174
});
@@ -182,13 +181,13 @@ describe('find-module', () => {
182181

183182
// moduleExt ignored because exact path is found
184183
options.module = 'app.module.ts';
185-
modPath = findModuleFromOptions(tree, options);
186-
expect(modPath).toBe('/projects/my-proj/src/app.module.ts' as Path);
184+
modPath = findModuleFromOptions(tree, options) as string;
185+
expect(modPath).toBe('/projects/my-proj/src/app.module.ts');
187186

188187
// moduleExt ignored because module + .ts is found
189188
options.module = 'app.module';
190-
modPath = findModuleFromOptions(tree, options);
191-
expect(modPath).toBe('/projects/my-proj/src/app.module.ts' as Path);
189+
modPath = findModuleFromOptions(tree, options) as string;
190+
expect(modPath).toBe('/projects/my-proj/src/app.module.ts');
192191
});
193192
});
194193

packages/schematics/angular/utility/parse-name.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// import { relative, Path } from "../../../angular_devkit/core/src/virtual-fs";
109
import { Path, basename, dirname, join, normalize } from '@angular-devkit/core';
1110

1211
export interface Location {

packages/schematics/angular/utility/validation.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { tags } from '@angular-devkit/core';
109
import { SchematicsException } from '@angular-devkit/schematics';
1110

1211
// Must start with a letter, and must contain only alphanumeric characters or dashes.
@@ -15,7 +14,6 @@ export const htmlSelectorRe = /^[a-zA-Z][.0-9a-zA-Z]*(:?-[a-zA-Z][.0-9a-zA-Z]*)*
1514

1615
export function validateHtmlSelector(selector: string): void {
1716
if (selector && !htmlSelectorRe.test(selector)) {
18-
throw new SchematicsException(tags.oneLine`Selector (${selector})
19-
is invalid.`);
17+
throw new SchematicsException(`Selector (${selector}) is invalid.`);
2018
}
2119
}

0 commit comments

Comments
 (0)