@docusaurus/utils 2.0.0-beta.2 → 2.0.0-beta.21
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 +73 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +78 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +60 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +91 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +66 -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 +40 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +71 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +6 -4
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +13 -10
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +51 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +69 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +16 -76
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +92 -396
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +49 -5
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +57 -13
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +45 -1
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +92 -12
- package/lib/pathUtils.js.map +1 -0
- package/lib/{getFilePathForRoutePath.d.ts → shellUtils.d.ts} +2 -1
- package/lib/shellUtils.d.ts.map +1 -0
- package/lib/shellUtils.js +21 -0
- package/lib/shellUtils.js.map +1 -0
- package/lib/slugger.d.ts +24 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +23 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +59 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +91 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +66 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +207 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +35 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +115 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +20 -10
- package/src/constants.ts +98 -0
- package/src/dataFileUtils.ts +122 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +146 -0
- package/src/globUtils.ts +85 -0
- package/src/hashUtils.ts +9 -8
- package/src/i18nUtils.ts +115 -0
- package/src/index.ts +98 -503
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +101 -30
- package/src/markdownUtils.ts +357 -0
- package/src/pathUtils.ts +93 -12
- package/src/shellUtils.ts +18 -0
- package/src/slugger.ts +36 -0
- package/src/tags.ts +130 -0
- package/src/urlUtils.ts +234 -0
- package/src/webpackUtils.ts +153 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/docuHash.d.ts +0 -13
- package/lib/docuHash.js +0 -29
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/getFilePathForRoutePath.js +0 -40
- package/lib/markdownParser.d.ts +0 -30
- package/lib/markdownParser.js +0 -140
- 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__/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/escapePath.ts +0 -23
- package/src/getFilePathForRoutePath.ts +0 -43
- package/src/markdownParser.ts +0 -182
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
|
@@ -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
|
-
});
|
|
@@ -1,87 +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 {getFilePathForRoutePath} from '../getFilePathForRoutePath';
|
|
9
|
-
import {posixPath} from '../posixPath';
|
|
10
|
-
|
|
11
|
-
describe('getFilePathForRoutePath trailingSlash=undefined', () => {
|
|
12
|
-
test('works for /', () => {
|
|
13
|
-
expect(posixPath(getFilePathForRoutePath('/', undefined))).toEqual(
|
|
14
|
-
'/index.html',
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('works for /somePath', () => {
|
|
19
|
-
expect(posixPath(getFilePathForRoutePath('/somePath', undefined))).toEqual(
|
|
20
|
-
'/somePath/index.html',
|
|
21
|
-
);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('works for /somePath/', () => {
|
|
25
|
-
expect(posixPath(getFilePathForRoutePath('/somePath/', undefined))).toEqual(
|
|
26
|
-
'/somePath/index.html',
|
|
27
|
-
);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('works for /somePath/xyz.html', () => {
|
|
31
|
-
expect(
|
|
32
|
-
posixPath(getFilePathForRoutePath('/somePath/xyz.html', undefined)),
|
|
33
|
-
).toEqual('/somePath/xyz.html');
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getFilePathForRoutePath trailingSlash=true', () => {
|
|
38
|
-
test('works for /', () => {
|
|
39
|
-
expect(posixPath(getFilePathForRoutePath('/', true))).toEqual(
|
|
40
|
-
'/index.html',
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('works for /somePath', () => {
|
|
45
|
-
expect(posixPath(getFilePathForRoutePath('/somePath', true))).toEqual(
|
|
46
|
-
'/somePath/index.html',
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('works for /somePath/', () => {
|
|
51
|
-
expect(posixPath(getFilePathForRoutePath('/somePath/', true))).toEqual(
|
|
52
|
-
'/somePath/index.html',
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('works for /somePath/xyz.html', () => {
|
|
57
|
-
expect(
|
|
58
|
-
posixPath(getFilePathForRoutePath('/somePath/xyz.html', true)),
|
|
59
|
-
).toEqual('/somePath/xyz.html');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('getFilePathForRoutePath trailingSlash=false', () => {
|
|
64
|
-
test('works for /', () => {
|
|
65
|
-
expect(posixPath(getFilePathForRoutePath('/', false))).toEqual(
|
|
66
|
-
'/index.html',
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('works for /somePath', () => {
|
|
71
|
-
expect(posixPath(getFilePathForRoutePath('/somePath', false))).toEqual(
|
|
72
|
-
'/somePath.html',
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('works for /somePath/', () => {
|
|
77
|
-
expect(posixPath(getFilePathForRoutePath('/somePath/', false))).toEqual(
|
|
78
|
-
'/somePath/index.html',
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test('works for /somePath/xyz.html', () => {
|
|
83
|
-
expect(
|
|
84
|
-
posixPath(getFilePathForRoutePath('/somePath/xyz.html', false)),
|
|
85
|
-
).toEqual('/somePath/xyz.html');
|
|
86
|
-
});
|
|
87
|
-
});
|
|
@@ -1,51 +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 {simpleHash, docuHash} from '../hashUtils';
|
|
9
|
-
|
|
10
|
-
describe('hashUtils', () => {
|
|
11
|
-
test('simpleHash', () => {
|
|
12
|
-
const asserts: Record<string, string> = {
|
|
13
|
-
'': 'd41',
|
|
14
|
-
'/foo-bar': '096',
|
|
15
|
-
'/foo/bar': '1df',
|
|
16
|
-
'/endi/lie': '9fa',
|
|
17
|
-
'/endi-lie': 'fd3',
|
|
18
|
-
'/yangshun/tay': '48d',
|
|
19
|
-
'/yangshun-tay': 'f3b',
|
|
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':
|
|
21
|
-
'd46',
|
|
22
|
-
'/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/test1-test2':
|
|
23
|
-
'787',
|
|
24
|
-
};
|
|
25
|
-
Object.keys(asserts).forEach((str) => {
|
|
26
|
-
expect(simpleHash(str, 3)).toBe(asserts[str]);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe('docuHash', () => {
|
|
32
|
-
test('docuHash works', () => {
|
|
33
|
-
const asserts: Record<string, string> = {
|
|
34
|
-
'': '-d41',
|
|
35
|
-
'/': 'index',
|
|
36
|
-
'/foo-bar': 'foo-bar-096',
|
|
37
|
-
'/foo/bar': 'foo-bar-1df',
|
|
38
|
-
'/endi/lie': 'endi-lie-9fa',
|
|
39
|
-
'/endi-lie': 'endi-lie-fd3',
|
|
40
|
-
'/yangshun/tay': 'yangshun-tay-48d',
|
|
41
|
-
'/yangshun-tay': 'yangshun-tay-f3b',
|
|
42
|
-
'/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':
|
|
43
|
-
'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--d46',
|
|
44
|
-
'/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/test1-test2':
|
|
45
|
-
'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--787',
|
|
46
|
-
};
|
|
47
|
-
Object.keys(asserts).forEach((file) => {
|
|
48
|
-
expect(docuHash(file)).toBe(asserts[file]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|