@docusaurus/utils 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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 +20 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +26 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +24 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +65 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/emitUtils.d.ts +23 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +90 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +17 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +12 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +48 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +1 -0
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +7 -5
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +17 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +40 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +15 -75
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +84 -395
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +17 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +72 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +1 -0
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +36 -11
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownParser.d.ts +5 -3
- package/lib/markdownParser.d.ts.map +1 -0
- package/lib/markdownParser.js +72 -52
- package/lib/markdownParser.js.map +1 -0
- package/lib/pathUtils.d.ts +44 -0
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +88 -10
- package/lib/pathUtils.js.map +1 -0
- package/lib/slugger.d.ts +14 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +19 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +27 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +76 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +20 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +136 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +30 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +112 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +20 -10
- package/src/constants.ts +38 -0
- package/src/dataFileUtils.ts +90 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +113 -0
- package/src/gitUtils.ts +93 -0
- package/src/globUtils.ts +64 -0
- package/src/hashUtils.ts +3 -3
- package/src/i18nUtils.ts +58 -0
- package/src/index.ts +87 -502
- package/src/jsUtils.ts +88 -0
- package/src/markdownLinks.ts +35 -13
- package/src/markdownParser.ts +76 -57
- package/src/pathUtils.ts +87 -8
- package/src/slugger.ts +24 -0
- package/src/tags.ts +105 -0
- package/src/urlUtils.ts +149 -0
- package/src/webpackUtils.ts +146 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -631
- package/src/__tests__/markdownParser.test.ts +0 -817
- package/src/__tests__/pathUtils.test.ts +0 -63
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/codeTranslationsUtils.ts +0 -56
- package/src/escapePath.ts +0 -23
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/lib/tags.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
export declare type Tag = {
|
|
8
|
+
label: string;
|
|
9
|
+
permalink: string;
|
|
10
|
+
};
|
|
11
|
+
export declare type FrontMatterTag = string | Tag;
|
|
12
|
+
export declare function normalizeFrontMatterTag(tagsPath: string, frontMatterTag: FrontMatterTag): Tag;
|
|
13
|
+
export declare function normalizeFrontMatterTags(tagsPath: string, frontMatterTags?: FrontMatterTag[] | undefined): Tag[];
|
|
14
|
+
export declare type TaggedItemGroup<Item> = {
|
|
15
|
+
tag: Tag;
|
|
16
|
+
items: Item[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Permits to group docs/blogPosts by tag (provided by front matter)
|
|
20
|
+
* Note: groups are indexed by permalink, because routes must be unique in the
|
|
21
|
+
* end. Labels may vary on 2 md files but they are normalized. Docs with
|
|
22
|
+
* label='some label' and label='some-label' should end-up in the same
|
|
23
|
+
* group/page in the end. We can't create 2 routes /some-label because one would
|
|
24
|
+
* override the other
|
|
25
|
+
*/
|
|
26
|
+
export declare function groupTaggedItems<Item>(items: Item[], getItemTags: (item: Item) => Tag[]): Record<string, TaggedItemGroup<Item>>;
|
|
27
|
+
//# sourceMappingURL=tags.d.ts.map
|
|
@@ -0,0 +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,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAE1C,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,cAAc,GAC7B,GAAG,CAyBL;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,eAAe,GAAE,cAAc,EAAE,GAAG,SAAc,GACjD,GAAG,EAAE,CAMP;AAED,oBAAY,eAAe,CAAC,IAAI,IAAI;IAClC,GAAG,EAAE,GAAG,CAAC;IACT,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EACnC,KAAK,EAAE,IAAI,EAAE,EACb,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,GAAG,EAAE,GACjC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CA8BvC"}
|
package/lib/tags.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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.groupTaggedItems = exports.normalizeFrontMatterTags = exports.normalizeFrontMatterTag = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
12
|
+
const urlUtils_1 = require("./urlUtils");
|
|
13
|
+
function normalizeFrontMatterTag(tagsPath, frontMatterTag) {
|
|
14
|
+
function toTagObject(tagString) {
|
|
15
|
+
return {
|
|
16
|
+
label: tagString,
|
|
17
|
+
permalink: lodash_1.default.kebabCase(tagString),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
// TODO maybe make ensure the permalink is valid url path?
|
|
21
|
+
function normalizeTagPermalink(permalink) {
|
|
22
|
+
// note: we always apply tagsPath on purpose. For versioned docs, v1/doc.md
|
|
23
|
+
// and v2/doc.md tags with custom permalinks don't lead to the same created
|
|
24
|
+
// page. tagsPath is different for each doc version
|
|
25
|
+
return (0, urlUtils_1.normalizeUrl)([tagsPath, permalink]);
|
|
26
|
+
}
|
|
27
|
+
const tag = typeof frontMatterTag === 'string'
|
|
28
|
+
? toTagObject(frontMatterTag)
|
|
29
|
+
: frontMatterTag;
|
|
30
|
+
return {
|
|
31
|
+
label: tag.label,
|
|
32
|
+
permalink: normalizeTagPermalink(tag.permalink),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.normalizeFrontMatterTag = normalizeFrontMatterTag;
|
|
36
|
+
function normalizeFrontMatterTags(tagsPath, frontMatterTags = []) {
|
|
37
|
+
const tags = frontMatterTags.map((tag) => normalizeFrontMatterTag(tagsPath, tag));
|
|
38
|
+
return lodash_1.default.uniqBy(tags, (tag) => tag.permalink);
|
|
39
|
+
}
|
|
40
|
+
exports.normalizeFrontMatterTags = normalizeFrontMatterTags;
|
|
41
|
+
/**
|
|
42
|
+
* Permits to group docs/blogPosts by tag (provided by front matter)
|
|
43
|
+
* Note: groups are indexed by permalink, because routes must be unique in the
|
|
44
|
+
* end. Labels may vary on 2 md files but they are normalized. Docs with
|
|
45
|
+
* label='some label' and label='some-label' should end-up in the same
|
|
46
|
+
* group/page in the end. We can't create 2 routes /some-label because one would
|
|
47
|
+
* override the other
|
|
48
|
+
*/
|
|
49
|
+
function groupTaggedItems(items, getItemTags) {
|
|
50
|
+
const result = {};
|
|
51
|
+
function handleItemTag(item, tag) {
|
|
52
|
+
// Init missing tag groups
|
|
53
|
+
// TODO: it's not really clear what should be the behavior if 2 items have
|
|
54
|
+
// the same tag but the permalink is different for each
|
|
55
|
+
// For now, the first tag found wins
|
|
56
|
+
result[tag.permalink] = result[tag.permalink] ?? {
|
|
57
|
+
tag,
|
|
58
|
+
items: [],
|
|
59
|
+
};
|
|
60
|
+
// Add item to group
|
|
61
|
+
result[tag.permalink].items.push(item);
|
|
62
|
+
}
|
|
63
|
+
items.forEach((item) => {
|
|
64
|
+
getItemTags(item).forEach((tag) => {
|
|
65
|
+
handleItemTag(item, tag);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
// If user add twice the same tag to a md doc (weird but possible),
|
|
69
|
+
// we don't want the item to appear twice in the list...
|
|
70
|
+
Object.values(result).forEach((group) => {
|
|
71
|
+
group.items = lodash_1.default.uniq(group.items);
|
|
72
|
+
});
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
exports.groupTaggedItems = groupTaggedItems;
|
|
76
|
+
//# sourceMappingURL=tags.js.map
|
package/lib/tags.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tags.js","sourceRoot":"","sources":["../src/tags.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,4DAAuB;AACvB,yCAAwC;AASxC,SAAgB,uBAAuB,CACrC,QAAgB,EAChB,cAA8B;IAE9B,SAAS,WAAW,CAAC,SAAiB;QACpC,OAAO;YACL,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,gBAAC,CAAC,SAAS,CAAC,SAAS,CAAC;SAClC,CAAC;IACJ,CAAC;IAED,0DAA0D;IAC1D,SAAS,qBAAqB,CAAC,SAAiB;QAC9C,2EAA2E;QAC3E,2EAA2E;QAC3E,mDAAmD;QACnD,OAAO,IAAA,uBAAY,EAAC,CAAC,QAAQ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AI,EAAE,GAAG,CAAC,CAAC;QAC3B,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
export declare function normalizeUrl(rawUrls: string[]): string;
|
|
8
|
+
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Convert filepath to url path.
|
|
11
|
+
* Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
|
|
12
|
+
*/
|
|
13
|
+
export declare function fileToPath(file: string): string;
|
|
14
|
+
export declare function encodePath(userPath: string): string;
|
|
15
|
+
export declare function isValidPathname(str: string): boolean;
|
|
16
|
+
export declare function resolvePathname(to: string, from?: string): string;
|
|
17
|
+
export declare function addLeadingSlash(str: string): string;
|
|
18
|
+
export declare function addTrailingSlash(str: string): string;
|
|
19
|
+
export declare function removeTrailingSlash(str: string): string;
|
|
20
|
+
//# sourceMappingURL=urlUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CA8EtD;AAED,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,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAWpD;AAGD,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAEjE;AACD,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAGD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AACD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
|
package/lib/urlUtils.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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.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
|
+
function normalizeUrl(rawUrls) {
|
|
14
|
+
const urls = [...rawUrls];
|
|
15
|
+
const resultArray = [];
|
|
16
|
+
let hasStartingSlash = false;
|
|
17
|
+
let hasEndingSlash = false;
|
|
18
|
+
// If the first part is a plain protocol, we combine it with the next part.
|
|
19
|
+
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
20
|
+
const first = urls.shift();
|
|
21
|
+
if (first.startsWith('file:') && urls[0].startsWith('/')) {
|
|
22
|
+
// Force a double slash here, else we lose the information that the next
|
|
23
|
+
// segment is an absolute path
|
|
24
|
+
urls[0] = `${first}//${urls[0]}`;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
urls[0] = first + urls[0];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// There must be two or three slashes in the file protocol,
|
|
31
|
+
// two slashes in anything else.
|
|
32
|
+
const replacement = urls[0].match(/^file:\/\/\//) ? '$1:///' : '$1://';
|
|
33
|
+
urls[0] = urls[0].replace(/^(?<protocol>[^/:]+):\/*/, replacement);
|
|
34
|
+
for (let i = 0; i < urls.length; i += 1) {
|
|
35
|
+
let component = urls[i];
|
|
36
|
+
if (typeof component !== 'string') {
|
|
37
|
+
throw new TypeError(`Url must be a string. Received ${typeof component}`);
|
|
38
|
+
}
|
|
39
|
+
if (component === '') {
|
|
40
|
+
if (i === urls.length - 1 && hasEndingSlash) {
|
|
41
|
+
resultArray.push('/');
|
|
42
|
+
}
|
|
43
|
+
// eslint-disable-next-line no-continue
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (component !== '/') {
|
|
47
|
+
if (i > 0) {
|
|
48
|
+
// Removing the starting slashes for each component but the first.
|
|
49
|
+
component = component.replace(/^[/]+/,
|
|
50
|
+
// Special case where the first element of rawUrls is empty
|
|
51
|
+
// ["", "/hello"] => /hello
|
|
52
|
+
component[0] === '/' && !hasStartingSlash ? '/' : '');
|
|
53
|
+
}
|
|
54
|
+
hasEndingSlash = component[component.length - 1] === '/';
|
|
55
|
+
// Removing the ending slashes for each component but the last. For the
|
|
56
|
+
// last component we will combine multiple slashes to a single one.
|
|
57
|
+
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/');
|
|
58
|
+
}
|
|
59
|
+
hasStartingSlash = true;
|
|
60
|
+
resultArray.push(component);
|
|
61
|
+
}
|
|
62
|
+
let str = resultArray.join('/');
|
|
63
|
+
// Each input component is now separated by a single slash
|
|
64
|
+
// except the possible first plain protocol part.
|
|
65
|
+
// Remove trailing slash before parameters or hash.
|
|
66
|
+
str = str.replace(/\/(?<search>\?|&|#[^!])/g, '$1');
|
|
67
|
+
// Replace ? in parameters with &.
|
|
68
|
+
const parts = str.split('?');
|
|
69
|
+
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
70
|
+
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
71
|
+
str = str.replace(/(?<textBefore>[^:/]\/)\/+/g, '$1');
|
|
72
|
+
// Dedupe forward slashes at the beginning of the path.
|
|
73
|
+
str = str.replace(/^\/+/g, '/');
|
|
74
|
+
return str;
|
|
75
|
+
}
|
|
76
|
+
exports.normalizeUrl = normalizeUrl;
|
|
77
|
+
function getEditUrl(fileRelativePath, editUrl) {
|
|
78
|
+
return editUrl
|
|
79
|
+
? // Don't use posixPath for this: we need to force a forward slash path
|
|
80
|
+
normalizeUrl([editUrl, fileRelativePath.replace(/\\/g, '/')])
|
|
81
|
+
: undefined;
|
|
82
|
+
}
|
|
83
|
+
exports.getEditUrl = getEditUrl;
|
|
84
|
+
/**
|
|
85
|
+
* Convert filepath to url path.
|
|
86
|
+
* Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
|
|
87
|
+
*/
|
|
88
|
+
function fileToPath(file) {
|
|
89
|
+
const indexRE = /(?<dirname>^|.*\/)index\.(?:mdx?|jsx?|tsx?)$/i;
|
|
90
|
+
const extRE = /\.(?:mdx?|jsx?|tsx?)$/;
|
|
91
|
+
if (indexRE.test(file)) {
|
|
92
|
+
return file.replace(indexRE, '/$1');
|
|
93
|
+
}
|
|
94
|
+
return `/${file.replace(extRE, '').replace(/\\/g, '/')}`;
|
|
95
|
+
}
|
|
96
|
+
exports.fileToPath = fileToPath;
|
|
97
|
+
function encodePath(userPath) {
|
|
98
|
+
return userPath
|
|
99
|
+
.split('/')
|
|
100
|
+
.map((item) => encodeURIComponent(item))
|
|
101
|
+
.join('/');
|
|
102
|
+
}
|
|
103
|
+
exports.encodePath = encodePath;
|
|
104
|
+
function isValidPathname(str) {
|
|
105
|
+
if (!str.startsWith('/')) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
// weird, but is there a better way?
|
|
110
|
+
const parsedPathname = new URL(str, 'https://domain.com').pathname;
|
|
111
|
+
return parsedPathname === str || parsedPathname === encodeURI(str);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.isValidPathname = isValidPathname;
|
|
118
|
+
// resolve pathname and fail fast if resolution fails
|
|
119
|
+
function resolvePathname(to, from) {
|
|
120
|
+
return (0, resolve_pathname_1.default)(to, from);
|
|
121
|
+
}
|
|
122
|
+
exports.resolvePathname = resolvePathname;
|
|
123
|
+
function addLeadingSlash(str) {
|
|
124
|
+
return str.startsWith('/') ? str : `/${str}`;
|
|
125
|
+
}
|
|
126
|
+
exports.addLeadingSlash = addLeadingSlash;
|
|
127
|
+
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
128
|
+
function addTrailingSlash(str) {
|
|
129
|
+
return str.endsWith('/') ? str : `${str}/`;
|
|
130
|
+
}
|
|
131
|
+
exports.addTrailingSlash = addTrailingSlash;
|
|
132
|
+
function removeTrailingSlash(str) {
|
|
133
|
+
return (0, jsUtils_1.removeSuffix)(str, '/');
|
|
134
|
+
}
|
|
135
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
136
|
+
//# sourceMappingURL=urlUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mapp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CAAC;AALD,gCAKC;AAED,SAAgB,eAAe,CAAC,GAAW;IACzC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,KAAK,CAAC;KACd;IACD,IAAI;QACF,oCAAoC;QACpC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC,QAAQ,CAAC;QACnE,OAAO,cAAc,KAAK,GAAG,IAAI,cAAc,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC;KACpE;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAXD,0CAWC;AAED,qDAAqD;AACrD,SAAgB,eAAe,CAAC,EAAU,EAAE,IAAa;IACvD,OAAO,IAAA,0BAAqB,EAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACzC,CAAC;AAFD,0CAEC;AACD,SAAgB,eAAe,CAAC,GAAW;IACzC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;AAC/C,CAAC;AAFD,0CAEC;AAED,6DAA6D;AAC7D,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC7C,CAAC;AAFD,4CAEC;AACD,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,IAAA,sBAAY,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC;AAFD,kDAEC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { RuleSetRule } from 'webpack';
|
|
8
|
+
declare type AssetFolder = 'images' | 'files' | 'fonts' | 'medias';
|
|
9
|
+
declare type FileLoaderUtils = {
|
|
10
|
+
loaders: {
|
|
11
|
+
file: (options: {
|
|
12
|
+
folder: AssetFolder;
|
|
13
|
+
}) => RuleSetRule;
|
|
14
|
+
url: (options: {
|
|
15
|
+
folder: AssetFolder;
|
|
16
|
+
}) => RuleSetRule;
|
|
17
|
+
inlineMarkdownImageFileLoader: string;
|
|
18
|
+
inlineMarkdownLinkFileLoader: string;
|
|
19
|
+
};
|
|
20
|
+
rules: {
|
|
21
|
+
images: () => RuleSetRule;
|
|
22
|
+
fonts: () => RuleSetRule;
|
|
23
|
+
media: () => RuleSetRule;
|
|
24
|
+
svg: () => RuleSetRule;
|
|
25
|
+
otherAssets: () => RuleSetRule;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export declare function getFileLoaderUtils(): FileLoaderUtils;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=webpackUtils.d.ts.map
|
|
@@ -0,0 +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;AAGF,wBAAgB,kBAAkB,IAAI,eAAe,CA+GpD"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getFileLoaderUtils = void 0;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const pathUtils_1 = require("./pathUtils");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
// Inspired by https://github.com/gatsbyjs/gatsby/blob/8e6e021014da310b9cc7d02e58c9b3efe938c665/packages/gatsby/src/utils/webpack-utils.ts#L447
|
|
15
|
+
function getFileLoaderUtils() {
|
|
16
|
+
// files/images < urlLoaderLimit will be inlined as base64 strings directly in
|
|
17
|
+
// the html
|
|
18
|
+
const urlLoaderLimit = constants_1.WEBPACK_URL_LOADER_LIMIT;
|
|
19
|
+
// defines the path/pattern of the assets handled by webpack
|
|
20
|
+
const fileLoaderFileName = (folder) => `${constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME}/${folder}/[name]-[contenthash].[ext]`;
|
|
21
|
+
const loaders = {
|
|
22
|
+
file: (options) => ({
|
|
23
|
+
loader: require.resolve(`file-loader`),
|
|
24
|
+
options: {
|
|
25
|
+
name: fileLoaderFileName(options.folder),
|
|
26
|
+
},
|
|
27
|
+
}),
|
|
28
|
+
url: (options) => ({
|
|
29
|
+
loader: require.resolve('url-loader'),
|
|
30
|
+
options: {
|
|
31
|
+
limit: urlLoaderLimit,
|
|
32
|
+
name: fileLoaderFileName(options.folder),
|
|
33
|
+
fallback: require.resolve('file-loader'),
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
// TODO avoid conflicts with the ideal-image plugin
|
|
37
|
+
// TODO this may require a little breaking change for ideal-image users?
|
|
38
|
+
// Maybe with the ideal image plugin, all md images should be "ideal"?
|
|
39
|
+
// This is used to force url-loader+file-loader on markdown images
|
|
40
|
+
// https://webpack.js.org/concepts/loaders/#inline
|
|
41
|
+
inlineMarkdownImageFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('url-loader'))}?limit=${urlLoaderLimit}&name=${fileLoaderFileName('images')}&fallback=${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}!`,
|
|
42
|
+
inlineMarkdownLinkFileLoader: `!${(0, pathUtils_1.escapePath)(require.resolve('file-loader'))}?name=${fileLoaderFileName('files')}!`,
|
|
43
|
+
};
|
|
44
|
+
const rules = {
|
|
45
|
+
/**
|
|
46
|
+
* Loads image assets, inlines images via a data URI if they are below
|
|
47
|
+
* the size threshold
|
|
48
|
+
*/
|
|
49
|
+
images: () => ({
|
|
50
|
+
use: [loaders.url({ folder: 'images' })],
|
|
51
|
+
test: /\.(?:ico|jpe?g|png|gif|webp)(?:\?.*)?$/i,
|
|
52
|
+
}),
|
|
53
|
+
fonts: () => ({
|
|
54
|
+
use: [loaders.url({ folder: 'fonts' })],
|
|
55
|
+
test: /\.(?:woff2?|eot|ttf|otf)$/i,
|
|
56
|
+
}),
|
|
57
|
+
/**
|
|
58
|
+
* Loads audio and video and inlines them via a data URI if they are below
|
|
59
|
+
* the size threshold
|
|
60
|
+
*/
|
|
61
|
+
media: () => ({
|
|
62
|
+
use: [loaders.url({ folder: 'medias' })],
|
|
63
|
+
test: /\.(?:mp4|webm|ogv|wav|mp3|m4a|aac|oga|flac)$/i,
|
|
64
|
+
}),
|
|
65
|
+
svg: () => ({
|
|
66
|
+
test: /\.svg$/i,
|
|
67
|
+
oneOf: [
|
|
68
|
+
{
|
|
69
|
+
use: [
|
|
70
|
+
{
|
|
71
|
+
loader: require.resolve('@svgr/webpack'),
|
|
72
|
+
options: {
|
|
73
|
+
prettier: false,
|
|
74
|
+
svgo: true,
|
|
75
|
+
svgoConfig: {
|
|
76
|
+
plugins: [
|
|
77
|
+
{
|
|
78
|
+
name: 'preset-default',
|
|
79
|
+
params: {
|
|
80
|
+
overrides: {
|
|
81
|
+
removeTitle: false,
|
|
82
|
+
removeViewBox: false,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
titleProp: true,
|
|
89
|
+
ref: ![path_1.default],
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
// We don't want to use SVGR loader for non-React source code
|
|
94
|
+
// ie we don't want to use SVGR for CSS files...
|
|
95
|
+
issuer: {
|
|
96
|
+
and: [/\.(?:tsx?|jsx?|mdx?)$/i],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
use: [loaders.url({ folder: 'images' })],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
}),
|
|
104
|
+
otherAssets: () => ({
|
|
105
|
+
use: [loaders.file({ folder: 'files' })],
|
|
106
|
+
test: /\.(?:pdf|docx?|xlsx?|zip|rar)$/i,
|
|
107
|
+
}),
|
|
108
|
+
};
|
|
109
|
+
return { loaders, rules };
|
|
110
|
+
}
|
|
111
|
+
exports.getFileLoaderUtils = getFileLoaderUtils;
|
|
112
|
+
//# sourceMappingURL=webpackUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpackUtils.js","sourceRoot":"","sources":["../src/webpackUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wDAAwB;AACxB,2CAAuC;AACvC,2CAGqB;AAoBrB,+IAA+I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C,CAAC;YAClB,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;YACtC,IAAI,EAAE,iCAAiC;SACxC,CAAC;KACH,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,CAAC;AAC1B,CAAC;AA/GD,gDA+GC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.17",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,22 +18,32 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.17",
|
|
22
|
+
"@svgr/webpack": "^6.0.0",
|
|
23
|
+
"file-loader": "^6.2.0",
|
|
24
|
+
"fs-extra": "^10.0.1",
|
|
25
|
+
"github-slugger": "^1.4.0",
|
|
26
|
+
"globby": "^11.0.4",
|
|
26
27
|
"gray-matter": "^4.0.3",
|
|
27
|
-
"
|
|
28
|
+
"js-yaml": "^4.1.0",
|
|
29
|
+
"lodash": "^4.17.21",
|
|
30
|
+
"micromatch": "^4.0.4",
|
|
28
31
|
"resolve-pathname": "^3.0.0",
|
|
29
|
-
"
|
|
32
|
+
"shelljs": "^0.8.5",
|
|
33
|
+
"tslib": "^2.3.1",
|
|
34
|
+
"url-loader": "^4.1.1",
|
|
35
|
+
"webpack": "^5.69.1"
|
|
30
36
|
},
|
|
31
37
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
38
|
+
"node": ">=14"
|
|
33
39
|
},
|
|
34
40
|
"devDependencies": {
|
|
41
|
+
"@docusaurus/types": "2.0.0-beta.17",
|
|
35
42
|
"@types/dedent": "^0.7.0",
|
|
43
|
+
"@types/github-slugger": "^1.3.0",
|
|
44
|
+
"@types/micromatch": "^4.0.2",
|
|
45
|
+
"@types/react-dom": "^17.0.11",
|
|
36
46
|
"dedent": "^0.7.0"
|
|
37
47
|
},
|
|
38
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
|
|
39
49
|
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const NODE_MAJOR_VERSION = parseInt(
|
|
9
|
+
process.versions.node.split('.')[0],
|
|
10
|
+
10,
|
|
11
|
+
);
|
|
12
|
+
export const NODE_MINOR_VERSION = parseInt(
|
|
13
|
+
process.versions.node.split('.')[1],
|
|
14
|
+
10,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// Can be overridden with cli option --out-dir
|
|
18
|
+
export const DEFAULT_BUILD_DIR_NAME = 'build';
|
|
19
|
+
|
|
20
|
+
// Can be overridden with cli option --config
|
|
21
|
+
export const DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
|
|
22
|
+
|
|
23
|
+
export const BABEL_CONFIG_FILE_NAME =
|
|
24
|
+
process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
|
|
25
|
+
|
|
26
|
+
export const GENERATED_FILES_DIR_NAME =
|
|
27
|
+
process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
|
|
28
|
+
|
|
29
|
+
export const SRC_DIR_NAME = 'src';
|
|
30
|
+
export const STATIC_DIR_NAME = 'static';
|
|
31
|
+
export const OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
|
|
32
|
+
export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
|
33
|
+
export const DEFAULT_PORT = 3000;
|
|
34
|
+
export const DEFAULT_PLUGIN_ID = 'default';
|
|
35
|
+
|
|
36
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5493
|
|
37
|
+
export const WEBPACK_URL_LOADER_LIMIT =
|
|
38
|
+
process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import fs from 'fs-extra';
|
|
9
|
+
import Yaml from 'js-yaml';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import {findAsyncSequential} from './index';
|
|
12
|
+
import type {ContentPaths} from './markdownLinks';
|
|
13
|
+
import logger from '@docusaurus/logger';
|
|
14
|
+
|
|
15
|
+
type DataFileParams = {
|
|
16
|
+
filePath: string;
|
|
17
|
+
contentPaths: ContentPaths;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export async function getDataFilePath({
|
|
21
|
+
filePath,
|
|
22
|
+
contentPaths,
|
|
23
|
+
}: DataFileParams): Promise<string | undefined> {
|
|
24
|
+
// Loads a localized data file in priority
|
|
25
|
+
const contentPath = await findFolderContainingFile(
|
|
26
|
+
getContentPathList(contentPaths),
|
|
27
|
+
filePath,
|
|
28
|
+
);
|
|
29
|
+
if (contentPath) {
|
|
30
|
+
return path.join(contentPath, filePath);
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Looks up for a data file in the content paths, returns the normalized object.
|
|
37
|
+
* Throws when validation fails; returns undefined when file not found
|
|
38
|
+
*/
|
|
39
|
+
export async function getDataFileData<T>(
|
|
40
|
+
params: DataFileParams & {fileType: string},
|
|
41
|
+
validate: (content: unknown) => T,
|
|
42
|
+
): Promise<T | undefined> {
|
|
43
|
+
const filePath = await getDataFilePath(params);
|
|
44
|
+
if (!filePath) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
|
|
49
|
+
const unsafeContent = Yaml.load(contentString);
|
|
50
|
+
return validate(unsafeContent);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
// TODO replace later by error cause, see https://v8.dev/features/error-cause
|
|
53
|
+
logger.error`The ${params.fileType} file at path=${filePath} looks invalid.`;
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Order matters: we look in priority in localized folder
|
|
59
|
+
export function getContentPathList(contentPaths: ContentPaths): string[] {
|
|
60
|
+
return [contentPaths.contentPathLocalized, contentPaths.contentPath];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// return the first folder path in which the file exists in
|
|
64
|
+
export async function findFolderContainingFile(
|
|
65
|
+
folderPaths: string[],
|
|
66
|
+
relativeFilePath: string,
|
|
67
|
+
): Promise<string | undefined> {
|
|
68
|
+
return findAsyncSequential(folderPaths, (folderPath) =>
|
|
69
|
+
fs.pathExists(path.join(folderPath, relativeFilePath)),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export async function getFolderContainingFile(
|
|
74
|
+
folderPaths: string[],
|
|
75
|
+
relativeFilePath: string,
|
|
76
|
+
): Promise<string> {
|
|
77
|
+
const maybeFolderPath = await findFolderContainingFile(
|
|
78
|
+
folderPaths,
|
|
79
|
+
relativeFilePath,
|
|
80
|
+
);
|
|
81
|
+
// should never happen, as the source was read from the FS anyway...
|
|
82
|
+
if (!maybeFolderPath) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join(
|
|
85
|
+
'\n- ',
|
|
86
|
+
)}]`,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return maybeFolderPath;
|
|
90
|
+
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module 'resolve-pathname' {
|
|
9
|
+
export default function resolvePathname(to: string, from?: string): string;
|
|
10
|
+
}
|