@dimina/compiler 1.0.12-beta.3 → 1.0.12-beta.6

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.
@@ -5,7 +5,7 @@ const process = require("node:process");
5
5
  const chokidar = require("chokidar");
6
6
  const commander = require("commander");
7
7
  const index = require("../index.cjs");
8
- const version = "1.0.12-beta.2";
8
+ const version = "1.0.12-beta.6";
9
9
  const pack = {
10
10
  version
11
11
  };
package/dist/bin/index.js CHANGED
@@ -4,7 +4,7 @@ import process from "node:process";
4
4
  import chokidar from "chokidar";
5
5
  import { program } from "commander";
6
6
  import build from "../index.js";
7
- const version = "1.0.12-beta.2";
7
+ const version = "1.0.12-beta.6";
8
8
  const pack = {
9
9
  version
10
10
  };
@@ -95,17 +95,22 @@ async function compileJS(pages, root, mainCompileRes, progress) {
95
95
  return compileRes;
96
96
  }
97
97
  function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
98
- if (!module2.path) {
98
+ const currentPath = module2.path;
99
+ if (depthChain.includes(currentPath)) {
100
+ console.warn("[logic]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
101
+ return;
102
+ }
103
+ if (depthChain.length > 20) {
104
+ console.warn("[logic]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
99
105
  return;
100
106
  }
101
- const moduleKey = packageName + module2.path;
102
- if (processedModules.has(moduleKey)) {
107
+ depthChain = [...depthChain, currentPath];
108
+ if (!module2.path) {
103
109
  return;
104
110
  }
105
111
  if (env.hasCompileInfo(module2.path, compileRes, mainCompileRes)) {
106
112
  return;
107
113
  }
108
- processedModules.add(moduleKey);
109
114
  const compileInfo = {
110
115
  path: module2.path,
111
116
  code: ""
@@ -167,7 +172,7 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
167
172
  if (!componentModule) {
168
173
  continue;
169
174
  }
170
- buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, toMainSubPackage);
175
+ buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
171
176
  const props = types.objectProperty(types.identifier(`'${name}'`), types.stringLiteral(path2));
172
177
  components.value.properties.push(props);
173
178
  }
@@ -193,7 +198,9 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
193
198
  id = "/" + id;
194
199
  }
195
200
  ap.node.arguments[0] = types.stringLiteral(id);
196
- buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false);
201
+ if (!processedModules.has(packageName + id)) {
202
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
203
+ }
197
204
  }
198
205
  }
199
206
  },
@@ -223,7 +230,9 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
223
230
  }
224
231
  if (shouldProcess) {
225
232
  ap.node.source = types.stringLiteral(id);
226
- buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false);
233
+ if (!processedModules.has(packageName + id)) {
234
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
235
+ }
227
236
  }
228
237
  }
229
238
  }
@@ -236,6 +245,7 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
236
245
  ]
237
246
  });
238
247
  compileInfo.code = code;
248
+ processedModules.add(packageName + currentPath);
239
249
  }
240
250
  function getExtraInfoStatement(type, addedArgs) {
241
251
  const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
@@ -93,17 +93,22 @@ async function compileJS(pages, root, mainCompileRes, progress) {
93
93
  return compileRes;
94
94
  }
95
95
  function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
96
- if (!module.path) {
96
+ const currentPath = module.path;
97
+ if (depthChain.includes(currentPath)) {
98
+ console.warn("[logic]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
99
+ return;
100
+ }
101
+ if (depthChain.length > 20) {
102
+ console.warn("[logic]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
97
103
  return;
98
104
  }
99
- const moduleKey = packageName + module.path;
100
- if (processedModules.has(moduleKey)) {
105
+ depthChain = [...depthChain, currentPath];
106
+ if (!module.path) {
101
107
  return;
102
108
  }
103
109
  if (hasCompileInfo(module.path, compileRes, mainCompileRes)) {
104
110
  return;
105
111
  }
106
- processedModules.add(moduleKey);
107
112
  const compileInfo = {
108
113
  path: module.path,
109
114
  code: ""
@@ -165,7 +170,7 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
165
170
  if (!componentModule) {
166
171
  continue;
167
172
  }
168
- buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, toMainSubPackage);
173
+ buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
169
174
  const props = types.objectProperty(types.identifier(`'${name}'`), types.stringLiteral(path));
170
175
  components.value.properties.push(props);
171
176
  }
@@ -191,7 +196,9 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
191
196
  id = "/" + id;
192
197
  }
193
198
  ap.node.arguments[0] = types.stringLiteral(id);
194
- buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false);
199
+ if (!processedModules.has(packageName + id)) {
200
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
201
+ }
195
202
  }
196
203
  }
197
204
  },
@@ -221,7 +228,9 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
221
228
  }
222
229
  if (shouldProcess) {
223
230
  ap.node.source = types.stringLiteral(id);
224
- buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false);
231
+ if (!processedModules.has(packageName + id)) {
232
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
233
+ }
225
234
  }
226
235
  }
227
236
  }
@@ -234,6 +243,7 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
234
243
  ]
235
244
  });
236
245
  compileInfo.code = code;
246
+ processedModules.add(packageName + currentPath);
237
247
  }
238
248
  function getExtraInfoStatement(type, addedArgs) {
239
249
  const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
@@ -30,7 +30,6 @@ function _interopNamespaceDefault(e) {
30
30
  const sass__namespace = /* @__PURE__ */ _interopNamespaceDefault(sass);
31
31
  const fileType = [".wxss", ".ddss", ".less", ".scss", ".sass"];
32
32
  const compileRes = /* @__PURE__ */ new Map();
33
- const processedPaths = /* @__PURE__ */ new Set();
34
33
  if (!node_worker_threads.isMainThread) {
35
34
  node_worker_threads.parentPort.on("message", async ({ pages, storeInfo }) => {
36
35
  try {
@@ -84,10 +83,15 @@ async function compileSS(pages, root, progress) {
84
83
  }
85
84
  async function buildCompileCss(module2, depthChain = []) {
86
85
  const currentPath = module2.path;
87
- if (processedPaths.has(currentPath)) {
86
+ if (depthChain.includes(currentPath)) {
87
+ console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
88
88
  return;
89
89
  }
90
- processedPaths.add(currentPath);
90
+ if (depthChain.length > 20) {
91
+ console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
92
+ return;
93
+ }
94
+ depthChain = [...depthChain, currentPath];
91
95
  let result = await enhanceCSS(module2) || "";
92
96
  if (module2.usingComponents) {
93
97
  for (const componentInfo of Object.values(module2.usingComponents)) {
@@ -95,7 +99,7 @@ async function buildCompileCss(module2, depthChain = []) {
95
99
  if (!componentModule) {
96
100
  continue;
97
101
  }
98
- result += await buildCompileCss(componentModule);
102
+ result += await buildCompileCss(componentModule, depthChain);
99
103
  }
100
104
  }
101
105
  return result;
@@ -11,7 +11,6 @@ import * as sass from "sass";
11
11
  import { r as resetStoreInfo, g as getTargetPath, a as getComponent, b as getContentByPath, h as tagWhiteList, e as collectAssets, f as getAppId, d as getWorkPath, t as transformRpx } from "../env-Csj3AHY4.js";
12
12
  const fileType = [".wxss", ".ddss", ".less", ".scss", ".sass"];
13
13
  const compileRes = /* @__PURE__ */ new Map();
14
- const processedPaths = /* @__PURE__ */ new Set();
15
14
  if (!isMainThread) {
16
15
  parentPort.on("message", async ({ pages, storeInfo }) => {
17
16
  try {
@@ -65,10 +64,15 @@ async function compileSS(pages, root, progress) {
65
64
  }
66
65
  async function buildCompileCss(module, depthChain = []) {
67
66
  const currentPath = module.path;
68
- if (processedPaths.has(currentPath)) {
67
+ if (depthChain.includes(currentPath)) {
68
+ console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
69
69
  return;
70
70
  }
71
- processedPaths.add(currentPath);
71
+ if (depthChain.length > 20) {
72
+ console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
73
+ return;
74
+ }
75
+ depthChain = [...depthChain, currentPath];
72
76
  let result = await enhanceCSS(module) || "";
73
77
  if (module.usingComponents) {
74
78
  for (const componentInfo of Object.values(module.usingComponents)) {
@@ -76,7 +80,7 @@ async function buildCompileCss(module, depthChain = []) {
76
80
  if (!componentModule) {
77
81
  continue;
78
82
  }
79
- result += await buildCompileCss(componentModule);
83
+ result += await buildCompileCss(componentModule, depthChain);
80
84
  }
81
85
  }
82
86
  return result;
@@ -6,6 +6,7 @@ const node_worker_threads = require("node:worker_threads");
6
6
  const babel = require("@babel/core");
7
7
  const _traverse = require("@babel/traverse");
8
8
  const types = require("@babel/types");
9
+ const pluginTransformArrowFunctions = require("@babel/plugin-transform-arrow-functions");
9
10
  const compilerSfc = require("@vue/compiler-sfc");
10
11
  const cheerio = require("cheerio");
11
12
  const esbuild = require("esbuild");
@@ -140,7 +141,6 @@ const fileType = [".wxml", ".ddml"];
140
141
  const compileResCache = /* @__PURE__ */ new Map();
141
142
  const wxsModuleRegistry = /* @__PURE__ */ new Set();
142
143
  const wxsFilePathMap = /* @__PURE__ */ new Map();
143
- const processedViewPaths = /* @__PURE__ */ new Set();
144
144
  if (!node_worker_threads.isMainThread) {
145
145
  node_worker_threads.parentPort.on("message", async ({ pages, storeInfo }) => {
146
146
  try {
@@ -239,10 +239,15 @@ function isRegisteredWxsModule(modulePath) {
239
239
  }
240
240
  function buildCompileView(module2, isComponent = false, scriptRes, depthChain = []) {
241
241
  const currentPath = module2.path;
242
- if (processedViewPaths.has(currentPath)) {
243
- return null;
242
+ if (depthChain.includes(currentPath)) {
243
+ console.warn("[view]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
244
+ return;
245
+ }
246
+ if (depthChain.length > 20) {
247
+ console.warn("[view]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
248
+ return;
244
249
  }
245
- processedViewPaths.add(currentPath);
250
+ depthChain = [...depthChain, currentPath];
246
251
  const allScriptModules = [];
247
252
  const currentInstruction = compileModule(module2, isComponent, scriptRes);
248
253
  if (currentInstruction && currentInstruction.scriptModule) {
@@ -255,10 +260,10 @@ function buildCompileView(module2, isComponent = false, scriptRes, depthChain =
255
260
  continue;
256
261
  }
257
262
  if (componentModule.path === module2.path) {
258
- console.warn("[view]", `检测到自依赖,跳过处理: ${module2.path}`);
263
+ console.warn("[view]", `检测到循环依赖,跳过处理: ${module2.path}`);
259
264
  continue;
260
265
  }
261
- const componentInstruction = buildCompileView(componentModule, true, scriptRes);
266
+ const componentInstruction = buildCompileView(componentModule, true, scriptRes, depthChain);
262
267
  if (componentInstruction && componentInstruction.scriptModule) {
263
268
  for (const sm of componentInstruction.scriptModule) {
264
269
  if (!allScriptModules.find((existing) => existing.path === sm.path)) {
@@ -355,7 +360,10 @@ function compileModule(module2, isComponent, scriptRes) {
355
360
  insertWxsToRenderAst(ast, instruction.scriptModule, scriptRes);
356
361
  code2 = babel.transformFromAstSync(ast, "", {
357
362
  comments: false,
358
- sourceType: "script"
363
+ sourceType: "script",
364
+ plugins: [
365
+ pluginTransformArrowFunctions
366
+ ]
359
367
  }).code;
360
368
  tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
361
369
  }
@@ -364,7 +372,10 @@ function compileModule(module2, isComponent, scriptRes) {
364
372
  insertWxsToRenderAst(tplAst, instruction.scriptModule, scriptRes);
365
373
  const { code: transCode } = babel.transformFromAstSync(tplAst, "", {
366
374
  comments: false,
367
- sourceType: "script"
375
+ sourceType: "script",
376
+ plugins: [
377
+ pluginTransformArrowFunctions
378
+ ]
368
379
  });
369
380
  const code = `Module({
370
381
  path: '${module2.path}',
@@ -497,7 +508,10 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
497
508
  });
498
509
  return babel.transformFromAstSync(wxsAst, "", {
499
510
  comments: false,
500
- sourceType: "script"
511
+ sourceType: "script",
512
+ plugins: [
513
+ pluginTransformArrowFunctions
514
+ ]
501
515
  }).code;
502
516
  }
503
517
  function isWxsModuleByContent(moduleCode, modulePath = "") {
@@ -572,7 +586,10 @@ function compileModuleWithAllWxs(module2, scriptRes, allScriptModules) {
572
586
  insertWxsToRenderAst(ast, allScriptModules, scriptRes);
573
587
  code2 = babel.transformFromAstSync(ast, "", {
574
588
  comments: false,
575
- sourceType: "script"
589
+ sourceType: "script",
590
+ plugins: [
591
+ pluginTransformArrowFunctions
592
+ ]
576
593
  }).code;
577
594
  tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
578
595
  }
@@ -581,7 +598,10 @@ function compileModuleWithAllWxs(module2, scriptRes, allScriptModules) {
581
598
  insertWxsToRenderAst(tplAst, allScriptModules, scriptRes);
582
599
  const { code: transCode } = babel.transformFromAstSync(tplAst, "", {
583
600
  comments: false,
584
- sourceType: "script"
601
+ sourceType: "script",
602
+ plugins: [
603
+ pluginTransformArrowFunctions
604
+ ]
585
605
  });
586
606
  const code = `Module({
587
607
  path: '${module2.path}',
@@ -4,6 +4,7 @@ import { isMainThread, parentPort } from "node:worker_threads";
4
4
  import babel from "@babel/core";
5
5
  import _traverse from "@babel/traverse";
6
6
  import types from "@babel/types";
7
+ import pluginTransformArrowFunctions from "@babel/plugin-transform-arrow-functions";
7
8
  import { compileTemplate } from "@vue/compiler-sfc";
8
9
  import * as cheerio from "cheerio";
9
10
  import { transform } from "esbuild";
@@ -120,7 +121,6 @@ const fileType = [".wxml", ".ddml"];
120
121
  const compileResCache = /* @__PURE__ */ new Map();
121
122
  const wxsModuleRegistry = /* @__PURE__ */ new Set();
122
123
  const wxsFilePathMap = /* @__PURE__ */ new Map();
123
- const processedViewPaths = /* @__PURE__ */ new Set();
124
124
  if (!isMainThread) {
125
125
  parentPort.on("message", async ({ pages, storeInfo }) => {
126
126
  try {
@@ -219,10 +219,15 @@ function isRegisteredWxsModule(modulePath) {
219
219
  }
220
220
  function buildCompileView(module, isComponent = false, scriptRes, depthChain = []) {
221
221
  const currentPath = module.path;
222
- if (processedViewPaths.has(currentPath)) {
223
- return null;
222
+ if (depthChain.includes(currentPath)) {
223
+ console.warn("[view]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
224
+ return;
225
+ }
226
+ if (depthChain.length > 20) {
227
+ console.warn("[view]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
228
+ return;
224
229
  }
225
- processedViewPaths.add(currentPath);
230
+ depthChain = [...depthChain, currentPath];
226
231
  const allScriptModules = [];
227
232
  const currentInstruction = compileModule(module, isComponent, scriptRes);
228
233
  if (currentInstruction && currentInstruction.scriptModule) {
@@ -235,10 +240,10 @@ function buildCompileView(module, isComponent = false, scriptRes, depthChain = [
235
240
  continue;
236
241
  }
237
242
  if (componentModule.path === module.path) {
238
- console.warn("[view]", `检测到自依赖,跳过处理: ${module.path}`);
243
+ console.warn("[view]", `检测到循环依赖,跳过处理: ${module.path}`);
239
244
  continue;
240
245
  }
241
- const componentInstruction = buildCompileView(componentModule, true, scriptRes);
246
+ const componentInstruction = buildCompileView(componentModule, true, scriptRes, depthChain);
242
247
  if (componentInstruction && componentInstruction.scriptModule) {
243
248
  for (const sm of componentInstruction.scriptModule) {
244
249
  if (!allScriptModules.find((existing) => existing.path === sm.path)) {
@@ -335,7 +340,10 @@ function compileModule(module, isComponent, scriptRes) {
335
340
  insertWxsToRenderAst(ast, instruction.scriptModule, scriptRes);
336
341
  code2 = babel.transformFromAstSync(ast, "", {
337
342
  comments: false,
338
- sourceType: "script"
343
+ sourceType: "script",
344
+ plugins: [
345
+ pluginTransformArrowFunctions
346
+ ]
339
347
  }).code;
340
348
  tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
341
349
  }
@@ -344,7 +352,10 @@ function compileModule(module, isComponent, scriptRes) {
344
352
  insertWxsToRenderAst(tplAst, instruction.scriptModule, scriptRes);
345
353
  const { code: transCode } = babel.transformFromAstSync(tplAst, "", {
346
354
  comments: false,
347
- sourceType: "script"
355
+ sourceType: "script",
356
+ plugins: [
357
+ pluginTransformArrowFunctions
358
+ ]
348
359
  });
349
360
  const code = `Module({
350
361
  path: '${module.path}',
@@ -477,7 +488,10 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
477
488
  });
478
489
  return babel.transformFromAstSync(wxsAst, "", {
479
490
  comments: false,
480
- sourceType: "script"
491
+ sourceType: "script",
492
+ plugins: [
493
+ pluginTransformArrowFunctions
494
+ ]
481
495
  }).code;
482
496
  }
483
497
  function isWxsModuleByContent(moduleCode, modulePath = "") {
@@ -552,7 +566,10 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
552
566
  insertWxsToRenderAst(ast, allScriptModules, scriptRes);
553
567
  code2 = babel.transformFromAstSync(ast, "", {
554
568
  comments: false,
555
- sourceType: "script"
569
+ sourceType: "script",
570
+ plugins: [
571
+ pluginTransformArrowFunctions
572
+ ]
556
573
  }).code;
557
574
  tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
558
575
  }
@@ -561,7 +578,10 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
561
578
  insertWxsToRenderAst(tplAst, allScriptModules, scriptRes);
562
579
  const { code: transCode } = babel.transformFromAstSync(tplAst, "", {
563
580
  comments: false,
564
- sourceType: "script"
581
+ sourceType: "script",
582
+ plugins: [
583
+ pluginTransformArrowFunctions
584
+ ]
565
585
  });
566
586
  const code = `Module({
567
587
  path: '${module.path}',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.12-beta.3",
3
+ "version": "1.0.12-beta.6",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -48,6 +48,7 @@
48
48
  ],
49
49
  "dependencies": {
50
50
  "@babel/core": "^7.28.5",
51
+ "@babel/plugin-transform-arrow-functions": "^7.27.1",
51
52
  "@babel/plugin-transform-modules-commonjs": "^7.27.1",
52
53
  "@babel/traverse": "^7.28.5",
53
54
  "@babel/types": "^7.28.5",