@dcloudio/uni-cli-shared 2.0.2-4020920240930001 → 2.0.2-4030620241128001
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/platform.js +10 -4
- package/lib/uts/dataToEsm.js +154 -0
- package/lib/uts/uni_modules.js +52 -21
- package/lib/uts/uts-loader.js +152 -0
- package/lib/uts/uts-webpack-plugin.js +138 -0
- package/lib/uts/uts.js +185 -14
- package/license.md +1 -1
- package/package.json +3 -2
package/lib/platform.js
CHANGED
|
@@ -46,13 +46,19 @@ function getShadowCdn () {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
let appid
|
|
49
|
+
let platformAppId
|
|
49
50
|
|
|
50
|
-
function createIdent () {
|
|
51
|
+
function createIdent (platform) {
|
|
51
52
|
if (process.env.UNI_INPUT_DIR) {
|
|
52
53
|
if (typeof appid === 'undefined') {
|
|
53
|
-
|
|
54
|
+
const manifestJson = getManifestJson()
|
|
55
|
+
appid = manifestJson.appid || ''
|
|
56
|
+
platformAppId = manifestJson[platform]?.appid
|
|
57
|
+
}
|
|
58
|
+
let id = appid.replace('__UNI__', '')
|
|
59
|
+
if (platformAppId) {
|
|
60
|
+
id += '%%' + platformAppId
|
|
54
61
|
}
|
|
55
|
-
const id = appid.replace('__UNI__', '')
|
|
56
62
|
if (id) {
|
|
57
63
|
return Buffer.from(Buffer.from(id).toString('base64')).toString('hex')
|
|
58
64
|
}
|
|
@@ -63,7 +69,7 @@ function createIdent () {
|
|
|
63
69
|
function createShadowImageUrl (cdn, type = 'grey') {
|
|
64
70
|
let identStr = ''
|
|
65
71
|
if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'web') {
|
|
66
|
-
const ident = createIdent()
|
|
72
|
+
const ident = createIdent(process.env.UNI_PLATFORM)
|
|
67
73
|
identStr = ident ? `${ident}/` : ''
|
|
68
74
|
}
|
|
69
75
|
return `https://cdn${cdn || ''}.dcloud.net.cn/${identStr}img/shadow-${type}.png`
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const reservedWords =
|
|
2
|
+
'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'
|
|
3
|
+
const builtins =
|
|
4
|
+
'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'
|
|
5
|
+
const forbiddenIdentifiers = new Set(`${reservedWords} ${builtins}`.split(' '))
|
|
6
|
+
forbiddenIdentifiers.add('')
|
|
7
|
+
const makeLegalIdentifier = function makeLegalIdentifier (str) {
|
|
8
|
+
let identifier = str
|
|
9
|
+
.replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
|
|
10
|
+
.replace(/[^$_a-zA-Z0-9]/g, '_')
|
|
11
|
+
if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) {
|
|
12
|
+
identifier = `_${identifier}`
|
|
13
|
+
}
|
|
14
|
+
return identifier || '_'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function stringify (obj) {
|
|
18
|
+
return (JSON.stringify(obj) || 'undefined').replace(/[\u2028\u2029]/g, (char) =>
|
|
19
|
+
`\\u${`000${char.charCodeAt(0).toString(16)}`.slice(-4)}`)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function serializeArray (arr, indent, baseIndent) {
|
|
23
|
+
let output = '['
|
|
24
|
+
const separator = indent ? `\n${baseIndent}${indent}` : ''
|
|
25
|
+
for (let i = 0; i < arr.length; i++) {
|
|
26
|
+
const key = arr[i]
|
|
27
|
+
output += `${i > 0 ? ',' : ''}${separator}${serialize(key, indent, baseIndent + indent)}`
|
|
28
|
+
}
|
|
29
|
+
return `${output}${indent ? `\n${baseIndent}` : ''}]`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function serializeObject (obj, indent, baseIndent) {
|
|
33
|
+
let output = '{'
|
|
34
|
+
const separator = indent ? `\n${baseIndent}${indent}` : ''
|
|
35
|
+
const entries = Object.entries(obj)
|
|
36
|
+
for (let i = 0; i < entries.length; i++) {
|
|
37
|
+
const [key, value] = entries[i]
|
|
38
|
+
const stringKey = makeLegalIdentifier(key) === key ? key : stringify(key)
|
|
39
|
+
output +=
|
|
40
|
+
`${i > 0 ? ',' : ''}${separator}${stringKey}:${indent ? ' ' : ''}${serialize(value, indent, baseIndent + indent)}`
|
|
41
|
+
}
|
|
42
|
+
return `${output}${indent ? `\n${baseIndent}` : ''}}`
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function serialize (obj, indent, baseIndent) {
|
|
46
|
+
if (typeof obj === 'object' && obj !== null) {
|
|
47
|
+
if (Array.isArray(obj)) {
|
|
48
|
+
return serializeArray(obj, indent, baseIndent)
|
|
49
|
+
}
|
|
50
|
+
if (obj instanceof Date) {
|
|
51
|
+
return `new Date(${obj.getTime()})`
|
|
52
|
+
}
|
|
53
|
+
if (obj instanceof RegExp) {
|
|
54
|
+
return obj.toString()
|
|
55
|
+
}
|
|
56
|
+
return serializeObject(obj, indent, baseIndent)
|
|
57
|
+
}
|
|
58
|
+
if (typeof obj === 'number') {
|
|
59
|
+
if (obj === Infinity) {
|
|
60
|
+
return 'Infinity'
|
|
61
|
+
}
|
|
62
|
+
if (obj === -Infinity) {
|
|
63
|
+
return '-Infinity'
|
|
64
|
+
}
|
|
65
|
+
if (obj === 0) {
|
|
66
|
+
return 1 / obj === Infinity ? '0' : '-0'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (isNaN(obj)) {
|
|
70
|
+
return 'NaN'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (typeof obj === 'symbol') {
|
|
74
|
+
const key = Symbol.keyFor(obj)
|
|
75
|
+
// eslint-disable-next-line no-undefined
|
|
76
|
+
if (key !== undefined) {
|
|
77
|
+
return `Symbol.for(${stringify(key)})`
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (typeof obj === 'bigint') {
|
|
81
|
+
return `${obj}n`
|
|
82
|
+
}
|
|
83
|
+
return stringify(obj)
|
|
84
|
+
}
|
|
85
|
+
// isWellFormed exists from Node.js 20
|
|
86
|
+
const hasStringIsWellFormed = 'isWellFormed' in String.prototype
|
|
87
|
+
|
|
88
|
+
function isWellFormedString (input) {
|
|
89
|
+
// @ts-expect-error String::isWellFormed exists from ES2024. tsconfig lib is set to ES6
|
|
90
|
+
if (hasStringIsWellFormed) {
|
|
91
|
+
return input.isWellFormed()
|
|
92
|
+
}
|
|
93
|
+
// https://github.com/tc39/proposal-is-usv-string/blob/main/README.md#algorithm
|
|
94
|
+
return !/\p{Surrogate}/u.test(input)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function dataToEsm (data, options = {}) {
|
|
98
|
+
var _a, _b
|
|
99
|
+
const t = options.compact ? '' : 'indent' in options ? options.indent : '\t'
|
|
100
|
+
const _ = options.compact ? '' : ' '
|
|
101
|
+
const n = options.compact ? '' : '\n'
|
|
102
|
+
const declarationType = options.preferConst ? 'const' : 'var'
|
|
103
|
+
if (options.namedExports === false ||
|
|
104
|
+
typeof data !== 'object' ||
|
|
105
|
+
Array.isArray(data) ||
|
|
106
|
+
data instanceof Date ||
|
|
107
|
+
data instanceof RegExp ||
|
|
108
|
+
data === null) {
|
|
109
|
+
const code = serialize(data, options.compact ? null : t, '')
|
|
110
|
+
const magic = _ || (/^[{[\-\/]/.test(code) ? '' : ' ') // eslint-disable-line no-useless-escape
|
|
111
|
+
return `export default${magic}${code};`
|
|
112
|
+
}
|
|
113
|
+
let maxUnderbarPrefixLength = 0
|
|
114
|
+
for (const key of Object.keys(data)) {
|
|
115
|
+
const underbarPrefixLength = (_b = (_a = key.match(/^(_+)/)) === null || _a === undefined ? undefined : _a[0]
|
|
116
|
+
.length) !==
|
|
117
|
+
null && _b !== undefined ? _b : 0
|
|
118
|
+
if (underbarPrefixLength > maxUnderbarPrefixLength) {
|
|
119
|
+
maxUnderbarPrefixLength = underbarPrefixLength
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const arbitraryNamePrefix = `${'_'.repeat(maxUnderbarPrefixLength + 1)}arbitrary`
|
|
123
|
+
let namedExportCode = ''
|
|
124
|
+
const defaultExportRows = []
|
|
125
|
+
const arbitraryNameExportRows = []
|
|
126
|
+
for (const [key, value] of Object.entries(data)) {
|
|
127
|
+
if (key === makeLegalIdentifier(key)) {
|
|
128
|
+
if (options.objectShorthand) {
|
|
129
|
+
defaultExportRows.push(key)
|
|
130
|
+
} else {
|
|
131
|
+
defaultExportRows.push(`${key}:${_}${key}`)
|
|
132
|
+
}
|
|
133
|
+
namedExportCode +=
|
|
134
|
+
`export ${declarationType} ${key}${_}=${_}${serialize(value, options.compact ? null : t, '')};${n}`
|
|
135
|
+
} else {
|
|
136
|
+
defaultExportRows.push(`${stringify(key)}:${_}${serialize(value, options.compact ? null : t, '')}`)
|
|
137
|
+
if (options.includeArbitraryNames && isWellFormedString(key)) {
|
|
138
|
+
const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`
|
|
139
|
+
namedExportCode +=
|
|
140
|
+
`${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, '')};${n}`
|
|
141
|
+
arbitraryNameExportRows.push(`${variableName} as ${JSON.stringify(key)}`)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const arbitraryExportCode = arbitraryNameExportRows.length > 0
|
|
146
|
+
? `export${_}{${n}${t}${arbitraryNameExportRows.join(`,${n}${t}`)}${n}};${n}`
|
|
147
|
+
: ''
|
|
148
|
+
const defaultExportCode = `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`
|
|
149
|
+
return `${namedExportCode}${arbitraryExportCode}${defaultExportCode}`
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
module.exports = {
|
|
153
|
+
dataToEsm
|
|
154
|
+
}
|
package/lib/uts/uni_modules.js
CHANGED
|
@@ -3,27 +3,38 @@ 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.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.getUniExtApiProviders = void 0;
|
|
6
|
+
exports.parseUTSModuleDeps = exports.capitalize = exports.camelize = exports.parseInjects = exports.parseUniExtApi = exports.parseUniExtApis = exports.getUniExtApiProviderRegisters = exports.formatExtApiProviderName = exports.getUniExtApiPlugins = exports.getUniExtApiProviders = void 0;
|
|
7
7
|
// 重要:此文件编译后的js,需同步至 vue2 编译器中 uni-cli-shared/lib/uts/uni_modules.js
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
10
|
const extApiProviders = [];
|
|
11
|
+
const extApiPlugins = new Set();
|
|
11
12
|
function getUniExtApiProviders() {
|
|
12
13
|
return extApiProviders;
|
|
13
14
|
}
|
|
14
15
|
exports.getUniExtApiProviders = getUniExtApiProviders;
|
|
16
|
+
function getUniExtApiPlugins() {
|
|
17
|
+
return [...extApiPlugins].map((plugin) => {
|
|
18
|
+
return { plugin };
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
exports.getUniExtApiPlugins = getUniExtApiPlugins;
|
|
22
|
+
function formatExtApiProviderName(service, name) {
|
|
23
|
+
if (service === 'oauth') {
|
|
24
|
+
service = 'OAuth';
|
|
25
|
+
}
|
|
26
|
+
return `Uni${(0, exports.capitalize)((0, exports.camelize)(service))}${(0, exports.capitalize)((0, exports.camelize)(name))}ProviderImpl`;
|
|
27
|
+
}
|
|
28
|
+
exports.formatExtApiProviderName = formatExtApiProviderName;
|
|
15
29
|
function getUniExtApiProviderRegisters() {
|
|
16
30
|
const result = [];
|
|
17
31
|
extApiProviders.forEach((provider) => {
|
|
18
32
|
if (provider.name && provider.service) {
|
|
19
33
|
result.push({
|
|
20
34
|
name: provider.name,
|
|
35
|
+
plugin: provider.plugin,
|
|
21
36
|
service: provider.service,
|
|
22
|
-
class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${(
|
|
23
|
-
provider.service +
|
|
24
|
-
'-' +
|
|
25
|
-
provider.name +
|
|
26
|
-
'-provider'))}`,
|
|
37
|
+
class: `uts.sdk.modules.${(0, exports.camelize)(provider.plugin)}.${formatExtApiProviderName(provider.service, provider.name)}`,
|
|
27
38
|
});
|
|
28
39
|
}
|
|
29
40
|
});
|
|
@@ -40,6 +51,7 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
40
51
|
}
|
|
41
52
|
const injects = {};
|
|
42
53
|
extApiProviders.length = 0;
|
|
54
|
+
extApiPlugins.clear();
|
|
43
55
|
fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
|
|
44
56
|
// 必须以 uni- 开头
|
|
45
57
|
if (!uniModuleDir.startsWith('uni-')) {
|
|
@@ -62,6 +74,7 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
62
74
|
provider.plugin = uniModuleDir;
|
|
63
75
|
extApiProviders.push(provider);
|
|
64
76
|
}
|
|
77
|
+
extApiPlugins.add(uniModuleDir);
|
|
65
78
|
const curInjects = parseInjects(vite, platform, language, `@/uni_modules/${uniModuleDir}`, uniModuleRootDir, exports);
|
|
66
79
|
Object.assign(injects, curInjects);
|
|
67
80
|
}
|
|
@@ -71,6 +84,21 @@ function parseUniExtApis(vite = true, platform, language = 'javascript') {
|
|
|
71
84
|
return injects;
|
|
72
85
|
}
|
|
73
86
|
exports.parseUniExtApis = parseUniExtApis;
|
|
87
|
+
function parseUniExtApi(pluginDir, pluginId, vite = true, platform, language = 'javascript') {
|
|
88
|
+
const pkgPath = path_1.default.resolve(pluginDir, 'package.json');
|
|
89
|
+
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
let exports;
|
|
93
|
+
const pkg = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'));
|
|
94
|
+
if (pkg && pkg.uni_modules && pkg.uni_modules['uni-ext-api']) {
|
|
95
|
+
exports = pkg.uni_modules['uni-ext-api'];
|
|
96
|
+
}
|
|
97
|
+
if (exports) {
|
|
98
|
+
return parseInjects(vite, platform, language, `@/uni_modules/${pluginId}`, pluginDir, exports);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.parseUniExtApi = parseUniExtApi;
|
|
74
102
|
/**
|
|
75
103
|
* uni:'getBatteryInfo'
|
|
76
104
|
* import getBatteryInfo from '..'
|
|
@@ -113,13 +141,15 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
113
141
|
if (platform === 'app') {
|
|
114
142
|
hasPlatformFile =
|
|
115
143
|
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-android')) ||
|
|
116
|
-
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios'))
|
|
144
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-ios')) ||
|
|
145
|
+
fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-harmony'));
|
|
117
146
|
}
|
|
118
147
|
}
|
|
119
148
|
// 其他平台修改source,直接指向目标文件,否则 uts2js 找不到类型信息
|
|
120
149
|
if (platform !== 'app' &&
|
|
121
150
|
platform !== 'app-android' &&
|
|
122
|
-
platform !== 'app-ios'
|
|
151
|
+
platform !== 'app-ios' &&
|
|
152
|
+
platform !== 'app-harmony') {
|
|
123
153
|
if (fs_extra_1.default.existsSync(platformIndexFileName)) {
|
|
124
154
|
source = `${source}/utssdk/${platform}/index.uts`;
|
|
125
155
|
}
|
|
@@ -127,6 +157,11 @@ function parseInjects(vite = true, platform, language, source, uniModuleRootDir,
|
|
|
127
157
|
source = `${source}/utssdk/index.uts`;
|
|
128
158
|
}
|
|
129
159
|
}
|
|
160
|
+
else if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
|
|
161
|
+
if (fs_extra_1.default.existsSync(path_1.default.resolve(uniModuleRootDir, 'utssdk', 'app-js', 'index.uts'))) {
|
|
162
|
+
source = `${source}/utssdk/app-js/index.uts`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
130
165
|
for (const key in rootDefines) {
|
|
131
166
|
Object.assign(injects, parseInject(vite, platform, language, source, 'uni', rootDefines[key], hasPlatformFile));
|
|
132
167
|
}
|
|
@@ -162,7 +197,9 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
|
|
|
162
197
|
}
|
|
163
198
|
else {
|
|
164
199
|
const defineOptions = define[d];
|
|
165
|
-
const p = platform === 'app-android' ||
|
|
200
|
+
const p = platform === 'app-android' ||
|
|
201
|
+
platform === 'app-ios' ||
|
|
202
|
+
platform === 'app-harmony'
|
|
166
203
|
? 'app'
|
|
167
204
|
: platform;
|
|
168
205
|
if (!(p in defineOptions)) {
|
|
@@ -175,18 +212,12 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
|
|
|
175
212
|
if (p === 'app') {
|
|
176
213
|
const appOptions = defineOptions.app;
|
|
177
214
|
if (isPlainObject(appOptions)) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
if (appOptions.kotlin === false) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
else if (language === 'swift') {
|
|
189
|
-
if (appOptions.swift === false) {
|
|
215
|
+
// js engine 下且存在 app-js,不检查
|
|
216
|
+
const skipCheck = process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js' &&
|
|
217
|
+
source.includes('app-js');
|
|
218
|
+
if (!skipCheck) {
|
|
219
|
+
const targetLanguage = language === 'javascript' ? 'js' : language;
|
|
220
|
+
if (targetLanguage && appOptions[targetLanguage] === false) {
|
|
190
221
|
return;
|
|
191
222
|
}
|
|
192
223
|
}
|
package/lib/uts/uts-loader.js
CHANGED
|
@@ -6,10 +6,159 @@ const {
|
|
|
6
6
|
const {
|
|
7
7
|
parseUTSModuleDeps
|
|
8
8
|
} = require('./uni_modules')
|
|
9
|
+
const {
|
|
10
|
+
dataToEsm
|
|
11
|
+
} = require('./dataToEsm')
|
|
12
|
+
const {
|
|
13
|
+
getUniXKotlinCompiler,
|
|
14
|
+
getUniXSwiftCompiler,
|
|
15
|
+
getChangedFiles,
|
|
16
|
+
getUTSPlugins
|
|
17
|
+
} = require('./uts-webpack-plugin')
|
|
18
|
+
|
|
19
|
+
function createUniModulesSyncFilePreprocessor (
|
|
20
|
+
platform,
|
|
21
|
+
utsPlatform
|
|
22
|
+
) {
|
|
23
|
+
const initPreprocessContext = require('../preprocess')
|
|
24
|
+
const {
|
|
25
|
+
vueContext: preContext
|
|
26
|
+
} = initPreprocessContext(
|
|
27
|
+
platform,
|
|
28
|
+
global.uniPlugin.platforms
|
|
29
|
+
)
|
|
30
|
+
if (utsPlatform === 'app-android') {
|
|
31
|
+
preContext.APP_ANDROID = true
|
|
32
|
+
}
|
|
33
|
+
if (utsPlatform === 'app-ios') {
|
|
34
|
+
preContext.APP_IOS = true
|
|
35
|
+
}
|
|
36
|
+
const {
|
|
37
|
+
preprocess
|
|
38
|
+
} = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/preprocess/lib/preprocess')
|
|
39
|
+
|
|
40
|
+
function preJs (jsCode) {
|
|
41
|
+
return preprocess(jsCode, preContext, {
|
|
42
|
+
type: 'js'
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function preHtml (htmlCode) {
|
|
47
|
+
return preprocess(htmlCode, preContext, {
|
|
48
|
+
type: 'html'
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return async (content, fileName) => {
|
|
53
|
+
const extname = path.extname(fileName)
|
|
54
|
+
if (extname === '.json') {
|
|
55
|
+
return dataToEsm(JSON.parse(preJs(content)), {
|
|
56
|
+
namedExports: true,
|
|
57
|
+
preferConst: true
|
|
58
|
+
})
|
|
59
|
+
} else if (extname === '.uts' || extname === '.ts') {
|
|
60
|
+
return preJs(content)
|
|
61
|
+
} else if (extname === '.uvue' || extname === '.vue') {
|
|
62
|
+
return preJs(preHtml(content))
|
|
63
|
+
}
|
|
64
|
+
return content
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function once (fn, ctx = null) {
|
|
69
|
+
let res
|
|
70
|
+
return (...args) => {
|
|
71
|
+
if (fn) {
|
|
72
|
+
res = fn.apply(ctx, args)
|
|
73
|
+
fn = null
|
|
74
|
+
}
|
|
75
|
+
return res
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const createAppAndroidUniModulesSyncFilePreprocessorOnce = once(
|
|
80
|
+
() => {
|
|
81
|
+
return createUniModulesSyncFilePreprocessor('app', 'app-android')
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const createAppIosUniModulesSyncFilePreprocessorOnce = once(
|
|
86
|
+
() => {
|
|
87
|
+
return createUniModulesSyncFilePreprocessor('app', 'app-ios')
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
|
|
9
91
|
module.exports = async function (content) {
|
|
10
92
|
const callback = this.async()
|
|
11
93
|
|
|
94
|
+
const uniXKotlinCompiler = getUniXKotlinCompiler()
|
|
95
|
+
const uniXSwiftCompiler = getUniXSwiftCompiler()
|
|
96
|
+
|
|
97
|
+
const {
|
|
98
|
+
syncUniModuleFilesByCompiler,
|
|
99
|
+
resolveTscUniModuleIndexFileName
|
|
100
|
+
} = resolveUTSCompiler()
|
|
101
|
+
|
|
12
102
|
const compilePlugin = async (pluginDir) => {
|
|
103
|
+
const pluginId = path.basename(pluginDir)
|
|
104
|
+
|
|
105
|
+
const utsPlugins = getUTSPlugins()
|
|
106
|
+
const changedFiles = getChangedFiles()
|
|
107
|
+
if (uniXKotlinCompiler) {
|
|
108
|
+
await uniXKotlinCompiler.init()
|
|
109
|
+
await syncUniModuleFilesByCompiler(
|
|
110
|
+
'app-android',
|
|
111
|
+
uniXKotlinCompiler,
|
|
112
|
+
pluginDir,
|
|
113
|
+
createAppAndroidUniModulesSyncFilePreprocessorOnce()
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (uniXSwiftCompiler) {
|
|
118
|
+
await uniXSwiftCompiler.init()
|
|
119
|
+
await syncUniModuleFilesByCompiler(
|
|
120
|
+
'app-ios',
|
|
121
|
+
uniXSwiftCompiler,
|
|
122
|
+
pluginDir,
|
|
123
|
+
createAppIosUniModulesSyncFilePreprocessorOnce()
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!utsPlugins.has(pluginId)) {
|
|
128
|
+
utsPlugins.add(pluginId)
|
|
129
|
+
if (uniXKotlinCompiler) {
|
|
130
|
+
const indexFileName = resolveTscUniModuleIndexFileName(
|
|
131
|
+
'app-android',
|
|
132
|
+
pluginDir
|
|
133
|
+
)
|
|
134
|
+
if (indexFileName) {
|
|
135
|
+
await uniXKotlinCompiler.addRootFile(indexFileName)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (uniXSwiftCompiler) {
|
|
139
|
+
const indexFileName = resolveTscUniModuleIndexFileName(
|
|
140
|
+
'app-ios',
|
|
141
|
+
pluginDir
|
|
142
|
+
)
|
|
143
|
+
if (indexFileName) {
|
|
144
|
+
await uniXSwiftCompiler.addRootFile(indexFileName)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 处理uni_modules中的文件变更
|
|
150
|
+
const files = changedFiles.get(pluginId)
|
|
151
|
+
if (files) {
|
|
152
|
+
// 仅限watch模式是会生效
|
|
153
|
+
changedFiles.delete(pluginId)
|
|
154
|
+
if (uniXKotlinCompiler) {
|
|
155
|
+
await uniXKotlinCompiler.invalidate(files)
|
|
156
|
+
}
|
|
157
|
+
if (uniXSwiftCompiler) {
|
|
158
|
+
await uniXSwiftCompiler.invalidate(files)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
13
162
|
const pkgJson = require(path.join(pluginDir, 'package.json'))
|
|
14
163
|
const compiler = resolveUTSCompiler()
|
|
15
164
|
// 处理依赖的 uts 插件
|
|
@@ -33,6 +182,9 @@ module.exports = async function (content) {
|
|
|
33
182
|
),
|
|
34
183
|
sourceMap: process.env.NODE_ENV === 'development',
|
|
35
184
|
uni_modules: deps
|
|
185
|
+
// 暂不提供
|
|
186
|
+
// async kotlinAutoImports() {}
|
|
187
|
+
// async swiftAutoImports() {}
|
|
36
188
|
})
|
|
37
189
|
}
|
|
38
190
|
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const fs = require('fs-extra')
|
|
3
|
+
const {
|
|
4
|
+
resolveUTSCompiler
|
|
5
|
+
} = require('./uts')
|
|
6
|
+
const {
|
|
7
|
+
normalizePath
|
|
8
|
+
} = require('../util')
|
|
9
|
+
const {
|
|
10
|
+
runByHBuilderX
|
|
11
|
+
} = require('../platform')
|
|
12
|
+
|
|
13
|
+
class WebpackUTSPlugin {
|
|
14
|
+
apply (compiler) {
|
|
15
|
+
compiler.hooks.watchRun.tapAsync('WatchRun', (comp, done) => {
|
|
16
|
+
let changedFileNames = []
|
|
17
|
+
if (comp.modifiedFiles) { // webpack5
|
|
18
|
+
changedFileNames = Array.from(comp.modifiedFiles)
|
|
19
|
+
} else if (comp.watchFileSystem?.watcher?.mtimes) { // webpack4
|
|
20
|
+
changedFileNames = Object.keys(comp.watchFileSystem.watcher.mtimes)
|
|
21
|
+
}
|
|
22
|
+
if (changedFileNames.length) {
|
|
23
|
+
// console.log('====================================')
|
|
24
|
+
// console.log('NEW BUILD FILES CHANGED:', changedFileNames)
|
|
25
|
+
// console.log('====================================')
|
|
26
|
+
const uniModulesDir = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules'))
|
|
27
|
+
changedFileNames.forEach(fileName => {
|
|
28
|
+
fileName = normalizePath(fileName)
|
|
29
|
+
if (fileName.startsWith(uniModulesDir)) {
|
|
30
|
+
// 仅处理uni_modules中的文件
|
|
31
|
+
const plugin = fileName.slice(uniModulesDir.length + 1).split('/')[0]
|
|
32
|
+
if (utsPlugins.has(plugin)) {
|
|
33
|
+
const changeFile = {
|
|
34
|
+
fileName,
|
|
35
|
+
event: 'update' // 写死 update
|
|
36
|
+
}
|
|
37
|
+
if (!changedFiles.has(plugin)) {
|
|
38
|
+
changedFiles.set(plugin, [changeFile])
|
|
39
|
+
} else {
|
|
40
|
+
changedFiles.get(plugin).push(changeFile)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
return done()
|
|
47
|
+
})
|
|
48
|
+
compiler.hooks.done.tapPromise('webpack-uts-done', async () => {
|
|
49
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
50
|
+
if (uniXKotlinCompiler) {
|
|
51
|
+
await uniXKotlinCompiler.close()
|
|
52
|
+
}
|
|
53
|
+
if (uniXSwiftCompiler) {
|
|
54
|
+
await uniXSwiftCompiler.close()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
let uniXKotlinCompiler = null
|
|
61
|
+
let uniXSwiftCompiler = null
|
|
62
|
+
const utsPlugins = new Set()
|
|
63
|
+
const changedFiles = new Map()
|
|
64
|
+
|
|
65
|
+
function getUTSPlugins () {
|
|
66
|
+
return utsPlugins
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function getChangedFiles () {
|
|
70
|
+
return changedFiles
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function getUniXKotlinCompiler () {
|
|
74
|
+
if (uniXKotlinCompiler) {
|
|
75
|
+
return uniXKotlinCompiler
|
|
76
|
+
}
|
|
77
|
+
const {
|
|
78
|
+
createUniXKotlinCompilerOnce
|
|
79
|
+
} = resolveUTSCompiler()
|
|
80
|
+
|
|
81
|
+
uniXKotlinCompiler = runByHBuilderX && process.env.UNI_APP_X_TSC === 'true' &&
|
|
82
|
+
(process.env.UNI_UTS_PLATFORM === 'app-android' ||
|
|
83
|
+
process.env.UNI_UTS_PLATFORM === 'app' ||
|
|
84
|
+
process.env.UNI_UTS_PLATFORM === 'app-plus')
|
|
85
|
+
? createUniXKotlinCompilerOnce()
|
|
86
|
+
: null
|
|
87
|
+
if (uniXKotlinCompiler) {
|
|
88
|
+
const tscDir = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tsc/app-android')
|
|
89
|
+
const uvueDir = path.resolve(process.env.UNI_OUTPUT_DIR, '../.uvue/app-android')
|
|
90
|
+
try {
|
|
91
|
+
if (fs.existsSync(tscDir)) {
|
|
92
|
+
fs.emptyDirSync(tscDir)
|
|
93
|
+
}
|
|
94
|
+
if (fs.existsSync(uvueDir)) {
|
|
95
|
+
fs.emptyDirSync(uvueDir)
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {}
|
|
98
|
+
}
|
|
99
|
+
return uniXKotlinCompiler
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function getUniXSwiftCompiler () {
|
|
103
|
+
if (uniXSwiftCompiler) {
|
|
104
|
+
return uniXSwiftCompiler
|
|
105
|
+
}
|
|
106
|
+
const {
|
|
107
|
+
createUniXSwiftCompilerOnce
|
|
108
|
+
} = resolveUTSCompiler()
|
|
109
|
+
|
|
110
|
+
uniXSwiftCompiler =
|
|
111
|
+
runByHBuilderX && process.env.UNI_APP_X_TSC === 'true' &&
|
|
112
|
+
(process.env.UNI_UTS_PLATFORM === 'app-ios' ||
|
|
113
|
+
process.env.UNI_UTS_PLATFORM === 'app' ||
|
|
114
|
+
process.env.UNI_UTS_PLATFORM === 'app-plus')
|
|
115
|
+
? createUniXSwiftCompilerOnce()
|
|
116
|
+
: null
|
|
117
|
+
|
|
118
|
+
if (uniXSwiftCompiler) {
|
|
119
|
+
const tscDir = path.resolve(process.env.UNI_OUTPUT_DIR, '../.tsc/app-ios')
|
|
120
|
+
const uvueDir = path.resolve(process.env.UNI_OUTPUT_DIR, '../.uvue/app-ios')
|
|
121
|
+
try {
|
|
122
|
+
if (fs.existsSync(tscDir)) {
|
|
123
|
+
fs.emptyDirSync(tscDir)
|
|
124
|
+
}
|
|
125
|
+
if (fs.existsSync(uvueDir)) {
|
|
126
|
+
fs.emptyDirSync(uvueDir)
|
|
127
|
+
}
|
|
128
|
+
} catch (e) {}
|
|
129
|
+
}
|
|
130
|
+
return uniXSwiftCompiler
|
|
131
|
+
}
|
|
132
|
+
module.exports = {
|
|
133
|
+
getUTSPlugins,
|
|
134
|
+
getChangedFiles,
|
|
135
|
+
getUniXKotlinCompiler,
|
|
136
|
+
getUniXSwiftCompiler,
|
|
137
|
+
WebpackUTSPlugin
|
|
138
|
+
}
|
package/lib/uts/uts.js
CHANGED
|
@@ -3,9 +3,9 @@ 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.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
|
|
6
|
+
exports.tscOutDir = exports.uvueOutDir = exports.genUniExtApiDeclarationFileOnce = exports.initUTSSwiftAutoImportsOnce = exports.initUTSKotlinAutoImportsOnce = exports.resolveUniTypeScript = exports.parseUniExtApiNamespacesJsOnce = exports.parseUniExtApiNamespacesOnce = exports.parseSwiftPackageWithPluginId = exports.parseKotlinPackageWithPluginId = exports.initUTSComponents = exports.parseUTSComponent = exports.getUTSComponentAutoImports = exports.isUTSComponent = exports.resolveUTSCompiler = exports.resolveUTSModule = exports.resolveUTSAppModule = void 0;
|
|
7
7
|
// 重要,该文件编译后的 js 需要同步到 vue2 编译器 uni-cli-shared/lib/uts
|
|
8
|
-
const
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
11
11
|
const hbx_1 = require("./hbx");
|
|
@@ -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('/');
|
|
@@ -35,13 +35,29 @@ function resolveUTSAppModule(id, importer, includeUTSSDK = true) {
|
|
|
35
35
|
if (parentDir === 'uni_modules' ||
|
|
36
36
|
(includeUTSSDK && parentDir === 'utssdk')) {
|
|
37
37
|
const basedir = parentDir === 'uni_modules' ? 'utssdk' : '';
|
|
38
|
-
if (
|
|
38
|
+
if (process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js') {
|
|
39
|
+
// js engine
|
|
40
|
+
if (parentDir === 'uni_modules') {
|
|
41
|
+
const appJsIndex = path_1.default.resolve(id, basedir, 'app-js', 'index.uts');
|
|
42
|
+
if (fs_extra_1.default.existsSync(appJsIndex)) {
|
|
43
|
+
return appJsIndex;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (fs_extra_1.default.existsSync(path_1.default.resolve(id, basedir, 'index.uts'))) {
|
|
39
48
|
return id;
|
|
40
49
|
}
|
|
50
|
+
const fileName = id.split('?')[0];
|
|
41
51
|
const resolvePlatformDir = (p) => {
|
|
42
|
-
return path_1.default.resolve(
|
|
52
|
+
return path_1.default.resolve(fileName, basedir, p);
|
|
43
53
|
};
|
|
44
|
-
const extname = ['.uts'];
|
|
54
|
+
const extname = ['.uts', '.vue', '.uvue'];
|
|
55
|
+
if (platform === 'app-harmony') {
|
|
56
|
+
if (resolveUTSFile(resolvePlatformDir(platform), extname)) {
|
|
57
|
+
return id;
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
45
61
|
if (resolveUTSFile(resolvePlatformDir('app-android'), extname)) {
|
|
46
62
|
return id;
|
|
47
63
|
}
|
|
@@ -55,8 +71,9 @@ exports.resolveUTSAppModule = resolveUTSAppModule;
|
|
|
55
71
|
// 仅限 root/uni_modules/test-plugin | root/utssdk/test-plugin 格式
|
|
56
72
|
function resolveUTSModule(id, importer, includeUTSSDK = true) {
|
|
57
73
|
if (process.env.UNI_PLATFORM === 'app' ||
|
|
58
|
-
process.env.UNI_PLATFORM === 'app-plus'
|
|
59
|
-
|
|
74
|
+
process.env.UNI_PLATFORM === 'app-plus' ||
|
|
75
|
+
process.env.UNI_PLATFORM === 'app-harmony') {
|
|
76
|
+
return resolveUTSAppModule(process.env.UNI_UTS_PLATFORM, id, importer);
|
|
60
77
|
}
|
|
61
78
|
id = path_1.default.resolve(importer, id);
|
|
62
79
|
if (id.includes('uni_modules') || (includeUTSSDK && id.includes('utssdk'))) {
|
|
@@ -73,7 +90,7 @@ function resolveUTSModule(id, importer, includeUTSSDK = true) {
|
|
|
73
90
|
return index;
|
|
74
91
|
}
|
|
75
92
|
index = path_1.default.resolve(id, basedir, 'index.uts');
|
|
76
|
-
if (
|
|
93
|
+
if (fs_extra_1.default.existsSync(index)) {
|
|
77
94
|
return index;
|
|
78
95
|
}
|
|
79
96
|
}
|
|
@@ -83,7 +100,7 @@ exports.resolveUTSModule = resolveUTSModule;
|
|
|
83
100
|
function resolveUTSFile(dir, extensions = ['.uts', '.ts', '.js']) {
|
|
84
101
|
for (let i = 0; i < extensions.length; i++) {
|
|
85
102
|
const indexFile = path_1.default.join(dir, 'index' + extensions[i]);
|
|
86
|
-
if (
|
|
103
|
+
if (fs_extra_1.default.existsSync(indexFile)) {
|
|
87
104
|
return indexFile;
|
|
88
105
|
}
|
|
89
106
|
}
|
|
@@ -99,7 +116,7 @@ function resolveUTSCompiler() {
|
|
|
99
116
|
if (!compilerPath) {
|
|
100
117
|
try {
|
|
101
118
|
compilerPath = require.resolve('@dcloudio/uni-uts-v1', {
|
|
102
|
-
paths: [process.env.UNI_CLI_CONTEXT],
|
|
119
|
+
paths: [process.env.UNI_CLI_CONTEXT || process.cwd()],
|
|
103
120
|
});
|
|
104
121
|
}
|
|
105
122
|
catch (e) {
|
|
@@ -129,6 +146,23 @@ function isUTSComponent(name) {
|
|
|
129
146
|
return utsComponents.has(name);
|
|
130
147
|
}
|
|
131
148
|
exports.isUTSComponent = isUTSComponent;
|
|
149
|
+
function getUTSComponentAutoImports(language) {
|
|
150
|
+
const utsComponentAutoImports = {};
|
|
151
|
+
utsComponents.forEach(({ kotlinPackage, swiftModule }, name) => {
|
|
152
|
+
const source = language === 'kotlin' ? kotlinPackage : swiftModule;
|
|
153
|
+
const className = (0, utils_1.capitalize)((0, utils_1.camelize)(name)) + 'Element';
|
|
154
|
+
if (!utsComponentAutoImports[source]) {
|
|
155
|
+
utsComponentAutoImports[source] = [[className]];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
if (!utsComponentAutoImports[source].find((item) => item[0] === className)) {
|
|
159
|
+
utsComponentAutoImports[source].push([className]);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return utsComponentAutoImports;
|
|
164
|
+
}
|
|
165
|
+
exports.getUTSComponentAutoImports = getUTSComponentAutoImports;
|
|
132
166
|
function parseUTSComponent(name, type) {
|
|
133
167
|
const meta = utsComponents.get(name);
|
|
134
168
|
if (meta) {
|
|
@@ -168,9 +202,12 @@ function initUTSComponents(inputDir, platform) {
|
|
|
168
202
|
}
|
|
169
203
|
}
|
|
170
204
|
if (name) {
|
|
171
|
-
const
|
|
205
|
+
const source = '@/' +
|
|
206
|
+
(0, utils_1.normalizePath)(isApp
|
|
207
|
+
? path_1.default.relative(inputDir, is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir)
|
|
208
|
+
: path_1.default.relative(inputDir, file));
|
|
172
209
|
easycomsObj[`^${name}$`] = {
|
|
173
|
-
source: isApp ? `${
|
|
210
|
+
source: isApp ? `${source}?uts-proxy` : source,
|
|
174
211
|
kotlinPackage: parseKotlinPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
175
212
|
swiftModule: parseSwiftPackageWithPluginId(pluginId, is_uni_modules_utssdk),
|
|
176
213
|
};
|
|
@@ -212,7 +249,7 @@ function resolveUTSComponentDirs(inputDir) {
|
|
|
212
249
|
}
|
|
213
250
|
const nameRE = /name\s*:\s*['|"](.*)['|"]/;
|
|
214
251
|
function parseVueComponentName(file) {
|
|
215
|
-
const content =
|
|
252
|
+
const content = fs_extra_1.default.readFileSync(file, 'utf8');
|
|
216
253
|
const matches = content.match(nameRE);
|
|
217
254
|
if (matches) {
|
|
218
255
|
return matches[1];
|
|
@@ -235,6 +272,54 @@ function parseSwiftPackageWithPluginId(id, is_uni_modules) {
|
|
|
235
272
|
(0, utils_1.capitalize)((0, utils_1.camelize)(prefix(id))));
|
|
236
273
|
}
|
|
237
274
|
exports.parseSwiftPackageWithPluginId = parseSwiftPackageWithPluginId;
|
|
275
|
+
async function parseUniExtApiAutoImports(uniExtApiAutoImports, extApis, parseSource) {
|
|
276
|
+
if (Object.keys(extApis).length) {
|
|
277
|
+
const { parseExportIdentifiers } = resolveUTSCompiler();
|
|
278
|
+
for (const name in extApis) {
|
|
279
|
+
const options = extApis[name];
|
|
280
|
+
if ((0, utils_1.isArray)(options) && options.length >= 2) {
|
|
281
|
+
const pluginId = path_1.default.basename(options[0]);
|
|
282
|
+
const source = parseSource(pluginId);
|
|
283
|
+
if (uniExtApiAutoImports[source]) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
uniExtApiAutoImports[source] = [];
|
|
287
|
+
const filename = `uni_modules/${pluginId}/utssdk/interface.uts`;
|
|
288
|
+
const interfaceFileName = path_1.default.resolve(process.env.UNI_INPUT_DIR, filename);
|
|
289
|
+
if (fs_extra_1.default.existsSync(interfaceFileName)) {
|
|
290
|
+
const ids = await parseExportIdentifiers(interfaceFileName);
|
|
291
|
+
ids
|
|
292
|
+
// 过滤掉 Uni
|
|
293
|
+
.filter((id) => id !== 'Uni')
|
|
294
|
+
.forEach((id) => {
|
|
295
|
+
uniExtApiAutoImports[source].push([id]);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return uniExtApiAutoImports;
|
|
302
|
+
}
|
|
303
|
+
let uniExtApiKotlinAutoImports = null;
|
|
304
|
+
async function parseUniExtApiKotlinAutoImportsOnce(extApis) {
|
|
305
|
+
if (uniExtApiKotlinAutoImports) {
|
|
306
|
+
return uniExtApiKotlinAutoImports;
|
|
307
|
+
}
|
|
308
|
+
uniExtApiKotlinAutoImports = {};
|
|
309
|
+
return parseUniExtApiAutoImports(uniExtApiKotlinAutoImports, extApis, (pluginId) => {
|
|
310
|
+
return parseKotlinPackageWithPluginId(pluginId, true);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
let uniExtApiSwiftAutoImports = null;
|
|
314
|
+
async function parseUniExtApiSwiftAutoImportsOnce(extApis) {
|
|
315
|
+
if (uniExtApiSwiftAutoImports) {
|
|
316
|
+
return uniExtApiSwiftAutoImports;
|
|
317
|
+
}
|
|
318
|
+
uniExtApiSwiftAutoImports = {};
|
|
319
|
+
return parseUniExtApiAutoImports(uniExtApiSwiftAutoImports, extApis, (pluginId) => {
|
|
320
|
+
return parseSwiftPackageWithPluginId(pluginId, true);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
238
323
|
exports.parseUniExtApiNamespacesOnce = once((platform, language) => {
|
|
239
324
|
const extApis = (0, exports.parseUniExtApiNamespacesJsOnce)(platform, language);
|
|
240
325
|
const namespaces = {};
|
|
@@ -263,3 +348,89 @@ exports.parseUniExtApiNamespacesJsOnce = once((platform, language) => {
|
|
|
263
348
|
});
|
|
264
349
|
return namespaces;
|
|
265
350
|
});
|
|
351
|
+
function resolveUniTypeScript() {
|
|
352
|
+
if ((0, hbx_1.isInHBuilderX)()) {
|
|
353
|
+
return require(path_1.default.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'uniapp-uts-v1', 'node_modules', '@dcloudio', 'uni-uts-v1', 'lib', 'typescript'));
|
|
354
|
+
}
|
|
355
|
+
return require('@dcloudio/uni-uts-v1/lib/typescript');
|
|
356
|
+
}
|
|
357
|
+
exports.resolveUniTypeScript = resolveUniTypeScript;
|
|
358
|
+
async function initUTSAutoImports(autoImports, platform, language) {
|
|
359
|
+
const utsComponents = getUTSComponentAutoImports(language);
|
|
360
|
+
Object.keys(utsComponents).forEach((source) => {
|
|
361
|
+
if (autoImports[source]) {
|
|
362
|
+
autoImports[source].push(...utsComponents[source]);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
autoImports[source] = utsComponents[source];
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
const extApis = (0, uni_modules_1.parseUniExtApis)(true, platform, language);
|
|
369
|
+
const extApiImports = await (language === 'kotlin'
|
|
370
|
+
? parseUniExtApiKotlinAutoImportsOnce
|
|
371
|
+
: parseUniExtApiSwiftAutoImportsOnce)(extApis);
|
|
372
|
+
Object.keys(extApiImports).forEach((source) => {
|
|
373
|
+
if (autoImports[source]) {
|
|
374
|
+
autoImports[source].push(...extApiImports[source]);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
autoImports[source] = extApiImports[source];
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
return autoImports;
|
|
381
|
+
}
|
|
382
|
+
let autoKotlinImports = null;
|
|
383
|
+
async function initUTSKotlinAutoImportsOnce() {
|
|
384
|
+
if (autoKotlinImports) {
|
|
385
|
+
return autoKotlinImports;
|
|
386
|
+
}
|
|
387
|
+
autoKotlinImports = {};
|
|
388
|
+
return initUTSAutoImports(autoKotlinImports, 'app-android', 'kotlin');
|
|
389
|
+
}
|
|
390
|
+
exports.initUTSKotlinAutoImportsOnce = initUTSKotlinAutoImportsOnce;
|
|
391
|
+
let autoSwiftImports = null;
|
|
392
|
+
async function initUTSSwiftAutoImportsOnce() {
|
|
393
|
+
if (autoSwiftImports) {
|
|
394
|
+
return autoSwiftImports;
|
|
395
|
+
}
|
|
396
|
+
autoSwiftImports = {};
|
|
397
|
+
return initUTSAutoImports(autoSwiftImports, 'app-ios', 'swift');
|
|
398
|
+
}
|
|
399
|
+
exports.initUTSSwiftAutoImportsOnce = initUTSSwiftAutoImportsOnce;
|
|
400
|
+
exports.genUniExtApiDeclarationFileOnce = once((tscInputDir) => {
|
|
401
|
+
const extApis = (0, uni_modules_1.parseUniExtApis)(true, 'app-android', 'kotlin');
|
|
402
|
+
// 之所以往上一级写,是因为 tscInputDir 会被 empty,目前时机有问题,比如先生成了d.ts,又被empty
|
|
403
|
+
const fileName = path_1.default.resolve(tscInputDir, '../uni-ext-api.d.ts');
|
|
404
|
+
if (fs_extra_1.default.existsSync(fileName)) {
|
|
405
|
+
try {
|
|
406
|
+
// 先删除
|
|
407
|
+
fs_extra_1.default.unlinkSync(fileName);
|
|
408
|
+
}
|
|
409
|
+
catch (e) { }
|
|
410
|
+
}
|
|
411
|
+
if (Object.keys(extApis).length) {
|
|
412
|
+
const apis = [];
|
|
413
|
+
for (const name in extApis) {
|
|
414
|
+
const options = extApis[name];
|
|
415
|
+
if ((0, utils_1.isArray)(options) && options.length >= 2) {
|
|
416
|
+
const api = name.replace('uni.', '');
|
|
417
|
+
apis.push(' ' + api + `: typeof import("${options[0]}")["${options[1]}"]`);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (apis.length) {
|
|
421
|
+
fs_extra_1.default.outputFileSync(fileName, `
|
|
422
|
+
interface Uni {
|
|
423
|
+
${apis.join('\n')}
|
|
424
|
+
}
|
|
425
|
+
`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
function uvueOutDir(platform) {
|
|
430
|
+
return path_1.default.join(process.env.UNI_APP_X_UVUE_DIR, platform);
|
|
431
|
+
}
|
|
432
|
+
exports.uvueOutDir = uvueOutDir;
|
|
433
|
+
function tscOutDir(platform) {
|
|
434
|
+
return path_1.default.join(process.env.UNI_APP_X_TSC_DIR, platform);
|
|
435
|
+
}
|
|
436
|
+
exports.tscOutDir = tscOutDir;
|
package/license.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[https://
|
|
1
|
+
[https://dcloud.io/license/uni-app.html](https://dcloud.io/license/uni-app.html)
|
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-4030620241128001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,10 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"escape-string-regexp": "^4.0.0",
|
|
23
23
|
"fast-glob": "^3.2.11",
|
|
24
|
+
"fs-extra": "^10.0.0",
|
|
24
25
|
"glob-escape": "^0.0.2",
|
|
25
26
|
"hash-sum": "^1.0.2",
|
|
26
27
|
"postcss-urlrewrite": "^0.2.2",
|
|
27
28
|
"strip-json-comments": "^2.0.1"
|
|
28
29
|
},
|
|
29
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "260d428e1b77f54051f87b758586e3333ca58619"
|
|
30
31
|
}
|