Skip to content

Commit

Permalink
feat(ng-add): added warning for applications without modules (#6664)
Browse files Browse the repository at this point in the history
* feat(ng-add): added warning for applications without modules

* feat(docs): fixed typo

* feat(docs): fixed typo
  • Loading branch information
lexasq authored Jul 12, 2024
1 parent 876f20d commit 740a10f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ <h2 id="installation">
<a class="anchor-link" routerLink="." fragment="installation">#</a>
</h2>
<h4>Angular CLI way</h4>
<p>Make sure that your app uses modular approach and you have app.module.ts set as your starting point before you proceed</p>
<pre class="prettyprint lang-js prettyprinted">
<span class="kwd">import</span><span class="pln"> </span><span class="pun">{{'{'}}</span><span class="kwd"> platformBrowser </span><span
class="pun">{{'}'}}</span><span class="pln"> from </span><span class="str">'&#64;angular/platform-browser'</span><span
class="pun">;</span>
<span class="kwd">import</span><span class="pln"> </span><span class="pun">{{'{'}}</span><span class="kwd"> AppModule </span><span
class="pun">{{'}'}}</span><span class="pln"> from </span><span class="str">'./app.module'</span><span
class="pun">;</span>
<span class="pln">&nbsp;</span>
<span class="pun">platformBrowser().bootstrapModule(AppModule).catch((err) => console.error(err));</span>
</pre>
<!-- // main.ts-->
<!-- import { platformBrowser } from '&#64;angular/platform-browser';-->
<!-- import { AppModule } from './app.module';-->

<!-- platformBrowser().bootstrapModule(AppModule).catch((err) => console.error(err));-->
<p>Use the Angular CLI ng add command for updating your Angular project.</p>
<pre class="prettyprint lang-bash prettyprinted"><span class="pln">ng add ngx-bootstrap</span></pre>

Expand Down Expand Up @@ -233,7 +249,7 @@ <h2 id="compatibility">
</thead>
<tbody>
<tr>
<th>13.x.x</th>
<th>18.x.x</th>
<th>18.x.x</th>
<th>5.x.x or 4.x.x</th>
</tr>
Expand Down
4 changes: 4 additions & 0 deletions src/schematics/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/schematics/src/utils/project-main-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 740a10f

Please sign in to comment.