Skip to content

Commit

Permalink
Fix: Change some dependencies to smaller alternatives (#1248)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed authored and sapegin committed Jan 17, 2019
1 parent 8554a3d commit 63a3a47
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/Development.md
Expand Up @@ -76,7 +76,7 @@ Each component folder usually has several files:

For styles we use [JSS](http://cssinjs.org/), it allows users to customize their style guide and allows us to ensure styles isolations (thanks to [jss-isolate](http://cssinjs.org/jss-isolate/)). No user styles should affect Styleguidist UI and no Styleguidist styles should affect user components.

Use [classnames](https://github.com/JedWatson/classnames) to merge several class names or for conditional class names, import it as `cx` (`import cx from 'classnames'`).
Use [clsx](https://github.com/lukeed/clsx) to merge several class names or for conditional class names, import it as `cx` (`import cx from 'clsx'`).

We use `Styled` higher-order component to allow theming (see [theme](Configuration.md#theme) and [style](Configuration.md#style) style guide config options). Use it like this:

Expand Down
5 changes: 5 additions & 0 deletions flow-typed/qss.js.flow
@@ -0,0 +1,5 @@
declare module 'qss' {
declare type Params = { [key: string]: any };
declare function decode(query: string): Params;
declare function encode(obj: Params, prefix?: string): string;
}
5 changes: 0 additions & 5 deletions flow-typed/querystringify.js.flow

This file was deleted.

34 changes: 26 additions & 8 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -32,9 +32,9 @@
"acorn-jsx": "^5.0.1",
"ast-types": "^0.11.7",
"buble": "0.19.4",
"classnames": "^2.2.6",
"clean-webpack-plugin": "^1.0.0",
"clipboard-copy": "^2.0.1",
"clsx": "^1.0.1",
"common-dir": "^2.0.2",
"copy-webpack-plugin": "^4.6.0",
"core-js": "^2.6.0",
Expand All @@ -56,20 +56,20 @@
"jss-global": "^3.0.0",
"jss-isolate": "^5.1.0",
"jss-nested": "^6.0.1",
"kleur": "^2.0.2",
"kleur": "^3.0.1",
"leven": "^2.1.0",
"listify": "^1.0.0",
"loader-utils": "^1.1.0",
"lodash": "^4.17.11",
"lowercase-keys": "^1.0.1",
"markdown-to-jsx": "^6.9.0",
"mini-html-webpack-plugin": "^0.2.3",
"minimist": "^1.2.0",
"mri": "^1.1.4",
"ora": "^3.0.0",
"prismjs": "^1.15.0",
"prop-types": "^15.6.2",
"q-i": "^2.0.1",
"querystringify": "^2.1.0",
"qss": "^2.0.0",
"react-dev-utils": "^6.1.1",
"react-docgen": "3.0.0-rc.2",
"react-docgen-annotation-resolver": "^1.0.0",
Expand Down
43 changes: 36 additions & 7 deletions src/bin/styleguidist.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/* eslint-disable no-console */
const minimist = require('minimist');
const mri = require('mri');
const kleur = require('kleur');
const ora = require('ora');
const stringify = require('q-i').stringify;
Expand All @@ -13,7 +13,7 @@ const setupLogger = require('../scripts/logger');
const consts = require('../scripts/consts');
const StyleguidistError = require('../scripts/utils/error');

const argv = minimist(process.argv.slice(2));
const argv = mri(process.argv.slice(2));
const command = argv._[0];

// Do not show nasty stack traces for Styleguidist errors
Expand All @@ -27,7 +27,11 @@ process.on('uncaughtException', err => {
consts.DOCS_CONFIG
);
} else if (err instanceof StyleguidistError) {
console.error(kleur.bold.red(err.message));
console.error(
kleur()
.bold()
.red(err.message)
);
logger.debug(err.stack);
} else {
console.error(err.toString());
Expand Down Expand Up @@ -219,7 +223,11 @@ function printBuildInstructions(config) {
* @param {string} linkUrl
*/
function printErrorWithLink(message, linkTitle, linkUrl) {
console.error(`${kleur.bold.red(message)}\n\n${linkTitle}\n${kleur.underline(linkUrl)}\n`);
console.error(
`${kleur()
.bold()
.red(message)}\n\n${linkTitle}\n${kleur.underline(linkUrl)}\n`
);
}

/**
Expand All @@ -243,11 +251,32 @@ function printErrors(header, errors, originalErrors, type) {
*/
function printStatus(text, type) {
if (type === 'success') {
console.log(kleur.inverse.bold.green(' DONE ') + ' ' + text);
console.log(
kleur
.inverse()
.bold()
.green(' DONE ') +
' ' +
text
);
} else if (type === 'error') {
console.error(kleur.inverse.bold.red(' FAIL ') + ' ' + kleur.red(text));
console.error(
kleur
.inverse()
.bold()
.red(' FAIL ') +
' ' +
kleur.red(text)
);
} else {
console.error(kleur.inverse.bold.yellow(' WARN ') + ' ' + kleur.yellow(text));
console.error(
kleur
.inverse()
.bold()
.yellow(' WARN ') +
' ' +
kleur.yellow(text)
);
}
}

Expand Down
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Link from 'rsg-components/Link';
import Styled from 'rsg-components/Styled';
import { getHash } from '../../utils/handleHash';
Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Heading/HeadingRenderer.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Styled from 'rsg-components/Styled';

const styles = ({ color, fontFamily, fontSize }) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Link/LinkRenderer.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Styled from 'rsg-components/Styled';

const styles = ({ color }) => ({
Expand Down
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';

import Styled from 'rsg-components/Styled';

Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Markdown/List/ListRenderer.js
@@ -1,6 +1,6 @@
import React, { Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Styled from 'rsg-components/Styled';

const styles = ({ space, color, fontFamily }) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Markdown/Pre/PreRenderer.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Styled from 'rsg-components/Styled';
import prismTheme from '../../../styles/prismTheme';

Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Name/NameRenderer.js
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
import cx from 'clsx';

export const styles = ({ fontFamily, fontSize, color }) => ({
name: {
Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Playground/PlaygroundRenderer.js
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Styled from 'rsg-components/Styled';

export const styles = ({ space, color, borderRadius }) => ({
Expand Down
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import cx from 'clsx';
import Heading from 'rsg-components/Heading';
import Styled from 'rsg-components/Styled';

Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/StyleGuide/StyleGuideRenderer.js
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import Logo from 'rsg-components/Logo';
import Markdown from 'rsg-components/Markdown';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
import cx from 'clsx';
import Ribbon from 'rsg-components/Ribbon';
import Version from 'rsg-components/Version';

Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/TabButton/TabButtonRenderer.js
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
import cx from 'clsx';

export const styles = ({ space, color, fontFamily, fontSize, buttonTextTransform }) => ({
button: {
Expand Down
2 changes: 1 addition & 1 deletion src/client/rsg-components/Text/TextRenderer.js
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
import cx from 'clsx';

export const styles = ({ fontFamily, fontSize, color }) => ({
text: {
Expand Down
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
import cx from 'clsx';

export const styles = ({ space, color }) => ({
button: {
Expand Down
4 changes: 2 additions & 2 deletions src/loaders/__tests__/examples-loader.spec.js
@@ -1,4 +1,4 @@
import qs from 'querystringify';
import { encode } from 'qss';
import examplesLoader from '../examples-loader';

/* eslint-disable no-new-func */
Expand All @@ -9,7 +9,7 @@ const query = {
shouldShowDefaultExample: false,
};

const getQuery = (options = {}) => `?${qs.stringify({ ...query, ...options })}`;
const getQuery = (options = {}) => encode({ ...query, ...options }, '?');

it('should return valid, parsable JS', () => {
const exampleMarkdown = `
Expand Down
4 changes: 2 additions & 2 deletions src/loaders/utils/getExamples.js
@@ -1,6 +1,6 @@
// @flow
import path from 'path';
import qs from 'querystringify';
import { encode } from 'qss';
import requireIt from './requireIt';

const examplesLoader = path.resolve(__dirname, '../examples-loader.js');
Expand All @@ -26,5 +26,5 @@ module.exports = function getExamples(
file: relativePath,
shouldShowDefaultExample: !examplesFile && !!defaultExample,
};
return requireIt(`!!${examplesLoader}?${qs.stringify(query)}!${examplesFileToLoad}`);
return requireIt(`!!${examplesLoader}?${encode(query)}!${examplesFileToLoad}`);
};

0 comments on commit 63a3a47

Please sign in to comment.