Skip to content

Commit eb9fddf

Browse files
committed
fix(deps): --disableLifeCycleHooks with @ignore on component/directive
fix #526
1 parent c7a3264 commit eb9fddf

File tree

2 files changed

+169
-127
lines changed

2 files changed

+169
-127
lines changed

src/utils/utils.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ export function handlePath(files: Array<string>, cwd: string): Array<string> {
115115

116116
export function cleanLifecycleHooksFromMethods(methods: Array<any>): Array<any> {
117117
let result = [];
118-
let i = 0;
119-
let len = methods.length;
120-
121-
for (i; i < len; i++) {
122-
if (!(methods[i].name in AngularLifecycleHooks)) {
123-
result.push(methods[i]);
118+
if (typeof methods !== 'undefined') {
119+
let i = 0;
120+
let len = methods.length;
121+
for (i; i < len; i++) {
122+
if (!(methods[i].name in AngularLifecycleHooks)) {
123+
result.push(methods[i]);
124+
}
124125
}
125126
}
126-
127127
return result;
128128
}
129129

test/src/cli/cli-ignore.spec.ts

Lines changed: 162 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -7,126 +7,168 @@ const tmp = temporaryDir();
77
describe('CLI ignore JSDoc tag support', () => {
88
const distFolder = tmp.name + '-ignore-jsdoc';
99

10-
before(done => {
11-
tmp.create(distFolder);
12-
let ls = shell('node', [
13-
'./bin/index-cli.js',
14-
'-p',
15-
'./test/src/todomvc-ng2-ignore/src/tsconfig.json',
16-
'-d',
17-
distFolder
18-
]);
19-
20-
if (ls.stderr.toString() !== '') {
21-
console.error(`shell error: ${ls.stderr.toString()}`);
22-
done('error');
23-
}
24-
done();
25-
});
26-
after(() => tmp.clean(distFolder));
27-
28-
it('AppComponent ignored', () => {
29-
const file = exists(distFolder + '/components/AppComponent.html');
30-
expect(file).to.be.false;
31-
});
32-
33-
it('Component property ignored', () => {
34-
const file = read(distFolder + '/components/FooterComponent.html');
35-
expect(file).to.not.contain('<code>ignoredProperty');
36-
});
37-
38-
it('Component function ignored', () => {
39-
const file = read(distFolder + '/components/FooterComponent.html');
40-
expect(file).to.not.contain('<code>ignoredFunction');
41-
});
42-
43-
it('Component input ignored', () => {
44-
const file = read(distFolder + '/components/FooterComponent.html');
45-
expect(file).to.not.contain('<code>ignoredInput');
46-
});
47-
48-
it('Component output ignored', () => {
49-
const file = read(distFolder + '/components/FooterComponent.html');
50-
expect(file).to.not.contain('<code>ignoredOutput');
51-
});
52-
53-
it('Component hostbinding ignored', () => {
54-
const file = read(distFolder + '/components/FooterComponent.html');
55-
expect(file).to.not.contain('<code>style.color');
56-
});
57-
58-
it('Component hostlistener ignored', () => {
59-
const file = read(distFolder + '/components/FooterComponent.html');
60-
expect(file).to.not.contain('<code>mouseup');
61-
});
62-
63-
it('Module ignored', () => {
64-
const file = exists(distFolder + '/modules/FooterModule.html');
65-
expect(file).to.be.false;
66-
});
67-
68-
it('Directive ignored', () => {
69-
const file = exists(distFolder + '/directives/DoNothingDirective.html');
70-
expect(file).to.be.false;
71-
});
72-
73-
it('Service ignored', () => {
74-
const file = exists(distFolder + '/services/TodoStore.html');
75-
expect(file).to.be.false;
76-
});
77-
78-
it('Pipe ignored', () => {
79-
const file = exists(distFolder + '/pipes/FirstUpperPipe.html');
80-
expect(file).to.be.false;
81-
});
82-
83-
it('Interface ignored', () => {
84-
const file = exists(distFolder + '/interfaces/ClockInterface.html');
85-
expect(file).to.be.false;
86-
});
87-
88-
it('Class ignored', () => {
89-
const file = exists(distFolder + '/classes/Todo.html');
90-
expect(file).to.be.false;
91-
});
92-
93-
it('Class constructor ignored', () => {
94-
const file = read(distFolder + '/classes/PrivateConstructor.html');
95-
expect(file).to.not.contain('<code>constructor');
96-
});
97-
98-
it('Class property ignored', () => {
99-
const file = read(distFolder + '/classes/PrivateConstructor.html');
100-
expect(file).to.not.contain('<code>myproperty');
101-
});
102-
103-
it('Class function ignored', () => {
104-
const file = read(distFolder + '/classes/PrivateConstructor.html');
105-
expect(file).to.not.contain('<code>yo');
106-
});
107-
108-
it('Class acessors ignored', () => {
109-
const file = read(distFolder + '/components/FooterComponent.html');
110-
expect(file).to.not.contain('<code>title(v');
111-
});
112-
113-
it('Simple function ignored', () => {
114-
const file = read(distFolder + '/miscellaneous/functions.html');
115-
expect(file).to.not.contain('<code>LogMethod');
116-
});
117-
118-
it('Simple enum ignored', () => {
119-
const file = read(distFolder + '/miscellaneous/enumerations.html');
120-
expect(file).to.not.contain('<a href="#Direction">');
121-
});
122-
123-
it('Simple variable ignored', () => {
124-
const file = read(distFolder + '/miscellaneous/variables.html');
125-
expect(file).to.not.contain('<code>PIT');
126-
});
10+
describe('without --disableLifeCycleHooks', () => {
11+
12+
before(done => {
13+
tmp.create(distFolder);
14+
let ls = shell('node', [
15+
'./bin/index-cli.js',
16+
'-p',
17+
'./test/src/todomvc-ng2-ignore/src/tsconfig.json',
18+
'-d',
19+
distFolder
20+
]);
21+
22+
if (ls.stderr.toString() !== '') {
23+
console.error(`shell error: ${ls.stderr.toString()}`);
24+
done('error');
25+
}
26+
done();
27+
});
28+
after(() => tmp.clean(distFolder));
29+
30+
it('AppComponent ignored', () => {
31+
const file = exists(distFolder + '/components/AppComponent.html');
32+
expect(file).to.be.false;
33+
});
34+
35+
it('Component property ignored', () => {
36+
const file = read(distFolder + '/components/FooterComponent.html');
37+
expect(file).to.not.contain('<code>ignoredProperty');
38+
});
39+
40+
it('Component function ignored', () => {
41+
const file = read(distFolder + '/components/FooterComponent.html');
42+
expect(file).to.not.contain('<code>ignoredFunction');
43+
});
44+
45+
it('Component input ignored', () => {
46+
const file = read(distFolder + '/components/FooterComponent.html');
47+
expect(file).to.not.contain('<code>ignoredInput');
48+
});
49+
50+
it('Component output ignored', () => {
51+
const file = read(distFolder + '/components/FooterComponent.html');
52+
expect(file).to.not.contain('<code>ignoredOutput');
53+
});
54+
55+
it('Component hostbinding ignored', () => {
56+
const file = read(distFolder + '/components/FooterComponent.html');
57+
expect(file).to.not.contain('<code>style.color');
58+
});
59+
60+
it('Component hostlistener ignored', () => {
61+
const file = read(distFolder + '/components/FooterComponent.html');
62+
expect(file).to.not.contain('<code>mouseup');
63+
});
64+
65+
it('Module ignored', () => {
66+
const file = exists(distFolder + '/modules/FooterModule.html');
67+
expect(file).to.be.false;
68+
});
69+
70+
it('Directive ignored', () => {
71+
const file = exists(distFolder + '/directives/DoNothingDirective.html');
72+
expect(file).to.be.false;
73+
});
74+
75+
it('Service ignored', () => {
76+
const file = exists(distFolder + '/services/TodoStore.html');
77+
expect(file).to.be.false;
78+
});
79+
80+
it('Pipe ignored', () => {
81+
const file = exists(distFolder + '/pipes/FirstUpperPipe.html');
82+
expect(file).to.be.false;
83+
});
84+
85+
it('Interface ignored', () => {
86+
const file = exists(distFolder + '/interfaces/ClockInterface.html');
87+
expect(file).to.be.false;
88+
});
89+
90+
it('Class ignored', () => {
91+
const file = exists(distFolder + '/classes/Todo.html');
92+
expect(file).to.be.false;
93+
});
94+
95+
it('Class constructor ignored', () => {
96+
const file = read(distFolder + '/classes/PrivateConstructor.html');
97+
expect(file).to.not.contain('<code>constructor');
98+
});
99+
100+
it('Class property ignored', () => {
101+
const file = read(distFolder + '/classes/PrivateConstructor.html');
102+
expect(file).to.not.contain('<code>myproperty');
103+
});
104+
105+
it('Class function ignored', () => {
106+
const file = read(distFolder + '/classes/PrivateConstructor.html');
107+
expect(file).to.not.contain('<code>yo');
108+
});
109+
110+
it('Class acessors ignored', () => {
111+
const file = read(distFolder + '/components/FooterComponent.html');
112+
expect(file).to.not.contain('<code>title(v');
113+
});
114+
115+
it('Simple function ignored', () => {
116+
const file = read(distFolder + '/miscellaneous/functions.html');
117+
expect(file).to.not.contain('<code>LogMethod');
118+
});
119+
120+
it('Simple enum ignored', () => {
121+
const file = read(distFolder + '/miscellaneous/enumerations.html');
122+
expect(file).to.not.contain('<a href="#Direction">');
123+
});
124+
125+
it('Simple variable ignored', () => {
126+
const file = read(distFolder + '/miscellaneous/variables.html');
127+
expect(file).to.not.contain('<code>PIT');
128+
});
129+
130+
it('Simple type alias ignored', () => {
131+
const file = read(distFolder + '/miscellaneous/typealiases.html');
132+
expect(file).to.not.contain('<code>ChartChange');
133+
});
134+
135+
});
136+
137+
describe('with --disableLifeCycleHooks', () => {
138+
139+
before(done => {
140+
tmp.create(distFolder);
141+
let ls = shell('node', [
142+
'./bin/index-cli.js',
143+
'-p',
144+
'./test/src/todomvc-ng2-ignore/src/tsconfig.json',
145+
'--disableLifeCycleHooks',
146+
'-d',
147+
distFolder
148+
]);
149+
150+
if (ls.stdout.toString().indexOf('Sorry') !== -1) {
151+
console.error(`shell error: ${ls.stdout.toString()}`);
152+
done('error');
153+
}
154+
155+
if (ls.stderr.toString() !== '') {
156+
console.error(`shell error: ${ls.stderr.toString()}`);
157+
done('error');
158+
}
159+
done();
160+
});
161+
after(() => tmp.clean(distFolder));
162+
163+
it('AppComponent ignored', () => {
164+
const file = exists(distFolder + '/components/AppComponent.html');
165+
expect(file).to.be.false;
166+
});
167+
168+
it('Directive ignored', () => {
169+
const file = exists(distFolder + '/directives/DoNothingDirective.html');
170+
expect(file).to.be.false;
171+
});
127172

128-
it('Simple type alias ignored', () => {
129-
const file = read(distFolder + '/miscellaneous/typealiases.html');
130-
expect(file).to.not.contain('<code>ChartChange');
131173
});
132174
});

0 commit comments

Comments
 (0)