chartjs-plugin-trendline 3.1.1 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,10 @@ jobs:
10
10
  publish:
11
11
  runs-on: ubuntu-latest
12
12
 
13
+ permissions:
14
+ id-token: write
15
+ contents: read
16
+
13
17
  steps:
14
18
  - name: Checkout repository
15
19
  uses: actions/checkout@v4
@@ -20,8 +24,11 @@ jobs:
20
24
  node-version: '22'
21
25
  registry-url: 'https://registry.npmjs.org/'
22
26
 
27
+ - name: Upgrade npm for OIDC support
28
+ run: npm install -g npm@latest
29
+
23
30
  - name: Install dependencies
24
- run: npm ci
31
+ run: npm install
25
32
 
26
33
  - name: Build
27
34
  run: npm run build
@@ -50,12 +57,8 @@ jobs:
50
57
 
51
58
  - name: Publish to npm (beta)
52
59
  if: startsWith(github.ref, 'refs/tags/beta/')
53
- run: npm publish --tag beta
54
- env:
55
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
60
+ run: npm publish --tag beta --provenance --access public
56
61
 
57
62
  - name: Publish to npm (latest)
58
63
  if: startsWith(github.ref, 'refs/tags/v')
59
- run: npm publish
60
- env:
61
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
64
+ run: npm publish --provenance --access public
package/MIGRATION.md ADDED
@@ -0,0 +1,126 @@
1
+ # Migration Guide - v3.2.0
2
+
3
+ ## What Changed?
4
+
5
+ Version 3.2.0 introduces ES module (ESM) support as the primary distribution format while maintaining backward compatibility with CommonJS and browser usage.
6
+
7
+ ## Breaking Changes
8
+
9
+ ### 1. Package Distribution Format
10
+
11
+ The package now uses **dual package exports** with ESM as the default:
12
+
13
+ **Before (v3.x):**
14
+ - Single UMD bundle: `dist/chartjs-plugin-trendline.min.js`
15
+ - CommonJS-style package
16
+
17
+ **After (v3.2.x):**
18
+ - ESM build: `dist/chartjs-plugin-trendline.esm.js`
19
+ - CommonJS build: `dist/chartjs-plugin-trendline.cjs`
20
+ - UMD build (unminified): `dist/chartjs-plugin-trendline.js`
21
+ - UMD build (minified): `dist/chartjs-plugin-trendline.min.js`
22
+
23
+ ### 2. Import Changes
24
+
25
+ #### Modern Bundlers (Vite, SvelteKit, Next.js, webpack 5)
26
+ No changes needed! Your bundler will automatically use the ESM version:
27
+
28
+ ```javascript
29
+ import ChartJSTrendline from 'chartjs-plugin-trendline';
30
+ ```
31
+
32
+ #### Node.js with CommonJS
33
+ The CommonJS build is automatically used when using `require()`:
34
+
35
+ ```javascript
36
+ const ChartJSTrendline = require('chartjs-plugin-trendline');
37
+ ```
38
+
39
+ #### Browser via CDN
40
+ The global export name has changed:
41
+
42
+ **Before:**
43
+ ```html
44
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline@3"></script>
45
+ <!-- Plugin auto-registered with Chart.js -->
46
+ ```
47
+
48
+ **After:**
49
+ ```html
50
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline@3"></script>
51
+ <script>
52
+ // Option 1: Plugin auto-registers if Chart.js is available
53
+ // Option 2: Manual registration
54
+ Chart.register(ChartJSTrendline);
55
+ </script>
56
+ ```
57
+
58
+ ## Benefits
59
+
60
+ ### For Modern Projects
61
+ - ✅ Better tree-shaking support
62
+ - ✅ Faster build times with Vite, SvelteKit, and modern bundlers
63
+ - ✅ Full ESM support
64
+ - ✅ Smaller bundle sizes (only import what you need)
65
+
66
+ ### For Legacy Projects
67
+ - ✅ Backward compatible with CommonJS
68
+ - ✅ UMD builds still available for browser `<script>` tags
69
+ - ✅ Works with older webpack and Node.js versions
70
+
71
+ ## Recommendations
72
+
73
+ ### New Projects
74
+ Use ESM imports with modern bundlers (Vite, SvelteKit, Next.js, Nuxt):
75
+
76
+ ```javascript
77
+ import ChartJSTrendline from 'chartjs-plugin-trendline';
78
+ import { Chart } from 'chart.js';
79
+
80
+ Chart.register(ChartJSTrendline);
81
+ ```
82
+
83
+ ### Legacy Projects
84
+ Continue using CommonJS `require()`:
85
+
86
+ ```javascript
87
+ const ChartJSTrendline = require('chartjs-plugin-trendline');
88
+ const Chart = require('chart.js');
89
+
90
+ Chart.register(ChartJSTrendline);
91
+ ```
92
+
93
+ ### Browser CDN
94
+ Use the minified UMD build:
95
+
96
+ ```html
97
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
98
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline@3"></script>
99
+ ```
100
+
101
+ ## Technical Details
102
+
103
+ ### Package.json Configuration
104
+
105
+ ```json
106
+ {
107
+ "type": "module",
108
+ "main": "./dist/chartjs-plugin-trendline.cjs",
109
+ "module": "./dist/chartjs-plugin-trendline.esm.js",
110
+ "exports": {
111
+ ".": {
112
+ "import": "./dist/chartjs-plugin-trendline.esm.js",
113
+ "require": "./dist/chartjs-plugin-trendline.cjs"
114
+ }
115
+ }
116
+ }
117
+ ```
118
+
119
+ This ensures:
120
+ - Modern bundlers use the ESM version
121
+ - Node.js `require()` uses the CommonJS version
122
+ - Maximum compatibility across environments
123
+
124
+ ## Questions?
125
+
126
+ If you encounter any issues during migration, please [open an issue](https://github.com/Makanz/chartjs-plugin-trendline/issues) on GitHub.
package/README.md CHANGED
@@ -9,28 +9,45 @@ See the plugin in action with interactive examples for different chart types.
9
9
 
10
10
  ## Installation
11
11
 
12
- #### Load directly in the browser
12
+ > **Note:** Version 3.2.0+ supports ES modules (ESM) for modern bundlers like Vite, SvelteKit, and Next.js. See [MIGRATION.md](./MIGRATION.md) for upgrade details.
13
13
 
14
- Load Chart.js first, then the plugin which will automatically register itself with Chart.js
14
+ ### Modern Bundlers (Vite, SvelteKit, Next.js, webpack 5+)
15
15
 
16
- ```html
17
- <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.min.js"></script>
18
- <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
16
+ Install via npm:
17
+
18
+ ```bash
19
+ npm i chart.js chartjs-plugin-trendline
19
20
  ```
20
21
 
21
- #### As a Chart.JS plugin
22
+ Import and register with Chart.js:
22
23
 
23
- Install & import the plugin via npm:
24
+ ```js
25
+ import { Chart } from 'chart.js';
26
+ import ChartJSTrendline from 'chartjs-plugin-trendline';
27
+
28
+ Chart.register(ChartJSTrendline);
29
+ ```
24
30
 
25
- `npm i chart.js chartjs-plugin-trendline`
31
+ ### Node.js (CommonJS)
26
32
 
27
33
  ```js
28
- import ChartJS from 'chart.js';
29
- import chartTrendline from 'chartjs-plugin-trendline';
34
+ const { Chart } = require('chart.js');
35
+ const ChartJSTrendline = require('chartjs-plugin-trendline');
30
36
 
31
- ChartJS.plugins.register(chartTrendline);
37
+ Chart.register(ChartJSTrendline);
32
38
  ```
33
39
 
40
+ ### Browser (CDN)
41
+
42
+ Load Chart.js first, then the plugin which will automatically register itself:
43
+
44
+ ```html
45
+ <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.9/dist/chart.min.js"></script>
46
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-trendline/dist/chartjs-plugin-trendline.min.js"></script>
47
+ ```
48
+
49
+ The plugin is now available globally as `ChartJSTrendline` and auto-registers with Chart.js.
50
+
34
51
  ## Configuration
35
52
 
36
53
  To configure the trendline plugin you simply add a new config options to your dataset in your chart config.
package/babel.config.js CHANGED
@@ -1,3 +1,3 @@
1
- module.exports = {
1
+ export default {
2
2
  presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
3
3
  };