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

Clean dependencies #739

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@
"@babel/types": "^7.16.0",
"@modular-css/processor": "^27.0.3",
"common-tags": "^1.8.2",
"cosmiconfig": "^7.0.1",
"css-loader": "^5.1.3",
"fast-glob": "^3.2.7",
"fast-levenshtein": "^3.0.0",
"find-cache-dir": "^3.3.2",
"globby": "^11.0.0",
"json5": "^2.2.0",
"lodash": "^4.17.21",
"lilconfig": "^2.0.4",
"lodash.camelcase": "^4.3.0",
"lodash.defaults": "^4.2.0",
"lodash.flow": "^3.5.0",
"lodash.get": "^4.4.2",
"lodash.groupby": "^4.6.0",
"lodash.sortby": "^4.7.0",
"lodash.uniq": "^4.5.0",
"lodash.upperfirst": "^4.3.1",
"magic-string": "^0.25.7",
"picocolors": "^1.0.0",
"postcss": "^8.4.5",
Expand All @@ -106,8 +113,14 @@
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.15.0",
"@types/common-tags": "^1.8.1",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.172",
"@types/lodash.camelcase": "^4.3.6",
"@types/lodash.defaults": "^4.2.6",
"@types/lodash.flow": "^3.5.6",
"@types/lodash.get": "^4.4.6",
"@types/lodash.groupby": "^4.6.6",
"@types/lodash.sortby": "^4.7.6",
"@types/lodash.uniq": "^4.5.6",
"@types/lodash.upperfirst": "^4.3.6",
"@types/react": "^17.0.18",
"@types/react-dom": "^17.0.9",
"@types/resolve": "^1.20.1",
Expand Down
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from 'path';

import Processor from '@modular-css/processor';
import Output from '@modular-css/processor/lib/output';
import globby from 'globby';
import fastGlob from 'fast-glob';
import { AtRule, PluginCreator, Result, Rule } from 'postcss';
import postcssScss from 'postcss-scss';
import resolve from 'resolve';
Expand Down Expand Up @@ -280,7 +280,7 @@ yargs
}),

async ({ _, 'css-out-file': cssOutFile, config: configFile }) => {
const files = await globby(_);
const files = await fastGlob(_);

await handler({ files, outFile: cssOutFile, configFile });
},
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cosmiconfig } from 'cosmiconfig';
import JSON5 from 'json5';
import { lilconfig } from 'lilconfig';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the tradeoff for this. is lilconfig feature matched with cosmiconfig (given what we and users might depend on)?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature match is the idea of lilconfig (but it has fewer dependencies and works faster). I moved from cosmiconfig to lilconfig in PostCSS Load Config and Size Limit without any problems.


const explorer = cosmiconfig('astroturf', {
const explorer = lilconfig('astroturf', {
searchPlaces: ['package.json', `.astroturfrc`, `.astroturfrc.json`],
loaders: {
json: (_file: string, content: string) => JSON5.parse(content),
Expand Down
2 changes: 1 addition & 1 deletion src/features/styled-component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodePath } from '@babel/core';
import generate from '@babel/generator';
import * as t from '@babel/types';
import get from 'lodash/get';
import get from 'lodash.get';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike these little packages. they may be smaller but it usually balloons the dep tree and number of transitive dependencies significantly. What is the actual cost saves between all of them over installing lodash. TBH I don't understand this sort of optimization, even on slow networks installing 70kb of text is not expensive, in the context of "putting files on disk to do development", I would imagine (unscientifically) having more limited deps, thereby reducing the amount of network hops and logic required by bundlers to install would be faster overall.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lodash is 1.3 MB vs 23 KB for lodash.get

For instance, I don't have lodash in subdependecies of my projects. Adding extra MB will slow down CI by a few seconds.

Copy link

@krutoo krutoo Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RKatarine @jquense @ai can we replace lodash by native ECMAScript features?


import {
DynamicStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import generate from '@babel/generator';
import { NodePath, visitors } from '@babel/traverse';
import * as t from '@babel/types';
import { stripIndent } from 'common-tags';
import defaults from 'lodash/defaults';
import defaults from 'lodash.defaults';

import cssProp from './features/css-prop';
import styledComponent from './features/styled-component';
Expand Down
6 changes: 3 additions & 3 deletions src/utils/buildTaggedTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NodePath } from '@babel/core';
import * as t from '@babel/types';
import camelCase from 'lodash/camelCase';
import groupBy from 'lodash/groupBy';
import uniq from 'lodash/uniq';
import camelCase from 'lodash.camelcase';
import groupBy from 'lodash.groupby';
import uniq from 'lodash.uniq';

import { NodeStyleMap, ResolvedOptions, Style } from '../types';
import cssUnits from './cssUnits';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/loaders.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { codeFrameColumns } from '@babel/code-frame';
import { SourceLocation } from '@babel/types';
import levenshtein from 'fast-levenshtein';
import sortBy from 'lodash/sortBy';
import sortBy from 'lodash.sortby';
import MagicString from 'magic-string';
import pico from 'picocolors';
import type { CssSyntaxError } from 'postcss';
Expand Down
6 changes: 3 additions & 3 deletions src/utils/pascalCase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import camelCase from 'lodash/camelCase';
import flow from 'lodash/flow';
import upperFirst from 'lodash/upperFirst';
import camelCase from 'lodash.camelcase';
import flow from 'lodash.flow';
import upperFirst from 'lodash.upperfirst';

export default flow(camelCase, upperFirst);
8 changes: 4 additions & 4 deletions test/__file_snapshots__/issue-365-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var astroturf_react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! astroturf/react */ "../src/runtime/react.js");
/* harmony import */ var issue_365_mixins_module_css_astroturf_inline_loader_style_1_Users_jquense_src_astroturf_test_integration_issue_365_js_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! issue-365-mixins.module.css!=!astroturf/inline-loader?style=1!./integration/issue-365.js?mixins */ "issue-365-mixins.module.css!=!../src/inline-loader.ts?style=1!./integration/issue-365.js?mixins");
/* harmony import */ var issue_365_BlockStyled_module_css_astroturf_inline_loader_style_1_Users_jquense_src_astroturf_test_integration_issue_365_js_BlockStyled__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! issue-365-BlockStyled.module.css!=!astroturf/inline-loader?style=1!./integration/issue-365.js?BlockStyled */ "issue-365-BlockStyled.module.css!=!../src/inline-loader.ts?style=1!./integration/issue-365.js?BlockStyled");
/* harmony import */ var issue_365_mixins_module_css_astroturf_inline_loader_style_1_Users_ekaterinarazanova_astroturf_test_integration_issue_365_js_mixins__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! issue-365-mixins.module.css!=!astroturf/inline-loader?style=1!./integration/issue-365.js?mixins */ "issue-365-mixins.module.css!=!../src/inline-loader.ts?style=1!./integration/issue-365.js?mixins");
/* harmony import */ var issue_365_BlockStyled_module_css_astroturf_inline_loader_style_1_Users_ekaterinarazanova_astroturf_test_integration_issue_365_js_BlockStyled__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! issue-365-BlockStyled.module.css!=!astroturf/inline-loader?style=1!./integration/issue-365.js?BlockStyled */ "issue-365-BlockStyled.module.css!=!../src/inline-loader.ts?style=1!./integration/issue-365.js?BlockStyled");



const mixins = issue_365_mixins_module_css_astroturf_inline_loader_style_1_Users_jquense_src_astroturf_test_integration_issue_365_js_mixins__WEBPACK_IMPORTED_MODULE_1__["default"].cls2;
const mixins = issue_365_mixins_module_css_astroturf_inline_loader_style_1_Users_ekaterinarazanova_astroturf_test_integration_issue_365_js_mixins__WEBPACK_IMPORTED_MODULE_1__["default"].cls2;
const Block = /*#__PURE__*/React.createElement(BlockStyled, {
active: false
});
const BlockStyled = /*#__PURE__*/(0,astroturf_react__WEBPACK_IMPORTED_MODULE_0__["default"])("div", null, {
displayName: "BlockStyled",
styles: issue_365_BlockStyled_module_css_astroturf_inline_loader_style_1_Users_jquense_src_astroturf_test_integration_issue_365_js_BlockStyled__WEBPACK_IMPORTED_MODULE_2__["default"]
styles: issue_365_BlockStyled_module_css_astroturf_inline_loader_style_1_Users_ekaterinarazanova_astroturf_test_integration_issue_365_js_BlockStyled__WEBPACK_IMPORTED_MODULE_2__["default"]
});

/***/ }),
Expand Down

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

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

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

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

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

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

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

2 changes: 1 addition & 1 deletion test/__file_snapshots__/loader__pass-options-FancyBox.css

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

2 changes: 1 addition & 1 deletion test/__file_snapshots__/loader__styled-FancierBox.css

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

2 changes: 1 addition & 1 deletion test/__file_snapshots__/loader__styled-FancyBox.css

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

Loading