@varlet/cli 1.23.4-alpha.0 → 1.23.4-alpha.4

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.
@@ -54,7 +54,7 @@ function syncVersion(name) {
54
54
  var pkg = JSON.parse((0, fs_extra_1.readFileSync)(file, 'utf-8'));
55
55
  var cliPkg = JSON.parse((0, fs_extra_1.readFileSync)(constant_1.CLI_PACKAGE_JSON, 'utf-8'));
56
56
  pkg.devDependencies['@varlet/cli'] = "^" + cliPkg.version;
57
- pkg.files = ['es', 'umd', 'highlight', 'types', 'README.md'];
57
+ pkg.files = ['es', 'lib', 'umd', 'highlight', 'types', 'README.md'];
58
58
  (0, fs_extra_1.writeFileSync)(file, JSON.stringify(pkg, null, 2));
59
59
  }
60
60
  function gen(name) {
@@ -142,7 +142,7 @@ function compileModule(modules) {
142
142
  return [4 /*yield*/, (0, fs_extra_1.copy)(constant_1.SRC_DIR, dest)];
143
143
  case 3:
144
144
  _a.sent();
145
- return [4 /*yield*/, (0, fs_extra_1.readdir)(constant_1.ES_DIR)];
145
+ return [4 /*yield*/, (0, fs_extra_1.readdir)(dest)];
146
146
  case 4:
147
147
  moduleDir = _a.sent();
148
148
  return [4 /*yield*/, Promise.all(moduleDir.map(function (filename) {
@@ -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) { return script.replace(exports.IMPORT_VUE_PATH_RE, scriptReplacer); };
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) { return script.replace(exports.IMPORT_TS_PATH_RE, scriptReplacer); };
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) { return script.replace(exports.IMPORT_JSX_PATH_RE, scriptReplacer); };
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) { return script.replace(exports.IMPORT_TSX_PATH_RE, scriptReplacer); };
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 code, modules;
83
+ var modules, code;
61
84
  return __generator(this, function (_a) {
62
85
  switch (_a.label) {
63
- case 0: return [4 /*yield*/, (0, core_1.transformAsync)(script, {
64
- filename: file,
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@varlet/cli",
3
- "version": "1.23.4-alpha.0+4a424d4c",
3
+ "version": "1.23.4-alpha.4+0b1d95fc",
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": "4a424d4c066f7de69cbf561a5bc9279862739637",
34
+ "gitHead": "0b1d95fc740a225240ee3f28e06015f4538b2304",
35
35
  "dependencies": {
36
36
  "@babel/core": "^7.14.8",
37
37
  "@babel/preset-env": "^7.14.8",