Skip to content

Architecture and Tricks for Migrations & Schematics

Nikolay Alipiev edited this page Feb 13, 2024 · 10 revisions

ES & CommonJS Modules in migrations & schematics

With IVY introduced by angular, all angular packages became ESModules, except angular schematics, which is a CommonJS one. In our Ignite UI angular schematics we need to call some of the other angular modules like @angular/compiler and dynamic import() is needed. But this is compiled to require() instead of preserved as a dynamic module, because of the CommonJS nature of the schematics. Our solution, in that case, is to introduce a util function in a .js file instead of .ts, which contains the native dynamic import(), therefore being a .js after a compilation the import is preserved: https://github.com/IgniteUI/igniteui-angular/pull/10043/files#diff-be445e23dd0ce197a4f388f80338f15ed89c9d55e3492950a12447dd6fbcd68d

TypeScript and compiler options

Here are the builds for the schematics and migrations, using TypeScript compiler (tsc):

"build:migrations": "gulp copyMigrations && tsc --listEmittedFiles --project ./projects/igniteui-angular/migrations/tsconfig.json",
"build:schematics": "gulp copySchematics && tsc --listEmittedFiles --project ./projects/igniteui-angular/schematics/tsconfig.json"

Compiler diagnostics

The first problem in Tips & Tricks section (Add skipLibCheck on compile for schematics & migrations) was diagnosed using --explainFiles. You can do that by adding the flag during the compile:

tsc --explainFiles --listEmittedFiles --project ./projects/igniteui-angular/schematics/tsconfig.json"

Tips & Tricks

Below you can find some well-described migrations' & schematics' issues that define some concepts and some more advanced cases.

Here are all migrations & schematics issues.

Add skipLibCheck on compile for schematics & migrations

https://github.com/IgniteUI/igniteui-angular/pull/13883

Turn on encapsulation for devkit/schematics dependencies

https://github.com/IgniteUI/igniteui-angular/pull/13712

Migrations are failing, when @angular-devkit/core is not on root level in the node_modules

https://github.com/IgniteUI/igniteui-angular/issues/13668

Clone this wiki locally