@mindbase/node-tools 1.3.0 → 1.3.7
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 +1 -1
- package/src/publish/registry/adapters/npm.js +10 -12
- package/src/publish/ui.js +12 -0
package/package.json
CHANGED
|
@@ -12,14 +12,14 @@ class NpmAdapter extends BaseAdapter {
|
|
|
12
12
|
/**
|
|
13
13
|
* 发布包到 npm
|
|
14
14
|
*/
|
|
15
|
-
async publish(pkg, options) {
|
|
15
|
+
async publish (pkg, options) {
|
|
16
16
|
const { tag = 'latest', dryRun = false } = options;
|
|
17
17
|
|
|
18
18
|
// 创建临时 .npmrc,包含 token 认证
|
|
19
19
|
const npmrcPath = join(pkg.path, '.npmrc');
|
|
20
|
-
//
|
|
21
|
-
const
|
|
22
|
-
const authTokenLine =
|
|
20
|
+
// 提取 registry 主机名,不使用 origin(避免带协议)
|
|
21
|
+
const registryHost = new URL(this.registry).host;
|
|
22
|
+
const authTokenLine = `//${registryHost}/:_authToken=${this.token}\n`;
|
|
23
23
|
const npmrcContent = `registry=${this.registry}\n${authTokenLine}`;
|
|
24
24
|
writeFileSync(npmrcPath, npmrcContent, 'utf-8');
|
|
25
25
|
|
|
@@ -28,7 +28,7 @@ class NpmAdapter extends BaseAdapter {
|
|
|
28
28
|
if (tag) args.push('--tag', tag);
|
|
29
29
|
if (dryRun) args.push('--dry-run');
|
|
30
30
|
|
|
31
|
-
await execaCommand('npm
|
|
31
|
+
await execaCommand('npm ' + args.join(' '), {
|
|
32
32
|
cwd: pkg.path,
|
|
33
33
|
stdout: 'inherit',
|
|
34
34
|
stderr: 'inherit'
|
|
@@ -43,23 +43,21 @@ class NpmAdapter extends BaseAdapter {
|
|
|
43
43
|
} finally {
|
|
44
44
|
// 清理临时 .npmrc
|
|
45
45
|
if (existsSync(npmrcPath)) {
|
|
46
|
-
unlinkSync(npmrcPath);
|
|
46
|
+
// unlinkSync(npmrcPath);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
|
|
51
50
|
/**
|
|
52
51
|
* 验证 token 有效性
|
|
53
52
|
*/
|
|
54
|
-
async validateToken() {
|
|
53
|
+
async validateToken () {
|
|
55
54
|
const { tmpdir } = require('os');
|
|
56
55
|
const { join } = require('path');
|
|
57
|
-
const { writeFileSync, unlinkSync } = require('fs');
|
|
58
56
|
|
|
59
57
|
// 创建临时 .npmrc
|
|
60
58
|
const tmpNpmrcPath = join(tmpdir(), '.npmrc-' + Date.now());
|
|
61
|
-
const
|
|
62
|
-
const authTokenLine =
|
|
59
|
+
const registryHost = new URL(this.registry).host;
|
|
60
|
+
const authTokenLine = `//${registryHost}/:_authToken=${this.token}\n`;
|
|
63
61
|
const npmrcContent = `registry=${this.registry}\n${authTokenLine}`;
|
|
64
62
|
writeFileSync(tmpNpmrcPath, npmrcContent, 'utf-8');
|
|
65
63
|
|
|
@@ -95,7 +93,7 @@ class NpmAdapter extends BaseAdapter {
|
|
|
95
93
|
/**
|
|
96
94
|
* 检查包是否存在
|
|
97
95
|
*/
|
|
98
|
-
async checkPackage(name, version) {
|
|
96
|
+
async checkPackage (name, version) {
|
|
99
97
|
try {
|
|
100
98
|
const args = ['view', `${name}@${version}`];
|
|
101
99
|
if (this.registry && this.registry !== 'https://registry.npmjs.org') {
|
package/src/publish/ui.js
CHANGED
|
@@ -139,6 +139,18 @@ async function showRegistrySelection(renderer, projectPath) {
|
|
|
139
139
|
|
|
140
140
|
const selected = await selectRegistriesInteractive(allRegistries, registryManager);
|
|
141
141
|
registries = selected;
|
|
142
|
+
|
|
143
|
+
// 更新项目默认配置
|
|
144
|
+
if (selected.length > 0) {
|
|
145
|
+
const projectConfig = registryManager.projectConfig;
|
|
146
|
+
const registryIds = selected.map(r => r.registry.id);
|
|
147
|
+
projectConfig.setDefaultRegistries(registryIds);
|
|
148
|
+
|
|
149
|
+
// 设置每个源的默认 token
|
|
150
|
+
for (const { registry, tokenId } of selected) {
|
|
151
|
+
projectConfig.setDefaultToken(registry.id, tokenId);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
142
154
|
}
|
|
143
155
|
}
|
|
144
156
|
|