diff --git a/modules/component-store/schematics-core/utility/standalone.ts b/modules/component-store/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/component-store/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/component/schematics-core/utility/standalone.ts b/modules/component/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/component/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/data/schematics-core/utility/standalone.ts b/modules/data/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/data/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/effects/schematics-core/utility/standalone.ts b/modules/effects/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/effects/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/effects/schematics/ng-add/index.spec.ts b/modules/effects/schematics/ng-add/index.spec.ts index dcbcf6aab5..0d811bc129 100644 --- a/modules/effects/schematics/ng-add/index.spec.ts +++ b/modules/effects/schematics/ng-add/index.spec.ts @@ -231,7 +231,6 @@ describe('Effects ng-add Schematic', () => { const standaloneDefaultOptions = { ...defaultOptions, project: 'bar-standalone', - standalone: true, }; it('provides minimal effects setup', async () => { diff --git a/modules/effects/schematics/ng-add/index.ts b/modules/effects/schematics/ng-add/index.ts index a078e76d3b..33526bb298 100644 --- a/modules/effects/schematics/ng-add/index.ts +++ b/modules/effects/schematics/ng-add/index.ts @@ -33,6 +33,7 @@ import { callsProvidersFunction, } from '@schematics/angular/private/standalone'; import { getProjectMainFile } from '../../schematics-core/utility/project'; +import { isStandaloneApp } from '../../schematics-core/utility/standalone'; function addImportToNgModule(options: EffectOptions): Rule { return (host: Tree) => { @@ -199,9 +200,12 @@ function addStandaloneConfig(options: EffectOptions): Rule { export default function (options: EffectOptions): Rule { return (host: Tree, context: SchematicContext) => { + const mainFile = getProjectMainFile(host, options); + const isStandalone = isStandaloneApp(host, mainFile); + options.path = getProjectPath(host, options); - if (options.module && !options.standalone) { + if (options.module && !isStandalone) { options.module = findModuleFromOptions(host, options); } @@ -226,7 +230,7 @@ export default function (options: EffectOptions): Rule { move(parsedPath.path), ]); - const configOrModuleUpdate = options.standalone + const configOrModuleUpdate = isStandalone ? addStandaloneConfig(options) : addImportToNgModule(options); diff --git a/modules/effects/schematics/ng-add/schema.json b/modules/effects/schematics/ng-add/schema.json index 27c6686a36..225c2a54c4 100644 --- a/modules/effects/schematics/ng-add/schema.json +++ b/modules/effects/schematics/ng-add/schema.json @@ -55,11 +55,6 @@ "type": "boolean", "default": true, "description": "Setup root effects module without registering initial effects." - }, - "standalone": { - "type": "boolean", - "default": false, - "description": "Configure @ngrx/effects for standalone application" } }, "required": [] diff --git a/modules/effects/schematics/ng-add/schema.ts b/modules/effects/schematics/ng-add/schema.ts index 8457cfe811..1ba2f9d1e2 100644 --- a/modules/effects/schematics/ng-add/schema.ts +++ b/modules/effects/schematics/ng-add/schema.ts @@ -11,5 +11,4 @@ export interface Schema { * Setup root effects module without registering initial effects. */ minimal?: boolean; - standalone?: boolean; } diff --git a/modules/entity/schematics-core/utility/standalone.ts b/modules/entity/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/entity/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/router-store/schematics-core/utility/standalone.ts b/modules/router-store/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/router-store/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/router-store/schematics/ng-add/index.spec.ts b/modules/router-store/schematics/ng-add/index.spec.ts index 8365889669..1bdb53d788 100644 --- a/modules/router-store/schematics/ng-add/index.spec.ts +++ b/modules/router-store/schematics/ng-add/index.spec.ts @@ -85,7 +85,6 @@ describe('Router Store ng-add Schematic', () => { const standaloneDefaultOptions = { ...defaultOptions, project: 'bar-standalone', - standalone: true, }; it('provides initial setup', async () => { diff --git a/modules/router-store/schematics/ng-add/index.ts b/modules/router-store/schematics/ng-add/index.ts index b46ccb3701..275f9076e9 100644 --- a/modules/router-store/schematics/ng-add/index.ts +++ b/modules/router-store/schematics/ng-add/index.ts @@ -25,6 +25,7 @@ import { callsProvidersFunction, } from '@schematics/angular/private/standalone'; import { getProjectMainFile } from '../../schematics-core/utility/project'; +import { isStandaloneApp } from '../../schematics-core/utility/standalone'; function addImportToNgModule(options: RouterStoreOptions): Rule { return (host: Tree) => { @@ -130,9 +131,12 @@ function addStandaloneConfig(options: RouterStoreOptions): Rule { export default function (options: RouterStoreOptions): Rule { return (host: Tree, context: SchematicContext) => { + const mainFile = getProjectMainFile(host, options); + const isStandalone = isStandaloneApp(host, mainFile); + options.path = getProjectPath(host, options); - if (options.module && !options.standalone) { + if (options.module && !isStandalone) { options.module = findModuleFromOptions(host, { name: '', module: options.module, @@ -143,7 +147,7 @@ export default function (options: RouterStoreOptions): Rule { const parsedPath = parseName(options.path, ''); options.path = parsedPath.path; - const configOrModuleUpdate = options.standalone + const configOrModuleUpdate = isStandalone ? addStandaloneConfig(options) : addImportToNgModule(options); diff --git a/modules/router-store/schematics/ng-add/schema.json b/modules/router-store/schematics/ng-add/schema.json index 9c810e43ad..1cca53d9cb 100644 --- a/modules/router-store/schematics/ng-add/schema.json +++ b/modules/router-store/schematics/ng-add/schema.json @@ -29,11 +29,6 @@ "description": "Allows specification of the declaring module.", "alias": "m", "subtype": "filepath" - }, - "standalone": { - "type": "boolean", - "default": false, - "description": "Configure @ngrx/router-store for standalone application" } }, "required": [] diff --git a/modules/router-store/schematics/ng-add/schema.ts b/modules/router-store/schematics/ng-add/schema.ts index 5d62f487dd..14969b929e 100644 --- a/modules/router-store/schematics/ng-add/schema.ts +++ b/modules/router-store/schematics/ng-add/schema.ts @@ -3,5 +3,4 @@ export interface Schema { path?: string; project?: string; module?: string; - standalone?: string; } diff --git a/modules/schematics-core/utility/standalone.ts b/modules/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/schematics/schematics-core/utility/standalone.ts b/modules/schematics/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/schematics/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/store-devtools/schematics-core/utility/standalone.ts b/modules/store-devtools/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/store-devtools/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/store-devtools/schematics/ng-add/index.spec.ts b/modules/store-devtools/schematics/ng-add/index.spec.ts index 2a01da4ee6..7571d5a99c 100644 --- a/modules/store-devtools/schematics/ng-add/index.spec.ts +++ b/modules/store-devtools/schematics/ng-add/index.spec.ts @@ -134,7 +134,6 @@ describe('Store-Devtools ng-add Schematic', () => { const standaloneDefaultOptions = { ...defaultOptions, project: 'bar-standalone', - standalone: true, }; it('provides initial setup', async () => { diff --git a/modules/store-devtools/schematics/ng-add/index.ts b/modules/store-devtools/schematics/ng-add/index.ts index a8d7c882dc..50358121d5 100644 --- a/modules/store-devtools/schematics/ng-add/index.ts +++ b/modules/store-devtools/schematics/ng-add/index.ts @@ -25,6 +25,7 @@ import { callsProvidersFunction, } from '@schematics/angular/private/standalone'; import { getProjectMainFile } from '../../schematics-core/utility/project'; +import { isStandaloneApp } from '../../schematics-core/utility/standalone'; function addImportToNgModule(options: StoreDevtoolsOptions): Rule { return (host: Tree) => { @@ -154,9 +155,12 @@ function addStandaloneConfig(options: StoreDevtoolsOptions): Rule { export default function (options: StoreDevtoolsOptions): Rule { return (host: Tree, context: SchematicContext) => { + const mainFile = getProjectMainFile(host, options); + const isStandalone = isStandaloneApp(host, mainFile); + options.path = getProjectPath(host, options); - if (options.module && !options.standalone) { + if (options.module && !isStandalone) { options.module = findModuleFromOptions(host, { name: '', module: options.module, @@ -173,7 +177,7 @@ export default function (options: StoreDevtoolsOptions): Rule { ); } - const configOrModuleUpdate = options.standalone + const configOrModuleUpdate = isStandalone ? addStandaloneConfig(options) : addImportToNgModule(options); diff --git a/modules/store-devtools/schematics/ng-add/schema.json b/modules/store-devtools/schematics/ng-add/schema.json index efb1aea9f8..d3695b609b 100644 --- a/modules/store-devtools/schematics/ng-add/schema.json +++ b/modules/store-devtools/schematics/ng-add/schema.json @@ -39,11 +39,6 @@ "type": "boolean", "default": false, "description": "boolean - pauses recording actions and state changes when the extension window is not open." - }, - "standalone": { - "type": "boolean", - "default": false, - "description": "Configure @ngrx/store-devtools for standalone application" } }, "required": [] diff --git a/modules/store-devtools/schematics/ng-add/schema.ts b/modules/store-devtools/schematics/ng-add/schema.ts index d99d70d13a..4a73e53f76 100644 --- a/modules/store-devtools/schematics/ng-add/schema.ts +++ b/modules/store-devtools/schematics/ng-add/schema.ts @@ -5,5 +5,4 @@ export interface Schema { module?: string; maxAge?: number; autoPause?: boolean; - standalone?: boolean; } diff --git a/modules/store/schematics-core/utility/standalone.ts b/modules/store/schematics-core/utility/standalone.ts new file mode 100644 index 0000000000..5262a80473 --- /dev/null +++ b/modules/store/schematics-core/utility/standalone.ts @@ -0,0 +1,15 @@ +import * as ts from 'typescript'; +import { Tree } from '@angular-devkit/schematics'; +import { findBootstrapApplicationCall } from '@schematics/angular/private/standalone'; + +export function isStandaloneApp(host: Tree, mainPath: string): boolean { + const source = ts.createSourceFile( + mainPath, + host.readText(mainPath), + ts.ScriptTarget.Latest, + true + ); + const bootstrapCall = findBootstrapApplicationCall(source); + + return bootstrapCall !== null; +} diff --git a/modules/store/schematics/ng-add/index.spec.ts b/modules/store/schematics/ng-add/index.spec.ts index 15a31f9d7e..bf32bd73b8 100644 --- a/modules/store/schematics/ng-add/index.spec.ts +++ b/modules/store/schematics/ng-add/index.spec.ts @@ -169,7 +169,6 @@ describe('Store ng-add Schematic', () => { const standaloneDefaultOptions = { ...defaultOptions, project: 'bar-standalone', - standalone: true, }; it('provides minimal store setup', async () => { diff --git a/modules/store/schematics/ng-add/index.ts b/modules/store/schematics/ng-add/index.ts index 831f912802..f5393edb34 100644 --- a/modules/store/schematics/ng-add/index.ts +++ b/modules/store/schematics/ng-add/index.ts @@ -36,6 +36,7 @@ import { callsProvidersFunction, } from '@schematics/angular/private/standalone'; import { getProjectMainFile } from '../../schematics-core/utility/project'; +import { isStandaloneApp } from '../../schematics-core/utility/standalone'; function addImportToNgModule(options: RootStoreOptions): Rule { return (host: Tree) => { @@ -212,12 +213,15 @@ function addStandaloneConfig(options: RootStoreOptions): Rule { export default function (options: RootStoreOptions): Rule { return (host: Tree, context: SchematicContext) => { + const mainFile = getProjectMainFile(host, options); + const isStandalone = isStandaloneApp(host, mainFile); + options.path = getProjectPath(host, options); const parsedPath = parseName(options.path, ''); options.path = parsedPath.path; - if (options.module && !options.standalone) { + if (options.module && !isStandalone) { options.module = findModuleFromOptions(host, { name: '', module: options.module, @@ -238,7 +242,7 @@ export default function (options: RootStoreOptions): Rule { move(parsedPath.path), ]); - const configOrModuleUpdate = options.standalone + const configOrModuleUpdate = isStandalone ? addStandaloneConfig(options) : addImportToNgModule(options); diff --git a/modules/store/schematics/ng-add/schema.json b/modules/store/schematics/ng-add/schema.json index fa63df003d..9135513c3d 100644 --- a/modules/store/schematics/ng-add/schema.json +++ b/modules/store/schematics/ng-add/schema.json @@ -49,11 +49,6 @@ "type": "boolean", "default": false, "description": "Do not register the NgRx ESLint Plugin." - }, - "standalone": { - "type": "boolean", - "default": false, - "description": "Configure store for standalone application" } }, "required": [] diff --git a/modules/store/schematics/ng-add/schema.ts b/modules/store/schematics/ng-add/schema.ts index a95b629451..d2725b4910 100644 --- a/modules/store/schematics/ng-add/schema.ts +++ b/modules/store/schematics/ng-add/schema.ts @@ -10,5 +10,4 @@ export interface Schema { */ minimal?: boolean; skipESLintPlugin?: boolean; - standalone?: boolean; } diff --git a/projects/ngrx.io/content/guide/effects/install.md b/projects/ngrx.io/content/guide/effects/install.md index 25cf122dd6..dec96be203 100644 --- a/projects/ngrx.io/content/guide/effects/install.md +++ b/projects/ngrx.io/content/guide/effects/install.md @@ -19,14 +19,13 @@ ng add @ngrx/effects@latest | `--module` | Name of file containing the module that you wish to add the import for the `EffectsModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts` | `string` | `app` | `--minimal` | When true, only provide minimal setup for the root effects setup. Only registers `EffectsModule.forRoot()` in the provided `module` with an empty array. | `boolean` | `true` | `--group` | Group effects file within `effects` folder. | `boolean` | `false` -| `--standalone` | Flag to configure `@ngrx/effects` in the standalone application config. | `boolean` |`false` | This command will automate the following steps: 1. Update `package.json` > `dependencies` with `@ngrx/effects`. 2. Run `npm install` to install those dependencies. 3. Update your `src/app/app.module.ts` > `imports` array with `EffectsModule.forRoot([AppEffects])`. If you provided flags then the command will attempt to locate and update module found by the flags. -4. If the flag `--standalone` is provided, it adds `provideEffects()` into the application config. +4. If the project is using a `standalone bootstrap`, it adds `provideEffects()` into the application config. ## Installing with `npm` diff --git a/projects/ngrx.io/content/guide/router-store/install.md b/projects/ngrx.io/content/guide/router-store/install.md index b87d505d6d..811c0559e4 100644 --- a/projects/ngrx.io/content/guide/router-store/install.md +++ b/projects/ngrx.io/content/guide/router-store/install.md @@ -15,14 +15,13 @@ ng add @ngrx/router-store@latest | `--path` | Path to the module that you wish to add the import for the `StoreRouterConnectingModule` to. | `string` | | `--project` | Name of the project defined in your `angular.json` to help locating the module to add the `StoreRouterConnectingModule` to. | `string` | `--module` | Name of file containing the module that you wish to add the import for the `StoreRouterConnectingModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`. | `string` | `app` -| `--standalone` | Flag to configure `@ngrx/router-store` in the standalone application config. | `boolean` |`false` | This command will automate the following steps: 1. Update `package.json` > `dependencies` with `@ngrx/router-store`. 2. Run `npm install` to install those dependencies. 3. By default, will update `src/app/app.module.ts` > `imports` array with `StoreRouterConnectingModule.forRoot()`. If you provided flags then the command will attempt to locate and update module found by the flags. -4. If the flag `--standalone` is provided, it adds `provideRouterStore()` into the application config. +4. If the project is using a `standalone bootstrap`, it adds `provideRouterStore()` into the application config. ## Installing with `npm` diff --git a/projects/ngrx.io/content/guide/store-devtools/install.md b/projects/ngrx.io/content/guide/store-devtools/install.md index 1b999a7960..5163871d4f 100644 --- a/projects/ngrx.io/content/guide/store-devtools/install.md +++ b/projects/ngrx.io/content/guide/store-devtools/install.md @@ -16,14 +16,13 @@ ng add @ngrx/store-devtools@latest | `--project` | Name of the project defined in your `angular.json` to help locating the module to add the `StoreDevtoolsModule` to. | `string` | | `--module` | Name of file containing the module that you wish to add the import for the `StoreDevtoolsModule` to. Can also include the relative path to the file. For example, `src/app/app.module.ts`. | `string` | `app` | `--maxAge` | Maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance. 0 is infinite. Must be greater than 1 or 0. | `number` | `25` -| `--standalone` | Flag to configure `@ngrx/store-devtools` in the standalone application config. | `boolean` |`false` | This command will automate the following steps: 1. Update `package.json` > `dependencies` with `@ngrx/store-devtools`. 2. Run `npm install` to install those dependencies. 3. Update your `src/app.module.ts` > `imports` array with `StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: !isDevMode() })`. The maxAge property will be set to the flag `maxAge` if provided. -4. If the flag `--standalone` is provided, it adds `provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode() })` into the application config. +4. If the project is using a `standalone bootstrap`, it adds `provideStoreDevtools({ maxAge: 25, logOnly: !isDevMode() })` into the application config. ## Installing with `npm` diff --git a/projects/ngrx.io/content/guide/store/install.md b/projects/ngrx.io/content/guide/store/install.md index 4488d1201b..eccfb7f980 100644 --- a/projects/ngrx.io/content/guide/store/install.md +++ b/projects/ngrx.io/content/guide/store/install.md @@ -17,14 +17,13 @@ ng add @ngrx/store@latest | `--minimal` | Flag to only provide minimal setup for the root state management. Only registers `StoreModule.forRoot()` in the provided `module` with an empty object, and default runtime checks. | `boolean` |`true` | `--statePath` | The file path to create the state in. | `string` | `reducers` | | `--stateInterface` | The type literal of the defined interface for the state. | `string` | `State` | -| `--standalone` | Flag to configure store for standalone application. | `boolean` |`false` | This command will automate the following steps: 1. Update `package.json` > `dependencies` with `@ngrx/store`. 2. Run `npm install` to install those dependencies. 3. Update your `src/app/app.module.ts` > `imports` array with `StoreModule.forRoot({})` -4. If the flag `--standalone` is provided, it adds `provideStore()` into the application config. +4. If the project is using a `standalone bootstrap`, it adds `provideStore()` into the application config. ```sh ng add @ngrx/store@latest --no-minimal