Skip to content

Commit 24873a6

Browse files
authored
refactor!: migrate to esm-only and update ml-levenberg-marquardt (#112)
* migrate jest to vitest * switch to `@zakodium/tsconfig` base config override `noUncheckedIndexedAccess` to `false` * update to eslint v9 with `eslint-config-cheminfo-typescript` base config Refs: https://github.com/cheminfo/generator-cheminfo/blob/main/ts-migration.md Closes: #111
1 parent d902e31 commit 24873a6

27 files changed

+147
-148
lines changed

.eslintrc.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/npm-prerelease.yml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.github/workflows/npm-prerelease.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
uses: zakodium/workflows/.github/workflows/npm-prerelease.yml@npm-prerelease-v1
1212
secrets:
1313
github-token: ${{ secrets.BOT_TOKEN }}
14-
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
14+
npm-token: ${{ secrets.NPM_BOT_TOKEN }}

.github/workflows/release.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
name: Release
2-
3-
on:
4-
push:
5-
branches:
6-
- main
7-
8-
jobs:
9-
release:
10-
# Documentation: https://github.com/zakodium/workflows#release
11-
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
12-
with:
13-
npm: true
14-
secrets:
15-
github-token: ${{ secrets.BOT_TOKEN }}
16-
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
# Documentation: https://github.com/zakodium/workflows#release
11+
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
12+
with:
13+
npm: true
14+
secrets:
15+
github-token: ${{ secrets.BOT_TOKEN }}
16+
npm-token: ${{ secrets.NPM_BOT_TOKEN }}

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
coverage
2+
CHANGELOG.md

babel.config.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig, globalIgnores } from 'eslint/config';
2+
import ts from 'eslint-config-cheminfo-typescript/base';
3+
4+
export default defineConfig(globalIgnores(['coverage', 'lib']), ts, {
5+
files: ['script/**'],
6+
rules: {
7+
'no-console': 'off',
8+
},
9+
});

package.json

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@
22
"name": "ml-spectra-fitting",
33
"version": "4.2.4",
44
"description": "Fit spectra using gaussian or lorentzian",
5-
"main": "./lib/index.js",
6-
"module": "./lib-esm/index.js",
7-
"types": "./lib/index.d.ts",
5+
"type": "module",
6+
"exports": "./lib/index.js",
87
"files": [
98
"lib",
10-
"src",
11-
"lib-esm"
9+
"src"
1210
],
1311
"scripts": {
14-
"build": "npm run tsc && cheminfo-build --entry lib-esm/index.js --root SpectraFitting",
12+
"build": "npm run tsc && cheminfo-build --entry lib/index.js --root SpectraFitting",
1513
"check-types": "tsc --noEmit",
16-
"clean": "rimraf lib lib-esm",
17-
"eslint": "eslint src",
18-
"eslint-fix": "npm run eslint -- --fix",
14+
"clean": "rimraf lib",
15+
"eslint": "eslint .",
16+
"eslint-fix": "eslint . --fix",
1917
"prepack": "npm run tsc",
20-
"test": "npm run test-only && npm run eslint && npm run check-types && npm run prettier",
21-
"prettier": "prettier --check src",
22-
"prettier-write": "prettier --write src",
23-
"test-only": "jest --coverage",
24-
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
25-
"tsc-cjs": "tsc --project tsconfig.cjs.json",
26-
"tsc-esm": "tsc --project tsconfig.esm.json",
27-
"debug": "npm run prepublishOnly && node src/debug.js"
18+
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
19+
"prettier": "prettier --check .",
20+
"prettier-write": "prettier --write .",
21+
"test-only": "vitest --run --coverage",
22+
"tsc": "npm run clean && npm run tsc-build",
23+
"tsc-build": "tsc --project tsconfig.build.json"
2824
},
2925
"repository": {
3026
"type": "git",
@@ -46,23 +42,24 @@
4642
},
4743
"homepage": "https://github.com/mljs/spectra-fitting",
4844
"devDependencies": {
49-
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
50-
"@babel/preset-typescript": "^7.23.3",
51-
"@types/jest": "^29.5.12",
45+
"@types/node": "^24.0.1",
46+
"@vitest/coverage-v8": "^3.2.3",
47+
"@zakodium/tsconfig": "^1.0.1",
5248
"cheminfo-build": "^1.2.0",
53-
"eslint": "^8.57.0",
54-
"eslint-config-cheminfo-typescript": "^12.2.0",
55-
"jest": "^29.7.0",
49+
"eslint": "^9.28.0",
50+
"eslint-config-cheminfo-typescript": "^18.0.1",
5651
"jest-matcher-deep-close-to": "^3.0.2",
5752
"prettier": "^3.2.5",
53+
"rimraf": "^6.0.1",
5854
"spectrum-generator": "^8.0.11",
59-
"typescript": "^5.4.2"
55+
"typescript": "^5.8.3",
56+
"vitest": "^3.2.3"
6057
},
6158
"dependencies": {
6259
"cheminfo-types": "^1.7.2",
6360
"ml-array-max": "^1.2.4",
6461
"ml-direct": "^1.0.0",
65-
"ml-levenberg-marquardt": "^4.1.3",
62+
"ml-levenberg-marquardt": "^5.0.0",
6663
"ml-peak-shape-generator": "^4.1.4",
6764
"ml-spectra-processing": "^14.2.0"
6865
}

src/__tests__/globalOptimization.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { DataXY } from 'cheminfo-types';
2-
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
32
import { generateSpectrum } from 'spectrum-generator';
3+
import { describe, expect, it } from 'vitest';
44

5-
import { optimize } from '../index';
6-
7-
expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
5+
import { optimize } from '../index.ts';
86

97
describe('Optimize sum of Gaussians', () => {
108
const peaks = [
@@ -59,7 +57,7 @@ describe('Optimize sum of Gaussians', () => {
5957
for (const key in peak) {
6058
//@ts-expect-error to be improved
6159
const value = peak[key];
62-
// eslint-disable-next-line @typescript-eslint/no-loop-func
60+
6361
it(`peak at ${peak.x} key: ${key}`, () => {
6462
//@ts-expect-error to be improved
6563
expect(result.peaks[i][key]).toMatchCloseTo(value, 2);

src/__tests__/mixShapes.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { DataXY } from 'cheminfo-types';
2-
import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to';
32
import { generateSpectrum } from 'spectrum-generator';
3+
import { describe, expect, it } from 'vitest';
44

5-
import { optimize } from '../index';
6-
7-
expect.extend({ toBeDeepCloseTo, toMatchCloseTo });
5+
import { optimize } from '../index.ts';
86

97
describe('Sum of a mix of distributions', () => {
108
it('2 peaks', () => {
@@ -94,7 +92,8 @@ describe('Sum of a mix of distributions', () => {
9492
expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3);
9593
}
9694
});
97-
it('20 peaks with overlap', () => {
95+
// it seems CI needs extra time for this test
96+
it('20 peaks with overlap', { timeout: 10000 }, () => {
9897
const nbPeaks = 5;
9998
const peaks = [];
10099
for (let i = 0; i < nbPeaks; i++) {
@@ -119,7 +118,7 @@ describe('Sum of a mix of distributions', () => {
119118
optimization: { options: { maxIterations: 10 } },
120119
});
121120
// we have a little bit more error on mu
122-
//@ts-expect-error we ignoere this ts error
121+
//@ts-expect-error we ignore this ts error
123122
peaks.forEach((peak) => peak.shape.mu && delete peak.shape.mu);
124123
for (let i = 0; i < result.peaks.length; i++) {
125124
expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3);

0 commit comments

Comments
 (0)