@docusaurus/core 3.9.2-canary-6495 → 3.9.2-canary-6526

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/README.md CHANGED
@@ -1 +1,3 @@
1
- # Docusaurus core
1
+ # `@docusaurus/core`
2
+
3
+ The core package of Docusaurus
@@ -135,8 +135,10 @@ async function createCLIProgram({ cli, cliArgs, siteDir, config, }) {
135
135
  cli
136
136
  .command('write-heading-ids [siteDir] [files...]')
137
137
  .description('Generate heading ids in Markdown content.')
138
+ .option('--syntax <syntax>', 'heading ID syntax: "classic" ({#id}) or "mdx-comment" ({/* #id */}) (default: "classic")')
139
+ .option('--migrate', 'migrate existing heading IDs to the target --syntax, if they are using a different syntax (default: false)')
140
+ .option('--overwrite', 'overwrite existing heading IDs, re-generate them from the heading text (default: false)')
138
141
  .option('--maintain-case', "keep the headings' casing, otherwise make all lowercase (default: false)")
139
- .option('--overwrite', 'overwrite existing heading IDs (default: false)')
140
142
  .action(writeHeadingIds_1.writeHeadingIds);
141
143
  cli.arguments('<command>').action((cmd) => {
142
144
  cli.outputHelp();
@@ -13,9 +13,25 @@ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
13
13
  const utils_1 = require("@docusaurus/utils");
14
14
  const site_1 = require("../server/site");
15
15
  const init_1 = require("../server/plugins/init");
16
+ function inferFallbackSyntax(_filepath) {
17
+ // TODO Docusaurus v4 - infer the syntax based on the file extensions?
18
+ // This is not ideal because we have many ways to define the syntax
19
+ // (front matter "format", siteConfig.markdown.format etc...)
20
+ // but probably good enough for now
21
+ // Until then, we default to the classic syntax
22
+ // The mdx-comment syntax is opt-in
23
+ return 'classic';
24
+ }
25
+ function getHeadingIdSyntax(filepath, options) {
26
+ return options?.syntax ?? inferFallbackSyntax(filepath);
27
+ }
16
28
  async function transformMarkdownFile(filepath, options) {
17
29
  const content = await fs_extra_1.default.readFile(filepath, 'utf8');
18
- const updatedContent = (0, utils_1.writeMarkdownHeadingId)(content, options);
30
+ const syntax = getHeadingIdSyntax(filepath, options);
31
+ const updatedContent = (0, utils_1.writeMarkdownHeadingId)(content, {
32
+ ...options,
33
+ syntax,
34
+ });
19
35
  if (content !== updatedContent) {
20
36
  await fs_extra_1.default.writeFile(filepath, updatedContent);
21
37
  return filepath;
@@ -33,17 +49,35 @@ async function getPathsToWatch(siteDir) {
33
49
  const plugins = await (0, init_1.initPlugins)(context);
34
50
  return plugins.flatMap((plugin) => plugin.getPathsToWatch?.() ?? []);
35
51
  }
52
+ // TODO Docusaurus v4 - Upgrade commander, use choices() API?
53
+ function validateOptions(options) {
54
+ const validSyntaxValues = ['classic', 'mdx-comment'];
55
+ if (options.syntax && !validSyntaxValues.includes(options.syntax)) {
56
+ throw new Error(`Invalid --syntax value "${options.syntax}". Valid values: ${validSyntaxValues.join(', ')}`);
57
+ }
58
+ if (options.overwrite && options.migrate) {
59
+ throw new Error("Options --overwrite and --migrate cannot be used together.\nThe --overwrite already re-generates IDs in the target syntax, so the --migrate option wouldn't have any effect.");
60
+ }
61
+ }
36
62
  async function writeHeadingIds(siteDirParam = '.', files = [], options = {}) {
63
+ validateOptions(options);
37
64
  const siteDir = await fs_extra_1.default.realpath(siteDirParam);
38
- const markdownFiles = await (0, utils_1.safeGlobby)(files ?? (await getPathsToWatch(siteDir)), {
65
+ const patterns = files.length ? files : await getPathsToWatch(siteDir);
66
+ const markdownFiles = await (0, utils_1.safeGlobby)(patterns, {
39
67
  expandDirectories: ['**/*.{md,mdx}'],
40
68
  });
69
+ if (markdownFiles.length === 0) {
70
+ logger_1.default.warn `No markdown files found in siteDir path=${siteDir} for patterns: ${patterns}`;
71
+ return;
72
+ }
41
73
  const result = await Promise.all(markdownFiles.map((p) => transformMarkdownFile(p, options)));
42
74
  const pathsModified = result.filter(Boolean);
43
75
  if (pathsModified.length) {
44
76
  logger_1.default.success `Heading ids added to Markdown files (number=${`${pathsModified.length}/${markdownFiles.length}`} files): ${pathsModified}`;
45
77
  }
46
78
  else {
47
- logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs. If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.`;
79
+ logger_1.default.warn `number=${markdownFiles.length} Markdown files already have explicit heading IDs.
80
+ If you intend to overwrite the existing heading IDs, use the code=${'--overwrite'} option.
81
+ If you intend to change their heading ID syntax, use the code=${'--migrate'} option.`;
48
82
  }
49
83
  }
@@ -118,24 +118,6 @@ async function createBaseConfig({ props, isServer, minify, faster, configureWebp
118
118
  buildDependencies: getCacheBuildDependencies(),
119
119
  };
120
120
  }
121
- if (process.env.DISABLE_RSPACK_INCREMENTAL) {
122
- // Enabled by default since Rspack 1.4
123
- console.log('Rspack incremental disabled');
124
- experiments.incremental = false;
125
- }
126
- // See https://rspack.rs/blog/announcing-1-5#barrel-file-optimization
127
- if (process.env.DISABLE_RSPACK_LAZY_BARREL) {
128
- console.log('Rspack lazyBarrel disabled');
129
- experiments.lazyBarrel = false;
130
- }
131
- else {
132
- // TODO remove after we upgrade to Rspack 1.6+
133
- // Enabled by default for Rspack >= 1.6
134
- experiments.lazyBarrel = true;
135
- }
136
- // TODO re-enable later, there's an Rspack performance issue
137
- // see https://github.com/facebook/docusaurus/pull/11178
138
- experiments.parallelCodeSplitting = false;
139
121
  return experiments;
140
122
  }
141
123
  return undefined;
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.9.2-canary-6495",
4
+ "version": "3.9.2-canary-6526",
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.9.2-canary-6495",
37
- "@docusaurus/bundler": "3.9.2-canary-6495",
38
- "@docusaurus/logger": "3.9.2-canary-6495",
39
- "@docusaurus/mdx-loader": "3.9.2-canary-6495",
40
- "@docusaurus/utils": "3.9.2-canary-6495",
41
- "@docusaurus/utils-common": "3.9.2-canary-6495",
42
- "@docusaurus/utils-validation": "3.9.2-canary-6495",
36
+ "@docusaurus/babel": "3.9.2-canary-6526",
37
+ "@docusaurus/bundler": "3.9.2-canary-6526",
38
+ "@docusaurus/logger": "3.9.2-canary-6526",
39
+ "@docusaurus/mdx-loader": "3.9.2-canary-6526",
40
+ "@docusaurus/utils": "3.9.2-canary-6526",
41
+ "@docusaurus/utils-common": "3.9.2-canary-6526",
42
+ "@docusaurus/utils-validation": "3.9.2-canary-6526",
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.9.2-canary-6495",
81
- "@docusaurus/types": "3.9.2-canary-6495",
80
+ "@docusaurus/module-type-aliases": "3.9.2-canary-6526",
81
+ "@docusaurus/types": "3.9.2-canary-6526",
82
82
  "@total-typescript/shoehorn": "^0.1.2",
83
83
  "@types/detect-port": "^1.3.3",
84
84
  "@types/react-dom": "^19.2.3",
@@ -97,5 +97,5 @@
97
97
  "engines": {
98
98
  "node": ">=20.0"
99
99
  },
100
- "gitHead": "fb9b28015f40d530ceb623dc486a5b8f48902ca0"
100
+ "gitHead": "a37ae138931cb80b31664f86a34f97671c00e409"
101
101
  }