@modern-js/generator-utils 3.0.7-beta.0 → 3.0.8
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/CHANGELOG.md +30 -4
- package/dist/{js/node → cjs}/index.js +69 -95
- package/dist/cjs/utils/fs-exist.js +38 -0
- package/dist/cjs/utils/package.js +92 -0
- package/dist/esm/index.js +182 -0
- package/dist/esm/utils/fs-exist.js +15 -0
- package/dist/esm/utils/package.js +66 -0
- package/package.json +11 -12
- package/dist/js/modern/index.js +0 -212
- package/dist/js/modern/utils/fs-exist.js +0 -37
- package/dist/js/modern/utils/package.js +0 -92
- package/dist/js/node/utils/fs-exist.js +0 -60
- package/dist/js/node/utils/package.js +0 -118
- /package/dist/{js/node → cjs}/locale/en.js +0 -0
- /package/dist/{js/node → cjs}/locale/index.js +0 -0
- /package/dist/{js/node → cjs}/locale/zh.js +0 -0
- /package/dist/{js/node → cjs}/utils/index.js +0 -0
- /package/dist/{js/node → cjs}/utils/strip-ansi.js +0 -0
- /package/dist/{js/modern → esm}/locale/en.js +0 -0
- /package/dist/{js/modern → esm}/locale/index.js +0 -0
- /package/dist/{js/modern → esm}/locale/zh.js +0 -0
- /package/dist/{js/modern → esm}/utils/index.js +0 -0
- /package/dist/{js/modern → esm}/utils/strip-ansi.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
# @modern-js/generator-utils
|
|
2
2
|
|
|
3
|
-
## 3.0.
|
|
3
|
+
## 3.0.8
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- Updated dependencies [e1f799e]
|
|
8
|
+
- Updated dependencies [b2ea17b]
|
|
9
|
+
- Updated dependencies [7915ab3]
|
|
10
|
+
- Updated dependencies [0fe658a]
|
|
11
|
+
- @modern-js/utils@2.6.0
|
|
12
|
+
- @modern-js/generator-common@3.0.8
|
|
13
|
+
- @modern-js/plugin-i18n@2.6.0
|
|
14
|
+
|
|
15
|
+
## 3.0.7
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 89ca6cc: refactor: merge build-config into scripts/build
|
|
20
|
+
|
|
21
|
+
refactor: 把 build-config 合并进 scripts/build
|
|
22
|
+
|
|
23
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
|
24
|
+
chore: 更改 package.json entry 字段以及构建配置
|
|
25
|
+
- 577084d: feat: update codesmith version
|
|
26
|
+
|
|
27
|
+
feat: 更新 codesmith 版本
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [89ca6cc]
|
|
30
|
+
- Updated dependencies [30614fa]
|
|
31
|
+
- Updated dependencies [1b0ce87]
|
|
7
32
|
- Updated dependencies [11c053b]
|
|
8
|
-
|
|
9
|
-
- @modern-js/plugin-i18n@2.
|
|
10
|
-
- @modern-js/generator-common@3.0.7
|
|
33
|
+
- Updated dependencies [577084d]
|
|
34
|
+
- @modern-js/plugin-i18n@2.5.0
|
|
35
|
+
- @modern-js/generator-common@3.0.7
|
|
36
|
+
- @modern-js/utils@2.5.0
|
|
11
37
|
|
|
12
38
|
## 3.0.6
|
|
13
39
|
|
|
@@ -18,30 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
24
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
var __async = (__this, __arguments, generator) => {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
var fulfilled = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.next(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var rejected = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.throw(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
42
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
29
|
var src_exports = {};
|
|
46
30
|
__export(src_exports, {
|
|
47
31
|
canUseNpm: () => import_utils2.canUseNpm,
|
|
@@ -80,71 +64,65 @@ var import_fs_exist = require("./utils/fs-exist");
|
|
|
80
64
|
__reExport(src_exports, require("./utils"), module.exports);
|
|
81
65
|
var import_utils2 = require("@modern-js/utils");
|
|
82
66
|
var import_locale2 = require("./locale");
|
|
83
|
-
function getPackageVersion(packageName, registry) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
args.push(`--registry=${registry}`);
|
|
93
|
-
}
|
|
94
|
-
const result = yield (0, import_utils.execa)("pnpm", args);
|
|
95
|
-
spinner.stop();
|
|
96
|
-
return (0, import_strip_ansi.stripAnsi)(result.stdout);
|
|
67
|
+
async function getPackageVersion(packageName, registry) {
|
|
68
|
+
const spinner = (0, import_utils.ora)({
|
|
69
|
+
text: "Load Generator...",
|
|
70
|
+
spinner: "runner"
|
|
71
|
+
}).start();
|
|
72
|
+
if (await (0, import_utils.canUsePnpm)()) {
|
|
73
|
+
const args = ["info", packageName, "version"];
|
|
74
|
+
if (registry) {
|
|
75
|
+
args.push(`--registry=${registry}`);
|
|
97
76
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
77
|
+
const result = await (0, import_utils.execa)("pnpm", args);
|
|
78
|
+
spinner.stop();
|
|
79
|
+
return (0, import_strip_ansi.stripAnsi)(result.stdout);
|
|
80
|
+
}
|
|
81
|
+
if (await (0, import_utils.canUseNpm)()) {
|
|
82
|
+
const args = ["view", packageName, "version"];
|
|
83
|
+
if (registry) {
|
|
84
|
+
args.push(`--registry=${registry}`);
|
|
106
85
|
}
|
|
86
|
+
const result = await (0, import_utils.execa)("npm", args);
|
|
107
87
|
spinner.stop();
|
|
108
|
-
|
|
109
|
-
}
|
|
88
|
+
return (0, import_strip_ansi.stripAnsi)(result.stdout);
|
|
89
|
+
}
|
|
90
|
+
spinner.stop();
|
|
91
|
+
throw new Error("not found npm, please install npm before");
|
|
110
92
|
}
|
|
111
|
-
function getModernVersion(solution, registry, distTag = "latest") {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return modernVersion;
|
|
116
|
-
});
|
|
93
|
+
async function getModernVersion(solution, registry, distTag = "latest") {
|
|
94
|
+
const dep = import_generator_common.SolutionToolsMap[solution];
|
|
95
|
+
const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
|
|
96
|
+
return modernVersion;
|
|
117
97
|
}
|
|
118
|
-
function getModernPluginVersion(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
registry
|
|
127
|
-
);
|
|
128
|
-
return version;
|
|
129
|
-
});
|
|
130
|
-
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
131
|
-
return getLatetPluginVersion("latest");
|
|
132
|
-
}
|
|
133
|
-
const pkgPath = import_path.default.join(
|
|
134
|
-
require.resolve(import_generator_common.SolutionToolsMap[solution], { paths: [cwd] }),
|
|
135
|
-
"../../../../",
|
|
136
|
-
"package.json"
|
|
98
|
+
async function getModernPluginVersion(solution, packageName, options = {
|
|
99
|
+
distTag: "latest"
|
|
100
|
+
}) {
|
|
101
|
+
const { cwd = process.cwd(), registry, distTag } = options;
|
|
102
|
+
const getLatetPluginVersion = async (tag) => {
|
|
103
|
+
const version = await getPackageVersion(
|
|
104
|
+
`${packageName}@${tag || distTag || "latest"}`,
|
|
105
|
+
registry
|
|
137
106
|
);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
107
|
+
return version;
|
|
108
|
+
};
|
|
109
|
+
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
110
|
+
return getLatetPluginVersion("latest");
|
|
111
|
+
}
|
|
112
|
+
const pkgPath = import_path.default.join(
|
|
113
|
+
require.resolve(import_generator_common.SolutionToolsMap[solution], { paths: [cwd] }),
|
|
114
|
+
"../../../../",
|
|
115
|
+
"package.json"
|
|
116
|
+
);
|
|
117
|
+
if (import_utils.fs.existsSync(pkgPath)) {
|
|
118
|
+
const pkgInfo = import_utils.fs.readJSONSync(pkgPath);
|
|
119
|
+
const modernVersion = pkgInfo.version;
|
|
120
|
+
if (typeof modernVersion !== "string") {
|
|
121
|
+
return getLatetPluginVersion();
|
|
145
122
|
}
|
|
146
|
-
return
|
|
147
|
-
}
|
|
123
|
+
return (0, import_package.getAvailableVersion)(packageName, modernVersion, registry);
|
|
124
|
+
}
|
|
125
|
+
return getLatetPluginVersion();
|
|
148
126
|
}
|
|
149
127
|
function getPackageManagerText(packageManager) {
|
|
150
128
|
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
@@ -152,11 +130,9 @@ function getPackageManagerText(packageManager) {
|
|
|
152
130
|
function isTsProject(appDir) {
|
|
153
131
|
return import_utils.fs.existsSync(import_path.default.join(appDir, "tsconfig.json"));
|
|
154
132
|
}
|
|
155
|
-
function getPackageObj(context) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return JSON.parse(pkgStr);
|
|
159
|
-
});
|
|
133
|
+
async function getPackageObj(context) {
|
|
134
|
+
const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
|
|
135
|
+
return JSON.parse(pkgStr);
|
|
160
136
|
}
|
|
161
137
|
function getAllPackages(appDir) {
|
|
162
138
|
const packages = (0, import_utils.getMonorepoPackages)(appDir);
|
|
@@ -204,18 +180,16 @@ function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
|
204
180
|
}
|
|
205
181
|
return "";
|
|
206
182
|
}
|
|
207
|
-
function getModernConfigFile(appDir) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
218
|
-
});
|
|
183
|
+
async function getModernConfigFile(appDir) {
|
|
184
|
+
let exist = await (0, import_fs_exist.fileExist)(import_path.default.join(appDir, "modern.config.ts"));
|
|
185
|
+
if (exist) {
|
|
186
|
+
return "modern.config.ts";
|
|
187
|
+
}
|
|
188
|
+
exist = await (0, import_fs_exist.fileExist)(import_path.default.join(appDir, "modern.config.js"));
|
|
189
|
+
if (exist) {
|
|
190
|
+
return "modern.config.js";
|
|
191
|
+
}
|
|
192
|
+
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
219
193
|
}
|
|
220
194
|
// Annotate the CommonJS export names for ESM import in node:
|
|
221
195
|
0 && (module.exports = {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var fs_exist_exports = {};
|
|
19
|
+
__export(fs_exist_exports, {
|
|
20
|
+
fileExist: () => fileExist
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(fs_exist_exports);
|
|
23
|
+
var import_utils = require("@modern-js/utils");
|
|
24
|
+
async function fileExist(filePath) {
|
|
25
|
+
try {
|
|
26
|
+
const stat = await import_utils.fs.stat(filePath);
|
|
27
|
+
if (stat.isFile()) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
fileExist
|
|
38
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var package_exports = {};
|
|
19
|
+
__export(package_exports, {
|
|
20
|
+
getAvailableVersion: () => getAvailableVersion,
|
|
21
|
+
isPackageDeprecated: () => isPackageDeprecated,
|
|
22
|
+
isPackageExist: () => isPackageExist,
|
|
23
|
+
semverDecrease: () => semverDecrease
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(package_exports);
|
|
26
|
+
var import_utils = require("@modern-js/utils");
|
|
27
|
+
async function isPackageExist(packageName, registry) {
|
|
28
|
+
if (await (0, import_utils.canUseNpm)()) {
|
|
29
|
+
const args = ["view", packageName, "version"];
|
|
30
|
+
if (registry) {
|
|
31
|
+
args.push(`--registry=${registry}`);
|
|
32
|
+
}
|
|
33
|
+
const result = await (0, import_utils.execa)("npm", args);
|
|
34
|
+
return (0, import_utils.stripAnsi)(result.stdout);
|
|
35
|
+
}
|
|
36
|
+
throw new Error("not found npm, please install npm before");
|
|
37
|
+
}
|
|
38
|
+
async function isPackageDeprecated(packageName, registry) {
|
|
39
|
+
if (await (0, import_utils.canUseNpm)()) {
|
|
40
|
+
const args = ["view", packageName, "deprecated"];
|
|
41
|
+
if (registry) {
|
|
42
|
+
args.push(`--registry=${registry}`);
|
|
43
|
+
}
|
|
44
|
+
const result = await (0, import_utils.execa)("npm", args);
|
|
45
|
+
return (0, import_utils.stripAnsi)(result.stdout);
|
|
46
|
+
}
|
|
47
|
+
throw new Error("not found npm, please install npm before");
|
|
48
|
+
}
|
|
49
|
+
function semverDecrease(version) {
|
|
50
|
+
const versionObj = import_utils.semver.parse(version, { loose: true });
|
|
51
|
+
if (!versionObj) {
|
|
52
|
+
throw new Error(`Version ${version} is not valid semver`);
|
|
53
|
+
}
|
|
54
|
+
versionObj.build = [];
|
|
55
|
+
versionObj.prerelease = [];
|
|
56
|
+
versionObj.patch--;
|
|
57
|
+
const result = versionObj.format();
|
|
58
|
+
if (!import_utils.semver.valid(result)) {
|
|
59
|
+
import_utils.logger.debug(`Version ${result} is not valid semver`);
|
|
60
|
+
return version;
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
65
|
+
let times = 5;
|
|
66
|
+
let version = currentVersion;
|
|
67
|
+
while (times) {
|
|
68
|
+
if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
|
|
69
|
+
version = import_utils.semver.inc(version, "patch");
|
|
70
|
+
times--;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
return version;
|
|
74
|
+
}
|
|
75
|
+
times = 5;
|
|
76
|
+
while (times) {
|
|
77
|
+
version = semverDecrease(version);
|
|
78
|
+
if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
|
|
79
|
+
times--;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
return version;
|
|
83
|
+
}
|
|
84
|
+
return currentVersion;
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
getAvailableVersion,
|
|
89
|
+
isPackageDeprecated,
|
|
90
|
+
isPackageExist,
|
|
91
|
+
semverDecrease
|
|
92
|
+
});
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import {
|
|
3
|
+
fs,
|
|
4
|
+
ora,
|
|
5
|
+
execa,
|
|
6
|
+
getMonorepoPackages,
|
|
7
|
+
canUseNpm,
|
|
8
|
+
canUsePnpm
|
|
9
|
+
} from "@modern-js/utils";
|
|
10
|
+
import { SolutionToolsMap } from "@modern-js/generator-common";
|
|
11
|
+
import { stripAnsi } from "./utils/strip-ansi";
|
|
12
|
+
import { i18n, localeKeys } from "./locale";
|
|
13
|
+
import { getAvailableVersion } from "./utils/package";
|
|
14
|
+
import { fileExist } from "./utils/fs-exist";
|
|
15
|
+
export * from "./utils";
|
|
16
|
+
import {
|
|
17
|
+
ora as ora2,
|
|
18
|
+
fs as fs2,
|
|
19
|
+
semver,
|
|
20
|
+
execa as execa2,
|
|
21
|
+
chalk,
|
|
22
|
+
readTsConfigByFile,
|
|
23
|
+
getPackageManager,
|
|
24
|
+
canUseNpm as canUseNpm2,
|
|
25
|
+
canUsePnpm as canUsePnpm2,
|
|
26
|
+
canUseYarn,
|
|
27
|
+
isReact18
|
|
28
|
+
} from "@modern-js/utils";
|
|
29
|
+
import { i18n as i18n2 } from "./locale";
|
|
30
|
+
async function getPackageVersion(packageName, registry) {
|
|
31
|
+
const spinner = ora({
|
|
32
|
+
text: "Load Generator...",
|
|
33
|
+
spinner: "runner"
|
|
34
|
+
}).start();
|
|
35
|
+
if (await canUsePnpm()) {
|
|
36
|
+
const args = ["info", packageName, "version"];
|
|
37
|
+
if (registry) {
|
|
38
|
+
args.push(`--registry=${registry}`);
|
|
39
|
+
}
|
|
40
|
+
const result = await execa("pnpm", args);
|
|
41
|
+
spinner.stop();
|
|
42
|
+
return stripAnsi(result.stdout);
|
|
43
|
+
}
|
|
44
|
+
if (await canUseNpm()) {
|
|
45
|
+
const args = ["view", packageName, "version"];
|
|
46
|
+
if (registry) {
|
|
47
|
+
args.push(`--registry=${registry}`);
|
|
48
|
+
}
|
|
49
|
+
const result = await execa("npm", args);
|
|
50
|
+
spinner.stop();
|
|
51
|
+
return stripAnsi(result.stdout);
|
|
52
|
+
}
|
|
53
|
+
spinner.stop();
|
|
54
|
+
throw new Error("not found npm, please install npm before");
|
|
55
|
+
}
|
|
56
|
+
async function getModernVersion(solution, registry, distTag = "latest") {
|
|
57
|
+
const dep = SolutionToolsMap[solution];
|
|
58
|
+
const modernVersion = await getPackageVersion(`${dep}@${distTag}`, registry);
|
|
59
|
+
return modernVersion;
|
|
60
|
+
}
|
|
61
|
+
async function getModernPluginVersion(solution, packageName, options = {
|
|
62
|
+
distTag: "latest"
|
|
63
|
+
}) {
|
|
64
|
+
const { cwd = process.cwd(), registry, distTag } = options;
|
|
65
|
+
const getLatetPluginVersion = async (tag) => {
|
|
66
|
+
const version = await getPackageVersion(
|
|
67
|
+
`${packageName}@${tag || distTag || "latest"}`,
|
|
68
|
+
registry
|
|
69
|
+
);
|
|
70
|
+
return version;
|
|
71
|
+
};
|
|
72
|
+
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
73
|
+
return getLatetPluginVersion("latest");
|
|
74
|
+
}
|
|
75
|
+
const pkgPath = path.join(
|
|
76
|
+
require.resolve(SolutionToolsMap[solution], { paths: [cwd] }),
|
|
77
|
+
"../../../../",
|
|
78
|
+
"package.json"
|
|
79
|
+
);
|
|
80
|
+
if (fs.existsSync(pkgPath)) {
|
|
81
|
+
const pkgInfo = fs.readJSONSync(pkgPath);
|
|
82
|
+
const modernVersion = pkgInfo.version;
|
|
83
|
+
if (typeof modernVersion !== "string") {
|
|
84
|
+
return getLatetPluginVersion();
|
|
85
|
+
}
|
|
86
|
+
return getAvailableVersion(packageName, modernVersion, registry);
|
|
87
|
+
}
|
|
88
|
+
return getLatetPluginVersion();
|
|
89
|
+
}
|
|
90
|
+
function getPackageManagerText(packageManager) {
|
|
91
|
+
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
92
|
+
}
|
|
93
|
+
function isTsProject(appDir) {
|
|
94
|
+
return fs.existsSync(path.join(appDir, "tsconfig.json"));
|
|
95
|
+
}
|
|
96
|
+
async function getPackageObj(context) {
|
|
97
|
+
const pkgStr = (await context.materials.default.get(`package.json`).value()).content;
|
|
98
|
+
return JSON.parse(pkgStr);
|
|
99
|
+
}
|
|
100
|
+
function getAllPackages(appDir) {
|
|
101
|
+
const packages = getMonorepoPackages(appDir);
|
|
102
|
+
return packages.map((pkg) => pkg.name);
|
|
103
|
+
}
|
|
104
|
+
function validatePackageName(value, packages, options) {
|
|
105
|
+
const { isMonorepoSubProject } = options;
|
|
106
|
+
if (isMonorepoSubProject && packages.includes(value)) {
|
|
107
|
+
return {
|
|
108
|
+
success: false,
|
|
109
|
+
error: i18n.t(localeKeys.packageName.exit, { value })
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return { success: true };
|
|
113
|
+
}
|
|
114
|
+
function validatePackagePath(value, projectDir, options) {
|
|
115
|
+
const { isMwa, isPublic, isTest } = options || {};
|
|
116
|
+
let dir = "apps";
|
|
117
|
+
if (isMwa && isTest) {
|
|
118
|
+
dir = "examples";
|
|
119
|
+
} else {
|
|
120
|
+
dir = isPublic ? "packages" : "features";
|
|
121
|
+
}
|
|
122
|
+
const packageDir = path.resolve(projectDir || "", dir, value);
|
|
123
|
+
if (fs.existsSync(packageDir)) {
|
|
124
|
+
return {
|
|
125
|
+
success: false,
|
|
126
|
+
error: i18n.t(localeKeys.packagePath.exit, { value })
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return { success: true };
|
|
130
|
+
}
|
|
131
|
+
function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
132
|
+
if (isLocalPackages && packagePath) {
|
|
133
|
+
return `${packagePath}/`;
|
|
134
|
+
}
|
|
135
|
+
if (isMonorepoSubProject && packagePath) {
|
|
136
|
+
return `${isPublic ? "packages" : "features"}/${packagePath}/`;
|
|
137
|
+
}
|
|
138
|
+
return "";
|
|
139
|
+
}
|
|
140
|
+
function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
141
|
+
if (isMonorepoSubProject && packagePath) {
|
|
142
|
+
return `${isTest ? "examples" : "apps"}/${packagePath}/`;
|
|
143
|
+
}
|
|
144
|
+
return "";
|
|
145
|
+
}
|
|
146
|
+
async function getModernConfigFile(appDir) {
|
|
147
|
+
let exist = await fileExist(path.join(appDir, "modern.config.ts"));
|
|
148
|
+
if (exist) {
|
|
149
|
+
return "modern.config.ts";
|
|
150
|
+
}
|
|
151
|
+
exist = await fileExist(path.join(appDir, "modern.config.js"));
|
|
152
|
+
if (exist) {
|
|
153
|
+
return "modern.config.js";
|
|
154
|
+
}
|
|
155
|
+
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
156
|
+
}
|
|
157
|
+
export {
|
|
158
|
+
canUseNpm2 as canUseNpm,
|
|
159
|
+
canUsePnpm2 as canUsePnpm,
|
|
160
|
+
canUseYarn,
|
|
161
|
+
chalk,
|
|
162
|
+
execa2 as execa,
|
|
163
|
+
fs2 as fs,
|
|
164
|
+
getAllPackages,
|
|
165
|
+
getMWAProjectPath,
|
|
166
|
+
getModernConfigFile,
|
|
167
|
+
getModernPluginVersion,
|
|
168
|
+
getModernVersion,
|
|
169
|
+
getModuleProjectPath,
|
|
170
|
+
getPackageManager,
|
|
171
|
+
getPackageManagerText,
|
|
172
|
+
getPackageObj,
|
|
173
|
+
getPackageVersion,
|
|
174
|
+
i18n2 as i18n,
|
|
175
|
+
isReact18,
|
|
176
|
+
isTsProject,
|
|
177
|
+
ora2 as ora,
|
|
178
|
+
readTsConfigByFile,
|
|
179
|
+
semver,
|
|
180
|
+
validatePackageName,
|
|
181
|
+
validatePackagePath
|
|
182
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { fs } from "@modern-js/utils";
|
|
2
|
+
async function fileExist(filePath) {
|
|
3
|
+
try {
|
|
4
|
+
const stat = await fs.stat(filePath);
|
|
5
|
+
if (stat.isFile()) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
} catch (e) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
fileExist
|
|
15
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { canUseNpm, execa, logger, semver, stripAnsi } from "@modern-js/utils";
|
|
2
|
+
async function isPackageExist(packageName, registry) {
|
|
3
|
+
if (await canUseNpm()) {
|
|
4
|
+
const args = ["view", packageName, "version"];
|
|
5
|
+
if (registry) {
|
|
6
|
+
args.push(`--registry=${registry}`);
|
|
7
|
+
}
|
|
8
|
+
const result = await execa("npm", args);
|
|
9
|
+
return stripAnsi(result.stdout);
|
|
10
|
+
}
|
|
11
|
+
throw new Error("not found npm, please install npm before");
|
|
12
|
+
}
|
|
13
|
+
async function isPackageDeprecated(packageName, registry) {
|
|
14
|
+
if (await canUseNpm()) {
|
|
15
|
+
const args = ["view", packageName, "deprecated"];
|
|
16
|
+
if (registry) {
|
|
17
|
+
args.push(`--registry=${registry}`);
|
|
18
|
+
}
|
|
19
|
+
const result = await execa("npm", args);
|
|
20
|
+
return stripAnsi(result.stdout);
|
|
21
|
+
}
|
|
22
|
+
throw new Error("not found npm, please install npm before");
|
|
23
|
+
}
|
|
24
|
+
function semverDecrease(version) {
|
|
25
|
+
const versionObj = semver.parse(version, { loose: true });
|
|
26
|
+
if (!versionObj) {
|
|
27
|
+
throw new Error(`Version ${version} is not valid semver`);
|
|
28
|
+
}
|
|
29
|
+
versionObj.build = [];
|
|
30
|
+
versionObj.prerelease = [];
|
|
31
|
+
versionObj.patch--;
|
|
32
|
+
const result = versionObj.format();
|
|
33
|
+
if (!semver.valid(result)) {
|
|
34
|
+
logger.debug(`Version ${result} is not valid semver`);
|
|
35
|
+
return version;
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
async function getAvailableVersion(packageName, currentVersion, registry) {
|
|
40
|
+
let times = 5;
|
|
41
|
+
let version = currentVersion;
|
|
42
|
+
while (times) {
|
|
43
|
+
if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
|
|
44
|
+
version = semver.inc(version, "patch");
|
|
45
|
+
times--;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
return version;
|
|
49
|
+
}
|
|
50
|
+
times = 5;
|
|
51
|
+
while (times) {
|
|
52
|
+
version = semverDecrease(version);
|
|
53
|
+
if (!await isPackageExist(`${packageName}@${version}`, registry) || await isPackageDeprecated(`${packageName}@${version}`, registry)) {
|
|
54
|
+
times--;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
return version;
|
|
58
|
+
}
|
|
59
|
+
return currentVersion;
|
|
60
|
+
}
|
|
61
|
+
export {
|
|
62
|
+
getAvailableVersion,
|
|
63
|
+
isPackageDeprecated,
|
|
64
|
+
isPackageExist,
|
|
65
|
+
semverDecrease
|
|
66
|
+
};
|
package/package.json
CHANGED
|
@@ -11,35 +11,34 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "3.0.
|
|
14
|
+
"version": "3.0.8",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
21
20
|
"node": {
|
|
22
21
|
"jsnext:source": "./src/index.ts",
|
|
23
|
-
"import": "./dist/
|
|
24
|
-
"require": "./dist/
|
|
22
|
+
"import": "./dist/esm/index.js",
|
|
23
|
+
"require": "./dist/cjs/index.js"
|
|
25
24
|
},
|
|
26
|
-
"default": "./dist/
|
|
25
|
+
"default": "./dist/cjs/index.js"
|
|
27
26
|
}
|
|
28
27
|
},
|
|
29
28
|
"dependencies": {
|
|
30
29
|
"@babel/runtime": "^7.18.0",
|
|
31
|
-
"@modern-js/plugin-i18n": "2.
|
|
32
|
-
"@modern-js/generator-common": "3.0.
|
|
33
|
-
"@modern-js/utils": "2.
|
|
30
|
+
"@modern-js/plugin-i18n": "2.6.0",
|
|
31
|
+
"@modern-js/generator-common": "3.0.8",
|
|
32
|
+
"@modern-js/utils": "2.6.0"
|
|
34
33
|
},
|
|
35
34
|
"devDependencies": {
|
|
36
|
-
"@modern-js/codesmith": "2.0.
|
|
35
|
+
"@modern-js/codesmith": "2.0.4",
|
|
37
36
|
"@types/jest": "^27",
|
|
38
37
|
"@types/node": "^14",
|
|
39
38
|
"jest": "^27",
|
|
40
39
|
"typescript": "^4",
|
|
41
|
-
"@scripts/build": "2.
|
|
42
|
-
"@scripts/jest-config": "2.
|
|
40
|
+
"@scripts/build": "2.6.0",
|
|
41
|
+
"@scripts/jest-config": "2.6.0"
|
|
43
42
|
},
|
|
44
43
|
"sideEffects": false,
|
|
45
44
|
"modernConfig": {
|
package/dist/js/modern/index.js
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import path from "path";
|
|
22
|
-
import {
|
|
23
|
-
fs,
|
|
24
|
-
ora,
|
|
25
|
-
execa,
|
|
26
|
-
getMonorepoPackages,
|
|
27
|
-
canUseNpm,
|
|
28
|
-
canUsePnpm
|
|
29
|
-
} from "@modern-js/utils";
|
|
30
|
-
import { SolutionToolsMap } from "@modern-js/generator-common";
|
|
31
|
-
import { stripAnsi } from "./utils/strip-ansi";
|
|
32
|
-
import { i18n, localeKeys } from "./locale";
|
|
33
|
-
import { getAvailableVersion } from "./utils/package";
|
|
34
|
-
import { fileExist } from "./utils/fs-exist";
|
|
35
|
-
export * from "./utils";
|
|
36
|
-
import {
|
|
37
|
-
ora as ora2,
|
|
38
|
-
fs as fs2,
|
|
39
|
-
semver,
|
|
40
|
-
execa as execa2,
|
|
41
|
-
chalk,
|
|
42
|
-
readTsConfigByFile,
|
|
43
|
-
getPackageManager,
|
|
44
|
-
canUseNpm as canUseNpm2,
|
|
45
|
-
canUsePnpm as canUsePnpm2,
|
|
46
|
-
canUseYarn,
|
|
47
|
-
isReact18
|
|
48
|
-
} from "@modern-js/utils";
|
|
49
|
-
import { i18n as i18n2 } from "./locale";
|
|
50
|
-
function getPackageVersion(packageName, registry) {
|
|
51
|
-
return __async(this, null, function* () {
|
|
52
|
-
const spinner = ora({
|
|
53
|
-
text: "Load Generator...",
|
|
54
|
-
spinner: "runner"
|
|
55
|
-
}).start();
|
|
56
|
-
if (yield canUsePnpm()) {
|
|
57
|
-
const args = ["info", packageName, "version"];
|
|
58
|
-
if (registry) {
|
|
59
|
-
args.push(`--registry=${registry}`);
|
|
60
|
-
}
|
|
61
|
-
const result = yield execa("pnpm", args);
|
|
62
|
-
spinner.stop();
|
|
63
|
-
return stripAnsi(result.stdout);
|
|
64
|
-
}
|
|
65
|
-
if (yield canUseNpm()) {
|
|
66
|
-
const args = ["view", packageName, "version"];
|
|
67
|
-
if (registry) {
|
|
68
|
-
args.push(`--registry=${registry}`);
|
|
69
|
-
}
|
|
70
|
-
const result = yield execa("npm", args);
|
|
71
|
-
spinner.stop();
|
|
72
|
-
return stripAnsi(result.stdout);
|
|
73
|
-
}
|
|
74
|
-
spinner.stop();
|
|
75
|
-
throw new Error("not found npm, please install npm before");
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function getModernVersion(solution, registry, distTag = "latest") {
|
|
79
|
-
return __async(this, null, function* () {
|
|
80
|
-
const dep = SolutionToolsMap[solution];
|
|
81
|
-
const modernVersion = yield getPackageVersion(`${dep}@${distTag}`, registry);
|
|
82
|
-
return modernVersion;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
function getModernPluginVersion(_0, _1) {
|
|
86
|
-
return __async(this, arguments, function* (solution, packageName, options = {
|
|
87
|
-
distTag: "latest"
|
|
88
|
-
}) {
|
|
89
|
-
const { cwd = process.cwd(), registry, distTag } = options;
|
|
90
|
-
const getLatetPluginVersion = (tag) => __async(this, null, function* () {
|
|
91
|
-
const version = yield getPackageVersion(
|
|
92
|
-
`${packageName}@${tag || distTag || "latest"}`,
|
|
93
|
-
registry
|
|
94
|
-
);
|
|
95
|
-
return version;
|
|
96
|
-
});
|
|
97
|
-
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
98
|
-
return getLatetPluginVersion("latest");
|
|
99
|
-
}
|
|
100
|
-
const pkgPath = path.join(
|
|
101
|
-
require.resolve(SolutionToolsMap[solution], { paths: [cwd] }),
|
|
102
|
-
"../../../../",
|
|
103
|
-
"package.json"
|
|
104
|
-
);
|
|
105
|
-
if (fs.existsSync(pkgPath)) {
|
|
106
|
-
const pkgInfo = fs.readJSONSync(pkgPath);
|
|
107
|
-
const modernVersion = pkgInfo.version;
|
|
108
|
-
if (typeof modernVersion !== "string") {
|
|
109
|
-
return getLatetPluginVersion();
|
|
110
|
-
}
|
|
111
|
-
return getAvailableVersion(packageName, modernVersion, registry);
|
|
112
|
-
}
|
|
113
|
-
return getLatetPluginVersion();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
function getPackageManagerText(packageManager) {
|
|
117
|
-
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
118
|
-
}
|
|
119
|
-
function isTsProject(appDir) {
|
|
120
|
-
return fs.existsSync(path.join(appDir, "tsconfig.json"));
|
|
121
|
-
}
|
|
122
|
-
function getPackageObj(context) {
|
|
123
|
-
return __async(this, null, function* () {
|
|
124
|
-
const pkgStr = (yield context.materials.default.get(`package.json`).value()).content;
|
|
125
|
-
return JSON.parse(pkgStr);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
function getAllPackages(appDir) {
|
|
129
|
-
const packages = getMonorepoPackages(appDir);
|
|
130
|
-
return packages.map((pkg) => pkg.name);
|
|
131
|
-
}
|
|
132
|
-
function validatePackageName(value, packages, options) {
|
|
133
|
-
const { isMonorepoSubProject } = options;
|
|
134
|
-
if (isMonorepoSubProject && packages.includes(value)) {
|
|
135
|
-
return {
|
|
136
|
-
success: false,
|
|
137
|
-
error: i18n.t(localeKeys.packageName.exit, { value })
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return { success: true };
|
|
141
|
-
}
|
|
142
|
-
function validatePackagePath(value, projectDir, options) {
|
|
143
|
-
const { isMwa, isPublic, isTest } = options || {};
|
|
144
|
-
let dir = "apps";
|
|
145
|
-
if (isMwa && isTest) {
|
|
146
|
-
dir = "examples";
|
|
147
|
-
} else {
|
|
148
|
-
dir = isPublic ? "packages" : "features";
|
|
149
|
-
}
|
|
150
|
-
const packageDir = path.resolve(projectDir || "", dir, value);
|
|
151
|
-
if (fs.existsSync(packageDir)) {
|
|
152
|
-
return {
|
|
153
|
-
success: false,
|
|
154
|
-
error: i18n.t(localeKeys.packagePath.exit, { value })
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
return { success: true };
|
|
158
|
-
}
|
|
159
|
-
function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
160
|
-
if (isLocalPackages && packagePath) {
|
|
161
|
-
return `${packagePath}/`;
|
|
162
|
-
}
|
|
163
|
-
if (isMonorepoSubProject && packagePath) {
|
|
164
|
-
return `${isPublic ? "packages" : "features"}/${packagePath}/`;
|
|
165
|
-
}
|
|
166
|
-
return "";
|
|
167
|
-
}
|
|
168
|
-
function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
169
|
-
if (isMonorepoSubProject && packagePath) {
|
|
170
|
-
return `${isTest ? "examples" : "apps"}/${packagePath}/`;
|
|
171
|
-
}
|
|
172
|
-
return "";
|
|
173
|
-
}
|
|
174
|
-
function getModernConfigFile(appDir) {
|
|
175
|
-
return __async(this, null, function* () {
|
|
176
|
-
let exist = yield fileExist(path.join(appDir, "modern.config.ts"));
|
|
177
|
-
if (exist) {
|
|
178
|
-
return "modern.config.ts";
|
|
179
|
-
}
|
|
180
|
-
exist = yield fileExist(path.join(appDir, "modern.config.js"));
|
|
181
|
-
if (exist) {
|
|
182
|
-
return "modern.config.js";
|
|
183
|
-
}
|
|
184
|
-
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
export {
|
|
188
|
-
canUseNpm2 as canUseNpm,
|
|
189
|
-
canUsePnpm2 as canUsePnpm,
|
|
190
|
-
canUseYarn,
|
|
191
|
-
chalk,
|
|
192
|
-
execa2 as execa,
|
|
193
|
-
fs2 as fs,
|
|
194
|
-
getAllPackages,
|
|
195
|
-
getMWAProjectPath,
|
|
196
|
-
getModernConfigFile,
|
|
197
|
-
getModernPluginVersion,
|
|
198
|
-
getModernVersion,
|
|
199
|
-
getModuleProjectPath,
|
|
200
|
-
getPackageManager,
|
|
201
|
-
getPackageManagerText,
|
|
202
|
-
getPackageObj,
|
|
203
|
-
getPackageVersion,
|
|
204
|
-
i18n2 as i18n,
|
|
205
|
-
isReact18,
|
|
206
|
-
isTsProject,
|
|
207
|
-
ora2 as ora,
|
|
208
|
-
readTsConfigByFile,
|
|
209
|
-
semver,
|
|
210
|
-
validatePackageName,
|
|
211
|
-
validatePackagePath
|
|
212
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { fs } from "@modern-js/utils";
|
|
22
|
-
function fileExist(filePath) {
|
|
23
|
-
return __async(this, null, function* () {
|
|
24
|
-
try {
|
|
25
|
-
const stat = yield fs.stat(filePath);
|
|
26
|
-
if (stat.isFile()) {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
} catch (e) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
export {
|
|
36
|
-
fileExist
|
|
37
|
-
};
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import { canUseNpm, execa, logger, semver, stripAnsi } from "@modern-js/utils";
|
|
22
|
-
function isPackageExist(packageName, registry) {
|
|
23
|
-
return __async(this, null, function* () {
|
|
24
|
-
if (yield canUseNpm()) {
|
|
25
|
-
const args = ["view", packageName, "version"];
|
|
26
|
-
if (registry) {
|
|
27
|
-
args.push(`--registry=${registry}`);
|
|
28
|
-
}
|
|
29
|
-
const result = yield execa("npm", args);
|
|
30
|
-
return stripAnsi(result.stdout);
|
|
31
|
-
}
|
|
32
|
-
throw new Error("not found npm, please install npm before");
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function isPackageDeprecated(packageName, registry) {
|
|
36
|
-
return __async(this, null, function* () {
|
|
37
|
-
if (yield canUseNpm()) {
|
|
38
|
-
const args = ["view", packageName, "deprecated"];
|
|
39
|
-
if (registry) {
|
|
40
|
-
args.push(`--registry=${registry}`);
|
|
41
|
-
}
|
|
42
|
-
const result = yield execa("npm", args);
|
|
43
|
-
return stripAnsi(result.stdout);
|
|
44
|
-
}
|
|
45
|
-
throw new Error("not found npm, please install npm before");
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function semverDecrease(version) {
|
|
49
|
-
const versionObj = semver.parse(version, { loose: true });
|
|
50
|
-
if (!versionObj) {
|
|
51
|
-
throw new Error(`Version ${version} is not valid semver`);
|
|
52
|
-
}
|
|
53
|
-
versionObj.build = [];
|
|
54
|
-
versionObj.prerelease = [];
|
|
55
|
-
versionObj.patch--;
|
|
56
|
-
const result = versionObj.format();
|
|
57
|
-
if (!semver.valid(result)) {
|
|
58
|
-
logger.debug(`Version ${result} is not valid semver`);
|
|
59
|
-
return version;
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
function getAvailableVersion(packageName, currentVersion, registry) {
|
|
64
|
-
return __async(this, null, function* () {
|
|
65
|
-
let times = 5;
|
|
66
|
-
let version = currentVersion;
|
|
67
|
-
while (times) {
|
|
68
|
-
if (!(yield isPackageExist(`${packageName}@${version}`, registry)) || (yield isPackageDeprecated(`${packageName}@${version}`, registry))) {
|
|
69
|
-
version = semver.inc(version, "patch");
|
|
70
|
-
times--;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
return version;
|
|
74
|
-
}
|
|
75
|
-
times = 5;
|
|
76
|
-
while (times) {
|
|
77
|
-
version = semverDecrease(version);
|
|
78
|
-
if (!(yield isPackageExist(`${packageName}@${version}`, registry)) || (yield isPackageDeprecated(`${packageName}@${version}`, registry))) {
|
|
79
|
-
times--;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
return version;
|
|
83
|
-
}
|
|
84
|
-
return currentVersion;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
export {
|
|
88
|
-
getAvailableVersion,
|
|
89
|
-
isPackageDeprecated,
|
|
90
|
-
isPackageExist,
|
|
91
|
-
semverDecrease
|
|
92
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var fs_exist_exports = {};
|
|
39
|
-
__export(fs_exist_exports, {
|
|
40
|
-
fileExist: () => fileExist
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(fs_exist_exports);
|
|
43
|
-
var import_utils = require("@modern-js/utils");
|
|
44
|
-
function fileExist(filePath) {
|
|
45
|
-
return __async(this, null, function* () {
|
|
46
|
-
try {
|
|
47
|
-
const stat = yield import_utils.fs.stat(filePath);
|
|
48
|
-
if (stat.isFile()) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
-
0 && (module.exports = {
|
|
59
|
-
fileExist
|
|
60
|
-
});
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
var package_exports = {};
|
|
39
|
-
__export(package_exports, {
|
|
40
|
-
getAvailableVersion: () => getAvailableVersion,
|
|
41
|
-
isPackageDeprecated: () => isPackageDeprecated,
|
|
42
|
-
isPackageExist: () => isPackageExist,
|
|
43
|
-
semverDecrease: () => semverDecrease
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(package_exports);
|
|
46
|
-
var import_utils = require("@modern-js/utils");
|
|
47
|
-
function isPackageExist(packageName, registry) {
|
|
48
|
-
return __async(this, null, function* () {
|
|
49
|
-
if (yield (0, import_utils.canUseNpm)()) {
|
|
50
|
-
const args = ["view", packageName, "version"];
|
|
51
|
-
if (registry) {
|
|
52
|
-
args.push(`--registry=${registry}`);
|
|
53
|
-
}
|
|
54
|
-
const result = yield (0, import_utils.execa)("npm", args);
|
|
55
|
-
return (0, import_utils.stripAnsi)(result.stdout);
|
|
56
|
-
}
|
|
57
|
-
throw new Error("not found npm, please install npm before");
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function isPackageDeprecated(packageName, registry) {
|
|
61
|
-
return __async(this, null, function* () {
|
|
62
|
-
if (yield (0, import_utils.canUseNpm)()) {
|
|
63
|
-
const args = ["view", packageName, "deprecated"];
|
|
64
|
-
if (registry) {
|
|
65
|
-
args.push(`--registry=${registry}`);
|
|
66
|
-
}
|
|
67
|
-
const result = yield (0, import_utils.execa)("npm", args);
|
|
68
|
-
return (0, import_utils.stripAnsi)(result.stdout);
|
|
69
|
-
}
|
|
70
|
-
throw new Error("not found npm, please install npm before");
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function semverDecrease(version) {
|
|
74
|
-
const versionObj = import_utils.semver.parse(version, { loose: true });
|
|
75
|
-
if (!versionObj) {
|
|
76
|
-
throw new Error(`Version ${version} is not valid semver`);
|
|
77
|
-
}
|
|
78
|
-
versionObj.build = [];
|
|
79
|
-
versionObj.prerelease = [];
|
|
80
|
-
versionObj.patch--;
|
|
81
|
-
const result = versionObj.format();
|
|
82
|
-
if (!import_utils.semver.valid(result)) {
|
|
83
|
-
import_utils.logger.debug(`Version ${result} is not valid semver`);
|
|
84
|
-
return version;
|
|
85
|
-
}
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
|
-
function getAvailableVersion(packageName, currentVersion, registry) {
|
|
89
|
-
return __async(this, null, function* () {
|
|
90
|
-
let times = 5;
|
|
91
|
-
let version = currentVersion;
|
|
92
|
-
while (times) {
|
|
93
|
-
if (!(yield isPackageExist(`${packageName}@${version}`, registry)) || (yield isPackageDeprecated(`${packageName}@${version}`, registry))) {
|
|
94
|
-
version = import_utils.semver.inc(version, "patch");
|
|
95
|
-
times--;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
return version;
|
|
99
|
-
}
|
|
100
|
-
times = 5;
|
|
101
|
-
while (times) {
|
|
102
|
-
version = semverDecrease(version);
|
|
103
|
-
if (!(yield isPackageExist(`${packageName}@${version}`, registry)) || (yield isPackageDeprecated(`${packageName}@${version}`, registry))) {
|
|
104
|
-
times--;
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
return version;
|
|
108
|
-
}
|
|
109
|
-
return currentVersion;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
-
0 && (module.exports = {
|
|
114
|
-
getAvailableVersion,
|
|
115
|
-
isPackageDeprecated,
|
|
116
|
-
isPackageExist,
|
|
117
|
-
semverDecrease
|
|
118
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|