@modern-js/generator-utils 3.2.2 → 3.2.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.
package/dist/cjs/index.js CHANGED
@@ -1,104 +1,76 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
6
9
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- ora: function() {
14
- return _utils.ora;
15
- },
16
- fs: function() {
17
- return _utils.fs;
18
- },
19
- semver: function() {
20
- return _utils.semver;
21
- },
22
- execa: function() {
23
- return _utils.execa;
24
- },
25
- chalk: function() {
26
- return _utils.chalk;
27
- },
28
- readTsConfigByFile: function() {
29
- return _utils.readTsConfigByFile;
30
- },
31
- getPackageManager: function() {
32
- return _utils.getPackageManager;
33
- },
34
- canUseNpm: function() {
35
- return _utils.canUseNpm;
36
- },
37
- canUsePnpm: function() {
38
- return _utils.canUsePnpm;
39
- },
40
- canUseYarn: function() {
41
- return _utils.canUseYarn;
42
- },
43
- isReact18: function() {
44
- return _utils.isReact18;
45
- },
46
- i18n: function() {
47
- return _locale.i18n;
48
- },
49
- getPackageVersion: function() {
50
- return getPackageVersion;
51
- },
52
- getModernVersion: function() {
53
- return getModernVersion;
54
- },
55
- getModernPluginVersion: function() {
56
- return getModernPluginVersion;
57
- },
58
- getPackageManagerText: function() {
59
- return getPackageManagerText;
60
- },
61
- isTsProject: function() {
62
- return isTsProject;
63
- },
64
- getPackageObj: function() {
65
- return getPackageObj;
66
- },
67
- getAllPackages: function() {
68
- return getAllPackages;
69
- },
70
- validatePackageName: function() {
71
- return validatePackageName;
72
- },
73
- validatePackagePath: function() {
74
- return validatePackagePath;
75
- },
76
- getModuleProjectPath: function() {
77
- return getModuleProjectPath;
78
- },
79
- getMWAProjectPath: function() {
80
- return getMWAProjectPath;
81
- },
82
- getModernConfigFile: function() {
83
- return getModernConfigFile;
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
84
17
  }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ canUseNpm: () => import_utils2.canUseNpm,
33
+ canUsePnpm: () => import_utils2.canUsePnpm,
34
+ canUseYarn: () => import_utils2.canUseYarn,
35
+ chalk: () => import_utils2.chalk,
36
+ execa: () => import_utils2.execa,
37
+ fs: () => import_utils2.fs,
38
+ getAllPackages: () => getAllPackages,
39
+ getMWAProjectPath: () => getMWAProjectPath,
40
+ getModernConfigFile: () => getModernConfigFile,
41
+ getModernPluginVersion: () => getModernPluginVersion,
42
+ getModernVersion: () => getModernVersion,
43
+ getModuleProjectPath: () => getModuleProjectPath,
44
+ getPackageManager: () => import_utils2.getPackageManager,
45
+ getPackageManagerText: () => getPackageManagerText,
46
+ getPackageObj: () => getPackageObj,
47
+ getPackageVersion: () => getPackageVersion,
48
+ i18n: () => import_locale2.i18n,
49
+ isReact18: () => import_utils2.isReact18,
50
+ isTsProject: () => isTsProject,
51
+ ora: () => import_utils2.ora,
52
+ readTsConfigByFile: () => import_utils2.readTsConfigByFile,
53
+ semver: () => import_utils2.semver,
54
+ validatePackageName: () => validatePackageName,
55
+ validatePackagePath: () => validatePackagePath
85
56
  });
86
- const _export_star = require("@swc/helpers/_/_export_star");
87
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
88
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
89
- const _utils = require("@modern-js/utils");
90
- const _generatorcommon = require("@modern-js/generator-common");
91
- const _stripAnsi = require("./utils/stripAnsi");
92
- const _locale = require("./locale");
93
- const _package = require("./utils/package");
94
- const _fsExist = require("./utils/fsExist");
95
- _export_star._(require("./utils"), exports);
57
+ module.exports = __toCommonJS(src_exports);
58
+ var import_path = __toESM(require("path"));
59
+ var import_utils = require("@modern-js/utils");
60
+ var import_generator_common = require("@modern-js/generator-common");
61
+ var import_stripAnsi = require("./utils/stripAnsi");
62
+ var import_locale = require("./locale");
63
+ var import_package = require("./utils/package");
64
+ var import_fsExist = require("./utils/fsExist");
65
+ __reExport(src_exports, require("./utils"), module.exports);
66
+ var import_utils2 = require("@modern-js/utils");
67
+ var import_locale2 = require("./locale");
96
68
  async function getPackageVersion(packageName, registry) {
97
- const spinner = (0, _utils.ora)({
69
+ const spinner = (0, import_utils.ora)({
98
70
  text: "Load Generator...",
99
71
  spinner: "runner"
100
72
  }).start();
101
- if (await (0, _utils.canUsePnpm)()) {
73
+ if (await (0, import_utils.canUsePnpm)()) {
102
74
  const args = [
103
75
  "info",
104
76
  packageName,
@@ -107,11 +79,11 @@ async function getPackageVersion(packageName, registry) {
107
79
  if (registry) {
108
80
  args.push(`--registry=${registry}`);
109
81
  }
110
- const result = await (0, _utils.execa)("pnpm", args);
82
+ const result = await (0, import_utils.execa)("pnpm", args);
111
83
  spinner.stop();
112
- return (0, _stripAnsi.stripAnsi)(result.stdout);
84
+ return (0, import_stripAnsi.stripAnsi)(result.stdout);
113
85
  }
114
- if (await (0, _utils.canUseNpm)()) {
86
+ if (await (0, import_utils.canUseNpm)()) {
115
87
  const args = [
116
88
  "view",
117
89
  packageName,
@@ -120,15 +92,15 @@ async function getPackageVersion(packageName, registry) {
120
92
  if (registry) {
121
93
  args.push(`--registry=${registry}`);
122
94
  }
123
- const result = await (0, _utils.execa)("npm", args);
95
+ const result = await (0, import_utils.execa)("npm", args);
124
96
  spinner.stop();
125
- return (0, _stripAnsi.stripAnsi)(result.stdout);
97
+ return (0, import_stripAnsi.stripAnsi)(result.stdout);
126
98
  }
127
99
  spinner.stop();
128
100
  throw new Error("not found npm, please install npm before");
129
101
  }
130
102
  async function getModernVersion(solution, registry, distTag = "latest") {
131
- const dep = _generatorcommon.SolutionToolsMap[solution];
103
+ const dep = import_generator_common.SolutionToolsMap[solution];
132
104
  const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
133
105
  return modernVersion;
134
106
  }
@@ -143,25 +115,25 @@ async function getModernPluginVersion(solution, packageName, options = {
143
115
  if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
144
116
  return getLatetPluginVersion("latest");
145
117
  }
146
- let pkgPath = _path.default.join(require.resolve(_generatorcommon.SolutionToolsMap[solution], {
118
+ let pkgPath = import_path.default.join(require.resolve(import_generator_common.SolutionToolsMap[solution], {
147
119
  paths: [
148
120
  cwd
149
121
  ]
150
122
  }), "../../..", "package.json");
151
- if (solution === _generatorcommon.Solution.Module) {
152
- pkgPath = _path.default.join(require.resolve(_generatorcommon.SolutionToolsMap[solution], {
123
+ if (solution === import_generator_common.Solution.Module) {
124
+ pkgPath = import_path.default.join(require.resolve(import_generator_common.SolutionToolsMap[solution], {
153
125
  paths: [
154
126
  cwd
155
127
  ]
156
128
  }), "../..", "package.json");
157
129
  }
158
- if (_utils.fs.existsSync(pkgPath)) {
159
- const pkgInfo = _utils.fs.readJSONSync(pkgPath);
130
+ if (import_utils.fs.existsSync(pkgPath)) {
131
+ const pkgInfo = import_utils.fs.readJSONSync(pkgPath);
160
132
  const modernVersion = pkgInfo.version;
161
133
  if (typeof modernVersion !== "string") {
162
134
  return getLatetPluginVersion();
163
135
  }
164
- return (0, _package.getAvailableVersion)(packageName, modernVersion, registry);
136
+ return (0, import_package.getAvailableVersion)(packageName, modernVersion, registry);
165
137
  }
166
138
  return getLatetPluginVersion();
167
139
  }
@@ -169,14 +141,14 @@ function getPackageManagerText(packageManager) {
169
141
  return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
170
142
  }
171
143
  function isTsProject(appDir) {
172
- return _utils.fs.existsSync(_path.default.join(appDir, "tsconfig.json"));
144
+ return import_utils.fs.existsSync(import_path.default.join(appDir, "tsconfig.json"));
173
145
  }
174
146
  async function getPackageObj(context) {
175
147
  const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
176
148
  return JSON.parse(pkgStr);
177
149
  }
178
150
  function getAllPackages(appDir) {
179
- const packages = (0, _utils.getMonorepoPackages)(appDir);
151
+ const packages = (0, import_utils.getMonorepoPackages)(appDir);
180
152
  return packages.map((pkg) => pkg.name);
181
153
  }
182
154
  function validatePackageName(value, packages, options) {
@@ -184,7 +156,7 @@ function validatePackageName(value, packages, options) {
184
156
  if (isMonorepoSubProject && packages.includes(value)) {
185
157
  return {
186
158
  success: false,
187
- error: _locale.i18n.t(_locale.localeKeys.packageName.exit, {
159
+ error: import_locale.i18n.t(import_locale.localeKeys.packageName.exit, {
188
160
  value
189
161
  })
190
162
  };
@@ -194,18 +166,13 @@ function validatePackageName(value, packages, options) {
194
166
  };
195
167
  }
196
168
  function validatePackagePath(value, projectDir, options) {
197
- const { isMwa, isPublic, isTest } = options || {};
198
- let dir = "apps";
199
- if (isMwa && isTest) {
200
- dir = "examples";
201
- } else {
202
- dir = isPublic ? "packages" : "features";
203
- }
204
- const packageDir = _path.default.resolve(projectDir || "", dir, value);
205
- if (_utils.fs.existsSync(packageDir)) {
169
+ const { isMwa } = options || {};
170
+ const dir = isMwa ? "apps" : "packages";
171
+ const packageDir = import_path.default.resolve(projectDir || "", dir, value);
172
+ if (import_utils.fs.existsSync(packageDir)) {
206
173
  return {
207
174
  success: false,
208
- error: _locale.i18n.t(_locale.localeKeys.packagePath.exit, {
175
+ error: import_locale.i18n.t(import_locale.localeKeys.packagePath.exit, {
209
176
  value
210
177
  })
211
178
  };
@@ -214,29 +181,57 @@ function validatePackagePath(value, projectDir, options) {
214
181
  success: true
215
182
  };
216
183
  }
217
- function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
184
+ function getModuleProjectPath(packagePath, isMonorepoSubProject, isLocalPackages) {
218
185
  if (isLocalPackages && packagePath) {
219
186
  return `${packagePath}/`;
220
187
  }
221
188
  if (isMonorepoSubProject && packagePath) {
222
- return `${isPublic ? "packages" : "features"}/${packagePath}/`;
189
+ return `packages/${packagePath}/`;
223
190
  }
224
191
  return "";
225
192
  }
226
- function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
193
+ function getMWAProjectPath(packagePath, isMonorepoSubProject) {
227
194
  if (isMonorepoSubProject && packagePath) {
228
- return `${isTest ? "examples" : "apps"}/${packagePath}/`;
195
+ return `apps/${packagePath}/`;
229
196
  }
230
197
  return "";
231
198
  }
232
199
  async function getModernConfigFile(appDir) {
233
- let exist = await (0, _fsExist.fileExist)(_path.default.join(appDir, "modern.config.ts"));
200
+ let exist = await (0, import_fsExist.fileExist)(import_path.default.join(appDir, "modern.config.ts"));
234
201
  if (exist) {
235
202
  return "modern.config.ts";
236
203
  }
237
- exist = await (0, _fsExist.fileExist)(_path.default.join(appDir, "modern.config.js"));
204
+ exist = await (0, import_fsExist.fileExist)(import_path.default.join(appDir, "modern.config.js"));
238
205
  if (exist) {
239
206
  return "modern.config.js";
240
207
  }
241
208
  return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
242
209
  }
210
+ // Annotate the CommonJS export names for ESM import in node:
211
+ 0 && (module.exports = {
212
+ canUseNpm,
213
+ canUsePnpm,
214
+ canUseYarn,
215
+ chalk,
216
+ execa,
217
+ fs,
218
+ getAllPackages,
219
+ getMWAProjectPath,
220
+ getModernConfigFile,
221
+ getModernPluginVersion,
222
+ getModernVersion,
223
+ getModuleProjectPath,
224
+ getPackageManager,
225
+ getPackageManagerText,
226
+ getPackageObj,
227
+ getPackageVersion,
228
+ i18n,
229
+ isReact18,
230
+ isTsProject,
231
+ ora,
232
+ readTsConfigByFile,
233
+ semver,
234
+ validatePackageName,
235
+ validatePackagePath,
236
+ ...require("./utils")
237
+ });
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "EN_LOCALE", {
6
- enumerable: true,
7
- get: function() {
8
- return EN_LOCALE;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var en_exports = {};
20
+ __export(en_exports, {
21
+ EN_LOCALE: () => EN_LOCALE
10
22
  });
23
+ module.exports = __toCommonJS(en_exports);
11
24
  const EN_LOCALE = {
12
25
  packageName: {
13
26
  exit: "package name `{value}` is already exists"
@@ -16,3 +29,7 @@ const EN_LOCALE = {
16
29
  exit: "package path {value} is already exists"
17
30
  }
18
31
  };
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ EN_LOCALE
35
+ });
@@ -1,27 +1,37 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- i18n: function() {
14
- return i18n;
15
- },
16
- localeKeys: function() {
17
- return localeKeys;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var locale_exports = {};
20
+ __export(locale_exports, {
21
+ i18n: () => i18n,
22
+ localeKeys: () => localeKeys
19
23
  });
20
- const _plugini18n = require("@modern-js/plugin-i18n");
21
- const _zh = require("./zh");
22
- const _en = require("./en");
23
- const i18n = new _plugini18n.I18n();
24
+ module.exports = __toCommonJS(locale_exports);
25
+ var import_plugin_i18n = require("@modern-js/plugin-i18n");
26
+ var import_zh = require("./zh");
27
+ var import_en = require("./en");
28
+ const i18n = new import_plugin_i18n.I18n();
24
29
  const localeKeys = i18n.init("en", {
25
- zh: _zh.ZH_LOCALE,
26
- en: _en.EN_LOCALE
30
+ zh: import_zh.ZH_LOCALE,
31
+ en: import_en.EN_LOCALE
32
+ });
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ i18n,
36
+ localeKeys
27
37
  });
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "ZH_LOCALE", {
6
- enumerable: true,
7
- get: function() {
8
- return ZH_LOCALE;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var zh_exports = {};
20
+ __export(zh_exports, {
21
+ ZH_LOCALE: () => ZH_LOCALE
10
22
  });
23
+ module.exports = __toCommonJS(zh_exports);
11
24
  const ZH_LOCALE = {
12
25
  packageName: {
13
26
  exit: "项目名称 {value} 已存在"
@@ -16,3 +29,7 @@ const ZH_LOCALE = {
16
29
  exit: "目录 {value} 已存在"
17
30
  }
18
31
  };
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ ZH_LOCALE
35
+ });
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "fileExist", {
6
- enumerable: true,
7
- get: function() {
8
- return fileExist;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var fsExist_exports = {};
20
+ __export(fsExist_exports, {
21
+ fileExist: () => fileExist
10
22
  });
11
- const _utils = require("@modern-js/utils");
23
+ module.exports = __toCommonJS(fsExist_exports);
24
+ var import_utils = require("@modern-js/utils");
12
25
  async function fileExist(filePath) {
13
26
  try {
14
- const stat = await _utils.fs.stat(filePath);
27
+ const stat = await import_utils.fs.stat(filePath);
15
28
  if (stat.isFile()) {
16
29
  return true;
17
30
  }
@@ -20,3 +33,7 @@ async function fileExist(filePath) {
20
33
  return false;
21
34
  }
22
35
  }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ fileExist
39
+ });
@@ -1,7 +1,24 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var utils_exports = {};
17
+ module.exports = __toCommonJS(utils_exports);
18
+ __reExport(utils_exports, require("./stripAnsi"), module.exports);
19
+ __reExport(utils_exports, require("./package"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./stripAnsi"),
23
+ ...require("./package")
4
24
  });
5
- const _export_star = require("@swc/helpers/_/_export_star");
6
- _export_star._(require("./stripAnsi"), exports);
7
- _export_star._(require("./package"), exports);
@@ -1,31 +1,32 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- isPackageExist: function() {
14
- return isPackageExist;
15
- },
16
- isPackageDeprecated: function() {
17
- return isPackageDeprecated;
18
- },
19
- semverDecrease: function() {
20
- return semverDecrease;
21
- },
22
- getAvailableVersion: function() {
23
- return getAvailableVersion;
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var package_exports = {};
20
+ __export(package_exports, {
21
+ getAvailableVersion: () => getAvailableVersion,
22
+ isPackageDeprecated: () => isPackageDeprecated,
23
+ isPackageExist: () => isPackageExist,
24
+ semverDecrease: () => semverDecrease
25
25
  });
26
- const _utils = require("@modern-js/utils");
26
+ module.exports = __toCommonJS(package_exports);
27
+ var import_utils = require("@modern-js/utils");
27
28
  async function isPackageExist(packageName, registry) {
28
- if (await (0, _utils.canUseNpm)()) {
29
+ if (await (0, import_utils.canUseNpm)()) {
29
30
  try {
30
31
  const args = [
31
32
  "view",
@@ -35,8 +36,8 @@ async function isPackageExist(packageName, registry) {
35
36
  if (registry) {
36
37
  args.push(`--registry=${registry}`);
37
38
  }
38
- const result = await (0, _utils.execa)("npm", args);
39
- return (0, _utils.stripAnsi)(result.stdout);
39
+ const result = await (0, import_utils.execa)("npm", args);
40
+ return (0, import_utils.stripAnsi)(result.stdout);
40
41
  } catch (e) {
41
42
  return false;
42
43
  }
@@ -44,7 +45,7 @@ async function isPackageExist(packageName, registry) {
44
45
  throw new Error("not found npm, please install npm before");
45
46
  }
46
47
  async function isPackageDeprecated(packageName, registry) {
47
- if (await (0, _utils.canUseNpm)()) {
48
+ if (await (0, import_utils.canUseNpm)()) {
48
49
  const args = [
49
50
  "view",
50
51
  packageName,
@@ -53,13 +54,13 @@ async function isPackageDeprecated(packageName, registry) {
53
54
  if (registry) {
54
55
  args.push(`--registry=${registry}`);
55
56
  }
56
- const result = await (0, _utils.execa)("npm", args);
57
- return (0, _utils.stripAnsi)(result.stdout);
57
+ const result = await (0, import_utils.execa)("npm", args);
58
+ return (0, import_utils.stripAnsi)(result.stdout);
58
59
  }
59
60
  throw new Error("not found npm, please install npm before");
60
61
  }
61
62
  function semverDecrease(version) {
62
- const versionObj = _utils.semver.parse(version, {
63
+ const versionObj = import_utils.semver.parse(version, {
63
64
  loose: true
64
65
  });
65
66
  if (!versionObj) {
@@ -69,8 +70,8 @@ function semverDecrease(version) {
69
70
  versionObj.prerelease = [];
70
71
  versionObj.patch--;
71
72
  const result = versionObj.format();
72
- if (!_utils.semver.valid(result)) {
73
- _utils.logger.debug(`Version ${result} is not valid semver`);
73
+ if (!import_utils.semver.valid(result)) {
74
+ import_utils.logger.debug(`Version ${result} is not valid semver`);
74
75
  return version;
75
76
  }
76
77
  return result;
@@ -80,7 +81,7 @@ async function getAvailableVersion(packageName, currentVersion, registry) {
80
81
  let version = currentVersion;
81
82
  while (times) {
82
83
  if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
83
- version = _utils.semver.inc(version, "patch");
84
+ version = import_utils.semver.inc(version, "patch");
84
85
  times--;
85
86
  continue;
86
87
  }
@@ -97,3 +98,10 @@ async function getAvailableVersion(packageName, currentVersion, registry) {
97
98
  }
98
99
  return currentVersion;
99
100
  }
101
+ // Annotate the CommonJS export names for ESM import in node:
102
+ 0 && (module.exports = {
103
+ getAvailableVersion,
104
+ isPackageDeprecated,
105
+ isPackageExist,
106
+ semverDecrease
107
+ });
@@ -1,13 +1,26 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "stripAnsi", {
6
- enumerable: true,
7
- get: function() {
8
- return stripAnsi;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var stripAnsi_exports = {};
20
+ __export(stripAnsi_exports, {
21
+ stripAnsi: () => stripAnsi
10
22
  });
23
+ module.exports = __toCommonJS(stripAnsi_exports);
11
24
  function ansiRegex({ onlyFirst = false } = {}) {
12
25
  const pattern = [
13
26
  "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
@@ -21,3 +34,7 @@ function stripAnsi(string) {
21
34
  }
22
35
  return string.replace(ansiRegex(), "");
23
36
  }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ stripAnsi
40
+ });
package/dist/esm/index.js CHANGED
@@ -6,9 +6,9 @@ import { i18n, localeKeys } from "./locale";
6
6
  import { getAvailableVersion } from "./utils/package";
7
7
  import { fileExist } from "./utils/fsExist";
8
8
  export * from "./utils";
9
- export { ora, fs, semver, execa, chalk, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn, isReact18 } from "@modern-js/utils";
10
- export { i18n } from "./locale";
11
- export async function getPackageVersion(packageName, registry) {
9
+ import { ora as ora2, fs as fs2, semver, execa as execa2, chalk, readTsConfigByFile, getPackageManager, canUseNpm as canUseNpm2, canUsePnpm as canUsePnpm2, canUseYarn, isReact18 } from "@modern-js/utils";
10
+ import { i18n as i18n2 } from "./locale";
11
+ async function getPackageVersion(packageName, registry) {
12
12
  const spinner = ora({
13
13
  text: "Load Generator...",
14
14
  spinner: "runner"
@@ -42,12 +42,12 @@ export async function getPackageVersion(packageName, registry) {
42
42
  spinner.stop();
43
43
  throw new Error("not found npm, please install npm before");
44
44
  }
45
- export async function getModernVersion(solution, registry, distTag = "latest") {
45
+ async function getModernVersion(solution, registry, distTag = "latest") {
46
46
  const dep = SolutionToolsMap[solution];
47
47
  const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
48
48
  return modernVersion;
49
49
  }
50
- export async function getModernPluginVersion(solution, packageName, options = {
50
+ async function getModernPluginVersion(solution, packageName, options = {
51
51
  distTag: "latest"
52
52
  }) {
53
53
  const { cwd = process.cwd(), registry, distTag } = options;
@@ -80,21 +80,21 @@ export async function getModernPluginVersion(solution, packageName, options = {
80
80
  }
81
81
  return getLatetPluginVersion();
82
82
  }
83
- export function getPackageManagerText(packageManager) {
83
+ function getPackageManagerText(packageManager) {
84
84
  return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
85
85
  }
86
- export function isTsProject(appDir) {
86
+ function isTsProject(appDir) {
87
87
  return fs.existsSync(path.join(appDir, "tsconfig.json"));
88
88
  }
89
- export async function getPackageObj(context) {
89
+ async function getPackageObj(context) {
90
90
  const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
91
91
  return JSON.parse(pkgStr);
92
92
  }
93
- export function getAllPackages(appDir) {
93
+ function getAllPackages(appDir) {
94
94
  const packages = getMonorepoPackages(appDir);
95
95
  return packages.map((pkg) => pkg.name);
96
96
  }
97
- export function validatePackageName(value, packages, options) {
97
+ function validatePackageName(value, packages, options) {
98
98
  const { isMonorepoSubProject } = options;
99
99
  if (isMonorepoSubProject && packages.includes(value)) {
100
100
  return {
@@ -108,14 +108,9 @@ export function validatePackageName(value, packages, options) {
108
108
  success: true
109
109
  };
110
110
  }
111
- export function validatePackagePath(value, projectDir, options) {
112
- const { isMwa, isPublic, isTest } = options || {};
113
- let dir = "apps";
114
- if (isMwa && isTest) {
115
- dir = "examples";
116
- } else {
117
- dir = isPublic ? "packages" : "features";
118
- }
111
+ function validatePackagePath(value, projectDir, options) {
112
+ const { isMwa } = options || {};
113
+ const dir = isMwa ? "apps" : "packages";
119
114
  const packageDir = path.resolve(projectDir || "", dir, value);
120
115
  if (fs.existsSync(packageDir)) {
121
116
  return {
@@ -129,22 +124,22 @@ export function validatePackagePath(value, projectDir, options) {
129
124
  success: true
130
125
  };
131
126
  }
132
- export function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
127
+ function getModuleProjectPath(packagePath, isMonorepoSubProject, isLocalPackages) {
133
128
  if (isLocalPackages && packagePath) {
134
129
  return `${packagePath}/`;
135
130
  }
136
131
  if (isMonorepoSubProject && packagePath) {
137
- return `${isPublic ? "packages" : "features"}/${packagePath}/`;
132
+ return `packages/${packagePath}/`;
138
133
  }
139
134
  return "";
140
135
  }
141
- export function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
136
+ function getMWAProjectPath(packagePath, isMonorepoSubProject) {
142
137
  if (isMonorepoSubProject && packagePath) {
143
- return `${isTest ? "examples" : "apps"}/${packagePath}/`;
138
+ return `apps/${packagePath}/`;
144
139
  }
145
140
  return "";
146
141
  }
147
- export async function getModernConfigFile(appDir) {
142
+ async function getModernConfigFile(appDir) {
148
143
  let exist = await fileExist(path.join(appDir, "modern.config.ts"));
149
144
  if (exist) {
150
145
  return "modern.config.ts";
@@ -155,3 +150,29 @@ export async function getModernConfigFile(appDir) {
155
150
  }
156
151
  return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
157
152
  }
153
+ export {
154
+ canUseNpm2 as canUseNpm,
155
+ canUsePnpm2 as canUsePnpm,
156
+ canUseYarn,
157
+ chalk,
158
+ execa2 as execa,
159
+ fs2 as fs,
160
+ getAllPackages,
161
+ getMWAProjectPath,
162
+ getModernConfigFile,
163
+ getModernPluginVersion,
164
+ getModernVersion,
165
+ getModuleProjectPath,
166
+ getPackageManager,
167
+ getPackageManagerText,
168
+ getPackageObj,
169
+ getPackageVersion,
170
+ i18n2 as i18n,
171
+ isReact18,
172
+ isTsProject,
173
+ ora2 as ora,
174
+ readTsConfigByFile,
175
+ semver,
176
+ validatePackageName,
177
+ validatePackagePath
178
+ };
@@ -1,4 +1,4 @@
1
- export const EN_LOCALE = {
1
+ const EN_LOCALE = {
2
2
  packageName: {
3
3
  exit: "package name `{value}` is already exists"
4
4
  },
@@ -6,3 +6,6 @@ export const EN_LOCALE = {
6
6
  exit: "package path {value} is already exists"
7
7
  }
8
8
  };
9
+ export {
10
+ EN_LOCALE
11
+ };
@@ -6,4 +6,7 @@ const localeKeys = i18n.init("en", {
6
6
  zh: ZH_LOCALE,
7
7
  en: EN_LOCALE
8
8
  });
9
- export { i18n, localeKeys };
9
+ export {
10
+ i18n,
11
+ localeKeys
12
+ };
@@ -1,4 +1,4 @@
1
- export const ZH_LOCALE = {
1
+ const ZH_LOCALE = {
2
2
  packageName: {
3
3
  exit: "项目名称 {value} 已存在"
4
4
  },
@@ -6,3 +6,6 @@ export const ZH_LOCALE = {
6
6
  exit: "目录 {value} 已存在"
7
7
  }
8
8
  };
9
+ export {
10
+ ZH_LOCALE
11
+ };
@@ -1,5 +1,5 @@
1
1
  import { fs } from "@modern-js/utils";
2
- export async function fileExist(filePath) {
2
+ async function fileExist(filePath) {
3
3
  try {
4
4
  const stat = await fs.stat(filePath);
5
5
  if (stat.isFile()) {
@@ -10,3 +10,6 @@ export async function fileExist(filePath) {
10
10
  return false;
11
11
  }
12
12
  }
13
+ export {
14
+ fileExist
15
+ };
@@ -1,5 +1,5 @@
1
1
  import { canUseNpm, execa, logger, semver, stripAnsi } from "@modern-js/utils";
2
- export async function isPackageExist(packageName, registry) {
2
+ async function isPackageExist(packageName, registry) {
3
3
  if (await canUseNpm()) {
4
4
  try {
5
5
  const args = [
@@ -18,7 +18,7 @@ export async function isPackageExist(packageName, registry) {
18
18
  }
19
19
  throw new Error("not found npm, please install npm before");
20
20
  }
21
- export async function isPackageDeprecated(packageName, registry) {
21
+ async function isPackageDeprecated(packageName, registry) {
22
22
  if (await canUseNpm()) {
23
23
  const args = [
24
24
  "view",
@@ -33,7 +33,7 @@ export async function isPackageDeprecated(packageName, registry) {
33
33
  }
34
34
  throw new Error("not found npm, please install npm before");
35
35
  }
36
- export function semverDecrease(version) {
36
+ function semverDecrease(version) {
37
37
  const versionObj = semver.parse(version, {
38
38
  loose: true
39
39
  });
@@ -50,7 +50,7 @@ export function semverDecrease(version) {
50
50
  }
51
51
  return result;
52
52
  }
53
- export async function getAvailableVersion(packageName, currentVersion, registry) {
53
+ async function getAvailableVersion(packageName, currentVersion, registry) {
54
54
  let times = 5;
55
55
  let version = currentVersion;
56
56
  while (times) {
@@ -72,3 +72,9 @@ export async function getAvailableVersion(packageName, currentVersion, registry)
72
72
  }
73
73
  return currentVersion;
74
74
  }
75
+ export {
76
+ getAvailableVersion,
77
+ isPackageDeprecated,
78
+ isPackageExist,
79
+ semverDecrease
80
+ };
@@ -5,9 +5,12 @@ function ansiRegex({ onlyFirst = false } = {}) {
5
5
  ].join("|");
6
6
  return new RegExp(pattern, onlyFirst ? void 0 : "g");
7
7
  }
8
- export function stripAnsi(string) {
8
+ function stripAnsi(string) {
9
9
  if (typeof string !== "string") {
10
10
  throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
11
11
  }
12
12
  return string.replace(ansiRegex(), "");
13
13
  }
14
+ export {
15
+ stripAnsi
16
+ };
@@ -25,8 +25,6 @@ export declare function validatePackageName(value: string, packages: string[], o
25
25
  };
26
26
  export declare function validatePackagePath(value: string, projectDir: string, options?: {
27
27
  isMwa?: boolean;
28
- isPublic?: boolean;
29
- isTest?: boolean;
30
28
  }): {
31
29
  success: boolean;
32
30
  error: string;
@@ -34,6 +32,6 @@ export declare function validatePackagePath(value: string, projectDir: string, o
34
32
  success: boolean;
35
33
  error?: undefined;
36
34
  };
37
- export declare function getModuleProjectPath(packagePath: string, isMonorepoSubProject: boolean, isPublic: boolean, isLocalPackages: boolean): string;
38
- export declare function getMWAProjectPath(packagePath: string, isMonorepoSubProject: boolean, isTest?: boolean): string;
35
+ export declare function getModuleProjectPath(packagePath: string, isMonorepoSubProject: boolean, isLocalPackages: boolean): string;
36
+ export declare function getMWAProjectPath(packagePath: string, isMonorepoSubProject: boolean): string;
39
37
  export declare function getModernConfigFile(appDir: string): Promise<"modern.config.ts" | "modern.config.js">;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.2.2",
18
+ "version": "3.2.4",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -31,9 +31,9 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@swc/helpers": "0.5.1",
34
- "@modern-js/plugin-i18n": "2.35.1",
35
- "@modern-js/generator-common": "3.2.2",
36
- "@modern-js/utils": "2.35.1"
34
+ "@modern-js/plugin-i18n": "2.37.0",
35
+ "@modern-js/generator-common": "3.2.4",
36
+ "@modern-js/utils": "2.37.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@modern-js/codesmith": "2.2.5",
@@ -41,8 +41,8 @@
41
41
  "@types/node": "^14",
42
42
  "jest": "^29",
43
43
  "typescript": "^5",
44
- "@scripts/build": "2.35.1",
45
- "@scripts/jest-config": "2.35.1"
44
+ "@scripts/build": "2.37.0",
45
+ "@scripts/jest-config": "2.37.0"
46
46
  },
47
47
  "sideEffects": false,
48
48
  "publishConfig": {