@dcloudio/uni-cli-shared 2.0.2-4000820240401001 → 2.0.2-4010420240430001
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/lib/cache.js +25 -4
- package/lib/package.js +1 -1
- package/lib/uts/uni_modules.js +76 -3
- package/lib/uts/uts-loader.js +36 -11
- package/lib/uts/uts.js +15 -7
- package/package.json +2 -2
package/lib/cache.js
CHANGED
|
@@ -153,7 +153,16 @@ function updateUsingAutoImportComponents (name, usingAutoImportComponents) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
|
|
156
|
+
const styleIsolationRE =
|
|
157
|
+
/export\s+default\s+[\s\S]*?styleIsolation\s*:\s*['|"](isolated|apply-shared|shared)['|"]/
|
|
158
|
+
function parseComponentStyleIsolation (content) {
|
|
159
|
+
const matches = content.match(styleIsolationRE)
|
|
160
|
+
if (matches) {
|
|
161
|
+
return matches[1]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function updateUsingComponents (name, usingComponents, type, content = '') {
|
|
157
166
|
if (type === 'Component') {
|
|
158
167
|
componentSet.add(name)
|
|
159
168
|
}
|
|
@@ -168,9 +177,21 @@ function updateUsingComponents (name, usingComponents, type) {
|
|
|
168
177
|
if (type === 'Component') {
|
|
169
178
|
jsonObj.component = true
|
|
170
179
|
if (process.env.UNI_PLATFORM === 'mp-alipay') {
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
180
|
+
const alipayConfig = process.UNI_MANIFEST['mp-alipay'] || {}
|
|
181
|
+
jsonObj.styleIsolation =
|
|
182
|
+
parseComponentStyleIsolation(content) ||
|
|
183
|
+
alipayConfig.styleIsolation ||
|
|
184
|
+
'apply-shared'
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 微信小程序json文件中的styleIsolation优先级比options中的高,为了兼容旧版本,不能设置默认值,并且只有在manifest.json中配置styleIsolation才会静态分析组件的styleIsolation
|
|
188
|
+
if (process.env.UNI_PLATFORM === 'mp-weixin') {
|
|
189
|
+
const weixinConfig = process.UNI_MANIFEST['mp-weixin'] || {}
|
|
190
|
+
if (weixinConfig.styleIsolation) {
|
|
191
|
+
jsonObj.styleIsolation =
|
|
192
|
+
parseComponentStyleIsolation(content) ||
|
|
193
|
+
weixinConfig.styleIsolation
|
|
194
|
+
}
|
|
174
195
|
}
|
|
175
196
|
} else if (type === 'Page') {
|
|
176
197
|
if (process.env.UNI_PLATFORM === 'mp-baidu') {
|
package/lib/package.js
CHANGED
package/lib/uts/uni_modules.js
CHANGED
|
@@ -3,9 +3,33 @@ 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.parseInjects = exports.parseUniExtApis = void 0;
|
|
6
|
+
exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.getUniExtApiProviders = void 0;
|
|
7
|
+
// 重要:此文件编译后的js,需同步至 vue2 编译器中 uni-cli-shared/lib/uts/uni_modules.js
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const extApiProviders = [];
|
|
11
|
+
function getUniExtApiProviders() {
|
|
12
|
+
return extApiProviders;
|
|
13
|
+
}
|
|
14
|
+
exports.getUniExtApiProviders = getUniExtApiProviders;
|
|
15
|
+
function getUniExtApiProviderRegisters() {
|
|
16
|
+
const result = [];
|
|
17
|
+
extApiProviders.forEach((provider) => {
|
|
18
|
+
if (provider.name && provider.service) {
|
|
19
|
+
result.push({
|
|
20
|
+
name: provider.name,
|
|
21
|
+
service: provider.service,
|
|
22
|
+
class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${(0, exports.capitalize)((0, exports.camelize)('uni-ext-api-' +
|
|
23
|
+
provider.service +
|
|
24
|
+
'-' +
|
|
25
|
+
provider.name +
|
|
26
|
+
'-provider'))}`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
exports.getUniExtApiProviderRegisters = getUniExtApiProviderRegisters;
|
|
9
33
|
function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
10
34
|
if (!process.env.UNI_INPUT_DIR) {
|
|
11
35
|
return {};
|
|
@@ -15,6 +39,7 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
15
39
|
return {};
|
|
16
40
|
}
|
|
17
41
|
const injects = {};
|
|
42
|
+
extApiProviders.length = 0;
|
|
18
43
|
fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
|
|
19
44
|
// 必须以 uni- 开头
|
|
20
45
|
if (!uniModuleDir.startsWith('uni-')) {
|
|
@@ -32,6 +57,11 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
32
57
|
exports = pkg.uni_modules['uni-ext-api'];
|
|
33
58
|
}
|
|
34
59
|
if (exports) {
|
|
60
|
+
const provider = exports.provider;
|
|
61
|
+
if (provider && provider.service) {
|
|
62
|
+
provider.plugin = uniModuleDir;
|
|
63
|
+
extApiProviders.push(provider);
|
|
64
|
+
}
|
|
35
65
|
const curInjects = parseInjects(vite, platform, language, `@/uni_modules/${uniModuleDir}`, uniModuleRootDir, exports);
|
|
36
66
|
Object.assign(injects, curInjects);
|
|
37
67
|
}
|
|
@@ -74,9 +104,10 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
74
104
|
});
|
|
75
105
|
const injects = {};
|
|
76
106
|
if (Object.keys(rootDefines).length) {
|
|
107
|
+
const platformIndexFileName = path_1.default.resolve(uniModuleRootDir, 'utssdk', platform);
|
|
108
|
+
const rootIndexFileName = path_1.default.resolve(uniModuleRootDir, 'utssdk', 'index.uts');
|
|
77
109
|
let hasPlatformFile = uniModuleRootDir
|
|
78
|
-
? fs_extra_1.default.existsSync(
|
|
79
|
-
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', platform))
|
|
110
|
+
? fs_extra_1.default.existsSync(rootIndexFileName) || fs_extra_1.default.existsSync(platformIndexFileName)
|
|
80
111
|
: true;
|
|
81
112
|
if (!hasPlatformFile) {
|
|
82
113
|
if (platform === 'app') {
|
|
@@ -85,6 +116,17 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
85
116
|
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios'));
|
|
86
117
|
}
|
|
87
118
|
}
|
|
119
|
+
// 其他平台修改source,直接指向目标文件,否则 uts2js 找不到类型信息
|
|
120
|
+
if (platform !== 'app' &&
|
|
121
|
+
platform !== 'app-android' &&
|
|
122
|
+
platform !== 'app-ios') {
|
|
123
|
+
if (fs_extra_1.default.existsSync(platformIndexFileName)) {
|
|
124
|
+
source = `${source}/utssdk/${platform}/index.uts`;
|
|
125
|
+
}
|
|
126
|
+
else if (fs_extra_1.default.existsSync(rootIndexFileName)) {
|
|
127
|
+
source = `${source}/utssdk/index.uts`;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
88
130
|
for (const key in rootDefines) {
|
|
89
131
|
Object.assign(injects, parseInject(vite, platform, language, source, 'uni', rootDefines[key], hasPlatformFile));
|
|
90
132
|
}
|
|
@@ -173,3 +215,34 @@ const toTypeString = (value) => objectToString.call(value);
|
|
|
173
215
|
function isPlainObject(val) {
|
|
174
216
|
return toTypeString(val) === '[object Object]';
|
|
175
217
|
}
|
|
218
|
+
const cacheStringFunction = (fn) => {
|
|
219
|
+
const cache = Object.create(null);
|
|
220
|
+
return ((str) => {
|
|
221
|
+
const hit = cache[str];
|
|
222
|
+
return hit || (cache[str] = fn(str));
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
const camelizeRE = /-(\w)/g;
|
|
226
|
+
/**
|
|
227
|
+
* @private
|
|
228
|
+
*/
|
|
229
|
+
exports.camelize = cacheStringFunction((str) => {
|
|
230
|
+
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
|
|
231
|
+
});
|
|
232
|
+
/**
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
exports.capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
|
|
236
|
+
/**
|
|
237
|
+
* 解析 UTS 类型的模块依赖列表
|
|
238
|
+
* @param deps
|
|
239
|
+
* @param inputDir
|
|
240
|
+
* @returns
|
|
241
|
+
*/
|
|
242
|
+
function parseUTSModuleDeps(deps, inputDir) {
|
|
243
|
+
const modulesDir = path_1.default.resolve(inputDir, 'uni_modules');
|
|
244
|
+
return deps.filter((dep) => {
|
|
245
|
+
return fs_extra_1.default.existsSync(path_1.default.resolve(modulesDir, dep, 'utssdk'));
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
exports.parseUTSModuleDeps = parseUTSModuleDeps;
|
package/lib/uts/uts-loader.js
CHANGED
|
@@ -3,17 +3,42 @@ const {
|
|
|
3
3
|
resolveUTSCompiler,
|
|
4
4
|
parseUniExtApiNamespacesOnce
|
|
5
5
|
} = require('./uts')
|
|
6
|
-
|
|
6
|
+
const {
|
|
7
|
+
parseUTSModuleDeps
|
|
8
|
+
} = require('./uni_modules')
|
|
9
|
+
module.exports = async function (content) {
|
|
7
10
|
const callback = this.async()
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
|
|
12
|
+
const compilePlugin = async (pluginDir) => {
|
|
13
|
+
const pkgJson = require(path.join(pluginDir, 'package.json'))
|
|
14
|
+
const compiler = resolveUTSCompiler()
|
|
15
|
+
// 处理依赖的 uts 插件
|
|
16
|
+
const deps = parseUTSModuleDeps(
|
|
17
|
+
pkgJson.uni_modules?.dependencies || [],
|
|
18
|
+
process.env.UNI_INPUT_DIR
|
|
19
|
+
)
|
|
20
|
+
if (deps.length) {
|
|
21
|
+
for (const dep of deps) {
|
|
22
|
+
await compilePlugin(
|
|
23
|
+
path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', dep)
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return compiler.compile(pluginDir, {
|
|
28
|
+
isX: false,
|
|
29
|
+
isPlugin: true,
|
|
30
|
+
extApis: parseUniExtApiNamespacesOnce(
|
|
31
|
+
process.env.UNI_UTS_PLATFORM,
|
|
32
|
+
process.env.UNI_UTS_TARGET_LANGUAGE
|
|
33
|
+
),
|
|
34
|
+
sourceMap: process.env.NODE_ENV === 'development',
|
|
35
|
+
uni_modules: deps
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pluginDir = path.dirname(this.resourcePath)
|
|
40
|
+
|
|
41
|
+
compilePlugin(pluginDir).then(result => {
|
|
17
42
|
if (result) {
|
|
18
43
|
result.deps.forEach((dep) => {
|
|
19
44
|
this.addDependency(dep)
|
|
@@ -25,4 +50,4 @@ module.exports = function (content) {
|
|
|
25
50
|
}).catch(err => {
|
|
26
51
|
callback(err)
|
|
27
52
|
})
|
|
28
|
-
}
|
|
53
|
+
}
|
package/lib/uts/uts.js
CHANGED
|
@@ -4,13 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
|
|
7
|
+
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
11
|
const hbx_1 = require("./hbx");
|
|
11
12
|
const utils_1 = require("./utils");
|
|
12
13
|
const uni_modules_1 = require("./uni_modules");
|
|
13
|
-
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
|
|
14
14
|
function once(fn, ctx = null) {
|
|
15
15
|
let res;
|
|
16
16
|
return ((...args) => {
|
|
@@ -103,8 +103,18 @@ function resolveUTSCompiler() {
|
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
catch (e) {
|
|
106
|
-
let utsCompilerVersion =
|
|
107
|
-
|
|
106
|
+
let utsCompilerVersion = '';
|
|
107
|
+
try {
|
|
108
|
+
utsCompilerVersion = require('../package.json').version;
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
try {
|
|
112
|
+
// vue2
|
|
113
|
+
utsCompilerVersion = require('../../package.json').version;
|
|
114
|
+
}
|
|
115
|
+
catch (e) { }
|
|
116
|
+
}
|
|
117
|
+
if (utsCompilerVersion.startsWith('2.0.')) {
|
|
108
118
|
utsCompilerVersion = '^3.0.0-alpha-3060920221117001';
|
|
109
119
|
}
|
|
110
120
|
console.error((0, utils_1.installDepTips)('devDependencies', '@dcloudio/uni-uts-v1', utsCompilerVersion));
|
|
@@ -135,9 +145,7 @@ exports.parseUTSComponent = parseUTSComponent;
|
|
|
135
145
|
function initUTSComponents(inputDir, platform) {
|
|
136
146
|
utsComponents.clear();
|
|
137
147
|
const components = [];
|
|
138
|
-
|
|
139
|
-
return components;
|
|
140
|
-
}
|
|
148
|
+
const isApp = platform === 'app' || platform === 'app-plus';
|
|
141
149
|
const easycomsObj = {};
|
|
142
150
|
const dirs = resolveUTSComponentDirs(inputDir);
|
|
143
151
|
dirs.forEach((dir) => {
|
|
@@ -162,7 +170,7 @@ function initUTSComponents(inputDir, platform) {
|
|
|
162
170
|
if (name) {
|
|
163
171
|
const importDir = (0, utils_1.normalizePath)(is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir);
|
|
164
172
|
easycomsObj[`^${name}$`] = {
|
|
165
|
-
source: `${importDir}?uts-proxy
|
|
173
|
+
source: isApp ? `${importDir}?uts-proxy` : (0, utils_1.normalizePath)(file),
|
|
166
174
|
kotlinPackage: parseKotlinPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
167
175
|
swiftModule: parseSwiftPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
168
176
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.2-
|
|
3
|
+
"version": "2.0.2-4010420240430001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"postcss-urlrewrite": "^0.2.2",
|
|
27
27
|
"strip-json-comments": "^2.0.1"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "a7bbe4fc8a1d686ec33b8183cb0429083d7dd8b2"
|
|
30
30
|
}
|