From 740a10f9d07f57b2743362afb956df60b7bad773 Mon Sep 17 00:00:00 2001 From: Alexey Umanskiy Date: Fri, 12 Jul 2024 12:50:58 +0300 Subject: [PATCH] feat(ng-add): added warning for applications without modules (#6664) * feat(ng-add): added warning for applications without modules * feat(docs): fixed typo * feat(docs): fixed typo --- .../documentation/documentation.component.html | 18 +++++++++++++++++- src/schematics/src/utils/index.ts | 4 ++++ src/schematics/src/utils/project-main-file.ts | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libs/common-docs/src/lib/common/documentation/documentation.component.html b/libs/common-docs/src/lib/common/documentation/documentation.component.html index ae40a3d03a..332a04922f 100644 --- a/libs/common-docs/src/lib/common/documentation/documentation.component.html +++ b/libs/common-docs/src/lib/common/documentation/documentation.component.html @@ -112,6 +112,22 @@

#

Angular CLI way

+

Make sure that your app uses modular approach and you have app.module.ts set as your starting point before you proceed

+
+import {{'{'}} platformBrowser {{'}'}} from '@angular/platform-browser';
+import {{'{'}} AppModule {{'}'}} from './app.module';
+ 
+platformBrowser().bootstrapModule(AppModule).catch((err) => console.error(err));
+      
+ + + + +

Use the Angular CLI ng add command for updating your Angular project.

ng add ngx-bootstrap
@@ -233,7 +249,7 @@

- 13.x.x + 18.x.x 18.x.x 5.x.x or 4.x.x diff --git a/src/schematics/src/utils/index.ts b/src/schematics/src/utils/index.ts index c577271b94..ecf5c8a097 100644 --- a/src/schematics/src/utils/index.ts +++ b/src/schematics/src/utils/index.ts @@ -92,6 +92,10 @@ export function addModuleImportToRootModule( if (!moduleSource) { throw new SchematicsException(`Module not found: ${modulePath}`); } + if (modulePath.includes('component')) { + throw new SchematicsException(`ngx-bootstrap doesn't support moduleless approach if we couldn't find + your starting *.module.ts learn more here https://valor-software.com/ngx-bootstrap/#/documentation#installation`); + } const changes: Change[] = addImportToModule(moduleSource, modulePath, moduleName, src); const recorder = host.beginUpdate(modulePath); diff --git a/src/schematics/src/utils/project-main-file.ts b/src/schematics/src/utils/project-main-file.ts index f55135f2ee..c739ac7ec8 100644 --- a/src/schematics/src/utils/project-main-file.ts +++ b/src/schematics/src/utils/project-main-file.ts @@ -13,10 +13,10 @@ import { workspaces } from '@angular-devkit/core'; /** Looks for the main TypeScript file in the given project and returns its path. */ export function getProjectMainFile(project: workspaces.ProjectDefinition): string { const buildOptions = getProjectTargetOptions(project, 'build'); - if (!buildOptions.main) { + if (!buildOptions.main && !buildOptions.browser) { throw new SchematicsException(`Could not find the project main file inside of the ` + `workspace config (${project.sourceRoot})`); } - return buildOptions.main.toString(); + return buildOptions.main?.toString() ?? buildOptions.browser.toString(); }