dumi 2.3.0-beta.7 → 2.3.0-beta.8

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.
Files changed (40) hide show
  1. package/compiled/crates/swc_plugin_react_demo.wasm +0 -0
  2. package/dist/assetParsers/BaseParser.d.ts +55 -0
  3. package/dist/assetParsers/BaseParser.js +126 -0
  4. package/dist/assetParsers/atom.d.ts +18 -27
  5. package/dist/assetParsers/atom.js +84 -110
  6. package/dist/assetParsers/block.d.ts +2 -0
  7. package/dist/assetParsers/block.js +29 -16
  8. package/dist/assetParsers/utils.d.ts +79 -0
  9. package/dist/assetParsers/utils.js +112 -0
  10. package/dist/client/pages/Demo/index.js +11 -5
  11. package/dist/client/theme-api/DumiDemo/index.js +12 -4
  12. package/dist/client/theme-api/context.d.ts +1 -2
  13. package/dist/client/theme-api/index.d.ts +1 -1
  14. package/dist/client/theme-api/types.d.ts +12 -5
  15. package/dist/client/theme-api/useLiveDemo.js +114 -46
  16. package/dist/client/theme-api/useRenderer.d.ts +5 -0
  17. package/dist/client/theme-api/useRenderer.js +88 -0
  18. package/dist/constants.d.ts +2 -0
  19. package/dist/constants.js +13 -0
  20. package/dist/features/compile/index.js +15 -13
  21. package/dist/features/parser.js +9 -5
  22. package/dist/index.d.ts +3 -2
  23. package/dist/index.js +3 -0
  24. package/dist/loaders/markdown/index.js +24 -5
  25. package/dist/loaders/markdown/transformer/index.d.ts +11 -2
  26. package/dist/loaders/markdown/transformer/index.js +3 -0
  27. package/dist/loaders/markdown/transformer/rehypeDemo.js +22 -7
  28. package/dist/techStacks/react.js +6 -23
  29. package/dist/techStacks/utils.d.ts +18 -0
  30. package/dist/techStacks/utils.js +85 -0
  31. package/dist/types.d.ts +26 -3
  32. package/dist/utils.d.ts +2 -1
  33. package/dist/utils.js +2 -2
  34. package/package.json +7 -3
  35. package/tech-stack-utils.d.ts +12 -0
  36. package/tech-stack-utils.js +9 -0
  37. package/theme-default/builtins/API/index.d.ts +1 -0
  38. package/theme-default/builtins/API/index.js +12 -6
  39. package/theme-default/builtins/Previewer/index.less +1 -0
  40. package/theme-default/builtins/SourceCode/index.js +3 -2
@@ -0,0 +1,55 @@
1
+ import type { AtomComponentAsset, AtomFunctionAsset } from 'dumi-assets-types';
2
+ import { chokidar } from 'umi/plugin-utils';
3
+ export interface IPatchFile {
4
+ event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir';
5
+ fileName: string;
6
+ }
7
+ export interface IAtomAssetsParserResult {
8
+ components: Record<string, AtomComponentAsset>;
9
+ functions: Record<string, AtomFunctionAsset>;
10
+ }
11
+ /**
12
+ * The parsing and extraction of language metadata should be implemented separately
13
+ */
14
+ export interface ILanguageMetaParser {
15
+ patch(file: IPatchFile): void;
16
+ parse(): Promise<IAtomAssetsParserResult>;
17
+ destroy(): Promise<void>;
18
+ }
19
+ export interface IHandleWatcherArgs {
20
+ patch: ILanguageMetaParser['patch'];
21
+ parse: () => void;
22
+ watchArgs: {
23
+ paths: string | string[];
24
+ options: chokidar.WatchOptions;
25
+ };
26
+ }
27
+ export interface IBaseAtomAssetsParserParams<T> {
28
+ entryFile: string;
29
+ resolveDir: string;
30
+ parser: T;
31
+ handleWatcher?: (watcher: chokidar.FSWatcher, params: IHandleWatcherArgs) => chokidar.FSWatcher;
32
+ watchOptions?: chokidar.WatchOptions;
33
+ }
34
+ export declare class BaseAtomAssetsParser<T extends ILanguageMetaParser = ILanguageMetaParser> {
35
+ private watchArgs;
36
+ private watcher;
37
+ private handleWatcher?;
38
+ private entryDir;
39
+ private resolveDir;
40
+ private readonly parser;
41
+ private isParsing;
42
+ private parseDeferrer;
43
+ private cbs;
44
+ constructor(opts: IBaseAtomAssetsParserParams<T>);
45
+ parse(): Promise<IAtomAssetsParserResult>;
46
+ watch(cb: (data: IAtomAssetsParserResult) => void): void;
47
+ unwatch(cb: (data: IAtomAssetsParserResult) => void): void;
48
+ patchWatchArgs(handler: (args: BaseAtomAssetsParser<T>['watchArgs']) => BaseAtomAssetsParser<T>['watchArgs']): void;
49
+ getWatchArgs(): {
50
+ paths: string | string[];
51
+ options: chokidar.WatchOptions;
52
+ };
53
+ destroyWorker(): Promise<void>;
54
+ }
55
+ export type IAtomAssetsParser = InstanceType<typeof BaseAtomAssetsParser>;
@@ -0,0 +1,126 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/assetParsers/BaseParser.ts
30
+ var BaseParser_exports = {};
31
+ __export(BaseParser_exports, {
32
+ BaseAtomAssetsParser: () => BaseAtomAssetsParser
33
+ });
34
+ module.exports = __toCommonJS(BaseParser_exports);
35
+ var import_path = __toESM(require("path"));
36
+ var import_plugin_utils = require("umi/plugin-utils");
37
+ var BaseAtomAssetsParser = class {
38
+ constructor(opts) {
39
+ this.watcher = null;
40
+ this.isParsing = false;
41
+ this.parseDeferrer = null;
42
+ this.cbs = [];
43
+ const { entryFile, resolveDir, watchOptions, parser, handleWatcher } = opts;
44
+ this.resolveDir = resolveDir;
45
+ const absEntryFile = import_path.default.resolve(resolveDir, entryFile);
46
+ this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(absEntryFile));
47
+ this.watchArgs = {
48
+ paths: this.entryDir,
49
+ options: {
50
+ cwd: this.resolveDir,
51
+ ignored: [
52
+ "**/.*",
53
+ "**/.*/**",
54
+ "**/_*",
55
+ "**/_*/**",
56
+ "**/*.{md,less,scss,sass,styl,css}"
57
+ ],
58
+ ignoreInitial: true,
59
+ ...watchOptions
60
+ }
61
+ };
62
+ this.handleWatcher = handleWatcher;
63
+ this.parser = parser;
64
+ }
65
+ async parse() {
66
+ if (!this.parseDeferrer) {
67
+ this.isParsing = true;
68
+ this.parseDeferrer = this.parser.parse().finally(() => {
69
+ this.isParsing = false;
70
+ });
71
+ }
72
+ return this.parseDeferrer;
73
+ }
74
+ watch(cb) {
75
+ this.cbs.push(cb);
76
+ if (!this.watcher && this.handleWatcher) {
77
+ const lazyParse = import_plugin_utils.lodash.debounce(() => {
78
+ this.parse().then((data) => this.cbs.forEach((cb2) => cb2(data))).catch((err) => {
79
+ import_plugin_utils.logger.error(err);
80
+ });
81
+ }, 100);
82
+ this.watcher = import_plugin_utils.chokidar.watch(
83
+ this.watchArgs.paths,
84
+ this.watchArgs.options
85
+ );
86
+ this.handleWatcher(this.watcher, {
87
+ parse: () => {
88
+ if (this.isParsing && this.parseDeferrer) {
89
+ this.parseDeferrer.finally(() => {
90
+ this.parseDeferrer = null;
91
+ lazyParse();
92
+ });
93
+ } else {
94
+ this.parseDeferrer = null;
95
+ lazyParse();
96
+ }
97
+ },
98
+ watchArgs: this.watchArgs,
99
+ patch: (file) => {
100
+ this.parser.patch(file);
101
+ }
102
+ });
103
+ lazyParse();
104
+ }
105
+ }
106
+ unwatch(cb) {
107
+ this.cbs.splice(this.cbs.indexOf(cb), 1);
108
+ }
109
+ patchWatchArgs(handler) {
110
+ this.watchArgs = handler(this.watchArgs);
111
+ }
112
+ getWatchArgs() {
113
+ return this.watchArgs;
114
+ }
115
+ async destroyWorker() {
116
+ if (this.parseDeferrer) {
117
+ await this.parseDeferrer;
118
+ this.parseDeferrer = null;
119
+ }
120
+ await this.parser.destroy();
121
+ }
122
+ };
123
+ // Annotate the CommonJS export names for ESM import in node:
124
+ 0 && (module.exports = {
125
+ BaseAtomAssetsParser
126
+ });
@@ -1,30 +1,21 @@
1
- import { AtomComponentAsset, AtomFunctionAsset } from 'dumi-assets-types';
2
- declare class AtomAssetsParser {
3
- private entryDir;
4
- private resolveDir;
5
- private unresolvedFiles;
1
+ import { BaseAtomAssetsParser, IAtomAssetsParserResult, ILanguageMetaParser, IPatchFile } from './BaseParser';
2
+ interface ParserParams {
3
+ entryFile: string;
4
+ resolveDir: string;
5
+ resolveFilter?: ReactMetaParser['resolveFilter'];
6
+ unpkgHost?: string;
7
+ parseOptions?: object;
8
+ }
9
+ declare class ReactMetaParser implements ILanguageMetaParser {
6
10
  private parser;
7
- private isParsing;
8
- private parseDeferrer;
9
- private watcher;
10
- private cbs;
11
11
  private resolveFilter;
12
- private watchArgs;
13
- constructor(opts: {
14
- entryFile: string;
15
- resolveDir: string;
16
- resolveFilter?: AtomAssetsParser['resolveFilter'];
17
- unpkgHost?: string;
18
- watch?: boolean;
19
- parseOptions?: object;
20
- });
21
- parse(): Promise<{
22
- components: Record<string, AtomComponentAsset>;
23
- functions: Record<string, AtomFunctionAsset>;
24
- }>;
25
- watch(cb: AtomAssetsParser['cbs'][number]): void;
26
- unwatch(cb: AtomAssetsParser['cbs'][number]): void;
27
- patchWatchArgs(handler: (args: AtomAssetsParser['watchArgs']) => AtomAssetsParser['watchArgs']): void;
28
- destroyWorker(): void;
12
+ private unresolvedFiles;
13
+ constructor(opts: ParserParams);
14
+ parse(): Promise<IAtomAssetsParserResult>;
15
+ destroy(): Promise<void>;
16
+ patch(file: IPatchFile): void;
17
+ }
18
+ declare class ReactAtomAssetsParser extends BaseAtomAssetsParser<ReactMetaParser> {
19
+ constructor(opts: ParserParams);
29
20
  }
30
- export default AtomAssetsParser;
21
+ export default ReactAtomAssetsParser;
@@ -36,132 +36,106 @@ var import_utils = require("../utils");
36
36
  var import_parser = require("dumi-afx-deps/compiled/parser");
37
37
  var import_path = __toESM(require("path"));
38
38
  var import_plugin_utils = require("umi/plugin-utils");
39
+ var import_BaseParser = require("./BaseParser");
39
40
  var MAX_PARSE_SIZE = 1024 * 512;
40
- var AtomAssetsParser = class {
41
+ var ReactMetaParser = class {
41
42
  constructor(opts) {
42
43
  this.unresolvedFiles = [];
43
- this.isParsing = false;
44
- this.watcher = null;
45
- this.cbs = [];
46
- const absEntryFile = import_path.default.resolve(opts.resolveDir, opts.entryFile);
47
- this.resolveDir = opts.resolveDir;
44
+ const { resolveDir, entryFile, parseOptions, unpkgHost } = opts;
45
+ const absEntryFile = import_path.default.resolve(resolveDir, entryFile);
48
46
  this.resolveFilter = opts.resolveFilter || (() => true);
49
- this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(absEntryFile));
50
47
  this.parser = new import_parser.SchemaParser({
51
48
  entryPath: absEntryFile,
52
- basePath: (0, import_utils.getProjectRoot)(opts.resolveDir),
53
- unPkgHost: opts.unpkgHost ?? "https://unpkg.com",
49
+ basePath: (0, import_utils.getProjectRoot)(resolveDir),
50
+ unPkgHost: unpkgHost ?? "https://unpkg.com",
54
51
  mode: "worker",
55
52
  // @ts-ignore
56
- parseOptions: opts.parseOptions
53
+ parseOptions
57
54
  });
58
- this.watchArgs = {
59
- paths: this.entryDir,
60
- options: {
61
- cwd: this.resolveDir,
62
- ignored: [
63
- "**/.*",
64
- "**/.*/**",
65
- "**/_*",
66
- "**/_*/**",
67
- "**/*.{md,less,scss,sass,styl,css}"
68
- ],
69
- ignoreInitial: true
70
- }
71
- };
72
55
  }
73
56
  async parse() {
74
- if (!this.parseDeferrer || this.unresolvedFiles.length && !this.isParsing) {
75
- this.isParsing = true;
76
- this.parseDeferrer = (async () => {
77
- await this.parser.patch(this.unresolvedFiles.splice(0));
78
- const resolver = new import_parser.SchemaResolver(await this.parser.parse(), {
79
- mode: "worker"
80
- });
81
- const result = {
82
- components: {},
83
- functions: {}
84
- };
85
- const fallbackProps = { type: "object", properties: {} };
86
- const fallbackSignature = { arguments: [] };
87
- const componentList = await resolver.componentList;
88
- const functionList = await resolver.functionList;
89
- for (const id of componentList) {
90
- const needResolve = this.resolveFilter({
91
- id,
92
- type: "COMPONENT",
93
- ids: componentList
94
- });
95
- let propsConfig = needResolve ? (await resolver.getComponent(id)).props : fallbackProps;
96
- const size = Buffer.byteLength(JSON.stringify(propsConfig));
97
- if (size > MAX_PARSE_SIZE) {
98
- propsConfig = fallbackProps;
99
- import_plugin_utils.logger.warn(
100
- `Parsed component ${id} props size ${size} exceeds 512KB, skip it.`
101
- );
102
- }
103
- result.components[id] = {
104
- type: "COMPONENT",
105
- id,
106
- title: id,
107
- propsConfig
108
- };
109
- }
110
- for (const id of functionList) {
111
- const needResolve = this.resolveFilter({
112
- id,
113
- type: "FUNCTION",
114
- ids: functionList
115
- });
116
- let signature = needResolve ? (await resolver.getFunction(id)).signature : fallbackSignature;
117
- const size = Buffer.byteLength(JSON.stringify(signature));
118
- if (size > MAX_PARSE_SIZE) {
119
- signature = fallbackSignature;
120
- import_plugin_utils.logger.warn(
121
- `Parsed function ${id} signature size ${size} exceeds 512KB, skip it.`
122
- );
123
- }
124
- result.functions[id] = {
125
- type: "FUNCTION",
126
- id,
127
- title: id,
128
- signature
129
- };
130
- }
131
- resolver.$$destroyWorker();
132
- this.isParsing = false;
133
- return result;
134
- })();
57
+ await this.parser.patch(this.unresolvedFiles.splice(0));
58
+ const resolver = new import_parser.SchemaResolver(await this.parser.parse(), {
59
+ mode: "worker"
60
+ });
61
+ const result = {
62
+ components: {},
63
+ functions: {}
64
+ };
65
+ const fallbackProps = { type: "object", properties: {} };
66
+ const fallbackSignature = { arguments: [] };
67
+ const componentList = await resolver.componentList;
68
+ const functionList = await resolver.functionList;
69
+ for (const id of componentList) {
70
+ const needResolve = this.resolveFilter({
71
+ id,
72
+ type: "COMPONENT",
73
+ ids: componentList
74
+ });
75
+ let propsConfig = needResolve ? (await resolver.getComponent(id)).props : fallbackProps;
76
+ const size = Buffer.byteLength(JSON.stringify(propsConfig));
77
+ if (size > MAX_PARSE_SIZE) {
78
+ propsConfig = fallbackProps;
79
+ import_plugin_utils.logger.warn(
80
+ `Parsed component ${id} props size ${size} exceeds 512KB, skip it.`
81
+ );
82
+ }
83
+ result.components[id] = {
84
+ type: "COMPONENT",
85
+ id,
86
+ title: id,
87
+ propsConfig
88
+ };
135
89
  }
136
- return this.parseDeferrer;
137
- }
138
- watch(cb) {
139
- this.cbs.push(cb);
140
- if (!this.watcher) {
141
- const lazyParse = import_plugin_utils.lodash.debounce(() => {
142
- this.parse().then((data) => this.cbs.forEach((cb2) => cb2(data)));
143
- }, 100);
144
- this.watcher = import_plugin_utils.chokidar.watch(this.watchArgs.paths, this.watchArgs.options).on("all", (ev, file) => {
145
- if (["add", "change"].includes(ev) && /((?<!\.d)\.ts|\.(jsx?|tsx))$/.test(file)) {
146
- this.unresolvedFiles.push(import_path.default.join(this.watchArgs.options.cwd, file));
147
- lazyParse();
148
- }
90
+ for (const id of functionList) {
91
+ const needResolve = this.resolveFilter({
92
+ id,
93
+ type: "FUNCTION",
94
+ ids: functionList
149
95
  });
150
- lazyParse();
96
+ let signature = needResolve ? (await resolver.getFunction(id)).signature : fallbackSignature;
97
+ const size = Buffer.byteLength(JSON.stringify(signature));
98
+ if (size > MAX_PARSE_SIZE) {
99
+ signature = fallbackSignature;
100
+ import_plugin_utils.logger.warn(
101
+ `Parsed function ${id} signature size ${size} exceeds 512KB, skip it.`
102
+ );
103
+ }
104
+ result.functions[id] = {
105
+ type: "FUNCTION",
106
+ id,
107
+ title: id,
108
+ signature
109
+ };
151
110
  }
111
+ resolver.$$destroyWorker();
112
+ return result;
152
113
  }
153
- unwatch(cb) {
154
- this.cbs.splice(this.cbs.indexOf(cb), 1);
114
+ destroy() {
115
+ return this.parser.$$destroyWorker();
155
116
  }
156
- patchWatchArgs(handler) {
157
- this.watchArgs = handler(this.watchArgs);
117
+ patch(file) {
118
+ this.unresolvedFiles.push(file.fileName);
158
119
  }
159
- destroyWorker() {
160
- if (this.parseDeferrer) {
161
- this.parseDeferrer.finally(() => this.parser.$$destroyWorker());
162
- } else {
163
- this.parser.$$destroyWorker();
164
- }
120
+ };
121
+ var ReactAtomAssetsParser = class extends import_BaseParser.BaseAtomAssetsParser {
122
+ constructor(opts) {
123
+ super({
124
+ ...opts,
125
+ parser: new ReactMetaParser(opts),
126
+ handleWatcher: (watcher, { parse, patch, watchArgs }) => {
127
+ return watcher.on("all", (ev, file) => {
128
+ if (["add", "change"].includes(ev) && /((?<!\.d)\.ts|\.(jsx?|tsx))$/.test(file)) {
129
+ const cwd = watchArgs.options.cwd;
130
+ patch({
131
+ event: ev,
132
+ fileName: import_path.default.join(cwd, file)
133
+ });
134
+ parse();
135
+ }
136
+ });
137
+ }
138
+ });
165
139
  }
166
140
  };
167
- var atom_default = AtomAssetsParser;
141
+ var atom_default = ReactAtomAssetsParser;
@@ -1,6 +1,7 @@
1
1
  import { parseCodeFrontmatter } from "../utils";
2
2
  import type { ExampleBlockAsset } from 'dumi-assets-types';
3
3
  import type { sync } from 'enhanced-resolve';
4
+ import { IDumiTechStack } from '../types';
4
5
  export interface IParsedBlockAsset {
5
6
  asset: ExampleBlockAsset;
6
7
  /**
@@ -18,5 +19,6 @@ declare function parseBlockAsset(opts: {
18
19
  refAtomIds: string[];
19
20
  entryPointCode?: string;
20
21
  resolver: typeof sync;
22
+ techStack: IDumiTechStack;
21
23
  }): Promise<IParsedBlockAsset>;
22
24
  export default parseBlockAsset;
@@ -38,12 +38,14 @@ var import_assert = __toESM(require("assert"));
38
38
  var import_fs = __toESM(require("fs"));
39
39
  var import_path = __toESM(require("path"));
40
40
  var import_plugin_utils = require("umi/plugin-utils");
41
+ var import_constants = require("../constants");
41
42
  async function parseBlockAsset(opts) {
42
43
  const asset = {
43
44
  type: "BLOCK",
44
45
  id: opts.id,
45
46
  refAtomIds: opts.refAtomIds,
46
- dependencies: {}
47
+ dependencies: {},
48
+ entry: ""
47
49
  };
48
50
  const result = {
49
51
  asset,
@@ -95,34 +97,45 @@ async function parseBlockAsset(opts) {
95
97
  };
96
98
  });
97
99
  builder.onLoad({ filter: /.*/ }, (args) => {
98
- const ext = import_path.default.extname(args.path);
99
- const isModule = [".js", ".jsx", ".ts", ".tsx"].includes(ext);
100
- const isPlainText = [
101
- ".css",
102
- ".less",
103
- ".sass",
104
- ".scss",
105
- ".styl",
106
- ".json"
107
- ].includes(ext);
100
+ let ext = import_path.default.extname(args.path);
101
+ const techStack = opts.techStack;
108
102
  const isEntryPoint = args.pluginData.kind === "entry-point";
109
103
  const filename = `${isEntryPoint ? "index" : (0, import_plugin_utils.winPath)(
110
104
  import_path.default.format({
111
105
  ...import_path.default.parse(args.pluginData.source),
106
+ base: "",
112
107
  ext: ""
113
108
  })
114
109
  )}${ext}`;
110
+ let entryPointCode = opts.entryPointCode;
111
+ let contents = void 0;
112
+ if (techStack.onBlockLoad) {
113
+ const result2 = techStack.onBlockLoad({
114
+ filename,
115
+ entryPointCode: entryPointCode ?? (entryPointCode = import_fs.default.readFileSync(
116
+ args.path,
117
+ "utf-8"
118
+ )),
119
+ ...args
120
+ });
121
+ if (result2) {
122
+ ext = `.${result2.type}`;
123
+ contents = result2.content;
124
+ }
125
+ }
126
+ let isModule = import_constants.DEFAULT_DEMO_MODULE_EXTENSIONS.includes(ext);
127
+ let isPlainText = import_constants.DEFAULT_DEMO_PLAIN_TEXT_EXTENSIONS.includes(ext);
115
128
  if (isModule || isPlainText) {
116
129
  asset.dependencies[filename] = {
117
130
  type: "FILE",
118
131
  value: opts.entryPointCode ?? import_fs.default.readFileSync(args.path, "utf-8")
119
132
  };
133
+ const file = asset.dependencies[filename];
120
134
  if (isEntryPoint) {
121
- const { code, frontmatter } = (0, import_utils.parseCodeFrontmatter)(
122
- asset.dependencies[filename].value
123
- );
135
+ const { code, frontmatter } = (0, import_utils.parseCodeFrontmatter)(file.value);
136
+ asset.entry = filename;
124
137
  if (frontmatter) {
125
- asset.dependencies[filename].value = code;
138
+ file.value = code;
126
139
  result.frontmatter = frontmatter;
127
140
  ["description", "title", "snapshot", "keywords"].forEach(
128
141
  (key) => {
@@ -136,7 +149,7 @@ async function parseBlockAsset(opts) {
136
149
  }
137
150
  return {
138
151
  // only continue to load for module files
139
- contents: isModule ? asset.dependencies[filename].value : "",
152
+ contents: isModule ? contents ?? file.value : "",
140
153
  loader: isModule ? ext.slice(1) : "text"
141
154
  };
142
155
  }
@@ -0,0 +1,79 @@
1
+ import { BaseAtomAssetsParser, IBaseAtomAssetsParserParams, ILanguageMetaParser } from './BaseParser';
2
+ /**
3
+ * Only expose these methods to avoid all properties being proxied
4
+ * @param ClassConstructor The Class to be processed
5
+ * @param publicMethods accessible Class methods
6
+ * @returns processed Class
7
+ */
8
+ export declare function createExposedClass<T extends {
9
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
10
+ }>(ClassConstructor: T, publicMethods?: string[]): {
11
+ new (...params: ConstructorParameters<T>): {};
12
+ };
13
+ /**
14
+ * Create Class that can execute across threads
15
+ * @param filename Child thread running script path
16
+ * @param ClassConstructor Class that require remote execution
17
+ * @param opts
18
+ * @returns Remote Class, all its methods are asynchronous
19
+ */
20
+ export declare function createRemoteClass<T extends {
21
+ new (...args: ConstructorParameters<T>): InstanceType<T>;
22
+ }>(filename: string, ClassConstructor: T, opts?: {
23
+ destroyMethod: string;
24
+ publicMethods?: string[];
25
+ }): T;
26
+ interface ICreateApiParserOptions<S, C> {
27
+ /**
28
+ * The full file name (absolute path) of the file where `parseWorker` is located
29
+ */
30
+ filename: string;
31
+ /**
32
+ * Parsing class working in worker_thead
33
+ */
34
+ worker: S;
35
+ /**
36
+ * Main thread side work, mainly to detect file changes
37
+ */
38
+ parseOptions?: C;
39
+ }
40
+ export interface IBaseApiParserOptions {
41
+ entryFile: string;
42
+ resolveDir: string;
43
+ }
44
+ /**
45
+ * Can be used to override apiParser
46
+ * @param options
47
+ * @returns A function that returns a Parser instance
48
+ * @example
49
+ * ```ts
50
+ * interface ParserOptions extends BaseApiParserOptions {
51
+ * // other props...
52
+ * }
53
+ * const Parser = createApiParser({
54
+ * filename: __filename,
55
+ * worker: (class {
56
+ * constructor(opts: ParserOptions) {}
57
+ * patch () {}
58
+ * async parse () {
59
+ * return {
60
+ * components: {},
61
+ * functions: {}
62
+ * };
63
+ * }
64
+ * async destroy () {}
65
+ * }),
66
+ * parserOptions: {
67
+ * handleWatcher(watcher, { parse, patch }) {
68
+ * return watcher.on('all', (ev, file) => {
69
+ * // You can perform patch and parse operations based on file changes.
70
+ * // patch will transfer the corresponding file to the parseWorker,
71
+ * // and parse will instruct the parseWorker to parse according to updated files.
72
+ * });
73
+ * },
74
+ * },
75
+ * });
76
+ * ```
77
+ */
78
+ export declare function createApiParser<P extends new (...args: ConstructorParameters<P>) => InstanceType<P> & ILanguageMetaParser>(options: ICreateApiParserOptions<P, Partial<IBaseAtomAssetsParserParams<P>>>): (...args: ConstructorParameters<P>) => BaseAtomAssetsParser<ILanguageMetaParser>;
79
+ export {};