@docusaurus/core 0.0.0-5044 → 0.0.0-5049

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
@@ -16,7 +16,9 @@ import updateNotifier from 'update-notifier';
16
16
  import boxen from 'boxen';
17
17
  import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
18
18
 
19
- const packageJson = createRequire(import.meta.url)('../package.json');
19
+ const packageJson = /** @type {import("../package.json")} */ (
20
+ createRequire(import.meta.url)('../package.json')
21
+ );
20
22
  /** @type {Record<string, any>} */
21
23
  let sitePkg;
22
24
  try {
@@ -8,7 +8,7 @@ import { useLayoutEffect } from 'react';
8
8
  import clientModules from '@generated/client-modules';
9
9
  export function dispatchLifecycleAction(lifecycleAction, ...args) {
10
10
  const callbacks = clientModules.map((clientModule) => {
11
- const lifecycleFunction = (clientModule?.default?.[lifecycleAction] ??
11
+ const lifecycleFunction = (clientModule.default?.[lifecycleAction] ??
12
12
  clientModule[lifecycleAction]);
13
13
  return lifecycleFunction?.(...args);
14
14
  });
@@ -9,7 +9,7 @@ declare global {
9
9
  gca: (name: string) => string;
10
10
  };
11
11
  interface Navigator {
12
- connection: {
12
+ connection?: {
13
13
  effectiveType: string;
14
14
  saveData: boolean;
15
15
  };
@@ -42,7 +42,7 @@ const docusaurus = {
42
42
  // In some cases, webpack might decide to optimize further, leading to
43
43
  // the chunk assets being merged to another chunk. In this case, we can
44
44
  // safely filter it out and don't need to load it.
45
- if (chunkAsset && !/undefined/.test(chunkAsset)) {
45
+ if (chunkAsset && !chunkAsset.includes('undefined')) {
46
46
  return prefetchHelper(chunkAsset);
47
47
  }
48
48
  return Promise.resolve();
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export function hasProtocol(url) {
8
- return /^(?:\w*:|\/\/)/.test(url) === true;
8
+ return /^(?:\w*:|\/\/)/.test(url);
9
9
  }
10
10
  export default function isInternalUrl(url) {
11
11
  return typeof url !== 'undefined' && !hasProtocol(url);
@@ -8,9 +8,6 @@ import useDocusaurusContext from './useDocusaurusContext';
8
8
  import { DEFAULT_PLUGIN_ID } from './constants';
9
9
  export default function useGlobalData() {
10
10
  const { globalData } = useDocusaurusContext();
11
- if (!globalData) {
12
- throw new Error('Docusaurus global data not found.');
13
- }
14
11
  return globalData;
15
12
  }
16
13
  export function useAllPluginInstancesData(pluginName, options = {}) {
@@ -7,9 +7,9 @@
7
7
  function supports(feature) {
8
8
  try {
9
9
  const fakeLink = document.createElement('link');
10
- return fakeLink.relList?.supports?.(feature);
10
+ return fakeLink.relList.supports(feature);
11
11
  }
12
- catch (err) {
12
+ catch {
13
13
  return false;
14
14
  }
15
15
  }
@@ -84,9 +84,9 @@ async function doRender(locals) {
84
84
  // Using readJSON seems to fail for users of some plugins, possibly because of
85
85
  // the eval sandbox having a different `Buffer` instance (native one instead
86
86
  // of polyfilled one)
87
- const manifest = await fs
87
+ const manifest = (await fs
88
88
  .readFile(manifestPath, 'utf-8')
89
- .then(JSON.parse);
89
+ .then(JSON.parse));
90
90
  // Get all required assets for this particular page based on client
91
91
  // manifest information.
92
92
  const modulesToBeLoaded = [...manifest.entrypoints, ...Array.from(modules)];
@@ -45,7 +45,7 @@ async function serve(siteDir, cliOptions) {
45
45
  }
46
46
  // Remove baseUrl before calling serveHandler, because /baseUrl/ should
47
47
  // serve /build/index.html, not /build/baseUrl/index.html (does not exist)
48
- req.url = req.url?.replace(baseUrl, '/');
48
+ req.url = req.url.replace(baseUrl, '/');
49
49
  (0, serve_handler_1.default)(req, res, {
50
50
  cleanUrls: true,
51
51
  public: dir,
@@ -13,16 +13,14 @@ const utils_validation_1 = require("@docusaurus/utils-validation");
13
13
  const common_1 = require("./common");
14
14
  const themes_1 = require("./themes");
15
15
  function getModuleSwizzleConfig(swizzlePlugin) {
16
- const getSwizzleConfig = swizzlePlugin.plugin.plugin?.getSwizzleConfig ??
17
- swizzlePlugin.plugin.pluginModule?.module.getSwizzleConfig ??
18
- swizzlePlugin.plugin.pluginModule?.module?.getSwizzleConfig;
16
+ const getSwizzleConfig = swizzlePlugin.plugin.plugin.getSwizzleConfig ??
17
+ swizzlePlugin.plugin.pluginModule?.module.getSwizzleConfig;
19
18
  if (getSwizzleConfig) {
20
19
  return getSwizzleConfig();
21
20
  }
22
21
  // TODO deprecate getSwizzleComponentList later
23
- const getSwizzleComponentList = swizzlePlugin.plugin.plugin?.getSwizzleComponentList ??
24
- swizzlePlugin.plugin.pluginModule?.module.getSwizzleComponentList ??
25
- swizzlePlugin.plugin.pluginModule?.module?.getSwizzleComponentList;
22
+ const getSwizzleComponentList = swizzlePlugin.plugin.plugin.getSwizzleComponentList ??
23
+ swizzlePlugin.plugin.pluginModule?.module.getSwizzleComponentList;
26
24
  if (getSwizzleComponentList) {
27
25
  const safeComponents = getSwizzleComponentList() ?? [];
28
26
  const safeComponentConfig = {
@@ -65,7 +65,7 @@ function handleInvalidThemeName({ themeNameParam, themeNames, }) {
65
65
  : logger_1.default.interpolate `Themes available for swizzle: ${themeNames}`}`;
66
66
  return process.exit(1);
67
67
  }
68
- async function validateThemeName({ themeNameParam, themeNames, }) {
68
+ function validateThemeName({ themeNameParam, themeNames, }) {
69
69
  const isValidName = themeNames.includes(themeNameParam);
70
70
  if (!isValidName) {
71
71
  return handleInvalidThemeName({
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { type WriteHeadingIDOptions } from '@docusaurus/utils';
8
- export declare function writeHeadingIds(siteDir: string, files: string[], options: WriteHeadingIDOptions): Promise<void>;
8
+ export declare function writeHeadingIds(siteDir: string, files: string[] | undefined, options: WriteHeadingIDOptions): Promise<void>;
@@ -32,7 +32,7 @@ async function transformMarkdownFile(filepath, options) {
32
32
  async function getPathsToWatch(siteDir) {
33
33
  const context = await (0, server_1.loadContext)({ siteDir });
34
34
  const plugins = await (0, init_1.initPlugins)(context);
35
- return plugins.flatMap((plugin) => plugin?.getPathsToWatch?.() ?? []);
35
+ return plugins.flatMap((plugin) => plugin.getPathsToWatch?.() ?? []);
36
36
  }
37
37
  async function writeHeadingIds(siteDir, files, options) {
38
38
  const markdownFiles = await (0, utils_2.safeGlobby)(files ?? (await getPathsToWatch(siteDir)), {
@@ -65,7 +65,7 @@ function createPluginSchema(theme) {
65
65
  [function myPlugin() { },options]
66
66
  ],
67
67
  };`;
68
- error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value as path [${error.path}].
68
+ error.message = ` => Bad Docusaurus ${theme ? 'theme' : 'plugin'} value ${error.path.reduce((acc, cur) => typeof cur === 'string' ? `${acc}.${cur}` : `${acc}[${cur}]`)}.
69
69
  ${validConfigExample}
70
70
  `;
71
71
  });
@@ -189,7 +189,7 @@ function validateConfig(config) {
189
189
  if (error) {
190
190
  const unknownFields = error.details.reduce((formattedError, err) => {
191
191
  if (err.type === 'object.unknown') {
192
- return `${formattedError}"${err.path}",`;
192
+ return `${formattedError}"${err.path.reduce((acc, cur) => typeof cur === 'string' ? `${acc}.${cur}` : `${acc}[${cur}]`)}",`;
193
193
  }
194
194
  return formattedError;
195
195
  }, '');
@@ -19,7 +19,7 @@ async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
19
19
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
20
20
  const pluginModule = (0, import_fresh_1.default)(pluginPath);
21
21
  return {
22
- plugin: pluginModule?.default ?? pluginModule,
22
+ plugin: pluginModule.default ?? pluginModule,
23
23
  options: {},
24
24
  pluginModule: {
25
25
  path: pluginModuleImport,
@@ -44,7 +44,7 @@ async function normalizePluginConfig(pluginConfig, configPath, pluginRequire) {
44
44
  const pluginPath = pluginRequire.resolve(pluginModuleImport);
45
45
  const pluginModule = (0, import_fresh_1.default)(pluginPath);
46
46
  return {
47
- plugin: pluginModule?.default ?? pluginModule,
47
+ plugin: pluginModule.default ?? pluginModule,
48
48
  options: pluginConfig[1],
49
49
  pluginModule: {
50
50
  path: pluginModuleImport,
@@ -33,7 +33,7 @@ async function loadPlugins(context) {
33
33
  // translation files that the plugin declares.
34
34
  const loadedPlugins = await Promise.all(plugins.map(async (plugin) => {
35
35
  const content = await plugin.loadContent?.();
36
- const rawTranslationFiles = (await plugin?.getTranslationFiles?.({ content })) ?? [];
36
+ const rawTranslationFiles = (await plugin.getTranslationFiles?.({ content })) ?? [];
37
37
  const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
38
38
  locale: context.i18n.currentLocale,
39
39
  siteDir: context.siteDir,
@@ -18,8 +18,8 @@ const configs_1 = require("./configs");
18
18
  function getOptionValidationFunction(normalizedPluginConfig) {
19
19
  if (normalizedPluginConfig.pluginModule) {
20
20
  // Support both CommonJS and ES modules
21
- return (normalizedPluginConfig.pluginModule.module?.default?.validateOptions ??
22
- normalizedPluginConfig.pluginModule.module?.validateOptions);
21
+ return (normalizedPluginConfig.pluginModule.module.default?.validateOptions ??
22
+ normalizedPluginConfig.pluginModule.module.validateOptions);
23
23
  }
24
24
  return normalizedPluginConfig.plugin.validateOptions;
25
25
  }
@@ -42,7 +42,7 @@ async function initPlugins(context) {
42
42
  const pluginConfigs = await (0, configs_1.loadPluginConfigs)(context);
43
43
  async function doGetPluginVersion(normalizedPluginConfig) {
44
44
  if (normalizedPluginConfig.pluginModule?.path) {
45
- const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule?.path);
45
+ const pluginPath = pluginRequire.resolve(normalizedPluginConfig.pluginModule.path);
46
46
  return (0, siteMetadata_1.getPluginVersion)(pluginPath, context.siteDir);
47
47
  }
48
48
  return { type: 'local' };
@@ -38,8 +38,8 @@ function sortConfig(routeConfigs, baseUrl = '/') {
38
38
  }
39
39
  // Higher priority get placed first.
40
40
  if (a.priority || b.priority) {
41
- const priorityA = a.priority || 0;
42
- const priorityB = b.priority || 0;
41
+ const priorityA = a.priority ?? 0;
42
+ const priorityB = b.priority ?? 0;
43
43
  const score = priorityB - priorityA;
44
44
  if (score !== 0) {
45
45
  return score;
@@ -74,7 +74,7 @@ function createMDXFallbackPlugin({ siteDir, siteConfig, }) {
74
74
  // processed by content plugins mdx loaders. This works, but a bit
75
75
  // hacky... Not sure there's a way to handle that differently in webpack
76
76
  function getMDXFallbackExcludedPaths() {
77
- const rules = config?.module?.rules;
77
+ const rules = config.module?.rules;
78
78
  return rules.flatMap((rule) => {
79
79
  const isMDXRule = rule.test instanceof RegExp && rule.test.test('x.mdx');
80
80
  return isMDXRule ? rule.include : [];
@@ -99,7 +99,7 @@ async function extractSourceCodeFileTranslations(sourceCodeFilePath, babelOption
99
99
  // See https://twitter.com/NicoloRibaudo/status/1321130735605002243
100
100
  filename: sourceCodeFilePath,
101
101
  });
102
- const translations = await extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
102
+ const translations = extractSourceCodeAstTranslations(ast, sourceCodeFilePath);
103
103
  return translations;
104
104
  }
105
105
  catch (err) {
@@ -118,7 +118,7 @@ https://github.com/pugjs/babel-walk
118
118
  */
119
119
  function extractSourceCodeAstTranslations(ast, sourceCodeFilePath) {
120
120
  function sourceWarningPart(node) {
121
- return `File: ${sourceCodeFilePath} at line ${node.loc?.start.line}
121
+ return `File: ${sourceCodeFilePath} at line ${node.loc?.start.line ?? '?'}
122
122
  Full code: ${(0, generator_1.default)(node).code}`;
123
123
  }
124
124
  const translations = {};
@@ -157,9 +157,7 @@ Full code: ${(0, generator_1.default)(node).code}`;
157
157
  const attributePath = path
158
158
  .get('openingElement.attributes')
159
159
  .find((attr) => attr.isJSXAttribute() &&
160
- attr
161
- .get('name')
162
- .isJSXIdentifier({ name: propName }));
160
+ attr.get('name').isJSXIdentifier({ name: propName }));
163
161
  if (attributePath) {
164
162
  const attributeValue = attributePath.get('value');
165
163
  const attributeValueEvaluated = attributeValue.isJSXExpressionContainer()
@@ -209,7 +207,7 @@ ${sourceWarningPart(path.node)}`);
209
207
  if (isJSXText || isJSXExpressionContainer) {
210
208
  message = isJSXText
211
209
  ? singleChildren.node.value.trim().replace(/\s+/g, ' ')
212
- : singleChildren.get('expression').evaluate().value;
210
+ : String(singleChildren.get('expression').evaluate().value);
213
211
  translations[id ?? message] = {
214
212
  message,
215
213
  ...(description && { description }),
@@ -27,7 +27,7 @@ function excludeJS(modulePath) {
27
27
  return false;
28
28
  }
29
29
  // Don't transpile node_modules except any docusaurus npm package
30
- return (/node_modules/.test(modulePath) &&
30
+ return (modulePath.includes('node_modules') &&
31
31
  !/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
32
32
  !LibrariesToTranspileRegex.test(modulePath));
33
33
  }
@@ -62,7 +62,7 @@ class CleanWebpackPlugin {
62
62
  this.removeFiles = this.removeFiles.bind(this);
63
63
  }
64
64
  apply(compiler) {
65
- if (!compiler.options.output || !compiler.options.output.path) {
65
+ if (!compiler.options.output.path) {
66
66
  console.warn('clean-webpack-plugin: options.output.path not defined. Plugin disabled...');
67
67
  return;
68
68
  }
@@ -115,7 +115,7 @@ class CleanWebpackPlugin {
115
115
  *
116
116
  * (relies on del's cwd: outputPath option)
117
117
  */
118
- const staleFiles = this.currentAssets.filter((previousAsset) => assets.includes(previousAsset) === false);
118
+ const staleFiles = this.currentAssets.filter((previousAsset) => !assets.includes(previousAsset));
119
119
  /**
120
120
  * Save assets for next compilation
121
121
  */
@@ -124,7 +124,7 @@ class CleanWebpackPlugin {
124
124
  /**
125
125
  * Remove unused webpack assets
126
126
  */
127
- if (this.cleanStaleWebpackAssets === true && staleFiles.length !== 0) {
127
+ if (this.cleanStaleWebpackAssets && staleFiles.length !== 0) {
128
128
  removePatterns.push(...staleFiles);
129
129
  }
130
130
  if (removePatterns.length !== 0) {
@@ -157,7 +157,7 @@ class CleanWebpackPlugin {
157
157
  }
158
158
  }
159
159
  catch (err) {
160
- const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(err.message);
160
+ const needsForce = err.message.includes('Cannot delete files/folders outside the current working directory.');
161
161
  if (needsForce) {
162
162
  const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
163
163
  throw new Error(message);
@@ -131,13 +131,11 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
131
131
  };
132
132
  if (typeof configureWebpack === 'function') {
133
133
  const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
134
- if (res && typeof res === 'object') {
135
- const customizeRules = mergeStrategy ?? {};
136
- return (0, webpack_merge_1.mergeWithCustomize)({
137
- customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
138
- customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
139
- })(config, res);
140
- }
134
+ const customizeRules = mergeStrategy ?? {};
135
+ return (0, webpack_merge_1.mergeWithCustomize)({
136
+ customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
137
+ customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
138
+ })(config, res);
141
139
  }
142
140
  return config;
143
141
  }
@@ -170,7 +168,7 @@ function compile(config) {
170
168
  const compiler = (0, webpack_1.default)(config);
171
169
  compiler.run((err, stats) => {
172
170
  if (err) {
173
- logger_1.default.error(err.stack || err);
171
+ logger_1.default.error(err.stack ?? err);
174
172
  if (err.details) {
175
173
  logger_1.default.error(err.details);
176
174
  }
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-5044",
4
+ "version": "0.0.0-5049",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -43,13 +43,13 @@
43
43
  "@babel/runtime": "^7.18.0",
44
44
  "@babel/runtime-corejs3": "^7.18.0",
45
45
  "@babel/traverse": "^7.18.0",
46
- "@docusaurus/cssnano-preset": "0.0.0-5044",
47
- "@docusaurus/logger": "0.0.0-5044",
48
- "@docusaurus/mdx-loader": "0.0.0-5044",
46
+ "@docusaurus/cssnano-preset": "0.0.0-5049",
47
+ "@docusaurus/logger": "0.0.0-5049",
48
+ "@docusaurus/mdx-loader": "0.0.0-5049",
49
49
  "@docusaurus/react-loadable": "5.5.2",
50
- "@docusaurus/utils": "0.0.0-5044",
51
- "@docusaurus/utils-common": "0.0.0-5044",
52
- "@docusaurus/utils-validation": "0.0.0-5044",
50
+ "@docusaurus/utils": "0.0.0-5049",
51
+ "@docusaurus/utils-common": "0.0.0-5049",
52
+ "@docusaurus/utils-validation": "0.0.0-5049",
53
53
  "@slorber/static-site-generator-webpack-plugin": "^4.0.4",
54
54
  "@svgr/webpack": "^6.2.1",
55
55
  "autoprefixer": "^10.4.7",
@@ -107,8 +107,8 @@
107
107
  "webpackbar": "^5.0.2"
108
108
  },
109
109
  "devDependencies": {
110
- "@docusaurus/module-type-aliases": "0.0.0-5044",
111
- "@docusaurus/types": "0.0.0-5044",
110
+ "@docusaurus/module-type-aliases": "0.0.0-5049",
111
+ "@docusaurus/types": "0.0.0-5049",
112
112
  "@types/detect-port": "^1.3.2",
113
113
  "@types/react-dom": "^18.0.4",
114
114
  "@types/react-router-config": "^5.0.6",
@@ -128,5 +128,5 @@
128
128
  "engines": {
129
129
  "node": ">=14"
130
130
  },
131
- "gitHead": "9ffd6ca265dc2af7ed5b96daf5ebf32708e899cf"
131
+ "gitHead": "527b2a01c46b67483327a1a6873fccf81bc19e2c"
132
132
  }