@modern-js/generator-utils 3.0.0-beta.3 → 3.0.0-beta.5
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 +65 -0
- package/dist/js/modern/index.js +180 -108
- package/dist/js/modern/locale/en.js +7 -8
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +7 -8
- package/dist/js/modern/utils/fs-exist.js +37 -0
- package/dist/js/modern/utils/index.js +1 -1
- package/dist/js/modern/utils/package.js +73 -55
- package/dist/js/modern/utils/strip-ansi.js +13 -9
- package/dist/js/node/index.js +208 -219
- package/dist/js/node/locale/en.js +27 -12
- package/dist/js/node/locale/index.js +31 -14
- package/dist/js/node/locale/zh.js +27 -12
- package/dist/js/node/utils/fs-exist.js +60 -0
- package/dist/js/node/utils/index.js +18 -27
- package/dist/js/node/utils/package.js +99 -63
- package/dist/js/node/utils/strip-ansi.js +34 -13
- package/dist/types/index.d.ts +2 -1
- package/dist/types/utils/fs-exist.d.ts +1 -0
- package/dist/types/utils/package.d.ts +1 -0
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# @modern-js/generator-utils
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [7879e8f711]
|
|
12
|
+
- Updated dependencies [6aca875011]
|
|
13
|
+
- Updated dependencies [2e6031955e]
|
|
14
|
+
- Updated dependencies [7b7d12cf8f]
|
|
15
|
+
- Updated dependencies [7efeed4]
|
|
16
|
+
- Updated dependencies [92f0eade39]
|
|
17
|
+
- Updated dependencies [edd1cfb1af]
|
|
18
|
+
- Updated dependencies [cc971eabfc]
|
|
19
|
+
- Updated dependencies [5b9049f2e9]
|
|
20
|
+
- Updated dependencies [92004d1906]
|
|
21
|
+
- Updated dependencies [b8bbe036c7]
|
|
22
|
+
- Updated dependencies [d5a31df781]
|
|
23
|
+
- Updated dependencies [dda38c9c3e]
|
|
24
|
+
- Updated dependencies [3bbea92b2a]
|
|
25
|
+
- Updated dependencies [b710adb843]
|
|
26
|
+
- Updated dependencies [ea7cf06257]
|
|
27
|
+
- Updated dependencies [bbe4c4ab64]
|
|
28
|
+
- Updated dependencies [e4558a0bc4]
|
|
29
|
+
- Updated dependencies [abf3421a75]
|
|
30
|
+
- Updated dependencies [543be9558e]
|
|
31
|
+
- Updated dependencies [14b712da84]
|
|
32
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
33
|
+
- @modern-js/plugin-i18n@2.0.0-beta.6
|
|
34
|
+
- @modern-js/generator-common@3.0.0-beta.5
|
|
35
|
+
|
|
36
|
+
## 3.0.0-beta.4
|
|
37
|
+
|
|
38
|
+
### Major Changes
|
|
39
|
+
|
|
40
|
+
- dda38c9c3e: chore: v2
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [7879e8f]
|
|
45
|
+
- Updated dependencies [6aca875]
|
|
46
|
+
- Updated dependencies [2e6031955e]
|
|
47
|
+
- Updated dependencies [7b7d12c]
|
|
48
|
+
- Updated dependencies [92f0eade39]
|
|
49
|
+
- Updated dependencies [edd1cfb1af]
|
|
50
|
+
- Updated dependencies [cc971eabfc]
|
|
51
|
+
- Updated dependencies [5b9049f2e9]
|
|
52
|
+
- Updated dependencies [92004d1906]
|
|
53
|
+
- Updated dependencies [b8bbe036c7]
|
|
54
|
+
- Updated dependencies [d5a31df781]
|
|
55
|
+
- Updated dependencies [dda38c9c3e]
|
|
56
|
+
- Updated dependencies [3bbea92b2a]
|
|
57
|
+
- Updated dependencies [b710adb843]
|
|
58
|
+
- Updated dependencies [ea7cf06]
|
|
59
|
+
- Updated dependencies [bbe4c4a]
|
|
60
|
+
- Updated dependencies [e4558a0]
|
|
61
|
+
- Updated dependencies [abf3421a75]
|
|
62
|
+
- Updated dependencies [543be9558e]
|
|
63
|
+
- Updated dependencies [14b712da84]
|
|
64
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
65
|
+
- @modern-js/plugin-i18n@2.0.0-beta.4
|
|
66
|
+
- @modern-js/generator-common@3.0.0-beta.4
|
|
67
|
+
|
|
3
68
|
## 3.0.0-beta.3
|
|
4
69
|
|
|
5
70
|
### Major Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,148 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
canUseYarn
|
|
30
|
+
} from "@modern-js/utils";
|
|
31
|
+
import { SolutionToolsMap } from "@modern-js/generator-common";
|
|
4
32
|
import { stripAnsi } from "./utils/strip-ansi";
|
|
5
33
|
import { i18n, localeKeys } from "./locale";
|
|
6
34
|
import { getAvailableVersion } from "./utils/package";
|
|
35
|
+
import { fileExist } from "./utils/fs-exist";
|
|
7
36
|
export * from "./utils";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
37
|
+
import {
|
|
38
|
+
ora as ora2,
|
|
39
|
+
fs as fs2,
|
|
40
|
+
semver,
|
|
41
|
+
execa as execa2,
|
|
42
|
+
readTsConfigByFile,
|
|
43
|
+
getPackageManager,
|
|
44
|
+
canUseNpm as canUseNpm2,
|
|
45
|
+
canUsePnpm as canUsePnpm2,
|
|
46
|
+
canUseYarn as canUseYarn2,
|
|
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);
|
|
19
64
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
65
|
+
if (yield canUseYarn()) {
|
|
66
|
+
const args = ["info", packageName, "version", "--silent"];
|
|
67
|
+
if (registry) {
|
|
68
|
+
args.push(`--registry=${registry}`);
|
|
69
|
+
}
|
|
70
|
+
const result = yield execa("yarn", args);
|
|
71
|
+
spinner.stop();
|
|
72
|
+
return stripAnsi(result.stdout);
|
|
28
73
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
74
|
+
if (yield canUseNpm()) {
|
|
75
|
+
const args = ["view", packageName, "version"];
|
|
76
|
+
if (registry) {
|
|
77
|
+
args.push(`--registry=${registry}`);
|
|
78
|
+
}
|
|
79
|
+
const result = yield execa("npm", args);
|
|
80
|
+
spinner.stop();
|
|
81
|
+
return stripAnsi(result.stdout);
|
|
37
82
|
}
|
|
38
|
-
const result = await execa('npm', args);
|
|
39
83
|
spinner.stop();
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
spinner.stop();
|
|
43
|
-
throw new Error('not found npm, please install npm before');
|
|
84
|
+
throw new Error("not found npm, please install npm before");
|
|
85
|
+
});
|
|
44
86
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
87
|
+
function getModernVersion(solution, registry, distTag = "latest") {
|
|
88
|
+
return __async(this, null, function* () {
|
|
89
|
+
const dep = SolutionToolsMap[solution];
|
|
90
|
+
const modernVersion = yield getPackageVersion(`${dep}@${distTag}`, registry);
|
|
91
|
+
return modernVersion;
|
|
92
|
+
});
|
|
49
93
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
cwd = process.cwd(),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
// get project solution version
|
|
66
|
-
const pkgPath = path.join(require.resolve(SolutionToolsMap[solution], {
|
|
67
|
-
paths: [cwd]
|
|
68
|
-
}), '../../../../', 'package.json');
|
|
69
|
-
if (fs.existsSync(pkgPath)) {
|
|
70
|
-
const pkgInfo = fs.readJSONSync(pkgPath);
|
|
71
|
-
const modernVersion = pkgInfo.version;
|
|
72
|
-
if (typeof modernVersion !== 'string') {
|
|
73
|
-
return getLatetPluginVersion();
|
|
94
|
+
function getModernPluginVersion(_0, _1) {
|
|
95
|
+
return __async(this, arguments, function* (solution, packageName, options = {
|
|
96
|
+
distTag: "latest"
|
|
97
|
+
}) {
|
|
98
|
+
const { cwd = process.cwd(), registry, distTag } = options;
|
|
99
|
+
const getLatetPluginVersion = (tag) => __async(this, null, function* () {
|
|
100
|
+
const version = yield getPackageVersion(
|
|
101
|
+
`${packageName}@${tag || distTag || "latest"}`,
|
|
102
|
+
registry
|
|
103
|
+
);
|
|
104
|
+
return version;
|
|
105
|
+
});
|
|
106
|
+
if (!packageName.startsWith("@modern-js") || packageName.includes("electron") || packageName.includes("codesmith") || packageName.includes("easy-form") || packageName.startsWith("@modern-js-reduck")) {
|
|
107
|
+
return getLatetPluginVersion("latest");
|
|
74
108
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
109
|
+
const pkgPath = path.join(
|
|
110
|
+
require.resolve(SolutionToolsMap[solution], { paths: [cwd] }),
|
|
111
|
+
"../../../../",
|
|
112
|
+
"package.json"
|
|
113
|
+
);
|
|
114
|
+
if (fs.existsSync(pkgPath)) {
|
|
115
|
+
const pkgInfo = fs.readJSONSync(pkgPath);
|
|
116
|
+
const modernVersion = pkgInfo.version;
|
|
117
|
+
if (typeof modernVersion !== "string") {
|
|
118
|
+
return getLatetPluginVersion();
|
|
119
|
+
}
|
|
120
|
+
return getAvailableVersion(packageName, modernVersion, registry);
|
|
121
|
+
}
|
|
122
|
+
return getLatetPluginVersion();
|
|
123
|
+
});
|
|
78
124
|
}
|
|
79
|
-
|
|
80
|
-
return packageManager ===
|
|
125
|
+
function getPackageManagerText(packageManager) {
|
|
126
|
+
return packageManager === "yarn" ? "yarn" : `${packageManager} run`;
|
|
81
127
|
}
|
|
82
|
-
|
|
83
|
-
return fs.existsSync(path.join(appDir,
|
|
128
|
+
function isTsProject(appDir) {
|
|
129
|
+
return fs.existsSync(path.join(appDir, "tsconfig.json"));
|
|
84
130
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
131
|
+
function getPackageObj(context) {
|
|
132
|
+
return __async(this, null, function* () {
|
|
133
|
+
const pkgStr = (yield context.materials.default.get(`package.json`).value()).content;
|
|
134
|
+
return JSON.parse(pkgStr);
|
|
135
|
+
});
|
|
88
136
|
}
|
|
89
|
-
|
|
137
|
+
function getAllPackages(appDir) {
|
|
90
138
|
const packages = getMonorepoPackages(appDir);
|
|
91
|
-
return packages.map(pkg => pkg.name);
|
|
139
|
+
return packages.map((pkg) => pkg.name);
|
|
92
140
|
}
|
|
93
|
-
|
|
94
|
-
const {
|
|
95
|
-
isMonorepoSubProject
|
|
96
|
-
} = options;
|
|
141
|
+
function validatePackageName(value, packages, options) {
|
|
142
|
+
const { isMonorepoSubProject } = options;
|
|
97
143
|
if (isMonorepoSubProject && packages.includes(value)) {
|
|
98
144
|
return {
|
|
99
145
|
success: false,
|
|
100
|
-
error: i18n.t(localeKeys.packageName.exit, {
|
|
101
|
-
value
|
|
102
|
-
})
|
|
146
|
+
error: i18n.t(localeKeys.packageName.exit, { value })
|
|
103
147
|
};
|
|
104
148
|
}
|
|
105
|
-
return {
|
|
106
|
-
success: true
|
|
107
|
-
};
|
|
149
|
+
return { success: true };
|
|
108
150
|
}
|
|
109
|
-
|
|
110
|
-
const {
|
|
111
|
-
|
|
112
|
-
isPublic,
|
|
113
|
-
isTest
|
|
114
|
-
} = options || {};
|
|
115
|
-
let dir = 'apps';
|
|
151
|
+
function validatePackagePath(value, projectDir, options) {
|
|
152
|
+
const { isMwa, isPublic, isTest } = options || {};
|
|
153
|
+
let dir = "apps";
|
|
116
154
|
if (isMwa && isTest) {
|
|
117
|
-
dir =
|
|
155
|
+
dir = "examples";
|
|
118
156
|
} else {
|
|
119
|
-
dir = isPublic ?
|
|
157
|
+
dir = isPublic ? "packages" : "features";
|
|
120
158
|
}
|
|
121
|
-
const packageDir = path.resolve(projectDir ||
|
|
159
|
+
const packageDir = path.resolve(projectDir || "", dir, value);
|
|
122
160
|
if (fs.existsSync(packageDir)) {
|
|
123
161
|
return {
|
|
124
162
|
success: false,
|
|
125
|
-
error: i18n.t(localeKeys.packagePath.exit, {
|
|
126
|
-
value
|
|
127
|
-
})
|
|
163
|
+
error: i18n.t(localeKeys.packagePath.exit, { value })
|
|
128
164
|
};
|
|
129
165
|
}
|
|
130
|
-
return {
|
|
131
|
-
success: true
|
|
132
|
-
};
|
|
166
|
+
return { success: true };
|
|
133
167
|
}
|
|
134
|
-
|
|
168
|
+
function getModuleProjectPath(packagePath, isMonorepoSubProject, isPublic, isLocalPackages) {
|
|
135
169
|
if (isLocalPackages && packagePath) {
|
|
136
170
|
return `${packagePath}/`;
|
|
137
171
|
}
|
|
138
172
|
if (isMonorepoSubProject && packagePath) {
|
|
139
|
-
return `${isPublic ?
|
|
173
|
+
return `${isPublic ? "packages" : "features"}/${packagePath}/`;
|
|
140
174
|
}
|
|
141
|
-
return
|
|
175
|
+
return "";
|
|
142
176
|
}
|
|
143
|
-
|
|
177
|
+
function getMWAProjectPath(packagePath, isMonorepoSubProject, isTest = false) {
|
|
144
178
|
if (isMonorepoSubProject && packagePath) {
|
|
145
|
-
return `${isTest ?
|
|
179
|
+
return `${isTest ? "examples" : "apps"}/${packagePath}/`;
|
|
146
180
|
}
|
|
147
|
-
return
|
|
148
|
-
}
|
|
181
|
+
return "";
|
|
182
|
+
}
|
|
183
|
+
function getModernConfigFile(appDir) {
|
|
184
|
+
return __async(this, null, function* () {
|
|
185
|
+
let exist = yield fileExist(path.join(appDir, "modern.config.ts"));
|
|
186
|
+
if (exist) {
|
|
187
|
+
return "modern.config.ts";
|
|
188
|
+
}
|
|
189
|
+
exist = yield fileExist(path.join(appDir, "modern.config.js"));
|
|
190
|
+
if (exist) {
|
|
191
|
+
return "modern.config.js";
|
|
192
|
+
}
|
|
193
|
+
return isTsProject(appDir) ? "modern.config.ts" : "modern.config.js";
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
export {
|
|
197
|
+
canUseNpm2 as canUseNpm,
|
|
198
|
+
canUsePnpm2 as canUsePnpm,
|
|
199
|
+
canUseYarn2 as canUseYarn,
|
|
200
|
+
execa2 as execa,
|
|
201
|
+
fs2 as fs,
|
|
202
|
+
getAllPackages,
|
|
203
|
+
getMWAProjectPath,
|
|
204
|
+
getModernConfigFile,
|
|
205
|
+
getModernPluginVersion,
|
|
206
|
+
getModernVersion,
|
|
207
|
+
getModuleProjectPath,
|
|
208
|
+
getPackageManager,
|
|
209
|
+
getPackageManagerText,
|
|
210
|
+
getPackageObj,
|
|
211
|
+
getPackageVersion,
|
|
212
|
+
i18n2 as i18n,
|
|
213
|
+
isReact18,
|
|
214
|
+
isTsProject,
|
|
215
|
+
ora2 as ora,
|
|
216
|
+
readTsConfigByFile,
|
|
217
|
+
semver,
|
|
218
|
+
validatePackageName,
|
|
219
|
+
validatePackagePath
|
|
220
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
packageName: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
1
|
+
const EN_LOCALE = {
|
|
2
|
+
packageName: { exit: "package name `{value}` is already exists" },
|
|
3
|
+
packagePath: { exit: "package path {value} is already exists" }
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
EN_LOCALE
|
|
7
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { I18n } from
|
|
1
|
+
import { I18n } from "@modern-js/plugin-i18n";
|
|
2
2
|
import { ZH_LOCALE } from "./zh";
|
|
3
3
|
import { EN_LOCALE } from "./en";
|
|
4
4
|
const i18n = new I18n();
|
|
5
|
-
const localeKeys = i18n.init(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const localeKeys = i18n.init("zh", { zh: ZH_LOCALE, en: EN_LOCALE });
|
|
6
|
+
export {
|
|
7
|
+
i18n,
|
|
8
|
+
localeKeys
|
|
9
|
+
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
packageName: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
1
|
+
const ZH_LOCALE = {
|
|
2
|
+
packageName: { exit: "项目名称 {value} 已存在" },
|
|
3
|
+
packagePath: { exit: "目录 {value} 已存在" }
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
ZH_LOCALE
|
|
7
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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,2 +1,2 @@
|
|
|
1
1
|
export * from "./strip-ansi";
|
|
2
|
-
export * from "./package";
|
|
2
|
+
export * from "./package";
|
|
@@ -1,36 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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);
|
|
9
31
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
throw new Error('not found npm, please install npm before');
|
|
32
|
+
throw new Error("not found npm, please install npm before");
|
|
33
|
+
});
|
|
14
34
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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);
|
|
22
44
|
}
|
|
23
|
-
|
|
24
|
-
return stripAnsi(result.stdout);
|
|
25
|
-
}
|
|
26
|
-
throw new Error('not found npm, please install npm before');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// 降低包小版本号
|
|
30
|
-
export function semverDecrease(version) {
|
|
31
|
-
const versionObj = semver.parse(version, {
|
|
32
|
-
loose: true
|
|
45
|
+
throw new Error("not found npm, please install npm before");
|
|
33
46
|
});
|
|
47
|
+
}
|
|
48
|
+
function semverDecrease(version) {
|
|
49
|
+
const versionObj = semver.parse(version, { loose: true });
|
|
34
50
|
if (!versionObj) {
|
|
35
51
|
throw new Error(`Version ${version} is not valid semver`);
|
|
36
52
|
}
|
|
@@ -44,31 +60,33 @@ export function semverDecrease(version) {
|
|
|
44
60
|
}
|
|
45
61
|
return result;
|
|
46
62
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
version = semver.inc(version, 'patch');
|
|
59
|
-
times--;
|
|
60
|
-
continue;
|
|
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;
|
|
61
74
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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;
|
|
70
83
|
}
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
84
|
+
return currentVersion;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
getAvailableVersion,
|
|
89
|
+
isPackageDeprecated,
|
|
90
|
+
isPackageExist,
|
|
91
|
+
semverDecrease
|
|
92
|
+
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
function ansiRegex({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function ansiRegex({ onlyFirst = false } = {}) {
|
|
2
|
+
const pattern = [
|
|
3
|
+
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
|
|
4
|
+
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"
|
|
5
|
+
].join("|");
|
|
6
|
+
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
-
if (typeof string !==
|
|
8
|
+
function stripAnsi(string) {
|
|
9
|
+
if (typeof string !== "string") {
|
|
9
10
|
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
10
11
|
}
|
|
11
|
-
return string.replace(ansiRegex(),
|
|
12
|
-
}
|
|
12
|
+
return string.replace(ansiRegex(), "");
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
stripAnsi
|
|
16
|
+
};
|