@varlet/cli 1.23.4-alpha.3 → 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.
@@ -10,6 +10,7 @@ export declare const replaceVueExt: (script: string) => string;
10
10
  export declare const replaceTSExt: (script: string) => string;
11
11
  export declare const replaceJSXExt: (script: string) => string;
12
12
  export declare const replaceTSXExt: (script: string) => string;
13
+ export declare const moduleCompatible: (script: string) => string;
13
14
  export declare function compileScript(script: string, file: string): Promise<void>;
14
15
  export declare function compileScriptFile(file: string): Promise<void>;
15
16
  export declare function compileESEntry(dir: string, publicDirs: string[]): Promise<void>;
@@ -36,12 +36,14 @@ 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.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;
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;
@@ -67,17 +69,30 @@ var replaceTSXExt = function (script) {
67
69
  return script.replace(exports.IMPORT_TSX_PATH_RE, scriptReplacer).replace(exports.REQUIRE_TSX_PATH_RE, scriptReplacer);
68
70
  };
69
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;
70
81
  function compileScript(script, file) {
71
82
  return __awaiter(this, void 0, void 0, function () {
72
- var code, modules;
83
+ var modules, code;
73
84
  return __generator(this, function (_a) {
74
85
  switch (_a.label) {
75
- case 0: return [4 /*yield*/, (0, core_1.transformAsync)(script, {
76
- filename: file,
77
- })];
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
+ })];
78
94
  case 1:
79
95
  code = (_a.sent()).code;
80
- modules = process.env.BABEL_MODULE;
81
96
  code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_CSS_RE : compileStyle_1.IMPORT_CSS_RE, 'css', false);
82
97
  code = (0, compileStyle_1.extractStyleDependencies)(file, code, modules === 'commonjs' ? compileStyle_1.REQUIRE_LESS_RE : compileStyle_1.IMPORT_LESS_RE, 'less', false);
83
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.3+2b5b1bde",
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": "2b5b1bde5e1c16d4e58ce2a100ae4a1a3cc428ce",
34
+ "gitHead": "0b1d95fc740a225240ee3f28e06015f4538b2304",
35
35
  "dependencies": {
36
36
  "@babel/core": "^7.14.8",
37
37
  "@babel/preset-env": "^7.14.8",