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

chore(deps): use the lodash-es dependency #2678

Merged
merged 8 commits into from
May 22, 2023
Merged

chore(deps): use the lodash-es dependency #2678

merged 8 commits into from
May 22, 2023

Conversation

tbouffard
Copy link
Member

@tbouffard tbouffard commented May 11, 2023

Previously, there were 2 CommonJS dependencies: lodash-throttle and lodash-debounce.
It is now replaced by a single ESM dependency: lodash-es.

The change reduces the size of the minified IIFE bundle from 1.2kb.
With the CommonJS lodash dependencies, as the throttle implementation calls debounce, debounce is present in lodash-throttle. In this case, rollup (that generates the bundle) is unable to tree shaked the duplication.
In the resulting bpmn-viusalization IIFE bundle, there are 2 debounce implementation: debounce (from lodash-debounce)and debounce$1 (from lodash-throttle).
Notice that the previous CommonJS dependencies only includes the necessary code to run. The new lodash-es dependency includes the whole lodash code which increases the size at installation on dev machine.

The usage of a ESM dependency also provides a better interoperability for bundlers. For example, Angular 15 warns usage of CommonJS dependencies. In the past, application integrating bpmn-visualization had to add configuration to remove the warning emited because of lodash dependencies.
This also reduces the number of dependencies from 4 (2 libs and their related types) to 2.

Notes

bpmn-visualization.min.js size decrease: 1211b / 1.2kb

bundle master 006f196 new
bpmn-visualization.js 2 925 511 2 916 533
bpmn-visualization.min.js 986 964 985 753

Resources

Some alternatives to lodash for debounce/throttle:

Tasks

FAIL  test/unit/component/mxgraph/overlay/OverlayConverter.test.ts
    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /process-analytics/repo/bpmn-visualization-js/node_modules/lodash-es/lodash.js:10
    export { default as add } from './add.js';
    ^^^^^^

    SyntaxError: Unexpected token 'export'

      18 | import { FitType } from '../options';
      19 | import { ensurePositiveValue, ensureValidZoomConfiguration } from '../helpers/validators';
    > 20 | import { debounce } from 'lodash-es';
         | ^
      21 | import { throttle } from 'lodash-es';
      22 | import { mxgraph } from './initializer';
      23 | import type { mxCellState, mxGraphView, mxPoint } from 'mxgraph';

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1495:14)
      at Object.<anonymous> (src/component/mxgraph/BpmnGraph.ts:20:1)
      at Object.<anonymous> (src/component/mxgraph/GraphConfigurator.ts:21:1)
      at Object.<anonymous> (src/component/BpmnVisualization.ts:17:1)
      at Object.<anonymous> (src/bpmn-visualization.ts:22:1)
      at Object.<anonymous> (test/unit/component/mxgraph/overlay/OverlayConverter.test.ts:23:1)

@tbouffard tbouffard added dependencies Pull requests that update a dependency (dev or runtime) javascript Pull requests that update Javascript code labels May 11, 2023
@github-actions
Copy link

github-actions bot commented May 11, 2023

♻️ PR Preview 70f1ebe has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@github-actions
Copy link

github-actions bot commented May 11, 2023

♻️ PR Preview 70f1ebe has been successfully destroyed since this PR has been closed.

🤖 By surge-preview

@tbouffard tbouffard marked this pull request as ready for review May 21, 2023 19:03
@tbouffard tbouffard requested a review from csouchet May 21, 2023 19:04
@sonarcloud
Copy link

sonarcloud bot commented May 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@tbouffard tbouffard merged commit 6c32d5a into master May 22, 2023
@tbouffard tbouffard deleted the deps/lodash-es branch May 22, 2023 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency (dev or runtime) javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants