@dimina/compiler 1.0.1 → 1.0.2

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 CHANGED
@@ -1,6 +1,8 @@
1
1
  # 星河小程序编译工具
2
2
 
3
- ## compiler 编译工具
3
+ [![npm version](https://img.shields.io/npm/v/@dimina/compiler.svg?style=flat)](https://www.npmjs.com/package/@dimina/compiler)
4
+
5
+ ## 编译工具
4
6
 
5
7
  星河小程序编译工具(dmcc)用于将小程序源码编译为星河小程序运行时所需的文件格式。
6
8
 
@@ -5,7 +5,7 @@ const path = require("node:path");
5
5
  const commander = require("commander");
6
6
  const chokidar = require("chokidar");
7
7
  const index = require("../index.cjs");
8
- const version = "1.0.1";
8
+ const version = "1.0.2";
9
9
  const pack = {
10
10
  version
11
11
  };
package/dist/bin/index.js CHANGED
@@ -4,7 +4,7 @@ import path from "node:path";
4
4
  import { program } from "commander";
5
5
  import chokidar from "chokidar";
6
6
  import build from "../index.js";
7
- const version = "1.0.1";
7
+ const version = "1.0.2";
8
8
  const pack = {
9
9
  version
10
10
  };
@@ -79,7 +79,7 @@ async function compileJS(pages, root, mainCompileRes, progress) {
79
79
  });
80
80
  return compileRes;
81
81
  }
82
- function buildJSByPath(root, module2, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
82
+ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
83
83
  const currentPath = module2.path;
84
84
  if (depthChain.includes(currentPath)) {
85
85
  console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
@@ -114,8 +114,8 @@ function buildJSByPath(root, module2, compileRes, mainCompileRes, addExtra, dept
114
114
  const allSubPackages = env.getAppConfigInfo().subPackages;
115
115
  for (const [name, path2] of Object.entries(module2.usingComponents)) {
116
116
  let toMainSubPackage = true;
117
- if (root) {
118
- const rootPackageName = root.split("_")[1];
117
+ if (packageName) {
118
+ const rootPackageName = packageName.startsWith("sub_") ? packageName.slice(4) : packageName;
119
119
  const normalizedPath = path2.startsWith("/") ? path2.substring(1) : path2;
120
120
  for (const subPackage of allSubPackages) {
121
121
  if (normalizedPath.startsWith(`${subPackage.root}/`)) {
@@ -135,7 +135,7 @@ function buildJSByPath(root, module2, compileRes, mainCompileRes, addExtra, dept
135
135
  if (!componentModule) {
136
136
  continue;
137
137
  }
138
- buildJSByPath(root, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
138
+ buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
139
139
  const props = types.objectProperty(types.identifier(`'${name}'`), types.stringLiteral(path2));
140
140
  components.value.properties.push(props);
141
141
  }
@@ -158,7 +158,7 @@ function buildJSByPath(root, module2, compileRes, mainCompileRes, addExtra, dept
158
158
  const id = requireFullPath.split(`${env.getWorkPath()}/`)[1].split(".js")[0];
159
159
  ap.node.arguments[0] = types.stringLiteral(id);
160
160
  if (!processedModules.has(id)) {
161
- buildJSByPath(root, { path: id }, compileRes, mainCompileRes, false, depthChain);
161
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
162
162
  }
163
163
  }
164
164
  }
@@ -78,7 +78,7 @@ async function compileJS(pages, root, mainCompileRes, progress) {
78
78
  });
79
79
  return compileRes;
80
80
  }
81
- function buildJSByPath(root, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
81
+ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
82
82
  const currentPath = module.path;
83
83
  if (depthChain.includes(currentPath)) {
84
84
  console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
@@ -113,8 +113,8 @@ function buildJSByPath(root, module, compileRes, mainCompileRes, addExtra, depth
113
113
  const allSubPackages = getAppConfigInfo().subPackages;
114
114
  for (const [name, path] of Object.entries(module.usingComponents)) {
115
115
  let toMainSubPackage = true;
116
- if (root) {
117
- const rootPackageName = root.split("_")[1];
116
+ if (packageName) {
117
+ const rootPackageName = packageName.startsWith("sub_") ? packageName.slice(4) : packageName;
118
118
  const normalizedPath = path.startsWith("/") ? path.substring(1) : path;
119
119
  for (const subPackage of allSubPackages) {
120
120
  if (normalizedPath.startsWith(`${subPackage.root}/`)) {
@@ -134,7 +134,7 @@ function buildJSByPath(root, module, compileRes, mainCompileRes, addExtra, depth
134
134
  if (!componentModule) {
135
135
  continue;
136
136
  }
137
- buildJSByPath(root, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
137
+ buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, toMainSubPackage);
138
138
  const props = types.objectProperty(types.identifier(`'${name}'`), types.stringLiteral(path));
139
139
  components.value.properties.push(props);
140
140
  }
@@ -157,7 +157,7 @@ function buildJSByPath(root, module, compileRes, mainCompileRes, addExtra, depth
157
157
  const id = requireFullPath.split(`${getWorkPath()}/`)[1].split(".js")[0];
158
158
  ap.node.arguments[0] = types.stringLiteral(id);
159
159
  if (!processedModules.has(id)) {
160
- buildJSByPath(root, { path: id }, compileRes, mainCompileRes, false, depthChain);
160
+ buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
161
161
  }
162
162
  }
163
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",