Skip to content

Commit 6e33513

Browse files
HinataKah0ovflowd
andauthored
chore: add Node Releases JSON to bundle (nodejs#5443)
Co-authored-by: Claudio Wunder <cwunder@hubspot.com>
1 parent 6c1055a commit 6e33513

File tree

9 files changed

+80
-76
lines changed

9 files changed

+80
-76
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ build
1616
public/robots.txt
1717
public/sitemap.xml
1818
public/en/feed/*.xml
19-
public/node-releases-data.json
2019
pages/en/blog/year-[0-9][0-9][0-9][0-9].md
2120

2221
# Jest

.husky/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
DIR=$(cd `dirname $0` && pwd -P)
5+
6+
echo "[]" > $DIR/../public/node-releases-data.json
7+
8+
git add --sparse $DIR/../public/node-releases-data.json

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ Commits should be signed. You can read more about [Commit Signing][] here.
164164
- Commit messages **must** start with a capital letter
165165
- Commit messages **must not** end with a period `.`
166166
167+
### Pre-commit Hooks
168+
169+
This project uses [husky][] for pre-commit hooks.
170+
171+
Some JSON files are generated during Build time with empty files as placeholders. Build time happens when you run `npx turbo serve` or `npx turbo build`. We don't want to commit those unnecessary changes. Since these files exist in the repository, `.gitignore` won't work for them. As the workaround, we have a pre-commit hook to discard those changes.
172+
167173
# Pull Request Policy
168174
169175
This policy governs how contributions should land within this repository. The lines below state the checks and policies to be followed before merging and on the act of merging.
@@ -219,3 +225,4 @@ By contributing to this project, I certify that:
219225
[`squash`]: https://help.github.com/en/articles/about-pull-request-merges#squash-and-merge-your-pull-request-commits
220226
[Conventional Commits]: https://www.conventionalcommits.org/
221227
[Commit Signing]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
228+
[husky]: https://typicode.github.io/husky/

hooks/useFetchNodeReleases.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

package-lock.json

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

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"test:storybook": "concurrently -P -k -s first -n \"storybook,test-storybook\" -c \"magenta,blue\" \"npm:storybook -- --ci\" \"wait-on http://localhost:6006 && test-storybook {@}\"",
3333
"test:storybook:snapshot": "npm run test:storybook -- -- --updateSnapshot",
3434
"test:storybook:watch": "npm run test:storybook -- -- --watch",
35-
"test": "concurrently -s all -n \"test:unit,test:storybook\" -c \"yellow,green\" \"npm:test:unit\" \"npm:test:storybook\""
35+
"test": "concurrently -s all -n \"test:unit,test:storybook\" -c \"yellow,green\" \"npm:test:unit\" \"npm:test:storybook\"",
36+
"prepare": "husky install"
3637
},
3738
"dependencies": {
3839
"@emotion/react": "^11.11.1",
@@ -105,6 +106,7 @@
105106
"stylelint-selector-bem-pattern": "^2.1.1",
106107
"typescript": "^5.0.4",
107108
"user-agent-data-types": "^0.3.1",
108-
"wait-on": "^7.0.1"
109+
"wait-on": "^7.0.1",
110+
"husky": "^8.0.0"
109111
}
110112
}

providers/nodeReleasesProvider.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1-
import { createContext } from 'react';
2-
import { useFetchNodeReleases } from '../hooks/useFetchNodeReleases';
1+
import { createContext, useMemo } from 'react';
2+
import nodeReleasesData from '../public/node-releases-data.json';
3+
import { getNodeReleaseStatus } from '../util/nodeRelease';
34
import type { FC, PropsWithChildren } from 'react';
4-
import type { NodeRelease } from '../types';
5+
import type { NodeReleaseSource, NodeRelease } from '../types';
56

67
export const NodeReleasesContext = createContext<NodeRelease[]>([]);
78

89
export const NodeReleasesProvider: FC<PropsWithChildren> = ({ children }) => {
9-
const releases = useFetchNodeReleases();
10+
const releases = useMemo(() => {
11+
const now = new Date();
12+
13+
return nodeReleasesData.map((raw: NodeReleaseSource) => {
14+
const support = {
15+
currentStart: raw.currentStart,
16+
ltsStart: raw.ltsStart,
17+
maintenanceStart: raw.maintenanceStart,
18+
endOfLife: raw.endOfLife,
19+
};
20+
21+
const status = getNodeReleaseStatus(now, support);
22+
23+
return {
24+
...support,
25+
major: raw.major,
26+
version: raw.version,
27+
versionWithPrefix: `v${raw.version}`,
28+
codename: raw.codename || '',
29+
isLts: status === 'Active LTS' || status === 'Maintenance LTS',
30+
status: status,
31+
npm: raw.npm || '',
32+
v8: raw.v8 || '',
33+
releaseDate: raw.releaseDate || '',
34+
modules: raw.modules || '',
35+
};
36+
});
37+
}, []);
1038

1139
return (
1240
<NodeReleasesContext.Provider value={releases}>

public/node-releases-data.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

types/releases.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ export type NodeReleaseStatus =
1616
| 'End-of-life'
1717
| 'Pending';
1818

19-
export interface NodeRelease {
19+
export interface NodeReleaseSource {
2020
major: number;
2121
version: string;
22-
versionWithPrefix: string;
23-
codename: string;
24-
isLts: boolean;
25-
status: NodeReleaseStatus;
22+
codename?: string;
2623
currentStart: string;
2724
ltsStart?: string;
2825
maintenanceStart?: string;
2926
endOfLife: string;
30-
npm: string;
31-
v8: string;
32-
releaseDate: string;
33-
modules: string;
27+
npm?: string;
28+
v8?: string;
29+
releaseDate?: string;
30+
modules?: string;
31+
}
32+
33+
export interface NodeRelease extends NodeReleaseSource {
34+
versionWithPrefix: string;
35+
isLts: boolean;
36+
status: NodeReleaseStatus;
3437
}
3538

3639
export type NodeReleaseSupport = Pick<

0 commit comments

Comments
 (0)