@varlet/cli 2.7.0-alpha.1673640473187 → 2.7.0-alpha.1673714503631
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/README.en-US.md +1 -29
- package/README.md +2 -30
- package/lib/node/commands/compile.js +2 -4
- package/lib/node/compiler/compileModule.js +0 -5
- package/lib/node/compiler/compileSFC.js +1 -3
- package/lib/node/compiler/compileScript.d.ts +0 -1
- package/lib/node/compiler/compileScript.js +6 -20
- package/lib/node/compiler/compileStyle.d.ts +0 -2
- package/lib/node/compiler/compileStyle.js +1 -4
- package/package.json +7 -7
package/README.en-US.md
CHANGED
|
@@ -61,7 +61,7 @@ Also refer to `@varlet/ui` [varlet.config.mjs](https://github.com/varletjs/varle
|
|
|
61
61
|
If you want to insert other pages into the component library, you can create a `pages` folder in the project root directory to write a vue component to generate other pages.
|
|
62
62
|
The directory structure is as follows:
|
|
63
63
|
|
|
64
|
-
```
|
|
64
|
+
```text
|
|
65
65
|
|-- varlet-ui
|
|
66
66
|
|-- src
|
|
67
67
|
|-- docs
|
|
@@ -77,7 +77,6 @@ The directory structure is as follows:
|
|
|
77
77
|
|-- zh-CN.ts
|
|
78
78
|
|-- en-US.ts
|
|
79
79
|
|-- index.vue
|
|
80
|
-
|
|
81
80
|
```
|
|
82
81
|
|
|
83
82
|
The resulting route is as follows:
|
|
@@ -197,30 +196,3 @@ varlet-cli create
|
|
|
197
196
|
|
|
198
197
|
- 1.`npm` repository registry must set to `npm` official mirror
|
|
199
198
|
- 2.Execute `npm login` to log in
|
|
200
|
-
|
|
201
|
-
### Module Compatible
|
|
202
|
-
|
|
203
|
-
Some external dependencies may need to be compatible with module syntax to achieve the purpose of compiling correctly to `commonjs` and `esmodule`. For example, the wording of `esmodule` of `dayjs` is
|
|
204
|
-
|
|
205
|
-
```js
|
|
206
|
-
import dayjs from 'dayjs/esm'
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
In order to build `commonjs`, the writing method is
|
|
210
|
-
|
|
211
|
-
```js
|
|
212
|
-
import * as dayjs from 'dayjs'
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
In the project, we embrace the first way of writing the `esmodule` module, and make the following configuration for adaptation
|
|
216
|
-
|
|
217
|
-
```js
|
|
218
|
-
// varlet.config.mjs
|
|
219
|
-
import { defineConfig } from '@varlet/cli'
|
|
220
|
-
|
|
221
|
-
export default defineConfig({
|
|
222
|
-
moduleCompatible: {
|
|
223
|
-
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
```
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ varlet-cli gen
|
|
|
59
59
|
如果想在组件库中插入其他页面,可以在项目根目录下的创建 `pages` 文件夹编写 vue 组件, 用来生成其他的页面。
|
|
60
60
|
目录结构如下:
|
|
61
61
|
|
|
62
|
-
```
|
|
62
|
+
```text
|
|
63
63
|
|-- varlet-ui
|
|
64
64
|
|-- src
|
|
65
65
|
|-- docs
|
|
@@ -75,7 +75,6 @@ varlet-cli gen
|
|
|
75
75
|
|-- zh-CN.ts
|
|
76
76
|
|-- en-US.ts
|
|
77
77
|
|-- index.vue
|
|
78
|
-
|
|
79
78
|
```
|
|
80
79
|
|
|
81
80
|
生成的路由如下:
|
|
@@ -194,31 +193,4 @@ varlet-cli create
|
|
|
194
193
|
### 发布前注意
|
|
195
194
|
|
|
196
195
|
1. `npm` 的仓库源必须指向 `npm` 官方镜像
|
|
197
|
-
2. 执行 `npm login` 进行登录
|
|
198
|
-
|
|
199
|
-
### 模块适配对象
|
|
200
|
-
|
|
201
|
-
一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到 `commonjs` 和 `esmodule` 的目的,例如 `dayjs` 的 `esmodule` 写法是
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
import dayjs from 'dayjs/esm'
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
而为了构建 `commonjs` 时的写法是
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
import * as dayjs from 'dayjs'
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
在项目中我们拥抱 `esmodule` 模块使用第一种写法,并做如下配置进行适配
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
// varlet.config.mjs
|
|
217
|
-
import { defineConfig } from '@varlet/cli'
|
|
218
|
-
|
|
219
|
-
export default defineConfig({
|
|
220
|
-
moduleCompatible: {
|
|
221
|
-
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
222
|
-
}
|
|
223
|
-
})
|
|
224
|
-
```
|
|
196
|
+
2. 执行 `npm login` 进行登录
|
|
@@ -2,7 +2,7 @@ import ora from 'ora';
|
|
|
2
2
|
import logger from '../shared/logger.js';
|
|
3
3
|
import fse from 'fs-extra';
|
|
4
4
|
import { ES_DIR, HL_DIR, LIB_DIR, UMD_DIR } from '../shared/constant.js';
|
|
5
|
-
import { compileModule } from '../compiler/compileModule.js';
|
|
5
|
+
import { compileBundle, compileModule } from '../compiler/compileModule.js';
|
|
6
6
|
import { compileTemplateHighlight } from '../compiler/compileTemplateHighlight.js';
|
|
7
7
|
import { compileTypes } from '../compiler/compileTypes.js';
|
|
8
8
|
const { remove } = fse;
|
|
@@ -24,10 +24,8 @@ export async function compile() {
|
|
|
24
24
|
process.env.NODE_ENV = 'compile';
|
|
25
25
|
await removeDir();
|
|
26
26
|
await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
|
|
27
|
-
process.env.TARGET_MODULE = 'module';
|
|
28
27
|
process.env.BABEL_MODULE = 'module';
|
|
29
28
|
await runTask('module', compileModule);
|
|
30
29
|
process.env.BABEL_MODULE = '';
|
|
31
|
-
|
|
32
|
-
await runTask('bundle', compileModule);
|
|
30
|
+
await runTask('bundle', compileBundle);
|
|
33
31
|
}
|
|
@@ -56,11 +56,6 @@ export async function compileFile(file) {
|
|
|
56
56
|
isDir(file) && (await compileDir(file));
|
|
57
57
|
}
|
|
58
58
|
export async function compileModule() {
|
|
59
|
-
const targetModule = process.env.TARGET_MODULE;
|
|
60
|
-
if (targetModule === 'bundle') {
|
|
61
|
-
await compileBundle();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
59
|
const dest = ES_DIR;
|
|
65
60
|
await copy(SRC_DIR, dest);
|
|
66
61
|
const moduleDir = await readdir(dest);
|
|
@@ -68,9 +68,7 @@ export async function compileSFC(sfc) {
|
|
|
68
68
|
});
|
|
69
69
|
code = extractStyleDependencies(file, code, STYLE_IMPORT_RE);
|
|
70
70
|
writeFileSync(file, clearEmptyLine(code), 'utf-8');
|
|
71
|
-
smartAppendFileSync(cssFile,
|
|
72
|
-
? `require('${dependencyPath}.css')\n`
|
|
73
|
-
: `import '${dependencyPath}.css'\n`);
|
|
71
|
+
smartAppendFileSync(cssFile, `import '${dependencyPath}.css'\n`);
|
|
74
72
|
if (style.lang === 'less') {
|
|
75
73
|
await compileLess(file);
|
|
76
74
|
}
|
|
@@ -7,7 +7,6 @@ export declare const scriptIndexes: string[];
|
|
|
7
7
|
export declare const styleIndexes: string[];
|
|
8
8
|
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
9
9
|
export declare const resolveDependence: (file: string, script: string) => string;
|
|
10
|
-
export declare const moduleCompatible: (script: string) => Promise<string>;
|
|
11
10
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
12
11
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
13
12
|
export declare function getScriptExtname(): string;
|
|
@@ -2,10 +2,8 @@ import fse from 'fs-extra';
|
|
|
2
2
|
import { transformAsync } from '@babel/core';
|
|
3
3
|
import { bigCamelize } from '@varlet/shared';
|
|
4
4
|
import { getVersion, isDir, replaceExt } from '../shared/fsUtils.js';
|
|
5
|
-
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE
|
|
5
|
+
import { extractStyleDependencies, IMPORT_CSS_RE, IMPORT_LESS_RE } from './compileStyle.js';
|
|
6
6
|
import { resolve, extname, dirname } from 'path';
|
|
7
|
-
import { get } from 'lodash-es';
|
|
8
|
-
import { getVarletConfig } from '../config/varlet.config.js';
|
|
9
7
|
const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExistsSync } = fse;
|
|
10
8
|
// https://regexr.com/765a4
|
|
11
9
|
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
@@ -40,7 +38,7 @@ export const resolveDependence = (file, script) => {
|
|
|
40
38
|
}
|
|
41
39
|
if (ext) {
|
|
42
40
|
if (scriptExtNames.includes(ext)) {
|
|
43
|
-
// e.g. './a.vue' -> './a.
|
|
41
|
+
// e.g. './a.vue' -> './a.mjs'
|
|
44
42
|
return done(dependence.replace(ext, scriptExtname));
|
|
45
43
|
}
|
|
46
44
|
if (styleExtNames.includes(ext)) {
|
|
@@ -49,7 +47,7 @@ export const resolveDependence = (file, script) => {
|
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
if (!ext) {
|
|
52
|
-
// e.g. ../button/props -> ../button/props.
|
|
50
|
+
// e.g. ../button/props -> ../button/props.mjs
|
|
53
51
|
const matchedScript = tryMatchExtname(targetDependenceFile, scriptExtNames);
|
|
54
52
|
if (matchedScript) {
|
|
55
53
|
return done(`${dependence}${scriptExtname}`);
|
|
@@ -64,7 +62,7 @@ export const resolveDependence = (file, script) => {
|
|
|
64
62
|
const files = readdirSync(targetDependenceFile);
|
|
65
63
|
const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
|
|
66
64
|
if (hasScriptIndex) {
|
|
67
|
-
// e.g. -> ../button/index.
|
|
65
|
+
// e.g. -> ../button/index.mjs
|
|
68
66
|
return done(`${dependence}/index${scriptExtname}`);
|
|
69
67
|
}
|
|
70
68
|
const hasStyleIndex = files.some((file) => styleIndexes.some((name) => file.endsWith(name)));
|
|
@@ -80,26 +78,14 @@ export const resolveDependence = (file, script) => {
|
|
|
80
78
|
.replace(EXPORT_FROM_DEPENDENCE_RE, replacer)
|
|
81
79
|
.replace(IMPORT_DEPENDENCE_RE, replacer);
|
|
82
80
|
};
|
|
83
|
-
export const moduleCompatible = async (script) => {
|
|
84
|
-
const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
|
|
85
|
-
Object.keys(moduleCompatible).forEach((esm) => {
|
|
86
|
-
const commonjs = moduleCompatible[esm];
|
|
87
|
-
script = script.replace(esm, commonjs);
|
|
88
|
-
});
|
|
89
|
-
return script;
|
|
90
|
-
};
|
|
91
81
|
export async function compileScript(script, file) {
|
|
92
|
-
const targetModule = process.env.TARGET_MODULE;
|
|
93
|
-
if (targetModule === 'commonjs') {
|
|
94
|
-
script = await moduleCompatible(script);
|
|
95
|
-
}
|
|
96
82
|
let { code } = (await transformAsync(script, {
|
|
97
83
|
filename: file,
|
|
98
84
|
}));
|
|
99
85
|
if (code) {
|
|
100
86
|
code = resolveDependence(file, code);
|
|
101
|
-
code = extractStyleDependencies(file, code,
|
|
102
|
-
code = extractStyleDependencies(file, code,
|
|
87
|
+
code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
|
|
88
|
+
code = extractStyleDependencies(file, code, IMPORT_LESS_RE);
|
|
103
89
|
removeSync(file);
|
|
104
90
|
writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
|
|
105
91
|
}
|
|
@@ -2,8 +2,6 @@ export declare const EMPTY_SPACE_RE: RegExp;
|
|
|
2
2
|
export declare const EMPTY_LINE_RE: RegExp;
|
|
3
3
|
export declare const IMPORT_CSS_RE: RegExp;
|
|
4
4
|
export declare const IMPORT_LESS_RE: RegExp;
|
|
5
|
-
export declare const REQUIRE_CSS_RE: RegExp;
|
|
6
|
-
export declare const REQUIRE_LESS_RE: RegExp;
|
|
7
5
|
export declare const STYLE_IMPORT_RE: RegExp;
|
|
8
6
|
export declare const clearEmptyLine: (s: string) => string;
|
|
9
7
|
export declare function normalizeStyleDependency(styleImport: string, reg: RegExp): string;
|
|
@@ -10,8 +10,6 @@ export const EMPTY_SPACE_RE = /[\s]+/g;
|
|
|
10
10
|
export const EMPTY_LINE_RE = /[\n\r]*/g;
|
|
11
11
|
export const IMPORT_CSS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.css)['"]\s*;?(?!\s*['"`])/g;
|
|
12
12
|
export const IMPORT_LESS_RE = /(?<!['"`])import\s+['"](\.{1,2}\/.+\.less)['"]\s*;?(?!\s*['"`])/g;
|
|
13
|
-
export const REQUIRE_CSS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.css)['"]\s*\);?(?!\s*['"`])/g;
|
|
14
|
-
export const REQUIRE_LESS_RE = /(?<!['"`])require\(\s*['"](\.{1,2}\/.+\.less)['"]\s*\);?(?!\s*['"`])/g;
|
|
15
13
|
export const STYLE_IMPORT_RE = /@import\s+['"](.+)['"]\s*;/g;
|
|
16
14
|
export const clearEmptyLine = (s) => s.replace(EMPTY_LINE_RE, '').replace(EMPTY_SPACE_RE, ' ');
|
|
17
15
|
export function normalizeStyleDependency(styleImport, reg) {
|
|
@@ -26,10 +24,9 @@ export function extractStyleDependencies(file, code, styleReg) {
|
|
|
26
24
|
var _a;
|
|
27
25
|
const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
|
|
28
26
|
const cssFile = resolve(parse(file).dir, `./style/index${getScriptExtname()}`);
|
|
29
|
-
const targetModule = process.env.TARGET_MODULE;
|
|
30
27
|
styleImports.forEach((styleImport) => {
|
|
31
28
|
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
|
32
|
-
smartAppendFileSync(cssFile,
|
|
29
|
+
smartAppendFileSync(cssFile, `import '${normalizedPath}.css'\n`);
|
|
33
30
|
});
|
|
34
31
|
return code.replace(styleReg, '');
|
|
35
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.7.0-alpha.
|
|
3
|
+
"version": "2.7.0-alpha.1673714503631",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"vite": "4.0.4",
|
|
67
67
|
"vue": "3.2.25",
|
|
68
68
|
"vue-jest": "^5.0.0-alpha.8",
|
|
69
|
-
"@varlet/vite-plugins": "2.7.0-alpha.
|
|
70
|
-
"@varlet/shared": "2.7.0-alpha.
|
|
69
|
+
"@varlet/vite-plugins": "2.7.0-alpha.1673714503631",
|
|
70
|
+
"@varlet/shared": "2.7.0-alpha.1673714503631"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/babel__core": "^7.1.12",
|
|
@@ -79,8 +79,8 @@
|
|
|
79
79
|
"@types/node": "^18.7.20",
|
|
80
80
|
"@types/semver": "^7.3.9",
|
|
81
81
|
"@types/inquirer": "^9.0.2",
|
|
82
|
-
"@varlet/
|
|
83
|
-
"@varlet/
|
|
82
|
+
"@varlet/icons": "2.7.0-alpha.1673714503631",
|
|
83
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673714503631"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"@vue/runtime-core": "3.2.16",
|
|
@@ -90,8 +90,8 @@
|
|
|
90
90
|
"lodash-es": "^4.17.21",
|
|
91
91
|
"vue": "3.2.25",
|
|
92
92
|
"vue-router": "4.0.12",
|
|
93
|
-
"@varlet/
|
|
94
|
-
"@varlet/
|
|
93
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673714503631",
|
|
94
|
+
"@varlet/icons": "2.7.0-alpha.1673714503631"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"dev": "tsc --watch",
|