Skip to content

Commit dd0272f

Browse files
authored
Fixed yarn, babel and other problem which occured after dependencies version bump (#30)
* rollup import fix * babel fix * Update .gitignore Co-authored-by: Maksymilian Gala <94986692+maxidragon@users.noreply.github.com> * removed type: module from package.json * support both es import and cjs require * replaced libraries which doesn't support both mjs and cjs
1 parent bd5b528 commit dd0272f

File tree

10 files changed

+1255
-792
lines changed

10 files changed

+1255
-792
lines changed

.babelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
"@babel/proposal-object-rest-spread",
99
["@babel/plugin-proposal-decorators", { "legacy": true }],
1010
["@babel/proposal-class-properties", { "loose": true }],
11-
"babel-plugin-transform-typescript-metadata"
11+
"babel-plugin-transform-typescript-metadata",
12+
["@babel/plugin-transform-private-property-in-object", { "loose": true }],
13+
["@babel/plugin-transform-private-methods", { "loose": true }]
1214
]
1315
}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,7 @@ keystore.json
118118

119119
# Other package managers
120120
pnpm-lock.yaml
121+
122+
# IDE's
123+
.idea/
124+
.vscode/

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
{
2+
"main": "lib/index.js",
23
"name": "vulcan-api-js",
34
"version": "3.5.2",
45
"description": "Unofficial API for UONET+ e-register from Vulcan.",
5-
"main": "lib/index.js",
66
"scripts": {
7-
"prepublish": "rollup -c & yarn tsc",
7+
"prepublish": "rollup -c rollup.config.mjs & yarn tsc",
88
"type-check": "tsc"
99
},
1010
"repository": "https://github.com/avorty/vulcan-api-js.git",
1111
"homepage": "https://avorty.github.io/vulcan-api-js",
1212
"author": "Avorty",
1313
"license": "MIT",
14+
"type": "module",
15+
"exports": {
16+
"require": "./lib/index.cjs",
17+
"import": "./lib/index.js"
18+
},
1419
"dependencies": {
1520
"@babel/runtime": "^7.23.6",
1621
"axios": "^1.6.2",
1722
"buffer": "^6.0.3",
18-
"dateformat": "^5.0.3",
19-
"node-fetch": "^3.3.2",
23+
"cross-fetch": "^4.0.0",
24+
"moment": "^2.29.4",
2025
"node-forge": "^1.3.1",
2126
"querystring": "^0.2.1",
2227
"reflect-metadata": "^0.2.1",
@@ -27,6 +32,7 @@
2732
"@babel/core": "^7.23.6",
2833
"@babel/plugin-proposal-class-properties": "^7.18.6",
2934
"@babel/plugin-proposal-decorators": "^7.23.6",
35+
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
3036
"@babel/plugin-transform-runtime": "^7.23.6",
3137
"@babel/preset-env": "^7.23.6",
3238
"@babel/preset-typescript": "^7.23.3",

rollup.config.js renamed to rollup.config.mjs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ import commonjs from '@rollup/plugin-commonjs';
22
import resolve from '@rollup/plugin-node-resolve';
33
import babel from '@rollup/plugin-babel';
44
import json from '@rollup/plugin-json';
5-
import pkg from './package.json';
5+
import fs from 'fs';
66

77
const extensions = [
88
'.js', '.jsx', '.ts', '.tsx',
99
];
1010

11+
const packageRaw = fs.readFileSync("./package.json");
12+
const pkg = JSON.parse(packageRaw);
13+
1114
const name = 'RollupTypeScriptBabel';
1215

1316
export default {
@@ -29,8 +32,14 @@ export default {
2932
babel({ extensions, include: ['src/**/*'], babelHelpers: 'runtime' }),
3033
],
3134

32-
output: [{
33-
file: pkg.main,
34-
format: 'cjs',
35-
}]
36-
};
35+
output: [
36+
{
37+
file: pkg.exports.import,
38+
format: 'es',
39+
},
40+
{
41+
file: pkg.exports.require,
42+
format: 'cjs',
43+
},
44+
],
45+
};

src/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Keystore } from "./keystore";
2-
import fetch from "node-fetch";
2+
import "cross-fetch/polyfill";
33
import { getSignatureValues } from "./signer";
44
import { ApiHelper } from "./apiHelper";
55
import {

src/apiHelper.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dateFormat from "dateformat";
1+
import moment from 'moment';
22
import { Api } from "./api";
33
import {
44
DATA_BY_MESSAGEBOX,
@@ -89,20 +89,19 @@ export class ApiHelper {
8989
break;
9090
}
9191
if (dateFrom) {
92-
query["dateFrom"] = dateFormat(dateFrom, "yyyy-mm-dd");
92+
query["dateFrom"] = moment(dateFrom).format("yyyy-mm-dd");
9393
}
9494
if (dateTo) {
95-
query["dateTo"] = dateFormat(dateTo, "yyyy-mm-dd");
95+
query["dateTo"] = moment(dateTo).format("yyyy-mm-dd");
9696
}
9797
if (folder) {
9898
query['folder'] = folder;
9999
}
100100
query["lastId"] = "-2147483648"; // Comment from vulcan-api for python: don't ask, it's just Vulcan
101101
query["pageSize"] = 500;
102-
query["lastSyncDate"] = dateFormat(
103-
lastSync || new Date("1970"),
104-
"yyyy-mm-dd HH:MM:ss"
105-
);
102+
query["lastSyncDate"] = moment(
103+
lastSync || new Date("1970"),
104+
).format("yyyy-mm-dd HH:MM:ss");
106105

107106
if (params) {
108107
query = { ...query, ...params };

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { Keystore } from "./keystore";
1515
import { APP_OS, getBaseUrl, uuid } from "./utils";
1616
import { FilterType } from "./apiHelper";
1717
import dateFormat from "dateformat";
18+
import moment from "moment";
1819
import { Account, ChangedLesson, Grade, Lesson, LuckyNumber, Student, MessageBox, Message, Homework, Attendance, Exam } from "./models";
1920

2021
export { AccountTools } from "./utils";
@@ -62,7 +63,7 @@ export class VulcanHebe {
6263
}
6364

6465
public async getStudents() {
65-
const data = await this.api.get(STUDENT_LIST);
66+
const data: any = await this.api.get(STUDENT_LIST);
6667
const studentsToReturn: Student[] = data.map(
6768
(item: any): Student => new Student().serialize(item)
6869
);
@@ -120,7 +121,7 @@ export class VulcanHebe {
120121
public async getLuckyNumber(): Promise<LuckyNumber> {
121122
const data = await this.api.helper.getData(DATA_LUCKY_NUMBER, {
122123
constituentId: this.api.student.school.id,
123-
day: dateFormat(new Date(), "yyyy-mm-dd"),
124+
day: moment().format("yyyy-mm-dd"),
124125
});
125126
return new LuckyNumber().serialize(data);
126127
}

src/utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import dateFormat from "dateformat";
1+
import moment from 'moment';
22

33
import forge from "node-forge";
44

@@ -128,10 +128,7 @@ export const generateKeyPair = async () => {
128128
return { certificate, fingerprint, privateKey: privateKeyToReturn };
129129
};
130130

131-
export const nowIso = () => {
132-
const date = new Date();
133-
return dateFormat(date, "yyyy-mm-dd HH:MM:ss");
134-
};
131+
export const nowIso = () => moment().format('YYYY-MM-DD HH:mm:ss');
135132

136133
export class AccountTools {
137134
public static loadFromObject(account: {

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
2323
/* Strict Type-Checking Options */
2424
"strict": true /* Enable all strict type-checking options. */,
25+
"resolveJsonModule": true,
2526
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
2627
// "strictNullChecks": true, /* Enable strict null checks. */
2728
// "strictFunctionTypes": true, /* Enable strict checking of function types. */

0 commit comments

Comments
 (0)