Skip to content

Commit 2fe9aba

Browse files
authored
feat: add typescript (#41)
add typescript and types definitions for charts, add tree-shaking for chart.js imports BREAKING CHANGE: add typescript and tree-shaking for chart.js imports
1 parent 3075786 commit 2fe9aba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1323
-787
lines changed

.babelrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
[
44
"@babel/preset-env",
55
{
6+
"loose": true,
7+
"modules": false,
68
"targets": {
7-
"node": "current"
9+
"esmodules": true
810
}
911
}
1012
]

.eslintrc.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
2+
"parser": "@typescript-eslint/parser",
23
"plugins": [
3-
"import",
4-
"svelte3"
4+
"svelte3",
5+
"@typescript-eslint"
56
],
67
"extends": [
78
"eslint:recommended",
89
"plugin:import/recommended"
910
],
1011
"env": {
11-
"browser": true
12+
"browser": true,
13+
"node": true
1214
},
1315
"overrides": [
1416
{
@@ -38,6 +40,10 @@
3840
"always"
3941
],
4042
"strict": 0,
41-
"no-use-before-define": 0
43+
"no-use-before-define": 0,
44+
"import/no-unresolved": 0
45+
},
46+
"settings": {
47+
"svelte3/typescript": true
4248
}
4349
}

.github/workflows/checks.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Install pnpm
1515
uses: pnpm/[email protected]
1616
with:
17-
version: 6
17+
version: 7
1818
- name: Install Node.js
1919
uses: actions/setup-node@v3
2020
with:
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install pnpm
3434
uses: pnpm/[email protected]
3535
with:
36-
version: 6
36+
version: 7
3737
- name: Install Node.js
3838
uses: actions/setup-node@v3
3939
with:

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ jobs:
1313
- name: Install pnpm
1414
uses: pnpm/[email protected]
1515
with:
16-
version: 6
16+
version: 7
1717
- name: Install Node.js
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: 12
20+
node-version: 16
2121
cache: 'pnpm'
2222
- name: Install dependencies
2323
run: pnpm install

.github/workflows/release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Install pnpm
1313
uses: pnpm/[email protected]
1414
with:
15-
version: 6
15+
version: 7
1616
- name: Install Node.js
1717
uses: actions/setup-node@v3
1818
with:

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
strict-peer-dependencies=false

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"tabWidth": 2,
55
"bracketSpacing": true,
66
"arrowParens": "avoid",
7-
"trailingComma": "es5"
7+
"trailingComma": "es5",
8+
"plugins": ["prettier-plugin-svelte"]
89
}

.storybook/main.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
const path = require('path');
22

33
module.exports = {
4-
stories: ['../stories/*.stories.js'],
4+
webpackFinal: async config => {
5+
const svelteLoader = config.module.rules.find(
6+
r => r.loader && r.loader.includes('svelte-loader')
7+
);
8+
svelteLoader.options.preprocess = require('svelte-preprocess')({});
9+
config.resolve.alias['svelte-chartjs'] = path.resolve(
10+
__dirname,
11+
'../src'
12+
);
13+
return config;
14+
},
15+
stories: ['../stories/*.stories.(js|ts)'],
516
addons: ['@storybook/addon-essentials'],
617
framework: '@storybook/svelte',
718
};

jest.config.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"testEnvironment": "jsdom",
33
"setupFiles": ["<rootDir>/test/setup.js"],
44
"testMatch": ["<rootDir>/test/(*.)spec.(js|ts)"],
5+
"moduleFileExtensions": ["js", "svelte", "ts"],
56
"transform": {
67
"^.+\\.(t|j)sx?$": [
78
"@swc/jest",
@@ -16,9 +17,13 @@
1617
}
1718
}
1819
],
19-
"^.+\\.svelte$": "svelte-jester"
20+
"^.+\\.svelte$": [
21+
"svelte-jester",
22+
{
23+
"preprocess": "./svelte.config.mjs"
24+
}
25+
]
2026
},
21-
"moduleFileExtensions": ["js", "svelte"],
2227
"collectCoverage": true,
2328
"collectCoverageFrom": ["<rootDir>/src/**/*"],
2429
"coverageReporters": ["lcovonly", "text"]

package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"author": "Saurav Kanchan",
55
"homepage": "https://saurav.tech/mdbsvelte/?path=/story/charts--examples",
66
"license": "MIT",
7-
"module": "lib/index.mjs",
8-
"main": "src/index.js",
7+
"main": "src/index.ts",
98
"publishConfig": {
109
"main": "./dist/index.cjs",
1110
"module": "./dist/index.js",
@@ -27,11 +26,13 @@
2726
"url": "https://github.com/SauravKanchan/svelte-chartjs"
2827
},
2928
"scripts": {
30-
"build": "rollup -c",
29+
"emitDeclarations": "node scripts/emitSvelteDeclarations.cjs",
30+
"build:svelte": "svelte-strip strip src/ dist",
31+
"build": "rollup -c && pnpm build:svelte && pnpm emitDeclarations",
3132
"prepublishOnly": "pnpm test && pnpm build && del ./package && clean-publish",
3233
"postpublish": "del ./package",
3334
"commit": "cz",
34-
"format": "prettier --write 'src/**/*.{js,svelte}'",
35+
"format": "prettier --write 'src/**/*.{js,ts,svelte}'",
3536
"test:lint": "eslint src --ext .js,.svelte",
3637
"test:size": "size-limit",
3738
"test:unit": "jest -c jest.config.json",
@@ -52,7 +53,6 @@
5253
"@commitlint/cli": "^17.0.2",
5354
"@commitlint/config-conventional": "^17.0.2",
5455
"@commitlint/cz-commitlint": "^17.0.0",
55-
"@rollup/plugin-commonjs": "11.1.0",
5656
"@rollup/plugin-node-resolve": "^13.3.0",
5757
"@size-limit/preset-big-lib": "^7.0.8",
5858
"@storybook/addon-actions": "^6.5.9",
@@ -61,6 +61,9 @@
6161
"@swc/core": "^1.2.207",
6262
"@swc/jest": "^0.2.21",
6363
"@testing-library/svelte": "^3.1.3",
64+
"@types/jest": "^28.1.5",
65+
"@typescript-eslint/eslint-plugin": "^5.30.6",
66+
"@typescript-eslint/parser": "^5.30.6",
6467
"chart.js": "^3.5.0",
6568
"clean-publish": "^4.0.1",
6669
"commitizen": "^4.2.4",
@@ -78,12 +81,16 @@
7881
"rollup": "^2.75.7",
7982
"rollup-plugin-livereload": "^1.0.0",
8083
"rollup-plugin-svelte": "^7.1.0",
81-
"rollup-plugin-terser": "^5.1.2",
84+
"rollup-plugin-swc": "^0.2.1",
8285
"simple-github-release": "^1.0.0",
8386
"size-limit": "^7.0.8",
8487
"standard-version": "^9.5.0",
8588
"svelte": "^3.45.0",
8689
"svelte-jester": "^2.3.2",
87-
"svelte-loader": "^3.1.3"
90+
"svelte-loader": "^3.1.3",
91+
"svelte-preprocess": "^4.10.7",
92+
"svelte-strip": "^1.0.1",
93+
"svelte2tsx": "^0.5.11",
94+
"typescript": "^4.7.4"
8895
}
8996
}

0 commit comments

Comments
 (0)