@dimina/compiler 1.0.16 → 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/dist/index.js CHANGED
@@ -1,11 +1,65 @@
1
- import { c as getPages, l as getTargetPath, m as collectAssets, n as getAppId, p as storeInfo, r as getAppName, s as getPageConfigInfo, t as getAppConfigInfo, u as getWorkPath, y as art_default } from "./env-p9Az8lv5.js";
1
+ import { c as getPageConfigInfo, d as getTargetPath, f as getTemplateExts, h as getWorkPath, i as getAppStyleScopeId, l as getPages, n as getAppId, p as getViewScriptExts, r as getAppName, t as getAppConfigInfo, u as getStyleExts, v as storeInfo, y as collectAssets } from "./env-OH3--qg8.js";
2
2
  import path from "node:path";
3
+ import process from "node:process";
3
4
  import { fileURLToPath } from "node:url";
4
5
  import { Worker } from "node:worker_threads";
5
- import { Listr } from "listr2";
6
- import process from "node:process";
6
+ import { Listr, PRESET_TIMER, isUnicodeSupported } from "listr2";
7
7
  import fs from "node:fs";
8
8
  import os from "node:os";
9
+ //#region src/common/compile-progress.js
10
+ var DEFAULT_TERMINAL_COLUMNS = 80;
11
+ var MIN_PROGRESS_WIDTH = 8;
12
+ var MAX_PROGRESS_WIDTH = 28;
13
+ var RENDERER_CHROME_WIDTH = 14;
14
+ var PROGRESS_BRACKETS_WIDTH = 2;
15
+ /**
16
+ * Format worker progress without assuming a fixed terminal width.
17
+ * The completed count remains the source of truth. Whole cells avoid the
18
+ * visible gap that partial block glyphs leave before the unfilled section.
19
+ */
20
+ function formatCompileProgress(completed, total, options = {}) {
21
+ const unicode = options.unicode ?? isUnicodeSupported();
22
+ const columns = normalizePositiveInteger(options.columns) || process.stdout.columns || DEFAULT_TERMINAL_COLUMNS;
23
+ const safeTotal = normalizePositiveInteger(total);
24
+ const safeCompleted = Math.min(normalizePositiveInteger(completed), safeTotal);
25
+ const ratio = safeTotal === 0 ? 0 : safeCompleted / safeTotal;
26
+ const percentage = Math.round(ratio * 100);
27
+ const separator = unicode ? "·" : "|";
28
+ const metadata = `${String(safeCompleted).padStart(String(safeTotal).length)}/${safeTotal} ${separator} ${String(percentage).padStart(3)}%`;
29
+ const availableWidth = columns - metadata.length - RENDERER_CHROME_WIDTH - PROGRESS_BRACKETS_WIDTH;
30
+ if (availableWidth < MIN_PROGRESS_WIDTH) return metadata;
31
+ const width = Math.min(availableWidth, MAX_PROGRESS_WIDTH);
32
+ return `[${unicode ? createUnicodeBar(ratio, width) : createAsciiBar(ratio, width)}] ${metadata}`;
33
+ }
34
+ function createUnicodeBar(ratio, width) {
35
+ const completeWidth = Math.round(ratio * width);
36
+ const emptyWidth = width - completeWidth;
37
+ return `${"█".repeat(completeWidth)}${"░".repeat(emptyWidth)}`;
38
+ }
39
+ function createAsciiBar(ratio, width) {
40
+ const completeWidth = Math.floor(ratio * width);
41
+ const showHead = ratio > 0 && ratio < 1;
42
+ const bodyWidth = Math.max(0, completeWidth - (showHead ? 1 : 0));
43
+ const emptyWidth = width - bodyWidth - (showHead ? 1 : 0);
44
+ return `${"=".repeat(bodyWidth)}${showHead ? ">" : ""}${"-".repeat(emptyWidth)}`;
45
+ }
46
+ function normalizePositiveInteger(value) {
47
+ return Number.isFinite(value) ? Math.max(0, Math.trunc(value)) : 0;
48
+ }
49
+ //#endregion
50
+ //#region src/common/art.js
51
+ var artCode = `
52
+ ██████╗ ██╗███╗ ███╗██╗███╗ ██╗ █████╗
53
+ ██╔══██╗██║████╗ ████║██║████╗ ██║██╔══██╗
54
+ ██║ ██║██║██╔████╔██║██║██╔██╗ ██║███████║
55
+ ██║ ██║██║██║╚██╔╝██║██║██║╚██╗██║██╔══██║
56
+ ██████╔╝██║██║ ╚═╝ ██║██║██║ ╚████║██║ ██║
57
+ ╚═════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝
58
+ `;
59
+ function art_default() {
60
+ console.log(artCode);
61
+ }
62
+ //#endregion
9
63
  //#region src/common/publish.js
10
64
  function createDist() {
11
65
  const distPath = getTargetPath();
@@ -187,13 +241,10 @@ var NpmBuilder = class {
187
241
  const miniprogramExts = [
188
242
  ".js",
189
243
  ".json",
190
- ".wxml",
191
- ".wxss",
192
- ".wxs",
193
244
  ".ts",
194
- ".less",
195
- ".scss",
196
- ".styl"
245
+ ...getTemplateExts(),
246
+ ...getStyleExts(),
247
+ ...getViewScriptExts()
197
248
  ];
198
249
  const ext = path.extname(filename).toLowerCase();
199
250
  return miniprogramExts.includes(ext) || filename === "package.json" || filename === "README.md" || filename.startsWith(".");
@@ -308,26 +359,32 @@ function compileConfig() {
308
359
  //#endregion
309
360
  //#region src/index.js
310
361
  var isPrinted = false;
362
+ var previousCompatibilityWarnings = /* @__PURE__ */ new Map();
311
363
  /**
312
364
  * 构建命令入口
313
365
  * @param {string} targetPath 编译产物目标路径
314
366
  * @param {string} workPath 编译工作目录
315
- * @param {boolean} useAppIdDir 产物根目录是否包含appId
367
+ * @param {boolean} useAppIdDir 产物根目录是否包含 appId
368
+ * @param {object} [options] 构建选项
369
+ * @param {boolean} [options.sourcemap] 是否生成 sourcemap
370
+ * @param {{ template?: string[], style?: string[], viewScript?: string[] }} [options.fileTypes]
371
+ * 自定义文件类型,在内置 wx/dd 类型基础上追加;template 为模板扩展名,style 为样式扩展名,
372
+ * viewScript 为视图脚本扩展名和内联标签名
316
373
  */
317
374
  async function build(targetPath, workPath, useAppIdDir = true, options = {}) {
318
- const { sourcemap = false } = options;
375
+ const { sourcemap = false, fileTypes } = options;
319
376
  if (!isPrinted) {
320
377
  art_default();
321
378
  isPrinted = true;
322
379
  }
323
380
  const tasks = new Listr([
324
381
  {
325
- title: "准备项目编译环境",
382
+ title: "初始化项目",
326
383
  task: (_, task) => task.newListr([
327
384
  {
328
385
  title: "收集配置信息",
329
386
  task: (ctx) => {
330
- ctx.storeInfo = storeInfo(workPath);
387
+ ctx.storeInfo = storeInfo(workPath, { fileTypes });
331
388
  }
332
389
  },
333
390
  {
@@ -351,29 +408,42 @@ async function build(targetPath, workPath, useAppIdDir = true, options = {}) {
351
408
  ], { concurrent: false })
352
409
  },
353
410
  {
354
- title: `开始编译:${workPath.split("/").pop()}`,
411
+ title: `编译项目 · ${path.basename(path.resolve(workPath))}`,
355
412
  task: (ctx, task) => {
356
413
  const pages = getPages();
357
414
  ctx.pages = pages;
415
+ ctx.compatibilityWarnings = /* @__PURE__ */ new Set();
358
416
  return task.newListr([
359
417
  {
360
- title: "编译页面文件",
418
+ title: "编译视图",
419
+ rendererOptions: {
420
+ outputBar: true,
421
+ persistentOutput: false
422
+ },
361
423
  task: async (ctx, task) => {
362
424
  return runCompileInWorker("view", ctx, task, { sourcemap });
363
425
  }
364
426
  },
365
427
  {
366
- title: "编译页面逻辑",
428
+ title: "编译逻辑",
429
+ rendererOptions: {
430
+ outputBar: true,
431
+ persistentOutput: false
432
+ },
367
433
  task: async (ctx, task) => {
368
434
  return runCompileInWorker("logic", ctx, task, { sourcemap });
369
435
  }
370
436
  },
371
437
  {
372
- title: "编译样式文件",
438
+ title: "编译样式",
439
+ rendererOptions: {
440
+ outputBar: true,
441
+ persistentOutput: false
442
+ },
373
443
  task: async (ctx, task) => {
374
444
  pages.mainPages.unshift({
375
445
  path: "app",
376
- id: ""
446
+ id: getAppStyleScopeId()
377
447
  });
378
448
  return runCompileInWorker("style", ctx, task, { sourcemap });
379
449
  }
@@ -382,14 +452,23 @@ async function build(targetPath, workPath, useAppIdDir = true, options = {}) {
382
452
  }
383
453
  },
384
454
  {
385
- title: "输出编译产物",
455
+ title: "写入编译产物",
386
456
  task: () => {
387
457
  publishToDist(targetPath, useAppIdDir);
388
458
  }
389
459
  }
390
- ], { concurrent: false });
460
+ ], {
461
+ concurrent: false,
462
+ rendererOptions: {
463
+ collapseSubtasks: true,
464
+ formatOutput: "truncate",
465
+ timer: PRESET_TIMER
466
+ },
467
+ fallbackRendererOptions: { timer: PRESET_TIMER }
468
+ });
391
469
  try {
392
470
  const context = await tasks.run();
471
+ printCompatibilityWarnings(workPath, context.compatibilityWarnings);
393
472
  return {
394
473
  appId: getAppId(),
395
474
  name: getAppName(),
@@ -418,16 +497,12 @@ function runCompileInWorker(script, ctx, task, options = {}) {
418
497
  });
419
498
  worker.on("message", (message) => {
420
499
  try {
421
- if (message.completedTasks) {
422
- const progress = message.completedTasks / totalTasks;
423
- const percentage = progress * 100;
424
- const barLength = 30;
425
- const filledLength = Math.ceil(barLength * progress);
426
- task.output = `[${"█".repeat(filledLength) + "░".repeat(barLength - filledLength)}] ${percentage.toFixed(2)}%`;
427
- }
500
+ for (const warning of message.compatibilityWarnings || []) ctx.compatibilityWarnings.add(warning);
501
+ if (process.stdout.isTTY && message.completedTasks !== void 0) task.output = formatCompileProgress(message.completedTasks, totalTasks);
428
502
  if (message.success) {
429
503
  if (isResolved) return;
430
504
  isResolved = true;
505
+ if (process.stdout.isTTY && totalTasks > 0) task.output = formatCompileProgress(totalTasks, totalTasks);
431
506
  worker.terminate();
432
507
  resolve();
433
508
  } else if (message.error) {
@@ -446,9 +521,25 @@ function runCompileInWorker(script, ctx, task, options = {}) {
446
521
  handleError(err);
447
522
  });
448
523
  worker.on("exit", (code) => {
449
- if (code !== 0 && !isResolved) handleError(workerError || /* @__PURE__ */ new Error(code === 1 ? "Worker terminated due to reaching memory limit: JS heap out of memory" : `Worker stopped with exit code ${code}`));
524
+ if (code !== 0 && !isResolved) {
525
+ const error = workerError || /* @__PURE__ */ new Error(code === 1 ? "Worker terminated due to reaching memory limit: JS heap out of memory" : `Worker stopped with exit code ${code}`);
526
+ handleError(error);
527
+ }
450
528
  });
451
529
  }));
452
530
  }
531
+ function printCompatibilityWarnings(workPath, warnings = /* @__PURE__ */ new Set()) {
532
+ const projectPath = path.resolve(workPath);
533
+ const hasPreviousResult = previousCompatibilityWarnings.has(projectPath);
534
+ const previousWarnings = previousCompatibilityWarnings.get(projectPath) || /* @__PURE__ */ new Set();
535
+ const currentWarnings = new Set(warnings);
536
+ const newWarnings = [...currentWarnings].filter((warning) => !previousWarnings.has(warning));
537
+ previousCompatibilityWarnings.set(projectPath, currentWarnings);
538
+ if (newWarnings.length === 0) return;
539
+ const qualifier = hasPreviousResult ? " new" : "";
540
+ const suffix = newWarnings.length === 1 ? "" : "s";
541
+ console.warn(`\n[compat] ${newWarnings.length}${qualifier} compatibility warning${suffix}`);
542
+ for (const warning of newWarnings) console.warn(` - ${warning.replace(/^\[compat\]\s*/, "")}`);
543
+ }
453
544
  //#endregion
454
545
  export { build as default };
@@ -0,0 +1,28 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ Object.defineProperty(exports, "__toESM", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return __toESM;
27
+ }
28
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.16",
3
+ "version": "1.1.0",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -43,6 +43,9 @@
43
43
  },
44
44
  "author": "doslin",
45
45
  "license": "Apache-2.0",
46
+ "engines": {
47
+ "node": ">=20"
48
+ },
46
49
  "keywords": [
47
50
  "dimina",
48
51
  "compiler",
@@ -51,22 +54,23 @@
51
54
  "星河"
52
55
  ],
53
56
  "dependencies": {
54
- "@vue/compiler-sfc": "^3.5.34",
55
- "autoprefixer": "^10.5.0",
57
+ "@vue/compiler-sfc": "^3.5.39",
58
+ "@vue/shared": "^3.5.39",
59
+ "autoprefixer": "^10.5.3",
56
60
  "cheerio": "^1.2.0",
57
61
  "chokidar": "^4.0.3",
58
62
  "commander": "^14.0.3",
59
- "cssnano": "^8.0.1",
60
- "esbuild": "^0.28.0",
63
+ "cssnano": "^8.0.2",
64
+ "esbuild": "^0.28.1",
61
65
  "htmlparser2": "^12.0.0",
62
- "less": "^4.6.4",
66
+ "less": "^4.6.7",
63
67
  "listr2": "^9.0.5",
64
68
  "magic-string": "^0.30.21",
65
- "oxc-parser": "^0.129.0",
66
- "oxc-walker": "^0.7.0",
67
- "postcss": "^8.5.14",
68
- "postcss-selector-parser": "^7.1.1",
69
- "sass": "^1.99.0",
69
+ "oxc-parser": "^0.139.0",
70
+ "oxc-walker": "^1.0.0",
71
+ "postcss": "^8.5.19",
72
+ "postcss-selector-parser": "^7.1.4",
73
+ "sass": "^1.101.0",
70
74
  "source-map-js": "^1.2.1"
71
75
  },
72
76
  "publishConfig": {