Skip to content

Commit

Permalink
Merge pull request jhipster#25708 from mshima/lodash
Browse files Browse the repository at this point in the history
rework lodash-es imports
  • Loading branch information
DanielFran authored Apr 2, 2024
2 parents ee86179 + 7b273e8 commit 9387b1d
Show file tree
Hide file tree
Showing 97 changed files with 173 additions and 309 deletions.
4 changes: 1 addition & 3 deletions .blueprint/code-workspace/generator.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { join } from 'path';
import * as _ from 'lodash-es';
import { defaults, merge } from 'lodash-es';
import BaseGenerator from '../../generators/base/index.js';
import { getPackageRoot } from '../../lib/index.js';
import command from './command.mjs';
import { defaultSamplesFolder, promptSamplesFolder, samplesFolderConfig } from '../support.mjs';

const { merge } = _;

export default class extends BaseGenerator {
samplePath;

Expand Down
6 changes: 3 additions & 3 deletions cli/environment-builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { existsSync, readFileSync } from 'fs';
import path, { dirname, resolve } from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import chalk from 'chalk';
import * as _ from 'lodash-es';
import { cloneDeep, mergeWith } from 'lodash-es';
import Environment from 'yeoman-environment';
import { QueuedAdapter } from '@yeoman/adapter';

Expand Down Expand Up @@ -407,7 +407,7 @@ export default class EnvironmentBuilder {
const blueprintCommandsUrl = pathToFileURL(resolve(`${blueprintCommandFile}${blueprintCommandExtension}`));
try {
blueprintCommand = (await import(blueprintCommandsUrl)).default;
const blueprintCommands = _.cloneDeep(blueprintCommand);
const blueprintCommands = cloneDeep(blueprintCommand);
Object.entries(blueprintCommands).forEach(([_command, commandSpec]) => {
commandSpec.blueprint = commandSpec.blueprint || blueprint;
});
Expand Down Expand Up @@ -480,7 +480,7 @@ export default class EnvironmentBuilder {
for (const [blueprint, packagePath] of blueprintPackagePaths) {
const errorMsg = `No custom sharedOptions found within blueprint: ${blueprint} at ${packagePath}`;
const opts = await loadSharedOptionsFromFile(`${packagePath}/cli/sharedOptions`, undefined, errorMsg);
result = _.mergeWith(result, opts, joiner);
result = mergeWith(result, opts, joiner);
}
return result;
}
Expand Down
4 changes: 1 addition & 3 deletions cli/jhipster-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@

import chalk from 'chalk';
import { Command, Option } from 'commander';
import lodash from 'lodash';
import { kebabCase } from 'lodash-es';
import { convertConfigToOption } from '../lib/internal/index.js';

const { kebabCase } = lodash;

export default class JHipsterCommand extends Command {
createCommand(name) {
return new JHipsterCommand(name);
Expand Down
4 changes: 1 addition & 3 deletions generators/angular/generator.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, after, expect } from 'esmocha';
import lodash from 'lodash';
import { snakeCase } from 'lodash-es';

import { buildClientSamples, entitiesClientSamples as entities, defaultHelpers as helpers } from '../../testing/index.js';
import { shouldSupportFeatures, testBlueprintSupport, checkEnforcements } from '../../test/support/index.js';
Expand All @@ -10,8 +10,6 @@ import { clientFrameworkTypes } from '../../jdl/jhipster/index.js';
import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.js';
import { GENERATOR_ANGULAR } from '../generator-list.js';

const { snakeCase } = lodash;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down
6 changes: 3 additions & 3 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash-es';
import { camelCase } from 'lodash-es';
import chalk from 'chalk';
import { isFileStateModified } from 'mem-fs-editor/state';

Expand Down Expand Up @@ -334,7 +334,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
* @param {boolean} enableTranslation - If translations are enabled or not
* @param {string} translationKeyMenu - i18n key for entry in the admin menu
*/
addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu = _.camelCase(routerName), jhiPrefix?) {
addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu = camelCase(routerName), jhiPrefix?) {
this.needleApi.clientAngular.addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu, jhiPrefix);
}

Expand Down Expand Up @@ -450,7 +450,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);
}
}
6 changes: 3 additions & 3 deletions generators/angular/needle-api/needle-client-angular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* limitations under the License.
*/
import chalk from 'chalk';
import * as _ from 'lodash-es';
import { startCase } from 'lodash-es';

import needleClientBase from '../../client/needle-api/needle-client.js';
import { LINE_LENGTH } from '../../generator-constants.js';
Expand Down Expand Up @@ -124,7 +124,7 @@ export default class extends needleClientBase {
const entityEntry = `<li class="nav-item" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">
<a class="nav-link" ${routerLink} (click)="collapseNavbar()">
<fa-icon icon="${iconName}" [fixedWidth]="true"></fa-icon>
<span${enableTranslation ? ` ${jhiPrefix}Translate="global.menu.${translationKeyMenu}"` : ''}>${_.startCase(routerName)}</span>
<span${enableTranslation ? ` ${jhiPrefix}Translate="global.menu.${translationKeyMenu}"` : ''}>${startCase(routerName)}</span>
</a>
</li>`;
const rewriteFileModel = this.generateFileModel(entityMenuPath, 'jhipster-needle-add-element-to-menu', entityEntry);
Expand All @@ -142,7 +142,7 @@ export default class extends needleClientBase {
const entityEntry = `<li>
<a class="dropdown-item" ${routerLink} routerLinkActive="active" (click)="collapseNavbar()">
<fa-icon icon="${iconName}" [fixedWidth]="true"></fa-icon>
<span${enableTranslation ? ` ${jhiPrefix}Translate="global.menu.admin.${translationKeyMenu}"` : ''}>${_.startCase(routerName)}</span>
<span${enableTranslation ? ` ${jhiPrefix}Translate="global.menu.admin.${translationKeyMenu}"` : ''}>${startCase(routerName)}</span>
</a>
</li>`;
const rewriteFileModel = this.generateFileModel(navbarAdminPath, 'jhipster-needle-add-element-to-admin-menu', entityEntry);
Expand Down
6 changes: 3 additions & 3 deletions generators/app/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
/* eslint-disable consistent-return, import/no-named-as-default-member */
import chalk from 'chalk';
import * as _ from 'lodash-es';
import { camelCase, omit } from 'lodash-es';

import BaseApplicationGenerator from '../base-application/index.js';
import { checkNode, loadStoredAppOptions } from './support/index.js';
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
},
fixConfig() {
if (this.jhipsterConfig.jhiPrefix) {
this.jhipsterConfig.jhiPrefix = _.camelCase(this.jhipsterConfig.jhiPrefix);
this.jhipsterConfig.jhiPrefix = camelCase(this.jhipsterConfig.jhiPrefix);
}
},
defaults() {
Expand Down Expand Up @@ -178,7 +178,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator {
return this.asDefaultTaskGroup({
insight({ control }) {
const yorc = {
..._.omit(this.jhipsterConfig, [JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY]),
...omit(this.jhipsterConfig, [JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY]),
};
yorc.applicationType = this.jhipsterConfig.applicationType;
statistics.sendYoRc(yorc, control.existingProject, this.jhipsterConfig.jhipsterVersion);
Expand Down
4 changes: 1 addition & 3 deletions generators/app/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import { basename, dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, expect } from 'esmocha';
import lodash from 'lodash';
import { snakeCase } from 'lodash-es';

import { getCommandHelpOutput, shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.js';
import { defaultHelpers as helpers, runResult } from '../../testing/index.js';
import Generator from './index.js';

const { snakeCase } = lodash;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down
4 changes: 1 addition & 3 deletions generators/base-application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@
import { basename, dirname } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, expect, esmocha } from 'esmocha';
import lodash from 'lodash';
import { snakeCase } from 'lodash-es';

import EnvironmentBuilder from '../../cli/environment-builder.mjs';
import Generator from './index.js';
import type { BaseApplication } from '../base-application/types.js';
import { defaultHelpers as helpers } from '../../testing/index.js';
import { shouldSupportFeatures } from '../../test/support/tests.js';

const { snakeCase } = lodash;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down
4 changes: 1 addition & 3 deletions generators/base-application/support/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
* limitations under the License.
*/

import * as _ from 'lodash-es';
import { upperFirst } from 'lodash-es';
import { Entity } from '../../../jdl/converters/types.js';

const { upperFirst } = _;

// eslint-disable-next-line import/prefer-default-export
export const findEntityInEntities = (entityName: string, entities: Entity[]) =>
entities.find(entity => upperFirst(entity.name) === upperFirst(entityName));
4 changes: 2 additions & 2 deletions generators/base-application/support/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash-es';
import { lowerFirst } from 'lodash-es';
import { formatDocAsJavaDoc } from '../../java/support/doc.js';

const doesTheEnumValueHaveACustomValue = enumValue => {
Expand Down Expand Up @@ -70,7 +70,7 @@ const getEnums = (enums, customValuesState, comments) => {

const extractEnumInstance = field => {
const fieldType = field.fieldType;
return _.lowerFirst(fieldType);
return lowerFirst(fieldType);
};

const extractEnumEntries = field => {
Expand Down
11 changes: 5 additions & 6 deletions generators/base-application/support/prepare-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { snakeCase, startCase, upperFirst } from 'lodash-es';
import * as _ from 'lodash-es';
import { snakeCase, startCase, upperFirst, defaults, kebabCase } from 'lodash-es';
import { fieldTypes, validations } from '../../../jdl/jhipster/index.js';
import { getTypescriptType, prepareField as prepareClientFieldForTemplates } from '../../client/support/index.js';
import { prepareField as prepareServerFieldForTemplates } from '../../server/support/index.js';
Expand Down Expand Up @@ -217,7 +216,7 @@ function _derivedProperties(field) {
const fieldType = field.fieldType;
const fieldTypeBlobContent = field.fieldTypeBlobContent;
const validationRules = field.fieldValidate ? field.fieldValidateRules : [];
_.defaults(field, {
defaults(field, {
blobContentTypeText: fieldTypeBlobContent === TEXT,
blobContentTypeImage: fieldTypeBlobContent === IMAGE,
blobContentTypeAny: fieldTypeBlobContent === ANY,
Expand Down Expand Up @@ -283,14 +282,14 @@ function prepareCommonFieldForTemplates(entityWithConfig, field, generator) {

prepareProperty(field);

_.defaults(field, {
defaults(field, {
entity: entityWithConfig,
});
const fieldType = field.fieldType;

field.fieldIsEnum = !field.id && fieldIsEnum(fieldType);
if (field.fieldIsEnum) {
field.enumFileName = _.kebabCase(field.fieldType);
field.enumFileName = kebabCase(field.fieldType);
field.enumValues = getEnumValuesWithCustomValues(field.fieldValues);
}

Expand All @@ -300,7 +299,7 @@ function prepareCommonFieldForTemplates(entityWithConfig, field, generator) {
}

field.fieldValidate = Array.isArray(field.fieldValidateRules) && field.fieldValidateRules.length >= 1;
_.defaults(field, {
defaults(field, {
nullable: !(field.fieldValidate === true && field.fieldValidateRules.includes(REQUIRED)),
});
field.unique = field.fieldValidate === true && field.fieldValidateRules.includes(UNIQUE);
Expand Down
4 changes: 1 addition & 3 deletions generators/base-application/support/relationship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
* limitations under the License.
*/

import * as _ from 'lodash-es';
import { upperFirst, lowerFirst } from 'lodash-es';

import { Relationship, Entity } from '../../../jdl/converters/types.js';
import { ValidationResult } from '../../base/api.js';
import { stringifyApplicationData } from './debug.js';
import { findEntityInEntities } from './entity.js';

const { upperFirst, lowerFirst } = _;

export const otherRelationshipType = relationshipType => relationshipType.split('-').reverse().join('-');

export const findOtherRelationshipInRelationships = (entityName: string, relationship: Relationship, inRelationships: Relationship[]) => {
Expand Down
4 changes: 1 addition & 3 deletions generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { requireNamespace } from '@yeoman/namespace';
import { GeneratorMeta } from '@yeoman/types';
import chalk from 'chalk';
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
import * as _ from 'lodash-es';
import { kebabCase, snakeCase } from 'lodash-es';
import { kebabCase, snakeCase, merge, get, set } from 'lodash-es';
import { simpleGit } from 'simple-git';
import type { CopyOptions } from 'mem-fs-editor';
import type { Data as TemplateData, Options as TemplateOptions } from 'ejs';
Expand Down Expand Up @@ -62,7 +61,6 @@ import { convertConfigToOption } from '../../lib/internal/index.js';
import { getGradleLibsVersionsProperties } from '../gradle/support/dependabot-gradle.js';
import { dockerPlaceholderGenerator } from '../docker/utils.js';

const { merge, get, set } = _;
const {
INITIALIZING,
PROMPTING,
Expand Down
4 changes: 2 additions & 2 deletions generators/base-workspaces/internal/deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash-es';
import { defaults } from 'lodash-es';
import { applicationOptions, deploymentOptions } from '../../../jdl/index.js';
import { loadDerivedPlatformConfig, loadPlatformConfig, loadDerivedServerAndPlatformProperties } from '../../server/support/index.js';
import type { GeneratorBaseCore } from '../../index.js';
Expand All @@ -29,7 +29,7 @@ const { JWT_SECRET_KEY } = OptionNames;
export function loadDeploymentConfig(
this: GeneratorBaseCore,
{
config = _.defaults({}, this.jhipsterConfig, DeploymentOptions.defaults(this.jhipsterConfig.deploymentType)),
config = defaults({}, this.jhipsterConfig, DeploymentOptions.defaults(this.jhipsterConfig.deploymentType)),
deployment = this,
}: { config?: any; deployment?: any } = {},
) {
Expand Down
4 changes: 1 addition & 3 deletions generators/base/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import { basename, dirname } from 'path';
import { fileURLToPath } from 'url';
import { before, it, describe, expect, esmocha } from 'esmocha';
import lodash from 'lodash';
import { snakeCase } from 'lodash-es';

import EnvironmentBuilder from '../../cli/environment-builder.mjs';
import BaseGenerator from './index.js';
import { defaultHelpers as helpers } from '../../testing/index.js';
import { getCommandHelpOutput, shouldSupportFeatures } from '../../test/support/tests.js';

const { snakeCase } = lodash;

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

Expand Down
4 changes: 1 addition & 3 deletions generators/base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import fs from 'fs';
import path from 'path';
import chalk from 'chalk';
import semver from 'semver';
import * as _ from 'lodash-es';
import { defaults } from 'lodash-es';

import type { ComposeOptions } from 'yeoman-generator';
import { packageJson } from '../../lib/index.js';
Expand All @@ -34,8 +34,6 @@ import { LOCAL_BLUEPRINT_PACKAGE_NAMESPACE } from './support/constants.js';
import { getConfigWithDefaults } from '../../jdl/index.js';
import { loadStoredAppOptions } from '../app/support/index.js';

const { defaults } = _;

/**
* Base class that contains blueprints support.
*/
Expand Down
4 changes: 1 addition & 3 deletions generators/base/shared-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as _ from 'lodash-es';
import { defaults } from 'lodash-es';
import { type BaseApplication } from '../base-application/types.js';
import { type Control } from './types.js';

const { defaults } = _;

export default class SharedData<ApplicationType extends BaseApplication = BaseApplication> {
_storage: any;

Expand Down
4 changes: 1 addition & 3 deletions generators/base/support/basename.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import * as _ from 'lodash-es';

const { camelCase } = _;
import { camelCase } from 'lodash-es';

/**
* get the frontend application name.
Expand Down
5 changes: 1 addition & 4 deletions generators/base/support/needles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
* limitations under the License.
*/
import assert from 'assert';
import * as _ from 'lodash-es';
import { escapeRegExp } from 'lodash-es';
import { escapeRegExp, kebabCase } from 'lodash-es';
import CoreGenerator from '../../base-core/index.js';
import { CascatedEditFileCallback, EditFileCallback } from '../api.js';
import { joinCallbacks } from './write-files.js';

const { kebabCase } = _;

export type NeedleInsertion = {
needle: string;
/**
Expand Down
Loading

0 comments on commit 9387b1d

Please sign in to comment.