@docusaurus/utils 3.9.2 → 3.10.1-canary-6591
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/index.d.ts +5 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -11
- package/lib/index.js.map +1 -1
- package/lib/lastUpdateUtils.d.ts +2 -6
- package/lib/lastUpdateUtils.d.ts.map +1 -1
- package/lib/lastUpdateUtils.js +13 -60
- package/lib/lastUpdateUtils.js.map +1 -1
- package/lib/markdownHeadingIdUtils.d.ts +49 -0
- package/lib/markdownHeadingIdUtils.d.ts.map +1 -0
- package/lib/markdownHeadingIdUtils.js +148 -0
- package/lib/markdownHeadingIdUtils.js.map +1 -0
- package/lib/markdownUtils.d.ts +0 -31
- package/lib/markdownUtils.d.ts.map +1 -1
- package/lib/markdownUtils.js +0 -89
- package/lib/markdownUtils.js.map +1 -1
- package/lib/moduleUtils.d.ts.map +1 -1
- package/lib/moduleUtils.js +4 -4
- package/lib/moduleUtils.js.map +1 -1
- package/lib/{gitUtils.d.ts → vcs/gitUtils.d.ts} +18 -0
- package/lib/vcs/gitUtils.d.ts.map +1 -0
- package/lib/vcs/gitUtils.js +343 -0
- package/lib/vcs/gitUtils.js.map +1 -0
- package/lib/vcs/vcs.d.ts +19 -0
- package/lib/vcs/vcs.d.ts.map +1 -0
- package/lib/vcs/vcs.js +46 -0
- package/lib/vcs/vcs.js.map +1 -0
- package/lib/vcs/vcsDefaultV1.d.ts +13 -0
- package/lib/vcs/vcsDefaultV1.d.ts.map +1 -0
- package/lib/vcs/vcsDefaultV1.js +33 -0
- package/lib/vcs/vcsDefaultV1.js.map +1 -0
- package/lib/vcs/vcsDefaultV2.d.ts +13 -0
- package/lib/vcs/vcsDefaultV2.d.ts.map +1 -0
- package/lib/vcs/vcsDefaultV2.js +33 -0
- package/lib/vcs/vcsDefaultV2.js.map +1 -0
- package/lib/vcs/vcsDisabled.d.ts +12 -0
- package/lib/vcs/vcsDisabled.d.ts.map +1 -0
- package/lib/vcs/vcsDisabled.js +24 -0
- package/lib/vcs/vcsDisabled.js.map +1 -0
- package/lib/vcs/vcsGitAdHoc.d.ts +16 -0
- package/lib/vcs/vcsGitAdHoc.d.ts.map +1 -0
- package/lib/vcs/vcsGitAdHoc.js +29 -0
- package/lib/vcs/vcsGitAdHoc.js.map +1 -0
- package/lib/vcs/vcsGitEager.d.ts +10 -0
- package/lib/vcs/vcsGitEager.d.ts.map +1 -0
- package/lib/vcs/vcsGitEager.js +89 -0
- package/lib/vcs/vcsGitEager.js.map +1 -0
- package/lib/vcs/vcsHardcoded.d.ts +17 -0
- package/lib/vcs/vcsHardcoded.d.ts.map +1 -0
- package/lib/vcs/vcsHardcoded.js +41 -0
- package/lib/vcs/vcsHardcoded.js.map +1 -0
- package/package.json +11 -11
- package/src/index.ts +11 -8
- package/src/lastUpdateUtils.ts +18 -76
- package/src/markdownHeadingIdUtils.ts +209 -0
- package/src/markdownUtils.ts +0 -119
- package/src/moduleUtils.ts +6 -8
- package/src/vcs/gitUtils.ts +541 -0
- package/src/vcs/vcs.ts +54 -0
- package/src/vcs/vcsDefaultV1.ts +33 -0
- package/src/vcs/vcsDefaultV2.ts +33 -0
- package/src/vcs/vcsDisabled.ts +25 -0
- package/src/vcs/vcsGitAdHoc.ts +30 -0
- package/src/vcs/vcsGitEager.ts +135 -0
- package/src/vcs/vcsHardcoded.ts +45 -0
- package/lib/cliUtils.d.ts +0 -14
- package/lib/cliUtils.d.ts.map +0 -1
- package/lib/cliUtils.js +0 -49
- package/lib/cliUtils.js.map +0 -1
- package/lib/gitUtils.d.ts.map +0 -1
- package/lib/gitUtils.js +0 -103
- package/lib/gitUtils.js.map +0 -1
- package/src/cliUtils.ts +0 -65
- package/src/gitUtils.ts +0 -200
package/lib/markdownUtils.js
CHANGED
|
@@ -7,53 +7,18 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.DEFAULT_PARSE_FRONT_MATTER = void 0;
|
|
10
|
-
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
11
|
-
exports.escapeMarkdownHeadingIds = escapeMarkdownHeadingIds;
|
|
12
10
|
exports.unwrapMdxCodeBlocks = unwrapMdxCodeBlocks;
|
|
13
11
|
exports.admonitionTitleToDirectiveLabel = admonitionTitleToDirectiveLabel;
|
|
14
12
|
exports.createExcerpt = createExcerpt;
|
|
15
13
|
exports.parseFileContentFrontMatter = parseFileContentFrontMatter;
|
|
16
14
|
exports.parseMarkdownContentTitle = parseMarkdownContentTitle;
|
|
17
15
|
exports.parseMarkdownFile = parseMarkdownFile;
|
|
18
|
-
exports.writeMarkdownHeadingId = writeMarkdownHeadingId;
|
|
19
16
|
const tslib_1 = require("tslib");
|
|
20
17
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
21
18
|
const gray_matter_1 = tslib_1.__importDefault(require("gray-matter"));
|
|
22
|
-
const slugger_1 = require("./slugger");
|
|
23
19
|
// Some utilities for parsing Markdown content. These things are only used on
|
|
24
20
|
// server-side when we infer metadata like `title` and `description` from the
|
|
25
21
|
// content. Most parsing is still done in MDX through the mdx-loader.
|
|
26
|
-
/**
|
|
27
|
-
* Parses custom ID from a heading. The ID can contain any characters except
|
|
28
|
-
* `{#` and `}`.
|
|
29
|
-
*
|
|
30
|
-
* @param heading e.g. `## Some heading {#some-heading}` where the last
|
|
31
|
-
* character must be `}` for the ID to be recognized
|
|
32
|
-
*/
|
|
33
|
-
function parseMarkdownHeadingId(heading) {
|
|
34
|
-
const customHeadingIdRegex = /\s*\{#(?<id>(?:.(?!\{#|\}))*.)\}$/;
|
|
35
|
-
const matches = customHeadingIdRegex.exec(heading);
|
|
36
|
-
if (matches) {
|
|
37
|
-
return {
|
|
38
|
-
text: heading.replace(matches[0], ''),
|
|
39
|
-
id: matches.groups.id,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
return { text: heading, id: undefined };
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* MDX 2 requires escaping { with a \ so our anchor syntax need that now.
|
|
46
|
-
* See https://mdxjs.com/docs/troubleshooting-mdx/#could-not-parse-expression-with-acorn-error
|
|
47
|
-
*/
|
|
48
|
-
function escapeMarkdownHeadingIds(content) {
|
|
49
|
-
const markdownHeadingRegexp = /(?:^|\n)#{1,6}(?!#).*/g;
|
|
50
|
-
return content.replaceAll(markdownHeadingRegexp, (substring) =>
|
|
51
|
-
// TODO probably not the most efficient impl...
|
|
52
|
-
substring
|
|
53
|
-
.replace('{#', '\\{#')
|
|
54
|
-
// prevent duplicate escaping
|
|
55
|
-
.replace('\\\\{#', '\\{#'));
|
|
56
|
-
}
|
|
57
22
|
/**
|
|
58
23
|
* Hacky temporary escape hatch for Crowdin bad MDX support
|
|
59
24
|
* See https://docusaurus.io/docs/i18n/crowdin#mdx
|
|
@@ -288,58 +253,4 @@ This can happen if you use special characters in front matter values (try using
|
|
|
288
253
|
throw err;
|
|
289
254
|
}
|
|
290
255
|
}
|
|
291
|
-
function unwrapMarkdownLinks(line) {
|
|
292
|
-
return line.replace(/\[(?<alt>[^\]]+)\]\([^)]+\)/g, (match, p1) => p1);
|
|
293
|
-
}
|
|
294
|
-
function addHeadingId(line, slugger, maintainCase) {
|
|
295
|
-
let headingLevel = 0;
|
|
296
|
-
while (line.charAt(headingLevel) === '#') {
|
|
297
|
-
headingLevel += 1;
|
|
298
|
-
}
|
|
299
|
-
const headingText = line.slice(headingLevel).trimEnd();
|
|
300
|
-
const headingHashes = line.slice(0, headingLevel);
|
|
301
|
-
const slug = slugger.slug(unwrapMarkdownLinks(headingText).trim(), {
|
|
302
|
-
maintainCase,
|
|
303
|
-
});
|
|
304
|
-
return `${headingHashes}${headingText} {#${slug}}`;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Takes Markdown content, returns new content with heading IDs written.
|
|
308
|
-
* Respects existing IDs (unless `overwrite=true`) and never generates colliding
|
|
309
|
-
* IDs (through the slugger).
|
|
310
|
-
*/
|
|
311
|
-
function writeMarkdownHeadingId(content, options = { maintainCase: false, overwrite: false }) {
|
|
312
|
-
const { maintainCase = false, overwrite = false } = options;
|
|
313
|
-
const lines = content.split('\n');
|
|
314
|
-
const slugger = (0, slugger_1.createSlugger)();
|
|
315
|
-
// If we can't overwrite existing slugs, make sure other headings don't
|
|
316
|
-
// generate colliding slugs by first marking these slugs as occupied
|
|
317
|
-
if (!overwrite) {
|
|
318
|
-
lines.forEach((line) => {
|
|
319
|
-
const parsedHeading = parseMarkdownHeadingId(line);
|
|
320
|
-
if (parsedHeading.id) {
|
|
321
|
-
slugger.slug(parsedHeading.id);
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
let inCode = false;
|
|
326
|
-
return lines
|
|
327
|
-
.map((line) => {
|
|
328
|
-
if (line.startsWith('```')) {
|
|
329
|
-
inCode = !inCode;
|
|
330
|
-
return line;
|
|
331
|
-
}
|
|
332
|
-
// Ignore h1 headings, as we don't create anchor links for those
|
|
333
|
-
if (inCode || !line.startsWith('##')) {
|
|
334
|
-
return line;
|
|
335
|
-
}
|
|
336
|
-
const parsedHeading = parseMarkdownHeadingId(line);
|
|
337
|
-
// Do not process if id is already there
|
|
338
|
-
if (parsedHeading.id && !overwrite) {
|
|
339
|
-
return line;
|
|
340
|
-
}
|
|
341
|
-
return addHeadingId(parsedHeading.text, slugger, maintainCase);
|
|
342
|
-
})
|
|
343
|
-
.join('\n');
|
|
344
|
-
}
|
|
345
256
|
//# sourceMappingURL=markdownUtils.js.map
|
package/lib/markdownUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdownUtils.js","sourceRoot":"","sources":["../src/markdownUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"markdownUtils.js","sourceRoot":"","sources":["../src/markdownUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG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AO;SACR,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,gBAAM,CAAC,KAAK,CAAC;kHACiG,CAAC,CAAC;QAChH,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
package/lib/moduleUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleUtils.d.ts","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"moduleUtils.d.ts","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA2B1E"}
|
package/lib/moduleUtils.js
CHANGED
|
@@ -14,10 +14,10 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
|
14
14
|
jiti is able to load ESM, CJS, JSON, TS modules
|
|
15
15
|
*/
|
|
16
16
|
async function loadFreshModule(modulePath) {
|
|
17
|
+
if (typeof modulePath !== 'string') {
|
|
18
|
+
throw new Error(logger_1.default.interpolate `Invalid module path of type "name=${typeof modulePath}" with value "name=${modulePath}"`);
|
|
19
|
+
}
|
|
17
20
|
try {
|
|
18
|
-
if (typeof modulePath !== 'string') {
|
|
19
|
-
throw new Error(logger_1.default.interpolate `Invalid module path of type name=${modulePath}`);
|
|
20
|
-
}
|
|
21
21
|
const load = (0, jiti_1.default)(__filename, {
|
|
22
22
|
// Transpilation cache, can be safely enabled
|
|
23
23
|
cache: true,
|
|
@@ -33,7 +33,7 @@ async function loadFreshModule(modulePath) {
|
|
|
33
33
|
return load(modulePath);
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
|
-
throw new Error(logger_1.default.interpolate `Docusaurus could not load module at path path=${modulePath}
|
|
36
|
+
throw new Error(logger_1.default.interpolate `Docusaurus could not load module at path path=${modulePath}`, { cause: error });
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
//# sourceMappingURL=moduleUtils.js.map
|
package/lib/moduleUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"moduleUtils.js","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,
|
|
1
|
+
{"version":3,"file":"moduleUtils.js","sourceRoot":"","sources":["../src/moduleUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAQH,0CA2BC;;AAjCD,wDAAwB;AACxB,wEAAwC;AAExC;;GAEG;AACI,KAAK,UAAU,eAAe,CAAC,UAAkB;IACtD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,gBAAM,CAAC,WAAW,CAAA,qCAAqC,OAAO,UAAU,sBAAsB,UAAU,GAAG,CAC5G,CAAC;IACJ,CAAC;IACD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAA,cAAI,EAAC,UAAU,EAAE;YAC5B,6CAA6C;YAC7C,KAAK,EAAE,IAAI;YACX,uCAAuC;YACvC,oDAAoD;YACpD,YAAY,EAAE,KAAK;YACnB,kDAAkD;YAClD,sCAAsC;YACtC,qEAAqE;YACrE,cAAc,EAAE,IAAI;YACpB,eAAe;SAChB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,gBAAM,CAAC,WAAW,CAAA,iDAAiD,UAAU,EAAE,EAC/E,EAAC,KAAK,EAAE,KAAK,EAAC,CACf,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -63,4 +63,22 @@ file: string, args: {
|
|
|
63
63
|
/** The author's name, as returned from git. */
|
|
64
64
|
author: string;
|
|
65
65
|
}>;
|
|
66
|
+
type GitCommitInfo = {
|
|
67
|
+
timestamp: number;
|
|
68
|
+
author: string;
|
|
69
|
+
};
|
|
70
|
+
export declare function getGitLastUpdate(filePath: string): Promise<GitCommitInfo | null>;
|
|
71
|
+
export declare function getGitCreation(filePath: string): Promise<GitCommitInfo | null>;
|
|
72
|
+
export declare function isGitInsideWorktree(cwd: string): Promise<boolean>;
|
|
73
|
+
export declare function getGitRepoRoot(cwd: string): Promise<string>;
|
|
74
|
+
export declare function getGitSuperProjectRoot(cwd: string): Promise<string | null>;
|
|
75
|
+
export declare function getGitSubmodulePaths(cwd: string): Promise<string[]>;
|
|
76
|
+
export declare function getGitAllRepoRoots(cwd: string): Promise<string[]>;
|
|
77
|
+
export type GitFileInfo = {
|
|
78
|
+
creation: GitCommitInfo;
|
|
79
|
+
lastUpdate: GitCommitInfo;
|
|
80
|
+
};
|
|
81
|
+
export type GitFileInfoMap = Map<string, GitFileInfo>;
|
|
82
|
+
export declare function getGitRepositoryFilesInfo(cwd: string): Promise<GitFileInfoMap>;
|
|
83
|
+
export {};
|
|
66
84
|
//# sourceMappingURL=gitUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgDH,2DAA2D;AAC3D,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAI9C,uEAAuE;AACvE,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB;AACrC,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,uEAAuE;IACvE,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB,GACA,OAAO,CAAC;IACT,4BAA4B;IAC5B,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E,aAAa,CAAC;IACxB,UAAU,EAAE,aAAa,CAAC;CAC3B,CAAC;AAGF,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAKtD,wBAAsB,yBAAyB,CAC7C,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,cAAc,CAAC,CA8FzB"}
|
|
@@ -0,0 +1,343 @@
|
|
|
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.FileNotTrackedError = exports.GitNotFoundError = void 0;
|
|
10
|
+
exports.getFileCommitDate = getFileCommitDate;
|
|
11
|
+
exports.getGitLastUpdate = getGitLastUpdate;
|
|
12
|
+
exports.getGitCreation = getGitCreation;
|
|
13
|
+
exports.isGitInsideWorktree = isGitInsideWorktree;
|
|
14
|
+
exports.getGitRepoRoot = getGitRepoRoot;
|
|
15
|
+
exports.getGitSuperProjectRoot = getGitSuperProjectRoot;
|
|
16
|
+
exports.getGitSubmodulePaths = getGitSubmodulePaths;
|
|
17
|
+
exports.getGitAllRepoRoots = getGitAllRepoRoots;
|
|
18
|
+
exports.getGitRepositoryFilesInfo = getGitRepositoryFilesInfo;
|
|
19
|
+
const tslib_1 = require("tslib");
|
|
20
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
21
|
+
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
22
|
+
const os_1 = tslib_1.__importDefault(require("os"));
|
|
23
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
24
|
+
const execa_1 = tslib_1.__importDefault(require("execa"));
|
|
25
|
+
const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
|
|
26
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
27
|
+
// Quite high/conservative concurrency value (it was previously "Infinity")
|
|
28
|
+
// See https://github.com/facebook/docusaurus/pull/10915
|
|
29
|
+
const DefaultGitCommandConcurrency =
|
|
30
|
+
// TODO Docusaurus v4: bump node, availableParallelism() now always exists
|
|
31
|
+
(typeof os_1.default.availableParallelism === 'function'
|
|
32
|
+
? os_1.default.availableParallelism()
|
|
33
|
+
: os_1.default.cpus().length) * 4;
|
|
34
|
+
const GitCommandConcurrencyEnv = process.env.DOCUSAURUS_GIT_COMMAND_CONCURRENCY
|
|
35
|
+
? parseInt(process.env.DOCUSAURUS_GIT_COMMAND_CONCURRENCY, 10)
|
|
36
|
+
: undefined;
|
|
37
|
+
const GitCommandConcurrency = GitCommandConcurrencyEnv && GitCommandConcurrencyEnv > 0
|
|
38
|
+
? GitCommandConcurrencyEnv
|
|
39
|
+
: DefaultGitCommandConcurrency;
|
|
40
|
+
// We use a queue to avoid running too many concurrent Git commands at once
|
|
41
|
+
// See https://github.com/facebook/docusaurus/issues/10348
|
|
42
|
+
const GitCommandQueue = new p_queue_1.default({
|
|
43
|
+
concurrency: GitCommandConcurrency,
|
|
44
|
+
});
|
|
45
|
+
const realHasGitFn = () => {
|
|
46
|
+
try {
|
|
47
|
+
return execa_1.default.sync('git', ['--version']).exitCode === 0;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
// The hasGit call is synchronous IO so we memoize it
|
|
54
|
+
// The user won't install Git in the middle of a build anyway...
|
|
55
|
+
const hasGit = process.env.NODE_ENV === 'test' ? realHasGitFn : lodash_1.default.memoize(realHasGitFn);
|
|
56
|
+
// TODO Docusaurus v4: remove this
|
|
57
|
+
// Exceptions are not made for control flow logic
|
|
58
|
+
/** Custom error thrown when git is not found in `PATH`. */
|
|
59
|
+
class GitNotFoundError extends Error {
|
|
60
|
+
}
|
|
61
|
+
exports.GitNotFoundError = GitNotFoundError;
|
|
62
|
+
// TODO Docusaurus v4: remove this, only kept for retro-compatibility
|
|
63
|
+
// Exceptions are not made for control flow logic
|
|
64
|
+
/** Custom error thrown when the current file is not tracked by git. */
|
|
65
|
+
class FileNotTrackedError extends Error {
|
|
66
|
+
}
|
|
67
|
+
exports.FileNotTrackedError = FileNotTrackedError;
|
|
68
|
+
async function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
|
|
69
|
+
if (!hasGit()) {
|
|
70
|
+
throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
|
|
71
|
+
}
|
|
72
|
+
if (!(await fs_extra_1.default.pathExists(file))) {
|
|
73
|
+
throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
|
|
74
|
+
}
|
|
75
|
+
// We add a "RESULT:" prefix to make parsing easier
|
|
76
|
+
// See why: https://github.com/facebook/docusaurus/pull/10022
|
|
77
|
+
const resultFormat = includeAuthor ? 'RESULT:%ct,%an' : 'RESULT:%ct';
|
|
78
|
+
const args = [
|
|
79
|
+
`--format=${resultFormat}`,
|
|
80
|
+
'--max-count=1',
|
|
81
|
+
age === 'oldest' ? '--follow --diff-filter=A' : undefined,
|
|
82
|
+
]
|
|
83
|
+
.filter(Boolean)
|
|
84
|
+
.join(' ');
|
|
85
|
+
// Do not include GPG signature in the log output
|
|
86
|
+
// See https://github.com/facebook/docusaurus/pull/10022
|
|
87
|
+
const command = `git -c log.showSignature=false log ${args} -- "${path_1.default.basename(file)}"`;
|
|
88
|
+
const result = (await GitCommandQueue.add(() => {
|
|
89
|
+
return (0, execa_1.default)(command, {
|
|
90
|
+
cwd: path_1.default.dirname(file),
|
|
91
|
+
shell: true,
|
|
92
|
+
});
|
|
93
|
+
}));
|
|
94
|
+
if (result.exitCode !== 0) {
|
|
95
|
+
throw new Error(`Failed to retrieve the git history for file "${file}" with exit code ${result.exitCode}: ${result.stderr}`);
|
|
96
|
+
}
|
|
97
|
+
// We only parse the output line starting with our "RESULT:" prefix
|
|
98
|
+
// See why https://github.com/facebook/docusaurus/pull/10022
|
|
99
|
+
const regex = includeAuthor
|
|
100
|
+
? /(?:^|\n)RESULT:(?<timestamp>\d+),(?<author>.+)(?:$|\n)/
|
|
101
|
+
: /(?:^|\n)RESULT:(?<timestamp>\d+)(?:$|\n)/;
|
|
102
|
+
const output = result.stdout.trim();
|
|
103
|
+
if (!output) {
|
|
104
|
+
throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
|
|
105
|
+
}
|
|
106
|
+
const match = output.match(regex);
|
|
107
|
+
if (!match) {
|
|
108
|
+
throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
|
|
109
|
+
}
|
|
110
|
+
const timestampInSeconds = Number(match.groups.timestamp);
|
|
111
|
+
const timestamp = timestampInSeconds * 1000;
|
|
112
|
+
const date = new Date(timestamp);
|
|
113
|
+
if (includeAuthor) {
|
|
114
|
+
return { date, timestamp, author: match.groups.author };
|
|
115
|
+
}
|
|
116
|
+
return { date, timestamp };
|
|
117
|
+
}
|
|
118
|
+
let showedGitRequirementError = false;
|
|
119
|
+
let showedFileNotTrackedError = false;
|
|
120
|
+
async function getGitCommitInfo(filePath, age) {
|
|
121
|
+
if (!filePath) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
// Wrap in try/catch in case the shell commands fail
|
|
125
|
+
// (e.g. project doesn't use Git, etc).
|
|
126
|
+
try {
|
|
127
|
+
const result = await getFileCommitDate(filePath, {
|
|
128
|
+
age,
|
|
129
|
+
includeAuthor: true,
|
|
130
|
+
});
|
|
131
|
+
return { timestamp: result.timestamp, author: result.author };
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
// TODO legacy perf issue: do not use exceptions for control flow!
|
|
135
|
+
if (err instanceof GitNotFoundError) {
|
|
136
|
+
if (!showedGitRequirementError) {
|
|
137
|
+
logger_1.default.warn('Sorry, the last update options require Git.');
|
|
138
|
+
showedGitRequirementError = true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
else if (err instanceof FileNotTrackedError) {
|
|
142
|
+
if (!showedFileNotTrackedError) {
|
|
143
|
+
logger_1.default.warn('Cannot infer the update date for some files, as they are not tracked by git.');
|
|
144
|
+
showedFileNotTrackedError = true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
throw new Error(`An error occurred when trying to get the file ${age === 'oldest' ? 'creation' : 'last update'} date from Git`, { cause: err });
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
async function getGitLastUpdate(filePath) {
|
|
154
|
+
return getGitCommitInfo(filePath, 'newest');
|
|
155
|
+
}
|
|
156
|
+
async function getGitCreation(filePath) {
|
|
157
|
+
return getGitCommitInfo(filePath, 'oldest');
|
|
158
|
+
}
|
|
159
|
+
async function isGitInsideWorktree(cwd) {
|
|
160
|
+
try {
|
|
161
|
+
const result = await (0, execa_1.default)('git', ['rev-parse', '--is-inside-work-tree'], {
|
|
162
|
+
cwd,
|
|
163
|
+
reject: false,
|
|
164
|
+
});
|
|
165
|
+
return result.exitCode === 0;
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
throw new Error(`Couldn't check if this directory is within a Git worktree: ${cwd}`, { cause: error });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async function getGitRepoRoot(cwd) {
|
|
172
|
+
const createErrorMessageBase = () => {
|
|
173
|
+
return `Couldn't find the git repository root directory
|
|
174
|
+
Failure while running ${logger_1.default.code('git rev-parse --show-toplevel')} from cwd=${logger_1.default.path(cwd)}`;
|
|
175
|
+
};
|
|
176
|
+
const result = await (0, execa_1.default)('git', ['rev-parse', '--show-toplevel'], {
|
|
177
|
+
cwd,
|
|
178
|
+
}).catch((error) => {
|
|
179
|
+
// We enter this rejection when cwd is not a dir for example
|
|
180
|
+
throw new Error(`${createErrorMessageBase()}
|
|
181
|
+
The command executed throws an error: ${error.message}`, { cause: error });
|
|
182
|
+
});
|
|
183
|
+
if (result.exitCode !== 0) {
|
|
184
|
+
throw new Error(`${createErrorMessageBase()}
|
|
185
|
+
The command returned exit code ${logger_1.default.code(result.exitCode)}: ${logger_1.default.subdue(result.stderr)}`);
|
|
186
|
+
}
|
|
187
|
+
return fs_extra_1.default.realpath.native(result.stdout.trim());
|
|
188
|
+
}
|
|
189
|
+
// A Git "superproject" is a Git repository that contains submodules
|
|
190
|
+
// See https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---show-superproject-working-tree
|
|
191
|
+
// See https://git-scm.com/book/en/v2/Git-Tools-Submodules
|
|
192
|
+
async function getGitSuperProjectRoot(cwd) {
|
|
193
|
+
const createErrorMessageBase = () => {
|
|
194
|
+
return `Couldn't find the git superproject root directory
|
|
195
|
+
Failure while running ${logger_1.default.code('git rev-parse --show-superproject-working-tree')} from cwd=${logger_1.default.path(cwd)}`;
|
|
196
|
+
};
|
|
197
|
+
const result = await (0, execa_1.default)('git', ['rev-parse', '--show-superproject-working-tree'], {
|
|
198
|
+
cwd,
|
|
199
|
+
}).catch((error) => {
|
|
200
|
+
// We enter this rejection when cwd is not a dir for example
|
|
201
|
+
throw new Error(`${createErrorMessageBase()}
|
|
202
|
+
The command executed throws an error: ${error.message}`, { cause: error });
|
|
203
|
+
});
|
|
204
|
+
if (result.exitCode !== 0) {
|
|
205
|
+
throw new Error(`${createErrorMessageBase()}
|
|
206
|
+
The command returned exit code ${logger_1.default.code(result.exitCode)}: ${logger_1.default.subdue(result.stderr)}`);
|
|
207
|
+
}
|
|
208
|
+
const output = result.stdout.trim();
|
|
209
|
+
// this command only works when inside submodules
|
|
210
|
+
// otherwise it doesn't return anything when we are inside the main repo
|
|
211
|
+
if (output) {
|
|
212
|
+
return fs_extra_1.default.realpath.native(output);
|
|
213
|
+
}
|
|
214
|
+
return getGitRepoRoot(cwd);
|
|
215
|
+
}
|
|
216
|
+
// See https://git-scm.com/book/en/v2/Git-Tools-Submodules
|
|
217
|
+
async function getGitSubmodulePaths(cwd) {
|
|
218
|
+
const createErrorMessageBase = () => {
|
|
219
|
+
return `Couldn't read the list of git submodules
|
|
220
|
+
Failure while running ${logger_1.default.code('git submodule status')} from cwd=${logger_1.default.path(cwd)}`;
|
|
221
|
+
};
|
|
222
|
+
const result = await (0, execa_1.default)('git', ['submodule', 'status'], {
|
|
223
|
+
cwd,
|
|
224
|
+
}).catch((error) => {
|
|
225
|
+
// We enter this rejection when cwd is not a dir for example
|
|
226
|
+
throw new Error(`${createErrorMessageBase()}
|
|
227
|
+
The command executed throws an error: ${error.message}`, { cause: error });
|
|
228
|
+
});
|
|
229
|
+
if (result.exitCode !== 0) {
|
|
230
|
+
throw new Error(`${createErrorMessageBase()}
|
|
231
|
+
The command returned exit code ${logger_1.default.code(result.exitCode)}: ${logger_1.default.subdue(result.stderr)}`);
|
|
232
|
+
}
|
|
233
|
+
const output = result.stdout.trim();
|
|
234
|
+
if (!output) {
|
|
235
|
+
return [];
|
|
236
|
+
}
|
|
237
|
+
/* The output may contain a space/-/+/U prefix, for example
|
|
238
|
+
1234567e3e35d1f5b submodules/foo (heads/main)
|
|
239
|
+
-9ab1f1d3a2d77b0a4 submodules/bar (heads/dev)
|
|
240
|
+
+f00ba42e1b3ddead submodules/baz (remotes/origin/main)
|
|
241
|
+
Udeadbeefcafe1234 submodules/qux
|
|
242
|
+
*/
|
|
243
|
+
const getSubmodulePath = async (line) => {
|
|
244
|
+
const submodulePath = line.substring(1).split(' ')[1];
|
|
245
|
+
if (!submodulePath) {
|
|
246
|
+
throw new Error(`Failed to parse git submodule line: ${line}`);
|
|
247
|
+
}
|
|
248
|
+
return submodulePath;
|
|
249
|
+
};
|
|
250
|
+
return Promise.all(output.split('\n').map(getSubmodulePath));
|
|
251
|
+
}
|
|
252
|
+
// Find the root git repository alongside all its submodules, if any
|
|
253
|
+
async function getGitAllRepoRoots(cwd) {
|
|
254
|
+
try {
|
|
255
|
+
const superProjectRoot = await getGitSuperProjectRoot(cwd);
|
|
256
|
+
if (!superProjectRoot) {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
let submodulePaths = await getGitSubmodulePaths(superProjectRoot);
|
|
260
|
+
submodulePaths = await Promise.all(submodulePaths.map((submodulePath) => fs_extra_1.default.realpath.native(path_1.default.resolve(superProjectRoot, submodulePath))));
|
|
261
|
+
return [superProjectRoot, ...submodulePaths];
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
throw new Error(`Could not get all the git repository root paths (superproject + submodules) from cwd=${cwd}`, { cause: error });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// Logic inspired from Astro Starlight:
|
|
268
|
+
// See https://bsky.app/profile/bluwy.me/post/3lyihod6qos2a
|
|
269
|
+
// See https://github.com/withastro/starlight/blob/c417f1efd463be63b7230617d72b120caed098cd/packages/starlight/utils/git.ts#L58
|
|
270
|
+
async function getGitRepositoryFilesInfo(cwd) {
|
|
271
|
+
// git --no-pager -c log.showSignature=false log --format=t:%ct,a:%an --name-status
|
|
272
|
+
const result = await (0, execa_1.default)('git', [
|
|
273
|
+
'--no-pager',
|
|
274
|
+
// Do not include GPG signature in the log output
|
|
275
|
+
// See https://github.com/facebook/docusaurus/pull/10022
|
|
276
|
+
'-c',
|
|
277
|
+
'log.showSignature=false',
|
|
278
|
+
// The git command we want to run
|
|
279
|
+
'log',
|
|
280
|
+
// Format each history entry as t:<seconds since epoch>
|
|
281
|
+
'--format=t:%ct,a:%an',
|
|
282
|
+
// In each entry include the name and status for each modified file
|
|
283
|
+
'--name-status',
|
|
284
|
+
// For creation info, should we use --follow --find-renames=100% ???
|
|
285
|
+
], {
|
|
286
|
+
cwd,
|
|
287
|
+
encoding: 'utf-8',
|
|
288
|
+
// TODO use streaming to avoid a large buffer
|
|
289
|
+
// See https://github.com/withastro/starlight/issues/3154
|
|
290
|
+
maxBuffer: 20 * 1024 * 1024,
|
|
291
|
+
});
|
|
292
|
+
if (result.exitCode !== 0) {
|
|
293
|
+
throw new Error(`Docusaurus failed to run the 'git log' to retrieve tracked files last update date/author.
|
|
294
|
+
The command exited with code ${result.exitCode}: ${result.stderr}`);
|
|
295
|
+
}
|
|
296
|
+
const logLines = result.stdout.split('\n');
|
|
297
|
+
const now = Date.now();
|
|
298
|
+
// TODO not fail-fast
|
|
299
|
+
let runningDate = now;
|
|
300
|
+
let runningAuthor = 'N/A';
|
|
301
|
+
const runningMap = new Map();
|
|
302
|
+
for (const logLine of logLines) {
|
|
303
|
+
if (logLine.startsWith('t:')) {
|
|
304
|
+
// t:<timestamp>,a:<author name>
|
|
305
|
+
const [timestampStr, authorStr] = logLine.split(',');
|
|
306
|
+
const timestamp = Number.parseInt(timestampStr.slice(2), 10) * 1000;
|
|
307
|
+
const author = authorStr.slice(2);
|
|
308
|
+
runningDate = timestamp;
|
|
309
|
+
runningAuthor = author;
|
|
310
|
+
}
|
|
311
|
+
// TODO the code below doesn't handle delete/move/rename operations properly
|
|
312
|
+
// it returns files that no longer exist in the repo (deleted/moved)
|
|
313
|
+
// - Added files take the format `A\t<file>`
|
|
314
|
+
// - Modified files take the format `M\t<file>`
|
|
315
|
+
// - Deleted files take the format `D\t<file>`
|
|
316
|
+
// - Renamed files take the format `R<count>\t<old>\t<new>`
|
|
317
|
+
// - Copied files take the format `C<count>\t<old>\t<new>`
|
|
318
|
+
// The name of the file as of the commit being processed is always
|
|
319
|
+
// the last part of the log line.
|
|
320
|
+
const tabSplit = logLine.lastIndexOf('\t');
|
|
321
|
+
if (tabSplit === -1) {
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
const relativeFile = logLine.slice(tabSplit + 1);
|
|
325
|
+
const currentFileInfo = runningMap.get(relativeFile);
|
|
326
|
+
const currentCreationTime = currentFileInfo?.creation.timestamp || now;
|
|
327
|
+
const newCreationTime = Math.min(currentCreationTime, runningDate);
|
|
328
|
+
const newCreation = !currentFileInfo || newCreationTime !== currentCreationTime
|
|
329
|
+
? { timestamp: newCreationTime, author: runningAuthor }
|
|
330
|
+
: currentFileInfo.creation;
|
|
331
|
+
const currentLastUpdateTime = currentFileInfo?.lastUpdate.timestamp || 0;
|
|
332
|
+
const newLastUpdateTime = Math.max(currentLastUpdateTime, runningDate);
|
|
333
|
+
const newLastUpdate = !currentFileInfo || newLastUpdateTime !== currentLastUpdateTime
|
|
334
|
+
? { timestamp: newLastUpdateTime, author: runningAuthor }
|
|
335
|
+
: currentFileInfo.lastUpdate;
|
|
336
|
+
runningMap.set(relativeFile, {
|
|
337
|
+
creation: newCreation,
|
|
338
|
+
lastUpdate: newLastUpdate,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return runningMap;
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=gitUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../../src/vcs/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAkHH,8CAuFC;AAgDD,4CAIC;AAED,wCAIC;AAED,kDAaC;AAED,wCA6BC;AAKD,wDAyCC;AAGD,oDAiDC;AAGD,gDAmBC;AAcD,8DAgGC;;AArhBD,wDAAwB;AACxB,gEAA0B;AAC1B,oDAAoB;AACpB,4DAAuB;AACvB,0DAA0B;AAC1B,8DAA6B;AAC7B,wEAAwC;AAExC,2EAA2E;AAC3E,wDAAwD;AACxD,MAAM,4BAA4B;AAChC,0EAA0E;AAC1E,CAAC,OAAO,YAAE,CAAC,oBAAoB,KAAK,UAAU;IAC5C,CAAC,CAAC,YAAE,CAAC,oBAAoB,EAAE;IAC3B,CAAC,CAAC,YAAE,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAE5B,MAAM,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,kCAAkC;IAC7E,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,EAAE,CAAC;IAC9D,CAAC,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C;QACzE,MAAM,iBAAiB,GAAG,IAAI,CAAC,GAAG,CAAC,qBAAqB,EAAE,WAAW,CAAC,CAAC;QACvE,MAAM,aAAa,GACjB,CAAC,eAAe,IAAI,iBAAiB,KAAK,qBAAqB;YAC7D,CAAC,CAAC,EAAC,SAAS,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAC;YACvD,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC;QAEjC,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE;YAC3B,QAAQ,EAAE,WAAW;YACrB,UAAU,EAAE,aAAa;SAC1B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/lib/vcs/vcs.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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 { VcsConfig, VcsPreset } from '@docusaurus/types';
|
|
8
|
+
export declare const VcsPresetNames: VcsPreset[];
|
|
9
|
+
export declare function findVcsPreset(presetName: string): VcsConfig | undefined;
|
|
10
|
+
export declare function getVcsPreset(presetName: VcsPreset): VcsConfig;
|
|
11
|
+
export declare const TEST_VCS: {
|
|
12
|
+
initialize: (params: import("@docusaurus/types").VscInitializeParams) => void;
|
|
13
|
+
getFileCreationInfo: (filePath: string) => Promise<import("@docusaurus/types").VcsChangeInfo | null>;
|
|
14
|
+
getFileLastUpdateInfo: (filePath: string) => Promise<import("@docusaurus/types").VcsChangeInfo | null>;
|
|
15
|
+
CREATION_INFO: import("@docusaurus/types").VcsChangeInfo;
|
|
16
|
+
LAST_UPDATE_INFO: import("@docusaurus/types").VcsChangeInfo;
|
|
17
|
+
UNTRACKED_FILE_PATH: string;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=vcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcs.d.ts","sourceRoot":"","sources":["../../src/vcs/vcs.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,SAAS,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAY5D,eAAO,MAAM,cAAc,EAA8B,SAAS,EAAE,CAAC;AAErE,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAEvE;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,SAAS,GAAG,SAAS,CAS7D;AAGD,eAAO,MAAM,QAAQ;;;;;;;CAKpB,CAAC"}
|
package/lib/vcs/vcs.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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.TEST_VCS = exports.VcsPresetNames = void 0;
|
|
10
|
+
exports.findVcsPreset = findVcsPreset;
|
|
11
|
+
exports.getVcsPreset = getVcsPreset;
|
|
12
|
+
const vcsHardcoded_1 = require("./vcsHardcoded");
|
|
13
|
+
const vcsGitAdHoc_1 = require("./vcsGitAdHoc");
|
|
14
|
+
const vcsGitEager_1 = require("./vcsGitEager");
|
|
15
|
+
const vcsDisabled_1 = require("./vcsDisabled");
|
|
16
|
+
const vcsDefaultV1_1 = require("./vcsDefaultV1");
|
|
17
|
+
const vcsDefaultV2_1 = require("./vcsDefaultV2");
|
|
18
|
+
const VcsPresets = {
|
|
19
|
+
'git-ad-hoc': vcsGitAdHoc_1.VcsGitAdHoc,
|
|
20
|
+
'git-eager': vcsGitEager_1.VscGitEager,
|
|
21
|
+
hardcoded: vcsHardcoded_1.VcsHardcoded,
|
|
22
|
+
disabled: vcsDisabled_1.VcsDisabled,
|
|
23
|
+
'default-v1': vcsDefaultV1_1.VcsDefaultV1,
|
|
24
|
+
'default-v2': vcsDefaultV2_1.VcsDefaultV2,
|
|
25
|
+
};
|
|
26
|
+
exports.VcsPresetNames = Object.keys(VcsPresets);
|
|
27
|
+
function findVcsPreset(presetName) {
|
|
28
|
+
return VcsPresets[presetName];
|
|
29
|
+
}
|
|
30
|
+
function getVcsPreset(presetName) {
|
|
31
|
+
const vcs = findVcsPreset(presetName);
|
|
32
|
+
if (vcs) {
|
|
33
|
+
return vcs;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Unknown Docusaurus VCS preset name: ${process.env.DOCUSAURUS_VCS}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Convenient export for writing unit tests depending on VCS
|
|
40
|
+
exports.TEST_VCS = {
|
|
41
|
+
CREATION_INFO: vcsHardcoded_1.VCS_HARDCODED_CREATION_INFO,
|
|
42
|
+
LAST_UPDATE_INFO: vcsHardcoded_1.VCS_HARDCODED_LAST_UPDATE_INFO,
|
|
43
|
+
UNTRACKED_FILE_PATH: vcsHardcoded_1.VCS_HARDCODED_UNTRACKED_FILE_PATH,
|
|
44
|
+
...vcsHardcoded_1.VcsHardcoded,
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=vcs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vcs.js","sourceRoot":"","sources":["../../src/vcs/vcs.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA2BH,sCAEC;AAED,oCASC;AAtCD,iDAKwB;AACxB,+CAA0C;AAC1C,+CAA0C;AAC1C,+CAA0C;AAC1C,iDAA4C;AAC5C,iDAA4C;AAG5C,MAAM,UAAU,GAAiC;IAC/C,YAAY,EAAE,yBAAW;IACzB,WAAW,EAAE,yBAAW;IACxB,SAAS,EAAE,2BAAY;IACvB,QAAQ,EAAE,yBAAW;IAErB,YAAY,EAAE,2BAAY;IAC1B,YAAY,EAAE,2BAAY;CAC3B,CAAC;AAEW,QAAA,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAgB,CAAC;AAErE,SAAgB,aAAa,CAAC,UAAkB;IAC9C,OAAO,UAAU,CAAC,UAAuB,CAAC,CAAC;AAC7C,CAAC;AAED,SAAgB,YAAY,CAAC,UAAqB;IAChD,MAAM,GAAG,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IACtC,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,GAAG,CAAC;IACb,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CACb,uCAAuC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CACpE,CAAC;IACJ,CAAC;AACH,CAAC;AAED,4DAA4D;AAC/C,QAAA,QAAQ,GAAG;IACtB,aAAa,EAAE,0CAA2B;IAC1C,gBAAgB,EAAE,6CAA8B;IAChD,mBAAmB,EAAE,gDAAiC;IACtD,GAAG,2BAAY;CAChB,CAAC"}
|