@varlet/cli 2.7.3-alpha.1675189320554 → 2.7.3-alpha.1675238644507

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,3 +1,4 @@
1
+ export declare function declareEmptySFC(): string;
1
2
  export declare function replaceExportToDeclare(script: string): string;
2
3
  export declare function injectExport(script: string): string;
3
4
  export declare function injectScopeId(script: string, scopeId: string): string;
@@ -10,6 +10,9 @@ const EXPORT = 'export default';
10
10
  const SFC = '__sfc__';
11
11
  const SFC_DECLARE = `const ${SFC} = `;
12
12
  const RENDER = '__render__';
13
+ export function declareEmptySFC() {
14
+ return `${SFC_DECLARE}{}\n`;
15
+ }
13
16
  export function replaceExportToDeclare(script) {
14
17
  return script.replace(EXPORT, SFC_DECLARE);
15
18
  }
@@ -33,9 +36,9 @@ export async function compileSFC(sfc) {
33
36
  const id = hash(sources);
34
37
  const { descriptor } = parseSFC(sources, { sourceMap: false });
35
38
  const { script, scriptSetup, template, styles } = descriptor;
39
+ let scriptContent;
40
+ let bindingMetadata;
36
41
  if (script || scriptSetup) {
37
- let scriptContent;
38
- let bindingMetadata;
39
42
  if (scriptSetup) {
40
43
  const { content, bindings } = compileScriptSFC(descriptor, { id });
41
44
  scriptContent = content;
@@ -46,45 +49,48 @@ export async function compileSFC(sfc) {
46
49
  scriptContent = script.content;
47
50
  }
48
51
  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({
54
- id,
55
- source: template.content,
56
- filename: sfc,
57
- compilerOptions: {
58
- scopeId,
59
- bindingMetadata,
60
- },
61
- }).code;
62
- scriptContent = injectRender(scriptContent, render);
63
- }
64
- if (scopeId) {
65
- scriptContent = injectScopeId(scriptContent, scopeId);
66
- }
67
- scriptContent = injectExport(scriptContent);
68
- await compileScript(scriptContent, sfc);
69
- // style
70
- for (let index = 0; index < styles.length; index++) {
71
- const style = styles[index];
72
- const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
73
- const { base, dir } = parse(file);
74
- const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
75
- const cssFile = resolve(dir, `./style/index${getScriptExtname()}`);
76
- let { code } = compileStyle({
77
- source: style.content,
78
- filename: file,
79
- id: scopeId,
80
- scoped: style.scoped,
81
- });
82
- code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
83
- writeFileSync(file, clearEmptyLine(code), 'utf-8');
84
- smartAppendFileSync(cssFile, `import '${dependencyPath}.css'\n`);
85
- if (style.lang === 'less') {
86
- await compileLess(file);
87
- }
52
+ }
53
+ if (!scriptContent) {
54
+ scriptContent = declareEmptySFC();
55
+ }
56
+ // scoped
57
+ const hasScope = styles.some((style) => style.scoped);
58
+ const scopeId = hasScope ? `data-v-${id}` : '';
59
+ if (template) {
60
+ const render = compileTemplate({
61
+ id,
62
+ source: template.content,
63
+ filename: sfc,
64
+ compilerOptions: {
65
+ scopeId,
66
+ bindingMetadata,
67
+ },
68
+ }).code;
69
+ scriptContent = injectRender(scriptContent, render);
70
+ }
71
+ if (scopeId) {
72
+ scriptContent = injectScopeId(scriptContent, scopeId);
73
+ }
74
+ scriptContent = injectExport(scriptContent);
75
+ await compileScript(scriptContent, sfc);
76
+ // style
77
+ for (let index = 0; index < styles.length; index++) {
78
+ const style = styles[index];
79
+ const file = replaceExt(sfc, `Sfc${index || ''}.${style.lang || 'css'}`);
80
+ const { base, dir } = parse(file);
81
+ const dependencyPath = normalizeStyleDependency(base, STYLE_IMPORT_RE);
82
+ const cssFile = resolve(dir, `./style/index${getScriptExtname()}`);
83
+ let { code } = compileStyle({
84
+ source: style.content,
85
+ filename: file,
86
+ id: scopeId,
87
+ scoped: style.scoped,
88
+ });
89
+ code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
90
+ writeFileSync(file, clearEmptyLine(code), 'utf-8');
91
+ smartAppendFileSync(cssFile, `import '${dependencyPath}.css'\n`);
92
+ if (style.lang === 'less') {
93
+ await compileLess(file);
88
94
  }
89
95
  }
90
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.7.3-alpha.1675189320554",
3
+ "version": "2.7.3-alpha.1675238644507",
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.1675189320554",
72
- "@varlet/shared": "2.7.3-alpha.1675189320554"
71
+ "@varlet/vite-plugins": "2.7.3-alpha.1675238644507",
72
+ "@varlet/shared": "2.7.3-alpha.1675238644507"
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.1675189320554",
86
- "@varlet/touch-emulator": "2.7.3-alpha.1675189320554"
85
+ "@varlet/icons": "2.7.3-alpha.1675238644507",
86
+ "@varlet/touch-emulator": "2.7.3-alpha.1675238644507"
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.1675189320554",
97
- "@varlet/touch-emulator": "2.7.3-alpha.1675189320554"
96
+ "@varlet/icons": "2.7.3-alpha.1675238644507",
97
+ "@varlet/touch-emulator": "2.7.3-alpha.1675238644507"
98
98
  },
99
99
  "scripts": {
100
100
  "dev": "tsc --watch",
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <button class="var-button" :style="{ background: color }">
2
+ <button class="var-button" :style="{ background: color }" @click="handleClick">
3
3
  <slot />
4
4
  </button>
5
5
  </template>
@@ -18,7 +18,10 @@ export default defineComponent({
18
18
  },
19
19
  },
20
20
  setup(props) {
21
- const handleClick = (e: Event) => props.onClick?.(e)
21
+ const handleClick = (e: Event) => {
22
+ props.onClick?.(e)
23
+ }
24
+
22
25
  return {
23
26
  handleClick,
24
27
  }
@@ -18,11 +18,9 @@ export default defineComponent({
18
18
  const { color } = props
19
19
 
20
20
  return (
21
- <>
22
- <button class="var-button" style={{ background: color }} onClick={handleClick}>
23
- {slots.default?.()}
24
- </button>
25
- </>
21
+ <button class="var-button" style={{ background: color }} onClick={handleClick}>
22
+ {slots.default?.()}
23
+ </button>
26
24
  )
27
25
  }
28
26
  },
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <button class="var-button" :style="{ background: color }">
2
+ <button class="var-button" :style="{ background: color }" @click="handleClick">
3
3
  {{ pack.button }}
4
4
  <slot />
5
5
  </button>
@@ -22,7 +22,9 @@ export default defineComponent({
22
22
  },
23
23
  },
24
24
  setup(props) {
25
- const handleClick = (e: Event) => props.onClick?.(e)
25
+ const handleClick = (e: Event) => {
26
+ props.onClick?.(e)
27
+ }
26
28
 
27
29
  return {
28
30
  pack,
@@ -15,7 +15,9 @@ export default defineComponent({
15
15
  },
16
16
  },
17
17
  setup(props, { slots }) {
18
- const handleClick = (e: Event) => props.onClick?.(e)
18
+ const handleClick = (e: Event) => {
19
+ props.onClick?.(e)
20
+ }
19
21
 
20
22
  return () => {
21
23
  const { color } = props