cli: npm - strict platform / arch mapping for provided targets
This commit is contained in:
parent
d7fcc7aad3
commit
7642fda99f
2 changed files with 40 additions and 17 deletions
|
|
@ -6,21 +6,41 @@ const http = require('http');
|
|||
const https = require('https');
|
||||
const packageJSON = require('./package.json');
|
||||
|
||||
// Look to a results table in https://github.com/tree-sitter/tree-sitter/issues/2196
|
||||
const matrix = {
|
||||
platform: {
|
||||
'darwin': {
|
||||
name: 'macos',
|
||||
arch: {
|
||||
'arm64': { name: 'arm64' },
|
||||
'x64': { name: 'x64' },
|
||||
}
|
||||
},
|
||||
'linux': {
|
||||
name: 'linux',
|
||||
arch: {
|
||||
'arm64': { name: 'arm64' },
|
||||
'arm': { name: 'arm' },
|
||||
'x64': { name: 'x64' },
|
||||
'x86': { name: 'x86' },
|
||||
}
|
||||
},
|
||||
'win32': {
|
||||
name: 'windows',
|
||||
arch: {
|
||||
'x64': { name: 'x64' },
|
||||
'x86': { name: 'x86' },
|
||||
'ia32': { name: 'x86' },
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// Determine the URL of the file.
|
||||
const platformName = {
|
||||
'darwin': 'macos',
|
||||
'linux': 'linux',
|
||||
'win32': 'windows'
|
||||
}[process.platform];
|
||||
const platform = matrix.platform[process.platform];
|
||||
const arch = platform && platform.arch[process.arch];
|
||||
|
||||
let archName = {
|
||||
'x64': 'x64',
|
||||
'x86': 'x86',
|
||||
'ia32': 'x86',
|
||||
'arm64': 'arm64'
|
||||
}[process.arch];
|
||||
|
||||
if (!platformName || !archName) {
|
||||
if (!platform || !platform.name || !arch || !arch.name) {
|
||||
console.error(
|
||||
`Cannot install tree-sitter-cli for platform ${process.platform}, architecture ${process.arch}`
|
||||
);
|
||||
|
|
@ -28,7 +48,7 @@ if (!platformName || !archName) {
|
|||
}
|
||||
|
||||
const releaseURL = `https://github.com/tree-sitter/tree-sitter/releases/download/v${packageJSON.version}`;
|
||||
const assetName = `tree-sitter-${platformName}-${archName}.gz`;
|
||||
const assetName = `tree-sitter-${platform.name}-${arch.name}.gz`;
|
||||
const assetURL = `${releaseURL}/${assetName}`;
|
||||
|
||||
// Remove previously-downloaded files.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue