@dcloudio/uni-cli-shared 2.0.2-alpha-3061420221216003 → 2.0.2-alpha-3061520221222001

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/index.js CHANGED
@@ -32,7 +32,9 @@ const {
32
32
  normalizePath,
33
33
  getComponentName,
34
34
  convertStaticStyle,
35
- getTemplatePath
35
+ getTemplatePath,
36
+ createSource,
37
+ deleteAsset
36
38
  } = require('./util')
37
39
 
38
40
  const {
@@ -108,6 +110,8 @@ module.exports = {
108
110
  getComponentName,
109
111
  convertStaticStyle,
110
112
  getTemplatePath,
113
+ createSource,
114
+ deleteAsset,
111
115
  jsPreprocessOptions,
112
116
  cssPreprocessOptions,
113
117
  htmlPreprocessOptions,
package/lib/pages.js CHANGED
@@ -425,6 +425,16 @@ function initAutoComponents () {
425
425
 
426
426
  function initAutoImportScanComponents () {
427
427
  const components = initAutoComponents()
428
+
429
+ const {
430
+ initUTSComponents
431
+ } = require('./uts/uts.js')
432
+
433
+ initUTSComponents(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM).forEach((item) => {
434
+ components[item.pattern.source] = item.replacement.replace('\0', '').replace('?uts-proxy',
435
+ '/package.json?uts-proxy')
436
+ })
437
+
428
438
  if (process.env.UNI_PLATFORM === 'quickapp-native') {
429
439
  if (!uniQuickAppAutoImportScanComponents) {
430
440
  uniQuickAppAutoImportScanComponents = getAutoComponentsByDir(
@@ -463,8 +473,7 @@ function initAutoImportComponents (easycom = {}) {
463
473
  }
464
474
  initBuiltInEasycom(BUILT_IN_EASYCOMS, usingAutoImportComponents)
465
475
  // 目前仅 mp-weixin 内置支持 page-meta 等组件
466
- if (process.env.UNI_PLATFORM === 'mp-weixin') {
467
- } else if (process.env.UNI_PLATFORM === 'mp-alipay') {
476
+ if (process.env.UNI_PLATFORM === 'mp-weixin') {} else if (process.env.UNI_PLATFORM === 'mp-alipay') {
468
477
  initBuiltInEasycom(BUILT_IN_COMPONENTS_ALIPAY, usingAutoImportComponents)
469
478
  } else {
470
479
  initBuiltInEasycom(BUILT_IN_COMPONENTS, usingAutoImportComponents)
package/lib/util.js CHANGED
@@ -4,6 +4,7 @@ const hash = require('hash-sum')
4
4
  const crypto = require('crypto')
5
5
  const escapeStringRegexp = require('escape-string-regexp')
6
6
  const escapeGlob = require('glob-escape')
7
+ const webpack = require('webpack')
7
8
 
8
9
  const isWin = /^win/.test(process.platform)
9
10
 
@@ -159,6 +160,25 @@ function isNormalPage (pagePath) {
159
160
  return !pagePath.startsWith('ext://')
160
161
  }
161
162
 
163
+ function createSource (content) {
164
+ return webpack.version[0] > 4 ? new webpack.sources.RawSource(content) : {
165
+ size () {
166
+ return Buffer.byteLength(content, 'utf8')
167
+ },
168
+ source () {
169
+ return content
170
+ }
171
+ }
172
+ }
173
+
174
+ function deleteAsset (compilation, name) {
175
+ if ('deleteAsset' in compilation) {
176
+ compilation.deleteAsset(name)
177
+ } else {
178
+ delete compilation.assets[name]
179
+ }
180
+ }
181
+
162
182
  module.exports = {
163
183
  isNormalPage,
164
184
  isInHBuilderX,
@@ -198,5 +218,7 @@ module.exports = {
198
218
  }),
199
219
  getTemplatePath () {
200
220
  return path.join(__dirname, '../template')
201
- }
221
+ },
222
+ createSource,
223
+ deleteAsset
202
224
  }
package/lib/uts/uts.js CHANGED
@@ -3,9 +3,10 @@ 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.resolveUTSCompiler = exports.resolveUtsModule = exports.resolveUtsAppModule = void 0;
6
+ exports.initUTSComponents = exports.resolveUTSCompiler = exports.resolveUtsModule = exports.resolveUtsAppModule = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
+ const fast_glob_1 = __importDefault(require("fast-glob"));
9
10
  const hbx_1 = require("./hbx");
10
11
  const utils_1 = require("./utils");
11
12
  /**
@@ -99,3 +100,65 @@ function resolveUTSCompiler() {
99
100
  return require(compilerPath);
100
101
  }
101
102
  exports.resolveUTSCompiler = resolveUTSCompiler;
103
+ function initUTSComponents(inputDir, platform) {
104
+ const components = [];
105
+ if (platform !== 'app' && platform !== 'app-plus') {
106
+ return components;
107
+ }
108
+ const easycomsObj = Object.create(null);
109
+ const dirs = resolveUTSComponentDirs(inputDir);
110
+ dirs.forEach((dir) => {
111
+ const is_uni_modules_utssdk = dir.endsWith('utssdk');
112
+ const is_ussdk = !is_uni_modules_utssdk && path_1.default.dirname(dir).endsWith('utssdk');
113
+ if (is_uni_modules_utssdk || is_ussdk) {
114
+ fast_glob_1.default
115
+ .sync('**/*.vue', {
116
+ cwd: dir,
117
+ absolute: true,
118
+ })
119
+ .forEach((file) => {
120
+ let name = parseVueComponentName(file);
121
+ if (!name) {
122
+ if (file.endsWith('index.vue')) {
123
+ name = path_1.default.basename(is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir);
124
+ }
125
+ }
126
+ if (name) {
127
+ const importDir = (0, utils_1.normalizePath)(is_uni_modules_utssdk ? path_1.default.dirname(dir) : dir);
128
+ easycomsObj[`^${name}$`] = `\0${importDir}?uts-proxy`;
129
+ }
130
+ });
131
+ }
132
+ });
133
+ Object.keys(easycomsObj).forEach((name) => {
134
+ components.push({
135
+ pattern: new RegExp(name),
136
+ replacement: easycomsObj[name],
137
+ });
138
+ });
139
+ return components;
140
+ }
141
+ exports.initUTSComponents = initUTSComponents;
142
+ function resolveUTSComponentDirs(inputDir) {
143
+ const utssdkDir = path_1.default.resolve(inputDir, 'utssdk');
144
+ const uniModulesDir = path_1.default.resolve(inputDir, 'uni_modules');
145
+ return fast_glob_1.default
146
+ .sync('*', {
147
+ cwd: utssdkDir,
148
+ absolute: true,
149
+ onlyDirectories: true,
150
+ })
151
+ .concat(fast_glob_1.default.sync('*/utssdk', {
152
+ cwd: uniModulesDir,
153
+ absolute: true,
154
+ onlyDirectories: true,
155
+ }));
156
+ }
157
+ const nameRE = /name\s*:\s*['|"](.*)['|"]/;
158
+ function parseVueComponentName(file) {
159
+ const content = fs_1.default.readFileSync(file, 'utf8');
160
+ const matches = content.match(nameRE);
161
+ if (matches) {
162
+ return matches[1];
163
+ }
164
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "2.0.2-alpha-3061420221216003",
3
+ "version": "2.0.2-alpha-3061520221222001",
4
4
  "description": "uni-cli-shared",
5
5
  "main": "lib/index.js",
6
6
  "repository": {
@@ -20,10 +20,11 @@
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
22
  "escape-string-regexp": "^4.0.0",
23
+ "fast-glob": "^3.2.11",
23
24
  "glob-escape": "^0.0.2",
24
25
  "hash-sum": "^1.0.2",
25
26
  "postcss-urlrewrite": "^0.2.2",
26
27
  "strip-json-comments": "^2.0.1"
27
28
  },
28
- "gitHead": "d5a8bd175373e9e5daef8846ae15c439a16b5c38"
29
+ "gitHead": "dcc8aea3aeeef17980166d128ca3788a758670e1"
29
30
  }