@dimina/compiler 1.0.1 → 1.0.3

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,14 +5,15 @@ 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.3";
9
9
  const pack = {
10
10
  version
11
11
  };
12
- commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").action(async (options) => {
12
+ commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
13
13
  const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
14
14
  const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
15
- await index(targetPath, workPath);
15
+ const useAppIdDir = options.appIdDir !== false;
16
+ await index(targetPath, workPath, useAppIdDir);
16
17
  const watch = options.watch;
17
18
  if (watch) {
18
19
  chokidar.watch(workPath, {
@@ -23,7 +24,7 @@ commander.program.command("build").option("-c, --work-path <path>", "编译工
23
24
  }).on("all", async (event, path2) => {
24
25
  if (event === "change") {
25
26
  console.log(`${path2} 改动,重新编译`);
26
- await index(targetPath, workPath);
27
+ await index(targetPath, workPath, useAppIdDir);
27
28
  }
28
29
  });
29
30
  }
package/dist/bin/index.js CHANGED
@@ -4,14 +4,15 @@ 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.3";
8
8
  const pack = {
9
9
  version
10
10
  };
11
- program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").action(async (options) => {
11
+ program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
12
12
  const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
13
13
  const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
14
- await build(targetPath, workPath);
14
+ const useAppIdDir = options.appIdDir !== false;
15
+ await build(targetPath, workPath, useAppIdDir);
15
16
  const watch = options.watch;
16
17
  if (watch) {
17
18
  chokidar.watch(workPath, {
@@ -22,7 +23,7 @@ program.command("build").option("-c, --work-path <path>", "编译工作目录").
22
23
  }).on("all", async (event, path2) => {
23
24
  if (event === "change") {
24
25
  console.log(`${path2} 改动,重新编译`);
25
- await build(targetPath, workPath);
26
+ await build(targetPath, workPath, useAppIdDir);
26
27
  }
27
28
  });
28
29
  }
@@ -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/dist/index.cjs CHANGED
@@ -39,10 +39,10 @@ function createDist() {
39
39
  }
40
40
  shelljs.mkdir("-p", `${distPath}`);
41
41
  }
42
- function publishToDist(dist) {
42
+ function publishToDist(dist, useAppIdDir = true) {
43
43
  const distPath = env.getTargetPath();
44
44
  const appId = env.getAppId();
45
- const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
45
+ const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
46
46
  shelljs.rm("-rf", absolutePath);
47
47
  shelljs.mkdir("-p", absolutePath);
48
48
  shelljs.cp("-r", `${distPath}/*`, absolutePath);
@@ -113,7 +113,7 @@ class WorkerPool {
113
113
  }
114
114
  const workerPool = new WorkerPool();
115
115
  let isPrinted = false;
116
- async function build(targetPath, workPath) {
116
+ async function build(targetPath, workPath, useAppIdDir = true) {
117
117
  if (!isPrinted) {
118
118
  artCode$1();
119
119
  isPrinted = true;
@@ -183,7 +183,7 @@ async function build(targetPath, workPath) {
183
183
  {
184
184
  title: "输出编译产物",
185
185
  task: () => {
186
- publishToDist(targetPath);
186
+ publishToDist(targetPath, useAppIdDir);
187
187
  }
188
188
  }
189
189
  ],
package/dist/index.js CHANGED
@@ -37,10 +37,10 @@ function createDist() {
37
37
  }
38
38
  shelljs.mkdir("-p", `${distPath}`);
39
39
  }
40
- function publishToDist(dist) {
40
+ function publishToDist(dist, useAppIdDir = true) {
41
41
  const distPath = getTargetPath();
42
42
  const appId = getAppId();
43
- const absolutePath = `${path.resolve(process.cwd(), dist)}/${appId}`;
43
+ const absolutePath = useAppIdDir ? `${path.resolve(process.cwd(), dist)}/${appId}` : `${path.resolve(process.cwd(), dist)}`;
44
44
  shelljs.rm("-rf", absolutePath);
45
45
  shelljs.mkdir("-p", absolutePath);
46
46
  shelljs.cp("-r", `${distPath}/*`, absolutePath);
@@ -111,7 +111,7 @@ class WorkerPool {
111
111
  }
112
112
  const workerPool = new WorkerPool();
113
113
  let isPrinted = false;
114
- async function build(targetPath, workPath) {
114
+ async function build(targetPath, workPath, useAppIdDir = true) {
115
115
  if (!isPrinted) {
116
116
  artCode$1();
117
117
  isPrinted = true;
@@ -181,7 +181,7 @@ async function build(targetPath, workPath) {
181
181
  {
182
182
  title: "输出编译产物",
183
183
  task: () => {
184
- publishToDist(targetPath);
184
+ publishToDist(targetPath, useAppIdDir);
185
185
  }
186
186
  }
187
187
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina/compiler",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "星河编译工具",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",