@dcloudio/uni-cli-shared 3.0.0-4010420240430002 → 3.0.0-4020320240708001
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/easycom.js +35 -3
- package/dist/fs.js +8 -5
- package/dist/hbx/log.js +9 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/dist/json/app/manifest/nvue.d.ts +1 -1
- package/dist/json/app/pages/definePage.d.ts +1 -1
- package/dist/json/app/pages/definePage.js +3 -3
- package/dist/json/app/pages/index.d.ts +1 -1
- package/dist/json/app/pages/index.js +2 -2
- package/dist/json/manifest.d.ts +1 -0
- package/dist/json/manifest.js +13 -2
- package/dist/json/pages.js +20 -2
- package/dist/json/theme.d.ts +19 -0
- package/dist/json/theme.js +240 -2
- package/dist/json/uni-x/uniConfig.js +5 -0
- package/dist/messages/en.d.ts +1 -0
- package/dist/messages/en.js +1 -0
- package/dist/messages/index.d.ts +2 -0
- package/dist/messages/zh_CN.d.ts +1 -0
- package/dist/messages/zh_CN.js +1 -0
- package/dist/postcss/plugins/uniapp.js +1 -0
- package/dist/preprocess/context.js +10 -2
- package/dist/resolve.js +6 -1
- package/dist/uni_modules.d.ts +51 -0
- package/dist/uni_modules.js +357 -23
- package/dist/utils.d.ts +14 -1
- package/dist/utils.js +39 -3
- package/dist/uts.d.ts +1 -1
- package/dist/uts.js +10 -3
- package/dist/vite/autoImport.js +16 -2
- package/dist/vite/cloud.d.ts +6 -0
- package/dist/vite/cloud.js +305 -0
- package/dist/vite/index.d.ts +2 -0
- package/dist/vite/index.js +4 -1
- package/dist/vite/plugins/easycom.js +3 -1
- package/dist/vite/plugins/uts/uni_modules.d.ts +3 -2
- package/dist/vite/plugins/uts/uni_modules.js +76 -14
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +3 -3
- package/dist/vite/plugins/vitejs/plugins/asset.js +11 -9
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +6 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +27 -25
- package/dist/vite/plugins/vitejs/plugins/static.d.ts +2 -0
- package/dist/vite/plugins/vitejs/plugins/static.js +40 -0
- package/dist/vite/utils/index.js +3 -0
- package/dist/vite/utils/plugin.d.ts +5 -2
- package/dist/vite/utils/plugin.js +7 -2
- package/dist/vite/utils/utils.js +3 -0
- package/dist/vue/transforms/transformPageHead.js +7 -3
- package/package.json +7 -4
package/dist/uts.js
CHANGED
|
@@ -27,7 +27,7 @@ function once(fn, ctx = null) {
|
|
|
27
27
|
* @param importer
|
|
28
28
|
* @returns
|
|
29
29
|
*/
|
|
30
|
-
function resolveUTSAppModule(id, importer, includeUTSSDK = true) {
|
|
30
|
+
function resolveUTSAppModule(platform, id, importer, includeUTSSDK = true) {
|
|
31
31
|
id = path_1.default.resolve(importer, id);
|
|
32
32
|
if (id.includes('uni_modules') || (includeUTSSDK && id.includes('utssdk'))) {
|
|
33
33
|
const parts = (0, utils_1.normalizePath)(id).split('/');
|
|
@@ -51,6 +51,12 @@ function resolveUTSAppModule(id, importer, includeUTSSDK = true) {
|
|
|
51
51
|
return path_1.default.resolve(id, basedir, p);
|
|
52
52
|
};
|
|
53
53
|
const extname = ['.uts'];
|
|
54
|
+
if (platform === 'app-harmony') {
|
|
55
|
+
if (resolveUTSFile(resolvePlatformDir(platform), extname)) {
|
|
56
|
+
return id;
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
54
60
|
if (resolveUTSFile(resolvePlatformDir('app-android'), extname)) {
|
|
55
61
|
return id;
|
|
56
62
|
}
|
|
@@ -64,8 +70,9 @@ exports.resolveUTSAppModule = resolveUTSAppModule;
|
|
|
64
70
|
// 仅限 root/uni_modules/test-plugin | root/utssdk/test-plugin 格式
|
|
65
71
|
function resolveUTSModule(id, importer, includeUTSSDK = true) {
|
|
66
72
|
if (process.env.UNI_PLATFORM === 'app' ||
|
|
67
|
-
process.env.UNI_PLATFORM === 'app-plus'
|
|
68
|
-
|
|
73
|
+
process.env.UNI_PLATFORM === 'app-plus' ||
|
|
74
|
+
process.env.UNI_PLATFORM === 'app-harmony') {
|
|
75
|
+
return resolveUTSAppModule(process.env.UNI_UTS_PLATFORM, id, importer);
|
|
69
76
|
}
|
|
70
77
|
id = path_1.default.resolve(importer, id);
|
|
71
78
|
if (id.includes('uni_modules') || (includeUTSSDK && id.includes('utssdk'))) {
|
package/dist/vite/autoImport.js
CHANGED
|
@@ -4,12 +4,14 @@ exports.initAutoImportOptions = void 0;
|
|
|
4
4
|
const uniPreset = {
|
|
5
5
|
from: '@dcloudio/uni-app',
|
|
6
6
|
imports: [
|
|
7
|
+
// ssr
|
|
8
|
+
'ssrRef',
|
|
9
|
+
'shallowSsrRef',
|
|
7
10
|
// uni-app lifecycle
|
|
8
11
|
// App and Page
|
|
9
12
|
'onShow',
|
|
10
13
|
'onHide',
|
|
11
14
|
// App
|
|
12
|
-
'onAppShow',
|
|
13
15
|
'onLaunch',
|
|
14
16
|
'onError',
|
|
15
17
|
'onThemeChange',
|
|
@@ -37,6 +39,10 @@ const uniPreset = {
|
|
|
37
39
|
const uniH5Preset = {
|
|
38
40
|
from: '@dcloudio/uni-h5',
|
|
39
41
|
imports: [
|
|
42
|
+
'onAppShow',
|
|
43
|
+
'onAppHide',
|
|
44
|
+
'offAppHide',
|
|
45
|
+
'offAppShow',
|
|
40
46
|
'UniElement',
|
|
41
47
|
'UniElementImpl',
|
|
42
48
|
'UniButtonElement',
|
|
@@ -126,13 +132,21 @@ const vuePreset = {
|
|
|
126
132
|
'defineComponent',
|
|
127
133
|
'defineAsyncComponent',
|
|
128
134
|
'getCurrentInstance',
|
|
129
|
-
'h',
|
|
130
135
|
'inject',
|
|
131
136
|
'nextTick',
|
|
132
137
|
'provide',
|
|
133
138
|
'useCssModule',
|
|
134
139
|
'createApp',
|
|
135
140
|
'hasInjectionContext',
|
|
141
|
+
// render
|
|
142
|
+
'h',
|
|
143
|
+
'mergeProps',
|
|
144
|
+
'cloneVNode',
|
|
145
|
+
'isVNode',
|
|
146
|
+
'resolveComponent',
|
|
147
|
+
'resolveDirective',
|
|
148
|
+
'withDirectives',
|
|
149
|
+
'withModifiers',
|
|
136
150
|
// effect scope
|
|
137
151
|
'effectScope',
|
|
138
152
|
'EffectScope',
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin, ResolveFn } from 'vite';
|
|
2
|
+
import type { CssUrlReplacer } from './plugins/vitejs/plugins/css';
|
|
3
|
+
export declare function createEncryptCssUrlReplacer(resolve: ResolveFn): CssUrlReplacer;
|
|
4
|
+
export declare function uniEncryptUniModulesAssetsPlugin(): Plugin;
|
|
5
|
+
export declare function uniEncryptUniModulesPlugin(): Plugin;
|
|
6
|
+
export declare function addUniModulesExtApiComponents(relativeFilename: string, components: string[]): void;
|
|
@@ -0,0 +1,305 @@
|
|
|
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.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.uniEncryptUniModulesAssetsPlugin = exports.createEncryptCssUrlReplacer = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const uni_modules_1 = require("../uni_modules");
|
|
10
|
+
const utils_1 = require("./plugins/vitejs/utils");
|
|
11
|
+
const uts_1 = require("../uts");
|
|
12
|
+
const utils_2 = require("../utils");
|
|
13
|
+
const easycom_1 = require("../easycom");
|
|
14
|
+
function createEncryptCssUrlReplacer(resolve) {
|
|
15
|
+
return async (url, importer) => {
|
|
16
|
+
if (url.startsWith('/') && !url.startsWith('//')) {
|
|
17
|
+
// /static/logo.png => @/static/logo.png
|
|
18
|
+
url = '@' + url;
|
|
19
|
+
}
|
|
20
|
+
const resolved = await resolve(url, importer);
|
|
21
|
+
if (resolved) {
|
|
22
|
+
return ('@/' + (0, utils_2.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, resolved)));
|
|
23
|
+
}
|
|
24
|
+
return url;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.createEncryptCssUrlReplacer = createEncryptCssUrlReplacer;
|
|
28
|
+
// 处理静态资源加载(目前仅限非app-android)
|
|
29
|
+
function uniEncryptUniModulesAssetsPlugin() {
|
|
30
|
+
let resolvedConfig;
|
|
31
|
+
return {
|
|
32
|
+
name: 'uni:encrypt-uni-modules-assets',
|
|
33
|
+
enforce: 'pre',
|
|
34
|
+
configResolved(config) {
|
|
35
|
+
resolvedConfig = config;
|
|
36
|
+
},
|
|
37
|
+
resolveId(id, importer) {
|
|
38
|
+
if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
|
|
39
|
+
id = (0, utils_2.normalizePath)(id);
|
|
40
|
+
if (importer && (id.startsWith('./') || id.startsWith('../'))) {
|
|
41
|
+
id = (0, utils_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(importer), id));
|
|
42
|
+
}
|
|
43
|
+
if (path_1.default.isAbsolute(id)) {
|
|
44
|
+
id = '@/' + path_1.default.relative(process.env.UNI_INPUT_DIR, id);
|
|
45
|
+
}
|
|
46
|
+
return `\0${id}`;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
load(id) {
|
|
50
|
+
if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
|
|
51
|
+
return {
|
|
52
|
+
code: `export default ${JSON.stringify(id.replace(/\0/g, ''))}`,
|
|
53
|
+
moduleSideEffects: false,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
exports.uniEncryptUniModulesAssetsPlugin = uniEncryptUniModulesAssetsPlugin;
|
|
60
|
+
function uniEncryptUniModulesPlugin() {
|
|
61
|
+
let resolvedConfig;
|
|
62
|
+
return {
|
|
63
|
+
name: 'uni:encrypt-uni-modules',
|
|
64
|
+
apply: 'build',
|
|
65
|
+
config() {
|
|
66
|
+
return {
|
|
67
|
+
resolve: {
|
|
68
|
+
alias: initEncryptUniModulesAlias(),
|
|
69
|
+
},
|
|
70
|
+
build: initEncryptUniModulesBuildOptions(process.env.UNI_UTS_PLATFORM, process.env.UNI_INPUT_DIR),
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
configResolved(config) {
|
|
74
|
+
// 编译组件时,禁用内联资源
|
|
75
|
+
config.build.assetsInlineLimit = 0;
|
|
76
|
+
config.build.rollupOptions.external = createExternal(config);
|
|
77
|
+
resolvedConfig = config;
|
|
78
|
+
},
|
|
79
|
+
resolveId(id, importer) {
|
|
80
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
81
|
+
if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
|
|
82
|
+
id = (0, utils_2.normalizePath)(id);
|
|
83
|
+
if (importer && (id.startsWith('./') || id.startsWith('../'))) {
|
|
84
|
+
id = (0, utils_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(importer), id));
|
|
85
|
+
}
|
|
86
|
+
if (path_1.default.isAbsolute(id)) {
|
|
87
|
+
id = '@/' + path_1.default.relative(process.env.UNI_INPUT_DIR, id);
|
|
88
|
+
}
|
|
89
|
+
return `\0${id}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
load(id) {
|
|
94
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
95
|
+
if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
|
|
96
|
+
return {
|
|
97
|
+
code: `export default ${JSON.stringify(id.replace(/\0/g, ''))}`,
|
|
98
|
+
moduleSideEffects: false,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
generateBundle(_, bundle) {
|
|
104
|
+
Object.keys(bundle).forEach((fileName) => {
|
|
105
|
+
if (fileName.endsWith('.module.js')) {
|
|
106
|
+
const uniModuleId = path_1.default.basename(fileName).replace('.module.js', '');
|
|
107
|
+
// app-android 不需要 js
|
|
108
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
109
|
+
const newFileName = 'uni_modules/' +
|
|
110
|
+
fileName.replace('.module.js', '/index.module.js');
|
|
111
|
+
bundle[newFileName] = bundle[fileName];
|
|
112
|
+
bundle[newFileName].fileName = newFileName;
|
|
113
|
+
}
|
|
114
|
+
delete bundle[fileName];
|
|
115
|
+
const pkg = `uni_modules/${uniModuleId}/package.json`;
|
|
116
|
+
bundle[pkg] = {
|
|
117
|
+
type: 'asset',
|
|
118
|
+
fileName: pkg,
|
|
119
|
+
name: pkg,
|
|
120
|
+
needsCodeReference: false,
|
|
121
|
+
source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, {
|
|
122
|
+
env: (0, uni_modules_1.initCheckEnv)(),
|
|
123
|
+
}),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
},
|
|
128
|
+
async writeBundle() {
|
|
129
|
+
if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
// 编译所有 uni_modules 插件
|
|
133
|
+
const tempOutputDir = uvueOutDir();
|
|
134
|
+
const tempUniModulesDir = path_1.default.join(tempOutputDir, 'uni_modules');
|
|
135
|
+
const tempUniModules = [];
|
|
136
|
+
if (fs_extra_1.default.existsSync(tempUniModulesDir)) {
|
|
137
|
+
fs_extra_1.default.readdirSync(tempUniModulesDir).forEach((uniModuleDir) => {
|
|
138
|
+
if (fs_extra_1.default.existsSync(path_1.default.join(tempUniModulesDir, uniModuleDir, 'index.module.uts'))) {
|
|
139
|
+
tempUniModules.push(uniModuleDir);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
const compiler = (0, uts_1.resolveUTSCompiler)();
|
|
144
|
+
for (const uniModule of tempUniModules) {
|
|
145
|
+
const pluginDir = path_1.default.resolve(tempUniModulesDir, uniModule);
|
|
146
|
+
const result = await compiler.compile(pluginDir, {
|
|
147
|
+
isX: process.env.UNI_APP_X === 'true',
|
|
148
|
+
isSingleThread: true,
|
|
149
|
+
isPlugin: false,
|
|
150
|
+
sourceMap: false,
|
|
151
|
+
uni_modules: [],
|
|
152
|
+
transform: {
|
|
153
|
+
uvueClassNamePrefix: 'Gen',
|
|
154
|
+
autoImports: (0, easycom_1.getUTSEasyComAutoImports)(),
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
if (result) {
|
|
158
|
+
const apis = result.inject_apis;
|
|
159
|
+
const scopedSlots = result.scoped_slots;
|
|
160
|
+
const components = getUniModulesExtApiComponents(uniModule);
|
|
161
|
+
const modules = (0, uts_1.resolveUTSCompiler)().parseInjectModules(apis, {}, components);
|
|
162
|
+
fs_extra_1.default.writeFileSync(path_1.default.resolve(process.env.UNI_OUTPUT_DIR, 'uni_modules', uniModule, 'package.json'), genUniModulesPackageJson(uniModule, tempOutputDir, {
|
|
163
|
+
env: (0, uni_modules_1.initCheckEnv)(),
|
|
164
|
+
apis,
|
|
165
|
+
components,
|
|
166
|
+
modules,
|
|
167
|
+
scopedSlots,
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
exports.uniEncryptUniModulesPlugin = uniEncryptUniModulesPlugin;
|
|
175
|
+
function uvueOutDir() {
|
|
176
|
+
return path_1.default.join(process.env.UNI_OUTPUT_DIR, '../.uvue');
|
|
177
|
+
}
|
|
178
|
+
function createExternal(config) {
|
|
179
|
+
return function external(source) {
|
|
180
|
+
if ([
|
|
181
|
+
'vue',
|
|
182
|
+
'plugin-vue:export-helper',
|
|
183
|
+
'vue-router',
|
|
184
|
+
'pinia',
|
|
185
|
+
'vuex',
|
|
186
|
+
'vue-i18n',
|
|
187
|
+
].includes(source)) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (source.startsWith('@vue/')) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (source.startsWith('@dcloudio/')) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (source.startsWith('@/uni_modules/')) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
// 相对目录
|
|
200
|
+
if (source.startsWith('@/') || source.startsWith('.')) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (path_1.default.isAbsolute(source)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
// android 系统库,三方库,iOS 的库呢?一般不包含.
|
|
207
|
+
if (source.includes('.')) {
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
function initEncryptUniModulesAlias() {
|
|
214
|
+
return [
|
|
215
|
+
{
|
|
216
|
+
find: '\0plugin-vue:export-helper',
|
|
217
|
+
replacement: 'plugin-vue:export-helper',
|
|
218
|
+
},
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
const indexFiles = ['index.uts', 'index.ts', 'index.js'];
|
|
222
|
+
function hasIndexFile(uniModuleDir) {
|
|
223
|
+
return fs_extra_1.default.readdirSync(uniModuleDir).some((file) => indexFiles.includes(file));
|
|
224
|
+
}
|
|
225
|
+
function initEncryptUniModulesBuildOptions(platform, inputDir) {
|
|
226
|
+
const modules = (0, uni_modules_1.parseUniModulesWithComponents)(inputDir);
|
|
227
|
+
const moduleNames = Object.keys(modules);
|
|
228
|
+
if (!moduleNames.length) {
|
|
229
|
+
throw new Error('No encrypt uni_modules found');
|
|
230
|
+
}
|
|
231
|
+
// 生成入口文件
|
|
232
|
+
const input = {};
|
|
233
|
+
moduleNames.forEach((module) => {
|
|
234
|
+
const moduleDir = path_1.default.resolve(inputDir, 'uni_modules', module);
|
|
235
|
+
const indexEncryptFile = path_1.default.resolve(moduleDir, 'index.module.uts');
|
|
236
|
+
const codes = [];
|
|
237
|
+
if (hasIndexFile(moduleDir)) {
|
|
238
|
+
codes.push(`export * from './index'`);
|
|
239
|
+
}
|
|
240
|
+
// easyCom
|
|
241
|
+
if (modules[module] && Object.keys(modules[module]).length) {
|
|
242
|
+
codes.push((0, uni_modules_1.genEncryptEasyComModuleIndex)(platform, modules[module]));
|
|
243
|
+
}
|
|
244
|
+
if (codes.length) {
|
|
245
|
+
fs_extra_1.default.writeFileSync(indexEncryptFile, codes.join(`\n`));
|
|
246
|
+
// 输出 xxx.module ,确保相对路径的准确性,因为真正引用的时候,是从 @/uni_modules/xxx 引入的
|
|
247
|
+
input[module + '.module'] = indexEncryptFile;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return {
|
|
251
|
+
lib: false, // 不使用 lib 模式,lib模式会直接内联资源
|
|
252
|
+
cssCodeSplit: false,
|
|
253
|
+
// outDir: process.env.UNI_OUTPUT_DIR,
|
|
254
|
+
rollupOptions: {
|
|
255
|
+
preserveEntrySignatures: 'strict',
|
|
256
|
+
input,
|
|
257
|
+
output: {
|
|
258
|
+
format: 'es',
|
|
259
|
+
banner: ``,
|
|
260
|
+
entryFileNames: '[name].js',
|
|
261
|
+
assetFileNames(asset) {
|
|
262
|
+
if (asset.name && path_1.default.isAbsolute(asset.name)) {
|
|
263
|
+
const uniModuleId = parseUniModuleId(path_1.default.relative(inputDir, asset.name));
|
|
264
|
+
if (uniModuleId) {
|
|
265
|
+
return `uni_modules/${uniModuleId}/assets/[name]-[hash][extname]`;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return 'assets/[name]-[hash][extname]';
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function genUniModulesPackageJson(uniModuleId, inputDir, artifacts) {
|
|
275
|
+
const pkg = require(path_1.default.resolve(inputDir, path_1.default.join('uni_modules', uniModuleId, 'package.json')));
|
|
276
|
+
return JSON.stringify({
|
|
277
|
+
id: pkg.id,
|
|
278
|
+
version: pkg.version,
|
|
279
|
+
uni_modules: {
|
|
280
|
+
artifacts,
|
|
281
|
+
},
|
|
282
|
+
}, null, 2);
|
|
283
|
+
}
|
|
284
|
+
function parseUniModuleId(relativeFilename) {
|
|
285
|
+
const parts = (0, utils_2.normalizePath)(relativeFilename).split('/', 2);
|
|
286
|
+
if (parts[0] === 'uni_modules') {
|
|
287
|
+
return parts[1];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const uniModulesExtApiComponents = new Map();
|
|
291
|
+
function addUniModulesExtApiComponents(relativeFilename, components) {
|
|
292
|
+
const uniModuleId = parseUniModuleId(relativeFilename);
|
|
293
|
+
if (uniModuleId) {
|
|
294
|
+
let extApiComponents = uniModulesExtApiComponents.get(uniModuleId);
|
|
295
|
+
if (!extApiComponents) {
|
|
296
|
+
extApiComponents = new Set();
|
|
297
|
+
uniModulesExtApiComponents.set(uniModuleId, extApiComponents);
|
|
298
|
+
}
|
|
299
|
+
components.forEach((component) => extApiComponents.add(component));
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.addUniModulesExtApiComponents = addUniModulesExtApiComponents;
|
|
303
|
+
function getUniModulesExtApiComponents(uniModuleId) {
|
|
304
|
+
return [...(uniModulesExtApiComponents.get(uniModuleId) || [])];
|
|
305
|
+
}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { EmittedAsset } from 'rollup';
|
|
|
3
3
|
import type { ParserOptions } from '@vue/compiler-core';
|
|
4
4
|
import type { CompilerOptions, SFCStyleCompileOptions, TemplateCompiler } from '@vue/compiler-sfc';
|
|
5
5
|
import type { UniViteCopyPluginOptions } from './plugins/copy';
|
|
6
|
+
export { getIsStaticFile } from './plugins/vitejs/plugins/static';
|
|
6
7
|
export declare const cssTarget = "chrome53";
|
|
7
8
|
export interface CopyOptions {
|
|
8
9
|
/**
|
|
@@ -36,4 +37,5 @@ export * from './utils';
|
|
|
36
37
|
export * from './plugins';
|
|
37
38
|
export * from './features';
|
|
38
39
|
export * from './autoImport';
|
|
40
|
+
export * from './cloud';
|
|
39
41
|
export declare function rewriteExistsSyncHasRootFile(): void;
|
package/dist/vite/index.js
CHANGED
|
@@ -17,14 +17,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.rewriteExistsSyncHasRootFile = exports.cssTarget = void 0;
|
|
20
|
+
exports.rewriteExistsSyncHasRootFile = exports.cssTarget = exports.getIsStaticFile = void 0;
|
|
21
21
|
const fs_1 = __importDefault(require("fs"));
|
|
22
22
|
const path_1 = __importDefault(require("path"));
|
|
23
|
+
var static_1 = require("./plugins/vitejs/plugins/static");
|
|
24
|
+
Object.defineProperty(exports, "getIsStaticFile", { enumerable: true, get: function () { return static_1.getIsStaticFile; } });
|
|
23
25
|
exports.cssTarget = 'chrome53';
|
|
24
26
|
__exportStar(require("./utils"), exports);
|
|
25
27
|
__exportStar(require("./plugins"), exports);
|
|
26
28
|
__exportStar(require("./features"), exports);
|
|
27
29
|
__exportStar(require("./autoImport"), exports);
|
|
30
|
+
__exportStar(require("./cloud"), exports);
|
|
28
31
|
// https://github.com/vitejs/vite/blob/aac2ef77521f66ddd908f9d97020b8df532148cf/packages/vite/src/node/server/searchRoot.ts#L38
|
|
29
32
|
// vite 在初始化阶段会执行 initTSConfck,此时会 searchForWorkspaceRoot,如果找到了 pnpm-workspace.yaml 文件,会将其作为 root
|
|
30
33
|
// HBuilderX 项目,root 一定是 UNI_INPUT_DIR,所以需要重写 fs.existsSync,不重写的话,可能会找错,
|
|
@@ -34,7 +34,9 @@ function uniEasycomPlugin(options) {
|
|
|
34
34
|
// 处理easycom组件优先级
|
|
35
35
|
return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
|
|
36
36
|
? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
|
|
37
|
-
: '')
|
|
37
|
+
: source.includes('uni_helpers')
|
|
38
|
+
? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
|
|
39
|
+
: ''));
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
return str;
|
|
@@ -4,8 +4,8 @@ interface UniUTSPluginOptions {
|
|
|
4
4
|
extApis?: Record<string, [string, string]>;
|
|
5
5
|
isSingleThread?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export declare
|
|
8
|
-
export declare function
|
|
7
|
+
export declare function getCurrentCompiledUTSPlugins(): Set<string>;
|
|
8
|
+
export declare function uniUTSAppUniModulesPlugin(options?: UniUTSPluginOptions): Plugin;
|
|
9
9
|
export declare function buildUniExtApis(): Promise<void>;
|
|
10
10
|
export declare function resolveExtApiProvider(pkg: Record<string, any>): {
|
|
11
11
|
name?: string | undefined;
|
|
@@ -13,4 +13,5 @@ export declare function resolveExtApiProvider(pkg: Record<string, any>): {
|
|
|
13
13
|
service: string;
|
|
14
14
|
servicePlugin: string;
|
|
15
15
|
} | undefined;
|
|
16
|
+
export declare function uniDecryptUniModulesPlugin(): Plugin;
|
|
16
17
|
export {};
|
|
@@ -3,47 +3,67 @@ 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.resolveExtApiProvider = exports.buildUniExtApis = exports.
|
|
6
|
+
exports.uniDecryptUniModulesPlugin = exports.resolveExtApiProvider = exports.buildUniExtApis = exports.uniUTSAppUniModulesPlugin = exports.getCurrentCompiledUTSPlugins = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
10
10
|
const uts_1 = require("../../../uts");
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
12
|
const uni_modules_1 = require("../../../uni_modules");
|
|
13
|
+
const utils_2 = require("../../../utils");
|
|
14
|
+
const json_1 = require("../../../json");
|
|
13
15
|
const UTSProxyRE = /\?uts-proxy$/;
|
|
16
|
+
const UniHelpersRE = /\?uni_helpers$/;
|
|
14
17
|
function isUTSProxy(id) {
|
|
15
18
|
return UTSProxyRE.test(id);
|
|
16
19
|
}
|
|
20
|
+
function isUniHelpers(id) {
|
|
21
|
+
return UniHelpersRE.test(id);
|
|
22
|
+
}
|
|
17
23
|
const utsModuleCaches = new Map();
|
|
18
|
-
|
|
24
|
+
const utsPlugins = new Set();
|
|
25
|
+
function getCurrentCompiledUTSPlugins() {
|
|
26
|
+
return utsPlugins;
|
|
27
|
+
}
|
|
28
|
+
exports.getCurrentCompiledUTSPlugins = getCurrentCompiledUTSPlugins;
|
|
19
29
|
let uniExtApiCompiler = async () => { };
|
|
20
|
-
|
|
30
|
+
// 该插件仅限app-android、app-ios、app-harmony
|
|
31
|
+
function uniUTSAppUniModulesPlugin(options = {}) {
|
|
32
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
21
33
|
process.env.UNI_UTS_USING_ROLLUP = 'true';
|
|
22
34
|
const compilePlugin = async (pluginDir) => {
|
|
23
|
-
|
|
35
|
+
utsPlugins.add(path_1.default.basename(pluginDir));
|
|
24
36
|
const pkgJson = require(path_1.default.join(pluginDir, 'package.json'));
|
|
37
|
+
const isExtApi = !!pkgJson.uni_modules?.['uni-ext-api'];
|
|
25
38
|
const extApiProvider = resolveExtApiProvider(pkgJson);
|
|
26
39
|
// 如果是 provider 扩展,需要判断 provider 的宿主插件是否在本地,在的话,自动导入该宿主插件包名
|
|
27
40
|
let uniExtApiProviderServicePlugin = '';
|
|
28
41
|
if (extApiProvider?.servicePlugin) {
|
|
29
|
-
if (fs_1.default.existsSync(path_1.default.resolve(
|
|
42
|
+
if (fs_1.default.existsSync(path_1.default.resolve(inputDir, 'uni_modules', extApiProvider.servicePlugin))) {
|
|
30
43
|
uniExtApiProviderServicePlugin = extApiProvider.servicePlugin;
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
46
|
const compiler = (0, uts_1.resolveUTSCompiler)();
|
|
34
47
|
// 处理依赖的 uts 插件
|
|
35
|
-
const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [],
|
|
48
|
+
const deps = (0, uni_modules_1.parseUTSModuleDeps)(pkgJson.uni_modules?.dependencies || [], inputDir);
|
|
36
49
|
if (deps.length) {
|
|
37
50
|
for (const dep of deps) {
|
|
38
|
-
await compilePlugin(path_1.default.resolve(
|
|
51
|
+
await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', dep));
|
|
39
52
|
}
|
|
40
53
|
}
|
|
54
|
+
if (process.env.UNI_PLATFORM === 'app-harmony') {
|
|
55
|
+
return compiler.compileArkTS(pluginDir, {
|
|
56
|
+
isX: !!options.x,
|
|
57
|
+
isExtApi,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
41
60
|
return compiler.compile(pluginDir, {
|
|
42
61
|
isX: !!options.x,
|
|
43
62
|
isSingleThread: !!options.isSingleThread,
|
|
44
63
|
isPlugin: true,
|
|
64
|
+
isExtApi,
|
|
45
65
|
extApis: options.extApis,
|
|
46
|
-
sourceMap:
|
|
66
|
+
sourceMap: (0, utils_2.enableSourceMap)(),
|
|
47
67
|
uni_modules: deps,
|
|
48
68
|
transform: {
|
|
49
69
|
uniExtApiProviderName: extApiProvider?.name,
|
|
@@ -54,9 +74,9 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
54
74
|
};
|
|
55
75
|
uniExtApiCompiler = async () => {
|
|
56
76
|
// 获取 provider 扩展(编译所有uni)
|
|
57
|
-
const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !
|
|
77
|
+
const plugins = (0, uni_modules_1.getUniExtApiPlugins)().filter((provider) => !utsPlugins.has(provider.plugin));
|
|
58
78
|
for (const plugin of plugins) {
|
|
59
|
-
const result = await compilePlugin(path_1.default.resolve(
|
|
79
|
+
const result = await compilePlugin(path_1.default.resolve(inputDir, 'uni_modules', plugin.plugin));
|
|
60
80
|
if (result) {
|
|
61
81
|
// 时机不对,不能addWatch
|
|
62
82
|
// result.deps.forEach((dep) => {
|
|
@@ -70,10 +90,14 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
70
90
|
apply: 'build',
|
|
71
91
|
enforce: 'pre',
|
|
72
92
|
resolveId(id, importer) {
|
|
73
|
-
if (isUTSProxy(id)) {
|
|
93
|
+
if (isUTSProxy(id) || isUniHelpers(id)) {
|
|
74
94
|
return id;
|
|
75
95
|
}
|
|
76
|
-
|
|
96
|
+
// 加密插件缓存目录的css文件
|
|
97
|
+
if (id.endsWith('.css')) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const module = (0, uts_1.resolveUTSAppModule)(process.env.UNI_UTS_PLATFORM, id, importer ? path_1.default.dirname(importer) : inputDir, options.x !== true);
|
|
77
101
|
if (module) {
|
|
78
102
|
// app-js 会直接返回 index.uts 路径,不需要 uts-proxy
|
|
79
103
|
if (module.endsWith('.uts')) {
|
|
@@ -133,10 +157,9 @@ function uniUTSUniModulesPlugin(options = {}) {
|
|
|
133
157
|
};
|
|
134
158
|
}
|
|
135
159
|
},
|
|
136
|
-
async generateBundle() { },
|
|
137
160
|
};
|
|
138
161
|
}
|
|
139
|
-
exports.
|
|
162
|
+
exports.uniUTSAppUniModulesPlugin = uniUTSAppUniModulesPlugin;
|
|
140
163
|
async function buildUniExtApis() {
|
|
141
164
|
await uniExtApiCompiler();
|
|
142
165
|
}
|
|
@@ -151,3 +174,42 @@ function resolveExtApiProvider(pkg) {
|
|
|
151
174
|
}
|
|
152
175
|
}
|
|
153
176
|
exports.resolveExtApiProvider = resolveExtApiProvider;
|
|
177
|
+
function uniDecryptUniModulesPlugin() {
|
|
178
|
+
const inputDir = process.env.UNI_INPUT_DIR;
|
|
179
|
+
const isX = process.env.UNI_APP_X === 'true';
|
|
180
|
+
return {
|
|
181
|
+
name: 'uni:uni_modules-d',
|
|
182
|
+
enforce: 'pre',
|
|
183
|
+
async configResolved() {
|
|
184
|
+
if (isX && process.env.UNI_COMPILE_TARGET !== 'uni_modules') {
|
|
185
|
+
const manifest = (0, json_1.parseManifestJsonOnce)(inputDir);
|
|
186
|
+
await (0, uni_modules_1.checkEncryptUniModules)(inputDir, {
|
|
187
|
+
mode: process.env.NODE_ENV !== 'development'
|
|
188
|
+
? 'production'
|
|
189
|
+
: 'development',
|
|
190
|
+
packType: process.env.UNI_APP_PACK_TYPE ||
|
|
191
|
+
(process.env.NODE_ENV !== 'development' ? 'release' : 'debug'),
|
|
192
|
+
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
|
193
|
+
appid: manifest.appid,
|
|
194
|
+
appname: manifest.name,
|
|
195
|
+
platform: process.env.UNI_UTS_PLATFORM,
|
|
196
|
+
'uni-app-x': isX,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
resolveId(id) {
|
|
201
|
+
if (isUTSProxy(id) || isUniHelpers(id)) {
|
|
202
|
+
return id;
|
|
203
|
+
}
|
|
204
|
+
if (isX &&
|
|
205
|
+
process.env.UNI_COMPILE_TARGET !== 'uni_modules' &&
|
|
206
|
+
!id.endsWith('.css')) {
|
|
207
|
+
const resolvedId = (0, uni_modules_1.resolveEncryptUniModule)(id, process.env.UNI_UTS_PLATFORM, process.env.UNI_APP_X === 'true');
|
|
208
|
+
if (resolvedId) {
|
|
209
|
+
return resolvedId;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
exports.uniDecryptUniModulesPlugin = uniDecryptUniModulesPlugin;
|
|
@@ -8,12 +8,12 @@ export declare const chunkToEmittedAssetsMap: WeakMap<RenderedChunk, Set<string>
|
|
|
8
8
|
* Also supports loading plain strings with import text from './foo.txt?raw'
|
|
9
9
|
*/
|
|
10
10
|
export declare function assetPlugin(config: ResolvedConfig, options?: {
|
|
11
|
-
isAndroidX
|
|
11
|
+
isAndroidX?: boolean;
|
|
12
12
|
}): Plugin;
|
|
13
13
|
export declare function parseAssets(config: ResolvedConfig, code: string): string;
|
|
14
14
|
export declare function registerAssetToChunk(chunk: RenderedChunk, file: string): void;
|
|
15
15
|
export declare function checkPublicFile(url: string, { publicDir }: ResolvedConfig): string | undefined;
|
|
16
|
-
export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline
|
|
16
|
+
export declare function fileToUrl(id: string, config: ResolvedConfig, ctx: PluginContext, canInline: boolean | undefined, isStaticFile: (file: string) => boolean): string;
|
|
17
17
|
export declare function getAssetFilename(hash: string, config: ResolvedConfig): string | undefined;
|
|
18
18
|
/**
|
|
19
19
|
* converts the source filepath of the asset to the output filename based on the assetFileNames option. \
|
|
@@ -40,4 +40,4 @@ export declare function getAssetFilename(hash: string, config: ResolvedConfig):
|
|
|
40
40
|
*/
|
|
41
41
|
export declare function assetFileNamesToFileName(assetFileNames: Exclude<OutputOptions['assetFileNames'], undefined>, file: string, contentHash: string, content: string | Buffer): string;
|
|
42
42
|
export declare function getAssetHash(content: Buffer | string): string;
|
|
43
|
-
export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext): string;
|
|
43
|
+
export declare function urlToBuiltUrl(url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext, isStaticFile: (file: string) => boolean): string;
|