Skip to content

Commit

Permalink
Package Manager improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Oct 16, 2024
1 parent 91fd466 commit d20b7d9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 44 deletions.
30 changes: 8 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ViperIDE",
"version": "0.5.6",
"version": "0.5.7",
"description": "An innovative MicroPython / CircuitPython IDE for Web and Mobile",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"@eslint/js": "^9.12.0",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-replace": "^6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,9 @@ export async function installPkg(pkg, { version=null } = {}) {
prefer_source: QID('force-install-package-source').checked,
})
if (pkg_info.version) {
toastr.success(`Installed ${pkg}@${pkg_info.version}`)
toastr.success(`Installed ${pkg_info.name}@${pkg_info.version}`)
} else {
toastr.success(`Installed ${pkg}`)
toastr.success(`Installed ${pkg_info.name}`)
}
await _raw_updateFileTree(raw)
} catch (err) {
Expand Down
47 changes: 29 additions & 18 deletions src/package_mgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export async function findPkg(name) {
return [{}, null]
}

async function loadPkgInfo(url, { base=null }= {}) {
async function loadPkgInfo(url, { base=null, version=null }= {}) {
if (url.endsWith('.py') || url.endsWith('.mpy')) {
const pkg_info = {
version: "latest",
Expand All @@ -111,7 +111,7 @@ async function loadPkgInfo(url, { base=null }= {}) {
if (!url.endsWith('.json')) {
url += '/package.json'
}
const pkg_json = rewriteUrl(url, { base })
const pkg_json = rewriteUrl(url, { base, branch: version })
const pkg_info = await fetchJSON(pkg_json);
return [ pkg_info, pkg_json ]
}
Expand All @@ -137,26 +137,37 @@ export async function rawInstallPkg(raw, name, { dev=null, version=null, index=n
}

if (!pkg_info) {
let index_pkg;
[index, index_pkg] = await findPkg(name)
if (index_pkg) { // Found in index
if (index.index.v === 2) {
pkg_json = rewriteUrl(`${index.url}/package/${mpy_ver}/${index_pkg.name}/${version || 'latest'}.json`)
pkg_info = await fetchJSON(pkg_json)
} else if (index.index.v === '3.viper-ide') {
for (const pkg_ver of index_pkg.versions) {
if (!verify_mpy_ver(pkg_ver.mpy)) continue;
[ pkg_info, pkg_json ] = await loadPkgInfo(pkg_ver.url, { base: index.url })
break
try {
let index_pkg;
[index, index_pkg] = await findPkg(name)
if (index_pkg) { // Found in index
if (index.index.v === 2) {
pkg_json = rewriteUrl(`${index.url}/package/${mpy_ver}/${name}/${version || 'latest'}.json`)
pkg_info = await fetchJSON(pkg_json)
} else if (index.index.v === '3.viper-ide') {
for (const pkg_ver of index_pkg.versions) {
if (!verify_mpy_ver(pkg_ver.mpy)) continue;
[ pkg_info, pkg_json ] = await loadPkgInfo(pkg_ver.url, { base: index.url, version })
break
}
if (!pkg_info) {
throw new Error('Not found')
}
} else {
throw new Error(`Package index version ${index.index.v} is not supported`)
}
} else {
throw new Error(`Package index version ${index.index.v} is not supported`)
} else { // Not in index => URL?
[ pkg_info, pkg_json ] = await loadPkgInfo(name, { base: index.url, version })
}
} else { // Not in index => URL?
[ pkg_info, pkg_json ] = await loadPkgInfo(name, { base: index.url })
} catch (_err) {
throw new Error(`Cannot find ${name}@${version}`)
}
}

if (!pkg_info.name) {
pkg_info.name = name
}

if ('hashes' in pkg_info) {
for (const [fn, hash, ..._] of pkg_info.hashes) {
const response = await fetch(rewriteUrl(`${index.url}/file/${hash.slice(0,2)}/${hash}`))
Expand All @@ -174,7 +185,7 @@ export async function rawInstallPkg(raw, name, { dev=null, version=null, index=n

if ('urls' in pkg_info) {
for (const [fn, url, ..._] of pkg_info.urls) {
const response = await fetch(rewriteUrl(url, { base: pkg_json }))
const response = await fetch(rewriteUrl(url, { base: pkg_json, branch: version }))
if (!response.ok) { throw new Error(response.status) }
const content = await response.arrayBuffer()

Expand Down

0 comments on commit d20b7d9

Please sign in to comment.