Skip to content

Commit

Permalink
fix: do not dynamically import @o3r/rules-engine during rules-engine …
Browse files Browse the repository at this point in the history
…install (#2324)

## Proposed change
@o3r/schematics is not fully installed and not accessible during ng-add
schematics run. A relative import allows to access the library during
the installation process.

The use of composite in tsconfig.builders.json (current setup) allow to
make reference
to the dist/src folder without risking the override of the src build.
## Related issues

- 🐛 Fixes #2334

<!-- Please make sure to follow the contributing guidelines on
https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md -->
  • Loading branch information
cpaulve-1A authored Nov 20, 2024
2 parents 2322a59 + 0276322 commit f921d47
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions packages/@o3r/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ npm create @o3r my-project -- --package-manager=yarn
> [!TIP]
> Get more details on [@o3r/create](https://www.npmjs.com/package/@o3r/create).
> [!NOTE]
> If you want to add o3r to an existing project, you will first need to install @o3r/schematics via
> `ng add @o3r/schematics` and then `ng add @o3r/core`.
### Adding Material design theming

```shell
Expand Down
8 changes: 3 additions & 5 deletions packages/@o3r/schematics/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Rule } from '@angular-devkit/schematics';
import type { DependencyToAdd } from '@o3r/schematics';
import { createSchematicWithMetricsIfInstalled, type DependencyToAdd, getExternalDependenciesVersionRange, setupDependencies } from '../../src/public_api';
import { NodeDependencyType } from '@schematics/angular/utility/dependencies';
import * as path from 'node:path';
import type { NgAddSchematicsSchema } from './schema';
Expand All @@ -10,9 +10,8 @@ import type { NgAddSchematicsSchema } from './schema';
*/
function ngAddFn(options: NgAddSchematicsSchema): Rule {
const schematicsDependencies = ['@angular-devkit/architect', '@angular-devkit/schematics', '@angular-devkit/core', '@schematics/angular', 'globby'];
return async (_, context) => {
return (_, context) => {
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const { getExternalDependenciesVersionRange, setupDependencies } = await import('@o3r/schematics');
const dependencies = Object.entries(getExternalDependenciesVersionRange(schematicsDependencies, packageJsonPath, context.logger)).reduce((acc, [dep, range]) => {
acc[dep] = {
inManifest: [{
Expand Down Expand Up @@ -43,8 +42,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
* Add Otter schematics to an Angular Project
* @param options
*/
export const ngAdd = (options: NgAddSchematicsSchema): Rule => async () => {
const { createSchematicWithMetricsIfInstalled } = await import('@o3r/schematics');
export const ngAdd = (options: NgAddSchematicsSchema): Rule => () => {
return createSchematicWithMetricsIfInstalled(ngAddFn)(options);
};

3 changes: 2 additions & 1 deletion packages/@o3r/storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Otter framework provides 2 mechanisms to setup Storybook on an application/libra

### When starting a new Application/Library

When creating a new application/library (`ng new`), the Otter Framework can be added with the `ng add @o3r/core` command. When executing this command, the following question will be asked: *Add storybook setup?* (default value: `yes`).
When creating a new application/library (`ng new`), the Otter Framework can be added with the `ng add @o3r/schematics` and
`ng add @o3r/core` commands. When executing this command, the following question will be asked: *Add storybook setup?* (default value: `yes`).
If `yes` is chosen, [Storybook mandatory configurations](#storybook-mandatory-configurations) will be automatically added.

### Storybook mandatory configurations
Expand Down
27 changes: 27 additions & 0 deletions tools/github-actions/new-version/packaged-action/LICENSE.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f921d47

Please sign in to comment.