Skip to content

Commit

Permalink
fix: add missing devDep to schematics (#2491)
Browse files Browse the repository at this point in the history
## Proposed change

fix: add missing devDep to schematics

<!--
Please include a summary of the changes and the related issue.
Please also include relevant motivation and context.
-->

## Related issues

<!--
Please make sure to follow the [contribution
guidelines](https://github.com/amadeus-digital/Otter/blob/main/CONTRIBUTING.md)
-->

*- No issue associated -*

<!-- * 🐛 Fix #issue -->
<!-- * 🐛 Fix resolves #issue -->
<!-- * 🚀 Feature #issue -->
<!-- * 🚀 Feature resolves #issue -->
<!-- * :octocat: Pull Request #issue -->
  • Loading branch information
kpanot authored Dec 2, 2024
2 parents 378e033 + 023f3b9 commit 8a9fa82
Show file tree
Hide file tree
Showing 18 changed files with 279 additions and 202 deletions.
1 change: 1 addition & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
],
"source": [
"base",
"{projectRoot}/ng-package.json",
"{projectRoot}/tsconfig.build.json",
"{projectRoot}/tsconfig.build.*.json",
"{projectRoot}/src/**/*",
Expand Down
1 change: 1 addition & 0 deletions packages/@ama-sdk/client-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@ama-sdk/client-beacon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@ama-sdk/client-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@ama-sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@o3r/build-helpers": "workspace:^",
"@o3r/core": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down
18 changes: 14 additions & 4 deletions packages/@o3r/application/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
getProjectNewDependenciesTypes,
getPackageInstallConfig
} = await import('@o3r/schematics');
const { isImported } = await import('@schematics/angular/utility/ast-utils');
const ts = await import('typescript');
const { isImported } = await import('@schematics/angular/utility/ast-utils').catch(() => ({ isImported: undefined }));
const ts = await import('typescript').catch(() => undefined);
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const depsInfo = getO3rPeerDeps(packageJsonPath);

Expand All @@ -56,15 +56,25 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
}

const sourceFileContent = tree.readText(moduleFilePath);
const sourceFile = ts.createSourceFile(
const sourceFile = ts?.createSourceFile(
moduleFilePath,
sourceFileContent,
ts.ScriptTarget.ES2015,
true
);

if (!sourceFile) {
context.logger.warn('No Typescript executor detected, the ng-add process will be skipped.');
return tree;
}

if (!isImported) {
context.logger.warn('No @schematics/angular dependency detected, the ng-add process will be skipped.');
return tree;
}

if (isImported(sourceFile, 'prefersReducedMotion', '@o3r/application')) {
context.logger.info('[LOG]: prefersReducedMotion from @o3r/application is already imported.');
context.logger.info('prefersReducedMotion from @o3r/application is already imported.');
return tree;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/@o3r/components/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {
import type {
DependencyToAdd,
} from '@o3r/schematics';
import type {
NodeDependencyType as NodeDependencyTypeEnum,
} from '@schematics/angular/utility/dependencies';
import {
updateCmsAdapter,
} from '../cms-adapter';
Expand Down Expand Up @@ -43,7 +46,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
registerPackageCollectionSchematics,
getPackageInstallConfig
} = await import('@o3r/schematics');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies').catch(() => ({ NodeDependencyType: { Dev: 'devDependencies' as NodeDependencyTypeEnum.Dev } }));
options = { ...getDefaultOptionsForSchematic(getWorkspaceConfig(tree), '@o3r/components', 'ng-add', options), ...options };
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf8' }));
Expand Down
5 changes: 4 additions & 1 deletion packages/@o3r/extractors/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
import type {
Rule,
} from '@angular-devkit/schematics';
import type {
NodeDependencyType as NodeDependencyTypeEnum,
} from '@schematics/angular/utility/dependencies';
import {
updateCmsAdapter,
} from '../cms-adapter';
Expand Down Expand Up @@ -37,7 +40,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
getO3rPeerDeps,
getWorkspaceConfig
} = await import('@o3r/schematics');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies').catch(() => ({ NodeDependencyType: { Dev: 'devDependencies' as NodeDependencyTypeEnum.Dev } }));
const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const depsInfo = getO3rPeerDeps(packageJsonPath);
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/localization/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
const depsInfo = getO3rPeerDeps(packageJsonPath);
context.logger.info(`The package ${depsInfo.packageName as string} comes with a debug mechanism`);
context.logger.info('Get information on https://github.com/AmadeusITGroup/otter/tree/main/docs/localization/LOCALIZATION.md#Debugging');

const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/@o3r/new-version/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"@nx/jest": "~19.5.0",
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
"@types/jest": "~29.5.2",
"@types/node": "^20.0.0",
Expand All @@ -68,6 +70,7 @@
"jest-junit": "~16.0.0",
"nx": "~19.5.0",
"pid-from-port": "^1.1.3",
"rxjs": "^7.8.1",
"semver": "^7.5.2",
"ts-jest": "~29.2.0",
"ts-node": "~10.9.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/@o3r/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"eslint": {
"optional": true
},
"rxjs": {
"optional": true
},
"type-fest": {
"optional": true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
chain,
Rule,
type Rule,
} from '@angular-devkit/schematics';
import {
isImported,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ import {
chain,
externalSchematic,
noop,
Rule,
Schematic,
SchematicContext,
type Rule,
type Schematic,
type SchematicContext,
} from '@angular-devkit/schematics';
import {
NodePackageInstallTask,
} from '@angular-devkit/schematics/tasks';
import {
NodeDependencyType,
} from '@schematics/angular/utility/dependencies';
import {
lastValueFrom,
} from 'rxjs';
import type {
PackageJson,
} from 'type-fest';
Expand Down Expand Up @@ -145,7 +142,10 @@ export function ngAddPackages(packages: string[], options?: Omit<NgAddPackageOpt
hideOutput: false,
quiet: false
} as any));
await lastValueFrom(context.engine.executePostTasks());

await new Promise<void>((resolve, reject) =>
context.engine.executePostTasks().subscribe({ next: () => { /* don't store data */ }, complete: () => resolve(), error: (errors: Error) => reject(errors) })
);

const ngAddsToApply = packagesToInstall
.map((packageName) => ({ packageName, ngAddCollection: getNgAddSchema(packageName, context) }))
Expand Down
2 changes: 2 additions & 0 deletions packages/@o3r/stylelint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@o3r/build-helpers": "workspace:^",
"@o3r/eslint-config": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin": "~2.7.0",
Expand Down Expand Up @@ -85,6 +86,7 @@
"postcss": "~8.4.31",
"postcss-scss": "~4.0.9",
"rimraf": "^5.0.1",
"rxjs": "^7.8.1",
"semver": "^7.5.2",
"stylelint": "^16.0.2",
"ts-jest": "~29.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@o3r/stylelint-plugin/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
getWorkspaceConfig,
setupDependencies
} = await import('@o3r/schematics');

const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const depsInfo = getO3rPeerDeps(packageJsonPath);
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
Expand Down
27 changes: 0 additions & 27 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.

Loading

0 comments on commit 8a9fa82

Please sign in to comment.