@varlet/cli 2.7.3-alpha.1675176726761 → 2.7.3-alpha.1675189320554
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.
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare function replaceExportToDeclare(script: string): string;
|
|
2
|
+
export declare function injectExport(script: string): string;
|
|
3
|
+
export declare function injectScopeId(script: string, scopeId: string): string;
|
|
1
4
|
export declare function injectRender(script: string, render: string): string;
|
|
2
5
|
export declare function compileSFC(sfc: string): Promise<void>;
|
|
@@ -1,58 +1,71 @@
|
|
|
1
1
|
import fse from 'fs-extra';
|
|
2
2
|
import hash from 'hash-sum';
|
|
3
3
|
import { parse, resolve } from 'path';
|
|
4
|
-
import { parse as parseSFC, compileTemplate, compileStyle } from '@vue/compiler-sfc';
|
|
4
|
+
import { parse as parseSFC, compileTemplate, compileStyle, compileScript as compileScriptSFC } from '@vue/compiler-sfc';
|
|
5
5
|
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
6
6
|
import { compileScript, getScriptExtname } from './compileScript.js';
|
|
7
7
|
import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
|
|
8
|
-
import logger from '../shared/logger.js';
|
|
9
8
|
const { readFile, writeFileSync } = fse;
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const EXPORT = 'export default';
|
|
10
|
+
const SFC = '__sfc__';
|
|
11
|
+
const SFC_DECLARE = `const ${SFC} = `;
|
|
12
|
+
const RENDER = '__render__';
|
|
13
|
+
export function replaceExportToDeclare(script) {
|
|
14
|
+
return script.replace(EXPORT, SFC_DECLARE);
|
|
15
|
+
}
|
|
16
|
+
export function injectExport(script) {
|
|
17
|
+
script += `\n${EXPORT} ${SFC}`;
|
|
18
|
+
return script;
|
|
19
|
+
}
|
|
20
|
+
export function injectScopeId(script, scopeId) {
|
|
21
|
+
script += `\n${SFC}.__scopeId = '${scopeId}'`;
|
|
22
|
+
return script;
|
|
23
|
+
}
|
|
12
24
|
export function injectRender(script, render) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
if (NORMAL_EXPORT_START_RE.test(script.trim())) {
|
|
19
|
-
return script.trim().replace(NORMAL_EXPORT_START_RE, `${render}\nexport default {
|
|
20
|
-
render,\
|
|
21
|
-
`);
|
|
22
|
-
}
|
|
25
|
+
script = script.trim();
|
|
26
|
+
render = render.replace('export function render', `function ${RENDER}`);
|
|
27
|
+
script = script.replace(SFC_DECLARE, `${render}\n${SFC_DECLARE}`);
|
|
28
|
+
script += `\n${SFC}.render = ${RENDER}`;
|
|
23
29
|
return script;
|
|
24
30
|
}
|
|
25
31
|
export async function compileSFC(sfc) {
|
|
26
32
|
const sources = await readFile(sfc, 'utf-8');
|
|
33
|
+
const id = hash(sources);
|
|
27
34
|
const { descriptor } = parseSFC(sources, { sourceMap: false });
|
|
28
35
|
const { script, scriptSetup, template, styles } = descriptor;
|
|
29
|
-
if (scriptSetup) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
if (script || scriptSetup) {
|
|
37
|
+
let scriptContent;
|
|
38
|
+
let bindingMetadata;
|
|
39
|
+
if (scriptSetup) {
|
|
40
|
+
const { content, bindings } = compileScriptSFC(descriptor, { id });
|
|
41
|
+
scriptContent = content;
|
|
42
|
+
bindingMetadata = bindings;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
// script only
|
|
46
|
+
scriptContent = script.content;
|
|
47
|
+
}
|
|
48
|
+
scriptContent = replaceExportToDeclare(scriptContent);
|
|
49
|
+
// scoped
|
|
50
|
+
const hasScope = styles.some((style) => style.scoped);
|
|
51
|
+
const scopeId = hasScope ? `data-v-${id}` : '';
|
|
52
|
+
if (template) {
|
|
53
|
+
const render = compileTemplate({
|
|
42
54
|
id,
|
|
43
55
|
source: template.content,
|
|
44
56
|
filename: sfc,
|
|
45
57
|
compilerOptions: {
|
|
46
58
|
scopeId,
|
|
59
|
+
bindingMetadata,
|
|
47
60
|
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
}).code;
|
|
62
|
+
scriptContent = injectRender(scriptContent, render);
|
|
63
|
+
}
|
|
64
|
+
if (scopeId) {
|
|
65
|
+
scriptContent = injectScopeId(scriptContent, scopeId);
|
|
53
66
|
}
|
|
54
|
-
|
|
55
|
-
await compileScript(
|
|
67
|
+
scriptContent = injectExport(scriptContent);
|
|
68
|
+
await compileScript(scriptContent, sfc);
|
|
56
69
|
// style
|
|
57
70
|
for (let index = 0; index < styles.length; index++) {
|
|
58
71
|
const style = styles[index];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.7.3-alpha.
|
|
3
|
+
"version": "2.7.3-alpha.1675189320554",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"vite": "4.0.4",
|
|
69
69
|
"vue": "3.2.25",
|
|
70
70
|
"vue-jest": "^5.0.0-alpha.8",
|
|
71
|
-
"@varlet/vite-plugins": "2.7.3-alpha.
|
|
72
|
-
"@varlet/shared": "2.7.3-alpha.
|
|
71
|
+
"@varlet/vite-plugins": "2.7.3-alpha.1675189320554",
|
|
72
|
+
"@varlet/shared": "2.7.3-alpha.1675189320554"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/babel__core": "^7.1.12",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"@types/semver": "^7.3.9",
|
|
83
83
|
"@types/inquirer": "^9.0.2",
|
|
84
84
|
"@types/sharp": "0.31.1",
|
|
85
|
-
"@varlet/icons": "2.7.3-alpha.
|
|
86
|
-
"@varlet/touch-emulator": "2.7.3-alpha.
|
|
85
|
+
"@varlet/icons": "2.7.3-alpha.1675189320554",
|
|
86
|
+
"@varlet/touch-emulator": "2.7.3-alpha.1675189320554"
|
|
87
87
|
},
|
|
88
88
|
"peerDependencies": {
|
|
89
89
|
"@vue/runtime-core": "3.2.16",
|
|
@@ -93,8 +93,8 @@
|
|
|
93
93
|
"lodash-es": "^4.17.21",
|
|
94
94
|
"vue": "3.2.25",
|
|
95
95
|
"vue-router": "4.0.12",
|
|
96
|
-
"@varlet/icons": "2.7.3-alpha.
|
|
97
|
-
"@varlet/touch-emulator": "2.7.3-alpha.
|
|
96
|
+
"@varlet/icons": "2.7.3-alpha.1675189320554",
|
|
97
|
+
"@varlet/touch-emulator": "2.7.3-alpha.1675189320554"
|
|
98
98
|
},
|
|
99
99
|
"scripts": {
|
|
100
100
|
"dev": "tsc --watch",
|