@docusaurus/plugin-content-docs 0.0.0-5043 → 0.0.0-5048

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.js CHANGED
@@ -41,12 +41,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
41
41
  logger_1.default.info `${pluginIdLogPrefix}: Invalid version name provided. Try something like: 1.0.0`;
42
42
  throw err;
43
43
  }
44
- // Load existing versions.
45
- let versions = [];
46
- const versionsJSONFile = (0, files_1.getVersionsFilePath)(siteDir, pluginId);
47
- if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
48
- versions = await fs_extra_1.default.readJSON(versionsJSONFile);
49
- }
44
+ const versions = (await (0, files_1.readVersionsFile)(siteDir, pluginId)) ?? [];
50
45
  // Check if version already exists.
51
46
  if (versions.includes(version)) {
52
47
  throw new Error(`${pluginIdLogPrefix}: this version already exists! Use a version tag that does not already exist.`);
@@ -92,7 +87,7 @@ async function cliDocsVersionCommand(version, { id: pluginId, path: docsPath, si
92
87
  });
93
88
  // Update versions.json file.
94
89
  versions.unshift(version);
95
- await fs_extra_1.default.outputFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
90
+ await fs_extra_1.default.outputFile((0, files_1.getVersionsFilePath)(siteDir, pluginId), `${JSON.stringify(versions, null, 2)}\n`);
96
91
  logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
97
92
  }
98
93
  exports.cliDocsVersionCommand = cliDocsVersionCommand;
@@ -73,6 +73,6 @@ export function getActiveDocContext(data, pathname) {
73
73
  export function getDocVersionSuggestions(data, pathname) {
74
74
  const latestVersion = getLatestVersion(data);
75
75
  const activeDocContext = getActiveDocContext(data, pathname);
76
- const latestDocSuggestion = activeDocContext?.alternateDocVersions[latestVersion.name];
76
+ const latestDocSuggestion = activeDocContext.alternateDocVersions[latestVersion.name];
77
77
  return { latestDocSuggestion, latestVersionSuggestion: latestVersion };
78
78
  }
package/lib/index.js CHANGED
@@ -76,7 +76,7 @@ async function pluginContentDocs(context, options) {
76
76
  if (docFiles.length === 0) {
77
77
  throw new Error(`Docs version "${versionMetadata.versionName}" has no docs! At least one doc should exist at "${path_1.default.relative(siteDir, versionMetadata.contentPath)}".`);
78
78
  }
79
- async function processVersionDoc(docFile) {
79
+ function processVersionDoc(docFile) {
80
80
  return (0, docs_1.processDocMetadata)({
81
81
  docFile,
82
82
  versionMetadata,
@@ -11,6 +11,6 @@ function markdownLoader(source) {
11
11
  const fileString = source;
12
12
  const callback = this.async();
13
13
  const options = this.getOptions();
14
- return callback?.(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
14
+ return callback(null, (0, linkify_1.linkify)(fileString, this.resourcePath, options));
15
15
  }
16
16
  exports.default = markdownLoader;
package/lib/props.js CHANGED
@@ -26,7 +26,7 @@ Available document ids are:
26
26
  const { title, permalink, frontMatter: { sidebar_label: sidebarLabel }, } = docMetadata;
27
27
  return {
28
28
  type: 'link',
29
- label: sidebarLabel || item.label || title,
29
+ label: sidebarLabel ?? item.label ?? title,
30
30
  href: permalink,
31
31
  className: item.className,
32
32
  customProps: item.customProps ?? docMetadata.frontMatter.sidebar_custom_props,
@@ -21,7 +21,7 @@ function getLocalDocId(docId) {
21
21
  exports.CategoryMetadataFilenameBase = '_category_';
22
22
  exports.CategoryMetadataFilenamePattern = '_category_.{json,yml,yaml}';
23
23
  // Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
24
- const DefaultSidebarItemsGenerator = async ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
24
+ const DefaultSidebarItemsGenerator = ({ numberPrefixParser, isCategoryIndex, docs: allDocs, item: { dirName: autogenDir }, categoriesMetadata, }) => {
25
25
  const docsById = (0, docs_1.createDocsByIdIndex)(allDocs);
26
26
  const findDoc = (docId) => docsById[docId];
27
27
  const getDoc = (docId) => {
@@ -61,7 +61,7 @@ function postProcessSidebarItem(item, params) {
61
61
  };
62
62
  }
63
63
  // A non-collapsible category can't be collapsed!
64
- if (category.collapsible === false) {
64
+ if (!category.collapsible) {
65
65
  category.collapsed = false;
66
66
  }
67
67
  return category;
@@ -157,7 +157,7 @@ export declare type SidebarItemsGeneratorArgs = {
157
157
  [filePath: string]: CategoryMetadataFile;
158
158
  };
159
159
  };
160
- export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => Promise<NormalizedSidebar>;
160
+ export declare type SidebarItemsGenerator = (generatorArgs: SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
161
161
  export declare type SidebarItemsGeneratorOption = (generatorArgs: {
162
162
  /**
163
163
  * Useful to re-use/enhance the default sidebar generation logic from
@@ -165,7 +165,7 @@ export declare type SidebarItemsGeneratorOption = (generatorArgs: {
165
165
  * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320
166
166
  */
167
167
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
168
- } & SidebarItemsGeneratorArgs) => Promise<NormalizedSidebarItem[]>;
168
+ } & SidebarItemsGeneratorArgs) => NormalizedSidebar | Promise<NormalizedSidebar>;
169
169
  export declare type SidebarProcessorParams = {
170
170
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
171
171
  numberPrefixParser: NumberPrefixParser;
@@ -158,7 +158,7 @@ function createSidebarsUtils(sidebars) {
158
158
  function getCategoryGeneratedIndexNavigation(categoryGeneratedIndexPermalink) {
159
159
  function isCurrentCategoryGeneratedIndexItem(item) {
160
160
  return (item.type === 'category' &&
161
- item.link?.type === 'generated-index' &&
161
+ item.link.type === 'generated-index' &&
162
162
  item.link.permalink === categoryGeneratedIndexPermalink);
163
163
  }
164
164
  const sidebarName = Object.entries(sidebarNameToNavigationItems).find(([, navigationItems]) => navigationItems.find(isCurrentCategoryGeneratedIndexItem))[0];
@@ -133,6 +133,10 @@ const categoryMetadataFileSchema = utils_validation_1.Joi.object({
133
133
  customProps: utils_validation_1.Joi.object().unknown(),
134
134
  });
135
135
  function validateCategoryMetadataFile(unsafeContent) {
136
- return utils_validation_1.Joi.attempt(unsafeContent, categoryMetadataFileSchema);
136
+ const { error, value } = categoryMetadataFileSchema.validate(unsafeContent);
137
+ if (error) {
138
+ throw error;
139
+ }
140
+ return value;
137
141
  }
138
142
  exports.validateCategoryMetadataFile = validateCategoryMetadataFile;
package/lib/slug.js CHANGED
@@ -28,7 +28,7 @@ function getSlug({ baseID, frontMatterSlug, source, sourceDirName, stripDirNumbe
28
28
  (0, docs_1.isCategoryIndex)((0, docs_1.toCategoryIndexMatcherParam)({ source, sourceDirName }))) {
29
29
  return dirNameSlug;
30
30
  }
31
- const baseSlug = frontMatterSlug || baseID;
31
+ const baseSlug = frontMatterSlug ?? baseID;
32
32
  return (0, utils_1.resolvePathname)(baseSlug, getDirNameSlug());
33
33
  }
34
34
  function ensureValidSlug(slug) {
@@ -18,6 +18,13 @@ export declare function getDocsDirPathLocalized({ siteDir, locale, pluginId, ver
18
18
  }): string;
19
19
  /** `community` => `[siteDir]/community_versions.json` */
20
20
  export declare function getVersionsFilePath(siteDir: string, pluginId: string): string;
21
+ /**
22
+ * Reads the plugin's respective `versions.json` file, and returns its content.
23
+ *
24
+ * @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
25
+ * array of valid version names.
26
+ */
27
+ export declare function readVersionsFile(siteDir: string, pluginId: string): Promise<string[] | null>;
21
28
  /**
22
29
  * Reads the `versions.json` file, and returns an ordered list of version names.
23
30
  *
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getVersionMetadataPaths = exports.readVersionNames = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
9
+ exports.getVersionMetadataPaths = exports.readVersionNames = exports.readVersionsFile = exports.getVersionsFilePath = exports.getDocsDirPathLocalized = exports.getVersionSidebarsPath = exports.getVersionDocsDirPath = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
@@ -63,6 +63,7 @@ async function readVersionsFile(siteDir, pluginId) {
63
63
  }
64
64
  return null;
65
65
  }
66
+ exports.readVersionsFile = readVersionsFile;
66
67
  /**
67
68
  * Reads the `versions.json` file, and returns an ordered list of version names.
68
69
  *
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  function validateVersionName(name) {
13
13
  if (typeof name !== 'string') {
14
- throw new Error(`Versions should be strings. Found type "${typeof name}" for version "${name}".`);
14
+ throw new Error(`Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(name)}.`);
15
15
  }
16
16
  if (!name.trim()) {
17
17
  throw new Error(`Invalid version name "${name}": version name must contain at least one non-whitespace character.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-5043",
3
+ "version": "0.0.0-5048",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -25,11 +25,11 @@
25
25
  },
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "@docusaurus/core": "0.0.0-5043",
29
- "@docusaurus/logger": "0.0.0-5043",
30
- "@docusaurus/mdx-loader": "0.0.0-5043",
31
- "@docusaurus/utils": "0.0.0-5043",
32
- "@docusaurus/utils-validation": "0.0.0-5043",
28
+ "@docusaurus/core": "0.0.0-5048",
29
+ "@docusaurus/logger": "0.0.0-5048",
30
+ "@docusaurus/mdx-loader": "0.0.0-5048",
31
+ "@docusaurus/utils": "0.0.0-5048",
32
+ "@docusaurus/utils-validation": "0.0.0-5048",
33
33
  "combine-promises": "^1.1.0",
34
34
  "fs-extra": "^10.1.0",
35
35
  "import-fresh": "^3.3.0",
@@ -41,8 +41,8 @@
41
41
  "webpack": "^5.72.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@docusaurus/module-type-aliases": "0.0.0-5043",
45
- "@docusaurus/types": "0.0.0-5043",
44
+ "@docusaurus/module-type-aliases": "0.0.0-5048",
45
+ "@docusaurus/types": "0.0.0-5048",
46
46
  "@types/js-yaml": "^4.0.5",
47
47
  "@types/picomatch": "^2.3.0",
48
48
  "commander": "^5.1.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=14"
60
60
  },
61
- "gitHead": "28ad11cdb6c55b7a8355e327913f617d4fe359bd"
61
+ "gitHead": "f5680d2f2633fbd6594972ae1f4c1ddb1467f9ac"
62
62
  }
package/src/cli.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  getVersionDocsDirPath,
15
15
  getVersionSidebarsPath,
16
16
  getDocsDirPathLocalized,
17
+ readVersionsFile,
17
18
  } from './versions/files';
18
19
  import {validateVersionName} from './versions/validation';
19
20
  import {loadSidebarsFileUnsafe} from './sidebars';
@@ -69,12 +70,7 @@ export async function cliDocsVersionCommand(
69
70
  throw err;
70
71
  }
71
72
 
72
- // Load existing versions.
73
- let versions: string[] = [];
74
- const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
75
- if (await fs.pathExists(versionsJSONFile)) {
76
- versions = await fs.readJSON(versionsJSONFile);
77
- }
73
+ const versions = (await readVersionsFile(siteDir, pluginId)) ?? [];
78
74
 
79
75
  // Check if version already exists.
80
76
  if (versions.includes(version)) {
@@ -137,7 +133,7 @@ export async function cliDocsVersionCommand(
137
133
  // Update versions.json file.
138
134
  versions.unshift(version);
139
135
  await fs.outputFile(
140
- versionsJSONFile,
136
+ getVersionsFilePath(siteDir, pluginId),
141
137
  `${JSON.stringify(versions, null, 2)}\n`,
142
138
  );
143
139
 
@@ -126,6 +126,6 @@ export function getDocVersionSuggestions(
126
126
  const latestVersion = getLatestVersion(data);
127
127
  const activeDocContext = getActiveDocContext(data, pathname);
128
128
  const latestDocSuggestion: GlobalDoc | undefined =
129
- activeDocContext?.alternateDocVersions[latestVersion.name];
129
+ activeDocContext.alternateDocVersions[latestVersion.name];
130
130
  return {latestDocSuggestion, latestVersionSuggestion: latestVersion};
131
131
  }
@@ -34,9 +34,11 @@ const StableEmptyObject = {};
34
34
  // In blog-only mode, docs hooks are still used by the theme. We need a fail-
35
35
  // safe fallback when the docs plugin is not in use
36
36
  export const useAllDocsData = (): {[pluginId: string]: GlobalPluginData} =>
37
- (useAllPluginInstancesData('docusaurus-plugin-content-docs') as {
38
- [pluginId: string]: GlobalPluginData;
39
- }) ?? StableEmptyObject;
37
+ (useAllPluginInstancesData('docusaurus-plugin-content-docs') as
38
+ | {
39
+ [pluginId: string]: GlobalPluginData;
40
+ }
41
+ | undefined) ?? StableEmptyObject;
40
42
 
41
43
  export const useDocsData = (pluginId: string | undefined): GlobalPluginData =>
42
44
  usePluginData('docusaurus-plugin-content-docs', pluginId, {
package/src/index.ts CHANGED
@@ -143,7 +143,7 @@ export default async function pluginContentDocs(
143
143
  )}".`,
144
144
  );
145
145
  }
146
- async function processVersionDoc(docFile: DocFile) {
146
+ function processVersionDoc(docFile: DocFile) {
147
147
  return processDocMetadata({
148
148
  docFile,
149
149
  versionMetadata,
@@ -16,5 +16,5 @@ export default function markdownLoader(
16
16
  const fileString = source;
17
17
  const callback = this.async();
18
18
  const options = this.getOptions();
19
- return callback?.(null, linkify(fileString, this.resourcePath, options));
19
+ return callback(null, linkify(fileString, this.resourcePath, options));
20
20
  }
package/src/options.ts CHANGED
@@ -165,7 +165,7 @@ export function validateOptions({
165
165
  }
166
166
  }
167
167
 
168
- const normalizedOptions = validate(OptionsSchema, options) as PluginOptions;
168
+ const normalizedOptions = validate(OptionsSchema, options);
169
169
 
170
170
  if (normalizedOptions.admonitions) {
171
171
  normalizedOptions.remarkPlugins = normalizedOptions.remarkPlugins.concat([
package/src/props.ts CHANGED
@@ -51,7 +51,7 @@ Available document ids are:
51
51
  } = docMetadata;
52
52
  return {
53
53
  type: 'link',
54
- label: sidebarLabel || item.label || title,
54
+ label: sidebarLabel ?? item.label ?? title,
55
55
  href: permalink,
56
56
  className: item.className,
57
57
  customProps:
@@ -46,7 +46,7 @@ type Dir = {
46
46
  };
47
47
 
48
48
  // Comment for this feature: https://github.com/facebook/docusaurus/issues/3464#issuecomment-818670449
49
- export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = async ({
49
+ export const DefaultSidebarItemsGenerator: SidebarItemsGenerator = ({
50
50
  numberPrefixParser,
51
51
  isCategoryIndex,
52
52
  docs: allDocs,
@@ -84,7 +84,7 @@ function postProcessSidebarItem(
84
84
  };
85
85
  }
86
86
  // A non-collapsible category can't be collapsed!
87
- if (category.collapsible === false) {
87
+ if (!category.collapsible) {
88
88
  category.collapsed = false;
89
89
  }
90
90
  return category;
@@ -251,7 +251,7 @@ export type SidebarItemsGeneratorArgs = {
251
251
  };
252
252
  export type SidebarItemsGenerator = (
253
253
  generatorArgs: SidebarItemsGeneratorArgs,
254
- ) => Promise<NormalizedSidebar>;
254
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
255
255
 
256
256
  export type SidebarItemsGeneratorOption = (
257
257
  generatorArgs: {
@@ -262,7 +262,7 @@ export type SidebarItemsGeneratorOption = (
262
262
  */
263
263
  defaultSidebarItemsGenerator: SidebarItemsGenerator;
264
264
  } & SidebarItemsGeneratorArgs,
265
- ) => Promise<NormalizedSidebarItem[]>;
265
+ ) => NormalizedSidebar | Promise<NormalizedSidebar>;
266
266
 
267
267
  export type SidebarProcessorParams = {
268
268
  sidebarItemsGenerator: SidebarItemsGeneratorOption;
@@ -257,7 +257,7 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
257
257
  ): boolean {
258
258
  return (
259
259
  item.type === 'category' &&
260
- item.link?.type === 'generated-index' &&
260
+ item.link.type === 'generated-index' &&
261
261
  item.link.permalink === categoryGeneratedIndexPermalink
262
262
  );
263
263
  }
@@ -144,7 +144,7 @@ function validateSidebarItem(
144
144
  // manually
145
145
  Joi.assert(item, sidebarItemSchema);
146
146
 
147
- if ((item as NormalizedSidebarItemCategory).type === 'category') {
147
+ if ((item as NormalizedSidebarItem).type === 'category') {
148
148
  (item as NormalizedSidebarItemCategory).items.forEach(validateSidebarItem);
149
149
  }
150
150
  }
@@ -170,5 +170,9 @@ const categoryMetadataFileSchema = Joi.object<CategoryMetadataFile>({
170
170
  export function validateCategoryMetadataFile(
171
171
  unsafeContent: unknown,
172
172
  ): CategoryMetadataFile {
173
- return Joi.attempt(unsafeContent, categoryMetadataFileSchema);
173
+ const {error, value} = categoryMetadataFileSchema.validate(unsafeContent);
174
+ if (error) {
175
+ throw error;
176
+ }
177
+ return value;
174
178
  }
package/src/slug.ts CHANGED
@@ -58,7 +58,7 @@ export default function getSlug({
58
58
  ) {
59
59
  return dirNameSlug;
60
60
  }
61
- const baseSlug = frontMatterSlug || baseID;
61
+ const baseSlug = frontMatterSlug ?? baseID;
62
62
  return resolvePathname(baseSlug, getDirNameSlug());
63
63
  }
64
64
 
@@ -89,7 +89,7 @@ export function getVersionsFilePath(siteDir: string, pluginId: string): string {
89
89
  * @throws Throws if validation fails, i.e. `versions.json` doesn't contain an
90
90
  * array of valid version names.
91
91
  */
92
- async function readVersionsFile(
92
+ export async function readVersionsFile(
93
93
  siteDir: string,
94
94
  pluginId: string,
95
95
  ): Promise<string[] | null> {
@@ -11,7 +11,9 @@ import type {VersionsOptions} from '@docusaurus/plugin-content-docs';
11
11
  export function validateVersionName(name: unknown): asserts name is string {
12
12
  if (typeof name !== 'string') {
13
13
  throw new Error(
14
- `Versions should be strings. Found type "${typeof name}" for version "${name}".`,
14
+ `Versions should be strings. Found type "${typeof name}" for version ${JSON.stringify(
15
+ name,
16
+ )}.`,
15
17
  );
16
18
  }
17
19
  if (!name.trim()) {