Skip to content

Commit

Permalink
fix(@angular/cli): fix issue with console prompt bailing early (angul…
Browse files Browse the repository at this point in the history
…ar#5218)

* fix(@angular/cli): fix issue with console prompt bailing early

fixes angular#4614

* fix(@angular/cli): fix declarable types not finding closest module

fixes angular#5127
  • Loading branch information
delasteve authored and Zhicheng Wang committed Mar 16, 2017
1 parent 6c21402 commit cd69373
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
3 changes: 1 addition & 2 deletions packages/@angular/cli/blueprints/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export default Blueprint.extend({
}
} else {
try {
this.pathToModule = findParentModule(
this.project.root, appConfig.root, this.dynamicPath.dir);
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
3 changes: 1 addition & 2 deletions packages/@angular/cli/blueprints/directive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export default Blueprint.extend({
}
} else {
try {
this.pathToModule = findParentModule
(this.project.root, appConfig.root, this.dynamicPath.dir);
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
3 changes: 1 addition & 2 deletions packages/@angular/cli/blueprints/pipe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ export default Blueprint.extend({
}
} else {
try {
this.pathToModule = findParentModule
(this.project.root, appConfig.root, this.dynamicPath.dir);
this.pathToModule = findParentModule(this.project.root, appConfig.root, this.generatePath);
} catch (e) {
if (!options.skipImport) {
throw `Error locating module for declaration\n\t${e}`;
Expand Down
8 changes: 3 additions & 5 deletions packages/@angular/cli/ember-cli/lib/ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,10 @@ UI.prototype.prompt = function(questions, callback) {

// If no callback was provided, automatically return a promise
if (callback) {
inquirer.prompt(questions, callback);
} else {
return new Promise(function(resolve) {
inquirer.prompt(questions, resolve);
});
return inquirer.prompt(questions, callback);
}

return inquirer.prompt(questions);
};

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/@angular/cli/utilities/find-parent-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default function findParentModule(
let pathToCheck = path.join(sourceRoot, currentDir);

while (pathToCheck.length >= sourceRoot.length) {
if (!fs.existsSync(pathToCheck)) {
pathToCheck = path.dirname(pathToCheck);
continue;
}
// TODO: refactor to not be based upon file name
const files = fs.readdirSync(pathToCheck)
.filter(fileName => !fileName.endsWith('routing.module.ts'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { join } from 'path';
import { ng } from '../../../utils/process';
import { expectFileToMatch } from '../../../utils/fs';

export default function () {
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');

return Promise.resolve()
.then(() => ng('generate', 'module', 'foo'))
.then(() => ng('generate', 'component', 'foo'))
.then(() => expectFileToMatch(modulePath, /import { FooComponent } from '.\/foo.component'/));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { join } from 'path';
import { ng } from '../../../utils/process';
import { expectFileToMatch } from '../../../utils/fs';

export default function () {
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');

return Promise.resolve()
.then(() => ng('generate', 'module', 'foo'))
.then(() => ng('generate', 'directive', 'foo', '--no-flat'))
.then(() => expectFileToMatch(modulePath, /import { FooDirective } from '.\/foo.directive'/));
}
12 changes: 12 additions & 0 deletions tests/e2e/tests/generate/pipe/pipe-in-existing-module-dir.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { join } from 'path';
import { ng } from '../../../utils/process';
import { expectFileToMatch } from '../../../utils/fs';

export default function () {
const modulePath = join('src', 'app', 'foo', 'foo.module.ts');

return Promise.resolve()
.then(() => ng('generate', 'module', 'foo'))
.then(() => ng('generate', 'pipe', 'foo', '--no-flat'))
.then(() => expectFileToMatch(modulePath, /import { FooPipe } from '.\/foo.pipe'/));
}

0 comments on commit cd69373

Please sign in to comment.