@varlet/cli 2.22.1 → 2.22.2

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.
@@ -3,4 +3,5 @@ export declare function replaceExportToDeclare(script: string): string;
3
3
  export declare function injectExport(script: string): string;
4
4
  export declare function injectScopeId(script: string, scopeId: string): string;
5
5
  export declare function injectRender(script: string, render: string): string;
6
+ export declare function getFsPath(sfc: string, fsFile: string): string;
6
7
  export declare function compileSFC(sfc: string): Promise<void>;
@@ -1,11 +1,14 @@
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, compileScript as compileScriptSFC } from '@vue/compiler-sfc';
4
+ import { parse as parseSFC, compileTemplate, compileStyle, compileScript as compileScriptSFC, registerTS, } from '@vue/compiler-sfc';
5
5
  import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
6
+ import { CWD, SRC_DIR, ES_DIR } from '../shared/constant.js';
6
7
  import { compileScript, getScriptExtname } from './compileScript.js';
8
+ import ts from 'typescript';
7
9
  import { clearEmptyLine, compileLess, extractStyleDependencies, normalizeStyleDependency, STYLE_IMPORT_RE, } from './compileStyle.js';
8
- const { readFile, writeFileSync } = fse;
10
+ const { readFile, existsSync, readFileSync, writeFileSync } = fse;
11
+ registerTS(() => ts);
9
12
  const EXPORT = 'export default';
10
13
  const SFC = '__sfc__';
11
14
  const SFC_DECLARE = `const ${SFC} = `;
@@ -31,6 +34,12 @@ export function injectRender(script, render) {
31
34
  script += `\n${SFC}.render = ${RENDER}`;
32
35
  return script;
33
36
  }
37
+ export function getFsPath(sfc, fsFile) {
38
+ if (fsFile === 'tsconfig.json' || fsFile.startsWith('node_modules')) {
39
+ return resolve(CWD, fsFile);
40
+ }
41
+ return resolve(sfc.replace(ES_DIR, SRC_DIR), '..', fsFile);
42
+ }
34
43
  export async function compileSFC(sfc) {
35
44
  const sources = await readFile(sfc, 'utf-8');
36
45
  const id = hash(sources);
@@ -40,7 +49,14 @@ export async function compileSFC(sfc) {
40
49
  let bindingMetadata;
41
50
  if (script || scriptSetup) {
42
51
  if (scriptSetup) {
43
- const { content, bindings } = compileScriptSFC(descriptor, { id });
52
+ const { content, bindings } = compileScriptSFC(descriptor, {
53
+ id,
54
+ // issue https://github.com/varletjs/varlet/issues/1458
55
+ fs: {
56
+ fileExists: (file) => existsSync(getFsPath(sfc, file)),
57
+ readFile: (file) => readFileSync(getFsPath(sfc, file), 'utf-8'),
58
+ },
59
+ });
44
60
  scriptContent = content;
45
61
  bindingMetadata = bindings;
46
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "2.22.1",
3
+ "version": "2.22.2",
4
4
  "type": "module",
5
5
  "description": "cli of varlet",
6
6
  "bin": {
@@ -64,8 +64,8 @@
64
64
  "slash": "^3.0.0",
65
65
  "typescript": "^5.1.5",
66
66
  "webfont": "11.2.26",
67
- "@varlet/shared": "2.22.1",
68
- "@varlet/vite-plugins": "2.22.1"
67
+ "@varlet/shared": "2.22.2",
68
+ "@varlet/vite-plugins": "2.22.2"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__core": "^7.20.1",
@@ -80,9 +80,9 @@
80
80
  "@types/semver": "^7.3.9",
81
81
  "@types/sharp": "0.31.1",
82
82
  "rimraf": "^5.0.1",
83
- "@varlet/ui": "2.22.1",
84
- "@varlet/icons": "2.22.1",
85
- "@varlet/touch-emulator": "2.22.1"
83
+ "@varlet/icons": "2.22.2",
84
+ "@varlet/touch-emulator": "2.22.2",
85
+ "@varlet/ui": "2.22.2"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "@vue/runtime-core": "3.4.3",
@@ -95,9 +95,9 @@
95
95
  "lodash-es": "^4.17.21",
96
96
  "vue": "3.4.3",
97
97
  "vue-router": "4.2.0",
98
- "@varlet/ui": "2.22.1",
99
- "@varlet/icons": "2.22.1",
100
- "@varlet/touch-emulator": "2.22.1"
98
+ "@varlet/icons": "2.22.2",
99
+ "@varlet/touch-emulator": "2.22.2",
100
+ "@varlet/ui": "2.22.2"
101
101
  },
102
102
  "scripts": {
103
103
  "dev": "tsc --watch",