@unmagic/vms 0.1.0 → 0.1.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.
@@ -19,6 +19,7 @@ import { createRequire } from "node:module";
19
19
  import chokidar from "chokidar";
20
20
  import { getPackageInfo } from "local-pkg";
21
21
  import os from "node:os";
22
+ import process$1 from "node:process";
22
23
  import { rolldown } from "rolldown";
23
24
  import { minify } from "terser";
24
25
  import { performance } from "perf_hooks";
@@ -1007,7 +1008,7 @@ if (!userConfig.wx) throw new Error("请在vms.config.*s中配置完整的wx");
1007
1008
  process.env.APP_VERSION = userConfig.wx.version;
1008
1009
  if (!userConfig.sourceDir) userConfig.sourceDir = "src";
1009
1010
  if (!userConfig.outputDir) userConfig.outputDir = "dist";
1010
- const OUTPUT_DIR = path.resolve(userConfig.outputDir, "prod");
1011
+ const OUTPUT_DIR = path.resolve(userConfig.outputDir, "dev");
1011
1012
  const POLYFILL_OUTPUT_DIR = path.resolve(OUTPUT_DIR, "polyfill");
1012
1013
  const getComponentMatcher = new ComponentMatcher(userConfig.component);
1013
1014
  function findPolyfillDirectory(baseDir) {
@@ -1687,7 +1688,7 @@ function copyProjectConfigFile() {
1687
1688
  return fs$1.readJson(path.join(process.cwd(), "project.config.json")).then((config) => {
1688
1689
  Reflect.deleteProperty(config, "miniprogramRoot");
1689
1690
  Reflect.deleteProperty(config, "srcMiniprogramRoot");
1690
- config.projectName = config.projectName + "-prod";
1691
+ config.projectName = config.projectName + "-dev";
1691
1692
  return fs$1.writeFile(path.join(OUTPUT_DIR, "project.config.json"), JSON.stringify(config, null, 2));
1692
1693
  });
1693
1694
  }
@@ -2170,9 +2171,10 @@ function getTemplateNodeProp(node, prop, returnValue, counter, wxsExpressionStat
2170
2171
  * 2. babelParse(code) — 重新解析为完整 AST
2171
2172
  *
2172
2173
  * 注意:isAsync 必须正确传递,否则 babel 无法解析 await 关键字。
2174
+ * 注意:不能使用 compact: true,否则多语句的 { } 会被移除导致解析错误
2173
2175
  */
2174
2176
  function reparseBodyAsAST(body, isAsync) {
2175
- const code = generate(t.arrowFunctionExpression([], body, isAsync), { compact: true }).code;
2177
+ const code = generate(t.arrowFunctionExpression([], body, isAsync)).code;
2176
2178
  return parse$1(code, {
2177
2179
  sourceType: "module",
2178
2180
  plugins: ["typescript"]
@@ -2251,6 +2253,11 @@ function processASTExpression(ast, counter, callExpressionWithArgs, excludeBindi
2251
2253
  if (t.isCallExpression(ast)) return processCallableExpression(ast.callee, ast.arguments, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, vForInfoList, ctx, returnValue);
2252
2254
  else if (t.isMemberExpression(ast)) return processCallableExpression(ast, null, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, vForInfoList, ctx, returnValue);
2253
2255
  else if (t.isArrowFunctionExpression(ast)) return processArrowFunctionExpression(ast, counter, callExpressionWithArgs, excludeBindingVars, vForItemName, node, returnValue, ctx);
2256
+ else if (t.isAssignmentExpression(ast)) return processInlineArrowFunction(t.blockStatement([t.expressionStatement(ast)]), [], counter, callExpressionWithArgs, excludeBindingVars, node, returnValue, ctx, false);
2257
+ else if (t.isSequenceExpression(ast)) {
2258
+ const statements = ast.expressions.map((expr) => t.expressionStatement(expr));
2259
+ return processInlineArrowFunction(t.blockStatement(statements), [], counter, callExpressionWithArgs, excludeBindingVars, node, returnValue, ctx, false);
2260
+ } else if (t.isLogicalExpression(ast) || t.isConditionalExpression(ast)) return createShortExprHandler(ast, [], callExpressionWithArgs, vForInfoList, getVForVariables(ctx, node), ctx, counter, returnValue, false);
2254
2261
  return "";
2255
2262
  }
2256
2263
  /**
@@ -2342,6 +2349,10 @@ function collectExternalVarsFromExpression(body, arrowFunctionArgumentNames, vFo
2342
2349
  collectVarsFromNode(node.left);
2343
2350
  collectVarsFromNode(node.right);
2344
2351
  } else if (t.isUnaryExpression(node)) collectVarsFromNode(node.argument);
2352
+ else if (t.isAssignmentExpression(node)) {
2353
+ collectVarsFromNode(node.left);
2354
+ collectVarsFromNode(node.right);
2355
+ }
2345
2356
  };
2346
2357
  if (t.isConditionalExpression(body)) {
2347
2358
  collectVarsFromNode(body.test);
@@ -2374,6 +2385,14 @@ function rewriteExpressionVars(expr, varsToCollect, arrowFunctionArgumentNames,
2374
2385
  else if (t.isLogicalExpression(node)) return t.logicalExpression(node.operator, processExpr(node.left), processExpr(node.right));
2375
2386
  else if (t.isBinaryExpression(node)) return t.binaryExpression(node.operator, processExpr(node.left), processExpr(node.right));
2376
2387
  else if (t.isUnaryExpression(node)) return t.unaryExpression(node.operator, processExpr(node.argument));
2388
+ else if (t.isAssignmentExpression(node)) {
2389
+ const left = node.left;
2390
+ if (t.isIdentifier(left) || t.isMemberExpression(left)) {
2391
+ const rewritten = processExpr(left);
2392
+ if (t.isIdentifier(rewritten) || t.isMemberExpression(rewritten)) return t.assignmentExpression(node.operator, rewritten, processExpr(node.right));
2393
+ }
2394
+ return t.assignmentExpression(node.operator, left, processExpr(node.right));
2395
+ }
2377
2396
  return node;
2378
2397
  };
2379
2398
  return processExpr(expr);
@@ -4093,7 +4112,7 @@ function bindingifyBuiltInPlugin(plugin) {
4093
4112
  * **Basic usage**
4094
4113
  * ```js
4095
4114
  * replacePlugin({
4096
- * '"production"': JSON.stringify('production'),
4115
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
4097
4116
  * __buildVersion: 15
4098
4117
  * })
4099
4118
  * ```
@@ -4101,7 +4120,7 @@ function bindingifyBuiltInPlugin(plugin) {
4101
4120
  * **With options**
4102
4121
  * ```js
4103
4122
  * replacePlugin({
4104
- * '"production"': JSON.stringify('production'),
4123
+ * 'process.env.NODE_ENV': JSON.stringify('production'),
4105
4124
  * __buildVersion: 15
4106
4125
  * }, {
4107
4126
  * preventAssignment: false,
@@ -4123,7 +4142,7 @@ function replacePlugin(values = {}, options = {}) {
4123
4142
  }
4124
4143
  //#endregion
4125
4144
  //#region src/cli.ts
4126
- const NODE_ENV = "production";
4145
+ const NODE_ENV = process$1.env.NODE_ENV || "production";
4127
4146
  let pagePaths = null;
4128
4147
  const pageComponentCache = /* @__PURE__ */ new Map();
4129
4148
  /**
@@ -4253,7 +4272,7 @@ async function bundleModule(module, pkg) {
4253
4272
  await (await rolldown({
4254
4273
  input: module,
4255
4274
  external: peerDependencies ? Object.keys(peerDependencies) : void 0,
4256
- plugins: [replacePlugin({ "\"production\"": JSON.stringify(NODE_ENV) }, { preventAssignment: true })],
4275
+ plugins: [replacePlugin({ "process.env.NODE_ENV": JSON.stringify(NODE_ENV) }, { preventAssignment: true })],
4257
4276
  treeshake: true
4258
4277
  })).write({
4259
4278
  file: `${pkg.replace(sourceDir, OUTPUT_DIR)}/miniprogram_npm/${module}/index.js`,
@@ -4307,8 +4326,6 @@ async function buildComponentLibrary(name) {
4307
4326
  if (entry.isDirectory()) await processJsFiles(fullPath);
4308
4327
  else if (entry.isFile() && entry.name.endsWith(".js")) jsFiles.push(fullPath);
4309
4328
  }
4310
- const jsConcurrency = Math.min(10, CONCURRENT_LIMIT);
4311
- console.log(bold(green(` 处理 ${jsFiles.length} 个 JS 文件(并发=${jsConcurrency})...`)));
4312
4329
  await batchProcess(jsFiles, async (filePath) => {
4313
4330
  try {
4314
4331
  const result = await transformFileAsync(filePath, {
@@ -4326,7 +4343,7 @@ async function buildComponentLibrary(name) {
4326
4343
  } catch (error) {
4327
4344
  console.error(`处理 ${filePath} 失败:`, getErrorMessage(error));
4328
4345
  }
4329
- }, jsConcurrency);
4346
+ }, Math.min(10, CONCURRENT_LIMIT));
4330
4347
  };
4331
4348
  await processJsFiles(destination);
4332
4349
  if (independentPackages.length > 0) await Promise.all(independentPackages.map(async (item) => {
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import dotenv from "dotenv-flow";
2
2
  //#region src/index.ts
3
3
  async function runVMS(options) {
4
4
  dotenv.config({ node_env: options.mode });
5
- const { dev, prod } = await import("./cli-BtVCp04t.js");
5
+ const { dev, prod } = await import("./cli-B8qDheMe.js");
6
6
  if (options.mode === "production") return prod(options);
7
7
  else return dev();
8
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unmagic/vms",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "基于 @unmagic/vue-mini 的Vue3 单文件组件构建工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",