@docusaurus/core 3.7.0-canary-6268 → 3.7.0-canary-6269
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/lib/commands/build/buildLocale.js +5 -0
- package/lib/commands/clear.js +2 -1
- package/lib/commands/utils/clearPath.d.ts +10 -0
- package/lib/commands/utils/clearPath.js +21 -0
- package/lib/webpack/client.js +0 -3
- package/package.json +11 -12
- package/lib/webpack/plugins/CleanWebpackPlugin.d.ts +0 -59
- package/lib/webpack/plugins/CleanWebpackPlugin.js +0 -177
|
@@ -19,6 +19,7 @@ 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 ssgExecutor_1 = require("../../ssg/ssgExecutor");
|
|
22
|
+
const clearPath_1 = tslib_1.__importDefault(require("../utils/clearPath"));
|
|
22
23
|
async function buildLocale({ siteDir, locale, cliOptions, }) {
|
|
23
24
|
// Temporary workaround to unlock the ability to translate the site config
|
|
24
25
|
// We'll remove it if a better official API can be designed
|
|
@@ -47,6 +48,10 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
|
|
|
47
48
|
props,
|
|
48
49
|
configureWebpackUtils,
|
|
49
50
|
}),
|
|
51
|
+
// We also clear website/build dir
|
|
52
|
+
// returns void, no useful result needed before compilation
|
|
53
|
+
// See also https://github.com/facebook/docusaurus/pull/11037
|
|
54
|
+
(0, clearPath_1.default)(outDir),
|
|
50
55
|
]));
|
|
51
56
|
// Run webpack to build JS bundle (client) and static html files (server).
|
|
52
57
|
await logger_1.PerfLogger.async(`Bundling with ${props.currentBundler.name}`, () => {
|
package/lib/commands/clear.js
CHANGED
|
@@ -12,12 +12,13 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
14
14
|
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const clearPath_1 = tslib_1.__importDefault(require("./utils/clearPath"));
|
|
15
16
|
async function removePath(entry) {
|
|
16
17
|
if (!(await fs_extra_1.default.pathExists(entry.path))) {
|
|
17
18
|
return;
|
|
18
19
|
}
|
|
19
20
|
try {
|
|
20
|
-
await
|
|
21
|
+
await (0, clearPath_1.default)(entry.path);
|
|
21
22
|
logger_1.default.success `Removed the ${entry.description} at path=${path_1.default.relative(process.cwd(), entry.path)}.`;
|
|
22
23
|
}
|
|
23
24
|
catch (err) {
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* @param pathToClear
|
|
9
|
+
*/
|
|
10
|
+
export default function clearPath(pathToClear: string): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
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.default = clearPath;
|
|
10
|
+
const tslib_1 = require("tslib");
|
|
11
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
|
+
const promises_1 = require("fs/promises");
|
|
13
|
+
const logger_1 = require("@docusaurus/logger");
|
|
14
|
+
/**
|
|
15
|
+
* @param pathToClear
|
|
16
|
+
*/
|
|
17
|
+
async function clearPath(pathToClear) {
|
|
18
|
+
return logger_1.PerfLogger.async(`clearPath ${path_1.default.relative(process.cwd(), pathToClear)}`, async () => {
|
|
19
|
+
await (0, promises_1.rm)(pathToClear, { recursive: true, force: true });
|
|
20
|
+
});
|
|
21
|
+
}
|
package/lib/webpack/client.js
CHANGED
|
@@ -17,7 +17,6 @@ const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plug
|
|
|
17
17
|
const bundler_1 = require("@docusaurus/bundler");
|
|
18
18
|
const base_1 = require("./base");
|
|
19
19
|
const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
|
|
20
|
-
const CleanWebpackPlugin_1 = tslib_1.__importDefault(require("./plugins/CleanWebpackPlugin"));
|
|
21
20
|
const ForceTerminatePlugin_1 = tslib_1.__importDefault(require("./plugins/ForceTerminatePlugin"));
|
|
22
21
|
const StaticDirectoriesCopyPlugin_1 = require("./plugins/StaticDirectoriesCopyPlugin");
|
|
23
22
|
async function createBaseClientConfig({ props, hydrate, minify, faster, configureWebpackUtils, }) {
|
|
@@ -108,8 +107,6 @@ async function createBuildClientConfig({ props, minify, faster, configureWebpack
|
|
|
108
107
|
}), {
|
|
109
108
|
plugins: [
|
|
110
109
|
new ForceTerminatePlugin_1.default(),
|
|
111
|
-
// Remove/clean build folders before building bundles.
|
|
112
|
-
new CleanWebpackPlugin_1.default({ verbose: false }),
|
|
113
110
|
// Visualize size of webpack output files with an interactive zoomable
|
|
114
111
|
// tree map.
|
|
115
112
|
bundleAnalyzer && new webpack_bundle_analyzer_1.BundleAnalyzerPlugin(),
|
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": "3.7.0-canary-
|
|
4
|
+
"version": "3.7.0-canary-6269",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "3.7.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "3.7.0-canary-
|
|
38
|
-
"@docusaurus/logger": "3.7.0-canary-
|
|
39
|
-
"@docusaurus/mdx-loader": "3.7.0-canary-
|
|
40
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
41
|
-
"@docusaurus/utils-common": "3.7.0-canary-
|
|
42
|
-
"@docusaurus/utils-validation": "3.7.0-canary-
|
|
36
|
+
"@docusaurus/babel": "3.7.0-canary-6269",
|
|
37
|
+
"@docusaurus/bundler": "3.7.0-canary-6269",
|
|
38
|
+
"@docusaurus/logger": "3.7.0-canary-6269",
|
|
39
|
+
"@docusaurus/mdx-loader": "3.7.0-canary-6269",
|
|
40
|
+
"@docusaurus/utils": "3.7.0-canary-6269",
|
|
41
|
+
"@docusaurus/utils-common": "3.7.0-canary-6269",
|
|
42
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6269",
|
|
43
43
|
"boxen": "^6.2.1",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"chokidar": "^3.5.3",
|
|
@@ -47,7 +47,6 @@
|
|
|
47
47
|
"combine-promises": "^1.1.0",
|
|
48
48
|
"commander": "^5.1.0",
|
|
49
49
|
"core-js": "^3.31.1",
|
|
50
|
-
"del": "^6.1.1",
|
|
51
50
|
"detect-port": "^1.5.1",
|
|
52
51
|
"escape-html": "^1.0.3",
|
|
53
52
|
"eta": "^2.2.0",
|
|
@@ -78,8 +77,8 @@
|
|
|
78
77
|
"webpack-merge": "^6.0.1"
|
|
79
78
|
},
|
|
80
79
|
"devDependencies": {
|
|
81
|
-
"@docusaurus/module-type-aliases": "3.7.0-canary-
|
|
82
|
-
"@docusaurus/types": "3.7.0-canary-
|
|
80
|
+
"@docusaurus/module-type-aliases": "3.7.0-canary-6269",
|
|
81
|
+
"@docusaurus/types": "3.7.0-canary-6269",
|
|
83
82
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
84
83
|
"@types/detect-port": "^1.3.3",
|
|
85
84
|
"@types/react-dom": "^18.2.7",
|
|
@@ -99,5 +98,5 @@
|
|
|
99
98
|
"engines": {
|
|
100
99
|
"node": ">=18.0"
|
|
101
100
|
},
|
|
102
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "deb4953b7b273312e2a139a205440810786d4228"
|
|
103
102
|
}
|
|
@@ -1,59 +0,0 @@
|
|
|
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 { Compiler, Stats } from 'webpack';
|
|
8
|
-
export type Options = {
|
|
9
|
-
/**
|
|
10
|
-
* Write Logs to Console
|
|
11
|
-
* (Always enabled when dry is true)
|
|
12
|
-
*
|
|
13
|
-
* default: false
|
|
14
|
-
*/
|
|
15
|
-
verbose?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Automatically remove all unused webpack assets on rebuild
|
|
18
|
-
*
|
|
19
|
-
* default: true
|
|
20
|
-
*/
|
|
21
|
-
cleanStaleWebpackAssets?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Do not allow removal of current webpack assets
|
|
24
|
-
*
|
|
25
|
-
* default: true
|
|
26
|
-
*/
|
|
27
|
-
protectWebpackAssets?: boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Removes files once prior to Webpack compilation
|
|
30
|
-
* Not included in rebuilds (watch mode)
|
|
31
|
-
*
|
|
32
|
-
* Use !negative patterns to exclude files
|
|
33
|
-
*
|
|
34
|
-
* default: ['**\/*']
|
|
35
|
-
*/
|
|
36
|
-
cleanOnceBeforeBuildPatterns?: string[];
|
|
37
|
-
};
|
|
38
|
-
export default class CleanWebpackPlugin {
|
|
39
|
-
private readonly verbose;
|
|
40
|
-
private readonly cleanStaleWebpackAssets;
|
|
41
|
-
private readonly protectWebpackAssets;
|
|
42
|
-
private readonly cleanOnceBeforeBuildPatterns;
|
|
43
|
-
private currentAssets;
|
|
44
|
-
private initialClean;
|
|
45
|
-
private outputPath;
|
|
46
|
-
constructor(options?: Options);
|
|
47
|
-
apply(compiler: Compiler): void;
|
|
48
|
-
/**
|
|
49
|
-
* Initially remove files from output directory prior to build.
|
|
50
|
-
*
|
|
51
|
-
* Only happens once.
|
|
52
|
-
*
|
|
53
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
54
|
-
* of webpack to minimize unexpected behavior.
|
|
55
|
-
*/
|
|
56
|
-
handleInitial(): void;
|
|
57
|
-
handleDone(stats: Stats): void;
|
|
58
|
-
removeFiles(patterns: string[]): void;
|
|
59
|
-
}
|
|
@@ -1,177 +0,0 @@
|
|
|
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
|
-
const tslib_1 = require("tslib");
|
|
10
|
-
/**
|
|
11
|
-
* The MIT License (MIT)
|
|
12
|
-
* Copyright (c) 2015 John Agan
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
-
* furnished to do so, subject to the following conditions:
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in
|
|
20
|
-
* all copies or substantial portions of the Software.
|
|
21
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
-
* SOFTWARE.
|
|
28
|
-
*/
|
|
29
|
-
// Forked from https://github.com/johnagan/clean-webpack-plugin
|
|
30
|
-
// Modified to optimize performance for Docusaurus specific use case
|
|
31
|
-
// More context: https://github.com/facebook/docusaurus/pull/1839
|
|
32
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
33
|
-
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
34
|
-
const del_1 = require("del");
|
|
35
|
-
class CleanWebpackPlugin {
|
|
36
|
-
constructor(options = {}) {
|
|
37
|
-
this.verbose = options.verbose === true || false;
|
|
38
|
-
this.cleanStaleWebpackAssets =
|
|
39
|
-
options.cleanStaleWebpackAssets === true ||
|
|
40
|
-
options.cleanStaleWebpackAssets === false
|
|
41
|
-
? options.cleanStaleWebpackAssets
|
|
42
|
-
: true;
|
|
43
|
-
this.protectWebpackAssets =
|
|
44
|
-
options.protectWebpackAssets === true ||
|
|
45
|
-
options.protectWebpackAssets === false
|
|
46
|
-
? options.protectWebpackAssets
|
|
47
|
-
: true;
|
|
48
|
-
this.cleanOnceBeforeBuildPatterns = Array.isArray(options.cleanOnceBeforeBuildPatterns)
|
|
49
|
-
? options.cleanOnceBeforeBuildPatterns
|
|
50
|
-
: ['**/*'];
|
|
51
|
-
/**
|
|
52
|
-
* Store webpack build assets
|
|
53
|
-
*/
|
|
54
|
-
this.currentAssets = [];
|
|
55
|
-
/**
|
|
56
|
-
* Only used with cleanOnceBeforeBuildPatterns
|
|
57
|
-
*/
|
|
58
|
-
this.initialClean = false;
|
|
59
|
-
this.outputPath = '';
|
|
60
|
-
this.apply = this.apply.bind(this);
|
|
61
|
-
this.handleInitial = this.handleInitial.bind(this);
|
|
62
|
-
this.handleDone = this.handleDone.bind(this);
|
|
63
|
-
this.removeFiles = this.removeFiles.bind(this);
|
|
64
|
-
}
|
|
65
|
-
apply(compiler) {
|
|
66
|
-
if (!compiler.options.output.path) {
|
|
67
|
-
console.warn('clean-webpack-plugin: options.output.path not defined. Plugin disabled...');
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
this.outputPath = compiler.options.output.path;
|
|
71
|
-
const { hooks } = compiler;
|
|
72
|
-
if (this.cleanOnceBeforeBuildPatterns.length !== 0) {
|
|
73
|
-
hooks.compile.tap('clean-webpack-plugin', () => {
|
|
74
|
-
this.handleInitial();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
hooks.done.tap('clean-webpack-plugin', (stats) => {
|
|
78
|
-
this.handleDone(stats);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Initially remove files from output directory prior to build.
|
|
83
|
-
*
|
|
84
|
-
* Only happens once.
|
|
85
|
-
*
|
|
86
|
-
* Warning: It is recommended to initially clean your build directory outside
|
|
87
|
-
* of webpack to minimize unexpected behavior.
|
|
88
|
-
*/
|
|
89
|
-
handleInitial() {
|
|
90
|
-
if (this.initialClean) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (
|
|
94
|
-
// eslint-disable-next-line no-restricted-properties
|
|
95
|
-
fs_extra_1.default.pathExistsSync(this.outputPath) &&
|
|
96
|
-
// eslint-disable-next-line no-restricted-properties
|
|
97
|
-
fs_extra_1.default.statSync(this.outputPath).isFile()) {
|
|
98
|
-
throw new Error(`A file '${this.outputPath}' already exists. Docusaurus needs this directory to save the build output. Either remove/change the file or choose a different build directory via '--out-dir'.`);
|
|
99
|
-
}
|
|
100
|
-
this.initialClean = true;
|
|
101
|
-
this.removeFiles(this.cleanOnceBeforeBuildPatterns);
|
|
102
|
-
}
|
|
103
|
-
handleDone(stats) {
|
|
104
|
-
/**
|
|
105
|
-
* Do nothing if there is a webpack error
|
|
106
|
-
*/
|
|
107
|
-
if (stats.hasErrors()) {
|
|
108
|
-
if (this.verbose) {
|
|
109
|
-
console.warn('clean-webpack-plugin: pausing due to webpack errors');
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Fetch Webpack's output asset files
|
|
115
|
-
*/
|
|
116
|
-
const statsAssets = stats.toJson({
|
|
117
|
-
all: false,
|
|
118
|
-
assets: true,
|
|
119
|
-
}).assets ?? [];
|
|
120
|
-
const assets = statsAssets.map((asset) => asset.name);
|
|
121
|
-
/**
|
|
122
|
-
* Get all files that were in the previous build but not the current
|
|
123
|
-
*
|
|
124
|
-
* (relies on del's cwd: outputPath option)
|
|
125
|
-
*/
|
|
126
|
-
const staleFiles = this.currentAssets.filter((previousAsset) => !assets.includes(previousAsset));
|
|
127
|
-
/**
|
|
128
|
-
* Save assets for next compilation
|
|
129
|
-
*/
|
|
130
|
-
this.currentAssets = assets.sort();
|
|
131
|
-
const removePatterns = [];
|
|
132
|
-
/**
|
|
133
|
-
* Remove unused webpack assets
|
|
134
|
-
*/
|
|
135
|
-
if (this.cleanStaleWebpackAssets && staleFiles.length !== 0) {
|
|
136
|
-
removePatterns.push(...staleFiles);
|
|
137
|
-
}
|
|
138
|
-
if (removePatterns.length !== 0) {
|
|
139
|
-
this.removeFiles(removePatterns);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
removeFiles(patterns) {
|
|
143
|
-
try {
|
|
144
|
-
const deleted = (0, del_1.sync)(patterns, {
|
|
145
|
-
force: false,
|
|
146
|
-
// Change context to build directory
|
|
147
|
-
cwd: this.outputPath,
|
|
148
|
-
dryRun: false,
|
|
149
|
-
dot: true,
|
|
150
|
-
ignore: this.protectWebpackAssets ? this.currentAssets : [],
|
|
151
|
-
});
|
|
152
|
-
/**
|
|
153
|
-
* Log if verbose is enabled
|
|
154
|
-
*/
|
|
155
|
-
if (this.verbose) {
|
|
156
|
-
deleted.forEach((file) => {
|
|
157
|
-
const filename = path_1.default.relative(process.cwd(), file);
|
|
158
|
-
/**
|
|
159
|
-
* Use console.warn over .log
|
|
160
|
-
* https://github.com/webpack/webpack/issues/1904
|
|
161
|
-
* https://github.com/johnagan/clean-webpack-plugin/issues/11
|
|
162
|
-
*/
|
|
163
|
-
console.warn(`clean-webpack-plugin: removed ${filename}`);
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
catch (err) {
|
|
168
|
-
const needsForce = err.message.includes('Cannot delete files/folders outside the current working directory.');
|
|
169
|
-
if (needsForce) {
|
|
170
|
-
const message = 'clean-webpack-plugin: Cannot delete files/folders outside the current working directory. Can be overridden with the "dangerouslyAllowCleanPatternsOutsideProject" option.';
|
|
171
|
-
throw new Error(message);
|
|
172
|
-
}
|
|
173
|
-
throw err;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.default = CleanWebpackPlugin;
|