Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lodash dependency #383

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-days-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': patch
---

Remove `lodash` dependency
20 changes: 18 additions & 2 deletions lib/getStaticTypes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const findUp = require('find-up');
const fastGlob = require('fast-glob');
const keyBy = require('lodash/keyBy');
const mapValues = require('lodash/mapValues');
const fs = require('fs');
const ts = require('typescript');
const path = require('path');
Expand All @@ -16,6 +14,24 @@ const parsePropType = (propType) => {
return [];
};

/**
* Modified from https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore?tab=readme-ov-file#_keyby.
* Only supports arrays and expects a `key` to be provided.
*/
const keyBy = (array = [], key) =>
array.reduce(
(previousValue, currentValue) => ({
...previousValue,
[currentValue[key]]: currentValue,
}),
{}
);

const mapValues = (object, callback) =>
Object.fromEntries(
Object.entries(object).map(([key, value]) => [key, callback(value)])
);

module.exports = async (playroomConfig) => {
const {
cwd,
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@types/base64-url": "^2.2.0",
"@types/codemirror": "^5.60.5",
"@types/lodash": "^4.14.191",
"@types/prettier": "^2.7.1",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
Expand All @@ -96,7 +95,6 @@
"history": "^5.3.0",
"html-webpack-plugin": "^5.5.0",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"memoize-one": "^6.0.0",
"mini-css-extract-plugin": "^2.7.2",
Expand Down
10 changes: 0 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/Playroom/Frames/Frames.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useRef } from 'react';
import flatMap from 'lodash/flatMap';
import Iframe from './Iframe';
import { compileJsx } from '../../utils/compileJsx';
import type { PlayroomProps } from '../Playroom';
Expand All @@ -21,7 +20,7 @@ export default function Frames({ code, themes, widths }: FramesProps) {
const scrollingPanelRef = useRef<HTMLDivElement | null>(null);
const renderCode = useRef<string>('');

const frames = flatMap(widths, (width) =>
const frames = widths.flatMap((width) =>
themes.map((theme) => ({
theme,
width,
Expand Down
6 changes: 3 additions & 3 deletions src/utils/componentsToHints.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import omit from 'lodash/omit';
// @ts-expect-error
import parsePropTypes from 'parse-prop-types';
import type { PlayroomProps } from '../Playroom/Playroom';
Expand All @@ -24,8 +23,9 @@ export default (
};
}

const parsedPropTypes = parsePropTypes(components[componentName]);
const filteredPropTypes = omit(parsedPropTypes, 'children');
const { children, ...filteredPropTypes } = parsePropTypes(
components[componentName]
);
const propNames = Object.keys(filteredPropTypes);

return {
Expand Down
Loading