@docusaurus/core 4.0.0-canary-6835 → 4.0.0-canary-6840
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/client/App.js +9 -12
- package/lib/client/exports/useIsBrowser.js +9 -3
- package/lib/commands/start/watcher.d.ts +1 -1
- package/lib/commands/start/watcher.js +8 -8
- package/lib/commands/swizzle/actions.js +2 -1
- package/lib/commands/writeHeadingIds.js +6 -3
- package/lib/commands/writeTranslations.js +2 -2
- package/lib/server/plugins/synthetic.js +1 -0
- package/lib/server/translations/translationsExtractor.js +2 -1
- package/lib/webpack/aliases/index.js +2 -1
- package/lib/webpack/base.js +4 -0
- package/package.json +13 -13
- package/lib/client/browserContext.d.ts +0 -11
- package/lib/client/browserContext.js +0 -22
package/lib/client/App.js
CHANGED
|
@@ -13,7 +13,6 @@ import Root from '@theme/Root';
|
|
|
13
13
|
import ThemeProvider from '@theme/ThemeProvider';
|
|
14
14
|
import SiteMetadata from '@theme/SiteMetadata';
|
|
15
15
|
import normalizeLocation from './normalizeLocation';
|
|
16
|
-
import { BrowserContextProvider } from './browserContext';
|
|
17
16
|
import { DocusaurusContextProvider } from './docusaurusContext';
|
|
18
17
|
import PendingNavigation from './PendingNavigation';
|
|
19
18
|
import BaseUrlIssueBanner from './BaseUrlIssueBanner';
|
|
@@ -33,17 +32,15 @@ function AppNavigation() {
|
|
|
33
32
|
export default function App() {
|
|
34
33
|
return (<ErrorBoundary>
|
|
35
34
|
<DocusaurusContextProvider>
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<HasHydratedDataAttribute />
|
|
46
|
-
</BrowserContextProvider>
|
|
35
|
+
<Root>
|
|
36
|
+
<ThemeProvider>
|
|
37
|
+
<SiteMetadataDefaults />
|
|
38
|
+
<SiteMetadata />
|
|
39
|
+
<BaseUrlIssueBanner />
|
|
40
|
+
<AppNavigation />
|
|
41
|
+
</ThemeProvider>
|
|
42
|
+
</Root>
|
|
43
|
+
<HasHydratedDataAttribute />
|
|
47
44
|
</DocusaurusContextProvider>
|
|
48
45
|
</ErrorBoundary>);
|
|
49
46
|
}
|
|
@@ -4,8 +4,14 @@
|
|
|
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 {
|
|
8
|
-
|
|
7
|
+
import { useSyncExternalStore } from 'react';
|
|
8
|
+
// The "browser" state never changes, there's nothing to subscribe to
|
|
9
|
+
const subscribe = () => () => { };
|
|
10
|
+
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
+
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
12
|
+
// React uses getServerSnapshot during SSR and hydration, and re-renders with
|
|
13
|
+
// getSnapshot right after hydration. Components mounted after hydration
|
|
14
|
+
// directly get the client value, without an extra re-render.
|
|
9
15
|
export default function useIsBrowser() {
|
|
10
|
-
return
|
|
16
|
+
return useSyncExternalStore(subscribe, () => true, () => false);
|
|
11
17
|
}
|
|
@@ -24,7 +24,7 @@ type WatchParams = {
|
|
|
24
24
|
* Watch file system paths for changes and emit events
|
|
25
25
|
* Returns an async handle to stop watching
|
|
26
26
|
*/
|
|
27
|
-
export declare function
|
|
27
|
+
export declare function watchPaths(params: WatchParams, callback: (event: FileWatchEvent) => void): () => Promise<void>;
|
|
28
28
|
export declare function getSitePathsToWatch({ props }: {
|
|
29
29
|
props: Props;
|
|
30
30
|
}): string[];
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createPollingOptions = createPollingOptions;
|
|
10
|
-
exports.
|
|
10
|
+
exports.watchPaths = watchPaths;
|
|
11
11
|
exports.getSitePathsToWatch = getSitePathsToWatch;
|
|
12
12
|
exports.getPluginPathsToWatch = getPluginPathsToWatch;
|
|
13
13
|
exports.setupSiteFileWatchers = setupSiteFileWatchers;
|
|
14
14
|
const tslib_1 = require("tslib");
|
|
15
15
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
-
const
|
|
16
|
+
const glob_1 = require("@docusaurus/glob");
|
|
17
17
|
const utils_1 = require("@docusaurus/utils");
|
|
18
18
|
function createPollingOptions(cliOptions) {
|
|
19
19
|
return {
|
|
@@ -27,15 +27,15 @@ function createPollingOptions(cliOptions) {
|
|
|
27
27
|
* Watch file system paths for changes and emit events
|
|
28
28
|
* Returns an async handle to stop watching
|
|
29
29
|
*/
|
|
30
|
-
function
|
|
30
|
+
function watchPaths(params, callback) {
|
|
31
31
|
const { pathsToWatch, siteDir, ...options } = params;
|
|
32
|
-
const
|
|
32
|
+
const watcher = (0, glob_1.watch)(pathsToWatch, {
|
|
33
33
|
cwd: siteDir,
|
|
34
34
|
ignoreInitial: true,
|
|
35
35
|
...options,
|
|
36
36
|
});
|
|
37
|
-
|
|
38
|
-
return () =>
|
|
37
|
+
watcher.on('all', (name, eventPath) => callback({ name, path: eventPath }));
|
|
38
|
+
return () => watcher.close();
|
|
39
39
|
}
|
|
40
40
|
function getSitePathsToWatch({ props }) {
|
|
41
41
|
return [
|
|
@@ -62,13 +62,13 @@ function setupSiteFileWatchers({ props, cliOptions, }, callback) {
|
|
|
62
62
|
// TODO on config / or local plugin updates,
|
|
63
63
|
// the getFilePathsToWatch lifecycle code might get updated
|
|
64
64
|
// so we should probably reset the watchers?
|
|
65
|
-
|
|
65
|
+
watchPaths({
|
|
66
66
|
pathsToWatch: getSitePathsToWatch({ props }),
|
|
67
67
|
siteDir: props.siteDir,
|
|
68
68
|
...pollingOptions,
|
|
69
69
|
}, (event) => callback({ plugin: null, event }));
|
|
70
70
|
props.plugins.forEach((plugin) => {
|
|
71
|
-
|
|
71
|
+
watchPaths({
|
|
72
72
|
pathsToWatch: getPluginPathsToWatch({ plugin, siteDir }),
|
|
73
73
|
siteDir,
|
|
74
74
|
...pollingOptions,
|
|
@@ -16,6 +16,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
16
16
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
17
17
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
18
18
|
const utils_1 = require("@docusaurus/utils");
|
|
19
|
+
const glob_1 = require("@docusaurus/glob");
|
|
19
20
|
const prompts_1 = require("./prompts");
|
|
20
21
|
exports.SwizzleActions = ['wrap', 'eject'];
|
|
21
22
|
async function getAction(componentConfig, options) {
|
|
@@ -38,7 +39,7 @@ async function eject({ siteDir, themePath, componentName, typescript, }) {
|
|
|
38
39
|
path_1.default.join(fromPath, '**/*')
|
|
39
40
|
: `${fromPath}.*`;
|
|
40
41
|
const globPatternPosix = (0, utils_1.posixPath)(globPattern);
|
|
41
|
-
const filesToCopy = await (0,
|
|
42
|
+
const filesToCopy = await (0, glob_1.glob)(globPatternPosix, {
|
|
42
43
|
// Workaround for Tinyglobby bug?
|
|
43
44
|
// We glob absolute from the theme root path, not from cwd
|
|
44
45
|
// See https://github.com/SuperchupuDev/tinyglobby/issues/186
|
|
@@ -11,6 +11,7 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
12
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const glob_1 = require("@docusaurus/glob");
|
|
14
15
|
const site_1 = require("../server/site");
|
|
15
16
|
const init_1 = require("../server/plugins/init");
|
|
16
17
|
function inferFallbackSyntax(_filepath) {
|
|
@@ -38,6 +39,10 @@ async function transformMarkdownFile(filepath, options) {
|
|
|
38
39
|
}
|
|
39
40
|
return undefined;
|
|
40
41
|
}
|
|
42
|
+
async function globMarkdownFiles(patterns) {
|
|
43
|
+
const files = await (0, glob_1.safeGlob)(patterns);
|
|
44
|
+
return files.filter((file) => file.endsWith('.md') || file.endsWith('.mdx'));
|
|
45
|
+
}
|
|
41
46
|
/**
|
|
42
47
|
* We only handle the "paths to watch" because these are the paths where the
|
|
43
48
|
* markdown files are. Also we don't want to transform the site md docs that do
|
|
@@ -63,9 +68,7 @@ async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
|
|
|
63
68
|
validateOptions(options);
|
|
64
69
|
const siteDir = await fs_extra_1.default.realpath(siteDirParam);
|
|
65
70
|
const patterns = files.length ? files : await getPathsToWatch(siteDir);
|
|
66
|
-
const markdownFiles =
|
|
67
|
-
expandDirectories: true,
|
|
68
|
-
})).filter((file) => file.endsWith('.md') || file.endsWith('.mdx'));
|
|
71
|
+
const markdownFiles = await globMarkdownFiles(patterns);
|
|
69
72
|
if (markdownFiles.length === 0) {
|
|
70
73
|
logger_1.default.warn `No markdown files found in siteDir path=${siteDir} for patterns: ${patterns}`;
|
|
71
74
|
return;
|
|
@@ -10,7 +10,7 @@ exports.writeTranslations = writeTranslations;
|
|
|
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"));
|
|
13
|
-
const
|
|
13
|
+
const glob_1 = require("@docusaurus/glob");
|
|
14
14
|
const site_1 = require("../server/site");
|
|
15
15
|
const init_1 = require("../server/plugins/init");
|
|
16
16
|
const translations_1 = require("../server/translations/translations");
|
|
@@ -35,7 +35,7 @@ async function getExtraSourceCodeFilePaths() {
|
|
|
35
35
|
if (!themeCommonLibDir) {
|
|
36
36
|
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
37
37
|
}
|
|
38
|
-
return (0,
|
|
38
|
+
return (0, glob_1.globTranslatableSourceFiles)([themeCommonLibDir]);
|
|
39
39
|
}
|
|
40
40
|
async function writePluginTranslationFiles({ localizationDir, plugin, options, }) {
|
|
41
41
|
if (plugin.getTranslationFiles) {
|
|
@@ -11,6 +11,7 @@ const tslib_1 = require("tslib");
|
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const glob_1 = require("@docusaurus/glob");
|
|
14
15
|
const babel_1 = require("@docusaurus/babel");
|
|
15
16
|
function getSiteSourceCodeFilePaths(siteDir) {
|
|
16
17
|
return [path_1.default.join(siteDir, utils_1.SRC_DIR_NAME)];
|
|
@@ -36,7 +37,7 @@ async function getSourceCodeFilePaths(siteDir, plugins) {
|
|
|
36
37
|
// new lifecycle method for that???
|
|
37
38
|
const pluginsPaths = plugins.flatMap(getPluginSourceCodeFilePaths);
|
|
38
39
|
const allPaths = [...sitePaths, ...pluginsPaths];
|
|
39
|
-
return (0,
|
|
40
|
+
return (0, glob_1.globTranslatableSourceFiles)(allPaths);
|
|
40
41
|
}
|
|
41
42
|
async function extractSiteSourceCodeTranslations({ siteDir, plugins, extraSourceCodeFilePaths = [], }) {
|
|
42
43
|
const babelOptions = (0, babel_1.getBabelOptions)({
|
|
@@ -15,6 +15,7 @@ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
|
15
15
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
16
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
17
17
|
const utils_1 = require("@docusaurus/utils");
|
|
18
|
+
const glob_1 = require("@docusaurus/glob");
|
|
18
19
|
const ThemeFallbackDir = path_1.default.join(__dirname, '../../client/theme-fallback');
|
|
19
20
|
/**
|
|
20
21
|
* Order of Webpack aliases is important because one alias can shadow another.
|
|
@@ -37,7 +38,7 @@ async function createAliasesForTheme(themePath, addOriginalAlias) {
|
|
|
37
38
|
if (!(await fs_extra_1.default.pathExists(themePath))) {
|
|
38
39
|
return {};
|
|
39
40
|
}
|
|
40
|
-
const themeComponentFiles = await (0,
|
|
41
|
+
const themeComponentFiles = await (0, glob_1.glob)(['**/*.{js,jsx,ts,tsx}'], {
|
|
41
42
|
cwd: themePath,
|
|
42
43
|
ignore: [
|
|
43
44
|
// Ignore co-located test files
|
package/lib/webpack/base.js
CHANGED
|
@@ -109,6 +109,7 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
|
|
|
109
109
|
},
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
+
const notTextImport = { type: { not: 'text' } };
|
|
112
113
|
return {
|
|
113
114
|
mode,
|
|
114
115
|
name,
|
|
@@ -212,6 +213,7 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
|
|
|
212
213
|
{
|
|
213
214
|
test: /\.[jt]sx?$/i,
|
|
214
215
|
exclude: excludeJS,
|
|
216
|
+
with: notTextImport,
|
|
215
217
|
use: [
|
|
216
218
|
createJsLoader({
|
|
217
219
|
isServer,
|
|
@@ -222,6 +224,7 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
|
|
|
222
224
|
{
|
|
223
225
|
test: CSS_REGEX,
|
|
224
226
|
exclude: CSS_MODULE_REGEX,
|
|
227
|
+
with: notTextImport,
|
|
225
228
|
use: configureWebpackUtils.getStyleLoaders(isServer, {
|
|
226
229
|
importLoaders: 1,
|
|
227
230
|
sourceMap: !isProd,
|
|
@@ -231,6 +234,7 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
|
|
|
231
234
|
// using the extension .module.css
|
|
232
235
|
{
|
|
233
236
|
test: CSS_MODULE_REGEX,
|
|
237
|
+
with: notTextImport,
|
|
234
238
|
use: configureWebpackUtils.getStyleLoaders(isServer, {
|
|
235
239
|
modules: {
|
|
236
240
|
// Using the same CSS Module class pattern in dev/prod on purpose
|
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": "4.0.0-canary-
|
|
4
|
+
"version": "4.0.0-canary-6840",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -33,15 +33,15 @@
|
|
|
33
33
|
"url": "https://github.com/facebook/docusaurus/issues"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@docusaurus/babel": "4.0.0-canary-
|
|
37
|
-
"@docusaurus/bundler": "4.0.0-canary-
|
|
38
|
-
"@docusaurus/
|
|
39
|
-
"@docusaurus/
|
|
40
|
-
"@docusaurus/
|
|
41
|
-
"@docusaurus/utils
|
|
42
|
-
"@docusaurus/utils-
|
|
36
|
+
"@docusaurus/babel": "4.0.0-canary-6840",
|
|
37
|
+
"@docusaurus/bundler": "4.0.0-canary-6840",
|
|
38
|
+
"@docusaurus/glob": "4.0.0-canary-6840",
|
|
39
|
+
"@docusaurus/logger": "4.0.0-canary-6840",
|
|
40
|
+
"@docusaurus/mdx-loader": "4.0.0-canary-6840",
|
|
41
|
+
"@docusaurus/utils": "4.0.0-canary-6840",
|
|
42
|
+
"@docusaurus/utils-common": "4.0.0-canary-6840",
|
|
43
|
+
"@docusaurus/utils-validation": "4.0.0-canary-6840",
|
|
43
44
|
"boxen": "^8.0.1",
|
|
44
|
-
"chokidar": "^3.6.0",
|
|
45
45
|
"cli-table3": "^0.6.5",
|
|
46
46
|
"combine-promises": "^1.2.0",
|
|
47
47
|
"commander": "^15.0.0",
|
|
@@ -76,8 +76,8 @@
|
|
|
76
76
|
"webpack-merge": "^6.0.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@docusaurus/module-type-aliases": "4.0.0-canary-
|
|
80
|
-
"@docusaurus/types": "4.0.0-canary-
|
|
79
|
+
"@docusaurus/module-type-aliases": "4.0.0-canary-6840",
|
|
80
|
+
"@docusaurus/types": "4.0.0-canary-6840",
|
|
81
81
|
"@total-typescript/shoehorn": "^0.1.2",
|
|
82
82
|
"@types/escape-html": "^1.0.4",
|
|
83
83
|
"@types/history": "^4.7.11",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"tree-node-cli": "^3.0.0"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
|
-
"@docusaurus/faster": "4.0.0-canary-
|
|
94
|
+
"@docusaurus/faster": "4.0.0-canary-6840",
|
|
95
95
|
"@mdx-js/react": "^3.1.1",
|
|
96
96
|
"react": "^19.3.0",
|
|
97
97
|
"react-dom": "^19.3.0"
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"engines": {
|
|
105
105
|
"node": ">=24.21"
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "b767143bc76b7747a9d1cc747dece7b06195a5c0"
|
|
108
108
|
}
|
|
@@ -1,11 +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 React, { type ReactNode } from 'react';
|
|
8
|
-
export declare const Context: React.Context<boolean>;
|
|
9
|
-
export declare function BrowserContextProvider({ children, }: {
|
|
10
|
-
children: ReactNode;
|
|
11
|
-
}): ReactNode;
|
|
@@ -1,22 +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 React, { useEffect, useState } from 'react';
|
|
8
|
-
// Encapsulate the logic to avoid React hydration problems
|
|
9
|
-
// See https://www.joshwcomeau.com/react/the-perils-of-rehydration/
|
|
10
|
-
// On first client-side render, we need to render exactly as the server rendered
|
|
11
|
-
// isBrowser is set to true only after a successful hydration
|
|
12
|
-
// Note, isBrowser is not part of useDocusaurusContext() for perf reasons
|
|
13
|
-
// Using useDocusaurusContext() (much more common need) should not trigger
|
|
14
|
-
// re-rendering after a successful hydration
|
|
15
|
-
export const Context = React.createContext(false);
|
|
16
|
-
export function BrowserContextProvider({ children, }) {
|
|
17
|
-
const [isBrowser, setIsBrowser] = useState(false);
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
setIsBrowser(true);
|
|
20
|
-
}, []);
|
|
21
|
-
return <Context.Provider value={isBrowser}>{children}</Context.Provider>;
|
|
22
|
-
}
|