mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-17 05:09:30 +00:00
ALLOW platform specific url patterns
This commit is contained in:
@@ -49,6 +49,58 @@ describe('common', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getUrl', () => {
|
||||||
|
it('should get url from given string url', () => {
|
||||||
|
const url = common.getUrl('http://url');
|
||||||
|
|
||||||
|
expect(url).toEqual('http://url');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get specific url for current platform', () => {
|
||||||
|
const url = common.getUrl({
|
||||||
|
default: 'http://url.tar.gz',
|
||||||
|
windows: 'http://url.exe.zip'
|
||||||
|
}, { platform: 'windows' });
|
||||||
|
|
||||||
|
expect(url).toEqual('http://url.exe.zip');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get default url for current platform', () => {
|
||||||
|
const url = common.getUrl({
|
||||||
|
default: 'http://url.tar.gz',
|
||||||
|
windows: 'http://url.exe.zip'
|
||||||
|
}, { platform: 'linux' });
|
||||||
|
|
||||||
|
expect(url).toEqual('http://url.tar.gz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get specific url for current platform and architecture', () => {
|
||||||
|
const url = common.getUrl({
|
||||||
|
default: 'http://url.tar.gz',
|
||||||
|
windows: 'http://url.exe.zip',
|
||||||
|
darwin: {
|
||||||
|
default: 'http://url_darwin.tar.gz',
|
||||||
|
386: 'http://url_darwin_i386.tar.gz'
|
||||||
|
}
|
||||||
|
}, { platform: 'darwin', arch: '386' });
|
||||||
|
|
||||||
|
expect(url).toEqual('http://url_darwin_i386.tar.gz');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should get default url for current platform and architecture', () => {
|
||||||
|
const url = common.getUrl({
|
||||||
|
default: 'http://url.tar.gz',
|
||||||
|
windows: 'http://url.exe.zip',
|
||||||
|
darwin: {
|
||||||
|
default: 'http://url_darwin.tar.gz',
|
||||||
|
386: 'http://url_darwin_i386.tar.gz'
|
||||||
|
}
|
||||||
|
}, { platform: 'darwin', arch: 'amd64' });
|
||||||
|
|
||||||
|
expect(url).toEqual('http://url_darwin.tar.gz');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('parsePackageJson()', () => {
|
describe('parsePackageJson()', () => {
|
||||||
let _process;
|
let _process;
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,32 @@ function validateConfiguration({ version, goBinary }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUrl(url, process) {
|
||||||
|
if (typeof url === 'string') {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
let _url;
|
||||||
|
|
||||||
|
if (url[process.platform]) {
|
||||||
|
_url = url[process.platform];
|
||||||
|
} else {
|
||||||
|
_url = url.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof _url === 'string') {
|
||||||
|
return _url;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_url[process.arch]) {
|
||||||
|
_url = _url[process.arch]
|
||||||
|
} else {
|
||||||
|
_url = _url.default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _url;
|
||||||
|
}
|
||||||
|
|
||||||
function parsePackageJson() {
|
function parsePackageJson() {
|
||||||
if (!(process.arch in ARCH_MAPPING)) {
|
if (!(process.arch in ARCH_MAPPING)) {
|
||||||
console.error('Installation is not supported for this architecture: ' + process.arch);
|
console.error('Installation is not supported for this architecture: ' + process.arch);
|
||||||
@@ -99,9 +125,14 @@ function parsePackageJson() {
|
|||||||
// We have validated the config. It exists in all its glory
|
// We have validated the config. It exists in all its glory
|
||||||
const binPath = packageJson.goBinary.path;
|
const binPath = packageJson.goBinary.path;
|
||||||
let binName = packageJson.goBinary.name;
|
let binName = packageJson.goBinary.name;
|
||||||
let url = packageJson.goBinary.url;
|
let url = getUrl(packageJson.goBinary.url, process);
|
||||||
let version = packageJson.version;
|
let version = packageJson.version;
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
console.error('Could not find url matching platform and architecture');
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (version[0] === 'v') version = version.substr(1); // strip the 'v' if necessary v0.0.1 => 0.0.1
|
if (version[0] === 'v') version = version.substr(1); // strip the 'v' if necessary v0.0.1 => 0.0.1
|
||||||
|
|
||||||
// Binary name on Windows has .exe suffix
|
// Binary name on Windows has .exe suffix
|
||||||
@@ -127,4 +158,4 @@ function parsePackageJson() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { parsePackageJson, getInstallationPath };
|
module.exports = { parsePackageJson, getUrl, getInstallationPath };
|
||||||
|
|||||||
Reference in New Issue
Block a user