Skip to content

Commit 740a10f

Browse files
authored
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
1 parent 876f20d commit 740a10f

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

libs/common-docs/src/lib/common/documentation/documentation.component.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ <h2 id="installation">
112112
<a class="anchor-link" routerLink="." fragment="installation">#</a>
113113
</h2>
114114
<h4>Angular CLI way</h4>
115+
<p>Make sure that your app uses modular approach and you have app.module.ts set as your starting point before you proceed</p>
116+
<pre class="prettyprint lang-js prettyprinted">
117+
<span class="kwd">import</span><span class="pln"> </span><span class="pun">{{'{'}}</span><span class="kwd"> platformBrowser </span><span
118+
class="pun">{{'}'}}</span><span class="pln"> from </span><span class="str">'&#64;angular/platform-browser'</span><span
119+
class="pun">;</span>
120+
<span class="kwd">import</span><span class="pln"> </span><span class="pun">{{'{'}}</span><span class="kwd"> AppModule </span><span
121+
class="pun">{{'}'}}</span><span class="pln"> from </span><span class="str">'./app.module'</span><span
122+
class="pun">;</span>
123+
<span class="pln">&nbsp;</span>
124+
<span class="pun">platformBrowser().bootstrapModule(AppModule).catch((err) => console.error(err));</span>
125+
</pre>
126+
<!-- // main.ts-->
127+
<!-- import { platformBrowser } from '&#64;angular/platform-browser';-->
128+
<!-- import { AppModule } from './app.module';-->
129+
130+
<!-- platformBrowser().bootstrapModule(AppModule).catch((err) => console.error(err));-->
115131
<p>Use the Angular CLI ng add command for updating your Angular project.</p>
116132
<pre class="prettyprint lang-bash prettyprinted"><span class="pln">ng add ngx-bootstrap</span></pre>
117133

@@ -233,7 +249,7 @@ <h2 id="compatibility">
233249
</thead>
234250
<tbody>
235251
<tr>
236-
<th>13.x.x</th>
252+
<th>18.x.x</th>
237253
<th>18.x.x</th>
238254
<th>5.x.x or 4.x.x</th>
239255
</tr>

src/schematics/src/utils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ export function addModuleImportToRootModule(
9292
if (!moduleSource) {
9393
throw new SchematicsException(`Module not found: ${modulePath}`);
9494
}
95+
if (modulePath.includes('component')) {
96+
throw new SchematicsException(`ngx-bootstrap doesn't support moduleless approach if we couldn't find
97+
your starting *.module.ts learn more here https://valor-software.com/ngx-bootstrap/#/documentation#installation`);
98+
}
9599

96100
const changes: Change[] = addImportToModule(moduleSource, modulePath, moduleName, src);
97101
const recorder = host.beginUpdate(modulePath);

src/schematics/src/utils/project-main-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { workspaces } from '@angular-devkit/core';
1313
/** Looks for the main TypeScript file in the given project and returns its path. */
1414
export function getProjectMainFile(project: workspaces.ProjectDefinition): string {
1515
const buildOptions = getProjectTargetOptions(project, 'build');
16-
if (!buildOptions.main) {
16+
if (!buildOptions.main && !buildOptions.browser) {
1717
throw new SchematicsException(`Could not find the project main file inside of the ` +
1818
`workspace config (${project.sourceRoot})`);
1919
}
2020

21-
return buildOptions.main.toString();
21+
return buildOptions.main?.toString() ?? buildOptions.browser.toString();
2222
}

0 commit comments

Comments
 (0)