@docusaurus/utils 3.4.0 → 3.5.0

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 (57) hide show
  1. package/lib/cliUtils.js +1 -2
  2. package/lib/cliUtils.js.map +1 -1
  3. package/lib/contentVisibilityUtils.js +2 -3
  4. package/lib/contentVisibilityUtils.js.map +1 -1
  5. package/lib/dataFileUtils.d.ts +6 -7
  6. package/lib/dataFileUtils.d.ts.map +1 -1
  7. package/lib/dataFileUtils.js +14 -14
  8. package/lib/dataFileUtils.js.map +1 -1
  9. package/lib/emitUtils.d.ts +0 -1
  10. package/lib/emitUtils.d.ts.map +1 -1
  11. package/lib/emitUtils.js +2 -3
  12. package/lib/emitUtils.js.map +1 -1
  13. package/lib/gitUtils.js +2 -2
  14. package/lib/gitUtils.js.map +1 -1
  15. package/lib/globUtils.js +3 -3
  16. package/lib/globUtils.js.map +1 -1
  17. package/lib/hashUtils.js +3 -4
  18. package/lib/hashUtils.js.map +1 -1
  19. package/lib/i18nUtils.js +4 -5
  20. package/lib/i18nUtils.js.map +1 -1
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +2 -2
  24. package/lib/index.js.map +1 -1
  25. package/lib/jsUtils.js +2 -3
  26. package/lib/jsUtils.js.map +1 -1
  27. package/lib/lastUpdateUtils.js +4 -4
  28. package/lib/lastUpdateUtils.js.map +1 -1
  29. package/lib/markdownLinks.js +1 -2
  30. package/lib/markdownLinks.js.map +1 -1
  31. package/lib/markdownUtils.js +12 -12
  32. package/lib/markdownUtils.js.map +1 -1
  33. package/lib/moduleUtils.js +1 -2
  34. package/lib/moduleUtils.js.map +1 -1
  35. package/lib/pathUtils.js +8 -8
  36. package/lib/pathUtils.js.map +1 -1
  37. package/lib/regExpUtils.js +1 -2
  38. package/lib/regExpUtils.js.map +1 -1
  39. package/lib/routeUtils.js +1 -2
  40. package/lib/routeUtils.js.map +1 -1
  41. package/lib/shellUtils.js +1 -2
  42. package/lib/shellUtils.js.map +1 -1
  43. package/lib/slugger.js +1 -2
  44. package/lib/slugger.js.map +1 -1
  45. package/lib/tags.d.ts +1 -1
  46. package/lib/tags.d.ts.map +1 -1
  47. package/lib/tags.js +5 -6
  48. package/lib/tags.js.map +1 -1
  49. package/lib/urlUtils.js +14 -15
  50. package/lib/urlUtils.js.map +1 -1
  51. package/lib/webpackUtils.js +2 -3
  52. package/lib/webpackUtils.js.map +1 -1
  53. package/package.json +5 -5
  54. package/src/dataFileUtils.ts +12 -14
  55. package/src/index.ts +1 -1
  56. package/src/markdownUtils.ts +2 -2
  57. package/src/tags.ts +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/utils",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Node utility functions for Docusaurus packages.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/logger": "3.4.0",
22
- "@docusaurus/utils-common": "3.4.0",
21
+ "@docusaurus/logger": "3.5.0",
22
+ "@docusaurus/utils-common": "3.5.0",
23
23
  "@svgr/webpack": "^8.1.0",
24
24
  "escape-string-regexp": "^4.0.0",
25
25
  "file-loader": "^6.2.0",
@@ -43,7 +43,7 @@
43
43
  "node": ">=18.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@docusaurus/types": "3.4.0",
46
+ "@docusaurus/types": "3.5.0",
47
47
  "@types/dedent": "^0.7.0",
48
48
  "@types/github-slugger": "^1.3.0",
49
49
  "@types/micromatch": "^4.0.2",
@@ -59,5 +59,5 @@
59
59
  "optional": true
60
60
  }
61
61
  },
62
- "gitHead": "49e9a2143274a8dd795659b417b470bc42abbd6e"
62
+ "gitHead": "cb5829f3c34b26d798b869e38ee25073488140bd"
63
63
  }
@@ -43,30 +43,28 @@ export async function getDataFilePath({
43
43
  }
44
44
 
45
45
  /**
46
- * Looks up for a data file in the content paths, returns the object validated
47
- * and normalized according to the `validate` callback.
46
+ * Looks up for a data file in the content paths
47
+ * Favors the localized content path over the base content path
48
+ * Currently supports Yaml and JSON data files
49
+ * It is the caller responsibility to validate and normalize the resulting data
48
50
  *
49
51
  * @returns `undefined` when file not found
50
- * @throws Throws when validation fails, displaying a helpful context message.
52
+ * @throws Throws when data file can't be parsed
51
53
  */
52
- export async function getDataFileData<T>(
53
- params: DataFileParams & {
54
- /** Used for the "The X file looks invalid" message. */
55
- fileType: string;
56
- },
57
- validate: (content: unknown) => T,
58
- ): Promise<T | undefined> {
54
+ export async function readDataFile(params: DataFileParams): Promise<unknown> {
59
55
  const filePath = await getDataFilePath(params);
60
56
  if (!filePath) {
61
57
  return undefined;
62
58
  }
63
59
  try {
64
60
  const contentString = await fs.readFile(filePath, {encoding: 'utf8'});
65
- const unsafeContent = Yaml.load(contentString);
66
- return validate(unsafeContent);
61
+ return Yaml.load(contentString);
67
62
  } catch (err) {
68
- logger.error`The ${params.fileType} file at path=${filePath} looks invalid.`;
69
- throw err;
63
+ const msg = logger.interpolate`The file at path=${path.relative(
64
+ process.cwd(),
65
+ filePath,
66
+ )} looks invalid (not Yaml nor JSON).`;
67
+ throw new Error(msg, {cause: err as Error});
70
68
  }
71
69
  }
72
70
 
package/src/index.ts CHANGED
@@ -109,7 +109,7 @@ export {escapeShellArg} from './shellUtils';
109
109
  export {loadFreshModule} from './moduleUtils';
110
110
  export {
111
111
  getDataFilePath,
112
- getDataFileData,
112
+ readDataFile,
113
113
  getContentPathList,
114
114
  findFolderContainingFile,
115
115
  getFolderContainingFile,
@@ -70,9 +70,9 @@ export function escapeMarkdownHeadingIds(content: string): string {
70
70
  export function unwrapMdxCodeBlocks(content: string): string {
71
71
  // We only support 3/4 backticks on purpose, should be good enough
72
72
  const regexp3 =
73
- /(?<begin>^|\r?\n)```(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n```(?<end>\r?\n|$)/gs;
73
+ /(?<begin>^|\r?\n)(?<indentStart>\x20*)```(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n(?<indentEnd>\x20*)```(?<end>\r?\n|$)/gs;
74
74
  const regexp4 =
75
- /(?<begin>^|\r?\n)````(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n````(?<end>\r?\n|$)/gs;
75
+ /(?<begin>^|\r?\n)(?<indentStart>\x20*)````(?<spaces>\x20*)mdx-code-block\r?\n(?<children>.*?)\r?\n(?<indentEnd>\x20*)````(?<end>\r?\n|$)/gs;
76
76
 
77
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
78
  const replacer = (substring: string, ...args: any[]) => {
package/src/tags.ts CHANGED
@@ -28,7 +28,7 @@ export type TagsPluginOptions = {
28
28
  // TODO allow option tags later? | TagsFile;
29
29
  /** Path to the tags file. */
30
30
  tags: string | false | null | undefined;
31
- /** The behavior of Docusaurus when it found inline tags. */
31
+ /** The behavior of Docusaurus when it finds inline tags. */
32
32
  onInlineTags: 'ignore' | 'log' | 'warn' | 'throw';
33
33
  };
34
34
 
@@ -45,6 +45,7 @@ export type TagsListItem = Tag & {
45
45
  /** What the tag's own page should know about the tag. */
46
46
  export type TagModule = TagsListItem & {
47
47
  /** The tags list page's permalink. */
48
+ // TODO move this global value to a shared docs/blog bundle
48
49
  allTagsPath: string;
49
50
  /** Is this tag unlisted? (when it only contains unlisted items) */
50
51
  unlisted: boolean;