@docusaurus/utils 2.0.0-beta.ff31de0ff → 2.0.1

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.
Files changed (111) hide show
  1. package/README.md +1 -1
  2. package/lib/constants.d.ts +73 -0
  3. package/lib/constants.d.ts.map +1 -0
  4. package/lib/constants.js +78 -0
  5. package/lib/constants.js.map +1 -0
  6. package/lib/dataFileUtils.d.ts +60 -0
  7. package/lib/dataFileUtils.d.ts.map +1 -0
  8. package/lib/dataFileUtils.js +91 -0
  9. package/lib/dataFileUtils.js.map +1 -0
  10. package/lib/emitUtils.d.ts +32 -0
  11. package/lib/emitUtils.d.ts.map +1 -0
  12. package/lib/emitUtils.js +80 -0
  13. package/lib/emitUtils.js.map +1 -0
  14. package/lib/gitUtils.d.ts +66 -0
  15. package/lib/gitUtils.d.ts.map +1 -0
  16. package/lib/gitUtils.js +63 -0
  17. package/lib/gitUtils.js.map +1 -0
  18. package/lib/globUtils.d.ts +40 -0
  19. package/lib/globUtils.d.ts.map +1 -0
  20. package/lib/globUtils.js +71 -0
  21. package/lib/globUtils.js.map +1 -0
  22. package/lib/hashUtils.d.ts +17 -0
  23. package/lib/hashUtils.d.ts.map +1 -0
  24. package/lib/hashUtils.js +42 -0
  25. package/lib/hashUtils.js.map +1 -0
  26. package/lib/i18nUtils.d.ts +53 -0
  27. package/lib/i18nUtils.d.ts.map +1 -0
  28. package/lib/i18nUtils.js +70 -0
  29. package/lib/i18nUtils.js.map +1 -0
  30. package/lib/index.d.ts +17 -82
  31. package/lib/index.d.ts.map +1 -0
  32. package/lib/index.js +91 -411
  33. package/lib/index.js.map +1 -0
  34. package/lib/jsUtils.d.ts +28 -0
  35. package/lib/jsUtils.d.ts.map +1 -0
  36. package/lib/jsUtils.js +57 -0
  37. package/lib/jsUtils.js.map +1 -0
  38. package/lib/markdownLinks.d.ts +49 -5
  39. package/lib/markdownLinks.d.ts.map +1 -0
  40. package/lib/markdownLinks.js +57 -13
  41. package/lib/markdownLinks.js.map +1 -0
  42. package/lib/markdownUtils.d.ts +112 -0
  43. package/lib/markdownUtils.d.ts.map +1 -0
  44. package/lib/markdownUtils.js +271 -0
  45. package/lib/markdownUtils.js.map +1 -0
  46. package/lib/pathUtils.d.ts +52 -0
  47. package/lib/pathUtils.d.ts.map +1 -0
  48. package/lib/pathUtils.js +115 -0
  49. package/lib/pathUtils.js.map +1 -0
  50. package/lib/shellUtils.d.ts +8 -0
  51. package/lib/shellUtils.d.ts.map +1 -0
  52. package/lib/shellUtils.js +21 -0
  53. package/lib/shellUtils.js.map +1 -0
  54. package/lib/slugger.d.ts +24 -0
  55. package/lib/slugger.d.ts.map +1 -0
  56. package/lib/slugger.js +23 -0
  57. package/lib/slugger.js.map +1 -0
  58. package/lib/tags.d.ts +59 -0
  59. package/lib/tags.d.ts.map +1 -0
  60. package/lib/tags.js +91 -0
  61. package/lib/tags.js.map +1 -0
  62. package/lib/urlUtils.d.ts +66 -0
  63. package/lib/urlUtils.d.ts.map +1 -0
  64. package/lib/urlUtils.js +207 -0
  65. package/lib/urlUtils.js.map +1 -0
  66. package/lib/webpackUtils.d.ts +35 -0
  67. package/lib/webpackUtils.d.ts.map +1 -0
  68. package/lib/webpackUtils.js +115 -0
  69. package/lib/webpackUtils.js.map +1 -0
  70. package/package.json +28 -10
  71. package/src/constants.ts +98 -0
  72. package/src/dataFileUtils.ts +122 -0
  73. package/src/deps.d.ts +10 -0
  74. package/src/emitUtils.ts +99 -0
  75. package/src/gitUtils.ts +146 -0
  76. package/src/globUtils.ts +85 -0
  77. package/src/hashUtils.ts +38 -0
  78. package/src/i18nUtils.ts +114 -0
  79. package/src/index.ts +98 -521
  80. package/src/jsUtils.ts +59 -0
  81. package/src/markdownLinks.ts +101 -30
  82. package/src/markdownUtils.ts +357 -0
  83. package/src/pathUtils.ts +123 -0
  84. package/src/shellUtils.ts +18 -0
  85. package/src/slugger.ts +36 -0
  86. package/src/tags.ts +130 -0
  87. package/src/urlUtils.ts +234 -0
  88. package/src/webpackUtils.ts +153 -0
  89. package/lib/.tsbuildinfo +0 -3928
  90. package/lib/codeTranslationsUtils.d.ts +0 -11
  91. package/lib/codeTranslationsUtils.js +0 -50
  92. package/lib/escapePath.d.ts +0 -17
  93. package/lib/escapePath.js +0 -25
  94. package/lib/markdownParser.d.ts +0 -28
  95. package/lib/markdownParser.js +0 -132
  96. package/lib/posixPath.d.ts +0 -14
  97. package/lib/posixPath.js +0 -28
  98. package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
  99. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
  100. package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
  101. package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
  102. package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
  103. package/src/__tests__/escapePath.test.ts +0 -25
  104. package/src/__tests__/index.test.ts +0 -681
  105. package/src/__tests__/markdownParser.test.ts +0 -772
  106. package/src/__tests__/posixPath.test.ts +0 -25
  107. package/src/codeTranslationsUtils.ts +0 -56
  108. package/src/escapePath.ts +0 -23
  109. package/src/markdownParser.ts +0 -177
  110. package/src/posixPath.ts +0 -27
  111. package/tsconfig.json +0 -9
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # `@docusaurus/utils`
2
2
 
3
- Node validation utility functions for Docusaurus packages.
3
+ Node utility functions for Docusaurus packages.
@@ -0,0 +1,73 @@
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
+ /** Node major version, directly read from env. */
8
+ export declare const NODE_MAJOR_VERSION: number;
9
+ /** Node minor version, directly read from env. */
10
+ export declare const NODE_MINOR_VERSION: number;
11
+ /** Docusaurus core version. */
12
+ export declare const DOCUSAURUS_VERSION: string;
13
+ /**
14
+ * Can be overridden with cli option `--out-dir`. Code should generally use
15
+ * `context.outDir` instead (which is always absolute and localized).
16
+ */
17
+ export declare const DEFAULT_BUILD_DIR_NAME = "build";
18
+ /**
19
+ * Can be overridden with cli option `--config`. Code should generally use
20
+ * `context.siteConfigPath` instead (which is always absolute).
21
+ *
22
+ * This does not have extensions, so that we can substitute different ones
23
+ * when resolving the path.
24
+ */
25
+ export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config";
26
+ /** Can be absolute or relative to site directory. */
27
+ export declare const BABEL_CONFIG_FILE_NAME: string;
28
+ /**
29
+ * Can be absolute or relative to site directory. Code should generally use
30
+ * `context.generatedFilesDir` instead (which is always absolute).
31
+ */
32
+ export declare const GENERATED_FILES_DIR_NAME: string;
33
+ /**
34
+ * We would assume all of the site's JS code lives in here and not outside.
35
+ * Relative to the site directory.
36
+ */
37
+ export declare const SRC_DIR_NAME = "src";
38
+ /**
39
+ * Can be overridden with `config.staticDirectories`. Code should use
40
+ * `context.siteConfig.staticDirectories` instead (which is always absolute).
41
+ */
42
+ export declare const DEFAULT_STATIC_DIR_NAME = "static";
43
+ /**
44
+ * Files here are handled by webpack, hashed (can be cached aggressively).
45
+ * Relative to the build output folder.
46
+ */
47
+ export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
48
+ /**
49
+ * Components in this directory will receive the `@theme` alias and be able to
50
+ * shadow default theme components.
51
+ */
52
+ export declare const THEME_PATH: string;
53
+ /**
54
+ * All translation-related data live here, relative to site directory. Content
55
+ * will be namespaced by locale.
56
+ */
57
+ export declare const DEFAULT_I18N_DIR_NAME = "i18n";
58
+ /**
59
+ * Translations for React code.
60
+ */
61
+ export declare const CODE_TRANSLATIONS_FILE_NAME = "code.json";
62
+ /** Dev server opens on this port by default. */
63
+ export declare const DEFAULT_PORT = 3000;
64
+ /** Default plugin ID. */
65
+ export declare const DEFAULT_PLUGIN_ID = "default";
66
+ /**
67
+ * Allow overriding the limit after which the url loader will no longer inline
68
+ * assets.
69
+ *
70
+ * @see https://github.com/facebook/docusaurus/issues/5493
71
+ */
72
+ export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
73
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,kDAAkD;AAClD,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAEF,+BAA+B;AAC/B,eAAO,MAAM,kBAAkB,QAE4B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAQ,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD;;;GAGG;AACH,eAAO,MAAM,6BAA6B,WAAW,CAAC;AAEtD;;;GAGG;AACH,eAAO,MAAM,UAAU,QAA0B,CAAC;AAElD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,SAAS,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,gDAAgD;AAChD,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,yBAAyB;AACzB,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,iBACU,CAAC"}
@@ -0,0 +1,78 @@
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.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
+ /** Node major version, directly read from env. */
11
+ exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
12
+ /** Node minor version, directly read from env. */
13
+ exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
14
+ /** Docusaurus core version. */
15
+ exports.DOCUSAURUS_VERSION =
16
+ // eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
17
+ require('../package.json').version;
18
+ /**
19
+ * Can be overridden with cli option `--out-dir`. Code should generally use
20
+ * `context.outDir` instead (which is always absolute and localized).
21
+ */
22
+ exports.DEFAULT_BUILD_DIR_NAME = 'build';
23
+ /**
24
+ * Can be overridden with cli option `--config`. Code should generally use
25
+ * `context.siteConfigPath` instead (which is always absolute).
26
+ *
27
+ * This does not have extensions, so that we can substitute different ones
28
+ * when resolving the path.
29
+ */
30
+ exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config';
31
+ /** Can be absolute or relative to site directory. */
32
+ exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
33
+ /**
34
+ * Can be absolute or relative to site directory. Code should generally use
35
+ * `context.generatedFilesDir` instead (which is always absolute).
36
+ */
37
+ exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
38
+ /**
39
+ * We would assume all of the site's JS code lives in here and not outside.
40
+ * Relative to the site directory.
41
+ */
42
+ exports.SRC_DIR_NAME = 'src';
43
+ /**
44
+ * Can be overridden with `config.staticDirectories`. Code should use
45
+ * `context.siteConfig.staticDirectories` instead (which is always absolute).
46
+ */
47
+ exports.DEFAULT_STATIC_DIR_NAME = 'static';
48
+ /**
49
+ * Files here are handled by webpack, hashed (can be cached aggressively).
50
+ * Relative to the build output folder.
51
+ */
52
+ exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
53
+ /**
54
+ * Components in this directory will receive the `@theme` alias and be able to
55
+ * shadow default theme components.
56
+ */
57
+ exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
58
+ /**
59
+ * All translation-related data live here, relative to site directory. Content
60
+ * will be namespaced by locale.
61
+ */
62
+ exports.DEFAULT_I18N_DIR_NAME = 'i18n';
63
+ /**
64
+ * Translations for React code.
65
+ */
66
+ exports.CODE_TRANSLATIONS_FILE_NAME = 'code.json';
67
+ /** Dev server opens on this port by default. */
68
+ exports.DEFAULT_PORT = 3000;
69
+ /** Default plugin ID. */
70
+ exports.DEFAULT_PLUGIN_ID = 'default';
71
+ /**
72
+ * Allow overriding the limit after which the url loader will no longer inline
73
+ * assets.
74
+ *
75
+ * @see https://github.com/facebook/docusaurus/issues/5493
76
+ */
77
+ exports.WEBPACK_URL_LOADER_LIMIT = process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
78
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,kDAAkD;AACrC,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACpC,EAAE,CACH,CAAC;AACF,kDAAkD;AACrC,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,EACpC,EAAE,CACH,CAAC;AAEF,+BAA+B;AAClB,QAAA,kBAAkB;AAC7B,8EAA8E;AAC7E,OAAO,CAAC,iBAAiB,CAAuB,CAAC,OAAO,CAAC;AAE5D;;;GAGG;AACU,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C;;;;;;GAMG;AACU,QAAA,wBAAwB,GAAG,mBAAmB,CAAC;AAE5D,qDAAqD;AACxC,QAAA,sBAAsB,GACjC,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,iBAAiB,CAAC;AAErE;;;GAGG;AACU,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,aAAa,CAAC;AAEnE;;;GAGG;AACU,QAAA,YAAY,GAAG,KAAK,CAAC;AAElC;;;GAGG;AACU,QAAA,uBAAuB,GAAG,QAAQ,CAAC;AAEhD;;;GAGG;AACU,QAAA,6BAA6B,GAAG,QAAQ,CAAC;AAEtD;;;GAGG;AACU,QAAA,UAAU,GAAG,GAAG,oBAAY,QAAQ,CAAC;AAElD;;;GAGG;AACU,QAAA,qBAAqB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACU,QAAA,2BAA2B,GAAG,WAAW,CAAC;AAEvD,gDAAgD;AACnC,QAAA,YAAY,GAAG,IAAI,CAAC;AAEjC,yBAAyB;AACZ,QAAA,iBAAiB,GAAG,SAAS,CAAC;AAE3C;;;;;GAKG;AACU,QAAA,wBAAwB,GACnC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,KAAK,CAAC"}
@@ -0,0 +1,60 @@
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 { ContentPaths } from './markdownLinks';
8
+ declare type DataFileParams = {
9
+ /** Path to the potential data file, relative to `contentPaths` */
10
+ filePath: string;
11
+ /**
12
+ * Includes the base path and localized path, both of which are eligible for
13
+ * sourcing data files. Both paths should be absolute.
14
+ */
15
+ contentPaths: ContentPaths;
16
+ };
17
+ /**
18
+ * Looks for a data file in the potential content paths; loads a localized data
19
+ * file in priority.
20
+ *
21
+ * @returns An absolute path to the data file, or `undefined` if there isn't one.
22
+ */
23
+ export declare function getDataFilePath({ filePath, contentPaths, }: DataFileParams): Promise<string | undefined>;
24
+ /**
25
+ * Looks up for a data file in the content paths, returns the object validated
26
+ * and normalized according to the `validate` callback.
27
+ *
28
+ * @returns `undefined` when file not found
29
+ * @throws Throws when validation fails, displaying a helpful context message.
30
+ */
31
+ export declare function getDataFileData<T>(params: DataFileParams & {
32
+ /** Used for the "The X file looks invalid" message. */
33
+ fileType: string;
34
+ }, validate: (content: unknown) => T): Promise<T | undefined>;
35
+ /**
36
+ * Takes the `contentPaths` data structure and returns an ordered path list
37
+ * indicating their priorities. For all data, we look in the localized folder
38
+ * in priority.
39
+ */
40
+ export declare function getContentPathList(contentPaths: ContentPaths): string[];
41
+ /**
42
+ * @param folderPaths a list of absolute paths.
43
+ * @param relativeFilePath file path relative to each `folderPaths`.
44
+ * @returns the first folder path in which the file exists, or `undefined` if
45
+ * none is found.
46
+ */
47
+ export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
48
+ /**
49
+ * Fail-fast alternative to `findFolderContainingFile`.
50
+ *
51
+ * @param folderPaths a list of absolute paths.
52
+ * @param relativeFilePath file path relative to each `folderPaths`.
53
+ * @returns the first folder path in which the file exists.
54
+ * @throws Throws if no file can be found. You should use this method only when
55
+ * you actually know the file exists (e.g. when the `relativeFilePath` is read
56
+ * with a glob and you are just trying to localize it)
57
+ */
58
+ export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
59
+ export {};
60
+ //# sourceMappingURL=dataFileUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataFileUtils.d.ts","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAElD,aAAK,cAAc,GAAG;IACpB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAS9C;AAED;;;;;;GAMG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,MAAM,EAAE,cAAc,GAAG;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;CAClB,EACD,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,GAChC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAaxB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,EAAE,CAEvE;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAI7B;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EAAE,EACrB,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,MAAM,CAAC,CAYjB"}
@@ -0,0 +1,91 @@
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.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
15
+ const index_1 = require("./index");
16
+ /**
17
+ * Looks for a data file in the potential content paths; loads a localized data
18
+ * file in priority.
19
+ *
20
+ * @returns An absolute path to the data file, or `undefined` if there isn't one.
21
+ */
22
+ async function getDataFilePath({ filePath, contentPaths, }) {
23
+ const contentPath = await findFolderContainingFile(getContentPathList(contentPaths), filePath);
24
+ if (contentPath) {
25
+ return path_1.default.resolve(contentPath, filePath);
26
+ }
27
+ return undefined;
28
+ }
29
+ exports.getDataFilePath = getDataFilePath;
30
+ /**
31
+ * Looks up for a data file in the content paths, returns the object validated
32
+ * and normalized according to the `validate` callback.
33
+ *
34
+ * @returns `undefined` when file not found
35
+ * @throws Throws when validation fails, displaying a helpful context message.
36
+ */
37
+ async function getDataFileData(params, validate) {
38
+ const filePath = await getDataFilePath(params);
39
+ if (!filePath) {
40
+ return undefined;
41
+ }
42
+ try {
43
+ const contentString = await fs_extra_1.default.readFile(filePath, { encoding: 'utf8' });
44
+ const unsafeContent = js_yaml_1.default.load(contentString);
45
+ return validate(unsafeContent);
46
+ }
47
+ catch (err) {
48
+ logger_1.default.error `The ${params.fileType} file at path=${filePath} looks invalid.`;
49
+ throw err;
50
+ }
51
+ }
52
+ exports.getDataFileData = getDataFileData;
53
+ /**
54
+ * Takes the `contentPaths` data structure and returns an ordered path list
55
+ * indicating their priorities. For all data, we look in the localized folder
56
+ * in priority.
57
+ */
58
+ function getContentPathList(contentPaths) {
59
+ return [contentPaths.contentPathLocalized, contentPaths.contentPath];
60
+ }
61
+ exports.getContentPathList = getContentPathList;
62
+ /**
63
+ * @param folderPaths a list of absolute paths.
64
+ * @param relativeFilePath file path relative to each `folderPaths`.
65
+ * @returns the first folder path in which the file exists, or `undefined` if
66
+ * none is found.
67
+ */
68
+ async function findFolderContainingFile(folderPaths, relativeFilePath) {
69
+ return (0, index_1.findAsyncSequential)(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
70
+ }
71
+ exports.findFolderContainingFile = findFolderContainingFile;
72
+ /**
73
+ * Fail-fast alternative to `findFolderContainingFile`.
74
+ *
75
+ * @param folderPaths a list of absolute paths.
76
+ * @param relativeFilePath file path relative to each `folderPaths`.
77
+ * @returns the first folder path in which the file exists.
78
+ * @throws Throws if no file can be found. You should use this method only when
79
+ * you actually know the file exists (e.g. when the `relativeFilePath` is read
80
+ * with a glob and you are just trying to localize it)
81
+ */
82
+ async function getFolderContainingFile(folderPaths, relativeFilePath) {
83
+ const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
84
+ if (!maybeFolderPath) {
85
+ throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:
86
+ - ${folderPaths.join('\n- ')}`);
87
+ }
88
+ return maybeFolderPath;
89
+ }
90
+ exports.getFolderContainingFile = getFolderContainingFile;
91
+ //# sourceMappingURL=dataFileUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataFileUtils.js","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wDAAwB;AACxB,wEAAwC;AACxC,8DAA2B;AAC3B,mCAA4C;AAa5C;;;;;GAKG;AACI,KAAK,UAAU,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACG;IACf,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAChD,kBAAkB,CAAC,YAAY,CAAC,EAChC,QAAQ,CACT,CAAC;IACF,IAAI,WAAW,EAAE;QACf,OAAO,cAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;KAC5C;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAZD,0CAYC;AAED;;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AAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACzB,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAfD,0DAeC"}
@@ -0,0 +1,32 @@
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
+ /// <reference types="node" />
8
+ /**
9
+ * Outputs a file to the generated files directory. Only writes files if content
10
+ * differs from cache (for hot reload performance).
11
+ *
12
+ * @param generatedFilesDir Absolute path.
13
+ * @param file Path relative to `generatedFilesDir`. File will always be
14
+ * outputted; no need to ensure directory exists.
15
+ * @param content String content to write.
16
+ * @param skipCache If `true` (defaults as `true` for production), file is
17
+ * force-rewritten, skipping cache.
18
+ */
19
+ export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
20
+ /**
21
+ * @param permalink The URL that the HTML file corresponds to, without base URL
22
+ * @param outDir Full path to the output directory
23
+ * @param trailingSlash The site config option. If provided, only one path will
24
+ * be read.
25
+ * @returns This returns a buffer, which you have to decode string yourself if
26
+ * needed. (Not always necessary since the output isn't for human consumption
27
+ * anyways, and most HTML manipulation libs accept buffers)
28
+ * @throws Throws when the HTML file is not found at any of the potential paths.
29
+ * This should never happen as it would lead to a 404.
30
+ */
31
+ export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
32
+ //# sourceMappingURL=emitUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitUtils.d.ts","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AASH;;;;;;;;;;GAUG;AACH,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CAgCf;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,MAAM,CAAC,CAmBjB"}
@@ -0,0 +1,80 @@
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.readOutputHTMLFile = exports.generate = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const crypto_1 = require("crypto");
14
+ const jsUtils_1 = require("./jsUtils");
15
+ const fileHash = new Map();
16
+ /**
17
+ * Outputs a file to the generated files directory. Only writes files if content
18
+ * differs from cache (for hot reload performance).
19
+ *
20
+ * @param generatedFilesDir Absolute path.
21
+ * @param file Path relative to `generatedFilesDir`. File will always be
22
+ * outputted; no need to ensure directory exists.
23
+ * @param content String content to write.
24
+ * @param skipCache If `true` (defaults as `true` for production), file is
25
+ * force-rewritten, skipping cache.
26
+ */
27
+ async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
28
+ const filepath = path_1.default.resolve(generatedFilesDir, file);
29
+ if (skipCache) {
30
+ await fs_extra_1.default.outputFile(filepath, content);
31
+ // Cache still needs to be reset, otherwise, writing "A", "B", and "A" where
32
+ // "B" skips cache will cause the last "A" not be able to overwrite as the
33
+ // first "A" remains in cache. But if the file never existed in cache, no
34
+ // need to register it.
35
+ if (fileHash.get(filepath)) {
36
+ fileHash.set(filepath, (0, crypto_1.createHash)('md5').update(content).digest('hex'));
37
+ }
38
+ return;
39
+ }
40
+ let lastHash = fileHash.get(filepath);
41
+ // If file already exists but it's not in runtime cache yet, we try to
42
+ // calculate the content hash and then compare. This is to avoid unnecessary
43
+ // overwriting and we can reuse old file.
44
+ if (!lastHash && (await fs_extra_1.default.pathExists(filepath))) {
45
+ const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
46
+ lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
47
+ fileHash.set(filepath, lastHash);
48
+ }
49
+ const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
50
+ if (lastHash !== currentHash) {
51
+ await fs_extra_1.default.outputFile(filepath, content);
52
+ fileHash.set(filepath, currentHash);
53
+ }
54
+ }
55
+ exports.generate = generate;
56
+ /**
57
+ * @param permalink The URL that the HTML file corresponds to, without base URL
58
+ * @param outDir Full path to the output directory
59
+ * @param trailingSlash The site config option. If provided, only one path will
60
+ * be read.
61
+ * @returns This returns a buffer, which you have to decode string yourself if
62
+ * needed. (Not always necessary since the output isn't for human consumption
63
+ * anyways, and most HTML manipulation libs accept buffers)
64
+ * @throws Throws when the HTML file is not found at any of the potential paths.
65
+ * This should never happen as it would lead to a 404.
66
+ */
67
+ async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
68
+ const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
69
+ const withoutTrailingSlashPath = path_1.default.join(outDir, `${permalink.replace(/\/$/, '')}.html`);
70
+ const HTMLPath = await (0, jsUtils_1.findAsyncSequential)([
71
+ trailingSlash !== false && withTrailingSlashPath,
72
+ trailingSlash !== true && withoutTrailingSlashPath,
73
+ ].filter((p) => Boolean(p)), fs_extra_1.default.pathExists);
74
+ if (!HTMLPath) {
75
+ throw new Error(`Expected output HTML file to be found at ${withTrailingSlashPath}.`);
76
+ }
77
+ return fs_extra_1.default.readFile(HTMLPath);
78
+ }
79
+ exports.readOutputHTMLFile = readOutputHTMLFile;
80
+ //# sourceMappingURL=emitUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emitUtils.js","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,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AAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEpE,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC5B,MAAM,kBAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACvC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;KACrC;AACH,CAAC;AArCD,4BAqCC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,kBAAkB,CACtC,SAAiB,EACjB,MAAc,EACd,aAAkC;IAElC,MAAM,qBAAqB,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;IACzE,MAAM,wBAAwB,GAAG,cAAI,CAAC,IAAI,CACxC,MAAM,EACN,GAAG,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CACvC,CAAC;IACF,MAAM,QAAQ,GAAG,MAAM,IAAA,6BAAmB,EACxC;QACE,aAAa,KAAK,KAAK,IAAI,qBAAqB;QAChD,aAAa,KAAK,IAAI,IAAI,wBAAwB;KACnD,CAAC,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EACxC,kBAAE,CAAC,UAAU,CACd,CAAC;IACF,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,IAAI,KAAK,CACb,4CAA4C,qBAAqB,GAAG,CACrE,CAAC;KACH;IACD,OAAO,kBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAvBD,gDAuBC"}
@@ -0,0 +1,66 @@
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
+ /** Custom error thrown when git is not found in `PATH`. */
8
+ export declare class GitNotFoundError extends Error {
9
+ }
10
+ /** Custom error thrown when the current file is not tracked by git. */
11
+ export declare class FileNotTrackedError extends Error {
12
+ }
13
+ /**
14
+ * Fetches the git history of a file and returns a relevant commit date.
15
+ * It gets the commit date instead of author date so that amended commits
16
+ * can have their dates updated.
17
+ *
18
+ * @throws {@link GitNotFoundError} If git is not found in `PATH`.
19
+ * @throws {@link FileNotTrackedError} If the current file is not tracked by git.
20
+ * @throws Also throws when `git log` exited with non-zero, or when it outputs
21
+ * unexpected text.
22
+ */
23
+ export declare function getFileCommitDate(
24
+ /** Absolute path to the file. */
25
+ file: string, args: {
26
+ /**
27
+ * `"oldest"` is the commit that added the file, following renames;
28
+ * `"newest"` is the last commit that edited the file.
29
+ */
30
+ age?: 'oldest' | 'newest';
31
+ /** Use `includeAuthor: true` to get the author information as well. */
32
+ includeAuthor?: false;
33
+ }): {
34
+ /** Relevant commit date. */
35
+ date: Date;
36
+ /** Timestamp in **seconds**, as returned from git. */
37
+ timestamp: number;
38
+ };
39
+ /**
40
+ * Fetches the git history of a file and returns a relevant commit date.
41
+ * It gets the commit date instead of author date so that amended commits
42
+ * can have their dates updated.
43
+ *
44
+ * @throws {@link GitNotFoundError} If git is not found in `PATH`.
45
+ * @throws {@link FileNotTrackedError} If the current file is not tracked by git.
46
+ * @throws Also throws when `git log` exited with non-zero, or when it outputs
47
+ * unexpected text.
48
+ */
49
+ export declare function getFileCommitDate(
50
+ /** Absolute path to the file. */
51
+ file: string, args: {
52
+ /**
53
+ * `"oldest"` is the commit that added the file, following renames;
54
+ * `"newest"` is the last commit that edited the file.
55
+ */
56
+ age?: 'oldest' | 'newest';
57
+ includeAuthor: true;
58
+ }): {
59
+ /** Relevant commit date. */
60
+ date: Date;
61
+ /** Timestamp in **seconds**, as returned from git. */
62
+ timestamp: number;
63
+ /** The author's name, as returned from git. */
64
+ author: string;
65
+ };
66
+ //# sourceMappingURL=gitUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,2DAA2D;AAC3D,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,uEAAuE;AACvE,qBAAa,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;AAC/B,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;IACD,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AACF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB;AAC/B,iCAAiC;AACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE;IACJ;;;OAGG;IACH,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC1B,aAAa,EAAE,IAAI,CAAC;CACrB,GACA;IACD,4BAA4B;IAC5B,IAAI,EAAE,IAAI,CAAC;IACX,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1,63 @@
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.getFileCommitDate = exports.FileNotTrackedError = exports.GitNotFoundError = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
13
+ /** Custom error thrown when git is not found in `PATH`. */
14
+ class GitNotFoundError extends Error {
15
+ }
16
+ exports.GitNotFoundError = GitNotFoundError;
17
+ /** Custom error thrown when the current file is not tracked by git. */
18
+ class FileNotTrackedError extends Error {
19
+ }
20
+ exports.FileNotTrackedError = FileNotTrackedError;
21
+ function getFileCommitDate(file, { age = 'oldest', includeAuthor = false, }) {
22
+ if (!shelljs_1.default.which('git')) {
23
+ throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
24
+ }
25
+ if (!shelljs_1.default.test('-f', file)) {
26
+ throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
27
+ }
28
+ const args = [
29
+ `--format=%ct${includeAuthor ? ',%an' : ''}`,
30
+ '--max-count=1',
31
+ age === 'oldest' ? '--follow --diff-filter=A' : undefined,
32
+ ]
33
+ .filter(Boolean)
34
+ .join(' ');
35
+ const result = shelljs_1.default.exec(`git log ${args} -- "${path_1.default.basename(file)}"`, {
36
+ // Setting cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
37
+ cwd: path_1.default.dirname(file),
38
+ silent: true,
39
+ });
40
+ if (result.code !== 0) {
41
+ throw new Error(`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`);
42
+ }
43
+ let regex = /^(?<timestamp>\d+)$/;
44
+ if (includeAuthor) {
45
+ regex = /^(?<timestamp>\d+),(?<author>.+)$/;
46
+ }
47
+ const output = result.stdout.trim();
48
+ if (!output) {
49
+ throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
50
+ }
51
+ const match = output.match(regex);
52
+ if (!match) {
53
+ throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
54
+ }
55
+ const timestamp = Number(match.groups.timestamp);
56
+ const date = new Date(timestamp * 1000);
57
+ if (includeAuthor) {
58
+ return { date, timestamp, author: match.groups.author };
59
+ }
60
+ return { date, timestamp };
61
+ }
62
+ exports.getFileCommitDate = getFileCommitDate;
63
+ //# sourceMappingURL=gitUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git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MAAM,EAAE,CACxG,CAAC;KACH;IACD,IAAI,KAAK,GAAG,qBAAqB,CAAC;IAClC,IAAI,aAAa,EAAE;QACjB,KAAK,GAAG,mCAAmC,CAAC;KAC7C;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAEpC,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,mBAAmB,CAC3B,gDAAgD,IAAI,2CAA2C,CAChG,CAAC;KACH;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAElC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,KAAK,CACb,gDAAgD,IAAI,6BAA6B,MAAM,EAAE,CAC1F,CAAC;KACH;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,KAAK,CAAC,MAAO,CAAC,SAAS,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IAExC,IAAI,aAAa,EAAE;QACjB,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAO,CAAC,MAAO,EAAC,CAAC;KACzD;IACD,OAAO,EAAC,IAAI,EAAE,SAAS,EAAC,CAAC;AAC3B,CAAC;AAxED,8CAwEC"}
@@ -0,0 +1,40 @@
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
+ /** A re-export of the globby instance. */
8
+ export { default as Globby } from 'globby';
9
+ /**
10
+ * The default glob patterns we ignore when sourcing content.
11
+ * - Ignore files and folders starting with `_` recursively
12
+ * - Ignore tests
13
+ */
14
+ export declare const GlobExcludeDefault: string[];
15
+ declare type Matcher = (str: string) => boolean;
16
+ /**
17
+ * A very thin wrapper around `Micromatch.makeRe`.
18
+ *
19
+ * @see {@link createAbsoluteFilePathMatcher}
20
+ * @param patterns A list of glob patterns. If the list is empty, it defaults to
21
+ * matching none.
22
+ * @returns A matcher handle that tells if a file path is matched by any of the
23
+ * patterns.
24
+ */
25
+ export declare function createMatcher(patterns: string[]): Matcher;
26
+ /**
27
+ * We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
28
+ * should only be matched within a subfolder. This function would:
29
+ * - Match `/user/sebastien/website/docs/_partials/xyz.md`
30
+ * - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
31
+ *
32
+ * @param patterns A list of glob patterns.
33
+ * @param rootFolders A list of root folders to resolve the glob from.
34
+ * @returns A matcher handle that tells if a file path is matched by any of the
35
+ * patterns, resolved from the first root folder that contains the path.
36
+ * @throws Throws when the returned matcher receives a path that doesn't belong
37
+ * to any of the `rootFolders`.
38
+ */
39
+ export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
40
+ //# sourceMappingURL=globUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globUtils.d.ts","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,0CAA0C;AAC1C,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,UAK9B,CAAC;AAEF,aAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CASzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}