Skip to content

Commit 3515c3b

Browse files
delasteveBrocco
authored andcommitted
fix(@angular/cli): fix issue with console prompt bailing early (#5218)
* fix(@angular/cli): fix issue with console prompt bailing early fixes #4614 * fix(@angular/cli): fix declarable types not finding closest module fixes #5127
1 parent 5c9c653 commit 3515c3b

File tree

8 files changed

+46
-11
lines changed

8 files changed

+46
-11
lines changed

packages/@angular/cli/blueprints/component/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export default Blueprint.extend({
9595
}
9696
} else {
9797
try {
98-
this.pathToModule = findParentModule(
99-
this.project.root, appConfig.root, this.dynamicPath.dir);
98+
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
10099
} catch (e) {
101100
if (!options.skipImport) {
102101
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/blueprints/directive/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export default Blueprint.extend({
7070
}
7171
} else {
7272
try {
73-
this.pathToModule = findParentModule
74-
(this.project.root, appConfig.root, this.dynamicPath.dir);
73+
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
7574
} catch (e) {
7675
if (!options.skipImport) {
7776
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/blueprints/pipe/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ export default Blueprint.extend({
6565
}
6666
} else {
6767
try {
68-
this.pathToModule = findParentModule
69-
(this.project.root, appConfig.root, this.dynamicPath.dir);
68+
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
7069
} catch (e) {
7170
if (!options.skipImport) {
7271
throw `Error locating module for declaration\n\t${e}`;

packages/@angular/cli/ember-cli/lib/ui/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,10 @@ UI.prototype.prompt = function(questions, callback) {
174174

175175
// If no callback was provided, automatically return a promise
176176
if (callback) {
177-
inquirer.prompt(questions, callback);
178-
} else {
179-
return new Promise(function(resolve) {
180-
inquirer.prompt(questions, resolve);
181-
});
177+
return inquirer.prompt(questions, callback);
182178
}
179+
180+
return inquirer.prompt(questions);
183181
};
184182

185183
/**

packages/@angular/cli/utilities/find-parent-module.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default function findParentModule(
1313
let pathToCheck = path.join(sourceRoot, currentDir);
1414

1515
while (pathToCheck.length >= sourceRoot.length) {
16+
if (!fs.existsSync(pathToCheck)) {
17+
pathToCheck = path.dirname(pathToCheck);
18+
continue;
19+
}
1620
// TODO: refactor to not be based upon file name
1721
const files = fs.readdirSync(pathToCheck)
1822
.filter(fileName => !fileName.endsWith('routing.module.ts'))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from 'path';
2+
import { ng } from '../../../utils/process';
3+
import { expectFileToMatch } from '../../../utils/fs';
4+
5+
export default function () {
6+
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');
7+
8+
return Promise.resolve()
9+
.then(() => ng('generate', 'module', 'foo'))
10+
.then(() => ng('generate', 'component', 'foo'))
11+
.then(() => expectFileToMatch(modulePath, /import { FooComponent } from '.\/foo.component'/));
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from 'path';
2+
import { ng } from '../../../utils/process';
3+
import { expectFileToMatch } from '../../../utils/fs';
4+
5+
export default function () {
6+
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');
7+
8+
return Promise.resolve()
9+
.then(() => ng('generate', 'module', 'foo'))
10+
.then(() => ng('generate', 'directive', 'foo', '--no-flat'))
11+
.then(() => expectFileToMatch(modulePath, /import { FooDirective } from '.\/foo.directive'/));
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { join } from 'path';
2+
import { ng } from '../../../utils/process';
3+
import { expectFileToMatch } from '../../../utils/fs';
4+
5+
export default function () {
6+
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');
7+
8+
return Promise.resolve()
9+
.then(() => ng('generate', 'module', 'foo'))
10+
.then(() => ng('generate', 'pipe', 'foo', '--no-flat'))
11+
.then(() => expectFileToMatch(modulePath, /import { FooPipe } from '.\/foo.pipe'/));
12+
}

0 commit comments

Comments
 (0)