mp-weixin-back 0.0.6 → 0.0.7

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/build.config.ts CHANGED
@@ -8,5 +8,5 @@ export default defineBuildConfig({
8
8
  emitCJS: true,
9
9
  },
10
10
  failOnWarn: false,
11
- externals: ['vite', 'vue']
12
- })
11
+ externals: ['vite', 'vue', '@babel/generator'],
12
+ })
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const path = require('path');
4
4
  const fs = require('fs');
5
5
  const JSON5 = require('json5');
6
- const chalk = require('chalk');
6
+ const kolorist = require('kolorist');
7
7
  const generate = require('@babel/generator');
8
8
  const compilerSfc = require('@vue/compiler-sfc');
9
9
  const astKit = require('ast-kit');
@@ -13,7 +13,6 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
13
13
  const path__default = /*#__PURE__*/_interopDefaultCompat(path);
14
14
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
15
15
  const JSON5__default = /*#__PURE__*/_interopDefaultCompat(JSON5);
16
- const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
17
16
  const generate__default = /*#__PURE__*/_interopDefaultCompat(generate);
18
17
 
19
18
  const virtualFileId = "mp-weixin-back-helper";
@@ -65,14 +64,17 @@ async function transformVueFile(code, id) {
65
64
  const callback = node.expression.arguments[0];
66
65
  const backArguments = node.expression.arguments[1];
67
66
  if (backArguments && backArguments.type == "ObjectExpression") {
68
- const config = new Function(`return (${generate__default(backArguments).code});`)();
67
+ const config = new Function(
68
+ // @ts-ignore
69
+ `return (${(generate__default.default ? generate__default.default : generate__default)(backArguments).code});`
70
+ )();
69
71
  pageBackConfig = { ...pageBackConfig, ...config };
70
72
  }
71
73
  if (callback && (callback.type === "ArrowFunctionExpression" || callback.type === "FunctionExpression")) {
72
74
  const body = callback.body;
73
75
  if (body.type === "BlockStatement") {
74
76
  body.body.forEach((statement) => {
75
- callbackCode += generate__default(statement).code;
77
+ callbackCode += (generate__default.default ? generate__default.default : generate__default)(statement).code;
76
78
  });
77
79
  }
78
80
  }
@@ -150,14 +152,14 @@ class pageContext {
150
152
  __publicField(this, "pages", []);
151
153
  __publicField(this, "log", {
152
154
  info: (text) => {
153
- console.log(chalk__default.white(text));
155
+ console.log(kolorist.white(text));
154
156
  },
155
157
  error: (text) => {
156
- console.log(chalk__default.red(text));
158
+ console.log(kolorist.red(text));
157
159
  },
158
160
  devLog: (text) => {
159
161
  if (this.config.mode === "development" && this.config.debug) {
160
- console.log(chalk__default.green(text));
162
+ console.log(kolorist.green(text));
161
163
  }
162
164
  }
163
165
  });
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
3
  import JSON5 from 'json5';
4
- import chalk from 'chalk';
4
+ import { white, red, green } from 'kolorist';
5
5
  import generate from '@babel/generator';
6
6
  import { parse } from '@vue/compiler-sfc';
7
7
  import { babelParse, walkAST } from 'ast-kit';
@@ -55,14 +55,17 @@ async function transformVueFile(code, id) {
55
55
  const callback = node.expression.arguments[0];
56
56
  const backArguments = node.expression.arguments[1];
57
57
  if (backArguments && backArguments.type == "ObjectExpression") {
58
- const config = new Function(`return (${generate(backArguments).code});`)();
58
+ const config = new Function(
59
+ // @ts-ignore
60
+ `return (${(generate.default ? generate.default : generate)(backArguments).code});`
61
+ )();
59
62
  pageBackConfig = { ...pageBackConfig, ...config };
60
63
  }
61
64
  if (callback && (callback.type === "ArrowFunctionExpression" || callback.type === "FunctionExpression")) {
62
65
  const body = callback.body;
63
66
  if (body.type === "BlockStatement") {
64
67
  body.body.forEach((statement) => {
65
- callbackCode += generate(statement).code;
68
+ callbackCode += (generate.default ? generate.default : generate)(statement).code;
66
69
  });
67
70
  }
68
71
  }
@@ -140,14 +143,14 @@ class pageContext {
140
143
  __publicField(this, "pages", []);
141
144
  __publicField(this, "log", {
142
145
  info: (text) => {
143
- console.log(chalk.white(text));
146
+ console.log(white(text));
144
147
  },
145
148
  error: (text) => {
146
- console.log(chalk.red(text));
149
+ console.log(red(text));
147
150
  },
148
151
  devLog: (text) => {
149
152
  if (this.config.mode === "development" && this.config.debug) {
150
- console.log(chalk.green(text));
153
+ console.log(green(text));
151
154
  }
152
155
  }
153
156
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mp-weixin-back",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "description": "监听微信小程序的手势返回和页面默认导航栏的返回",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.mjs",
@@ -46,9 +46,9 @@
46
46
  "@vitejs/plugin-vue": "^5.2.0",
47
47
  "@vue/test-utils": "^2.4.6",
48
48
  "ast-kit": "^1.3.1",
49
- "chalk": "^5.3.0",
50
49
  "happy-dom": "^15.11.6",
51
50
  "json5": "^2.2.3",
51
+ "kolorist": "^1.8.0",
52
52
  "typescript": "^5.7.2",
53
53
  "vitest": "^2.1.5"
54
54
  },
package/src/context.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from 'path'
2
2
  import fs from 'fs'
3
3
  import JSON5 from 'json5'
4
- import chalk from 'chalk'
4
+ import { red, white, green } from 'kolorist'
5
5
  import { ContextConfig, PagesJson } from '../types'
6
6
  import { transformVueFile } from '../utils'
7
7
 
@@ -10,14 +10,14 @@ export class pageContext {
10
10
  pages: string[] = []
11
11
  log = {
12
12
  info: (text: string) => {
13
- console.log(chalk.white(text))
13
+ console.log(white(text))
14
14
  },
15
15
  error: (text: string) => {
16
- console.log(chalk.red(text))
16
+ console.log(red(text))
17
17
  },
18
18
  devLog: (text: string) => {
19
19
  if (this.config.mode === 'development' && this.config.debug) {
20
- console.log(chalk.green(text))
20
+ console.log(green(text))
21
21
  }
22
22
  },
23
23
  }
package/utils/index.ts CHANGED
@@ -71,7 +71,10 @@ export async function transformVueFile(this: pageContext, code: string, id: stri
71
71
  const backArguments = node.expression.arguments[1]
72
72
  // 第二个参数为object才有效,覆盖插件传入的配置
73
73
  if (backArguments && backArguments.type == 'ObjectExpression') {
74
- const config = new Function(`return (${generate(backArguments).code});`)()
74
+ const config = new Function(
75
+ // @ts-ignore
76
+ `return (${(generate.default ? generate.default : generate)(backArguments).code});`
77
+ )()
75
78
  pageBackConfig = { ...pageBackConfig, ...config }
76
79
  }
77
80
 
@@ -83,7 +86,8 @@ export async function transformVueFile(this: pageContext, code: string, id: stri
83
86
  if (body.type === 'BlockStatement') {
84
87
  // 遍历 BlockStatement 的内容
85
88
  body.body.forEach((statement) => {
86
- callbackCode += generate(statement).code // 将 AST 节点生成代码
89
+ // @ts-ignore
90
+ callbackCode += (generate.default ? generate.default : generate)(statement).code // 将 AST 节点生成代码
87
91
  })
88
92
  }
89
93
  }