@docusaurus/core 2.2.0 → 2.3.0
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/docusaurus.mjs +18 -0
- package/lib/client/ClientLifecyclesDispatcher.js +12 -4
- package/lib/client/exports/useBaseUrl.js +3 -1
- package/lib/commands/build.js +5 -1
- package/lib/commands/deploy.js +1 -1
- package/lib/commands/swizzle/actions.js +2 -1
- package/lib/commands/swizzle/components.d.ts +9 -0
- package/lib/commands/swizzle/components.js +2 -1
- package/lib/server/routes.js +7 -1
- package/package.json +10 -10
package/bin/docusaurus.mjs
CHANGED
|
@@ -104,6 +104,23 @@ cli
|
|
|
104
104
|
)
|
|
105
105
|
.action(deploy);
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @param {string | undefined} value
|
|
109
|
+
* @returns {boolean | number}
|
|
110
|
+
*/
|
|
111
|
+
function normalizePollValue(value) {
|
|
112
|
+
if (value === undefined || value === '') {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const parsedIntValue = Number.parseInt(value, 10);
|
|
117
|
+
if (!Number.isNaN(parsedIntValue)) {
|
|
118
|
+
return parsedIntValue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return value === 'true';
|
|
122
|
+
}
|
|
123
|
+
|
|
107
124
|
cli
|
|
108
125
|
.command('start [siteDir]')
|
|
109
126
|
.description('Start the development server.')
|
|
@@ -122,6 +139,7 @@ cli
|
|
|
122
139
|
.option(
|
|
123
140
|
'--poll [interval]',
|
|
124
141
|
'use polling rather than watching for reload (default: false). Can specify a poll interval in milliseconds',
|
|
142
|
+
normalizePollValue,
|
|
125
143
|
)
|
|
126
144
|
.option(
|
|
127
145
|
'--no-minify',
|
|
@@ -14,7 +14,17 @@ export function dispatchLifecycleAction(lifecycleAction, ...args) {
|
|
|
14
14
|
});
|
|
15
15
|
return () => callbacks.forEach((cb) => cb?.());
|
|
16
16
|
}
|
|
17
|
-
function scrollAfterNavigation(location) {
|
|
17
|
+
function scrollAfterNavigation({ location, previousLocation, }) {
|
|
18
|
+
if (!previousLocation) {
|
|
19
|
+
return; // no-op: use native browser feature
|
|
20
|
+
}
|
|
21
|
+
const samePathname = location.pathname === previousLocation.pathname;
|
|
22
|
+
const sameHash = location.hash === previousLocation.hash;
|
|
23
|
+
const sameSearch = location.search === previousLocation.search;
|
|
24
|
+
// Query-string changes: do not scroll to top/hash
|
|
25
|
+
if (samePathname && sameHash && !sameSearch) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
18
28
|
const { hash } = location;
|
|
19
29
|
if (!hash) {
|
|
20
30
|
window.scrollTo(0, 0);
|
|
@@ -28,9 +38,7 @@ function scrollAfterNavigation(location) {
|
|
|
28
38
|
function ClientLifecyclesDispatcher({ children, location, previousLocation, }) {
|
|
29
39
|
useLayoutEffect(() => {
|
|
30
40
|
if (previousLocation !== location) {
|
|
31
|
-
|
|
32
|
-
scrollAfterNavigation(location);
|
|
33
|
-
}
|
|
41
|
+
scrollAfterNavigation({ location, previousLocation });
|
|
34
42
|
dispatchLifecycleAction('onRouteDidUpdate', { previousLocation, location });
|
|
35
43
|
}
|
|
36
44
|
}, [previousLocation, location]);
|
|
@@ -4,6 +4,7 @@
|
|
|
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 { useCallback } from 'react';
|
|
7
8
|
import useDocusaurusContext from './useDocusaurusContext';
|
|
8
9
|
import { hasProtocol } from './isInternalUrl';
|
|
9
10
|
function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolute = false } = {}) {
|
|
@@ -27,8 +28,9 @@ function addBaseUrl(siteUrl, baseUrl, url, { forcePrependBaseUrl = false, absolu
|
|
|
27
28
|
}
|
|
28
29
|
export function useBaseUrlUtils() {
|
|
29
30
|
const { siteConfig: { baseUrl, url: siteUrl }, } = useDocusaurusContext();
|
|
31
|
+
const withBaseUrl = useCallback((url, options) => addBaseUrl(siteUrl, baseUrl, url, options), [siteUrl, baseUrl]);
|
|
30
32
|
return {
|
|
31
|
-
withBaseUrl
|
|
33
|
+
withBaseUrl,
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
export default function useBaseUrl(url, options = {}) {
|
package/lib/commands/build.js
CHANGED
|
@@ -131,7 +131,11 @@ async function buildLocale({ siteDir, locale, cliOptions, forceTerminate, isLast
|
|
|
131
131
|
serverConfig = (0, webpack_merge_1.default)(serverConfig, {
|
|
132
132
|
plugins: [
|
|
133
133
|
new copy_webpack_plugin_1.default({
|
|
134
|
-
patterns: staticDirectories.map((dir) => ({
|
|
134
|
+
patterns: staticDirectories.map((dir) => ({
|
|
135
|
+
from: dir,
|
|
136
|
+
to: outDir,
|
|
137
|
+
toType: 'dir',
|
|
138
|
+
})),
|
|
135
139
|
}),
|
|
136
140
|
],
|
|
137
141
|
});
|
package/lib/commands/deploy.js
CHANGED
|
@@ -53,7 +53,7 @@ This behavior can have SEO impacts and create relative link issues.
|
|
|
53
53
|
}
|
|
54
54
|
// Source repo is the repo from where the command is invoked
|
|
55
55
|
const sourceRepoUrl = shelljs_1.default
|
|
56
|
-
.exec('git
|
|
56
|
+
.exec('git remote get-url origin', { silent: true })
|
|
57
57
|
.stdout.trim();
|
|
58
58
|
// The source branch; defaults to the currently checked out branch
|
|
59
59
|
const sourceBranch = process.env.CURRENT_BRANCH ??
|
|
@@ -33,7 +33,7 @@ async function eject({ siteDir, themePath, componentName, typescript, }) {
|
|
|
33
33
|
const isDirectory = await isDir(fromPath);
|
|
34
34
|
const globPattern = isDirectory
|
|
35
35
|
? // Do we really want to copy all components?
|
|
36
|
-
path_1.default.join(fromPath, '
|
|
36
|
+
path_1.default.join(fromPath, '**/*')
|
|
37
37
|
: `${fromPath}.*`;
|
|
38
38
|
const globPatternPosix = (0, utils_1.posixPath)(globPattern);
|
|
39
39
|
const filesToCopy = await (0, utils_1.Globby)(globPatternPosix, {
|
|
@@ -42,6 +42,7 @@ async function eject({ siteDir, themePath, componentName, typescript, }) {
|
|
|
42
42
|
// When ejecting JS components, we want to avoid emitting TS files
|
|
43
43
|
// In particular the .d.ts files that theme build output contains
|
|
44
44
|
typescript ? null : '**/*.{d.ts,ts,tsx}',
|
|
45
|
+
'**/{__fixtures__,__tests__}/*',
|
|
45
46
|
]),
|
|
46
47
|
});
|
|
47
48
|
if (filesToCopy.length === 0) {
|
|
@@ -15,6 +15,15 @@ export declare type ThemeComponents = {
|
|
|
15
15
|
hasAnySafeAction: (component: string) => boolean;
|
|
16
16
|
hasAllSafeAction: (component: string) => boolean;
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Expand a list of components to include and return parent folders.
|
|
20
|
+
* If a folder is not directly a component (no Folder/index.tsx file),
|
|
21
|
+
* we still want to be able to swizzle --eject that folder.
|
|
22
|
+
* See https://github.com/facebook/docusaurus/pull/7175#issuecomment-1103757218
|
|
23
|
+
*
|
|
24
|
+
* @param componentNames the original list of component names
|
|
25
|
+
*/
|
|
26
|
+
export declare function getMissingIntermediateComponentFolderNames(componentNames: string[]): string[];
|
|
18
27
|
export declare function readComponentNames(themePath: string): Promise<string[]>;
|
|
19
28
|
export declare function listComponentNames(themeComponents: ThemeComponents): string;
|
|
20
29
|
export declare function getThemeComponents({ themeName, themePath, swizzleConfig, }: {
|
|
@@ -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.getComponentName = exports.getThemeComponents = exports.listComponentNames = exports.readComponentNames = void 0;
|
|
9
|
+
exports.getComponentName = exports.getThemeComponents = exports.listComponentNames = exports.readComponentNames = exports.getMissingIntermediateComponentFolderNames = 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"));
|
|
@@ -37,6 +37,7 @@ function getMissingIntermediateComponentFolderNames(componentNames) {
|
|
|
37
37
|
const expandedComponentNames = lodash_1.default.uniq(componentNames.flatMap((componentName) => getAllIntermediatePaths(componentName)));
|
|
38
38
|
return lodash_1.default.difference(expandedComponentNames, componentNames);
|
|
39
39
|
}
|
|
40
|
+
exports.getMissingIntermediateComponentFolderNames = getMissingIntermediateComponentFolderNames;
|
|
40
41
|
const skipReadDirNames = ['__test__', '__tests__', '__mocks__', '__fixtures__'];
|
|
41
42
|
async function readComponentNames(themePath) {
|
|
42
43
|
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
package/lib/server/routes.js
CHANGED
|
@@ -18,6 +18,7 @@ function indent(str) {
|
|
|
18
18
|
return ` ${str.replace(/\n/g, `\n `)}`;
|
|
19
19
|
}
|
|
20
20
|
const chunkNameCache = new Map();
|
|
21
|
+
const chunkNameCount = new Map();
|
|
21
22
|
/**
|
|
22
23
|
* Generates a unique chunk name that can be used in the chunk registry.
|
|
23
24
|
*
|
|
@@ -41,10 +42,15 @@ function genChunkName(modulePath, prefix, preferredName, shortId = process.env.N
|
|
|
41
42
|
const shortHash = (0, utils_1.simpleHash)(modulePath, 3);
|
|
42
43
|
str = `${preferredName}${shortHash}`;
|
|
43
44
|
}
|
|
44
|
-
const name =
|
|
45
|
+
const name = (0, utils_1.docuHash)(str);
|
|
45
46
|
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
46
47
|
}
|
|
48
|
+
const seenCount = (chunkNameCount.get(chunkName) ?? 0) + 1;
|
|
49
|
+
if (seenCount > 1) {
|
|
50
|
+
chunkName += seenCount.toString(36);
|
|
51
|
+
}
|
|
47
52
|
chunkNameCache.set(modulePath, chunkName);
|
|
53
|
+
chunkNameCount.set(chunkName, seenCount);
|
|
48
54
|
}
|
|
49
55
|
return chunkName;
|
|
50
56
|
}
|
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": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"@babel/runtime": "^7.18.6",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.18.6",
|
|
45
45
|
"@babel/traverse": "^7.18.8",
|
|
46
|
-
"@docusaurus/cssnano-preset": "2.
|
|
47
|
-
"@docusaurus/logger": "2.
|
|
48
|
-
"@docusaurus/mdx-loader": "2.
|
|
46
|
+
"@docusaurus/cssnano-preset": "2.3.0",
|
|
47
|
+
"@docusaurus/logger": "2.3.0",
|
|
48
|
+
"@docusaurus/mdx-loader": "2.3.0",
|
|
49
49
|
"@docusaurus/react-loadable": "5.5.2",
|
|
50
|
-
"@docusaurus/utils": "2.
|
|
51
|
-
"@docusaurus/utils-common": "2.
|
|
52
|
-
"@docusaurus/utils-validation": "2.
|
|
50
|
+
"@docusaurus/utils": "2.3.0",
|
|
51
|
+
"@docusaurus/utils-common": "2.3.0",
|
|
52
|
+
"@docusaurus/utils-validation": "2.3.0",
|
|
53
53
|
"@slorber/static-site-generator-webpack-plugin": "^4.0.7",
|
|
54
54
|
"@svgr/webpack": "^6.2.1",
|
|
55
55
|
"autoprefixer": "^10.4.7",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
"webpackbar": "^5.0.2"
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
-
"@docusaurus/module-type-aliases": "2.
|
|
110
|
-
"@docusaurus/types": "2.
|
|
109
|
+
"@docusaurus/module-type-aliases": "2.3.0",
|
|
110
|
+
"@docusaurus/types": "2.3.0",
|
|
111
111
|
"@types/detect-port": "^1.3.2",
|
|
112
112
|
"@types/react-dom": "^18.0.6",
|
|
113
113
|
"@types/react-router-config": "^5.0.6",
|
|
@@ -127,5 +127,5 @@
|
|
|
127
127
|
"engines": {
|
|
128
128
|
"node": ">=16.14"
|
|
129
129
|
},
|
|
130
|
-
"gitHead": "
|
|
130
|
+
"gitHead": "ad477781bdca6a11fa9c6daef5048bdcec0ee37e"
|
|
131
131
|
}
|