@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
@@ -0,0 +1,71 @@
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.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = void 0;
10
+ const tslib_1 = require("tslib");
11
+ // Globby/Micromatch are the 2 libs we use in Docusaurus consistently
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const micromatch_1 = tslib_1.__importDefault(require("micromatch")); // Note: Micromatch is used by Globby
14
+ /** A re-export of the globby instance. */
15
+ var globby_1 = require("globby");
16
+ Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return tslib_1.__importDefault(globby_1).default; } });
17
+ /**
18
+ * The default glob patterns we ignore when sourcing content.
19
+ * - Ignore files and folders starting with `_` recursively
20
+ * - Ignore tests
21
+ */
22
+ exports.GlobExcludeDefault = [
23
+ '**/_*.{js,jsx,ts,tsx,md,mdx}',
24
+ '**/_*/**',
25
+ '**/*.test.{js,jsx,ts,tsx}',
26
+ '**/__tests__/**',
27
+ ];
28
+ /**
29
+ * A very thin wrapper around `Micromatch.makeRe`.
30
+ *
31
+ * @see {@link createAbsoluteFilePathMatcher}
32
+ * @param patterns A list of glob patterns. If the list is empty, it defaults to
33
+ * matching none.
34
+ * @returns A matcher handle that tells if a file path is matched by any of the
35
+ * patterns.
36
+ */
37
+ function createMatcher(patterns) {
38
+ if (patterns.length === 0) {
39
+ // `/(?:)/.test("foo")` is `true`
40
+ return () => false;
41
+ }
42
+ const regexp = new RegExp(patterns.map((pattern) => micromatch_1.default.makeRe(pattern).source).join('|'));
43
+ return (str) => regexp.test(str);
44
+ }
45
+ exports.createMatcher = createMatcher;
46
+ /**
47
+ * We use match patterns like `"** /_* /**"` (ignore the spaces), where `"_*"`
48
+ * should only be matched within a subfolder. This function would:
49
+ * - Match `/user/sebastien/website/docs/_partials/xyz.md`
50
+ * - Ignore `/user/_sebastien/website/docs/partials/xyz.md`
51
+ *
52
+ * @param patterns A list of glob patterns.
53
+ * @param rootFolders A list of root folders to resolve the glob from.
54
+ * @returns A matcher handle that tells if a file path is matched by any of the
55
+ * patterns, resolved from the first root folder that contains the path.
56
+ * @throws Throws when the returned matcher receives a path that doesn't belong
57
+ * to any of the `rootFolders`.
58
+ */
59
+ function createAbsoluteFilePathMatcher(patterns, rootFolders) {
60
+ const matcher = createMatcher(patterns);
61
+ function getRelativeFilePath(absoluteFilePath) {
62
+ const rootFolder = rootFolders.find((folderPath) => absoluteFilePath.startsWith(folderPath));
63
+ if (!rootFolder) {
64
+ throw new Error(`createAbsoluteFilePathMatcher unexpected error, absoluteFilePath=${absoluteFilePath} was not contained in any of the root folders: ${rootFolders.join(', ')}`);
65
+ }
66
+ return path_1.default.relative(rootFolder, absoluteFilePath);
67
+ }
68
+ return (absoluteFilePath) => matcher(getRelativeFilePath(absoluteFilePath));
69
+ }
70
+ exports.createAbsoluteFilePathMatcher = createAbsoluteFilePathMatcher;
71
+ //# sourceMappingURL=globUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globUtils.js","sourceRoot":"","sources":["../src/globUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,qEAAqE;AAErE,wDAAwB;AACxB,oEAAoC,CAAC,qCAAqC;AAE1E,0CAA0C;AAC1C,iCAAyC;AAAjC,yHAAA,OAAO,OAAU;AAEzB;;;;GAIG;AACU,QAAA,kBAAkB,GAAG;IAChC,8BAA8B;IAC9B,UAAU;IACV,2BAA2B;IAC3B,iBAAiB;CAClB,CAAC;AAIF;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAAC,QAAkB;IAC9C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;QACzB,iCAAiC;QACjC,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC;KACpB;IACD,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,oBAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACvE,CAAC;IACF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AATD,sCASC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,6BAA6B,CAC3C,QAAkB,EAClB,WAAqB;IAErB,MAAM,OAAO,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExC,SAAS,mBAAmB,CAAC,gBAAwB;QACnD,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACjD,gBAAgB,CAAC,UAAU,CAAC,UAAU,CAAC,CACxC,CAAC;QACF,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,KAAK,CACb,oEAAoE,gBAAgB,kDAAkD,WAAW,CAAC,IAAI,CACpJ,IAAI,CACL,EAAE,CACJ,CAAC;SACH;QACD,OAAO,cAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,CAAC,gBAAwB,EAAE,EAAE,CAClC,OAAO,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,CAAC;AACnD,CAAC;AAtBD,sEAsBC"}
@@ -0,0 +1,17 @@
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
+ /** Thin wrapper around `crypto.createHash("md5")`. */
8
+ export declare function md5Hash(str: string): string;
9
+ /** Creates an MD5 hash and truncates it to the given length. */
10
+ export declare function simpleHash(str: string, length: number): string;
11
+ /**
12
+ * Given an input string, convert to kebab-case and append a hash, avoiding name
13
+ * collision. Also removes part of the string if its larger than the allowed
14
+ * filename per OS, avoiding `ERRNAMETOOLONG` error.
15
+ */
16
+ export declare function docuHash(str: string): string;
17
+ //# sourceMappingURL=hashUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
@@ -0,0 +1,42 @@
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.docuHash = exports.simpleHash = exports.md5Hash = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const crypto_1 = require("crypto");
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const pathUtils_1 = require("./pathUtils");
14
+ /** Thin wrapper around `crypto.createHash("md5")`. */
15
+ function md5Hash(str) {
16
+ return (0, crypto_1.createHash)('md5').update(str).digest('hex');
17
+ }
18
+ exports.md5Hash = md5Hash;
19
+ /** Creates an MD5 hash and truncates it to the given length. */
20
+ function simpleHash(str, length) {
21
+ return md5Hash(str).substring(0, length);
22
+ }
23
+ exports.simpleHash = simpleHash;
24
+ // Based on https://github.com/gatsbyjs/gatsby/pull/21518/files
25
+ /**
26
+ * Given an input string, convert to kebab-case and append a hash, avoiding name
27
+ * collision. Also removes part of the string if its larger than the allowed
28
+ * filename per OS, avoiding `ERRNAMETOOLONG` error.
29
+ */
30
+ function docuHash(str) {
31
+ if (str === '/') {
32
+ return 'index';
33
+ }
34
+ const shortHash = simpleHash(str, 3);
35
+ const parsedPath = `${lodash_1.default.kebabCase(str)}-${shortHash}`;
36
+ if ((0, pathUtils_1.isNameTooLong)(parsedPath)) {
37
+ return `${(0, pathUtils_1.shortName)(lodash_1.default.kebabCase(str))}-${shortHash}`;
38
+ }
39
+ return parsedPath;
40
+ }
41
+ exports.docuHash = docuHash;
42
+ //# sourceMappingURL=hashUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mCAAkC;AAClC,4DAAuB;AACvB,2CAAqD;AAErD,sDAAsD;AACtD,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAFD,0BAEC;AAED,gEAAgE;AAChE,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,GAAG,KAAK,GAAG,EAAE;QACf,OAAO,OAAO,CAAC;KAChB;IACD,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,UAAU,GAAG,GAAG,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACtD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE;QAC7B,OAAO,GAAG,IAAA,qBAAS,EAAC,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;KACtD;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAVD,4BAUC"}
@@ -0,0 +1,53 @@
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 { TranslationFileContent, TranslationFile, I18n } from '@docusaurus/types';
8
+ /**
9
+ * Takes a list of translation file contents, and shallow-merges them into one.
10
+ */
11
+ export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
12
+ /**
13
+ * Useful to update all the messages of a translation file. Used in tests to
14
+ * simulate translations.
15
+ */
16
+ export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
17
+ /**
18
+ * Takes everything needed and constructs a plugin i18n path. Plugins should
19
+ * expect everything it needs for translations to be found under this path.
20
+ */
21
+ export declare function getPluginI18nPath({ localizationDir, pluginName, pluginId, subPaths, }: {
22
+ localizationDir: string;
23
+ pluginName: string;
24
+ pluginId?: string | undefined;
25
+ subPaths?: string[];
26
+ }): string;
27
+ /**
28
+ * Takes a path and returns a localized a version (which is basically `path +
29
+ * i18n.currentLocale`).
30
+ *
31
+ * This is used to resolve the `outDir` and `baseUrl` of each locale; it is NOT
32
+ * used to determine plugin localization file locations.
33
+ */
34
+ export declare function localizePath({ pathType, path: originalPath, i18n, options, }: {
35
+ /**
36
+ * FS paths will treat Windows specially; URL paths will always have a
37
+ * trailing slash to make it a valid base URL.
38
+ */
39
+ pathType: 'fs' | 'url';
40
+ /** The path, URL or file path, to be localized. */
41
+ path: string;
42
+ /** The current i18n context. */
43
+ i18n: I18n;
44
+ options?: {
45
+ /**
46
+ * By default, we don't localize the path of defaultLocale. This option
47
+ * would override that behavior. Setting `false` is useful for `yarn build
48
+ * -l zh-Hans` to always emit into the root build directory.
49
+ */
50
+ localizePath?: boolean;
51
+ };
52
+ }): string;
53
+ //# sourceMappingURL=i18nUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nUtils.d.ts","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,IAAI,EACL,MAAM,mBAAmB,CAAC;AAE3B;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,sBAAsB,EAAE,GACjC,sBAAsB,CAExB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,eAAe,EAAE,eAAe,EAChC,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GACzC,eAAe,CAQjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,eAAe,EACf,UAAU,EACV,QAA4B,EAC5B,QAAa,GACd,EAAE;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,GAAG,MAAM,CAQT;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,IAAI,EAAE,YAAY,EAClB,IAAI,EACJ,OAAY,GACb,EAAE;IACD;;;OAGG;IACH,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC;IACvB,mDAAmD;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH,GAAG,MAAM,CAgBT"}
@@ -0,0 +1,70 @@
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.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
13
+ const constants_1 = require("./constants");
14
+ const urlUtils_1 = require("./urlUtils");
15
+ /**
16
+ * Takes a list of translation file contents, and shallow-merges them into one.
17
+ */
18
+ function mergeTranslations(contents) {
19
+ return contents.reduce((acc, content) => ({ ...acc, ...content }), {});
20
+ }
21
+ exports.mergeTranslations = mergeTranslations;
22
+ /**
23
+ * Useful to update all the messages of a translation file. Used in tests to
24
+ * simulate translations.
25
+ */
26
+ function updateTranslationFileMessages(translationFile, updateMessage) {
27
+ return {
28
+ ...translationFile,
29
+ content: lodash_1.default.mapValues(translationFile.content, (translation) => ({
30
+ ...translation,
31
+ message: updateMessage(translation.message),
32
+ })),
33
+ };
34
+ }
35
+ exports.updateTranslationFileMessages = updateTranslationFileMessages;
36
+ /**
37
+ * Takes everything needed and constructs a plugin i18n path. Plugins should
38
+ * expect everything it needs for translations to be found under this path.
39
+ */
40
+ function getPluginI18nPath({ localizationDir, pluginName, pluginId = constants_1.DEFAULT_PLUGIN_ID, subPaths = [], }) {
41
+ return path_1.default.join(localizationDir,
42
+ // Make it convenient to use for single-instance
43
+ // ie: return "docs", not "docs-default" nor "docs/default"
44
+ `${pluginName}${pluginId === constants_1.DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`, ...subPaths);
45
+ }
46
+ exports.getPluginI18nPath = getPluginI18nPath;
47
+ /**
48
+ * Takes a path and returns a localized a version (which is basically `path +
49
+ * i18n.currentLocale`).
50
+ *
51
+ * This is used to resolve the `outDir` and `baseUrl` of each locale; it is NOT
52
+ * used to determine plugin localization file locations.
53
+ */
54
+ function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
55
+ const shouldLocalizePath = options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
56
+ if (!shouldLocalizePath) {
57
+ return originalPath;
58
+ }
59
+ // FS paths need special care, for Windows support. Note: we don't use the
60
+ // locale config's `path` here, because this function is used for resolving
61
+ // outDir, which must be the same as baseUrl. When we have the baseUrl config,
62
+ // we need to sync the two.
63
+ if (pathType === 'fs') {
64
+ return path_1.default.join(originalPath, i18n.currentLocale);
65
+ }
66
+ // Url paths; add a trailing slash so it's a valid base URL
67
+ return (0, urlUtils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
68
+ }
69
+ exports.localizePath = localizePath;
70
+ //# sourceMappingURL=i18nUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18nUtils.js","sourceRoot":"","sources":["../src/i18nUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;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ACvB,OAAO,YAAY,CAAC;KACrB;IACD,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,2BAA2B;IAC3B,IAAI,QAAQ,KAAK,IAAI,EAAE;QACrB,OAAO,cAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;KACpD;IACD,2DAA2D;IAC3D,OAAO,IAAA,uBAAY,EAAC,CAAC,YAAY,EAAE,IAAI,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;AAC/D,CAAC;AAvCD,oCAuCC"}
package/lib/index.d.ts CHANGED
@@ -4,85 +4,20 @@
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
- import { ReportingSeverity, TranslationFileContent, TranslationFile } from '@docusaurus/types';
8
- import { posixPath as posixPathImport } from './posixPath';
9
- export declare const posixPath: typeof posixPathImport;
10
- export * from './codeTranslationsUtils';
11
- export * from './markdownParser';
12
- export * from './markdownLinks';
13
- export * from './escapePath';
14
- export declare function generate(generatedFilesDir: string, file: string, content: string, skipCache?: boolean): Promise<void>;
15
- export declare function objectWithKeySorted<T>(obj: Record<string, T>): Record<string, T>;
16
- /**
17
- * Convert filepath to url path.
18
- * Example: 'index.md' -> '/', 'foo/bar.js' -> '/foo/bar',
19
- */
20
- export declare function fileToPath(file: string): string;
21
- export declare function encodePath(userpath: string): string;
22
- export declare function simpleHash(str: string, length: number): string;
23
- /**
24
- * Given an input string, convert to kebab-case and append a hash.
25
- * Avoid str collision.
26
- */
27
- export declare function docuHash(str: string): string;
28
- /**
29
- * Convert first string character to the upper case.
30
- * E.g: docusaurus -> Docusaurus
31
- */
32
- export declare function upperFirst(str: string): string;
33
- /**
34
- * Generate unique React Component Name.
35
- * E.g: /foo-bar -> FooBar096
36
- */
37
- export declare function genComponentName(pagePath: string): string;
38
- export declare function toMessageRelativeFilePath(filePath: string): string;
39
- /**
40
- * Generate unique chunk name given a module path.
41
- */
42
- export declare function genChunkName(modulePath: string, prefix?: string, preferredName?: string, shortId?: boolean): string;
43
- export declare function idx(target: any, keyPaths?: string | (string | number)[]): any;
44
- /**
45
- * Given a filepath and dirpath, get the first directory.
46
- */
47
- export declare function getSubFolder(file: string, refDir: string): string | null;
48
- export declare function normalizeUrl(rawUrls: string[]): string;
49
- /**
50
- * Alias filepath relative to site directory, very useful so that we
51
- * don't expose user's site structure.
52
- * Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
53
- */
54
- export declare function aliasedSitePath(filePath: string, siteDir: string): string;
55
- export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
56
- export declare function isValidPathname(str: string): boolean;
57
- export declare function resolvePathname(to: string, from?: string): string;
58
- export declare function addLeadingSlash(str: string): string;
59
- export declare function addTrailingSlash(str: string): string;
60
- export declare function addTrailingPathSeparator(str: string): string;
61
- export declare function removeTrailingSlash(str: string): string;
62
- export declare function removeSuffix(str: string, suffix: string): string;
63
- export declare function removePrefix(str: string, prefix: string): string;
64
- export declare function getFilePathForRoutePath(routePath: string): string;
65
- export declare function getElementsAround<T extends unknown>(array: T[], aroundIndex: number): {
66
- next: T | undefined;
67
- previous: T | undefined;
68
- };
69
- export declare function getPluginI18nPath({ siteDir, locale, pluginName, pluginId, // TODO duplicated constant
70
- subPaths, }: {
71
- siteDir: string;
72
- locale: string;
73
- pluginName: string;
74
- pluginId?: string | undefined;
75
- subPaths?: string[];
76
- }): string;
77
- export declare function mapAsyncSequencial<T extends unknown, R extends unknown>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
78
- export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
79
- export declare function findFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string | undefined>;
80
- export declare function getFolderContainingFile(folderPaths: string[], relativeFilePath: string): Promise<string>;
81
- export declare function reportMessage(message: string, reportingSeverity: ReportingSeverity): void;
82
- export declare function mergeTranslations(contents: TranslationFileContent[]): TranslationFileContent;
83
- export declare function getSwizzledComponent(componentPath: string): string | undefined;
84
- export declare function updateTranslationFileMessages(translationFile: TranslationFile, updateMessage: (message: string) => string): TranslationFile;
85
- export declare function parseMarkdownHeadingId(heading: string): {
86
- text: string;
87
- id?: string;
88
- };
7
+ export { NODE_MAJOR_VERSION, NODE_MINOR_VERSION, DOCUSAURUS_VERSION, DEFAULT_BUILD_DIR_NAME, DEFAULT_CONFIG_FILE_NAME, BABEL_CONFIG_FILE_NAME, GENERATED_FILES_DIR_NAME, SRC_DIR_NAME, DEFAULT_STATIC_DIR_NAME, OUTPUT_STATIC_ASSETS_DIR_NAME, THEME_PATH, DEFAULT_I18N_DIR_NAME, CODE_TRANSLATIONS_FILE_NAME, DEFAULT_PORT, DEFAULT_PLUGIN_ID, WEBPACK_URL_LOADER_LIMIT, } from './constants';
8
+ export { generate, readOutputHTMLFile } from './emitUtils';
9
+ export { getFileCommitDate, FileNotTrackedError, GitNotFoundError, } from './gitUtils';
10
+ export { mergeTranslations, updateTranslationFileMessages, getPluginI18nPath, localizePath, } from './i18nUtils';
11
+ export { removeSuffix, removePrefix, mapAsyncSequential, findAsyncSequential, } from './jsUtils';
12
+ export { normalizeUrl, getEditUrl, fileToPath, encodePath, isValidPathname, resolvePathname, addLeadingSlash, addTrailingSlash, removeTrailingSlash, hasSSHProtocol, buildHttpsUrl, buildSshUrl, } from './urlUtils';
13
+ export { type Tag, type TagsListItem, type TagModule, type FrontMatterTag, normalizeFrontMatterTags, groupTaggedItems, } from './tags';
14
+ export { parseMarkdownHeadingId, createExcerpt, parseFrontMatter, parseMarkdownContentTitle, parseMarkdownString, writeMarkdownHeadingId, type WriteHeadingIDOptions, } from './markdownUtils';
15
+ export { type ContentPaths, type BrokenMarkdownLink, replaceMarkdownLinks, } from './markdownLinks';
16
+ export { type SluggerOptions, type Slugger, createSlugger } from './slugger';
17
+ export { isNameTooLong, shortName, posixPath, toMessageRelativeFilePath, aliasedSitePath, escapePath, addTrailingPathSeparator, } from './pathUtils';
18
+ export { md5Hash, simpleHash, docuHash } from './hashUtils';
19
+ export { Globby, GlobExcludeDefault, createMatcher, createAbsoluteFilePathMatcher, } from './globUtils';
20
+ export { getFileLoaderUtils } from './webpackUtils';
21
+ export { escapeShellArg } from './shellUtils';
22
+ export { getDataFilePath, getDataFileData, getContentPathList, findFolderContainingFile, getFolderContainingFile, } from './dataFileUtils';
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,wBAAwB,EACxB,YAAY,EACZ,uBAAuB,EACvB,6BAA6B,EAC7B,UAAU,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACZ,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAC,QAAQ,EAAE,kBAAkB,EAAC,MAAM,aAAa,CAAC;AACzD,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,6BAA6B,EAC7B,iBAAiB,EACjB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,wBAAwB,EACxB,gBAAgB,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