@docusaurus/core 0.0.0-6049 → 0.0.0-6052

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.
@@ -202,7 +202,9 @@ async function getBuildClientConfig({ props, cliOptions, }) {
202
202
  plugins,
203
203
  config,
204
204
  isServer: false,
205
- jsLoader: props.siteConfig.webpack?.jsLoader,
205
+ utils: await (0, configure_1.createConfigureWebpackUtils)({
206
+ siteConfig: props.siteConfig,
207
+ }),
206
208
  });
207
209
  return { clientConfig: config, clientManifestPath: result.clientManifestPath };
208
210
  }
@@ -216,7 +218,9 @@ async function getBuildServerConfig({ props }) {
216
218
  plugins,
217
219
  config,
218
220
  isServer: true,
219
- jsLoader: props.siteConfig.webpack?.jsLoader,
221
+ utils: await (0, configure_1.createConfigureWebpackUtils)({
222
+ siteConfig: props.siteConfig,
223
+ }),
220
224
  });
221
225
  return { serverConfig: config, serverBundlePath: result.serverBundlePath };
222
226
  }
@@ -108,7 +108,7 @@ async function getStartClientConfig({ props, minify, poll, }) {
108
108
  plugins,
109
109
  config,
110
110
  isServer: false,
111
- jsLoader: siteConfig.webpack?.jsLoader,
111
+ utils: await (0, configure_1.createConfigureWebpackUtils)({ siteConfig }),
112
112
  });
113
113
  return config;
114
114
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { ConfigureWebpackUtils } from '@docusaurus/types';
8
+ export declare function getSwcJsLoaderFactory(): Promise<ConfigureWebpackUtils['getJSLoader']>;
package/lib/faster.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getSwcJsLoaderFactory = getSwcJsLoaderFactory;
10
+ async function importFaster() {
11
+ return import('@docusaurus/faster');
12
+ }
13
+ async function ensureFaster() {
14
+ try {
15
+ return await importFaster();
16
+ }
17
+ catch (error) {
18
+ throw new Error('Your Docusaurus site need to add the @docusaurus/faster package as a dependency.', { cause: error });
19
+ }
20
+ }
21
+ async function getSwcJsLoaderFactory() {
22
+ const faster = await ensureFaster();
23
+ return faster.getSwcJsLoaderFactory;
24
+ }
@@ -5,10 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import { Joi } from '@docusaurus/utils-validation';
8
- import type { FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
8
+ import type { FasterConfig, FutureConfig, StorageConfig } from '@docusaurus/types/src/config';
9
9
  import type { DocusaurusConfig, I18nConfig, MarkdownConfig } from '@docusaurus/types';
10
10
  export declare const DEFAULT_I18N_CONFIG: I18nConfig;
11
11
  export declare const DEFAULT_STORAGE_CONFIG: StorageConfig;
12
+ export declare const DEFAULT_FASTER_CONFIG: FasterConfig;
13
+ export declare const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig;
12
14
  export declare const DEFAULT_FUTURE_CONFIG: FutureConfig;
13
15
  export declare const DEFAULT_MARKDOWN_CONFIG: MarkdownConfig;
14
16
  export declare const DEFAULT_CONFIG: Pick<DocusaurusConfig, 'i18n' | 'future' | 'onBrokenLinks' | 'onBrokenAnchors' | 'onBrokenMarkdownLinks' | 'onDuplicateRoutes' | 'plugins' | 'themes' | 'presets' | 'headTags' | 'stylesheets' | 'scripts' | 'clientModules' | 'customFields' | 'themeConfig' | 'titleDelimiter' | 'noIndex' | 'tagline' | 'baseUrlIssueBanner' | 'staticDirectories' | 'markdown'>;
@@ -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.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
9
+ exports.ConfigSchema = exports.DEFAULT_CONFIG = exports.DEFAULT_MARKDOWN_CONFIG = exports.DEFAULT_FUTURE_CONFIG = exports.DEFAULT_FASTER_CONFIG_TRUE = exports.DEFAULT_FASTER_CONFIG = exports.DEFAULT_STORAGE_CONFIG = exports.DEFAULT_I18N_CONFIG = void 0;
10
10
  exports.validateConfig = validateConfig;
11
11
  const utils_1 = require("@docusaurus/utils");
12
12
  const utils_validation_1 = require("@docusaurus/utils-validation");
@@ -22,7 +22,15 @@ exports.DEFAULT_STORAGE_CONFIG = {
22
22
  type: 'localStorage',
23
23
  namespace: false,
24
24
  };
25
+ exports.DEFAULT_FASTER_CONFIG = {
26
+ swcJsLoader: false,
27
+ };
28
+ // When using the "faster: true" shortcut
29
+ exports.DEFAULT_FASTER_CONFIG_TRUE = {
30
+ swcJsLoader: true,
31
+ };
25
32
  exports.DEFAULT_FUTURE_CONFIG = {
33
+ experimental_faster: exports.DEFAULT_FASTER_CONFIG,
26
34
  experimental_storage: exports.DEFAULT_STORAGE_CONFIG,
27
35
  experimental_router: 'browser',
28
36
  };
@@ -130,6 +138,14 @@ const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
130
138
  })
131
139
  .optional()
132
140
  .default(exports.DEFAULT_I18N_CONFIG);
141
+ const FASTER_CONFIG_SCHEMA = utils_validation_1.Joi.alternatives()
142
+ .try(utils_validation_1.Joi.object({
143
+ swcJsLoader: utils_validation_1.Joi.boolean().default(exports.DEFAULT_FASTER_CONFIG.swcJsLoader),
144
+ }), utils_validation_1.Joi.boolean()
145
+ .required()
146
+ .custom((bool) => bool ? exports.DEFAULT_FASTER_CONFIG_TRUE : exports.DEFAULT_FASTER_CONFIG))
147
+ .optional()
148
+ .default(exports.DEFAULT_FASTER_CONFIG);
133
149
  const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
134
150
  type: utils_validation_1.Joi.string()
135
151
  .equal('localStorage', 'sessionStorage')
@@ -141,6 +157,7 @@ const STORAGE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
141
157
  .optional()
142
158
  .default(exports.DEFAULT_STORAGE_CONFIG);
143
159
  const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
160
+ experimental_faster: FASTER_CONFIG_SCHEMA,
144
161
  experimental_storage: STORAGE_CONFIG_SCHEMA,
145
162
  experimental_router: utils_validation_1.Joi.string()
146
163
  .equal('browser', 'hash')
@@ -51,6 +51,7 @@ async function createBaseConfig({ props, isServer, minify, }) {
51
51
  const name = isServer ? 'server' : 'client';
52
52
  const mode = isProd ? 'production' : 'development';
53
53
  const themeAliases = await (0, aliases_1.loadThemeAliases)({ siteDir, plugins });
54
+ const createJsLoader = await (0, utils_2.createJsLoaderFactory)({ siteConfig });
54
55
  return {
55
56
  mode,
56
57
  name,
@@ -175,7 +176,7 @@ async function createBaseConfig({ props, isServer, minify, }) {
175
176
  test: /\.[jt]sx?$/i,
176
177
  exclude: excludeJS,
177
178
  use: [
178
- (0, utils_2.getCustomizableJSLoader)(siteConfig.webpack?.jsLoader)({
179
+ createJsLoader({
179
180
  isServer,
180
181
  babelOptions: await (0, utils_2.getCustomBabelConfigFilePath)(siteDir),
181
182
  }),
@@ -4,22 +4,36 @@
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 { Configuration, RuleSetRule } from 'webpack';
8
- import type { Plugin, LoadedPlugin } from '@docusaurus/types';
7
+ import { createJsLoaderFactory } from './utils';
8
+ import type { Configuration } from 'webpack';
9
+ import type { Plugin, ConfigureWebpackUtils, LoadedPlugin } from '@docusaurus/types';
10
+ /**
11
+ * Creates convenient utils to inject into the configureWebpack() lifecycle
12
+ * @param config the Docusaurus config
13
+ */
14
+ export declare function createConfigureWebpackUtils({ siteConfig, }: {
15
+ siteConfig: Parameters<typeof createJsLoaderFactory>[0]['siteConfig'];
16
+ }): Promise<ConfigureWebpackUtils>;
9
17
  /**
10
18
  * Helper function to modify webpack config
11
19
  * @param configureWebpack a webpack config or a function to modify config
12
20
  * @param config initial webpack config
13
21
  * @param isServer indicates if this is a server webpack configuration
14
- * @param jsLoader custom js loader config
22
+ * @param utils the <code>ConfigureWebpackUtils</code> utils to inject into the configureWebpack() lifecycle
15
23
  * @param content content loaded by the plugin
16
24
  * @returns final/ modified webpack config
17
25
  */
18
- export declare function applyConfigureWebpack(configureWebpack: NonNullable<Plugin['configureWebpack']>, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
26
+ export declare function applyConfigureWebpack({ configureWebpack, config, isServer, utils, content, }: {
27
+ configureWebpack: NonNullable<Plugin['configureWebpack']>;
28
+ config: Configuration;
29
+ isServer: boolean;
30
+ utils: ConfigureWebpackUtils;
31
+ content: unknown;
32
+ }): Configuration;
19
33
  export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
20
- export declare function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }: {
34
+ export declare function executePluginsConfigureWebpack({ plugins, config: configInput, isServer, utils, }: {
21
35
  plugins: LoadedPlugin[];
22
36
  config: Configuration;
23
37
  isServer: boolean;
24
- jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined;
38
+ utils: ConfigureWebpackUtils;
25
39
  }): Configuration;
@@ -6,26 +6,32 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createConfigureWebpackUtils = createConfigureWebpackUtils;
9
10
  exports.applyConfigureWebpack = applyConfigureWebpack;
10
11
  exports.applyConfigurePostCss = applyConfigurePostCss;
11
12
  exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
12
13
  const webpack_merge_1 = require("webpack-merge");
13
14
  const utils_1 = require("./utils");
15
+ /**
16
+ * Creates convenient utils to inject into the configureWebpack() lifecycle
17
+ * @param config the Docusaurus config
18
+ */
19
+ async function createConfigureWebpackUtils({ siteConfig, }) {
20
+ return {
21
+ getStyleLoaders: utils_1.getStyleLoaders,
22
+ getJSLoader: await (0, utils_1.createJsLoaderFactory)({ siteConfig }),
23
+ };
24
+ }
14
25
  /**
15
26
  * Helper function to modify webpack config
16
27
  * @param configureWebpack a webpack config or a function to modify config
17
28
  * @param config initial webpack config
18
29
  * @param isServer indicates if this is a server webpack configuration
19
- * @param jsLoader custom js loader config
30
+ * @param utils the <code>ConfigureWebpackUtils</code> utils to inject into the configureWebpack() lifecycle
20
31
  * @param content content loaded by the plugin
21
32
  * @returns final/ modified webpack config
22
33
  */
23
- function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, content) {
24
- // Export some utility functions
25
- const utils = {
26
- getStyleLoaders: utils_1.getStyleLoaders,
27
- getJSLoader: (0, utils_1.getCustomizableJSLoader)(jsLoader),
28
- };
34
+ function applyConfigureWebpack({ configureWebpack, config, isServer, utils, content, }) {
29
35
  if (typeof configureWebpack === 'function') {
30
36
  const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
31
37
  const customizeRules = mergeStrategy ?? {};
@@ -74,14 +80,19 @@ function executePluginsConfigurePostCss({ plugins, config, }) {
74
80
  return resultConfig;
75
81
  }
76
82
  // Plugin Lifecycle - configureWebpack()
77
- function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }) {
83
+ function executePluginsConfigureWebpack({ plugins, config: configInput, isServer, utils, }) {
84
+ let config = configInput;
78
85
  // Step1 - Configure Webpack
79
- let resultConfig = config;
80
86
  plugins.forEach((plugin) => {
81
87
  const { configureWebpack } = plugin;
82
88
  if (configureWebpack) {
83
- resultConfig = applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
84
- resultConfig, isServer, jsLoader, plugin.content);
89
+ config = applyConfigureWebpack({
90
+ configureWebpack: configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
91
+ config,
92
+ isServer,
93
+ utils,
94
+ content: plugin.content,
95
+ });
85
96
  }
86
97
  });
87
98
  // Step2 - For client code, configure PostCSS
@@ -90,10 +101,10 @@ function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }
90
101
  // See https://github.com/facebook/docusaurus/issues/10106
91
102
  // Note: it's useless to configure postCSS for the server
92
103
  if (!isServer) {
93
- resultConfig = executePluginsConfigurePostCss({
104
+ config = executePluginsConfigurePostCss({
94
105
  plugins,
95
- config: resultConfig,
106
+ config,
96
107
  });
97
108
  }
98
- return resultConfig;
109
+ return config;
99
110
  }
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import webpack, { type Configuration, type RuleSetRule } from 'webpack';
8
+ import type { ConfigureWebpackUtils, DocusaurusConfig } from '@docusaurus/types';
8
9
  import type { TransformOptions } from '@babel/core';
9
10
  export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
10
11
  export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
@@ -16,10 +17,14 @@ export declare function getBabelOptions({ isServer, babelOptions, }?: {
16
17
  isServer?: boolean;
17
18
  babelOptions?: TransformOptions | string;
18
19
  }): TransformOptions;
19
- export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer: boolean) => RuleSetRule)) => ({ isServer, babelOptions, }: {
20
- isServer: boolean;
21
- babelOptions?: TransformOptions | string;
22
- }) => RuleSetRule;
20
+ export declare function createJsLoaderFactory({ siteConfig, }: {
21
+ siteConfig: {
22
+ webpack?: DocusaurusConfig['webpack'];
23
+ future?: {
24
+ experimental_faster: DocusaurusConfig['future']['experimental_faster'];
25
+ };
26
+ };
27
+ }): Promise<ConfigureWebpackUtils['getJSLoader']>;
23
28
  declare global {
24
29
  interface Error {
25
30
  /** @see https://webpack.js.org/api/node/#error-handling */
@@ -6,12 +6,12 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getCustomizableJSLoader = void 0;
10
9
  exports.formatStatsErrorMessage = formatStatsErrorMessage;
11
10
  exports.printStatsWarnings = printStatsWarnings;
12
11
  exports.getStyleLoaders = getStyleLoaders;
13
12
  exports.getCustomBabelConfigFilePath = getCustomBabelConfigFilePath;
14
13
  exports.getBabelOptions = getBabelOptions;
14
+ exports.createJsLoaderFactory = createJsLoaderFactory;
15
15
  exports.compile = compile;
16
16
  exports.getHttpsConfig = getHttpsConfig;
17
17
  const tslib_1 = require("tslib");
@@ -23,6 +23,7 @@ const utils_1 = require("@docusaurus/utils");
23
23
  const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
24
24
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
25
25
  const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
26
+ const faster_1 = require("../faster");
26
27
  function formatStatsErrorMessage(statsJson) {
27
28
  if (statsJson?.errors?.length) {
28
29
  // TODO formatWebpackMessages does not print stack-traces
@@ -123,18 +124,32 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
123
124
  caller: { name: isServer ? 'server' : 'client' },
124
125
  };
125
126
  }
126
- // Name is generic on purpose
127
- // we want to support multiple js loader implementations (babel + esbuild)
128
- function getDefaultBabelLoader({ isServer, babelOptions, }) {
127
+ const BabelJsLoaderFactory = ({ isServer, babelOptions, }) => {
129
128
  return {
130
129
  loader: require.resolve('babel-loader'),
131
130
  options: getBabelOptions({ isServer, babelOptions }),
132
131
  };
132
+ };
133
+ // Confusing: function that creates a function that creates actual js loaders
134
+ // This is done on purpose because the js loader factory is a public API
135
+ // It is injected in configureWebpack plugin lifecycle for plugin authors
136
+ async function createJsLoaderFactory({ siteConfig, }) {
137
+ const jsLoader = siteConfig.webpack?.jsLoader ?? 'babel';
138
+ if (jsLoader instanceof Function &&
139
+ siteConfig.future?.experimental_faster.swcJsLoader) {
140
+ throw new Error("You can't use a custom webpack.jsLoader and experimental_faster.swcJsLoader at the same time");
141
+ }
142
+ if (jsLoader instanceof Function) {
143
+ return ({ isServer }) => jsLoader(isServer);
144
+ }
145
+ if (siteConfig.future?.experimental_faster.swcJsLoader) {
146
+ return (0, faster_1.getSwcJsLoaderFactory)();
147
+ }
148
+ if (jsLoader === 'babel') {
149
+ return BabelJsLoaderFactory;
150
+ }
151
+ throw new Error(`Docusaurus bug: unexpected jsLoader value${jsLoader}`);
133
152
  }
134
- const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOptions, }) => jsLoader === 'babel'
135
- ? getDefaultBabelLoader({ isServer, babelOptions })
136
- : jsLoader(isServer);
137
- exports.getCustomizableJSLoader = getCustomizableJSLoader;
138
153
  function compile(config) {
139
154
  return new Promise((resolve, reject) => {
140
155
  const compiler = (0, webpack_1.default)(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-6049",
4
+ "version": "0.0.0-6052",
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-6049",
47
- "@docusaurus/logger": "0.0.0-6049",
48
- "@docusaurus/mdx-loader": "0.0.0-6049",
49
- "@docusaurus/utils": "0.0.0-6049",
50
- "@docusaurus/utils-common": "0.0.0-6049",
51
- "@docusaurus/utils-validation": "0.0.0-6049",
46
+ "@docusaurus/cssnano-preset": "0.0.0-6052",
47
+ "@docusaurus/logger": "0.0.0-6052",
48
+ "@docusaurus/mdx-loader": "0.0.0-6052",
49
+ "@docusaurus/utils": "0.0.0-6052",
50
+ "@docusaurus/utils-common": "0.0.0-6052",
51
+ "@docusaurus/utils-validation": "0.0.0-6052",
52
52
  "autoprefixer": "^10.4.14",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-dynamic-import-node": "^2.3.3",
@@ -103,8 +103,8 @@
103
103
  "webpackbar": "^5.0.2"
104
104
  },
105
105
  "devDependencies": {
106
- "@docusaurus/module-type-aliases": "0.0.0-6049",
107
- "@docusaurus/types": "0.0.0-6049",
106
+ "@docusaurus/module-type-aliases": "0.0.0-6052",
107
+ "@docusaurus/types": "0.0.0-6052",
108
108
  "@total-typescript/shoehorn": "^0.1.2",
109
109
  "@types/detect-port": "^1.3.3",
110
110
  "@types/react-dom": "^18.2.7",
@@ -118,12 +118,18 @@
118
118
  "tree-node-cli": "^1.6.0"
119
119
  },
120
120
  "peerDependencies": {
121
+ "@docusaurus/faster": "3.5.2",
121
122
  "@mdx-js/react": "^3.0.0",
122
123
  "react": "^18.0.0",
123
124
  "react-dom": "^18.0.0"
124
125
  },
126
+ "peerDependenciesMeta": {
127
+ "@docusaurus/faster": {
128
+ "optional": true
129
+ }
130
+ },
125
131
  "engines": {
126
132
  "node": ">=18.0"
127
133
  },
128
- "gitHead": "f6855e0f81535a12a66babb934ad8dcf6e9361b2"
134
+ "gitHead": "ff41451cf14cc627f2c0e002edc580ae91732eaf"
129
135
  }