Skip to content

Commit b90825c

Browse files
hanslBrocco
authored andcommitted
fix(@angular/cli): fix an issue with schematics
The issue here is that the sourceDir string could be anywhere in the path. We only care about it if its at the start.
1 parent f2a2149 commit b90825c

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/@angular/cli/commands/generate.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ export default Command.extend({
142142
commandOptions.appRoot = parsedPath.appRoot.startsWith(root)
143143
? parsedPath.appRoot.substr(root.length)
144144
: parsedPath.appRoot;
145-
commandOptions.path = parsedPath.dir
146-
.replace(appConfig.root + path.sep, '')
147-
.replace(separatorRegEx, '/');
145+
commandOptions.path = parsedPath.dir.replace(separatorRegEx, '/');
146+
if (parsedPath.dir.startsWith(root)) {
147+
commandOptions.path = commandOptions.path.substr(root.length);
148+
}
148149

149150
const cwd = this.project.root;
150151
const schematicName = rawArgs[0];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as fs from 'fs-extra';
2+
import {join} from 'path';
3+
import {ng} from '../../../utils/process';
4+
import {expectFileToMatch} from '../../../utils/fs';
5+
6+
7+
export default function() {
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
12+
13+
return ng('generate', 'component', 'test-component', '--module', 'app.module.ts')
14+
.then(() => expectFileToMatch(modulePath,
15+
/import { TestComponentComponent } from '.\/test-component\/test-component.component'/))
16+
17+
.then(() => process.chdir(join(root, 'src', 'app')))
18+
.then(() => ng('generate', 'component', 'test-component2', '--module', 'app.module.ts'))
19+
.then(() => expectFileToMatch(modulePath,
20+
/import { TestComponent2Component } from '.\/test-component2\/test-component2.component'/))
21+
22+
// Try to run the unit tests.
23+
.then(() => ng('build'));
24+
}

0 commit comments

Comments
 (0)