Skip to content

Commit

Permalink
chore: convert to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Oct 26, 2024
1 parent 20cbeb4 commit 73ef3e3
Show file tree
Hide file tree
Showing 17 changed files with 830 additions and 572 deletions.
16 changes: 6 additions & 10 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ const env = process.env.NODE_ENV;

module.exports = function(karma) {
const build = builds[0];
const buildPlugins = [...build.plugins]

if (env === 'test') {
build.plugins = [
resolve(),
istanbul({exclude: ['node_modules/**/*.js', 'package.json']})
];
build.plugins.push(istanbul({exclude: ['node_modules/**/*.js', 'package.json']}));
}

karma.set({
Expand All @@ -24,8 +22,8 @@ module.exports = function(karma) {
{pattern: './test/fixtures/**/*.png', included: false},
'node_modules/chart.js/dist/chart.umd.js',
'test/index.js',
'src/index.js',
'test/specs/**/*.js'
{pattern: 'src/index.ts', type: 'js'},
{pattern: 'test/specs/**/*.js', type: 'js'},
],

customLaunchers: {
Expand All @@ -49,13 +47,11 @@ module.exports = function(karma) {
'test/fixtures/**/*.js': ['fixtures'],
'test/specs/**/*.js': ['rollup'],
'test/index.js': ['rollup'],
'src/index.js': ['sources']
'src/index.ts': ['sources']
},

rollupPreprocessor: {
plugins: [
resolve(),
],
plugins: buildPlugins,
external: [
'chart.js'
],
Expand Down
237 changes: 237 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
"homepage": "https://github.com/kurkle/chartjs-chart-sankey#readme",
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-swc": "^0.4.0",
"@rollup/plugin-terser": "^0.4.0",
"@swc/core": "^1.7.40",
"@typescript-eslint/eslint-plugin": "^8.11.0",
"@typescript-eslint/parser": "^8.11.0",
"chart.js": "^4.0.1",
Expand Down
23 changes: 20 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const resolve = require('@rollup/plugin-node-resolve').default;
const terser = require('@rollup/plugin-terser').default;
const { default: swc } = require('@rollup/plugin-swc');
const {author, name, version, homepage, main, module: _module, license} = require('./package.json');

const banner = `/*!
Expand All @@ -9,8 +10,8 @@ const banner = `/*!
* Released under the ${license} license
*/`;

const input = 'src/index.js';
const inputESM = 'src/index.esm.js';
const input = 'src/index.ts';
const inputESM = 'src/index.esm.ts';
const external = [
'chart.js',
'chart.js/helpers'
Expand All @@ -20,6 +21,19 @@ const globals = {
'chart.js/helpers': 'Chart.helpers'
};

const swcOptions = {
jsc: {
parser: {
syntax: 'typescript'
},
target: 'es2022'
},
module: {
type: 'es6'
},
sourceMaps: true
}

module.exports = [
{
input,
Expand All @@ -32,6 +46,7 @@ module.exports = [
},
plugins: [
resolve(),
swc(swcOptions),
],
external
},
Expand All @@ -45,6 +60,7 @@ module.exports = [
},
plugins: [
resolve(),
swc(swcOptions),
terser({
output: {
preamble: banner
Expand All @@ -63,7 +79,8 @@ module.exports = [
globals
},
plugins: [
resolve()
resolve(),
swc(swcOptions),
],
external
}
Expand Down
Loading

0 comments on commit 73ef3e3

Please sign in to comment.