8000 options, bugfix: alias name package install error. · fibjs/fibjs@188b2a4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 188b2a4

Browse files
committed
options, bugfix: alias name package install error.
1 parent 1206531 commit 188b2a4

File tree

6 files changed

+578
-437
lines changed

6 files changed

+578
-437
lines changed

fibjs/scripts/internal/helpers/package.js

Lines changed: 106 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,61 +16,116 @@ exports.is_special_installname = function (pkg_name = '') {
1616
return false;
1717
}
1818

19-
const parse_pkg_installname = exports.parse_pkg_installname = function (input_uri = '', version = '') {
20-
/**
21-
* when providing version but not semantic version, consider it as special installation name
22-
*/
23-
if (version && exports.is_special_installname(version)) {
24-
input_uri = version
25-
}
26-
27-
const Is = {
28-
http: false,
29-
github: false,
30-
registry: false,
31-
file: false,
32-
}
33-
const uriObj = url.parse(input_uri)
34-
Is.http = uriObj.protocol === 'http:' || uriObj.protocol === 'https:'
35-
36-
const origin = !Is.http ? '' : `${uriObj.protocol}//${uriObj.host}`;
37-
38-
39-
let pkg_pattern = input_uri;
40-
if (Is.http) pkg_pattern = `${uriObj.pathname}${uriObj.hash}`;
41-
42-
pkg_pattern = helpers_string.ensure_unprefix(pkg_pattern);
43-
44-
let [scope_str, pkg] = (pkg_pattern || '').split('/')
45-
46-
if (!pkg) {
47-
pkg = scope_str
48-
scope_str = ''
19+
const GIT_PATTERN = /^([a-zA-Z0-9_.~-]+\/([a-zA-Z0-9_.~-]+)(\.git)?)(\#(.+))?$/
20+
const MODULE_NAME_PATTERN = /^[a-z][a-z0-9_.~-]*$/;
21+
22+
const parse_pkg_installname = exports.parse_pkg_installname = function (pkg_name, input_uri) {
23+
if (!input_uri || input_uri === '*')
24+
input_uri = pkg_name;
25+
26+
input_uri = input_uri.replace(/^npm:/, '');
27+
input_uri = input_uri.replace(/^https?:\/\/[^\/]+\//, '');
28+
29+
const registry_part = input_uri.split('@');
30+
if (registry_part.length == 2 && registry_part[0] !== '')
31+
return {
32+
type: 'registry',
33+
package_name: registry_part[0],
34+
registry_pkg_path: registry_part[0],
35+
registry_semver: registry_part[1],
36+
from_http: false,
37+
git_origin: '',
38+
git_basename: null,
39+
git_path: null,
40+
git_reference: null,
41+
}
42+
43+
if (registry_part.length == 2 && registry_part[0] === '')
44+
return {
45+
type: 'registry',
46+
package_name: input_uri,
47+
registry_pkg_path: input_uri,
48+
registry_semver: "*",
49+
from_http: false,
50+
git_origin: '',
51+
git_basename: null,
52+
git_path: null,
53+
git_reference: null,
54+
}
55+
56+
if (registry_part.length == 3) {
57+
if (registry_part[0] !== '')
58+
throw new Error(`[parse_pkg_installname] invalid input_uri: ${input_uri}`);
59+
60+
const pkg_name = '@' + registry_part[1];
61+
return {
62+
type: 'registry',
63+
package_name: pkg_name,
64+
registry_pkg_path: pkg_name,
65+
registry_semver: registry_part[2],
66+
from_http: false,
67+
git_origin: '',
68+
git_basename: null,
69+
git_path: null,
70+
git_reference: null,
71+
}
4972
}
5073

51-
Is.github = scope_str && /[a-zA-Z]/.test(scope_str[0])
52-
Is.registry = !scope_str || scope_str[0] === '@'
53-
54-
let github_org_str = ''
55-
if (Is.github) github_org_str = scope_str
56-
57-
const [name1, registry_semver = null] = (pkg || '').split('@')
58-
59-
const [name0, git_reference = null] = (name1 || '').split('#')
60-
61-
const installation_name = Is.github ? null : (scope_str ? `${scope_str}/${name0}` : name0)
74+
if (registry_part.length > 1)
75+
throw new Error(`[parse_pkg_installname] invalid input_uri: ${input_uri}`);
76+
77+
const git_part = input_uri.match(GIT_PATTERN);
78+
if (git_part)
79+
return {
80+
type: 'git',
81+
package_name: null,
82+
registry_pkg_path: null,
83+
registry_semver: null,
84+
from_http: false,
85+
git_origin: helpers_string.ensure_suffx(CST.DEFAULT_GIT_ORIGIN),
86+
git_basename: git_part[2],
87+
git_path: git_part[1],
88+
git_reference: git_part[5] || 'master',
89+
}
90+
91+
const git_part1 = pkg_name.match(GIT_PATTERN);
92+
if (git_part1)
93+
return {
94+
type: 'git',
95+
package_name: null,
96+
registry_pkg_path: null,
97+
registry_semver: null,
98+
from_http: false,
99+
git_origin: helpers_string.ensure_suffx(CST.DEFAULT_GIT_ORIGIN),
100+
git_basename: git_part1[2],
101+
git_path: git_part1[1],
102+
git_reference: input_uri || git_part1[5] || 'master',
103+
}
104+
105+
if (MODULE_NAME_PATTERN.test(input_uri))
106+
return {
107+
type: 'registry',
108+
package_name: input_uri,
109+
registry_pkg_path: input_uri,
110+
registry_semver: "*",
111+
from_http: false,
112+
git_origin: '',
113+
git_basename: null,
114+
git_path: null,
115+
git_reference: null,
116+
};
62117

63118
return {
64-
type: Is.github ? 'git' : 'registry',
65-
package_name: installation_name,
66-
registry_pkg_path: !Is.registry ? null : installation_name,
67-
registry_semver: registry_semver,
68-
from_http: Is.http,
69-
git_origin: Is.github ? (null || helpers_string.ensure_suffx(CST.DEFAULT_GIT_ORIGIN)) : origin,
70-
git_basename: !Is.github ? null : name0,
71-
git_path: !Is.github ? null : `${github_org_str}/${name0}`,
72-
git_reference: !Is.github ? null : (git_reference || 'master'),
73-
}
119+
type: 'registry',
120+
package_name: pkg_name,
121+
registry_pkg_path: pkg_name,
122+
registry_semver: input_uri,
123+
from_http: false,
124+
git_origin: '',
125+
git_basename: null,
126+
git_path: null,
127+
git_reference: null,
128+
};
74129
}
75130

76131
/**

fibjs/scripts/opt_tools/install.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ function fetch_leveled_module_info(m, v, parent) {
131131
case 'registry':
132132
let info = pkg_registrytype_module_infos[m];
133133
if (info === undefined) {
134-
const registry_url = `${rootsnap.registry}${encodeURIComponent(m)}`
134+
const registry_url = `${rootsnap.registry}${encodeURIComponent(pkg_install_typeinfo.registry_pkg_path)}`
135135
install_log('fetch metadata:', m, "=>", registry_url);
136136
pkg_registrytype_module_infos[m] = info = json_parse_response(http_get(registry_url));
137137
}
@@ -143,13 +143,13 @@ function fetch_leveled_module_info(m, v, parent) {
143143
const all_vers = Object.keys(info.versions);
144144
let filtered_vers = [];
145145

146-
switch (v) {
146+
switch (pkg_install_typeinfo.registry_semver) {
147147
case 'latest':
148148
case '*':
149149
filtered_vers = all_vers.sort(semver.rcompare);
150150
break
151151
default:
152-
all_vers.forEach(ver => semver.satisfies(ver, v) ? filtered_vers.push(ver) : undefined)
152+
all_vers.forEach(ver => semver.satisfies(ver, pkg_install_typeinfo.registry_semver) ? filtered_vers.push(ver) : undefined)
153153

154154
filtered_vers.sort(semver.rcompare);
155155
break
@@ -158,7 +158,7 @@ function fetch_leveled_module_info(m, v, parent) {
158158
matched_ver = filtered_vers[0];
159159

160160
if (!matched_ver)
161-
throw new Error(`[package/${info.name}]no matched for pattern '${v}'`)
161+
throw new Error(`[package/${info.name}]no matched for pattern '${pkg_install_typeinfo.registry_semver}'`)
162162
/* registry: match version :end */
163163

164164
const minfo = info.versions[matched_ver];
@@ -188,7 +188,7 @@ function fetch_leveled_module_info(m, v, parent) {
188188
}
189189

190190
return {
191-
name: minfo.name,
191+
name: m,
192192
version: minfo.version,
193193
bin: minfo.bin,
194194
binary: binary,

0 commit comments

Comments
 (0)
0