@dcloudio/uni-cli-shared 3.0.0-alpha-3060320220919006 → 3.0.0-alpha-3060420220922002
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/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/vite/plugins/index.d.ts +1 -0
- package/dist/vite/plugins/index.js +3 -1
- package/dist/vite/plugins/inject.js +8 -4
- package/dist/vite/plugins/uniModules.d.ts +14 -0
- package/dist/vite/plugins/uniModules.js +134 -0
- package/dist/vite/utils/url.js +4 -0
- package/package.json +9 -9
package/dist/constants.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare const EXTNAME_VUE_RE: RegExp;
|
|
|
7
7
|
export declare const EXTNAME_JS_RE: RegExp;
|
|
8
8
|
export declare const EXTNAME_TS_RE: RegExp;
|
|
9
9
|
export declare const extensions: string[];
|
|
10
|
+
export declare const UNI_MODULES_EXPORTS = "\0uni-modules-exports";
|
|
10
11
|
export declare const PAGES_JSON_JS = "pages-json-js";
|
|
11
12
|
export declare const MANIFEST_JSON_JS = "manifest-json-js";
|
|
12
13
|
export declare const JSON_JS_MAP: {
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_ASSETS_RE = exports.KNOWN_ASSET_TYPES = exports.COMMON_EXCLUDE = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.BINDING_COMPONENTS = exports.APP_CONFIG_SERVICE = exports.APP_CONFIG = exports.APP_SERVICE_FILENAME = exports.ASSETS_INLINE_LIMIT = exports.JSON_JS_MAP = exports.MANIFEST_JSON_JS = exports.PAGES_JSON_JS = exports.extensions = exports.EXTNAME_TS_RE = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE_TEMPLATE = exports.EXTNAME_VUE = exports.EXTNAME_TS = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
|
|
3
|
+
exports.DEFAULT_ASSETS_RE = exports.KNOWN_ASSET_TYPES = exports.COMMON_EXCLUDE = exports.BASE_COMPONENTS_STYLE_PATH = exports.H5_COMPONENTS_STYLE_PATH = exports.H5_FRAMEWORK_STYLE_PATH = exports.H5_API_STYLE_PATH = exports.PAGE_EXTNAME = exports.PAGE_EXTNAME_APP = exports.BINDING_COMPONENTS = exports.APP_CONFIG_SERVICE = exports.APP_CONFIG = exports.APP_SERVICE_FILENAME = exports.ASSETS_INLINE_LIMIT = exports.JSON_JS_MAP = exports.MANIFEST_JSON_JS = exports.PAGES_JSON_JS = exports.UNI_MODULES_EXPORTS = exports.extensions = exports.EXTNAME_TS_RE = exports.EXTNAME_JS_RE = exports.EXTNAME_VUE_RE = exports.EXTNAME_VUE_TEMPLATE = exports.EXTNAME_VUE = exports.EXTNAME_TS = exports.EXTNAME_JS = exports.PUBLIC_DIR = void 0;
|
|
4
4
|
exports.PUBLIC_DIR = 'static';
|
|
5
5
|
exports.EXTNAME_JS = ['.js', '.ts', '.jsx', '.tsx'];
|
|
6
6
|
exports.EXTNAME_TS = ['.ts', '.tsx'];
|
|
@@ -18,6 +18,7 @@ exports.extensions = [
|
|
|
18
18
|
'.tsx',
|
|
19
19
|
'.json',
|
|
20
20
|
].concat(exports.EXTNAME_VUE);
|
|
21
|
+
exports.UNI_MODULES_EXPORTS = '\0uni-modules-exports';
|
|
21
22
|
exports.PAGES_JSON_JS = 'pages-json-js';
|
|
22
23
|
exports.MANIFEST_JSON_JS = 'manifest-json-js';
|
|
23
24
|
exports.JSON_JS_MAP = {
|
|
@@ -5,6 +5,7 @@ export * from './mainJs';
|
|
|
5
5
|
export * from './jsonJs';
|
|
6
6
|
export * from './console';
|
|
7
7
|
export * from './dynamicImportPolyfill';
|
|
8
|
+
export { uniModulesExportsPlugin } from './uniModules';
|
|
8
9
|
export { assetPlugin, getAssetHash } from './vitejs/plugins/asset';
|
|
9
10
|
export { isCSSRequest, cssPlugin, cssPostPlugin, minifyCSS, cssLangRE, commonjsProxyRE, } from './vitejs/plugins/css';
|
|
10
11
|
export { generateCodeFrame } from './vitejs/utils';
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.generateCodeFrame = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.assetPlugin = void 0;
|
|
17
|
+
exports.generateCodeFrame = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.assetPlugin = exports.uniModulesExportsPlugin = void 0;
|
|
18
18
|
__exportStar(require("./cssScoped"), exports);
|
|
19
19
|
__exportStar(require("./copy"), exports);
|
|
20
20
|
__exportStar(require("./inject"), exports);
|
|
@@ -22,6 +22,8 @@ __exportStar(require("./mainJs"), exports);
|
|
|
22
22
|
__exportStar(require("./jsonJs"), exports);
|
|
23
23
|
__exportStar(require("./console"), exports);
|
|
24
24
|
__exportStar(require("./dynamicImportPolyfill"), exports);
|
|
25
|
+
var uniModules_1 = require("./uniModules");
|
|
26
|
+
Object.defineProperty(exports, "uniModulesExportsPlugin", { enumerable: true, get: function () { return uniModules_1.uniModulesExportsPlugin; } });
|
|
25
27
|
var asset_1 = require("./vitejs/plugins/asset");
|
|
26
28
|
Object.defineProperty(exports, "assetPlugin", { enumerable: true, get: function () { return asset_1.assetPlugin; } });
|
|
27
29
|
Object.defineProperty(exports, "getAssetHash", { enumerable: true, get: function () { return asset_1.getAssetHash; } });
|
|
@@ -11,6 +11,7 @@ const estree_walker_1 = require("estree-walker");
|
|
|
11
11
|
const shared_1 = require("@vue/shared");
|
|
12
12
|
const magic_string_1 = __importDefault(require("magic-string"));
|
|
13
13
|
const utils_1 = require("../utils");
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
14
15
|
const debugInject = (0, debug_1.default)('uni:inject');
|
|
15
16
|
const debugInjectTry = (0, debug_1.default)('uni:inject-try');
|
|
16
17
|
function uniViteInjectPlugin(name, options) {
|
|
@@ -45,10 +46,13 @@ function uniViteInjectPlugin(name, options) {
|
|
|
45
46
|
// 确保在 commonjs 之后,否则会混合 es6 module 与 cjs 的代码,导致 commonjs 失效
|
|
46
47
|
enforce: 'post',
|
|
47
48
|
transform(code, id) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
// 硬编码支持了uni_modules_exports
|
|
50
|
+
if (id !== constants_1.UNI_MODULES_EXPORTS) {
|
|
51
|
+
if (!filter(id))
|
|
52
|
+
return null;
|
|
53
|
+
if (!(0, utils_1.isJsFile)(id))
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
52
56
|
debugInjectTry(id);
|
|
53
57
|
if (code.search(firstpass) === -1)
|
|
54
58
|
return null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
export declare function uniModulesExportsPlugin({ enable, }: {
|
|
3
|
+
enable: boolean;
|
|
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 {};
|
|
@@ -0,0 +1,134 @@
|
|
|
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.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");
|
|
11
|
+
const constants_1 = require("../../constants");
|
|
12
|
+
const json_1 = require("../../json");
|
|
13
|
+
function uniModulesExportsPlugin({ enable, }) {
|
|
14
|
+
return {
|
|
15
|
+
name: 'uni:modules:exports',
|
|
16
|
+
resolveId(id) {
|
|
17
|
+
if (id === constants_1.UNI_MODULES_EXPORTS) {
|
|
18
|
+
return constants_1.UNI_MODULES_EXPORTS;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
load(id) {
|
|
22
|
+
if (id !== constants_1.UNI_MODULES_EXPORTS) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// 未启用
|
|
26
|
+
if (!enable) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
const uniModulesDir = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'uni_modules');
|
|
30
|
+
if (!fs_extra_1.default.existsSync(uniModulesDir)) {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
const importCodes = [];
|
|
34
|
+
const assignCodes = [];
|
|
35
|
+
fs_extra_1.default.readdirSync(uniModulesDir).forEach((uniModuleDir) => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
const pkgPath = path_1.default.resolve(uniModulesDir, uniModuleDir, 'package.json');
|
|
38
|
+
if (!fs_extra_1.default.existsSync(pkgPath)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
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;
|
|
42
|
+
if (exports) {
|
|
43
|
+
const [exportsImportCodes, exportsAssignCodes] = parseExports(process.env.UNI_PLATFORM === 'h5'
|
|
44
|
+
? 'web'
|
|
45
|
+
: process.env.UNI_PLATFORM, `@/uni_modules/${uniModuleDir}`, exports);
|
|
46
|
+
importCodes.push(...exportsImportCodes);
|
|
47
|
+
assignCodes.push(...exportsAssignCodes);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!importCodes.length) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
return `${importCodes.join('\n')}
|
|
54
|
+
${assignCodes.join('\n')}`;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.uniModulesExportsPlugin = uniModulesExportsPlugin;
|
|
59
|
+
function parseExports(platform, source, exports = {}) {
|
|
60
|
+
const rootDefines = {};
|
|
61
|
+
Object.keys(exports).forEach((name) => {
|
|
62
|
+
if (name.startsWith('uni')) {
|
|
63
|
+
rootDefines[name] = exports[name];
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const platformDefines = exports[platform];
|
|
67
|
+
// 该平台不支持
|
|
68
|
+
if (platformDefines === false) {
|
|
69
|
+
return [[], []];
|
|
70
|
+
}
|
|
71
|
+
return parseDefines(source, (0, merge_1.recursive)(true, rootDefines, platformDefines));
|
|
72
|
+
}
|
|
73
|
+
exports.parseExports = parseExports;
|
|
74
|
+
function parseDefines(source, defines = {}) {
|
|
75
|
+
const importCodes = [];
|
|
76
|
+
const assignCodes = [];
|
|
77
|
+
Object.keys(defines).forEach((name) => {
|
|
78
|
+
const [defineImportCodes, defineAssignCodes] = parseDefine(source, name, defines[name]);
|
|
79
|
+
importCodes.push(...defineImportCodes);
|
|
80
|
+
assignCodes.push(...defineAssignCodes);
|
|
81
|
+
});
|
|
82
|
+
return [importCodes, assignCodes];
|
|
83
|
+
}
|
|
84
|
+
exports.parseDefines = parseDefines;
|
|
85
|
+
/**
|
|
86
|
+
* uni:'getBatteryInfo'
|
|
87
|
+
* import getBatteryInfo from '..'
|
|
88
|
+
*
|
|
89
|
+
* uni:['getBatteryInfo']
|
|
90
|
+
* import { getBatteryInfo } from '..'
|
|
91
|
+
*
|
|
92
|
+
* uni:['openLocation','chooseLocation']
|
|
93
|
+
* import { openLocation, chooseLocation } from '..'
|
|
94
|
+
*
|
|
95
|
+
* uni:{
|
|
96
|
+
* onUserCaptureScreen: "onCaptureScreen"
|
|
97
|
+
* offUserCaptureScreen: "offCaptureScreen"
|
|
98
|
+
* }
|
|
99
|
+
*
|
|
100
|
+
* uni.getBatteryInfo = getBatteryInfo
|
|
101
|
+
* @param source
|
|
102
|
+
* @param globalObject
|
|
103
|
+
* @param define
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
function parseDefine(source, globalObject, define) {
|
|
107
|
+
const importCodes = [];
|
|
108
|
+
const assignCodes = [];
|
|
109
|
+
if ((0, shared_1.isString)(define)) {
|
|
110
|
+
importCodes.push(`import ${define} from '${source}'`);
|
|
111
|
+
assignCodes.push(`${globalObject}.${define} = ${define}`);
|
|
112
|
+
}
|
|
113
|
+
else if ((0, shared_1.isArray)(define)) {
|
|
114
|
+
importCodes.push(`import { ${define.join(', ')} } from '${source}'`);
|
|
115
|
+
define.forEach((d) => {
|
|
116
|
+
assignCodes.push(`${globalObject}.${d} = ${d}`);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
else if ((0, shared_1.isPlainObject)(define)) {
|
|
120
|
+
const keys = Object.keys(define);
|
|
121
|
+
const specifiers = [];
|
|
122
|
+
keys.forEach((d) => {
|
|
123
|
+
if (d !== define[d]) {
|
|
124
|
+
specifiers.push(`${define[d]} as ${d}`);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
specifiers.push(d);
|
|
128
|
+
}
|
|
129
|
+
assignCodes.push(`${globalObject}.${d} = ${d}`);
|
|
130
|
+
});
|
|
131
|
+
importCodes.push(`import { ${specifiers.join(', ')} } from '${source}'`);
|
|
132
|
+
}
|
|
133
|
+
return [importCodes, assignCodes];
|
|
134
|
+
}
|
package/dist/vite/utils/url.js
CHANGED
|
@@ -54,6 +54,10 @@ exports.hashRE = /#.*$/;
|
|
|
54
54
|
const cleanUrl = (url) => url.replace(exports.hashRE, '').replace(exports.queryRE, '');
|
|
55
55
|
exports.cleanUrl = cleanUrl;
|
|
56
56
|
function isJsFile(id) {
|
|
57
|
+
// inject 使用了isJsFile 判断。uni_modules_exports 中注入使用了 uni,在小程序平台,inject 需要注入 uni 对象
|
|
58
|
+
if (id === constants_1.UNI_MODULES_EXPORTS) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
57
61
|
const isJs = constants_1.EXTNAME_JS_RE.test(id);
|
|
58
62
|
if (isJs) {
|
|
59
63
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-3060420220922002",
|
|
4
4
|
"description": "@dcloudio/uni-cli-shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@ampproject/remapping": "^2.1.2",
|
|
25
|
-
"@babel/core": "^7.
|
|
26
|
-
"@babel/parser": "^7.
|
|
25
|
+
"@babel/core": "^7.18.13",
|
|
26
|
+
"@babel/parser": "^7.18.13",
|
|
27
27
|
"@babel/types": "^7.17.0",
|
|
28
|
-
"@dcloudio/uni-i18n": "3.0.0-alpha-
|
|
29
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
28
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-3060420220922002",
|
|
29
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-3060420220922002",
|
|
30
30
|
"@intlify/core-base": "9.1.9",
|
|
31
31
|
"@intlify/shared": "9.1.9",
|
|
32
32
|
"@intlify/vue-devtools": "9.1.9",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"compare-versions": "^3.6.0",
|
|
43
43
|
"debug": "^4.3.3",
|
|
44
44
|
"es-module-lexer": "^0.9.3",
|
|
45
|
-
"esbuild": "^0.
|
|
45
|
+
"esbuild": "^0.15.9",
|
|
46
46
|
"estree-walker": "^2.0.2",
|
|
47
47
|
"fast-glob": "^3.2.11",
|
|
48
48
|
"fs-extra": "^10.0.0",
|
|
49
49
|
"hash-sum": "^2.0.0",
|
|
50
50
|
"jsonc-parser": "^3.0.0",
|
|
51
|
-
"magic-string": "^0.26.
|
|
51
|
+
"magic-string": "^0.26.3",
|
|
52
52
|
"merge": "^2.1.1",
|
|
53
53
|
"mime": "^3.0.0",
|
|
54
54
|
"module-alias": "^2.2.2",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"postcss-load-config": "^3.1.1",
|
|
59
59
|
"postcss-modules": "^4.3.0",
|
|
60
60
|
"postcss-selector-parser": "^6.0.6",
|
|
61
|
-
"resolve": "^1.22.
|
|
61
|
+
"resolve": "^1.22.1",
|
|
62
62
|
"tapable": "^2.2.0",
|
|
63
63
|
"xregexp": "3.1.0"
|
|
64
64
|
},
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@types/resolve": "^1.20.2",
|
|
76
76
|
"@types/sass": "^1.43.1",
|
|
77
77
|
"@types/stylus": "^0.48.36",
|
|
78
|
-
"postcss": "^8.4.
|
|
78
|
+
"postcss": "^8.4.16",
|
|
79
79
|
"vue": "3.2.39"
|
|
80
80
|
}
|
|
81
81
|
}
|