chore(v2): upgrade dependencies + require Node 12 (#4223)

* chore(v2): upgrade dependencies

* Set minimum Node.js version to 12.13

* Fix test

* Upgrade copy-text-to-clipboard

* Bump Node versions

* Update .nvmrc

* mark cacheTime as forbidded field

* Downgrade jest to v25.2.7

* Increase Node version for Windows CI

* Test fix

* Attempt to fix Windows CI

* Downgrade execa

* fix async test errors

* Upgrade execa

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Alexey Pyltsyn 2021-02-18 17:12:42 +03:00 committed by GitHub
parent 02f7722f2e
commit f13448d5e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 2097 additions and 1840 deletions

View file

@ -42,6 +42,7 @@ module.exports = {
'react/forbid-prop-types': OFF, // 1
'react/require-default-props': OFF, // 1
'jsx-a11y/control-has-associated-label': OFF, // 1
'react/jsx-no-target-blank': OFF, // 1
'react/jsx-props-no-spreading': OFF, // 2
'max-classes-per-file': OFF, // 2
'prefer-object-spread': OFF, // 5

View file

@ -31,6 +31,6 @@
"shelljs": "^0.8.4"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -16,8 +16,8 @@
},
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.12.5",
"@babel/traverse": "^7.12.5",
"@babel/parser": "^7.12.16",
"@babel/traverse": "^7.12.13",
"@docusaurus/core": "2.0.0-alpha.70",
"@docusaurus/utils": "2.0.0-alpha.70",
"@mdx-js/mdx": "^1.6.21",
@ -41,13 +41,13 @@
"remark-mdx": "^1.6.21",
"to-vfile": "^6.0.0",
"unist-builder": "^2.0.3",
"unist-util-remove-position": "^2.0.1"
"unist-util-remove-position": "^3.0.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -23,7 +23,7 @@
"docusaurus-migrate": "bin/index.js"
},
"dependencies": {
"@babel/preset-env": "^7.1.6",
"@babel/preset-env": "^7.12.16",
"@mapbox/hast-util-to-jsx": "^1.0.0",
"chalk": "^4.1.0",
"color": "^3.1.3",

View file

@ -592,9 +592,9 @@ function migrateVersionedSidebar(
acc: {[key: string]: Array<Record<string, unknown> | string>},
val,
) => {
acc[val[0].replace(versionRegex, '')] = (val[1] as Array<
any
>).map((item) => {
acc[
val[0].replace(versionRegex, '')
] = (val[1] as Array<any>).map((item) => {
if (typeof item === 'string') {
return item.replace(versionRegex, '');
}

View file

@ -25,7 +25,7 @@
"eta": "^1.11.0",
"fs-extra": "^9.0.1",
"globby": "^11.0.2",
"joi": "^17.2.1",
"joi": "^17.4.0",
"lodash": "^4.17.20"
},
"peerDependencies": {

View file

@ -27,7 +27,7 @@
"feed": "^4.2.2",
"fs-extra": "^9.1.0",
"globby": "^11.0.2",
"joi": "^17.2.1",
"joi": "^17.4.0",
"loader-utils": "^1.2.3",
"lodash": "^4.17.20",
"reading-time": "^1.3.0",
@ -39,6 +39,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -30,11 +30,11 @@
"@docusaurus/utils": "2.0.0-alpha.70",
"@docusaurus/utils-validation": "2.0.0-alpha.70",
"chalk": "^4.1.0",
"execa": "^3.4.0",
"execa": "^5.0.0",
"fs-extra": "^9.1.0",
"globby": "^11.0.2",
"import-fresh": "^3.2.2",
"joi": "^17.2.1",
"joi": "^17.4.0",
"loader-utils": "^1.2.3",
"lodash": "^4.17.19",
"lodash.flatmap": "^4.5.0",
@ -52,6 +52,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -38,10 +38,8 @@ describe('lastUpdate', () => {
);
expect(await getFileLastUpdate(nonExistingFilePath)).toBeNull();
expect(consoleMock).toHaveBeenCalledTimes(1);
expect(consoleMock).toHaveBeenCalledWith(
new Error(
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`,
),
expect(consoleMock.mock.calls[0][0].message).toContain(
`Command failed with exit code 128: git log -1 --format=%ct, %an ${nonExistingFilePath}`,
);
expect(await getFileLastUpdate(null)).toBeNull();
expect(await getFileLastUpdate(undefined)).toBeNull();

View file

@ -24,7 +24,7 @@
"@docusaurus/utils": "2.0.0-alpha.70",
"@docusaurus/utils-validation": "2.0.0-alpha.70",
"globby": "^11.0.2",
"joi": "^17.2.1",
"joi": "^17.4.0",
"loader-utils": "^1.2.3",
"lodash": "^4.17.19",
"minimatch": "^3.0.4",
@ -37,6 +37,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -20,13 +20,13 @@
"@docusaurus/core": "2.0.0-alpha.70",
"@docusaurus/types": "2.0.0-alpha.70",
"@docusaurus/utils": "2.0.0-alpha.70",
"react-json-view": "^1.20.4"
"react-json-view": "^1.21.1"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -20,6 +20,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -20,6 +20,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -34,6 +34,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -13,20 +13,20 @@
},
"license": "MIT",
"dependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
"@babel/plugin-proposal-optional-chaining": "^7.12.16",
"@babel/preset-env": "^7.12.16",
"@docusaurus/core": "2.0.0-alpha.70",
"babel-loader": "^8.2.1",
"babel-loader": "^8.2.2",
"clsx": "^1.1.1",
"core-js": "^2.6.5",
"joi": "^17.2.1",
"joi": "^17.4.0",
"terser-webpack-plugin": "^4.1.0",
"webpack": "^4.44.1",
"webpack-merge": "^4.2.2",
"workbox-build": "^6.0.2",
"workbox-precaching": "^6.0.2",
"workbox-window": "^6.0.2"
"workbox-build": "^6.1.0",
"workbox-precaching": "^6.1.0",
"workbox-window": "^6.1.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",

View file

@ -21,14 +21,14 @@
"@docusaurus/types": "2.0.0-alpha.70",
"@docusaurus/utils": "2.0.0-alpha.70",
"fs-extra": "^9.1.0",
"joi": "^17.2.1",
"sitemap": "^3.2.2"
"joi": "^17.4.0",
"sitemap": "^6.3.6"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -9,67 +9,58 @@ import createSitemap from '../createSitemap';
import {DocusaurusConfig} from '@docusaurus/types';
describe('createSitemap', () => {
test('simple site', () => {
const sitemap = createSitemap(
test('simple site', async () => {
const sitemap = await createSitemap(
{
url: 'https://example.com',
} as DocusaurusConfig,
['/', '/test'],
{
cacheTime: 600,
changefreq: 'daily',
priority: 0.7,
trailingSlash: false,
},
);
expect(sitemap.toString()).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
expect(sitemap).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
);
});
test('empty site', () => {
expect(() => {
createSitemap({} as DocusaurusConfig, [], {});
}).toThrowErrorMatchingInlineSnapshot(
`"url in docusaurus.config.js cannot be empty/undefined"`,
);
return expect(async () => {
await createSitemap({} as DocusaurusConfig, [], {});
}).rejects.toThrow('url in docusaurus.config.js cannot be empty/undefined');
});
test('exclusion of 404 page', () => {
const sitemap = createSitemap(
test('exclusion of 404 page', async () => {
const sitemap = await createSitemap(
{
url: 'https://example.com',
} as DocusaurusConfig,
['/', '/404.html', '/mypage'],
{
cacheTime: 600,
changefreq: 'daily',
priority: 0.7,
trailingSlash: false,
},
);
expect(sitemap.toString()).not.toContain('404');
expect(sitemap).not.toContain('404');
});
test('add trailing slash', () => {
const sitemap = createSitemap(
test('add trailing slash', async () => {
const sitemap = await createSitemap(
{
url: 'https://example.com',
} as DocusaurusConfig,
['/', '/test'],
{
cacheTime: 600,
changefreq: 'daily',
priority: 0.7,
trailingSlash: true,
},
);
expect(sitemap.toString()).toContain(
'<loc>https://example.com/test/</loc>',
);
expect(sitemap.toString()).not.toContain(
'<loc>https://example.com/test</loc>',
);
expect(sitemap).toContain('<loc>https://example.com/test/</loc>');
expect(sitemap).not.toContain('<loc>https://example.com/test</loc>');
});
});

View file

@ -26,7 +26,6 @@ describe('normalizeSitemapPluginOptions', () => {
test('should accept correctly defined user options', async () => {
const userOptions = {
cacheTime: 300,
changefreq: 'yearly',
priority: 0.9,
trailingSlash: false,
@ -35,14 +34,6 @@ describe('normalizeSitemapPluginOptions', () => {
expect(value).toEqual(userOptions);
});
test('should reject cacheTime inputs with wrong type', () => {
expect(() => {
normalizePluginOptions({
cacheTime: '42',
});
}).toThrowErrorMatchingInlineSnapshot(`"\\"cacheTime\\" must be a number"`);
});
test('should reject out-of-range priority inputs', () => {
expect(() => {
normalizePluginOptions({

View file

@ -5,35 +5,41 @@
* LICENSE file in the root directory of this source tree.
*/
import sitemap, {Sitemap, SitemapItemOptions} from 'sitemap';
import {SitemapStream, streamToPromise} from 'sitemap';
import {PluginOptions} from './types';
import {DocusaurusConfig} from '@docusaurus/types';
import {addTrailingSlash} from '@docusaurus/utils';
export default function createSitemap(
export default async function createSitemap(
siteConfig: DocusaurusConfig,
routesPaths: string[],
options: PluginOptions,
): Sitemap {
): Promise<string> {
const {url: hostname} = siteConfig;
if (!hostname) {
throw new Error('url in docusaurus.config.js cannot be empty/undefined');
}
const {cacheTime, changefreq, priority, trailingSlash} = options;
const {changefreq, priority, trailingSlash} = options;
const urls = routesPaths
const sitemapStream = new SitemapStream({
hostname,
});
routesPaths
.filter((route) => !route.endsWith('404.html'))
.map(
(routePath): SitemapItemOptions => ({
.map((routePath) =>
sitemapStream.write({
url: trailingSlash ? addTrailingSlash(routePath) : routePath,
changefreq,
priority,
}),
);
return sitemap.createSitemap({
hostname,
cacheTime,
urls,
});
sitemapStream.end();
const generatedSitemap = await streamToPromise(sitemapStream).then((sm) =>
sm.toString(),
);
return generatedSitemap;
}

View file

@ -28,11 +28,11 @@ export default function pluginSitemap(
async postBuild({siteConfig, routesPaths, outDir}: Props) {
// Generate sitemap.
const generatedSitemap = createSitemap(
const generatedSitemap = await createSitemap(
siteConfig,
routesPaths,
options,
).toString();
);
// Write sitemap file.
const sitemapPath = path.join(outDir, 'sitemap.xml');

View file

@ -4,19 +4,23 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as Joi from 'joi';
import {EnumChangefreq} from 'sitemap';
import {PluginOptions} from './types';
export const DEFAULT_OPTIONS: Required<PluginOptions> = {
cacheTime: 600 * 1000, // 600 sec - cache purge period.
changefreq: EnumChangefreq.WEEKLY,
priority: 0.5,
trailingSlash: false,
};
export const PluginOptionSchema = Joi.object({
cacheTime: Joi.number().positive().default(DEFAULT_OPTIONS.cacheTime),
// TODO temporary (@alpha-71)
cacheTime: Joi.forbidden().messages({
'any.unknown':
'Option `cacheTime` in sitemap config is deprecated. Please remove it.',
}),
changefreq: Joi.string()
.valid(...Object.values(EnumChangefreq))
.default(DEFAULT_OPTIONS.changefreq),

View file

@ -4,10 +4,10 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {EnumChangefreq} from 'sitemap';
export interface PluginOptions {
cacheTime?: number;
changefreq?: EnumChangefreq;
priority?: number;
trailingSlash?: boolean;

View file

@ -24,6 +24,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -29,6 +29,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -25,6 +25,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -33,9 +33,9 @@
"@mdx-js/react": "^1.6.21",
"@types/react-toggle": "^4.0.2",
"clsx": "^1.1.1",
"copy-text-to-clipboard": "^2.2.0",
"copy-text-to-clipboard": "^3.0.0",
"infima": "0.2.0-alpha.19",
"joi": "^17.2.1",
"joi": "^17.4.0",
"lodash": "^4.17.19",
"parse-numeric-range": "^1.2.0",
"postcss": "^7.0.2",
@ -54,6 +54,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -23,9 +23,9 @@ function Tabs(props: Props): JSX.Element {
const {lazy, block, defaultValue, values, groupId, className} = props;
const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext();
const [selectedValue, setSelectedValue] = useState(defaultValue);
const children = Children.toArray(props.children) as ReactElement<
TabItemProps
>[];
const children = Children.toArray(
props.children,
) as ReactElement<TabItemProps>[];
const tabRefs: (HTMLLIElement | null)[] = [];
if (groupId != null) {

View file

@ -32,6 +32,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -25,6 +25,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -21,7 +21,7 @@
"algoliasearch-helper": "^3.3.4",
"clsx": "^1.1.1",
"eta": "^1.12.1",
"joi": "^17.2.1",
"joi": "^17.4.0",
"lodash": "^4.17.19"
},
"peerDependencies": {
@ -29,6 +29,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -20,9 +20,9 @@
"dependencies": {
"@docusaurus/utils": "2.0.0-alpha.70",
"chalk": "^4.1.0",
"joi": "^17.2.1"
"joi": "^17.4.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -29,6 +29,6 @@
"resolve-pathname": "^3.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -37,18 +37,18 @@
"tmp-promise": "^3.0.2"
},
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/generator": "^7.12.11",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.1",
"@babel/plugin-proposal-optional-chaining": "^7.12.7",
"@babel/core": "^7.12.16",
"@babel/generator": "^7.12.15",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.12.13",
"@babel/plugin-proposal-optional-chaining": "^7.12.16",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/preset-react": "^7.12.10",
"@babel/preset-typescript": "^7.12.7",
"@babel/plugin-transform-runtime": "^7.12.15",
"@babel/preset-env": "^7.12.16",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.12.16",
"@babel/runtime": "^7.12.5",
"@babel/runtime-corejs3": "^7.12.5",
"@babel/traverse": "^7.12.12",
"@babel/runtime-corejs3": "^7.12.13",
"@babel/traverse": "^7.12.13",
"@docusaurus/cssnano-preset": "2.0.0-alpha.70",
"@docusaurus/react-loadable": "5.5.0",
"@docusaurus/types": "2.0.0-alpha.70",
@ -56,7 +56,7 @@
"@docusaurus/utils-validation": "2.0.0-alpha.70",
"@endiliey/static-site-generator-webpack-plugin": "^4.0.0",
"@svgr/webpack": "^5.5.0",
"babel-loader": "^8.2.1",
"babel-loader": "^8.2.2",
"babel-plugin-dynamic-import-node": "2.3.0",
"boxen": "^5.0.0",
"cache-loader": "^4.1.0",
@ -66,7 +66,7 @@
"commander": "^4.0.1",
"copy-webpack-plugin": "^6.4.1",
"core-js": "^2.6.5",
"css-loader": "^5.0.1",
"css-loader": "^5.0.2",
"del": "^6.0.0",
"detect-port": "^1.3.0",
"eta": "^1.12.1",
@ -79,7 +79,7 @@
"html-webpack-plugin": "^4.5.0",
"import-fresh": "^3.3.0",
"is-root": "^2.1.0",
"joi": "^17.2.1",
"joi": "^17.4.0",
"leven": "^3.1.0",
"lodash": "^4.17.20",
"lodash.flatmap": "^4.5.0",
@ -122,6 +122,6 @@
"react-dom": "^16.8.4 || ^17.0.0"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -210,12 +210,12 @@ function extractSourceCodeAstTranslations(
path.node.openingElement.name.name === 'Translate'
) {
// We only handle the optimistic case where we have a single non-empty content
const singleChildren: NodePath | undefined = path
const singleChildren = path
.get('children')
// Remove empty/useless text nodes that might be around our translation!
// Makes the translation system more reliable to JSX formatting issues
.filter(
(childrenPath: NodePath) =>
(childrenPath) =>
!(
t.isJSXText(childrenPath.node) &&
childrenPath.node.value.replace('\n', '').trim() === ''

View file

@ -20,6 +20,6 @@
"sharp": "^0.27.1"
},
"engines": {
"node": ">=10.15.1"
"node": ">=12.13.0"
}
}

View file

@ -49,22 +49,19 @@ describe('lqip-loader', () => {
const imgPath = path.join(__dirname, '__fixtures__', 'endi.jpg');
const invalidPath = path.join(__dirname, '__fixtures__', 'docusaurus.svg');
it('should reject unknown or unsupported file format', () => {
expect(lqip.base64(invalidPath)).rejects.toBeTruthy();
it('should reject unknown or unsupported file format', async () => {
await expect(lqip.base64(invalidPath)).rejects.toBeTruthy();
});
it('should generate a valid base64', () => {
it('should generate a valid base64', async () => {
const expectedBase64 = 'data:image/jpeg;base64,/9j/2wBDA';
lqip.base64(imgPath).then((base64: string) => {
expect(base64).toContain(expectedBase64);
});
await expect(lqip.base64(imgPath)).resolves.toContain(expectedBase64);
});
it('should generate a valid color palette', () => {
lqip.palette(imgPath).then((imgPalette: string[]) => {
expect(imgPalette).toHaveLength(6);
expect(imgPalette).toContain('#578ca1');
});
it('should generate a valid color palette', async () => {
const imgPalette = await lqip.palette(imgPath);
expect(imgPalette).toHaveLength(6);
expect(imgPalette).toContain('#578ca1');
});
});
});