@modern-js/upgrade-generator 3.7.1-alpha.0 → 3.7.2
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/package.json +12 -11
- package/src/index.ts +0 -208
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "3.7.
|
|
18
|
+
"version": "3.7.2",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"main": "./dist/index.js",
|
|
21
21
|
"files": [
|
|
@@ -23,24 +23,25 @@
|
|
|
23
23
|
"/dist/index.js"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@modern-js/codesmith": "2.6.
|
|
27
|
-
"@modern-js/codesmith-utils": "2.6.
|
|
28
|
-
"@modern-js/codesmith-api-app": "2.6.
|
|
29
|
-
"@modern-js/codesmith-api-json": "2.6.
|
|
26
|
+
"@modern-js/codesmith": "2.6.5",
|
|
27
|
+
"@modern-js/codesmith-utils": "2.6.5",
|
|
28
|
+
"@modern-js/codesmith-api-app": "2.6.5",
|
|
29
|
+
"@modern-js/codesmith-api-json": "2.6.5",
|
|
30
30
|
"@types/jest": "^29",
|
|
31
31
|
"@types/node": "^14",
|
|
32
32
|
"jest": "^29",
|
|
33
33
|
"typescript": "^5",
|
|
34
|
-
"@modern-js/generator-common": "3.7.
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@modern-js/
|
|
38
|
-
"@scripts/
|
|
34
|
+
"@modern-js/generator-common": "3.7.2",
|
|
35
|
+
"@modern-js/generator-utils": "3.7.2",
|
|
36
|
+
"@scripts/jest-config": "2.60.6",
|
|
37
|
+
"@modern-js/plugin-i18n": "2.60.6",
|
|
38
|
+
"@scripts/build": "2.60.6"
|
|
39
39
|
},
|
|
40
40
|
"sideEffects": false,
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"registry": "https://registry.npmjs.org/",
|
|
43
|
-
"access": "public"
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
44
45
|
},
|
|
45
46
|
"types": "./src/index.ts",
|
|
46
47
|
"scripts": {
|
package/src/index.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import type { GeneratorContext, GeneratorCore } from '@modern-js/codesmith';
|
|
3
|
-
import { AppAPI } from '@modern-js/codesmith-api-app';
|
|
4
|
-
import { JsonAPI } from '@modern-js/codesmith-api-json';
|
|
5
|
-
import {
|
|
6
|
-
PackageManager,
|
|
7
|
-
type Solution,
|
|
8
|
-
SolutionText,
|
|
9
|
-
SolutionToolsMap,
|
|
10
|
-
} from '@modern-js/generator-common';
|
|
11
|
-
import {
|
|
12
|
-
fs,
|
|
13
|
-
getAvailableVersion,
|
|
14
|
-
getModernVersion,
|
|
15
|
-
getPackageManager,
|
|
16
|
-
getPackageObj,
|
|
17
|
-
getPackageVersion,
|
|
18
|
-
isPackageExist,
|
|
19
|
-
ora,
|
|
20
|
-
semver,
|
|
21
|
-
} from '@modern-js/generator-utils';
|
|
22
|
-
import { i18n, localeKeys } from './locale';
|
|
23
|
-
|
|
24
|
-
// Special modern.js dependencies, the plugin version maybe not same with other modern.js plugin
|
|
25
|
-
const SpecialModernDeps = [
|
|
26
|
-
'@modern-js/plugin-storybook',
|
|
27
|
-
'@modern-js/builder-rspack-provider', // need be removed after 2.46.1
|
|
28
|
-
'@modern-js/eslint-config',
|
|
29
|
-
'@modern-js-app/eslint-config',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const DeprecatedModernBuilderDeps = [
|
|
33
|
-
'@modern-js/builder-plugin-image-compress',
|
|
34
|
-
'@modern-js/builder-plugin-swc',
|
|
35
|
-
'@modern-js/builder-plugin-esbuild',
|
|
36
|
-
'@modern-js/builder-plugin-node-polyfill',
|
|
37
|
-
'@modern-js/builder-plugin-stylus',
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
const handleSpecialModernDeps = async (dep: string, modernVersion: string) => {
|
|
41
|
-
const version = await getAvailableVersion(dep, modernVersion);
|
|
42
|
-
if (!(await isPackageExist(`${dep}@${version}`))) {
|
|
43
|
-
return getPackageVersion(dep);
|
|
44
|
-
}
|
|
45
|
-
return version;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const handleTemplateFile = async (
|
|
49
|
-
context: GeneratorContext,
|
|
50
|
-
generator: GeneratorCore,
|
|
51
|
-
appApi: AppAPI,
|
|
52
|
-
) => {
|
|
53
|
-
const jsonAPI = new JsonAPI(generator);
|
|
54
|
-
// get project solution type
|
|
55
|
-
const pkgInfo = await getPackageObj(context);
|
|
56
|
-
const deps = {
|
|
57
|
-
...pkgInfo.devDependencies,
|
|
58
|
-
...pkgInfo.dependencies,
|
|
59
|
-
};
|
|
60
|
-
const solutions = Object.keys(SolutionToolsMap).filter(
|
|
61
|
-
solution => deps[SolutionToolsMap[solution as Solution]],
|
|
62
|
-
);
|
|
63
|
-
if (solutions.length === 0) {
|
|
64
|
-
throw Error(i18n.t(localeKeys.tooltip.no_solution));
|
|
65
|
-
}
|
|
66
|
-
if (solutions.length >= 2) {
|
|
67
|
-
throw Error(i18n.t(localeKeys.tooltip.more_solution));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
generator.logger.info(
|
|
71
|
-
`[${i18n.t(localeKeys.projectType)}]: ${SolutionText[
|
|
72
|
-
solutions[0] as Solution
|
|
73
|
-
]()}`,
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
// get modern latest version
|
|
77
|
-
const modernVersion = await getModernVersion(
|
|
78
|
-
solutions[0] as Solution,
|
|
79
|
-
context.config.registry,
|
|
80
|
-
context.config.distTag || 'latest',
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
generator.logger.info(
|
|
84
|
-
`[${i18n.t(localeKeys.modernVersion)}]: ${modernVersion}`,
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
// adjust Modern.js packages' version is latest?
|
|
88
|
-
if (
|
|
89
|
-
Object.keys(deps)
|
|
90
|
-
.filter(
|
|
91
|
-
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
92
|
-
)
|
|
93
|
-
.filter(dep => !dep.includes('electron'))
|
|
94
|
-
.filter(dep => !dep.includes('codesmith') && !dep.includes('easy-form'))
|
|
95
|
-
.filter(dep => !dep.startsWith('@modern-js-reduck'))
|
|
96
|
-
.filter(dep => !dep.includes('eslint-config'))
|
|
97
|
-
.every(dep => deps[dep] === modernVersion)
|
|
98
|
-
) {
|
|
99
|
-
generator.logger.info(
|
|
100
|
-
`[${i18n.t(localeKeys.alreadyLatest)}]: ${modernVersion}`,
|
|
101
|
-
);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
const appDir = context.materials.default.basePath;
|
|
106
|
-
|
|
107
|
-
const packageManager = await getPackageManager(appDir);
|
|
108
|
-
context.config.packageManager = packageManager;
|
|
109
|
-
|
|
110
|
-
if (packageManager === PackageManager.Pnpm) {
|
|
111
|
-
const npmrcPath = path.join(generator.outputPath, '.npmrc');
|
|
112
|
-
if (fs.existsSync(npmrcPath)) {
|
|
113
|
-
const content = fs.readFileSync(npmrcPath, 'utf-8');
|
|
114
|
-
if (!content.includes('strict-peer-dependencies=false')) {
|
|
115
|
-
fs.appendFileSync(npmrcPath, '\nstrict-peer-dependencies=false\n');
|
|
116
|
-
}
|
|
117
|
-
} else {
|
|
118
|
-
fs.ensureFileSync(npmrcPath);
|
|
119
|
-
fs.writeFileSync(npmrcPath, 'strict-peer-dependencies=false');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const modernDeps = Object.keys(pkgInfo.dependencies || {}).filter(
|
|
124
|
-
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
125
|
-
);
|
|
126
|
-
const modernDevDeps = Object.keys(pkgInfo.devDependencies || {}).filter(
|
|
127
|
-
dep => dep.startsWith('@modern-js') || dep.startsWith('@modern-js-app'),
|
|
128
|
-
);
|
|
129
|
-
const updateInfo: Record<string, string> = {};
|
|
130
|
-
|
|
131
|
-
const spinner = ora({
|
|
132
|
-
text: 'Load Generator...',
|
|
133
|
-
spinner: 'runner',
|
|
134
|
-
}).start();
|
|
135
|
-
|
|
136
|
-
await Promise.all(
|
|
137
|
-
modernDeps.map(async dep => {
|
|
138
|
-
if (SpecialModernDeps.includes(dep)) {
|
|
139
|
-
updateInfo[`dependencies.${dep}`] = await handleSpecialModernDeps(
|
|
140
|
-
dep,
|
|
141
|
-
modernVersion,
|
|
142
|
-
);
|
|
143
|
-
} else if (DeprecatedModernBuilderDeps.includes(dep)) {
|
|
144
|
-
generator.logger.warn(
|
|
145
|
-
`🟡 [Deprecated] ${dep} is no longer maintained, please use Rsbuild plugin instead`,
|
|
146
|
-
);
|
|
147
|
-
} else {
|
|
148
|
-
updateInfo[`dependencies.${dep}`] = await getAvailableVersion(
|
|
149
|
-
dep,
|
|
150
|
-
modernVersion,
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
await Promise.all(
|
|
157
|
-
modernDevDeps.map(async dep => {
|
|
158
|
-
if (SpecialModernDeps.includes(dep)) {
|
|
159
|
-
updateInfo[`devDependencies.${dep}`] = await handleSpecialModernDeps(
|
|
160
|
-
dep,
|
|
161
|
-
modernVersion,
|
|
162
|
-
);
|
|
163
|
-
} else if (DeprecatedModernBuilderDeps.includes(dep)) {
|
|
164
|
-
generator.logger.warn(
|
|
165
|
-
`🟡 [Deprecated] ${dep} is no longer maintained, please use Rsbuild plugin instead`,
|
|
166
|
-
);
|
|
167
|
-
} else {
|
|
168
|
-
updateInfo[`devDependencies.${dep}`] = await getAvailableVersion(
|
|
169
|
-
dep,
|
|
170
|
-
modernVersion,
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
}),
|
|
174
|
-
);
|
|
175
|
-
await jsonAPI.update(
|
|
176
|
-
context.materials.default.get(path.join(appDir, 'package.json')),
|
|
177
|
-
{
|
|
178
|
-
query: {},
|
|
179
|
-
update: {
|
|
180
|
-
$set: updateInfo,
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
true,
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
spinner.stop();
|
|
187
|
-
|
|
188
|
-
await appApi.runInstall();
|
|
189
|
-
|
|
190
|
-
appApi.showSuccessInfo(i18n.t(localeKeys.success));
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export default async (context: GeneratorContext, generator: GeneratorCore) => {
|
|
194
|
-
const appApi = new AppAPI(context, generator);
|
|
195
|
-
|
|
196
|
-
const { locale } = context.config;
|
|
197
|
-
appApi.i18n.changeLanguage({ locale });
|
|
198
|
-
|
|
199
|
-
generator.logger.debug(`🚀 [Start Run Upgrade Generator]`);
|
|
200
|
-
generator.logger.debug(
|
|
201
|
-
'💡 [Current Config]:',
|
|
202
|
-
JSON.stringify(context.config),
|
|
203
|
-
);
|
|
204
|
-
|
|
205
|
-
await handleTemplateFile(context, generator, appApi);
|
|
206
|
-
|
|
207
|
-
generator.logger.debug(`🌟 [End Run Upgrade Generator]`);
|
|
208
|
-
};
|