Skip to content

Commit bfb68c2

Browse files
authored
Remove moment as a dependency for apollo-language-server (#2595)
There is really no strong need for `moment` to a dependency of `apollo-language-server` when it is used just to calculate durations in milliseconds. A simple constant will suffice instead. Also added some tests to prove that this change works but is by no means exhaustive. Related: #2323.
1 parent 72cf80f commit bfb68c2

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
55
## vNEXT
66

7+
- `apollo-language-server`
8+
- Remove `moment` as a dependency [#2595](https://github.com/apollographql/apollo-tooling/pull/2595)
9+
710
## `apollo@2.33.10`
811
- This release includes a number of patch updates for dependencies within the following packages. Behavior changes aren't expected and should be considered reportable issues.
912
- apollo-codegen-core@0.40.8

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/apollo-language-server/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"lodash.debounce": "^4.0.8",
4040
"lodash.merge": "^4.6.1",
4141
"minimatch": "^5.0.0",
42-
"moment": "2.29.1",
4342
"vscode-languageserver": "^5.1.0",
4443
"vscode-uri": "1.0.6"
4544
},
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { formatMS } from "../format";
2+
3+
const SECOND_AS_MS = 1000;
4+
const MIN_AS_MS = 60 * SECOND_AS_MS;
5+
const HOUR_AS_MS = 60 * MIN_AS_MS;
6+
7+
describe("formatMS", () => {
8+
describe("hours display", () => {
9+
it("works with no digits", () => {
10+
const value = 2 * HOUR_AS_MS;
11+
expect(formatMS(value, 0)).toEqual("2hr");
12+
});
13+
14+
it("works with 1 digit", () => {
15+
const value = 2 * HOUR_AS_MS;
16+
expect(formatMS(value, 1)).toEqual("2.0hr");
17+
});
18+
});
19+
20+
describe("minutes display", () => {
21+
it("works with no digits", () => {
22+
const value = 3 * MIN_AS_MS;
23+
expect(formatMS(value, 0)).toEqual("3min");
24+
});
25+
26+
it("works with 1 digit", () => {
27+
const value = 3 * MIN_AS_MS;
28+
expect(formatMS(value, 1)).toEqual("3.0min");
29+
});
30+
});
31+
32+
describe("seconds display", () => {
33+
it("works with no digits", () => {
34+
const value = 4 * SECOND_AS_MS;
35+
expect(formatMS(value, 0)).toEqual("4s");
36+
});
37+
38+
it("works with 1 digit", () => {
39+
const value = 4 * SECOND_AS_MS;
40+
expect(formatMS(value, 1)).toEqual("4.0s");
41+
});
42+
});
43+
});

packages/apollo-language-server/src/format.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import moment from "moment";
1+
const ONE_SECOND_AS_MS = 1000;
2+
const ONE_MINUTE_AS_MS = 60 * ONE_SECOND_AS_MS;
3+
const ONE_HOUR_AS_MS = 60 * ONE_MINUTE_AS_MS;
24

35
export function formatMS(
46
ms: number,
@@ -8,9 +10,9 @@ export function formatMS(
810
) {
911
if (ms === 0 || ms === null) return "0";
1012
const bounds = [
11-
moment.duration(1, "hour").asMilliseconds(),
12-
moment.duration(1, "minute").asMilliseconds(),
13-
moment.duration(1, "second").asMilliseconds(),
13+
ONE_HOUR_AS_MS,
14+
ONE_MINUTE_AS_MS,
15+
ONE_SECOND_AS_MS,
1416
1,
1517
0.001,
1618
0.000001

0 commit comments

Comments
 (0)