Skip to content

Commit

Permalink
build: update deps and apply linting changes (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens authored Oct 4, 2024
1 parent c7e7c3d commit 018204d
Show file tree
Hide file tree
Showing 25 changed files with 6,873 additions and 5,279 deletions.
7 changes: 1 addition & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@
"typescript.tsdk": "node_modules/typescript/lib",
"json.schemas": [
{
"fileMatch": [
"**/*.jsonc",
"**/tsconfig.json",
"**/tsconfig.*.json",
".vscode/*.json"
],
"fileMatch": ["**/*.jsonc", "**/tsconfig.json", "**/tsconfig.*.json", ".vscode/*.json"],
"schema": {
"allowTrailingCommas": true
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"name": "Rebecca Stevens",
"email": "[email protected]"
},
"type": "module",
"scripts": {
"benchmark": "tsx run.ts"
},
"type": "module",
"dependencies": {
"deepmerge": "^4.3.1",
"deepmerge-ts": "link:..",
Expand Down
50 changes: 9 additions & 41 deletions benchmark/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import { merge as mergeAnything } from "merge-anything";
import { Accumulator as ObjectAccumulator } from "object-accumulator";
import { Bench } from "tinybench";

Check warning on line 14 in benchmark/run.ts

View workflow job for this annotation

GitHub Actions / lint_js / lint_js

"tinybench" is not published

const benchmarkDataFile = path.join(
dirname(fileURLToPath(import.meta.url)),
"data.json",
);
const benchmarkDataFile = path.join(dirname(fileURLToPath(import.meta.url)), "data.json");

const benchmarkDataSets: Array<{
name: string;
Expand All @@ -29,16 +26,10 @@ const benchmarkDataSets: Array<{
return JSON.parse(data);
})
.catch(async (error: unknown) => {
if (
!(error instanceof Error) ||
!("code" in error) ||
error.code !== "ENOENT"
) {
if (!(error instanceof Error) || !("code" in error) || error.code !== "ENOENT") {
throw error;
}
console.log(
"No benchmark data file found. Generating random data for benchmarking against.",
);
console.log("No benchmark data file found. Generating random data for benchmarking against.");

const data = [
generateBenchmarkDataSet("tall", 2, 3, 16),
Expand All @@ -62,11 +53,7 @@ for (let m_i = 0; m_i < benchmarkDataSets.length; m_i++) {
warmupIterations: 1,
});

console.log(
`\nRunning benchmarks for data set "${benchmarkName}" (${m_i + 1} of ${
benchmarkDataSets.length
}):\n`,
);
console.log(`\nRunning benchmarks for data set "${benchmarkName}" (${m_i + 1} of ${benchmarkDataSets.length}):\n`);

bench
.add("deepmerge-ts", () => {
Expand Down Expand Up @@ -94,12 +81,7 @@ for (let m_i = 0; m_i < benchmarkDataSets.length; m_i++) {
console.table(bench.table());
}

function generateBenchmarkDataSet(
name: string,
items: number,
maxProperties: number,
maxDepth: number,
) {
function generateBenchmarkDataSet(name: string, items: number, maxProperties: number, maxDepth: number) {
const data: object[] = [];

for (let m_i = 0; m_i < items; m_i++) {
Expand All @@ -112,28 +94,17 @@ function generateBenchmarkDataSet(
};
}

function generateBenchmarkDataItem(
maxProperties: number,
depth: number,
currentDepth = 0,
) {
function generateBenchmarkDataItem(maxProperties: number, depth: number, currentDepth = 0) {
const obj: object = {};

const properties = Math.floor(maxProperties * Math.random()) + 1;

const propertiesOptions = shuffle(
Array.from({ length: maxProperties }, (_, i) =>
String.fromCodePoint(i + 65),
),
);
const propertiesOptions = shuffle(Array.from({ length: maxProperties }, (_, i) => String.fromCodePoint(i + 65)));

for (let m_i = 0; m_i < properties; m_i++) {
const prop = propertiesOptions[m_i];

obj[prop] =
currentDepth < depth
? generateBenchmarkDataItem(maxProperties, depth, currentDepth + 1)
: "value";
obj[prop] = currentDepth < depth ? generateBenchmarkDataItem(maxProperties, depth, currentDepth + 1) : "value";
}

return obj;
Expand All @@ -147,10 +118,7 @@ function shuffle<T>(array: T[]) {
m_randomIndex = Math.floor(Math.random() * m_currentIndex);
m_currentIndex--;

[array[m_currentIndex], array[m_randomIndex]] = [
array[m_randomIndex],
array[m_currentIndex],
];
[array[m_currentIndex], array[m_randomIndex]] = [array[m_randomIndex], array[m_currentIndex]];
}

return array;
Expand Down
70 changes: 16 additions & 54 deletions docs/deepmergeCustom.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,7 @@ declaring a module block for this library and defining the same interface.

```ts
declare module "deepmerge-ts" {
interface DeepMergeFunctionURItoKind<
Ts extends ReadonlyArray<unknown>,
Fs extends DeepMergeFunctionsURIs,
M,
> {
interface DeepMergeFunctionURItoKind<Ts extends ReadonlyArray<unknown>, Fs extends DeepMergeFunctionsURIs, M> {
readonly MyCustomMergeURI: MyValue;
}
}
Expand All @@ -183,11 +179,7 @@ Here's an example of creating a custom deepmerge function that amalgamates dates
<!-- eslint-disable ts/no-shadow -->

```ts
import {
type DeepMergeFunctionsURIs,
type DeepMergeLeaf,
deepmergeCustom,
} from "deepmerge-ts";
import { type DeepMergeFunctionsURIs, type DeepMergeLeaf, deepmergeCustom } from "deepmerge-ts";

const customizedDeepmerge = deepmergeCustom<
unknown, // <-- Types that can be passed into the function.
Expand All @@ -212,21 +204,12 @@ const z = { foo: new Date("2022-03-03") };
customizedDeepmerge(x, y, z); // => { foo: [Date, Date, Date] }

declare module "deepmerge-ts" {
interface DeepMergeFunctionURItoKind<
Ts extends ReadonlyArray<unknown>,
Fs extends DeepMergeFunctionsURIs,
M,
> {
readonly MyDeepMergeDatesURI: EveryIsDate<Ts> extends true
? Ts
: DeepMergeLeaf<Ts>;
interface DeepMergeFunctionURItoKind<Ts extends ReadonlyArray<unknown>, Fs extends DeepMergeFunctionsURIs, M> {
readonly MyDeepMergeDatesURI: EveryIsDate<Ts> extends true ? Ts : DeepMergeLeaf<Ts>;
}
}

type EveryIsDate<Ts extends ReadonlyArray<unknown>> = Ts extends readonly [
infer Head,
...infer Rest,
]
type EveryIsDate<Ts extends ReadonlyArray<unknown>> = Ts extends readonly [infer Head, ...infer Rest]
? Head extends Date
? EveryIsDate<Rest>
: false
Expand Down Expand Up @@ -267,11 +250,7 @@ Here's an example that creates a custom deepmerge function that filters out all
<!-- eslint-disable ts/no-shadow -->

```ts
import {
type DeepMergeFunctionsURIs,
type FilterOut,
deepmergeCustom,
} from "deepmerge-ts";
import { type DeepMergeFunctionsURIs, type FilterOut, deepmergeCustom } from "deepmerge-ts";

const customizedDeepmerge = deepmergeCustom<
unknown,
Expand Down Expand Up @@ -332,9 +311,7 @@ const customizedDeepmerge = deepmergeCustom({
},
});

function areAllNumbers(
values: ReadonlyArray<unknown>,
): values is ReadonlyArray<number> {
function areAllNumbers(values: ReadonlyArray<unknown>): values is ReadonlyArray<number> {
return values.every((value) => typeof value === "number");
}

Expand All @@ -356,11 +333,7 @@ Here's an example that uses custom metadata that accumulates the full key path.
<!-- eslint-disable ts/no-shadow -->

```ts
import {
type DeepMergeFunctionsURIs,
type DeepMergeLeaf,
deepmergeCustom,
} from "deepmerge-ts";
import { type DeepMergeFunctionsURIs, type DeepMergeLeaf, deepmergeCustom } from "deepmerge-ts";

const customizedDeepmerge = deepmergeCustom<
// Allow any value to be passed into the function.
Expand Down Expand Up @@ -422,9 +395,7 @@ declare module "deepmerge-ts" {
Fs extends DeepMergeFunctionsURIs,
M, // This is the meta data type
> {
readonly KeyPathBasedMerge: Ts[number] extends number
? Ts[number] | string
: DeepMergeLeaf<Ts>;
readonly KeyPathBasedMerge: Ts[number] extends number ? Ts[number] | string : DeepMergeLeaf<Ts>;
}
}
```
Expand All @@ -445,12 +416,7 @@ See [deepmerge custom API](./API.md#deepmergecustomoptions-rootmetadata).
The signature of merging functions for `deepmergeIntoCustom` looks like this:

```ts
(
target: DeepMergeValueReference<T>,
values: Ts,
utils: U,
meta: M | undefined,
) => symbol | undefined;
(target: DeepMergeValueReference<T>, values: Ts, utils: U, meta: M | undefined) => symbol | undefined;
```

Instead of returning a value like with `deepmergeCustom`'s merge functions, mutations should be made to `target.value`.\
Expand Down Expand Up @@ -483,10 +449,7 @@ But if you want to do this then you'll simply need to explicity declare a type a
Here's an example:

```ts
type CustomizedDeepmergeInto = <
Target extends object,
Ts extends ReadonlyArray<object>,
>(
type CustomizedDeepmergeInto = <Target extends object, Ts extends ReadonlyArray<object>>(
target: Target,
...objects: Ts
) => asserts target is Target & // Intercepting with `Target` is essentially required to make TypeScript happy.
Expand All @@ -502,12 +465,11 @@ type CustomizedDeepmergeInto = <
DeepMergeBuiltInMetaData // Use default meta data.
>;

export const customizedDeepmergeInto: CustomizedDeepmergeInto =
deepmergeIntoCustom({
mergeOthers: (source, values, utils, meta) => {
/* ... */
},
});
export const customizedDeepmergeInto: CustomizedDeepmergeInto = deepmergeIntoCustom({
mergeOthers: (source, values, utils, meta) => {
/* ... */
},
});
```

## API
Expand Down
70 changes: 35 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,68 +86,68 @@
"@commitlint/config-conventional": "19.5.0",
"@cspell/dict-cryptocurrencies": "5.0.0",
"@eslint/compat": "1.1.1",
"@rebeccastevens/eslint-config": "3.0.0",
"@rollup/plugin-replace": "5.0.7",
"@rebeccastevens/eslint-config": "3.2.2",
"@rollup/plugin-replace": "6.0.1",
"@semantic-release/changelog": "6.0.3",
"@semantic-release/commit-analyzer": "13.0.0",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "10.1.7",
"@semantic-release/github": "11.0.0",
"@semantic-release/npm": "12.0.1",
"@semantic-release/release-notes-generator": "14.0.1",
"@stylistic/eslint-plugin": "2.6.2",
"@types/lodash": "4.17.7",
"@stylistic/eslint-plugin": "2.8.0",
"@types/lodash": "4.17.10",
"@types/node": "20.14.14",
"@typescript-eslint/eslint-plugin": "8.0.1",
"@typescript-eslint/parser": "8.0.1",
"@vitest/coverage-v8": "2.0.5",
"commitizen": "4.3.0",
"cspell": "8.13.2",
"@typescript-eslint/eslint-plugin": "8.8.0",
"@typescript-eslint/parser": "8.8.0",
"@vitest/coverage-v8": "2.1.2",
"commitizen": "4.3.1",
"cspell": "8.14.4",
"cz-conventional-changelog": "3.3.0",
"deassert": "1.0.2",
"denoify": "1.6.13",
"eslint": "9.9.1",
"denoify": "1.6.16",
"eslint": "9.11.1",
"eslint-config-prettier": "9.1.0",
"eslint-flat-config-utils": "0.3.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-flat-config-utils": "0.4.0",
"eslint-import-resolver-typescript": "3.6.3",
"eslint-merge-processors": "0.1.0",
"eslint-plugin-eslint-comments": "3.2.0",
"eslint-plugin-format": "0.1.2",
"eslint-plugin-functional": "7.0.0",
"eslint-plugin-import-x": "3.1.0",
"eslint-plugin-jsdoc": "48.11.0",
"eslint-plugin-functional": "7.0.2",
"eslint-plugin-import-x": "4.3.1",
"eslint-plugin-jsdoc": "50.3.1",
"eslint-plugin-jsonc": "2.16.0",
"eslint-plugin-markdown": "5.1.0",
"eslint-plugin-n": "17.10.2",
"eslint-plugin-no-only-tests": "3.1.0",
"eslint-plugin-n": "17.10.3",
"eslint-plugin-no-only-tests": "3.3.0",
"eslint-plugin-optimize-regex": "1.2.1",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-promise": "7.0.0",
"eslint-plugin-promise": "7.1.0",
"eslint-plugin-regexp": "2.6.0",
"eslint-plugin-sonarjs": "1.0.4",
"eslint-plugin-unicorn": "55.0.0",
"eslint-plugin-sonarjs": "2.0.3",
"eslint-plugin-unicorn": "56.0.0",
"eslint-plugin-vitest": "0.5.4",
"eslint-plugin-yml": "1.14.0",
"husky": "9.1.4",
"husky": "9.1.6",
"if-env-defined": "1.0.0",
"jsonc-eslint-parser": "2.4.0",
"knip": "5.27.0",
"lint-staged": "15.2.8",
"knip": "5.31.0",
"lint-staged": "15.2.10",
"lodash": "4.17.21",
"markdownlint-cli2": "0.13.0",
"markdownlint-cli2": "0.14.0",
"prettier": "3.3.3",
"prettier-plugin-packagejson": "2.5.1",
"prettier-plugin-packagejson": "2.5.2",
"rimraf": "6.0.1",
"rollup": "4.22.4",
"rollup": "4.24.0",
"rollup-plugin-deassert": "1.3.0",
"rollup-plugin-ts": "3.4.5",
"semantic-release": "24.1.0",
"semantic-release": "24.1.2",
"tsc-files": "1.1.4",
"tsd": "0.31.1",
"typescript": "5.5.4",
"vite-tsconfig-paths": "4.3.2",
"vitest": "2.0.5",
"tsd": "0.31.2",
"typescript": "5.6.2",
"vite-tsconfig-paths": "5.0.1",
"vitest": "2.1.2",
"yaml-eslint-parser": "1.2.3"
},
"packageManager": "pnpm@9.6.0",
"packageManager": "pnpm@9.12.0",
"engines": {
"node": ">=16.0.0"
},
Expand Down
Loading

0 comments on commit 018204d

Please sign in to comment.