@docusaurus/plugin-content-docs 0.0.0-4610 → 0.0.0-4611

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
@@ -26,8 +26,8 @@ async function createVersionedSidebarFile({ siteDir, pluginId, sidebarPath, vers
26
26
  if (shouldCreateVersionedSidebarFile) {
27
27
  const versionedSidebarsDir = (0, versions_1.getVersionedSidebarsDirPath)(siteDir, pluginId);
28
28
  const newSidebarFile = path_1.default.join(versionedSidebarsDir, `version-${version}-sidebars.json`);
29
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(newSidebarFile));
30
- fs_extra_1.default.writeFileSync(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
29
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(newSidebarFile));
30
+ await fs_extra_1.default.writeFile(newSidebarFile, `${JSON.stringify(sidebars, null, 2)}\n`, 'utf8');
31
31
  }
32
32
  }
33
33
  // Tests depend on non-default export for mocking.
@@ -56,8 +56,8 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
56
56
  // Load existing versions.
57
57
  let versions = [];
58
58
  const versionsJSONFile = (0, versions_1.getVersionsFilePath)(siteDir, pluginId);
59
- if (fs_extra_1.default.existsSync(versionsJSONFile)) {
60
- versions = JSON.parse(fs_extra_1.default.readFileSync(versionsJSONFile, 'utf8'));
59
+ if (await fs_extra_1.default.pathExists(versionsJSONFile)) {
60
+ versions = JSON.parse(await fs_extra_1.default.readFile(versionsJSONFile, 'utf8'));
61
61
  }
62
62
  // Check if version already exists.
63
63
  if (versions.includes(version)) {
@@ -66,10 +66,11 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
66
66
  const { path: docsPath, sidebarPath } = options;
67
67
  // Copy docs files.
68
68
  const docsDir = path_1.default.join(siteDir, docsPath);
69
- if (fs_extra_1.default.existsSync(docsDir) && fs_extra_1.default.readdirSync(docsDir).length > 0) {
69
+ if ((await fs_extra_1.default.pathExists(docsDir)) &&
70
+ (await fs_extra_1.default.readdir(docsDir)).length > 0) {
70
71
  const versionedDir = (0, versions_1.getVersionedDocsDirPath)(siteDir, pluginId);
71
72
  const newVersionDir = path_1.default.join(versionedDir, `version-${version}`);
72
- fs_extra_1.default.copySync(docsDir, newVersionDir);
73
+ await fs_extra_1.default.copy(docsDir, newVersionDir);
73
74
  }
74
75
  else {
75
76
  throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
@@ -82,8 +83,8 @@ async function cliDocsVersionCommand(version, siteDir, pluginId, options) {
82
83
  });
83
84
  // Update versions.json file.
84
85
  versions.unshift(version);
85
- fs_extra_1.default.ensureDirSync(path_1.default.dirname(versionsJSONFile));
86
- fs_extra_1.default.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
86
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(versionsJSONFile));
87
+ await fs_extra_1.default.writeFile(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
87
88
  logger_1.default.success `name=${pluginIdLogPrefix}: version name=${version} created!`;
88
89
  }
89
90
  exports.cliDocsVersionCommand = cliDocsVersionCommand;
@@ -69,7 +69,7 @@ async function loadSidebarsFileUnsafe(sidebarFilePath) {
69
69
  // Non-existent sidebars file: no sidebars
70
70
  // Note: this edge case can happen on versioned docs, not current version
71
71
  // We avoid creating empty versioned sidebars file with the CLI
72
- if (!fs_extra_1.default.existsSync(sidebarFilePath)) {
72
+ if (!(await fs_extra_1.default.pathExists(sidebarFilePath))) {
73
73
  return exports.DisabledSidebars;
74
74
  }
75
75
  // We don't want sidebars to be cached because of hot reloading.
package/lib/versions.js CHANGED
@@ -236,11 +236,11 @@ function createVersionMetadata({ versionName, versionNames, lastVersionName, con
236
236
  contentPathLocalized,
237
237
  };
238
238
  }
239
- function checkVersionMetadataPaths({ versionMetadata, context, }) {
239
+ async function checkVersionMetadataPaths({ versionMetadata, context, }) {
240
240
  const { versionName, contentPath, sidebarFilePath } = versionMetadata;
241
241
  const { siteDir } = context;
242
242
  const isCurrentVersion = versionName === constants_1.CURRENT_VERSION_NAME;
243
- if (!fs_extra_1.default.existsSync(contentPath)) {
243
+ if (!(await fs_extra_1.default.pathExists(contentPath))) {
244
244
  throw new Error(`The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path_1.default.relative(siteDir, contentPath)}.`);
245
245
  }
246
246
  // If the current version defines a path to a sidebar file that does not
@@ -250,7 +250,7 @@ function checkVersionMetadataPaths({ versionMetadata, context, }) {
250
250
  // See https://github.com/facebook/docusaurus/pull/4775
251
251
  if (isCurrentVersion &&
252
252
  typeof sidebarFilePath === 'string' &&
253
- !fs_extra_1.default.existsSync(sidebarFilePath)) {
253
+ !(await fs_extra_1.default.pathExists(sidebarFilePath))) {
254
254
  throw new Error(`The path to the sidebar file does not exist at "${path_1.default.relative(siteDir, sidebarFilePath)}".
255
255
  Please set the docs "sidebarPath" field in your config file to:
256
256
  - a sidebars path that exists
@@ -316,7 +316,7 @@ async function readVersionsMetadata({ context, options, }) {
316
316
  context,
317
317
  options,
318
318
  }));
319
- versionsMetadata.forEach((versionMetadata) => checkVersionMetadataPaths({ versionMetadata, context }));
319
+ await Promise.all(versionsMetadata.map((versionMetadata) => checkVersionMetadataPaths({ versionMetadata, context })));
320
320
  return versionsMetadata;
321
321
  }
322
322
  exports.readVersionsMetadata = readVersionsMetadata;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-4610",
3
+ "version": "0.0.0-4611",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
- "@docusaurus/core": "0.0.0-4610",
27
- "@docusaurus/logger": "0.0.0-4610",
28
- "@docusaurus/mdx-loader": "0.0.0-4610",
29
- "@docusaurus/utils": "0.0.0-4610",
30
- "@docusaurus/utils-validation": "0.0.0-4610",
26
+ "@docusaurus/core": "0.0.0-4611",
27
+ "@docusaurus/logger": "0.0.0-4611",
28
+ "@docusaurus/mdx-loader": "0.0.0-4611",
29
+ "@docusaurus/utils": "0.0.0-4611",
30
+ "@docusaurus/utils-validation": "0.0.0-4611",
31
31
  "combine-promises": "^1.1.0",
32
32
  "fs-extra": "^10.0.0",
33
33
  "import-fresh": "^3.3.0",
@@ -39,8 +39,8 @@
39
39
  "webpack": "^5.69.1"
40
40
  },
41
41
  "devDependencies": {
42
- "@docusaurus/module-type-aliases": "0.0.0-4610",
43
- "@docusaurus/types": "0.0.0-4610",
42
+ "@docusaurus/module-type-aliases": "0.0.0-4611",
43
+ "@docusaurus/types": "0.0.0-4611",
44
44
  "@types/js-yaml": "^4.0.5",
45
45
  "@types/picomatch": "^2.3.0",
46
46
  "commander": "^5.1.0",
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=14"
58
58
  },
59
- "gitHead": "3208d225c0366f7a46f6f9ecf622cf2e1f9a3018"
59
+ "gitHead": "6a09283902da2fc8e205f36a018b80d8c8140d1f"
60
60
  }
package/src/cli.ts CHANGED
@@ -47,8 +47,8 @@ async function createVersionedSidebarFile({
47
47
  versionedSidebarsDir,
48
48
  `version-${version}-sidebars.json`,
49
49
  );
50
- fs.ensureDirSync(path.dirname(newSidebarFile));
51
- fs.writeFileSync(
50
+ await fs.ensureDir(path.dirname(newSidebarFile));
51
+ await fs.writeFile(
52
52
  newSidebarFile,
53
53
  `${JSON.stringify(sidebars, null, 2)}\n`,
54
54
  'utf8',
@@ -104,8 +104,8 @@ export async function cliDocsVersionCommand(
104
104
  // Load existing versions.
105
105
  let versions = [];
106
106
  const versionsJSONFile = getVersionsFilePath(siteDir, pluginId);
107
- if (fs.existsSync(versionsJSONFile)) {
108
- versions = JSON.parse(fs.readFileSync(versionsJSONFile, 'utf8'));
107
+ if (await fs.pathExists(versionsJSONFile)) {
108
+ versions = JSON.parse(await fs.readFile(versionsJSONFile, 'utf8'));
109
109
  }
110
110
 
111
111
  // Check if version already exists.
@@ -120,10 +120,13 @@ export async function cliDocsVersionCommand(
120
120
  // Copy docs files.
121
121
  const docsDir = path.join(siteDir, docsPath);
122
122
 
123
- if (fs.existsSync(docsDir) && fs.readdirSync(docsDir).length > 0) {
123
+ if (
124
+ (await fs.pathExists(docsDir)) &&
125
+ (await fs.readdir(docsDir)).length > 0
126
+ ) {
124
127
  const versionedDir = getVersionedDocsDirPath(siteDir, pluginId);
125
128
  const newVersionDir = path.join(versionedDir, `version-${version}`);
126
- fs.copySync(docsDir, newVersionDir);
129
+ await fs.copy(docsDir, newVersionDir);
127
130
  } else {
128
131
  throw new Error(`${pluginIdLogPrefix}: there is no docs to version!`);
129
132
  }
@@ -137,8 +140,11 @@ export async function cliDocsVersionCommand(
137
140
 
138
141
  // Update versions.json file.
139
142
  versions.unshift(version);
140
- fs.ensureDirSync(path.dirname(versionsJSONFile));
141
- fs.writeFileSync(versionsJSONFile, `${JSON.stringify(versions, null, 2)}\n`);
143
+ await fs.ensureDir(path.dirname(versionsJSONFile));
144
+ await fs.writeFile(
145
+ versionsJSONFile,
146
+ `${JSON.stringify(versions, null, 2)}\n`,
147
+ );
142
148
 
143
149
  logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
144
150
  }
@@ -85,7 +85,7 @@ export async function loadSidebarsFileUnsafe(
85
85
  // Non-existent sidebars file: no sidebars
86
86
  // Note: this edge case can happen on versioned docs, not current version
87
87
  // We avoid creating empty versioned sidebars file with the CLI
88
- if (!fs.existsSync(sidebarFilePath)) {
88
+ if (!(await fs.pathExists(sidebarFilePath))) {
89
89
  return DisabledSidebars;
90
90
  }
91
91
 
package/src/versions.ts CHANGED
@@ -418,7 +418,7 @@ function createVersionMetadata({
418
418
  };
419
419
  }
420
420
 
421
- function checkVersionMetadataPaths({
421
+ async function checkVersionMetadataPaths({
422
422
  versionMetadata,
423
423
  context,
424
424
  }: {
@@ -429,7 +429,7 @@ function checkVersionMetadataPaths({
429
429
  const {siteDir} = context;
430
430
  const isCurrentVersion = versionName === CURRENT_VERSION_NAME;
431
431
 
432
- if (!fs.existsSync(contentPath)) {
432
+ if (!(await fs.pathExists(contentPath))) {
433
433
  throw new Error(
434
434
  `The docs folder does not exist for version "${versionName}". A docs folder is expected to be found at ${path.relative(
435
435
  siteDir,
@@ -446,7 +446,7 @@ function checkVersionMetadataPaths({
446
446
  if (
447
447
  isCurrentVersion &&
448
448
  typeof sidebarFilePath === 'string' &&
449
- !fs.existsSync(sidebarFilePath)
449
+ !(await fs.pathExists(sidebarFilePath))
450
450
  ) {
451
451
  throw new Error(`The path to the sidebar file does not exist at "${path.relative(
452
452
  siteDir,
@@ -585,8 +585,10 @@ export async function readVersionsMetadata({
585
585
  options,
586
586
  }),
587
587
  );
588
- versionsMetadata.forEach((versionMetadata) =>
589
- checkVersionMetadataPaths({versionMetadata, context}),
588
+ await Promise.all(
589
+ versionsMetadata.map((versionMetadata) =>
590
+ checkVersionMetadataPaths({versionMetadata, context}),
591
+ ),
590
592
  );
591
593
  return versionsMetadata;
592
594
  }