@dimina/compiler 1.0.12-beta.2 → 1.0.12-beta.5

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.0";
8
+ const version = "1.0.12-beta.4";
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.0";
7
+ const version = "1.0.12-beta.4";
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,12 +245,14 @@ 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) {
251
+ const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
241
252
  const assignmentExpression = types.assignmentExpression(
242
253
  "=",
243
- types.memberExpression(types.identifier("globalThis"), types.identifier("__extraInfo")),
244
- addedArgs
254
+ types.memberExpression(types.identifier("globalThis"), propertyAssignment.key),
255
+ propertyAssignment.value
245
256
  );
246
257
  return types.expressionStatement(assignmentExpression);
247
258
  }
@@ -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,12 +243,14 @@ 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) {
249
+ const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
239
250
  const assignmentExpression = types.assignmentExpression(
240
251
  "=",
241
- types.memberExpression(types.identifier("globalThis"), types.identifier("__extraInfo")),
242
- addedArgs
252
+ types.memberExpression(types.identifier("globalThis"), propertyAssignment.key),
253
+ propertyAssignment.value
243
254
  );
244
255
  return types.expressionStatement(assignmentExpression);
245
256
  }
@@ -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;
@@ -140,7 +140,6 @@ const fileType = [".wxml", ".ddml"];
140
140
  const compileResCache = /* @__PURE__ */ new Map();
141
141
  const wxsModuleRegistry = /* @__PURE__ */ new Set();
142
142
  const wxsFilePathMap = /* @__PURE__ */ new Map();
143
- const processedViewPaths = /* @__PURE__ */ new Set();
144
143
  if (!node_worker_threads.isMainThread) {
145
144
  node_worker_threads.parentPort.on("message", async ({ pages, storeInfo }) => {
146
145
  try {
@@ -239,10 +238,15 @@ function isRegisteredWxsModule(modulePath) {
239
238
  }
240
239
  function buildCompileView(module2, isComponent = false, scriptRes, depthChain = []) {
241
240
  const currentPath = module2.path;
242
- if (processedViewPaths.has(currentPath)) {
243
- return null;
241
+ if (depthChain.includes(currentPath)) {
242
+ console.warn("[view]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
243
+ return;
244
244
  }
245
- processedViewPaths.add(currentPath);
245
+ if (depthChain.length > 20) {
246
+ console.warn("[view]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
247
+ return;
248
+ }
249
+ depthChain = [...depthChain, currentPath];
246
250
  const allScriptModules = [];
247
251
  const currentInstruction = compileModule(module2, isComponent, scriptRes);
248
252
  if (currentInstruction && currentInstruction.scriptModule) {
@@ -255,10 +259,10 @@ function buildCompileView(module2, isComponent = false, scriptRes, depthChain =
255
259
  continue;
256
260
  }
257
261
  if (componentModule.path === module2.path) {
258
- console.warn("[view]", `检测到自依赖,跳过处理: ${module2.path}`);
262
+ console.warn("[view]", `检测到循环依赖,跳过处理: ${module2.path}`);
259
263
  continue;
260
264
  }
261
- const componentInstruction = buildCompileView(componentModule, true, scriptRes);
265
+ const componentInstruction = buildCompileView(componentModule, true, scriptRes, depthChain);
262
266
  if (componentInstruction && componentInstruction.scriptModule) {
263
267
  for (const sm of componentInstruction.scriptModule) {
264
268
  if (!allScriptModules.find((existing) => existing.path === sm.path)) {
@@ -357,7 +361,7 @@ function compileModule(module2, isComponent, scriptRes) {
357
361
  comments: false,
358
362
  sourceType: "script"
359
363
  }).code;
360
- tplComponents += `'${tm.path}':${code2.replace(/;$/, "")},`;
364
+ tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
361
365
  }
362
366
  tplComponents += "}";
363
367
  const tplAst = babel.parseSync(tplCode.code);
@@ -369,7 +373,7 @@ function compileModule(module2, isComponent, scriptRes) {
369
373
  const code = `Module({
370
374
  path: '${module2.path}',
371
375
  id: '${module2.id}',
372
- render: ${transCode.replace(/;$/, "")},
376
+ render: ${cleanCompiledCode(transCode)},
373
377
  usingComponents: ${JSON.stringify(module2.usingComponents)},
374
378
  tplComponents: ${tplComponents},
375
379
  });`;
@@ -574,7 +578,7 @@ function compileModuleWithAllWxs(module2, scriptRes, allScriptModules) {
574
578
  comments: false,
575
579
  sourceType: "script"
576
580
  }).code;
577
- tplComponents += `'${tm.path}':${code2.replace(/;$/, "").replace(/^"use strict";\s*/, "")},`;
581
+ tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
578
582
  }
579
583
  tplComponents += "}";
580
584
  const tplAst = babel.parseSync(tplCode.code);
@@ -586,7 +590,7 @@ function compileModuleWithAllWxs(module2, scriptRes, allScriptModules) {
586
590
  const code = `Module({
587
591
  path: '${module2.path}',
588
592
  id: '${module2.id}',
589
- render: ${transCode.replace(/;$/, "").replace(/^"use strict";\s*/, "")},
593
+ render: ${cleanCompiledCode(transCode)},
590
594
  usingComponents: ${JSON.stringify(module2.usingComponents)},
591
595
  tplComponents: ${tplComponents},
592
596
  });`;
@@ -656,6 +660,9 @@ function processIncludedFileWxsDependencies(content, includePath, scriptModule,
656
660
  }
657
661
  }
658
662
  }
663
+ function cleanCompiledCode(code) {
664
+ return code.replace(/;$/, "").replace(/^"use strict";\s*/, "");
665
+ }
659
666
  function toCompileTemplate(isComponent, path2, components, componentPlaceholder, processedPaths = /* @__PURE__ */ new Set()) {
660
667
  const workPath = env.getWorkPath();
661
668
  const fullPath = getViewPath(workPath, path2);
@@ -120,7 +120,6 @@ const fileType = [".wxml", ".ddml"];
120
120
  const compileResCache = /* @__PURE__ */ new Map();
121
121
  const wxsModuleRegistry = /* @__PURE__ */ new Set();
122
122
  const wxsFilePathMap = /* @__PURE__ */ new Map();
123
- const processedViewPaths = /* @__PURE__ */ new Set();
124
123
  if (!isMainThread) {
125
124
  parentPort.on("message", async ({ pages, storeInfo }) => {
126
125
  try {
@@ -219,10 +218,15 @@ function isRegisteredWxsModule(modulePath) {
219
218
  }
220
219
  function buildCompileView(module, isComponent = false, scriptRes, depthChain = []) {
221
220
  const currentPath = module.path;
222
- if (processedViewPaths.has(currentPath)) {
223
- return null;
221
+ if (depthChain.includes(currentPath)) {
222
+ console.warn("[view]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
223
+ return;
224
224
  }
225
- processedViewPaths.add(currentPath);
225
+ if (depthChain.length > 20) {
226
+ console.warn("[view]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
227
+ return;
228
+ }
229
+ depthChain = [...depthChain, currentPath];
226
230
  const allScriptModules = [];
227
231
  const currentInstruction = compileModule(module, isComponent, scriptRes);
228
232
  if (currentInstruction && currentInstruction.scriptModule) {
@@ -235,10 +239,10 @@ function buildCompileView(module, isComponent = false, scriptRes, depthChain = [
235
239
  continue;
236
240
  }
237
241
  if (componentModule.path === module.path) {
238
- console.warn("[view]", `检测到自依赖,跳过处理: ${module.path}`);
242
+ console.warn("[view]", `检测到循环依赖,跳过处理: ${module.path}`);
239
243
  continue;
240
244
  }
241
- const componentInstruction = buildCompileView(componentModule, true, scriptRes);
245
+ const componentInstruction = buildCompileView(componentModule, true, scriptRes, depthChain);
242
246
  if (componentInstruction && componentInstruction.scriptModule) {
243
247
  for (const sm of componentInstruction.scriptModule) {
244
248
  if (!allScriptModules.find((existing) => existing.path === sm.path)) {
@@ -337,7 +341,7 @@ function compileModule(module, isComponent, scriptRes) {
337
341
  comments: false,
338
342
  sourceType: "script"
339
343
  }).code;
340
- tplComponents += `'${tm.path}':${code2.replace(/;$/, "")},`;
344
+ tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
341
345
  }
342
346
  tplComponents += "}";
343
347
  const tplAst = babel.parseSync(tplCode.code);
@@ -349,7 +353,7 @@ function compileModule(module, isComponent, scriptRes) {
349
353
  const code = `Module({
350
354
  path: '${module.path}',
351
355
  id: '${module.id}',
352
- render: ${transCode.replace(/;$/, "")},
356
+ render: ${cleanCompiledCode(transCode)},
353
357
  usingComponents: ${JSON.stringify(module.usingComponents)},
354
358
  tplComponents: ${tplComponents},
355
359
  });`;
@@ -554,7 +558,7 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
554
558
  comments: false,
555
559
  sourceType: "script"
556
560
  }).code;
557
- tplComponents += `'${tm.path}':${code2.replace(/;$/, "").replace(/^"use strict";\s*/, "")},`;
561
+ tplComponents += `'${tm.path}':${cleanCompiledCode(code2)},`;
558
562
  }
559
563
  tplComponents += "}";
560
564
  const tplAst = babel.parseSync(tplCode.code);
@@ -566,7 +570,7 @@ function compileModuleWithAllWxs(module, scriptRes, allScriptModules) {
566
570
  const code = `Module({
567
571
  path: '${module.path}',
568
572
  id: '${module.id}',
569
- render: ${transCode.replace(/;$/, "").replace(/^"use strict";\s*/, "")},
573
+ render: ${cleanCompiledCode(transCode)},
570
574
  usingComponents: ${JSON.stringify(module.usingComponents)},
571
575
  tplComponents: ${tplComponents},
572
576
  });`;
@@ -636,6 +640,9 @@ function processIncludedFileWxsDependencies(content, includePath, scriptModule,
636
640
  }
637
641
  }
638
642
  }
643
+ function cleanCompiledCode(code) {
644
+ return code.replace(/;$/, "").replace(/^"use strict";\s*/, "");
645
+ }
639
646
  function toCompileTemplate(isComponent, path2, components, componentPlaceholder, processedPaths = /* @__PURE__ */ new Set()) {
640
647
  const workPath = getWorkPath();
641
648
  const fullPath = getViewPath(workPath, path2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.12-beta.2",
3
+ "version": "1.0.12-beta.5",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",