@docusaurus/core 0.0.0-4609 → 0.0.0-4615

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/bin/beforeCli.mjs CHANGED
@@ -36,7 +36,7 @@ const {
36
36
  *
37
37
  * cache data is stored in `~/.config/configstore/update-notifier-@docusaurus`
38
38
  */
39
- function beforeCli() {
39
+ async function beforeCli() {
40
40
  const notifier = updateNotifier({
41
41
  pkg: {
42
42
  name,
@@ -98,7 +98,9 @@ function beforeCli() {
98
98
  .filter((p) => p.startsWith('@docusaurus'))
99
99
  .map((p) => p.concat('@latest'))
100
100
  .join(' ');
101
- const isYarnUsed = fs.existsSync(path.resolve(process.cwd(), 'yarn.lock'));
101
+ const isYarnUsed = await fs.pathExists(
102
+ path.resolve(process.cwd(), 'yarn.lock'),
103
+ );
102
104
  const upgradeCommand = isYarnUsed
103
105
  ? `yarn upgrade ${siteDocusaurusPackagesForUpdate}`
104
106
  : `npm i ${siteDocusaurusPackagesForUpdate}`;
@@ -9,7 +9,7 @@
9
9
  // @ts-check
10
10
 
11
11
  import logger from '@docusaurus/logger';
12
- import fs from 'fs';
12
+ import fs from 'fs-extra';
13
13
  import cli from 'commander';
14
14
  import {createRequire} from 'module';
15
15
  import {
@@ -25,9 +25,9 @@ import {
25
25
  } from '../lib/index.js';
26
26
  import beforeCli from './beforeCli.mjs';
27
27
 
28
- beforeCli();
28
+ await beforeCli();
29
29
 
30
- const resolveDir = (dir = '.') => fs.realpathSync(dir);
30
+ const resolveDir = (dir = '.') => fs.realpath(dir);
31
31
 
32
32
  cli
33
33
  .version(createRequire(import.meta.url)('../package.json').version)
@@ -56,8 +56,8 @@ cli
56
56
  '--no-minify',
57
57
  'build website without minimizing JS bundles (default: false)',
58
58
  )
59
- .action((siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => {
60
- build(resolveDir(siteDir), {
59
+ .action(async (siteDir, {bundleAnalyzer, config, outDir, locale, minify}) => {
60
+ build(await resolveDir(siteDir), {
61
61
  bundleAnalyzer,
62
62
  outDir,
63
63
  config,
@@ -74,8 +74,14 @@ cli
74
74
  'copy TypeScript theme files when possible (default: false)',
75
75
  )
76
76
  .option('--danger', 'enable swizzle for internal component of themes')
77
- .action((themeName, componentName, siteDir, {typescript, danger}) => {
78
- swizzle(resolveDir(siteDir), themeName, componentName, typescript, danger);
77
+ .action(async (themeName, componentName, siteDir, {typescript, danger}) => {
78
+ swizzle(
79
+ await resolveDir(siteDir),
80
+ themeName,
81
+ componentName,
82
+ typescript,
83
+ danger,
84
+ );
79
85
  });
80
86
 
81
87
  cli
@@ -97,8 +103,8 @@ cli
97
103
  '--skip-build',
98
104
  'skip building website before deploy it (default: false)',
99
105
  )
100
- .action((siteDir, {outDir, skipBuild, config}) => {
101
- deploy(resolveDir(siteDir), {
106
+ .action(async (siteDir, {outDir, skipBuild, config}) => {
107
+ deploy(await resolveDir(siteDir), {
102
108
  outDir,
103
109
  config,
104
110
  skipBuild,
@@ -124,17 +130,19 @@ cli
124
130
  '--poll [interval]',
125
131
  'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
126
132
  )
127
- .action((siteDir, {port, host, locale, config, hotOnly, open, poll}) => {
128
- start(resolveDir(siteDir), {
129
- port,
130
- host,
131
- locale,
132
- config,
133
- hotOnly,
134
- open,
135
- poll,
136
- });
137
- });
133
+ .action(
134
+ async (siteDir, {port, host, locale, config, hotOnly, open, poll}) => {
135
+ start(await resolveDir(siteDir), {
136
+ port,
137
+ host,
138
+ locale,
139
+ config,
140
+ hotOnly,
141
+ open,
142
+ poll,
143
+ });
144
+ },
145
+ );
138
146
 
139
147
  cli
140
148
  .command('serve [siteDir]')
@@ -151,7 +159,7 @@ cli
151
159
  .option('--build', 'build website before serving (default: false)')
152
160
  .option('-h, --host <host>', 'use specified host (default: localhost)')
153
161
  .action(
154
- (
162
+ async (
155
163
  siteDir,
156
164
  {
157
165
  dir = 'build',
@@ -161,7 +169,7 @@ cli
161
169
  config,
162
170
  },
163
171
  ) => {
164
- serve(resolveDir(siteDir), {
172
+ serve(await resolveDir(siteDir), {
165
173
  dir,
166
174
  port,
167
175
  build: buildSite,
@@ -174,8 +182,8 @@ cli
174
182
  cli
175
183
  .command('clear [siteDir]')
176
184
  .description('Remove build artifacts.')
177
- .action((siteDir) => {
178
- clear(resolveDir(siteDir));
185
+ .action(async (siteDir) => {
186
+ clear(await resolveDir(siteDir));
179
187
  });
180
188
 
181
189
  cli
@@ -198,11 +206,11 @@ cli
198
206
  'allows to init new written messages with a given prefix. This might help you to highlight untranslated message to make them stand out in the UI',
199
207
  )
200
208
  .action(
201
- (
209
+ async (
202
210
  siteDir,
203
211
  {locale = undefined, override = false, messagePrefix = '', config},
204
212
  ) => {
205
- writeTranslations(resolveDir(siteDir), {
213
+ writeTranslations(await resolveDir(siteDir), {
206
214
  locale,
207
215
  override,
208
216
  config,
@@ -219,8 +227,8 @@ cli
219
227
  "keep the headings' casing, otherwise make all lowercase (default: false)",
220
228
  )
221
229
  .option('--overwrite', 'overwrite existing heading IDs (default: false)')
222
- .action((siteDir, files, options) =>
223
- writeHeadingIds(resolveDir(siteDir), files, options),
230
+ .action(async (siteDir, files, options) =>
231
+ writeHeadingIds(await resolveDir(siteDir), files, options),
224
232
  );
225
233
 
226
234
  cli.arguments('<command>').action((cmd) => {
@@ -246,7 +254,7 @@ function isInternalCommand(command) {
246
254
 
247
255
  async function run() {
248
256
  if (!isInternalCommand(process.argv.slice(2)[0])) {
249
- await externalCommand(cli, resolveDir('.'));
257
+ await externalCommand(cli, await resolveDir('.'));
250
258
  }
251
259
 
252
260
  cli.parse(process.argv);
@@ -6,6 +6,6 @@
6
6
  */
7
7
  /// <reference types="@docusaurus/module-type-aliases" />
8
8
  /// <reference types="react" />
9
- import type { HeadProps } from '@docusaurus/Head';
10
- declare function Head(props: HeadProps): JSX.Element;
9
+ import type { Props } from '@docusaurus/Head';
10
+ declare function Head(props: Props): JSX.Element;
11
11
  export default Head;
@@ -75,6 +75,7 @@ forceTerminate = true) {
75
75
  }
76
76
  exports.default = build;
77
77
  async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLastLocale, }) {
78
+ var _a;
78
79
  process.env.BABEL_ENV = 'production';
79
80
  process.env.NODE_ENV = 'production';
80
81
  logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
@@ -87,7 +88,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
87
88
  // Apply user webpack config.
88
89
  const { outDir, generatedFilesDir, plugins, siteConfig: { baseUrl, onBrokenLinks, staticDirectories }, routes, } = props;
89
90
  const clientManifestPath = path_1.default.join(generatedFilesDir, 'client-manifest.json');
90
- let clientConfig = (0, webpack_merge_1.default)((0, client_1.default)(props, cliOptions.minify), {
91
+ let clientConfig = (0, webpack_merge_1.default)(await (0, client_1.default)(props, cliOptions.minify), {
91
92
  plugins: [
92
93
  // Remove/clean build folders before building bundles.
93
94
  new CleanWebpackPlugin_1.default({ verbose: false }),
@@ -101,22 +102,24 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
101
102
  ].filter(Boolean),
102
103
  });
103
104
  const allCollectedLinks = {};
104
- let serverConfig = (0, server_2.default)({
105
+ let serverConfig = await (0, server_2.default)({
105
106
  props,
106
107
  onLinksCollected: (staticPagePath, links) => {
107
108
  allCollectedLinks[staticPagePath] = links;
108
109
  },
109
110
  });
110
- serverConfig = (0, webpack_merge_1.default)(serverConfig, {
111
- plugins: [
112
- new copy_webpack_plugin_1.default({
113
- patterns: staticDirectories
114
- .map((dir) => path_1.default.resolve(siteDir, dir))
115
- .filter(fs_extra_1.default.existsSync)
116
- .map((dir) => ({ from: dir, to: outDir })),
117
- }),
118
- ],
119
- });
111
+ if (staticDirectories.length > 0) {
112
+ await Promise.all(staticDirectories.map((dir) => fs_extra_1.default.ensureDir(dir)));
113
+ serverConfig = (0, webpack_merge_1.default)(serverConfig, {
114
+ plugins: [
115
+ new copy_webpack_plugin_1.default({
116
+ patterns: staticDirectories
117
+ .map((dir) => path_1.default.resolve(siteDir, dir))
118
+ .map((dir) => ({ from: dir, to: outDir })),
119
+ }),
120
+ ],
121
+ });
122
+ }
120
123
  // Plugin Lifecycle - configureWebpack and configurePostCss.
121
124
  plugins.forEach((plugin) => {
122
125
  var _a, _b;
@@ -139,9 +142,7 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
139
142
  // Run webpack to build JS bundle (client) and static html files (server).
140
143
  await (0, utils_1.compile)([clientConfig, serverConfig]);
141
144
  // Remove server.bundle.js because it is not needed.
142
- if (serverConfig.output &&
143
- serverConfig.output.filename &&
144
- typeof serverConfig.output.filename === 'string') {
145
+ if (typeof ((_a = serverConfig.output) === null || _a === void 0 ? void 0 : _a.filename) === 'string') {
145
146
  const serverBundle = path_1.default.join(outDir, serverConfig.output.filename);
146
147
  if (await fs_extra_1.default.pathExists(serverBundle)) {
147
148
  await fs_extra_1.default.unlink(serverBundle);
@@ -86,14 +86,14 @@ async function start(siteDir, cliOptions) {
86
86
  ? cliOptions.poll
87
87
  : undefined,
88
88
  };
89
- const httpsConfig = (0, utils_2.getHttpsConfig)();
89
+ const httpsConfig = await (0, utils_2.getHttpsConfig)();
90
90
  const fsWatcher = chokidar_1.default.watch(pathsToWatch, {
91
91
  cwd: siteDir,
92
92
  ignoreInitial: true,
93
93
  ...{ pollingOptions },
94
94
  });
95
95
  ['add', 'change', 'unlink', 'addDir', 'unlinkDir'].forEach((event) => fsWatcher.on(event, reload));
96
- let config = (0, webpack_merge_1.default)((0, client_1.default)(props), {
96
+ let config = (0, webpack_merge_1.default)(await (0, client_1.default)(props), {
97
97
  infrastructureLogging: {
98
98
  // Reduce log verbosity, see https://github.com/facebook/docusaurus/pull/5420#issuecomment-906613105
99
99
  level: 'warn',
@@ -8,6 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getPluginNames = void 0;
10
10
  const tslib_1 = require("tslib");
11
+ /* eslint-disable no-restricted-properties */
11
12
  const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
12
13
  const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
13
14
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
@@ -65,7 +65,7 @@ Available locales are: ${context.i18n.locales.join(',')}.`);
65
65
  }
66
66
  const babelOptions = (0, utils_1.getBabelOptions)({
67
67
  isServer: true,
68
- babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
68
+ babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
69
69
  });
70
70
  const extractedCodeTranslations = await (0, translationsExtractor_1.extractSiteSourceCodeTranslations)(siteDir, plugins, babelOptions, await getExtraSourceCodeFilePaths());
71
71
  const defaultCodeMessages = await (0, translations_1.getPluginsDefaultCodeTranslationMessages)(plugins);
@@ -14,6 +14,7 @@ const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
14
14
  const utils_1 = require("@docusaurus/utils");
15
15
  const utils_2 = require("./utils");
16
16
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
17
+ const combine_promises_1 = (0, tslib_1.__importDefault)(require("combine-promises"));
17
18
  function toReactRouterRoutes(routes) {
18
19
  // @ts-expect-error: types incompatible???
19
20
  return routes;
@@ -93,9 +94,9 @@ function getBrokenLinksErrorMessage(allBrokenLinks) {
93
94
  `);
94
95
  }
95
96
  exports.getBrokenLinksErrorMessage = getBrokenLinksErrorMessage;
96
- function isExistingFile(filePath) {
97
+ async function isExistingFile(filePath) {
97
98
  try {
98
- return fs_extra_1.default.statSync(filePath).isFile();
99
+ return (await fs_extra_1.default.stat(filePath)).isFile();
99
100
  }
100
101
  catch (e) {
101
102
  return false;
@@ -104,8 +105,7 @@ function isExistingFile(filePath) {
104
105
  // If a file actually exist on the file system, we know the link is valid
105
106
  // even if docusaurus does not know about this file, so we don't report it
106
107
  async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, }) {
107
- // not easy to make this async :'(
108
- function linkFileExists(link) {
108
+ async function linkFileExists(link) {
109
109
  // /baseUrl/javadoc/ -> /outDir/javadoc
110
110
  const baseFilePath = (0, utils_1.removeSuffix)(`${outDir}/${(0, utils_1.removePrefix)(link, baseUrl)}`, '/');
111
111
  // -> /outDir/javadoc
@@ -116,9 +116,14 @@ async function filterExistingFileLinks({ baseUrl, outDir, allCollectedLinks, })
116
116
  filePathsToTry.push(`${baseFilePath}.html`);
117
117
  filePathsToTry.push(path_1.default.join(baseFilePath, 'index.html'));
118
118
  }
119
- return filePathsToTry.some(isExistingFile);
119
+ for (const file of filePathsToTry) {
120
+ if (await isExistingFile(file)) {
121
+ return true;
122
+ }
123
+ }
124
+ return false;
120
125
  }
121
- return lodash_1.default.mapValues(allCollectedLinks, (links) => links.filter((link) => !linkFileExists(link)));
126
+ return (0, combine_promises_1.default)(lodash_1.default.mapValues(allCollectedLinks, async (links) => (await Promise.all(links.map(async (link) => ((await linkFileExists(link)) ? '' : link)))).filter(Boolean)));
122
127
  }
123
128
  exports.filterExistingFileLinks = filterExistingFileLinks;
124
129
  async function handleBrokenLinks({ allCollectedLinks, onBrokenLinks, routes, baseUrl, outDir, }) {
@@ -11,7 +11,7 @@ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
11
11
  const import_fresh_1 = (0, tslib_1.__importDefault)(require("import-fresh"));
12
12
  const configValidation_1 = require("./configValidation");
13
13
  async function loadConfig(configPath) {
14
- if (!fs_extra_1.default.existsSync(configPath)) {
14
+ if (!(await fs_extra_1.default.pathExists(configPath))) {
15
15
  throw new Error(`Config file at "${configPath}" not found.`);
16
16
  }
17
17
  const importedConfig = (0, import_fresh_1.default)(configPath);
@@ -6,7 +6,6 @@
6
6
  */
7
7
  import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
8
8
  export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
9
- export declare function shouldWarnAboutNodeVersion(version: number, locales: string[]): boolean;
10
9
  export declare function loadI18n(config: DocusaurusConfig, options?: {
11
10
  locale?: string;
12
11
  }): Promise<I18n>;
@@ -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.localizePath = exports.loadI18n = exports.shouldWarnAboutNodeVersion = exports.getDefaultLocaleConfig = void 0;
9
+ exports.localizePath = exports.loadI18n = exports.getDefaultLocaleConfig = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
@@ -24,12 +24,6 @@ function getDefaultLocaleConfig(locale) {
24
24
  };
25
25
  }
26
26
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
27
- function shouldWarnAboutNodeVersion(version, locales) {
28
- const isOnlyEnglish = locales.length === 1 && locales.includes('en');
29
- const isOlderNodeVersion = version < 14;
30
- return isOlderNodeVersion && !isOnlyEnglish;
31
- }
32
- exports.shouldWarnAboutNodeVersion = shouldWarnAboutNodeVersion;
33
27
  async function loadI18n(config, options = {}) {
34
28
  var _a;
35
29
  const { i18n: i18nConfig } = config;
@@ -57,20 +51,20 @@ Note: Docusaurus only support running one locale at a time.`;
57
51
  }
58
52
  exports.loadI18n = loadI18n;
59
53
  function localizePath({ pathType, path: originalPath, i18n, options = {}, }) {
60
- const shouldLocalizePath = typeof options.localizePath === 'undefined'
61
- ? // By default, we don't localize the path of defaultLocale
62
- i18n.currentLocale !== i18n.defaultLocale
63
- : options.localizePath;
54
+ var _a;
55
+ const shouldLocalizePath =
56
+ // By default, we don't localize the path of defaultLocale
57
+ (_a = options.localizePath) !== null && _a !== void 0 ? _a : i18n.currentLocale !== i18n.defaultLocale;
64
58
  if (!shouldLocalizePath) {
65
59
  return originalPath;
66
60
  }
67
61
  // FS paths need special care, for Windows support
68
62
  if (pathType === 'fs') {
69
- return path_1.default.join(originalPath, path_1.default.sep, i18n.currentLocale, path_1.default.sep);
63
+ return path_1.default.join(originalPath, i18n.currentLocale);
70
64
  }
71
- // Url paths
65
+ // Url paths; add a trailing slash so it's a valid base URL
72
66
  if (pathType === 'url') {
73
- return (0, utils_1.normalizeUrl)([originalPath, '/', i18n.currentLocale, '/']);
67
+ return (0, utils_1.normalizeUrl)([originalPath, i18n.currentLocale, '/']);
74
68
  }
75
69
  // should never happen
76
70
  throw new Error(`Unhandled path type "${pathType}".`);
@@ -252,8 +252,8 @@ ${Object.keys(registry)
252
252
  const genCodeTranslations = (0, utils_1.generate)(generatedFilesDir, 'codeTranslations.json', JSON.stringify(codeTranslationsWithFallbacks, null, 2));
253
253
  // Version metadata.
254
254
  const siteMetadata = {
255
- docusaurusVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json')),
256
- siteVersion: (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
255
+ docusaurusVersion: (await (0, versions_1.getPackageJsonVersion)(path_1.default.join(__dirname, '../../package.json'))),
256
+ siteVersion: await (0, versions_1.getPackageJsonVersion)(path_1.default.join(siteDir, 'package.json')),
257
257
  pluginVersions: {},
258
258
  };
259
259
  plugins
@@ -85,7 +85,7 @@ async function initPlugins({ pluginConfigs, context, }) {
85
85
  // We need to resolve plugins from the perspective of the siteDir, since the
86
86
  // siteDir's package.json declares the dependency on these plugins.
87
87
  const pluginRequire = (0, module_1.createRequire)(context.siteConfigPath);
88
- function doGetPluginVersion(normalizedPluginConfig) {
88
+ async function doGetPluginVersion(normalizedPluginConfig) {
89
89
  var _a, _b;
90
90
  // get plugin version
91
91
  if ((_a = normalizedPluginConfig.pluginModule) === null || _a === void 0 ? void 0 : _a.path) {
@@ -122,7 +122,7 @@ async function initPlugins({ pluginConfigs, context, }) {
122
122
  }
123
123
  async function initializePlugin(pluginConfig) {
124
124
  const normalizedPluginConfig = await normalizePluginConfig(pluginConfig, pluginRequire);
125
- const pluginVersion = doGetPluginVersion(normalizedPluginConfig);
125
+ const pluginVersion = await doGetPluginVersion(normalizedPluginConfig);
126
126
  const pluginOptions = doValidatePluginOptions(normalizedPluginConfig);
127
127
  // Side-effect: merge the normalized theme config in the original one
128
128
  context.siteConfig.themeConfig = {
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import type { ThemeAliases } from '@docusaurus/types';
8
8
  export declare function sortAliases(aliases: ThemeAliases): ThemeAliases;
9
- export default function themeAlias(themePath: string, addOriginalAlias: boolean): ThemeAliases;
9
+ export default function themeAlias(themePath: string, addOriginalAlias: boolean): Promise<ThemeAliases>;
@@ -24,12 +24,11 @@ function sortAliases(aliases) {
24
24
  return Object.fromEntries(entries);
25
25
  }
26
26
  exports.sortAliases = sortAliases;
27
- // TODO make async
28
- function themeAlias(themePath, addOriginalAlias) {
29
- if (!fs_extra_1.default.pathExistsSync(themePath)) {
27
+ async function themeAlias(themePath, addOriginalAlias) {
28
+ if (!(await fs_extra_1.default.pathExists(themePath))) {
30
29
  return {};
31
30
  }
32
- const themeComponentFiles = utils_1.Globby.sync(['**/*.{js,jsx,ts,tsx}'], {
31
+ const themeComponentFiles = await (0, utils_1.Globby)(['**/*.{js,jsx,ts,tsx}'], {
33
32
  cwd: themePath,
34
33
  });
35
34
  const aliases = {};
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { ThemeAliases, LoadedPlugin } from '@docusaurus/types';
8
- export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): ThemeAliases;
8
+ export declare function loadThemeAliases(themePaths: string[], userThemePaths: string[]): Promise<ThemeAliases>;
9
9
  export declare function loadPluginsThemeAliases({ siteDir, plugins, }: {
10
10
  siteDir: string;
11
11
  plugins: LoadedPlugin[];
12
- }): ThemeAliases;
12
+ }): Promise<ThemeAliases>;
@@ -12,10 +12,10 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const alias_1 = (0, tslib_1.__importStar)(require("./alias"));
14
14
  const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
15
- function loadThemeAliases(themePaths, userThemePaths) {
15
+ async function loadThemeAliases(themePaths, userThemePaths) {
16
16
  const aliases = {};
17
- themePaths.forEach((themePath) => {
18
- const themeAliases = (0, alias_1.default)(themePath, true);
17
+ for (const themePath of themePaths) {
18
+ const themeAliases = await (0, alias_1.default)(themePath, true);
19
19
  Object.keys(themeAliases).forEach((aliasKey) => {
20
20
  // If this alias shadows a previous one, use @theme-init to preserve the
21
21
  // initial one. @theme-init is only applied once: to the initial theme
@@ -29,11 +29,11 @@ function loadThemeAliases(themePaths, userThemePaths) {
29
29
  }
30
30
  aliases[aliasKey] = themeAliases[aliasKey];
31
31
  });
32
- });
33
- userThemePaths.forEach((themePath) => {
34
- const userThemeAliases = (0, alias_1.default)(themePath, false);
32
+ }
33
+ for (const themePath of userThemePaths) {
34
+ const userThemeAliases = await (0, alias_1.default)(themePath, false);
35
35
  Object.assign(aliases, userThemeAliases);
36
- });
36
+ }
37
37
  return (0, alias_1.sortAliases)(aliases);
38
38
  }
39
39
  exports.loadThemeAliases = loadThemeAliases;
@@ -5,6 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
8
- export declare function getPackageJsonVersion(packageJsonPath: string): string | undefined;
9
- export declare function getPackageJsonName(packageJsonPath: string): string | undefined;
10
- export declare function getPluginVersion(pluginPath: string, siteDir: string): DocusaurusPluginVersionInformation;
8
+ export declare function getPackageJsonVersion(packageJsonPath: string): Promise<string | undefined>;
9
+ export declare function getPackageJsonName(packageJsonPath: string): Promise<string | undefined>;
10
+ export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<DocusaurusPluginVersionInformation>;
@@ -7,10 +7,11 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getPluginVersion = exports.getPackageJsonName = exports.getPackageJsonVersion = void 0;
10
- const fs_extra_1 = require("fs-extra");
11
- const path_1 = require("path");
12
- function getPackageJsonVersion(packageJsonPath) {
13
- if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
10
+ const tslib_1 = require("tslib");
11
+ const fs_extra_1 = (0, tslib_1.__importDefault)(require("fs-extra"));
12
+ const path_1 = (0, tslib_1.__importDefault)(require("path"));
13
+ async function getPackageJsonVersion(packageJsonPath) {
14
+ if (await fs_extra_1.default.pathExists(packageJsonPath)) {
14
15
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
15
16
  const { version } = require(packageJsonPath);
16
17
  return typeof version === 'string' ? version : undefined;
@@ -18,8 +19,8 @@ function getPackageJsonVersion(packageJsonPath) {
18
19
  return undefined;
19
20
  }
20
21
  exports.getPackageJsonVersion = getPackageJsonVersion;
21
- function getPackageJsonName(packageJsonPath) {
22
- if ((0, fs_extra_1.existsSync)(packageJsonPath)) {
22
+ async function getPackageJsonName(packageJsonPath) {
23
+ if (await fs_extra_1.default.pathExists(packageJsonPath)) {
23
24
  // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
24
25
  const { name } = require(packageJsonPath);
25
26
  return typeof name === 'string' ? name : undefined;
@@ -27,11 +28,12 @@ function getPackageJsonName(packageJsonPath) {
27
28
  return undefined;
28
29
  }
29
30
  exports.getPackageJsonName = getPackageJsonName;
30
- function getPluginVersion(pluginPath, siteDir) {
31
- let potentialPluginPackageJsonDirectory = (0, path_1.dirname)(pluginPath);
31
+ async function getPluginVersion(pluginPath, siteDir) {
32
+ let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
32
33
  while (potentialPluginPackageJsonDirectory !== '/') {
33
- const packageJsonPath = (0, path_1.join)(potentialPluginPackageJsonDirectory, 'package.json');
34
- if ((0, fs_extra_1.existsSync)(packageJsonPath) && (0, fs_extra_1.lstatSync)(packageJsonPath).isFile()) {
34
+ const packageJsonPath = path_1.default.join(potentialPluginPackageJsonDirectory, 'package.json');
35
+ if ((await fs_extra_1.default.pathExists(packageJsonPath)) &&
36
+ (await fs_extra_1.default.lstat(packageJsonPath)).isFile()) {
35
37
  if (potentialPluginPackageJsonDirectory === siteDir) {
36
38
  // If the plugin belongs to the same docusaurus project, we classify it
37
39
  // as local plugin.
@@ -39,11 +41,11 @@ function getPluginVersion(pluginPath, siteDir) {
39
41
  }
40
42
  return {
41
43
  type: 'package',
42
- name: getPackageJsonName(packageJsonPath),
43
- version: getPackageJsonVersion(packageJsonPath),
44
+ name: await getPackageJsonName(packageJsonPath),
45
+ version: await getPackageJsonVersion(packageJsonPath),
44
46
  };
45
47
  }
46
- potentialPluginPackageJsonDirectory = (0, path_1.dirname)(potentialPluginPackageJsonDirectory);
48
+ potentialPluginPackageJsonDirectory = path_1.default.dirname(potentialPluginPackageJsonDirectory);
47
49
  }
48
50
  // In the case where a plugin is a path where no parent directory contains
49
51
  // package.json (e.g. inline plugin), we can only classify it as local.
@@ -8,5 +8,5 @@ import type { Configuration } from 'webpack';
8
8
  import type { Props } from '@docusaurus/types';
9
9
  export declare const clientDir: string;
10
10
  export declare function excludeJS(modulePath: string): boolean;
11
- export declare function getDocusaurusAliases(): Record<string, string>;
12
- export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Configuration;
11
+ export declare function getDocusaurusAliases(): Promise<Record<string, string>>;
12
+ export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
@@ -32,11 +32,11 @@ function excludeJS(modulePath) {
32
32
  !LibrariesToTranspileRegex.test(modulePath));
33
33
  }
34
34
  exports.excludeJS = excludeJS;
35
- function getDocusaurusAliases() {
35
+ async function getDocusaurusAliases() {
36
36
  const dirPath = path_1.default.resolve(__dirname, '../client/exports');
37
37
  const extensions = ['.js', '.ts', '.tsx'];
38
38
  const aliases = {};
39
- fs_extra_1.default.readdirSync(dirPath)
39
+ (await fs_extra_1.default.readdir(dirPath))
40
40
  .filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
41
41
  .forEach((fileName) => {
42
42
  const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
@@ -46,7 +46,7 @@ function getDocusaurusAliases() {
46
46
  return aliases;
47
47
  }
48
48
  exports.getDocusaurusAliases = getDocusaurusAliases;
49
- function createBaseConfig(props, isServer, minify = true) {
49
+ async function createBaseConfig(props, isServer, minify = true) {
50
50
  var _a;
51
51
  const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
52
52
  const totalPages = routesPaths.length;
@@ -56,7 +56,7 @@ function createBaseConfig(props, isServer, minify = true) {
56
56
  const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
57
57
  const name = isServer ? 'server' : 'client';
58
58
  const mode = isProd ? 'production' : 'development';
59
- const themeAliases = (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
59
+ const themeAliases = await (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
60
60
  return {
61
61
  mode,
62
62
  name,
@@ -120,7 +120,7 @@ function createBaseConfig(props, isServer, minify = true) {
120
120
  // Note: a @docusaurus alias would also catch @docusaurus/theme-common,
121
121
  // so we use fine-grained aliases instead
122
122
  // '@docusaurus': path.resolve(__dirname, '../client/exports'),
123
- ...getDocusaurusAliases(),
123
+ ...(await getDocusaurusAliases()),
124
124
  ...themeAliases,
125
125
  },
126
126
  // This allows you to set a fallback for where Webpack should look for
@@ -131,7 +131,7 @@ function createBaseConfig(props, isServer, minify = true) {
131
131
  modules: [
132
132
  path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
133
133
  'node_modules',
134
- path_1.default.resolve(fs_extra_1.default.realpathSync(process.cwd()), 'node_modules'),
134
+ path_1.default.resolve(await fs_extra_1.default.realpath(process.cwd()), 'node_modules'),
135
135
  ],
136
136
  },
137
137
  resolveLoader: {
@@ -187,7 +187,7 @@ function createBaseConfig(props, isServer, minify = true) {
187
187
  use: [
188
188
  (0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
189
189
  isServer,
190
- babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
190
+ babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
191
191
  }),
192
192
  ],
193
193
  },
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import type { Configuration } from 'webpack';
8
8
  import type { Props } from '@docusaurus/types';
9
- export default function createClientConfig(props: Props, minify?: boolean): Configuration;
9
+ export default function createClientConfig(props: Props, minify?: boolean): Promise<Configuration>;
@@ -13,10 +13,10 @@ const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
13
13
  const base_1 = require("./base");
14
14
  const ChunkAssetPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/ChunkAssetPlugin"));
15
15
  const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
16
- function createClientConfig(props, minify = true) {
16
+ async function createClientConfig(props, minify = true) {
17
17
  var _a;
18
18
  const isBuilding = process.argv[2] === 'build';
19
- const config = (0, base_1.createBaseConfig)(props, false, minify);
19
+ const config = await (0, base_1.createBaseConfig)(props, false, minify);
20
20
  const clientConfig = (0, webpack_merge_1.default)(config, {
21
21
  // useless, disabled on purpose (errors on existing sites with no
22
22
  // browserslist config)
@@ -9,4 +9,4 @@ import type { Props } from '@docusaurus/types';
9
9
  export default function createServerConfig({ props, onLinksCollected, }: {
10
10
  props: Props;
11
11
  onLinksCollected?: (staticPagePath: string, links: string[]) => void;
12
- }): Configuration;
12
+ }): Promise<Configuration>;
@@ -15,9 +15,9 @@ const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"))
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  // Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
17
17
  const static_site_generator_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("@slorber/static-site-generator-webpack-plugin"));
18
- function createServerConfig({ props, onLinksCollected = () => { }, }) {
18
+ async function createServerConfig({ props, onLinksCollected = () => { }, }) {
19
19
  const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
20
- const config = (0, base_1.createBaseConfig)(props, true);
20
+ const config = await (0, base_1.createBaseConfig)(props, true);
21
21
  const routesLocation = {};
22
22
  // Array of paths to be rendered. Relative to output directory
23
23
  const ssgPaths = routesPaths.map((str) => {
@@ -11,7 +11,7 @@ import type { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
11
11
  export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
12
12
  [key: string]: unknown;
13
13
  }): RuleSetRule[];
14
- export declare function getCustomBabelConfigFilePath(siteDir: string): string | undefined;
14
+ export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
15
15
  export declare function getBabelOptions({ isServer, babelOptions, }?: {
16
16
  isServer?: boolean;
17
17
  babelOptions?: TransformOptions | string;
@@ -32,8 +32,8 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
32
32
  export declare function applyConfigureWebpack(configureWebpack: ConfigureWebpackFn, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
33
33
  export declare function applyConfigurePostCss(configurePostCss: NonNullable<ConfigurePostCssFn>, config: Configuration): Configuration;
34
34
  export declare function compile(config: Configuration[]): Promise<void>;
35
- export declare function getHttpsConfig(): boolean | {
35
+ export declare function getHttpsConfig(): Promise<boolean | {
36
36
  cert: Buffer;
37
37
  key: Buffer;
38
- };
38
+ }>;
39
39
  export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
@@ -80,9 +80,9 @@ function getStyleLoaders(isServer, cssOptionsArg = {}) {
80
80
  ];
81
81
  }
82
82
  exports.getStyleLoaders = getStyleLoaders;
83
- function getCustomBabelConfigFilePath(siteDir) {
83
+ async function getCustomBabelConfigFilePath(siteDir) {
84
84
  const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
85
- return fs_extra_1.default.existsSync(customBabelConfigurationPath)
85
+ return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
86
86
  ? customBabelConfigurationPath
87
87
  : undefined;
88
88
  }
@@ -247,24 +247,24 @@ ${err}`);
247
247
  }
248
248
  }
249
249
  // Read file and throw an error if it doesn't exist
250
- function readEnvFile(file, type) {
251
- if (!fs_extra_1.default.existsSync(file)) {
250
+ async function readEnvFile(file, type) {
251
+ if (!(await fs_extra_1.default.pathExists(file))) {
252
252
  throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
253
253
  }
254
- return fs_extra_1.default.readFileSync(file);
254
+ return fs_extra_1.default.readFile(file);
255
255
  }
256
- const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
257
256
  // Get the https config
258
257
  // Return cert files if provided in env, otherwise just true or false
259
- function getHttpsConfig() {
258
+ async function getHttpsConfig() {
259
+ const appDirectory = await fs_extra_1.default.realpath(process.cwd());
260
260
  const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
261
261
  const isHttps = HTTPS === 'true';
262
262
  if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
263
263
  const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
264
264
  const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
265
265
  const config = {
266
- cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
267
- key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
266
+ cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
267
+ key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
268
268
  };
269
269
  validateKeyAndCerts({ ...config, keyFile, crtFile });
270
270
  return config;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@docusaurus/core",
3
3
  "description": "Easy to Maintain Open Source Documentation Websites",
4
- "version": "0.0.0-4609",
4
+ "version": "0.0.0-4615",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -41,13 +41,13 @@
41
41
  "@babel/runtime": "^7.17.2",
42
42
  "@babel/runtime-corejs3": "^7.17.2",
43
43
  "@babel/traverse": "^7.17.3",
44
- "@docusaurus/cssnano-preset": "0.0.0-4609",
45
- "@docusaurus/logger": "0.0.0-4609",
46
- "@docusaurus/mdx-loader": "0.0.0-4609",
44
+ "@docusaurus/cssnano-preset": "0.0.0-4615",
45
+ "@docusaurus/logger": "0.0.0-4615",
46
+ "@docusaurus/mdx-loader": "0.0.0-4615",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "0.0.0-4609",
49
- "@docusaurus/utils-common": "0.0.0-4609",
50
- "@docusaurus/utils-validation": "0.0.0-4609",
48
+ "@docusaurus/utils": "0.0.0-4615",
49
+ "@docusaurus/utils-common": "0.0.0-4615",
50
+ "@docusaurus/utils-validation": "0.0.0-4615",
51
51
  "@slorber/static-site-generator-webpack-plugin": "^4.0.1",
52
52
  "@svgr/webpack": "^6.2.1",
53
53
  "autoprefixer": "^10.4.2",
@@ -56,6 +56,7 @@
56
56
  "boxen": "^5.1.2",
57
57
  "chokidar": "^3.5.3",
58
58
  "clean-css": "^5.2.4",
59
+ "combine-promises": "^1.1.0",
59
60
  "commander": "^5.1.0",
60
61
  "copy-webpack-plugin": "^10.2.4",
61
62
  "core-js": "^3.21.1",
@@ -104,8 +105,8 @@
104
105
  "webpackbar": "^5.0.2"
105
106
  },
106
107
  "devDependencies": {
107
- "@docusaurus/module-type-aliases": "0.0.0-4609",
108
- "@docusaurus/types": "0.0.0-4609",
108
+ "@docusaurus/module-type-aliases": "0.0.0-4615",
109
+ "@docusaurus/types": "0.0.0-4615",
109
110
  "@types/detect-port": "^1.3.2",
110
111
  "@types/nprogress": "^0.2.0",
111
112
  "@types/react-dom": "^17.0.11",
@@ -125,5 +126,5 @@
125
126
  "engines": {
126
127
  "node": ">=14"
127
128
  },
128
- "gitHead": "398a24ae6b46221f1b07e23573affd1641861431"
129
+ "gitHead": "02bd619fc85e38d320177f4d96f39864109300c8"
129
130
  }