@docusaurus/utils 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants.d.ts +20 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +26 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +24 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +65 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/emitUtils.d.ts +23 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +90 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +17 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +12 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +48 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +1 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +7 -5
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +17 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +40 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +15 -75
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +84 -395
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +17 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +72 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +36 -11
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +5 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +72 -52
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +44 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +88 -10
- package/lib/pathUtils.js.map +1 -0
- package/lib/slugger.d.ts +14 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +19 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +27 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +76 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +20 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +136 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +30 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +112 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +20 -10
- package/src/constants.ts +38 -0
- package/src/dataFileUtils.ts +90 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +113 -0
- package/src/gitUtils.ts +93 -0
- package/src/globUtils.ts +64 -0
- package/src/hashUtils.ts +3 -3
- package/src/i18nUtils.ts +58 -0
- package/src/index.ts +87 -502
- package/src/jsUtils.ts +88 -0
- package/src/markdownLinks.ts +35 -13
- package/src/markdownParser.ts +76 -57
- package/src/pathUtils.ts +87 -8
- package/src/slugger.ts +24 -0
- package/src/tags.ts +105 -0
- package/src/urlUtils.ts +149 -0
- package/src/webpackUtils.ts +146 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -631
- package/src/__tests__/markdownParser.test.ts +0 -817
- package/src/__tests__/pathUtils.test.ts +0 -63
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/codeTranslationsUtils.ts +0 -56
- package/src/escapePath.ts +0 -23
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {isNameTooLong, shortName} from '../pathUtils';
|
|
9
|
-
|
|
10
|
-
describe('pathUtils', () => {
|
|
11
|
-
test('isNameTooLong', () => {
|
|
12
|
-
const asserts: Record<string, boolean> = {
|
|
13
|
-
'': false,
|
|
14
|
-
'foo-bar-096': false,
|
|
15
|
-
'foo-bar-1df': false,
|
|
16
|
-
'endi-lie-9fa': false,
|
|
17
|
-
'endi-lie-fd3': false,
|
|
18
|
-
'yangshun-tay-48d': false,
|
|
19
|
-
'yangshun-tay-f3b': false,
|
|
20
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-d46': true,
|
|
21
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-2-787': true,
|
|
22
|
-
};
|
|
23
|
-
Object.keys(asserts).forEach((path) => {
|
|
24
|
-
expect(isNameTooLong(path)).toBe(asserts[path]);
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('shortName', () => {
|
|
29
|
-
test('works', () => {
|
|
30
|
-
const asserts: Record<string, string> = {
|
|
31
|
-
'': '',
|
|
32
|
-
'foo-bar': 'foo-bar',
|
|
33
|
-
'endi-lie': 'endi-lie',
|
|
34
|
-
'yangshun-tay': 'yangshun-tay',
|
|
35
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar':
|
|
36
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-',
|
|
37
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-2':
|
|
38
|
-
'foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-foo-bar-test-1-test-',
|
|
39
|
-
};
|
|
40
|
-
Object.keys(asserts).forEach((file) => {
|
|
41
|
-
expect(shortName(file)).toBe(asserts[file]);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
|
|
46
|
-
|
|
47
|
-
const SHORT_PATH = `/short/path/without/trailing/slash`;
|
|
48
|
-
const VERY_LONG_PATH = `/${`x`.repeat(256)}/`;
|
|
49
|
-
const VERY_LONG_PATH_NON_LATIN = `/${`あ`.repeat(255)}/`;
|
|
50
|
-
|
|
51
|
-
it(`Truncates long paths correctly`, () => {
|
|
52
|
-
const truncatedPathLatin = shortName(VERY_LONG_PATH);
|
|
53
|
-
const truncatedPathNonLatin = shortName(VERY_LONG_PATH_NON_LATIN);
|
|
54
|
-
expect(truncatedPathLatin.length).toBeLessThanOrEqual(255);
|
|
55
|
-
expect(truncatedPathNonLatin.length).toBeLessThanOrEqual(255);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it(`Does not truncate short paths`, () => {
|
|
59
|
-
const truncatedPath = shortName(SHORT_PATH);
|
|
60
|
-
expect(truncatedPath).toEqual(SHORT_PATH);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {posixPath} from '../posixPath';
|
|
9
|
-
|
|
10
|
-
describe('posixPath', () => {
|
|
11
|
-
test('posixPath works', () => {
|
|
12
|
-
const asserts: Record<string, string> = {
|
|
13
|
-
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
|
14
|
-
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
|
15
|
-
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
|
16
|
-
'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb',
|
|
17
|
-
'foo\\bar': 'foo/bar',
|
|
18
|
-
'foo\\bar/lol': 'foo/bar/lol',
|
|
19
|
-
'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}',
|
|
20
|
-
};
|
|
21
|
-
Object.keys(asserts).forEach((file) => {
|
|
22
|
-
expect(posixPath(file)).toBe(asserts[file]);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import path from 'path';
|
|
9
|
-
import fs from 'fs-extra';
|
|
10
|
-
|
|
11
|
-
// Return an ordered list of locales we should try
|
|
12
|
-
export function codeTranslationLocalesToTry(locale: string): string[] {
|
|
13
|
-
// @ts-expect-error: TODO until available in TS, see https://github.com/microsoft/TypeScript/issues/37326
|
|
14
|
-
const intlLocale = Intl.Locale ? new Intl.Locale(locale) : undefined;
|
|
15
|
-
if (!intlLocale) {
|
|
16
|
-
return [locale];
|
|
17
|
-
}
|
|
18
|
-
// if locale is just a simple language like "pt", we want to fallback to pt-BR (not pt-PT!)
|
|
19
|
-
// see https://github.com/facebook/docusaurus/pull/4536#issuecomment-810088783
|
|
20
|
-
if (intlLocale.language === locale) {
|
|
21
|
-
const maximizedLocale = intlLocale.maximize(); // pt-Latn-BR`
|
|
22
|
-
// ["pt","pt-BR"]
|
|
23
|
-
return [locale, `${maximizedLocale.language}-${maximizedLocale.region}`];
|
|
24
|
-
}
|
|
25
|
-
// if locale is like "pt-BR", we want to fallback to "pt"
|
|
26
|
-
else {
|
|
27
|
-
return [locale, intlLocale.language];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Useful to implement getDefaultCodeTranslationMessages() in themes
|
|
32
|
-
export async function readDefaultCodeTranslationMessages({
|
|
33
|
-
dirPath,
|
|
34
|
-
locale,
|
|
35
|
-
}: {
|
|
36
|
-
dirPath: string;
|
|
37
|
-
locale: string;
|
|
38
|
-
}): Promise<Record<string, string>> {
|
|
39
|
-
const localesToTry = codeTranslationLocalesToTry(locale);
|
|
40
|
-
|
|
41
|
-
// Return the content of the first file that match
|
|
42
|
-
// fr_FR.json => fr.json => nothing
|
|
43
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
44
|
-
for (const fileName of localesToTry) {
|
|
45
|
-
const filePath = path.resolve(dirPath, `${fileName}.json`);
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line no-await-in-loop
|
|
48
|
-
if (await fs.pathExists(filePath)) {
|
|
49
|
-
// eslint-disable-next-line no-await-in-loop
|
|
50
|
-
const fileContent = await fs.readFile(filePath, 'utf8');
|
|
51
|
-
return JSON.parse(fileContent);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {};
|
|
56
|
-
}
|
package/src/escapePath.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* When you have a path like C:\X\Y
|
|
10
|
-
* It is not safe to use directly when generating code
|
|
11
|
-
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
12
|
-
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
13
|
-
*
|
|
14
|
-
* Workaround for issue in posixPath, maybe we won't need it anymore soon?
|
|
15
|
-
* https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
16
|
-
* https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
17
|
-
*/
|
|
18
|
-
export function escapePath(str: string): string {
|
|
19
|
-
const escaped = JSON.stringify(str);
|
|
20
|
-
|
|
21
|
-
// Remove the " around the json string;
|
|
22
|
-
return escaped.substring(1, escaped.length - 1);
|
|
23
|
-
}
|
package/src/posixPath.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Convert Windows backslash paths to posix style paths.
|
|
10
|
-
* E.g: endi\\lie -> endi/lie
|
|
11
|
-
*
|
|
12
|
-
* Looks like this code was originally copied from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export function posixPath(str: string): string {
|
|
16
|
-
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
|
17
|
-
|
|
18
|
-
// TODO not sure why we need this
|
|
19
|
-
// See https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
20
|
-
// See https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
21
|
-
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
|
22
|
-
|
|
23
|
-
if (isExtendedLengthPath || hasNonAscii) {
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
return str.replace(/\\/g, '/');
|
|
27
|
-
}
|