@docusaurus/utils 2.0.0-beta.16 → 2.0.0-beta.19
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 +51 -1
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +57 -10
- 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 +39 -13
- package/lib/dataFileUtils.js.map +1 -1
- 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 +54 -5
- package/lib/gitUtils.d.ts.map +1 -1
- package/lib/gitUtils.js +17 -14
- package/lib/gitUtils.js.map +1 -1
- package/lib/globUtils.d.ts +28 -0
- package/lib/globUtils.d.ts.map +1 -1
- package/lib/globUtils.js +36 -13
- 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 +7 -6
- package/lib/hashUtils.js.map +1 -1
- package/lib/i18nUtils.d.ts +51 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +69 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +10 -54
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +56 -256
- package/lib/index.js.map +1 -1
- package/lib/jsUtils.d.ts +45 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +94 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +48 -5
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +29 -13
- package/lib/markdownLinks.js.map +1 -1
- 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 +2 -1
- package/lib/pathUtils.d.ts.map +1 -1
- package/lib/pathUtils.js +16 -7
- 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 +6 -2
- package/lib/slugger.js.map +1 -1
- package/lib/tags.d.ts +42 -10
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +40 -26
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +57 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +132 -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 +8 -5
- package/lib/webpackUtils.js.map +1 -1
- package/package.json +11 -11
- package/src/constants.ts +65 -9
- package/src/dataFileUtils.ts +44 -12
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +77 -17
- package/src/globUtils.ts +34 -13
- package/src/hashUtils.ts +6 -5
- package/src/i18nUtils.ts +115 -0
- package/src/index.ts +43 -307
- package/src/jsUtils.ts +102 -0
- package/src/markdownLinks.ts +71 -28
- package/src/markdownUtils.ts +354 -0
- package/src/pathUtils.ts +15 -7
- package/src/slugger.ts +13 -1
- package/src/tags.ts +53 -28
- package/src/urlUtils.ts +145 -7
- package/src/webpackUtils.ts +11 -4
- package/lib/markdownParser.d.ts +0 -32
- package/lib/markdownParser.d.ts.map +0 -1
- package/lib/markdownParser.js +0 -161
- package/lib/markdownParser.js.map +0 -1
- package/src/markdownParser.ts +0 -201
package/lib/tags.d.ts
CHANGED
|
@@ -4,24 +4,56 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/** What the user configures. */
|
|
7
8
|
export declare type Tag = {
|
|
8
9
|
label: string;
|
|
10
|
+
/** Permalink to this tag's page, without the `/tags/` base path. */
|
|
9
11
|
permalink: string;
|
|
10
12
|
};
|
|
13
|
+
/** What the tags list page should know about each tag. */
|
|
14
|
+
export declare type TagsListItem = Tag & {
|
|
15
|
+
/** Number of posts/docs with this tag. */
|
|
16
|
+
count: number;
|
|
17
|
+
};
|
|
18
|
+
/** What the tag's own page should know about the tag. */
|
|
19
|
+
export declare type TagModule = TagsListItem & {
|
|
20
|
+
/** The tags list page's permalink. */
|
|
21
|
+
allTagsPath: string;
|
|
22
|
+
};
|
|
11
23
|
export declare type FrontMatterTag = string | Tag;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Takes tag objects as they are defined in front matter, and normalizes each
|
|
26
|
+
* into a standard tag object. The permalink is created by appending the
|
|
27
|
+
* sluggified label to `tagsPath`. Front matter tags already containing
|
|
28
|
+
* permalinks would still have `tagsPath` prepended.
|
|
29
|
+
*
|
|
30
|
+
* The result will always be unique by permalinks. The behavior with colliding
|
|
31
|
+
* permalinks is undetermined.
|
|
32
|
+
*/
|
|
33
|
+
export declare function normalizeFrontMatterTags(
|
|
34
|
+
/** Base path to append the tag permalinks to. */
|
|
35
|
+
tagsPath: string,
|
|
36
|
+
/** Can be `undefined`, so that we can directly pipe in `frontMatter.tags`. */
|
|
37
|
+
frontMatterTags?: FrontMatterTag[] | undefined): Tag[];
|
|
38
|
+
declare type TaggedItemGroup<Item> = {
|
|
15
39
|
tag: Tag;
|
|
16
40
|
items: Item[];
|
|
17
41
|
};
|
|
18
42
|
/**
|
|
19
|
-
* Permits to group docs/
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
43
|
+
* Permits to group docs/blog posts by tag (provided by front matter).
|
|
44
|
+
*
|
|
45
|
+
* @returns a map from tag permalink to the items and other relevant tag data.
|
|
46
|
+
* The record is indexed by permalink, because routes must be unique in the end.
|
|
47
|
+
* Labels may vary on 2 MD files but they are normalized. Docs with
|
|
48
|
+
* label='some label' and label='some-label' should end up in the same page.
|
|
49
|
+
*/
|
|
50
|
+
export declare function groupTaggedItems<Item>(items: readonly Item[],
|
|
51
|
+
/**
|
|
52
|
+
* A callback telling me how to get the tags list of the current item. Usually
|
|
53
|
+
* simply getting it from some metadata of the current item.
|
|
25
54
|
*/
|
|
26
|
-
|
|
55
|
+
getItemTags: (item: Item) => readonly Tag[]): {
|
|
56
|
+
[permalink: string]: TaggedItemGroup<Item>;
|
|
57
|
+
};
|
|
58
|
+
export {};
|
|
27
59
|
//# sourceMappingURL=tags.d.ts.map
|
package/lib/tags.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,oBAAY,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,oBAAY,
|
|
1
|
+
{"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,gCAAgC;AAChC,oBAAY,GAAG,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,0DAA0D;AAC1D,oBAAY,YAAY,GAAG,GAAG,GAAG;IAC/B,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,yDAAyD;AACzD,oBAAY,SAAS,GAAG,YAAY,GAAG;IACrC,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,oBAAY,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAgC1C;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB;AACtC,iDAAiD;AACjD,QAAQ,EAAE,MAAM;AAChB,8EAA8E;AAC9E,eAAe,GAAE,cAAc,EAAE,GAAG,SAAc,GACjD,GAAG,EAAE,CAMP;AAED,aAAK,eAAe,CAAC,IAAI,IAAI;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EACnC,KAAK,EAAE,SAAS,IAAI,EAAE;AACtB;;;GAGG;AACH,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,SAAS,GAAG,EAAE,GAC1C;IAAC,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;CAAC,CA0B9C"}
|
package/lib/tags.js
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.groupTaggedItems = exports.normalizeFrontMatterTags =
|
|
9
|
+
exports.groupTaggedItems = exports.normalizeFrontMatterTags = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const lodash_1 =
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
12
|
const urlUtils_1 = require("./urlUtils");
|
|
13
13
|
function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
14
14
|
function toTagObject(tagString) {
|
|
@@ -19,7 +19,7 @@ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
|
19
19
|
}
|
|
20
20
|
// TODO maybe make ensure the permalink is valid url path?
|
|
21
21
|
function normalizeTagPermalink(permalink) {
|
|
22
|
-
//
|
|
22
|
+
// Note: we always apply tagsPath on purpose. For versioned docs, v1/doc.md
|
|
23
23
|
// and v2/doc.md tags with custom permalinks don't lead to the same created
|
|
24
24
|
// page. tagsPath is different for each doc version
|
|
25
25
|
return (0, urlUtils_1.normalizeUrl)([tagsPath, permalink]);
|
|
@@ -32,38 +32,52 @@ function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
|
32
32
|
permalink: normalizeTagPermalink(tag.permalink),
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Takes tag objects as they are defined in front matter, and normalizes each
|
|
37
|
+
* into a standard tag object. The permalink is created by appending the
|
|
38
|
+
* sluggified label to `tagsPath`. Front matter tags already containing
|
|
39
|
+
* permalinks would still have `tagsPath` prepended.
|
|
40
|
+
*
|
|
41
|
+
* The result will always be unique by permalinks. The behavior with colliding
|
|
42
|
+
* permalinks is undetermined.
|
|
43
|
+
*/
|
|
44
|
+
function normalizeFrontMatterTags(
|
|
45
|
+
/** Base path to append the tag permalinks to. */
|
|
46
|
+
tagsPath,
|
|
47
|
+
/** Can be `undefined`, so that we can directly pipe in `frontMatter.tags`. */
|
|
48
|
+
frontMatterTags = []) {
|
|
37
49
|
const tags = frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag));
|
|
38
50
|
return lodash_1.default.uniqBy(tags, (tag) => tag.permalink);
|
|
39
51
|
}
|
|
40
52
|
exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
|
|
41
53
|
/**
|
|
42
|
-
* Permits to group docs/
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
54
|
+
* Permits to group docs/blog posts by tag (provided by front matter).
|
|
55
|
+
*
|
|
56
|
+
* @returns a map from tag permalink to the items and other relevant tag data.
|
|
57
|
+
* The record is indexed by permalink, because routes must be unique in the end.
|
|
58
|
+
* Labels may vary on 2 MD files but they are normalized. Docs with
|
|
59
|
+
* label='some label' and label='some-label' should end up in the same page.
|
|
60
|
+
*/
|
|
61
|
+
function groupTaggedItems(items,
|
|
62
|
+
/**
|
|
63
|
+
* A callback telling me how to get the tags list of the current item. Usually
|
|
64
|
+
* simply getting it from some metadata of the current item.
|
|
48
65
|
*/
|
|
49
|
-
|
|
66
|
+
getItemTags) {
|
|
50
67
|
const result = {};
|
|
51
|
-
function handleItemTag(item, tag) {
|
|
52
|
-
var _a;
|
|
53
|
-
// Init missing tag groups
|
|
54
|
-
// TODO: it's not really clear what should be the behavior if 2 items have
|
|
55
|
-
// the same tag but the permalink is different for each
|
|
56
|
-
// For now, the first tag found wins
|
|
57
|
-
result[tag.permalink] = (_a = result[tag.permalink]) !== null && _a !== void 0 ? _a : {
|
|
58
|
-
tag,
|
|
59
|
-
items: [],
|
|
60
|
-
};
|
|
61
|
-
// Add item to group
|
|
62
|
-
result[tag.permalink].items.push(item);
|
|
63
|
-
}
|
|
64
68
|
items.forEach((item) => {
|
|
65
69
|
getItemTags(item).forEach((tag) => {
|
|
66
|
-
|
|
70
|
+
var _a;
|
|
71
|
+
// Init missing tag groups
|
|
72
|
+
// TODO: it's not really clear what should be the behavior if 2 tags have
|
|
73
|
+
// the same permalink but the label is different for each
|
|
74
|
+
// For now, the first tag found wins
|
|
75
|
+
result[_a = tag.permalink] ?? (result[_a] = {
|
|
76
|
+
tag,
|
|
77
|
+
items: [],
|
|
78
|
+
});
|
|
79
|
+
// Add item to group
|
|
80
|
+
result[tag.permalink].items.push(item);
|
|
67
81
|
});
|
|
68
82
|
});
|
|
69
83
|
// If user add twice the same tag to a md doc (weird but possible),
|
package/lib/tags.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,4DAAuB;AACvB,yCAAwC;AAuBxC,SAAS,uBAAuB,CAC9B,QAAgB,EAChB,cAA8B;IAE9B,SAAS,WAAW,CAAC,SAAiB;QACpC,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,gBAAC,CAAC,SAAS,CAAC,SAAS,CAA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AC;YAEF,oBAAoB;YACpB,MAAM,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,mEAAmE;IACnE,wDAAwD;IACxD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACtC,KAAK,CAAC,KAAK,GAAG,gBAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAjCD,4CAiCC"}
|
package/lib/urlUtils.d.ts
CHANGED
|
@@ -4,6 +4,63 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Much like `path.join`, but much better. Takes an array of URL segments, and
|
|
9
|
+
* joins them into a reasonable URL.
|
|
10
|
+
*
|
|
11
|
+
* - `["file:", "/home", "/user/", "website"]` => `file:///home/user/website`
|
|
12
|
+
* - `["file://", "home", "/user/", "website"]` => `file://home/user/website` (relative!)
|
|
13
|
+
* - Remove trailing slash before parameters or hash.
|
|
14
|
+
* - Replace `?` in query parameters with `&`.
|
|
15
|
+
* - Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
16
|
+
*
|
|
17
|
+
* @throws {TypeError} If any of the URL segment is not a string, this throws.
|
|
18
|
+
*/
|
|
7
19
|
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
20
|
+
/**
|
|
21
|
+
* Takes a file's path, relative to its content folder, and computes its edit
|
|
22
|
+
* URL. If `editUrl` is `undefined`, this returns `undefined`, as is the case
|
|
23
|
+
* when the user doesn't want an edit URL in her config.
|
|
24
|
+
*/
|
|
8
25
|
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Converts file path to a reasonable URL path, e.g. `'index.md'` -> `'/'`,
|
|
28
|
+
* `'foo/bar.js'` -> `'/foo/bar'`
|
|
29
|
+
*/
|
|
30
|
+
export declare function fileToPath(file: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Similar to `encodeURI`, but uses `encodeURIComponent` and assumes there's no
|
|
33
|
+
* query.
|
|
34
|
+
*
|
|
35
|
+
* `encodeURI("/question?/answer")` => `"/question?/answer#section"`;
|
|
36
|
+
* `encodePath("/question?/answer#section")` => `"/question%3F/answer%23foo"`
|
|
37
|
+
*/
|
|
38
|
+
export declare function encodePath(userPath: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* Whether `str` is a valid pathname. It must be absolute, and not contain
|
|
41
|
+
* special characters.
|
|
42
|
+
*/
|
|
43
|
+
export declare function isValidPathname(str: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve pathnames and fail-fast if resolution fails. Uses standard URL
|
|
46
|
+
* semantics (provided by `resolve-pathname` which is used internally by React
|
|
47
|
+
* router)
|
|
48
|
+
*/
|
|
49
|
+
export declare function resolvePathname(to: string, from?: string): string;
|
|
50
|
+
/** Appends a leading slash to `str`, if one doesn't exist. */
|
|
51
|
+
export declare function addLeadingSlash(str: string): string;
|
|
52
|
+
/** Appends a trailing slash to `str`, if one doesn't exist. */
|
|
53
|
+
export declare function addTrailingSlash(str: string): string;
|
|
54
|
+
/** Removes the trailing slash from `str`. */
|
|
55
|
+
export declare function removeTrailingSlash(str: string): string;
|
|
56
|
+
/** Constructs an SSH URL that can be used to push to GitHub. */
|
|
57
|
+
export declare function buildSshUrl(githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
58
|
+
/** Constructs an HTTP URL that can be used to push to GitHub. */
|
|
59
|
+
export declare function buildHttpsUrl(gitCredentials: string, githubHost: string, organizationName: string, projectName: string, githubPort?: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Whether the current URL is an SSH protocol. In addition to looking for
|
|
62
|
+
* `ssh:`, it will also allow protocol-less URLs like
|
|
63
|
+
* `git@github.com:facebook/docusaurus.git`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function hasSSHProtocol(sourceRepoUrl: string): boolean;
|
|
9
66
|
//# sourceMappingURL=urlUtils.d.ts.map
|
package/lib/urlUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAoFtD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAKpB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUpD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AACD,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAGD,+DAA+D;AAC/D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED,6CAA6C;AAC7C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAU7D"}
|
package/lib/urlUtils.js
CHANGED
|
@@ -6,12 +6,31 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
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 jsUtils_1 = require("./jsUtils");
|
|
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
|
+
*/
|
|
10
25
|
function normalizeUrl(rawUrls) {
|
|
11
26
|
const urls = [...rawUrls];
|
|
12
27
|
const resultArray = [];
|
|
13
28
|
let hasStartingSlash = false;
|
|
14
29
|
let hasEndingSlash = false;
|
|
30
|
+
const isNonEmptyArray = (arr) => arr.length > 0;
|
|
31
|
+
if (!isNonEmptyArray(urls)) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
15
34
|
// If the first part is a plain protocol, we combine it with the next part.
|
|
16
35
|
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
17
36
|
const first = urls.shift();
|
|
@@ -37,13 +56,12 @@ function normalizeUrl(rawUrls) {
|
|
|
37
56
|
if (i === urls.length - 1 && hasEndingSlash) {
|
|
38
57
|
resultArray.push('/');
|
|
39
58
|
}
|
|
40
|
-
// eslint-disable-next-line no-continue
|
|
41
59
|
continue;
|
|
42
60
|
}
|
|
43
61
|
if (component !== '/') {
|
|
44
62
|
if (i > 0) {
|
|
45
63
|
// Removing the starting slashes for each component but the first.
|
|
46
|
-
component = component.replace(
|
|
64
|
+
component = component.replace(/^\/+/,
|
|
47
65
|
// Special case where the first element of rawUrls is empty
|
|
48
66
|
// ["", "/hello"] => /hello
|
|
49
67
|
component[0] === '/' && !hasStartingSlash ? '/' : '');
|
|
@@ -51,14 +69,14 @@ function normalizeUrl(rawUrls) {
|
|
|
51
69
|
hasEndingSlash = component[component.length - 1] === '/';
|
|
52
70
|
// Removing the ending slashes for each component but the last. For the
|
|
53
71
|
// last component we will combine multiple slashes to a single one.
|
|
54
|
-
component = component.replace(
|
|
72
|
+
component = component.replace(/\/+$/, i < urls.length - 1 ? '' : '/');
|
|
55
73
|
}
|
|
56
74
|
hasStartingSlash = true;
|
|
57
75
|
resultArray.push(component);
|
|
58
76
|
}
|
|
59
77
|
let str = resultArray.join('/');
|
|
60
|
-
// Each input component is now separated by a single slash
|
|
61
|
-
//
|
|
78
|
+
// Each input component is now separated by a single slash except the possible
|
|
79
|
+
// first plain protocol part.
|
|
62
80
|
// Remove trailing slash before parameters or hash.
|
|
63
81
|
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
64
82
|
// Replace ? in parameters with &.
|
|
@@ -71,6 +89,11 @@ function normalizeUrl(rawUrls) {
|
|
|
71
89
|
return str;
|
|
72
90
|
}
|
|
73
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
|
+
*/
|
|
74
97
|
function getEditUrl(fileRelativePath, editUrl) {
|
|
75
98
|
return editUrl
|
|
76
99
|
? // Don't use posixPath for this: we need to force a forward slash path
|
|
@@ -78,4 +101,107 @@ function getEditUrl(fileRelativePath, editUrl) {
|
|
|
78
101
|
: undefined;
|
|
79
102
|
}
|
|
80
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;
|
|
81
207
|
//# sourceMappingURL=urlUtils.js.map
|
package/lib/urlUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,uCAAuC;AACvC,gFAAqD;AAErD;;;;;;;;;;;GAWG;AACH,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,GAAG,CAAC,EAAE;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAG,CAAC;QAC5B,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACxD,wEAAwE;YACxE,8BAA8B;YAC9B,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;SAClC;aAAM;YACL,IAA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AI,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,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;
|
|
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,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"}
|
package/lib/webpackUtils.js
CHANGED
|
@@ -8,16 +8,19 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getFileLoaderUtils = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const path_1 =
|
|
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
|
-
|
|
20
|
-
const fileLoaderFileName = (folder) => `${constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[contenthash].[ext]`;
|
|
23
|
+
const fileLoaderFileName = (folder) => path_1.default.posix.join(constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME, folder, '[name]-[contenthash].[ext]');
|
|
21
24
|
const loaders = {
|
|
22
25
|
file: (options) => ({
|
|
23
26
|
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,
|
|
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,MAAM,kBAAkB,GAAG,CAAC,MAAmB,EAAE,EAAE,CACjD,cAAI,CAAC,KAAK,CAAC,IAAI,CACb,yCAA6B,EAC7B,MAAM,EACN,4BAA4B,CAC7B,CAAC;IAEJ,MAAM,OAAO,GAA+B;QAC1C,IAAI,EAAE,CAAC,OAA8B,EAAE,EAAE,CAAC,CAAC;YACzC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,aAAa,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-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,32 +18,32 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
22
|
-
"@svgr/webpack": "^6.
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.19",
|
|
22
|
+
"@svgr/webpack": "^6.2.1",
|
|
23
23
|
"file-loader": "^6.2.0",
|
|
24
|
-
"fs-extra": "^10.0
|
|
24
|
+
"fs-extra": "^10.1.0",
|
|
25
25
|
"github-slugger": "^1.4.0",
|
|
26
|
-
"globby": "^11.0
|
|
26
|
+
"globby": "^11.1.0",
|
|
27
27
|
"gray-matter": "^4.0.3",
|
|
28
28
|
"js-yaml": "^4.1.0",
|
|
29
29
|
"lodash": "^4.17.21",
|
|
30
|
-
"micromatch": "^4.0.
|
|
30
|
+
"micromatch": "^4.0.5",
|
|
31
31
|
"resolve-pathname": "^3.0.0",
|
|
32
32
|
"shelljs": "^0.8.5",
|
|
33
|
-
"tslib": "^2.
|
|
33
|
+
"tslib": "^2.4.0",
|
|
34
34
|
"url-loader": "^4.1.1",
|
|
35
|
-
"webpack": "^5.
|
|
35
|
+
"webpack": "^5.72.0"
|
|
36
36
|
},
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
41
|
+
"@docusaurus/types": "2.0.0-beta.19",
|
|
42
42
|
"@types/dedent": "^0.7.0",
|
|
43
43
|
"@types/github-slugger": "^1.3.0",
|
|
44
44
|
"@types/micromatch": "^4.0.2",
|
|
45
|
-
"@types/react-dom": "^
|
|
45
|
+
"@types/react-dom": "^18.0.3",
|
|
46
46
|
"dedent": "^0.7.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a71e60a49cce93c1006ef10c41ac03187f057102"
|
|
49
49
|
}
|