@varlet/cli 2.7.0-alpha.1673639241179 → 2.7.0-alpha.1673641087704

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 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
- ```js
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
- ```js
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,13 +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
- process.env.TARGET_MODULE = 'commonjs';
31
- process.env.BABEL_MODULE = 'commonjs';
32
- await runTask('commonjs', compileModule);
33
29
  process.env.BABEL_MODULE = '';
34
- process.env.TARGET_MODULE = 'bundle';
35
- await runTask('bundle', compileModule);
30
+ await runTask('bundle', compileBundle);
36
31
  }
@@ -4,7 +4,7 @@ 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, UMD_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, getScriptExtname } from './compileScript.js';
7
+ import { compileESEntry, compileScriptFile, getScriptExtname } from './compileScript.js';
8
8
  import { clearLessFiles, compileLess } from './compileStyle.js';
9
9
  import { getBundleConfig } from '../config/vite.config.js';
10
10
  import { getVarletConfig } from '../config/varlet.config.js';
@@ -56,12 +56,7 @@ 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
- const dest = targetModule === 'commonjs' ? LIB_DIR : ES_DIR;
59
+ const dest = ES_DIR;
65
60
  await copy(SRC_DIR, dest);
66
61
  const moduleDir = await readdir(dest);
67
62
  await Promise.all(moduleDir.map((filename) => {
@@ -70,12 +65,7 @@ export async function compileModule() {
70
65
  return isDir(file) ? compileDir(file) : null;
71
66
  }));
72
67
  const publicDirs = await getPublicDirs();
73
- if (targetModule === 'commonjs') {
74
- await compileCommonJSEntry(dest, publicDirs);
75
- }
76
- else {
77
- await compileESEntry(dest, publicDirs);
78
- }
68
+ await compileESEntry(dest, publicDirs);
79
69
  clearLessFiles(dest);
80
70
  generateReference(dest);
81
71
  }
@@ -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, process.env.TARGET_MODULE === 'commonjs'
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
  }
@@ -1,16 +1,13 @@
1
1
  export declare const IMPORT_FROM_DEPENDENCE_RE: RegExp;
2
2
  export declare const EXPORT_FROM_DEPENDENCE_RE: RegExp;
3
3
  export declare const IMPORT_DEPENDENCE_RE: RegExp;
4
- export declare const REQUIRE_DEPENDENCE_RE: RegExp;
5
4
  export declare const scriptExtNames: string[];
6
5
  export declare const styleExtNames: string[];
7
6
  export declare const scriptIndexes: string[];
8
7
  export declare const styleIndexes: string[];
9
8
  export declare const tryMatchExtname: (file: string, extname: string[]) => string | undefined;
10
9
  export declare const resolveDependence: (file: string, script: string) => string;
11
- export declare const moduleCompatible: (script: string) => Promise<string>;
12
10
  export declare function compileScript(script: string, file: string): Promise<void>;
13
11
  export declare function compileScriptFile(file: string): Promise<void>;
14
- export declare function getScriptExtname(): ".js" | ".mjs";
12
+ export declare function getScriptExtname(): string;
15
13
  export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
16
- export declare function compileCommonJSEntry(dir: string, publicDirs: string[]): Promise<void>;
@@ -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, REQUIRE_CSS_RE, REQUIRE_LESS_RE, } from './compileStyle.js';
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;
@@ -13,8 +11,6 @@ export const IMPORT_FROM_DEPENDENCE_RE = /import\s+?[\w\s{},$*]+\s+from\s+?(".*?
13
11
  export const EXPORT_FROM_DEPENDENCE_RE = /export\s+?[\w\s{},$*]+\s+from\s+?(".*?"|'.*?')/g;
14
12
  // https://regexr.com/764ve
15
13
  export const IMPORT_DEPENDENCE_RE = /import\s+(".*?"|'.*?')/g;
16
- // https://regexr.com/764vn
17
- export const REQUIRE_DEPENDENCE_RE = /require\((".*?"|'.*?')\)/g;
18
14
  export const scriptExtNames = ['.vue', '.ts', '.tsx', '.mjs', '.js', '.jsx'];
19
15
  export const styleExtNames = ['.less', '.css'];
20
16
  export const scriptIndexes = ['index.mjs', 'index.vue', 'index.ts', 'index.tsx', 'index.js', 'index.jsx'];
@@ -42,7 +38,7 @@ export const resolveDependence = (file, script) => {
42
38
  }
43
39
  if (ext) {
44
40
  if (scriptExtNames.includes(ext)) {
45
- // e.g. './a.vue' -> './a.m?js'
41
+ // e.g. './a.vue' -> './a.mjs'
46
42
  return done(dependence.replace(ext, scriptExtname));
47
43
  }
48
44
  if (styleExtNames.includes(ext)) {
@@ -51,7 +47,7 @@ export const resolveDependence = (file, script) => {
51
47
  }
52
48
  }
53
49
  if (!ext) {
54
- // e.g. ../button/props -> ../button/props.m?js
50
+ // e.g. ../button/props -> ../button/props.mjs
55
51
  const matchedScript = tryMatchExtname(targetDependenceFile, scriptExtNames);
56
52
  if (matchedScript) {
57
53
  return done(`${dependence}${scriptExtname}`);
@@ -66,7 +62,7 @@ export const resolveDependence = (file, script) => {
66
62
  const files = readdirSync(targetDependenceFile);
67
63
  const hasScriptIndex = files.some((file) => scriptIndexes.some((name) => file.endsWith(name)));
68
64
  if (hasScriptIndex) {
69
- // e.g. -> ../button/index.m?js
65
+ // e.g. -> ../button/index.mjs
70
66
  return done(`${dependence}/index${scriptExtname}`);
71
67
  }
72
68
  const hasStyleIndex = files.some((file) => styleIndexes.some((name) => file.endsWith(name)));
@@ -80,29 +76,16 @@ export const resolveDependence = (file, script) => {
80
76
  return script
81
77
  .replace(IMPORT_FROM_DEPENDENCE_RE, replacer)
82
78
  .replace(EXPORT_FROM_DEPENDENCE_RE, replacer)
83
- .replace(IMPORT_DEPENDENCE_RE, replacer)
84
- .replace(REQUIRE_DEPENDENCE_RE, replacer);
85
- };
86
- export const moduleCompatible = async (script) => {
87
- const moduleCompatible = get(await getVarletConfig(), 'moduleCompatible', {});
88
- Object.keys(moduleCompatible).forEach((esm) => {
89
- const commonjs = moduleCompatible[esm];
90
- script = script.replace(esm, commonjs);
91
- });
92
- return script;
79
+ .replace(IMPORT_DEPENDENCE_RE, replacer);
93
80
  };
94
81
  export async function compileScript(script, file) {
95
- const targetModule = process.env.TARGET_MODULE;
96
- if (targetModule === 'commonjs') {
97
- script = await moduleCompatible(script);
98
- }
99
82
  let { code } = (await transformAsync(script, {
100
83
  filename: file,
101
84
  }));
102
85
  if (code) {
103
86
  code = resolveDependence(file, code);
104
- code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_CSS_RE : IMPORT_CSS_RE);
105
- code = extractStyleDependencies(file, code, targetModule === 'commonjs' ? REQUIRE_LESS_RE : IMPORT_LESS_RE);
87
+ code = extractStyleDependencies(file, code, IMPORT_CSS_RE);
88
+ code = extractStyleDependencies(file, code, IMPORT_LESS_RE);
106
89
  removeSync(file);
107
90
  writeFileSync(replaceExt(file, getScriptExtname()), code, 'utf8');
108
91
  }
@@ -112,10 +95,7 @@ export async function compileScriptFile(file) {
112
95
  await compileScript(sources, file);
113
96
  }
114
97
  export function getScriptExtname() {
115
- if (process.env.TARGET_MODULE === 'module') {
116
- return '.mjs';
117
- }
118
- return '.js';
98
+ return '.mjs';
119
99
  }
120
100
  export async function compileESEntry(dir, publicDirs) {
121
101
  const imports = [];
@@ -183,54 +163,3 @@ export default {
183
163
  writeFile(resolve(dir, 'style.mjs'), styleTemplate, 'utf-8'),
184
164
  ]);
185
165
  }
186
- export async function compileCommonJSEntry(dir, publicDirs) {
187
- const requires = [];
188
- const plugins = [];
189
- const cssRequires = [];
190
- const publicComponents = [];
191
- const exports = [];
192
- publicDirs.forEach((dirname) => {
193
- const publicComponent = bigCamelize(dirname);
194
- const module = `'./${dirname}/index.js'`;
195
- publicComponents.push(publicComponent);
196
- requires.push(`var ${publicComponent} = require(${module})['default']`);
197
- exports.push(`...ignoreDefault(require(${module}))`);
198
- plugins.push(`${publicComponent}.install && app.use(${publicComponent})`);
199
- cssRequires.push(`require('./${dirname}/style/index.js')`);
200
- });
201
- const version = `const version = '${getVersion()}'`;
202
- const install = `
203
- function install(app) {
204
- ${plugins.join('\n ')}
205
- }
206
- `;
207
- const indexTemplate = `\
208
- ${requires.join('\n')}\n
209
- ${version}
210
- ${install}
211
-
212
- function ignoreDefault(module) {
213
- return Object.keys(module).reduce((exports, key) => {
214
- if (key !== 'default') {
215
- exports[key] = module[key]
216
- }
217
-
218
- return exports
219
- }, {})
220
- }
221
-
222
- module.exports = {
223
- version,
224
- install,
225
- ${exports.join(',\n ')},
226
- ${publicComponents.join(',\n ')}
227
- }
228
- `;
229
- const styleTemplate = `\
230
- ${cssRequires.join('\n')}
231
- `;
232
- await Promise.all([
233
- writeFile(resolve(dir, 'index.js'), indexTemplate, 'utf-8'),
234
- writeFile(resolve(dir, 'style.js'), styleTemplate, 'utf-8'),
235
- ]);
236
- }
@@ -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, targetModule === 'commonjs' ? `require('${normalizedPath}.css')\n` : `import '${normalizedPath}.css'\n`);
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.1673639241179",
3
+ "version": "2.7.0-alpha.1673641087704",
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/shared": "2.7.0-alpha.1673639241179",
70
- "@varlet/vite-plugins": "2.7.0-alpha.1673639241179"
69
+ "@varlet/shared": "2.7.0-alpha.1673641087704",
70
+ "@varlet/vite-plugins": "2.7.0-alpha.1673641087704"
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/touch-emulator": "2.7.0-alpha.1673639241179",
83
- "@varlet/icons": "2.7.0-alpha.1673639241179"
82
+ "@varlet/icons": "2.7.0-alpha.1673641087704",
83
+ "@varlet/touch-emulator": "2.7.0-alpha.1673641087704"
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.1673639241179",
94
- "@varlet/touch-emulator": "2.7.0-alpha.1673639241179"
93
+ "@varlet/icons": "2.7.0-alpha.1673641087704",
94
+ "@varlet/touch-emulator": "2.7.0-alpha.1673641087704"
95
95
  },
96
96
  "scripts": {
97
97
  "dev": "tsc --watch",