Skip to content

Commit

Permalink
LG-4662: Fix CommonJS imports (#2587)
Browse files Browse the repository at this point in the history
* Remove tree-shaking

* Delete rollup config

* Changeset

* Fix tests
  • Loading branch information
tsck authored Dec 10, 2024
1 parent d59d8ee commit 6e37cfa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/rude-dryers-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lg-charts/core': patch
---

Fixes CommonJS imports
18 changes: 1 addition & 17 deletions charts/core/src/Chart/hooks/useChart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SeriesOption } from '../Chart.types';

import { useChart } from './useChart';

jest.mock('echarts/core', () => ({
jest.mock('echarts', () => ({
init: jest.fn(() => ({
setOption: jest.fn(),
dispose: jest.fn(),
Expand All @@ -16,22 +16,6 @@ jest.mock('echarts/core', () => ({
use: jest.fn(),
}));

jest.mock('echarts/charts', () => ({
LineChart: jest.fn(),
}));

jest.mock('echarts/components', () => ({
TitleComponent: jest.fn(),
TooltipComponent: jest.fn(),
GridComponent: jest.fn(),
LegendComponent: jest.fn(),
ToolboxComponent: jest.fn(),
}));

jest.mock('echarts/renderers', () => ({
CanvasRenderer: jest.fn(),
}));

describe('@lg-echarts/core/hooks/useChart', () => {
test('should return an object with the correct properties', () => {
const { result } = renderHook(() => useChart({ theme: 'dark' }));
Expand Down
30 changes: 1 addition & 29 deletions charts/core/src/Chart/hooks/useChart.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { LineChart as EchartsLineChart } from 'echarts/charts';
import {
DataZoomComponent,
DataZoomInsideComponent,
GridComponent,
LegendComponent,
TitleComponent,
ToolboxComponent,
TooltipComponent,
} from 'echarts/components';
import * as echarts from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import * as echarts from 'echarts';
import debounce from 'lodash.debounce';

import { ChartOptions, SeriesOption } from '../../Chart/Chart.types';
Expand All @@ -20,23 +9,6 @@ import { getDefaultChartOptions } from '../config';
import { addSeries, removeSeries, updateOptions } from './updateUtils';
import { ChartHookProps, ZoomSelectionEvent } from './useChart.types';

/**
* Register the required components. By using separate imports, we can avoid
* importing the entire echarts library which will reduce the bundle size.
* Must be added to if additional functionality is supported.
*/
echarts.use([
TitleComponent,
TooltipComponent,
GridComponent,
LegendComponent,
EchartsLineChart,
CanvasRenderer,
ToolboxComponent,
DataZoomComponent,
DataZoomInsideComponent,
]);

/**
* Creates a generic Apache ECharts options object with default values for those not set
* that are in line with the designs and needs of the design system.
Expand Down

0 comments on commit 6e37cfa

Please sign in to comment.