From 1f18546cb1b429659ec99f8a18510c49d8a58d16 Mon Sep 17 00:00:00 2001 From: Corentin THOMASSET Date: Sat, 24 Aug 2024 13:46:29 +0200 Subject: [PATCH] refactor(server): switched to lodash-es to reduce bundle and docker image (#17) --- packages/app-server/package.json | 4 ++-- packages/app-server/src/modules/notes/notes.repository.ts | 4 ++-- packages/app-server/src/modules/shared/errors/errors.ts | 6 +++--- pnpm-lock.yaml | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/app-server/package.json b/packages/app-server/package.json index 788c4f2e..4b603f17 100644 --- a/packages/app-server/package.json +++ b/packages/app-server/package.json @@ -31,7 +31,7 @@ "date-fns": "^3.6.0", "figue": "^2.0.0", "hono": "^4.5.8", - "lodash": "^4.17.21", + "lodash-es": "^4.17.21", "pino": "^9.3.2", "ulid-workers": "^2.1.0", "unstorage": "^1.10.2", @@ -40,7 +40,7 @@ "devDependencies": { "@antfu/eslint-config": "^2.27.0", "@cloudflare/workers-types": "^4.20240821.1", - "@types/lodash": "^4.17.7", + "@types/lodash-es": "^4.17.12", "dotenv": "^16.4.5", "esbuild": "^0.23.1", "eslint": "^9.9.0", diff --git a/packages/app-server/src/modules/notes/notes.repository.ts b/packages/app-server/src/modules/notes/notes.repository.ts index da2a45de..932196e7 100644 --- a/packages/app-server/src/modules/notes/notes.repository.ts +++ b/packages/app-server/src/modules/notes/notes.repository.ts @@ -1,6 +1,6 @@ import type { Storage } from 'unstorage'; import { addSeconds, isBefore } from 'date-fns'; -import _ from 'lodash'; +import { omit } from 'lodash-es'; import { generateNoteId } from './notes.models'; import { createNoteNotFoundError } from './notes.errors'; @@ -51,7 +51,7 @@ function createNoteRepository({ storage }: { storage: Storage }) { } return { - note: _.omit(note, 'expirationDate'), + note: omit(note, 'expirationDate'), }; }, }; diff --git a/packages/app-server/src/modules/shared/errors/errors.ts b/packages/app-server/src/modules/shared/errors/errors.ts index 652e9ecf..a901e2ac 100644 --- a/packages/app-server/src/modules/shared/errors/errors.ts +++ b/packages/app-server/src/modules/shared/errors/errors.ts @@ -1,5 +1,5 @@ import type { StatusCode } from 'hono/utils/http-status'; -import _ from 'lodash'; +import { get, isError, toString } from 'lodash-es'; export { createError, createErrorFactory, isCustomError }; @@ -24,7 +24,7 @@ export class CustomError extends Error { super(message); this.code = code; - this.cause = _.isError(cause) ? cause : new Error(_.toString(cause)); + this.cause = isError(cause) ? cause : new Error(toString(cause)); this.statusCode = statusCode; this.documentationUrl = documentationUrl; this.isInternal = isInternal; @@ -42,5 +42,5 @@ function createErrorFactory(baseOption: ErrorOptions) { } function isCustomError(error: unknown): error is CustomError { - return _.get(error, 'isCustomError') === true; + return get(error, 'isCustomError') === true; } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 802ed196..73817399 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -86,7 +86,7 @@ importers: hono: specifier: ^4.5.8 version: 4.5.8 - lodash: + lodash-es: specifier: ^4.17.21 version: 4.17.21 pino: @@ -108,9 +108,9 @@ importers: '@cloudflare/workers-types': specifier: ^4.20240821.1 version: 4.20240821.1 - '@types/lodash': - specifier: ^4.17.7 - version: 4.17.7 + '@types/lodash-es': + specifier: ^4.17.12 + version: 4.17.12 dotenv: specifier: ^16.4.5 version: 16.4.5