@alauda/doom 0.6.9 → 0.6.12

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.
@@ -2,10 +2,8 @@ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { nodeTypes } from '@mdx-js/mdx';
4
4
  import { addLeadingSlash, addTrailingSlash, normalizeSlash, removeLeadingSlash, removeTrailingSlash, } from '@rspress/core';
5
- import { pluginPreview } from '@rspress/plugin-preview';
6
5
  import { logger } from '@rspress/shared/logger';
7
6
  import { transformerMetaHighlight, transformerMetaWordHighlight, transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape, } from '@shikijs/transformers';
8
- import getPort from 'get-port';
9
7
  import rehypeRaw from 'rehype-raw';
10
8
  import { apiPlugin, autoSidebarPlugin, createTransformerCallouts, globalPlugin, shikiPlugin, } from '../plugins/index.js';
11
9
  import { normalizeVersion } from '../shared/index.js';
@@ -21,7 +19,7 @@ const zhLocaleConfig = {
21
19
  prevPageText: '上一页',
22
20
  nextPageText: '下一页',
23
21
  };
24
- const getCommonConfig = async (config, cliRoot, prefix, configFilePath, version, force) => {
22
+ const getCommonConfig = (config, cliRoot, prefix, configFilePath, version, force) => {
25
23
  const fallbackToZh = 'lang' in config && config.lang == null;
26
24
  const root = resolveDocRoot(CWD, cliRoot, config.root);
27
25
  let base = addLeadingSlash(config.base || '/');
@@ -67,12 +65,6 @@ const getCommonConfig = async (config, cliRoot, prefix, configFilePath, version,
67
65
  }),
68
66
  },
69
67
  plugins: [
70
- pluginPreview({
71
- iframeOptions: {
72
- devPort: await getPort({ port: 7891 }),
73
- },
74
- defaultRenderMode: 'pure',
75
- }),
76
68
  apiPlugin(config.api),
77
69
  autoSidebarPlugin(config.sidebar),
78
70
  globalPlugin({
@@ -174,7 +166,7 @@ export async function loadConfig(root, configFile, prefix, version, force) {
174
166
  }
175
167
  }
176
168
  const normalizedVersion = normalizeVersion(version);
177
- const commonConfig = await getCommonConfig(config, root, prefix, configFilePath, normalizedVersion, force);
169
+ const commonConfig = getCommonConfig(config, root, prefix, configFilePath, normalizedVersion, force);
178
170
  const mergedConfig = mergeRsbuildConfig(commonConfig, config, {
179
171
  base: commonConfig.base,
180
172
  root: commonConfig.root,
package/lib/cli/new.js CHANGED
@@ -79,7 +79,7 @@ const resolveScaffoldings = async (name, force) => {
79
79
  for (const branch of branches) {
80
80
  if (branch === currentBranch) {
81
81
  logger.info(`Pulling latest changes from branch \`${cyan(branch)}\`...`);
82
- await git.pull([...options, '--rebase']);
82
+ await git.pull([...options, '--rebase', '--allow-unrelated-histories']);
83
83
  }
84
84
  else {
85
85
  logger.info(`Switching to branch \`${cyan(branch)}\`...`);
@@ -169,7 +169,9 @@ export const newCommand = new Command('new')
169
169
  });
170
170
  const files = new Set(dirents
171
171
  .filter((d) => d.isFile())
172
- .map((d) => path.relative(source, path.resolve(d.parentPath, d.name))));
172
+ .map((d) => path.relative(source, path.resolve(d.parentPath ||
173
+ // eslint-disable-next-line @typescript-eslint/no-deprecated
174
+ d.path, d.name))));
173
175
  for (const matcher of layout.matchers || []) {
174
176
  const matched = await glob(matcher.match.map((m) => render(m, { parameters })), { cwd: source });
175
177
  for (const file of matched) {
@@ -1,7 +1,6 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import { logger } from '@rspress/shared/logger';
3
3
  import { MD_RELEASE_COMMENT_PATTERN, MDX_RELEASE_COMMENT_PATTERN, refCache, releaseCache, remarkReplace, } from './remark-replace.js';
4
- import { remarkPluginToc } from './remark-toc.js';
5
4
  import { mdProcessor, mdxProcessor, normalizeReferenceItems } from './utils.js';
6
5
  export const referencePlugin = ({ root, lang, localBasePath, items = [], force, releaseNotes, }) => {
7
6
  const normalizedItems = normalizeReferenceItems(items);
@@ -38,17 +37,14 @@ export const referencePlugin = ({ root, lang, localBasePath, items = [], force,
38
37
  return;
39
38
  }
40
39
  const processor = isMdx ? mdxProcessor : mdProcessor;
41
- const compiler = processor()
42
- .data('pageMeta', {})
43
- .use(remarkReplace, {
40
+ const compiler = processor().data('pageMeta', {}).use(remarkReplace, {
44
41
  lang,
45
42
  localBasePath,
46
43
  root,
47
44
  items: normalizedItems,
48
45
  force,
49
46
  releaseNotes,
50
- })
51
- .use(remarkPluginToc);
47
+ });
52
48
  const vfile = await compiler.process({
53
49
  path: filepath,
54
50
  value: content,
@@ -56,9 +52,6 @@ export const referencePlugin = ({ root, lang, localBasePath, items = [], force,
56
52
  original: true,
57
53
  },
58
54
  });
59
- const { toc, title } = compiler.data('pageMeta');
60
- page.title = title;
61
- page.toc = toc;
62
55
  page.content = vfile.toString();
63
56
  }));
64
57
  for (const result of results) {
@@ -0,0 +1,17 @@
1
+ import type { Root } from 'mdast';
2
+ export interface TocItem {
3
+ id: string;
4
+ text: string;
5
+ depth: number;
6
+ index: number;
7
+ }
8
+ export interface PageMeta {
9
+ toc: TocItem[];
10
+ title: string;
11
+ headingTitle: string;
12
+ frontmatter?: Record<string, unknown>;
13
+ }
14
+ export declare const parseToc: (tree: Root, allDepths?: boolean) => {
15
+ title: string;
16
+ toc: TocItem[];
17
+ };
@@ -0,0 +1,51 @@
1
+ import Slugger from 'github-slugger';
2
+ import { visitChildren } from 'unist-util-visit-children';
3
+ import { extractTextAndId } from './utils.js';
4
+ export const parseToc = (tree, allDepths) => {
5
+ let title = '';
6
+ const toc = [];
7
+ const slugger = new Slugger();
8
+ visitChildren((node, index) => {
9
+ if (node.type !== 'heading' || !node.depth || !node.children) {
10
+ return;
11
+ }
12
+ // Collect h1 ~ h4 by default
13
+ if (allDepths || node.depth < 5) {
14
+ let customId = '';
15
+ const text = node.children
16
+ .map((child) => {
17
+ if (child.type === 'link') {
18
+ return child.children?.map((item) => item.value).join('');
19
+ }
20
+ if (child.type === 'strong') {
21
+ return `**${child.children?.map((item) => item.value).join('')}**`;
22
+ }
23
+ if (child.type === 'text') {
24
+ const [textPart, idPart] = extractTextAndId(child.value);
25
+ customId = idPart;
26
+ return textPart;
27
+ }
28
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
29
+ if (child.type === 'inlineCode') {
30
+ return `\`${child.value}\``;
31
+ }
32
+ return '';
33
+ })
34
+ .join('');
35
+ if (!allDepths && node.depth === 1) {
36
+ if (!title) {
37
+ title = text;
38
+ }
39
+ }
40
+ else {
41
+ const id = customId ? customId : slugger.slug(text);
42
+ const { depth } = node;
43
+ toc.push({ id, text, depth, index });
44
+ }
45
+ }
46
+ })(tree);
47
+ return {
48
+ title,
49
+ toc,
50
+ };
51
+ };
@@ -7,7 +7,7 @@ import { render } from 'ejs';
7
7
  import { simpleGit } from 'simple-git';
8
8
  import { parse, stringify } from 'yaml';
9
9
  import { cyan, red } from 'yoctocolors';
10
- import { parseToc } from './remark-toc.js';
10
+ import { parseToc } from './parse-toc.js';
11
11
  import { getFrontmatterNode, mdProcessor, mdxProcessor } from './utils.js';
12
12
  const remotesFolder = path.resolve(os.homedir(), '.doom/remotes');
13
13
  export const refCache = new Map();
@@ -41,7 +41,13 @@ const resolveReference_ = async (localBasePath, items, refName, force) => {
41
41
  }
42
42
  if (force) {
43
43
  logger.info(`Pulling latest changes for \`${cyan(source.slug)}\`...`);
44
- await git.pull(['--depth', '1', '--force', '--rebase']);
44
+ await git.pull([
45
+ '--depth',
46
+ '1',
47
+ '--force',
48
+ '--rebase',
49
+ '--allow-unrelated-histories',
50
+ ]);
45
51
  }
46
52
  sourcePath = path.resolve(repoFolder, sourcePath);
47
53
  }
@@ -334,9 +340,13 @@ export const remarkReplace = function ({ lang, localBasePath, root, items, force
334
340
  if (checkContent) {
335
341
  const newContent = processor.stringify({
336
342
  ...ast,
337
- children: newContentChildren
338
- .flat()
339
- .filter((n) => n.type !== 'mdxjsEsm'),
343
+ children: newContentChildren.flat().filter((n) => {
344
+ if (n.type !== 'mdxjsEsm') {
345
+ return true;
346
+ }
347
+ const matched = n.value.match(/^import\b.+\bfrom\b\s+(['"])([^'"]+)\1$/);
348
+ return !matched?.[2] || !path.isAbsolute(matched[2]);
349
+ }),
340
350
  });
341
351
  if (content !== newContent) {
342
352
  await fs.writeFile(filepath, newContent);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "0.6.9",
3
+ "version": "0.6.12",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "packageManager": "yarn@4.5.0",
11
11
  "engines": {
12
- "node": ">=18.20.0 <20 || >=20.1.0"
12
+ "node": ">=18.17.0 <20 || >=20.1.0"
13
13
  },
14
14
  "bin": "lib/cli/index.js",
15
15
  "exports": {
@@ -41,14 +41,12 @@
41
41
  "@inquirer/prompts": "^7.2.1",
42
42
  "@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
43
43
  "@rspress/core": "1.39.3",
44
- "@rspress/plugin-preview": "1.39.3",
45
44
  "@shikijs/transformers": "^1.26.1",
46
45
  "chokidar": "^4.0.3",
47
46
  "clsx": "^2.1.1",
48
47
  "commander": "^12.1.0",
49
48
  "ejs": "^3.1.10",
50
49
  "es-toolkit": "^1.31.0",
51
- "get-port": "^7.1.0",
52
50
  "openapi-types": "^12.1.3",
53
51
  "react-markdown": "^8.0.7",
54
52
  "rehype-raw": "^6.1.1",