@mbler/mcx-core 0.0.8-rc.4 → 0.1.0
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/dist/index.d.ts +16 -4
- package/dist/index.js +53 -36
- package/dist/index.js.map +1 -1
- package/dist/types/compile-mcx/compiler/main.d.ts +6 -4
- package/dist/types/compile-mcx/index.d.ts +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/utils.d.ts +12 -2
- package/package.json +2 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { TransformPluginContext, Plugin } from 'rollup';
|
|
1
|
+
import { TransformPluginContext, Plugin as Plugin$1 } from 'rollup';
|
|
2
2
|
import * as t from '@babel/types';
|
|
3
3
|
import { Expression, CallExpression, SpreadElement, ArgumentPlaceholder, ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration, ExportDefaultDeclaration } from '@babel/types';
|
|
4
4
|
import { CompileOpt } from '@mbler/mcx-types';
|
|
5
|
+
import { Plugin } from 'rolldown';
|
|
5
6
|
import * as Parser from '@babel/parser';
|
|
6
7
|
|
|
7
8
|
interface callList {
|
|
@@ -216,7 +217,8 @@ declare const _default: {
|
|
|
216
217
|
prop: typeof PropParser;
|
|
217
218
|
};
|
|
218
219
|
|
|
219
|
-
declare function
|
|
220
|
+
declare function rollupPlugin(opt: CompileOpt, output: transformCtx['output']): Plugin$1;
|
|
221
|
+
declare function rolldownPlugin(opt: CompileOpt, output: transformCtx['output']): Plugin;
|
|
220
222
|
|
|
221
223
|
declare class McxUtlis {
|
|
222
224
|
/**
|
|
@@ -233,7 +235,17 @@ declare class McxUtlis {
|
|
|
233
235
|
*/
|
|
234
236
|
static readFile(filePath: string, opt?: ReadFileOpt): Promise<object | string>;
|
|
235
237
|
static sleep(time: number): Promise<void>;
|
|
236
|
-
static TypeVerify(obj:
|
|
238
|
+
static TypeVerify<T extends Record<string, any>, U extends TypeVerifyBody>(obj: T, types: U): obj is T & {
|
|
239
|
+
[P in keyof U]: {
|
|
240
|
+
boolean: boolean;
|
|
241
|
+
number: number;
|
|
242
|
+
string: string;
|
|
243
|
+
object: object;
|
|
244
|
+
function: Function;
|
|
245
|
+
bigint: bigint;
|
|
246
|
+
symbol: Symbol;
|
|
247
|
+
}[U[P]];
|
|
248
|
+
};
|
|
237
249
|
static AbsoluteJoin(baseDir: string, inputPath: string): string;
|
|
238
250
|
}
|
|
239
251
|
|
|
@@ -5099,4 +5111,4 @@ declare namespace index {
|
|
|
5099
5111
|
|
|
5100
5112
|
declare function transform(code: MCXCompileData, cache: Map<string, MCXCompileData>, id: string, context: TransformPluginContext, opt: CompileOpt, output: transformCtx["output"]): Promise<string>;
|
|
5101
5113
|
|
|
5102
|
-
export { _default as AST, BlockComponent, types as ComponentType, EntityComponent, GIFImageComponent, ItemComponent, JPGImageComponent, PNGImageComponent, types$1 as PUBTYPE, SVGImageComponent, index as compile_component, index$1 as compiler,
|
|
5114
|
+
export { _default as AST, BlockComponent, types as ComponentType, EntityComponent, GIFImageComponent, ItemComponent, JPGImageComponent, PNGImageComponent, types$1 as PUBTYPE, SVGImageComponent, index as compile_component, index$1 as compiler, rolldownPlugin, rollupPlugin, transform, McxUtlis as utils };
|
package/dist/index.js
CHANGED
|
@@ -1519,9 +1519,8 @@ class McxUtlis {
|
|
|
1519
1519
|
return opts.want === 'object' ? {} : '';
|
|
1520
1520
|
}
|
|
1521
1521
|
static sleep(time) {
|
|
1522
|
-
return new Promise(
|
|
1522
|
+
return new Promise(resolve => setTimeout(resolve, time));
|
|
1523
1523
|
}
|
|
1524
|
-
// 在运行时进行对象类型验证
|
|
1525
1524
|
static TypeVerify(obj, types) {
|
|
1526
1525
|
for (const item of Object.entries(types)) {
|
|
1527
1526
|
const [key, ShouldType] = item;
|
|
@@ -1531,9 +1530,9 @@ class McxUtlis {
|
|
|
1531
1530
|
return true;
|
|
1532
1531
|
}
|
|
1533
1532
|
static AbsoluteJoin(baseDir, inputPath) {
|
|
1534
|
-
return path__namespace.isAbsolute(inputPath)
|
|
1535
|
-
inputPath
|
|
1536
|
-
path__namespace.join(baseDir, inputPath);
|
|
1533
|
+
return path__namespace.isAbsolute(inputPath)
|
|
1534
|
+
? inputPath
|
|
1535
|
+
: path__namespace.join(baseDir, inputPath);
|
|
1537
1536
|
}
|
|
1538
1537
|
}
|
|
1539
1538
|
|
|
@@ -10986,13 +10985,13 @@ async function transform(code, cache, id, context, opt, output) {
|
|
|
10986
10985
|
return await _transform(transformContext);
|
|
10987
10986
|
}
|
|
10988
10987
|
|
|
10989
|
-
function
|
|
10988
|
+
function createMcxPlugin(opt, output) {
|
|
10990
10989
|
let cache = new Map();
|
|
10991
10990
|
let tsconfig;
|
|
10992
10991
|
try {
|
|
10993
|
-
const configResult = ts__namespace.readConfigFile(opt.tsconfigPath,
|
|
10992
|
+
const configResult = ts__namespace.readConfigFile(opt.tsconfigPath, path => {
|
|
10994
10993
|
try {
|
|
10995
|
-
return node_fs.readFileSync(path,
|
|
10994
|
+
return node_fs.readFileSync(path, 'utf-8');
|
|
10996
10995
|
}
|
|
10997
10996
|
catch (error) {
|
|
10998
10997
|
throw new Error(`Failed to read TypeScript config file at ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -11007,7 +11006,9 @@ function mcxPlugn(opt, output) {
|
|
|
11007
11006
|
// Parse the configuration with proper path resolution
|
|
11008
11007
|
const parsedConfig = ts__namespace.parseJsonConfigFileContent(configResult.config, ts__namespace.sys, path.dirname(opt.tsconfigPath), undefined, opt.tsconfigPath);
|
|
11009
11008
|
if (parsedConfig.errors.length > 0) {
|
|
11010
|
-
const errorMessages = parsedConfig.errors
|
|
11009
|
+
const errorMessages = parsedConfig.errors
|
|
11010
|
+
.map(err => err.messageText)
|
|
11011
|
+
.join('\n');
|
|
11011
11012
|
throw new Error(`TypeScript configuration parsing errors:\n${errorMessages}`);
|
|
11012
11013
|
}
|
|
11013
11014
|
tsconfig = parsedConfig;
|
|
@@ -11019,16 +11020,16 @@ function mcxPlugn(opt, output) {
|
|
|
11019
11020
|
tsconfig = {
|
|
11020
11021
|
options: {},
|
|
11021
11022
|
fileNames: [],
|
|
11022
|
-
errors: []
|
|
11023
|
+
errors: [],
|
|
11023
11024
|
};
|
|
11024
11025
|
}
|
|
11025
|
-
const resolveExtensions = [
|
|
11026
|
-
const indexExtensions = resolveExtensions.map(ext =>
|
|
11026
|
+
const resolveExtensions = ['', '.ts', '.mts', '.cts', '.js', '.mjs', '.cjs'];
|
|
11027
|
+
const indexExtensions = resolveExtensions.map(ext => '/index' + ext);
|
|
11027
11028
|
async function tryResolvePath(filePath) {
|
|
11028
11029
|
for (const idxExt of indexExtensions) {
|
|
11029
11030
|
try {
|
|
11030
11031
|
const fullPath = filePath + idxExt;
|
|
11031
|
-
await fs.readFile(fullPath,
|
|
11032
|
+
await fs.readFile(fullPath, 'utf-8');
|
|
11032
11033
|
return fullPath;
|
|
11033
11034
|
}
|
|
11034
11035
|
catch { }
|
|
@@ -11036,7 +11037,7 @@ function mcxPlugn(opt, output) {
|
|
|
11036
11037
|
for (const ext of resolveExtensions) {
|
|
11037
11038
|
try {
|
|
11038
11039
|
const fullPath = filePath + ext;
|
|
11039
|
-
await fs.readFile(fullPath,
|
|
11040
|
+
await fs.readFile(fullPath, 'utf-8');
|
|
11040
11041
|
return fullPath;
|
|
11041
11042
|
}
|
|
11042
11043
|
catch { }
|
|
@@ -11046,21 +11047,21 @@ function mcxPlugn(opt, output) {
|
|
|
11046
11047
|
async function resolvePackageExports(pkgDir, subPath, pkgJson) {
|
|
11047
11048
|
const exports$1 = pkgJson.exports;
|
|
11048
11049
|
if (exports$1) {
|
|
11049
|
-
const subImport = subPath.startsWith(
|
|
11050
|
-
if (typeof exports$1 ===
|
|
11050
|
+
const subImport = subPath.startsWith('./') ? subPath : `./${subPath}`;
|
|
11051
|
+
if (typeof exports$1 === 'object' && exports$1 !== null) {
|
|
11051
11052
|
if (exports$1[subImport]) {
|
|
11052
11053
|
const target = exports$1[subImport];
|
|
11053
|
-
if (typeof target ===
|
|
11054
|
+
if (typeof target === 'string') {
|
|
11054
11055
|
return path.join(pkgDir, target);
|
|
11055
11056
|
}
|
|
11056
|
-
else if (typeof target ===
|
|
11057
|
+
else if (typeof target === 'object' && target !== null) {
|
|
11057
11058
|
if (target.import) {
|
|
11058
11059
|
return path.join(pkgDir, target.import);
|
|
11059
11060
|
}
|
|
11060
11061
|
return path.join(pkgDir, target.default || Object.values(target)[0]);
|
|
11061
11062
|
}
|
|
11062
11063
|
}
|
|
11063
|
-
if (subImport.endsWith(
|
|
11064
|
+
if (subImport.endsWith('/') || subImport.endsWith('/*')) {
|
|
11064
11065
|
const dirMapping = subImport.slice(0, -1);
|
|
11065
11066
|
for (const [key, value] of Object.entries(exports$1)) {
|
|
11066
11067
|
if (key.startsWith(dirMapping) && key !== dirMapping) {
|
|
@@ -11070,17 +11071,17 @@ function mcxPlugn(opt, output) {
|
|
|
11070
11071
|
}
|
|
11071
11072
|
}
|
|
11072
11073
|
}
|
|
11073
|
-
else if (typeof exports$1 ===
|
|
11074
|
+
else if (typeof exports$1 === 'string') {
|
|
11074
11075
|
return path.join(pkgDir, exports$1);
|
|
11075
11076
|
}
|
|
11076
11077
|
}
|
|
11077
11078
|
return null;
|
|
11078
11079
|
}
|
|
11079
11080
|
return {
|
|
11080
|
-
name:
|
|
11081
|
+
name: 'mbler-mcx-core',
|
|
11081
11082
|
async resolveId(id, imp) {
|
|
11082
11083
|
const i = path.parse(id);
|
|
11083
|
-
if (i.dir.startsWith(
|
|
11084
|
+
if (i.dir.startsWith('.') || i.root) {
|
|
11084
11085
|
if (imp) {
|
|
11085
11086
|
const baseDir = path.dirname(imp);
|
|
11086
11087
|
const resolved = await tryResolvePath(path.join(baseDir, id));
|
|
@@ -11090,28 +11091,33 @@ function mcxPlugn(opt, output) {
|
|
|
11090
11091
|
return null;
|
|
11091
11092
|
}
|
|
11092
11093
|
else {
|
|
11093
|
-
const isScopedPackage = id.startsWith(
|
|
11094
|
-
const parts = id.split(
|
|
11095
|
-
const pkgName = isScopedPackage
|
|
11096
|
-
|
|
11094
|
+
const isScopedPackage = id.startsWith('@');
|
|
11095
|
+
const parts = id.split('/');
|
|
11096
|
+
const pkgName = isScopedPackage
|
|
11097
|
+
? `${parts[0]}/${parts[1]}`
|
|
11098
|
+
: parts[0];
|
|
11099
|
+
const subPath = isScopedPackage
|
|
11100
|
+
? parts.slice(2).join('/')
|
|
11101
|
+
: parts.slice(1).join('/');
|
|
11097
11102
|
const d = path.join(opt.moduleDir, pkgName);
|
|
11098
11103
|
let pkgJson;
|
|
11099
11104
|
try {
|
|
11100
|
-
pkgJson = JSON.parse(await fs.readFile(path.join(d,
|
|
11105
|
+
pkgJson = JSON.parse(await fs.readFile(path.join(d, 'package.json'), 'utf-8'));
|
|
11101
11106
|
}
|
|
11102
11107
|
catch (err) {
|
|
11103
|
-
|
|
11108
|
+
const nodeErr = err;
|
|
11109
|
+
if (!nodeErr.code || nodeErr.code === 'ENOENT') {
|
|
11104
11110
|
throw new Error(`[mcx resolveId]: package.json not found for '${id}' at '${d}'`);
|
|
11105
11111
|
}
|
|
11106
11112
|
else {
|
|
11107
|
-
throw new Error(`[mcx resolveId]: invalid package.json for '${id}': ${
|
|
11113
|
+
throw new Error(`[mcx resolveId]: invalid package.json for '${id}': ${nodeErr.message}`);
|
|
11108
11114
|
}
|
|
11109
11115
|
}
|
|
11110
11116
|
if (subPath) {
|
|
11111
11117
|
const fromExports = await resolvePackageExports(d, subPath, pkgJson);
|
|
11112
11118
|
if (fromExports)
|
|
11113
11119
|
return fromExports;
|
|
11114
|
-
const fromDist = await tryResolvePath(path.join(d,
|
|
11120
|
+
const fromDist = await tryResolvePath(path.join(d, './dist', subPath));
|
|
11115
11121
|
if (fromDist)
|
|
11116
11122
|
return fromDist;
|
|
11117
11123
|
const fromRoot = await tryResolvePath(path.join(d, subPath));
|
|
@@ -11126,7 +11132,7 @@ function mcxPlugn(opt, output) {
|
|
|
11126
11132
|
const magic = new MagicString(code);
|
|
11127
11133
|
const ext = path.extname(id).slice(1);
|
|
11128
11134
|
const tsRegex = /^.+?\.(ts|mts|cts)$/;
|
|
11129
|
-
if (ext ==
|
|
11135
|
+
if (ext == 'mcx') {
|
|
11130
11136
|
let compileData;
|
|
11131
11137
|
try {
|
|
11132
11138
|
compileData = cache.has(id)
|
|
@@ -11149,18 +11155,22 @@ function mcxPlugn(opt, output) {
|
|
|
11149
11155
|
const compiledCode = await transform(compileData, cache, id, this, opt, output);
|
|
11150
11156
|
return {
|
|
11151
11157
|
code: compiledCode,
|
|
11152
|
-
map: opt.sourcemap
|
|
11158
|
+
map: opt.sourcemap
|
|
11159
|
+
? magic.generateMap({ hires: true, source: id })
|
|
11160
|
+
: void 0,
|
|
11153
11161
|
};
|
|
11154
11162
|
}
|
|
11155
11163
|
else if (tsRegex.test(id)) {
|
|
11156
11164
|
// Use the parsed TypeScript configuration
|
|
11157
11165
|
const compiledCode = ts__namespace.transpileModule(code, {
|
|
11158
11166
|
compilerOptions: tsconfig.options,
|
|
11159
|
-
fileName: id
|
|
11167
|
+
fileName: id,
|
|
11160
11168
|
}).outputText;
|
|
11161
11169
|
return {
|
|
11162
11170
|
code: compiledCode,
|
|
11163
|
-
map: opt.sourcemap
|
|
11171
|
+
map: opt.sourcemap
|
|
11172
|
+
? magic.generateMap({ hires: true, source: id })
|
|
11173
|
+
: void 0,
|
|
11164
11174
|
};
|
|
11165
11175
|
}
|
|
11166
11176
|
return null;
|
|
@@ -11170,9 +11180,15 @@ function mcxPlugn(opt, output) {
|
|
|
11170
11180
|
},
|
|
11171
11181
|
buildStart() {
|
|
11172
11182
|
cache = new Map();
|
|
11173
|
-
}
|
|
11183
|
+
},
|
|
11174
11184
|
};
|
|
11175
11185
|
}
|
|
11186
|
+
function rollupPlugin(opt, output) {
|
|
11187
|
+
return createMcxPlugin(opt, output);
|
|
11188
|
+
}
|
|
11189
|
+
function rolldownPlugin(opt, output) {
|
|
11190
|
+
return createMcxPlugin(opt, output);
|
|
11191
|
+
}
|
|
11176
11192
|
|
|
11177
11193
|
var types = /*#__PURE__*/Object.freeze({
|
|
11178
11194
|
__proto__: null
|
|
@@ -11190,7 +11206,8 @@ exports.PUBTYPE = types;
|
|
|
11190
11206
|
exports.SVGImageComponent = SVGImageComponent;
|
|
11191
11207
|
exports.compile_component = index;
|
|
11192
11208
|
exports.compiler = index$1;
|
|
11193
|
-
exports.
|
|
11209
|
+
exports.rolldownPlugin = rolldownPlugin;
|
|
11210
|
+
exports.rollupPlugin = rollupPlugin;
|
|
11194
11211
|
exports.transform = transform;
|
|
11195
11212
|
exports.utils = McxUtlis;
|
|
11196
11213
|
//# sourceMappingURL=index.js.map
|