@docusaurus/utils 2.0.0-beta.17 → 2.0.0-beta.18

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 (86) hide show
  1. package/lib/constants.d.ts +49 -1
  2. package/lib/constants.d.ts.map +1 -1
  3. package/lib/constants.js +53 -8
  4. package/lib/constants.js.map +1 -1
  5. package/lib/dataFileUtils.d.ts +38 -2
  6. package/lib/dataFileUtils.d.ts.map +1 -1
  7. package/lib/dataFileUtils.js +34 -8
  8. package/lib/dataFileUtils.js.map +1 -1
  9. package/lib/emitUtils.d.ts +12 -0
  10. package/lib/emitUtils.d.ts.map +1 -1
  11. package/lib/emitUtils.js +24 -7
  12. package/lib/emitUtils.js.map +1 -1
  13. package/lib/gitUtils.d.ts +54 -5
  14. package/lib/gitUtils.d.ts.map +1 -1
  15. package/lib/gitUtils.js +14 -11
  16. package/lib/gitUtils.js.map +1 -1
  17. package/lib/globUtils.d.ts +27 -0
  18. package/lib/globUtils.d.ts.map +1 -1
  19. package/lib/globUtils.js +28 -10
  20. package/lib/globUtils.js.map +1 -1
  21. package/lib/hashUtils.d.ts +5 -4
  22. package/lib/hashUtils.d.ts.map +1 -1
  23. package/lib/hashUtils.js +6 -5
  24. package/lib/hashUtils.js.map +1 -1
  25. package/lib/i18nUtils.d.ts +11 -0
  26. package/lib/i18nUtils.d.ts.map +1 -1
  27. package/lib/i18nUtils.js +12 -3
  28. package/lib/i18nUtils.js.map +1 -1
  29. package/lib/index.d.ts +7 -7
  30. package/lib/index.d.ts.map +1 -1
  31. package/lib/index.js +16 -11
  32. package/lib/index.js.map +1 -1
  33. package/lib/jsUtils.d.ts +32 -4
  34. package/lib/jsUtils.d.ts.map +1 -1
  35. package/lib/jsUtils.js +35 -13
  36. package/lib/jsUtils.js.map +1 -1
  37. package/lib/markdownLinks.d.ts +48 -5
  38. package/lib/markdownLinks.d.ts.map +1 -1
  39. package/lib/markdownLinks.js +21 -11
  40. package/lib/markdownLinks.js.map +1 -1
  41. package/lib/markdownUtils.d.ts +112 -0
  42. package/lib/markdownUtils.d.ts.map +1 -0
  43. package/lib/markdownUtils.js +271 -0
  44. package/lib/markdownUtils.js.map +1 -0
  45. package/lib/pathUtils.d.ts +1 -1
  46. package/lib/pathUtils.d.ts.map +1 -1
  47. package/lib/pathUtils.js +2 -2
  48. package/lib/pathUtils.js.map +1 -1
  49. package/lib/slugger.d.ts +10 -0
  50. package/lib/slugger.d.ts.map +1 -1
  51. package/lib/slugger.js +4 -0
  52. package/lib/slugger.js.map +1 -1
  53. package/lib/tags.d.ts +31 -10
  54. package/lib/tags.d.ts.map +1 -1
  55. package/lib/tags.js +38 -23
  56. package/lib/tags.js.map +1 -1
  57. package/lib/urlUtils.d.ts +48 -2
  58. package/lib/urlUtils.d.ts.map +1 -1
  59. package/lib/urlUtils.js +81 -9
  60. package/lib/urlUtils.js.map +1 -1
  61. package/lib/webpackUtils.d.ts +5 -0
  62. package/lib/webpackUtils.d.ts.map +1 -1
  63. package/lib/webpackUtils.js +6 -2
  64. package/lib/webpackUtils.js.map +1 -1
  65. package/package.json +9 -9
  66. package/src/constants.ts +61 -9
  67. package/src/dataFileUtils.ts +43 -11
  68. package/src/emitUtils.ts +26 -9
  69. package/src/gitUtils.ts +76 -16
  70. package/src/globUtils.ts +29 -13
  71. package/src/hashUtils.ts +6 -5
  72. package/src/i18nUtils.ts +13 -4
  73. package/src/index.ts +14 -8
  74. package/src/jsUtils.ts +34 -20
  75. package/src/markdownLinks.ts +64 -27
  76. package/src/markdownUtils.ts +354 -0
  77. package/src/pathUtils.ts +2 -2
  78. package/src/slugger.ts +13 -1
  79. package/src/tags.ts +39 -27
  80. package/src/urlUtils.ts +96 -10
  81. package/src/webpackUtils.ts +10 -2
  82. package/lib/markdownParser.d.ts +0 -32
  83. package/lib/markdownParser.d.ts.map +0 -1
  84. package/lib/markdownParser.js +0 -160
  85. package/lib/markdownParser.js.map +0 -1
  86. package/src/markdownParser.ts +0 -201
@@ -4,17 +4,65 @@
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
+ /** Node major version, directly read from env. */
7
8
  export declare const NODE_MAJOR_VERSION: number;
9
+ /** Node minor version, directly read from env. */
8
10
  export declare const NODE_MINOR_VERSION: number;
11
+ /**
12
+ * Can be overridden with cli option `--out-dir`. Code should generally use
13
+ * `context.outDir` instead (which is always absolute and localized).
14
+ */
9
15
  export declare const DEFAULT_BUILD_DIR_NAME = "build";
16
+ /**
17
+ * Can be overridden with cli option `--config`. Code should generally use
18
+ * `context.siteConfigPath` instead (which is always absolute).
19
+ */
10
20
  export declare const DEFAULT_CONFIG_FILE_NAME = "docusaurus.config.js";
21
+ /** Can be absolute or relative to site directory. */
11
22
  export declare const BABEL_CONFIG_FILE_NAME: string;
23
+ /**
24
+ * Can be absolute or relative to site directory. Code should generally use
25
+ * `context.generatedFilesDir` instead (which is always absolute).
26
+ */
12
27
  export declare const GENERATED_FILES_DIR_NAME: string;
28
+ /**
29
+ * We would assume all of the site's JS code lives in here and not outside.
30
+ * Relative to the site directory.
31
+ */
13
32
  export declare const SRC_DIR_NAME = "src";
14
- export declare const STATIC_DIR_NAME = "static";
33
+ /**
34
+ * Can be overridden with `config.staticDirectories`. Code should use
35
+ * `context.siteConfig.staticDirectories` instead (which is always absolute).
36
+ */
37
+ export declare const DEFAULT_STATIC_DIR_NAME = "static";
38
+ /**
39
+ * Files here are handled by webpack, hashed (can be cached aggressively).
40
+ * Relative to the build output folder.
41
+ */
15
42
  export declare const OUTPUT_STATIC_ASSETS_DIR_NAME = "assets";
43
+ /**
44
+ * Components in this directory will receive the `@theme` alias and be able to
45
+ * shadow default theme components.
46
+ */
16
47
  export declare const THEME_PATH: string;
48
+ /**
49
+ * All translation-related data live here, relative to site directory. Content
50
+ * will be namespaced by locale.
51
+ */
52
+ export declare const I18N_DIR_NAME = "i18n";
53
+ /**
54
+ * Translations for React code.
55
+ */
56
+ export declare const CODE_TRANSLATIONS_FILE_NAME = "code.json";
57
+ /** Dev server opens on this port by default. */
17
58
  export declare const DEFAULT_PORT = 3000;
59
+ /** Default plugin ID. */
18
60
  export declare const DEFAULT_PLUGIN_ID = "default";
61
+ /**
62
+ * Allow overriding the limit after which the url loader will no longer inline
63
+ * assets.
64
+ *
65
+ * @see https://github.com/facebook/docusaurus/issues/5493
66
+ */
19
67
  export declare const WEBPACK_URL_LOADER_LIMIT: string | number;
20
68
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AACF,eAAO,MAAM,kBAAkB,QAG9B,CAAC;AAGF,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAG9C,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,eAAO,MAAM,sBAAsB,QACiC,CAAC;AAErE,eAAO,MAAM,wBAAwB,QAC6B,CAAC;AAEnE,eAAO,MAAM,YAAY,QAAQ,CAAC;AAClC,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,6BAA6B,WAAW,CAAC;AACtD,eAAO,MAAM,UAAU,QAA0B,CAAC;AAClD,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAG3C,eAAO,MAAM,wBAAwB,iBACU,CAAC"}
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;;;GAGG;AACH,eAAO,MAAM,sBAAsB,UAAU,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,wBAAwB,yBAAyB,CAAC;AAE/D,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,aAAa,SAAS,CAAC;AAEpC;;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"}
package/lib/constants.js CHANGED
@@ -6,21 +6,66 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.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.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
9
+ exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.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.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
10
+ /** Node major version, directly read from env. */
10
11
  exports.NODE_MAJOR_VERSION = parseInt(process.versions.node.split('.')[0], 10);
12
+ /** Node minor version, directly read from env. */
11
13
  exports.NODE_MINOR_VERSION = parseInt(process.versions.node.split('.')[1], 10);
12
- // Can be overridden with cli option --out-dir
14
+ /**
15
+ * Can be overridden with cli option `--out-dir`. Code should generally use
16
+ * `context.outDir` instead (which is always absolute and localized).
17
+ */
13
18
  exports.DEFAULT_BUILD_DIR_NAME = 'build';
14
- // Can be overridden with cli option --config
19
+ /**
20
+ * Can be overridden with cli option `--config`. Code should generally use
21
+ * `context.siteConfigPath` instead (which is always absolute).
22
+ */
15
23
  exports.DEFAULT_CONFIG_FILE_NAME = 'docusaurus.config.js';
16
- exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME || 'babel.config.js';
17
- exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME || '.docusaurus';
24
+ /** Can be absolute or relative to site directory. */
25
+ exports.BABEL_CONFIG_FILE_NAME = process.env.DOCUSAURUS_BABEL_CONFIG_FILE_NAME ?? 'babel.config.js';
26
+ /**
27
+ * Can be absolute or relative to site directory. Code should generally use
28
+ * `context.generatedFilesDir` instead (which is always absolute).
29
+ */
30
+ exports.GENERATED_FILES_DIR_NAME = process.env.DOCUSAURUS_GENERATED_FILES_DIR_NAME ?? '.docusaurus';
31
+ /**
32
+ * We would assume all of the site's JS code lives in here and not outside.
33
+ * Relative to the site directory.
34
+ */
18
35
  exports.SRC_DIR_NAME = 'src';
19
- exports.STATIC_DIR_NAME = 'static';
20
- exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets'; // files handled by webpack, hashed (can be cached aggressively)
36
+ /**
37
+ * Can be overridden with `config.staticDirectories`. Code should use
38
+ * `context.siteConfig.staticDirectories` instead (which is always absolute).
39
+ */
40
+ exports.DEFAULT_STATIC_DIR_NAME = 'static';
41
+ /**
42
+ * Files here are handled by webpack, hashed (can be cached aggressively).
43
+ * Relative to the build output folder.
44
+ */
45
+ exports.OUTPUT_STATIC_ASSETS_DIR_NAME = 'assets';
46
+ /**
47
+ * Components in this directory will receive the `@theme` alias and be able to
48
+ * shadow default theme components.
49
+ */
21
50
  exports.THEME_PATH = `${exports.SRC_DIR_NAME}/theme`;
51
+ /**
52
+ * All translation-related data live here, relative to site directory. Content
53
+ * will be namespaced by locale.
54
+ */
55
+ exports.I18N_DIR_NAME = 'i18n';
56
+ /**
57
+ * Translations for React code.
58
+ */
59
+ exports.CODE_TRANSLATIONS_FILE_NAME = 'code.json';
60
+ /** Dev server opens on this port by default. */
22
61
  exports.DEFAULT_PORT = 3000;
62
+ /** Default plugin ID. */
23
63
  exports.DEFAULT_PLUGIN_ID = 'default';
24
- // Temporary fix for https://github.com/facebook/docusaurus/issues/5493
64
+ /**
65
+ * Allow overriding the limit after which the url loader will no longer inline
66
+ * assets.
67
+ *
68
+ * @see https://github.com/facebook/docusaurus/issues/5493
69
+ */
25
70
  exports.WEBPACK_URL_LOADER_LIMIT = process.env.WEBPACK_URL_LOADER_LIMIT ?? 10000;
26
71
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CAAC;AACW,QAAA,kBAAkB,GAAG,QAAQ,CACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EACnC,EAAE,CACH,CA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;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,aAAa,GAAG,MAAM,CAAC;AAEpC;;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"}
@@ -6,19 +6,55 @@
6
6
  */
7
7
  import type { ContentPaths } from './markdownLinks';
8
8
  declare type DataFileParams = {
9
+ /** Path to the potential data file, relative to `contentPaths` */
9
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
+ */
10
15
  contentPaths: ContentPaths;
11
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
+ */
12
23
  export declare function getDataFilePath({ filePath, contentPaths, }: DataFileParams): Promise<string | undefined>;
13
24
  /**
14
- * Looks up for a data file in the content paths, returns the normalized object.
15
- * Throws when validation fails; returns undefined when file not found
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.
16
30
  */
17
31
  export declare function getDataFileData<T>(params: DataFileParams & {
32
+ /** Used for the "The X file looks invalid" message. */
18
33
  fileType: string;
19
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
+ */
20
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
+ */
21
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
+ */
22
58
  export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
23
59
  export {};
24
60
  //# sourceMappingURL=dataFileUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dataFileUtils.d.ts","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAGlD,aAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAsB,eAAe,CAAC,EACpC,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU9C;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,CAAC,EACrC,MAAM,EAAE,cAAc,GAAG;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAC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B,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"}
@@ -13,8 +13,13 @@ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
13
13
  const path_1 = tslib_1.__importDefault(require("path"));
14
14
  const index_1 = require("./index");
15
15
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
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
+ */
16
22
  async function getDataFilePath({ filePath, contentPaths, }) {
17
- // Loads a localized data file in priority
18
23
  const contentPath = await findFolderContainingFile(getContentPathList(contentPaths), filePath);
19
24
  if (contentPath) {
20
25
  return path_1.default.join(contentPath, filePath);
@@ -23,8 +28,11 @@ async function getDataFilePath({ filePath, contentPaths, }) {
23
28
  }
24
29
  exports.getDataFilePath = getDataFilePath;
25
30
  /**
26
- * Looks up for a data file in the content paths, returns the normalized object.
27
- * Throws when validation fails; returns undefined when file not found
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.
28
36
  */
29
37
  async function getDataFileData(params, validate) {
30
38
  const filePath = await getDataFilePath(params);
@@ -37,27 +45,45 @@ async function getDataFileData(params, validate) {
37
45
  return validate(unsafeContent);
38
46
  }
39
47
  catch (err) {
40
- // TODO replace later by error cause, see https://v8.dev/features/error-cause
41
48
  logger_1.default.error `The ${params.fileType} file at path=${filePath} looks invalid.`;
42
49
  throw err;
43
50
  }
44
51
  }
45
52
  exports.getDataFileData = getDataFileData;
46
- // Order matters: we look in priority in localized folder
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
+ */
47
58
  function getContentPathList(contentPaths) {
48
59
  return [contentPaths.contentPathLocalized, contentPaths.contentPath];
49
60
  }
50
61
  exports.getContentPathList = getContentPathList;
51
- // return the first folder path in which the file exists in
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
+ */
52
68
  async function findFolderContainingFile(folderPaths, relativeFilePath) {
53
69
  return (0, index_1.findAsyncSequential)(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
54
70
  }
55
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
+ */
56
82
  async function getFolderContainingFile(folderPaths, relativeFilePath) {
57
83
  const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
58
- // should never happen, as the source was read from the FS anyway...
59
84
  if (!maybeFolderPath) {
60
- throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join('\n- ')}]`);
85
+ throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:
86
+ - ${folderPaths.join('\n- ')}`);
61
87
  }
62
88
  return maybeFolderPath;
63
89
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dataFileUtils.js","sourceRoot":"","sources":["../src/dataFileUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,8DAA2B;AAC3B,wDAAwB;AACxB,mCAA4C;AAE5C,wEAAwC;AAO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ACtE,MAAM,aAAa,GAAG,iBAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC,aAAa,CAAC,CAAC;KAChC;IAAC,OAAO,GAAG,EAAE;QACZ,gBAAM,CAAC,KAAK,CAAA,OAAO,MAAM,CAAC,QAAQ,iBAAiB,QAAQ,iBAAiB,CAAC;QAC7E,MAAM,GAAG,CAAC;KACX;AACH,CAAC;AAnBD,0CAmBC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,YAA0B;IAC3D,OAAO,CAAC,YAAY,CAAC,oBAAoB,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;AACvE,CAAC;AAFD,gDAEC;AAED;;;;;GAKG;AACI,KAAK,UAAU,wBAAwB,CAC5C,WAAqB,EACrB,gBAAwB;IAExB,OAAO,IAAA,2BAAmB,EAAC,WAAW,EAAE,CAAC,UAAU,EAAE,EAAE,CACrD,kBAAE,CAAC,UAAU,CAAC,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC,CACvD,CAAC;AACJ,CAAC;AAPD,4DAOC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAAqB,EACrB,gBAAwB;IAExB,MAAM,eAAe,GAAG,MAAM,wBAAwB,CACpD,WAAW,EACX,gBAAgB,CACjB,CAAC;IACF,IAAI,CAAC,eAAe,EAAE;QACpB,MAAM,IAAI,KAAK,CACb,SAAS,gBAAgB;IAC3B,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACzB,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAfD,0DAeC"}
@@ -5,6 +5,16 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
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`.
14
+ * @param content String content to write.
15
+ * @param skipCache If `true` (defaults as `true` for production), file is
16
+ * force-rewritten, skipping cache.
17
+ */
8
18
  export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
9
19
  /**
10
20
  * Generate unique chunk name given a module path.
@@ -18,6 +28,8 @@ export declare function genChunkName(modulePath: string, prefix?: string, prefer
18
28
  * @returns This returns a buffer, which you have to decode string yourself if
19
29
  * needed. (Not always necessary since the output isn't for human consumption
20
30
  * anyways, and most HTML manipulation libs accept buffers)
31
+ * @throws Throws when the HTML file is not found at any of the potential paths.
32
+ * This should never happen as it would lead to a 404.
21
33
  */
22
34
  export declare function readOutputHTMLFile(permalink: string, outDir: string, trailingSlash: boolean | undefined): Promise<Buffer>;
23
35
  //# sourceMappingURL=emitUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"emitUtils.d.ts","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAUH,wBAAsB,QAAQ,CAC5B,iBAAiB,EAAE,MAAM,EACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,SAAS,GAAE,OAA+C,GACzD,OAAO,CAAC,IAAI,CAAC,CA2Bf;AAID;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,GAAE,OAA+C,GACvD,MAAM,CAiBR;AAED;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
1
+ {"version":3,"file":"emitUtils.d.ts","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;;AAUH;;;;;;;;;GASG;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;AAID;;GAEG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,GAAE,OAA+C,GACvD,MAAM,CAiBR;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,OAAO,GAAG,SAAS,GACjC,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
package/lib/emitUtils.js CHANGED
@@ -14,17 +14,33 @@ const crypto_1 = require("crypto");
14
14
  const hashUtils_1 = require("./hashUtils");
15
15
  const jsUtils_1 = require("./jsUtils");
16
16
  const fileHash = new Map();
17
+ /**
18
+ * Outputs a file to the generated files directory. Only writes files if content
19
+ * differs from cache (for hot reload performance).
20
+ *
21
+ * @param generatedFilesDir Absolute path.
22
+ * @param file Path relative to `generatedFilesDir`.
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
+ */
17
27
  async function generate(generatedFilesDir, file, content, skipCache = process.env.NODE_ENV === 'production') {
18
28
  const filepath = path_1.default.join(generatedFilesDir, file);
19
29
  if (skipCache) {
20
- await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
21
- await fs_extra_1.default.writeFile(filepath, content);
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
+ }
22
38
  return;
23
39
  }
24
40
  let lastHash = fileHash.get(filepath);
25
- // If file already exists but its not in runtime cache yet,
26
- // we try to calculate the content hash and then compare
27
- // This is to avoid unnecessary overwriting and we can reuse old file.
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.
28
44
  if (!lastHash && (await fs_extra_1.default.pathExists(filepath))) {
29
45
  const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
30
46
  lastHash = (0, crypto_1.createHash)('md5').update(lastContent).digest('hex');
@@ -32,8 +48,7 @@ async function generate(generatedFilesDir, file, content, skipCache = process.en
32
48
  }
33
49
  const currentHash = (0, crypto_1.createHash)('md5').update(content).digest('hex');
34
50
  if (lastHash !== currentHash) {
35
- await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));
36
- await fs_extra_1.default.writeFile(filepath, content);
51
+ await fs_extra_1.default.outputFile(filepath, content);
37
52
  fileHash.set(filepath, currentHash);
38
53
  }
39
54
  }
@@ -70,6 +85,8 @@ exports.genChunkName = genChunkName;
70
85
  * @returns This returns a buffer, which you have to decode string yourself if
71
86
  * needed. (Not always necessary since the output isn't for human consumption
72
87
  * anyways, and most HTML manipulation libs accept buffers)
88
+ * @throws Throws when the HTML file is not found at any of the potential paths.
89
+ * This should never happen as it would lead to a 404.
73
90
  */
74
91
  async function readOutputHTMLFile(permalink, outDir, trailingSlash) {
75
92
  const withTrailingSlashPath = path_1.default.join(outDir, permalink, 'index.html');
@@ -1 +1 @@
1
- {"version":3,"file":"emitUtils.js","sourceRoot":"","sources":["../src/emitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,gEAA0B;AAC1B,mCAAkC;AAClC,2CAAiD;AACjD,uCAA8C;AAE9C,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;AAEpC,KAAK,UAAU,QAAQ,CAC5B,iBAAyB,EACzB,IAA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AE;QACb,MAAM,IAAI,KAAK,CACb,4CAA4C,qBAAqB,EAAE,CACpE,CAAC;KACH;IACD,OAAO,kBAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC;AAzBD,gDAyBC"}
package/lib/gitUtils.d.ts CHANGED
@@ -4,14 +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
+ /** Custom error thrown when git is not found in `PATH`. */
7
8
  export declare class GitNotFoundError extends Error {
8
9
  }
9
- export declare const getFileCommitDate: (file: string, { age, includeAuthor, }: {
10
- age?: "oldest" | "newest" | undefined;
11
- includeAuthor?: boolean | undefined;
12
- }) => {
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 {GitNotFoundError} If git is not found in `PATH`.
19
+ * @throws {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 {GitNotFoundError} If git is not found in `PATH`.
45
+ * @throws {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. */
13
60
  date: Date;
61
+ /** Timestamp in **seconds**, as returned from git. */
14
62
  timestamp: number;
15
- author?: string | undefined;
63
+ /** The author's name, as returned from git. */
64
+ author: string;
16
65
  };
17
66
  //# sourceMappingURL=gitUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gitUtils.d.ts","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,qBAAa,gBAAiB,SAAQ,KAAK;CAAG;AAE9C,eAAO,MAAM,iBAAiB,SACtB,MAAM;;;;UASN,IAAI;eACC,MAAM;;CAqElB,CAAC"}
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"}
package/lib/gitUtils.js CHANGED
@@ -6,22 +6,25 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getFileCommitDate = exports.GitNotFoundError = void 0;
9
+ exports.getFileCommitDate = exports.FileNotTrackedError = exports.GitNotFoundError = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const shelljs_1 = tslib_1.__importDefault(require("shelljs"));
13
+ /** Custom error thrown when git is not found in `PATH`. */
13
14
  class GitNotFoundError extends Error {
14
15
  }
15
16
  exports.GitNotFoundError = GitNotFoundError;
16
- const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) => {
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, }) {
17
22
  if (!shelljs_1.default.which('git')) {
18
23
  throw new GitNotFoundError(`Failed to retrieve git history for "${file}" because git is not installed.`);
19
24
  }
20
25
  if (!shelljs_1.default.test('-f', file)) {
21
26
  throw new Error(`Failed to retrieve git history for "${file}" because the file does not exist.`);
22
27
  }
23
- const fileBasename = path_1.default.basename(file);
24
- const fileDirname = path_1.default.dirname(file);
25
28
  let formatArg = '--format=%ct';
26
29
  if (includeAuthor) {
27
30
  formatArg += ',%an';
@@ -32,9 +35,9 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
32
35
  // --diff-filter=A ensures we only get the commit which (A)dded the file
33
36
  extraArgs += ' --follow --diff-filter=A';
34
37
  }
35
- const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${fileBasename}"`, {
38
+ const result = shelljs_1.default.exec(`git log ${extraArgs} ${formatArg} -- "${path_1.default.basename(file)}"`, {
36
39
  // cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
37
- cwd: fileDirname,
40
+ cwd: path_1.default.dirname(file),
38
41
  silent: true,
39
42
  });
40
43
  if (result.code !== 0) {
@@ -45,11 +48,11 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
45
48
  regex = /^(?<timestamp>\d+),(?<author>.+)$/;
46
49
  }
47
50
  const output = result.stdout.trim();
51
+ if (!output) {
52
+ throw new FileNotTrackedError(`Failed to retrieve the git history for file "${file}" because the file is not tracked by git.`);
53
+ }
48
54
  const match = output.match(regex);
49
- if (!match ||
50
- !match.groups ||
51
- !match.groups.timestamp ||
52
- (includeAuthor && !match.groups.author)) {
55
+ if (!match) {
53
56
  throw new Error(`Failed to retrieve the git history for file "${file}" with unexpected output: ${output}`);
54
57
  }
55
58
  const timestamp = Number(match.groups.timestamp);
@@ -58,6 +61,6 @@ const getFileCommitDate = (file, { age = 'oldest', includeAuthor = false, }) =>
58
61
  return { date, timestamp, author: match.groups.author };
59
62
  }
60
63
  return { date, timestamp };
61
- };
64
+ }
62
65
  exports.getFileCommitDate = getFileCommitDate;
63
66
  //# sourceMappingURL=gitUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gitUtils.js","sourceRoot":"","sources":["../src/gitUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AACxB,8DAA4B;AAE5B,MAAa,gBAAiB,SAAQ,KAAK;CAAG;AAA9C,4CAA8C;AAEvC,MAAM,iBAAiB,GAAG,CAC/B,IAAY,EACZ,EACE,GAAG,GAAG,QAAQ,EACd,aAAa,GAAG,KAAK,GAItB,EAKD,EAAE;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AI,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;AA/ED,8CA+EC"}
@@ -4,9 +4,36 @@
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
+ /** A re-export of the globby instance. */
7
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
+ */
8
14
  export declare const GlobExcludeDefault: string[];
9
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.
21
+ * @returns A matcher handle that tells if a file path is matched by any of the
22
+ * patterns.
23
+ */
10
24
  export declare function createMatcher(patterns: string[]): Matcher;
25
+ /**
26
+ * We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
27
+ * should only be matched within a subfolder. This function would:
28
+ * - Match `/user/sebastien/website/docs/_partials/xyz.md`
29
+ * - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
30
+ *
31
+ * @param patterns A list of glob patterns.
32
+ * @param rootFolders A list of root folders to resolve the glob from.
33
+ * @returns A matcher handle that tells if a file path is matched by any of the
34
+ * patterns, resolved from the first root folder that contains the path.
35
+ * @throws Throws when the returned matcher receives a path that doesn't belong
36
+ * to any of the `rootFolders`.
37
+ */
11
38
  export declare function createAbsoluteFilePathMatcher(patterns: string[], rootFolders: string[]): Matcher;
12
39
  //# sourceMappingURL=globUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"globUtils.d.ts","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAC,MAAM,QAAQ,CAAC;AAIzC,eAAO,MAAM,kBAAkB,UAU9B,CAAC;AAEF,aAAK,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;AAExC,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAKzD;AAMD,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}
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;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAKzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAmBT"}