Title: Support executing ESM schematics · Issue #22786 · angular/angular-cli · GitHub
Open Graph Title: Support executing ESM schematics · Issue #22786 · angular/angular-cli
X Title: Support executing ESM schematics · Issue #22786 · angular/angular-cli
Description: 🚀 Feature request Support schematics written in ES Modules. Currently only CommonJS schematics are supported. Command (mark with an x) new build serve test e2e generate add update lint extract-i18n run config help version doc other: comp...
Open Graph Description: 🚀 Feature request Support schematics written in ES Modules. Currently only CommonJS schematics are supported. Command (mark with an x) new build serve test e2e generate add update lint extract-i18n...
X Description: 🚀 Feature request Support schematics written in ES Modules. Currently only CommonJS schematics are supported. Command (mark with an x) new build serve test e2e generate add update lint extract-i18n...
Opengraph URL: https://github.com/angular/angular-cli/issues/22786
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support executing ESM schematics","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n# 🚀 Feature request\r\nSupport schematics written in ES Modules. Currently only CommonJS schematics are supported.\r\n\r\n### Command (mark with an `x`)\r\n\r\n\u003c!-- Can you pin-point the command or commands that are relevant for this feature request? -->\r\n\u003c!-- ✍️edit: -->\r\n\r\n- [ ] new\r\n- [ ] build\r\n- [ ] serve\r\n- [ ] test\r\n- [ ] e2e\r\n- [ ] generate\r\n- [ ] add\r\n- [ ] update\r\n- [ ] lint\r\n- [ ] extract-i18n\r\n- [ ] run\r\n- [ ] config\r\n- [ ] help\r\n- [ ] version\r\n- [ ] doc\r\n- [x] other: compiling custom schematics\r\n\r\n### Description\r\n\r\nCurrently custom (and official) schematics can execute only CommonJS code, but not ES Modules. This is problematic when you want to import an ES Module in your custom schematics, [for example `HtmlParser` from `@angular/compiler`](https://github.com/SAP/spartacus/blob/7a1672a83224a5a2f3e6b3d08de3e461514120ea/projects/schematics/src/shared/utils/file-utils.ts#L253) (which since ng13 is shipped only as ESM).\r\n\r\n#### Problems with not supporting ESM:\r\n\r\nThe following error started to occur for our custom schematics in runtime, since we upgraded from ng12 to 13:\r\n`require() of ES Module \u003cpath-to-the-repo>/node_modules/@angular/compiler/fesm2015/compiler.mjs not supported. Instead change the require of \u003cpath-to-the-repo>/node_modules/@angular/compiler/fesm2015/compiler.mjs to a dynamic import() which is available in all CommonJS modules.`\r\n\r\nBut the advised change of the static `@angular/compiler` to a dynamic import is cumbersome due to various reasons:\r\n- it unnecessarily changes the our synchronous code to asynchronous code\r\n- it induces passing down the `compilerModule` (result of `await import(@angular/compiler)`) as an argument down to all helper functions ([example in angular repo](https://github.com/angular/angular/blob/a432ad65c77d5888da49b630d5055da2b8f7513c/packages/core/schematics/migrations/router-link-empty-expression/index.ts#L61))\r\n- it requires a hacky workaround ticking the Typescript compiler so to avoid compiling the dynamic `import()` into the `require()` call - for more see [the workaround function `loadEsmModule()` in angular repo ](https://github.com/angular/angular/blob/e0015d3c456d584242269b0765878d598a550888/packages/core/schematics/utils/load_esm.ts#L11-L35). Btw. this function is not exported in public API, so we need to copy-paste it to our repo.\r\n\r\n\r\n### Describe the solution you'd like\r\nSupport executing ESM schematics .\r\n\r\n### Describe alternatives you've considered\r\nChange the import of ESM to dynamic imports in our schematics code and deal with all its cumbersome consequences (described above). \r\n\r\n","author":{"url":"https://github.com/Platonn","@type":"Person","name":"Platonn"},"datePublished":"2022-03-02T10:02:32Z","url":"https://github.com/angular/angular-cli/issues/22786"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:40d0fbce-d913-b5b6-5246-82d65dd4a49e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C7AC:1CCECA:EB8662:13A5D9B:6B01E23B |
| html-safe-nonce | 78d32e88daa9c38b99d6367c34dec5a74a6b6a2423d2cd17a49a59b33a350ff2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDN0FDOjFDQ0VDQTpFQjg2NjI6MTNBNUQ5Qjo2QjAxRTIzQiIsInZpc2l0b3JfaWQiOiIzMDEwNDk3NDYwMzc3MzQ2NjE5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b2abcb22954fac48ec8b29937442f60afe2b111364a60d7f6355938899f0d356 |
| hovercard-subject-tag | issue:1156963124 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/22786/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8e2eee1027a566658715d14838e47127e18fdb3c4d6ca7b0e71fe7922a70e55b/angular/angular-cli/issues/22786 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8e2eee1027a566658715d14838e47127e18fdb3c4d6ca7b0e71fe7922a70e55b/angular/angular-cli/issues/22786 |
| og:image:alt | 🚀 Feature request Support schematics written in ES Modules. Currently only CommonJS schematics are supported. Command (mark with an x) new build serve test e2e generate add update lint extract-i18n... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Platonn |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width