Skip to content

Commit

Permalink
Merge pull request #27235 from mshima/types
Browse files Browse the repository at this point in the history
fix types and enable type check for entire project
  • Loading branch information
DanielFran committed Sep 10, 2024
2 parents 79566aa + da6233c commit 19a9225
Show file tree
Hide file tree
Showing 77 changed files with 559 additions and 374 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default ts.config(
extends: [...ts.configs.recommended, ...ts.configs.stylistic],
languageOptions: {
parserOptions: {
project: ['./tsconfig.spec.json', './tsconfig.eslint.json'],
project: ['./tsconfig.spec.json'],
},
},
rules: {
Expand Down
10 changes: 5 additions & 5 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
* }
*
*/
addVendorSCSSStyle(style, comment) {
addVendorSCSSStyle(style, comment?) {
this.needleApi.clientAngular.addVendorSCSSStyle(style, comment);
}

Expand Down Expand Up @@ -392,15 +392,15 @@ export default class AngularGenerator extends BaseApplicationGenerator {
this.needleApi.clientAngular.addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu, jhiPrefix);
}

addEntitiesToMenu({ application, entities }: PostWritingEntitiesTaskParam) {
addEntitiesToMenu({ application, entities }: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const filePath = `${application.clientSrcDir}app/layouts/navbar/navbar.component.html`;
const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.');
const editCallback = addToEntitiesMenu({ application, entities });

this.editFile(filePath, { ignoreNonExisting }, editCallback);
}

addEntitiesToModule(param: PostWritingEntitiesTaskParam) {
addEntitiesToModule(param: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const filePath = `${param.application.clientSrcDir}app/entities/entity.routes.ts`;
const ignoreNonExisting = chalk.yellow(`Route(s) not added to ${filePath}.`);
const addRouteCallback = addEntitiesRoute(param);
Expand All @@ -427,7 +427,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
* }
*
*/
addMainSCSSStyle(style, comment) {
addMainSCSSStyle(style, comment?) {
this.needleApi.clientAngular.addGlobalSCSSStyle(style, comment);
}

Expand Down Expand Up @@ -504,7 +504,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
* @param {string} clientFramework - The name of the client framework
* @param {string} translationKeyMenu - i18n key for entry in the menu
*/
addElementToMenu(routerName, iconName, enableTranslation, clientFramework, translationKeyMenu = camelCase(routerName)) {
addElementToMenu(routerName, iconName, enableTranslation, _clientFramework?, translationKeyMenu = camelCase(routerName)) {
this.needleApi.clientAngular.addElementToMenu(routerName, iconName, enableTranslation, translationKeyMenu);
}
}
4 changes: 2 additions & 2 deletions generators/angular/needle-api/needle-client-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import { createNeedleCallback } from '../../base/support/needles.js';

const { ANGULAR } = clientFrameworkTypes;
export default class extends needleClientBase {
addGlobalSCSSStyle(style, comment) {
addGlobalSCSSStyle(style, comment?) {
const filePath = `${this.clientSrcDir}content/scss/global.scss`;
this.addStyle(style, comment, filePath, 'jhipster-needle-scss-add-main');
}

addVendorSCSSStyle(style, comment) {
addVendorSCSSStyle(style, comment?) {
const filePath = `${this.clientSrcDir}content/scss/vendor.scss`;
super.addStyle(style, comment, filePath, 'jhipster-needle-scss-add-vendor');
}
Expand Down
6 changes: 2 additions & 4 deletions generators/angular/support/needles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Entity } from '../../../lib/types/application/entity.js';
import type { BaseApplication } from '../../base-application/types.js';
import { createNeedleCallback } from '../../base/support/needles.js';
import { upperFirstCamelCase } from '../../../lib/utils/string.js';
import { joinCallbacks } from '../../base/support/write-files.js';
Expand Down Expand Up @@ -56,7 +54,7 @@ export function addRoute({
});
}

export function addEntitiesRoute({ application, entities }: PostWritingEntitiesTaskParam) {
export function addEntitiesRoute({ application, entities }: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const { enableTranslation } = application;
return joinCallbacks(
...entities.map(entity => {
Expand Down Expand Up @@ -128,7 +126,7 @@ export const addIconImport = ({ icon }: { icon: string }) => {
});
};

export function addToEntitiesMenu({ application, entities }: { application: BaseApplication; entities: Entity[] }) {
export function addToEntitiesMenu({ application, entities }: Pick<PostWritingEntitiesTaskParam, 'application' | 'entities'>) {
const { enableTranslation, jhiPrefix } = application;
return joinCallbacks(
...entities.map(entity => {
Expand Down
12 changes: 0 additions & 12 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
"eslintConfigFile": "eslint.config.mjs",
"fakerSeed": undefined,
"feignClient": false,
"fromInit": undefined,
"frontendAppName": "jhipsterApp",
"gatewayRoutes": undefined,
"gatewayServerPort": undefined,
Expand Down Expand Up @@ -595,7 +594,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
"microfrontend": false,
"microfrontends": undefined,
"monorepository": undefined,
"monorepositoryRoot": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
"angularLocale": "en",
Expand Down Expand Up @@ -726,7 +724,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
"packageJsonType": "commonjs",
"packageName": "com.mycompany.myapp",
"pages": [],
"prettierConfigFile": ".prettierrc",
"prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java,html,css,scss",
"prettierFolders": ",**/",
"prettierJava": undefined,
Expand Down Expand Up @@ -779,7 +776,6 @@ exports[`generator - app with default config should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": false,
"sortMavenPom": true,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
Expand Down Expand Up @@ -1073,7 +1069,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"eslintConfigFile": "eslint.config.mjs",
"fakerSeed": undefined,
"feignClient": false,
"fromInit": undefined,
"frontendAppName": "jhipsterApp",
"gatewayRoutes": [],
"gatewayServerPort": undefined,
Expand Down Expand Up @@ -1209,7 +1204,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"microfrontend": undefined,
"microfrontends": undefined,
"monorepository": undefined,
"monorepositoryRoot": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
"angularLocale": "en",
Expand Down Expand Up @@ -1340,7 +1334,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"packageJsonType": "commonjs",
"packageName": "com.mycompany.myapp",
"pages": [],
"prettierConfigFile": ".prettierrc",
"prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java,html,css,scss",
"prettierFolders": ",**/",
"prettierJava": undefined,
Expand Down Expand Up @@ -1395,7 +1388,6 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": false,
"sortMavenPom": true,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
Expand Down Expand Up @@ -1686,7 +1678,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"entitySuffix": "",
"fakerSeed": undefined,
"feignClient": false,
"fromInit": undefined,
"frontendAppName": "jhipsterApp",
"gatewayRoutes": undefined,
"gatewayServerPort": undefined,
Expand Down Expand Up @@ -1828,7 +1819,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"microfrontend": false,
"microfrontends": undefined,
"monorepository": undefined,
"monorepositoryRoot": undefined,
"nativeLanguage": "en",
"nativeLanguageDefinition": {
"angularLocale": "en",
Expand Down Expand Up @@ -1900,7 +1890,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"packageJsonType": "commonjs",
"packageName": "com.mycompany.myapp",
"pages": [],
"prettierConfigFile": ".prettierrc",
"prettierExtensions": "md,json,yml,js,cjs,mjs,ts,cts,mts,java",
"prettierFolders": ",**/",
"prettierJava": undefined,
Expand Down Expand Up @@ -1953,7 +1942,6 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"skipJhipsterDependencies": undefined,
"skipServer": undefined,
"skipUserManagement": true,
"sortMavenPom": true,
"springBootDependencies": Any<Object>,
"srcMainDir": "src/main/",
"srcMainJava": "src/main/java/",
Expand Down
5 changes: 5 additions & 0 deletions generators/app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const command = {
defaults: {
description: 'Execute jhipster with default config',
type: Boolean,
scope: 'none',
},
skipClient: {
description: 'Skip the client-side application generation',
Expand Down Expand Up @@ -62,15 +63,18 @@ const command = {
blueprint: {
description: 'DEPRECATED: Specify a generator blueprint to use for the sub generators',
type: Array,
scope: 'none',
},
blueprints: {
description:
'A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs',
type: String,
scope: 'none',
},
ignoreErrors: {
description: "Don't fail on prettier errors.",
type: Boolean,
scope: 'none',
},
pkType: {
description: 'Default primary key type (beta)',
Expand All @@ -85,6 +89,7 @@ const command = {
testFrameworks: {
description: 'Test frameworks to be generated',
type: Array,
scope: 'none',
},
},
import: [
Expand Down
4 changes: 2 additions & 2 deletions generators/base-application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe(`generator - ${generator}`, () => {
}

before(async () => {
await helpers.run(CustomGenerator).withJHipsterConfig({}, [
await helpers.run(CustomGenerator as any).withJHipsterConfig({}, [
{
name: 'One',
fields: [{ fieldName: 'id', fieldType: 'Long' }],
Expand Down Expand Up @@ -396,7 +396,7 @@ describe(`generator - ${generator}`, () => {

before(async () => {
await helpers
.run(CustomGenerator)
.run(CustomGenerator as any)
.withJHipsterConfig({}, [
{
name: 'One',
Expand Down
6 changes: 4 additions & 2 deletions generators/base-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type { Entity } from '../../lib/types/application/entity.js';
import type { Entity as BaseEntity } from '../../lib/types/base/entity.js';
import type { GenericTaskGroup } from '../../lib/types/base/tasks.js';
import type { ApplicationConfiguration } from '../../lib/types/application/yo-rc.js';
import type SharedData from '../base/shared-data.js';
import { getEntitiesFromDir } from './support/index.js';
import { CUSTOM_PRIORITIES, PRIORITY_NAMES, QUEUES } from './priorities.js';

Expand Down Expand Up @@ -75,8 +76,8 @@ const asPriority = BaseGenerator.asPriority;
* This is the base class for a generator that generates entities.
*/
export default class BaseApplicationGenerator<
E = Entity,
A = ApplicationType<E>,
E extends Entity = Entity,
A extends ApplicationType<E> = ApplicationType<E>,
TaskTypes extends DefaultTaskTypes<any, any> = DefaultTaskTypes<E, A>,
> extends BaseGenerator<TaskTypes> {
static CONFIGURING_EACH_ENTITY = asPriority(CONFIGURING_EACH_ENTITY);
Expand All @@ -96,6 +97,7 @@ export default class BaseApplicationGenerator<
static POST_WRITING_ENTITIES = asPriority(POST_WRITING_ENTITIES);

declare jhipsterConfig: ApplicationConfiguration & Record<string, any>;
declare sharedData: SharedData<A>;

constructor(args: string | string[], options: JHipsterGeneratorOptions, features: JHipsterGeneratorFeatures) {
super(args, options, features);
Expand Down
8 changes: 5 additions & 3 deletions generators/base-core/generator-core.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('generator - base-core', () => {
let Dummy;
beforeEach(async () => {
await helpers.prepareTemporaryDir();
Dummy = helpers.createDummyGenerator(Base);
Dummy = helpers.createDummyGenerator(Base as any);
});

it('no argument', async () => {
Expand Down Expand Up @@ -77,7 +77,8 @@ describe('generator - base-core', () => {
},
});
jestExpect(base.first).toBe('bar');
jestExpect(base.jdlFiles).toMatchObject(['foo']);
jestExpect(base.jdlFiles).toHaveLength(1);
jestExpect(base.jdlFiles[0]).toMatch('foo');
});
it('vararg arguments using positionalArguments', async () => {
const base = new Dummy({ positionalArguments: ['bar', ['foo']], sharedData: {}, env: await helpers.createTestEnv() });
Expand All @@ -90,7 +91,8 @@ describe('generator - base-core', () => {
},
});
jestExpect(base.first).toBe('bar');
jestExpect(base.jdlFiles).toMatchObject(['foo']);
jestExpect(base.jdlFiles).toHaveLength(1);
jestExpect(base.jdlFiles[0]).toBe('foo');
});
});
});
19 changes: 14 additions & 5 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
convertConfigToOption,
} from '../../lib/command/index.js';
import { packageJson } from '../../lib/index.js';
import type { BaseApplication, CommonClientServerApplication } from '../base-application/types.js';
import type { BaseApplication } from '../base-application/types.js';
import { GENERATOR_BOOTSTRAP } from '../generator-list.js';
import NeedleApi from '../needle-api.js';
import command from '../base/command.js';
Expand All @@ -66,7 +66,6 @@ import { getGradleLibsVersionsProperties } from '../gradle/support/dependabot-gr
import { dockerPlaceholderGenerator } from '../docker/utils.js';
import { getConfigWithDefaults } from '../../lib/jhipster/index.js';
import { extractArgumentsFromConfigs } from '../../lib/command/index.js';
import type { Entity } from '../../lib/types/base/entity.js';
import type BaseApplicationGenerator from '../base-application/generator.js';
import type { ApplicationConfiguration } from '../../lib/types/application/yo-rc.js';

Expand Down Expand Up @@ -133,6 +132,7 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti

static END = asPriority(END);

context?: Record<string, any>;
useVersionPlaceholders?: boolean;
skipChecks?: boolean;
ignoreNeedlesError?: boolean;
Expand All @@ -142,7 +142,7 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
relativeDir = relativeDir;
relative = posixRelative;

readonly sharedData!: SharedData<CommonClientServerApplication<Entity>>;
readonly sharedData!: SharedData<any>;
readonly logger: Logger;
jhipsterConfig!: Record<string, any>;
/**
Expand Down Expand Up @@ -544,7 +544,9 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
this.sharedData.getControl()[optionName] = optionValue;
} else if (optionDesc.scope === 'generator') {
this[optionName] = optionValue;
} else {
} else if (optionDesc.scope === 'context') {
this.context![optionName] = optionValue;
} else if (optionDesc.scope !== 'none') {
throw new Error(`Scope ${optionDesc.scope} not supported`);
}
} else if (optionDesc.default && optionDesc.scope === 'generator' && this[optionName] === undefined) {
Expand Down Expand Up @@ -574,8 +576,10 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
}
if (argument !== undefined) {
const convertedValue = !argumentDef.type || argumentDef.type === Array ? argument : argumentDef.type(argument);
if ((argumentDef.scope ?? 'generator') === 'generator') {
if (argumentDef.scope === undefined || argumentDef.scope === 'generator') {
this[argumentName] = convertedValue;
} else if (argumentDef.scope === 'context') {
this.context![argumentName] = convertedValue;
} else if (argumentDef.scope === 'storage') {
this.config.set(argumentName, convertedValue);
} else if (argumentDef.scope === 'blueprint') {
Expand Down Expand Up @@ -613,6 +617,11 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
getPath: path => get(this, path),
setPath: (path, value) => set(this, path, value),
};
} else if (def.scope === 'context') {
storage = {
getPath: path => get(this.context, path),
setPath: (path, value) => set(this.context!, path, value),
};
}
return {
name,
Expand Down
9 changes: 4 additions & 5 deletions generators/base-entity-changes/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,10 @@ type TaskTypes<E, A> = ApplicationTaskTypes<E, A> & {
/**
* This is the base class for a generator for every generator.
*/
export default abstract class GeneratorBaseEntityChanges<E = Entity, A = ApplicationType<E>> extends GeneratorBaseApplication<
E,
A,
TaskTypes<E, A>
> {
export default abstract class GeneratorBaseEntityChanges<
E extends Entity = Entity,
A extends ApplicationType<E> = ApplicationType<E>,
> extends GeneratorBaseApplication<E, A, TaskTypes<E, A>> {
recreateInitialChangelog!: boolean;
private entityChanges!: any[];

Expand Down
Loading

0 comments on commit 19a9225

Please sign in to comment.