@dcloudio/uni-cli-shared 3.0.0-alpha-1000920260519001 → 3.0.0-alpha-1000920260522733
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/index.d.ts +1 -1
- package/dist/logs/console.js +1 -14
- package/dist/mp/imports.d.ts +1 -3
- package/dist/mp/template.d.ts +1 -2
- package/dist/mp/usingComponents.d.ts +1 -2
- package/dist/vite/cloud.js +7 -2
- package/dist/vite/index.d.ts +3 -2
- package/dist/vite/plugins/console.js +26 -29
- package/dist/vite/plugins/copy.js +0 -1
- package/dist/vite/plugins/cssScoped.js +8 -13
- package/dist/vite/plugins/dynamicImportPolyfill.d.ts +1 -8
- package/dist/vite/plugins/easycom.js +43 -46
- package/dist/vite/plugins/inject.js +113 -127
- package/dist/vite/plugins/json.js +14 -17
- package/dist/vite/plugins/jsonJs.d.ts +2 -2
- package/dist/vite/plugins/jsonJs.js +0 -7
- package/dist/vite/plugins/mainJs.d.ts +1 -1
- package/dist/vite/plugins/mainJs.js +0 -7
- package/dist/vite/plugins/pre.js +30 -35
- package/dist/vite/plugins/sfc.js +1 -11
- package/dist/vite/plugins/sourceMap.js +1 -4
- package/dist/vite/plugins/uts/ext-api.js +17 -23
- package/dist/vite/plugins/uts/uni_modules.js +39 -66
- package/dist/vite/plugins/uts/uvue.js +48 -55
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +4 -11
- package/dist/vite/plugins/vitejs/plugins/asset.js +1 -1
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +1 -4
- package/dist/vite/plugins/vitejs/plugins/css.js +73 -88
- package/dist/vite/utils/utils.d.ts +2 -3
- package/package.json +5 -5
- package/lib/@vue/compiler-core/node_modules/.bin/parser +0 -17
package/dist/hbx/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { formatAtFilename, createErrorWithBlockFlag } from './log';
|
|
2
2
|
export * from './env';
|
|
3
3
|
export { initModuleAlias, installHBuilderXPlugin, formatInstallHBuilderXPluginTips, } from './alias';
|
|
4
|
-
export declare function uniHBuilderXConsolePlugin(method?: string): import("vite
|
|
4
|
+
export declare function uniHBuilderXConsolePlugin(method?: string): import("vite").Plugin<any>;
|
|
5
5
|
export declare function isEnableConsole(): boolean;
|
package/dist/logs/console.js
CHANGED
|
@@ -19,25 +19,12 @@ function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
|
|
|
19
19
|
if (s.hasChanged()) {
|
|
20
20
|
return {
|
|
21
21
|
code: s.toString(),
|
|
22
|
-
map: sourceMap
|
|
23
|
-
? normalizeSourceMap(s.generateMap({ hires: true }))
|
|
24
|
-
: { mappings: '' },
|
|
22
|
+
map: sourceMap ? s.generateMap({ hires: true }) : { mappings: '' },
|
|
25
23
|
};
|
|
26
24
|
}
|
|
27
25
|
return { code, map: null };
|
|
28
26
|
}
|
|
29
27
|
exports.rewriteConsoleExpr = rewriteConsoleExpr;
|
|
30
|
-
function normalizeSourceMap(map) {
|
|
31
|
-
return {
|
|
32
|
-
...map,
|
|
33
|
-
file: map.file || '',
|
|
34
|
-
names: map.names || [],
|
|
35
|
-
sources: map.sources || [],
|
|
36
|
-
sourcesContent: map.sourcesContent || [],
|
|
37
|
-
toString: () => map.toString(),
|
|
38
|
-
toUrl: () => map.toUrl(),
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
28
|
function restoreConsoleExpr(code) {
|
|
42
29
|
return code.replace(/(?:uni\.)?__f__\('([^']+)','at ([^:]+):(\d+)',/g, 'console.$1(');
|
|
43
30
|
}
|
package/dist/mp/imports.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import type { PluginContext } from 'rollup';
|
|
1
2
|
import { type ImportSpecifier } from 'es-module-lexer';
|
|
2
|
-
import type { Rolldown } from 'vite';
|
|
3
|
-
type PluginContext = Rolldown.PluginContext;
|
|
4
3
|
/**
|
|
5
4
|
* 暂时没用
|
|
6
5
|
* @param source
|
|
@@ -11,4 +10,3 @@ type PluginContext = Rolldown.PluginContext;
|
|
|
11
10
|
export declare function findVueComponentImports(source: string, importer: string, resolve: PluginContext['resolve']): Promise<(ImportSpecifier & {
|
|
12
11
|
i: string;
|
|
13
12
|
})[]>;
|
|
14
|
-
export {};
|
package/dist/mp/template.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EmittedAsset } from 'rollup';
|
|
2
2
|
import type { AttributeNode, DirectiveNode, ElementNode } from '@vue/compiler-core';
|
|
3
3
|
import type { MiniProgramComponentsType } from '../json/mp/types';
|
|
4
|
-
type EmittedAsset = Rolldown.EmittedAsset;
|
|
5
4
|
type LazyElementFn = (node: ElementNode, context: {
|
|
6
5
|
isMiniProgramComponent(name: string): MiniProgramComponentsType | undefined;
|
|
7
6
|
}) => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { type ImportDeclaration, type Program } from '@babel/types';
|
|
2
|
-
import type {
|
|
3
|
-
type PluginContext = Rolldown.PluginContext;
|
|
2
|
+
import type { PluginContext } from 'rollup';
|
|
4
3
|
type BindingComponents = Record<string, {
|
|
5
4
|
tag: string;
|
|
6
5
|
type: 'unknown' | 'setup' | 'self';
|
package/dist/vite/cloud.js
CHANGED
|
@@ -131,13 +131,18 @@ function uniEncryptUniModulesPlugin() {
|
|
|
131
131
|
}
|
|
132
132
|
delete bundle[fileName];
|
|
133
133
|
const pkg = `uni_modules/${uniModuleId}/package.json`;
|
|
134
|
-
|
|
134
|
+
bundle[pkg] = {
|
|
135
135
|
type: 'asset',
|
|
136
136
|
fileName: pkg,
|
|
137
|
+
name: pkg,
|
|
138
|
+
names: [pkg],
|
|
139
|
+
originalFileName: null,
|
|
140
|
+
originalFileNames: [],
|
|
141
|
+
needsCodeReference: false,
|
|
137
142
|
source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, {
|
|
138
143
|
env: (0, uni_modules_cloud_1.initCheckEnv)(),
|
|
139
144
|
}),
|
|
140
|
-
}
|
|
145
|
+
};
|
|
141
146
|
}
|
|
142
147
|
else if (fileName.endsWith('.js')) {
|
|
143
148
|
if (isMp) {
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Plugin
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { EmittedAsset } from 'rollup';
|
|
2
3
|
import type { ParserOptions } from '@vue/compiler-core';
|
|
3
4
|
import type { CompilerOptions, SFCStyleCompileOptions, TemplateCompiler } from '@vue/compiler-sfc';
|
|
4
5
|
import type { UniViteCopyPluginOptions } from './plugins/copy';
|
|
@@ -16,7 +17,7 @@ interface UniVitePluginUniOptions {
|
|
|
16
17
|
styleOptions?: Pick<SFCStyleCompileOptions, 'postcssPlugins'>;
|
|
17
18
|
compilerOptions?: {
|
|
18
19
|
miniProgram?: {
|
|
19
|
-
emitFile?: (emittedFile:
|
|
20
|
+
emitFile?: (emittedFile: EmittedAsset) => string;
|
|
20
21
|
};
|
|
21
22
|
isNativeTag?: ParserOptions['isNativeTag'];
|
|
22
23
|
isVoidTag?: ParserOptions['isVoidTag'];
|
|
@@ -29,35 +29,32 @@ function uniConsolePlugin(options) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
|
-
transform
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
debugConsole(id);
|
|
59
|
-
return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
|
|
60
|
-
},
|
|
32
|
+
transform(code, id) {
|
|
33
|
+
if (dropConsole) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if ((0, filter_1.isRenderjs)(id) || (0, filter_1.isWxs)(id)) {
|
|
37
|
+
return {
|
|
38
|
+
code: (0, console_1.restoreConsoleExpr)(code),
|
|
39
|
+
map: null,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
if (!filter(id))
|
|
43
|
+
return null;
|
|
44
|
+
if (!(0, utils_1.isJsFile)(id))
|
|
45
|
+
return null;
|
|
46
|
+
let { filename } = (0, utils_1.parseVueRequest)(id);
|
|
47
|
+
if (options.filename) {
|
|
48
|
+
filename = options.filename(filename);
|
|
49
|
+
}
|
|
50
|
+
if (!filename) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (!code.includes('console.')) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
debugConsole(id);
|
|
57
|
+
return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
|
|
61
58
|
},
|
|
62
59
|
};
|
|
63
60
|
}
|
|
@@ -13,7 +13,6 @@ const utils_1 = require("../../utils");
|
|
|
13
13
|
const utils_2 = require("../../vue/utils");
|
|
14
14
|
const debugScoped = (0, debug_1.default)('uni:scoped');
|
|
15
15
|
const SCOPED_RE = /<style\s[^>]*scoped[^>]*>/i;
|
|
16
|
-
const VUE_SFC_ID_RE = /\.(?:vue|nvue|uvue)(?:$|\?(?!vue(?:&|=|$)))/;
|
|
17
16
|
function addScoped(code) {
|
|
18
17
|
return code.replace(/(<style\b[^><]*)>/gi, (str, $1) => {
|
|
19
18
|
if ($1.includes('scoped')) {
|
|
@@ -50,18 +49,14 @@ function uniCssScopedPlugin({ filter } = { filter: () => false }) {
|
|
|
50
49
|
return {
|
|
51
50
|
name: 'uni:css-scoped',
|
|
52
51
|
enforce: 'pre',
|
|
53
|
-
transform
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
code: addScoped(code),
|
|
62
|
-
map: null,
|
|
63
|
-
};
|
|
64
|
-
},
|
|
52
|
+
transform(code, id) {
|
|
53
|
+
if (!filter(id))
|
|
54
|
+
return null;
|
|
55
|
+
debugScoped(id);
|
|
56
|
+
return {
|
|
57
|
+
code: addScoped(code),
|
|
58
|
+
map: null,
|
|
59
|
+
};
|
|
65
60
|
},
|
|
66
61
|
// 仅 h5
|
|
67
62
|
handleHotUpdate(ctx) {
|
|
@@ -1,9 +1,2 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
renderDynamicImport(): {
|
|
4
|
-
left: string;
|
|
5
|
-
right: string;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
8
|
-
export declare function dynamicImportPolyfill(promise?: boolean): DynamicImportPolyfillPlugin;
|
|
9
|
-
export {};
|
|
2
|
+
export declare function dynamicImportPolyfill(promise?: boolean): Plugin;
|
|
@@ -16,56 +16,53 @@ function uniEasycomPlugin(options) {
|
|
|
16
16
|
const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
|
|
17
17
|
return {
|
|
18
18
|
name: 'uni:app-easycom',
|
|
19
|
-
transform
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
|
|
41
|
-
:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
(0, easycom_1.addImportDeclaration)(importDeclarations, '', utsCustomElement.source, '');
|
|
49
|
-
return `'${name}'`;
|
|
50
|
-
}
|
|
19
|
+
transform(code, id) {
|
|
20
|
+
if (!filter(id)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const { filename } = (0, url_1.parseVueRequest)(id);
|
|
24
|
+
if (!constants_1.EXTNAME_VUE_TEMPLATE.includes(path_1.default.extname(filename))) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!code.includes('_resolveComponent')) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let i = 0;
|
|
31
|
+
const importDeclarations = [];
|
|
32
|
+
code = code.replace(/_resolveComponent\("(.+?)"(, true)?\)/g, (str, name) => {
|
|
33
|
+
if (name && !name.startsWith('_')) {
|
|
34
|
+
const source = (0, easycom_1.matchEasycom)(name);
|
|
35
|
+
if (source) {
|
|
36
|
+
// 处理easycom组件优先级
|
|
37
|
+
return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
|
|
38
|
+
? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
|
|
39
|
+
: source.includes('uni_helpers')
|
|
40
|
+
? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
|
|
41
|
+
: ''));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const utsCustomElement = (0, uts_1.getUTSCustomElement)(name);
|
|
45
|
+
if (utsCustomElement) {
|
|
46
|
+
(0, easycom_1.addImportDeclaration)(importDeclarations, '', utsCustomElement.source, '');
|
|
47
|
+
return `'${name}'`;
|
|
51
48
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
}
|
|
50
|
+
if (process.env.UNI_APP_X === 'true') {
|
|
51
|
+
if ((0, uni_shared_1.isAppUVueBuiltInEasyComponent)(name)) {
|
|
52
|
+
// 内置easycom组件不传入self参数
|
|
53
|
+
return str.replace(', true)', ')');
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
|
-
return str;
|
|
60
|
-
});
|
|
61
|
-
if (importDeclarations.length) {
|
|
62
|
-
code = importDeclarations.join('') + code;
|
|
63
56
|
}
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
57
|
+
return str;
|
|
58
|
+
});
|
|
59
|
+
if (importDeclarations.length) {
|
|
60
|
+
code = importDeclarations.join('') + code;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
code,
|
|
64
|
+
map: null,
|
|
65
|
+
};
|
|
69
66
|
},
|
|
70
67
|
};
|
|
71
68
|
}
|
|
@@ -38,154 +38,140 @@ function uniViteInjectPlugin(name, options) {
|
|
|
38
38
|
normalizeModulesMap(modulesMap);
|
|
39
39
|
normalizeModulesMap(namespaceModulesMap);
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
const exactKeys = Array.from(modulesMap.keys()).filter((name) => !name.endsWith('.'));
|
|
43
|
-
// 仅匹配独立标识符,避免 uni/wx 等短名称命中 function、undefined 等普通单词。
|
|
44
|
-
// namespace 配置以 "." 结尾,后面会继续跟方法名,不能统一追加右边界。
|
|
45
|
-
const firstpass = new RegExp(`(?:^|[^\\w$])(?:${[
|
|
46
|
-
...namespaceKeys.map(escape),
|
|
47
|
-
...exactKeys.map((name) => `${escape(name)}(?![\\w$])`),
|
|
48
|
-
].join('|')})`, 'g');
|
|
49
|
-
const firstpassFilter = new RegExp(firstpass.source);
|
|
50
|
-
const jsIdFilter = /(?:\.(?:js|jsx|ts|uts|tsx|mjs)(?:$|\?)|\.(?:vue|nvue|uvue)(?:$|\?)|\?uni_helpers$)/;
|
|
41
|
+
const firstpass = new RegExp(`(?:${Array.from(modulesMap.keys()).map(escape).join('|')})`, 'g');
|
|
51
42
|
const sourceMap = options.sourceMap !== false;
|
|
52
43
|
const callback = options.callback;
|
|
53
44
|
return {
|
|
54
45
|
name,
|
|
55
46
|
// 确保在 commonjs 之后,否则会混合 es6 module 与 cjs 的代码,导致 commonjs 失效
|
|
56
47
|
enforce: options.enforce ?? 'post',
|
|
57
|
-
transform
|
|
58
|
-
filter
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if ((
|
|
91
|
-
|
|
92
|
-
if (testFn(mods[1])) {
|
|
93
|
-
mod = [mod[0], mods[1]];
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
mod = undefined;
|
|
97
|
-
}
|
|
48
|
+
transform(code, id) {
|
|
49
|
+
if (!filter(id))
|
|
50
|
+
return null;
|
|
51
|
+
// 加密插件也要走后续注入逻辑
|
|
52
|
+
if (!(0, utils_1.isJsFile)(id) && !(0, uts_1.isUniHelpers)(id))
|
|
53
|
+
return null;
|
|
54
|
+
// debugInjectTry(id)
|
|
55
|
+
if (code.search(firstpass) === -1)
|
|
56
|
+
return null;
|
|
57
|
+
if (path_1.sep !== '/')
|
|
58
|
+
id = id.split(path_1.sep).join('/');
|
|
59
|
+
const ast = this.parse(code);
|
|
60
|
+
const imports = new Set();
|
|
61
|
+
ast.body.forEach((node) => {
|
|
62
|
+
if (node.type === 'ImportDeclaration') {
|
|
63
|
+
node.specifiers.forEach((specifier) => {
|
|
64
|
+
imports.add(specifier.local.name);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
// analyse scopes
|
|
69
|
+
let scope = (0, pluginutils_1.attachScopes)(ast, 'scope');
|
|
70
|
+
const magicString = new magic_string_1.default(code);
|
|
71
|
+
const newImports = new Map();
|
|
72
|
+
function handleReference(node, name, keypath, parent) {
|
|
73
|
+
let mod = modulesMap.get(keypath);
|
|
74
|
+
if (!mod && hasNamespace) {
|
|
75
|
+
const mods = keypath.split('.');
|
|
76
|
+
if (mods.length === 2) {
|
|
77
|
+
mod = namespaceModulesMap.get(mods[0] + '.');
|
|
78
|
+
if (mod) {
|
|
79
|
+
if ((0, shared_1.isArray)(mod)) {
|
|
80
|
+
const testFn = mod[1];
|
|
81
|
+
if (testFn(mods[1])) {
|
|
82
|
+
mod = [mod[0], mods[1]];
|
|
98
83
|
}
|
|
99
84
|
else {
|
|
100
|
-
mod =
|
|
85
|
+
mod = undefined;
|
|
101
86
|
}
|
|
102
87
|
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (mod && !imports.has(name) && !scope.contains(name)) {
|
|
106
|
-
if ((0, shared_1.isString)(mod))
|
|
107
|
-
mod = [mod, 'default'];
|
|
108
|
-
if (mod[0] === id)
|
|
109
|
-
return false;
|
|
110
|
-
const hash = `${keypath}:${mod[0]}:${mod[1]}`;
|
|
111
|
-
// 当 API 被覆盖定义后,不再摇树
|
|
112
|
-
if (reassignments.has(hash)) {
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
if (parent &&
|
|
116
|
-
(0, utils_1.isAssignmentExpression)(parent) &&
|
|
117
|
-
parent.left === node) {
|
|
118
|
-
reassignments.add(hash);
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const importLocalName = name === keypath
|
|
122
|
-
? name
|
|
123
|
-
: (0, pluginutils_1.makeLegalIdentifier)(`$inject_${keypath}`);
|
|
124
|
-
if (!newImports.has(hash)) {
|
|
125
|
-
if (mod[1] === '*') {
|
|
126
|
-
newImports.set(hash, `import * as ${importLocalName} from '${mod[0]}';`);
|
|
127
|
-
}
|
|
128
88
|
else {
|
|
129
|
-
|
|
130
|
-
callback && callback(newImports, mod);
|
|
89
|
+
mod = [mod, mods[1]];
|
|
131
90
|
}
|
|
132
91
|
}
|
|
133
|
-
if (name !== keypath) {
|
|
134
|
-
magicString.overwrite(node.start, node.end, importLocalName, {
|
|
135
|
-
storeName: true,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
92
|
}
|
|
140
|
-
return false;
|
|
141
93
|
}
|
|
142
|
-
(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
94
|
+
if (mod && !imports.has(name) && !scope.contains(name)) {
|
|
95
|
+
if ((0, shared_1.isString)(mod))
|
|
96
|
+
mod = [mod, 'default'];
|
|
97
|
+
if (mod[0] === id)
|
|
98
|
+
return false;
|
|
99
|
+
const hash = `${keypath}:${mod[0]}:${mod[1]}`;
|
|
100
|
+
// 当 API 被覆盖定义后,不再摇树
|
|
101
|
+
if (reassignments.has(hash)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (parent &&
|
|
105
|
+
(0, utils_1.isAssignmentExpression)(parent) &&
|
|
106
|
+
parent.left === node) {
|
|
107
|
+
reassignments.add(hash);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
const importLocalName = name === keypath ? name : (0, pluginutils_1.makeLegalIdentifier)(`$inject_${keypath}`);
|
|
111
|
+
if (!newImports.has(hash)) {
|
|
112
|
+
if (mod[1] === '*') {
|
|
113
|
+
newImports.set(hash, `import * as ${importLocalName} from '${mod[0]}';`);
|
|
147
114
|
}
|
|
148
|
-
|
|
149
|
-
|
|
115
|
+
else {
|
|
116
|
+
newImports.set(hash, `import { ${mod[1]} as ${importLocalName} } from '${mod[0]}';`);
|
|
117
|
+
callback && callback(newImports, mod);
|
|
150
118
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
119
|
+
}
|
|
120
|
+
if (name !== keypath) {
|
|
121
|
+
magicString.overwrite(node.start, node.end, importLocalName, {
|
|
122
|
+
storeName: true,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
(0, estree_walker_1.walk)(ast, {
|
|
130
|
+
enter(node, parent) {
|
|
131
|
+
if (sourceMap) {
|
|
132
|
+
magicString.addSourcemapLocation(node.start);
|
|
133
|
+
magicString.addSourcemapLocation(node.end);
|
|
134
|
+
}
|
|
135
|
+
if (node.scope) {
|
|
136
|
+
scope = node.scope;
|
|
137
|
+
}
|
|
138
|
+
if ((0, utils_1.isProperty)(node) && node.shorthand) {
|
|
139
|
+
const { name } = node.key;
|
|
140
|
+
handleReference(node, name, name);
|
|
141
|
+
this.skip();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if ((0, utils_1.isReference)(node, parent)) {
|
|
145
|
+
const { name, keypath } = flatten(node);
|
|
146
|
+
const handled = handleReference(node, name, keypath, parent);
|
|
147
|
+
if (handled) {
|
|
154
148
|
this.skip();
|
|
155
|
-
return;
|
|
156
149
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
scope = scope.parent;
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
debugInject(id, newImports.size);
|
|
172
|
-
if (newImports.size === 0) {
|
|
173
|
-
return {
|
|
174
|
-
code,
|
|
175
|
-
// 不能返回 ast ,否则会导致代码不能被再次修改
|
|
176
|
-
// 比如 App.vue 中,console.log('uniCloud') 触发了 inject 检测,检测完,发现不需要
|
|
177
|
-
// 此时返回 ast,会导致 import { setupApp } from '@dcloudio/uni-h5' 不会被编译
|
|
178
|
-
// ast
|
|
179
|
-
map: null,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
const importBlock = Array.from(newImports.values()).join('\n\n');
|
|
183
|
-
magicString.prepend(`${importBlock}\n\n`);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
leave(node) {
|
|
153
|
+
if (node.scope) {
|
|
154
|
+
scope = scope.parent;
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
debugInject(id, newImports.size);
|
|
159
|
+
if (newImports.size === 0) {
|
|
184
160
|
return {
|
|
185
|
-
code
|
|
186
|
-
|
|
161
|
+
code,
|
|
162
|
+
// 不能返回 ast ,否则会导致代码不能被再次修改
|
|
163
|
+
// 比如 App.vue 中,console.log('uniCloud') 触发了 inject 检测,检测完,发现不需要
|
|
164
|
+
// 此时返回 ast,会导致 import { setupApp } from '@dcloudio/uni-h5' 不会被编译
|
|
165
|
+
// ast
|
|
166
|
+
map: null,
|
|
187
167
|
};
|
|
188
|
-
}
|
|
168
|
+
}
|
|
169
|
+
const importBlock = Array.from(newImports.values()).join('\n\n');
|
|
170
|
+
magicString.prepend(`${importBlock}\n\n`);
|
|
171
|
+
return {
|
|
172
|
+
code: magicString.toString(),
|
|
173
|
+
map: sourceMap ? magicString.generateMap({ hires: true }) : null,
|
|
174
|
+
};
|
|
189
175
|
},
|
|
190
176
|
};
|
|
191
177
|
}
|
|
@@ -12,23 +12,20 @@ function uniJsonPlugin() {
|
|
|
12
12
|
return {
|
|
13
13
|
name: 'uni:json',
|
|
14
14
|
enforce: 'pre',
|
|
15
|
-
transform
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
},
|
|
15
|
+
transform(code, id) {
|
|
16
|
+
// 如果已经被其他插件处理过了,就不再处理,比如 commonjs 插件,ICAPRegistrar.json?commonjs-external
|
|
17
|
+
if (id.startsWith('\0')) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (path_1.default.extname((0, utils_1.parseVueRequest)(id).filename) !== '.json') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
code: JSON.stringify((0, json_1.parseJson)((0, preprocess_1.preJson)(code, id), false, id), null, 2),
|
|
25
|
+
map: {
|
|
26
|
+
mappings: '',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
32
29
|
},
|
|
33
30
|
};
|
|
34
31
|
}
|