@docusaurus/utils 2.0.0-beta.fc64c12e4 → 2.0.0
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 +29 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +36 -12
- 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 +53 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +70 -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 +86 -395
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +28 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +57 -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/shellUtils.d.ts +8 -0
- 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 +27 -12
- 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 +37 -15
- package/src/hashUtils.ts +9 -8
- package/src/i18nUtils.ts +114 -0
- package/src/index.ts +91 -502
- package/src/jsUtils.ts +59 -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/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- 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__/globUtils.test.ts +0 -109
- 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/markdownParser.ts +0 -182
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/lib/urlUtils.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
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.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
12
|
+
const jsUtils_1 = require("./jsUtils");
|
|
13
|
+
/**
|
|
14
|
+
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
|
15
|
+
* joins them into a reasonable URL.
|
|
16
|
+
*
|
|
17
|
+
* - `["file:", "/home", "/user/", "website"]` => `file:///home/user/website`
|
|
18
|
+
* - `["file://", "home", "/user/", "website"]` => `file://home/user/website` (relative!)
|
|
19
|
+
* - Remove trailing slash before parameters or hash.
|
|
20
|
+
* - Replace `?` in query parameters with `&`.
|
|
21
|
+
* - Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
22
|
+
*
|
|
23
|
+
* @throws {TypeError} If any of the URL segment is not a string, this throws.
|
|
24
|
+
*/
|
|
25
|
+
function normalizeUrl(rawUrls) {
|
|
26
|
+
const urls = [...rawUrls];
|
|
27
|
+
const resultArray = [];
|
|
28
|
+
let hasStartingSlash = false;
|
|
29
|
+
let hasEndingSlash = false;
|
|
30
|
+
const isNonEmptyArray = (arr) => arr.length > 0;
|
|
31
|
+
if (!isNonEmptyArray(urls)) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
// If the first part is a plain protocol, we combine it with the next part.
|
|
35
|
+
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
36
|
+
const first = urls.shift();
|
|
37
|
+
if (first.startsWith('file:') && urls[0].startsWith('/')) {
|
|
38
|
+
// Force a double slash here, else we lose the information that the next
|
|
39
|
+
// segment is an absolute path
|
|
40
|
+
urls[0] = `${first}//${urls[0]}`;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
urls[0] = first + urls[0];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// There must be two or three slashes in the file protocol,
|
|
47
|
+
// two slashes in anything else.
|
|
48
|
+
const replacement = urls[0].match(/^file:\/\/\//) ? '$1:///' : '$1://';
|
|
49
|
+
urls[0] = urls[0].replace(/^(?<protocol>[^/:]+):\/*/, replacement);
|
|
50
|
+
for (let i = 0; i < urls.length; i += 1) {
|
|
51
|
+
let component = urls[i];
|
|
52
|
+
if (typeof component !== 'string') {
|
|
53
|
+
throw new TypeError(`Url must be a string. Received ${typeof component}`);
|
|
54
|
+
}
|
|
55
|
+
if (component === '') {
|
|
56
|
+
if (i === urls.length - 1 && hasEndingSlash) {
|
|
57
|
+
resultArray.push('/');
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (component !== '/') {
|
|
62
|
+
if (i > 0) {
|
|
63
|
+
// Removing the starting slashes for each component but the first.
|
|
64
|
+
component = component.replace(/^\/+/,
|
|
65
|
+
// Special case where the first element of rawUrls is empty
|
|
66
|
+
// ["", "/hello"] => /hello
|
|
67
|
+
component.startsWith('/') && !hasStartingSlash ? '/' : '');
|
|
68
|
+
}
|
|
69
|
+
hasEndingSlash = component.endsWith('/');
|
|
70
|
+
// Removing the ending slashes for each component but the last. For the
|
|
71
|
+
// last component we will combine multiple slashes to a single one.
|
|
72
|
+
component = component.replace(/\/+$/, i < urls.length - 1 ? '' : '/');
|
|
73
|
+
}
|
|
74
|
+
hasStartingSlash = true;
|
|
75
|
+
resultArray.push(component);
|
|
76
|
+
}
|
|
77
|
+
let str = resultArray.join('/');
|
|
78
|
+
// Each input component is now separated by a single slash except the possible
|
|
79
|
+
// first plain protocol part.
|
|
80
|
+
// Remove trailing slash before parameters or hash.
|
|
81
|
+
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
82
|
+
// Replace ? in parameters with &.
|
|
83
|
+
const parts = str.split('?');
|
|
84
|
+
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
85
|
+
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
86
|
+
str = str.replace(/(?<textBefore>[^:/]\/)\/+/g, '$1');
|
|
87
|
+
// Dedupe forward slashes at the beginning of the path.
|
|
88
|
+
str = str.replace(/^\/+/g, '/');
|
|
89
|
+
return str;
|
|
90
|
+
}
|
|
91
|
+
exports.normalizeUrl = normalizeUrl;
|
|
92
|
+
/**
|
|
93
|
+
* Takes a file's path, relative to its content folder, and computes its edit
|
|
94
|
+
* URL. If `editUrl` is `undefined`, this returns `undefined`, as is the case
|
|
95
|
+
* when the user doesn't want an edit URL in her config.
|
|
96
|
+
*/
|
|
97
|
+
function getEditUrl(fileRelativePath, editUrl) {
|
|
98
|
+
return editUrl
|
|
99
|
+
? // Don't use posixPath for this: we need to force a forward slash path
|
|
100
|
+
normalizeUrl([editUrl, fileRelativePath.replace(/\\/g, '/')])
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
exports.getEditUrl = getEditUrl;
|
|
104
|
+
/**
|
|
105
|
+
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
106
|
+
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
107
|
+
*/
|
|
108
|
+
function fileToPath(file) {
|
|
109
|
+
const indexRE = /(?<dirname>^|.*\/)index\.(?:mdx?|jsx?|tsx?)$/i;
|
|
110
|
+
const extRE = /\.(?:mdx?|jsx?|tsx?)$/;
|
|
111
|
+
if (indexRE.test(file)) {
|
|
112
|
+
return file.replace(indexRE, '/$1');
|
|
113
|
+
}
|
|
114
|
+
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
115
|
+
}
|
|
116
|
+
exports.fileToPath = fileToPath;
|
|
117
|
+
/**
|
|
118
|
+
* Similar to `encodeURI`, but uses `encodeURIComponent` and assumes there's no
|
|
119
|
+
* query.
|
|
120
|
+
*
|
|
121
|
+
* `encodeURI("/question?/answer")` => `"/question?/answer#section"`;
|
|
122
|
+
* `encodePath("/question?/answer#section")` => `"/question%3F/answer%23foo"`
|
|
123
|
+
*/
|
|
124
|
+
function encodePath(userPath) {
|
|
125
|
+
return userPath
|
|
126
|
+
.split('/')
|
|
127
|
+
.map((item) => encodeURIComponent(item))
|
|
128
|
+
.join('/');
|
|
129
|
+
}
|
|
130
|
+
exports.encodePath = encodePath;
|
|
131
|
+
/**
|
|
132
|
+
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
133
|
+
* special characters.
|
|
134
|
+
*/
|
|
135
|
+
function isValidPathname(str) {
|
|
136
|
+
if (!str.startsWith('/')) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
const parsedPathname = new URL(str, 'https://domain.com').pathname;
|
|
141
|
+
return parsedPathname === str || parsedPathname === encodeURI(str);
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.isValidPathname = isValidPathname;
|
|
148
|
+
/**
|
|
149
|
+
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
150
|
+
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
151
|
+
* router)
|
|
152
|
+
*/
|
|
153
|
+
function resolvePathname(to, from) {
|
|
154
|
+
return (0, resolve_pathname_1.default)(to, from);
|
|
155
|
+
}
|
|
156
|
+
exports.resolvePathname = resolvePathname;
|
|
157
|
+
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
158
|
+
function addLeadingSlash(str) {
|
|
159
|
+
return str.startsWith('/') ? str : `/${str}`;
|
|
160
|
+
}
|
|
161
|
+
exports.addLeadingSlash = addLeadingSlash;
|
|
162
|
+
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
163
|
+
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
164
|
+
function addTrailingSlash(str) {
|
|
165
|
+
return str.endsWith('/') ? str : `${str}/`;
|
|
166
|
+
}
|
|
167
|
+
exports.addTrailingSlash = addTrailingSlash;
|
|
168
|
+
/** Removes the trailing slash from `str`. */
|
|
169
|
+
function removeTrailingSlash(str) {
|
|
170
|
+
return (0, jsUtils_1.removeSuffix)(str, '/');
|
|
171
|
+
}
|
|
172
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
173
|
+
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
174
|
+
function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
175
|
+
if (githubPort) {
|
|
176
|
+
return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
177
|
+
}
|
|
178
|
+
return `git@${githubHost}:${organizationName}/${projectName}.git`;
|
|
179
|
+
}
|
|
180
|
+
exports.buildSshUrl = buildSshUrl;
|
|
181
|
+
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
182
|
+
function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
|
|
183
|
+
if (githubPort) {
|
|
184
|
+
return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
185
|
+
}
|
|
186
|
+
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
|
|
187
|
+
}
|
|
188
|
+
exports.buildHttpsUrl = buildHttpsUrl;
|
|
189
|
+
/**
|
|
190
|
+
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
191
|
+
* `ssh:`, it will also allow protocol-less URLs like
|
|
192
|
+
* `git@github.com:facebook/docusaurus.git`.
|
|
193
|
+
*/
|
|
194
|
+
function hasSSHProtocol(sourceRepoUrl) {
|
|
195
|
+
try {
|
|
196
|
+
if (new URL(sourceRepoUrl).protocol === 'ssh:') {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// Fails when there isn't a protocol
|
|
203
|
+
return /^(?:[\w-]+@)?[\w.-]+:[\w./-]+/.test(sourceRepoUrl);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.hasSSHProtocol = hasSSHProtocol;
|
|
207
|
+
//# sourceMappingURL=urlUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gFAAqD;AACrD,uCAAuC;AAEvC;;;;;;;;;;;GAWG;AACH,SAAgB,YAAY,CAAC,OAAiB;IAC5C,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC1B,MAAM,WAAW,GAA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AAI,WAAW,MAAM,CAAC;KACvF;IACD,OAAO,OAAO,UAAU,IAAI,gBAAgB,IAAI,WAAW,MAAM,CAAC;AACpE,CAAC;AAVD,kCAUC;AAED,iEAAiE;AACjE,SAAgB,aAAa,CAC3B,cAAsB,EACtB,UAAkB,EAClB,gBAAwB,EACxB,WAAmB,EACnB,UAAmB;IAEnB,IAAI,UAAU,EAAE;QACd,OAAO,WAAW,cAAc,IAAI,UAAU,IAAI,UAAU,IAAI,gBAAgB,IAAI,WAAW,MAAM,CAAC;KACvG;IACD,OAAO,WAAW,cAAc,IAAI,UAAU,IAAI,gBAAgB,IAAI,WAAW,MAAM,CAAC;AAC1F,CAAC;AAXD,sCAWC;AAED;;;;GAIG;AACH,SAAgB,cAAc,CAAC,aAAqB;IAClD,IAAI;QACF,IAAI,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC,QAAQ,KAAK,MAAM,EAAE;YAC9C,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;KACd;IAAC,MAAM;QACN,oCAAoC;QACpC,OAAO,+BAA+B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;KAC5D;AACH,CAAC;AAVD,wCAUC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
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 type { RuleSetRule } from 'webpack';
|
|
8
|
+
declare type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
|
|
9
|
+
declare type FileLoaderUtils = {
|
|
10
|
+
loaders: {
|
|
11
|
+
file: (options: {
|
|
12
|
+
folder: AssetFolder;
|
|
13
|
+
}) => RuleSetRule;
|
|
14
|
+
url: (options: {
|
|
15
|
+
folder: AssetFolder;
|
|
16
|
+
}) => RuleSetRule;
|
|
17
|
+
inlineMarkdownImageFileLoader: string;
|
|
18
|
+
inlineMarkdownLinkFileLoader: string;
|
|
19
|
+
};
|
|
20
|
+
rules: {
|
|
21
|
+
images: () => RuleSetRule;
|
|
22
|
+
fonts: () => RuleSetRule;
|
|
23
|
+
media: () => RuleSetRule;
|
|
24
|
+
svg: () => RuleSetRule;
|
|
25
|
+
otherAssets: () => RuleSetRule;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Returns unified loader configurations to be used for various file types.
|
|
30
|
+
*
|
|
31
|
+
* Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
32
|
+
*/
|
|
33
|
+
export declare function getFileLoaderUtils(): FileLoaderUtils;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=webpackUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpackUtils.d.ts","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,aAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE3D,aAAK,eAAe,GAAG;IACrB,OAAO,EAAE;QACP,IAAI,EAAE,CAAC,OAAO,EAAE;YAAC,MAAM,EAAE,WAAW,CAAA;SAAC,KAAK,WAAW,CAAC;QACtD,GAAG,EAAE,CAAC,OAAO,EAAE;YAAC,MAAM,EAAE,WAAW,CAAA;SAAC,KAAK,WAAW,CAAC;QACrD,6BAA6B,EAAE,MAAM,CAAC;QACtC,4BAA4B,EAAE,MAAM,CAAC;KACtC,CAAC;IACF,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,WAAW,CAAC;QAC1B,KAAK,EAAE,MAAM,WAAW,CAAC;QACzB,KAAK,EAAE,MAAM,WAAW,CAAC;QACzB,GAAG,EAAE,MAAM,WAAW,CAAC;QACvB,WAAW,EAAE,MAAM,WAAW,CAAC;KAChC,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CAkHpD"}
|
|
@@ -0,0 +1,115 @@
|
|
|
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.getFileLoaderUtils = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const pathUtils_1 = require("./pathUtils");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
/**
|
|
15
|
+
* Returns unified loader configurations to be used for various file types.
|
|
16
|
+
*
|
|
17
|
+
* Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
18
|
+
*/
|
|
19
|
+
function getFileLoaderUtils() {
|
|
20
|
+
// Files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
21
|
+
// the html
|
|
22
|
+
const urlLoaderLimit = constants_1.WEBPACK_URL_LOADER_LIMIT;
|
|
23
|
+
const fileLoaderFileName = (folder) => path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash].[ext]');
|
|
24
|
+
const loaders = {
|
|
25
|
+
file: (options) => ({
|
|
26
|
+
loader: require.resolve(`file-loader`),
|
|
27
|
+
options: {
|
|
28
|
+
name: fileLoaderFileName(options.folder),
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
url: (options) => ({
|
|
32
|
+
loader: require.resolve('url-loader'),
|
|
33
|
+
options: {
|
|
34
|
+
limit: urlLoaderLimit,
|
|
35
|
+
name: fileLoaderFileName(options.folder),
|
|
36
|
+
fallback: require.resolve('file-loader'),
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
// TODO avoid conflicts with the ideal-image plugin
|
|
40
|
+
// TODO this may require a little breaking change for ideal-image users?
|
|
41
|
+
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
42
|
+
// This is used to force url-loader+file-loader on markdown images
|
|
43
|
+
// https://webpack.js.org/concepts/loaders/#inline
|
|
44
|
+
inlineMarkdownImageFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('url-loader'))}?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}!`,
|
|
45
|
+
inlineMarkdownLinkFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}?name=${fileLoaderFileName('files')}!`,
|
|
46
|
+
};
|
|
47
|
+
const rules = {
|
|
48
|
+
/**
|
|
49
|
+
* Loads image assets, inlines images via a data URI if they are below
|
|
50
|
+
* the size threshold
|
|
51
|
+
*/
|
|
52
|
+
images: () => ({
|
|
53
|
+
use: [loaders.url({ folder: 'images' })],
|
|
54
|
+
test: /\.(?:ico|jpe?g|png|gif|webp)(?:\?.*)?$/i,
|
|
55
|
+
}),
|
|
56
|
+
fonts: () => ({
|
|
57
|
+
use: [loaders.url({ folder: 'fonts' })],
|
|
58
|
+
test: /\.(?:woff2?|eot|ttf|otf)$/i,
|
|
59
|
+
}),
|
|
60
|
+
/**
|
|
61
|
+
* Loads audio and video and inlines them via a data URI if they are below
|
|
62
|
+
* the size threshold
|
|
63
|
+
*/
|
|
64
|
+
media: () => ({
|
|
65
|
+
use: [loaders.url({ folder: 'medias' })],
|
|
66
|
+
test: /\.(?:mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
|
|
67
|
+
}),
|
|
68
|
+
svg: () => ({
|
|
69
|
+
test: /\.svg$/i,
|
|
70
|
+
oneOf: [
|
|
71
|
+
{
|
|
72
|
+
use: [
|
|
73
|
+
{
|
|
74
|
+
loader: require.resolve('@svgr/webpack'),
|
|
75
|
+
options: {
|
|
76
|
+
prettier: false,
|
|
77
|
+
svgo: true,
|
|
78
|
+
svgoConfig: {
|
|
79
|
+
plugins: [
|
|
80
|
+
{
|
|
81
|
+
name: 'preset-default',
|
|
82
|
+
params: {
|
|
83
|
+
overrides: {
|
|
84
|
+
removeTitle: false,
|
|
85
|
+
removeViewBox: false,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
titleProp: true,
|
|
92
|
+
ref: ![path_1.default],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
// We don't want to use SVGR loader for non-React source code
|
|
97
|
+
// ie we don't want to use SVGR for CSS files...
|
|
98
|
+
issuer: {
|
|
99
|
+
and: [/\.(?:tsx?|jsx?|mdx?)$/i],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
use: [loaders.url({ folder: 'images' })],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
}),
|
|
107
|
+
otherAssets: () => ({
|
|
108
|
+
use: [loaders.file({ folder: 'files' })],
|
|
109
|
+
test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
|
|
110
|
+
}),
|
|
111
|
+
};
|
|
112
|
+
return { loaders, rules };
|
|
113
|
+
}
|
|
114
|
+
exports.getFileLoaderUtils = getFileLoaderUtils;
|
|
115
|
+
//# sourceMappingURL=webpackUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAqBrB;;;;GAIG;AACH,SAAgB,kBAAkB;IAChC,8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AC;YAClB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;YACtC,IAAI,EAAE,iCAAiC;SACxC,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC;AAlHD,gDAkHC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,25 +18,40 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"globby": "^11.0
|
|
21
|
+
"@docusaurus/logger": "2.0.0",
|
|
22
|
+
"@svgr/webpack": "^6.2.1",
|
|
23
|
+
"file-loader": "^6.2.0",
|
|
24
|
+
"fs-extra": "^10.1.0",
|
|
25
|
+
"github-slugger": "^1.4.0",
|
|
26
|
+
"globby": "^11.1.0",
|
|
27
27
|
"gray-matter": "^4.0.3",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"js-yaml": "^4.1.0",
|
|
29
|
+
"lodash": "^4.17.21",
|
|
30
|
+
"micromatch": "^4.0.5",
|
|
30
31
|
"resolve-pathname": "^3.0.0",
|
|
31
|
-
"
|
|
32
|
+
"shelljs": "^0.8.5",
|
|
33
|
+
"tslib": "^2.4.0",
|
|
34
|
+
"url-loader": "^4.1.1",
|
|
35
|
+
"webpack": "^5.73.0"
|
|
32
36
|
},
|
|
33
37
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
38
|
+
"node": ">=16.14"
|
|
35
39
|
},
|
|
36
40
|
"devDependencies": {
|
|
41
|
+
"@docusaurus/types": "2.0.0",
|
|
37
42
|
"@types/dedent": "^0.7.0",
|
|
43
|
+
"@types/github-slugger": "^1.3.0",
|
|
38
44
|
"@types/micromatch": "^4.0.2",
|
|
45
|
+
"@types/react-dom": "^18.0.6",
|
|
39
46
|
"dedent": "^0.7.0"
|
|
40
47
|
},
|
|
41
|
-
"
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@docusaurus/types": "*"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"@docusaurus/types": {
|
|
53
|
+
"optional": true
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"gitHead": "2a9e8f5ec807e49a973fc72326f1ef26092e977e"
|
|
42
57
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
/** Node major version, directly read from env. */
|
|
9
|
+
export const NODE_MAJOR_VERSION = parseInt(
|
|
10
|
+
process.versions.node.split('.')[0]!,
|
|
11
|
+
10,
|
|
12
|
+
);
|
|
13
|
+
/** Node minor version, directly read from env. */
|
|
14
|
+
export const NODE_MINOR_VERSION = parseInt(
|
|
15
|
+
process.versions.node.split('.')[1]!,
|
|
16
|
+
10,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/** Docusaurus core version. */
|
|
20
|
+
export const DOCUSAURUS_VERSION =
|
|
21
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
22
|
+
(require('../package.json') as {version: string}).version;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Can be overridden with cli option `--out-dir`. Code should generally use
|
|
26
|
+
* `context.outDir` instead (which is always absolute and localized).
|
|
27
|
+
*/
|
|
28
|
+
export const DEFAULT_BUILD_DIR_NAME = 'build';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Can be overridden with cli option `--config`. Code should generally use
|
|
32
|
+
* `context.siteConfigPath` instead (which is always absolute).
|
|
33
|
+
*
|
|
34
|
+
* This does not have extensions, so that we can substitute different ones
|
|
35
|
+
* when resolving the path.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config';
|
|
38
|
+
|
|
39
|
+
/** Can be absolute or relative to site directory. */
|
|
40
|
+
export const BABEL_CONFIG_FILE_NAME =
|
|
41
|
+
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Can be absolute or relative to site directory. Code should generally use
|
|
45
|
+
* `context.generatedFilesDir` instead (which is always absolute).
|
|
46
|
+
*/
|
|
47
|
+
export const GENERATED_FILES_DIR_NAME =
|
|
48
|
+
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* We would assume all of the site's JS code lives in here and not outside.
|
|
52
|
+
* Relative to the site directory.
|
|
53
|
+
*/
|
|
54
|
+
export const SRC_DIR_NAME = 'src';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Can be overridden with `config.staticDirectories`. Code should use
|
|
58
|
+
* `context.siteConfig.staticDirectories` instead (which is always absolute).
|
|
59
|
+
*/
|
|
60
|
+
export const DEFAULT_STATIC_DIR_NAME = 'static';
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Files here are handled by webpack, hashed (can be cached aggressively).
|
|
64
|
+
* Relative to the build output folder.
|
|
65
|
+
*/
|
|
66
|
+
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Components in this directory will receive the `@theme` alias and be able to
|
|
70
|
+
* shadow default theme components.
|
|
71
|
+
*/
|
|
72
|
+
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* All translation-related data live here, relative to site directory. Content
|
|
76
|
+
* will be namespaced by locale.
|
|
77
|
+
*/
|
|
78
|
+
export const DEFAULT_I18N_DIR_NAME = 'i18n';
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Translations for React code.
|
|
82
|
+
*/
|
|
83
|
+
export const CODE_TRANSLATIONS_FILE_NAME = 'code.json';
|
|
84
|
+
|
|
85
|
+
/** Dev server opens on this port by default. */
|
|
86
|
+
export const DEFAULT_PORT = 3000;
|
|
87
|
+
|
|
88
|
+
/** Default plugin ID. */
|
|
89
|
+
export const DEFAULT_PLUGIN_ID = 'default';
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Allow overriding the limit after which the url loader will no longer inline
|
|
93
|
+
* assets.
|
|
94
|
+
*
|
|
95
|
+
* @see https://github.com/facebook/docusaurus/issues/5493
|
|
96
|
+
*/
|
|
97
|
+
export const WEBPACK_URL_LOADER_LIMIT =
|
|
98
|
+
process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
|
|
@@ -0,0 +1,122 @@
|
|
|
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 fs from 'fs-extra';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
import logger from '@docusaurus/logger';
|
|
11
|
+
import Yaml from 'js-yaml';
|
|
12
|
+
import {findAsyncSequential} from './index';
|
|
13
|
+
import type {ContentPaths} from './markdownLinks';
|
|
14
|
+
|
|
15
|
+
type DataFileParams = {
|
|
16
|
+
/** Path to the potential data file, relative to `contentPaths` */
|
|
17
|
+
filePath: string;
|
|
18
|
+
/**
|
|
19
|
+
* Includes the base path and localized path, both of which are eligible for
|
|
20
|
+
* sourcing data files. Both paths should be absolute.
|
|
21
|
+
*/
|
|
22
|
+
contentPaths: ContentPaths;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Looks for a data file in the potential content paths; loads a localized data
|
|
27
|
+
* file in priority.
|
|
28
|
+
*
|
|
29
|
+
* @returns An absolute path to the data file, or `undefined` if there isn't one.
|
|
30
|
+
*/
|
|
31
|
+
export async function getDataFilePath({
|
|
32
|
+
filePath,
|
|
33
|
+
contentPaths,
|
|
34
|
+
}: DataFileParams): Promise<string | undefined> {
|
|
35
|
+
const contentPath = await findFolderContainingFile(
|
|
36
|
+
getContentPathList(contentPaths),
|
|
37
|
+
filePath,
|
|
38
|
+
);
|
|
39
|
+
if (contentPath) {
|
|
40
|
+
return path.resolve(contentPath, filePath);
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Looks up for a data file in the content paths, returns the object validated
|
|
47
|
+
* and normalized according to the `validate` callback.
|
|
48
|
+
*
|
|
49
|
+
* @returns `undefined` when file not found
|
|
50
|
+
* @throws Throws when validation fails, displaying a helpful context message.
|
|
51
|
+
*/
|
|
52
|
+
export async function getDataFileData<T>(
|
|
53
|
+
params: DataFileParams & {
|
|
54
|
+
/** Used for the "The X file looks invalid" message. */
|
|
55
|
+
fileType: string;
|
|
56
|
+
},
|
|
57
|
+
validate: (content: unknown) => T,
|
|
58
|
+
): Promise<T | undefined> {
|
|
59
|
+
const filePath = await getDataFilePath(params);
|
|
60
|
+
if (!filePath) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
|
|
65
|
+
const unsafeContent = Yaml.load(contentString);
|
|
66
|
+
return validate(unsafeContent);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
logger.error`The ${params.fileType} file at path=${filePath} looks invalid.`;
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Takes the `contentPaths` data structure and returns an ordered path list
|
|
75
|
+
* indicating their priorities. For all data, we look in the localized folder
|
|
76
|
+
* in priority.
|
|
77
|
+
*/
|
|
78
|
+
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
|
79
|
+
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param folderPaths a list of absolute paths.
|
|
84
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
85
|
+
* @returns the first folder path in which the file exists, or `undefined` if
|
|
86
|
+
* none is found.
|
|
87
|
+
*/
|
|
88
|
+
export async function findFolderContainingFile(
|
|
89
|
+
folderPaths: string[],
|
|
90
|
+
relativeFilePath: string,
|
|
91
|
+
): Promise<string | undefined> {
|
|
92
|
+
return findAsyncSequential(folderPaths, (folderPath) =>
|
|
93
|
+
fs.pathExists(path.join(folderPath, relativeFilePath)),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Fail-fast alternative to `findFolderContainingFile`.
|
|
99
|
+
*
|
|
100
|
+
* @param folderPaths a list of absolute paths.
|
|
101
|
+
* @param relativeFilePath file path relative to each `folderPaths`.
|
|
102
|
+
* @returns the first folder path in which the file exists.
|
|
103
|
+
* @throws Throws if no file can be found. You should use this method only when
|
|
104
|
+
* you actually know the file exists (e.g. when the `relativeFilePath` is read
|
|
105
|
+
* with a glob and you are just trying to localize it)
|
|
106
|
+
*/
|
|
107
|
+
export async function getFolderContainingFile(
|
|
108
|
+
folderPaths: string[],
|
|
109
|
+
relativeFilePath: string,
|
|
110
|
+
): Promise<string> {
|
|
111
|
+
const maybeFolderPath = await findFolderContainingFile(
|
|
112
|
+
folderPaths,
|
|
113
|
+
relativeFilePath,
|
|
114
|
+
);
|
|
115
|
+
if (!maybeFolderPath) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`File "${relativeFilePath}" does not exist in any of these folders:
|
|
118
|
+
- ${folderPaths.join('\n- ')}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return maybeFolderPath;
|
|
122
|
+
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
declare module 'resolve-pathname' {
|
|
9
|
+
export default function resolvePathname(to: string, from?: string): string;
|
|
10
|
+
}
|