@dcloudio/uni-cli-shared 3.0.0-alpha-3060420220922005 → 3.0.0-alpha-3060420220922006

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.
@@ -0,0 +1,11 @@
1
+ declare type Define = string | string[] | Record<string, string>;
2
+ declare type Defines = {
3
+ [name: string]: Define;
4
+ };
5
+ interface Exports {
6
+ [name: string]: Define | Defines | false;
7
+ }
8
+ export declare function genUniModulesExports(): string;
9
+ export declare function parseExports(platform: UniApp.PLATFORM, source: string, exports?: Exports): [string[], string[]];
10
+ export declare function parseDefines(source: string, defines?: Defines): [string[], string[]];
11
+ export {};
@@ -0,0 +1,114 @@
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.parseDefines = exports.parseExports = exports.genUniModulesExports = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const shared_1 = require("@vue/shared");
10
+ const merge_1 = require("merge");
11
+ const json_1 = require("./json");
12
+ function genUniModulesExports() {
13
+ const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
14
+ if (!fs_extra_1.default.existsSync(uniModulesDir)) {
15
+ return '';
16
+ }
17
+ const importCodes = [];
18
+ const assignCodes = [];
19
+ fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
20
+ var _a, _b;
21
+ const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
22
+ if (!fs_extra_1.default.existsSync(pkgPath)) {
23
+ return;
24
+ }
25
+ const exports = (_b = (_a = (0, json_1.parseJson)(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b.exports;
26
+ if (exports) {
27
+ const [exportsImportCodes, exportsAssignCodes] = parseExports(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports);
28
+ importCodes.push(...exportsImportCodes);
29
+ assignCodes.push(...exportsAssignCodes);
30
+ }
31
+ });
32
+ if (!importCodes.length) {
33
+ return '';
34
+ }
35
+ return `${importCodes.join('\n')}
36
+ ${assignCodes.join('\n')}`;
37
+ }
38
+ exports.genUniModulesExports = genUniModulesExports;
39
+ function parseExports(platform, source, exports = {}) {
40
+ const rootDefines = {};
41
+ Object.keys(exports).forEach((name) => {
42
+ if (name.startsWith('uni')) {
43
+ rootDefines[name] = exports[name];
44
+ }
45
+ });
46
+ const platformDefines = exports[platform];
47
+ // 该平台不支持
48
+ if (platformDefines === false) {
49
+ return [[], []];
50
+ }
51
+ return parseDefines(source, (0, merge_1.recursive)(true, rootDefines, platformDefines));
52
+ }
53
+ exports.parseExports = parseExports;
54
+ function parseDefines(source, defines = {}) {
55
+ const importCodes = [];
56
+ const assignCodes = [];
57
+ Object.keys(defines).forEach((name) => {
58
+ const [defineImportCodes, defineAssignCodes] = parseDefine(source, name, defines[name]);
59
+ importCodes.push(...defineImportCodes);
60
+ assignCodes.push(...defineAssignCodes);
61
+ });
62
+ return [importCodes, assignCodes];
63
+ }
64
+ exports.parseDefines = parseDefines;
65
+ /**
66
+ * uni:'getBatteryInfo'
67
+ * import getBatteryInfo from '..'
68
+ *
69
+ * uni:['getBatteryInfo']
70
+ * import { getBatteryInfo } from '..'
71
+ *
72
+ * uni:['openLocation','chooseLocation']
73
+ * import { openLocation, chooseLocation } from '..'
74
+ *
75
+ * uni:{
76
+ * onUserCaptureScreen: "onCaptureScreen"
77
+ * offUserCaptureScreen: "offCaptureScreen"
78
+ * }
79
+ *
80
+ * uni.getBatteryInfo = getBatteryInfo
81
+ * @param source
82
+ * @param globalObject
83
+ * @param define
84
+ * @returns
85
+ */
86
+ function parseDefine(source, globalObject, define) {
87
+ const importCodes = [];
88
+ const assignCodes = [];
89
+ if ((0, shared_1.isString)(define)) {
90
+ importCodes.push(`import ${define} from '${source}'`);
91
+ assignCodes.push(`${globalObject}.${define} = ${define}`);
92
+ }
93
+ else if ((0, shared_1.isArray)(define)) {
94
+ importCodes.push(`import { ${define.join(', ')} } from '${source}'`);
95
+ define.forEach((d) => {
96
+ assignCodes.push(`${globalObject}.${d} = ${d}`);
97
+ });
98
+ }
99
+ else if ((0, shared_1.isPlainObject)(define)) {
100
+ const keys = Object.keys(define);
101
+ const specifiers = [];
102
+ keys.forEach((d) => {
103
+ if (d !== define[d]) {
104
+ specifiers.push(`${define[d]} as ${d}`);
105
+ }
106
+ else {
107
+ specifiers.push(d);
108
+ }
109
+ assignCodes.push(`${globalObject}.${d} = ${d}`);
110
+ });
111
+ importCodes.push(`import { ${specifiers.join(', ')} } from '${source}'`);
112
+ }
113
+ return [importCodes, assignCodes];
114
+ }
@@ -2,13 +2,3 @@ import type { Plugin } from 'vite';
2
2
  export declare function uniModulesExportsPlugin({ enable, }: {
3
3
  enable: boolean;
4
4
  }): Plugin;
5
- declare type Define = string | string[] | Record<string, string>;
6
- declare type Defines = {
7
- [name: string]: Define;
8
- };
9
- interface Exports {
10
- [name: string]: Define | Defines | false;
11
- }
12
- export declare function parseExports(platform: UniApp.PLATFORM, source: string, exports?: Exports): [string[], string[]];
13
- export declare function parseDefines(source: string, defines?: Defines): [string[], string[]];
14
- export {};
@@ -1,15 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseDefines = exports.parseExports = exports.uniModulesExportsPlugin = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_extra_1 = __importDefault(require("fs-extra"));
9
- const merge_1 = require("merge");
10
- const shared_1 = require("@vue/shared");
3
+ exports.uniModulesExportsPlugin = void 0;
11
4
  const constants_1 = require("../../constants");
12
- const json_1 = require("../../json");
5
+ const uni_modules_1 = require("../../uni_modules");
13
6
  function uniModulesExportsPlugin({ enable, }) {
14
7
  return {
15
8
  name: 'uni:modules:exports',
@@ -26,110 +19,8 @@ function uniModulesExportsPlugin({ enable, }) {
26
19
  if (!enable) {
27
20
  return '';
28
21
  }
29
- return genUniModulesExports();
22
+ return (0, uni_modules_1.genUniModulesExports)();
30
23
  },
31
24
  };
32
25
  }
33
26
  exports.uniModulesExportsPlugin = uniModulesExportsPlugin;
34
- function genUniModulesExports() {
35
- const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
36
- if (!fs_extra_1.default.existsSync(uniModulesDir)) {
37
- return '';
38
- }
39
- const importCodes = [];
40
- const assignCodes = [];
41
- fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
42
- var _a, _b;
43
- const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
44
- if (!fs_extra_1.default.existsSync(pkgPath)) {
45
- return;
46
- }
47
- const exports = (_b = (_a = (0, json_1.parseJson)(fs_extra_1.default.readFileSync(pkgPath, 'utf8'))) === null || _a === void 0 ? void 0 : _a.uni_modules) === null || _b === void 0 ? void 0 : _b.exports;
48
- if (exports) {
49
- const [exportsImportCodes, exportsAssignCodes] = parseExports(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports);
50
- importCodes.push(...exportsImportCodes);
51
- assignCodes.push(...exportsAssignCodes);
52
- }
53
- });
54
- if (!importCodes.length) {
55
- return '';
56
- }
57
- return `${importCodes.join('\n')}
58
- ${assignCodes.join('\n')}`;
59
- }
60
- function parseExports(platform, source, exports = {}) {
61
- const rootDefines = {};
62
- Object.keys(exports).forEach((name) => {
63
- if (name.startsWith('uni')) {
64
- rootDefines[name] = exports[name];
65
- }
66
- });
67
- const platformDefines = exports[platform];
68
- // 该平台不支持
69
- if (platformDefines === false) {
70
- return [[], []];
71
- }
72
- return parseDefines(source, (0, merge_1.recursive)(true, rootDefines, platformDefines));
73
- }
74
- exports.parseExports = parseExports;
75
- function parseDefines(source, defines = {}) {
76
- const importCodes = [];
77
- const assignCodes = [];
78
- Object.keys(defines).forEach((name) => {
79
- const [defineImportCodes, defineAssignCodes] = parseDefine(source, name, defines[name]);
80
- importCodes.push(...defineImportCodes);
81
- assignCodes.push(...defineAssignCodes);
82
- });
83
- return [importCodes, assignCodes];
84
- }
85
- exports.parseDefines = parseDefines;
86
- /**
87
- * uni:'getBatteryInfo'
88
- * import getBatteryInfo from '..'
89
- *
90
- * uni:['getBatteryInfo']
91
- * import { getBatteryInfo } from '..'
92
- *
93
- * uni:['openLocation','chooseLocation']
94
- * import { openLocation, chooseLocation } from '..'
95
- *
96
- * uni:{
97
- * onUserCaptureScreen: "onCaptureScreen"
98
- * offUserCaptureScreen: "offCaptureScreen"
99
- * }
100
- *
101
- * uni.getBatteryInfo = getBatteryInfo
102
- * @param source
103
- * @param globalObject
104
- * @param define
105
- * @returns
106
- */
107
- function parseDefine(source, globalObject, define) {
108
- const importCodes = [];
109
- const assignCodes = [];
110
- if ((0, shared_1.isString)(define)) {
111
- importCodes.push(`import ${define} from '${source}'`);
112
- assignCodes.push(`${globalObject}.${define} = ${define}`);
113
- }
114
- else if ((0, shared_1.isArray)(define)) {
115
- importCodes.push(`import { ${define.join(', ')} } from '${source}'`);
116
- define.forEach((d) => {
117
- assignCodes.push(`${globalObject}.${d} = ${d}`);
118
- });
119
- }
120
- else if ((0, shared_1.isPlainObject)(define)) {
121
- const keys = Object.keys(define);
122
- const specifiers = [];
123
- keys.forEach((d) => {
124
- if (d !== define[d]) {
125
- specifiers.push(`${define[d]} as ${d}`);
126
- }
127
- else {
128
- specifiers.push(d);
129
- }
130
- assignCodes.push(`${globalObject}.${d} = ${d}`);
131
- });
132
- importCodes.push(`import { ${specifiers.join(', ')} } from '${source}'`);
133
- }
134
- return [importCodes, assignCodes];
135
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3060420220922005",
3
+ "version": "3.0.0-alpha-3060420220922006",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "@babel/core": "^7.18.13",
26
26
  "@babel/parser": "^7.18.13",
27
27
  "@babel/types": "^7.17.0",
28
- "@dcloudio/uni-i18n": "3.0.0-alpha-3060420220922005",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-3060420220922005",
28
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3060420220922006",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3060420220922006",
30
30
  "@intlify/core-base": "9.1.9",
31
31
  "@intlify/shared": "9.1.9",
32
32
  "@intlify/vue-devtools": "9.1.9",