Skip to content

Commit c110206

Browse files
authored
refactor: remove filelist-utils and jszip for better alternatives (#3615)
BREAKING-CHANGE: `file-collection` is now used to manage data sources
1 parent 43f0b13 commit c110206

File tree

11 files changed

+699
-934
lines changed

11 files changed

+699
-934
lines changed

package-lock.json

Lines changed: 648 additions & 859 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,45 @@
5757
"dependencies": {
5858
"@atlaskit/pragmatic-drag-and-drop": "^1.7.4",
5959
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
60-
"@blueprintjs/core": "^6.0.0",
60+
"@blueprintjs/core": "^6.1.0",
6161
"@blueprintjs/icons": "^6.0.0",
62-
"@blueprintjs/select": "^6.0.0",
62+
"@blueprintjs/select": "^6.0.1",
6363
"@emotion/react": "^11.14.0",
6464
"@emotion/styled": "^11.14.1",
6565
"@hookform/resolvers": "^5.1.1",
66-
"@zakodium/nmr-types": "^0.0.1",
67-
"@zakodium/nmrium-core": "^0.1.3",
68-
"@zakodium/nmrium-core-plugins": "^0.1.4",
66+
"@zakodium/nmr-types": "^0.1.0",
67+
"@zakodium/nmrium-core": "^0.1.4",
68+
"@zakodium/nmrium-core-plugins": "^0.1.7",
69+
"@zip.js/zip.js": "^2.7.68",
6970
"cheminfo-font": "^1.13.1",
7071
"cheminfo-types": "^1.8.1",
7172
"clipboard-polyfill": "^4.1.1",
7273
"d3": "^7.9.0",
7374
"dlv": "^1.1.3",
7475
"eventemitter3": "^5.0.1",
7576
"fifo-logger": "^2.0.0",
77+
"file-collection": "^5.1.0",
7678
"file-saver": "^2.0.5",
77-
"filelist-utils": "^1.11.3",
7879
"immer": "^10.1.1",
79-
"jszip": "^3.10.1",
8080
"lodash": "^4.17.21",
8181
"mf-parser": "^3.4.2",
8282
"ml-array-mean": "^1.1.6",
8383
"ml-array-median": "^1.1.6",
8484
"ml-conrec": "^5.0.3",
8585
"ml-gsd": "^13.0.1",
8686
"ml-signal-processing": "^2.0.0",
87-
"ml-spectra-processing": "^14.13.0",
87+
"ml-spectra-processing": "^14.14.0",
8888
"ml-tree-similarity": "^2.2.0",
8989
"nmr-correlation": "2.3.3",
90-
"nmr-processing": "^19.0.1",
90+
"nmr-processing": "^19.0.3",
9191
"numeral": "^2.0.6",
9292
"openchemlib": "^9.6.0",
9393
"openchemlib-utils": "^8.2.0",
9494
"papaparse": "^5.5.3",
9595
"react-d3-utils": "^3.1.1",
9696
"react-dropzone": "^14.3.8",
9797
"react-error-boundary": "^6.0.0",
98-
"react-hook-form": "^7.60.0",
98+
"react-hook-form": "^7.61.1",
9999
"react-icons": "^5.5.0",
100100
"react-inspector": "^6.0.2",
101101
"react-mf": "^3.1.0",
@@ -114,37 +114,37 @@
114114
"@types/d3": "^7.4.3",
115115
"@types/dlv": "^1.1.5",
116116
"@types/lodash": "^4.17.20",
117-
"@types/node": "^24.0.13",
117+
"@types/node": "^24.1.0",
118118
"@types/papaparse": "^5.3.16",
119119
"@types/react": "^18.3.13",
120120
"@types/react-dom": "^18.3.1",
121121
"@types/react-table": "^7.7.20",
122-
"@vitejs/plugin-react": "^4.6.0",
122+
"@vitejs/plugin-react": "^4.7.0",
123123
"@vitest/coverage-v8": "^3.2.4",
124124
"@zakodium/tsconfig": "^1.0.2",
125125
"cross-env": "^7.0.3",
126-
"cspell": "^9.1.5",
126+
"cspell": "^9.2.0",
127127
"eslint": "^9.31.0",
128128
"eslint-config-cheminfo-react": "^17.0.0",
129129
"eslint-config-cheminfo-typescript": "^19.0.0",
130-
"knip": "^5.61.3",
130+
"knip": "^5.62.0",
131131
"modern-normalize": "^3.0.1",
132132
"postcss-styled-syntax": "^0.7.1",
133133
"prettier": "^3.6.2",
134134
"rc-menu": "^9.16.1",
135135
"react": "^18.3.1",
136136
"react-dom": "^18.3.1",
137-
"react-router-dom": "^7.6.3",
137+
"react-router-dom": "^7.7.0",
138138
"rimraf": "^6.0.1",
139139
"rollup-plugin-analyzer": "^4.0.0",
140140
"serve": "^14.2.4",
141-
"stylelint": "^16.21.1",
141+
"stylelint": "^16.22.0",
142142
"stylelint-config-standard": "^38.0.0",
143143
"typescript": "^5.8.3",
144-
"vite": "^7.0.4",
144+
"vite": "^7.0.6",
145145
"vitest": "^3.2.4"
146146
},
147147
"volta": {
148-
"node": "24.4.0"
148+
"node": "24.4.1"
149149
}
150150
}

src/component/loader/useLoadFiles.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fileCollectionFromFileList } from 'filelist-utils';
1+
import { FileCollection } from 'file-collection';
22
import type { ParseResult } from 'papaparse';
33
import { useCallback } from 'react';
44

@@ -24,15 +24,17 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
2424
(files: File[]) => {
2525
dispatch({ type: 'SET_LOADING_FLAG', payload: { isLoading: true } });
2626

27-
async function loadFiles(files) {
27+
async function loadFiles(files: File[]) {
2828
if (
2929
onOpenMetaInformation &&
3030
files.length === 1 &&
3131
isMetaFile(files[0])
3232
) {
3333
onOpenMetaInformation(files[0]);
3434
} else {
35-
const fileCollection = await fileCollectionFromFileList(files);
35+
const fileCollection = await new FileCollection().appendFileList(
36+
files,
37+
);
3638
const metaFile = Object.values(fileCollection.files).find((file) =>
3739
isMetaFile(file),
3840
);
@@ -52,11 +54,11 @@ export function useLoadFiles(onOpenMetaInformation?: (file: File) => void) {
5254
},
5355
);
5456

55-
if ((nmriumState as any)?.settings) {
57+
if (nmriumState.settings) {
5658
dispatchPreferences({
5759
type: 'SET_WORKSPACE',
5860
payload: {
59-
data: (nmriumState as any).settings,
61+
data: nmriumState.settings,
6062
workspaceSource: 'nmriumFile',
6163
},
6264
});

src/component/main/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import type {
33
Spectrum,
44
WorkspacePreferences as NMRiumPreferences,
55
} from '@zakodium/nmrium-core';
6-
import type { WebSource } from 'filelist-utils';
6+
import type { Source } from 'file-collection';
77
import type { CorrelationData } from 'nmr-correlation';
88

99
type DeepPartial<T> = {
1010
[P in keyof T]?: DeepPartial<T[P]>;
1111
};
1212

1313
interface NMRiumData {
14-
source?: WebSource;
14+
source?: Source;
1515
molecules?: NMRiumMolecules;
1616
spectra: Array<DeepPartial<Spectrum>>;
1717
correlations?: CorrelationData;

src/component/reducer/Reducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BaselineCorrectionZone } from '@zakodium/nmr-types';
22
import type { Spectrum, ViewState } from '@zakodium/nmrium-core';
3-
import type { WebSource as Source } from 'filelist-utils';
3+
import type { Source } from 'file-collection';
44
import type { Draft } from 'immer';
55
import { original, produce } from 'immer';
66
import type { CorrelationData } from 'nmr-correlation';

src/component/utility/export.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import type {
44
JpathTableColumn,
55
SpectraTableColumn,
66
} from '@zakodium/nmrium-core';
7+
import { BlobWriter, TextReader, ZipWriter } from '@zip.js/zip.js';
78
import dlv from 'dlv';
89
import fileSaver from 'file-saver';
9-
import JSZip from 'jszip';
1010

1111
export const browserNotSupportedErrorToast: ToastProps = {
1212
message:
@@ -38,15 +38,9 @@ async function exportAsJSON(
3838
fileSaver.saveAs(blob, `${fileName}.nmrium`);
3939
} else {
4040
try {
41-
const zip = new JSZip();
42-
zip.file(`${fileName}.nmrium`, fileData);
43-
const blob = await zip.generateAsync({
44-
type: 'blob',
45-
compression: 'DEFLATE',
46-
compressionOptions: {
47-
level: 9,
48-
},
49-
});
41+
const zip = new ZipWriter(new BlobWriter());
42+
await zip.add(`${fileName}.nmrium`, new TextReader(fileData));
43+
const blob = await zip.close();
5044
fileSaver.saveAs(blob, `${fileName}.nmrium`);
5145
} catch (error) {
5246
// TODO: handle error.

src/data/SpectraManager.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
processJCAMPDX,
1010
spectrum1DToJCAMPDX,
1111
} from '@zakodium/nmrium-core-plugins';
12+
import { BlobWriter, TextReader, ZipWriter } from '@zip.js/zip.js';
1213
import fileSaver from 'file-saver';
13-
import JSZip from 'jszip';
1414
import * as OCL from 'openchemlib';
1515

1616
import type { State } from '../component/reducer/Reducer.js';
@@ -202,24 +202,17 @@ export async function exportForCT(options: ExportForCTOptions) {
202202
throw new Error('Failed to convert the 1D spectrum to JCAMP');
203203
}
204204
const name = spectrum.info.name;
205-
const zip = new JSZip();
205+
const zip = new ZipWriter(new BlobWriter());
206206

207207
//add jcamp file
208-
zip.file(`${name}.dx`, jcamp);
208+
await zip.add(`${name}.dx`, new TextReader(jcamp));
209209
//add mol file
210210
const { molfile } = molecules[0];
211211
const molecule = OCL.Molecule.fromMolfile(molfile);
212212
const molFileName = molecule.getMolecularFormula().formula;
213213

214-
zip.file(`${molFileName}.mol`, molecule.toMolfile());
215-
216-
const blob = await zip.generateAsync({
217-
type: 'blob',
218-
compression: 'DEFLATE',
219-
compressionOptions: {
220-
level: 9,
221-
},
222-
});
214+
await zip.add(`${molFileName}.mol`, new TextReader(molecule.toMolfile()));
223215

216+
const blob = await zip.close();
224217
fileSaver.saveAs(blob, name);
225218
}

src/data/parseMeta/isMetaFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { FileCollectionItem } from 'filelist-utils';
1+
import type { FileItem } from 'file-collection';
22

3-
export function isMetaFile(file: File | FileCollectionItem) {
3+
export function isMetaFile(file: File | FileItem) {
44
if (file instanceof File) {
55
return ['text/csv', 'text/tsv', 'text/plain'].includes(file?.type);
66
}

src/data/parseMeta/parseMetaFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { FileCollectionItem } from 'filelist-utils';
1+
import type { FileItem } from 'file-collection';
22
import type { ParseResult } from 'papaparse';
33
import papa from 'papaparse';
44

55
export async function parseMetaFile(
6-
file: FileCollectionItem | File,
6+
file: FileItem | File,
77
): Promise<ParseResult<any>> {
88
const data = file instanceof File ? file : await file.text();
99
return new Promise((complete, error) => {

src/demo/views/AuoProcessingView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { NMRiumCore } from '@zakodium/nmrium-core';
2-
import { fileCollectionFromWebSource } from 'filelist-utils';
2+
import { FileCollection } from 'file-collection';
33
import { useEffect, useState } from 'react';
44

55
import { useCore } from '../../component/context/CoreContext.js';
@@ -23,7 +23,7 @@ async function loadSpectrumFromURL(core: NMRiumCore, url: string) {
2323
],
2424
baseURL,
2525
};
26-
const fileCollection = await fileCollectionFromWebSource(source, {});
26+
const fileCollection = await new FileCollection().appendSource(source);
2727

2828
const { nmriumState } = await core.read(fileCollection, {
2929
experimentalFeatures: true,

0 commit comments

Comments
 (0)