@docusaurus/core 2.0.0-beta.15 → 2.0.0-beta.16
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 +136 -0
- package/bin/{docusaurus.js → docusaurus.mjs} +62 -40
- package/lib/babel/preset.d.ts +1 -2
- package/lib/babel/preset.js +5 -4
- package/lib/choosePort.js +22 -30
- package/lib/client/App.d.ts +1 -2
- package/lib/client/App.js +13 -8
- package/lib/client/LinksCollector.js +1 -1
- package/lib/client/PendingNavigation.d.ts +4 -4
- package/lib/client/PendingNavigation.js +4 -6
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.d.ts +8 -0
- package/lib/client/baseUrlIssueBanner/BaseUrlIssueBanner.js +15 -10
- package/lib/client/client-lifecycles-dispatcher.d.ts +2 -5
- package/lib/client/client-lifecycles-dispatcher.js +5 -7
- package/lib/client/clientEntry.js +11 -5
- package/lib/client/docusaurus.js +6 -4
- package/lib/client/exports/BrowserOnly.d.ts +1 -2
- package/lib/client/exports/BrowserOnly.js +2 -3
- package/lib/client/exports/ComponentCreator.d.ts +1 -2
- package/lib/client/exports/ComponentCreator.js +7 -6
- package/lib/client/exports/ErrorBoundary.d.ts +2 -2
- package/lib/client/exports/ErrorBoundary.js +1 -2
- package/lib/client/exports/Head.d.ts +2 -3
- package/lib/client/exports/Head.js +3 -4
- package/lib/client/exports/Interpolate.js +9 -12
- package/lib/client/exports/Link.d.ts +11 -5
- package/lib/client/exports/Link.js +13 -7
- package/lib/client/exports/Translate.js +2 -1
- package/lib/client/exports/browserContext.js +3 -2
- package/lib/client/exports/docusaurusContext.js +1 -1
- package/lib/client/exports/isInternalUrl.js +1 -1
- package/lib/client/exports/renderRoutes.d.ts +1 -2
- package/lib/client/exports/renderRoutes.js +1 -2
- package/lib/client/exports/router.d.ts +1 -1
- package/lib/client/exports/router.js +1 -1
- package/lib/client/exports/useDocusaurusContext.d.ts +1 -2
- package/lib/client/exports/useDocusaurusContext.js +1 -2
- package/lib/client/flat.d.ts +1 -2
- package/lib/client/flat.js +1 -2
- package/lib/client/normalizeLocation.d.ts +2 -3
- package/lib/client/normalizeLocation.js +1 -2
- package/lib/client/prefetch.d.ts +1 -2
- package/lib/client/prefetch.js +1 -2
- package/lib/client/preload.d.ts +2 -1
- package/lib/client/preload.js +2 -1
- package/lib/client/serverEntry.js +23 -19
- package/lib/client/theme-fallback/Error/index.d.ts +10 -0
- package/lib/client/theme-fallback/Error/index.js +21 -29
- package/lib/client/theme-fallback/Layout/index.d.ts +10 -0
- package/lib/client/theme-fallback/Layout/index.js +10 -19
- package/lib/client/theme-fallback/Loading/index.d.ts +9 -0
- package/lib/client/theme-fallback/Loading/index.js +46 -114
- package/lib/{server/versions/__tests/index.test.d.ts → client/theme-fallback/NotFound/index.d.ts} +2 -1
- package/lib/client/theme-fallback/NotFound/index.js +9 -16
- package/lib/client/theme-fallback/Root/index.d.ts +10 -0
- package/lib/client/theme-fallback/Root/index.js +2 -5
- package/lib/commands/build.js +33 -34
- package/lib/commands/clear.js +23 -11
- package/lib/commands/deploy.js +12 -11
- package/lib/commands/external.d.ts +2 -2
- package/lib/commands/external.js +1 -1
- package/lib/commands/serve.js +3 -2
- package/lib/commands/start.js +4 -4
- package/lib/commands/swizzle/actions.d.ts +23 -0
- package/lib/commands/swizzle/actions.js +102 -0
- package/lib/commands/swizzle/common.d.ts +33 -0
- package/lib/commands/swizzle/common.js +57 -0
- package/lib/commands/swizzle/components.d.ts +29 -0
- package/lib/commands/swizzle/components.js +165 -0
- package/lib/commands/swizzle/config.d.ts +10 -0
- package/lib/commands/swizzle/config.js +77 -0
- package/lib/commands/swizzle/context.d.ts +8 -0
- package/lib/commands/swizzle/context.js +30 -0
- package/lib/commands/swizzle/index.d.ts +8 -0
- package/lib/commands/swizzle/index.js +115 -0
- package/lib/commands/swizzle/prompts.d.ts +12 -0
- package/lib/commands/swizzle/prompts.js +110 -0
- package/lib/commands/swizzle/tables.d.ts +9 -0
- package/lib/commands/swizzle/tables.js +116 -0
- package/lib/commands/swizzle/themes.d.ts +20 -0
- package/lib/commands/swizzle/themes.js +105 -0
- package/lib/commands/writeHeadingIds.d.ts +1 -1
- package/lib/commands/writeHeadingIds.js +13 -14
- package/lib/commands/writeTranslations.js +10 -7
- package/lib/index.d.ts +10 -9
- package/lib/index.js +20 -19
- package/lib/server/brokenLinks.js +30 -20
- package/lib/server/config.js +1 -1
- package/lib/server/configValidation.d.ts +1 -1
- package/lib/server/configValidation.js +32 -23
- package/lib/server/duplicateRoutes.js +2 -4
- package/lib/server/html-tags/htmlTags.js +1 -2
- package/lib/server/i18n.d.ts +0 -1
- package/lib/server/i18n.js +16 -26
- package/lib/server/index.d.ts +1 -1
- package/lib/server/index.js +17 -15
- package/lib/server/loadSetup.d.ts +1 -2
- package/lib/server/loadSetup.js +2 -2
- package/lib/server/moduleShorthand.js +1 -1
- package/lib/server/plugins/index.js +9 -9
- package/lib/server/plugins/init.d.ts +11 -1
- package/lib/server/plugins/init.js +23 -28
- package/lib/server/plugins/pluginIds.js +4 -3
- package/lib/server/presets/index.d.ts +2 -2
- package/lib/server/presets/index.js +3 -3
- package/lib/server/routes.js +13 -7
- package/lib/server/themes/alias.d.ts +1 -1
- package/lib/server/themes/alias.js +5 -6
- package/lib/server/themes/index.d.ts +2 -2
- package/lib/server/themes/index.js +10 -9
- package/lib/server/translations/translations.js +10 -11
- package/lib/server/translations/translationsExtractor.js +20 -19
- package/lib/server/versions/index.d.ts +2 -3
- package/lib/server/versions/index.js +22 -21
- package/lib/webpack/base.d.ts +2 -2
- package/lib/webpack/base.js +30 -22
- package/lib/webpack/client.d.ts +1 -1
- package/lib/webpack/client.js +7 -4
- package/lib/webpack/plugins/ChunkAssetPlugin.d.ts +12 -2
- package/lib/webpack/plugins/ChunkAssetPlugin.js +17 -10
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +5 -5
- package/lib/webpack/plugins/CleanWebpackPlugin.js +5 -4
- package/lib/webpack/server.d.ts +1 -1
- package/lib/webpack/server.js +6 -5
- package/lib/webpack/utils.d.ts +3 -3
- package/lib/webpack/utils.js +17 -37
- package/package.json +56 -56
- package/bin/beforeCli.js +0 -124
- package/lib/commands/swizzle.d.ts +0 -9
- package/lib/commands/swizzle.js +0 -236
- package/lib/server/versions/__tests/index.test.js +0 -26
package/lib/webpack/base.js
CHANGED
|
@@ -14,8 +14,8 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
const themes_1 = require("../server/themes");
|
|
16
16
|
const utils_2 = require("@docusaurus/utils");
|
|
17
|
-
const CSS_REGEX = /\.css
|
|
18
|
-
const CSS_MODULE_REGEX = /\.module\.css
|
|
17
|
+
const CSS_REGEX = /\.css$/i;
|
|
18
|
+
const CSS_MODULE_REGEX = /\.module\.css$/i;
|
|
19
19
|
exports.clientDir = path_1.default.join(__dirname, '..', 'client');
|
|
20
20
|
const LibrariesToTranspile = [
|
|
21
21
|
'copy-text-to-clipboard', // contains optional catch binding, incompatible with recent versions of Edge
|
|
@@ -28,15 +28,15 @@ function excludeJS(modulePath) {
|
|
|
28
28
|
}
|
|
29
29
|
// Don't transpile node_modules except any docusaurus npm package
|
|
30
30
|
return (/node_modules/.test(modulePath) &&
|
|
31
|
-
!/
|
|
31
|
+
!/docusaurus(?:(?!node_modules).)*\.jsx?$/.test(modulePath) &&
|
|
32
32
|
!LibrariesToTranspileRegex.test(modulePath));
|
|
33
33
|
}
|
|
34
34
|
exports.excludeJS = excludeJS;
|
|
35
|
-
function getDocusaurusAliases() {
|
|
35
|
+
async function getDocusaurusAliases() {
|
|
36
36
|
const dirPath = path_1.default.resolve(__dirname, '../client/exports');
|
|
37
37
|
const extensions = ['.js', '.ts', '.tsx'];
|
|
38
38
|
const aliases = {};
|
|
39
|
-
fs_extra_1.default.
|
|
39
|
+
(await fs_extra_1.default.readdir(dirPath))
|
|
40
40
|
.filter((fileName) => extensions.includes(path_1.default.extname(fileName)))
|
|
41
41
|
.forEach((fileName) => {
|
|
42
42
|
const fileNameWithoutExtension = path_1.default.basename(fileName, path_1.default.extname(fileName));
|
|
@@ -46,7 +46,7 @@ function getDocusaurusAliases() {
|
|
|
46
46
|
return aliases;
|
|
47
47
|
}
|
|
48
48
|
exports.getDocusaurusAliases = getDocusaurusAliases;
|
|
49
|
-
function createBaseConfig(props, isServer, minify = true) {
|
|
49
|
+
async function createBaseConfig(props, isServer, minify = true) {
|
|
50
50
|
var _a;
|
|
51
51
|
const { outDir, siteDir, siteConfig, siteConfigPath, baseUrl, generatedFilesDir, routesPaths, siteMetadata, plugins, } = props;
|
|
52
52
|
const totalPages = routesPaths.length;
|
|
@@ -56,7 +56,7 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
56
56
|
const fileLoaderUtils = (0, utils_2.getFileLoaderUtils)();
|
|
57
57
|
const name = isServer ? 'server' : 'client';
|
|
58
58
|
const mode = isProd ? 'production' : 'development';
|
|
59
|
-
const themeAliases = (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
|
|
59
|
+
const themeAliases = await (0, themes_1.loadPluginsThemeAliases)({ siteDir, plugins });
|
|
60
60
|
return {
|
|
61
61
|
mode,
|
|
62
62
|
name,
|
|
@@ -69,16 +69,19 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
69
69
|
// When version string changes, cache is evicted
|
|
70
70
|
version: [
|
|
71
71
|
siteMetadata.docusaurusVersion,
|
|
72
|
-
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
72
|
+
// Webpack does not evict the cache correctly on alias/swizzle change,
|
|
73
|
+
// so we force eviction.
|
|
73
74
|
// See https://github.com/webpack/webpack/issues/13627
|
|
74
75
|
(0, utils_2.md5Hash)(JSON.stringify(themeAliases)),
|
|
75
76
|
].join('-'),
|
|
76
|
-
// When one of those modules/dependencies change (including transitive
|
|
77
|
+
// When one of those modules/dependencies change (including transitive
|
|
78
|
+
// deps), cache is invalidated
|
|
77
79
|
buildDependencies: {
|
|
78
80
|
config: [
|
|
79
81
|
__filename,
|
|
80
82
|
path_1.default.join(__dirname, isServer ? 'server.js' : 'client.js'),
|
|
81
|
-
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
83
|
+
// Docusaurus config changes can affect MDX/JSX compilation, so we'd
|
|
84
|
+
// rather evict the cache.
|
|
82
85
|
// See https://github.com/questdb/questdb.io/issues/493
|
|
83
86
|
siteConfigPath,
|
|
84
87
|
],
|
|
@@ -117,17 +120,18 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
117
120
|
// Note: a @docusaurus alias would also catch @docusaurus/theme-common,
|
|
118
121
|
// so we use fine-grained aliases instead
|
|
119
122
|
// '@docusaurus': path.resolve(__dirname, '../client/exports'),
|
|
120
|
-
...getDocusaurusAliases(),
|
|
123
|
+
...(await getDocusaurusAliases()),
|
|
121
124
|
...themeAliases,
|
|
122
125
|
},
|
|
123
|
-
// This allows you to set a fallback for where Webpack should look for
|
|
124
|
-
// We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
125
|
-
// Example: if there is core-js@3 in user's
|
|
126
|
-
// core-js@2, we should use
|
|
126
|
+
// This allows you to set a fallback for where Webpack should look for
|
|
127
|
+
// modules. We want `@docusaurus/core` own dependencies/`node_modules` to
|
|
128
|
+
// "win" if there is conflict. Example: if there is core-js@3 in user's
|
|
129
|
+
// own node_modules, but core depends on core-js@2, we should use
|
|
130
|
+
// core-js@2.
|
|
127
131
|
modules: [
|
|
128
132
|
path_1.default.resolve(__dirname, '..', '..', 'node_modules'),
|
|
129
133
|
'node_modules',
|
|
130
|
-
path_1.default.resolve(fs_extra_1.default.
|
|
134
|
+
path_1.default.resolve(await fs_extra_1.default.realpath(process.cwd()), 'node_modules'),
|
|
131
135
|
],
|
|
132
136
|
},
|
|
133
137
|
resolveLoader: {
|
|
@@ -135,7 +139,8 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
135
139
|
},
|
|
136
140
|
optimization: {
|
|
137
141
|
removeAvailableModules: false,
|
|
138
|
-
// Only minimize client bundle in production because server bundle is only
|
|
142
|
+
// Only minimize client bundle in production because server bundle is only
|
|
143
|
+
// used for static site generation
|
|
139
144
|
minimize: minimizeEnabled,
|
|
140
145
|
minimizer: minimizeEnabled
|
|
141
146
|
? (0, utils_1.getMinimizer)(useSimpleCssMinifier)
|
|
@@ -143,7 +148,9 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
143
148
|
splitChunks: isServer
|
|
144
149
|
? false
|
|
145
150
|
: {
|
|
146
|
-
// Since the chunk name includes all origin chunk names it's
|
|
151
|
+
// Since the chunk name includes all origin chunk names it's
|
|
152
|
+
// recommended for production builds with long term caching to NOT
|
|
153
|
+
// include [name] in the filenames
|
|
147
154
|
name: false,
|
|
148
155
|
cacheGroups: {
|
|
149
156
|
// disable the built-in cacheGroups
|
|
@@ -175,12 +182,12 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
175
182
|
fileLoaderUtils.rules.svg(),
|
|
176
183
|
fileLoaderUtils.rules.otherAssets(),
|
|
177
184
|
{
|
|
178
|
-
test: /\.
|
|
185
|
+
test: /\.[jt]sx?$/i,
|
|
179
186
|
exclude: excludeJS,
|
|
180
187
|
use: [
|
|
181
188
|
(0, utils_1.getCustomizableJSLoader)((_a = siteConfig.webpack) === null || _a === void 0 ? void 0 : _a.jsLoader)({
|
|
182
189
|
isServer,
|
|
183
|
-
babelOptions: (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
190
|
+
babelOptions: await (0, utils_1.getCustomBabelConfigFilePath)(siteDir),
|
|
184
191
|
}),
|
|
185
192
|
],
|
|
186
193
|
},
|
|
@@ -217,8 +224,9 @@ function createBaseConfig(props, isServer, minify = true) {
|
|
|
217
224
|
chunkFilename: isProd
|
|
218
225
|
? 'assets/css/[name].[contenthash:8].css'
|
|
219
226
|
: '[name].css',
|
|
220
|
-
// remove css order warnings if css imports are not sorted
|
|
221
|
-
//
|
|
227
|
+
// remove css order warnings if css imports are not sorted
|
|
228
|
+
// alphabetically. See https://github.com/webpack-contrib/mini-css-extract-plugin/pull/422
|
|
229
|
+
// for more reasoning
|
|
222
230
|
ignoreOrder: true,
|
|
223
231
|
}),
|
|
224
232
|
],
|
package/lib/webpack/client.d.ts
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Configuration } from 'webpack';
|
|
8
8
|
import type { Props } from '@docusaurus/types';
|
|
9
|
-
export default function createClientConfig(props: Props, minify?: boolean): Configuration
|
|
9
|
+
export default function createClientConfig(props: Props, minify?: boolean): Promise<Configuration>;
|
package/lib/webpack/client.js
CHANGED
|
@@ -13,12 +13,14 @@ const webpack_merge_1 = (0, tslib_1.__importDefault)(require("webpack-merge"));
|
|
|
13
13
|
const base_1 = require("./base");
|
|
14
14
|
const ChunkAssetPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/ChunkAssetPlugin"));
|
|
15
15
|
const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"));
|
|
16
|
-
function createClientConfig(props, minify = true) {
|
|
16
|
+
async function createClientConfig(props, minify = true) {
|
|
17
17
|
var _a;
|
|
18
18
|
const isBuilding = process.argv[2] === 'build';
|
|
19
|
-
const config = (0, base_1.createBaseConfig)(props, false, minify);
|
|
19
|
+
const config = await (0, base_1.createBaseConfig)(props, false, minify);
|
|
20
20
|
const clientConfig = (0, webpack_merge_1.default)(config, {
|
|
21
|
-
//
|
|
21
|
+
// useless, disabled on purpose (errors on existing sites with no
|
|
22
|
+
// browserslist config)
|
|
23
|
+
// target: 'browserslist',
|
|
22
24
|
entry: path_1.default.resolve(__dirname, '../client/clientEntry.js'),
|
|
23
25
|
optimization: {
|
|
24
26
|
// Keep the runtime chunk separated to enable long term caching
|
|
@@ -33,7 +35,8 @@ function createClientConfig(props, minify = true) {
|
|
|
33
35
|
}),
|
|
34
36
|
],
|
|
35
37
|
});
|
|
36
|
-
// When building include the plugin to force terminate building if errors
|
|
38
|
+
// When building, include the plugin to force terminate building if errors
|
|
39
|
+
// happened in the client bundle.
|
|
37
40
|
if (isBuilding) {
|
|
38
41
|
(_a = clientConfig.plugins) === null || _a === void 0 ? void 0 : _a.push({
|
|
39
42
|
apply: (compiler) => {
|
|
@@ -5,7 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type Compiler } from 'webpack';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* We modify webpack runtime to add an extra function called
|
|
10
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
11
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
12
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
13
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
14
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
15
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
16
|
+
*
|
|
17
|
+
* "gca" stands for "get chunk asset"
|
|
18
|
+
*/
|
|
19
|
+
export default class ChunkAssetPlugin {
|
|
9
20
|
apply(compiler: Compiler): void;
|
|
10
21
|
}
|
|
11
|
-
export default ChunkAssetPlugin;
|
|
@@ -8,16 +8,20 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
const webpack_1 = require("webpack");
|
|
10
10
|
const pluginName = 'chunk-asset-plugin';
|
|
11
|
+
/**
|
|
12
|
+
* We modify webpack runtime to add an extra function called
|
|
13
|
+
* "__webpack_require__.gca" that will allow us to get the corresponding chunk
|
|
14
|
+
* asset for a webpack chunk. Pass it the chunkName or chunkId you want to load.
|
|
15
|
+
* For example: if you have a chunk named "my-chunk-name" that will map to
|
|
16
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
17
|
+
* __webpack_require__.gca("my-chunk-name") will return
|
|
18
|
+
* "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
+
*
|
|
20
|
+
* "gca" stands for "get chunk asset"
|
|
21
|
+
*/
|
|
11
22
|
class ChunkAssetPlugin {
|
|
12
23
|
apply(compiler) {
|
|
13
24
|
compiler.hooks.thisCompilation.tap(pluginName, ({ mainTemplate }) => {
|
|
14
|
-
/* We modify webpack runtime to add an extra function called "__webpack_require__.gca"
|
|
15
|
-
that will allow us to get the corresponding chunk asset for a webpack chunk.
|
|
16
|
-
Pass it the chunkName or chunkId you want to load.
|
|
17
|
-
For example: if you have a chunk named "my-chunk-name" that will map to "/publicPath/0a84b5e7.c8e35c7a.js" as its corresponding output path
|
|
18
|
-
__webpack_require__.gca("my-chunk-name") will return "/publicPath/0a84b5e7.c8e35c7a.js"
|
|
19
|
-
"gca" stands for "get chunk asset"
|
|
20
|
-
*/
|
|
21
25
|
mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk) => {
|
|
22
26
|
const chunkIdToName = chunk.getChunkMaps(false).name;
|
|
23
27
|
const chunkNameToId = Object.create(null);
|
|
@@ -30,10 +34,13 @@ class ChunkAssetPlugin {
|
|
|
30
34
|
buf.push(
|
|
31
35
|
// If chunkName is passed, we convert it to chunk asset url
|
|
32
36
|
// .p => public path url ("/" or "/baseUrl/")
|
|
33
|
-
// .u(chunkId) =>
|
|
34
|
-
//
|
|
37
|
+
// .u(chunkId) =>
|
|
38
|
+
// chunk asset url ("assets/js/x63b64xd.contentHash.js")
|
|
39
|
+
// not sure where this is documented, but this link was helpful:
|
|
40
|
+
// https://programmer.help/blogs/5d68849083e1a.html
|
|
35
41
|
//
|
|
36
|
-
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
42
|
+
// Note: __webpack_require__.gca() is called in docusaurus.ts for
|
|
43
|
+
// prefetching
|
|
37
44
|
// Note: we previously used jsonpScriptSrc (Webpack 4)
|
|
38
45
|
`__webpack_require__.gca = function(chunkId) { chunkId = ${JSON.stringify(chunkNameToId)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`);
|
|
39
46
|
return webpack_1.Template.asString(buf);
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
14
|
* copies of the Software, and to permit persons to whom the Software is
|
|
15
15
|
* furnished to do so, subject to the following conditions:
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in
|
|
17
|
+
* all copies or substantial portions of the Software.
|
|
18
18
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
19
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
20
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -54,7 +54,7 @@ export interface Options {
|
|
|
54
54
|
*/
|
|
55
55
|
cleanOnceBeforeBuildPatterns?: string[];
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
export default class CleanWebpackPlugin {
|
|
58
58
|
private readonly verbose;
|
|
59
59
|
private readonly cleanStaleWebpackAssets;
|
|
60
60
|
private readonly protectWebpackAssets;
|
|
@@ -69,10 +69,10 @@ declare class CleanWebpackPlugin {
|
|
|
69
69
|
*
|
|
70
70
|
* Only happens once.
|
|
71
71
|
*
|
|
72
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
72
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
73
|
+
* of webpack to minimize unexpected behavior.
|
|
73
74
|
*/
|
|
74
75
|
handleInitial(): void;
|
|
75
76
|
handleDone(stats: Stats): void;
|
|
76
77
|
removeFiles(patterns: string[]): void;
|
|
77
78
|
}
|
|
78
|
-
export default CleanWebpackPlugin;
|
|
@@ -60,7 +60,8 @@ class CleanWebpackPlugin {
|
|
|
60
60
|
*
|
|
61
61
|
* Only happens once.
|
|
62
62
|
*
|
|
63
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
63
|
+
* Warning: It is recommended to initially clean your build directory outside
|
|
64
|
+
* of webpack to minimize unexpected behavior.
|
|
64
65
|
*/
|
|
65
66
|
handleInitial() {
|
|
66
67
|
if (this.initialClean) {
|
|
@@ -133,13 +134,13 @@ class CleanWebpackPlugin {
|
|
|
133
134
|
});
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
catch (
|
|
137
|
-
const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(
|
|
137
|
+
catch (err) {
|
|
138
|
+
const needsForce = /Cannot delete files\/folders outside the current working directory\./.test(err.message);
|
|
138
139
|
if (needsForce) {
|
|
139
140
|
const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
|
|
140
141
|
throw new Error(message);
|
|
141
142
|
}
|
|
142
|
-
throw
|
|
143
|
+
throw err;
|
|
143
144
|
}
|
|
144
145
|
}
|
|
145
146
|
}
|
package/lib/webpack/server.d.ts
CHANGED
package/lib/webpack/server.js
CHANGED
|
@@ -15,9 +15,9 @@ const LogPlugin_1 = (0, tslib_1.__importDefault)(require("./plugins/LogPlugin"))
|
|
|
15
15
|
const utils_1 = require("@docusaurus/utils");
|
|
16
16
|
// Forked for Docusaurus: https://github.com/slorber/static-site-generator-webpack-plugin
|
|
17
17
|
const static_site_generator_webpack_plugin_1 = (0, tslib_1.__importDefault)(require("@slorber/static-site-generator-webpack-plugin"));
|
|
18
|
-
function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
18
|
+
async function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
19
19
|
const { baseUrl, routesPaths, generatedFilesDir, headTags, preBodyTags, postBodyTags, ssrTemplate, siteConfig: { noIndex, trailingSlash }, } = props;
|
|
20
|
-
const config = (0, base_1.createBaseConfig)(props, true);
|
|
20
|
+
const config = await (0, base_1.createBaseConfig)(props, true);
|
|
21
21
|
const routesLocation = {};
|
|
22
22
|
// Array of paths to be rendered. Relative to output directory
|
|
23
23
|
const ssgPaths = routesPaths.map((str) => {
|
|
@@ -57,9 +57,10 @@ function createServerConfig({ props, onLinksCollected = () => { }, }) {
|
|
|
57
57
|
},
|
|
58
58
|
paths: ssgPaths,
|
|
59
59
|
preferFoldersOutput: trailingSlash,
|
|
60
|
-
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
-
//
|
|
62
|
-
//
|
|
60
|
+
// When using "new URL('file.js', import.meta.url)", Webpack will emit
|
|
61
|
+
// __filename, and this plugin will throw. not sure the __filename value
|
|
62
|
+
// has any importance for this plugin, just using an empty string to
|
|
63
|
+
// avoid the error. See https://github.com/facebook/docusaurus/issues/4922
|
|
63
64
|
globals: { __filename: '' },
|
|
64
65
|
}),
|
|
65
66
|
// Show compilation progress bar.
|
package/lib/webpack/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { ConfigureWebpackFn, ConfigurePostCssFn } from '@docusaurus/types';
|
|
|
11
11
|
export declare function getStyleLoaders(isServer: boolean, cssOptionsArg?: {
|
|
12
12
|
[key: string]: unknown;
|
|
13
13
|
}): RuleSetRule[];
|
|
14
|
-
export declare function getCustomBabelConfigFilePath(siteDir: string): string | undefined
|
|
14
|
+
export declare function getCustomBabelConfigFilePath(siteDir: string): Promise<string | undefined>;
|
|
15
15
|
export declare function getBabelOptions({ isServer, babelOptions, }?: {
|
|
16
16
|
isServer?: boolean;
|
|
17
17
|
babelOptions?: TransformOptions | string;
|
|
@@ -32,8 +32,8 @@ export declare const getCustomizableJSLoader: (jsLoader?: "babel" | ((isServer:
|
|
|
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
34
|
export declare function compile(config: Configuration[]): Promise<void>;
|
|
35
|
-
export declare function getHttpsConfig(): boolean | {
|
|
35
|
+
export declare function getHttpsConfig(): Promise<boolean | {
|
|
36
36
|
cert: Buffer;
|
|
37
37
|
key: Buffer;
|
|
38
|
-
}
|
|
38
|
+
}>;
|
|
39
39
|
export declare function getMinimizer(useSimpleCssMinifier?: boolean): WebpackPluginInstance[];
|
package/lib/webpack/utils.js
CHANGED
|
@@ -18,7 +18,6 @@ const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
|
18
18
|
const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
|
|
19
19
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
20
20
|
const utils_1 = require("@docusaurus/utils");
|
|
21
|
-
const lodash_1 = require("lodash");
|
|
22
21
|
// Utility method to get style loaders
|
|
23
22
|
function getStyleLoaders(isServer, cssOptionsArg = {}) {
|
|
24
23
|
const cssOptions = {
|
|
@@ -80,9 +79,9 @@ function getStyleLoaders(isServer, cssOptionsArg = {}) {
|
|
|
80
79
|
];
|
|
81
80
|
}
|
|
82
81
|
exports.getStyleLoaders = getStyleLoaders;
|
|
83
|
-
function getCustomBabelConfigFilePath(siteDir) {
|
|
82
|
+
async function getCustomBabelConfigFilePath(siteDir) {
|
|
84
83
|
const customBabelConfigurationPath = path_1.default.join(siteDir, utils_1.BABEL_CONFIG_FILE_NAME);
|
|
85
|
-
return fs_extra_1.default.
|
|
84
|
+
return (await fs_extra_1.default.pathExists(customBabelConfigurationPath))
|
|
86
85
|
? customBabelConfigurationPath
|
|
87
86
|
: undefined;
|
|
88
87
|
}
|
|
@@ -95,13 +94,12 @@ function getBabelOptions({ isServer, babelOptions, } = {}) {
|
|
|
95
94
|
caller: { name: isServer ? 'server' : 'client' },
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
97
|
+
return {
|
|
98
|
+
...(babelOptions !== null && babelOptions !== void 0 ? babelOptions : { presets: [require.resolve('../babel/preset')] }),
|
|
99
|
+
babelrc: false,
|
|
100
|
+
configFile: false,
|
|
101
|
+
caller: { name: isServer ? 'server' : 'client' },
|
|
102
|
+
};
|
|
105
103
|
}
|
|
106
104
|
exports.getBabelOptions = getBabelOptions;
|
|
107
105
|
// Name is generic on purpose
|
|
@@ -116,22 +114,6 @@ const getCustomizableJSLoader = (jsLoader = 'babel') => ({ isServer, babelOption
|
|
|
116
114
|
? getDefaultBabelLoader({ isServer, babelOptions })
|
|
117
115
|
: jsLoader(isServer);
|
|
118
116
|
exports.getCustomizableJSLoader = getCustomizableJSLoader;
|
|
119
|
-
// TODO remove this before end of 2021?
|
|
120
|
-
const warnBabelLoaderOnce = (0, lodash_1.memoize)(() => {
|
|
121
|
-
logger_1.default.warn `Docusaurus plans to support multiple JS loader strategies (Babel, esbuild...): code=${'getBabelLoader(isServer)'} is now deprecated in favor of code=${'getJSLoader(isServer)'}.`;
|
|
122
|
-
});
|
|
123
|
-
const getBabelLoaderDeprecated = function getBabelLoaderDeprecated(isServer, babelOptions) {
|
|
124
|
-
warnBabelLoaderOnce();
|
|
125
|
-
return getDefaultBabelLoader({ isServer, babelOptions });
|
|
126
|
-
};
|
|
127
|
-
// TODO remove this before end of 2021 ?
|
|
128
|
-
const warnCacheLoaderOnce = (0, lodash_1.memoize)(() => {
|
|
129
|
-
logger_1.default.warn `Docusaurus uses Webpack 5 and code=${'getCacheLoader()'} usage is now deprecated.`;
|
|
130
|
-
});
|
|
131
|
-
function getCacheLoaderDeprecated() {
|
|
132
|
-
warnCacheLoaderOnce();
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
117
|
/**
|
|
136
118
|
* Helper function to modify webpack config
|
|
137
119
|
* @param configureWebpack a webpack config or a function to modify config
|
|
@@ -146,8 +128,6 @@ function applyConfigureWebpack(configureWebpack, config, isServer, jsLoader, con
|
|
|
146
128
|
const utils = {
|
|
147
129
|
getStyleLoaders,
|
|
148
130
|
getJSLoader: (0, exports.getCustomizableJSLoader)(jsLoader),
|
|
149
|
-
getBabelLoader: getBabelLoaderDeprecated,
|
|
150
|
-
getCacheLoader: getCacheLoaderDeprecated,
|
|
151
131
|
};
|
|
152
132
|
if (typeof configureWebpack === 'function') {
|
|
153
133
|
const { mergeStrategy, ...res } = configureWebpack(config, isServer, utils, content);
|
|
@@ -248,24 +228,24 @@ ${err}`);
|
|
|
248
228
|
}
|
|
249
229
|
}
|
|
250
230
|
// Read file and throw an error if it doesn't exist
|
|
251
|
-
function readEnvFile(file, type) {
|
|
252
|
-
if (!fs_extra_1.default.
|
|
231
|
+
async function readEnvFile(file, type) {
|
|
232
|
+
if (!(await fs_extra_1.default.pathExists(file))) {
|
|
253
233
|
throw new Error(`You specified ${type} in your env, but the file "${file}" can't be found.`);
|
|
254
234
|
}
|
|
255
|
-
return fs_extra_1.default.
|
|
235
|
+
return fs_extra_1.default.readFile(file);
|
|
256
236
|
}
|
|
257
|
-
const appDirectory = fs_extra_1.default.realpathSync(process.cwd());
|
|
258
237
|
// Get the https config
|
|
259
238
|
// Return cert files if provided in env, otherwise just true or false
|
|
260
|
-
function getHttpsConfig() {
|
|
239
|
+
async function getHttpsConfig() {
|
|
240
|
+
const appDirectory = await fs_extra_1.default.realpath(process.cwd());
|
|
261
241
|
const { SSL_CRT_FILE, SSL_KEY_FILE, HTTPS } = process.env;
|
|
262
242
|
const isHttps = HTTPS === 'true';
|
|
263
243
|
if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) {
|
|
264
244
|
const crtFile = path_1.default.resolve(appDirectory, SSL_CRT_FILE);
|
|
265
245
|
const keyFile = path_1.default.resolve(appDirectory, SSL_KEY_FILE);
|
|
266
246
|
const config = {
|
|
267
|
-
cert: readEnvFile(crtFile, 'SSL_CRT_FILE'),
|
|
268
|
-
key: readEnvFile(keyFile, 'SSL_KEY_FILE'),
|
|
247
|
+
cert: await readEnvFile(crtFile, 'SSL_CRT_FILE'),
|
|
248
|
+
key: await readEnvFile(keyFile, 'SSL_KEY_FILE'),
|
|
269
249
|
};
|
|
270
250
|
validateKeyAndCerts({ ...config, keyFile, crtFile });
|
|
271
251
|
return config;
|
|
@@ -308,8 +288,8 @@ function getMinimizer(useSimpleCssMinifier = false) {
|
|
|
308
288
|
output: {
|
|
309
289
|
ecma: 5,
|
|
310
290
|
comments: false,
|
|
311
|
-
// Turned on because emoji and regex is not minified properly using
|
|
312
|
-
// https://github.com/facebook/create-react-app/issues/2488
|
|
291
|
+
// Turned on because emoji and regex is not minified properly using
|
|
292
|
+
// default. See https://github.com/facebook/create-react-app/issues/2488
|
|
313
293
|
ascii_only: true,
|
|
314
294
|
},
|
|
315
295
|
},
|