@vureact/compiler-core 1.0.4 → 1.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/README.md +278 -1
- package/README.zh.md +280 -0
- package/lib/{chunk-VWMAAVDB.esm.js → chunk-37YHAUPX.esm.js} +319 -149
- package/lib/{chunk-6PSD2CIO.js → chunk-P26R53VO.js} +351 -181
- package/lib/cli.esm.js +14 -4
- package/lib/cli.js +21 -11
- package/lib/compiler-core.d.cts +92 -53
- package/lib/compiler-core.d.ts +92 -53
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +1 -1
package/lib/cli.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @vureact/compiler-core v1.0
|
|
3
|
+
* @vureact/compiler-core v1.1.0
|
|
4
4
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
calcElapsedTime,
|
|
13
13
|
normalizePath,
|
|
14
14
|
version
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-37YHAUPX.esm.js";
|
|
16
16
|
|
|
17
17
|
// src/cli/index.ts
|
|
18
18
|
import { cac } from "cac";
|
|
@@ -104,7 +104,10 @@ function setupWatcher(compiler, config) {
|
|
|
104
104
|
const processors = {
|
|
105
105
|
".vue": (p) => compiler.processSFC(p),
|
|
106
106
|
".js": (p) => compiler.processScript(p),
|
|
107
|
-
".ts": (p) => compiler.processScript(p)
|
|
107
|
+
".ts": (p) => compiler.processScript(p),
|
|
108
|
+
".less": (p) => compiler.processStyle(p),
|
|
109
|
+
".sass": (p) => compiler.processStyle(p),
|
|
110
|
+
".scss": (p) => compiler.processStyle(p)
|
|
108
111
|
};
|
|
109
112
|
const onRecompile = async (event, filePath) => {
|
|
110
113
|
const ext = path.extname(filePath);
|
|
@@ -130,6 +133,8 @@ function setupWatcher(compiler, config) {
|
|
|
130
133
|
};
|
|
131
134
|
const onRemoveFile = async (type, filePath) => {
|
|
132
135
|
const ext = path.extname(filePath);
|
|
136
|
+
const scriptExtRegex = /\.(js|ts)$/i;
|
|
137
|
+
const styleExtRegex = /\.(less|sass|scss)$/i;
|
|
133
138
|
const removeFile = async (type2) => {
|
|
134
139
|
await compiler.removeOutputPath(filePath, type2);
|
|
135
140
|
cmpHelper.print(
|
|
@@ -142,16 +147,21 @@ function setupWatcher(compiler, config) {
|
|
|
142
147
|
await removeFile("sfc" /* SFC */);
|
|
143
148
|
return;
|
|
144
149
|
}
|
|
145
|
-
if (
|
|
150
|
+
if (scriptExtRegex.test(ext)) {
|
|
146
151
|
await removeFile("script" /* SCRIPT */);
|
|
147
152
|
return;
|
|
148
153
|
}
|
|
154
|
+
if (styleExtRegex.test(ext)) {
|
|
155
|
+
await removeFile("style" /* STYLE */);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
149
158
|
await removeFile("copied" /* ASSET */);
|
|
150
159
|
return;
|
|
151
160
|
}
|
|
152
161
|
if (type === "unlinkDir") {
|
|
153
162
|
await removeFile("sfc" /* SFC */);
|
|
154
163
|
await removeFile("script" /* SCRIPT */);
|
|
164
|
+
await removeFile("style" /* STYLE */);
|
|
155
165
|
await removeFile("copied" /* ASSET */);
|
|
156
166
|
}
|
|
157
167
|
};
|
package/lib/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
3
|
-
* @vureact/compiler-core v1.0
|
|
3
|
+
* @vureact/compiler-core v1.1.0
|
|
4
4
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkP26R53VOjs = require('./chunk-P26R53VO.js');
|
|
16
16
|
|
|
17
17
|
// src/cli/index.ts
|
|
18
18
|
var _cac = require('cac');
|
|
@@ -28,7 +28,7 @@ async function resolveAction(root, options) {
|
|
|
28
28
|
const projectRoot = root ? _path2.default.resolve(process.cwd(), root) : process.cwd();
|
|
29
29
|
const userConfig = await loadUserConfig(projectRoot);
|
|
30
30
|
const finalConfig = mergeConfig(projectRoot, options, userConfig);
|
|
31
|
-
const compiler = new (0,
|
|
31
|
+
const compiler = new (0, _chunkP26R53VOjs.VuReact)(finalConfig);
|
|
32
32
|
await compiler.execute();
|
|
33
33
|
if (finalConfig.watch) {
|
|
34
34
|
setupWatcher(compiler, finalConfig);
|
|
@@ -82,7 +82,7 @@ function mergeConfig(projectRoot, options, userConfig) {
|
|
|
82
82
|
}
|
|
83
83
|
function setupWatcher(compiler, config) {
|
|
84
84
|
const spinner = _ora2.default.call(void 0, );
|
|
85
|
-
const cmpHelper = new (0,
|
|
85
|
+
const cmpHelper = new (0, _chunkP26R53VOjs.Helper)(config);
|
|
86
86
|
const watcher = _chokidar2.default.watch(cmpHelper.getInputPath(), {
|
|
87
87
|
ignored: cmpHelper.getExcludes(),
|
|
88
88
|
persistent: true,
|
|
@@ -104,7 +104,10 @@ function setupWatcher(compiler, config) {
|
|
|
104
104
|
const processors = {
|
|
105
105
|
".vue": (p) => compiler.processSFC(p),
|
|
106
106
|
".js": (p) => compiler.processScript(p),
|
|
107
|
-
".ts": (p) => compiler.processScript(p)
|
|
107
|
+
".ts": (p) => compiler.processScript(p),
|
|
108
|
+
".less": (p) => compiler.processStyle(p),
|
|
109
|
+
".sass": (p) => compiler.processStyle(p),
|
|
110
|
+
".scss": (p) => compiler.processStyle(p)
|
|
108
111
|
};
|
|
109
112
|
const onRecompile = async (event, filePath) => {
|
|
110
113
|
const ext = _path2.default.extname(filePath);
|
|
@@ -114,7 +117,7 @@ function setupWatcher(compiler, config) {
|
|
|
114
117
|
const fn = processors[ext];
|
|
115
118
|
const unit = await fn(filePath);
|
|
116
119
|
cmpHelper.printCoreLogs();
|
|
117
|
-
cmpHelper.printCompileInfo(filePath,
|
|
120
|
+
cmpHelper.printCompileInfo(filePath, _chunkP26R53VOjs.calcElapsedTime.call(void 0, startTime));
|
|
118
121
|
if (unit) {
|
|
119
122
|
await _optionalChain([config, 'access', _11 => _11.onChange, 'optionalCall', _12 => _12(event, unit)]);
|
|
120
123
|
}
|
|
@@ -123,18 +126,20 @@ function setupWatcher(compiler, config) {
|
|
|
123
126
|
await compiler.processAsset(filePath);
|
|
124
127
|
cmpHelper.print(
|
|
125
128
|
_kleur2.default.blue("Copied Asset"),
|
|
126
|
-
_kleur2.default.dim(
|
|
129
|
+
_kleur2.default.dim(_chunkP26R53VOjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
|
|
127
130
|
);
|
|
128
131
|
}
|
|
129
132
|
spinner.stop();
|
|
130
133
|
};
|
|
131
134
|
const onRemoveFile = async (type, filePath) => {
|
|
132
135
|
const ext = _path2.default.extname(filePath);
|
|
136
|
+
const scriptExtRegex = /\.(js|ts)$/i;
|
|
137
|
+
const styleExtRegex = /\.(less|sass|scss)$/i;
|
|
133
138
|
const removeFile = async (type2) => {
|
|
134
139
|
await compiler.removeOutputPath(filePath, type2);
|
|
135
140
|
cmpHelper.print(
|
|
136
141
|
_kleur2.default.yellow("Removed"),
|
|
137
|
-
_kleur2.default.dim(
|
|
142
|
+
_kleur2.default.dim(_chunkP26R53VOjs.normalizePath.call(void 0, cmpHelper.relativePath(filePath)))
|
|
138
143
|
);
|
|
139
144
|
};
|
|
140
145
|
if (type === "unlink") {
|
|
@@ -142,16 +147,21 @@ function setupWatcher(compiler, config) {
|
|
|
142
147
|
await removeFile("sfc" /* SFC */);
|
|
143
148
|
return;
|
|
144
149
|
}
|
|
145
|
-
if (
|
|
150
|
+
if (scriptExtRegex.test(ext)) {
|
|
146
151
|
await removeFile("script" /* SCRIPT */);
|
|
147
152
|
return;
|
|
148
153
|
}
|
|
154
|
+
if (styleExtRegex.test(ext)) {
|
|
155
|
+
await removeFile("style" /* STYLE */);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
149
158
|
await removeFile("copied" /* ASSET */);
|
|
150
159
|
return;
|
|
151
160
|
}
|
|
152
161
|
if (type === "unlinkDir") {
|
|
153
162
|
await removeFile("sfc" /* SFC */);
|
|
154
163
|
await removeFile("script" /* SCRIPT */);
|
|
164
|
+
await removeFile("style" /* STYLE */);
|
|
155
165
|
await removeFile("copied" /* ASSET */);
|
|
156
166
|
}
|
|
157
167
|
};
|
|
@@ -163,7 +173,7 @@ function resolveOptions(command) {
|
|
|
163
173
|
}
|
|
164
174
|
|
|
165
175
|
// src/cli/index.ts
|
|
166
|
-
var [programName] = Object.keys(
|
|
176
|
+
var [programName] = Object.keys(_chunkP26R53VOjs.bin);
|
|
167
177
|
var cli = _cac.cac.call(void 0, programName);
|
|
168
178
|
var buildCommand = cli.command("build [root]", "Compile Vue3 to React (one-time)");
|
|
169
179
|
resolveOptions(buildCommand).action((root, options) => {
|
|
@@ -173,4 +183,4 @@ var watchCommand = cli.command("watch [root]", "Compile Vue3 to React and watch
|
|
|
173
183
|
resolveOptions(watchCommand).action((root, options) => {
|
|
174
184
|
resolveAction(root, { ...options, watch: true });
|
|
175
185
|
});
|
|
176
|
-
cli.help().version(
|
|
186
|
+
cli.help().version(_chunkP26R53VOjs.version).parse();
|
package/lib/compiler-core.d.cts
CHANGED
|
@@ -52,7 +52,7 @@ type ImportItem = {
|
|
|
52
52
|
name: string;
|
|
53
53
|
onDemand: boolean;
|
|
54
54
|
};
|
|
55
|
-
type FileInputType = 'sfc' | 'script-js' | 'script-ts';
|
|
55
|
+
type FileInputType = 'sfc' | 'script-js' | 'script-ts' | 'style' | 'unknow';
|
|
56
56
|
interface SlotNodesContext {
|
|
57
57
|
name: string;
|
|
58
58
|
isScope: boolean;
|
|
@@ -703,12 +703,12 @@ interface CompilerOptions {
|
|
|
703
703
|
* @param event Add or modify file
|
|
704
704
|
* @param unit Current sfc or script file compilation unit
|
|
705
705
|
*/
|
|
706
|
-
onChange?: (event: 'add' | 'change', unit:
|
|
706
|
+
onChange?: (event: 'add' | 'change', unit: CompilationUnit) => Promise<void | undefined>;
|
|
707
707
|
}
|
|
708
708
|
interface PluginRegister<T> {
|
|
709
709
|
[name: string]: (result: T, ctx: ICompilationContext) => void;
|
|
710
710
|
}
|
|
711
|
-
type CompilationResult = SFCCompilationResult | ScriptCompilationResult;
|
|
711
|
+
type CompilationResult = SFCCompilationResult | ScriptCompilationResult | StyleCompilationResult;
|
|
712
712
|
interface SFCCompilationResult extends BaseCompilationResult {
|
|
713
713
|
fileInfo: {
|
|
714
714
|
jsx: {
|
|
@@ -730,33 +730,52 @@ interface ScriptCompilationResult extends BaseCompilationResult {
|
|
|
730
730
|
};
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
+
interface StyleCompilationResult extends Omit<BaseCompilationResult, 'hasRoute' | keyof GeneratorResult> {
|
|
734
|
+
code: string;
|
|
735
|
+
fileInfo: {
|
|
736
|
+
style: {
|
|
737
|
+
file: string;
|
|
738
|
+
lang: string;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
}
|
|
733
742
|
interface BaseCompilationResult extends GeneratorResult {
|
|
734
743
|
fileId: string;
|
|
735
744
|
hasRoute?: boolean;
|
|
736
745
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
}
|
|
742
|
-
interface SFCUnit extends CompilationUnit {
|
|
743
|
-
output: {
|
|
746
|
+
type CompilationUnit = SFCUnit | ScriptUnit | StyleUnit;
|
|
747
|
+
interface SFCUnit extends BaseUnit {
|
|
748
|
+
type: CacheKey.SFC;
|
|
749
|
+
output?: {
|
|
744
750
|
jsx: OutputItem;
|
|
745
751
|
css: Partial<OutputItem>;
|
|
746
|
-
}
|
|
752
|
+
};
|
|
747
753
|
}
|
|
748
|
-
interface
|
|
749
|
-
|
|
750
|
-
|
|
754
|
+
interface ScriptUnit extends BaseUnit {
|
|
755
|
+
type: CacheKey.SCRIPT;
|
|
756
|
+
output?: {
|
|
757
|
+
script: OutputItem;
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
interface StyleUnit extends Omit<BaseUnit, 'hasRoute'> {
|
|
761
|
+
type: CacheKey.STYLE;
|
|
762
|
+
output?: {
|
|
763
|
+
style: OutputItem;
|
|
764
|
+
};
|
|
751
765
|
}
|
|
752
|
-
interface AssetUnit extends Omit<
|
|
766
|
+
interface AssetUnit extends Omit<BaseUnit, 'fileId' | 'source' | 'hasRoute'> {
|
|
767
|
+
type: CacheKey.ASSET;
|
|
753
768
|
}
|
|
754
|
-
interface
|
|
769
|
+
interface BaseUnit extends FileMeta {
|
|
755
770
|
file: string;
|
|
756
771
|
fileId: string;
|
|
757
772
|
source: string;
|
|
758
773
|
hasRoute?: boolean;
|
|
759
774
|
}
|
|
775
|
+
interface OutputItem {
|
|
776
|
+
file: string;
|
|
777
|
+
code: string;
|
|
778
|
+
}
|
|
760
779
|
type LoadedCache<T = CacheMeta> = {
|
|
761
780
|
key: CacheKey;
|
|
762
781
|
target: T[];
|
|
@@ -766,11 +785,13 @@ type CacheMeta = Vue2ReactCacheMeta | FileCacheMeta;
|
|
|
766
785
|
declare enum CacheKey {
|
|
767
786
|
SFC = "sfc",
|
|
768
787
|
SCRIPT = "script",
|
|
788
|
+
STYLE = "style",
|
|
769
789
|
ASSET = "copied"
|
|
770
790
|
}
|
|
771
791
|
interface CacheList {
|
|
772
792
|
[CacheKey.SFC]: Vue2ReactCacheMeta[];
|
|
773
793
|
[CacheKey.SCRIPT]: FileCacheMeta[];
|
|
794
|
+
[CacheKey.STYLE]: FileCacheMeta[];
|
|
774
795
|
[CacheKey.ASSET]: FileCacheMeta[];
|
|
775
796
|
}
|
|
776
797
|
type Vue2ReactCacheMeta = Omit<SFCUnit, 'source'>;
|
|
@@ -868,8 +889,8 @@ declare class Helper {
|
|
|
868
889
|
* @param key 缓存键
|
|
869
890
|
*/
|
|
870
891
|
loadCache(key: CacheKey.SFC): Promise<LoadedCache<Vue2ReactCacheMeta>>;
|
|
871
|
-
loadCache(key: CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<FileCacheMeta>>;
|
|
872
|
-
loadCache(key: CacheKey.SFC | CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<Vue2ReactCacheMeta | FileCacheMeta>>;
|
|
892
|
+
loadCache(key: CacheKey.SCRIPT | CacheKey.STYLE | CacheKey.ASSET): Promise<LoadedCache<FileCacheMeta>>;
|
|
893
|
+
loadCache(key: CacheKey.SFC | CacheKey.SCRIPT | CacheKey.STYLE | CacheKey.ASSET): Promise<LoadedCache<Vue2ReactCacheMeta | FileCacheMeta>>;
|
|
873
894
|
createCacheData(key: CacheKey): LoadedCache;
|
|
874
895
|
/**
|
|
875
896
|
* 获取缓存文件路径
|
|
@@ -1021,8 +1042,7 @@ declare class BaseCompiler extends Helper {
|
|
|
1021
1042
|
* `;
|
|
1022
1043
|
*
|
|
1023
1044
|
* const result = compiler.compile(vueCode, 'MyComponent.vue');
|
|
1024
|
-
* console.log(result
|
|
1025
|
-
* console.log(result.fileInfo.jsx.file); // 输出文件路径
|
|
1045
|
+
* console.log(result);
|
|
1026
1046
|
* ```
|
|
1027
1047
|
*
|
|
1028
1048
|
* @throws 不会直接抛出异常,错误通过日志系统记录
|
|
@@ -1032,37 +1052,6 @@ declare class BaseCompiler extends Helper {
|
|
|
1032
1052
|
* @see {@link executePlugins} 插件执行函数
|
|
1033
1053
|
*/
|
|
1034
1054
|
compile(source: string, filename: string): CompilationResult;
|
|
1035
|
-
/**
|
|
1036
|
-
* 处理 SFC 和 Script 文件的编译结果
|
|
1037
|
-
*
|
|
1038
|
-
* 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
|
|
1039
|
-
* 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
|
|
1040
|
-
* 对于 Script 文件,返回仅包含脚本信息的结果。
|
|
1041
|
-
*
|
|
1042
|
-
* 关键处理逻辑:
|
|
1043
|
-
* 1. 构建基础结果:包含文件ID、路由信息和生成的代码
|
|
1044
|
-
* 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
|
|
1045
|
-
* 3. 区分文件类型:
|
|
1046
|
-
* - SFC 文件:生成 .tsx 扩展名,包含样式信息
|
|
1047
|
-
* - Script 文件:保持原扩展名,不包含样式信息
|
|
1048
|
-
* 4. 样式处理:提取样式文件路径、作用域ID和样式代码
|
|
1049
|
-
*
|
|
1050
|
-
* @private
|
|
1051
|
-
* @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
|
|
1052
|
-
* @param gen - 代码生成结果,包含生成的代码和源码映射
|
|
1053
|
-
* @param ctxData - 编译上下文数据,包含文件信息和编译状态
|
|
1054
|
-
* @returns {CompilationResult} 整理后的编译结果
|
|
1055
|
-
*
|
|
1056
|
-
* @remarks
|
|
1057
|
-
* - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
|
|
1058
|
-
* - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
|
|
1059
|
-
* - 路由检测:自动检测组件是否使用路由,用于依赖注入
|
|
1060
|
-
* - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
|
|
1061
|
-
*
|
|
1062
|
-
* @see {@link SFCCompilationResult} SFC 编译结果类型
|
|
1063
|
-
* @see {@link ScriptCompilationResult} Script 编译结果类型
|
|
1064
|
-
*/
|
|
1065
|
-
private resolveResult;
|
|
1066
1055
|
/**
|
|
1067
1056
|
* 初始化 Babel 代码生成选项
|
|
1068
1057
|
*
|
|
@@ -1110,6 +1099,43 @@ declare class BaseCompiler extends Helper {
|
|
|
1110
1099
|
* @see {@link GeneratorOptions} Babel 生成选项类型定义
|
|
1111
1100
|
*/
|
|
1112
1101
|
private prepareGenerateOptions;
|
|
1102
|
+
/**
|
|
1103
|
+
* 处理 SFC 和 Script 文件的编译结果
|
|
1104
|
+
*
|
|
1105
|
+
* 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
|
|
1106
|
+
* 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
|
|
1107
|
+
* 对于 Script 文件,返回仅包含脚本信息的结果。
|
|
1108
|
+
*
|
|
1109
|
+
* 关键处理逻辑:
|
|
1110
|
+
* 1. 构建基础结果:包含文件ID、路由信息和生成的代码
|
|
1111
|
+
* 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
|
|
1112
|
+
* 3. 区分文件类型:
|
|
1113
|
+
* - SFC 文件:生成 .tsx 扩展名,包含样式信息
|
|
1114
|
+
* - Script 文件:保持原扩展名,不包含样式信息
|
|
1115
|
+
* 4. 样式处理:提取样式文件路径、作用域ID和样式代码
|
|
1116
|
+
*
|
|
1117
|
+
* @private
|
|
1118
|
+
* @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
|
|
1119
|
+
* @param gen - 代码生成结果,包含生成的代码和源码映射
|
|
1120
|
+
* @param ctxData - 编译上下文数据,包含文件信息和编译状态
|
|
1121
|
+
* @returns {CompilationResult} 整理后的编译结果
|
|
1122
|
+
*
|
|
1123
|
+
* @remarks
|
|
1124
|
+
* - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
|
|
1125
|
+
* - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
|
|
1126
|
+
* - 路由检测:自动检测组件是否使用路由,用于依赖注入
|
|
1127
|
+
* - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
|
|
1128
|
+
*
|
|
1129
|
+
* @see {@link SFCCompilationResult} SFC 编译结果类型
|
|
1130
|
+
* @see {@link ScriptCompilationResult} Script 编译结果类型
|
|
1131
|
+
*/
|
|
1132
|
+
private resolveMainResult;
|
|
1133
|
+
/**
|
|
1134
|
+
* 处理 Style 文件的编译结果
|
|
1135
|
+
* @param data style 文件解析结果
|
|
1136
|
+
* @param ctxData 上下文数据
|
|
1137
|
+
*/
|
|
1138
|
+
private resolveStyleResult;
|
|
1113
1139
|
}
|
|
1114
1140
|
|
|
1115
1141
|
/**
|
|
@@ -1252,6 +1278,19 @@ declare class FileCompiler extends BaseCompiler {
|
|
|
1252
1278
|
* @see {@link FileProcessor.processScript}
|
|
1253
1279
|
*/
|
|
1254
1280
|
processScript(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<ScriptUnit | undefined>;
|
|
1281
|
+
/**
|
|
1282
|
+
* 处理单个 CSS/LESS/SCSS 样式文件
|
|
1283
|
+
*
|
|
1284
|
+
* 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
|
|
1285
|
+
* 支持增量编译,如果文件未变更则跳过编译。
|
|
1286
|
+
*
|
|
1287
|
+
* @async
|
|
1288
|
+
* @param filePath - style 文件的绝对路径
|
|
1289
|
+
* @param existingCache - 可选的预加载缓存对象,用于增量编译
|
|
1290
|
+
* @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
|
|
1291
|
+
* @see {@link FileProcessor.processStyle}
|
|
1292
|
+
*/
|
|
1293
|
+
processStyle(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<StyleUnit | undefined>;
|
|
1255
1294
|
/**
|
|
1256
1295
|
* 处理单个文件(Vue 或 Script)
|
|
1257
1296
|
*
|
|
@@ -1265,7 +1304,7 @@ declare class FileCompiler extends BaseCompiler {
|
|
|
1265
1304
|
* @returns {Promise<SFCUnit | ScriptUnit | undefined>} 编译单元对象
|
|
1266
1305
|
* @see {@link FileProcessor.processFile}
|
|
1267
1306
|
*/
|
|
1268
|
-
processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise<
|
|
1307
|
+
processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise<CompilationUnit | undefined>;
|
|
1269
1308
|
/**
|
|
1270
1309
|
* 处理单个资源文件
|
|
1271
1310
|
*
|
|
@@ -1341,4 +1380,4 @@ declare function defineConfig(options: CompilerOptions): CompilerOptions;
|
|
|
1341
1380
|
declare class VuReact extends FileCompiler {
|
|
1342
1381
|
}
|
|
1343
1382
|
|
|
1344
|
-
export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type CacheCheckResult, CacheKey, type CacheList, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type FileCacheMeta, FileCompiler, type FileMeta, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type SFCCompilationResult, type SFCUnit, type ScriptCompilationResult, type ScriptUnit, type TransformerOptions, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };
|
|
1383
|
+
export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type BaseUnit, type CacheCheckResult, CacheKey, type CacheList, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type FileCacheMeta, FileCompiler, type FileMeta, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type SFCCompilationResult, type SFCUnit, type ScriptCompilationResult, type ScriptUnit, type StyleCompilationResult, type StyleUnit, type TransformerOptions, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };
|
package/lib/compiler-core.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ type ImportItem = {
|
|
|
52
52
|
name: string;
|
|
53
53
|
onDemand: boolean;
|
|
54
54
|
};
|
|
55
|
-
type FileInputType = 'sfc' | 'script-js' | 'script-ts';
|
|
55
|
+
type FileInputType = 'sfc' | 'script-js' | 'script-ts' | 'style' | 'unknow';
|
|
56
56
|
interface SlotNodesContext {
|
|
57
57
|
name: string;
|
|
58
58
|
isScope: boolean;
|
|
@@ -703,12 +703,12 @@ interface CompilerOptions {
|
|
|
703
703
|
* @param event Add or modify file
|
|
704
704
|
* @param unit Current sfc or script file compilation unit
|
|
705
705
|
*/
|
|
706
|
-
onChange?: (event: 'add' | 'change', unit:
|
|
706
|
+
onChange?: (event: 'add' | 'change', unit: CompilationUnit) => Promise<void | undefined>;
|
|
707
707
|
}
|
|
708
708
|
interface PluginRegister<T> {
|
|
709
709
|
[name: string]: (result: T, ctx: ICompilationContext) => void;
|
|
710
710
|
}
|
|
711
|
-
type CompilationResult = SFCCompilationResult | ScriptCompilationResult;
|
|
711
|
+
type CompilationResult = SFCCompilationResult | ScriptCompilationResult | StyleCompilationResult;
|
|
712
712
|
interface SFCCompilationResult extends BaseCompilationResult {
|
|
713
713
|
fileInfo: {
|
|
714
714
|
jsx: {
|
|
@@ -730,33 +730,52 @@ interface ScriptCompilationResult extends BaseCompilationResult {
|
|
|
730
730
|
};
|
|
731
731
|
};
|
|
732
732
|
}
|
|
733
|
+
interface StyleCompilationResult extends Omit<BaseCompilationResult, 'hasRoute' | keyof GeneratorResult> {
|
|
734
|
+
code: string;
|
|
735
|
+
fileInfo: {
|
|
736
|
+
style: {
|
|
737
|
+
file: string;
|
|
738
|
+
lang: string;
|
|
739
|
+
};
|
|
740
|
+
};
|
|
741
|
+
}
|
|
733
742
|
interface BaseCompilationResult extends GeneratorResult {
|
|
734
743
|
fileId: string;
|
|
735
744
|
hasRoute?: boolean;
|
|
736
745
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
}
|
|
742
|
-
interface SFCUnit extends CompilationUnit {
|
|
743
|
-
output: {
|
|
746
|
+
type CompilationUnit = SFCUnit | ScriptUnit | StyleUnit;
|
|
747
|
+
interface SFCUnit extends BaseUnit {
|
|
748
|
+
type: CacheKey.SFC;
|
|
749
|
+
output?: {
|
|
744
750
|
jsx: OutputItem;
|
|
745
751
|
css: Partial<OutputItem>;
|
|
746
|
-
}
|
|
752
|
+
};
|
|
747
753
|
}
|
|
748
|
-
interface
|
|
749
|
-
|
|
750
|
-
|
|
754
|
+
interface ScriptUnit extends BaseUnit {
|
|
755
|
+
type: CacheKey.SCRIPT;
|
|
756
|
+
output?: {
|
|
757
|
+
script: OutputItem;
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
interface StyleUnit extends Omit<BaseUnit, 'hasRoute'> {
|
|
761
|
+
type: CacheKey.STYLE;
|
|
762
|
+
output?: {
|
|
763
|
+
style: OutputItem;
|
|
764
|
+
};
|
|
751
765
|
}
|
|
752
|
-
interface AssetUnit extends Omit<
|
|
766
|
+
interface AssetUnit extends Omit<BaseUnit, 'fileId' | 'source' | 'hasRoute'> {
|
|
767
|
+
type: CacheKey.ASSET;
|
|
753
768
|
}
|
|
754
|
-
interface
|
|
769
|
+
interface BaseUnit extends FileMeta {
|
|
755
770
|
file: string;
|
|
756
771
|
fileId: string;
|
|
757
772
|
source: string;
|
|
758
773
|
hasRoute?: boolean;
|
|
759
774
|
}
|
|
775
|
+
interface OutputItem {
|
|
776
|
+
file: string;
|
|
777
|
+
code: string;
|
|
778
|
+
}
|
|
760
779
|
type LoadedCache<T = CacheMeta> = {
|
|
761
780
|
key: CacheKey;
|
|
762
781
|
target: T[];
|
|
@@ -766,11 +785,13 @@ type CacheMeta = Vue2ReactCacheMeta | FileCacheMeta;
|
|
|
766
785
|
declare enum CacheKey {
|
|
767
786
|
SFC = "sfc",
|
|
768
787
|
SCRIPT = "script",
|
|
788
|
+
STYLE = "style",
|
|
769
789
|
ASSET = "copied"
|
|
770
790
|
}
|
|
771
791
|
interface CacheList {
|
|
772
792
|
[CacheKey.SFC]: Vue2ReactCacheMeta[];
|
|
773
793
|
[CacheKey.SCRIPT]: FileCacheMeta[];
|
|
794
|
+
[CacheKey.STYLE]: FileCacheMeta[];
|
|
774
795
|
[CacheKey.ASSET]: FileCacheMeta[];
|
|
775
796
|
}
|
|
776
797
|
type Vue2ReactCacheMeta = Omit<SFCUnit, 'source'>;
|
|
@@ -868,8 +889,8 @@ declare class Helper {
|
|
|
868
889
|
* @param key 缓存键
|
|
869
890
|
*/
|
|
870
891
|
loadCache(key: CacheKey.SFC): Promise<LoadedCache<Vue2ReactCacheMeta>>;
|
|
871
|
-
loadCache(key: CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<FileCacheMeta>>;
|
|
872
|
-
loadCache(key: CacheKey.SFC | CacheKey.SCRIPT | CacheKey.ASSET): Promise<LoadedCache<Vue2ReactCacheMeta | FileCacheMeta>>;
|
|
892
|
+
loadCache(key: CacheKey.SCRIPT | CacheKey.STYLE | CacheKey.ASSET): Promise<LoadedCache<FileCacheMeta>>;
|
|
893
|
+
loadCache(key: CacheKey.SFC | CacheKey.SCRIPT | CacheKey.STYLE | CacheKey.ASSET): Promise<LoadedCache<Vue2ReactCacheMeta | FileCacheMeta>>;
|
|
873
894
|
createCacheData(key: CacheKey): LoadedCache;
|
|
874
895
|
/**
|
|
875
896
|
* 获取缓存文件路径
|
|
@@ -1021,8 +1042,7 @@ declare class BaseCompiler extends Helper {
|
|
|
1021
1042
|
* `;
|
|
1022
1043
|
*
|
|
1023
1044
|
* const result = compiler.compile(vueCode, 'MyComponent.vue');
|
|
1024
|
-
* console.log(result
|
|
1025
|
-
* console.log(result.fileInfo.jsx.file); // 输出文件路径
|
|
1045
|
+
* console.log(result);
|
|
1026
1046
|
* ```
|
|
1027
1047
|
*
|
|
1028
1048
|
* @throws 不会直接抛出异常,错误通过日志系统记录
|
|
@@ -1032,37 +1052,6 @@ declare class BaseCompiler extends Helper {
|
|
|
1032
1052
|
* @see {@link executePlugins} 插件执行函数
|
|
1033
1053
|
*/
|
|
1034
1054
|
compile(source: string, filename: string): CompilationResult;
|
|
1035
|
-
/**
|
|
1036
|
-
* 处理 SFC 和 Script 文件的编译结果
|
|
1037
|
-
*
|
|
1038
|
-
* 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
|
|
1039
|
-
* 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
|
|
1040
|
-
* 对于 Script 文件,返回仅包含脚本信息的结果。
|
|
1041
|
-
*
|
|
1042
|
-
* 关键处理逻辑:
|
|
1043
|
-
* 1. 构建基础结果:包含文件ID、路由信息和生成的代码
|
|
1044
|
-
* 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
|
|
1045
|
-
* 3. 区分文件类型:
|
|
1046
|
-
* - SFC 文件:生成 .tsx 扩展名,包含样式信息
|
|
1047
|
-
* - Script 文件:保持原扩展名,不包含样式信息
|
|
1048
|
-
* 4. 样式处理:提取样式文件路径、作用域ID和样式代码
|
|
1049
|
-
*
|
|
1050
|
-
* @private
|
|
1051
|
-
* @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
|
|
1052
|
-
* @param gen - 代码生成结果,包含生成的代码和源码映射
|
|
1053
|
-
* @param ctxData - 编译上下文数据,包含文件信息和编译状态
|
|
1054
|
-
* @returns {CompilationResult} 整理后的编译结果
|
|
1055
|
-
*
|
|
1056
|
-
* @remarks
|
|
1057
|
-
* - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
|
|
1058
|
-
* - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
|
|
1059
|
-
* - 路由检测:自动检测组件是否使用路由,用于依赖注入
|
|
1060
|
-
* - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
|
|
1061
|
-
*
|
|
1062
|
-
* @see {@link SFCCompilationResult} SFC 编译结果类型
|
|
1063
|
-
* @see {@link ScriptCompilationResult} Script 编译结果类型
|
|
1064
|
-
*/
|
|
1065
|
-
private resolveResult;
|
|
1066
1055
|
/**
|
|
1067
1056
|
* 初始化 Babel 代码生成选项
|
|
1068
1057
|
*
|
|
@@ -1110,6 +1099,43 @@ declare class BaseCompiler extends Helper {
|
|
|
1110
1099
|
* @see {@link GeneratorOptions} Babel 生成选项类型定义
|
|
1111
1100
|
*/
|
|
1112
1101
|
private prepareGenerateOptions;
|
|
1102
|
+
/**
|
|
1103
|
+
* 处理 SFC 和 Script 文件的编译结果
|
|
1104
|
+
*
|
|
1105
|
+
* 根据编译上下文中的输入类型(SFC 或 Script),整理并返回相应的编译结果。
|
|
1106
|
+
* 对于 SFC 文件,返回包含 JSX 和 CSS 信息的完整结果;
|
|
1107
|
+
* 对于 Script 文件,返回仅包含脚本信息的结果。
|
|
1108
|
+
*
|
|
1109
|
+
* 关键处理逻辑:
|
|
1110
|
+
* 1. 构建基础结果:包含文件ID、路由信息和生成的代码
|
|
1111
|
+
* 2. 确定输出路径:根据源文件路径和语言类型生成输出文件路径
|
|
1112
|
+
* 3. 区分文件类型:
|
|
1113
|
+
* - SFC 文件:生成 .tsx 扩展名,包含样式信息
|
|
1114
|
+
* - Script 文件:保持原扩展名,不包含样式信息
|
|
1115
|
+
* 4. 样式处理:提取样式文件路径、作用域ID和样式代码
|
|
1116
|
+
*
|
|
1117
|
+
* @private
|
|
1118
|
+
* @param ir - React 中间表示(IR)描述符,包含转换后的组件信息
|
|
1119
|
+
* @param gen - 代码生成结果,包含生成的代码和源码映射
|
|
1120
|
+
* @param ctxData - 编译上下文数据,包含文件信息和编译状态
|
|
1121
|
+
* @returns {CompilationResult} 整理后的编译结果
|
|
1122
|
+
*
|
|
1123
|
+
* @remarks
|
|
1124
|
+
* - 文件扩展名处理:Vue SFC 文件会转换为 .tsx 或 .jsx 文件
|
|
1125
|
+
* - 样式分离:SFC 中的样式会被提取到独立的 CSS 文件中
|
|
1126
|
+
* - 路由检测:自动检测组件是否使用路由,用于依赖注入
|
|
1127
|
+
* - 作用域样式:为 Scoped CSS 生成唯一的作用域ID
|
|
1128
|
+
*
|
|
1129
|
+
* @see {@link SFCCompilationResult} SFC 编译结果类型
|
|
1130
|
+
* @see {@link ScriptCompilationResult} Script 编译结果类型
|
|
1131
|
+
*/
|
|
1132
|
+
private resolveMainResult;
|
|
1133
|
+
/**
|
|
1134
|
+
* 处理 Style 文件的编译结果
|
|
1135
|
+
* @param data style 文件解析结果
|
|
1136
|
+
* @param ctxData 上下文数据
|
|
1137
|
+
*/
|
|
1138
|
+
private resolveStyleResult;
|
|
1113
1139
|
}
|
|
1114
1140
|
|
|
1115
1141
|
/**
|
|
@@ -1252,6 +1278,19 @@ declare class FileCompiler extends BaseCompiler {
|
|
|
1252
1278
|
* @see {@link FileProcessor.processScript}
|
|
1253
1279
|
*/
|
|
1254
1280
|
processScript(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<ScriptUnit | undefined>;
|
|
1281
|
+
/**
|
|
1282
|
+
* 处理单个 CSS/LESS/SCSS 样式文件
|
|
1283
|
+
*
|
|
1284
|
+
* 此方法主要用于 CLI 的 watch 模式,当检测到文件变更时调用。
|
|
1285
|
+
* 支持增量编译,如果文件未变更则跳过编译。
|
|
1286
|
+
*
|
|
1287
|
+
* @async
|
|
1288
|
+
* @param filePath - style 文件的绝对路径
|
|
1289
|
+
* @param existingCache - 可选的预加载缓存对象,用于增量编译
|
|
1290
|
+
* @returns {Promise<ScriptUnit | undefined>} 编译单元对象,如果跳过编译则返回 undefined
|
|
1291
|
+
* @see {@link FileProcessor.processStyle}
|
|
1292
|
+
*/
|
|
1293
|
+
processStyle(filePath: string, existingCache?: LoadedCache<FileCacheMeta>): Promise<StyleUnit | undefined>;
|
|
1255
1294
|
/**
|
|
1256
1295
|
* 处理单个文件(Vue 或 Script)
|
|
1257
1296
|
*
|
|
@@ -1265,7 +1304,7 @@ declare class FileCompiler extends BaseCompiler {
|
|
|
1265
1304
|
* @returns {Promise<SFCUnit | ScriptUnit | undefined>} 编译单元对象
|
|
1266
1305
|
* @see {@link FileProcessor.processFile}
|
|
1267
1306
|
*/
|
|
1268
|
-
processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise<
|
|
1307
|
+
processFile(key: CacheKey, filePath: string, existingCache?: LoadedCache): Promise<CompilationUnit | undefined>;
|
|
1269
1308
|
/**
|
|
1270
1309
|
* 处理单个资源文件
|
|
1271
1310
|
*
|
|
@@ -1341,4 +1380,4 @@ declare function defineConfig(options: CompilerOptions): CompilerOptions;
|
|
|
1341
1380
|
declare class VuReact extends FileCompiler {
|
|
1342
1381
|
}
|
|
1343
1382
|
|
|
1344
|
-
export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type CacheCheckResult, CacheKey, type CacheList, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type FileCacheMeta, FileCompiler, type FileMeta, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type SFCCompilationResult, type SFCUnit, type ScriptCompilationResult, type ScriptUnit, type TransformerOptions, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };
|
|
1383
|
+
export { type AssetUnit, type BaseCompilationResult, BaseCompiler, type BaseUnit, type CacheCheckResult, CacheKey, type CacheList, type CacheMeta, type CompilationResult, type CompilationUnit, type CompilerOptions, type FileCacheMeta, FileCompiler, type FileMeta, type GeneratorOptions, type GeneratorResult, Helper, type LoadedCache, type ParseResult, type ParserOptions, type PluginRegister, type ReactIRDescriptor, type SFCCompilationResult, type SFCUnit, type ScriptCompilationResult, type ScriptUnit, type StyleCompilationResult, type StyleUnit, type TransformerOptions, VuReact, type Vue2ReactCacheMeta, defineConfig, generate, generateComponent, generateOnlyScript, parse, parseOnlyScript, parseSFC, transform };
|
package/lib/compiler-core.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vureact/compiler-core v1.0
|
|
2
|
+
* @vureact/compiler-core v1.1.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
parseOnlyScript,
|
|
19
19
|
parseSFC,
|
|
20
20
|
transform
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-37YHAUPX.esm.js";
|
|
22
22
|
export {
|
|
23
23
|
BaseCompiler,
|
|
24
24
|
CacheKey,
|