Skip to content

Commit d362b77

Browse files
authored
feat: provided some file structural changes (nodejs#5464)
1 parent ddb88b8 commit d362b77

File tree

21 files changed

+2346
-1626
lines changed

21 files changed

+2346
-1626
lines changed

Diff for: .husky/pre-commit

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33

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

6-
# resets the node release data file
7-
echo "[]" > $DIR/../public/node-releases-data.json
8-
9-
# resets the blog post data file
10-
echo "{ \"pagination\": [], \"categories\": [], \"posts\": [] }" > $DIR/../public/blog-posts-data.json
11-
126
# adds these changes to be part of the current commit
13-
git add --sparse $DIR/../public/node-releases-data.json
14-
git add --sparse $DIR/../public/blog-posts-data.json
7+
git checkout $DIR/../public/node-releases-data.json
8+
git checkout $DIR/../public/blog-posts-data.json
159

1610
# lint and format staged files
1711
npx lint-staged

Diff for: .storybook/test-runner.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// TODO: Convert this to ESM once the bug is resolved
2-
// https://github.com/storybookjs/test-runner/issues/293
1+
import type { TestRunnerConfig } from '@storybook/test-runner';
32

4-
const config = {
3+
const config: TestRunnerConfig = {
54
async postRender(page, _context) {
65
const rootElementId = '[data-test-id="story-root"]';
76
const rootElement = await page.locator(rootElementId);
@@ -11,4 +10,4 @@ const config = {
1110
},
1211
};
1312

14-
module.exports = config;
13+
export default config;

Diff for: app/en/feed/[feed]/route.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { NextResponse } from 'next/server';
22
import * as nextJson from '@/next.json.mjs';
3-
import * as nextData from '@/next-data/index.mjs';
3+
import * as nextData from '@/next.data.mjs';
44

55
// loads all the data from the blog-posts-data.json file
66
const websiteFeeds = nextData.generateWebsiteFeeds(nextJson.blogData);

Diff for: components/Article/Codebox/__tests__/index.test.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import { IntlProvider } from 'react-intl';
44

55
import Codebox, { replaceLabelLanguages, replaceLanguages } from '../index';
66

7-
jest.mock('isomorphic-dompurify', () => {
8-
return {
9-
sanitize: jest.fn().mockImplementation(source => source),
10-
};
11-
});
12-
137
describe('Replacer tests', (): void => {
148
it('replaceLabelLanguages', (): void => {
159
expect(replaceLabelLanguages('language-console')).toBe('language-bash');

Diff for: components/Article/Codebox/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useEffect, useState } from 'react';
22
import { FormattedMessage } from 'react-intl';
33
import { highlight, languages } from 'prismjs';
4-
import { sanitize } from 'isomorphic-dompurify';
54
import classnames from 'classnames';
65
import styles from './index.module.scss';
76
import { useCopyToClipboard } from '../../../hooks/useCopyToClipboard';
@@ -46,7 +45,7 @@ const Codebox: FC<CodeBoxProps> = ({ children: { props } }) => {
4645
const prismLanguage = languages[parsedLanguage] || languages.text;
4746

4847
setParsedCode(
49-
sanitize(highlight(codeArray[langIndex], prismLanguage, parsedLanguage))
48+
highlight(codeArray[langIndex], prismLanguage, parsedLanguage)
5049
);
5150
// eslint-disable-next-line react-hooks/exhaustive-deps
5251
}, [langIndex]);

Diff for: components/Common/Banner/__snapshots__/index.stories.tsx.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ exports[`Common/Banner WithHTMLImage smoke-test 1`] = `
1919
target="_blank"
2020
rel="noopener noreferrer"
2121
>
22-
<img alt="Banner Image"
23-
src="/static/images/nodejs-training.png"
22+
<img src="/static/images/nodejs-training.png"
23+
alt="Banner Image"
2424
>
2525
</a>
2626
</div>

Diff for: components/Common/Banner/__tests__/index.test.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { IntlProvider } from 'react-intl';
33
import Banner from '../index';
44
import type { WebsiteBanner } from '../../../../types';
55

6-
jest.mock('isomorphic-dompurify', () => ({
7-
sanitize: jest.fn((html: string) => html),
8-
}));
9-
106
const bannersIndex: WebsiteBanner = {
117
endDate: '',
128
link: 'test/banner/link',

Diff for: components/Common/Banner/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useMemo } from 'react';
22
import { useIntl } from 'react-intl';
3-
import { sanitize } from 'isomorphic-dompurify';
43
import styles from './index.module.scss';
54
import { dateIsBetween } from '../../../util/dateIsBetween';
65
import { isAbsoluteUrl } from '../../../util/isAbsoluteUrl';
@@ -36,7 +35,7 @@ const useHtmlContent = ({ html, link }: WebsiteBanner) =>
3635
href={link}
3736
target="_blank"
3837
rel="noopener noreferrer"
39-
dangerouslySetInnerHTML={{ __html: sanitize(html) }}
38+
dangerouslySetInnerHTML={{ __html: html }}
4039
/>
4140
);
4241
}

Diff for: layouts/DownloadReleasesLayout.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useMemo } from 'react';
2-
import { sanitize } from 'isomorphic-dompurify';
32
import BaseLayout from './BaseLayout';
43
import { useLayoutContext } from '../hooks/useLayoutContext';
54
import DownloadReleasesTable from '../components/Downloads/DownloadReleasesTable';
@@ -14,7 +13,7 @@ const DownloadReleasesLayout: FC<PropsWithChildren> = ({ children }) => {
1413
// @TODO: Remove this once we migrate to `nodejs/nodejs.dev` codebase as this is unsafe
1514
// And completely not recommended
1615
const extraModulesContent = useMemo(
17-
() => sanitize(`[<a href="#backref-1">1</a>]: ${modules}`),
16+
() => `[<a href="#backref-1">1</a>]: ${modules}`,
1817
[modules]
1918
);
2019

Diff for: next-data/generateBlogPostsData.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict';
22

33
import { readFile, writeFile } from 'node:fs/promises';
4-
import { basename, dirname, extname, join } from 'node:path';
4+
import { basename, extname, join } from 'node:path';
55
import graymatter from 'gray-matter';
6-
import * as helpers from './helpers.mjs';
6+
import * as nextHelpers from '../next.helpers.mjs';
77

88
// gets the current blog path based on local module path
99
const blogPath = join(process.cwd(), 'pages/en/blog');
@@ -51,7 +51,7 @@ const getFrontMatter = (filename, source) => {
5151
*/
5252
const generateBlogPostsData = async () => {
5353
// we retrieve all the filenames of all blog posts
54-
const filenames = await helpers.getMarkdownFiles(
54+
const filenames = await nextHelpers.getMarkdownFiles(
5555
process.cwd(),
5656
'pages/en/blog',
5757
['**/index.md', '**/pagination.md']

Diff for: next-data/index.mjs

-13
This file was deleted.

Diff for: next.config.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ const nextConfig = {
1313
distDir: nextConstants.ENABLE_STATIC_EXPORT ? 'build' : '.next',
1414
output: nextConstants.ENABLE_STATIC_EXPORT ? 'export' : undefined,
1515
experimental: {
16+
swcMinify: true,
17+
legacyBrowsers: false,
1618
nextScriptWorkers: true,
19+
webpackBuildWorker: true,
1720
largePageDataBytes: 128 * 100000,
1821
swcPlugins: [['next-superjson-plugin', {}]],
22+
outputFileTracingExcludes: {
23+
'*': ['./public/**', 'node_modules/**/@swc/core*'],
24+
},
1925
},
2026
};
2127

Diff for: next.data.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
import generateWebsiteFeeds from './next-data/generateWebsiteFeeds.mjs';
4+
import generateBlogPostsData from './next-data/generateBlogPostsData.mjs';
5+
import generateNodeReleasesJson from './next-data/generateNodeReleasesJson.mjs';
6+
7+
export {
8+
generateWebsiteFeeds,
9+
generateBlogPostsData,
10+
generateNodeReleasesJson,
11+
};

Diff for: next.dynamic.mjs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import remarkGfm from 'remark-gfm';
66
import { serialize } from 'next-mdx-remote/serialize';
77
import * as nextLocales from './next.locales.mjs';
88
import * as nextConstants from './next.constants.mjs';
9-
import * as nextData from './next-data/index.mjs';
9+
import * as nextHelpers from './next.helpers.mjs';
1010

1111
// allows us to run a glob to get markdown files based on a language folder
1212
const getPathsByLanguage = async (
1313
locale = nextConstants.DEFAULT_LOCALE_CODE,
1414
ignored = []
15-
) =>
16-
nextData.helpers.getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored);
15+
) => nextHelpers.getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored);
1716

1817
/**
1918
* This method is responsible for generating a Collection of all available paths that

Diff for: next-data/helpers.mjs renamed to next.helpers.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
import { existsSync } from 'node:fs';
43
import { fileURLToPath } from 'node:url';
54
import { glob } from 'glob';
65

0 commit comments

Comments
 (0)