@dcloudio/uni-cli-shared 3.0.0-alpha-3021320211109002 → 3.0.0-alpha-3021220211105012
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 +2 -0
- package/dist/constants.js +3 -1
- package/dist/easycom.d.ts +7 -1
- package/dist/easycom.js +25 -6
- package/dist/env/define.d.ts +2 -0
- package/dist/env/define.js +5 -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/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/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 +7 -6
- package/dist/json/mp/jsonFile.js +56 -13
- 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 +2 -0
- package/dist/messages/index.js +2 -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 +10 -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 +8 -1
- package/dist/utils.js +71 -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 +3 -0
- package/dist/vue/transforms/transformTag.js +45 -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 +20 -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/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,6 @@ 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}需要两个参数',
|
|
19
21
|
};
|
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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformScopedCss = void 0;
|
|
4
|
+
const scopedRE = /\[(data-v-[a-f0-9]{8})\]/gi;
|
|
5
|
+
function transformScopedCss(cssCode) {
|
|
6
|
+
return cssCode.replace(scopedRE, (_, scopedId) => {
|
|
7
|
+
return '.' + scopedId;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
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 {};
|
|
@@ -0,0 +1,175 @@
|
|
|
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.transformVueComponentImports = void 0;
|
|
7
|
+
const parser_1 = require("@babel/parser");
|
|
8
|
+
const types_1 = require("@babel/types");
|
|
9
|
+
const shared_1 = require("@vue/shared");
|
|
10
|
+
const estree_walker_1 = require("estree-walker");
|
|
11
|
+
const magic_string_1 = __importDefault(require("magic-string"));
|
|
12
|
+
const messages_1 = require("../messages");
|
|
13
|
+
const constants_1 = require("../constants");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
async function transformVueComponentImports(code, importer, { root, resolve, global, dynamicImport, babelParserPlugins, }) {
|
|
16
|
+
if (!global && !code.includes(constants_1.BINDING_COMPONENTS)) {
|
|
17
|
+
return { code, usingComponents: {} };
|
|
18
|
+
}
|
|
19
|
+
const s = new magic_string_1.default(code);
|
|
20
|
+
const scriptAst = (0, parser_1.parse)(code, {
|
|
21
|
+
plugins: [...(babelParserPlugins || [])],
|
|
22
|
+
sourceType: 'module',
|
|
23
|
+
}).program;
|
|
24
|
+
const imports = findVueComponentImports(scriptAst.body, global
|
|
25
|
+
? parseGlobalComponents(scriptAst)
|
|
26
|
+
: parseComponents(scriptAst, findBindingComponents(scriptAst.body)));
|
|
27
|
+
const usingComponents = {};
|
|
28
|
+
for (let i = 0; i < imports.length; i++) {
|
|
29
|
+
const { tag, import: { start, end, specifiers: [specifier], source, }, } = imports[i];
|
|
30
|
+
const resolveId = await resolve(source.value, importer);
|
|
31
|
+
if (resolveId) {
|
|
32
|
+
s.overwrite(start, end, dynamicImport(specifier.local.name, resolveId.id) + ';');
|
|
33
|
+
const componentName = (0, shared_1.hyphenate)(tag);
|
|
34
|
+
if (!usingComponents[componentName]) {
|
|
35
|
+
usingComponents[componentName] =
|
|
36
|
+
'/' + (0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(resolveId.id, root));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { code: s.toString(), usingComponents };
|
|
41
|
+
}
|
|
42
|
+
exports.transformVueComponentImports = transformVueComponentImports;
|
|
43
|
+
/**
|
|
44
|
+
* 解析编译器生成的 bindingComponents
|
|
45
|
+
* @param ast
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function findBindingComponents(ast) {
|
|
49
|
+
for (const node of ast) {
|
|
50
|
+
if (!(0, types_1.isVariableDeclaration)(node)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const declarator = node.declarations[0];
|
|
54
|
+
if ((0, types_1.isIdentifier)(declarator.id) &&
|
|
55
|
+
declarator.id.name === constants_1.BINDING_COMPONENTS) {
|
|
56
|
+
const bindingComponents = JSON.parse(declarator.init.value);
|
|
57
|
+
return Object.keys(bindingComponents).reduce((bindings, tag) => {
|
|
58
|
+
const binding = bindingComponents[tag];
|
|
59
|
+
bindings[binding.name] = {
|
|
60
|
+
tag,
|
|
61
|
+
type: binding.type,
|
|
62
|
+
};
|
|
63
|
+
return bindings;
|
|
64
|
+
}, {});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 查找全局组件定义:app.component('component-a',{})
|
|
71
|
+
* @param ast
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
function parseGlobalComponents(ast) {
|
|
75
|
+
const bindingComponents = {};
|
|
76
|
+
estree_walker_1.walk(ast, {
|
|
77
|
+
enter(child) {
|
|
78
|
+
if (!(0, types_1.isCallExpression)(child)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const { callee } = child;
|
|
82
|
+
// .component
|
|
83
|
+
if (!(0, types_1.isMemberExpression)(callee) ||
|
|
84
|
+
!(0, types_1.isIdentifier)(callee.property) ||
|
|
85
|
+
callee.property.name !== 'component') {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
// .component('component-a',{})
|
|
89
|
+
const args = child.arguments;
|
|
90
|
+
if (args.length !== 2) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const [name, value] = args;
|
|
94
|
+
if (!(0, types_1.isStringLiteral)(name)) {
|
|
95
|
+
return console.warn(messages_1.M['mp.component.args[0]']);
|
|
96
|
+
}
|
|
97
|
+
if (!(0, types_1.isIdentifier)(value)) {
|
|
98
|
+
return console.warn(messages_1.M['mp.component.args[1]']);
|
|
99
|
+
}
|
|
100
|
+
bindingComponents[value.name] = {
|
|
101
|
+
tag: name.value,
|
|
102
|
+
type: 'unknown',
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return bindingComponents;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 从 components 中查找定义的组件,修改 bindingComponents
|
|
110
|
+
* @param ast
|
|
111
|
+
* @param bindingComponents
|
|
112
|
+
*/
|
|
113
|
+
function parseComponents(ast, bindingComponents) {
|
|
114
|
+
;
|
|
115
|
+
estree_walker_1.walk(ast, {
|
|
116
|
+
enter(child) {
|
|
117
|
+
if (!(0, types_1.isObjectExpression)(child)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const componentsProp = child.properties.find((prop) => (0, types_1.isObjectProperty)(prop) &&
|
|
121
|
+
(0, types_1.isIdentifier)(prop.key) &&
|
|
122
|
+
prop.key.name === 'components');
|
|
123
|
+
if (!componentsProp) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const componentsExpr = componentsProp.value;
|
|
127
|
+
if (!(0, types_1.isObjectExpression)(componentsExpr)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
componentsExpr.properties.forEach((prop) => {
|
|
131
|
+
if (!(0, types_1.isObjectProperty)(prop)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!(0, types_1.isIdentifier)(prop.key) && !(0, types_1.isStringLiteral)(prop.key)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (!(0, types_1.isIdentifier)(prop.value)) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const tag = (0, types_1.isIdentifier)(prop.key) ? prop.key.name : prop.key.value;
|
|
141
|
+
const name = findBindingComponent(tag, bindingComponents);
|
|
142
|
+
if (name) {
|
|
143
|
+
bindingComponents[prop.value.name] = bindingComponents[name];
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return bindingComponents;
|
|
149
|
+
}
|
|
150
|
+
function findBindingComponent(tag, bindingComponents) {
|
|
151
|
+
return Object.keys(bindingComponents).find((name) => {
|
|
152
|
+
const componentTag = bindingComponents[name].tag;
|
|
153
|
+
const camelName = (0, shared_1.camelize)(componentTag);
|
|
154
|
+
const PascalName = (0, shared_1.capitalize)(camelName);
|
|
155
|
+
return tag === componentTag || tag === camelName || tag === PascalName;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
function findVueComponentImports(ast, bindingComponents) {
|
|
159
|
+
const imports = [];
|
|
160
|
+
for (let i = 0; i < ast.length; i++) {
|
|
161
|
+
const node = ast[i];
|
|
162
|
+
if (!(0, types_1.isImportDeclaration)(node)) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (node.specifiers.length !== 1) {
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
const { name } = node.specifiers[0].local;
|
|
169
|
+
if (!bindingComponents[name]) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
imports.push({ tag: bindingComponents[name].tag, import: node });
|
|
173
|
+
}
|
|
174
|
+
return imports;
|
|
175
|
+
}
|