@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211117005 → 3.0.0-alpha-3021320211119002
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/alias.d.ts +2 -0
- package/dist/hbx/alias.js +14 -7
- package/dist/hbx/index.d.ts +1 -1
- package/dist/hbx/index.js +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json/manifest.d.ts +1 -0
- package/dist/json/manifest.js +6 -1
- package/dist/json/mp/jsonFile.js +2 -1
- package/dist/mp/template.d.ts +4 -1
- package/dist/preprocess/context.js +1 -0
- package/dist/resolve.d.ts +5 -0
- package/dist/resolve.js +89 -0
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +5 -70
- package/dist/vite/plugins/inject.js +11 -2
- package/dist/vite/utils/ast.d.ts +2 -1
- package/dist/vite/utils/ast.js +3 -1
- package/package.json +4 -3
package/dist/hbx/alias.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Formatter } from '../logs/format';
|
|
2
2
|
export declare function initModuleAlias(): void;
|
|
3
|
+
export declare function installHBuilderXPlugin(plugin: string): void;
|
|
3
4
|
export declare const moduleAliasFormatter: Formatter;
|
|
5
|
+
export declare function formatInstallHBuilderXPluginTips(lang: string, preprocessor: string): string;
|
package/dist/hbx/alias.js
CHANGED
|
@@ -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.moduleAliasFormatter = exports.initModuleAlias = void 0;
|
|
6
|
+
exports.formatInstallHBuilderXPluginTips = exports.moduleAliasFormatter = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const module_alias_1 = __importDefault(require("module-alias"));
|
|
9
9
|
const env_1 = require("./env");
|
|
@@ -25,9 +25,13 @@ exports.initModuleAlias = initModuleAlias;
|
|
|
25
25
|
function supportAutoInstallPlugin() {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
28
|
+
function installHBuilderXPlugin(plugin) {
|
|
29
|
+
if (!supportAutoInstallPlugin()) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
return console.error(`%HXRunUniAPPPluginName%${plugin}%HXRunUniAPPPluginName%`);
|
|
30
33
|
}
|
|
34
|
+
exports.installHBuilderXPlugin = installHBuilderXPlugin;
|
|
31
35
|
exports.moduleAliasFormatter = {
|
|
32
36
|
test(msg) {
|
|
33
37
|
return msg.includes('Preprocessor dependency');
|
|
@@ -48,11 +52,14 @@ exports.moduleAliasFormatter = {
|
|
|
48
52
|
preprocessor = 'compile-stylus';
|
|
49
53
|
}
|
|
50
54
|
if (lang) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return `预编译器错误:代码使用了${lang}语言,但未安装相应的编译器插件,${autoInstall ? '正在从' : '请前往'}插件市场安装该插件:
|
|
54
|
-
https://ext.dcloud.net.cn/plugin?name=${preprocessor}`;
|
|
55
|
+
installHBuilderXPlugin(preprocessor);
|
|
56
|
+
return formatInstallHBuilderXPluginTips(lang, preprocessor);
|
|
55
57
|
}
|
|
56
58
|
return msg;
|
|
57
59
|
},
|
|
58
60
|
};
|
|
61
|
+
function formatInstallHBuilderXPluginTips(lang, preprocessor) {
|
|
62
|
+
return `预编译器错误:代码使用了${lang}语言,但未安装相应的编译器插件,${supportAutoInstallPlugin() ? '正在从' : '请前往'}插件市场安装该插件:
|
|
63
|
+
https://ext.dcloud.net.cn/plugin?name=${preprocessor}`;
|
|
64
|
+
}
|
|
65
|
+
exports.formatInstallHBuilderXPluginTips = formatInstallHBuilderXPluginTips;
|
package/dist/hbx/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './env';
|
|
2
|
-
export { initModuleAlias } from './alias';
|
|
2
|
+
export { initModuleAlias, installHBuilderXPlugin, formatInstallHBuilderXPluginTips, } from './alias';
|
package/dist/hbx/index.js
CHANGED
|
@@ -10,7 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.initModuleAlias = void 0;
|
|
13
|
+
exports.formatInstallHBuilderXPluginTips = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
|
|
14
14
|
__exportStar(require("./env"), exports);
|
|
15
15
|
var alias_1 = require("./alias");
|
|
16
16
|
Object.defineProperty(exports, "initModuleAlias", { enumerable: true, get: function () { return alias_1.initModuleAlias; } });
|
|
17
|
+
Object.defineProperty(exports, "installHBuilderXPlugin", { enumerable: true, get: function () { return alias_1.installHBuilderXPlugin; } });
|
|
18
|
+
Object.defineProperty(exports, "formatInstallHBuilderXPluginTips", { enumerable: true, get: function () { return alias_1.formatInstallHBuilderXPluginTips; } });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __exportStar(require("./preprocess"), exports);
|
|
|
29
29
|
__exportStar(require("./postcss"), exports);
|
|
30
30
|
__exportStar(require("./filter"), exports);
|
|
31
31
|
__exportStar(require("./esbuild"), exports);
|
|
32
|
+
__exportStar(require("./resolve"), exports);
|
|
32
33
|
var messages_1 = require("./messages");
|
|
33
34
|
Object.defineProperty(exports, "M", { enumerable: true, get: function () { return messages_1.M; } });
|
|
34
35
|
__exportStar(require("./exports"), exports);
|
package/dist/json/manifest.d.ts
CHANGED
package/dist/json/manifest.js
CHANGED
|
@@ -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;
|
package/dist/json/mp/jsonFile.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.hasJsonFile = exports.isPageFile = void 0;
|
|
4
4
|
const shared_1 = require("@vue/shared");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
|
+
const resolve_1 = require("../../resolve");
|
|
6
7
|
let appJsonCache = {};
|
|
7
8
|
const jsonFilesCache = new Map();
|
|
8
9
|
const jsonPagesCache = new Map();
|
|
@@ -33,7 +34,7 @@ function findChangedJsonFiles() {
|
|
|
33
34
|
const usingComponents = newJson.usingComponents;
|
|
34
35
|
// 格式化为相对路径,这样作为分包也可以直接运行
|
|
35
36
|
Object.keys(usingComponents).forEach((name) => {
|
|
36
|
-
usingComponents[name] = (0,
|
|
37
|
+
usingComponents[name] = (0, resolve_1.relativeFile)(filename, usingComponents[name].slice(1));
|
|
37
38
|
});
|
|
38
39
|
const jsonStr = JSON.stringify(newJson, null, 2);
|
|
39
40
|
if (jsonFilesCache.get(filename) !== jsonStr) {
|
package/dist/mp/template.d.ts
CHANGED
|
@@ -4,7 +4,10 @@ export interface MiniProgramCompilerOptions {
|
|
|
4
4
|
* 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
|
|
5
5
|
*/
|
|
6
6
|
lazyElement?: {
|
|
7
|
-
[name: string]:
|
|
7
|
+
[name: string]: {
|
|
8
|
+
name: 'on' | 'bind';
|
|
9
|
+
arg: string[];
|
|
10
|
+
}[];
|
|
8
11
|
};
|
|
9
12
|
event?: {
|
|
10
13
|
format(name: string, opts: {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function relativeFile(from: string, to: string): string;
|
|
2
|
+
export declare const resolveMainPathOnce: (inputDir: string) => string;
|
|
3
|
+
export declare function getBuiltInPaths(): string[];
|
|
4
|
+
export declare function resolveBuiltIn(path: string): string;
|
|
5
|
+
export declare function resolveComponentsLibPath(): string;
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveComponentsLibPath = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const resolve_1 = __importDefault(require("resolve"));
|
|
11
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const DEFAULT_EXTENSIONS = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'];
|
|
14
|
+
function resolveWithSymlinks(id, basedir) {
|
|
15
|
+
return resolve_1.default.sync(id, {
|
|
16
|
+
basedir,
|
|
17
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
18
|
+
// necessary to work with pnpm
|
|
19
|
+
preserveSymlinks: true,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function relativeFile(from, to) {
|
|
23
|
+
const relativePath = (0, utils_1.normalizePath)(path_1.default.relative(path_1.default.dirname(from), to));
|
|
24
|
+
return relativePath.startsWith('.') ? relativePath : './' + relativePath;
|
|
25
|
+
}
|
|
26
|
+
exports.relativeFile = relativeFile;
|
|
27
|
+
exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
|
|
28
|
+
const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
|
|
29
|
+
if (fs_1.default.existsSync(mainTsPath)) {
|
|
30
|
+
return (0, utils_1.normalizePath)(mainTsPath);
|
|
31
|
+
}
|
|
32
|
+
return (0, utils_1.normalizePath)(path_1.default.resolve(inputDir, 'main.js'));
|
|
33
|
+
});
|
|
34
|
+
const ownerModules = ['@dcloudio/uni-app', '@dcloudio/vite-plugin-uni'];
|
|
35
|
+
const paths = [];
|
|
36
|
+
function resolveNodeModulePath(modulePath) {
|
|
37
|
+
const nodeModulesPaths = [];
|
|
38
|
+
const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
|
|
39
|
+
if (fs_1.default.existsSync(nodeModulesPath)) {
|
|
40
|
+
nodeModulesPaths.push(nodeModulesPath);
|
|
41
|
+
}
|
|
42
|
+
const index = modulePath.lastIndexOf('node_modules');
|
|
43
|
+
if (index > -1) {
|
|
44
|
+
nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
|
|
45
|
+
}
|
|
46
|
+
return nodeModulesPaths;
|
|
47
|
+
}
|
|
48
|
+
function initPaths() {
|
|
49
|
+
const cliContext = process.env.UNI_CLI_CONTEXT;
|
|
50
|
+
if (cliContext) {
|
|
51
|
+
const pathSet = new Set();
|
|
52
|
+
pathSet.add(path_1.default.join(cliContext, 'node_modules'));
|
|
53
|
+
[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
|
|
54
|
+
let pkgPath = '';
|
|
55
|
+
try {
|
|
56
|
+
pkgPath = require.resolve(ownerModule + '/package.json', {
|
|
57
|
+
paths: [cliContext],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (e) { }
|
|
61
|
+
if (pkgPath) {
|
|
62
|
+
resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
|
|
63
|
+
pathSet.add(nodeModulePath);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
paths.push(...pathSet);
|
|
68
|
+
(0, debug_1.default)('uni-paths')(paths);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function getBuiltInPaths() {
|
|
72
|
+
if (!paths.length) {
|
|
73
|
+
initPaths();
|
|
74
|
+
}
|
|
75
|
+
return paths;
|
|
76
|
+
}
|
|
77
|
+
exports.getBuiltInPaths = getBuiltInPaths;
|
|
78
|
+
function resolveBuiltIn(path) {
|
|
79
|
+
return require.resolve(path, { paths: getBuiltInPaths() });
|
|
80
|
+
}
|
|
81
|
+
exports.resolveBuiltIn = resolveBuiltIn;
|
|
82
|
+
let componentsLibPath = '';
|
|
83
|
+
function resolveComponentsLibPath() {
|
|
84
|
+
if (!componentsLibPath) {
|
|
85
|
+
componentsLibPath = path_1.default.join(resolveWithSymlinks('@dcloudio/uni-components/package.json', process.env.UNI_INPUT_DIR), '../lib');
|
|
86
|
+
}
|
|
87
|
+
return componentsLibPath;
|
|
88
|
+
}
|
|
89
|
+
exports.resolveComponentsLibPath = resolveComponentsLibPath;
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export { default as hash } from 'hash-sum';
|
|
2
2
|
import type { SFCTemplateCompileOptions } from '@vue/compiler-sfc';
|
|
3
3
|
import { ElementNode, RootNode, TemplateChildNode } from '@vue/compiler-core';
|
|
4
|
+
export declare let isRunningWithYarnPnp: boolean;
|
|
4
5
|
export declare const isWindows: boolean;
|
|
5
6
|
export declare function normalizePath(id: string): string;
|
|
6
|
-
export declare function relativeFile(from: string, to: string): string;
|
|
7
7
|
export declare function checkElementNodeTag(node: RootNode | TemplateChildNode | null | undefined, tag: string): node is ElementNode;
|
|
8
|
-
export declare const resolveMainPathOnce: (inputDir: string) => string;
|
|
9
|
-
export declare function resolveComponentsLibPath(): string;
|
|
10
|
-
export declare function getBuiltInPaths(): string[];
|
|
11
|
-
export declare function resolveBuiltIn(path: string): string;
|
|
12
8
|
export declare function normalizeIdentifier(str: string): string;
|
|
13
9
|
export declare function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM): string | undefined;
|
|
14
10
|
export declare function removeExt(str: string): string;
|
package/dist/utils.js
CHANGED
|
@@ -3,92 +3,27 @@ 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.createUniVueTransformAssetUrls = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.
|
|
6
|
+
exports.createUniVueTransformAssetUrls = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.hash = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const os_1 = __importDefault(require("os"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const shared_1 = require("@vue/shared");
|
|
11
|
-
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
12
11
|
var hash_sum_1 = require("hash-sum");
|
|
13
12
|
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return __importDefault(hash_sum_1).default; } });
|
|
14
|
-
const debug_1 = __importDefault(require("debug"));
|
|
15
13
|
const constants_1 = require("./constants");
|
|
14
|
+
try {
|
|
15
|
+
exports.isRunningWithYarnPnp = Boolean(require('pnpapi'));
|
|
16
|
+
}
|
|
17
|
+
catch (_a) { }
|
|
16
18
|
exports.isWindows = os_1.default.platform() === 'win32';
|
|
17
19
|
function normalizePath(id) {
|
|
18
20
|
return exports.isWindows ? id.replace(/\\/g, '/') : id;
|
|
19
21
|
}
|
|
20
22
|
exports.normalizePath = normalizePath;
|
|
21
|
-
function relativeFile(from, to) {
|
|
22
|
-
return normalizePath(path_1.default.relative(path_1.default.dirname(from), to));
|
|
23
|
-
}
|
|
24
|
-
exports.relativeFile = relativeFile;
|
|
25
23
|
function checkElementNodeTag(node, tag) {
|
|
26
24
|
return !!node && node.type === 1 /* ELEMENT */ && node.tag === tag;
|
|
27
25
|
}
|
|
28
26
|
exports.checkElementNodeTag = checkElementNodeTag;
|
|
29
|
-
exports.resolveMainPathOnce = (0, uni_shared_1.once)((inputDir) => {
|
|
30
|
-
const mainTsPath = path_1.default.resolve(inputDir, 'main.ts');
|
|
31
|
-
if (fs_1.default.existsSync(mainTsPath)) {
|
|
32
|
-
return normalizePath(mainTsPath);
|
|
33
|
-
}
|
|
34
|
-
return normalizePath(path_1.default.resolve(inputDir, 'main.js'));
|
|
35
|
-
});
|
|
36
|
-
let componentsLibPath = '';
|
|
37
|
-
function resolveComponentsLibPath() {
|
|
38
|
-
if (!componentsLibPath) {
|
|
39
|
-
componentsLibPath = path_1.default.resolve(resolveBuiltIn('@dcloudio/uni-components/package.json'), '../lib');
|
|
40
|
-
}
|
|
41
|
-
return componentsLibPath;
|
|
42
|
-
}
|
|
43
|
-
exports.resolveComponentsLibPath = resolveComponentsLibPath;
|
|
44
|
-
const ownerModules = ['@dcloudio/uni-app', '@dcloudio/vite-plugin-uni'];
|
|
45
|
-
const paths = [];
|
|
46
|
-
function resolveNodeModulePath(modulePath) {
|
|
47
|
-
const nodeModulesPaths = [];
|
|
48
|
-
const nodeModulesPath = path_1.default.join(modulePath, 'node_modules');
|
|
49
|
-
if (fs_1.default.existsSync(nodeModulesPath)) {
|
|
50
|
-
nodeModulesPaths.push(nodeModulesPath);
|
|
51
|
-
}
|
|
52
|
-
const index = modulePath.lastIndexOf('node_modules');
|
|
53
|
-
if (index > -1) {
|
|
54
|
-
nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
|
|
55
|
-
}
|
|
56
|
-
return nodeModulesPaths;
|
|
57
|
-
}
|
|
58
|
-
function initPaths() {
|
|
59
|
-
const cliContext = process.env.UNI_CLI_CONTEXT;
|
|
60
|
-
if (cliContext) {
|
|
61
|
-
const pathSet = new Set();
|
|
62
|
-
pathSet.add(path_1.default.join(cliContext, 'node_modules'));
|
|
63
|
-
[`@dcloudio/uni-` + process.env.UNI_PLATFORM, ...ownerModules].forEach((ownerModule) => {
|
|
64
|
-
let pkgPath = '';
|
|
65
|
-
try {
|
|
66
|
-
pkgPath = require.resolve(ownerModule + '/package.json', {
|
|
67
|
-
paths: [cliContext],
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (e) { }
|
|
71
|
-
if (pkgPath) {
|
|
72
|
-
resolveNodeModulePath(path_1.default.dirname(pkgPath)).forEach((nodeModulePath) => {
|
|
73
|
-
pathSet.add(nodeModulePath);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
paths.push(...pathSet);
|
|
78
|
-
(0, debug_1.default)('uni-paths')(paths);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function getBuiltInPaths() {
|
|
82
|
-
if (!paths.length) {
|
|
83
|
-
initPaths();
|
|
84
|
-
}
|
|
85
|
-
return paths;
|
|
86
|
-
}
|
|
87
|
-
exports.getBuiltInPaths = getBuiltInPaths;
|
|
88
|
-
function resolveBuiltIn(path) {
|
|
89
|
-
return require.resolve(path, { paths: getBuiltInPaths() });
|
|
90
|
-
}
|
|
91
|
-
exports.resolveBuiltIn = resolveBuiltIn;
|
|
92
27
|
function normalizeIdentifier(str) {
|
|
93
28
|
return (0, shared_1.capitalize)((0, shared_1.camelize)(str.replace(/\//g, '-')));
|
|
94
29
|
}
|
|
@@ -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
|
}
|
package/dist/vite/utils/ast.d.ts
CHANGED
|
@@ -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;
|
package/dist/vite/utils/ast.js
CHANGED
|
@@ -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-
|
|
3
|
+
"version": "3.0.0-alpha-3021320211119002",
|
|
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-
|
|
24
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
23
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-3021320211119002",
|
|
24
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211119002",
|
|
25
25
|
"@rollup/pluginutils": "^4.1.1",
|
|
26
26
|
"@vue/compiler-core": "3.2.22",
|
|
27
27
|
"@vue/compiler-dom": "3.2.22",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"postcss-import": "^14.0.2",
|
|
45
45
|
"postcss-load-config": "^3.1.0",
|
|
46
46
|
"postcss-selector-parser": "^6.0.6",
|
|
47
|
+
"resolve": "^1.20.0",
|
|
47
48
|
"rollup-plugin-copy": "^3.4.0",
|
|
48
49
|
"tapable": "^2.2.0",
|
|
49
50
|
"xregexp": "3.1.0"
|