@docusaurus/utils 2.0.0-beta.138b4c997 → 2.0.0-beta.14
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 +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/escapePath.d.ts +1 -0
- package/lib/escapePath.d.ts.map +1 -0
- package/lib/escapePath.js +1 -0
- package/lib/escapePath.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 +5 -4
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +11 -7
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +43 -96
- package/lib/index.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +20 -6
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +1 -0
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +17 -8
- package/lib/markdownParser.js.map +1 -0
- package/lib/mdxUtils.d.ts +17 -0
- package/lib/mdxUtils.d.ts.map +1 -0
- package/lib/mdxUtils.js +31 -0
- package/lib/mdxUtils.js.map +1 -0
- package/lib/{getFilePathForRoutePath.d.ts → normalizeUrl.d.ts} +2 -1
- package/lib/normalizeUrl.d.ts.map +1 -0
- package/lib/normalizeUrl.js +67 -0
- package/lib/normalizeUrl.js.map +1 -0
- package/lib/pathUtils.d.ts +1 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +4 -5
- package/lib/pathUtils.js.map +1 -0
- package/lib/posixPath.d.ts +1 -0
- package/lib/posixPath.d.ts.map +1 -0
- package/lib/posixPath.js +1 -0
- package/lib/posixPath.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 +19 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +73 -0
- package/lib/tags.js.map +1 -0
- package/lib/webpackUtils.d.ts +30 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +110 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +25 -8
- package/src/constants.ts +38 -0
- package/src/deps.d.ts +14 -0
- package/src/globUtils.ts +63 -0
- package/src/index.ts +25 -96
- package/src/markdownLinks.ts +19 -8
- package/src/markdownParser.ts +21 -16
- package/src/mdxUtils.ts +32 -0
- package/src/normalizeUrl.ts +80 -0
- package/src/pathUtils.ts +2 -3
- package/src/slugger.ts +24 -0
- package/src/tags.ts +100 -0
- package/src/webpackUtils.ts +144 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/getFilePathForRoutePath.js +0 -40
- 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__/getFilePathForRoutePath.test.ts +0 -87
- 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/getFilePathForRoutePath.ts +0 -43
- 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
|
-
}
|
|
@@ -1,43 +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
|
-
|
|
10
|
-
/*
|
|
11
|
-
export function getFilePathForRoutePath(routePath: string): string {
|
|
12
|
-
const fileName = path.basename(routePath);
|
|
13
|
-
const filePath = path.dirname(routePath);
|
|
14
|
-
return path.join(filePath, `${fileName}/index.html`);
|
|
15
|
-
}
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
// Almost exact copy of the behavior we implemented in our Docusaurus fork of the webpack static gen plugin
|
|
19
|
-
// See https://github.com/slorber/static-site-generator-webpack-plugin/blob/master/index.js#L167
|
|
20
|
-
export function getFilePathForRoutePath(
|
|
21
|
-
routePath: string,
|
|
22
|
-
trailingSlash: boolean | undefined,
|
|
23
|
-
): string {
|
|
24
|
-
// const outputFileName = routePath.replace(/^(\/|\\)/, ''); // Remove leading slashes for webpack-dev-server
|
|
25
|
-
|
|
26
|
-
// Paths ending with .html are left untouched
|
|
27
|
-
if (/\.(html?)$/i.test(routePath)) {
|
|
28
|
-
return routePath;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Legacy retro-compatible behavior
|
|
32
|
-
if (typeof trailingSlash === 'undefined') {
|
|
33
|
-
return path.join(routePath, 'index.html');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// New behavior: we can say if we prefer file/folder output
|
|
37
|
-
// Useful resource: https://github.com/slorber/trailing-slash-guide
|
|
38
|
-
if (routePath === '' || routePath.endsWith('/') || trailingSlash) {
|
|
39
|
-
return path.join(routePath, 'index.html');
|
|
40
|
-
} else {
|
|
41
|
-
return `${routePath}.html`;
|
|
42
|
-
}
|
|
43
|
-
}
|