Skip to content

Commit

Permalink
fix: add missing devDep to schematics
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Nov 22, 2024
1 parent 4c351b1 commit 2cd00d3
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 11 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-ts": "~2.4.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-ts": "~2.4.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-ts": "~2.4.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-ts": "~2.4.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-ts": "~2.4.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 @@ -28,8 +28,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 @@ -44,15 +44,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
3 changes: 2 additions & 1 deletion packages/@o3r/components/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { updateCmsAdapter } from '../cms-adapter';
import type { NgAddSchematicsSchema } from './schema';
import { registerDevtools } from './helpers/devtools-registration';
import type { DependencyToAdd } from '@o3r/schematics';
import type { NodeDependencyType as NodeDependencyTypeEnum } from '@schematics/angular/utility/dependencies';

const reportMissingSchematicsDep = (logger: { error: (message: string) => any }) => (reason: any) => {
logger.error(`[ERROR]: Adding @o3r/components has failed.
Expand All @@ -31,7 +32,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
getPackageInstallConfig
} = await import('@o3r/schematics');
// eslint-disable-next-line @typescript-eslint/naming-convention
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
3 changes: 2 additions & 1 deletion packages/@o3r/extractors/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Rule } from '@angular-devkit/schematics';
import * as path from 'node:path';
import { updateCmsAdapter } from '../cms-adapter';
import type { NgAddSchematicsSchema } from './schema';
import type { NodeDependencyType as NodeDependencyTypeEnum } from '@schematics/angular/utility/dependencies';

const dependenciesToInstall = [
'semver'
Expand Down Expand Up @@ -30,7 +31,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
getWorkspaceConfig
} = await import('@o3r/schematics');
// eslint-disable-next-line @typescript-eslint/naming-convention
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
3 changes: 2 additions & 1 deletion packages/@o3r/localization/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'node:path';
import { updateCmsAdapter } from '../cms-adapter';
import type { NgAddSchematicsSchema } from './schema';
import { registerDevtools } from './helpers/devtools-registration';
import type { NodeDependencyType as NodeDependencyTypeEnum } from '@schematics/angular/utility/dependencies';

const dependenciesToInstall = [
'chokidar',
Expand Down Expand Up @@ -41,7 +42,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
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');
// eslint-disable-next-line @typescript-eslint/naming-convention
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies').catch(() => ({ NodeDependencyType: { Dev: 'devDependencies' as NodeDependencyTypeEnum.Dev } }));
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
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-ts": "~2.4.0",
"@types/jest": "~29.5.2",
"@types/node": "^20.0.0",
Expand All @@ -64,6 +66,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,4 +1,4 @@
import { chain, Rule } from '@angular-devkit/schematics';
import { chain, type Rule } from '@angular-devkit/schematics';
import * as ts from 'typescript';
import { insertImport, isImported } from '@schematics/angular/utility/ast-utils';
import { getAppModuleFilePath, getDefaultOptionsForSchematic, getMainFilePath, getModuleIndex, getWorkspaceConfig } from '../../utility/index';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { NodeDependencyType } from '@schematics/angular/utility/dependencies';
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import * as path from 'node:path';
import { lastValueFrom } from 'rxjs';
import type { PackageJson } from 'type-fest';
import type { NgAddPackageOptions } from '../../tasks/index';
import { getPackageManager } from '../../utility/index';
Expand Down Expand Up @@ -121,7 +120,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) => reject(errors)})

Check warning on line 125 in packages/@o3r/schematics/src/rule-factories/ng-add/ng-add.helpers.ts

View check run for this annotation

Codecov / codecov/patch

packages/@o3r/schematics/src/rule-factories/ng-add/ng-add.helpers.ts#L124-L125

Added lines #L124 - L125 were not covered by tests
);

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-otter": "workspace:^",
"@o3r/eslint-plugin": "workspace:^",
"@o3r/schematics": "workspace:^",
"@o3r/test-helpers": "workspace:^",
"@schematics/angular": "~18.2.0",
"@stylistic/eslint-plugin-ts": "~2.4.0",
Expand All @@ -81,6 +82,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
3 changes: 2 additions & 1 deletion packages/@o3r/stylelint-plugin/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Rule } from '@angular-devkit/schematics';
import type { NgAddSchematicsSchema } from './schema';
import * as path from 'node:path';
import type { NodeDependencyType as NodeDependencyTypeEnum } from '@schematics/angular/utility/dependencies';

const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json');
const dependenciesToInstall = [
Expand Down Expand Up @@ -32,7 +33,7 @@ function ngAddFn(options: NgAddSchematicsSchema): Rule {
setupDependencies
} = await import('@o3r/schematics');
// eslint-disable-next-line @typescript-eslint/naming-convention
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies');
const { NodeDependencyType } = await import('@schematics/angular/utility/dependencies').catch(() => ({ NodeDependencyType: { Dev: 'devDependencies' as NodeDependencyTypeEnum.Dev } }));
const depsInfo = getO3rPeerDeps(packageJsonPath);
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ __metadata:
"@nx/jest": "npm:~19.5.0"
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -354,6 +355,7 @@ __metadata:
"@nx/jest": "npm:~19.5.0"
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -426,6 +428,7 @@ __metadata:
"@nx/jest": "npm:~19.5.0"
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -501,6 +504,7 @@ __metadata:
"@nx/jest": "npm:~19.5.0"
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -7255,6 +7259,7 @@ __metadata:
"@o3r/build-helpers": "workspace:^"
"@o3r/core": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand Down Expand Up @@ -9287,7 +9292,9 @@ __metadata:
"@nx/jest": "npm:~19.5.0"
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
"@types/jest": "npm:~29.5.2"
"@types/node": "npm:^20.0.0"
Expand All @@ -9306,6 +9313,7 @@ __metadata:
jest-junit: "npm:~16.0.0"
nx: "npm:~19.5.0"
pid-from-port: "npm:^1.1.3"
rxjs: "npm:^7.8.1"
semver: "npm:^7.5.2"
ts-jest: "npm:~29.2.0"
ts-node: "npm:~10.9.2"
Expand Down Expand Up @@ -9672,6 +9680,8 @@ __metadata:
optional: true
eslint:
optional: true
rxjs:
optional: true
type-fest:
optional: true
bin:
Expand Down Expand Up @@ -9983,6 +9993,7 @@ __metadata:
"@o3r/build-helpers": "workspace:^"
"@o3r/eslint-config-otter": "workspace:^"
"@o3r/eslint-plugin": "workspace:^"
"@o3r/schematics": "workspace:^"
"@o3r/test-helpers": "workspace:^"
"@schematics/angular": "npm:~18.2.0"
"@stylistic/eslint-plugin-ts": "npm:~2.4.0"
Expand All @@ -10006,6 +10017,7 @@ __metadata:
postcss: "npm:~8.4.31"
postcss-scss: "npm:~4.0.9"
rimraf: "npm:^5.0.1"
rxjs: "npm:^7.8.1"
semver: "npm:^7.5.2"
stylelint: "npm:^16.0.2"
ts-jest: "npm:~29.2.0"
Expand Down

0 comments on commit 2cd00d3

Please sign in to comment.