mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
utils: move bson and moment to optionalPeerDeps
This commit is contained in:
2 files changed
+17
-5
No files matched your search
@@ -5,8 +5,7 @@ import { Duplex, PassThrough, Writable } from 'stream';
|
||||
import { inspect } from 'util';
|
||||
import type { Entry, ZipReader } from '@zip.js/zip.js';
|
||||
import fs from 'fs-extra';
|
||||
import moment, { isMoment, Moment } from 'moment-timezone';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import type { Moment } from 'moment';
|
||||
import { Exporter, Factory, Logger as Reggol } from 'reggol';
|
||||
import type * as superagent from 'superagent';
|
||||
export * as yaml from 'js-yaml';
|
||||
@@ -34,7 +33,6 @@ function createLogger(name: string) {
|
||||
|
||||
export type Logger = Reggol & { new(name: string): Reggol & Logger };
|
||||
export const Logger = createLogger as any as Logger;
|
||||
export { moment };
|
||||
|
||||
const encrypt = (algorithm, content) => crypto.createHash(algorithm).update(content).digest('hex');
|
||||
export const sha1 = (content: string) => encrypt('sha1', content);
|
||||
@@ -146,6 +144,18 @@ export namespace Time {
|
||||
}
|
||||
|
||||
export function getObjectID(timestamp: string | Date | Moment, allZero = true) {
|
||||
let isMoment: (x: any) => x is Moment;
|
||||
let ObjectId: typeof import('bson').ObjectId; // eslint-disable-line
|
||||
try {
|
||||
({ ObjectId } = require('bson'));
|
||||
} catch (e) {
|
||||
throw new Error('No bson module found');
|
||||
}
|
||||
try {
|
||||
({ isMoment } = require('moment'));
|
||||
} catch (e) {
|
||||
throw new Error('No moment module found');
|
||||
}
|
||||
let _timestamp: number;
|
||||
if (typeof timestamp === 'string') _timestamp = new Date(timestamp).getTime();
|
||||
else if (isMoment(timestamp)) _timestamp = timestamp.toDate().getTime();
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"preferUnplugged": true,
|
||||
"optionalPeerDependencies": {
|
||||
"bson": "^6.17.0",
|
||||
"moment-timezone": "^0.5.48"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hydrooj/register": "workspace:^",
|
||||
"cac": "^6.7.14",
|
||||
"fs-extra": "^11.3.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"moment-timezone": "^0.5.48",
|
||||
"mongodb": "^6.17.0",
|
||||
"reggol": "^2.1.0",
|
||||
"search-query-parser": "^1.6.0",
|
||||
"systeminformation": "^5.27.1"
|
||||
|
||||
Reference in new issue
Block a user