@docusaurus/utils 2.0.0-beta.15d451942 → 2.0.0-beta.16
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/README.md +1 -1
- 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/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/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 +16 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +41 -0
- package/lib/hashUtils.js.map +1 -0
- package/lib/index.d.ts +30 -52
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +126 -247
- 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 +36 -11
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +7 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +77 -48
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +51 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +106 -0
- 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 +77 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +9 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +81 -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/gitUtils.ts +93 -0
- package/src/globUtils.ts +64 -0
- package/src/hashUtils.ts +37 -0
- package/src/index.ts +135 -294
- package/src/markdownLinks.ts +35 -13
- package/src/markdownParser.ts +86 -62
- package/src/pathUtils.ts +115 -0
- package/src/slugger.ts +24 -0
- package/src/tags.ts +105 -0
- package/src/urlUtils.ts +96 -0
- package/src/webpackUtils.ts +146 -0
- package/lib/.tsbuildinfo +0 -3972
- 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__/index.test.ts +0 -681
- package/src/__tests__/markdownParser.test.ts +0 -772
- 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,11 +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
|
-
export declare function codeTranslationLocalesToTry(locale: string): string[];
|
|
8
|
-
export declare function readDefaultCodeTranslationMessages({ dirPath, locale, }: {
|
|
9
|
-
dirPath: string;
|
|
10
|
-
locale: string;
|
|
11
|
-
}): Promise<Record<string, string>>;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.readDefaultCodeTranslationMessages = exports.codeTranslationLocalesToTry = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
|
-
// Return an ordered list of locales we should try
|
|
14
|
-
function codeTranslationLocalesToTry(locale) {
|
|
15
|
-
// @ts-expect-error: TODO until available in TS, see https://github.com/microsoft/TypeScript/issues/37326
|
|
16
|
-
const intlLocale = Intl.Locale ? new Intl.Locale(locale) : undefined;
|
|
17
|
-
if (!intlLocale) {
|
|
18
|
-
return [locale];
|
|
19
|
-
}
|
|
20
|
-
// if locale is just a simple language like "pt", we want to fallback to pt-BR (not pt-PT!)
|
|
21
|
-
// see https://github.com/facebook/docusaurus/pull/4536#issuecomment-810088783
|
|
22
|
-
if (intlLocale.language === locale) {
|
|
23
|
-
const maximizedLocale = intlLocale.maximize(); // pt-Latn-BR`
|
|
24
|
-
// ["pt","pt-BR"]
|
|
25
|
-
return [locale, `${maximizedLocale.language}-${maximizedLocale.region}`];
|
|
26
|
-
}
|
|
27
|
-
// if locale is like "pt-BR", we want to fallback to "pt"
|
|
28
|
-
else {
|
|
29
|
-
return [locale, intlLocale.language];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.codeTranslationLocalesToTry = codeTranslationLocalesToTry;
|
|
33
|
-
// Useful to implement getDefaultCodeTranslationMessages() in themes
|
|
34
|
-
async function readDefaultCodeTranslationMessages({ dirPath, locale, }) {
|
|
35
|
-
const localesToTry = codeTranslationLocalesToTry(locale);
|
|
36
|
-
// Return the content of the first file that match
|
|
37
|
-
// fr_FR.json => fr.json => nothing
|
|
38
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
39
|
-
for (const fileName of localesToTry) {
|
|
40
|
-
const filePath = path_1.default.resolve(dirPath, `${fileName}.json`);
|
|
41
|
-
// eslint-disable-next-line no-await-in-loop
|
|
42
|
-
if (await fs_extra_1.default.pathExists(filePath)) {
|
|
43
|
-
// eslint-disable-next-line no-await-in-loop
|
|
44
|
-
const fileContent = await fs_extra_1.default.readFile(filePath, 'utf8');
|
|
45
|
-
return JSON.parse(fileContent);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
exports.readDefaultCodeTranslationMessages = readDefaultCodeTranslationMessages;
|
package/lib/escapePath.d.ts
DELETED
|
@@ -1,17 +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
|
-
* When you have a path like C:\X\Y
|
|
9
|
-
* It is not safe to use directly when generating code
|
|
10
|
-
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
11
|
-
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
12
|
-
*
|
|
13
|
-
* Workaround for issue in posixPath, maybe we won't need it anymore soon?
|
|
14
|
-
* https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
15
|
-
* https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
16
|
-
*/
|
|
17
|
-
export declare function escapePath(str: string): string;
|
package/lib/escapePath.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.escapePath = void 0;
|
|
10
|
-
/**
|
|
11
|
-
* When you have a path like C:\X\Y
|
|
12
|
-
* It is not safe to use directly when generating code
|
|
13
|
-
* For example, this would fail due to unescaped \: `<img src={require('${filePath}')} />`
|
|
14
|
-
* But this would work: `<img src={require('${escapePath(filePath)}')} />`
|
|
15
|
-
*
|
|
16
|
-
* Workaround for issue in posixPath, maybe we won't need it anymore soon?
|
|
17
|
-
* https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
18
|
-
* https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
19
|
-
*/
|
|
20
|
-
function escapePath(str) {
|
|
21
|
-
const escaped = JSON.stringify(str);
|
|
22
|
-
// Remove the " around the json string;
|
|
23
|
-
return escaped.substring(1, escaped.length - 1);
|
|
24
|
-
}
|
|
25
|
-
exports.escapePath = escapePath;
|
package/lib/posixPath.d.ts
DELETED
|
@@ -1,14 +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
|
-
* Convert Windows backslash paths to posix style paths.
|
|
9
|
-
* E.g: endi\\lie -> endi/lie
|
|
10
|
-
*
|
|
11
|
-
* Looks like this code was originally copied from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
12
|
-
*
|
|
13
|
-
*/
|
|
14
|
-
export declare function posixPath(str: string): string;
|
package/lib/posixPath.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
-
*
|
|
5
|
-
* This source code is licensed under the MIT license found in the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.posixPath = void 0;
|
|
10
|
-
/**
|
|
11
|
-
* Convert Windows backslash paths to posix style paths.
|
|
12
|
-
* E.g: endi\\lie -> endi/lie
|
|
13
|
-
*
|
|
14
|
-
* Looks like this code was originally copied from https://github.com/sindresorhus/slash/blob/main/index.js
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
function posixPath(str) {
|
|
18
|
-
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
|
19
|
-
// TODO not sure why we need this
|
|
20
|
-
// See https://github.com/sindresorhus/slash/pull/16#issuecomment-833528479
|
|
21
|
-
// See https://github.com/facebook/docusaurus/issues/4730#issuecomment-833530370
|
|
22
|
-
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
|
23
|
-
if (isExtendedLengthPath || hasNonAscii) {
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
return str.replace(/\\/g, '/');
|
|
27
|
-
}
|
|
28
|
-
exports.posixPath = posixPath;
|
|
@@ -1,112 +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
|
-
import path from 'path';
|
|
8
|
-
import fs from 'fs-extra';
|
|
9
|
-
import {
|
|
10
|
-
codeTranslationLocalesToTry,
|
|
11
|
-
readDefaultCodeTranslationMessages,
|
|
12
|
-
} from '../codeTranslationsUtils';
|
|
13
|
-
|
|
14
|
-
describe('codeTranslationLocalesToTry', () => {
|
|
15
|
-
test('should return appropriate locale lists', () => {
|
|
16
|
-
expect(codeTranslationLocalesToTry('fr')).toEqual(['fr', 'fr-FR']);
|
|
17
|
-
expect(codeTranslationLocalesToTry('fr-FR')).toEqual(['fr-FR', 'fr']);
|
|
18
|
-
// Note: "pt" is expanded into "pt-BR", not "pt-PT", as "pt-BR" is more widely used!
|
|
19
|
-
// See https://github.com/facebook/docusaurus/pull/4536#issuecomment-810088783
|
|
20
|
-
expect(codeTranslationLocalesToTry('pt')).toEqual(['pt', 'pt-BR']);
|
|
21
|
-
expect(codeTranslationLocalesToTry('pt-BR')).toEqual(['pt-BR', 'pt']);
|
|
22
|
-
expect(codeTranslationLocalesToTry('pt-PT')).toEqual(['pt-PT', 'pt']);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('readDefaultCodeTranslationMessages', () => {
|
|
27
|
-
const dirPath = path.resolve(
|
|
28
|
-
__dirname,
|
|
29
|
-
'__fixtures__',
|
|
30
|
-
'defaultCodeTranslations',
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
async function readAsJSON(filename: string) {
|
|
34
|
-
return JSON.parse(
|
|
35
|
-
await fs.readFile(path.resolve(dirPath, filename), 'utf8'),
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
test('for empty locale', async () => {
|
|
40
|
-
await expect(
|
|
41
|
-
readDefaultCodeTranslationMessages({
|
|
42
|
-
locale: '',
|
|
43
|
-
dirPath,
|
|
44
|
-
}),
|
|
45
|
-
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
46
|
-
`"First argument to Intl.Locale constructor can't be empty or missing"`,
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('for unexisting locale', async () => {
|
|
51
|
-
await expect(
|
|
52
|
-
readDefaultCodeTranslationMessages({
|
|
53
|
-
locale: 'es',
|
|
54
|
-
dirPath,
|
|
55
|
-
}),
|
|
56
|
-
).resolves.toEqual({});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('for fr but bad folder', async () => {
|
|
60
|
-
await expect(
|
|
61
|
-
readDefaultCodeTranslationMessages({
|
|
62
|
-
locale: 'fr',
|
|
63
|
-
dirPath: __dirname,
|
|
64
|
-
}),
|
|
65
|
-
).resolves.toEqual({});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('for fr', async () => {
|
|
69
|
-
await expect(
|
|
70
|
-
readDefaultCodeTranslationMessages({
|
|
71
|
-
locale: 'fr',
|
|
72
|
-
dirPath,
|
|
73
|
-
}),
|
|
74
|
-
).resolves.toEqual(await readAsJSON('fr.json'));
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('for fr-FR', async () => {
|
|
78
|
-
await expect(
|
|
79
|
-
readDefaultCodeTranslationMessages({
|
|
80
|
-
locale: 'fr-FR',
|
|
81
|
-
dirPath,
|
|
82
|
-
}),
|
|
83
|
-
).resolves.toEqual(await readAsJSON('fr-FR.json'));
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('for en', async () => {
|
|
87
|
-
await expect(
|
|
88
|
-
readDefaultCodeTranslationMessages({
|
|
89
|
-
locale: 'en',
|
|
90
|
-
dirPath,
|
|
91
|
-
}),
|
|
92
|
-
).resolves.toEqual(await readAsJSON('en.json'));
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('for en-US', async () => {
|
|
96
|
-
await expect(
|
|
97
|
-
readDefaultCodeTranslationMessages({
|
|
98
|
-
locale: 'en-US',
|
|
99
|
-
dirPath,
|
|
100
|
-
}),
|
|
101
|
-
).resolves.toEqual(await readAsJSON('en.json'));
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('for en-WHATEVER', async () => {
|
|
105
|
-
await expect(
|
|
106
|
-
readDefaultCodeTranslationMessages({
|
|
107
|
-
locale: 'en-WHATEVER',
|
|
108
|
-
dirPath,
|
|
109
|
-
}),
|
|
110
|
-
).resolves.toEqual(await readAsJSON('en.json'));
|
|
111
|
-
});
|
|
112
|
-
});
|
|
@@ -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 {escapePath} from '../escapePath';
|
|
9
|
-
|
|
10
|
-
describe('escapePath', () => {
|
|
11
|
-
test('escapePath 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(escapePath(file)).toBe(asserts[file]);
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
});
|