From 638a55063b5b74ad30dfe98f8ee2e23e86f2c25a Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 24 Sep 2024 12:39:00 +0100 Subject: [PATCH] refactor: simplify date calculation and remove date-fns dependency (#6751) --- .changeset/light-insects-drive.md | 5 +++++ packages/wrangler/package.json | 1 - packages/wrangler/src/dev-registry.ts | 5 ++--- pnpm-lock.yaml | 8 -------- 4 files changed, 7 insertions(+), 12 deletions(-) create mode 100644 .changeset/light-insects-drive.md diff --git a/.changeset/light-insects-drive.md b/.changeset/light-insects-drive.md new file mode 100644 index 000000000000..59e581c712ce --- /dev/null +++ b/.changeset/light-insects-drive.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +refactor: simplify date calculation and remove date-fns dependency diff --git a/packages/wrangler/package.json b/packages/wrangler/package.json index 4314253bbb6b..dfbb41e417d4 100644 --- a/packages/wrangler/package.json +++ b/packages/wrangler/package.json @@ -75,7 +75,6 @@ "@esbuild-plugins/node-modules-polyfill": "^0.2.2", "blake3-wasm": "^2.1.5", "chokidar": "^3.5.3", - "date-fns": "^3.6.0", "esbuild": "0.17.19", "miniflare": "workspace:*", "nanoid": "^3.3.3", diff --git a/packages/wrangler/src/dev-registry.ts b/packages/wrangler/src/dev-registry.ts index c6d2d40d6caa..58a3b0f4f023 100644 --- a/packages/wrangler/src/dev-registry.ts +++ b/packages/wrangler/src/dev-registry.ts @@ -13,7 +13,6 @@ import net from "node:net"; import path from "node:path"; import bodyParser from "body-parser"; import { watch } from "chokidar"; -import { subMinutes } from "date-fns"; import express from "express"; import { createHttpTerminator } from "http-terminator"; import { fetch } from "undici"; @@ -75,8 +74,8 @@ async function loadWorkerDefinitions(): Promise { "utf8" ); const stats = await stat(path.join(DEV_REGISTRY_PATH, workerName)); - // Cleanup old workers - if (stats.mtime < subMinutes(new Date(), 10)) { + // Cleanup existing workers older than 10 minutes + if (stats.mtime.getTime() < Date.now() - 600000) { await unregisterWorker(workerName); } else { globalWorkers[workerName] = JSON.parse(file); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 54c22bbbaead..c7c78755f541 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1668,9 +1668,6 @@ importers: chokidar: specifier: ^3.5.3 version: 3.5.3 - date-fns: - specifier: ^3.6.0 - version: 3.6.0 esbuild: specifier: 0.17.19 version: 0.17.19 @@ -4833,9 +4830,6 @@ packages: resolution: {integrity: sha512-fnULvOpxnC5/Vg3NCiWelDsLiUc9bRwAPs/+LfTLNvetFCtCTN+yQz15C/fs4AwX1R9K5GLtLfn8QW+dWisaAw==} engines: {node: '>=0.11'} - date-fns@3.6.0: - resolution: {integrity: sha512-fRHTG8g/Gif+kSh50gaGEdToemgfj74aRX3swtiouboip5JDLAyDE9F11nHMIcvOaXeOC6D7SpNhi7uFyB7Uww==} - date-time@3.1.0: resolution: {integrity: sha512-uqCUKXE5q1PNBXjPqvwhwJf9SwMoAHBgWJ6DcrnS5o+W2JOiIILl0JEdVD8SGujrNS02GGxgwAg2PN2zONgtjg==} engines: {node: '>=6'} @@ -12216,8 +12210,6 @@ snapshots: dependencies: '@babel/runtime': 7.22.5 - date-fns@3.6.0: {} - date-time@3.1.0: dependencies: time-zone: 1.0.0