@dcloudio/uni-cli-shared 3.0.0-alpha-3030020211208002 → 3.0.0-alpha-3030120211210003

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/hbx/log.d.ts CHANGED
@@ -1,8 +1,6 @@
1
+ import { LogErrorOptions } from 'vite';
1
2
  import { Formatter } from '../logs/format';
2
3
  export declare const h5ServeFormatter: Formatter;
3
4
  export declare const removeInfoFormatter: Formatter;
4
5
  export declare const removeWarnFormatter: Formatter;
5
- export declare const FilenameFormatter: Formatter;
6
- export declare const VueFilenameFormatter: Formatter;
7
- export declare const HBuilderXFileFormatter: Formatter;
8
- export declare const HBuilderXVueFileFormatter: Formatter;
6
+ export declare const errorFormatter: Formatter<LogErrorOptions>;
package/dist/hbx/log.js CHANGED
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HBuilderXVueFileFormatter = exports.HBuilderXFileFormatter = exports.VueFilenameFormatter = exports.FilenameFormatter = exports.removeWarnFormatter = exports.removeInfoFormatter = exports.h5ServeFormatter = void 0;
6
+ exports.errorFormatter = exports.removeWarnFormatter = exports.removeInfoFormatter = exports.h5ServeFormatter = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
+ const chalk_1 = __importDefault(require("chalk"));
8
9
  const utils_1 = require("../utils");
9
10
  const SIGNAL_H5_LOCAL = ' > Local:';
10
11
  const SIGNAL_H5_NETWORK = ' > Network:';
@@ -54,58 +55,45 @@ exports.removeWarnFormatter = {
54
55
  return '';
55
56
  },
56
57
  };
57
- const fileRE = /file:\s(.*):(\d+):(\d+)/;
58
- exports.FilenameFormatter = {
59
- test(msg) {
60
- return fileRE.test(msg);
61
- },
62
- format(msg) {
63
- return msg.replace(fileRE, (_, filename, line, column) => {
64
- return `file: ${filename.split('?')[0]}:${line}:${column}`;
65
- });
58
+ exports.errorFormatter = {
59
+ test(_, opts) {
60
+ return !!(opts && opts.error);
66
61
  },
67
- };
68
- const vueFileRE = /file:\s(.*)\?vue&type=(.*)/;
69
- exports.VueFilenameFormatter = {
70
- test(msg) {
71
- return vueFileRE.test(msg);
72
- },
73
- format(msg) {
74
- return msg.replace(vueFileRE, (_, filename) => {
75
- return `file: ${filename.split('?')[0]}`;
76
- });
77
- },
78
- };
79
- exports.HBuilderXFileFormatter = {
80
- test(msg) {
81
- return fileRE.test(msg);
82
- },
83
- format(msg) {
84
- return (msg
85
- // remove color
86
- .replace(/\x1B[[(?);]{0,2}(;?\d)*./g, '')
87
- .replace(fileRE, (_, filename, line, column) => {
88
- return ('at ' +
89
- (0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename.split('?')[0])) +
90
- ':' +
91
- line +
92
- ':' +
93
- column);
94
- }));
95
- },
96
- };
97
- exports.HBuilderXVueFileFormatter = {
98
- test(msg) {
99
- return vueFileRE.test(msg);
100
- },
101
- format(msg) {
102
- return (msg
103
- // remove color
104
- .replace(/\x1B[[(?);]{0,2}(;?\d)*./g, '')
105
- .replace(vueFileRE, (_, filename) => {
106
- return ('at ' +
107
- (0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename)) +
108
- ':1');
109
- }));
62
+ format(_, opts) {
63
+ return buildErrorMessage(opts.error, [], false);
110
64
  },
111
65
  };
66
+ function buildErrorMessage(err, args = [], includeStack = true) {
67
+ var _a, _b;
68
+ if (err.plugin) {
69
+ args.push(`${chalk_1.default.magenta('[plugin:' + err.plugin + ']')} ${chalk_1.default.red(err.message)}`);
70
+ }
71
+ else {
72
+ args.push(chalk_1.default.red(err.message));
73
+ }
74
+ if (err.id) {
75
+ args.push(`at ${chalk_1.default.cyan((0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, err.id.split('?')[0])) +
76
+ ':' +
77
+ (((_a = err.loc) === null || _a === void 0 ? void 0 : _a.line) || 1) +
78
+ ':' +
79
+ (((_b = err.loc) === null || _b === void 0 ? void 0 : _b.column) || 0))}`);
80
+ }
81
+ if (err.frame) {
82
+ args.push(chalk_1.default.yellow(pad(err.frame)));
83
+ }
84
+ if (includeStack && err.stack) {
85
+ args.push(pad(cleanStack(err.stack)));
86
+ }
87
+ return args.join('\n');
88
+ }
89
+ function cleanStack(stack) {
90
+ return stack
91
+ .split(/\n/g)
92
+ .filter((l) => /^\s*at/.test(l))
93
+ .join('\n');
94
+ }
95
+ const splitRE = /\r?\n/;
96
+ function pad(source, n = 2) {
97
+ const lines = source.split(splitRE);
98
+ return lines.map((l) => ` `.repeat(n) + l).join(`\n`);
99
+ }
@@ -1,7 +1,8 @@
1
- export interface Formatter {
2
- test: (msg: string) => boolean;
3
- format: (msg: string) => string;
1
+ import { LogErrorOptions, LogOptions } from 'vite';
2
+ export interface Formatter<T extends LogOptions = LogOptions> {
3
+ test: (msg: string, options?: T) => boolean;
4
+ format: (msg: string, options?: T) => string;
4
5
  }
5
- export declare function formatErrMsg(msg: string): string;
6
- export declare function formatInfoMsg(msg: string): string;
7
- export declare function formatWarnMsg(msg: string): string;
6
+ export declare function formatErrMsg(msg: string, options?: LogErrorOptions): string;
7
+ export declare function formatInfoMsg(msg: string, options?: LogOptions): string;
8
+ export declare function formatWarnMsg(msg: string, options?: LogOptions): string;
@@ -12,14 +12,7 @@ const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
12
12
  if ((0, env_1.isInHBuilderX)()) {
13
13
  errFormatters.push(alias_1.moduleAliasFormatter);
14
14
  }
15
- if ((0, env_1.runByHBuilderX)()) {
16
- errFormatters.push(log_1.HBuilderXFileFormatter);
17
- errFormatters.push(log_1.HBuilderXVueFileFormatter);
18
- }
19
- else {
20
- errFormatters.push(log_1.FilenameFormatter);
21
- errFormatters.push(log_1.VueFilenameFormatter);
22
- }
15
+ errFormatters.push(log_1.errorFormatter);
23
16
  });
24
17
  const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
25
18
  if ((0, env_1.isInHBuilderX)()) {
@@ -35,29 +28,29 @@ const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
35
28
  const initWarnFormattersOnce = (0, uni_shared_1.once)(() => {
36
29
  warnFormatters.push(log_1.removeWarnFormatter);
37
30
  });
38
- function formatErrMsg(msg) {
31
+ function formatErrMsg(msg, options) {
39
32
  initErrFormattersOnce();
40
- const formatter = errFormatters.find(({ test }) => test(msg));
33
+ const formatter = errFormatters.find(({ test }) => test(msg, options));
41
34
  if (formatter) {
42
- return formatter.format(msg);
35
+ return formatter.format(msg, options);
43
36
  }
44
37
  return msg;
45
38
  }
46
39
  exports.formatErrMsg = formatErrMsg;
47
- function formatInfoMsg(msg) {
40
+ function formatInfoMsg(msg, options) {
48
41
  initInfoFormattersOnce();
49
- const formatter = infoFormatters.find(({ test }) => test(msg));
42
+ const formatter = infoFormatters.find(({ test }) => test(msg, options));
50
43
  if (formatter) {
51
- return formatter.format(msg);
44
+ return formatter.format(msg, options);
52
45
  }
53
46
  return msg;
54
47
  }
55
48
  exports.formatInfoMsg = formatInfoMsg;
56
- function formatWarnMsg(msg) {
49
+ function formatWarnMsg(msg, options) {
57
50
  initWarnFormattersOnce();
58
- const formatter = warnFormatters.find(({ test }) => test(msg));
51
+ const formatter = warnFormatters.find(({ test }) => test(msg, options));
59
52
  if (formatter) {
60
- return formatter.format(msg);
53
+ return formatter.format(msg, options);
61
54
  }
62
55
  return msg;
63
56
  }
@@ -9,10 +9,10 @@ const types_1 = require("@babel/types");
9
9
  const shared_1 = require("@vue/shared");
10
10
  const estree_walker_1 = require("estree-walker");
11
11
  const magic_string_1 = __importDefault(require("magic-string"));
12
+ const uni_shared_1 = require("@dcloudio/uni-shared");
12
13
  const messages_1 = require("../messages");
13
14
  const constants_1 = require("../constants");
14
15
  const utils_1 = require("../utils");
15
- const uni_shared_1 = require("@dcloudio/uni-shared");
16
16
  async function transformVueComponentImports(code, importer, { root, resolve, global, dynamicImport, babelParserPlugins, }) {
17
17
  if (!global && !code.includes(constants_1.BINDING_COMPONENTS)) {
18
18
  return { code, usingComponents: {} };
@@ -46,6 +46,7 @@ exports.transformVueComponentImports = transformVueComponentImports;
46
46
  * @returns
47
47
  */
48
48
  function findBindingComponents(ast) {
49
+ const mapping = findUnpluginComponents(ast);
49
50
  for (const node of ast) {
50
51
  if (!(0, types_1.isVariableDeclaration)(node)) {
51
52
  continue;
@@ -55,10 +56,10 @@ function findBindingComponents(ast) {
55
56
  declarator.id.name === constants_1.BINDING_COMPONENTS) {
56
57
  const bindingComponents = JSON.parse(declarator.init.value);
57
58
  return Object.keys(bindingComponents).reduce((bindings, tag) => {
58
- const binding = bindingComponents[tag];
59
- bindings[binding.name] = {
59
+ const { name, type } = bindingComponents[tag];
60
+ bindings[mapping[name] || name] = {
60
61
  tag,
61
- type: binding.type,
62
+ type: type,
62
63
  };
63
64
  return bindings;
64
65
  }, {});
@@ -66,6 +67,33 @@ function findBindingComponents(ast) {
66
67
  }
67
68
  return {};
68
69
  }
70
+ function findUnpluginComponents(ast) {
71
+ const res = Object.create(null);
72
+ // if(!Array){}
73
+ const ifStatement = ast.find((statement) => (0, types_1.isIfStatement)(statement) &&
74
+ (0, types_1.isUnaryExpression)(statement.test) &&
75
+ statement.test.operator === '!' &&
76
+ (0, types_1.isIdentifier)(statement.test.argument) &&
77
+ statement.test.argument.name === 'Array');
78
+ if (!ifStatement) {
79
+ return res;
80
+ }
81
+ if (!(0, types_1.isBlockStatement)(ifStatement.consequent)) {
82
+ return res;
83
+ }
84
+ for (const node of ifStatement.consequent.body) {
85
+ if (!(0, types_1.isVariableDeclaration)(node)) {
86
+ continue;
87
+ }
88
+ const { id, init } = node.declarations[0];
89
+ if ((0, types_1.isIdentifier)(id) &&
90
+ (0, types_1.isIdentifier)(init) &&
91
+ init.name.includes('unplugin_components')) {
92
+ res[id.name] = init.name;
93
+ }
94
+ }
95
+ return res;
96
+ }
69
97
  /**
70
98
  * 查找全局组件定义:app.component('component-a',{})
71
99
  * @param ast
@@ -167,7 +167,7 @@ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canI
167
167
  const contentHash = getAssetHash(content);
168
168
  const { search, hash } = (0, url_1.parse)(id);
169
169
  const postfix = (search || '') + (hash || '');
170
- const fileName = (0, utils_1.normalizePath)(path_1.default.posix.relative(process.env.UNI_INPUT_DIR, file));
170
+ const fileName = path_1.default.posix.relative((0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR), file);
171
171
  if (!map.has(contentHash)) {
172
172
  map.set(contentHash, fileName);
173
173
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3030020211208002",
3
+ "version": "3.0.0-alpha-3030120211210003",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,8 +20,8 @@
20
20
  "dependencies": {
21
21
  "@babel/parser": "^7.15.0",
22
22
  "@babel/types": "^7.15.0",
23
- "@dcloudio/uni-i18n": "3.0.0-alpha-3030020211208002",
24
- "@dcloudio/uni-shared": "3.0.0-alpha-3030020211208002",
23
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3030120211210003",
24
+ "@dcloudio/uni-shared": "3.0.0-alpha-3030120211210003",
25
25
  "@rollup/pluginutils": "^4.1.1",
26
26
  "@vue/compiler-core": "3.2.24",
27
27
  "@vue/compiler-dom": "3.2.24",