@varlet/cli 2.6.1 → 2.7.0-alpha.1673534139536
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/lib/node/commands/compile.js +5 -3
- package/lib/node/compiler/compileModule.d.ts +1 -1
- package/lib/node/compiler/compileModule.js +14 -24
- package/lib/node/compiler/compileSFC.js +1 -1
- package/lib/node/compiler/compileScript.d.ts +1 -0
- package/lib/node/compiler/compileScript.js +20 -13
- package/lib/node/compiler/compileStyle.js +4 -3
- package/lib/node/config/vite.config.js +2 -2
- package/package.json +7 -7
- package/site/pc/components/AppHeader.vue +1 -1
|
@@ -25,11 +25,13 @@ export async function compile(options) {
|
|
|
25
25
|
await removeDir();
|
|
26
26
|
await Promise.all([runTask('types', compileTypes), runTask('template highlight', compileTemplateHighlight)]);
|
|
27
27
|
process.env.TARGET_MODULE = 'module';
|
|
28
|
+
process.env.BABEL_MODULE = 'module';
|
|
28
29
|
await runTask('module', compileModule);
|
|
29
30
|
process.env.TARGET_MODULE = 'esm-bundle';
|
|
30
|
-
await runTask('esm bundle',
|
|
31
|
+
await runTask('esm bundle', compileModule);
|
|
31
32
|
process.env.TARGET_MODULE = 'commonjs';
|
|
32
|
-
|
|
33
|
+
process.env.BABEL_MODULE = 'commonjs';
|
|
34
|
+
await runTask('commonjs', compileModule);
|
|
33
35
|
process.env.TARGET_MODULE = 'umd';
|
|
34
|
-
!options.noUmd && (await runTask('umd',
|
|
36
|
+
!options.noUmd && (await runTask('umd', compileModule));
|
|
35
37
|
}
|
|
@@ -2,4 +2,4 @@ export declare function compileUMD(): Promise<void>;
|
|
|
2
2
|
export declare function compileESMBundle(): Promise<void>;
|
|
3
3
|
export declare function compileDir(dir: string): Promise<void>;
|
|
4
4
|
export declare function compileFile(file: string): Promise<void>;
|
|
5
|
-
export declare function compileModule(
|
|
5
|
+
export declare function compileModule(): Promise<void>;
|
|
@@ -4,29 +4,19 @@ import { resolve } from 'path';
|
|
|
4
4
|
import { EXAMPLE_DIR_NAME, TESTS_DIR_NAME, DOCS_DIR_NAME, SRC_DIR, ES_DIR, STYLE_DIR_NAME, LIB_DIR, } from '../shared/constant.js';
|
|
5
5
|
import { getPublicDirs, isDir, isDTS, isLess, isScript, isSFC } from '../shared/fsUtils.js';
|
|
6
6
|
import { compileSFC } from './compileSFC.js';
|
|
7
|
-
import { compileESEntry, compileCommonJSEntry, compileScriptFile } from './compileScript.js';
|
|
7
|
+
import { compileESEntry, compileCommonJSEntry, compileScriptFile, getScriptExtname } from './compileScript.js';
|
|
8
8
|
import { clearLessFiles, compileLess } from './compileStyle.js';
|
|
9
9
|
import { getESMBundleConfig, getUMDConfig } from '../config/vite.config.js';
|
|
10
10
|
import { getVarletConfig } from '../config/varlet.config.js';
|
|
11
11
|
import { generateReference } from './compileTypes.js';
|
|
12
12
|
const { copy, ensureFileSync, readdir, removeSync } = fse;
|
|
13
|
-
export function compileUMD() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
build(getUMDConfig(varletConfig))
|
|
17
|
-
.then(() => resolve())
|
|
18
|
-
.catch(reject);
|
|
19
|
-
});
|
|
20
|
-
});
|
|
13
|
+
export async function compileUMD() {
|
|
14
|
+
const varletConfig = await getVarletConfig();
|
|
15
|
+
await build(getUMDConfig(varletConfig));
|
|
21
16
|
}
|
|
22
|
-
export function compileESMBundle() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
build(getESMBundleConfig(varletConfig))
|
|
26
|
-
.then(() => resolve())
|
|
27
|
-
.catch(reject);
|
|
28
|
-
});
|
|
29
|
-
});
|
|
17
|
+
export async function compileESMBundle() {
|
|
18
|
+
const varletConfig = await getVarletConfig();
|
|
19
|
+
await build(getESMBundleConfig(varletConfig));
|
|
30
20
|
}
|
|
31
21
|
export async function compileDir(dir) {
|
|
32
22
|
const dirs = await readdir(dir);
|
|
@@ -45,26 +35,26 @@ export async function compileFile(file) {
|
|
|
45
35
|
isLess(file) && (await compileLess(file));
|
|
46
36
|
isDir(file) && (await compileDir(file));
|
|
47
37
|
}
|
|
48
|
-
export async function compileModule(
|
|
49
|
-
|
|
38
|
+
export async function compileModule() {
|
|
39
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
40
|
+
if (targetModule === 'umd') {
|
|
50
41
|
await compileUMD();
|
|
51
42
|
return;
|
|
52
43
|
}
|
|
53
|
-
if (
|
|
44
|
+
if (targetModule === 'esm-bundle') {
|
|
54
45
|
await compileESMBundle();
|
|
55
46
|
return;
|
|
56
47
|
}
|
|
57
|
-
|
|
58
|
-
const dest = modules === 'commonjs' ? LIB_DIR : ES_DIR;
|
|
48
|
+
const dest = targetModule === 'commonjs' ? LIB_DIR : ES_DIR;
|
|
59
49
|
await copy(SRC_DIR, dest);
|
|
60
50
|
const moduleDir = await readdir(dest);
|
|
61
51
|
await Promise.all(moduleDir.map((filename) => {
|
|
62
52
|
const file = resolve(dest, filename);
|
|
63
|
-
isDir(file) && ensureFileSync(resolve(file,
|
|
53
|
+
isDir(file) && ensureFileSync(resolve(file, `./style/index.${getScriptExtname()}`));
|
|
64
54
|
return isDir(file) ? compileDir(file) : null;
|
|
65
55
|
}));
|
|
66
56
|
const publicDirs = await getPublicDirs();
|
|
67
|
-
if (
|
|
57
|
+
if (targetModule === 'commonjs') {
|
|
68
58
|
await compileCommonJSEntry(dest, publicDirs);
|
|
69
59
|
}
|
|
70
60
|
else {
|
|
@@ -68,7 +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, process.env.
|
|
71
|
+
smartAppendFileSync(cssFile, process.env.TARGET_MODULE === 'commonjs'
|
|
72
72
|
? `require('${dependencyPath}.css')\n`
|
|
73
73
|
: `import '${dependencyPath}.css'\n`);
|
|
74
74
|
if (style.lang === 'less') {
|
|
@@ -13,5 +13,6 @@ export declare const replaceTSXExt: (script: string) => string;
|
|
|
13
13
|
export declare const moduleCompatible: (script: string) => Promise<string>;
|
|
14
14
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
15
15
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
16
|
+
export declare function getScriptExtname(): "mjs" | "js";
|
|
16
17
|
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
17
18
|
export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -15,7 +15,7 @@ export const REQUIRE_VUE_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\
|
|
|
15
15
|
export const REQUIRE_TS_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.ts(\s*['"`]\))(?!\s*['"`])/g;
|
|
16
16
|
export const REQUIRE_JSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.jsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
17
17
|
export const REQUIRE_TSX_PATH_RE = /(?<!['"`]\s*)(require\s*\(\s*['"]\s*\.{1,2}\/.+)\.tsx(\s*['"`]\))(?!\s*['"`])/g;
|
|
18
|
-
const scriptReplacer = (_, p1, p2) => `${p1}
|
|
18
|
+
const scriptReplacer = (_, p1, p2) => `${p1}.${getScriptExtname()}${p2}`;
|
|
19
19
|
export const replaceVueExt = (script) => script.replace(IMPORT_VUE_PATH_RE, scriptReplacer).replace(REQUIRE_VUE_PATH_RE, scriptReplacer);
|
|
20
20
|
export const replaceTSExt = (script) => script.replace(IMPORT_TS_PATH_RE, scriptReplacer).replace(REQUIRE_TS_PATH_RE, scriptReplacer);
|
|
21
21
|
export const replaceJSXExt = (script) => script.replace(IMPORT_JSX_PATH_RE, scriptReplacer).replace(REQUIRE_JSX_PATH_RE, scriptReplacer);
|
|
@@ -29,39 +29,46 @@ export const moduleCompatible = async (script) => {
|
|
|
29
29
|
return script;
|
|
30
30
|
};
|
|
31
31
|
export async function compileScript(script, file) {
|
|
32
|
-
const
|
|
33
|
-
if (
|
|
32
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
33
|
+
if (targetModule === 'commonjs') {
|
|
34
34
|
script = await moduleCompatible(script);
|
|
35
35
|
}
|
|
36
36
|
let { code } = (await transformAsync(script, {
|
|
37
37
|
filename: file,
|
|
38
38
|
}));
|
|
39
|
-
code = extractStyleDependencies(file, code,
|
|
40
|
-
code = extractStyleDependencies(file, code,
|
|
39
|
+
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
|
|
40
|
+
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
|
|
41
41
|
code = replaceVueExt(code);
|
|
42
42
|
code = replaceTSXExt(code);
|
|
43
43
|
code = replaceJSXExt(code);
|
|
44
44
|
code = replaceTSExt(code);
|
|
45
45
|
removeSync(file);
|
|
46
|
-
writeFileSync(replaceExt(file,
|
|
46
|
+
writeFileSync(replaceExt(file, `.${getScriptExtname()}`), code, 'utf8');
|
|
47
47
|
}
|
|
48
48
|
export async function compileScriptFile(file) {
|
|
49
49
|
const sources = readFileSync(file, 'utf-8');
|
|
50
50
|
await compileScript(sources, file);
|
|
51
51
|
}
|
|
52
|
+
export function getScriptExtname() {
|
|
53
|
+
if (process.env.TARGET_MODULE === 'module') {
|
|
54
|
+
return 'mjs';
|
|
55
|
+
}
|
|
56
|
+
return 'js';
|
|
57
|
+
}
|
|
52
58
|
export async function compileESEntry(dir, publicDirs) {
|
|
53
59
|
const imports = [];
|
|
54
60
|
const plugins = [];
|
|
55
61
|
const constInternalComponents = [];
|
|
56
62
|
const cssImports = [];
|
|
57
63
|
const publicComponents = [];
|
|
64
|
+
const scriptExtname = getScriptExtname();
|
|
58
65
|
publicDirs.forEach((dirname) => {
|
|
59
66
|
const publicComponent = bigCamelize(dirname);
|
|
60
67
|
publicComponents.push(publicComponent);
|
|
61
|
-
imports.push(`import ${publicComponent}, * as ${publicComponent}Module from './${dirname}'`);
|
|
68
|
+
imports.push(`import ${publicComponent}, * as ${publicComponent}Module from './${dirname}/index.${scriptExtname}'`);
|
|
62
69
|
constInternalComponents.push(`export const _${publicComponent}Component = ${publicComponent}Module._${publicComponent}Component || {}`);
|
|
63
70
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
64
|
-
cssImports.push(`import './${dirname}/style'`);
|
|
71
|
+
cssImports.push(`import './${dirname}/style/index.${scriptExtname}'`);
|
|
65
72
|
});
|
|
66
73
|
const install = `
|
|
67
74
|
function install(app) {
|
|
@@ -100,9 +107,9 @@ export default {
|
|
|
100
107
|
}
|
|
101
108
|
`;
|
|
102
109
|
await Promise.all([
|
|
103
|
-
writeFile(resolve(dir, 'index.
|
|
104
|
-
writeFile(resolve(dir, '
|
|
105
|
-
writeFile(resolve(dir, 'style.
|
|
110
|
+
writeFile(resolve(dir, 'index.mjs'), indexTemplate, 'utf-8'),
|
|
111
|
+
writeFile(resolve(dir, 'index.umd.mjs'), umdTemplate, 'utf-8'),
|
|
112
|
+
writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
|
|
106
113
|
]);
|
|
107
114
|
}
|
|
108
115
|
export async function compileCommonJSEntry(dir, publicDirs) {
|
|
@@ -113,9 +120,9 @@ export async function compileCommonJSEntry(dir, publicDirs) {
|
|
|
113
120
|
publicDirs.forEach((dirname) => {
|
|
114
121
|
const publicComponent = bigCamelize(dirname);
|
|
115
122
|
publicComponents.push(publicComponent);
|
|
116
|
-
requires.push(`var ${publicComponent} = require('./${dirname}')['default']`);
|
|
123
|
+
requires.push(`var ${publicComponent} = require('./${dirname}/index.js')['default']`);
|
|
117
124
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
118
|
-
cssRequires.push(`require('./${dirname}/style')`);
|
|
125
|
+
cssRequires.push(`require('./${dirname}/style/index.js')`);
|
|
119
126
|
});
|
|
120
127
|
const install = `
|
|
121
128
|
function install(app) {
|
|
@@ -3,6 +3,7 @@ import less from 'less';
|
|
|
3
3
|
import glob from 'glob';
|
|
4
4
|
import { replaceExt, smartAppendFileSync } from '../shared/fsUtils.js';
|
|
5
5
|
import { parse, resolve } from 'path';
|
|
6
|
+
import { getScriptExtname } from './compileScript.js';
|
|
6
7
|
const { render } = less;
|
|
7
8
|
const { readFileSync, writeFileSync, unlinkSync } = fse;
|
|
8
9
|
export const EMPTY_SPACE_RE = /[\s]+/g;
|
|
@@ -24,11 +25,11 @@ export function normalizeStyleDependency(styleImport, reg) {
|
|
|
24
25
|
export function extractStyleDependencies(file, code, styleReg) {
|
|
25
26
|
var _a;
|
|
26
27
|
const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
|
|
27
|
-
const cssFile = resolve(parse(file).dir,
|
|
28
|
-
const
|
|
28
|
+
const cssFile = resolve(parse(file).dir, `./style/index.${getScriptExtname()}`);
|
|
29
|
+
const targetModule = process.env.TARGET_MODULE;
|
|
29
30
|
styleImports.forEach((styleImport) => {
|
|
30
31
|
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
|
31
|
-
smartAppendFileSync(cssFile,
|
|
32
|
+
smartAppendFileSync(cssFile, targetModule === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
|
|
32
33
|
});
|
|
33
34
|
return code.replace(styleReg, '');
|
|
34
35
|
}
|
|
@@ -69,7 +69,7 @@ export function getESMBundleConfig(varletConfig) {
|
|
|
69
69
|
name,
|
|
70
70
|
formats: ['es'],
|
|
71
71
|
fileName: () => fileName,
|
|
72
|
-
entry: resolve(ES_DIR, '
|
|
72
|
+
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
73
73
|
},
|
|
74
74
|
rollupOptions: {
|
|
75
75
|
external: ['vue'],
|
|
@@ -98,7 +98,7 @@ export function getUMDConfig(varletConfig) {
|
|
|
98
98
|
name,
|
|
99
99
|
formats: ['umd'],
|
|
100
100
|
fileName: () => fileName,
|
|
101
|
-
entry: resolve(ES_DIR, '
|
|
101
|
+
entry: resolve(ES_DIR, 'index.umd.mjs'),
|
|
102
102
|
},
|
|
103
103
|
rollupOptions: {
|
|
104
104
|
external: ['vue'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-alpha.1673534139536",
|
|
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.
|
|
70
|
-
"@varlet/shared": "2.
|
|
69
|
+
"@varlet/vite-plugins": "2.7.0-alpha.1673534139536",
|
|
70
|
+
"@varlet/shared": "2.7.0-alpha.1673534139536"
|
|
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/icons": "2.
|
|
83
|
-
"@varlet/touch-emulator": "2.
|
|
82
|
+
"@varlet/icons": "2.7.0-alpha.1673534139536",
|
|
83
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673534139536"
|
|
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/icons": "2.
|
|
94
|
-
"@varlet/touch-emulator": "2.
|
|
93
|
+
"@varlet/icons": "2.7.0-alpha.1673534139536",
|
|
94
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673534139536"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"dev": "tsc --watch",
|
|
@@ -122,7 +122,7 @@ export default defineComponent({
|
|
|
122
122
|
class="varlet-site-header__versions"
|
|
123
123
|
@mouseenter="isOpenVersionsMenu = true"
|
|
124
124
|
@mouseleave="isOpenVersionsMenu = false"
|
|
125
|
-
v-if="
|
|
125
|
+
v-if="nonEmptyVersions && Object.keys(nonEmptyVersions).length"
|
|
126
126
|
>
|
|
127
127
|
<span style="font-size: 14px;">{{ currentVersion }}</span>
|
|
128
128
|
<var-icon name="chevron-down"/>
|