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 20, 2024
1 parent a8f22fd commit fc53c8f
Show file tree
Hide file tree
Showing 22 changed files with 2,472 additions and 2,438 deletions.
1 change: 1 addition & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
],
"source": [
"base-build",
"{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
15 changes: 10 additions & 5 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,20 @@ 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 (isImported(sourceFile, 'prefersReducedMotion', '@o3r/application')) {
context.logger.info('[LOG]: prefersReducedMotion from @o3r/application is already imported.');
if (!sourceFile) {
context.logger.warn('No Typescript executor detected, the ng-add process will be skipped.');
return tree;
}

if (isImported?.(sourceFile, 'prefersReducedMotion', '@o3r/application')) {
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 } 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 NodeDependencyType.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 } 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 NodeDependencyType.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 } 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 NodeDependencyType.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,7 @@ export function ngAddPackages(packages: string[], options?: Omit<NgAddPackageOpt
hideOutput: false,
quiet: false
} as any));
await lastValueFrom(context.engine.executePostTasks());
await new Promise<void>((resolve) => context.engine.executePostTasks().subscribe({ complete: () => resolve() }));

Check warning on line 123 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#L123

Added line #L123 was 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 } 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 NodeDependencyType.Dev } }));
const depsInfo = getO3rPeerDeps(packageJsonPath);
const workspaceProject = options.projectName ? getWorkspaceConfig(tree)?.projects[options.projectName] : undefined;
const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => {
Expand Down
Loading

0 comments on commit fc53c8f

Please sign in to comment.