@varlet/cli 2.7.0-alpha.1673584157662 → 2.7.0-alpha.1673617166404
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.
|
@@ -50,7 +50,7 @@ export async function compileModule() {
|
|
|
50
50
|
const moduleDir = await readdir(dest);
|
|
51
51
|
await Promise.all(moduleDir.map((filename) => {
|
|
52
52
|
const file = resolve(dest, filename);
|
|
53
|
-
isDir(file) && ensureFileSync(resolve(file, `./style/index
|
|
53
|
+
isDir(file) && ensureFileSync(resolve(file, `./style/index${getScriptExtname()}`));
|
|
54
54
|
return isDir(file) ? compileDir(file) : null;
|
|
55
55
|
}));
|
|
56
56
|
const publicDirs = await getPublicDirs();
|
|
@@ -2,12 +2,14 @@ export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
|
|
|
2
2
|
export declare const IMPORT_DEPENDENCE_RE: RegExp;
|
|
3
3
|
export declare const REQUIRE_DEPENDENCE_RE: RegExp;
|
|
4
4
|
export declare const scriptExtNames: string[];
|
|
5
|
+
export declare const styleExtNames: string[];
|
|
5
6
|
export declare const scriptIndexes: string[];
|
|
7
|
+
export declare const styleIndexes: string[];
|
|
6
8
|
export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
|
|
7
9
|
export declare const resolveDependence: (file: string, script: string) => string;
|
|
8
10
|
export declare const moduleCompatible: (script: string) => Promise<string>;
|
|
9
11
|
export declare function compileScript(script: string, file: string): Promise<void>;
|
|
10
12
|
export declare function compileScriptFile(file: string): Promise<void>;
|
|
11
|
-
export declare function getScriptExtname(): "
|
|
13
|
+
export declare function getScriptExtname(): ".js" | ".mjs";
|
|
12
14
|
export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
13
15
|
export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
|
|
@@ -10,36 +10,53 @@ const { writeFileSync, readdirSync, readFileSync, removeSync, writeFile, pathExi
|
|
|
10
10
|
// https://regexr.com/765a4
|
|
11
11
|
export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
|
|
12
12
|
// https://regexr.com/764ve
|
|
13
|
-
export const IMPORT_DEPENDENCE_RE = /import\s+
|
|
13
|
+
export const IMPORT_DEPENDENCE_RE = /import\s+(".*?"|'.*?')/g;
|
|
14
14
|
// https://regexr.com/764vn
|
|
15
|
-
export const REQUIRE_DEPENDENCE_RE = /require\(
|
|
16
|
-
export const scriptExtNames = ['
|
|
15
|
+
export const REQUIRE_DEPENDENCE_RE = /require\((".*?"|'.*?')\)/g;
|
|
16
|
+
export const scriptExtNames = ['.vue', '.ts', '.tsx', '.mjs', '.js', '.jsx'];
|
|
17
|
+
export const styleExtNames = ['.less', '.css'];
|
|
17
18
|
export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
|
|
19
|
+
export const styleIndexes = ['index.less', 'index.css'];
|
|
18
20
|
export const tryMatchExtname = (file, extname) => {
|
|
19
21
|
// eslint-disable-next-line no-restricted-syntax
|
|
20
22
|
for (const ext of extname) {
|
|
21
|
-
const matched = `${file}
|
|
23
|
+
const matched = `${file}${ext}`;
|
|
22
24
|
if (pathExistsSync(matched)) {
|
|
23
25
|
return ext;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
};
|
|
27
29
|
export const resolveDependence = (file, script) => {
|
|
28
|
-
|
|
30
|
+
const replacer = (source, dependence) => {
|
|
29
31
|
dependence = dependence.slice(1, dependence.length - 1);
|
|
30
32
|
const ext = extname(dependence);
|
|
31
33
|
const targetDependenceFile = resolve(dirname(file), dependence);
|
|
32
34
|
const scriptExtname = getScriptExtname();
|
|
33
35
|
const inNodeModules = !dependence.startsWith('.');
|
|
36
|
+
const done = (targetDependence) => source.replace(dependence, targetDependence);
|
|
34
37
|
if (inNodeModules) {
|
|
35
38
|
// e.g. @varlet/shared
|
|
36
39
|
return source;
|
|
37
40
|
}
|
|
41
|
+
if (ext) {
|
|
42
|
+
if (scriptExtNames.includes(ext)) {
|
|
43
|
+
// e.g. './a.vue' -> './a.m?js'
|
|
44
|
+
return done(dependence.replace(ext, scriptExtname));
|
|
45
|
+
}
|
|
46
|
+
if (styleExtNames.includes(ext)) {
|
|
47
|
+
// e.g. './a.css' -> './a.css' './a.less' -> './a.less'
|
|
48
|
+
return source;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
38
51
|
if (!ext) {
|
|
39
52
|
// e.g. ../button/props -> ../button/props.m?js
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
return
|
|
53
|
+
const matchedScript = tryMatchExtname(targetDependenceFile, scriptExtNames);
|
|
54
|
+
if (matchedScript) {
|
|
55
|
+
return done(`${dependence}${scriptExtname}`);
|
|
56
|
+
}
|
|
57
|
+
const matchedStyle = tryMatchExtname(targetDependenceFile, styleExtNames);
|
|
58
|
+
if (matchedStyle) {
|
|
59
|
+
return done(`${dependence}${matchedStyle}`);
|
|
43
60
|
}
|
|
44
61
|
}
|
|
45
62
|
if (!ext && isDir(targetDependenceFile)) {
|
|
@@ -48,17 +65,20 @@ export const resolveDependence = (file, script) => {
|
|
|
48
65
|
const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
|
|
49
66
|
if (hasScriptIndex) {
|
|
50
67
|
// e.g. -> ../button/index.m?js
|
|
51
|
-
return
|
|
68
|
+
return done(`${dependence}/index${scriptExtname}`);
|
|
52
69
|
}
|
|
53
|
-
const hasStyleIndex = files.some((file) =>
|
|
70
|
+
const hasStyleIndex = files.some((file) => styleIndexes.some((name) => file.endsWith(name)));
|
|
54
71
|
if (hasStyleIndex) {
|
|
55
72
|
// e.g. -> ../button/index.css
|
|
56
|
-
return
|
|
73
|
+
return done(`${dependence}/index.css`);
|
|
57
74
|
}
|
|
58
75
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
return '';
|
|
77
|
+
};
|
|
78
|
+
return script
|
|
79
|
+
.replace(IMPORT_FROM_DEPENDENCE_RE, replacer)
|
|
80
|
+
.replace(IMPORT_DEPENDENCE_RE, replacer)
|
|
81
|
+
.replace(REQUIRE_DEPENDENCE_RE, replacer);
|
|
62
82
|
};
|
|
63
83
|
export const moduleCompatible = async (script) => {
|
|
64
84
|
const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
|
|
@@ -77,11 +97,11 @@ export async function compileScript(script, file) {
|
|
|
77
97
|
filename: file,
|
|
78
98
|
}));
|
|
79
99
|
if (code) {
|
|
100
|
+
code = resolveDependence(file, code);
|
|
80
101
|
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
|
|
81
102
|
code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
|
|
82
|
-
code = resolveDependence(file, code);
|
|
83
103
|
removeSync(file);
|
|
84
|
-
writeFileSync(replaceExt(file,
|
|
104
|
+
writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
|
|
85
105
|
}
|
|
86
106
|
}
|
|
87
107
|
export async function compileScriptFile(file) {
|
|
@@ -90,9 +110,9 @@ export async function compileScriptFile(file) {
|
|
|
90
110
|
}
|
|
91
111
|
export function getScriptExtname() {
|
|
92
112
|
if (process.env.TARGET_MODULE === 'module') {
|
|
93
|
-
return 'mjs';
|
|
113
|
+
return '.mjs';
|
|
94
114
|
}
|
|
95
|
-
return 'js';
|
|
115
|
+
return '.js';
|
|
96
116
|
}
|
|
97
117
|
export async function compileESEntry(dir, publicDirs) {
|
|
98
118
|
const imports = [];
|
|
@@ -103,12 +123,12 @@ export async function compileESEntry(dir, publicDirs) {
|
|
|
103
123
|
const scriptExtname = getScriptExtname();
|
|
104
124
|
publicDirs.forEach((dirname) => {
|
|
105
125
|
const publicComponent = bigCamelize(dirname);
|
|
106
|
-
const module = `'./${dirname}/index
|
|
126
|
+
const module = `'./${dirname}/index${scriptExtname}'`;
|
|
107
127
|
publicComponents.push(publicComponent);
|
|
108
128
|
imports.push(`import ${publicComponent} from ${module}`);
|
|
109
129
|
exports.push(`export * from ${module}`);
|
|
110
130
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
111
|
-
cssImports.push(`import './${dirname}/style/index
|
|
131
|
+
cssImports.push(`import './${dirname}/style/index${scriptExtname}'`);
|
|
112
132
|
});
|
|
113
133
|
const install = `
|
|
114
134
|
function install(app) {
|
|
@@ -174,6 +194,7 @@ export async function compileCommonJSEntry(dir, publicDirs) {
|
|
|
174
194
|
plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
|
|
175
195
|
cssRequires.push(`require('./${dirname}/style/index.js')`);
|
|
176
196
|
});
|
|
197
|
+
const version = `const version = '${getVersion()}'`;
|
|
177
198
|
const install = `
|
|
178
199
|
function install(app) {
|
|
179
200
|
${plugins.join('\n ')}
|
|
@@ -181,11 +202,12 @@ function install(app) {
|
|
|
181
202
|
`;
|
|
182
203
|
const indexTemplate = `\
|
|
183
204
|
${requires.join('\n')}\n
|
|
205
|
+
${version}
|
|
184
206
|
${install}
|
|
185
207
|
|
|
186
208
|
function ignoreDefault(module) {
|
|
187
209
|
return Object.keys(module).reduce((exports, key) => {
|
|
188
|
-
if (key
|
|
210
|
+
if (key !== 'default') {
|
|
189
211
|
exports[key] = module[key]
|
|
190
212
|
}
|
|
191
213
|
|
|
@@ -193,11 +215,10 @@ function ignoreDefault(module) {
|
|
|
193
215
|
}, {})
|
|
194
216
|
}
|
|
195
217
|
|
|
196
|
-
exports.install = install
|
|
197
|
-
|
|
198
218
|
module.exports = {
|
|
219
|
+
version,
|
|
199
220
|
install,
|
|
200
|
-
${exports.join(',\n ')}
|
|
221
|
+
${exports.join(',\n ')},
|
|
201
222
|
${publicComponents.join(',\n ')}
|
|
202
223
|
}
|
|
203
224
|
`;
|
|
@@ -25,7 +25,7 @@ export function normalizeStyleDependency(styleImport, reg) {
|
|
|
25
25
|
export function extractStyleDependencies(file, code, styleReg) {
|
|
26
26
|
var _a;
|
|
27
27
|
const styleImports = (_a = code.match(styleReg)) !== null && _a !== void 0 ? _a : [];
|
|
28
|
-
const cssFile = resolve(parse(file).dir, `./style/index
|
|
28
|
+
const cssFile = resolve(parse(file).dir, `./style/index${getScriptExtname()}`);
|
|
29
29
|
const targetModule = process.env.TARGET_MODULE;
|
|
30
30
|
styleImports.forEach((styleImport) => {
|
|
31
31
|
const normalizedPath = normalizeStyleDependency(styleImport, styleReg);
|
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.1673617166404",
|
|
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.1673617166404",
|
|
70
|
+
"@varlet/shared": "2.7.0-alpha.1673617166404"
|
|
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/touch-emulator": "2.7.0-alpha.1673617166404",
|
|
83
|
+
"@varlet/icons": "2.7.0-alpha.1673617166404"
|
|
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.7.0-alpha.
|
|
94
|
-
"@varlet/touch-emulator": "2.7.0-alpha.
|
|
93
|
+
"@varlet/icons": "2.7.0-alpha.1673617166404",
|
|
94
|
+
"@varlet/touch-emulator": "2.7.0-alpha.1673617166404"
|
|
95
95
|
},
|
|
96
96
|
"scripts": {
|
|
97
97
|
"dev": "tsc --watch",
|