You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ng cli adding component breaks app.module.ts #7851
I have this issue to. It happens to me every single time i generate a new component/pipe/....
It always seems to affetc the last import statement ant the last item in the provide list.
I also have the same problem, and I believe I know how to reproduce it.
Some investigation has shown, that a default angular-cli project is not affected by this issue.
I started to have broken insertions after adding my company's copyright header. Can you confirm, that you get broken imports when there is a copyright symbol in your file header?
Angular CLI uses TypeScript functions to traverse the AST and find nodes.
TypeScript decorates those nodes with the textual position within the UTF-8 string.
Angular CLI then uses a LinkedList<Chunk> data structure to insert strings into the string by slicing the chunks and inserting a new Buffer at that position returned by TypeScript.
The Chunk data structure consists of a Buffer object. Slicing a Buffer at a certain position, assuming they contain UTF-8 strings, only works correctly if there are no characters using more than one byte.
I cannot think of a simple solution that would have a similar performance, without rewriting chunks of the code. Does performance really matter that much in this case? I guess this code is only used to insert short strings into files that are no longer than a few hundred lines of code. Not even that probably.
Oh, and this is only a guess. I'm not sure, if my investigation has found the right culprit.
Activity
bownie commentedon Sep 27, 2017
Additional info - this is excerpt from app.module.ts:
[..]
import { Md5 } from 'ts-md5/dist/md;
import { LoginDetailsComponent } from './login-details/login-details.component'5';
[..]
You can see that the existing md5 component has been split by the addition of the new component.
bownie commentedon Sep 27, 2017
Additionally the 'declarations' section is broken as follows:
asgerjensen commentedon Nov 21, 2017
I see this too, although most frequently in the declarations section of the module being updated.
mdelorimier commentedon Feb 6, 2018
Hello,
I have this issue to. It happens to me every single time i generate a new component/pipe/....
It always seems to affetc the last import statement ant the last item in the provide list.
Hope this can help
Regards
asmolenic commentedon Apr 3, 2018
Hi, this is happening to me as well when generating components (ng g c NewComponent --flat)
gfranco93 commentedon May 16, 2018
Hello,
I have the same problem when generating components (ng g component NewComponent) with @angular/cli: 1.7.4.
This is what app.module.ts looks like before generating the component:
after (broken):
xfh commentedon Jun 1, 2018
I also have the same problem, and I believe I know how to reproduce it.
Some investigation has shown, that a default angular-cli project is not affected by this issue.
I started to have broken insertions after adding my company's copyright header. Can you confirm, that you get broken imports when there is a copyright symbol in your file header?
e.g. test.module.ts
ng generate component test/abreaks the imports & declarations.When I remove the copyright symbol, everything works fine.
gfranco93 commentedon Jun 1, 2018
@xfh you are right, I was able to reproduce it that way. This bug occurs in version 6.0.7 as well.
sebastianhaeni commentedon Aug 22, 2018
I'm trying to guess why this happens:
LinkedList<Chunk>data structure to insert strings into the string by slicing the chunks and inserting a newBufferat that position returned by TypeScript.Chunkdata structure consists of aBufferobject. Slicing aBufferat a certain position, assuming they contain UTF-8 strings, only works correctly if there are no characters using more than one byte.©uses more than one byte and thus the index at which the slice occurs is incorrect.Implementation found here:
https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/schematics/src/utility/update-buffer.ts
I cannot think of a simple solution that would have a similar performance, without rewriting chunks of the code. Does performance really matter that much in this case? I guess this code is only used to insert short strings into files that are no longer than a few hundred lines of code. Not even that probably.
Oh, and this is only a guess. I'm not sure, if my investigation has found the right culprit.
fix(@angular-devkit/schematics): fix `generate` mangling files contai…
fix(@angular-devkit/schematics): fix `generate` mangling files contai…
fix(@angular-devkit/schematics): fix `generate` mangling files contai…
updating angular cli to my fork (#1)
angular-automatic-lock-bot commentedon Sep 8, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.
fix(@angular-devkit/schematics): fix `generate` mangling files contai…