From 524796cf7cd42a2876d09d7ea2a8aff26f10e0a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Pallar=C3=A9s?= Date: Fri, 2 Aug 2024 14:06:29 +0200 Subject: [PATCH] feat(cli): remove `lodash.once` in favor of custom implementation (#6979) --- apps/wing/package.json | 2 -- apps/wing/src/util.before-shutdown.ts | 2 +- apps/wing/src/util.once.ts | 14 ++++++++++++++ pnpm-lock.yaml | 12 ------------ 4 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 apps/wing/src/util.once.ts diff --git a/apps/wing/package.json b/apps/wing/package.json index 03f89c29776..05e15f05a16 100644 --- a/apps/wing/package.json +++ b/apps/wing/package.json @@ -46,7 +46,6 @@ "debug": "^4.3.5", "glob": "^10.4.2", "inquirer": "^8.2.6", - "lodash.once": "^4.1.1", "nanoid": "^3.3.7", "npm-packlist": "^8.0.2", "open": "^8.4.2", @@ -59,7 +58,6 @@ "devDependencies": { "@types/debug": "^4.1.12", "@types/inquirer": "^9.0.7", - "@types/lodash.once": "^4.1.9", "@types/node": "^20.11.0", "@types/node-persist": "^3.1.8", "@types/npm-packlist": "^7.0.3", diff --git a/apps/wing/src/util.before-shutdown.ts b/apps/wing/src/util.before-shutdown.ts index 0ada1f8d235..10e36b3292b 100644 --- a/apps/wing/src/util.before-shutdown.ts +++ b/apps/wing/src/util.before-shutdown.ts @@ -1,4 +1,4 @@ -import once from "lodash.once"; +import { once } from "./util.once"; /** * Based on https://gist.github.com/nfantone/1eaa803772025df69d07f4dbf5df7e58. diff --git a/apps/wing/src/util.once.ts b/apps/wing/src/util.once.ts new file mode 100644 index 00000000000..ada9965bc5f --- /dev/null +++ b/apps/wing/src/util.once.ts @@ -0,0 +1,14 @@ +export function once any>( + func: T +): (...args: Parameters) => ReturnType { + let called = false; + let result: ReturnType; + + return (...args: Parameters): ReturnType => { + if (!called) { + called = true; + result = func(...args); + } + return result; + }; +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8003dd9dbd..8306c25ad14 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -285,9 +285,6 @@ importers: inquirer: specifier: ^8.2.6 version: 8.2.6 - lodash.once: - specifier: ^4.1.1 - version: 4.1.1 nanoid: specifier: ^3.3.7 version: 3.3.7 @@ -319,9 +316,6 @@ importers: '@types/inquirer': specifier: ^9.0.7 version: 9.0.7 - '@types/lodash.once': - specifier: ^4.1.9 - version: 4.1.9 '@types/node': specifier: ^20.11.0 version: 20.14.8 @@ -10768,12 +10762,6 @@ packages: '@types/node': 20.14.8 dev: true - /@types/lodash.once@4.1.9: - resolution: {integrity: sha512-nvZ7GYfyZB6CUmXL+7HSXg53rFpc49FsKuRmMiCIGhgJB/yyTip8uHk4mxGyVJOl87dXPlf3qy42WsjOcIrnmg==} - dependencies: - '@types/lodash': 4.17.5 - dev: true - /@types/lodash@4.17.5: resolution: {integrity: sha512-MBIOHVZqVqgfro1euRDWX7OO0fBVUUMrN6Pwm8LQsz8cWhEpihlvR70ENj3f40j58TNxZaWv2ndSkInykNBBJw==} dev: true