@mbler/mcx-core 0.1.3-rc.5 → 0.1.3-rc.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.
package/README.md CHANGED
@@ -22,8 +22,8 @@ pnpm add -D @mbler/mcx-core
22
22
  ```
23
23
 
24
24
  ## Usage
25
-
26
- Add the plugin to your Rollup or Rolldown config:
25
+ 1. Use manually
26
+ Add the plugin to your Rollup or Rolldown/Rollup config:
27
27
 
28
28
  ```ts
29
29
  import { rollupPlugin } from '@mbler/mcx-core'
@@ -32,7 +32,10 @@ export default {
32
32
  plugins: [rollupPlugin({ moduleDir: './modules', tsconfigPath: './tsconfig.json' })],
33
33
  }
34
34
  ```
35
-
35
+ 2. Use with [mbler](https://npmjs.com/package/mbler)
36
+ ```bash
37
+ pnpm create mbler
38
+ ```
36
39
  For full documentation, visit the **[Docs](https://mbler-docs.ruanhor.dpdns.org/guide/mcx)**.
37
40
 
38
41
  ## License
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as t from "@babel/types";
2
2
  import { ArgumentPlaceholder, CallExpression, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, Expression, ImportDeclaration, SpreadElement } from "@babel/types";
3
3
  import * as Parser from "@babel/parser";
4
- import { Plugin, TransformPluginContext } from "rollup";
4
+ import * as vm from "node:vm";
5
5
  import { CompileOpt, CompileOpt as CompileOpt$1 } from "@mbler/mcx-types";
6
+ import { Plugin } from "rollup";
6
7
  import { Plugin as Plugin$1 } from "rolldown";
7
8
  import { EnchantableSlot, EntityComponentOptions, FoodEffect, ItemComponentOptions, ParticleType, Rarity, SoundEvent } from "@mbler/mcx-component";
8
9
 
@@ -75,8 +76,21 @@ declare class MCXCompileData {
75
76
  constructor(raw: ParsedTagNode[], JSIR: JsCompileData, strLoc: MCXstructureLoc);
76
77
  setFilePath(dir: string): void;
77
78
  }
79
+ //#endregion
80
+ //#region src/mcx-component/moduleResolver.d.ts
81
+ type FileTransformFn = (code: string, id: string) => string;
82
+ declare class ModuleResolver {
83
+ private cache;
84
+ private loadingModules;
85
+ private transformFile;
86
+ constructor(cache: Map<string, string>, transformFile: FileTransformFn);
87
+ getCache(): Map<string, string>;
88
+ clear(): void;
89
+ ensureModule(specifier: string, importerPath: string, context: vm.Context, nativeRequire?: (id: string) => unknown): unknown;
90
+ private executeInContext;
91
+ }
78
92
  declare namespace types_d_exports$1 {
79
- export { AttributeMap, BaseToken, CommentToken, ContentToken, JsType, MCXLoc, MCXPosition, ParseReadFileOpt, ParsedCommentNode, ParsedTagContentNode, ParsedTagNode, PropNode, PropValue, ReadFileOpt, TagEndToken, TagToken, Token, TokenType, TypeVerifyBody, mcxType, transformCtx, transformParseCtx };
93
+ export { AttributeMap, BaseToken, CommentToken, ContentToken, JsType, MCXLoc, MCXPosition, McxPluginContext, ParseReadFileOpt, ParsedCommentNode, ParsedTagContentNode, ParsedTagNode, PropNode, PropValue, ReadFileOpt, TagEndToken, TagToken, Token, TokenType, TypeVerifyBody, mcxType, transformCtx, transformParseCtx };
80
94
  }
81
95
  interface BaseToken {
82
96
  data: string;
@@ -143,8 +157,20 @@ interface ParseReadFileOpt {
143
157
  }
144
158
  type ReadFileOpt = Partial<ParseReadFileOpt>;
145
159
  type mcxType = 'component' | 'event' | 'app' | 'ui' | 'form';
160
+ interface McxPluginContext {
161
+ error: (err: string | {
162
+ message: string;
163
+ [key: string]: unknown;
164
+ }, extra?: number | {
165
+ column: number;
166
+ line: number;
167
+ }) => void;
168
+ warn: (warning: string | {
169
+ message: string;
170
+ }) => void;
171
+ }
146
172
  interface transformCtx {
147
- rollupContext: TransformPluginContext;
173
+ rollupContext: McxPluginContext;
148
174
  compiledCode: MCXCompileData;
149
175
  cache: Map<string, MCXCompileData>;
150
176
  currentId: string;
@@ -161,6 +187,7 @@ interface transformCtx {
161
187
  behavior: string;
162
188
  resources: string;
163
189
  };
190
+ moduleResolver?: ModuleResolver;
164
191
  }
165
192
  interface transformParseCtx {
166
193
  prop: t.ObjectProperty[];
@@ -331,7 +358,8 @@ declare class RunScript {
331
358
  private _context;
332
359
  private _module;
333
360
  private _pluginContext;
334
- constructor(filePath?: string, module?: 'esm' | 'cjs', pluginContext?: Record<string, string | null | boolean | number> | undefined);
361
+ private _moduleResolver;
362
+ constructor(filePath?: string, module?: 'esm' | 'cjs', pluginContext?: Record<string, string | null | boolean | number> | undefined, moduleResolver?: ModuleResolver);
335
363
  /**
336
364
  * run code in nodejs vm
337
365
  * @param code {string} exetuce code
@@ -392,7 +420,7 @@ declare function generateItemTextureJson(output: {
392
420
  declare function compileComponent(compiledCode: MCXCompileData, ctx: transformCtx): Promise<void>;
393
421
  //#endregion
394
422
  //#region src/transforms/index.d.ts
395
- declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt, output: transformCtx['output']): Promise<string>;
423
+ declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: McxPluginContext, opt: CompileOpt, output: transformCtx['output'], moduleResolver?: ModuleResolver): Promise<string>;
396
424
  //#endregion
397
425
  export { _default as AST, types_d_exports as ComponentType, types_d_exports$1 as PubType, index_d_exports as compile_component, index_d_exports$1 as compiler, rolldownPlugin, rollupPlugin, transform, Utils as utils };
398
426
  //# sourceMappingURL=index.d.ts.map