@docusaurus/core 2.0.0-beta.17 → 2.0.0-beta.18

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 (94) hide show
  1. package/bin/beforeCli.mjs +2 -5
  2. package/bin/docusaurus.mjs +20 -21
  3. package/lib/choosePort.js +3 -6
  4. package/lib/client/App.js +6 -2
  5. package/lib/client/LinksCollector.d.ts +1 -1
  6. package/lib/client/LinksCollector.js +3 -3
  7. package/lib/client/SiteMetadataDefaults.d.ts +8 -0
  8. package/lib/client/SiteMetadataDefaults.js +19 -0
  9. package/lib/client/{exports/browserContext.d.ts → browserContext.d.ts} +0 -0
  10. package/lib/client/{exports/browserContext.js → browserContext.js} +0 -0
  11. package/lib/client/clientEntry.js +2 -2
  12. package/lib/client/{exports/docusaurusContext.d.ts → docusaurusContext.d.ts} +0 -0
  13. package/lib/client/{exports/docusaurusContext.js → docusaurusContext.js} +0 -0
  14. package/lib/client/exports/BrowserOnly.js +1 -1
  15. package/lib/client/exports/ComponentCreator.js +34 -14
  16. package/lib/client/exports/Interpolate.d.ts +1 -1
  17. package/lib/client/exports/Interpolate.js +4 -4
  18. package/lib/client/exports/Link.d.ts +1 -1
  19. package/lib/client/exports/Link.js +1 -1
  20. package/lib/client/exports/Translate.d.ts +2 -2
  21. package/lib/client/exports/Translate.js +2 -1
  22. package/lib/client/exports/useBaseUrl.js +5 -0
  23. package/lib/client/exports/useDocusaurusContext.js +1 -1
  24. package/lib/client/exports/useGlobalData.d.ts +4 -3
  25. package/lib/client/exports/useIsBrowser.js +1 -1
  26. package/lib/client/exports/useRouteContext.d.ts +8 -0
  27. package/lib/client/exports/useRouteContext.js +15 -0
  28. package/lib/client/flat.d.ts +3 -1
  29. package/lib/client/flat.js +1 -2
  30. package/lib/client/normalizeLocation.js +1 -5
  31. package/lib/client/prefetch.js +3 -3
  32. package/lib/client/preload.js +3 -9
  33. package/lib/client/routeContext.d.ts +13 -0
  34. package/lib/client/routeContext.js +31 -0
  35. package/lib/client/serverEntry.js +7 -7
  36. package/lib/client/theme-fallback/Error/index.js +5 -1
  37. package/lib/client/theme-fallback/Layout/index.d.ts +1 -1
  38. package/lib/client/theme-fallback/Layout/index.js +2 -17
  39. package/lib/client/theme-fallback/NotFound/index.js +11 -5
  40. package/lib/client/theme-fallback/Root/index.d.ts +4 -4
  41. package/lib/client/theme-fallback/Root/index.js +2 -1
  42. package/lib/client/theme-fallback/SiteMetadata/index.d.ts +8 -0
  43. package/lib/client/theme-fallback/SiteMetadata/index.js +10 -0
  44. package/lib/commands/build.js +1 -1
  45. package/lib/commands/commandUtils.js +1 -1
  46. package/lib/commands/deploy.d.ts +0 -3
  47. package/lib/commands/deploy.js +4 -31
  48. package/lib/commands/external.js +1 -5
  49. package/lib/commands/start.js +7 -8
  50. package/lib/commands/swizzle/actions.js +1 -2
  51. package/lib/commands/swizzle/context.js +1 -3
  52. package/lib/commands/swizzle/tables.js +7 -10
  53. package/lib/commands/swizzle/themes.js +5 -2
  54. package/lib/commands/writeHeadingIds.d.ts +2 -9
  55. package/lib/commands/writeHeadingIds.js +2 -57
  56. package/lib/server/brokenLinks.d.ts +3 -16
  57. package/lib/server/brokenLinks.js +12 -19
  58. package/lib/server/client-modules/index.d.ts +2 -2
  59. package/lib/server/client-modules/index.js +4 -1
  60. package/lib/server/config.js +1 -1
  61. package/lib/server/configValidation.d.ts +1 -1
  62. package/lib/server/configValidation.js +34 -9
  63. package/lib/server/duplicateRoutes.d.ts +0 -2
  64. package/lib/server/duplicateRoutes.js +8 -8
  65. package/lib/server/html-tags/htmlTags.js +1 -1
  66. package/lib/server/html-tags/index.d.ts +1 -2
  67. package/lib/server/html-tags/index.js +2 -3
  68. package/lib/server/i18n.d.ts +1 -1
  69. package/lib/server/i18n.js +2 -9
  70. package/lib/server/index.js +36 -31
  71. package/lib/server/plugins/index.d.ts +2 -2
  72. package/lib/server/plugins/index.js +25 -12
  73. package/lib/server/plugins/init.d.ts +6 -2
  74. package/lib/server/plugins/init.js +34 -37
  75. package/lib/server/presets/index.js +7 -13
  76. package/lib/server/routes.d.ts +2 -4
  77. package/lib/server/routes.js +23 -12
  78. package/lib/server/themes/alias.js +3 -1
  79. package/lib/server/themes/index.js +4 -4
  80. package/lib/server/translations/translations.d.ts +12 -13
  81. package/lib/server/translations/translations.js +4 -10
  82. package/lib/server/translations/translationsExtractor.d.ts +3 -1
  83. package/lib/server/translations/translationsExtractor.js +3 -4
  84. package/lib/server/versions/index.d.ts +2 -2
  85. package/lib/server/versions/index.js +2 -5
  86. package/lib/webpack/base.d.ts +3 -1
  87. package/lib/webpack/plugins/ChunkAssetPlugin.js +7 -7
  88. package/lib/webpack/plugins/CleanWebpackPlugin.js +1 -1
  89. package/lib/webpack/utils.d.ts +6 -0
  90. package/lib/webpack/utils.js +1 -3
  91. package/package.json +26 -26
  92. package/lib/server/versions/__fixtures__/dummy-plugin.d.ts +0 -0
  93. package/lib/server/versions/__fixtures__/dummy-plugin.js +0 -0
  94. package/lib/server/versions/__fixtures__/package.json +0 -3
@@ -14,34 +14,28 @@ async function loadPresets(context) {
14
14
  // We need to resolve presets from the perspective of the siteDir, since the
15
15
  // siteDir's package.json declares the dependency on these presets.
16
16
  const presetRequire = (0, module_1.createRequire)(context.siteConfigPath);
17
- const presets = context.siteConfig.presets || [];
18
- const unflatPlugins = [];
19
- const unflatThemes = [];
17
+ const { presets } = context.siteConfig;
18
+ const plugins = [];
19
+ const themes = [];
20
20
  presets.forEach((presetItem) => {
21
21
  let presetModuleImport;
22
22
  let presetOptions = {};
23
23
  if (typeof presetItem === 'string') {
24
24
  presetModuleImport = presetItem;
25
25
  }
26
- else if (Array.isArray(presetItem)) {
27
- [presetModuleImport, presetOptions = {}] = presetItem;
28
- }
29
26
  else {
30
- throw new Error('Invalid presets format detected in config.');
27
+ [presetModuleImport, presetOptions] = presetItem;
31
28
  }
32
29
  const presetName = (0, moduleShorthand_1.resolveModuleName)(presetModuleImport, presetRequire, 'preset');
33
30
  const presetModule = (0, import_fresh_1.default)(presetRequire.resolve(presetName));
34
31
  const preset = (presetModule.default ?? presetModule)(context, presetOptions);
35
32
  if (preset.plugins) {
36
- unflatPlugins.push(preset.plugins);
33
+ plugins.push(...preset.plugins.filter(Boolean));
37
34
  }
38
35
  if (preset.themes) {
39
- unflatThemes.push(preset.themes);
36
+ themes.push(...preset.themes.filter(Boolean));
40
37
  }
41
38
  });
42
- return {
43
- plugins: unflatPlugins.flat().filter(Boolean),
44
- themes: unflatThemes.flat().filter(Boolean),
45
- };
39
+ return { plugins, themes };
46
40
  }
47
41
  exports.default = loadPresets;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { ChunkRegistry, RouteConfig, ChunkNames } from '@docusaurus/types';
8
- declare type LoadedRoutes = {
8
+ export default function loadRoutes(pluginsRouteConfigs: RouteConfig[], baseUrl: string): Promise<{
9
9
  registry: {
10
10
  [chunkName: string]: ChunkRegistry;
11
11
  };
@@ -14,6 +14,4 @@ declare type LoadedRoutes = {
14
14
  [routePath: string]: ChunkNames;
15
15
  };
16
16
  routesPaths: string[];
17
- };
18
- export default function loadRoutes(pluginsRouteConfigs: RouteConfig[], baseUrl: string): Promise<LoadedRoutes>;
19
- export {};
17
+ }>;
@@ -12,7 +12,7 @@ function indent(str) {
12
12
  const spaces = ' ';
13
13
  return `${spaces}${str.replace(/\n/g, `\n${spaces}`)}`;
14
14
  }
15
- const createRouteCodeString = ({ routePath, routeHash, exact, subroutesCodeStrings, props, }) => {
15
+ function createRouteCodeString({ routePath, routeHash, exact, subroutesCodeStrings, props, }) {
16
16
  const parts = [
17
17
  `path: '${routePath}'`,
18
18
  `component: ComponentCreator('${routePath}','${routeHash}')`,
@@ -26,16 +26,30 @@ ${indent((0, utils_1.removeSuffix)(subroutesCodeStrings.join(',\n'), ',\n'))}
26
26
  ]`);
27
27
  }
28
28
  Object.entries(props).forEach(([propName, propValue]) => {
29
- // Figure out how to "unquote" JS attributes that don't need to be quoted
30
- // Is this lib reliable? https://github.com/armanozak/should-quote
31
- const shouldQuote = true; // TODO
32
- const key = shouldQuote ? `'${propName}'` : propName;
29
+ // Inspired by https://github.com/armanozak/should-quote/blob/main/packages/should-quote/src/lib/should-quote.ts
30
+ const shouldQuote = ((key) => {
31
+ // Pre-sanitation to prevent injection
32
+ if (/[.,;:}/\s]/.test(key)) {
33
+ return true;
34
+ }
35
+ try {
36
+ // If this key can be used in an expression like ({a:0}).a
37
+ // eslint-disable-next-line no-eval
38
+ eval(`({${key}:0}).${key}`);
39
+ return false;
40
+ }
41
+ catch {
42
+ return true;
43
+ }
44
+ })(propName);
45
+ // Escape quotes as well
46
+ const key = shouldQuote ? JSON.stringify(propName) : propName;
33
47
  parts.push(`${key}: ${JSON.stringify(propValue)}`);
34
48
  });
35
49
  return `{
36
50
  ${indent(parts.join(',\n'))}
37
51
  }`;
38
- };
52
+ }
39
53
  const NotFoundRouteCode = `{
40
54
  path: '*',
41
55
  component: ComponentCreator('*')
@@ -127,15 +141,12 @@ registry, value, prefix, name) {
127
141
  const modulePath = getModulePath(value);
128
142
  const chunkName = (0, utils_1.genChunkName)(modulePath, prefix, name);
129
143
  const loader = `() => import(/* webpackChunkName: '${chunkName}' */ '${(0, utils_1.escapePath)(modulePath)}')`;
130
- registry[chunkName] = {
131
- loader,
132
- modulePath,
133
- };
144
+ registry[chunkName] = { loader, modulePath };
134
145
  return chunkName;
135
146
  }
136
147
  const newValue = {};
137
- Object.keys(value).forEach((key) => {
138
- newValue[key] = genRouteChunkNames(registry, value[key], key, name);
148
+ Object.entries(value).forEach(([key, v]) => {
149
+ newValue[key] = genRouteChunkNames(registry, v, key, name);
139
150
  });
140
151
  return newValue;
141
152
  }
@@ -20,7 +20,9 @@ function sortAliases(aliases) {
20
20
  // Alphabetical order by default
21
21
  const entries = lodash_1.default.sortBy(Object.entries(aliases), ([alias]) => alias);
22
22
  // @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
23
- entries.sort(([alias1], [alias2]) => alias1.includes(`${alias2}/`) ? -1 : 0);
23
+ entries.sort(([alias1], [alias2]) =>
24
+ // eslint-disable-next-line no-nested-ternary
25
+ alias1.includes(`${alias2}/`) ? -1 : alias2.includes(`${alias1}/`) ? 1 : 0);
24
26
  return Object.fromEntries(entries);
25
27
  }
26
28
  exports.sortAliases = sortAliases;
@@ -11,12 +11,12 @@ const tslib_1 = require("tslib");
11
11
  const path_1 = tslib_1.__importDefault(require("path"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
13
  const alias_1 = tslib_1.__importStar(require("./alias"));
14
- const ThemeFallbackDir = path_1.default.resolve(__dirname, '../../client/theme-fallback');
14
+ const ThemeFallbackDir = path_1.default.join(__dirname, '../../client/theme-fallback');
15
15
  async function loadThemeAliases(themePaths, userThemePaths) {
16
16
  const aliases = {};
17
17
  for (const themePath of themePaths) {
18
18
  const themeAliases = await (0, alias_1.default)(themePath, true);
19
- Object.keys(themeAliases).forEach((aliasKey) => {
19
+ Object.entries(themeAliases).forEach(([aliasKey, alias]) => {
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
22
22
  // that provided this component
@@ -27,7 +27,7 @@ async function loadThemeAliases(themePaths, userThemePaths) {
27
27
  aliases[initAlias] = aliases[aliasKey];
28
28
  }
29
29
  }
30
- aliases[aliasKey] = themeAliases[aliasKey];
30
+ aliases[aliasKey] = alias;
31
31
  });
32
32
  }
33
33
  for (const themePath of userThemePaths) {
@@ -39,7 +39,7 @@ async function loadThemeAliases(themePaths, userThemePaths) {
39
39
  exports.loadThemeAliases = loadThemeAliases;
40
40
  function loadPluginsThemeAliases({ siteDir, plugins, }) {
41
41
  const pluginThemes = plugins
42
- .map((plugin) => (plugin.getThemePath ? plugin.getThemePath() : undefined))
42
+ .map((plugin) => plugin.getThemePath && path_1.default.resolve(plugin.path, plugin.getThemePath()))
43
43
  .filter((x) => Boolean(x));
44
44
  const userTheme = path_1.default.resolve(siteDir, utils_1.THEME_PATH);
45
45
  return loadThemeAliases([ThemeFallbackDir, ...pluginThemes], [userTheme]);
@@ -13,16 +13,7 @@ declare type TranslationContext = {
13
13
  siteDir: string;
14
14
  locale: string;
15
15
  };
16
- export declare function ensureTranslationFileContent(content: unknown): asserts content is TranslationFileContent;
17
- export declare function readTranslationFileContent(filePath: string): Promise<TranslationFileContent | undefined>;
18
- export declare function writeTranslationFileContent({ filePath, content: newContent, options, }: {
19
- filePath: string;
20
- content: TranslationFileContent;
21
- options?: WriteTranslationsOptions;
22
- }): Promise<void>;
23
- export declare function getTranslationsDirPath(context: TranslationContext): string;
24
16
  export declare function getTranslationsLocaleDirPath(context: TranslationContext): string;
25
- export declare function getCodeTranslationsFilePath(context: TranslationContext): string;
26
17
  export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
27
18
  export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
28
19
  export declare function writePluginTranslations({ siteDir, plugin, locale, translationFile, options, }: TranslationContext & {
@@ -34,9 +25,17 @@ export declare function localizePluginTranslationFile({ siteDir, plugin, locale,
34
25
  plugin: InitializedPlugin;
35
26
  translationFile: TranslationFile;
36
27
  }): Promise<TranslationFile>;
37
- export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<Record<string, string>>;
28
+ export declare function getPluginsDefaultCodeTranslationMessages(plugins: InitializedPlugin[]): Promise<{
29
+ [msgId: string]: string;
30
+ }>;
38
31
  export declare function applyDefaultCodeTranslations({ extractedCodeTranslations, defaultCodeMessages, }: {
39
- extractedCodeTranslations: Record<string, TranslationMessage>;
40
- defaultCodeMessages: Record<string, string>;
41
- }): Record<string, TranslationMessage>;
32
+ extractedCodeTranslations: {
33
+ [msgId: string]: TranslationMessage;
34
+ };
35
+ defaultCodeMessages: {
36
+ [msgId: string]: string;
37
+ };
38
+ }): {
39
+ [msgId: string]: TranslationMessage;
40
+ };
42
41
  export {};
@@ -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.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getCodeTranslationsFilePath = exports.getTranslationsLocaleDirPath = exports.getTranslationsDirPath = exports.writeTranslationFileContent = exports.readTranslationFileContent = exports.ensureTranslationFileContent = void 0;
9
+ exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = exports.getTranslationsLocaleDirPath = 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"));
@@ -27,7 +27,6 @@ function ensureTranslationFileContent(content) {
27
27
  convert: false,
28
28
  });
29
29
  }
30
- exports.ensureTranslationFileContent = ensureTranslationFileContent;
31
30
  async function readTranslationFileContent(filePath) {
32
31
  if (await fs_extra_1.default.pathExists(filePath)) {
33
32
  try {
@@ -42,7 +41,6 @@ async function readTranslationFileContent(filePath) {
42
41
  }
43
42
  return undefined;
44
43
  }
45
- exports.readTranslationFileContent = readTranslationFileContent;
46
44
  function mergeTranslationFileContent({ existingContent = {}, newContent, options, }) {
47
45
  // Apply messagePrefix to all messages
48
46
  const newContentTransformed = lodash_1.default.mapValues(newContent, (value) => ({
@@ -78,24 +76,20 @@ Maybe you should remove them? ${unknownKeys}`;
78
76
  // Avoid creating empty translation files
79
77
  if (Object.keys(mergedContent).length > 0) {
80
78
  logger_1.default.info `number=${Object.keys(mergedContent).length} translations will be written at path=${(0, utils_1.toMessageRelativeFilePath)(filePath)}.`;
81
- await fs_extra_1.default.ensureDir(path_1.default.dirname(filePath));
82
- await fs_extra_1.default.writeFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
79
+ await fs_extra_1.default.outputFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
83
80
  }
84
81
  }
85
- exports.writeTranslationFileContent = writeTranslationFileContent;
86
82
  // should we make this configurable?
87
83
  function getTranslationsDirPath(context) {
88
- return path_1.default.resolve(path_1.default.join(context.siteDir, `i18n`));
84
+ return path_1.default.resolve(path_1.default.join(context.siteDir, utils_1.I18N_DIR_NAME));
89
85
  }
90
- exports.getTranslationsDirPath = getTranslationsDirPath;
91
86
  function getTranslationsLocaleDirPath(context) {
92
87
  return path_1.default.join(getTranslationsDirPath(context), context.locale);
93
88
  }
94
89
  exports.getTranslationsLocaleDirPath = getTranslationsLocaleDirPath;
95
90
  function getCodeTranslationsFilePath(context) {
96
- return path_1.default.join(getTranslationsLocaleDirPath(context), 'code.json');
91
+ return path_1.default.join(getTranslationsLocaleDirPath(context), utils_1.CODE_TRANSLATIONS_FILE_NAME);
97
92
  }
98
- exports.getCodeTranslationsFilePath = getCodeTranslationsFilePath;
99
93
  async function readCodeTranslationFileContent(context) {
100
94
  return readTranslationFileContent(getCodeTranslationsFilePath(context));
101
95
  }
@@ -10,7 +10,9 @@ export declare function globSourceCodeFilePaths(dirPaths: string[]): Promise<str
10
10
  export declare function extractSiteSourceCodeTranslations(siteDir: string, plugins: InitializedPlugin[], babelOptions: TransformOptions, extraSourceCodeFilePaths?: string[]): Promise<TranslationFileContent>;
11
11
  declare type SourceCodeFileTranslations = {
12
12
  sourceCodeFilePath: string;
13
- translations: Record<string, TranslationMessage>;
13
+ translations: {
14
+ [msgId: string]: TranslationMessage;
15
+ };
14
16
  warnings: string[];
15
17
  };
16
18
  export declare function extractAllSourceCodeFileTranslations(sourceCodeFilePaths: string[], babelOptions: TransformOptions): Promise<SourceCodeFileTranslations[]>;
@@ -44,7 +44,7 @@ function getPluginSourceCodeFilePaths(plugin) {
44
44
  if (themePath) {
45
45
  codePaths.push(themePath);
46
46
  }
47
- return codePaths;
47
+ return codePaths.map((p) => path_1.default.resolve(plugin.path, p));
48
48
  }
49
49
  async function globSourceCodeFilePaths(dirPaths) {
50
50
  const filePaths = await (0, utils_2.safeGlobby)(dirPaths);
@@ -203,9 +203,8 @@ ${sourceWarningPart(path.node)}`);
203
203
  .filter((children) => !(children.isJSXText() &&
204
204
  children.node.value.replace('\n', '').trim() === ''))
205
205
  .pop();
206
- const isJSXText = singleChildren && singleChildren.isJSXText();
207
- const isJSXExpressionContainer = singleChildren &&
208
- singleChildren.isJSXExpressionContainer() &&
206
+ const isJSXText = singleChildren?.isJSXText();
207
+ const isJSXExpressionContainer = singleChildren?.isJSXExpressionContainer() &&
209
208
  singleChildren.get('expression').evaluate().confident;
210
209
  if (isJSXText || isJSXExpressionContainer) {
211
210
  message = isJSXText
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import type { DocusaurusPluginVersionInformation } from '@docusaurus/types';
7
+ import type { PluginVersionInformation } from '@docusaurus/types';
8
8
  export declare function getPackageJsonVersion(packageJsonPath: string): Promise<string | undefined>;
9
- export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<DocusaurusPluginVersionInformation>;
9
+ export declare function getPluginVersion(pluginPath: string, siteDir: string): Promise<PluginVersionInformation>;
@@ -19,11 +19,8 @@ async function getPackageJsonVersion(packageJsonPath) {
19
19
  }
20
20
  exports.getPackageJsonVersion = getPackageJsonVersion;
21
21
  async function getPackageJsonName(packageJsonPath) {
22
- if (await fs_extra_1.default.pathExists(packageJsonPath)) {
23
- // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
24
- return require(packageJsonPath).name;
25
- }
26
- return undefined;
22
+ // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require
23
+ return require(packageJsonPath).name;
27
24
  }
28
25
  async function getPluginVersion(pluginPath, siteDir) {
29
26
  let potentialPluginPackageJsonDirectory = path_1.default.dirname(pluginPath);
@@ -8,5 +8,7 @@ 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(): Promise<Record<string, string>>;
11
+ export declare function getDocusaurusAliases(): Promise<{
12
+ [aliasName: string]: string;
13
+ }>;
12
14
  export declare function createBaseConfig(props: Props, isServer: boolean, minify?: boolean): Promise<Configuration>;
@@ -6,7 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- const webpack_1 = require("webpack");
9
+ const tslib_1 = require("tslib");
10
+ const webpack_1 = tslib_1.__importDefault(require("webpack"));
10
11
  const pluginName = 'chunk-asset-plugin';
11
12
  /**
12
13
  * We modify webpack runtime to add an extra function called
@@ -24,11 +25,10 @@ class ChunkAssetPlugin {
24
25
  compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
25
26
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
26
27
  const chunkIdToName = chunk.getChunkMaps(false).name;
27
- const chunkNameToId = Object.create(null);
28
- Object.keys(chunkIdToName).forEach((chunkId) => {
29
- const chunkName = chunkIdToName[chunkId];
30
- chunkNameToId[chunkName] = chunkId;
31
- });
28
+ const chunkNameToId = Object.fromEntries(Object.entries(chunkIdToName).map(([chunkId, chunkName]) => [
29
+ chunkName,
30
+ chunkId,
31
+ ]));
32
32
  const buf = [source];
33
33
  buf.push('// function to get chunk asset');
34
34
  buf.push(
@@ -43,7 +43,7 @@ class ChunkAssetPlugin {
43
43
  // prefetching
44
44
  // Note: we previously used jsonpScriptSrc (Webpack 4)
45
45
  `__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
46
- return webpack_1.Template.asString(buf);
46
+ return webpack_1.default.Template.asString(buf);
47
47
  });
48
48
  });
49
49
  }
@@ -86,7 +86,7 @@ class CleanWebpackPlugin {
86
86
  const statsAssets = stats.toJson({
87
87
  all: false,
88
88
  assets: true,
89
- }).assets || [];
89
+ }).assets ?? [];
90
90
  const assets = statsAssets.map((asset) => asset.name);
91
91
  /**
92
92
  * Get all files that were in the previous build but not the current
@@ -31,6 +31,12 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
31
31
  */
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
+ declare global {
35
+ interface Error {
36
+ /** @see https://webpack.js.org/api/node/#error-handling */
37
+ details: unknown;
38
+ }
39
+ }
34
40
  export declare function compile(config: Configuration[]): Promise<void>;
35
41
  export declare function getHttpsConfig(): Promise<boolean | {
36
42
  cert: Buffer;
@@ -130,7 +130,7 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
130
130
  getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
131
131
  };
132
132
  if (typeof configureWebpack === 'function') {
133
- const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
133
+ const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
134
134
  if (res && typeof res === 'object') {
135
135
  const customizeRules = mergeStrategy ?? {};
136
136
  return (0, webpack_merge_1.mergeWithCustomize)({
@@ -171,9 +171,7 @@ function compile(config) {
171
171
  compiler.run((err, stats) => {
172
172
  if (err) {
173
173
  logger_1.default.error(err.stack || err);
174
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
175
174
  if (err.details) {
176
- // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling
177
175
  logger_1.default.error(err.details);
178
176
  }
179
177
  reject(err);
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": "2.0.0-beta.17",
4
+ "version": "2.0.0-beta.18",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -24,34 +24,34 @@
24
24
  "docusaurus": "bin/docusaurus.mjs"
25
25
  },
26
26
  "scripts": {
27
- "build": "tsc && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
28
- "watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc --watch\" \"tsc -p tsconfig.client.json --watch\""
27
+ "build": "tsc -p tsconfig.server.json && tsc -p tsconfig.client.json && node copyUntypedFiles.mjs",
28
+ "watch": "node copyUntypedFiles.mjs && concurrently -n \"server,client\" --kill-others \"tsc -p tsconfig.server.json --watch\" \"tsc -p tsconfig.client.json --watch\""
29
29
  },
30
30
  "bugs": {
31
31
  "url": "https://github.com/facebook/docusaurus/issues"
32
32
  },
33
33
  "dependencies": {
34
- "@babel/core": "^7.17.5",
35
- "@babel/generator": "^7.17.3",
34
+ "@babel/core": "^7.17.8",
35
+ "@babel/generator": "^7.17.7",
36
36
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
37
37
  "@babel/plugin-transform-runtime": "^7.17.0",
38
38
  "@babel/preset-env": "^7.16.11",
39
39
  "@babel/preset-react": "^7.16.7",
40
40
  "@babel/preset-typescript": "^7.16.7",
41
- "@babel/runtime": "^7.17.2",
42
- "@babel/runtime-corejs3": "^7.17.2",
41
+ "@babel/runtime": "^7.17.8",
42
+ "@babel/runtime-corejs3": "^7.17.8",
43
43
  "@babel/traverse": "^7.17.3",
44
- "@docusaurus/cssnano-preset": "2.0.0-beta.17",
45
- "@docusaurus/logger": "2.0.0-beta.17",
46
- "@docusaurus/mdx-loader": "2.0.0-beta.17",
44
+ "@docusaurus/cssnano-preset": "2.0.0-beta.18",
45
+ "@docusaurus/logger": "2.0.0-beta.18",
46
+ "@docusaurus/mdx-loader": "2.0.0-beta.18",
47
47
  "@docusaurus/react-loadable": "5.5.2",
48
- "@docusaurus/utils": "2.0.0-beta.17",
49
- "@docusaurus/utils-common": "2.0.0-beta.17",
50
- "@docusaurus/utils-validation": "2.0.0-beta.17",
51
- "@slorber/static-site-generator-webpack-plugin": "^4.0.1",
48
+ "@docusaurus/utils": "2.0.0-beta.18",
49
+ "@docusaurus/utils-common": "2.0.0-beta.18",
50
+ "@docusaurus/utils-validation": "2.0.0-beta.18",
51
+ "@slorber/static-site-generator-webpack-plugin": "^4.0.4",
52
52
  "@svgr/webpack": "^6.2.1",
53
- "autoprefixer": "^10.4.2",
54
- "babel-loader": "^8.2.3",
53
+ "autoprefixer": "^10.4.4",
54
+ "babel-loader": "^8.2.4",
55
55
  "babel-plugin-dynamic-import-node": "2.3.0",
56
56
  "boxen": "^6.2.1",
57
57
  "chokidar": "^3.5.3",
@@ -61,9 +61,9 @@
61
61
  "commander": "^5.1.0",
62
62
  "copy-webpack-plugin": "^10.2.4",
63
63
  "core-js": "^3.21.1",
64
- "css-loader": "^6.6.0",
64
+ "css-loader": "^6.7.1",
65
65
  "css-minimizer-webpack-plugin": "^3.4.1",
66
- "cssnano": "^5.0.17",
66
+ "cssnano": "^5.1.5",
67
67
  "del": "^6.0.0",
68
68
  "detect-port": "^1.3.0",
69
69
  "escape-html": "^1.0.3",
@@ -77,9 +77,9 @@
77
77
  "is-root": "^2.1.0",
78
78
  "leven": "^3.1.0",
79
79
  "lodash": "^4.17.21",
80
- "mini-css-extract-plugin": "^2.5.3",
80
+ "mini-css-extract-plugin": "^2.6.0",
81
81
  "nprogress": "^0.2.0",
82
- "postcss": "^8.4.7",
82
+ "postcss": "^8.4.12",
83
83
  "postcss-loader": "^6.2.1",
84
84
  "prompts": "^2.4.2",
85
85
  "react-dev-utils": "^12.0.0",
@@ -91,7 +91,7 @@
91
91
  "react-router-dom": "^5.2.0",
92
92
  "remark-admonitions": "^1.2.1",
93
93
  "rtl-detect": "^1.0.4",
94
- "semver": "^7.3.4",
94
+ "semver": "^7.3.5",
95
95
  "serve-handler": "^6.1.3",
96
96
  "shelljs": "^0.8.5",
97
97
  "terser-webpack-plugin": "^5.3.1",
@@ -99,18 +99,18 @@
99
99
  "update-notifier": "^5.1.0",
100
100
  "url-loader": "^4.1.1",
101
101
  "wait-on": "^6.0.1",
102
- "webpack": "^5.69.1",
102
+ "webpack": "^5.70.0",
103
103
  "webpack-bundle-analyzer": "^4.5.0",
104
104
  "webpack-dev-server": "^4.7.4",
105
105
  "webpack-merge": "^5.8.0",
106
106
  "webpackbar": "^5.0.2"
107
107
  },
108
108
  "devDependencies": {
109
- "@docusaurus/module-type-aliases": "2.0.0-beta.17",
110
- "@docusaurus/types": "2.0.0-beta.17",
109
+ "@docusaurus/module-type-aliases": "2.0.0-beta.18",
110
+ "@docusaurus/types": "2.0.0-beta.18",
111
111
  "@types/detect-port": "^1.3.2",
112
112
  "@types/nprogress": "^0.2.0",
113
- "@types/react-dom": "^17.0.11",
113
+ "@types/react-dom": "^17.0.14",
114
114
  "@types/react-router-config": "^5.0.6",
115
115
  "@types/rtl-detect": "^1.0.0",
116
116
  "@types/serve-handler": "^6.1.1",
@@ -128,5 +128,5 @@
128
128
  "engines": {
129
129
  "node": ">=14"
130
130
  },
131
- "gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
131
+ "gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
132
132
  }
File without changes
@@ -1,3 +0,0 @@
1
- {
2
- "version": "random-version"
3
- }