@steedos/service-package-registry 3.0.1 → 3.0.2-beta.11
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.
|
@@ -1,45 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
log: {
|
|
5
|
-
error: noop,
|
|
6
|
-
warn: noop,
|
|
7
|
-
info: noop,
|
|
8
|
-
verbose: noop,
|
|
9
|
-
silly: noop,
|
|
10
|
-
http: noop,
|
|
11
|
-
pause: noop,
|
|
12
|
-
resume: noop
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
var fs = require('fs');
|
|
17
|
-
var path = require('path');
|
|
18
|
-
|
|
19
|
-
// jshint freeze:false
|
|
20
|
-
if (!Array.prototype.findIndex) {
|
|
21
|
-
Array.prototype.findIndex = function (predicate) {
|
|
22
|
-
if (this === null) {
|
|
23
|
-
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
|
24
|
-
}
|
|
25
|
-
if (typeof predicate !== 'function') {
|
|
26
|
-
throw new TypeError('predicate must be a function');
|
|
27
|
-
}
|
|
28
|
-
var list = Object(this);
|
|
29
|
-
var length = list.length >>> 0;
|
|
30
|
-
var thisArg = arguments[1];
|
|
31
|
-
var value;
|
|
32
|
-
|
|
33
|
-
for (var i = 0; i < length; i++) {
|
|
34
|
-
value = list[i];
|
|
35
|
-
if (predicate.call(thisArg, value, i, list)) {
|
|
36
|
-
return i;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return -1;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// jshint freeze:true
|
|
1
|
+
const fetch = require('npm-registry-fetch');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
43
4
|
|
|
44
5
|
function removeSuffix(pattern, suffix) {
|
|
45
6
|
if (pattern.endsWith(suffix)) {
|
|
@@ -68,75 +29,73 @@ module.exports = {
|
|
|
68
29
|
return args;
|
|
69
30
|
},
|
|
70
31
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
32
|
+
/**
|
|
33
|
+
* 使用 npm-registry-fetch 自行实现 adduser
|
|
34
|
+
*/
|
|
35
|
+
login: async function (args, callback) {
|
|
36
|
+
try {
|
|
37
|
+
const url = `${args.registry}/-/user/org.couchdb.user:${args.user}`;
|
|
38
|
+
const body = {
|
|
39
|
+
name: args.user,
|
|
75
40
|
password: args.pass,
|
|
76
41
|
email: args.email
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const res = await fetch(url, {
|
|
45
|
+
method: 'PUT',
|
|
46
|
+
body,
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
// 保证兼容私库需要 basic auth
|
|
49
|
+
auth: {
|
|
50
|
+
username: args.user,
|
|
51
|
+
password: args.pass
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const data = await res.json();
|
|
82
56
|
return callback(null, data);
|
|
83
|
-
})
|
|
57
|
+
} catch (err) {
|
|
58
|
+
return callback(err);
|
|
59
|
+
}
|
|
84
60
|
},
|
|
85
61
|
|
|
86
62
|
readFile: function (args, callback) {
|
|
87
63
|
fs.readFile(args.configPath, 'utf-8', function (err, contents) {
|
|
88
|
-
if (err)
|
|
89
|
-
contents = '';
|
|
90
|
-
}
|
|
64
|
+
if (err) contents = '';
|
|
91
65
|
return callback(null, contents);
|
|
92
66
|
});
|
|
93
67
|
},
|
|
94
68
|
|
|
95
69
|
generateFileContents: function (args, contents, response) {
|
|
96
|
-
// `contents` holds the initial content of the NPMRC file
|
|
97
|
-
// Convert the file contents into an array
|
|
98
70
|
var lines = contents ? contents.split('\n') : [];
|
|
99
|
-
|
|
71
|
+
|
|
100
72
|
const registryEndRegexPattern = /\:\//;
|
|
101
|
-
if (args.scope !== undefined) {
|
|
102
|
-
var scopeWrite = lines.findIndex(function (element) {
|
|
103
|
-
if (element.indexOf(args.scope + ':registry=' + args.registry) !== -1) {
|
|
104
|
-
// If an entry for the scope is found, replace it
|
|
105
|
-
element = args.scope + ':registry=' + args.registry;
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
73
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
74
|
+
if (args.scope !== undefined) {
|
|
75
|
+
const scopeLine = `${args.scope}:registry=${args.registry}`;
|
|
76
|
+
const index = lines.findIndex(l => l.startsWith(`${args.scope}:registry=`));
|
|
77
|
+
if (index === -1) {
|
|
78
|
+
lines.push(scopeLine);
|
|
79
|
+
} else {
|
|
80
|
+
lines[index] = scopeLine;
|
|
113
81
|
}
|
|
114
82
|
}
|
|
115
83
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
'/:_authToken=') !== -1) {
|
|
119
|
-
// If an entry for the auth token is found, replace it
|
|
120
|
-
array[index] = element.replace(/authToken\=.*/, 'authToken=' + (args.quotes ? '"' : '') +
|
|
121
|
-
response.token + (args.quotes ? '"' : ''));
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
84
|
+
const regPath = args.registry.slice(args.registry.search(registryEndRegexPattern, '') + 1);
|
|
85
|
+
const tokenLinePattern = `${regPath}/:_authToken=`;
|
|
125
86
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
lines.push(args.registry.slice(args.registry.search(registryEndRegexPattern, '') +
|
|
129
|
-
1) + '/:_authToken=' + (args.quotes ? '"' : '') + response.token + (args.quotes ? '"' : ''));
|
|
130
|
-
}
|
|
87
|
+
const tokenLine = tokenLinePattern + (args.quotes ? '"' : '') +
|
|
88
|
+
response.token + (args.quotes ? '"' : '');
|
|
131
89
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
90
|
+
const tokenIndex = lines.findIndex(l => l.includes(tokenLinePattern));
|
|
91
|
+
if (tokenIndex === -1) {
|
|
92
|
+
lines.push(tokenLine);
|
|
93
|
+
} else {
|
|
94
|
+
lines[tokenIndex] = tokenLine;
|
|
95
|
+
}
|
|
138
96
|
|
|
139
|
-
|
|
97
|
+
// 清理空行
|
|
98
|
+
return lines.filter(l => l.trim() !== '');
|
|
140
99
|
},
|
|
141
100
|
|
|
142
101
|
writeFile: function (args, lines, callback) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-package-registry",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2-beta.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "package.service.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
"author": "",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@steedos/auth": "3.0.
|
|
13
|
-
"@steedos/metadata-core": "3.0.
|
|
14
|
-
"@steedos/objectql": "3.0.
|
|
15
|
-
"@steedos/service-package-loader": "3.0.
|
|
12
|
+
"@steedos/auth": "3.0.2-beta.11",
|
|
13
|
+
"@steedos/metadata-core": "3.0.2-beta.11",
|
|
14
|
+
"@steedos/objectql": "3.0.2-beta.11",
|
|
15
|
+
"@steedos/service-package-loader": "3.0.2-beta.11",
|
|
16
16
|
"clone": "^2.1.2",
|
|
17
17
|
"fs-extra": "8.1.0",
|
|
18
18
|
"i18next": "20.3.2",
|
|
19
19
|
"json-stringify-safe": "5.0.1",
|
|
20
|
-
"jsonata": "1.8.
|
|
20
|
+
"jsonata": "1.8.7",
|
|
21
21
|
"lodash": "^4.17.21",
|
|
22
22
|
"lodash.clonedeep": "^4.5.0",
|
|
23
|
-
"moment-timezone": "0.5.
|
|
23
|
+
"moment-timezone": "0.5.35",
|
|
24
24
|
"npm-package-arg": "~9.1.0",
|
|
25
|
-
"npm-registry-
|
|
25
|
+
"npm-registry-fetch": "^19.1.1",
|
|
26
26
|
"package-json": "^7.0.0",
|
|
27
27
|
"radwag-mass": "~1.0.5",
|
|
28
28
|
"validator": "^13.5.2"
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "6355c86ba1122cc8e44065d74a010e3e2dfffc9f"
|
|
34
34
|
}
|