Skip to content

Commit

Permalink
Merge pull request #2669 from udecode/fix/js
Browse files Browse the repository at this point in the history
Lodash ES
  • Loading branch information
zbeyens authored Oct 2, 2023
2 parents 5ae2282 + 8a9172b commit 599cdfa
Show file tree
Hide file tree
Showing 48 changed files with 97 additions and 107 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-terms-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/slate': patch
---

Replace lodash by lodash-es
39 changes: 16 additions & 23 deletions config/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable unicorn/prefer-module,@typescript-eslint/no-shadow */
import fs from 'node:fs';
import path from 'node:path';
import { esbuildPluginImport } from '@linjiajian999/esbuild-plugin-import';
import { defineConfig } from 'tsup';

const silent = false;

const PACKAGE_ROOT_PATH = process.cwd();
const INPUT_FILE_PATH = path.join(PACKAGE_ROOT_PATH, 'src/index.ts');
const INPUT_FILE = fs.existsSync(INPUT_FILE_PATH)
Expand All @@ -15,30 +16,22 @@ export default defineConfig((opts) => {
...opts,
entry: [INPUT_FILE],
format: ['cjs', 'esm'],
skipNodeModulesBundle: true,
dts: {
resolve: false,
},
dts: { resolve: false },
sourcemap: true,
clean: true,
esbuildPlugins: [
esbuildPluginImport([
{
libraryName: 'lodash',
libraryDirectory: '',
camel2DashComponentName: false,
},
]) as any,
],
onSuccess: async () => {
if (opts.watch) {
console.info('Watching for changes...');
return;
}

console.info('Build succeeded!');
},
silent: true,
plugins: [],
...(silent
? {
silent: true,
onSuccess: async () => {
if (opts.watch) {
console.info('Watching for changes...');
return;
}

console.info('Build succeeded!');
},
}
: {}),
};
});
1 change: 1 addition & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
moduleFileExtensions: ['js', 'json', 'ts', 'tsx'],
moduleNameMapper: {
'\\.(css|less|sass|scss)$': '<rootDir>/scripts/styleMock.cjs',
'^lodash-es$': 'lodash',
...getTsConfigBasePaths(),
// '^@udecode/plate-core$': '<rootDir>/packages/core/src',
...modules,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"p:brl": "cd $INIT_CWD && barrelsby -d $INIT_CWD/src -D -l all -q -e '.*(fixture|template|spec|__tests__).*'",
"p:brl:below": "cd $INIT_CWD && barrelsby -d $INIT_CWD/src -D -l below -q -e '.*(fixture|template|spec|__tests__).*'",
"p:build": "cd $INIT_CWD && yarn p:tsup",
"p:build:watch": "cd $INIT_CWD && yarn p:tsup --watch",
"p:clean": "cd $INIT_CWD && rimraf dist && jest --clear-cache",
"p:lint": "eslint $INIT_CWD/src --color",
"p:lint:fix": "eslint $INIT_CWD/src --color --fix",
Expand Down Expand Up @@ -87,7 +88,6 @@
"@changesets/types": "^5.2.1",
"@dword-design/eslint-plugin-import-alias": "^4.0.8",
"@ianvs/prettier-plugin-sort-imports": "^4.0.2",
"@linjiajian999/esbuild-plugin-import": "1.0.2",
"@playwright/test": "1.36.0",
"@swc/core": "1.3.90",
"@swc/jest": "0.2.29",
Expand All @@ -99,6 +99,7 @@
"@types/is-hotkey": "^0.1.7",
"@types/jest": "^29.5.3",
"@types/lodash": "^4.14.195",
"@types/lodash-es": "^4.17.9",
"@types/marked": "^4.3.1",
"@types/node": "^20.4.2",
"@types/prismjs": "^1.26.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/autoformat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/autoformat/src/transforms/autoformatBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
someNode,
Value,
} from '@udecode/plate-common';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';
import { Range } from 'slate';

import { AutoformatBlockRule } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/autoformat/src/transforms/autoformatMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TEditor,
Value,
} from '@udecode/plate-common';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';
import { Point, Range } from 'slate';

import { AutoformatMarkRule } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/autoformat/src/transforms/autoformatText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
PlateEditor,
Value,
} from '@udecode/plate-common';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';
import { Point, Range } from 'slate';

import { AutoformatTextRule } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/autoformat/src/utils/getMatchRange.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';

import { AutoformatRule, MatchRange } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/comments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/comments/src/queries/getCommentPosition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlateEditor, toDOMNode, Value } from '@udecode/plate-common';
import { clamp } from 'lodash';
import { clamp } from 'lodash-es';

import { TCommentText } from '../types';
import { getElementAbsolutePosition } from '../utils/getElementAbsolutePosition';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"clsx": "^1.2.1",
"is-hotkey": "^0.2.0",
"jotai": "1.7.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"nanoid": "^3.3.6",
"react-hotkeys-hook": "^4.4.1",
"use-deep-compare": "^1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/Editor.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { render } from '@testing-library/react';
import { isBlock, setNodes } from '@udecode/slate';
import { isEqual, memoize } from 'lodash';
import { isEqual, memoize } from 'lodash-es';

import { PlatePlugin } from '../types/index';
import { createPlateEditor } from '../utils/index';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hooks/useEditableProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { isDefined } from '@udecode/utils';
import omit from 'lodash/omit';
import { omit } from 'lodash-es';
import { useDeepCompareMemo } from 'use-deep-compare';

import { usePlateSelectors } from '../stores';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hooks/usePlateEffects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ForwardedRef, useEffect } from 'react';
import { Value } from '@udecode/slate';
import { isUndefined } from 'lodash';
import { isUndefined } from 'lodash-es';

import { useEditorRef, usePlateStates } from '../stores';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Value } from '@udecode/slate';
import { AnyObject, isDefined } from '@udecode/utils';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';

import { Nullable } from '../../../types';
import { PlateEditor } from '../../../types/PlateEditor';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/createPlugins.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Value } from '@udecode/slate';
import { cloneDeep } from 'lodash';
import { cloneDeep } from 'lodash-es';

import { OverrideByKey } from '../types/OverrideByKey';
import { PlateEditor } from '../types/PlateEditor';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/flattenDeepPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Value } from '@udecode/slate';
import defaultsDeep from 'lodash/defaultsDeep';
import { defaultsDeep } from 'lodash-es';

import { PlateEditor } from '../types/PlateEditor';
import { PlatePlugin } from '../types/plugin/PlatePlugin';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/getKeysByTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Value } from '@udecode/slate';
import { castArray } from 'lodash';
import { castArray } from 'lodash-es';

import { PlateEditor } from '../types/PlateEditor';

Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/utils/mergeDeepPlugins.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { Value } from '@udecode/slate';
import defaultsDeep from 'lodash/defaultsDeep';
import keyBy from 'lodash/keyBy';
import merge from 'lodash/merge';
import values from 'lodash/values';
import { defaultsDeep, keyBy, merge, values } from 'lodash-es';

import { PlateEditor } from '../types/PlateEditor';
import { WithPlatePlugin } from '../types/plugin/PlatePlugin';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/mergeDeepToNodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TNode } from '@udecode/slate';
import merge from 'lodash/merge';
import { merge } from 'lodash-es';

import { applyDeepToNodes, ApplyDeepToNodesOptions } from './applyDeepToNodes';

Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/utils/normalizeInitialValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Value } from '@udecode/slate';
import { cloneDeep } from 'lodash';
import isEqual from 'lodash/isEqual';
import { cloneDeep, isEqual } from 'lodash-es';

import { PlateEditor } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/overridePluginsByKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Value } from '@udecode/slate';
import defaultsDeep from 'lodash/defaultsDeep';
import { defaultsDeep } from 'lodash-es';

import { NoInfer } from '../types/misc/NoInfer';
import { OverrideByKey } from '../types/OverrideByKey';
Expand Down
2 changes: 1 addition & 1 deletion packages/dnd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"raf": "^3.4.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/dnd/src/components/Scroller/ScrollArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useEffect,
useRef,
} from 'react';
import { throttle } from 'lodash';
import { throttle } from 'lodash-es';
import raf from 'raf';

const getCoords = (e: any) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/src/hooks/useColorsCustom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import debounce from 'lodash/debounce';
import { debounce } from 'lodash-es';

export const useColorsCustomState = ({
color,
Expand Down
2 changes: 1 addition & 1 deletion packages/list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@udecode/plate-common": "24.3.2",
"@udecode/plate-reset-node": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/list/src/onKeyDownList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Value,
WithPlatePlugin,
} from '@udecode/plate-common';
import { castArray } from 'lodash';
import { castArray } from 'lodash-es';
import { Range } from 'slate';

import { ELEMENT_LI } from './createListPlugin';
Expand Down
2 changes: 1 addition & 1 deletion packages/node-id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/node-id/src/withNodeId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
Value,
WithPlatePlugin,
} from '@udecode/plate-common';
import { castArray } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import { castArray, cloneDeep } from 'lodash-es';

import { NodeIdPlugin } from './createNodeIdPlugin';

Expand Down
2 changes: 1 addition & 1 deletion packages/normalizers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"dependencies": {
"@udecode/plate-common": "24.3.2",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/normalizers/src/withRemoveEmptyNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Value,
WithPlatePlugin,
} from '@udecode/plate-common';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';

import { RemoveEmptyNodesPlugin } from './createRemoveEmptyNodesPlugin';

Expand Down
2 changes: 1 addition & 1 deletion packages/plate-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@udecode/slate-utils": "24.3.2",
"@udecode/utils": "24.3.0",
"clsx": "^1.2.1",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"react": ">=16.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plate-utils/src/plate/onKeyDownToggleElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
WithPlatePlugin,
} from '@udecode/plate-core';
import { Value } from '@udecode/slate';
import { castArray } from 'lodash';
import { castArray } from 'lodash-es';

export const onKeyDownToggleElement =
<V extends Value = Value, E extends PlateEditor<V> = PlateEditor<V>>(
Expand Down
2 changes: 1 addition & 1 deletion packages/plate-utils/src/queries/isType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getPluginType, PlateEditor } from '@udecode/plate-core';
import { Value } from '@udecode/slate';
import castArray from 'lodash/castArray';
import { castArray } from 'lodash-es';

/**
* Does the node match the type provided.
Expand Down
3 changes: 1 addition & 2 deletions packages/plate-utils/src/utils/createNodesHOC.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FunctionComponent } from 'react';
import { AnyObject } from '@udecode/utils';
import { castArray } from 'lodash';
import merge from 'lodash/merge';
import { castArray, merge } from 'lodash-es';

import { createNodeHOC } from './createNodeHOC';

Expand Down
2 changes: 1 addition & 1 deletion packages/plate-utils/src/utils/defaultsDeepToNodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { applyDeepToNodes, ApplyDeepToNodesOptions } from '@udecode/plate-core';
import { TNode } from '@udecode/slate';
import defaults from 'lodash/defaults';
import { defaults } from 'lodash-es';

/**
* Recursively merge a source object to children nodes with a query.
Expand Down
2 changes: 1 addition & 1 deletion packages/slate-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@udecode/slate": "24.3.2",
"@udecode/utils": "24.3.0",
"lodash": "^4.17.21"
"lodash-es": "^4.17.21"
},
"peerDependencies": {
"slate": ">=0.94.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/slate-utils/src/queries/getPointBeforeLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
TEditor,
Value,
} from '@udecode/slate';
import castArray from 'lodash/castArray';
import map from 'lodash/map';
import { castArray, map } from 'lodash-es';
import { Location, Point } from 'slate';

import { isRangeAcrossBlocks } from './isRangeAcrossBlocks';
Expand Down
Loading

0 comments on commit 599cdfa

Please sign in to comment.