@docusaurus/utils 0.0.0-4759 → 0.0.0-4760
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 +49 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +53 -8
- package/lib/constants.js.map +1 -1
- package/lib/dataFileUtils.d.ts +38 -2
- package/lib/dataFileUtils.d.ts.map +1 -1
- package/lib/dataFileUtils.js +34 -7
- package/lib/dataFileUtils.js.map +1 -1
- package/lib/emitUtils.d.ts +12 -0
- package/lib/emitUtils.d.ts.map +1 -1
- package/lib/emitUtils.js +22 -3
- package/lib/emitUtils.js.map +1 -1
- package/lib/gitUtils.d.ts +42 -2
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +2 -2
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +27 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +28 -10
- package/lib/globUtils.js.map +1 -1
- package/lib/hashUtils.d.ts +5 -4
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +6 -5
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +11 -0
- package/lib/i18nUtils.d.ts.map +1 -1
- package/lib/i18nUtils.js +12 -3
- package/lib/i18nUtils.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +32 -4
- package/lib/jsUtils.d.ts.map +1 -1
- package/lib/jsUtils.js +35 -13
- package/lib/jsUtils.js.map +1 -1
- package/lib/markdownLinks.d.ts +45 -4
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +17 -8
- package/lib/markdownLinks.js.map +1 -1
- package/lib/markdownUtils.d.ts +80 -9
- package/lib/markdownUtils.d.ts.map +1 -1
- package/lib/markdownUtils.js +61 -10
- package/lib/markdownUtils.js.map +1 -1
- package/lib/pathUtils.d.ts +1 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +2 -2
- package/lib/pathUtils.js.map +1 -1
- package/lib/slugger.d.ts +10 -0
- package/lib/slugger.d.ts.map +1 -1
- package/lib/slugger.js +4 -0
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +31 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +38 -24
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +45 -2
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +48 -6
- package/lib/urlUtils.js.map +1 -1
- package/lib/webpackUtils.d.ts +5 -0
- package/lib/webpackUtils.d.ts.map +1 -1
- package/lib/webpackUtils.js +6 -2
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/constants.ts +59 -7
- package/src/dataFileUtils.ts +43 -10
- package/src/emitUtils.ts +24 -5
- package/src/gitUtils.ts +46 -4
- package/src/globUtils.ts +29 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +13 -4
- package/src/index.ts +3 -6
- package/src/jsUtils.ts +34 -20
- package/src/markdownLinks.ts +58 -22
- package/src/markdownUtils.ts +101 -23
- package/src/pathUtils.ts +2 -2
- package/src/slugger.ts +13 -1
- package/src/tags.ts +37 -25
- package/src/urlUtils.ts +49 -6
- package/src/webpackUtils.ts +10 -2
package/lib/urlUtils.js
CHANGED
|
@@ -10,6 +10,18 @@ exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = exports.r
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const jsUtils_1 = require("./jsUtils");
|
|
12
12
|
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
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
|
+
*/
|
|
13
25
|
function normalizeUrl(rawUrls) {
|
|
14
26
|
const urls = [...rawUrls];
|
|
15
27
|
const resultArray = [];
|
|
@@ -63,8 +75,8 @@ function normalizeUrl(rawUrls) {
|
|
|
63
75
|
resultArray.push(component);
|
|
64
76
|
}
|
|
65
77
|
let str = resultArray.join('/');
|
|
66
|
-
// Each input component is now separated by a single slash
|
|
67
|
-
//
|
|
78
|
+
// Each input component is now separated by a single slash except the possible
|
|
79
|
+
// first plain protocol part.
|
|
68
80
|
// Remove trailing slash before parameters or hash.
|
|
69
81
|
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
70
82
|
// Replace ? in parameters with &.
|
|
@@ -77,6 +89,11 @@ function normalizeUrl(rawUrls) {
|
|
|
77
89
|
return str;
|
|
78
90
|
}
|
|
79
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
|
+
*/
|
|
80
97
|
function getEditUrl(fileRelativePath, editUrl) {
|
|
81
98
|
return editUrl
|
|
82
99
|
? // Don't use posixPath for this: we need to force a forward slash path
|
|
@@ -85,8 +102,8 @@ function getEditUrl(fileRelativePath, editUrl) {
|
|
|
85
102
|
}
|
|
86
103
|
exports.getEditUrl = getEditUrl;
|
|
87
104
|
/**
|
|
88
|
-
*
|
|
89
|
-
*
|
|
105
|
+
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
106
|
+
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
90
107
|
*/
|
|
91
108
|
function fileToPath(file) {
|
|
92
109
|
const indexRE = /(?<dirname>^|.*\/)index\.(?:mdx?|jsx?|tsx?)$/i;
|
|
@@ -97,6 +114,13 @@ function fileToPath(file) {
|
|
|
97
114
|
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
98
115
|
}
|
|
99
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
|
+
*/
|
|
100
124
|
function encodePath(userPath) {
|
|
101
125
|
return userPath
|
|
102
126
|
.split('/')
|
|
@@ -104,6 +128,10 @@ function encodePath(userPath) {
|
|
|
104
128
|
.join('/');
|
|
105
129
|
}
|
|
106
130
|
exports.encodePath = encodePath;
|
|
131
|
+
/**
|
|
132
|
+
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
133
|
+
* special characters.
|
|
134
|
+
*/
|
|
107
135
|
function isValidPathname(str) {
|
|
108
136
|
if (!str.startsWith('/')) {
|
|
109
137
|
return false;
|
|
@@ -118,24 +146,32 @@ function isValidPathname(str) {
|
|
|
118
146
|
}
|
|
119
147
|
}
|
|
120
148
|
exports.isValidPathname = isValidPathname;
|
|
121
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
151
|
+
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
152
|
+
* router)
|
|
153
|
+
*/
|
|
122
154
|
function resolvePathname(to, from) {
|
|
123
155
|
return (0, resolve_pathname_1.default)(to, from);
|
|
124
156
|
}
|
|
125
157
|
exports.resolvePathname = resolvePathname;
|
|
158
|
+
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
126
159
|
function addLeadingSlash(str) {
|
|
127
160
|
return str.startsWith('/') ? str : `/${str}`;
|
|
128
161
|
}
|
|
129
162
|
exports.addLeadingSlash = addLeadingSlash;
|
|
130
163
|
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
164
|
+
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
131
165
|
function addTrailingSlash(str) {
|
|
132
166
|
return str.endsWith('/') ? str : `${str}/`;
|
|
133
167
|
}
|
|
134
168
|
exports.addTrailingSlash = addTrailingSlash;
|
|
169
|
+
/** Removes the trailing slash from `str`. */
|
|
135
170
|
function removeTrailingSlash(str) {
|
|
136
171
|
return (0, jsUtils_1.removeSuffix)(str, '/');
|
|
137
172
|
}
|
|
138
173
|
exports.removeTrailingSlash = removeTrailingSlash;
|
|
174
|
+
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
139
175
|
function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
140
176
|
if (githubPort) {
|
|
141
177
|
return `ssh://git@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
@@ -143,6 +179,7 @@ function buildSshUrl(githubHost, organizationName, projectName, githubPort) {
|
|
|
143
179
|
return `git@${githubHost}:${organizationName}/${projectName}.git`;
|
|
144
180
|
}
|
|
145
181
|
exports.buildSshUrl = buildSshUrl;
|
|
182
|
+
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
146
183
|
function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName, githubPort) {
|
|
147
184
|
if (githubPort) {
|
|
148
185
|
return `https://${gitCredentials}@${githubHost}:${githubPort}/${organizationName}/${projectName}.git`;
|
|
@@ -150,6 +187,11 @@ function buildHttpsUrl(gitCredentials, githubHost, organizationName, projectName
|
|
|
150
187
|
return `https://${gitCredentials}@${githubHost}/${organizationName}/${projectName}.git`;
|
|
151
188
|
}
|
|
152
189
|
exports.buildHttpsUrl = buildHttpsUrl;
|
|
190
|
+
/**
|
|
191
|
+
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
192
|
+
* `ssh:`, it will also allow protocol-less URLs like
|
|
193
|
+
* `git@github.com:facebook/docusaurus.git`.
|
|
194
|
+
*/
|
|
153
195
|
function hasSSHProtocol(sourceRepoUrl) {
|
|
154
196
|
try {
|
|
155
197
|
if (new URL(sourceRepoUrl).protocol === 'ssh:') {
|
|
@@ -159,7 +201,7 @@ function hasSSHProtocol(sourceRepoUrl) {
|
|
|
159
201
|
}
|
|
160
202
|
catch {
|
|
161
203
|
// Fails when there isn't a protocol
|
|
162
|
-
return /^(?:[\w-]+@)?[\w.-]+:[\w./-]+/.test(sourceRepoUrl);
|
|
204
|
+
return /^(?:[\w-]+@)?[\w.-]+:[\w./-]+/.test(sourceRepoUrl);
|
|
163
205
|
}
|
|
164
206
|
}
|
|
165
207
|
exports.hasSSHProtocol = hasSSHProtocol;
|
package/lib/urlUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,uCAAuC;AACvC,gFAAqD;AAErD,SAAgB,YAAY,CAAC,OAAiB;IAC5C,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC1B,MAAM,WAAW,GAAG,EAAE,CAAC;IAEvB,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,eAAe,GAAG,CAAC,GAAa,EAAgC,EAAE,CACtE,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC1B,OAAO,EAAE,CAAC;KACX;IAED,2EAA2E;IAC3E,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,IAAI,CAAC,MAAM,G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gB,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"}
|
package/lib/webpackUtils.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ declare type FileLoaderUtils = {
|
|
|
25
25
|
otherAssets: () => RuleSetRule;
|
|
26
26
|
};
|
|
27
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
|
+
*/
|
|
28
33
|
export declare function getFileLoaderUtils(): FileLoaderUtils;
|
|
29
34
|
export {};
|
|
30
35
|
//# sourceMappingURL=webpackUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.d.ts","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAQzC,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,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ils.js
CHANGED
|
@@ -11,13 +11,17 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const pathUtils_1 = require("./pathUtils");
|
|
13
13
|
const constants_1 = require("./constants");
|
|
14
|
-
|
|
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
|
+
*/
|
|
15
19
|
function getFileLoaderUtils() {
|
|
16
20
|
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
17
21
|
// the html
|
|
18
22
|
const urlLoaderLimit = constants_1.WEBPACK_URL_LOADER_LIMIT;
|
|
19
23
|
// defines the path/pattern of the assets handled by webpack
|
|
20
|
-
const fileLoaderFileName = (folder) =>
|
|
24
|
+
const fileLoaderFileName = (folder) => path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash].[ext]');
|
|
21
25
|
const loaders = {
|
|
22
26
|
file: (options) => ({
|
|
23
27
|
loader: require.resolve(`file-loader`),
|
package/lib/webpackUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAoBrB
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAoBrB;;;;GAIG;AACH,SAAgB,kBAAkB;IAChC,8EAA8E;IAC9E,WAAW;IACX,MAAM,cAAc,GAAG,oCAAwB,CAAC;IAEhD,4DAA4D;IA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AM,EAAE,OAAO,EAAC,CAAC,CAAC;YACtC,IAAI,EAAE,iCAAiC;SACxC,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC;AAnHD,gDAmHC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4760",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4760",
|
|
22
22
|
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
24
|
"fs-extra": "^10.0.1",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "0.0.0-
|
|
41
|
+
"@docusaurus/types": "0.0.0-4760",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
45
|
"@types/react-dom": "^17.0.14",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ca58c5f867aec349fb405a2056d4bdb4d140a0b5"
|
|
49
49
|
}
|
package/src/constants.ts
CHANGED
|
@@ -5,34 +5,86 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/** Node major version, directly read from env. */
|
|
8
9
|
export const NODE_MAJOR_VERSION = parseInt(
|
|
9
10
|
process.versions.node.split('.')[0]!,
|
|
10
11
|
10,
|
|
11
12
|
);
|
|
13
|
+
/** Node minor version, directly read from env. */
|
|
12
14
|
export const NODE_MINOR_VERSION = parseInt(
|
|
13
15
|
process.versions.node.split('.')[1]!,
|
|
14
16
|
10,
|
|
15
17
|
);
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Can be overridden with cli option `--out-dir`. Code should generally use
|
|
21
|
+
* `context.outDir` instead (which is always absolute and localized).
|
|
22
|
+
*/
|
|
18
23
|
export const DEFAULT_BUILD_DIR_NAME = 'build';
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Can be overridden with cli option `--config`. Code should generally use
|
|
27
|
+
* `context.siteConfigPath` instead (which is always absolute).
|
|
28
|
+
*/
|
|
21
29
|
export const DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
22
30
|
|
|
31
|
+
/** Can be absolute or relative to site directory. */
|
|
23
32
|
export const BABEL_CONFIG_FILE_NAME =
|
|
24
|
-
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME
|
|
33
|
+
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
|
|
25
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Can be absolute or relative to site directory. Code should generally use
|
|
37
|
+
* `context.generatedFilesDir` instead (which is always absolute).
|
|
38
|
+
*/
|
|
26
39
|
export const GENERATED_FILES_DIR_NAME =
|
|
27
|
-
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME
|
|
40
|
+
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
|
|
28
41
|
|
|
42
|
+
/**
|
|
43
|
+
* We would assume all of the site's JS code lives in here and not outside.
|
|
44
|
+
* Relative to the site directory.
|
|
45
|
+
*/
|
|
29
46
|
export const SRC_DIR_NAME = 'src';
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Can be overridden with `config.staticDirectories`. Code should use
|
|
50
|
+
* `context.siteConfig.staticDirectories` instead (which is always absolute).
|
|
51
|
+
*/
|
|
52
|
+
export const DEFAULT_STATIC_DIR_NAME = 'static';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Files here are handled by webpack, hashed (can be cached aggressively).
|
|
56
|
+
* Relative to the build output folder.
|
|
57
|
+
*/
|
|
58
|
+
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Components in this directory will receive the `@theme` alias and be able to
|
|
62
|
+
* shadow default theme components.
|
|
63
|
+
*/
|
|
32
64
|
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* All translation-related data live here, relative to site directory. Content
|
|
68
|
+
* will be namespaced by locale.
|
|
69
|
+
*/
|
|
70
|
+
export const I18N_DIR_NAME = 'i18n';
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Translations for React code.
|
|
74
|
+
*/
|
|
75
|
+
export const CODE_TRANSLATIONS_FILE_NAME = 'code.json';
|
|
76
|
+
|
|
77
|
+
/** Dev server opens on this port by default. */
|
|
33
78
|
export const DEFAULT_PORT = 3000;
|
|
79
|
+
|
|
80
|
+
/** Default plugin ID. */
|
|
34
81
|
export const DEFAULT_PLUGIN_ID = 'default';
|
|
35
82
|
|
|
36
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Allow overriding the limit after which the url loader will no longer inline
|
|
85
|
+
* assets.
|
|
86
|
+
*
|
|
87
|
+
* @see https://github.com/facebook/docusaurus/issues/5493
|
|
88
|
+
*/
|
|
37
89
|
export const WEBPACK_URL_LOADER_LIMIT =
|
|
38
90
|
process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
|
package/src/dataFileUtils.ts
CHANGED
|
@@ -13,15 +13,25 @@ import type {ContentPaths} from './markdownLinks';
|
|
|
13
13
|
import logger from '@docusaurus/logger';
|
|
14
14
|
|
|
15
15
|
type DataFileParams = {
|
|
16
|
+
/** Path to the potential data file, relative to `contentPaths` */
|
|
16
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
|
+
*/
|
|
17
22
|
contentPaths: ContentPaths;
|
|
18
23
|
};
|
|
19
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
|
+
*/
|
|
20
31
|
export async function getDataFilePath({
|
|
21
32
|
filePath,
|
|
22
33
|
contentPaths,
|
|
23
34
|
}: DataFileParams): Promise<string | undefined> {
|
|
24
|
-
// Loads a localized data file in priority
|
|
25
35
|
const contentPath = await findFolderContainingFile(
|
|
26
36
|
getContentPathList(contentPaths),
|
|
27
37
|
filePath,
|
|
@@ -33,11 +43,17 @@ export async function getDataFilePath({
|
|
|
33
43
|
}
|
|
34
44
|
|
|
35
45
|
/**
|
|
36
|
-
* Looks up for a data file in the content paths, returns the
|
|
37
|
-
*
|
|
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.
|
|
38
51
|
*/
|
|
39
52
|
export async function getDataFileData<T>(
|
|
40
|
-
params: DataFileParams & {
|
|
53
|
+
params: DataFileParams & {
|
|
54
|
+
/** Used for the "The X file looks invalid" message. */
|
|
55
|
+
fileType: string;
|
|
56
|
+
},
|
|
41
57
|
validate: (content: unknown) => T,
|
|
42
58
|
): Promise<T | undefined> {
|
|
43
59
|
const filePath = await getDataFilePath(params);
|
|
@@ -54,12 +70,21 @@ export async function getDataFileData<T>(
|
|
|
54
70
|
}
|
|
55
71
|
}
|
|
56
72
|
|
|
57
|
-
|
|
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
|
+
*/
|
|
58
78
|
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
|
59
79
|
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
60
80
|
}
|
|
61
81
|
|
|
62
|
-
|
|
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
|
+
*/
|
|
63
88
|
export async function findFolderContainingFile(
|
|
64
89
|
folderPaths: string[],
|
|
65
90
|
relativeFilePath: string,
|
|
@@ -69,6 +94,16 @@ export async function findFolderContainingFile(
|
|
|
69
94
|
);
|
|
70
95
|
}
|
|
71
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
|
+
*/
|
|
72
107
|
export async function getFolderContainingFile(
|
|
73
108
|
folderPaths: string[],
|
|
74
109
|
relativeFilePath: string,
|
|
@@ -77,12 +112,10 @@ export async function getFolderContainingFile(
|
|
|
77
112
|
folderPaths,
|
|
78
113
|
relativeFilePath,
|
|
79
114
|
);
|
|
80
|
-
// should never happen, as the source was read from the FS anyway...
|
|
81
115
|
if (!maybeFolderPath) {
|
|
82
116
|
throw new Error(
|
|
83
|
-
`File "${relativeFilePath}" does not exist in any of these folders
|
|
84
|
-
|
|
85
|
-
)}`,
|
|
117
|
+
`File "${relativeFilePath}" does not exist in any of these folders:
|
|
118
|
+
- ${folderPaths.join('\n- ')}`,
|
|
86
119
|
);
|
|
87
120
|
}
|
|
88
121
|
return maybeFolderPath;
|
package/src/emitUtils.ts
CHANGED
|
@@ -13,6 +13,16 @@ import {findAsyncSequential} from './jsUtils';
|
|
|
13
13
|
|
|
14
14
|
const fileHash = new Map<string, string>();
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Outputs a file to the generated files directory. Only writes files if content
|
|
18
|
+
* differs from cache (for hot reload performance).
|
|
19
|
+
*
|
|
20
|
+
* @param generatedFilesDir Absolute path.
|
|
21
|
+
* @param file Path relative to `generatedFilesDir`.
|
|
22
|
+
* @param content String content to write.
|
|
23
|
+
* @param skipCache If `true` (defaults as `true` for production), file is
|
|
24
|
+
* force-rewritten, skipping cache.
|
|
25
|
+
*/
|
|
16
26
|
export async function generate(
|
|
17
27
|
generatedFilesDir: string,
|
|
18
28
|
file: string,
|
|
@@ -23,14 +33,21 @@ export async function generate(
|
|
|
23
33
|
|
|
24
34
|
if (skipCache) {
|
|
25
35
|
await fs.outputFile(filepath, content);
|
|
36
|
+
// Cache still needs to be reset, otherwise, writing "A", "B", and "A" where
|
|
37
|
+
// "B" skips cache will cause the last "A" not be able to overwrite as the
|
|
38
|
+
// first "A" remains in cache. But if the file never existed in cache, no
|
|
39
|
+
// need to register it.
|
|
40
|
+
if (fileHash.get(filepath)) {
|
|
41
|
+
fileHash.set(filepath, createHash('md5').update(content).digest('hex'));
|
|
42
|
+
}
|
|
26
43
|
return;
|
|
27
44
|
}
|
|
28
45
|
|
|
29
46
|
let lastHash = fileHash.get(filepath);
|
|
30
47
|
|
|
31
|
-
// If file already exists but
|
|
32
|
-
//
|
|
33
|
-
//
|
|
48
|
+
// If file already exists but it's not in runtime cache yet, we try to
|
|
49
|
+
// calculate the content hash and then compare. This is to avoid unnecessary
|
|
50
|
+
// overwriting and we can reuse old file.
|
|
34
51
|
if (!lastHash && (await fs.pathExists(filepath))) {
|
|
35
52
|
const lastContent = await fs.readFile(filepath, 'utf8');
|
|
36
53
|
lastHash = createHash('md5').update(lastContent).digest('hex');
|
|
@@ -45,7 +62,7 @@ export async function generate(
|
|
|
45
62
|
}
|
|
46
63
|
}
|
|
47
64
|
|
|
48
|
-
const chunkNameCache = new Map();
|
|
65
|
+
const chunkNameCache = new Map<string, string>();
|
|
49
66
|
|
|
50
67
|
/**
|
|
51
68
|
* Generate unique chunk name given a module path.
|
|
@@ -56,7 +73,7 @@ export function genChunkName(
|
|
|
56
73
|
preferredName?: string,
|
|
57
74
|
shortId: boolean = process.env.NODE_ENV === 'production',
|
|
58
75
|
): string {
|
|
59
|
-
let chunkName
|
|
76
|
+
let chunkName = chunkNameCache.get(modulePath);
|
|
60
77
|
if (!chunkName) {
|
|
61
78
|
if (shortId) {
|
|
62
79
|
chunkName = simpleHash(modulePath, 8);
|
|
@@ -82,6 +99,8 @@ export function genChunkName(
|
|
|
82
99
|
* @returns This returns a buffer, which you have to decode string yourself if
|
|
83
100
|
* needed. (Not always necessary since the output isn't for human consumption
|
|
84
101
|
* anyways, and most HTML manipulation libs accept buffers)
|
|
102
|
+
* @throws Throws when the HTML file is not found at any of the potential paths.
|
|
103
|
+
* This should never happen as it would lead to a 404.
|
|
85
104
|
*/
|
|
86
105
|
export async function readOutputHTMLFile(
|
|
87
106
|
permalink: string,
|
package/src/gitUtils.ts
CHANGED
|
@@ -8,23 +8,67 @@
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import shell from 'shelljs';
|
|
10
10
|
|
|
11
|
+
/** Custom error thrown when git is not found in `PATH`. */
|
|
11
12
|
export class GitNotFoundError extends Error {}
|
|
12
13
|
|
|
14
|
+
/** Custom error thrown when the current file is not tracked by git. */
|
|
13
15
|
export class FileNotTrackedError extends Error {}
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the git history of a file and returns a relevant commit date.
|
|
19
|
+
* It gets the commit date instead of author date so that amended commits
|
|
20
|
+
* can have their dates updated.
|
|
21
|
+
*
|
|
22
|
+
* @throws {GitNotFoundError} If git is not found in `PATH`.
|
|
23
|
+
* @throws {FileNotTrackedError} If the current file is not tracked by git.
|
|
24
|
+
* @throws Also throws when `git log` exited with non-zero, or when it outputs
|
|
25
|
+
* unexpected text.
|
|
26
|
+
*/
|
|
15
27
|
export function getFileCommitDate(
|
|
28
|
+
/** Absolute path to the file. */
|
|
16
29
|
file: string,
|
|
17
|
-
args: {
|
|
30
|
+
args: {
|
|
31
|
+
/**
|
|
32
|
+
* `"oldest"` is the commit that added the file, following renames;
|
|
33
|
+
* `"newest"` is the last commit that edited the file.
|
|
34
|
+
*/
|
|
35
|
+
age?: 'oldest' | 'newest';
|
|
36
|
+
/** Use `includeAuthor: true` to get the author information as well. */
|
|
37
|
+
includeAuthor?: false;
|
|
38
|
+
},
|
|
18
39
|
): {
|
|
40
|
+
/** Relevant commit date. */
|
|
19
41
|
date: Date;
|
|
42
|
+
/** Timestamp in **seconds**, as returned from git. */
|
|
20
43
|
timestamp: number;
|
|
21
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Fetches the git history of a file and returns a relevant commit date.
|
|
47
|
+
* It gets the commit date instead of author date so that amended commits
|
|
48
|
+
* can have their dates updated.
|
|
49
|
+
*
|
|
50
|
+
* @throws {GitNotFoundError} If git is not found in `PATH`.
|
|
51
|
+
* @throws {FileNotTrackedError} If the current file is not tracked by git.
|
|
52
|
+
* @throws Also throws when `git log` exited with non-zero, or when it outputs
|
|
53
|
+
* unexpected text.
|
|
54
|
+
*/
|
|
22
55
|
export function getFileCommitDate(
|
|
56
|
+
/** Absolute path to the file. */
|
|
23
57
|
file: string,
|
|
24
|
-
args: {
|
|
58
|
+
args: {
|
|
59
|
+
/**
|
|
60
|
+
* `"oldest"` is the commit that added the file, following renames;
|
|
61
|
+
* `"newest"` is the last commit that edited the file.
|
|
62
|
+
*/
|
|
63
|
+
age?: 'oldest' | 'newest';
|
|
64
|
+
includeAuthor: true;
|
|
65
|
+
},
|
|
25
66
|
): {
|
|
67
|
+
/** Relevant commit date. */
|
|
26
68
|
date: Date;
|
|
69
|
+
/** Timestamp in **seconds**, as returned from git. */
|
|
27
70
|
timestamp: number;
|
|
71
|
+
/** The author's name, as returned from git. */
|
|
28
72
|
author: string;
|
|
29
73
|
};
|
|
30
74
|
export function getFileCommitDate(
|
|
@@ -53,8 +97,6 @@ export function getFileCommitDate(
|
|
|
53
97
|
);
|
|
54
98
|
}
|
|
55
99
|
|
|
56
|
-
// Commit time and author name; not using author time so that amended commits
|
|
57
|
-
// can have their dates updated
|
|
58
100
|
let formatArg = '--format=%ct';
|
|
59
101
|
if (includeAuthor) {
|
|
60
102
|
formatArg += ',%an';
|