Skip to content

Commit ca8de61

Browse files
authored
Merge pull request #5350 from NomicFoundation/replace-utils
Use isObject & kebabToCamelCase in v-next
2 parents 16a860c + 82e7a9c commit ca8de61

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

Diff for: v-next/core/src/internal/hook-manager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class HookManagerImplementation implements HookManager {
306306

307307
const category = await factory();
308308

309-
// TODO: Assert that category is not undefined and it's an object
309+
// TODO: Assert that category is not undefined and it's an object -- should use !isObject(category)
310310
if (typeof category !== "object" || category === null) {
311311
throw new Error(
312312
`Plugin ${pluginId} doesn't export a valid factory for category ${hookCategoryName} in ${path}, it didn't return an object`,

Diff for: v-next/hardhat-errors/src/errors.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CustomError } from "@nomicfoundation/hardhat-utils/error";
2+
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
23

34
import { ERRORS, ErrorDescriptor } from "./descriptors.js";
45

@@ -81,7 +82,7 @@ export class HardhatError<
8182
messageArgumentsOrParentError === undefined ||
8283
messageArgumentsOrParentError instanceof Error
8384
) {
84-
/* eslint-disable @typescript-eslint/consistent-type-assertions --
85+
/* eslint-disable @typescript-eslint/consistent-type-assertions --
8586
Typescript inference get's lost here, but we know that if we didn't get
8687
arguments, it's because the error doesn't have any. */
8788
this.#arguments = {} as MessagetTemplateArguments<
@@ -116,7 +117,7 @@ export class HardhatError<
116117
other: unknown,
117118
descriptor?: ErrorDescriptor,
118119
): other is HardhatError<ErrorDescriptor> {
119-
if (typeof other !== "object" || other === null) {
120+
if (!isObject(other) || other === null) {
120121
return false;
121122
}
122123

@@ -130,7 +131,7 @@ export class HardhatError<
130131
// If an error descriptor is provided, check if its number matches the Hardhat error number
131132
(descriptor === undefined
132133
? true
133-
: (other as HardhatError<ErrorDescriptor>).number === descriptor.number)
134+
: "number" in other && other.number === descriptor.number)
134135
);
135136
}
136137

Diff for: v-next/hardhat-utils/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"./lang": "./dist/src/lang.js",
2222
"./number": "./dist/src/number.js",
2323
"./package": "./dist/src/package.js",
24-
"./request": "./dist/src/request.js"
24+
"./request": "./dist/src/request.js",
25+
"./string": "./dist/src/string.js"
2526
},
2627
"keywords": [
2728
"ethereum",

Diff for: v-next/hardhat/src/internal/cli/main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
assertHardhatInvariant,
2525
} from "@nomicfoundation/hardhat-errors";
2626
import { isCi } from "@nomicfoundation/hardhat-utils/ci";
27+
import { kebabToCamelCase } from "@nomicfoundation/hardhat-utils/string";
2728

2829
import { builtinPlugins } from "../builtin-plugins/index.js";
2930
import {
@@ -56,7 +57,10 @@ export async function main(cliArguments: string[]) {
5657
try {
5758
const userConfig = await importUserConfig(hardhatSpecialArgs.configPath);
5859

59-
const plugins = [...builtinPlugins, ...(userConfig.plugins ?? [])];
60+
const configPlugins = Array.isArray(userConfig.plugins)
61+
? userConfig.plugins
62+
: [];
63+
const plugins = [...builtinPlugins, ...configPlugins];
6064
const resolvedPlugins = await resolvePluginList(
6165
plugins,
6266
hardhatSpecialArgs.configPath,
@@ -511,10 +515,6 @@ function validateRequiredParameters(
511515
);
512516
}
513517

514-
function kebabToCamelCase(str: string) {
515-
return str.replace(/-./g, (match) => match.charAt(1).toUpperCase());
516-
}
517-
518518
function parseParameterValue(
519519
strValue: string,
520520
type: ParameterType,

Diff for: v-next/hardhat/src/internal/helpers/config-loading.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { pathToFileURL } from "node:url";
33

44
import { HardhatError } from "@nomicfoundation/hardhat-errors";
55
import { findUp } from "@nomicfoundation/hardhat-utils/fs";
6+
import { isObject } from "@nomicfoundation/hardhat-utils/lang";
67

78
import { ERRORS } from "../../../../hardhat-errors/src/descriptors.js";
89

@@ -51,7 +52,7 @@ export async function importUserConfig(configPath: string) {
5152

5253
const config = imported.default;
5354

54-
if (typeof config !== "object" || config === null) {
55+
if (!isObject(config) || config === null) {
5556
throw new HardhatError(ERRORS.GENERAL.INVALID_CONFIG_OBJECT, {
5657
configPath,
5758
});

0 commit comments

Comments
 (0)