Skip to content

Commit b480dea

Browse files
Alanmgechev
Alan
authored andcommitted
fix(@schematics/angular): cannot create pipe in sub-directory if module is in different sub-directory
Similar to other schematics, `findModuleFromOptions` should happen prior to `parseName` that modifies the name and path. Fixes #13182
1 parent 970f24d commit b480dea

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/schematics/angular/pipe/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,14 @@ export default function (options: PipeOptions): Rule {
9696
options.path = buildDefaultPath(project);
9797
}
9898

99+
options.module = findModuleFromOptions(host, options);
100+
99101
const parsedPath = parseName(options.path, options.name);
100102
options.name = parsedPath.name;
101103
options.path = parsedPath.path;
102104

103-
options.module = findModuleFromOptions(host, options);
105+
// todo remove these when we remove the deprecations
106+
options.skipTests = options.skipTests || !options.spec;
104107

105108
const templateSource = apply(url('./files'), [
106109
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),

packages/schematics/angular/pipe/index_spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ describe('Pipe Schematic', () => {
7979
expect(thrownError).toBeDefined();
8080
});
8181

82+
it('should handle a path in the name and module options', () => {
83+
appTree = schematicRunner.runSchematic(
84+
'module',
85+
{ name: 'admin/module', project: 'bar' },
86+
appTree,
87+
);
88+
89+
const options = { ...defaultOptions, module: 'admin/module' };
90+
appTree = schematicRunner.runSchematic('pipe', options, appTree);
91+
92+
const content = appTree.readContent('/projects/bar/src/app/admin/module/module.module.ts');
93+
expect(content).toMatch(/import { FooPipe } from '\.\.\/\.\.\/foo.pipe'/);
94+
});
95+
8296
it('should export the pipe', () => {
8397
const options = { ...defaultOptions, export: true };
8498

0 commit comments

Comments
 (0)