Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add Node Releases JSON to bundle #5443

Merged
merged 6 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ build
public/robots.txt
public/sitemap.xml
public/en/feed/*.xml
public/node-releases-data.json
pages/en/blog/year-[0-9][0-9][0-9][0-9].md

# Jest
Expand Down
8 changes: 8 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

DIR=$(cd `dirname $0` && pwd -P)

echo "[]" > $DIR/../public/node-releases-data.json

git add --sparse $DIR/../public/node-releases-data.json
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ Commits should be signed. You can read more about [Commit Signing][] here.
- Commit messages **must** start with a capital letter
- Commit messages **must not** end with a period `.`

### Pre-commit Hooks

This project uses [husky][] for pre-commit hooks.

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.

# Pull Request Policy

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.
Expand Down Expand Up @@ -219,3 +225,4 @@ By contributing to this project, I certify that:
[`squash`]: https://help.github.com/en/articles/about-pull-request-merges#squash-and-merge-your-pull-request-commits
[Conventional Commits]: https://www.conventionalcommits.org/
[Commit Signing]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
[husky]: https://typicode.github.io/husky/
60 changes: 0 additions & 60 deletions hooks/useFetchNodeReleases.ts

This file was deleted.

16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"test:storybook": "concurrently -P -k -s first -n \"storybook,test-storybook\" -c \"magenta,blue\" \"npm:storybook -- --ci\" \"wait-on http://localhost:6006 && test-storybook {@}\"",
"test:storybook:snapshot": "npm run test:storybook -- -- --updateSnapshot",
"test:storybook:watch": "npm run test:storybook -- -- --watch",
"test": "concurrently -s all -n \"test:unit,test:storybook\" -c \"yellow,green\" \"npm:test:unit\" \"npm:test:storybook\""
"test": "concurrently -s all -n \"test:unit,test:storybook\" -c \"yellow,green\" \"npm:test:unit\" \"npm:test:storybook\"",
"prepare": "husky install"
},
"dependencies": {
"@emotion/react": "^11.11.1",
Expand Down Expand Up @@ -105,6 +106,7 @@
"stylelint-selector-bem-pattern": "^2.1.1",
"typescript": "^5.0.4",
"user-agent-data-types": "^0.3.1",
"wait-on": "^7.0.1"
"wait-on": "^7.0.1",
"husky": "^8.0.0"
}
}
36 changes: 32 additions & 4 deletions providers/nodeReleasesProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,40 @@
import { createContext } from 'react';
import { useFetchNodeReleases } from '../hooks/useFetchNodeReleases';
import { createContext, useMemo } from 'react';
import nodeReleasesData from '../public/node-releases-data.json';
import { getNodeReleaseStatus } from '../util/nodeRelease';
import type { FC, PropsWithChildren } from 'react';
import type { NodeRelease } from '../types';
import type { NodeReleaseSource, NodeRelease } from '../types';

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

export const NodeReleasesProvider: FC<PropsWithChildren> = ({ children }) => {
const releases = useFetchNodeReleases();
ovflowd marked this conversation as resolved.
Show resolved Hide resolved
const releases = useMemo(() => {
const now = new Date();

return nodeReleasesData.map((raw: NodeReleaseSource) => {
const support = {
currentStart: raw.currentStart,
ltsStart: raw.ltsStart,
maintenanceStart: raw.maintenanceStart,
endOfLife: raw.endOfLife,
};

const status = getNodeReleaseStatus(now, support);

return {
...support,
major: raw.major,
version: raw.version,
versionWithPrefix: `v${raw.version}`,
codename: raw.codename || '',
isLts: status === 'Active LTS' || status === 'Maintenance LTS',
status: status,
npm: raw.npm || '',
v8: raw.v8 || '',
releaseDate: raw.releaseDate || '',
modules: raw.modules || '',
};
});
}, []);

return (
<NodeReleasesContext.Provider value={releases}>
Expand Down
1 change: 1 addition & 0 deletions public/node-releases-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
21 changes: 12 additions & 9 deletions types/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,24 @@ export type NodeReleaseStatus =
| 'End-of-life'
| 'Pending';

export interface NodeRelease {
export interface NodeReleaseSource {
major: number;
version: string;
versionWithPrefix: string;
codename: string;
isLts: boolean;
status: NodeReleaseStatus;
codename?: string;
currentStart: string;
ltsStart?: string;
maintenanceStart?: string;
endOfLife: string;
npm: string;
v8: string;
releaseDate: string;
modules: string;
npm?: string;
v8?: string;
releaseDate?: string;
modules?: string;
}

export interface NodeRelease extends NodeReleaseSource {
versionWithPrefix: string;
isLts: boolean;
status: NodeReleaseStatus;
}

export type NodeReleaseSupport = Pick<
Expand Down