@docusaurus/plugin-content-docs 0.0.0-4364 → 0.0.0-4375

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/index.js CHANGED
@@ -28,7 +28,7 @@ const categoryGeneratedIndex_1 = require("./categoryGeneratedIndex");
28
28
  async function pluginContentDocs(context, options) {
29
29
  var _a;
30
30
  const { siteDir, generatedFilesDir, baseUrl, siteConfig } = context;
31
- const versionsMetadata = (0, versions_1.readVersionsMetadata)({ context, options });
31
+ const versionsMetadata = await (0, versions_1.readVersionsMetadata)({ context, options });
32
32
  const pluginId = (_a = options.id) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PLUGIN_ID;
33
33
  const pluginDataDirRoot = path_1.default.join(generatedFilesDir, 'docusaurus-plugin-content-docs');
34
34
  const dataDir = path_1.default.join(pluginDataDirRoot, pluginId);
package/lib/versions.d.ts CHANGED
@@ -12,5 +12,5 @@ export declare function getVersionsFilePath(siteDir: string, pluginId: string):
12
12
  export declare function readVersionsMetadata({ context, options, }: {
13
13
  context: Pick<LoadContext, 'siteDir' | 'baseUrl' | 'i18n'>;
14
14
  options: Pick<PluginOptions, 'id' | 'path' | 'sidebarPath' | 'routeBasePath' | 'tagsBasePath' | 'includeCurrentVersion' | 'disableVersioning' | 'lastVersion' | 'versions' | 'onlyIncludeVersions' | 'editUrl' | 'editCurrentVersion'>;
15
- }): VersionMetadata[];
15
+ }): Promise<VersionMetadata[]>;
16
16
  export declare function getDocsDirPaths(versionMetadata: Pick<VersionMetadata, 'contentPath' | 'contentPathLocalized'>): [string, string];
package/lib/versions.js CHANGED
@@ -50,11 +50,10 @@ function ensureValidVersionArray(versionArray) {
50
50
  }
51
51
  versionArray.forEach(ensureValidVersionString);
52
52
  }
53
- // TODO not easy to make async due to many deps
54
- function readVersionsFile(siteDir, pluginId) {
53
+ async function readVersionsFile(siteDir, pluginId) {
55
54
  const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
56
- if (fs_extra_1.default.existsSync(versionsFilePath)) {
57
- const content = JSON.parse(fs_extra_1.default.readFileSync(versionsFilePath, 'utf8'));
55
+ if (await fs_extra_1.default.pathExists(versionsFilePath)) {
56
+ const content = JSON.parse(await fs_extra_1.default.readFile(versionsFilePath, 'utf8'));
58
57
  ensureValidVersionArray(content);
59
58
  return content;
60
59
  }
@@ -62,22 +61,21 @@ function readVersionsFile(siteDir, pluginId) {
62
61
  return null;
63
62
  }
64
63
  }
65
- // TODO not easy to make async due to many deps
66
- function readVersionNames(siteDir, options) {
67
- const versionFileContent = readVersionsFile(siteDir, options.id);
64
+ async function readVersionNames(siteDir, options) {
65
+ const versionFileContent = await readVersionsFile(siteDir, options.id);
68
66
  if (!versionFileContent && options.disableVersioning) {
69
- throw new Error(`Docs: using "disableVersioning=${options.disableVersioning}" option on a non-versioned site does not make sense.`);
67
+ throw new Error(`Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`);
70
68
  }
71
69
  const versions = options.disableVersioning ? [] : versionFileContent !== null && versionFileContent !== void 0 ? versionFileContent : [];
72
- // We add the current version at the beginning, unless
73
- // - user don't want to
74
- // - it's been explicitly added to versions.json
70
+ // We add the current version at the beginning, unless:
71
+ // - user don't want to; or
72
+ // - it's already been explicitly added to versions.json
75
73
  if (options.includeCurrentVersion &&
76
74
  !versions.includes(constants_1.CURRENT_VERSION_NAME)) {
77
75
  versions.unshift(constants_1.CURRENT_VERSION_NAME);
78
76
  }
79
77
  if (versions.length === 0) {
80
- throw new Error(`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion=${options.includeCurrentVersion}", "disableVersioning=${options.disableVersioning}".`);
78
+ throw new Error(`It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion: ${options.includeCurrentVersion}", "disableVersioning: ${options.disableVersioning}".`);
81
79
  }
82
80
  return versions;
83
81
  }
@@ -96,27 +94,23 @@ function getDocsDirPathLocalized({ siteDir, locale, pluginId, versionName, }) {
96
94
  }
97
95
  function getVersionMetadataPaths({ versionName, context, options, }) {
98
96
  const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
99
- const contentPath = isCurrentVersion
100
- ? path_1.default.resolve(context.siteDir, options.path)
101
- : path_1.default.join(getVersionedDocsDirPath(context.siteDir, options.id), `version-${versionName}`);
102
97
  const contentPathLocalized = getDocsDirPathLocalized({
103
98
  siteDir: context.siteDir,
104
99
  locale: context.i18n.currentLocale,
105
100
  pluginId: options.id,
106
101
  versionName,
107
102
  });
108
- function getSidebarFilePath() {
109
- if (isCurrentVersion) {
110
- return (0, sidebars_1.resolveSidebarPathOption)(context.siteDir, options.sidebarPath);
111
- }
112
- else {
113
- return path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`);
114
- }
103
+ if (isCurrentVersion) {
104
+ return {
105
+ contentPath: path_1.default.resolve(context.siteDir, options.path),
106
+ contentPathLocalized,
107
+ sidebarFilePath: (0, sidebars_1.resolveSidebarPathOption)(context.siteDir, options.sidebarPath),
108
+ };
115
109
  }
116
110
  return {
117
- contentPath,
111
+ contentPath: path_1.default.join(getVersionedDocsDirPath(context.siteDir, options.id), `version-${versionName}`),
118
112
  contentPathLocalized,
119
- sidebarFilePath: getSidebarFilePath(),
113
+ sidebarFilePath: path_1.default.join(getVersionedSidebarsDirPath(context.siteDir, options.id), `version-${versionName}-sidebars.json`),
120
114
  };
121
115
  }
122
116
  function getVersionEditUrls({ contentPath, contentPathLocalized, context: { siteDir, i18n }, options: { id, path: currentVersionPath, editUrl, editCurrentVersion }, }) {
@@ -262,7 +256,7 @@ function checkVersionMetadataPaths({ versionMetadata, context, }) {
262
256
  Please set the docs "sidebarPath" field in your config file to:
263
257
  - a sidebars path that exists
264
258
  - false: to disable the sidebar
265
- - undefined: for Docusaurus generates it automatically`);
259
+ - undefined: for Docusaurus to generate it automatically`);
266
260
  }
267
261
  }
268
262
  // TODO for retrocompatibility with existing behavior
@@ -280,7 +274,7 @@ function checkVersionsOptions(availableVersionNames, options) {
280
274
  const availableVersionNamesMsg = `Available version names are: ${availableVersionNames.join(', ')}`;
281
275
  if (options.lastVersion &&
282
276
  !availableVersionNames.includes(options.lastVersion)) {
283
- throw new Error(`Docs option lastVersion=${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
277
+ throw new Error(`Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`);
284
278
  }
285
279
  const unknownVersionConfigNames = (0, lodash_1.difference)(Object.keys(options.versions), availableVersionNames);
286
280
  if (unknownVersionConfigNames.length > 0) {
@@ -300,9 +294,11 @@ function checkVersionsOptions(availableVersionNames, options) {
300
294
  }
301
295
  }
302
296
  }
303
- // Filter versions according to provided options
304
- // Note: we preserve the order in which versions are provided
305
- // the order of the onlyIncludeVersions array does not matter
297
+ /**
298
+ * Filter versions according to provided options.
299
+ * Note: we preserve the order in which versions are provided;
300
+ * the order of the onlyIncludeVersions array does not matter
301
+ */
306
302
  function filterVersions(versionNamesUnfiltered, options) {
307
303
  if (options.onlyIncludeVersions) {
308
304
  return versionNamesUnfiltered.filter((name) => (options.onlyIncludeVersions || []).includes(name));
@@ -311,10 +307,9 @@ function filterVersions(versionNamesUnfiltered, options) {
311
307
  return versionNamesUnfiltered;
312
308
  }
313
309
  }
314
- // TODO make this async (requires plugin init to be async)
315
- function readVersionsMetadata({ context, options, }) {
310
+ async function readVersionsMetadata({ context, options, }) {
316
311
  var _a;
317
- const versionNamesUnfiltered = readVersionNames(context.siteDir, options);
312
+ const versionNamesUnfiltered = await readVersionNames(context.siteDir, options);
318
313
  checkVersionsOptions(versionNamesUnfiltered, options);
319
314
  const versionNames = filterVersions(versionNamesUnfiltered, options);
320
315
  const lastVersionName = (_a = options.lastVersion) !== null && _a !== void 0 ? _a : getDefaultLastVersionName(versionNames);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4364",
3
+ "version": "0.0.0-4375",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/plugin-content-docs.d.ts",
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/core": "0.0.0-4364",
22
- "@docusaurus/logger": "0.0.0-4364",
23
- "@docusaurus/mdx-loader": "0.0.0-4364",
24
- "@docusaurus/utils": "0.0.0-4364",
25
- "@docusaurus/utils-validation": "0.0.0-4364",
21
+ "@docusaurus/core": "0.0.0-4375",
22
+ "@docusaurus/logger": "0.0.0-4375",
23
+ "@docusaurus/mdx-loader": "0.0.0-4375",
24
+ "@docusaurus/utils": "0.0.0-4375",
25
+ "@docusaurus/utils-validation": "0.0.0-4375",
26
26
  "combine-promises": "^1.1.0",
27
27
  "escape-string-regexp": "^4.0.0",
28
28
  "fs-extra": "^10.0.0",
@@ -38,8 +38,8 @@
38
38
  "webpack": "^5.61.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@docusaurus/module-type-aliases": "0.0.0-4364",
42
- "@docusaurus/types": "0.0.0-4364",
41
+ "@docusaurus/module-type-aliases": "0.0.0-4375",
42
+ "@docusaurus/types": "0.0.0-4375",
43
43
  "@types/js-yaml": "^4.0.0",
44
44
  "@types/picomatch": "^2.2.1",
45
45
  "commander": "^5.1.0",
@@ -53,5 +53,5 @@
53
53
  "engines": {
54
54
  "node": ">=14"
55
55
  },
56
- "gitHead": "db9cb5ab444107d56734f4e8405721484197d0a9"
56
+ "gitHead": "5738b5a5cb1c7446430167058e8d246fe6b596de"
57
57
  }
package/src/index.ts CHANGED
@@ -64,7 +64,7 @@ export default async function pluginContentDocs(
64
64
  ): Promise<Plugin<LoadedContent>> {
65
65
  const {siteDir, generatedFilesDir, baseUrl, siteConfig} = context;
66
66
 
67
- const versionsMetadata = readVersionsMetadata({context, options});
67
+ const versionsMetadata = await readVersionsMetadata({context, options});
68
68
 
69
69
  const pluginId = options.id ?? DEFAULT_PLUGIN_ID;
70
70
 
package/src/versions.ts CHANGED
@@ -87,11 +87,13 @@ function ensureValidVersionArray(
87
87
  versionArray.forEach(ensureValidVersionString);
88
88
  }
89
89
 
90
- // TODO not easy to make async due to many deps
91
- function readVersionsFile(siteDir: string, pluginId: string): string[] | null {
90
+ async function readVersionsFile(
91
+ siteDir: string,
92
+ pluginId: string,
93
+ ): Promise<string[] | null> {
92
94
  const versionsFilePath = getVersionsFilePath(siteDir, pluginId);
93
- if (fs.existsSync(versionsFilePath)) {
94
- const content = JSON.parse(fs.readFileSync(versionsFilePath, 'utf8'));
95
+ if (await fs.pathExists(versionsFilePath)) {
96
+ const content = JSON.parse(await fs.readFile(versionsFilePath, 'utf8'));
95
97
  ensureValidVersionArray(content);
96
98
  return content;
97
99
  } else {
@@ -99,27 +101,26 @@ function readVersionsFile(siteDir: string, pluginId: string): string[] | null {
99
101
  }
100
102
  }
101
103
 
102
- // TODO not easy to make async due to many deps
103
- function readVersionNames(
104
+ async function readVersionNames(
104
105
  siteDir: string,
105
106
  options: Pick<
106
107
  PluginOptions,
107
108
  'id' | 'disableVersioning' | 'includeCurrentVersion'
108
109
  >,
109
- ): string[] {
110
- const versionFileContent = readVersionsFile(siteDir, options.id);
110
+ ): Promise<string[]> {
111
+ const versionFileContent = await readVersionsFile(siteDir, options.id);
111
112
 
112
113
  if (!versionFileContent && options.disableVersioning) {
113
114
  throw new Error(
114
- `Docs: using "disableVersioning=${options.disableVersioning}" option on a non-versioned site does not make sense.`,
115
+ `Docs: using "disableVersioning: ${options.disableVersioning}" option on a non-versioned site does not make sense.`,
115
116
  );
116
117
  }
117
118
 
118
119
  const versions = options.disableVersioning ? [] : versionFileContent ?? [];
119
120
 
120
- // We add the current version at the beginning, unless
121
- // - user don't want to
122
- // - it's been explicitly added to versions.json
121
+ // We add the current version at the beginning, unless:
122
+ // - user don't want to; or
123
+ // - it's already been explicitly added to versions.json
123
124
  if (
124
125
  options.includeCurrentVersion &&
125
126
  !versions.includes(CURRENT_VERSION_NAME)
@@ -129,7 +130,7 @@ function readVersionNames(
129
130
 
130
131
  if (versions.length === 0) {
131
132
  throw new Error(
132
- `It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion=${options.includeCurrentVersion}", "disableVersioning=${options.disableVersioning}".`,
133
+ `It is not possible to use docs without any version. Please check the configuration of these options: "includeCurrentVersion: ${options.includeCurrentVersion}", "disableVersioning: ${options.disableVersioning}".`,
133
134
  );
134
135
  }
135
136
 
@@ -174,13 +175,6 @@ function getVersionMetadataPaths({
174
175
  > {
175
176
  const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
176
177
 
177
- const contentPath = isCurrentVersion
178
- ? path.resolve(context.siteDir, options.path)
179
- : path.join(
180
- getVersionedDocsDirPath(context.siteDir, options.id),
181
- `version-${versionName}`,
182
- );
183
-
184
178
  const contentPathLocalized = getDocsDirPathLocalized({
185
179
  siteDir: context.siteDir,
186
180
  locale: context.i18n.currentLocale,
@@ -188,21 +182,27 @@ function getVersionMetadataPaths({
188
182
  versionName,
189
183
  });
190
184
 
191
- function getSidebarFilePath() {
192
- if (isCurrentVersion) {
193
- return resolveSidebarPathOption(context.siteDir, options.sidebarPath);
194
- } else {
195
- return path.join(
196
- getVersionedSidebarsDirPath(context.siteDir, options.id),
197
- `version-${versionName}-sidebars.json`,
198
- );
199
- }
185
+ if (isCurrentVersion) {
186
+ return {
187
+ contentPath: path.resolve(context.siteDir, options.path),
188
+ contentPathLocalized,
189
+ sidebarFilePath: resolveSidebarPathOption(
190
+ context.siteDir,
191
+ options.sidebarPath,
192
+ ),
193
+ };
200
194
  }
201
195
 
202
196
  return {
203
- contentPath,
197
+ contentPath: path.join(
198
+ getVersionedDocsDirPath(context.siteDir, options.id),
199
+ `version-${versionName}`,
200
+ ),
204
201
  contentPathLocalized,
205
- sidebarFilePath: getSidebarFilePath(),
202
+ sidebarFilePath: path.join(
203
+ getVersionedSidebarsDirPath(context.siteDir, options.id),
204
+ `version-${versionName}-sidebars.json`,
205
+ ),
206
206
  };
207
207
  }
208
208
 
@@ -459,7 +459,7 @@ function checkVersionMetadataPaths({
459
459
  Please set the docs "sidebarPath" field in your config file to:
460
460
  - a sidebars path that exists
461
461
  - false: to disable the sidebar
462
- - undefined: for Docusaurus generates it automatically`);
462
+ - undefined: for Docusaurus to generate it automatically`);
463
463
  }
464
464
  }
465
465
 
@@ -488,7 +488,7 @@ function checkVersionsOptions(
488
488
  !availableVersionNames.includes(options.lastVersion)
489
489
  ) {
490
490
  throw new Error(
491
- `Docs option lastVersion=${options.lastVersion} is invalid. ${availableVersionNamesMsg}`,
491
+ `Docs option lastVersion: ${options.lastVersion} is invalid. ${availableVersionNamesMsg}`,
492
492
  );
493
493
  }
494
494
  const unknownVersionConfigNames = difference(
@@ -531,9 +531,11 @@ function checkVersionsOptions(
531
531
  }
532
532
  }
533
533
 
534
- // Filter versions according to provided options
535
- // Note: we preserve the order in which versions are provided
536
- // the order of the onlyIncludeVersions array does not matter
534
+ /**
535
+ * Filter versions according to provided options.
536
+ * Note: we preserve the order in which versions are provided;
537
+ * the order of the onlyIncludeVersions array does not matter
538
+ */
537
539
  function filterVersions(
538
540
  versionNamesUnfiltered: string[],
539
541
  options: Pick<PluginOptions, 'onlyIncludeVersions'>,
@@ -547,8 +549,7 @@ function filterVersions(
547
549
  }
548
550
  }
549
551
 
550
- // TODO make this async (requires plugin init to be async)
551
- export function readVersionsMetadata({
552
+ export async function readVersionsMetadata({
552
553
  context,
553
554
  options,
554
555
  }: {
@@ -568,8 +569,11 @@ export function readVersionsMetadata({
568
569
  | 'editUrl'
569
570
  | 'editCurrentVersion'
570
571
  >;
571
- }): VersionMetadata[] {
572
- const versionNamesUnfiltered = readVersionNames(context.siteDir, options);
572
+ }): Promise<VersionMetadata[]> {
573
+ const versionNamesUnfiltered = await readVersionNames(
574
+ context.siteDir,
575
+ options,
576
+ );
573
577
 
574
578
  checkVersionsOptions(versionNamesUnfiltered, options);
575
579