Skip to content

Commit 0ac5a32

Browse files
committed
feat: use latest&inner npminstall;default registry
1 parent 4347b59 commit 0ac5a32

File tree

6 files changed

+29
-13
lines changed

6 files changed

+29
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ English | [简体中文](README.zh-CN.md)
1212
Open git bash, zsh, and other command-line tools, type the following command, and press Enter:
1313

1414
```bash
15-
npm i @opentiny/cli npminstall@3 -g
15+
$ npm i @opentiny/cli -g
1616
```
1717

1818
Wait for a while. After the installation is complete, run `$tiny -v` on the terminal. If the version information is displayed, the installation is successful.

README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
打开git bash、zsh等命令行工具,输入如下命令后回车:
1313

1414
```bash
15-
npm i @opentiny/cli npminstall@3 -g
15+
$ npm i @opentiny/cli -g
1616
```
1717

1818
等待片刻,待安装完成之后在终端执行 `$ tiny -v`,正常返回版本信息,表示安装成功。

docs/use-install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $ npm -v
2222

2323

2424
```bash
25-
$ npm install @opentiny/cli npminstall -g
25+
$ npm install @opentiny/cli -g
2626
```
2727

2828

packages/cli/devkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"mem-fs-editor": "^6.0.0",
3232
"node-emoji": "^1.10.0",
3333
"npm-run": "^5.0.1",
34+
"npminstall": "^7.9.0",
3435
"npmlog": "^4.1.2",
3536
"os": "^0.1.1",
3637
"os-locale": "^4.0.0",

packages/cli/devkit/src/npm/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ const log = logs('core-npm');
2424
// TIMEOUT 超时时间
2525
const TIMEOUT = 5000;
2626

27+
// 未配置cnpmrc时默认使用淘宝镜像源
2728
const defaultRegistries = {
28-
registry: 'https://registry.npmjs.org/',
29-
'@opentiny:registry': 'https://registry.npmjs.org'
29+
registry: 'https://registry.npmmirror.com/',
30+
'@opentiny:registry': 'https://registry.npmmirror.com/'
3031
};
3132

3233
/**
@@ -149,6 +150,20 @@ export function setCnpmrc(config: any) {
149150
fs.writeFileSync(userConfig, data.join(os.EOL));
150151
}
151152

153+
/**
154+
* 获取安装器
155+
*/
156+
export function getInstaller() {
157+
return require.resolve('npminstall/bin/install.js')
158+
}
159+
160+
/**
161+
* 获取卸载器
162+
*/
163+
export function getUnInstaller() {
164+
return require.resolve('npminstall/bin/uninstall.js')
165+
}
166+
152167
/**
153168
* 安装 npm 包
154169
* @param pkg {string|array} 需要安装的包或包列表, 需要带版本号直接在包名后面 @ 版本号即可
@@ -158,23 +173,23 @@ export function setCnpmrc(config: any) {
158173
* @param options
159174
*/
160175
export async function install(pkg: string | string[], options?: NpmOption) {
161-
const installer = 'npminstall';
176+
const installer = getInstaller();
162177
await runInstall(installer, pkg, options);
163178
}
164179

165180
/**
166181
* 移除npm包
167182
*/
168183
export async function unInstall(pkg: string | string[], options?: NpmOption) {
169-
const installer = 'npmuninstall ';
184+
const installer = getUnInstaller();
170185
await runInstall(installer, pkg, options);
171186
}
172187

173188
/**
174189
* 安装package.json 中的依赖
175190
*/
176191
export async function installDependencies(options?: NpmOption) {
177-
const installer = 'npminstall';
192+
const installer = getInstaller();
178193
await runInstall(installer, [], options);
179194
}
180195

packages/cli/devkit/src/upgrade/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,30 @@ async function updateTip(data: any): Promise<boolean> {
7777
log.warn(
7878
intl.get('updatingCommand', {
7979
icon: emoji.get('point_right'),
80-
command: chalk.bgRed.bold(` ${installer} i ${data.name} npminstall -g `)
80+
command: chalk.bgRed.bold(` ${installer} i ${data.name} -g `)
8181
})
8282
);
8383
} else {
8484
log.warn(
8585
intl.get('updateCommand', {
8686
icon: emoji.get('point_right'),
87-
command: chalk.bgRed.bold(` ${installer} i ${data.name} npminstall -g`)
87+
command: chalk.bgRed.bold(` ${installer} i ${data.name} -g`)
8888
})
8989
);
9090
}
9191

9292
// linux & mac 下才提示
9393
if (process!.platform.indexOf('win') !== 0) {
94-
log.warn(`${intl.get('ifUpdateError')} ${chalk.red.bold(`sudo ${installer} install -g ${data.name} npminstall`)}`);
94+
log.warn(`${intl.get('ifUpdateError')} ${chalk.red.bold(`sudo ${installer} install -g ${data.name}`)}`);
9595
}
9696
log.warn(
9797
`******************************${emoji.get('point_up_2')} ${emoji.get('point_up_2')} ******************************`
9898
);
9999
console.log('\n');
100100

101101
if (needFocusUpdate) {
102-
// 执行 npm install -g @opentiny/cli 和 npminstall 更新本地系统
103-
const depen = [`${data.name}`, 'npminstall'];
102+
// 执行 npm install -g @opentiny/cli 更新本地版本
103+
const depen = [`${data.name}`];
104104
await npm.install(depen, {
105105
// global安装
106106
g: true

0 commit comments

Comments
 (0)