@varlet/cli 1.23.4-alpha.2 → 1.23.5
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/CHANGELOG.md +18 -0
- package/README.en-US.md +28 -2
- package/README.md +26 -0
- package/lib/compiler/compileModule.js +2 -0
- package/lib/compiler/compileScript.d.ts +5 -0
- package/lib/compiler/compileScript.js +38 -11
- package/lib/compiler/compileTypes.d.ts +1 -0
- package/lib/compiler/compileTypes.js +5 -1
- package/lib/config/vite.config.js +5 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.23.5](https://github.com/haoziqaq/varlet/compare/v1.23.4...v1.23.5) (2021-11-21)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **cli:** add module moduleCompatible option in varlet.config.js ([0b1d95f](https://github.com/haoziqaq/varlet/commit/0b1d95fc740a225240ee3f28e06015f4538b2304))
|
|
12
|
+
* **cli:** expose lib folder ([2a8848a](https://github.com/haoziqaq/varlet/commit/2a8848a6f064aa91d56875ba467c46da79589a79))
|
|
13
|
+
* **cli:** fix commonjs compiler ([c5c2b12](https://github.com/haoziqaq/varlet/commit/c5c2b12f163bed130b3c6c0ee0eb805fe4a015f1))
|
|
14
|
+
* **cli:** fix inline css plugin ([3e8b7b4](https://github.com/haoziqaq/varlet/commit/3e8b7b4e5489bc67dd38f8787477f07e2a13e7ac))
|
|
15
|
+
* **cli/compile:** add commonjs bundle ([4a424d4](https://github.com/haoziqaq/varlet/commit/4a424d4c066f7de69cbf561a5bc9279862739637))
|
|
16
|
+
* **cli/compile:** add match commonjs script extname function ([2b5b1bd](https://github.com/haoziqaq/varlet/commit/2b5b1bde5e1c16d4e58ce2a100ae4a1a3cc428ce))
|
|
17
|
+
* **cli/compile:** fix compile module readdir ([9c3ad08](https://github.com/haoziqaq/varlet/commit/9c3ad08410009e50b288f033b8fdbe10a8c01160))
|
|
18
|
+
* **ui/popup,input:** support nuxt ([def81ef](https://github.com/haoziqaq/varlet/commit/def81ef821a8ce679287702316bd98ca363bc7f4))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
6
24
|
## [1.23.3](https://github.com/haoziqaq/varlet/compare/v1.23.2...v1.23.3) (2021-11-20)
|
|
7
25
|
|
|
8
26
|
|
package/README.en-US.md
CHANGED
|
@@ -55,6 +55,32 @@ The `varlet.config.js` in the project root directory is used to manage the speci
|
|
|
55
55
|
| `analysis` | Document statistics related | _SiteAnalysis_ | `-` |
|
|
56
56
|
| `pc` | PC-side document structure configuration | _SitePC_ | `-` |
|
|
57
57
|
| `mobile` | Mobile document structure configuration | _SiteMobile_ | `-` |
|
|
58
|
+
| `moduleCompatible` | Module compatible config | _Record<string, string>_ | `-` |
|
|
59
|
+
|
|
60
|
+
#### Module Compatible
|
|
61
|
+
|
|
62
|
+
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
|
|
63
|
+
|
|
64
|
+
```js
|
|
65
|
+
import dayjs from 'dayjs/esm'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
In order to build `commonjs`, the writing method is
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import * as dayjs from 'dayjs'
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
In the project, we embrace the first way of writing the `esmodule` module, and make the following configuration for adaptation
|
|
75
|
+
|
|
76
|
+
```js
|
|
77
|
+
// varlet.config.js
|
|
78
|
+
module.exports = {
|
|
79
|
+
moduleCompatible: {
|
|
80
|
+
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
58
84
|
|
|
59
85
|
#### SiteThemes
|
|
60
86
|
|
|
@@ -93,7 +119,7 @@ Code snippets are highlighted, based on [highlight.js](https://highlightjs.org/)
|
|
|
93
119
|
|
|
94
120
|
| Parameter | Description | Type | Default |
|
|
95
121
|
| ----- | -------------- | -------- | ---------- |
|
|
96
|
-
| `style` | highlight
|
|
122
|
+
| `style` | highlight css link | _string_ | `-` |
|
|
97
123
|
|
|
98
124
|
#### SiteAnalysis
|
|
99
125
|
|
|
@@ -101,7 +127,7 @@ Statistics related to buried points
|
|
|
101
127
|
|
|
102
128
|
| Parameter | Description | Type | Default |
|
|
103
129
|
| ----- | -------------- | -------- | ---------- |
|
|
104
|
-
| `baidu` |
|
|
130
|
+
| `baidu` | Baidu statistics script address | _string_ | `-` |
|
|
105
131
|
|
|
106
132
|
#### SitePC, SiteMobile
|
|
107
133
|
|
package/README.md
CHANGED
|
@@ -53,6 +53,32 @@ yarn dev
|
|
|
53
53
|
| `analysis` | 文档统计相关 | _SiteAnalysis_ | `-` |
|
|
54
54
|
| `pc` | pc端文档结构配置 | _SitePC_ | `-` |
|
|
55
55
|
| `mobile` | mobile端文档结构配置 | _SiteMobile_ | `-` |
|
|
56
|
+
| `moduleCompatible` | 模块兼容配置 | _Record<string, string>_ | `-` |
|
|
57
|
+
|
|
58
|
+
#### 模块适配对象
|
|
59
|
+
|
|
60
|
+
一些外部依赖可能需要进行模块语法的适配,以达到可以正确编译到`commonjs`和`esmodule`的目的,例如`dayjs`的`esmodule`写法是
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import dayjs from 'dayjs/esm'
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
而为了构建`commonjs`时的写法是
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
import * as dayjs from 'dayjs'
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
在项目中我们拥抱`esmodule`模块使用第一种写法,并做如下配置进行适配
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
// varlet.config.js
|
|
76
|
+
module.exports = {
|
|
77
|
+
moduleCompatible: {
|
|
78
|
+
"import dayjs from 'dayjs/esm'\n": "import * as dayjs from 'dayjs'\n"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
56
82
|
|
|
57
83
|
#### SiteThemes
|
|
58
84
|
|
|
@@ -47,6 +47,7 @@ var compileScript_1 = require("./compileScript");
|
|
|
47
47
|
var compileStyle_1 = require("./compileStyle");
|
|
48
48
|
var vite_config_1 = require("../config/vite.config");
|
|
49
49
|
var varlet_config_1 = require("../config/varlet.config");
|
|
50
|
+
var compileTypes_1 = require("./compileTypes");
|
|
50
51
|
function compileUMD() {
|
|
51
52
|
return new Promise(function (resolve, reject) {
|
|
52
53
|
var config = (0, vite_config_1.getUMDConfig)((0, varlet_config_1.getVarletConfig)());
|
|
@@ -161,6 +162,7 @@ function compileModule(modules) {
|
|
|
161
162
|
return [4 /*yield*/, (modules === 'commonjs' ? (0, compileScript_1.compileCommonJSEntry)(dest, publicDirs) : (0, compileScript_1.compileESEntry)(dest, publicDirs))];
|
|
162
163
|
case 7:
|
|
163
164
|
_a.sent();
|
|
165
|
+
(0, compileTypes_1.generateReference)(dest);
|
|
164
166
|
return [2 /*return*/];
|
|
165
167
|
}
|
|
166
168
|
});
|
|
@@ -2,10 +2,15 @@ export declare const IMPORT_VUE_PATH_RE: RegExp;
|
|
|
2
2
|
export declare const IMPORT_TS_PATH_RE: RegExp;
|
|
3
3
|
export declare const IMPORT_JSX_PATH_RE: RegExp;
|
|
4
4
|
export declare const IMPORT_TSX_PATH_RE: RegExp;
|
|
5
|
+
export declare const REQUIRE_VUE_PATH_RE: RegExp;
|
|
6
|
+
export declare const REQUIRE_TS_PATH_RE: RegExp;
|
|
7
|
+
export declare const REQUIRE_JSX_PATH_RE: RegExp;
|
|
8
|
+
export declare const REQUIRE_TSX_PATH_RE: RegExp;
|
|
5
9
|
export declare const replaceVueExt: (script: string) => string;
|
|
6
10
|
export declare const replaceTSExt: (script: string) => string;
|
|
7
11
|
export declare const replaceJSXExt: (script: string) => string;
|
|
8
12
|
export declare const replaceTSXExt: (script: string) => string;
|
|
13
|
+
export declare const moduleCompatible: (script: string) => string;
|
|
9
14
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
10
15
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
11
16
|
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -36,36 +36,63 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.compileCommonJSEntry = exports.compileESEntry = exports.compileScriptFile = exports.compileScript = exports.replaceTSXExt = exports.replaceJSXExt = exports.replaceTSExt = exports.replaceVueExt = exports.IMPORT_TSX_PATH_RE = exports.IMPORT_JSX_PATH_RE = exports.IMPORT_TS_PATH_RE = exports.IMPORT_VUE_PATH_RE = void 0;
|
|
39
|
+
exports.compileCommonJSEntry = exports.compileESEntry = exports.compileScriptFile = exports.compileScript = exports.moduleCompatible = exports.replaceTSXExt = exports.replaceJSXExt = exports.replaceTSExt = exports.replaceVueExt = exports.REQUIRE_TSX_PATH_RE = exports.REQUIRE_JSX_PATH_RE = exports.REQUIRE_TS_PATH_RE = exports.REQUIRE_VUE_PATH_RE = exports.IMPORT_TSX_PATH_RE = exports.IMPORT_JSX_PATH_RE = exports.IMPORT_TS_PATH_RE = exports.IMPORT_VUE_PATH_RE = void 0;
|
|
40
40
|
var core_1 = require("@babel/core");
|
|
41
41
|
var fsUtils_1 = require("../shared/fsUtils");
|
|
42
42
|
var fs_extra_1 = require("fs-extra");
|
|
43
43
|
var compileStyle_1 = require("./compileStyle");
|
|
44
44
|
var path_1 = require("path");
|
|
45
|
+
var lodash_1 = require("lodash");
|
|
46
|
+
var varlet_config_1 = require("../config/varlet.config");
|
|
45
47
|
exports.IMPORT_VUE_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]);?(?!\s*['"`])/g;
|
|
46
48
|
exports.IMPORT_TS_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]);?(?!\s*['"`])/g;
|
|
47
49
|
exports.IMPORT_JSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]);?(?!\s*['"`])/g;
|
|
48
50
|
exports.IMPORT_TSX_PATH_RE = /((?<!['"`])import\s+.+from\s+['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]);?(?!\s*['"`])/g;
|
|
51
|
+
exports.REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.vue(\s*['"`]\))(?!\s*['"`])/g;
|
|
52
|
+
exports.REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
|
|
53
|
+
exports.REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
54
|
+
exports.REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
49
55
|
var scriptReplacer = function (_, p1, p2) { return p1 + ".js" + p2; };
|
|
50
|
-
var replaceVueExt = function (script) {
|
|
56
|
+
var replaceVueExt = function (script) {
|
|
57
|
+
return script.replace(exports.IMPORT_VUE_PATH_RE, scriptReplacer).replace(exports.REQUIRE_VUE_PATH_RE, scriptReplacer);
|
|
58
|
+
};
|
|
51
59
|
exports.replaceVueExt = replaceVueExt;
|
|
52
|
-
var replaceTSExt = function (script) {
|
|
60
|
+
var replaceTSExt = function (script) {
|
|
61
|
+
return script.replace(exports.IMPORT_TS_PATH_RE, scriptReplacer).replace(exports.REQUIRE_TS_PATH_RE, scriptReplacer);
|
|
62
|
+
};
|
|
53
63
|
exports.replaceTSExt = replaceTSExt;
|
|
54
|
-
var replaceJSXExt = function (script) {
|
|
64
|
+
var replaceJSXExt = function (script) {
|
|
65
|
+
return script.replace(exports.IMPORT_JSX_PATH_RE, scriptReplacer).replace(exports.REQUIRE_JSX_PATH_RE, scriptReplacer);
|
|
66
|
+
};
|
|
55
67
|
exports.replaceJSXExt = replaceJSXExt;
|
|
56
|
-
var replaceTSXExt = function (script) {
|
|
68
|
+
var replaceTSXExt = function (script) {
|
|
69
|
+
return script.replace(exports.IMPORT_TSX_PATH_RE, scriptReplacer).replace(exports.REQUIRE_TSX_PATH_RE, scriptReplacer);
|
|
70
|
+
};
|
|
57
71
|
exports.replaceTSXExt = replaceTSXExt;
|
|
72
|
+
var moduleCompatible = function (script) {
|
|
73
|
+
var moduleCompatible = (0, lodash_1.get)((0, varlet_config_1.getVarletConfig)(), 'moduleCompatible', {});
|
|
74
|
+
Object.keys(moduleCompatible).forEach(function (esm) {
|
|
75
|
+
var commonjs = moduleCompatible[esm];
|
|
76
|
+
script = script.replace(esm, commonjs);
|
|
77
|
+
});
|
|
78
|
+
return script;
|
|
79
|
+
};
|
|
80
|
+
exports.moduleCompatible = moduleCompatible;
|
|
58
81
|
function compileScript(script, file) {
|
|
59
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
-
var
|
|
83
|
+
var modules, code;
|
|
61
84
|
return __generator(this, function (_a) {
|
|
62
85
|
switch (_a.label) {
|
|
63
|
-
case 0:
|
|
64
|
-
|
|
65
|
-
|
|
86
|
+
case 0:
|
|
87
|
+
modules = process.env.BABEL_MODULE;
|
|
88
|
+
if (modules === 'commonjs') {
|
|
89
|
+
script = (0, exports.moduleCompatible)(script);
|
|
90
|
+
}
|
|
91
|
+
return [4 /*yield*/, (0, core_1.transformAsync)(script, {
|
|
92
|
+
filename: file,
|
|
93
|
+
})];
|
|
66
94
|
case 1:
|
|
67
95
|
code = (_a.sent()).code;
|
|
68
|
-
modules = process.env.BABEL_MODULE;
|
|
69
96
|
code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_CSS_RE : compileStyle_1.IMPORT_CSS_RE, 'css', false);
|
|
70
97
|
code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_LESS_RE : compileStyle_1.IMPORT_LESS_RE, 'less', false);
|
|
71
98
|
code = (0, exports.replaceVueExt)(code);
|
|
@@ -150,7 +177,7 @@ function compileCommonJSEntry(dir, publicDirs) {
|
|
|
150
177
|
publicDirs.forEach(function (dirname) {
|
|
151
178
|
var publicComponent = (0, fsUtils_1.bigCamelize)(dirname);
|
|
152
179
|
publicComponents.push(publicComponent);
|
|
153
|
-
requires.push("
|
|
180
|
+
requires.push("var " + publicComponent + " = require('./" + dirname + "')['default']");
|
|
154
181
|
plugins.push(publicComponent + ".install && app.use(" + publicComponent + ")");
|
|
155
182
|
cssRequires.push("require('./" + dirname + "/style')");
|
|
156
183
|
lessRequires.push("require('./" + dirname + "/style/less')");
|
|
@@ -36,13 +36,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.compileTypes = void 0;
|
|
39
|
+
exports.compileTypes = exports.generateReference = void 0;
|
|
40
40
|
var fs_extra_1 = require("fs-extra");
|
|
41
41
|
var constant_1 = require("../shared/constant");
|
|
42
42
|
var fsUtils_1 = require("../shared/fsUtils");
|
|
43
43
|
var path_1 = require("path");
|
|
44
44
|
var varlet_config_1 = require("../config/varlet.config");
|
|
45
45
|
var lodash_1 = require("lodash");
|
|
46
|
+
function generateReference(moduleDir) {
|
|
47
|
+
(0, fs_extra_1.writeFileSync)((0, path_1.resolve)(moduleDir, 'index.d.ts'), "export * from '" + (0, path_1.relative)(moduleDir, constant_1.TYPES_DIR) + "'\n");
|
|
48
|
+
}
|
|
49
|
+
exports.generateReference = generateReference;
|
|
46
50
|
function compileTypes() {
|
|
47
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
48
52
|
var varletConfig, namespace, name, dir, ignoreEntryDir, exports, declares, template, globalTemplate;
|
|
@@ -80,12 +80,16 @@ function inlineCSS(fileName, dir) {
|
|
|
80
80
|
apply: 'build',
|
|
81
81
|
closeBundle: function () {
|
|
82
82
|
var cssFile = (0, path_1.resolve)(dir, 'style.css');
|
|
83
|
+
if (!(0, fs_extra_1.pathExistsSync)(cssFile)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
83
86
|
var jsFile = (0, path_1.resolve)(dir, fileName);
|
|
84
87
|
var cssCode = (0, fs_extra_1.readFileSync)(cssFile, 'utf-8');
|
|
85
88
|
var jsCode = (0, fs_extra_1.readFileSync)(jsFile, 'utf-8');
|
|
86
89
|
var injectCode = ";(function(){var style=document.createElement('style');style.type='text/css';style.rel='stylesheet';style.appendChild(document.createTextNode(`" + cssCode.replace(/\\/g, '\\\\') + "`));var head=document.querySelector('head');head.appendChild(style)})();";
|
|
87
|
-
(0, fs_extra_1.removeSync)(cssFile);
|
|
88
90
|
(0, fs_extra_1.writeFileSync)(jsFile, "" + injectCode + jsCode);
|
|
91
|
+
(0, fs_extra_1.copyFileSync)(cssFile, (0, path_1.resolve)(constant_1.LIB_DIR, 'style.css'));
|
|
92
|
+
(0, fs_extra_1.removeSync)(cssFile);
|
|
89
93
|
},
|
|
90
94
|
};
|
|
91
95
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.5",
|
|
4
4
|
"description": "cli of varlet",
|
|
5
5
|
"bin": {
|
|
6
6
|
"varlet-cli": "./lib/index.js"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dev": "tsc --watch",
|
|
32
32
|
"build": "tsc"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "013da06688feb68a175e31dc8d91a16071dba461",
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@babel/core": "^7.14.8",
|
|
37
37
|
"@babel/preset-env": "^7.14.8",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@vitejs/plugin-vue": "1.9.2",
|
|
48
48
|
"@vitejs/plugin-vue-jsx": "1.1.8",
|
|
49
49
|
"@vue/babel-plugin-jsx": "^1.0.7",
|
|
50
|
-
"@vue/compiler-sfc": "3.2.
|
|
50
|
+
"@vue/compiler-sfc": "3.2.22",
|
|
51
51
|
"@vue/test-utils": "^2.0.0-rc.6",
|
|
52
52
|
"babel-jest": "26.6.3",
|
|
53
53
|
"chalk": "^4.1.0",
|