@dcloudio/uni-cli-shared 2.0.2-3071120230427001 → 2.0.2-3080420230530001

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 CHANGED
@@ -78,8 +78,10 @@ const supportGlobalUsingComponents = process.env.UNI_PLATFORM === 'mp-weixin' ||
78
78
  function updateComponentJson (name, jsonObj, usingComponents = true, type = 'Component') {
79
79
  if (type === 'Component') {
80
80
  jsonObj.component = true
81
- }
82
- if (type === 'Page') {
81
+ if (process.env.UNI_PLATFORM === 'mp-alipay') {
82
+ jsonObj.styleIsolation = 'apply-shared'
83
+ }
84
+ } else if (type === 'Page') {
83
85
  if (process.env.UNI_PLATFORM === 'mp-baidu') {
84
86
  jsonObj.component = true
85
87
  }
@@ -162,6 +164,9 @@ function updateUsingComponents (name, usingComponents, type) {
162
164
  const jsonObj = JSON.parse(oldJsonStr)
163
165
  if (type === 'Component') {
164
166
  jsonObj.component = true
167
+ if (process.env.UNI_PLATFORM === 'mp-alipay') {
168
+ jsonObj.styleIsolation = 'apply-shared'
169
+ }
165
170
  } else if (type === 'Page') {
166
171
  if (process.env.UNI_PLATFORM === 'mp-baidu') {
167
172
  jsonObj.component = true
@@ -179,6 +184,9 @@ function updateUsingComponents (name, usingComponents, type) {
179
184
  }
180
185
  if (type === 'Component') {
181
186
  jsonObj.component = true
187
+ if (process.env.UNI_PLATFORM === 'mp-alipay') {
188
+ jsonObj.styleIsolation = 'apply-shared'
189
+ }
182
190
  } else if (type === 'Page') {
183
191
  if (process.env.UNI_PLATFORM === 'mp-baidu') {
184
192
  jsonObj.component = true
@@ -322,7 +330,7 @@ module.exports = {
322
330
  if (!fs.existsSync(filepath)) {
323
331
  try {
324
332
  clearCache()
325
- } catch (e) {}
333
+ } catch (e) { }
326
334
  return
327
335
  }
328
336
  const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
@@ -331,7 +339,7 @@ module.exports = {
331
339
  if (jsonCache.mtimeMs !== mtimeMs) {
332
340
  try {
333
341
  clearCache()
334
- } catch (e) {}
342
+ } catch (e) { }
335
343
  return
336
344
  }
337
345
  jsonFileMap = new Map(jsonCache.files)
@@ -366,4 +374,4 @@ module.exports = {
366
374
  getChangedJsonFileMap,
367
375
  getSpecialMethods,
368
376
  supportGlobalUsingComponents
369
- }
377
+ }
package/lib/i18n.js CHANGED
@@ -84,7 +84,7 @@ function resolveI18nLocale (platfrom, locales, locale) {
84
84
  return locale
85
85
  }
86
86
  const defaultLocales = ['zh-Hans', 'zh-Hant']
87
- if (platfrom === 'app' || platfrom === 'h5') {
87
+ if (platfrom === 'app-plus' || platfrom === 'h5') {
88
88
  defaultLocales.unshift('en')
89
89
  } else {
90
90
  // 小程序
@@ -96,4 +96,4 @@ function resolveI18nLocale (platfrom, locales, locale) {
96
96
  module.exports = {
97
97
  initLocales,
98
98
  initI18nOptions
99
- }
99
+ }
package/lib/index.js CHANGED
@@ -34,7 +34,8 @@ const {
34
34
  convertStaticStyle,
35
35
  getTemplatePath,
36
36
  createSource,
37
- deleteAsset
37
+ deleteAsset,
38
+ showRunPrompt
38
39
  } = require('./util')
39
40
 
40
41
  const {
@@ -112,6 +113,7 @@ module.exports = {
112
113
  getTemplatePath,
113
114
  createSource,
114
115
  deleteAsset,
116
+ showRunPrompt,
115
117
  jsPreprocessOptions,
116
118
  cssPreprocessOptions,
117
119
  htmlPreprocessOptions,
@@ -12,9 +12,15 @@ function parseUniExtApis(vite = true) {
12
12
  if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
13
  return {};
14
14
  }
15
+ let platform = process.env.UNI_PLATFORM;
16
+ if (platform === 'h5') {
17
+ platform = 'web';
18
+ }
19
+ else if (platform === 'app-plus') {
20
+ platform = 'app';
21
+ }
15
22
  const injects = {};
16
23
  fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
17
- var _a, _b;
18
24
  // 必须以 uni- 开头
19
25
  if (!uniModuleDir.startsWith('uni-')) {
20
26
  return;
@@ -24,13 +30,25 @@ function parseUniExtApis(vite = true) {
24
30
  return;
25
31
  }
26
32
  try {
27
- const exports = (_b = (_a = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b['uni-ext-api'];
33
+ const exports = JSON.parse(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))
34
+ ?.uni_modules?.['uni-ext-api'];
28
35
  if (exports) {
29
- Object.assign(injects, parseInjects(vite, process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports));
36
+ const curInjects = parseInjects(vite, platform, `@/uni_modules/${uniModuleDir}`, exports);
37
+ if (platform === 'app') {
38
+ Object.keys(curInjects).forEach((name) => {
39
+ const options = curInjects[name];
40
+ // js 平台禁用了
41
+ if (Array.isArray(options) && options.length === 3) {
42
+ if (options[2] && options[2].js === false) {
43
+ delete curInjects[name];
44
+ }
45
+ }
46
+ });
47
+ }
48
+ Object.assign(injects, curInjects);
30
49
  }
31
50
  }
32
- catch (e) {
33
- }
51
+ catch (e) { }
34
52
  });
35
53
  return injects;
36
54
  }
@@ -73,12 +91,12 @@ function parseInjects(vite = true, platform, source, exports = {}) {
73
91
  }
74
92
  const injects = {};
75
93
  for (const key in rootDefines) {
76
- Object.assign(injects, parseInject(vite, source, 'uni', rootDefines[key]));
94
+ Object.assign(injects, parseInject(vite, platform, source, 'uni', rootDefines[key]));
77
95
  }
78
96
  return injects;
79
97
  }
80
98
  exports.parseInjects = parseInjects;
81
- function parseInject(vite = true, source, globalObject, define) {
99
+ function parseInject(vite = true, platform, source, globalObject, define) {
82
100
  const injects = {};
83
101
  if (define === false) {
84
102
  }
@@ -95,7 +113,24 @@ function parseInject(vite = true, source, globalObject, define) {
95
113
  else {
96
114
  const keys = Object.keys(define);
97
115
  keys.forEach((d) => {
98
- injects[globalObject + '.' + d] = [source, define[d]];
116
+ if (typeof define[d] === 'string') {
117
+ injects[globalObject + '.' + d] = [source, define[d]];
118
+ }
119
+ else {
120
+ const defineOptions = define[d];
121
+ if (defineOptions[platform] !== false) {
122
+ if (platform === 'app') {
123
+ injects[globalObject + '.' + d] = [
124
+ source,
125
+ defineOptions.name || d,
126
+ defineOptions.app,
127
+ ];
128
+ }
129
+ else {
130
+ injects[globalObject + '.' + d] = [source, defineOptions.name || d];
131
+ }
132
+ }
133
+ }
99
134
  });
100
135
  }
101
136
  return injects;
package/lib/util.js CHANGED
@@ -5,6 +5,7 @@ const crypto = require('crypto')
5
5
  const escapeStringRegexp = require('escape-string-regexp')
6
6
  const escapeGlob = require('glob-escape')
7
7
  const webpack = require('webpack')
8
+ const uniI18n = require('@dcloudio/uni-cli-i18n')
8
9
 
9
10
  const isWin = /^win/.test(process.platform)
10
11
 
@@ -179,6 +180,34 @@ function deleteAsset (compilation, name) {
179
180
  }
180
181
  }
181
182
 
183
+ /**
184
+ * cli 项目增加运行方式提示 https://ask.dcloud.net.cn/question/165071
185
+ * App 端存在多次编译问题(vue 2 nvue 3),故做防抖处理
186
+ * @param delay
187
+ * @returns
188
+ */
189
+ let runPromptTimer = null
190
+ function showRunPrompt (delay = 300) {
191
+ if (runPromptTimer) {
192
+ clearTimeout(runPromptTimer)
193
+ }
194
+ runPromptTimer = setTimeout(() => {
195
+ if (!isInHBuilderX) {
196
+ const chalk = require('chalk')
197
+ const outputDir = path.relative(
198
+ process.env.UNI_CLI_CONTEXT,
199
+ process.env.UNI_OUTPUT_DIR
200
+ )
201
+ const platform = process.env.UNI_PLATFORM.startsWith('quickapp-webview') && process.env.UNI_SUB_PLATFORM ? process.env.UNI_SUB_PLATFORM : process.env.UNI_PLATFORM
202
+ console.log(uniI18n.__('prompt.run.message', {
203
+ devtools: uniI18n.__(`prompt.run.devtools.${platform}`),
204
+ outputDir: chalk.cyan(outputDir)
205
+ }))
206
+ }
207
+ runPromptTimer = null
208
+ }, delay)
209
+ }
210
+
182
211
  module.exports = {
183
212
  isNormalPage,
184
213
  isInHBuilderX,
@@ -220,5 +249,6 @@ module.exports = {
220
249
  return path.join(__dirname, '../template')
221
250
  },
222
251
  createSource,
223
- deleteAsset
252
+ deleteAsset,
253
+ showRunPrompt
224
254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-3071120230427001",
3
+ "version": "2.0.2-3080420230530001",
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": "9eec36832c08c90ba3c80bc9021768487b79a8ea"
29
+ "gitHead": "a7f9b00100b54f72f05ad00205f98a5353bd7a4c"
30
30
  }