@docusaurus/core 0.0.0-5940 → 0.0.0-5941

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.
@@ -17,6 +17,7 @@ const site_1 = require("../server/site");
17
17
  const brokenLinks_1 = require("../server/brokenLinks");
18
18
  const client_1 = require("../webpack/client");
19
19
  const server_1 = tslib_1.__importDefault(require("../webpack/server"));
20
+ const configure_1 = require("../webpack/configure");
20
21
  const utils_2 = require("../webpack/utils");
21
22
  const utils_3 = require("../utils");
22
23
  const i18n_1 = require("../server/i18n");
@@ -194,11 +195,7 @@ async function getBuildClientConfig({ props, cliOptions, }) {
194
195
  bundleAnalyzer: cliOptions.bundleAnalyzer ?? false,
195
196
  });
196
197
  let { config } = result;
197
- config = (0, utils_2.executePluginsConfigurePostCss)({
198
- plugins,
199
- config,
200
- });
201
- config = (0, utils_2.executePluginsConfigureWebpack)({
198
+ config = (0, configure_1.executePluginsConfigureWebpack)({
202
199
  plugins,
203
200
  config,
204
201
  isServer: false,
@@ -212,7 +209,7 @@ async function getBuildServerConfig({ props }) {
212
209
  props,
213
210
  });
214
211
  let { config } = result;
215
- config = (0, utils_2.executePluginsConfigureWebpack)({
212
+ config = (0, configure_1.executePluginsConfigureWebpack)({
216
213
  plugins,
217
214
  config,
218
215
  isServer: true,
@@ -16,6 +16,7 @@ const webpack_dev_server_1 = tslib_1.__importDefault(require("webpack-dev-server
16
16
  const evalSourceMapMiddleware_1 = tslib_1.__importDefault(require("react-dev-utils/evalSourceMapMiddleware"));
17
17
  const watcher_1 = require("./watcher");
18
18
  const utils_1 = require("../../webpack/utils");
19
+ const configure_1 = require("../../webpack/configure");
19
20
  const client_1 = require("../../webpack/client");
20
21
  // E2E_TEST=true docusaurus start
21
22
  // Makes "docusaurus start" exit immediately on success/error, for E2E test
@@ -103,8 +104,7 @@ async function getStartClientConfig({ props, minify, poll, }) {
103
104
  minify,
104
105
  poll,
105
106
  });
106
- config = (0, utils_1.executePluginsConfigurePostCss)({ plugins, config });
107
- config = (0, utils_1.executePluginsConfigureWebpack)({
107
+ config = (0, configure_1.executePluginsConfigureWebpack)({
108
108
  plugins,
109
109
  config,
110
110
  isServer: false,
@@ -0,0 +1,25 @@
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 { Configuration, RuleSetRule } from 'webpack';
8
+ import type { Plugin, LoadedPlugin } from '@docusaurus/types';
9
+ /**
10
+ * Helper function to modify webpack config
11
+ * @param configureWebpack a webpack config or a function to modify config
12
+ * @param config initial webpack config
13
+ * @param isServer indicates if this is a server webpack configuration
14
+ * @param jsLoader custom js loader config
15
+ * @param content content loaded by the plugin
16
+ * @returns final/ modified webpack config
17
+ */
18
+ export declare function applyConfigureWebpack(configureWebpack: NonNullable<Plugin['configureWebpack']>, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
19
+ export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
20
+ export declare function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }: {
21
+ plugins: LoadedPlugin[];
22
+ config: Configuration;
23
+ isServer: boolean;
24
+ jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined;
25
+ }): Configuration;
@@ -0,0 +1,100 @@
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.executePluginsConfigureWebpack = exports.applyConfigurePostCss = exports.applyConfigureWebpack = void 0;
10
+ const webpack_merge_1 = require("webpack-merge");
11
+ const utils_1 = require("./utils");
12
+ /**
13
+ * Helper function to modify webpack config
14
+ * @param configureWebpack a webpack config or a function to modify config
15
+ * @param config initial webpack config
16
+ * @param isServer indicates if this is a server webpack configuration
17
+ * @param jsLoader custom js loader config
18
+ * @param content content loaded by the plugin
19
+ * @returns final/ modified webpack config
20
+ */
21
+ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, content) {
22
+ // Export some utility functions
23
+ const utils = {
24
+ getStyleLoaders: utils_1.getStyleLoaders,
25
+ getJSLoader: (0, utils_1.getCustomizableJSLoader)(jsLoader),
26
+ };
27
+ if (typeof configureWebpack === 'function') {
28
+ const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
29
+ const customizeRules = mergeStrategy ?? {};
30
+ return (0, webpack_merge_1.mergeWithCustomize)({
31
+ customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
32
+ customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
33
+ })(config, res);
34
+ }
35
+ return config;
36
+ }
37
+ exports.applyConfigureWebpack = applyConfigureWebpack;
38
+ function applyConfigurePostCss(configurePostCss, config) {
39
+ // Not ideal heuristic but good enough for our use-case?
40
+ function isPostCssLoader(loader) {
41
+ return !!loader?.options?.postcssOptions;
42
+ }
43
+ // Does not handle all edge cases, but good enough for now
44
+ function overridePostCssOptions(entry) {
45
+ if (isPostCssLoader(entry)) {
46
+ entry.options.postcssOptions = configurePostCss(entry.options.postcssOptions);
47
+ }
48
+ else if (Array.isArray(entry.oneOf)) {
49
+ entry.oneOf.forEach((r) => {
50
+ if (r) {
51
+ overridePostCssOptions(r);
52
+ }
53
+ });
54
+ }
55
+ else if (Array.isArray(entry.use)) {
56
+ entry.use
57
+ .filter((u) => typeof u === 'object')
58
+ .forEach((rule) => overridePostCssOptions(rule));
59
+ }
60
+ }
61
+ config.module?.rules?.forEach((rule) => overridePostCssOptions(rule));
62
+ return config;
63
+ }
64
+ exports.applyConfigurePostCss = applyConfigurePostCss;
65
+ // Plugin Lifecycle - configurePostCss()
66
+ function executePluginsConfigurePostCss({ plugins, config, }) {
67
+ let resultConfig = config;
68
+ plugins.forEach((plugin) => {
69
+ const { configurePostCss } = plugin;
70
+ if (configurePostCss) {
71
+ resultConfig = applyConfigurePostCss(configurePostCss.bind(plugin), resultConfig);
72
+ }
73
+ });
74
+ return resultConfig;
75
+ }
76
+ // Plugin Lifecycle - configureWebpack()
77
+ function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }) {
78
+ // Step1 - Configure Webpack
79
+ let resultConfig = config;
80
+ plugins.forEach((plugin) => {
81
+ const { configureWebpack } = plugin;
82
+ if (configureWebpack) {
83
+ resultConfig = applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
84
+ resultConfig, isServer, jsLoader, plugin.content);
85
+ }
86
+ });
87
+ // Step2 - For client code, configure PostCSS
88
+ // The order matters! We want to configure PostCSS on loaders
89
+ // that were potentially added by configureWebpack
90
+ // See https://github.com/facebook/docusaurus/issues/10106
91
+ // Note: it's useless to configure postCSS for the server
92
+ if (!isServer) {
93
+ resultConfig = executePluginsConfigurePostCss({
94
+ plugins,
95
+ config: resultConfig,
96
+ });
97
+ }
98
+ return resultConfig;
99
+ }
100
+ exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
@@ -7,7 +7,6 @@
7
7
  /// <reference types="node" />
8
8
  import webpack, { type Configuration, type RuleSetRule } from 'webpack';
9
9
  import type { TransformOptions } from '@babel/core';
10
- import type { Plugin, LoadedPlugin } from '@docusaurus/types';
11
10
  export declare function formatStatsErrorMessage(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): string | undefined;
12
11
  export declare function printStatsWarnings(statsJson: ReturnType<webpack.Stats['toJson']> | undefined): void;
13
12
  export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
@@ -22,27 +21,6 @@ export declare const getCustomizableJSLoader: (jsLoader?: 'babel' | ((isServer:
22
21
  isServer: boolean;
23
22
  babelOptions?: TransformOptions | string;
24
23
  }) => RuleSetRule;
25
- /**
26
- * Helper function to modify webpack config
27
- * @param configureWebpack a webpack config or a function to modify config
28
- * @param config initial webpack config
29
- * @param isServer indicates if this is a server webpack configuration
30
- * @param jsLoader custom js loader config
31
- * @param content content loaded by the plugin
32
- * @returns final/ modified webpack config
33
- */
34
- export declare function applyConfigureWebpack(configureWebpack: NonNullable<Plugin['configureWebpack']>, config: Configuration, isServer: boolean, jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined, content: unknown): Configuration;
35
- export declare function applyConfigurePostCss(configurePostCss: NonNullable<Plugin['configurePostCss']>, config: Configuration): Configuration;
36
- export declare function executePluginsConfigurePostCss({ plugins, config, }: {
37
- plugins: LoadedPlugin[];
38
- config: Configuration;
39
- }): Configuration;
40
- export declare function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }: {
41
- plugins: LoadedPlugin[];
42
- config: Configuration;
43
- isServer: boolean;
44
- jsLoader: 'babel' | ((isServer: boolean) => RuleSetRule) | undefined;
45
- }): Configuration;
46
24
  declare global {
47
25
  interface Error {
48
26
  /** @see https://webpack.js.org/api/node/#error-handling */
@@ -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.getHttpsConfig = exports.compile = exports.executePluginsConfigureWebpack = exports.executePluginsConfigurePostCss = exports.applyConfigurePostCss = exports.applyConfigureWebpack = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = exports.printStatsWarnings = exports.formatStatsErrorMessage = void 0;
9
+ exports.getHttpsConfig = exports.compile = exports.getCustomizableJSLoader = exports.getBabelOptions = exports.getCustomBabelConfigFilePath = exports.getStyleLoaders = exports.printStatsWarnings = exports.formatStatsErrorMessage = void 0;
10
10
  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"));
@@ -14,7 +14,6 @@ const crypto_1 = tslib_1.__importDefault(require("crypto"));
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const utils_1 = require("@docusaurus/utils");
16
16
  const mini_css_extract_plugin_1 = tslib_1.__importDefault(require("mini-css-extract-plugin"));
17
- const webpack_merge_1 = require("webpack-merge");
18
17
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
19
18
  const formatWebpackMessages_1 = tslib_1.__importDefault(require("react-dev-utils/formatWebpackMessages"));
20
19
  function formatStatsErrorMessage(statsJson) {
@@ -134,84 +133,6 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
134
133
  ? getDefaultBabelLoader({ isServer, babelOptions })
135
134
  : jsLoader(isServer);
136
135
  exports.getCustomizableJSLoader = getCustomizableJSLoader;
137
- /**
138
- * Helper function to modify webpack config
139
- * @param configureWebpack a webpack config or a function to modify config
140
- * @param config initial webpack config
141
- * @param isServer indicates if this is a server webpack configuration
142
- * @param jsLoader custom js loader config
143
- * @param content content loaded by the plugin
144
- * @returns final/ modified webpack config
145
- */
146
- function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, content) {
147
- // Export some utility functions
148
- const utils = {
149
- getStyleLoaders,
150
- getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
151
- };
152
- if (typeof configureWebpack === 'function') {
153
- const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content) ?? {};
154
- const customizeRules = mergeStrategy ?? {};
155
- return (0, webpack_merge_1.mergeWithCustomize)({
156
- customizeArray: (0, webpack_merge_1.customizeArray)(customizeRules),
157
- customizeObject: (0, webpack_merge_1.customizeObject)(customizeRules),
158
- })(config, res);
159
- }
160
- return config;
161
- }
162
- exports.applyConfigureWebpack = applyConfigureWebpack;
163
- function applyConfigurePostCss(configurePostCss, config) {
164
- // Not ideal heuristic but good enough for our use-case?
165
- function isPostCssLoader(loader) {
166
- return !!loader?.options?.postcssOptions;
167
- }
168
- // Does not handle all edge cases, but good enough for now
169
- function overridePostCssOptions(entry) {
170
- if (isPostCssLoader(entry)) {
171
- entry.options.postcssOptions = configurePostCss(entry.options.postcssOptions);
172
- }
173
- else if (Array.isArray(entry.oneOf)) {
174
- entry.oneOf.forEach((r) => {
175
- if (r) {
176
- overridePostCssOptions(r);
177
- }
178
- });
179
- }
180
- else if (Array.isArray(entry.use)) {
181
- entry.use
182
- .filter((u) => typeof u === 'object')
183
- .forEach((rule) => overridePostCssOptions(rule));
184
- }
185
- }
186
- config.module?.rules?.forEach((rule) => overridePostCssOptions(rule));
187
- return config;
188
- }
189
- exports.applyConfigurePostCss = applyConfigurePostCss;
190
- // Plugin Lifecycle - configurePostCss()
191
- function executePluginsConfigurePostCss({ plugins, config, }) {
192
- let resultConfig = config;
193
- plugins.forEach((plugin) => {
194
- const { configurePostCss } = plugin;
195
- if (configurePostCss) {
196
- resultConfig = applyConfigurePostCss(configurePostCss.bind(plugin), resultConfig);
197
- }
198
- });
199
- return resultConfig;
200
- }
201
- exports.executePluginsConfigurePostCss = executePluginsConfigurePostCss;
202
- // Plugin Lifecycle - configureWebpack()
203
- function executePluginsConfigureWebpack({ plugins, config, isServer, jsLoader, }) {
204
- let resultConfig = config;
205
- plugins.forEach((plugin) => {
206
- const { configureWebpack } = plugin;
207
- if (configureWebpack) {
208
- resultConfig = applyConfigureWebpack(configureWebpack.bind(plugin), // The plugin lifecycle may reference `this`.
209
- resultConfig, isServer, jsLoader, plugin.content);
210
- }
211
- });
212
- return resultConfig;
213
- }
214
- exports.executePluginsConfigureWebpack = executePluginsConfigureWebpack;
215
136
  function compile(config) {
216
137
  return new Promise((resolve, reject) => {
217
138
  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-5940",
4
+ "version": "0.0.0-5941",
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-5940",
47
- "@docusaurus/logger": "0.0.0-5940",
48
- "@docusaurus/mdx-loader": "0.0.0-5940",
49
- "@docusaurus/utils": "0.0.0-5940",
50
- "@docusaurus/utils-common": "0.0.0-5940",
51
- "@docusaurus/utils-validation": "0.0.0-5940",
46
+ "@docusaurus/cssnano-preset": "0.0.0-5941",
47
+ "@docusaurus/logger": "0.0.0-5941",
48
+ "@docusaurus/mdx-loader": "0.0.0-5941",
49
+ "@docusaurus/utils": "0.0.0-5941",
50
+ "@docusaurus/utils-common": "0.0.0-5941",
51
+ "@docusaurus/utils-validation": "0.0.0-5941",
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-5940",
107
- "@docusaurus/types": "0.0.0-5940",
106
+ "@docusaurus/module-type-aliases": "0.0.0-5941",
107
+ "@docusaurus/types": "0.0.0-5941",
108
108
  "@total-typescript/shoehorn": "^0.1.2",
109
109
  "@types/detect-port": "^1.3.3",
110
110
  "@types/react-dom": "^18.2.7",
@@ -124,5 +124,5 @@
124
124
  "engines": {
125
125
  "node": ">=18.0"
126
126
  },
127
- "gitHead": "4cb178f11c58280eef3865a03ffd8acf7b8bd5c7"
127
+ "gitHead": "a7af113c6e6ce762ad4ac764fb89a32252600e82"
128
128
  }