@docusaurus/core 3.8.1-canary-6372 → 3.8.1-canary-6374

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.
@@ -44,7 +44,6 @@ export default function ComponentCreator(path, hash) {
44
44
  Object.entries(flatChunkNames).forEach(([keyPath, chunkName]) => {
45
45
  const chunkRegistry = registry[chunkName];
46
46
  if (chunkRegistry) {
47
- // eslint-disable-next-line prefer-destructuring
48
47
  loader[keyPath] = chunkRegistry[0];
49
48
  modules.push(chunkRegistry[1]);
50
49
  optsWebpack.push(chunkRegistry[2]);
@@ -14,6 +14,7 @@ const utils_1 = require("@docusaurus/utils");
14
14
  const site_1 = require("../../server/site");
15
15
  const i18n_1 = require("../../server/i18n");
16
16
  const buildLocale_1 = require("./buildLocale");
17
+ const buildUtils_1 = require("./buildUtils");
17
18
  async function build(siteDirParam = '.', cliOptions = {}) {
18
19
  process.env.BABEL_ENV = 'production';
19
20
  process.env.NODE_ENV = 'production';
@@ -49,19 +50,19 @@ function orderLocales({ locales, defaultLocale, }) {
49
50
  }
50
51
  }
51
52
  async function getLocalesToBuild({ siteDir, cliOptions, }) {
52
- // We disable locale path localization if CLI has single "--locale" option
53
- // yarn build --locale fr => baseUrl=/ instead of baseUrl=/fr/
54
- const localizePath = cliOptions.locale?.length === 1 ? false : undefined;
53
+ // TODO we shouldn't need to load all context + i18n just to get that list
54
+ // only loading siteConfig should be enough
55
55
  const context = await (0, site_1.loadContext)({
56
56
  siteDir,
57
57
  outDir: cliOptions.outDir,
58
58
  config: cliOptions.config,
59
- localizePath,
59
+ automaticBaseUrlLocalizationDisabled: (0, buildUtils_1.isAutomaticBaseUrlLocalizationDisabled)(cliOptions),
60
60
  });
61
61
  const i18n = await (0, i18n_1.loadI18n)({
62
62
  siteDir,
63
63
  config: context.siteConfig,
64
- currentLocale: context.siteConfig.i18n.defaultLocale // Awkward but ok
64
+ currentLocale: context.siteConfig.i18n.defaultLocale, // Awkward but ok
65
+ automaticBaseUrlLocalizationDisabled: false,
65
66
  });
66
67
  const locales = cliOptions.locale ?? i18n.locales;
67
68
  return orderLocales({
@@ -20,6 +20,7 @@ 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
22
  const clearPath_1 = tslib_1.__importDefault(require("../utils/clearPath"));
23
+ const buildUtils_1 = require("./buildUtils");
23
24
  const SkipBundling = process.env.DOCUSAURUS_SKIP_BUNDLING === 'true';
24
25
  const ExitAfterLoading = process.env.DOCUSAURUS_EXIT_AFTER_LOADING === 'true';
25
26
  const ExitAfterBundling = process.env.DOCUSAURUS_EXIT_AFTER_BUNDLING === 'true';
@@ -34,7 +35,7 @@ async function buildLocale({ siteDir, locale, cliOptions, }) {
34
35
  outDir: cliOptions.outDir,
35
36
  config: cliOptions.config,
36
37
  locale,
37
- localizePath: cliOptions.locale?.length === 1 ? false : undefined,
38
+ automaticBaseUrlLocalizationDisabled: (0, buildUtils_1.isAutomaticBaseUrlLocalizationDisabled)(cliOptions),
38
39
  }));
39
40
  if (ExitAfterLoading) {
40
41
  return process.exit(0);
@@ -0,0 +1,14 @@
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 { BuildCLIOptions } from './build';
8
+ /**
9
+ * We disable locale path localization if CLI has a single "--locale" option
10
+ * yarn build --locale fr => baseUrl=/ instead of baseUrl=/fr/
11
+ * By default, this makes it easier to support multi-domain deployments
12
+ * See https://docusaurus.io/docs/i18n/tutorial#multi-domain-deployment
13
+ */
14
+ export declare function isAutomaticBaseUrlLocalizationDisabled(cliOptions: BuildCLIOptions): boolean;
@@ -0,0 +1,18 @@
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.isAutomaticBaseUrlLocalizationDisabled = isAutomaticBaseUrlLocalizationDisabled;
10
+ /**
11
+ * We disable locale path localization if CLI has a single "--locale" option
12
+ * yarn build --locale fr => baseUrl=/ instead of baseUrl=/fr/
13
+ * By default, this makes it easier to support multi-domain deployments
14
+ * See https://docusaurus.io/docs/i18n/tutorial#multi-domain-deployment
15
+ */
16
+ function isAutomaticBaseUrlLocalizationDisabled(cliOptions) {
17
+ return cliOptions.locale?.length === 1;
18
+ }
@@ -53,7 +53,6 @@ async function createLoadSiteParams({ siteDirParam, cliOptions, }) {
53
53
  siteDir,
54
54
  config: cliOptions.config,
55
55
  locale: cliOptions.locale,
56
- localizePath: undefined, // Should this be configurable?
57
56
  };
58
57
  }
59
58
  // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
@@ -14,6 +14,28 @@ const utils_validation_1 = require("@docusaurus/utils-validation");
14
14
  const utils_common_1 = require("@docusaurus/utils-common");
15
15
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
16
16
  const DEFAULT_I18N_LOCALE = 'en';
17
+ const SiteUrlSchema = utils_validation_1.Joi.string()
18
+ .custom((value, helpers) => {
19
+ try {
20
+ const { pathname } = new URL(value);
21
+ if (pathname !== '/') {
22
+ return helpers.error('docusaurus.subPathError', { pathname });
23
+ }
24
+ }
25
+ catch {
26
+ return helpers.error('any.invalid');
27
+ }
28
+ return (0, utils_common_1.removeTrailingSlash)(value);
29
+ })
30
+ .messages({
31
+ 'any.invalid': '"{#value}" does not look like a valid URL. Make sure it has a protocol; for example, "https://example.com".',
32
+ 'docusaurus.subPathError': 'The url is not supposed to contain a sub-path like "{#pathname}". Please use the baseUrl field for sub-paths.',
33
+ });
34
+ const BaseUrlSchema = utils_validation_1.Joi
35
+ // Weird Joi trick needed, otherwise value '' is not normalized...
36
+ .alternatives()
37
+ .try(utils_validation_1.Joi.string().required().allow(''))
38
+ .custom((value) => (0, utils_common_1.addLeadingSlash)((0, utils_common_1.addTrailingSlash)(value)));
17
39
  exports.DEFAULT_I18N_CONFIG = {
18
40
  defaultLocale: DEFAULT_I18N_LOCALE,
19
41
  path: utils_1.DEFAULT_I18N_DIR_NAME,
@@ -155,9 +177,11 @@ const PresetSchema = utils_validation_1.Joi.alternatives()
155
177
  const LocaleConfigSchema = utils_validation_1.Joi.object({
156
178
  label: utils_validation_1.Joi.string(),
157
179
  htmlLang: utils_validation_1.Joi.string(),
158
- direction: utils_validation_1.Joi.string().equal('ltr', 'rtl').default('ltr'),
180
+ direction: utils_validation_1.Joi.string().equal('ltr', 'rtl'),
159
181
  calendar: utils_validation_1.Joi.string(),
160
182
  path: utils_validation_1.Joi.string(),
183
+ url: SiteUrlSchema,
184
+ baseUrl: BaseUrlSchema,
161
185
  });
162
186
  const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
163
187
  defaultLocale: utils_validation_1.Joi.string().required(),
@@ -213,36 +237,13 @@ const FUTURE_CONFIG_SCHEMA = utils_validation_1.Joi.object({
213
237
  })
214
238
  .optional()
215
239
  .default(exports.DEFAULT_FUTURE_CONFIG);
216
- const SiteUrlSchema = utils_validation_1.Joi.string()
217
- .required()
218
- .custom((value, helpers) => {
219
- try {
220
- const { pathname } = new URL(value);
221
- if (pathname !== '/') {
222
- return helpers.error('docusaurus.subPathError', { pathname });
223
- }
224
- }
225
- catch {
226
- return helpers.error('any.invalid');
227
- }
228
- return (0, utils_common_1.removeTrailingSlash)(value);
229
- })
230
- .messages({
231
- 'any.invalid': '"{#value}" does not look like a valid URL. Make sure it has a protocol; for example, "https://example.com".',
232
- 'docusaurus.subPathError': 'The url is not supposed to contain a sub-path like "{#pathname}". Please use the baseUrl field for sub-paths.',
233
- });
234
240
  // TODO move to @docusaurus/utils-validation
235
241
  exports.ConfigSchema = utils_validation_1.Joi.object({
236
- baseUrl: utils_validation_1.Joi
237
- // Weird Joi trick needed, otherwise value '' is not normalized...
238
- .alternatives()
239
- .try(utils_validation_1.Joi.string().required().allow(''))
240
- .required()
241
- .custom((value) => (0, utils_common_1.addLeadingSlash)((0, utils_common_1.addTrailingSlash)(value))),
242
+ url: SiteUrlSchema.required(),
243
+ baseUrl: BaseUrlSchema.required(),
242
244
  baseUrlIssueBanner: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.baseUrlIssueBanner),
243
245
  favicon: utils_validation_1.Joi.string().optional(),
244
246
  title: utils_validation_1.Joi.string().required(),
245
- url: SiteUrlSchema,
246
247
  trailingSlash: utils_validation_1.Joi.boolean(), // No default value! undefined = retrocompatible legacy behavior!
247
248
  i18n: I18N_CONFIG_SCHEMA,
248
249
  future: FUTURE_CONFIG_SCHEMA,
@@ -5,9 +5,10 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
8
- export declare function getDefaultLocaleConfig(locale: string): Omit<I18nLocaleConfig, 'translate'>;
9
- export declare function loadI18n({ siteDir, config, currentLocale, }: {
8
+ export declare function getDefaultLocaleConfig(locale: string): Omit<I18nLocaleConfig, 'translate' | 'url' | 'baseUrl'>;
9
+ export declare function loadI18n({ siteDir, config, currentLocale, automaticBaseUrlLocalizationDisabled, }: {
10
10
  siteDir: string;
11
11
  config: DocusaurusConfig;
12
12
  currentLocale: string;
13
+ automaticBaseUrlLocalizationDisabled: boolean;
13
14
  }): Promise<I18n>;
@@ -13,6 +13,7 @@ const path_1 = tslib_1.__importDefault(require("path"));
13
13
  const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
14
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
15
  const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
16
+ const utils_1 = require("@docusaurus/utils");
16
17
  function inferLanguageDisplayName(locale) {
17
18
  const tryLocale = (l) => {
18
19
  try {
@@ -83,7 +84,7 @@ function getDefaultLocaleConfig(locale) {
83
84
  throw new Error(`Docusaurus couldn't get default locale config for ${locale}`, { cause: e });
84
85
  }
85
86
  }
86
- async function loadI18n({ siteDir, config, currentLocale, }) {
87
+ async function loadI18n({ siteDir, config, currentLocale, automaticBaseUrlLocalizationDisabled, }) {
87
88
  const { i18n: i18nConfig } = config;
88
89
  if (!i18nConfig.locales.includes(currentLocale)) {
89
90
  logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
@@ -103,10 +104,28 @@ Note: Docusaurus only support running one locale at a time.`;
103
104
  const localizationDir = path_1.default.resolve(siteDir, i18nConfig.path, localeConfig.path);
104
105
  return fs_extra_1.default.pathExists(localizationDir);
105
106
  }
107
+ function getInferredBaseUrl() {
108
+ const addLocaleSegment = locale !== i18nConfig.defaultLocale &&
109
+ !automaticBaseUrlLocalizationDisabled;
110
+ return (0, utils_1.normalizeUrl)([
111
+ '/',
112
+ config.baseUrl,
113
+ addLocaleSegment ? locale : '',
114
+ '/',
115
+ ]);
116
+ }
106
117
  const translate = localeConfigInput.translate ?? (await inferTranslate());
118
+ const url = typeof localeConfigInput.url !== 'undefined'
119
+ ? localeConfigInput.url
120
+ : config.url;
121
+ const baseUrl = typeof localeConfigInput.baseUrl !== 'undefined'
122
+ ? (0, utils_1.normalizeUrl)(['/', localeConfigInput.baseUrl, '/'])
123
+ : getInferredBaseUrl();
107
124
  return {
108
125
  ...localeConfig,
109
126
  translate,
127
+ url,
128
+ baseUrl,
110
129
  };
111
130
  }
112
131
  const localeConfigs = await (0, combine_promises_1.default)(Object.fromEntries(locales.map((locale) => [locale, getFullLocaleConfig(locale)])));
@@ -15,12 +15,19 @@ export type LoadContextParams = {
15
15
  /** Default is `i18n.defaultLocale` */
16
16
  locale?: string;
17
17
  /**
18
- * `true` means the paths will have the locale prepended; `false` means they
19
- * won't (useful for `yarn build -l zh-Hans` where the output should be
20
- * emitted into `build/` instead of `build/zh-Hans/`); `undefined` is like the
21
- * "smart" option where only non-default locale paths are localized
18
+ * By default, we try to automatically infer a localized baseUrl.
19
+ * We prepend `/<siteBaseUrl>/` with a `/<locale>/` path segment,
20
+ * except for the default locale.
21
+ *
22
+ * This option permits opting out of this baseUrl localization process.
23
+ * It is mostly useful to simplify config for multi-domain i18n deployments.
24
+ * See https://docusaurus.io/docs/i18n/tutorial#multi-domain-deployment
25
+ *
26
+ * In all cases, this process doesn't happen if an explicit localized baseUrl
27
+ * has been provided using `i18n.localeConfigs[].baseUrl`. We always use the
28
+ * provided value over the inferred one, letting you override it.
22
29
  */
23
- localizePath?: boolean;
30
+ automaticBaseUrlLocalizationDisabled?: boolean;
24
31
  };
25
32
  export type LoadSiteParams = LoadContextParams & {
26
33
  isReload?: boolean;
@@ -34,7 +34,7 @@ const siteMessages_1 = require("./siteMessages");
34
34
  * to plugin constructors.
35
35
  */
36
36
  async function loadContext(params) {
37
- const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, } = params;
37
+ const { siteDir, outDir: baseOutDir = utils_1.DEFAULT_BUILD_DIR_NAME, locale, config: customConfigFilePath, automaticBaseUrlLocalizationDisabled, } = params;
38
38
  const generatedFilesDir = path_1.default.resolve(siteDir, utils_1.GENERATED_FILES_DIR_NAME);
39
39
  const { siteVersion, loadSiteConfig: { siteConfig: initialSiteConfig, siteConfigPath }, } = await (0, combine_promises_1.default)({
40
40
  siteVersion: (0, siteMetadata_1.loadSiteVersion)(siteDir),
@@ -50,21 +50,19 @@ async function loadContext(params) {
50
50
  siteDir,
51
51
  config: initialSiteConfig,
52
52
  currentLocale: locale ?? initialSiteConfig.i18n.defaultLocale,
53
+ automaticBaseUrlLocalizationDisabled: automaticBaseUrlLocalizationDisabled ?? false,
53
54
  });
54
- const baseUrl = (0, utils_1.localizePath)({
55
- path: initialSiteConfig.baseUrl,
56
- i18n,
57
- options: params,
58
- pathType: 'url',
59
- });
60
- const outDir = (0, utils_1.localizePath)({
61
- path: path_1.default.resolve(siteDir, baseOutDir),
62
- i18n,
63
- options: params,
64
- pathType: 'fs',
65
- });
55
+ const localeConfig = (0, utils_1.getLocaleConfig)(i18n);
56
+ // We use the baseUrl from the locale config.
57
+ // By default, it is inferred as /<siteConfig.baseUrl>/
58
+ // eventually including the /<locale>/ suffix
59
+ const baseUrl = localeConfig.baseUrl;
60
+ const outDir = path_1.default.join(path_1.default.resolve(siteDir, baseOutDir), baseUrl);
66
61
  const localizationDir = path_1.default.resolve(siteDir, i18n.path, (0, utils_1.getLocaleConfig)(i18n).path);
67
- const siteConfig = { ...initialSiteConfig, baseUrl };
62
+ const siteConfig = {
63
+ ...initialSiteConfig,
64
+ baseUrl,
65
+ };
68
66
  const codeTranslations = await (0, translations_1.loadSiteCodeTranslations)({ localizationDir });
69
67
  const siteStorage = (0, storage_1.createSiteStorage)(siteConfig);
70
68
  return {
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.8.1-canary-6372",
4
+ "version": "3.8.1-canary-6374",
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.8.1-canary-6372",
37
- "@docusaurus/bundler": "3.8.1-canary-6372",
38
- "@docusaurus/logger": "3.8.1-canary-6372",
39
- "@docusaurus/mdx-loader": "3.8.1-canary-6372",
40
- "@docusaurus/utils": "3.8.1-canary-6372",
41
- "@docusaurus/utils-common": "3.8.1-canary-6372",
42
- "@docusaurus/utils-validation": "3.8.1-canary-6372",
36
+ "@docusaurus/babel": "3.8.1-canary-6374",
37
+ "@docusaurus/bundler": "3.8.1-canary-6374",
38
+ "@docusaurus/logger": "3.8.1-canary-6374",
39
+ "@docusaurus/mdx-loader": "3.8.1-canary-6374",
40
+ "@docusaurus/utils": "3.8.1-canary-6374",
41
+ "@docusaurus/utils-common": "3.8.1-canary-6374",
42
+ "@docusaurus/utils-validation": "3.8.1-canary-6374",
43
43
  "boxen": "^6.2.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -77,8 +77,8 @@
77
77
  "webpack-merge": "^6.0.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@docusaurus/module-type-aliases": "3.8.1-canary-6372",
81
- "@docusaurus/types": "3.8.1-canary-6372",
80
+ "@docusaurus/module-type-aliases": "3.8.1-canary-6374",
81
+ "@docusaurus/types": "3.8.1-canary-6374",
82
82
  "@total-typescript/shoehorn": "^0.1.2",
83
83
  "@types/detect-port": "^1.3.3",
84
84
  "@types/react-dom": "^18.2.7",
@@ -98,5 +98,5 @@
98
98
  "engines": {
99
99
  "node": ">=18.0"
100
100
  },
101
- "gitHead": "0229ae8aadbcfbebd1f49b3bdd174bea21ae93d4"
101
+ "gitHead": "d7c2ad4c6a14ff1185b4ee7bef89cd56c15d3869"
102
102
  }