@docusaurus/core 0.0.0-6067 → 0.0.0-6068

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
@@ -11,7 +11,7 @@ import fs from 'fs-extra';
11
11
  import path from 'path';
12
12
  import {createRequire} from 'module';
13
13
  import shell from 'shelljs';
14
- import logger from '@docusaurus/logger';
14
+ import {logger} from '@docusaurus/logger';
15
15
  import semver from 'semver';
16
16
  import updateNotifier from 'update-notifier';
17
17
  import boxen from 'boxen';
@@ -9,7 +9,7 @@
9
9
  // @ts-check
10
10
 
11
11
  import {inspect} from 'node:util';
12
- import logger from '@docusaurus/logger';
12
+ import {logger} from '@docusaurus/logger';
13
13
  import cli from 'commander';
14
14
  import {DOCUSAURUS_VERSION} from '@docusaurus/utils';
15
15
  import {
@@ -11,7 +11,7 @@ const tslib_1 = require("tslib");
11
11
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
12
  const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
14
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const site_1 = require("../server/site");
17
17
  const brokenLinks_1 = require("../server/brokenLinks");
@@ -19,7 +19,6 @@ const client_1 = require("../webpack/client");
19
19
  const server_1 = tslib_1.__importDefault(require("../webpack/server"));
20
20
  const configure_1 = require("../webpack/configure");
21
21
  const utils_2 = require("../webpack/utils");
22
- const utils_3 = require("../utils");
23
22
  const i18n_1 = require("../server/i18n");
24
23
  const ssg_1 = require("../ssg");
25
24
  const templates_1 = require("../templates/templates");
@@ -39,7 +38,7 @@ async function build(siteDirParam = '.', cliOptions = {}) {
39
38
  });
40
39
  async function tryToBuildLocale({ locale }) {
41
40
  try {
42
- await utils_3.PerfLogger.async(`${logger_1.default.name(locale)}`, () => buildLocale({
41
+ await logger_1.PerfLogger.async(`${logger_1.default.name(locale)}`, () => buildLocale({
43
42
  siteDir,
44
43
  locale,
45
44
  cliOptions,
@@ -51,11 +50,11 @@ async function build(siteDirParam = '.', cliOptions = {}) {
51
50
  });
52
51
  }
53
52
  }
54
- const locales = await utils_3.PerfLogger.async('Get locales to build', () => getLocalesToBuild({ siteDir, cliOptions }));
53
+ const locales = await logger_1.PerfLogger.async('Get locales to build', () => getLocalesToBuild({ siteDir, cliOptions }));
55
54
  if (locales.length > 1) {
56
55
  logger_1.default.info `Website will be built for all these locales: ${locales}`;
57
56
  }
58
- await utils_3.PerfLogger.async(`Build`, () => (0, utils_1.mapAsyncSequential)(locales, async (locale) => {
57
+ await logger_1.PerfLogger.async(`Build`, () => (0, utils_1.mapAsyncSequential)(locales, async (locale) => {
59
58
  await tryToBuildLocale({ locale });
60
59
  }));
61
60
  logger_1.default.info `Use code=${'npm run serve'} command to test your build locally.`;
@@ -90,7 +89,7 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
90
89
  // See https://github.com/facebook/docusaurus/issues/4542
91
90
  process.env.DOCUSAURUS_CURRENT_LOCALE = locale;
92
91
  logger_1.default.info `name=${`[${locale}]`} Creating an optimized production build...`;
93
- const site = await utils_3.PerfLogger.async('Load site', () => (0, site_1.loadSite)({
92
+ const site = await logger_1.PerfLogger.async('Load site', () => (0, site_1.loadSite)({
94
93
  siteDir,
95
94
  outDir: cliOptions.outDir,
96
95
  config: cliOptions.config,
@@ -101,7 +100,7 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
101
100
  const { outDir, plugins, siteConfig } = props;
102
101
  const router = siteConfig.future.experimental_router;
103
102
  // We can build the 2 configs in parallel
104
- const [{ clientConfig, clientManifestPath }, { serverConfig, serverBundlePath }] = await utils_3.PerfLogger.async('Creating webpack configs', () => Promise.all([
103
+ const [{ clientConfig, clientManifestPath }, { serverConfig, serverBundlePath }] = await logger_1.PerfLogger.async('Creating webpack configs', () => Promise.all([
105
104
  getBuildClientConfig({
106
105
  props,
107
106
  cliOptions,
@@ -111,7 +110,7 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
111
110
  }),
112
111
  ]));
113
112
  // Run webpack to build JS bundle (client) and static html files (server).
114
- await utils_3.PerfLogger.async('Bundling with Webpack', () => {
113
+ await logger_1.PerfLogger.async('Bundling with Webpack', () => {
115
114
  if (router === 'hash') {
116
115
  return (0, utils_2.compile)([clientConfig]);
117
116
  }
@@ -119,7 +118,7 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
119
118
  return (0, utils_2.compile)([clientConfig, serverConfig]);
120
119
  }
121
120
  });
122
- const { collectedData } = await utils_3.PerfLogger.async('SSG', () => executeSSG({
121
+ const { collectedData } = await logger_1.PerfLogger.async('SSG', () => executeSSG({
123
122
  props,
124
123
  serverBundlePath,
125
124
  clientManifestPath,
@@ -127,15 +126,15 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
127
126
  }));
128
127
  await cleanupServerBundle(serverBundlePath);
129
128
  // Plugin Lifecycle - postBuild.
130
- await utils_3.PerfLogger.async('postBuild()', () => executePluginsPostBuild({ plugins, props, collectedData }));
129
+ await logger_1.PerfLogger.async('postBuild()', () => executePluginsPostBuild({ plugins, props, collectedData }));
131
130
  // TODO execute this in parallel to postBuild?
132
- await utils_3.PerfLogger.async('Broken links checker', () => executeBrokenLinksCheck({ props, collectedData }));
131
+ await logger_1.PerfLogger.async('Broken links checker', () => executeBrokenLinksCheck({ props, collectedData }));
133
132
  logger_1.default.success `Generated static files in path=${path_1.default.relative(process.cwd(), outDir)}.`;
134
133
  return outDir;
135
134
  }
136
135
  async function executeSSG({ props, serverBundlePath, clientManifestPath, router, }) {
137
- const manifest = await utils_3.PerfLogger.async('Read client manifest', () => fs_extra_1.default.readJSON(clientManifestPath, 'utf-8'));
138
- const ssrTemplate = await utils_3.PerfLogger.async('Compile SSR template', () => (0, templates_1.compileSSRTemplate)(props.siteConfig.ssrTemplate ?? ssr_html_template_1.default));
136
+ const manifest = await logger_1.PerfLogger.async('Read client manifest', () => fs_extra_1.default.readJSON(clientManifestPath, 'utf-8'));
137
+ const ssrTemplate = await logger_1.PerfLogger.async('Compile SSR template', () => (0, templates_1.compileSSRTemplate)(props.siteConfig.ssrTemplate ?? ssr_html_template_1.default));
139
138
  const params = {
140
139
  trailingSlash: props.siteConfig.trailingSlash,
141
140
  outDir: props.outDir,
@@ -149,16 +148,16 @@ async function executeSSG({ props, serverBundlePath, clientManifestPath, router,
149
148
  DOCUSAURUS_VERSION: utils_1.DOCUSAURUS_VERSION,
150
149
  };
151
150
  if (router === 'hash') {
152
- utils_3.PerfLogger.start('Generate Hash Router entry point');
151
+ logger_1.PerfLogger.start('Generate Hash Router entry point');
153
152
  const content = (0, templates_1.renderHashRouterTemplate)({ params });
154
153
  await (0, ssg_1.generateHashRouterEntrypoint)({ content, params });
155
- utils_3.PerfLogger.end('Generate Hash Router entry point');
154
+ logger_1.PerfLogger.end('Generate Hash Router entry point');
156
155
  return { collectedData: {} };
157
156
  }
158
- const renderer = await utils_3.PerfLogger.async('Load App renderer', () => (0, ssg_1.loadAppRenderer)({
157
+ const renderer = await logger_1.PerfLogger.async('Load App renderer', () => (0, ssg_1.loadAppRenderer)({
159
158
  serverBundlePath,
160
159
  }));
161
- const ssgResult = await utils_3.PerfLogger.async('Generate static files', () => (0, ssg_1.generateStaticFiles)({
160
+ const ssgResult = await logger_1.PerfLogger.async('Generate static files', () => (0, ssg_1.generateStaticFiles)({
162
161
  pathnames: props.routesPaths,
163
162
  renderer,
164
163
  params,
@@ -231,7 +230,7 @@ async function cleanupServerBundle(serverBundlePath) {
231
230
  logger_1.default.warn("Will NOT delete server bundle because DOCUSAURUS_KEEP_SERVER_BUNDLE is set to 'true'");
232
231
  }
233
232
  else {
234
- await utils_3.PerfLogger.async('Deleting server bundle', async () => {
233
+ await logger_1.PerfLogger.async('Deleting server bundle', async () => {
235
234
  // For now we assume server entry is at the root of the server out dir
236
235
  const serverDir = path_1.default.dirname(serverBundlePath);
237
236
  await fs_extra_1.default.rm(serverDir, { recursive: true, force: true });
@@ -13,9 +13,8 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
13
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
14
  const WebpackDevServerUtils_1 = require("react-dev-utils/WebpackDevServerUtils");
15
15
  const utils_1 = require("@docusaurus/utils");
16
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
17
17
  const getHostPort_1 = require("../../server/getHostPort");
18
- const utils_2 = require("../../utils");
19
18
  const site_1 = require("../../server/site");
20
19
  const pluginsUtils_1 = require("../../server/plugins/pluginsUtils");
21
20
  async function createOpenUrlContext({ cliOptions, }) {
@@ -46,8 +45,8 @@ async function createLoadSiteParams({ siteDirParam, cliOptions, }) {
46
45
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
47
46
  async function createReloadableSite(startParams) {
48
47
  const openUrlContext = await createOpenUrlContext(startParams);
49
- const loadSiteParams = await utils_2.PerfLogger.async('createLoadSiteParams', () => createLoadSiteParams(startParams));
50
- let site = await utils_2.PerfLogger.async('Load site', () => (0, site_1.loadSite)(loadSiteParams));
48
+ const loadSiteParams = await logger_1.PerfLogger.async('createLoadSiteParams', () => createLoadSiteParams(startParams));
49
+ let site = await logger_1.PerfLogger.async('Load site', () => (0, site_1.loadSite)(loadSiteParams));
51
50
  const get = () => site;
52
51
  const getOpenUrl = () => openUrlContext.getOpenUrl({
53
52
  baseUrl: site.props.baseUrl,
@@ -60,7 +59,7 @@ async function createReloadableSite(startParams) {
60
59
  const reloadBase = async () => {
61
60
  try {
62
61
  const oldSite = site;
63
- site = await utils_2.PerfLogger.async('Reload site', () => (0, site_1.reloadSite)(site));
62
+ site = await logger_1.PerfLogger.async('Reload site', () => (0, site_1.reloadSite)(site));
64
63
  if (oldSite.props.baseUrl !== site.props.baseUrl) {
65
64
  printOpenUrlMessage();
66
65
  }
@@ -77,7 +76,7 @@ async function createReloadableSite(startParams) {
77
76
  // but we should still support it and probably use a task queuing system
78
77
  const reloadPlugin = async (plugin) => {
79
78
  try {
80
- site = await utils_2.PerfLogger.async(`Reload site plugin ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, () => {
79
+ site = await logger_1.PerfLogger.async(`Reload site plugin ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, () => {
81
80
  const pluginIdentifier = { name: plugin.name, id: plugin.options.id };
82
81
  return (0, site_1.reloadSitePlugin)(site, pluginIdentifier);
83
82
  });
@@ -8,11 +8,11 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadPlugins = loadPlugins;
10
10
  exports.reloadPlugin = reloadPlugin;
11
+ const logger_1 = require("@docusaurus/logger");
11
12
  const init_1 = require("./init");
12
13
  const synthetic_1 = require("./synthetic");
13
14
  const translations_1 = require("../translations/translations");
14
15
  const routeConfig_1 = require("./routeConfig");
15
- const utils_1 = require("../../utils");
16
16
  const actions_1 = require("./actions");
17
17
  const pluginsUtils_1 = require("./pluginsUtils");
18
18
  async function translatePluginContent({ plugin, content, context, }) {
@@ -35,14 +35,14 @@ async function translatePluginContent({ plugin, content, context, }) {
35
35
  return translatedContent;
36
36
  }
37
37
  async function executePluginContentLoading({ plugin, context, }) {
38
- return utils_1.PerfLogger.async(`Load ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
39
- let content = await utils_1.PerfLogger.async('loadContent()', () => plugin.loadContent?.());
40
- content = await utils_1.PerfLogger.async('translatePluginContent()', () => translatePluginContent({
38
+ return logger_1.PerfLogger.async(`Load ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
39
+ let content = await logger_1.PerfLogger.async('loadContent()', () => plugin.loadContent?.());
40
+ content = await logger_1.PerfLogger.async('translatePluginContent()', () => translatePluginContent({
41
41
  plugin,
42
42
  content,
43
43
  context,
44
44
  }));
45
- const defaultCodeTranslations = (await utils_1.PerfLogger.async('getDefaultCodeTranslationMessages()', () => plugin.getDefaultCodeTranslationMessages?.())) ?? {};
45
+ const defaultCodeTranslations = (await logger_1.PerfLogger.async('getDefaultCodeTranslationMessages()', () => plugin.getDefaultCodeTranslationMessages?.())) ?? {};
46
46
  if (!plugin.contentLoaded) {
47
47
  return {
48
48
  ...plugin,
@@ -58,7 +58,7 @@ async function executePluginContentLoading({ plugin, context, }) {
58
58
  baseUrl: context.siteConfig.baseUrl,
59
59
  trailingSlash: context.siteConfig.trailingSlash,
60
60
  });
61
- await utils_1.PerfLogger.async('contentLoaded()', () =>
61
+ await logger_1.PerfLogger.async('contentLoaded()', () =>
62
62
  // @ts-expect-error: should autofix with TS 5.4
63
63
  plugin.contentLoaded({
64
64
  content,
@@ -74,12 +74,12 @@ async function executePluginContentLoading({ plugin, context, }) {
74
74
  });
75
75
  }
76
76
  async function executeAllPluginsContentLoading({ plugins, context, }) {
77
- return utils_1.PerfLogger.async(`Load plugins content`, () => {
77
+ return logger_1.PerfLogger.async(`Load plugins content`, () => {
78
78
  return Promise.all(plugins.map((plugin) => executePluginContentLoading({ plugin, context })));
79
79
  });
80
80
  }
81
81
  async function executePluginAllContentLoaded({ plugin, context, allContent, }) {
82
- return utils_1.PerfLogger.async(`allContentLoaded() - ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
82
+ return logger_1.PerfLogger.async(`allContentLoaded() - ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
83
83
  if (!plugin.allContentLoaded) {
84
84
  return { routes: [], globalData: undefined };
85
85
  }
@@ -100,7 +100,7 @@ async function executePluginAllContentLoaded({ plugin, context, allContent, }) {
100
100
  });
101
101
  }
102
102
  async function executeAllPluginsAllContentLoaded({ plugins, context, }) {
103
- return utils_1.PerfLogger.async(`allContentLoaded()`, async () => {
103
+ return logger_1.PerfLogger.async(`allContentLoaded()`, async () => {
104
104
  const allContent = (0, pluginsUtils_1.aggregateAllContent)(plugins);
105
105
  const allRoutes = [];
106
106
  const allGlobalData = {};
@@ -133,8 +133,8 @@ function mergeResults({ baseUrl, plugins, allContentLoadedResult, }) {
133
133
  * Initializes the plugins and run their lifecycle functions.
134
134
  */
135
135
  async function loadPlugins(context) {
136
- return utils_1.PerfLogger.async('Load plugins', async () => {
137
- const initializedPlugins = await utils_1.PerfLogger.async('Init plugins', () => (0, init_1.initPlugins)(context));
136
+ return logger_1.PerfLogger.async('Load plugins', async () => {
137
+ const initializedPlugins = await logger_1.PerfLogger.async('Init plugins', () => (0, init_1.initPlugins)(context));
138
138
  // TODO probably not the ideal place to hardcode those plugins
139
139
  initializedPlugins.push((0, synthetic_1.createBootstrapPlugin)(context), await (0, synthetic_1.createMDXFallbackPlugin)(context));
140
140
  const plugins = await executeAllPluginsContentLoading({
@@ -154,7 +154,7 @@ async function loadPlugins(context) {
154
154
  });
155
155
  }
156
156
  async function reloadPlugin({ pluginIdentifier, plugins: previousPlugins, context, }) {
157
- return utils_1.PerfLogger.async(`Reload plugin ${(0, pluginsUtils_1.formatPluginName)(pluginIdentifier)}`, async () => {
157
+ return logger_1.PerfLogger.async(`Reload plugin ${(0, pluginsUtils_1.formatPluginName)(pluginIdentifier)}`, async () => {
158
158
  const previousPlugin = (0, pluginsUtils_1.getPluginByIdentifier)({
159
159
  plugins: previousPlugins,
160
160
  pluginIdentifier,
@@ -13,6 +13,7 @@ exports.reloadSitePlugin = reloadSitePlugin;
13
13
  const tslib_1 = require("tslib");
14
14
  const path_1 = tslib_1.__importDefault(require("path"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
+ const logger_1 = require("@docusaurus/logger");
16
17
  const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
17
18
  const config_1 = require("./config");
18
19
  const clientModules_1 = require("./clientModules");
@@ -21,7 +22,6 @@ const htmlTags_1 = require("./htmlTags");
21
22
  const siteMetadata_1 = require("./siteMetadata");
22
23
  const i18n_1 = require("./i18n");
23
24
  const translations_1 = require("./translations/translations");
24
- const utils_2 = require("../utils");
25
25
  const codegen_1 = require("./codegen/codegen");
26
26
  const routes_1 = require("./routes");
27
27
  const storage_1 = require("./storage");
@@ -109,7 +109,7 @@ function createSiteProps(params) {
109
109
  }
110
110
  // TODO global data should be part of site props?
111
111
  async function createSiteFiles({ site, globalData, }) {
112
- return utils_2.PerfLogger.async('Create site files', async () => {
112
+ return logger_1.PerfLogger.async('Create site files', async () => {
113
113
  const { props: { plugins, generatedFilesDir, siteConfig, siteMetadata, siteStorage, i18n, codeTranslations, routes, baseUrl, }, } = site;
114
114
  const clientModules = (0, clientModules_1.getAllClientModules)(plugins);
115
115
  await (0, codegen_1.generateSiteFiles)({
@@ -133,7 +133,7 @@ async function createSiteFiles({ site, globalData, }) {
133
133
  * it generates temp files in the `.docusaurus` folder for the bundler.
134
134
  */
135
135
  async function loadSite(params) {
136
- const context = await utils_2.PerfLogger.async('Load context', () => loadContext(params));
136
+ const context = await logger_1.PerfLogger.async('Load context', () => loadContext(params));
137
137
  const { plugins, routes, globalData } = await (0, plugins_1.loadPlugins)(context);
138
138
  const props = createSiteProps({ plugins, routes, globalData, context });
139
139
  const site = { props, params };
package/lib/ssg.js CHANGED
@@ -17,8 +17,7 @@ const lodash_1 = tslib_1.__importDefault(require("lodash"));
17
17
  const eval_1 = tslib_1.__importDefault(require("eval"));
18
18
  const p_map_1 = tslib_1.__importDefault(require("p-map"));
19
19
  const html_minifier_terser_1 = require("html-minifier-terser");
20
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
21
- const utils_1 = require("./utils");
20
+ const logger_1 = tslib_1.__importStar(require("@docusaurus/logger"));
22
21
  const templates_1 = require("./templates/templates");
23
22
  // Secret way to set SSR plugin concurrency option
24
23
  // Waiting for feedback before documenting this officially?
@@ -29,8 +28,8 @@ const Concurrency = process.env.DOCUSAURUS_SSR_CONCURRENCY
29
28
  // See also https://github.com/sindresorhus/p-map/issues/24
30
29
  32;
31
30
  async function loadAppRenderer({ serverBundlePath, }) {
32
- const source = await utils_1.PerfLogger.async(`Load server bundle`, () => fs_extra_1.default.readFile(serverBundlePath));
33
- utils_1.PerfLogger.log(`Server bundle size = ${(source.length / 1024000).toFixed(3)} MB`);
31
+ const source = await logger_1.PerfLogger.async(`Load server bundle`, () => fs_extra_1.default.readFile(serverBundlePath));
32
+ logger_1.PerfLogger.log(`Server bundle size = ${(source.length / 1024000).toFixed(3)} MB`);
34
33
  const filename = path_1.default.basename(serverBundlePath);
35
34
  const globals = {
36
35
  // When using "new URL('file.js', import.meta.url)", Webpack will emit
@@ -42,7 +41,7 @@ async function loadAppRenderer({ serverBundlePath, }) {
42
41
  // See also: https://github.com/pierrec/node-eval/issues/33
43
42
  require: (0, module_1.createRequire)(serverBundlePath),
44
43
  };
45
- const serverEntry = await utils_1.PerfLogger.async(`Evaluate server bundle`, () => (0, eval_1.default)(source,
44
+ const serverEntry = await logger_1.PerfLogger.async(`Evaluate server bundle`, () => (0, eval_1.default)(source,
46
45
  /* filename: */ filename,
47
46
  /* scope: */ globals,
48
47
  /* includeGlobals: */ true));
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-6067",
4
+ "version": "0.0.0-6068",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -43,12 +43,12 @@
43
43
  "@babel/runtime": "^7.22.6",
44
44
  "@babel/runtime-corejs3": "^7.22.6",
45
45
  "@babel/traverse": "^7.22.8",
46
- "@docusaurus/cssnano-preset": "0.0.0-6067",
47
- "@docusaurus/logger": "0.0.0-6067",
48
- "@docusaurus/mdx-loader": "0.0.0-6067",
49
- "@docusaurus/utils": "0.0.0-6067",
50
- "@docusaurus/utils-common": "0.0.0-6067",
51
- "@docusaurus/utils-validation": "0.0.0-6067",
46
+ "@docusaurus/cssnano-preset": "0.0.0-6068",
47
+ "@docusaurus/logger": "0.0.0-6068",
48
+ "@docusaurus/mdx-loader": "0.0.0-6068",
49
+ "@docusaurus/utils": "0.0.0-6068",
50
+ "@docusaurus/utils-common": "0.0.0-6068",
51
+ "@docusaurus/utils-validation": "0.0.0-6068",
52
52
  "autoprefixer": "^10.4.14",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -104,8 +104,8 @@
104
104
  "webpackbar": "^5.0.2"
105
105
  },
106
106
  "devDependencies": {
107
- "@docusaurus/module-type-aliases": "0.0.0-6067",
108
- "@docusaurus/types": "0.0.0-6067",
107
+ "@docusaurus/module-type-aliases": "0.0.0-6068",
108
+ "@docusaurus/types": "0.0.0-6068",
109
109
  "@total-typescript/shoehorn": "^0.1.2",
110
110
  "@types/detect-port": "^1.3.3",
111
111
  "@types/react-dom": "^18.2.7",
@@ -132,5 +132,5 @@
132
132
  "engines": {
133
133
  "node": ">=18.0"
134
134
  },
135
- "gitHead": "856911a5474e8e907f83438abe5c42d4793e06cb"
135
+ "gitHead": "4f0bc982b589965d7238334bb9b5bf6c483cc35a"
136
136
  }
package/lib/utils.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export declare const PerfDebuggingEnabled: boolean;
2
- type PerfLoggerAPI = {
3
- start: (label: string) => void;
4
- end: (label: string) => void;
5
- log: (message: string) => void;
6
- async: <Result>(label: string, asyncFn: () => Result | Promise<Result>) => Promise<Result>;
7
- };
8
- export declare const PerfLogger: PerfLoggerAPI;
9
- export {};
package/lib/utils.js DELETED
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PerfLogger = exports.PerfDebuggingEnabled = void 0;
4
- const tslib_1 = require("tslib");
5
- /**
6
- * Copyright (c) Facebook, Inc. and its affiliates.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */
11
- const async_hooks_1 = require("async_hooks");
12
- const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
- // For now this is a private env variable we use internally
14
- // But we'll want to expose this feature officially some day
15
- exports.PerfDebuggingEnabled = !!process.env.DOCUSAURUS_PERF_LOGGER;
16
- const Thresholds = {
17
- min: 5,
18
- yellow: 100,
19
- red: 1000,
20
- };
21
- const PerfPrefix = logger_1.default.yellow(`[PERF] `);
22
- // This is what enables to "see the parent stack" for each log
23
- // Parent1 > Parent2 > Parent3 > child trace
24
- const ParentPrefix = new async_hooks_1.AsyncLocalStorage();
25
- function applyParentPrefix(label) {
26
- const parentPrefix = ParentPrefix.getStore();
27
- return parentPrefix ? `${parentPrefix} > ${label}` : label;
28
- }
29
- function createPerfLogger() {
30
- if (!exports.PerfDebuggingEnabled) {
31
- const noop = () => { };
32
- return {
33
- start: noop,
34
- end: noop,
35
- log: noop,
36
- async: async (_label, asyncFn) => asyncFn(),
37
- };
38
- }
39
- const formatDuration = (duration) => {
40
- if (duration > Thresholds.red) {
41
- return logger_1.default.red(`${(duration / 1000).toFixed(2)} seconds!`);
42
- }
43
- else if (duration > Thresholds.yellow) {
44
- return logger_1.default.yellow(`${duration.toFixed(2)} ms`);
45
- }
46
- else {
47
- return logger_1.default.green(`${duration.toFixed(2)} ms`);
48
- }
49
- };
50
- const logDuration = (label, duration) => {
51
- if (duration < Thresholds.min) {
52
- return;
53
- }
54
- console.log(`${PerfPrefix + label} - ${formatDuration(duration)}`);
55
- };
56
- const start = (label) => performance.mark(label);
57
- const end = (label) => {
58
- const { duration } = performance.measure(label);
59
- performance.clearMarks(label);
60
- logDuration(applyParentPrefix(label), duration);
61
- };
62
- const log = (label) => console.log(PerfPrefix + applyParentPrefix(label));
63
- const async = async (label, asyncFn) => {
64
- const finalLabel = applyParentPrefix(label);
65
- const before = performance.now();
66
- const result = await ParentPrefix.run(finalLabel, () => asyncFn());
67
- const duration = performance.now() - before;
68
- logDuration(finalLabel, duration);
69
- return result;
70
- };
71
- return {
72
- start,
73
- end,
74
- log,
75
- async,
76
- };
77
- }
78
- exports.PerfLogger = createPerfLogger();