@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211109002 → 3.0.0-alpha-3021320211115001
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 +3 -0
- package/dist/constants.js +4 -1
- package/dist/easycom.d.ts +7 -1
- package/dist/easycom.js +25 -6
- package/dist/env/define.d.ts +3 -0
- package/dist/env/define.js +6 -0
- package/dist/exports.d.ts +1 -0
- package/dist/exports.js +8 -0
- package/dist/filter.d.ts +16 -0
- package/dist/filter.js +60 -0
- package/dist/hbx/alias.js +9 -1
- package/dist/hbx/env.js +4 -1
- package/dist/hbx/index.js +0 -7
- package/dist/hbx/log.d.ts +2 -0
- package/dist/hbx/log.js +36 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/json/app/manifest/confusion.d.ts +3 -0
- package/dist/json/app/manifest/confusion.js +56 -14
- package/dist/json/app/manifest/env.d.ts +1 -1
- package/dist/json/app/manifest/index.d.ts +1 -0
- package/dist/json/app/manifest/index.js +5 -1
- package/dist/json/app/manifest/nvue.d.ts +3 -3
- package/dist/json/app/pages/index.d.ts +0 -1
- package/dist/json/app/pages/index.js +0 -11
- package/dist/json/manifest.d.ts +1 -1
- package/dist/json/manifest.js +9 -3
- package/dist/json/mp/index.d.ts +1 -0
- package/dist/json/mp/index.js +11 -0
- package/dist/json/mp/jsonFile.d.ts +8 -6
- package/dist/json/mp/jsonFile.js +68 -16
- package/dist/json/mp/pages.d.ts +1 -0
- package/dist/json/mp/pages.js +17 -3
- package/dist/json/mp/types.d.ts +1 -0
- package/dist/json/pages.js +0 -4
- package/dist/logs/console.js +5 -2
- package/dist/logs/format.js +6 -0
- package/dist/messages/index.d.ts +3 -0
- package/dist/messages/index.js +3 -0
- package/dist/mp/constants.d.ts +2 -0
- package/dist/mp/constants.js +5 -0
- package/dist/mp/event.d.ts +2 -1
- package/dist/mp/event.js +18 -3
- package/dist/mp/imports.d.ts +5 -0
- package/dist/mp/imports.js +63 -0
- package/dist/mp/index.d.ts +5 -0
- package/dist/mp/index.js +7 -0
- package/dist/mp/nvue.d.ts +1 -0
- package/dist/mp/nvue.js +18 -0
- package/dist/mp/style.d.ts +1 -0
- package/dist/mp/style.js +9 -0
- package/dist/mp/template.d.ts +55 -0
- package/dist/mp/template.js +73 -0
- package/dist/mp/transformImports.d.ts +14 -0
- package/dist/mp/transformImports.js +175 -0
- package/dist/postcss/plugins/stylePluginScoped.d.ts +1 -1
- package/dist/postcss/plugins/uniapp.d.ts +1 -1
- package/dist/postcss/plugins/uniapp.js +51 -21
- package/dist/preprocess/context.js +1 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +93 -8
- package/dist/vite/features.d.ts +1 -1
- package/dist/vite/index.d.ts +2 -3
- package/dist/vite/plugins/copy.d.ts +1 -1
- package/dist/vite/plugins/cssScoped.d.ts +1 -1
- package/dist/vite/plugins/inject.d.ts +1 -1
- package/dist/vite/plugins/inject.js +2 -2
- package/dist/vite/plugins/vitejs/config.d.ts +1 -1
- package/dist/vite/plugins/vitejs/index.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugin.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -1
- package/dist/vite/plugins/vitejs/plugins/asset.js +28 -21
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +4 -4
- package/dist/vite/plugins/vitejs/plugins/css.js +15 -24
- package/dist/vite/plugins/vitejs/server/moduleGraph.d.ts +1 -1
- package/dist/vite/plugins/vitejs/server/moduleGraph.js +0 -3
- package/dist/vite/utils/ast.d.ts +1 -1
- package/dist/vite/utils/index.d.ts +1 -1
- package/dist/vite/utils/plugin.d.ts +4 -4
- package/dist/vite/utils/plugin.js +2 -2
- package/dist/vue/index.d.ts +2 -0
- package/dist/vue/index.js +14 -0
- package/dist/vue/transforms/index.d.ts +10 -0
- package/dist/vue/transforms/index.js +36 -0
- package/dist/vue/transforms/transformComponent.d.ts +3 -0
- package/dist/vue/transforms/transformComponent.js +26 -0
- package/dist/vue/transforms/transformEvent.d.ts +2 -0
- package/dist/vue/transforms/transformEvent.js +22 -0
- package/dist/vue/transforms/transformPageHead.d.ts +2 -0
- package/dist/vue/transforms/transformPageHead.js +11 -0
- package/dist/vue/transforms/transformRef.d.ts +2 -0
- package/dist/vue/transforms/transformRef.js +32 -0
- package/dist/vue/transforms/transformTag.d.ts +2 -0
- package/dist/vue/transforms/transformTag.js +18 -0
- package/dist/vue/transforms/vModel.d.ts +12 -0
- package/dist/vue/transforms/vModel.js +33 -0
- package/dist/vue/transforms/vOn.d.ts +15 -0
- package/dist/vue/transforms/vOn.js +88 -0
- package/dist/vue/utils.d.ts +9 -0
- package/dist/vue/utils.js +66 -0
- package/lib/nvue.css +34 -0
- package/package.json +27 -6
- package/LICENSE +0 -202
- package/dist/json/app/pages/nvue.d.ts +0 -1
- package/dist/json/app/pages/nvue.js +0 -88
- package/dist/renderjs.d.ts +0 -16
- package/dist/renderjs.js +0 -44
package/dist/json/mp/jsonFile.js
CHANGED
|
@@ -1,18 +1,70 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
exports.
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.hasJsonFile = exports.isPageFile = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
let appJsonCache = {};
|
|
7
|
+
const jsonFilesCache = new Map();
|
|
8
|
+
const jsonPagesCache = new Map();
|
|
9
|
+
const jsonComponentsCache = new Map();
|
|
10
|
+
const jsonUsingComponentsCache = new Map();
|
|
11
|
+
function isPageFile(file) {
|
|
12
|
+
return jsonPagesCache.has((0, utils_1.removeExt)(file));
|
|
13
|
+
}
|
|
14
|
+
exports.isPageFile = isPageFile;
|
|
15
|
+
function hasJsonFile(filename) {
|
|
16
|
+
return (filename === 'app' ||
|
|
17
|
+
jsonPagesCache.has(filename) ||
|
|
18
|
+
jsonComponentsCache.has(filename));
|
|
19
|
+
}
|
|
20
|
+
exports.hasJsonFile = hasJsonFile;
|
|
21
|
+
function normalizeJsonFilename(filename) {
|
|
22
|
+
return (0, utils_1.normalizeNodeModules)(filename);
|
|
23
|
+
}
|
|
24
|
+
exports.normalizeJsonFilename = normalizeJsonFilename;
|
|
25
|
+
function findChangedJsonFiles() {
|
|
26
|
+
const changedJsonFiles = new Map();
|
|
27
|
+
function findChangedFile(filename, json) {
|
|
28
|
+
const newJson = (0, shared_1.extend)({}, json);
|
|
29
|
+
if (!newJson.usingComponents) {
|
|
30
|
+
newJson.usingComponents = {};
|
|
31
|
+
}
|
|
32
|
+
(0, shared_1.extend)(newJson.usingComponents, jsonUsingComponentsCache.get(filename));
|
|
33
|
+
const usingComponents = newJson.usingComponents;
|
|
34
|
+
// 格式化为相对路径,这样作为分包也可以直接运行
|
|
35
|
+
Object.keys(usingComponents).forEach((name) => {
|
|
36
|
+
usingComponents[name] = (0, utils_1.relativeFile)(filename, usingComponents[name].slice(1));
|
|
37
|
+
});
|
|
38
|
+
const jsonStr = JSON.stringify(newJson, null, 2);
|
|
39
|
+
if (jsonFilesCache.get(filename) !== jsonStr) {
|
|
40
|
+
changedJsonFiles.set(filename, jsonStr);
|
|
41
|
+
jsonFilesCache.set(filename, jsonStr);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function findChangedFiles(jsonsCache) {
|
|
45
|
+
for (const name of jsonsCache.keys()) {
|
|
46
|
+
findChangedFile(name, jsonsCache.get(name));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
findChangedFile('app', appJsonCache);
|
|
50
|
+
findChangedFiles(jsonPagesCache);
|
|
51
|
+
findChangedFiles(jsonComponentsCache);
|
|
52
|
+
return changedJsonFiles;
|
|
53
|
+
}
|
|
54
|
+
exports.findChangedJsonFiles = findChangedJsonFiles;
|
|
55
|
+
function addMiniProgramAppJson(appJson) {
|
|
56
|
+
appJsonCache = appJson;
|
|
57
|
+
}
|
|
58
|
+
exports.addMiniProgramAppJson = addMiniProgramAppJson;
|
|
59
|
+
function addMiniProgramPageJson(filename, json) {
|
|
60
|
+
jsonPagesCache.set(filename, json);
|
|
61
|
+
}
|
|
62
|
+
exports.addMiniProgramPageJson = addMiniProgramPageJson;
|
|
63
|
+
function addMiniProgramComponentJson(filename, json) {
|
|
64
|
+
jsonComponentsCache.set(filename, json);
|
|
65
|
+
}
|
|
66
|
+
exports.addMiniProgramComponentJson = addMiniProgramComponentJson;
|
|
67
|
+
function addMiniProgramUsingComponents(filename, json) {
|
|
68
|
+
jsonUsingComponentsCache.set(filename, json);
|
|
69
|
+
}
|
|
70
|
+
exports.addMiniProgramUsingComponents = addMiniProgramUsingComponents;
|
package/dist/json/mp/pages.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ interface ParsePagesJsonOptions {
|
|
|
11
11
|
export declare function parseMiniProgramPagesJson(jsonStr: string, platform: UniApp.PLATFORM, options?: ParsePagesJsonOptions): {
|
|
12
12
|
appJson: AppJson;
|
|
13
13
|
pageJsons: Record<string, PageWindowOptions>;
|
|
14
|
+
nvuePages: string[];
|
|
14
15
|
};
|
|
15
16
|
export {};
|
package/dist/json/mp/pages.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.parseMiniProgramPagesJson = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const shared_1 = require("@vue/shared");
|
|
9
10
|
const json_1 = require("../json");
|
|
@@ -14,20 +15,32 @@ function parseMiniProgramPagesJson(jsonStr, platform, options = { subpackages: f
|
|
|
14
15
|
return parsePagesJson(jsonStr, platform, options);
|
|
15
16
|
}
|
|
16
17
|
exports.parseMiniProgramPagesJson = parseMiniProgramPagesJson;
|
|
17
|
-
function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, } = {
|
|
18
|
+
function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, tabBarOptionsMap, tabBarItemOptionsMap, } = {
|
|
18
19
|
subpackages: false,
|
|
19
20
|
}) {
|
|
20
21
|
const appJson = {
|
|
21
22
|
pages: [],
|
|
22
23
|
};
|
|
23
24
|
const pageJsons = {};
|
|
25
|
+
const nvuePages = [];
|
|
24
26
|
// preprocess
|
|
25
27
|
const pagesJson = (0, json_1.parseJson)(jsonStr, true);
|
|
26
28
|
if (!pagesJson) {
|
|
27
29
|
throw new Error(`[vite] Error: pages.json parse failed.\n`);
|
|
28
30
|
}
|
|
29
31
|
function addPageJson(pagePath, style) {
|
|
30
|
-
|
|
32
|
+
const filename = path_1.default.join(process.env.UNI_INPUT_DIR, pagePath);
|
|
33
|
+
if (fs_1.default.existsSync(filename + '.nvue') &&
|
|
34
|
+
!fs_1.default.existsSync(filename + '.vue')) {
|
|
35
|
+
nvuePages.push(pagePath);
|
|
36
|
+
}
|
|
37
|
+
const windowOptions = {};
|
|
38
|
+
if (platform === 'mp-baidu') {
|
|
39
|
+
// 仅百度小程序需要页面配置 component:true
|
|
40
|
+
// 快手小程序反而不能配置 component:true,故不能统一添加,目前硬编码处理
|
|
41
|
+
windowOptions.component = true;
|
|
42
|
+
}
|
|
43
|
+
pageJsons[pagePath] = (0, shared_1.extend)(windowOptions, (0, utils_1.parseWindowOptions)(style, platform, windowOptionsMap));
|
|
31
44
|
}
|
|
32
45
|
// pages
|
|
33
46
|
(0, pages_1.validatePages)(pagesJson, jsonStr);
|
|
@@ -65,7 +78,7 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
|
|
|
65
78
|
}
|
|
66
79
|
// tabBar
|
|
67
80
|
if (pagesJson.tabBar) {
|
|
68
|
-
const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform);
|
|
81
|
+
const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform, tabBarOptionsMap, tabBarItemOptionsMap);
|
|
69
82
|
if (tabBar) {
|
|
70
83
|
appJson.tabBar = tabBar;
|
|
71
84
|
}
|
|
@@ -89,5 +102,6 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
|
|
|
89
102
|
return {
|
|
90
103
|
appJson,
|
|
91
104
|
pageJsons,
|
|
105
|
+
nvuePages,
|
|
92
106
|
};
|
|
93
107
|
}
|
package/dist/json/mp/types.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ interface ShareWindowOptions {
|
|
|
18
18
|
declare type Style = 'v2' | string;
|
|
19
19
|
declare type RestartStrategy = 'homePage' | 'homePageAndLatestPage' | string;
|
|
20
20
|
export interface PageWindowOptions extends ShareWindowOptions {
|
|
21
|
+
component?: true;
|
|
21
22
|
disableScroll?: boolean;
|
|
22
23
|
usingComponents?: UsingComponents;
|
|
23
24
|
initialRenderingCache?: 'static' | string;
|
package/dist/json/pages.js
CHANGED
|
@@ -10,7 +10,6 @@ const shared_1 = require("@vue/shared");
|
|
|
10
10
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
11
11
|
const utils_1 = require("../utils");
|
|
12
12
|
const json_1 = require("./json");
|
|
13
|
-
const pages_1 = require("./app/pages");
|
|
14
13
|
const parsePagesJson = (inputDir, platform, normalize = true) => {
|
|
15
14
|
const jsonStr = fs_1.default.readFileSync(path_1.default.join(inputDir, 'pages.json'), 'utf8');
|
|
16
15
|
if (normalize) {
|
|
@@ -55,9 +54,6 @@ function normalizePagesJson(jsonStr, platform, { subpackages, } = { subpackages:
|
|
|
55
54
|
}
|
|
56
55
|
// pageStyle
|
|
57
56
|
normalizePages(pagesJson.pages, platform);
|
|
58
|
-
if (platform === 'app' && process.env.UNI_NVUE_COMPILER !== 'vue') {
|
|
59
|
-
(0, pages_1.initWebpackNVueEntry)(pagesJson.pages);
|
|
60
|
-
}
|
|
61
57
|
// globalStyle
|
|
62
58
|
pagesJson.globalStyle = normalizePageStyle(null, pagesJson.globalStyle, platform);
|
|
63
59
|
// tabBar
|
package/dist/logs/console.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.rewriteConsoleExpr = void 0;
|
|
4
|
-
const
|
|
7
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
5
8
|
const utils_1 = require("../utils");
|
|
6
9
|
const F = '__f__';
|
|
7
10
|
function rewriteConsoleExpr(filename, code) {
|
|
8
11
|
filename = (0, utils_1.normalizePath)(filename);
|
|
9
12
|
const re = /(console\.(log|info|debug|warn|error))\(([^)]+)\)/g;
|
|
10
13
|
const locate = getLocator(code);
|
|
11
|
-
const s = new
|
|
14
|
+
const s = new magic_string_1.default(code);
|
|
12
15
|
let match;
|
|
13
16
|
while ((match = re.exec(code))) {
|
|
14
17
|
const [, expr, type] = match;
|
package/dist/logs/format.js
CHANGED
|
@@ -12,6 +12,12 @@ const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
|
|
|
12
12
|
if ((0, env_1.isInHBuilderX)()) {
|
|
13
13
|
errFormatters.push(alias_1.moduleAliasFormatter);
|
|
14
14
|
}
|
|
15
|
+
if ((0, env_1.runByHBuilderX)()) {
|
|
16
|
+
errFormatters.push(log_1.HBuilderXFileFormatter);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
errFormatters.push(log_1.FilenameFormatter);
|
|
20
|
+
}
|
|
15
21
|
});
|
|
16
22
|
const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
|
|
17
23
|
if ((0, env_1.isInHBuilderX)()) {
|
package/dist/messages/index.d.ts
CHANGED
package/dist/messages/index.js
CHANGED
|
@@ -16,4 +16,7 @@ exports.M = {
|
|
|
16
16
|
'i18n.fallbackLocale.default': '当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}',
|
|
17
17
|
'i18n.fallbackLocale.missing': '当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件',
|
|
18
18
|
'easycom.conflict': 'easycom组件冲突:',
|
|
19
|
+
'mp.component.args[0]': '{0}的第一个参数必须为静态字符串',
|
|
20
|
+
'mp.component.args[1]': '{0}需要两个参数',
|
|
21
|
+
'mp.360.unsupported': 'vue3暂不支持360小程序',
|
|
19
22
|
};
|
package/dist/mp/event.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function formatMiniProgramEvent(eventName: string, { isCatch, isCapture, }: {
|
|
1
|
+
export declare function formatMiniProgramEvent(eventName: string, { isCatch, isCapture, isComponent, }: {
|
|
2
2
|
isCatch?: boolean;
|
|
3
3
|
isCapture?: boolean;
|
|
4
|
+
isComponent?: boolean;
|
|
4
5
|
}): string;
|
package/dist/mp/event.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatMiniProgramEvent = void 0;
|
|
4
|
-
function formatMiniProgramEvent(eventName, { isCatch, isCapture, }) {
|
|
4
|
+
function formatMiniProgramEvent(eventName, { isCatch, isCapture, isComponent, }) {
|
|
5
|
+
if (!isComponent && eventName === 'click') {
|
|
6
|
+
eventName = 'tap';
|
|
7
|
+
}
|
|
5
8
|
let eventType = 'bind';
|
|
6
9
|
if (isCatch) {
|
|
7
10
|
eventType = 'catch';
|
|
@@ -9,7 +12,19 @@ function formatMiniProgramEvent(eventName, { isCatch, isCapture, }) {
|
|
|
9
12
|
if (isCapture) {
|
|
10
13
|
return `capture-${eventType}:${eventName}`;
|
|
11
14
|
}
|
|
12
|
-
//
|
|
13
|
-
return
|
|
15
|
+
// bind:foo-bar
|
|
16
|
+
return eventType + (isSimpleExpr(eventName) ? '' : ':') + eventName;
|
|
14
17
|
}
|
|
15
18
|
exports.formatMiniProgramEvent = formatMiniProgramEvent;
|
|
19
|
+
function isSimpleExpr(name) {
|
|
20
|
+
if (name.startsWith('_')) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
if (name.indexOf('-') > -1) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (name.indexOf(':') > -1) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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.findVueComponentImports = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const es_module_lexer_1 = require("es-module-lexer");
|
|
9
|
+
const shared_1 = require("@vue/shared");
|
|
10
|
+
const types_1 = require("@babel/types");
|
|
11
|
+
const parser_1 = require("@babel/parser");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
async function findVueComponentImports(source, importer, resolve) {
|
|
14
|
+
await es_module_lexer_1.init;
|
|
15
|
+
let imports = [];
|
|
16
|
+
// strip UTF-8 BOM
|
|
17
|
+
if (source.charCodeAt(0) === 0xfeff) {
|
|
18
|
+
source = source.slice(1);
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
imports = (0, es_module_lexer_1.parse)(source)[0];
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
console.error(e);
|
|
25
|
+
}
|
|
26
|
+
if (!imports.length) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const rewriteImports = [];
|
|
30
|
+
for (let i = 0; i < imports.length; i++) {
|
|
31
|
+
const importSpecifier = imports[i];
|
|
32
|
+
const { n } = importSpecifier;
|
|
33
|
+
if (!n) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const extname = path_1.default.extname(n);
|
|
37
|
+
// 仅处理没有后缀,或后缀是.vue,.nvue的文件
|
|
38
|
+
if (extname && !constants_1.EXTNAME_VUE.includes(extname)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const res = await resolve(n, importer);
|
|
42
|
+
if (!res) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (constants_1.EXTNAME_VUE_RE.test(res.id)) {
|
|
46
|
+
const expr = (0, parser_1.parse)(source.slice(importSpecifier.ss, importSpecifier.se), {
|
|
47
|
+
sourceType: 'module',
|
|
48
|
+
}).program.body[0];
|
|
49
|
+
if ((0, types_1.isImportDeclaration)(expr) && expr.specifiers.length === 1) {
|
|
50
|
+
const importDefaultSpecifier = expr.specifiers[0];
|
|
51
|
+
if (!(0, types_1.isImportDefaultSpecifier)(importDefaultSpecifier)) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
rewriteImports.push((0, shared_1.extend)(importSpecifier, {
|
|
55
|
+
n: res.id,
|
|
56
|
+
i: importDefaultSpecifier.local.name,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return rewriteImports;
|
|
62
|
+
}
|
|
63
|
+
exports.findVueComponentImports = findVueComponentImports;
|
package/dist/mp/index.d.ts
CHANGED
package/dist/mp/index.js
CHANGED
|
@@ -10,4 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.transformVueComponentImports = void 0;
|
|
14
|
+
__exportStar(require("./nvue"), exports);
|
|
13
15
|
__exportStar(require("./event"), exports);
|
|
16
|
+
__exportStar(require("./style"), exports);
|
|
17
|
+
__exportStar(require("./template"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
19
|
+
var transformImports_1 = require("./transformImports");
|
|
20
|
+
Object.defineProperty(exports, "transformVueComponentImports", { enumerable: true, get: function () { return transformImports_1.transformVueComponentImports; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function genNVueCssCode(manifestJson: Record<string, any>): string;
|
package/dist/mp/nvue.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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.genNVueCssCode = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const nvue_1 = require("../json/app/manifest/nvue");
|
|
10
|
+
function genNVueCssCode(manifestJson) {
|
|
11
|
+
let nvueCssCode = fs_1.default.readFileSync(path_1.default.resolve(__dirname, '../../lib/nvue.css'), 'utf8');
|
|
12
|
+
const flexDirection = (0, nvue_1.getNVueFlexDirection)(manifestJson);
|
|
13
|
+
if (flexDirection !== 'column') {
|
|
14
|
+
nvueCssCode = nvueCssCode.replace('column', flexDirection);
|
|
15
|
+
}
|
|
16
|
+
return nvueCssCode;
|
|
17
|
+
}
|
|
18
|
+
exports.genNVueCssCode = genNVueCssCode;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function transformScopedCss(cssCode: string): string;
|
package/dist/mp/style.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformScopedCss = void 0;
|
|
4
|
+
function transformScopedCss(cssCode) {
|
|
5
|
+
return cssCode.replace(/\[(data-v-[a-f0-9]{8})\]/gi, (_, scopedId) => {
|
|
6
|
+
return '.' + scopedId;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
exports.transformScopedCss = transformScopedCss;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EmittedAsset } from 'rollup';
|
|
2
|
+
export interface MiniProgramCompilerOptions {
|
|
3
|
+
/**
|
|
4
|
+
* 需要延迟渲染的组件,通常是某个组件的某个事件会立刻触发,需要延迟到首次 render 之后,比如微信 editor 的 ready 事件,快手 switch 的 change
|
|
5
|
+
*/
|
|
6
|
+
lazyElement?: {
|
|
7
|
+
[name: string]: string[];
|
|
8
|
+
};
|
|
9
|
+
event?: {
|
|
10
|
+
format(name: string, opts: {
|
|
11
|
+
isCatch?: boolean;
|
|
12
|
+
isCapture?: boolean;
|
|
13
|
+
isComponent?: boolean;
|
|
14
|
+
}): string;
|
|
15
|
+
};
|
|
16
|
+
class: {
|
|
17
|
+
/**
|
|
18
|
+
* 是否支持绑定 array 类型
|
|
19
|
+
*/
|
|
20
|
+
array: boolean;
|
|
21
|
+
};
|
|
22
|
+
slot: {
|
|
23
|
+
/**
|
|
24
|
+
* 是否支持 $slots.default 访问
|
|
25
|
+
*/
|
|
26
|
+
$slots?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 是否支持后备内容
|
|
29
|
+
*/
|
|
30
|
+
fallbackContent?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 是否支持动态插槽名
|
|
33
|
+
*/
|
|
34
|
+
dynamicSlotNames?: boolean;
|
|
35
|
+
};
|
|
36
|
+
filter?: {
|
|
37
|
+
lang: string;
|
|
38
|
+
};
|
|
39
|
+
directive: string;
|
|
40
|
+
emitFile?: (emittedFile: EmittedAsset) => string;
|
|
41
|
+
}
|
|
42
|
+
export interface MiniProgramFilterOptions {
|
|
43
|
+
id: string;
|
|
44
|
+
type: string;
|
|
45
|
+
name: string;
|
|
46
|
+
src?: string;
|
|
47
|
+
code: string;
|
|
48
|
+
}
|
|
49
|
+
declare type GenFilterFn = (filter: MiniProgramFilterOptions, filename: string) => string | void;
|
|
50
|
+
export declare function findMiniProgramTemplateFiles(genFilter?: GenFilterFn): Record<string, string>;
|
|
51
|
+
export declare function clearMiniProgramTemplateFiles(): void;
|
|
52
|
+
export declare function addMiniProgramTemplateFile(filename: string, code: string): void;
|
|
53
|
+
export declare function clearMiniProgramTemplateFilter(filename: string): void;
|
|
54
|
+
export declare function addMiniProgramTemplateFilter(filename: string, filter: MiniProgramFilterOptions): void;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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.addMiniProgramTemplateFilter = exports.clearMiniProgramTemplateFilter = exports.addMiniProgramTemplateFile = exports.clearMiniProgramTemplateFiles = exports.findMiniProgramTemplateFiles = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
9
|
+
const utils_1 = require("../utils");
|
|
10
|
+
const templateFilesCache = new Map();
|
|
11
|
+
const templateFiltersCache = new Map();
|
|
12
|
+
function relativeFilterFilename(filename, filter) {
|
|
13
|
+
if (!filter.src) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
return ('./' +
|
|
17
|
+
(0, utils_1.normalizeMiniProgramFilename)(path_1.default.relative(path_1.default.dirname(filename), filter.src)));
|
|
18
|
+
}
|
|
19
|
+
function findMiniProgramTemplateFiles(genFilter) {
|
|
20
|
+
const files = Object.create(null);
|
|
21
|
+
templateFilesCache.forEach((code, filename) => {
|
|
22
|
+
if (!genFilter) {
|
|
23
|
+
files[filename] = code;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
const filters = getMiniProgramTemplateFilters(filename);
|
|
27
|
+
if (filters && filters.length) {
|
|
28
|
+
files[filename] =
|
|
29
|
+
filters
|
|
30
|
+
.map((filter) => genFilter(filter, relativeFilterFilename(filename, filter)))
|
|
31
|
+
.join(uni_shared_1.LINEFEED) +
|
|
32
|
+
uni_shared_1.LINEFEED +
|
|
33
|
+
code;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
files[filename] = code;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return files;
|
|
41
|
+
}
|
|
42
|
+
exports.findMiniProgramTemplateFiles = findMiniProgramTemplateFiles;
|
|
43
|
+
function clearMiniProgramTemplateFiles() {
|
|
44
|
+
templateFilesCache.clear();
|
|
45
|
+
}
|
|
46
|
+
exports.clearMiniProgramTemplateFiles = clearMiniProgramTemplateFiles;
|
|
47
|
+
function addMiniProgramTemplateFile(filename, code) {
|
|
48
|
+
templateFilesCache.set(filename, code);
|
|
49
|
+
}
|
|
50
|
+
exports.addMiniProgramTemplateFile = addMiniProgramTemplateFile;
|
|
51
|
+
function getMiniProgramTemplateFilters(filename) {
|
|
52
|
+
return templateFiltersCache.get(filename);
|
|
53
|
+
}
|
|
54
|
+
function clearMiniProgramTemplateFilter(filename) {
|
|
55
|
+
templateFiltersCache.delete(filename);
|
|
56
|
+
}
|
|
57
|
+
exports.clearMiniProgramTemplateFilter = clearMiniProgramTemplateFilter;
|
|
58
|
+
function addMiniProgramTemplateFilter(filename, filter) {
|
|
59
|
+
const filters = templateFiltersCache.get(filename);
|
|
60
|
+
if (filters) {
|
|
61
|
+
const filterIndex = filters.findIndex((f) => f.id === filter.id);
|
|
62
|
+
if (filterIndex > -1) {
|
|
63
|
+
filters.splice(filterIndex, 1, filter);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
filters.push(filter);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
templateFiltersCache.set(filename, [filter]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.addMiniProgramTemplateFilter = addMiniProgramTemplateFilter;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ParserPlugin } from '@babel/parser';
|
|
2
|
+
import { PluginContext } from 'rollup';
|
|
3
|
+
interface TransformVueComponentImportsOptions {
|
|
4
|
+
root: string;
|
|
5
|
+
global?: boolean;
|
|
6
|
+
resolve: PluginContext['resolve'];
|
|
7
|
+
dynamicImport: (name: string, source: string) => string;
|
|
8
|
+
babelParserPlugins?: ParserPlugin[];
|
|
9
|
+
}
|
|
10
|
+
export declare function transformVueComponentImports(code: string, importer: string, { root, resolve, global, dynamicImport, babelParserPlugins, }: TransformVueComponentImportsOptions): Promise<{
|
|
11
|
+
code: string;
|
|
12
|
+
usingComponents: Record<string, string>;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|