Skip to content

Commit

Permalink
fix(@schematics/angular): cannot create pipe in sub-directory if modu…
Browse files Browse the repository at this point in the history
…le is in different sub-directory

Similar to other schematics, `findModuleFromOptions` should happen prior to `parseName` that modifies the name and path.

Fixes #13182
  • Loading branch information
Alan authored and mgechev committed Dec 14, 2018
1 parent 3684df8 commit e447489
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/schematics/angular/pipe/index.ts
Expand Up @@ -96,12 +96,12 @@ export default function (options: PipeOptions): Rule {
options.path = buildDefaultPath(project);
}

options.module = findModuleFromOptions(host, options);

const parsedPath = parseName(options.path, options.name);
options.name = parsedPath.name;
options.path = parsedPath.path;

options.module = findModuleFromOptions(host, options);

// todo remove these when we remove the deprecations
options.skipTests = options.skipTests || !options.spec;

Expand Down
14 changes: 14 additions & 0 deletions packages/schematics/angular/pipe/index_spec.ts
Expand Up @@ -79,6 +79,20 @@ describe('Pipe Schematic', () => {
expect(thrownError).toBeDefined();
});

it('should handle a path in the name and module options', () => {
appTree = schematicRunner.runSchematic(
'module',
{ name: 'admin/module', project: 'bar' },
appTree,
);

const options = { ...defaultOptions, module: 'admin/module' };
appTree = schematicRunner.runSchematic('pipe', options, appTree);

const content = appTree.readContent('/projects/bar/src/app/admin/module/module.module.ts');
expect(content).toMatch(/import { FooPipe } from '\.\.\/\.\.\/foo.pipe'/);
});

it('should export the pipe', () => {
const options = { ...defaultOptions, export: true };

Expand Down

0 comments on commit e447489

Please sign in to comment.