@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211117003 → 3.0.0-alpha-3021320211118002

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.
@@ -23,4 +23,5 @@ export declare function getRouterOptions(manifestJson: Record<string, any>): {
23
23
  mode?: 'history' | 'hash';
24
24
  base?: string;
25
25
  };
26
+ export declare function isEnableTreeShaking(manifestJson: Record<string, any>): boolean;
26
27
  export {};
@@ -3,7 +3,7 @@ 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.getRouterOptions = exports.getUniStatistics = exports.normalizeNetworkTimeout = exports.parseCompatConfigOnce = exports.parseRpx2UnitOnce = exports.parseManifestJsonOnce = exports.parseManifestJson = void 0;
6
+ exports.isEnableTreeShaking = exports.getRouterOptions = exports.getUniStatistics = exports.normalizeNetworkTimeout = exports.parseCompatConfigOnce = exports.parseRpx2UnitOnce = exports.parseManifestJsonOnce = exports.parseManifestJson = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const shared_1 = require("@vue/shared");
@@ -52,3 +52,8 @@ function getRouterOptions(manifestJson) {
52
52
  return (0, shared_1.extend)({}, (_a = manifestJson.h5) === null || _a === void 0 ? void 0 : _a.router);
53
53
  }
54
54
  exports.getRouterOptions = getRouterOptions;
55
+ function isEnableTreeShaking(manifestJson) {
56
+ var _a, _b, _c;
57
+ return ((_c = (_b = (_a = manifestJson.h5) === null || _a === void 0 ? void 0 : _a.optimization) === null || _b === void 0 ? void 0 : _b.treeShaking) === null || _c === void 0 ? void 0 : _c.enable) !== false;
58
+ }
59
+ exports.isEnableTreeShaking = isEnableTreeShaking;
@@ -4,7 +4,10 @@ export interface MiniProgramCompilerOptions {
4
4
  * 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
5
5
  */
6
6
  lazyElement?: {
7
- [name: string]: string[];
7
+ [name: string]: {
8
+ name: 'on' | 'bind';
9
+ arg: string[];
10
+ }[];
8
11
  };
9
12
  event?: {
10
13
  format(name: string, opts: {
package/dist/utils.js CHANGED
@@ -116,7 +116,7 @@ const NODE_MODULES_REGEX = /(\.\.\/)?node_modules/g;
116
116
  function normalizeNodeModules(str) {
117
117
  str = normalizePath(str).replace(NODE_MODULES_REGEX, 'node-modules');
118
118
  // HBuilderX 内置模块路径转换
119
- str = str.replace(/.*\/plugins\/uniapp-cli\/node[-_]modules/, 'node-modules');
119
+ str = str.replace(/.*\/plugins\/uniapp-cli-vite\/node[-_]modules/, 'node-modules');
120
120
  if (process.env.UNI_PLATFORM === 'mp-alipay') {
121
121
  str = str.replace('node-modules/@', 'node-modules/npm-scope-');
122
122
  }
@@ -22,6 +22,7 @@ function uniViteInjectPlugin(options) {
22
22
  delete modules.exclude;
23
23
  delete modules.sourceMap;
24
24
  delete modules.callback;
25
+ const reassignments = new Set();
25
26
  const modulesMap = new Map();
26
27
  const namespaceModulesMap = new Map();
27
28
  Object.keys(modules).forEach((name) => {
@@ -76,7 +77,7 @@ function uniViteInjectPlugin(options) {
76
77
  let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
77
78
  const magicString = new magic_string_1.default(code);
78
79
  const newImports = new Map();
79
- function handleReference(node, name, keypath) {
80
+ function handleReference(node, name, keypath, parent) {
80
81
  let mod = modulesMap.get(keypath);
81
82
  if (!mod && hasNamespace) {
82
83
  const mods = keypath.split('.');
@@ -104,6 +105,14 @@ function uniViteInjectPlugin(options) {
104
105
  if (mod[0] === id)
105
106
  return false;
106
107
  const hash = `${keypath}:${mod[0]}:${mod[1]}`;
108
+ // 当 API 被覆盖定义后,不再摇树
109
+ if (reassignments.has(hash)) {
110
+ return false;
111
+ }
112
+ if (parent && (0, utils_1.isAssignmentExpression)(parent)) {
113
+ reassignments.add(hash);
114
+ return false;
115
+ }
107
116
  const importLocalName = name === keypath ? name : (0, pluginutils_1.makeLegalIdentifier)(`$inject_${keypath}`);
108
117
  if (!newImports.has(hash)) {
109
118
  if (mod[1] === '*') {
@@ -140,7 +149,7 @@ function uniViteInjectPlugin(options) {
140
149
  }
141
150
  if ((0, utils_1.isReference)(node, parent)) {
142
151
  const { name, keypath } = flatten(node);
143
- const handled = handleReference(node, name, keypath);
152
+ const handled = handleReference(node, name, keypath, parent);
144
153
  if (handled) {
145
154
  this.skip();
146
155
  }
@@ -1,7 +1,8 @@
1
- import type { Literal, BaseNode, Property, Identifier, CallExpression, MemberExpression, MethodDefinition, ExportSpecifier } from 'estree';
1
+ import type { Literal, BaseNode, Property, Identifier, CallExpression, AssignmentExpression, MemberExpression, MethodDefinition, ExportSpecifier } from 'estree';
2
2
  import { Node, ElementNode, DirectiveNode, SimpleExpressionNode } from '@vue/compiler-core';
3
3
  export declare const isProperty: (node: BaseNode) => node is Property;
4
4
  export declare const isIdentifier: (node: BaseNode) => node is Identifier;
5
+ export declare const isAssignmentExpression: (node: BaseNode) => node is AssignmentExpression;
5
6
  export declare const isCallExpression: (node: BaseNode) => node is CallExpression;
6
7
  export declare const isMemberExpression: (node: BaseNode) => node is MemberExpression;
7
8
  export declare const isMethodDefinition: (node: BaseNode) => node is MethodDefinition;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSimpleExpressionNode = exports.isDirectiveNode = exports.isElementNode = exports.parseVue = exports.createCallExpression = exports.createIdentifier = exports.createLiteral = exports.isReference = exports.isExportSpecifier = exports.isMethodDefinition = exports.isMemberExpression = exports.isCallExpression = exports.isIdentifier = exports.isProperty = void 0;
3
+ exports.isSimpleExpressionNode = exports.isDirectiveNode = exports.isElementNode = exports.parseVue = exports.createCallExpression = exports.createIdentifier = exports.createLiteral = exports.isReference = exports.isExportSpecifier = exports.isMethodDefinition = exports.isMemberExpression = exports.isCallExpression = exports.isAssignmentExpression = exports.isIdentifier = exports.isProperty = void 0;
4
4
  const compiler_dom_1 = require("@vue/compiler-dom");
5
5
  const isProperty = (node) => node.type === 'Property';
6
6
  exports.isProperty = isProperty;
7
7
  const isIdentifier = (node) => node.type === 'Identifier';
8
8
  exports.isIdentifier = isIdentifier;
9
+ const isAssignmentExpression = (node) => node.type === 'AssignmentExpression';
10
+ exports.isAssignmentExpression = isAssignmentExpression;
9
11
  const isCallExpression = (node) => node.type === 'CallExpression';
10
12
  exports.isCallExpression = isCallExpression;
11
13
  const isMemberExpression = (node) => node.type === 'MemberExpression';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3021320211117003",
3
+ "version": "3.0.0-alpha-3021320211118002",
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-3021320211117003",
24
- "@dcloudio/uni-shared": "3.0.0-alpha-3021320211117003",
23
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3021320211118002",
24
+ "@dcloudio/uni-shared": "3.0.0-alpha-3021320211118002",
25
25
  "@rollup/pluginutils": "^4.1.1",
26
26
  "@vue/compiler-core": "3.2.22",
27
27
  "@vue/compiler-dom": "3.2.22",