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

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.
@@ -17,7 +17,7 @@ export declare function isMiniProgramUsingComponent(name: string, options: {
17
17
  componentsDir?: string;
18
18
  }): boolean;
19
19
  interface MiniProgramComponents {
20
- [name: string]: 'plugin' | 'component';
20
+ [name: string]: 'plugin' | 'component' | 'dynamicLib';
21
21
  }
22
22
  export declare function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, }: {
23
23
  filename: string;
@@ -124,8 +124,14 @@ function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, })
124
124
  (0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(globalUsingComponents, componentsDir));
125
125
  }
126
126
  const jsonFile = findJsonFile((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(filename, inputDir)));
127
- if (jsonFile === null || jsonFile === void 0 ? void 0 : jsonFile.usingComponents) {
128
- (0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingComponents, componentsDir));
127
+ if (jsonFile) {
128
+ if (jsonFile.usingComponents) {
129
+ (0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingComponents, componentsDir));
130
+ }
131
+ // mp-baidu 特有
132
+ if (jsonFile.usingSwanComponents) {
133
+ (0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingSwanComponents, componentsDir));
134
+ }
129
135
  }
130
136
  return miniProgramComponents;
131
137
  }
@@ -136,6 +142,9 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
136
142
  if (path.includes('plugin://')) {
137
143
  res[name] = 'plugin';
138
144
  }
145
+ else if (path.includes('dynamicLib://')) {
146
+ res[name] = 'dynamicLib';
147
+ }
139
148
  else if (componentsDir && path.includes(componentsDir + '/')) {
140
149
  res[name] = 'component';
141
150
  }
@@ -21,6 +21,7 @@ export interface PageWindowOptions extends ShareWindowOptions {
21
21
  component?: true;
22
22
  disableScroll?: boolean;
23
23
  usingComponents?: UsingComponents;
24
+ usingSwanComponents?: UsingComponents;
24
25
  initialRenderingCache?: 'static' | string;
25
26
  style?: Style;
26
27
  singlePage?: SinglePage;
@@ -1,4 +1,13 @@
1
- import { EmittedAsset } from 'rollup';
1
+ import type { EmittedAsset } from 'rollup';
2
+ import type { ElementNode } from '@vue/compiler-core';
3
+ declare type LazyElementFn = (node: ElementNode, context: {
4
+ isMiniProgramComponent(name: string): 'plugin' | 'component' | 'dynamicLib' | undefined;
5
+ }) => {
6
+ [name: string]: {
7
+ name: 'on' | 'bind';
8
+ arg: string[];
9
+ }[];
10
+ } | boolean;
2
11
  export interface MiniProgramCompilerOptions {
3
12
  /**
4
13
  * 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
@@ -8,7 +17,7 @@ export interface MiniProgramCompilerOptions {
8
17
  name: 'on' | 'bind';
9
18
  arg: string[];
10
19
  }[];
11
- };
20
+ } | LazyElementFn;
12
21
  event?: {
13
22
  key?: boolean;
14
23
  format?(name: string, opts: {
@@ -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,112 @@
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 merge_1 = require("merge");
10
+ function genUniModulesExports() {
11
+ const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
12
+ if (!fs_extra_1.default.existsSync(uniModulesDir)) {
13
+ return '';
14
+ }
15
+ const importCodes = [];
16
+ const assignCodes = [];
17
+ fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
18
+ var _a, _b;
19
+ const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
20
+ if (!fs_extra_1.default.existsSync(pkgPath)) {
21
+ return;
22
+ }
23
+ 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.exports;
24
+ if (exports) {
25
+ const [exportsImportCodes, exportsAssignCodes] = parseExports(process.env.UNI_PLATFORM === 'h5' ? 'web' : process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports);
26
+ importCodes.push(...exportsImportCodes);
27
+ assignCodes.push(...exportsAssignCodes);
28
+ }
29
+ });
30
+ if (!importCodes.length) {
31
+ return '';
32
+ }
33
+ return `${importCodes.join('\n')}
34
+ ${assignCodes.join('\n')}`;
35
+ }
36
+ exports.genUniModulesExports = genUniModulesExports;
37
+ function parseExports(platform, source, exports = {}) {
38
+ const rootDefines = {};
39
+ Object.keys(exports).forEach((name) => {
40
+ if (name.startsWith('uni')) {
41
+ rootDefines[name] = exports[name];
42
+ }
43
+ });
44
+ const platformDefines = exports[platform];
45
+ // 该平台不支持
46
+ if (platformDefines === false) {
47
+ return [[], []];
48
+ }
49
+ return parseDefines(source, (0, merge_1.recursive)(true, rootDefines, platformDefines));
50
+ }
51
+ exports.parseExports = parseExports;
52
+ function parseDefines(source, defines = {}) {
53
+ const importCodes = [];
54
+ const assignCodes = [];
55
+ Object.keys(defines).forEach((name) => {
56
+ const [defineImportCodes, defineAssignCodes] = parseDefine(source, name, defines[name]);
57
+ importCodes.push(...defineImportCodes);
58
+ assignCodes.push(...defineAssignCodes);
59
+ });
60
+ return [importCodes, assignCodes];
61
+ }
62
+ exports.parseDefines = parseDefines;
63
+ /**
64
+ * uni:'getBatteryInfo'
65
+ * import getBatteryInfo from '..'
66
+ *
67
+ * uni:['getBatteryInfo']
68
+ * import { getBatteryInfo } from '..'
69
+ *
70
+ * uni:['openLocation','chooseLocation']
71
+ * import { openLocation, chooseLocation } from '..'
72
+ *
73
+ * uni:{
74
+ * onUserCaptureScreen: "onCaptureScreen"
75
+ * offUserCaptureScreen: "offCaptureScreen"
76
+ * }
77
+ *
78
+ * uni.getBatteryInfo = getBatteryInfo
79
+ * @param source
80
+ * @param globalObject
81
+ * @param define
82
+ * @returns
83
+ */
84
+ function parseDefine(source, globalObject, define) {
85
+ const importCodes = [];
86
+ const assignCodes = [];
87
+ if (typeof define === 'string') {
88
+ importCodes.push(`import ${define} from '${source}'`);
89
+ assignCodes.push(`${globalObject}.${define} = ${define}`);
90
+ }
91
+ else if (Array.isArray(define)) {
92
+ importCodes.push(`import { ${define.join(', ')} } from '${source}'`);
93
+ define.forEach((d) => {
94
+ assignCodes.push(`${globalObject}.${d} = ${d}`);
95
+ });
96
+ }
97
+ else {
98
+ const keys = Object.keys(define);
99
+ const specifiers = [];
100
+ keys.forEach((d) => {
101
+ if (d !== define[d]) {
102
+ specifiers.push(`${define[d]} as ${d}`);
103
+ }
104
+ else {
105
+ specifiers.push(d);
106
+ }
107
+ assignCodes.push(`${globalObject}.${d} = ${d}`);
108
+ });
109
+ importCodes.push(`import { ${specifiers.join(', ')} } from '${source}'`);
110
+ }
111
+ return [importCodes, assignCodes];
112
+ }
@@ -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
- }
@@ -36,6 +36,7 @@ const crypto_1 = require("crypto");
36
36
  const utils_1 = require("../utils");
37
37
  const utils_2 = require("../../../../vite/utils/utils");
38
38
  const shared_1 = require("@vue/shared");
39
+ const utils_3 = require("../../../../utils");
39
40
  exports.assetUrlRE = /__VITE_ASSET__([a-z\d]{8})__(?:\$_(.*?)__)?/g;
40
41
  // urls in JS must be quoted as strings, so when replacing them we need
41
42
  // a different regex
@@ -248,7 +249,8 @@ function fileToBuiltUrl(id, config, pluginContext, skipPublicCheck = false, canI
248
249
  const postfix = (search || '') + (hash || '');
249
250
  const inputDir = (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR);
250
251
  let fileName = file.startsWith(inputDir)
251
- ? path_1.default.posix.relative(inputDir, file)
252
+ ? // 需要处理 HBuilderX 项目中的 node_modules 目录
253
+ (0, utils_3.normalizeNodeModules)(path_1.default.posix.relative(inputDir, file))
252
254
  : assetFileNamesToFileName(path_1.default.posix.join(config.build.assetsDir, '[name].[hash][extname]'), file, contentHash, content);
253
255
  if (!map.has(contentHash)) {
254
256
  map.set(contentHash, fileName);
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-3060420220922007",
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-3060420220922007",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3060420220922007",
30
30
  "@intlify/core-base": "9.1.9",
31
31
  "@intlify/shared": "9.1.9",
32
32
  "@intlify/vue-devtools": "9.1.9",